Completed
Branch Gutenberg/master (ddf824)
by
unknown
52:49 queued 39:46
created
caffeinated/payment_methods/Paypal_Pro/EEG_Paypal_Pro.gateway.php 1 patch
Indentation   +588 added lines, -588 removed lines patch added patch discarded remove patch
@@ -11,592 +11,592 @@
 block discarded – undo
11 11
 class EEG_Paypal_Pro extends EE_Onsite_Gateway
12 12
 {
13 13
 
14
-    /**
15
-     * @var $_paypal_api_username string
16
-     */
17
-    protected $_username = null;
18
-
19
-    /**
20
-     * @var $_password string
21
-     */
22
-    protected $_password = null;
23
-
24
-    /**
25
-     * @var $_signature string
26
-     */
27
-    protected $_signature = null;
28
-
29
-    /**
30
-     * @var $_credit_card_types array with the keys for credit card types accepted on this account
31
-     */
32
-    protected $_credit_card_types    = null;
33
-
34
-    protected $_currencies_supported = array(
35
-        'USD',
36
-        'GBP',
37
-        'CAD',
38
-        'AUD',
39
-        'BRL',
40
-        'CHF',
41
-        'CZK',
42
-        'DKK',
43
-        'EUR',
44
-        'HKD',
45
-        'HUF',
46
-        'ILS',
47
-        'JPY',
48
-        'MXN',
49
-        'MYR',
50
-        'NOK',
51
-        'NZD',
52
-        'PHP',
53
-        'PLN',
54
-        'SEK',
55
-        'SGD',
56
-        'THB',
57
-        'TRY',
58
-        'TWD',
59
-        'RUB',
60
-        'INR',
61
-    );
62
-
63
-
64
-
65
-    /**
66
-     * @param EEI_Payment $payment
67
-     * @param array       $billing_info {
68
-     * @type string $credit_card
69
-     * @type string $credit_card_type
70
-     * @type string $exp_month always 2 characters
71
-     * @type string $exp_year always 4 characters
72
-     * @type string $cvv
73
-     * }
74
-     * @see      parent::do_direct_payment for more info
75
-     * @return EE_Payment|EEI_Payment
76
-     * @throws EE_Error
77
-     */
78
-    public function do_direct_payment($payment, $billing_info = null)
79
-    {
80
-        $transaction = $payment->transaction();
81
-        if (! $transaction instanceof EEI_Transaction) {
82
-            throw new EE_Error(
83
-                esc_html__('No transaction for payment while paying with PayPal Pro.', 'event_espresso')
84
-            );
85
-        }
86
-        $primary_registrant = $transaction->primary_registration();
87
-        if (! $primary_registrant instanceof EEI_Registration) {
88
-            throw new EE_Error(
89
-                esc_html__(
90
-                    'No primary registration on transaction while paying with PayPal Pro.',
91
-                    'event_espresso'
92
-                )
93
-            );
94
-        }
95
-        $attendee = $primary_registrant->attendee();
96
-        if (! $attendee instanceof EEI_Attendee) {
97
-            throw new EE_Error(
98
-                esc_html__(
99
-                    'No attendee on primary registration while paying with PayPal Pro.',
100
-                    'event_espresso'
101
-                )
102
-            );
103
-        }
104
-        $gateway_formatter = $this->_get_gateway_formatter();
105
-        $order_description = substr($gateway_formatter->formatOrderDescription($payment), 0, 127);
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
-                        $gateway_formatter->formatLineItemName($line_item, $payment),
120
-                        0,
121
-                        127
122
-                    ),
123
-                    // Item description.  127 char max.
124
-                    'l_desc'                 => substr(
125
-                        $gateway_formatter->formatLineItemDesc($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
-                    $gateway_formatter->formatPartialPaymentLineItemName($payment),
157
-                    0,
158
-                    127
159
-                ),
160
-                // Item description.  127 char max.
161
-                'l_desc'   => substr(
162
-                    $gateway_formatter->formatPartialPaymentLineItemDesc($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 indicates 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.
188
-            //  In addition, either start date or issue number must be specified.
189
-            'creditcardtype' => $billing_info['credit_card_type'],
190
-            // Required.  Credit card number.  No spaces or punctuation.
191
-            'acct'           => $billing_info['credit_card'],
192
-            // Required.  Credit card expiration date.  Format is MMYYYY
193
-            'expdate'        => $billing_info['exp_month'] . $billing_info['exp_year'],
194
-            // Requirements determined by your PayPal account settings.  Security digits for credit card.
195
-            'cvv2'           => $billing_info['cvv'],
196
-        );
197
-        $PayerInfo = array(
198
-            // Email address of payer.
199
-            'email'       => $billing_info['email'],
200
-            // Unique PayPal customer ID for payer.
201
-            'payerid'     => '',
202
-            // Status of payer.  Values are verified or unverified
203
-            'payerstatus' => '',
204
-            // Payer's business name.
205
-            'business'    => '',
206
-        );
207
-        $PayerName = array(
208
-            // Payer's salutation.  20 char max.
209
-            'salutation' => '',
210
-            // Payer's first name.  25 char max.
211
-            'firstname'  => substr($billing_info['first_name'], 0, 25),
212
-            // Payer's middle name.  25 char max.
213
-            'middlename' => '',
214
-            // Payer's last name.  25 char max.
215
-            'lastname'   => substr($billing_info['last_name'], 0, 25),
216
-            // Payer's suffix.  12 char max.
217
-            'suffix'     => '',
218
-        );
219
-        $BillingAddress = array(
220
-            // Required.  First street address.
221
-            'street'      => $billing_info['address'],
222
-            // Second street address.
223
-            'street2'     => $billing_info['address2'],
224
-            // Required.  Name of City.
225
-            'city'        => $billing_info['city'],
226
-            // Required. Name of State or Province.
227
-            'state'       => substr($billing_info['state'], 0, 40),
228
-            // Required.  Country code.
229
-            'countrycode' => $billing_info['country'],
230
-            // Required.  Postal code of payer.
231
-            'zip'         => $billing_info['zip'],
232
-        );
233
-        // check if the registration info contains the needed fields for paypal pro
234
-        // (see https://developer.paypal.com/docs/classic/api/merchant/DoDirectPayment_API_Operation_NVP/)
235
-        if ($attendee->address() && $attendee->city() && $attendee->country_ID()) {
236
-            $use_registration_address_info = true;
237
-        } else {
238
-            $use_registration_address_info = false;
239
-        }
240
-        // so if the attendee has enough data to fill out PayPal Pro's shipping info, use it.
241
-        // If not, use the billing info again
242
-        $ShippingAddress = array(
243
-            'shiptoname'     => substr($use_registration_address_info
244
-                ? $attendee->full_name()
245
-                : $billing_info['first_name'] . ' ' . $billing_info['last_name'], 0, 32),
246
-            'shiptostreet'   => substr($use_registration_address_info
247
-                ? $attendee->address()
248
-                : $billing_info['address'], 0, 100),
249
-            'shiptostreet2'  => substr($use_registration_address_info
250
-                ? $attendee->address2() : $billing_info['address2'], 0, 100),
251
-            'shiptocity'     => substr($use_registration_address_info
252
-                ? $attendee->city()
253
-                : $billing_info['city'], 0, 40),
254
-            'state'          => substr($use_registration_address_info
255
-                ? $attendee->state_name()
256
-                : $billing_info['state'], 0, 40),
257
-            'shiptocountry'  => $use_registration_address_info
258
-                ? $attendee->country_ID()
259
-                : $billing_info['country'],
260
-            'shiptozip'      => substr($use_registration_address_info
261
-                ? $attendee->zip()
262
-                : $billing_info['zip'], 0, 20),
263
-            'shiptophonenum' => substr($use_registration_address_info
264
-                ? $attendee->phone()
265
-                : $billing_info['phone'], 0, 20),
266
-        );
267
-        $PaymentDetails = array(
268
-            // Required.  Total amount of order, including shipping, handling, and tax.
269
-            'amt'          => $gateway_formatter->formatCurrency($payment->amount()),
270
-            // Required.  Three-letter currency code.  Default is USD.
271
-            'currencycode' => $payment->currency_code(),
272
-            // Required if you include itemized cart details. (L_AMTn, etc.)
273
-            // Subtotal of items not including S&H, or tax.
274
-            'itemamt'      => $gateway_formatter->formatCurrency($item_amount),//
275
-            // Total shipping costs for the order.  If you specify shippingamt, you must also specify itemamt.
276
-            'shippingamt'  => '',
277
-            // Total handling costs for the order.  If you specify handlingamt, you must also specify itemamt.
278
-            'handlingamt'  => '',
279
-            // Required if you specify itemized cart tax details.
280
-            // Sum of tax for all items on the order.  Total sales tax.
281
-            'taxamt'       => $gateway_formatter->formatCurrency($tax_amount),
282
-            // Description of the order the customer is purchasing.  127 char max.
283
-            'desc'         => $order_description,
284
-            // Free-form field for your own use.  256 char max.
285
-            'custom'       => $primary_registrant ? $primary_registrant->ID() : '',
286
-            // Your own invoice or tracking number
287
-            'invnum'       => wp_generate_password(12, false),// $transaction->ID(),
288
-            // URL for receiving Instant Payment Notifications.  This overrides what your profile is set to use.
289
-            'notifyurl'    => '',
290
-            'buttonsource' => 'EventEspresso_SP',// EE will blow up if you change this
291
-        );
292
-        // Wrap all data arrays into a single, "master" array which will be passed into the class function.
293
-        $PayPalRequestData = array(
294
-            'DPFields'        => $DPFields,
295
-            'CCDetails'       => $CCDetails,
296
-            'PayerInfo'       => $PayerInfo,
297
-            'PayerName'       => $PayerName,
298
-            'BillingAddress'  => $BillingAddress,
299
-            'ShippingAddress' => $ShippingAddress,
300
-            'PaymentDetails'  => $PaymentDetails,
301
-            'OrderItems'      => $order_items,
302
-        );
303
-        $this->_log_clean_request($PayPalRequestData, $payment);
304
-        try {
305
-            $PayPalResult = $this->prep_and_curl_request($PayPalRequestData);
306
-            // remove PCI-sensitive data so it doesn't get stored
307
-            $PayPalResult = $this->_log_clean_response($PayPalResult, $payment);
308
-            $message = isset($PayPalResult['L_LONGMESSAGE0']) ? $PayPalResult['L_LONGMESSAGE0'] : $PayPalResult['ACK'];
309
-            if (empty($PayPalResult['RAWRESPONSE'])) {
310
-                $payment->set_status($this->_pay_model->failed_status());
311
-                $payment->set_gateway_response(__('No response received from Paypal Pro', 'event_espresso'));
312
-                $payment->set_details($PayPalResult);
313
-            } else {
314
-                if ($this->_APICallSuccessful($PayPalResult)) {
315
-                    $payment->set_status($this->_pay_model->approved_status());
316
-                } else {
317
-                    $payment->set_status($this->_pay_model->declined_status());
318
-                }
319
-                // make sure we interpret the AMT as a float, not an international string
320
-                // (where periods are thousand separators)
321
-                $payment->set_amount(isset($PayPalResult['AMT']) ? floatval($PayPalResult['AMT']) : 0);
322
-                $payment->set_gateway_response($message);
323
-                $payment->set_txn_id_chq_nmbr(isset($PayPalResult['TRANSACTIONID'])
324
-                    ? $PayPalResult['TRANSACTIONID']
325
-                    : null);
326
-                $primary_registration_code = $primary_registrant instanceof EE_Registration
327
-                    ? $primary_registrant->reg_code()
328
-                    : '';
329
-                $payment->set_extra_accntng($primary_registration_code);
330
-                $payment->set_details($PayPalResult);
331
-            }
332
-        } catch (Exception $e) {
333
-            $payment->set_status($this->_pay_model->failed_status());
334
-            $payment->set_gateway_response($e->getMessage());
335
-        }
336
-        // $payment->set_status( $this->_pay_model->declined_status() );
337
-        // $payment->set_gateway_response( '' );
338
-        return $payment;
339
-    }
340
-
341
-
342
-
343
-    /**
344
-     * CLeans out sensitive CC data and then logs it, and returns the cleaned request
345
-     *
346
-     * @param array       $request
347
-     * @param EEI_Payment $payment
348
-     * @return void
349
-     */
350
-    private function _log_clean_request($request, $payment)
351
-    {
352
-        $cleaned_request_data = $request;
353
-        unset($cleaned_request_data['CCDetails']['acct']);
354
-        unset($cleaned_request_data['CCDetails']['cvv2']);
355
-        unset($cleaned_request_data['CCDetails']['expdate']);
356
-        $this->log(array('Paypal Request' => $cleaned_request_data), $payment);
357
-    }
358
-
359
-
360
-
361
-    /**
362
-     * Cleans the response, logs it, and returns it
363
-     *
364
-     * @param array       $response
365
-     * @param EEI_Payment $payment
366
-     * @return array cleaned
367
-     */
368
-    private function _log_clean_response($response, $payment)
369
-    {
370
-        unset($response['REQUESTDATA']['CREDITCARDTYPE']);
371
-        unset($response['REQUESTDATA']['ACCT']);
372
-        unset($response['REQUESTDATA']['EXPDATE']);
373
-        unset($response['REQUESTDATA']['CVV2']);
374
-        unset($response['RAWREQUEST']);
375
-        $this->log(array('Paypal Response' => $response), $payment);
376
-        return $response;
377
-    }
378
-
379
-
380
-
381
-    /**
382
-     * @param $DataArray
383
-     * @return array
384
-     */
385
-    private function prep_and_curl_request($DataArray)
386
-    {
387
-        // Create empty holders for each portion of the NVP string
388
-        $DPFieldsNVP = '&METHOD=DoDirectPayment&BUTTONSOURCE=AngellEYE_PHP_Class_DDP';
389
-        $CCDetailsNVP = '';
390
-        $PayerInfoNVP = '';
391
-        $PayerNameNVP = '';
392
-        $BillingAddressNVP = '';
393
-        $ShippingAddressNVP = '';
394
-        $PaymentDetailsNVP = '';
395
-        $OrderItemsNVP = '';
396
-        $Secure3DNVP = '';
397
-        // DP Fields
398
-        $DPFields = isset($DataArray['DPFields']) ? $DataArray['DPFields'] : array();
399
-        foreach ($DPFields as $DPFieldsVar => $DPFieldsVal) {
400
-            $DPFieldsNVP .= '&' . strtoupper($DPFieldsVar) . '=' . urlencode($DPFieldsVal);
401
-        }
402
-        // CC Details Fields
403
-        $CCDetails = isset($DataArray['CCDetails']) ? $DataArray['CCDetails'] : array();
404
-        foreach ($CCDetails as $CCDetailsVar => $CCDetailsVal) {
405
-            $CCDetailsNVP .= '&' . strtoupper($CCDetailsVar) . '=' . urlencode($CCDetailsVal);
406
-        }
407
-        // PayerInfo Type Fields
408
-        $PayerInfo = isset($DataArray['PayerInfo']) ? $DataArray['PayerInfo'] : array();
409
-        foreach ($PayerInfo as $PayerInfoVar => $PayerInfoVal) {
410
-            $PayerInfoNVP .= '&' . strtoupper($PayerInfoVar) . '=' . urlencode($PayerInfoVal);
411
-        }
412
-        // Payer Name Fields
413
-        $PayerName = isset($DataArray['PayerName']) ? $DataArray['PayerName'] : array();
414
-        foreach ($PayerName as $PayerNameVar => $PayerNameVal) {
415
-            $PayerNameNVP .= '&' . strtoupper($PayerNameVar) . '=' . urlencode($PayerNameVal);
416
-        }
417
-        // Address Fields (Billing)
418
-        $BillingAddress = isset($DataArray['BillingAddress']) ? $DataArray['BillingAddress'] : array();
419
-        foreach ($BillingAddress as $BillingAddressVar => $BillingAddressVal) {
420
-            $BillingAddressNVP .= '&' . strtoupper($BillingAddressVar) . '=' . urlencode($BillingAddressVal);
421
-        }
422
-        // Payment Details Type Fields
423
-        $PaymentDetails = isset($DataArray['PaymentDetails']) ? $DataArray['PaymentDetails'] : array();
424
-        foreach ($PaymentDetails as $PaymentDetailsVar => $PaymentDetailsVal) {
425
-            $PaymentDetailsNVP .= '&' . strtoupper($PaymentDetailsVar) . '=' . urlencode($PaymentDetailsVal);
426
-        }
427
-        // Payment Details Item Type Fields
428
-        $OrderItems = isset($DataArray['OrderItems']) ? $DataArray['OrderItems'] : array();
429
-        $n = 0;
430
-        foreach ($OrderItems as $OrderItemsVar => $OrderItemsVal) {
431
-            $CurrentItem = $OrderItems[ $OrderItemsVar ];
432
-            foreach ($CurrentItem as $CurrentItemVar => $CurrentItemVal) {
433
-                $OrderItemsNVP .= '&' . strtoupper($CurrentItemVar) . $n . '=' . urlencode($CurrentItemVal);
434
-            }
435
-            $n++;
436
-        }
437
-        // Ship To Address Fields
438
-        $ShippingAddress = isset($DataArray['ShippingAddress']) ? $DataArray['ShippingAddress'] : array();
439
-        foreach ($ShippingAddress as $ShippingAddressVar => $ShippingAddressVal) {
440
-            $ShippingAddressNVP .= '&' . strtoupper($ShippingAddressVar) . '=' . urlencode($ShippingAddressVal);
441
-        }
442
-        // 3D Secure Fields
443
-        $Secure3D = isset($DataArray['Secure3D']) ? $DataArray['Secure3D'] : array();
444
-        foreach ($Secure3D as $Secure3DVar => $Secure3DVal) {
445
-            $Secure3DNVP .= '&' . strtoupper($Secure3DVar) . '=' . urlencode($Secure3DVal);
446
-        }
447
-        // Now that we have each chunk we need to go ahead and append them all together for our entire NVP string
448
-        $NVPRequest = 'USER='
449
-                      . $this->_username
450
-                      . '&PWD='
451
-                      . $this->_password
452
-                      . '&VERSION=64.0'
453
-                      . '&SIGNATURE='
454
-                      . $this->_signature
455
-                      . $DPFieldsNVP
456
-                      . $CCDetailsNVP
457
-                      . $PayerInfoNVP
458
-                      . $PayerNameNVP
459
-                      . $BillingAddressNVP
460
-                      . $PaymentDetailsNVP
461
-                      . $OrderItemsNVP
462
-                      . $ShippingAddressNVP
463
-                      . $Secure3DNVP;
464
-        $NVPResponse = $this->_CURLRequest($NVPRequest);
465
-        $NVPRequestArray = $this->_NVPToArray($NVPRequest);
466
-        $NVPResponseArray = $this->_NVPToArray($NVPResponse);
467
-        $Errors = $this->_GetErrors($NVPResponseArray);
468
-        $NVPResponseArray['ERRORS'] = $Errors;
469
-        $NVPResponseArray['REQUESTDATA'] = $NVPRequestArray;
470
-        $NVPResponseArray['RAWREQUEST'] = $NVPRequest;
471
-        $NVPResponseArray['RAWRESPONSE'] = $NVPResponse;
472
-        return $NVPResponseArray;
473
-    }
474
-
475
-
476
-
477
-    /**
478
-     * @param $Request
479
-     * @return mixed
480
-     */
481
-    private function _CURLRequest($Request)
482
-    {
483
-        $EndPointURL = $this->_debug_mode ? 'https://api-3t.sandbox.paypal.com/nvp' : 'https://api-3t.paypal.com/nvp';
484
-        $curl = curl_init();
485
-        curl_setopt($curl, CURLOPT_VERBOSE, apply_filters('FHEE__EEG_Paypal_Pro__CurlRequest__CURLOPT_VERBOSE', true));
486
-        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
487
-        curl_setopt($curl, CURLOPT_TIMEOUT, 60);
488
-        curl_setopt($curl, CURLOPT_URL, $EndPointURL);
489
-        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
490
-        curl_setopt($curl, CURLOPT_POSTFIELDS, $Request);
491
-        curl_setopt($curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
492
-        // execute the curl POST
493
-        $Response = curl_exec($curl);
494
-        curl_close($curl);
495
-        return $Response;
496
-    }
497
-
498
-
499
-
500
-    /**
501
-     * @param $NVPString
502
-     * @return array
503
-     */
504
-    private function _NVPToArray($NVPString)
505
-    {
506
-        // prepare responses into array
507
-        $proArray = array();
508
-        while (strlen($NVPString)) {
509
-            // name
510
-            $keypos = strpos($NVPString, '=');
511
-            $keyval = substr($NVPString, 0, $keypos);
512
-            // value
513
-            $valuepos = strpos($NVPString, '&') ? strpos($NVPString, '&') : strlen($NVPString);
514
-            $valval = substr($NVPString, $keypos + 1, $valuepos - $keypos - 1);
515
-            // decoding the response
516
-            $proArray[ $keyval ] = urldecode($valval);
517
-            $NVPString = substr($NVPString, $valuepos + 1, strlen($NVPString));
518
-        }
519
-        return $proArray;
520
-    }
521
-
522
-
523
-
524
-    /**
525
-     * @param array $PayPalResult
526
-     * @return bool
527
-     */
528
-    private function _APICallSuccessful($PayPalResult)
529
-    {
530
-        $approved = false;
531
-        // check main response message from PayPal
532
-        if (isset($PayPalResult['ACK']) && ! empty($PayPalResult['ACK'])) {
533
-            $ack = strtoupper($PayPalResult['ACK']);
534
-            $approved = ($ack == 'SUCCESS' || $ack == 'SUCCESSWITHWARNING' || $ack == 'PARTIALSUCCESS') ? true : false;
535
-        }
536
-        return $approved;
537
-    }
538
-
539
-
540
-
541
-    /**
542
-     * @param $DataArray
543
-     * @return array
544
-     */
545
-    private function _GetErrors($DataArray)
546
-    {
547
-        $Errors = array();
548
-        $n = 0;
549
-        while (isset($DataArray[ 'L_ERRORCODE' . $n . '' ])) {
550
-            $LErrorCode = isset($DataArray[ 'L_ERRORCODE' . $n . '' ]) ? $DataArray[ 'L_ERRORCODE' . $n . '' ] : '';
551
-            $LShortMessage = isset($DataArray[ 'L_SHORTMESSAGE' . $n . '' ])
552
-                ? $DataArray[ 'L_SHORTMESSAGE' . $n . '' ]
553
-                : '';
554
-            $LLongMessage = isset($DataArray[ 'L_LONGMESSAGE' . $n . '' ])
555
-                ? $DataArray[ 'L_LONGMESSAGE' . $n . '' ]
556
-                : '';
557
-            $LSeverityCode = isset($DataArray[ 'L_SEVERITYCODE' . $n . '' ])
558
-                ? $DataArray[ 'L_SEVERITYCODE' . $n . '' ]
559
-                : '';
560
-            $CurrentItem = array(
561
-                'L_ERRORCODE'    => $LErrorCode,
562
-                'L_SHORTMESSAGE' => $LShortMessage,
563
-                'L_LONGMESSAGE'  => $LLongMessage,
564
-                'L_SEVERITYCODE' => $LSeverityCode,
565
-            );
566
-            array_push($Errors, $CurrentItem);
567
-            $n++;
568
-        }
569
-        return $Errors;
570
-    }
571
-
572
-
573
-
574
-    /**
575
-     *        nothing to see here...  move along....
576
-     *
577
-     * @access protected
578
-     * @param $Errors
579
-     * @return string
580
-     */
581
-    private function _DisplayErrors($Errors)
582
-    {
583
-        $error = '';
584
-        foreach ($Errors as $ErrorVar => $ErrorVal) {
585
-            $CurrentError = $Errors[ $ErrorVar ];
586
-            foreach ($CurrentError as $CurrentErrorVar => $CurrentErrorVal) {
587
-                $CurrentVarName = '';
588
-                if ($CurrentErrorVar == 'L_ERRORCODE') {
589
-                    $CurrentVarName = 'Error Code';
590
-                } elseif ($CurrentErrorVar == 'L_SHORTMESSAGE') {
591
-                    $CurrentVarName = 'Short Message';
592
-                } elseif ($CurrentErrorVar == 'L_LONGMESSAGE') {
593
-                    $CurrentVarName = 'Long Message';
594
-                } elseif ($CurrentErrorVar == 'L_SEVERITYCODE') {
595
-                    $CurrentVarName = 'Severity Code';
596
-                }
597
-                $error .= '<br />' . $CurrentVarName . ': ' . $CurrentErrorVal;
598
-            }
599
-        }
600
-        return $error;
601
-    }
14
+	/**
15
+	 * @var $_paypal_api_username string
16
+	 */
17
+	protected $_username = null;
18
+
19
+	/**
20
+	 * @var $_password string
21
+	 */
22
+	protected $_password = null;
23
+
24
+	/**
25
+	 * @var $_signature string
26
+	 */
27
+	protected $_signature = null;
28
+
29
+	/**
30
+	 * @var $_credit_card_types array with the keys for credit card types accepted on this account
31
+	 */
32
+	protected $_credit_card_types    = null;
33
+
34
+	protected $_currencies_supported = array(
35
+		'USD',
36
+		'GBP',
37
+		'CAD',
38
+		'AUD',
39
+		'BRL',
40
+		'CHF',
41
+		'CZK',
42
+		'DKK',
43
+		'EUR',
44
+		'HKD',
45
+		'HUF',
46
+		'ILS',
47
+		'JPY',
48
+		'MXN',
49
+		'MYR',
50
+		'NOK',
51
+		'NZD',
52
+		'PHP',
53
+		'PLN',
54
+		'SEK',
55
+		'SGD',
56
+		'THB',
57
+		'TRY',
58
+		'TWD',
59
+		'RUB',
60
+		'INR',
61
+	);
62
+
63
+
64
+
65
+	/**
66
+	 * @param EEI_Payment $payment
67
+	 * @param array       $billing_info {
68
+	 * @type string $credit_card
69
+	 * @type string $credit_card_type
70
+	 * @type string $exp_month always 2 characters
71
+	 * @type string $exp_year always 4 characters
72
+	 * @type string $cvv
73
+	 * }
74
+	 * @see      parent::do_direct_payment for more info
75
+	 * @return EE_Payment|EEI_Payment
76
+	 * @throws EE_Error
77
+	 */
78
+	public function do_direct_payment($payment, $billing_info = null)
79
+	{
80
+		$transaction = $payment->transaction();
81
+		if (! $transaction instanceof EEI_Transaction) {
82
+			throw new EE_Error(
83
+				esc_html__('No transaction for payment while paying with PayPal Pro.', 'event_espresso')
84
+			);
85
+		}
86
+		$primary_registrant = $transaction->primary_registration();
87
+		if (! $primary_registrant instanceof EEI_Registration) {
88
+			throw new EE_Error(
89
+				esc_html__(
90
+					'No primary registration on transaction while paying with PayPal Pro.',
91
+					'event_espresso'
92
+				)
93
+			);
94
+		}
95
+		$attendee = $primary_registrant->attendee();
96
+		if (! $attendee instanceof EEI_Attendee) {
97
+			throw new EE_Error(
98
+				esc_html__(
99
+					'No attendee on primary registration while paying with PayPal Pro.',
100
+					'event_espresso'
101
+				)
102
+			);
103
+		}
104
+		$gateway_formatter = $this->_get_gateway_formatter();
105
+		$order_description = substr($gateway_formatter->formatOrderDescription($payment), 0, 127);
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
+						$gateway_formatter->formatLineItemName($line_item, $payment),
120
+						0,
121
+						127
122
+					),
123
+					// Item description.  127 char max.
124
+					'l_desc'                 => substr(
125
+						$gateway_formatter->formatLineItemDesc($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
+					$gateway_formatter->formatPartialPaymentLineItemName($payment),
157
+					0,
158
+					127
159
+				),
160
+				// Item description.  127 char max.
161
+				'l_desc'   => substr(
162
+					$gateway_formatter->formatPartialPaymentLineItemDesc($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 indicates 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.
188
+			//  In addition, either start date or issue number must be specified.
189
+			'creditcardtype' => $billing_info['credit_card_type'],
190
+			// Required.  Credit card number.  No spaces or punctuation.
191
+			'acct'           => $billing_info['credit_card'],
192
+			// Required.  Credit card expiration date.  Format is MMYYYY
193
+			'expdate'        => $billing_info['exp_month'] . $billing_info['exp_year'],
194
+			// Requirements determined by your PayPal account settings.  Security digits for credit card.
195
+			'cvv2'           => $billing_info['cvv'],
196
+		);
197
+		$PayerInfo = array(
198
+			// Email address of payer.
199
+			'email'       => $billing_info['email'],
200
+			// Unique PayPal customer ID for payer.
201
+			'payerid'     => '',
202
+			// Status of payer.  Values are verified or unverified
203
+			'payerstatus' => '',
204
+			// Payer's business name.
205
+			'business'    => '',
206
+		);
207
+		$PayerName = array(
208
+			// Payer's salutation.  20 char max.
209
+			'salutation' => '',
210
+			// Payer's first name.  25 char max.
211
+			'firstname'  => substr($billing_info['first_name'], 0, 25),
212
+			// Payer's middle name.  25 char max.
213
+			'middlename' => '',
214
+			// Payer's last name.  25 char max.
215
+			'lastname'   => substr($billing_info['last_name'], 0, 25),
216
+			// Payer's suffix.  12 char max.
217
+			'suffix'     => '',
218
+		);
219
+		$BillingAddress = array(
220
+			// Required.  First street address.
221
+			'street'      => $billing_info['address'],
222
+			// Second street address.
223
+			'street2'     => $billing_info['address2'],
224
+			// Required.  Name of City.
225
+			'city'        => $billing_info['city'],
226
+			// Required. Name of State or Province.
227
+			'state'       => substr($billing_info['state'], 0, 40),
228
+			// Required.  Country code.
229
+			'countrycode' => $billing_info['country'],
230
+			// Required.  Postal code of payer.
231
+			'zip'         => $billing_info['zip'],
232
+		);
233
+		// check if the registration info contains the needed fields for paypal pro
234
+		// (see https://developer.paypal.com/docs/classic/api/merchant/DoDirectPayment_API_Operation_NVP/)
235
+		if ($attendee->address() && $attendee->city() && $attendee->country_ID()) {
236
+			$use_registration_address_info = true;
237
+		} else {
238
+			$use_registration_address_info = false;
239
+		}
240
+		// so if the attendee has enough data to fill out PayPal Pro's shipping info, use it.
241
+		// If not, use the billing info again
242
+		$ShippingAddress = array(
243
+			'shiptoname'     => substr($use_registration_address_info
244
+				? $attendee->full_name()
245
+				: $billing_info['first_name'] . ' ' . $billing_info['last_name'], 0, 32),
246
+			'shiptostreet'   => substr($use_registration_address_info
247
+				? $attendee->address()
248
+				: $billing_info['address'], 0, 100),
249
+			'shiptostreet2'  => substr($use_registration_address_info
250
+				? $attendee->address2() : $billing_info['address2'], 0, 100),
251
+			'shiptocity'     => substr($use_registration_address_info
252
+				? $attendee->city()
253
+				: $billing_info['city'], 0, 40),
254
+			'state'          => substr($use_registration_address_info
255
+				? $attendee->state_name()
256
+				: $billing_info['state'], 0, 40),
257
+			'shiptocountry'  => $use_registration_address_info
258
+				? $attendee->country_ID()
259
+				: $billing_info['country'],
260
+			'shiptozip'      => substr($use_registration_address_info
261
+				? $attendee->zip()
262
+				: $billing_info['zip'], 0, 20),
263
+			'shiptophonenum' => substr($use_registration_address_info
264
+				? $attendee->phone()
265
+				: $billing_info['phone'], 0, 20),
266
+		);
267
+		$PaymentDetails = array(
268
+			// Required.  Total amount of order, including shipping, handling, and tax.
269
+			'amt'          => $gateway_formatter->formatCurrency($payment->amount()),
270
+			// Required.  Three-letter currency code.  Default is USD.
271
+			'currencycode' => $payment->currency_code(),
272
+			// Required if you include itemized cart details. (L_AMTn, etc.)
273
+			// Subtotal of items not including S&H, or tax.
274
+			'itemamt'      => $gateway_formatter->formatCurrency($item_amount),//
275
+			// Total shipping costs for the order.  If you specify shippingamt, you must also specify itemamt.
276
+			'shippingamt'  => '',
277
+			// Total handling costs for the order.  If you specify handlingamt, you must also specify itemamt.
278
+			'handlingamt'  => '',
279
+			// Required if you specify itemized cart tax details.
280
+			// Sum of tax for all items on the order.  Total sales tax.
281
+			'taxamt'       => $gateway_formatter->formatCurrency($tax_amount),
282
+			// Description of the order the customer is purchasing.  127 char max.
283
+			'desc'         => $order_description,
284
+			// Free-form field for your own use.  256 char max.
285
+			'custom'       => $primary_registrant ? $primary_registrant->ID() : '',
286
+			// Your own invoice or tracking number
287
+			'invnum'       => wp_generate_password(12, false),// $transaction->ID(),
288
+			// URL for receiving Instant Payment Notifications.  This overrides what your profile is set to use.
289
+			'notifyurl'    => '',
290
+			'buttonsource' => 'EventEspresso_SP',// EE will blow up if you change this
291
+		);
292
+		// Wrap all data arrays into a single, "master" array which will be passed into the class function.
293
+		$PayPalRequestData = array(
294
+			'DPFields'        => $DPFields,
295
+			'CCDetails'       => $CCDetails,
296
+			'PayerInfo'       => $PayerInfo,
297
+			'PayerName'       => $PayerName,
298
+			'BillingAddress'  => $BillingAddress,
299
+			'ShippingAddress' => $ShippingAddress,
300
+			'PaymentDetails'  => $PaymentDetails,
301
+			'OrderItems'      => $order_items,
302
+		);
303
+		$this->_log_clean_request($PayPalRequestData, $payment);
304
+		try {
305
+			$PayPalResult = $this->prep_and_curl_request($PayPalRequestData);
306
+			// remove PCI-sensitive data so it doesn't get stored
307
+			$PayPalResult = $this->_log_clean_response($PayPalResult, $payment);
308
+			$message = isset($PayPalResult['L_LONGMESSAGE0']) ? $PayPalResult['L_LONGMESSAGE0'] : $PayPalResult['ACK'];
309
+			if (empty($PayPalResult['RAWRESPONSE'])) {
310
+				$payment->set_status($this->_pay_model->failed_status());
311
+				$payment->set_gateway_response(__('No response received from Paypal Pro', 'event_espresso'));
312
+				$payment->set_details($PayPalResult);
313
+			} else {
314
+				if ($this->_APICallSuccessful($PayPalResult)) {
315
+					$payment->set_status($this->_pay_model->approved_status());
316
+				} else {
317
+					$payment->set_status($this->_pay_model->declined_status());
318
+				}
319
+				// make sure we interpret the AMT as a float, not an international string
320
+				// (where periods are thousand separators)
321
+				$payment->set_amount(isset($PayPalResult['AMT']) ? floatval($PayPalResult['AMT']) : 0);
322
+				$payment->set_gateway_response($message);
323
+				$payment->set_txn_id_chq_nmbr(isset($PayPalResult['TRANSACTIONID'])
324
+					? $PayPalResult['TRANSACTIONID']
325
+					: null);
326
+				$primary_registration_code = $primary_registrant instanceof EE_Registration
327
+					? $primary_registrant->reg_code()
328
+					: '';
329
+				$payment->set_extra_accntng($primary_registration_code);
330
+				$payment->set_details($PayPalResult);
331
+			}
332
+		} catch (Exception $e) {
333
+			$payment->set_status($this->_pay_model->failed_status());
334
+			$payment->set_gateway_response($e->getMessage());
335
+		}
336
+		// $payment->set_status( $this->_pay_model->declined_status() );
337
+		// $payment->set_gateway_response( '' );
338
+		return $payment;
339
+	}
340
+
341
+
342
+
343
+	/**
344
+	 * CLeans out sensitive CC data and then logs it, and returns the cleaned request
345
+	 *
346
+	 * @param array       $request
347
+	 * @param EEI_Payment $payment
348
+	 * @return void
349
+	 */
350
+	private function _log_clean_request($request, $payment)
351
+	{
352
+		$cleaned_request_data = $request;
353
+		unset($cleaned_request_data['CCDetails']['acct']);
354
+		unset($cleaned_request_data['CCDetails']['cvv2']);
355
+		unset($cleaned_request_data['CCDetails']['expdate']);
356
+		$this->log(array('Paypal Request' => $cleaned_request_data), $payment);
357
+	}
358
+
359
+
360
+
361
+	/**
362
+	 * Cleans the response, logs it, and returns it
363
+	 *
364
+	 * @param array       $response
365
+	 * @param EEI_Payment $payment
366
+	 * @return array cleaned
367
+	 */
368
+	private function _log_clean_response($response, $payment)
369
+	{
370
+		unset($response['REQUESTDATA']['CREDITCARDTYPE']);
371
+		unset($response['REQUESTDATA']['ACCT']);
372
+		unset($response['REQUESTDATA']['EXPDATE']);
373
+		unset($response['REQUESTDATA']['CVV2']);
374
+		unset($response['RAWREQUEST']);
375
+		$this->log(array('Paypal Response' => $response), $payment);
376
+		return $response;
377
+	}
378
+
379
+
380
+
381
+	/**
382
+	 * @param $DataArray
383
+	 * @return array
384
+	 */
385
+	private function prep_and_curl_request($DataArray)
386
+	{
387
+		// Create empty holders for each portion of the NVP string
388
+		$DPFieldsNVP = '&METHOD=DoDirectPayment&BUTTONSOURCE=AngellEYE_PHP_Class_DDP';
389
+		$CCDetailsNVP = '';
390
+		$PayerInfoNVP = '';
391
+		$PayerNameNVP = '';
392
+		$BillingAddressNVP = '';
393
+		$ShippingAddressNVP = '';
394
+		$PaymentDetailsNVP = '';
395
+		$OrderItemsNVP = '';
396
+		$Secure3DNVP = '';
397
+		// DP Fields
398
+		$DPFields = isset($DataArray['DPFields']) ? $DataArray['DPFields'] : array();
399
+		foreach ($DPFields as $DPFieldsVar => $DPFieldsVal) {
400
+			$DPFieldsNVP .= '&' . strtoupper($DPFieldsVar) . '=' . urlencode($DPFieldsVal);
401
+		}
402
+		// CC Details Fields
403
+		$CCDetails = isset($DataArray['CCDetails']) ? $DataArray['CCDetails'] : array();
404
+		foreach ($CCDetails as $CCDetailsVar => $CCDetailsVal) {
405
+			$CCDetailsNVP .= '&' . strtoupper($CCDetailsVar) . '=' . urlencode($CCDetailsVal);
406
+		}
407
+		// PayerInfo Type Fields
408
+		$PayerInfo = isset($DataArray['PayerInfo']) ? $DataArray['PayerInfo'] : array();
409
+		foreach ($PayerInfo as $PayerInfoVar => $PayerInfoVal) {
410
+			$PayerInfoNVP .= '&' . strtoupper($PayerInfoVar) . '=' . urlencode($PayerInfoVal);
411
+		}
412
+		// Payer Name Fields
413
+		$PayerName = isset($DataArray['PayerName']) ? $DataArray['PayerName'] : array();
414
+		foreach ($PayerName as $PayerNameVar => $PayerNameVal) {
415
+			$PayerNameNVP .= '&' . strtoupper($PayerNameVar) . '=' . urlencode($PayerNameVal);
416
+		}
417
+		// Address Fields (Billing)
418
+		$BillingAddress = isset($DataArray['BillingAddress']) ? $DataArray['BillingAddress'] : array();
419
+		foreach ($BillingAddress as $BillingAddressVar => $BillingAddressVal) {
420
+			$BillingAddressNVP .= '&' . strtoupper($BillingAddressVar) . '=' . urlencode($BillingAddressVal);
421
+		}
422
+		// Payment Details Type Fields
423
+		$PaymentDetails = isset($DataArray['PaymentDetails']) ? $DataArray['PaymentDetails'] : array();
424
+		foreach ($PaymentDetails as $PaymentDetailsVar => $PaymentDetailsVal) {
425
+			$PaymentDetailsNVP .= '&' . strtoupper($PaymentDetailsVar) . '=' . urlencode($PaymentDetailsVal);
426
+		}
427
+		// Payment Details Item Type Fields
428
+		$OrderItems = isset($DataArray['OrderItems']) ? $DataArray['OrderItems'] : array();
429
+		$n = 0;
430
+		foreach ($OrderItems as $OrderItemsVar => $OrderItemsVal) {
431
+			$CurrentItem = $OrderItems[ $OrderItemsVar ];
432
+			foreach ($CurrentItem as $CurrentItemVar => $CurrentItemVal) {
433
+				$OrderItemsNVP .= '&' . strtoupper($CurrentItemVar) . $n . '=' . urlencode($CurrentItemVal);
434
+			}
435
+			$n++;
436
+		}
437
+		// Ship To Address Fields
438
+		$ShippingAddress = isset($DataArray['ShippingAddress']) ? $DataArray['ShippingAddress'] : array();
439
+		foreach ($ShippingAddress as $ShippingAddressVar => $ShippingAddressVal) {
440
+			$ShippingAddressNVP .= '&' . strtoupper($ShippingAddressVar) . '=' . urlencode($ShippingAddressVal);
441
+		}
442
+		// 3D Secure Fields
443
+		$Secure3D = isset($DataArray['Secure3D']) ? $DataArray['Secure3D'] : array();
444
+		foreach ($Secure3D as $Secure3DVar => $Secure3DVal) {
445
+			$Secure3DNVP .= '&' . strtoupper($Secure3DVar) . '=' . urlencode($Secure3DVal);
446
+		}
447
+		// Now that we have each chunk we need to go ahead and append them all together for our entire NVP string
448
+		$NVPRequest = 'USER='
449
+					  . $this->_username
450
+					  . '&PWD='
451
+					  . $this->_password
452
+					  . '&VERSION=64.0'
453
+					  . '&SIGNATURE='
454
+					  . $this->_signature
455
+					  . $DPFieldsNVP
456
+					  . $CCDetailsNVP
457
+					  . $PayerInfoNVP
458
+					  . $PayerNameNVP
459
+					  . $BillingAddressNVP
460
+					  . $PaymentDetailsNVP
461
+					  . $OrderItemsNVP
462
+					  . $ShippingAddressNVP
463
+					  . $Secure3DNVP;
464
+		$NVPResponse = $this->_CURLRequest($NVPRequest);
465
+		$NVPRequestArray = $this->_NVPToArray($NVPRequest);
466
+		$NVPResponseArray = $this->_NVPToArray($NVPResponse);
467
+		$Errors = $this->_GetErrors($NVPResponseArray);
468
+		$NVPResponseArray['ERRORS'] = $Errors;
469
+		$NVPResponseArray['REQUESTDATA'] = $NVPRequestArray;
470
+		$NVPResponseArray['RAWREQUEST'] = $NVPRequest;
471
+		$NVPResponseArray['RAWRESPONSE'] = $NVPResponse;
472
+		return $NVPResponseArray;
473
+	}
474
+
475
+
476
+
477
+	/**
478
+	 * @param $Request
479
+	 * @return mixed
480
+	 */
481
+	private function _CURLRequest($Request)
482
+	{
483
+		$EndPointURL = $this->_debug_mode ? 'https://api-3t.sandbox.paypal.com/nvp' : 'https://api-3t.paypal.com/nvp';
484
+		$curl = curl_init();
485
+		curl_setopt($curl, CURLOPT_VERBOSE, apply_filters('FHEE__EEG_Paypal_Pro__CurlRequest__CURLOPT_VERBOSE', true));
486
+		curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
487
+		curl_setopt($curl, CURLOPT_TIMEOUT, 60);
488
+		curl_setopt($curl, CURLOPT_URL, $EndPointURL);
489
+		curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
490
+		curl_setopt($curl, CURLOPT_POSTFIELDS, $Request);
491
+		curl_setopt($curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
492
+		// execute the curl POST
493
+		$Response = curl_exec($curl);
494
+		curl_close($curl);
495
+		return $Response;
496
+	}
497
+
498
+
499
+
500
+	/**
501
+	 * @param $NVPString
502
+	 * @return array
503
+	 */
504
+	private function _NVPToArray($NVPString)
505
+	{
506
+		// prepare responses into array
507
+		$proArray = array();
508
+		while (strlen($NVPString)) {
509
+			// name
510
+			$keypos = strpos($NVPString, '=');
511
+			$keyval = substr($NVPString, 0, $keypos);
512
+			// value
513
+			$valuepos = strpos($NVPString, '&') ? strpos($NVPString, '&') : strlen($NVPString);
514
+			$valval = substr($NVPString, $keypos + 1, $valuepos - $keypos - 1);
515
+			// decoding the response
516
+			$proArray[ $keyval ] = urldecode($valval);
517
+			$NVPString = substr($NVPString, $valuepos + 1, strlen($NVPString));
518
+		}
519
+		return $proArray;
520
+	}
521
+
522
+
523
+
524
+	/**
525
+	 * @param array $PayPalResult
526
+	 * @return bool
527
+	 */
528
+	private function _APICallSuccessful($PayPalResult)
529
+	{
530
+		$approved = false;
531
+		// check main response message from PayPal
532
+		if (isset($PayPalResult['ACK']) && ! empty($PayPalResult['ACK'])) {
533
+			$ack = strtoupper($PayPalResult['ACK']);
534
+			$approved = ($ack == 'SUCCESS' || $ack == 'SUCCESSWITHWARNING' || $ack == 'PARTIALSUCCESS') ? true : false;
535
+		}
536
+		return $approved;
537
+	}
538
+
539
+
540
+
541
+	/**
542
+	 * @param $DataArray
543
+	 * @return array
544
+	 */
545
+	private function _GetErrors($DataArray)
546
+	{
547
+		$Errors = array();
548
+		$n = 0;
549
+		while (isset($DataArray[ 'L_ERRORCODE' . $n . '' ])) {
550
+			$LErrorCode = isset($DataArray[ 'L_ERRORCODE' . $n . '' ]) ? $DataArray[ 'L_ERRORCODE' . $n . '' ] : '';
551
+			$LShortMessage = isset($DataArray[ 'L_SHORTMESSAGE' . $n . '' ])
552
+				? $DataArray[ 'L_SHORTMESSAGE' . $n . '' ]
553
+				: '';
554
+			$LLongMessage = isset($DataArray[ 'L_LONGMESSAGE' . $n . '' ])
555
+				? $DataArray[ 'L_LONGMESSAGE' . $n . '' ]
556
+				: '';
557
+			$LSeverityCode = isset($DataArray[ 'L_SEVERITYCODE' . $n . '' ])
558
+				? $DataArray[ 'L_SEVERITYCODE' . $n . '' ]
559
+				: '';
560
+			$CurrentItem = array(
561
+				'L_ERRORCODE'    => $LErrorCode,
562
+				'L_SHORTMESSAGE' => $LShortMessage,
563
+				'L_LONGMESSAGE'  => $LLongMessage,
564
+				'L_SEVERITYCODE' => $LSeverityCode,
565
+			);
566
+			array_push($Errors, $CurrentItem);
567
+			$n++;
568
+		}
569
+		return $Errors;
570
+	}
571
+
572
+
573
+
574
+	/**
575
+	 *        nothing to see here...  move along....
576
+	 *
577
+	 * @access protected
578
+	 * @param $Errors
579
+	 * @return string
580
+	 */
581
+	private function _DisplayErrors($Errors)
582
+	{
583
+		$error = '';
584
+		foreach ($Errors as $ErrorVar => $ErrorVal) {
585
+			$CurrentError = $Errors[ $ErrorVar ];
586
+			foreach ($CurrentError as $CurrentErrorVar => $CurrentErrorVal) {
587
+				$CurrentVarName = '';
588
+				if ($CurrentErrorVar == 'L_ERRORCODE') {
589
+					$CurrentVarName = 'Error Code';
590
+				} elseif ($CurrentErrorVar == 'L_SHORTMESSAGE') {
591
+					$CurrentVarName = 'Short Message';
592
+				} elseif ($CurrentErrorVar == 'L_LONGMESSAGE') {
593
+					$CurrentVarName = 'Long Message';
594
+				} elseif ($CurrentErrorVar == 'L_SEVERITYCODE') {
595
+					$CurrentVarName = 'Severity Code';
596
+				}
597
+				$error .= '<br />' . $CurrentVarName . ': ' . $CurrentErrorVal;
598
+			}
599
+		}
600
+		return $error;
601
+	}
602 602
 }
Please login to merge, or discard this patch.
payment_methods/Paypal_Express/EEG_Paypal_Express.gateway.php 1 patch
Indentation   +668 added lines, -668 removed lines patch added patch discarded remove patch
@@ -11,676 +11,676 @@
 block discarded – undo
11 11
  */
12 12
 // Quickfix to address https://events.codebasehq.com/projects/event-espresso/tickets/11089 ASAP
13 13
 if (! function_exists('mb_strcut')) {
14
-    /**
15
-     * Very simple mimic of mb_substr (which WP ensures exists in wp-includes/compat.php). Still has all the problems of mb_substr
16
-     * (namely, that we might send too many characters to PayPal; however in this case they just issue a warning but nothing breaks)
17
-     * @param $string
18
-     * @param $start
19
-     * @param $length
20
-     * @return bool|string
21
-     */
22
-    function mb_strcut($string, $start, $length = null)
23
-    {
24
-        return mb_substr($string, $start, $length);
25
-    }
14
+	/**
15
+	 * Very simple mimic of mb_substr (which WP ensures exists in wp-includes/compat.php). Still has all the problems of mb_substr
16
+	 * (namely, that we might send too many characters to PayPal; however in this case they just issue a warning but nothing breaks)
17
+	 * @param $string
18
+	 * @param $start
19
+	 * @param $length
20
+	 * @return bool|string
21
+	 */
22
+	function mb_strcut($string, $start, $length = null)
23
+	{
24
+		return mb_substr($string, $start, $length);
25
+	}
26 26
 }
27 27
 class EEG_Paypal_Express extends EE_Offsite_Gateway
28 28
 {
29 29
 
30
-    /**
31
-     * Merchant API Username.
32
-     *
33
-     * @var string
34
-     */
35
-    protected $_api_username;
36
-
37
-    /**
38
-     * Merchant API Password.
39
-     *
40
-     * @var string
41
-     */
42
-    protected $_api_password;
43
-
44
-    /**
45
-     * API Signature.
46
-     *
47
-     * @var string
48
-     */
49
-    protected $_api_signature;
50
-
51
-    /**
52
-     * Request Shipping address on PP checkout page.
53
-     *
54
-     * @var string
55
-     */
56
-    protected $_request_shipping_addr;
57
-
58
-    /**
59
-     * Business/personal logo.
60
-     *
61
-     * @var string
62
-     */
63
-    protected $_image_url;
64
-
65
-    /**
66
-     * gateway URL variable
67
-     *
68
-     * @var string
69
-     */
70
-    protected $_base_gateway_url = '';
71
-
72
-
73
-
74
-    /**
75
-     * EEG_Paypal_Express constructor.
76
-     */
77
-    public function __construct()
78
-    {
79
-        $this->_currencies_supported = array(
80
-            'USD',
81
-            'AUD',
82
-            'BRL',
83
-            'CAD',
84
-            'CZK',
85
-            'DKK',
86
-            'EUR',
87
-            'HKD',
88
-            'HUF',
89
-            'ILS',
90
-            'JPY',
91
-            'MYR',
92
-            'MXN',
93
-            'NOK',
94
-            'NZD',
95
-            'PHP',
96
-            'PLN',
97
-            'GBP',
98
-            'RUB',
99
-            'SGD',
100
-            'SEK',
101
-            'CHF',
102
-            'TWD',
103
-            'THB',
104
-            'TRY',
105
-            'INR',
106
-        );
107
-        parent::__construct();
108
-    }
109
-
110
-
111
-
112
-    /**
113
-     * Sets the gateway URL variable based on whether debug mode is enabled or not.
114
-     *
115
-     * @param array $settings_array
116
-     */
117
-    public function set_settings($settings_array)
118
-    {
119
-        parent::set_settings($settings_array);
120
-        // Redirect URL.
121
-        $this->_base_gateway_url = $this->_debug_mode
122
-            ? 'https://api-3t.sandbox.paypal.com/nvp'
123
-            : 'https://api-3t.paypal.com/nvp';
124
-    }
125
-
126
-
127
-
128
-    /**
129
-     * @param EEI_Payment $payment
130
-     * @param array       $billing_info
131
-     * @param string      $return_url
132
-     * @param string      $notify_url
133
-     * @param string      $cancel_url
134
-     * @return \EE_Payment|\EEI_Payment
135
-     * @throws \EE_Error
136
-     */
137
-    public function set_redirection_info(
138
-        $payment,
139
-        $billing_info = array(),
140
-        $return_url = null,
141
-        $notify_url = null,
142
-        $cancel_url = null
143
-    ) {
144
-        if (! $payment instanceof EEI_Payment) {
145
-            $payment->set_gateway_response(
146
-                esc_html__(
147
-                    'Error. No associated payment was found.',
148
-                    'event_espresso'
149
-                )
150
-            );
151
-            $payment->set_status($this->_pay_model->failed_status());
152
-            return $payment;
153
-        }
154
-        $transaction = $payment->transaction();
155
-        if (! $transaction instanceof EEI_Transaction) {
156
-            $payment->set_gateway_response(
157
-                esc_html__(
158
-                    'Could not process this payment because it has no associated transaction.',
159
-                    'event_espresso'
160
-                )
161
-            );
162
-            $payment->set_status($this->_pay_model->failed_status());
163
-            return $payment;
164
-        }
165
-        $gateway_formatter = $this->_get_gateway_formatter();
166
-        $order_description = mb_strcut($gateway_formatter->formatOrderDescription($payment), 0, 127);
167
-        $primary_registration = $transaction->primary_registration();
168
-        $primary_attendee = $primary_registration instanceof EE_Registration
169
-            ? $primary_registration->attendee()
170
-            : false;
171
-        $locale = explode('-', get_bloginfo('language'));
172
-        // Gather request parameters.
173
-        $token_request_dtls = array(
174
-            'METHOD'                         => 'SetExpressCheckout',
175
-            'PAYMENTREQUEST_0_AMT'           => $payment->amount(),
176
-            'PAYMENTREQUEST_0_CURRENCYCODE'  => $payment->currency_code(),
177
-            'PAYMENTREQUEST_0_DESC'          => $order_description,
178
-            'RETURNURL'                      => $return_url,
179
-            'CANCELURL'                      => $cancel_url,
180
-            'PAYMENTREQUEST_0_PAYMENTACTION' => 'Sale',
181
-            // Buyer does not need to create a PayPal account to check out.
182
-            // This is referred to as PayPal Account Optional.
183
-            'SOLUTIONTYPE'                   => 'Sole',
184
-            // EE will blow up if you change this
185
-            'BUTTONSOURCE'                   => 'EventEspresso_SP',
186
-            // Locale of the pages displayed by PayPal during Express Checkout.
187
-            'LOCALECODE'                     => $locale[1]
188
-        );
189
-        // Show itemized list.
190
-        $itemized_list = $this->itemize_list($payment, $transaction);
191
-        $token_request_dtls = array_merge($token_request_dtls, $itemized_list);
192
-        // Automatically filling out shipping and contact information.
193
-        if ($this->_request_shipping_addr && $primary_attendee instanceof EEI_Attendee) {
194
-            // If you do not pass the shipping address, PayPal obtains it from the buyer's account profile.
195
-            $token_request_dtls['NOSHIPPING'] = '2';
196
-            $token_request_dtls['PAYMENTREQUEST_0_SHIPTOSTREET'] = $primary_attendee->address();
197
-            $token_request_dtls['PAYMENTREQUEST_0_SHIPTOSTREET2'] = $primary_attendee->address2();
198
-            $token_request_dtls['PAYMENTREQUEST_0_SHIPTOCITY'] = $primary_attendee->city();
199
-            $token_request_dtls['PAYMENTREQUEST_0_SHIPTOSTATE'] = $primary_attendee->state_abbrev();
200
-            $token_request_dtls['PAYMENTREQUEST_0_SHIPTOCOUNTRYCODE'] = $primary_attendee->country_ID();
201
-            $token_request_dtls['PAYMENTREQUEST_0_SHIPTOZIP'] = $primary_attendee->zip();
202
-            $token_request_dtls['PAYMENTREQUEST_0_EMAIL'] = $primary_attendee->email();
203
-            $token_request_dtls['PAYMENTREQUEST_0_SHIPTOPHONENUM'] = $primary_attendee->phone();
204
-        } elseif (! $this->_request_shipping_addr) {
205
-            // Do not request shipping details on the PP Checkout page.
206
-            $token_request_dtls['NOSHIPPING'] = '1';
207
-            $token_request_dtls['REQCONFIRMSHIPPING'] = '0';
208
-        }
209
-        // Used a business/personal logo on the PayPal page.
210
-        if (! empty($this->_image_url)) {
211
-            $token_request_dtls['LOGOIMG'] = $this->_image_url;
212
-        }
213
-        $token_request_dtls = apply_filters(
214
-            'FHEE__EEG_Paypal_Express__set_redirection_info__arguments',
215
-            $token_request_dtls,
216
-            $this
217
-        );
218
-        // Request PayPal token.
219
-        $token_request_response = $this->_ppExpress_request($token_request_dtls, 'Payment Token', $payment);
220
-        $token_rstatus = $this->_ppExpress_check_response($token_request_response);
221
-        $response_args = (isset($token_rstatus['args']) && is_array($token_rstatus['args']))
222
-            ? $token_rstatus['args']
223
-            : array();
224
-        if ($token_rstatus['status']) {
225
-            // We got the Token so we may continue with the payment and redirect the client.
226
-            $payment->set_details($response_args);
227
-            $gateway_url = $this->_debug_mode ? 'https://www.sandbox.paypal.com' : 'https://www.paypal.com';
228
-            $payment->set_redirect_url(
229
-                $gateway_url
230
-                . '/checkoutnow?useraction=commit&cmd=_express-checkout&token='
231
-                . $response_args['TOKEN']
232
-            );
233
-        } else {
234
-            if (isset($response_args['L_ERRORCODE'])) {
235
-                $payment->set_gateway_response($response_args['L_ERRORCODE'] . '; ' . $response_args['L_SHORTMESSAGE']);
236
-            } else {
237
-                $payment->set_gateway_response(
238
-                    esc_html__(
239
-                        'Error occurred while trying to setup the Express Checkout.',
240
-                        'event_espresso'
241
-                    )
242
-                );
243
-            }
244
-            $payment->set_details($response_args);
245
-            $payment->set_status($this->_pay_model->failed_status());
246
-        }
247
-        return $payment;
248
-    }
249
-
250
-
251
-
252
-    /**
253
-     * @param array           $update_info {
254
-     * @type string           $gateway_txn_id
255
-     * @type string status an EEMI_Payment status
256
-     *                                     }
257
-     * @param EEI_Transaction $transaction
258
-     * @return EEI_Payment
259
-     */
260
-    public function handle_payment_update($update_info, $transaction)
261
-    {
262
-        $payment = $transaction instanceof EEI_Transaction ? $transaction->last_payment() : null;
263
-        if ($payment instanceof EEI_Payment) {
264
-            $this->log(array('Return from Authorization' => $update_info), $payment);
265
-            $transaction = $payment->transaction();
266
-            if (! $transaction instanceof EEI_Transaction) {
267
-                $payment->set_gateway_response(
268
-                    esc_html__(
269
-                        'Could not process this payment because it has no associated transaction.',
270
-                        'event_espresso'
271
-                    )
272
-                );
273
-                $payment->set_status($this->_pay_model->failed_status());
274
-                return $payment;
275
-            }
276
-            $primary_registrant = $transaction->primary_registration();
277
-            $payment_details = $payment->details();
278
-            // Check if we still have the token.
279
-            if (! isset($payment_details['TOKEN']) || empty($payment_details['TOKEN'])) {
280
-                $payment->set_status($this->_pay_model->failed_status());
281
-                return $payment;
282
-            }
283
-            $cdetails_request_dtls = array(
284
-                'METHOD' => 'GetExpressCheckoutDetails',
285
-                'TOKEN'  => $payment_details['TOKEN'],
286
-            );
287
-            // Request Customer Details.
288
-            $cdetails_request_response = $this->_ppExpress_request(
289
-                $cdetails_request_dtls,
290
-                'Customer Details',
291
-                $payment
292
-            );
293
-            $cdetails_rstatus = $this->_ppExpress_check_response($cdetails_request_response);
294
-            $cdata_response_args = (isset($cdetails_rstatus['args']) && is_array($cdetails_rstatus['args']))
295
-                ? $cdetails_rstatus['args']
296
-                : array();
297
-            if ($cdetails_rstatus['status']) {
298
-                // We got the PayerID so now we can Complete the transaction.
299
-                $docheckout_request_dtls = array(
300
-                    'METHOD'                         => 'DoExpressCheckoutPayment',
301
-                    'PAYERID'                        => $cdata_response_args['PAYERID'],
302
-                    'TOKEN'                          => $payment_details['TOKEN'],
303
-                    'PAYMENTREQUEST_0_PAYMENTACTION' => 'Sale',
304
-                    'PAYMENTREQUEST_0_AMT'           => $payment->amount(),
305
-                    'PAYMENTREQUEST_0_CURRENCYCODE'  => $payment->currency_code(),
306
-                    // EE will blow up if you change this
307
-                    'BUTTONSOURCE'                   => 'EventEspresso_SP',
308
-                );
309
-                 // Include itemized list.
310
-                $itemized_list = $this->itemize_list(
311
-                    $payment,
312
-                    $transaction,
313
-                    $cdata_response_args
314
-                );
315
-                $docheckout_request_dtls = array_merge($docheckout_request_dtls, $itemized_list);
316
-                // Payment Checkout/Capture.
317
-                $docheckout_request_response = $this->_ppExpress_request(
318
-                    $docheckout_request_dtls,
319
-                    'Do Payment',
320
-                    $payment
321
-                );
322
-                $docheckout_rstatus = $this->_ppExpress_check_response($docheckout_request_response);
323
-                $docheckout_response_args = (isset($docheckout_rstatus['args']) && is_array($docheckout_rstatus['args']))
324
-                    ? $docheckout_rstatus['args']
325
-                    : array();
326
-                if ($docheckout_rstatus['status']) {
327
-                    // All is well, payment approved.
328
-                    $primary_registration_code = $primary_registrant instanceof EE_Registration ?
329
-                        $primary_registrant->reg_code()
330
-                        : '';
331
-                    $payment->set_extra_accntng($primary_registration_code);
332
-                    $payment->set_amount(isset($docheckout_response_args['PAYMENTINFO_0_AMT'])
333
-                        ? (float) $docheckout_response_args['PAYMENTINFO_0_AMT']
334
-                        : 0);
335
-                    $payment->set_txn_id_chq_nmbr(isset($docheckout_response_args['PAYMENTINFO_0_TRANSACTIONID'])
336
-                        ? $docheckout_response_args['PAYMENTINFO_0_TRANSACTIONID']
337
-                        : null);
338
-                    $payment->set_details($cdata_response_args);
339
-                    $payment->set_gateway_response(isset($docheckout_response_args['PAYMENTINFO_0_ACK'])
340
-                        ? $docheckout_response_args['PAYMENTINFO_0_ACK']
341
-                        : '');
342
-                    $payment->set_status($this->_pay_model->approved_status());
343
-                } else {
344
-                    if (isset($docheckout_response_args['L_ERRORCODE'])) {
345
-                        $payment->set_gateway_response(
346
-                            $docheckout_response_args['L_ERRORCODE']
347
-                            . '; '
348
-                            . $docheckout_response_args['L_SHORTMESSAGE']
349
-                        );
350
-                    } else {
351
-                        $payment->set_gateway_response(
352
-                            esc_html__(
353
-                                'Error occurred while trying to Capture the funds.',
354
-                                'event_espresso'
355
-                            )
356
-                        );
357
-                    }
358
-                    $payment->set_details($docheckout_response_args);
359
-                    $payment->set_status($this->_pay_model->declined_status());
360
-                }
361
-            } else {
362
-                if (isset($cdata_response_args['L_ERRORCODE'])) {
363
-                    $payment->set_gateway_response(
364
-                        $cdata_response_args['L_ERRORCODE']
365
-                        . '; '
366
-                        . $cdata_response_args['L_SHORTMESSAGE']
367
-                    );
368
-                } else {
369
-                    $payment->set_gateway_response(
370
-                        esc_html__(
371
-                            'Error occurred while trying to get payment Details from PayPal.',
372
-                            'event_espresso'
373
-                        )
374
-                    );
375
-                }
376
-                $payment->set_details($cdata_response_args);
377
-                $payment->set_status($this->_pay_model->failed_status());
378
-            }
379
-        } else {
380
-            $payment->set_gateway_response(
381
-                esc_html__(
382
-                    'Error occurred while trying to process the payment.',
383
-                    'event_espresso'
384
-                )
385
-            );
386
-            $payment->set_status($this->_pay_model->failed_status());
387
-        }
388
-        return $payment;
389
-    }
390
-
391
-
392
-
393
-    /**
394
-     *  Make a list of items that are in the giver transaction.
395
-     *
396
-     * @param EEI_Payment     $payment
397
-     * @param EEI_Transaction $transaction
398
-     * @param array           $request_response_args Data from a previous communication with PP.
399
-     * @return array
400
-     */
401
-    public function itemize_list(EEI_Payment $payment, EEI_Transaction $transaction, $request_response_args = array())
402
-    {
403
-        $itemized_list = array();
404
-        $gateway_formatter = $this->_get_gateway_formatter();
405
-        // If we have data from a previous communication with PP (on this transaction) we may use that for our list...
406
-        if (! empty($request_response_args)
407
-            && array_key_exists('L_PAYMENTREQUEST_0_AMT0', $request_response_args)
408
-            && array_key_exists('PAYMENTREQUEST_0_ITEMAMT', $request_response_args)
409
-        ) {
410
-            foreach ($request_response_args as $arg_key => $arg_val) {
411
-                if (strpos($arg_key, 'PAYMENTREQUEST_') !== false
412
-                    && strpos($arg_key, 'NOTIFYURL') === false
413
-                ) {
414
-                    $itemized_list[ $arg_key ] = $arg_val;
415
-                }
416
-            }
417
-            // If we got only a few Items then something is not right.
418
-            if (count($itemized_list) > 2) {
419
-                return $itemized_list;
420
-            } else {
421
-                if (WP_DEBUG) {
422
-                    throw new EE_Error(
423
-                        sprintf(
424
-                            esc_html__(
425
-                                // @codingStandardsIgnoreStart
426
-                                'Unable to continue with the checkout because a proper purchase list could not be generated. The purchased list we could have sent was %1$s',
427
-                                // @codingStandardsIgnoreEnd
428
-                                'event_espresso'
429
-                            ),
430
-                            wp_json_encode($itemized_list)
431
-                        )
432
-                    );
433
-                }
434
-                // Reset the list and log an error, maybe allow to try and generate a new list (below).
435
-                $itemized_list = array();
436
-                $this->log(
437
-                    array(
438
-                        esc_html__(
439
-                            'Could not generate a proper item list with:',
440
-                            'event_espresso'
441
-                        ) => $request_response_args
442
-                    ),
443
-                    $payment
444
-                );
445
-            }
446
-        }
447
-        // ...otherwise we generate a new list for this transaction.
448
-        if ($this->_money->compare_floats($payment->amount(), $transaction->total(), '==')) {
449
-            $item_num = 0;
450
-            $itemized_sum = 0;
451
-            $total_line_items = $transaction->total_line_item();
452
-            // Go through each item in the list.
453
-            foreach ($total_line_items->get_items() as $line_item) {
454
-                if ($line_item instanceof EE_Line_Item) {
455
-                    // PayPal doesn't like line items with 0.00 amount, so we may skip those.
456
-                    if (EEH_Money::compare_floats($line_item->total(), '0.00', '==')) {
457
-                        continue;
458
-                    }
459
-                    $unit_price = $line_item->unit_price();
460
-                    $line_item_quantity = $line_item->quantity();
461
-                    // This is a discount.
462
-                    if ($line_item->is_percent()) {
463
-                        $unit_price = $line_item->total();
464
-                        $line_item_quantity = 1;
465
-                    }
466
-                    // Item Name.
467
-                    $itemized_list[ 'L_PAYMENTREQUEST_0_NAME' . $item_num ] = mb_strcut(
468
-                        $gateway_formatter->formatLineItemName($line_item, $payment),
469
-                        0,
470
-                        127
471
-                    );
472
-                    // Item description.
473
-                    $itemized_list[ 'L_PAYMENTREQUEST_0_DESC' . $item_num ] = mb_strcut(
474
-                        $gateway_formatter->formatLineItemDesc($line_item, $payment),
475
-                        0,
476
-                        127
477
-                    );
478
-                    // Cost of individual item.
479
-                    $itemized_list[ 'L_PAYMENTREQUEST_0_AMT' . $item_num ] = $gateway_formatter->formatCurrency($unit_price);
480
-                    // Item Number.
481
-                    $itemized_list[ 'L_PAYMENTREQUEST_0_NUMBER' . $item_num ] = $item_num + 1;
482
-                    // Item quantity.
483
-                    $itemized_list[ 'L_PAYMENTREQUEST_0_QTY' . $item_num ] = $line_item_quantity;
484
-                    // Digital item is sold.
485
-                    $itemized_list[ 'L_PAYMENTREQUEST_0_ITEMCATEGORY' . $item_num ] = 'Physical';
486
-                    $itemized_sum += $line_item->total();
487
-                    ++$item_num;
488
-                }
489
-            }
490
-            // Item's sales S/H and tax amount.
491
-            $itemized_list['PAYMENTREQUEST_0_ITEMAMT'] = $total_line_items->get_items_total();
492
-            $itemized_list['PAYMENTREQUEST_0_TAXAMT'] = $total_line_items->get_total_tax();
493
-            $itemized_list['PAYMENTREQUEST_0_SHIPPINGAMT'] = '0';
494
-            $itemized_list['PAYMENTREQUEST_0_HANDLINGAMT'] = '0';
495
-            $itemized_sum_diff_from_txn_total = round(
496
-                $transaction->total() - $itemized_sum - $total_line_items->get_total_tax(),
497
-                2
498
-            );
499
-            // If we were not able to recognize some item like promotion, surcharge or cancellation,
500
-            // add the difference as an extra line item.
501
-            if ($this->_money->compare_floats($itemized_sum_diff_from_txn_total, 0, '!=')) {
502
-                // Item Name.
503
-                $itemized_list[ 'L_PAYMENTREQUEST_0_NAME' . $item_num ] = mb_strcut(
504
-                    esc_html__(
505
-                        'Other (promotion/surcharge/cancellation)',
506
-                        'event_espresso'
507
-                    ),
508
-                    0,
509
-                    127
510
-                );
511
-                // Item description.
512
-                $itemized_list[ 'L_PAYMENTREQUEST_0_DESC' . $item_num ] = '';
513
-                // Cost of individual item.
514
-                $itemized_list[ 'L_PAYMENTREQUEST_0_AMT' . $item_num ] = $gateway_formatter->formatCurrency(
515
-                    $itemized_sum_diff_from_txn_total
516
-                );
517
-                // Item Number.
518
-                $itemized_list[ 'L_PAYMENTREQUEST_0_NUMBER' . $item_num ] = $item_num + 1;
519
-                // Item quantity.
520
-                $itemized_list[ 'L_PAYMENTREQUEST_0_QTY' . $item_num ] = 1;
521
-                // Digital item is sold.
522
-                $itemized_list[ 'L_PAYMENTREQUEST_0_ITEMCATEGORY' . $item_num ] = 'Physical';
523
-                $item_num++;
524
-            }
525
-        } else {
526
-            // Just one Item.
527
-            // Item Name.
528
-            $itemized_list['L_PAYMENTREQUEST_0_NAME0'] = mb_strcut(
529
-                $gateway_formatter->formatPartialPaymentLineItemName($payment),
530
-                0,
531
-                127
532
-            );
533
-            // Item description.
534
-            $itemized_list['L_PAYMENTREQUEST_0_DESC0'] = mb_strcut(
535
-                $gateway_formatter->formatPartialPaymentLineItemDesc($payment),
536
-                0,
537
-                127
538
-            );
539
-            // Cost of individual item.
540
-            $itemized_list['L_PAYMENTREQUEST_0_AMT0'] = $gateway_formatter->formatCurrency($payment->amount());
541
-            // Item Number.
542
-            $itemized_list['L_PAYMENTREQUEST_0_NUMBER0'] = 1;
543
-            // Item quantity.
544
-            $itemized_list['L_PAYMENTREQUEST_0_QTY0'] = 1;
545
-            // Digital item is sold.
546
-            $itemized_list['L_PAYMENTREQUEST_0_ITEMCATEGORY0'] = 'Physical';
547
-            // Item's sales S/H and tax amount.
548
-            $itemized_list['PAYMENTREQUEST_0_ITEMAMT'] = $gateway_formatter->formatCurrency($payment->amount());
549
-            $itemized_list['PAYMENTREQUEST_0_TAXAMT'] = '0';
550
-            $itemized_list['PAYMENTREQUEST_0_SHIPPINGAMT'] = '0';
551
-            $itemized_list['PAYMENTREQUEST_0_HANDLINGAMT'] = '0';
552
-        }
553
-        return $itemized_list;
554
-    }
555
-
556
-
557
-
558
-    /**
559
-     *  Make the Express checkout request.
560
-     *
561
-     * @param array       $request_params
562
-     * @param string      $request_text
563
-     * @param EEI_Payment $payment
564
-     * @return mixed
565
-     */
566
-    public function _ppExpress_request($request_params, $request_text, $payment)
567
-    {
568
-        $request_dtls = array(
569
-            'VERSION'   => '204.0',
570
-            'USER'      => urlencode($this->_api_username),
571
-            'PWD'       => urlencode($this->_api_password),
572
-            'SIGNATURE' => urlencode($this->_api_signature),
573
-        );
574
-        $dtls = array_merge($request_dtls, $request_params);
575
-        $this->_log_clean_request($dtls, $payment, $request_text . ' Request');
576
-        // Request Customer Details.
577
-        $request_response = wp_remote_post(
578
-            $this->_base_gateway_url,
579
-            array(
580
-                'method'      => 'POST',
581
-                'timeout'     => 45,
582
-                'httpversion' => '1.1',
583
-                'cookies'     => array(),
584
-                'headers'     => array(),
585
-                'body'        => http_build_query($dtls, '', '&'),
586
-            )
587
-        );
588
-        // Log the response.
589
-        $this->log(array($request_text . ' Response' => $request_response), $payment);
590
-        return $request_response;
591
-    }
592
-
593
-
594
-
595
-    /**
596
-     *  Check the response status.
597
-     *
598
-     * @param mixed $request_response
599
-     * @return array
600
-     */
601
-    public function _ppExpress_check_response($request_response)
602
-    {
603
-        if (is_wp_error($request_response) || empty($request_response['body'])) {
604
-            // If we got here then there was an error in this request.
605
-            return array('status' => false, 'args' => $request_response);
606
-        }
607
-        $response_args = array();
608
-        parse_str(urldecode($request_response['body']), $response_args);
609
-        if (! isset($response_args['ACK'])) {
610
-            return array('status' => false, 'args' => $request_response);
611
-        }
612
-        if ((
613
-                isset($response_args['PAYERID'])
614
-                || isset($response_args['TOKEN'])
615
-                || isset($response_args['PAYMENTINFO_0_TRANSACTIONID'])
616
-                || (isset($response_args['PAYMENTSTATUS']) && $response_args['PAYMENTSTATUS'] === 'Completed')
617
-            )
618
-            && in_array($response_args['ACK'], array('Success', 'SuccessWithWarning'), true)
619
-        ) {
620
-            // Response status OK, return response parameters for further processing.
621
-            return array('status' => true, 'args' => $response_args);
622
-        }
623
-        $errors = $this->_get_errors($response_args);
624
-        return array('status' => false, 'args' => $errors);
625
-    }
626
-
627
-
628
-
629
-    /**
630
-     *  Log a "Cleared" request.
631
-     *
632
-     * @param array       $request
633
-     * @param EEI_Payment $payment
634
-     * @param string      $info
635
-     * @return void
636
-     */
637
-    private function _log_clean_request($request, $payment, $info)
638
-    {
639
-        $cleaned_request_data = $request;
640
-        unset($cleaned_request_data['PWD'], $cleaned_request_data['USER'], $cleaned_request_data['SIGNATURE']);
641
-        $this->log(array($info => $cleaned_request_data), $payment);
642
-    }
643
-
644
-
645
-
646
-    /**
647
-     *  Get error from the response data.
648
-     *
649
-     * @param array $data_array
650
-     * @return array
651
-     */
652
-    private function _get_errors($data_array)
653
-    {
654
-        $errors = array();
655
-        $n = 0;
656
-        while (isset($data_array[ "L_ERRORCODE{$n}" ])) {
657
-            $l_error_code = isset($data_array[ "L_ERRORCODE{$n}" ])
658
-                ? $data_array[ "L_ERRORCODE{$n}" ]
659
-                : '';
660
-            $l_severity_code = isset($data_array[ "L_SEVERITYCODE{$n}" ])
661
-                ? $data_array[ "L_SEVERITYCODE{$n}" ]
662
-                : '';
663
-            $l_short_message = isset($data_array[ "L_SHORTMESSAGE{$n}" ])
664
-                ? $data_array[ "L_SHORTMESSAGE{$n}" ]
665
-                : '';
666
-            $l_long_message = isset($data_array[ "L_LONGMESSAGE{$n}" ])
667
-                ? $data_array[ "L_LONGMESSAGE{$n}" ]
668
-                : '';
669
-            if ($n === 0) {
670
-                $errors = array(
671
-                    'L_ERRORCODE'    => $l_error_code,
672
-                    'L_SHORTMESSAGE' => $l_short_message,
673
-                    'L_LONGMESSAGE'  => $l_long_message,
674
-                    'L_SEVERITYCODE' => $l_severity_code,
675
-                );
676
-            } else {
677
-                $errors['L_ERRORCODE'] .= ', ' . $l_error_code;
678
-                $errors['L_SHORTMESSAGE'] .= ', ' . $l_short_message;
679
-                $errors['L_LONGMESSAGE'] .= ', ' . $l_long_message;
680
-                $errors['L_SEVERITYCODE'] .= ', ' . $l_severity_code;
681
-            }
682
-            $n++;
683
-        }
684
-        return $errors;
685
-    }
30
+	/**
31
+	 * Merchant API Username.
32
+	 *
33
+	 * @var string
34
+	 */
35
+	protected $_api_username;
36
+
37
+	/**
38
+	 * Merchant API Password.
39
+	 *
40
+	 * @var string
41
+	 */
42
+	protected $_api_password;
43
+
44
+	/**
45
+	 * API Signature.
46
+	 *
47
+	 * @var string
48
+	 */
49
+	protected $_api_signature;
50
+
51
+	/**
52
+	 * Request Shipping address on PP checkout page.
53
+	 *
54
+	 * @var string
55
+	 */
56
+	protected $_request_shipping_addr;
57
+
58
+	/**
59
+	 * Business/personal logo.
60
+	 *
61
+	 * @var string
62
+	 */
63
+	protected $_image_url;
64
+
65
+	/**
66
+	 * gateway URL variable
67
+	 *
68
+	 * @var string
69
+	 */
70
+	protected $_base_gateway_url = '';
71
+
72
+
73
+
74
+	/**
75
+	 * EEG_Paypal_Express constructor.
76
+	 */
77
+	public function __construct()
78
+	{
79
+		$this->_currencies_supported = array(
80
+			'USD',
81
+			'AUD',
82
+			'BRL',
83
+			'CAD',
84
+			'CZK',
85
+			'DKK',
86
+			'EUR',
87
+			'HKD',
88
+			'HUF',
89
+			'ILS',
90
+			'JPY',
91
+			'MYR',
92
+			'MXN',
93
+			'NOK',
94
+			'NZD',
95
+			'PHP',
96
+			'PLN',
97
+			'GBP',
98
+			'RUB',
99
+			'SGD',
100
+			'SEK',
101
+			'CHF',
102
+			'TWD',
103
+			'THB',
104
+			'TRY',
105
+			'INR',
106
+		);
107
+		parent::__construct();
108
+	}
109
+
110
+
111
+
112
+	/**
113
+	 * Sets the gateway URL variable based on whether debug mode is enabled or not.
114
+	 *
115
+	 * @param array $settings_array
116
+	 */
117
+	public function set_settings($settings_array)
118
+	{
119
+		parent::set_settings($settings_array);
120
+		// Redirect URL.
121
+		$this->_base_gateway_url = $this->_debug_mode
122
+			? 'https://api-3t.sandbox.paypal.com/nvp'
123
+			: 'https://api-3t.paypal.com/nvp';
124
+	}
125
+
126
+
127
+
128
+	/**
129
+	 * @param EEI_Payment $payment
130
+	 * @param array       $billing_info
131
+	 * @param string      $return_url
132
+	 * @param string      $notify_url
133
+	 * @param string      $cancel_url
134
+	 * @return \EE_Payment|\EEI_Payment
135
+	 * @throws \EE_Error
136
+	 */
137
+	public function set_redirection_info(
138
+		$payment,
139
+		$billing_info = array(),
140
+		$return_url = null,
141
+		$notify_url = null,
142
+		$cancel_url = null
143
+	) {
144
+		if (! $payment instanceof EEI_Payment) {
145
+			$payment->set_gateway_response(
146
+				esc_html__(
147
+					'Error. No associated payment was found.',
148
+					'event_espresso'
149
+				)
150
+			);
151
+			$payment->set_status($this->_pay_model->failed_status());
152
+			return $payment;
153
+		}
154
+		$transaction = $payment->transaction();
155
+		if (! $transaction instanceof EEI_Transaction) {
156
+			$payment->set_gateway_response(
157
+				esc_html__(
158
+					'Could not process this payment because it has no associated transaction.',
159
+					'event_espresso'
160
+				)
161
+			);
162
+			$payment->set_status($this->_pay_model->failed_status());
163
+			return $payment;
164
+		}
165
+		$gateway_formatter = $this->_get_gateway_formatter();
166
+		$order_description = mb_strcut($gateway_formatter->formatOrderDescription($payment), 0, 127);
167
+		$primary_registration = $transaction->primary_registration();
168
+		$primary_attendee = $primary_registration instanceof EE_Registration
169
+			? $primary_registration->attendee()
170
+			: false;
171
+		$locale = explode('-', get_bloginfo('language'));
172
+		// Gather request parameters.
173
+		$token_request_dtls = array(
174
+			'METHOD'                         => 'SetExpressCheckout',
175
+			'PAYMENTREQUEST_0_AMT'           => $payment->amount(),
176
+			'PAYMENTREQUEST_0_CURRENCYCODE'  => $payment->currency_code(),
177
+			'PAYMENTREQUEST_0_DESC'          => $order_description,
178
+			'RETURNURL'                      => $return_url,
179
+			'CANCELURL'                      => $cancel_url,
180
+			'PAYMENTREQUEST_0_PAYMENTACTION' => 'Sale',
181
+			// Buyer does not need to create a PayPal account to check out.
182
+			// This is referred to as PayPal Account Optional.
183
+			'SOLUTIONTYPE'                   => 'Sole',
184
+			// EE will blow up if you change this
185
+			'BUTTONSOURCE'                   => 'EventEspresso_SP',
186
+			// Locale of the pages displayed by PayPal during Express Checkout.
187
+			'LOCALECODE'                     => $locale[1]
188
+		);
189
+		// Show itemized list.
190
+		$itemized_list = $this->itemize_list($payment, $transaction);
191
+		$token_request_dtls = array_merge($token_request_dtls, $itemized_list);
192
+		// Automatically filling out shipping and contact information.
193
+		if ($this->_request_shipping_addr && $primary_attendee instanceof EEI_Attendee) {
194
+			// If you do not pass the shipping address, PayPal obtains it from the buyer's account profile.
195
+			$token_request_dtls['NOSHIPPING'] = '2';
196
+			$token_request_dtls['PAYMENTREQUEST_0_SHIPTOSTREET'] = $primary_attendee->address();
197
+			$token_request_dtls['PAYMENTREQUEST_0_SHIPTOSTREET2'] = $primary_attendee->address2();
198
+			$token_request_dtls['PAYMENTREQUEST_0_SHIPTOCITY'] = $primary_attendee->city();
199
+			$token_request_dtls['PAYMENTREQUEST_0_SHIPTOSTATE'] = $primary_attendee->state_abbrev();
200
+			$token_request_dtls['PAYMENTREQUEST_0_SHIPTOCOUNTRYCODE'] = $primary_attendee->country_ID();
201
+			$token_request_dtls['PAYMENTREQUEST_0_SHIPTOZIP'] = $primary_attendee->zip();
202
+			$token_request_dtls['PAYMENTREQUEST_0_EMAIL'] = $primary_attendee->email();
203
+			$token_request_dtls['PAYMENTREQUEST_0_SHIPTOPHONENUM'] = $primary_attendee->phone();
204
+		} elseif (! $this->_request_shipping_addr) {
205
+			// Do not request shipping details on the PP Checkout page.
206
+			$token_request_dtls['NOSHIPPING'] = '1';
207
+			$token_request_dtls['REQCONFIRMSHIPPING'] = '0';
208
+		}
209
+		// Used a business/personal logo on the PayPal page.
210
+		if (! empty($this->_image_url)) {
211
+			$token_request_dtls['LOGOIMG'] = $this->_image_url;
212
+		}
213
+		$token_request_dtls = apply_filters(
214
+			'FHEE__EEG_Paypal_Express__set_redirection_info__arguments',
215
+			$token_request_dtls,
216
+			$this
217
+		);
218
+		// Request PayPal token.
219
+		$token_request_response = $this->_ppExpress_request($token_request_dtls, 'Payment Token', $payment);
220
+		$token_rstatus = $this->_ppExpress_check_response($token_request_response);
221
+		$response_args = (isset($token_rstatus['args']) && is_array($token_rstatus['args']))
222
+			? $token_rstatus['args']
223
+			: array();
224
+		if ($token_rstatus['status']) {
225
+			// We got the Token so we may continue with the payment and redirect the client.
226
+			$payment->set_details($response_args);
227
+			$gateway_url = $this->_debug_mode ? 'https://www.sandbox.paypal.com' : 'https://www.paypal.com';
228
+			$payment->set_redirect_url(
229
+				$gateway_url
230
+				. '/checkoutnow?useraction=commit&cmd=_express-checkout&token='
231
+				. $response_args['TOKEN']
232
+			);
233
+		} else {
234
+			if (isset($response_args['L_ERRORCODE'])) {
235
+				$payment->set_gateway_response($response_args['L_ERRORCODE'] . '; ' . $response_args['L_SHORTMESSAGE']);
236
+			} else {
237
+				$payment->set_gateway_response(
238
+					esc_html__(
239
+						'Error occurred while trying to setup the Express Checkout.',
240
+						'event_espresso'
241
+					)
242
+				);
243
+			}
244
+			$payment->set_details($response_args);
245
+			$payment->set_status($this->_pay_model->failed_status());
246
+		}
247
+		return $payment;
248
+	}
249
+
250
+
251
+
252
+	/**
253
+	 * @param array           $update_info {
254
+	 * @type string           $gateway_txn_id
255
+	 * @type string status an EEMI_Payment status
256
+	 *                                     }
257
+	 * @param EEI_Transaction $transaction
258
+	 * @return EEI_Payment
259
+	 */
260
+	public function handle_payment_update($update_info, $transaction)
261
+	{
262
+		$payment = $transaction instanceof EEI_Transaction ? $transaction->last_payment() : null;
263
+		if ($payment instanceof EEI_Payment) {
264
+			$this->log(array('Return from Authorization' => $update_info), $payment);
265
+			$transaction = $payment->transaction();
266
+			if (! $transaction instanceof EEI_Transaction) {
267
+				$payment->set_gateway_response(
268
+					esc_html__(
269
+						'Could not process this payment because it has no associated transaction.',
270
+						'event_espresso'
271
+					)
272
+				);
273
+				$payment->set_status($this->_pay_model->failed_status());
274
+				return $payment;
275
+			}
276
+			$primary_registrant = $transaction->primary_registration();
277
+			$payment_details = $payment->details();
278
+			// Check if we still have the token.
279
+			if (! isset($payment_details['TOKEN']) || empty($payment_details['TOKEN'])) {
280
+				$payment->set_status($this->_pay_model->failed_status());
281
+				return $payment;
282
+			}
283
+			$cdetails_request_dtls = array(
284
+				'METHOD' => 'GetExpressCheckoutDetails',
285
+				'TOKEN'  => $payment_details['TOKEN'],
286
+			);
287
+			// Request Customer Details.
288
+			$cdetails_request_response = $this->_ppExpress_request(
289
+				$cdetails_request_dtls,
290
+				'Customer Details',
291
+				$payment
292
+			);
293
+			$cdetails_rstatus = $this->_ppExpress_check_response($cdetails_request_response);
294
+			$cdata_response_args = (isset($cdetails_rstatus['args']) && is_array($cdetails_rstatus['args']))
295
+				? $cdetails_rstatus['args']
296
+				: array();
297
+			if ($cdetails_rstatus['status']) {
298
+				// We got the PayerID so now we can Complete the transaction.
299
+				$docheckout_request_dtls = array(
300
+					'METHOD'                         => 'DoExpressCheckoutPayment',
301
+					'PAYERID'                        => $cdata_response_args['PAYERID'],
302
+					'TOKEN'                          => $payment_details['TOKEN'],
303
+					'PAYMENTREQUEST_0_PAYMENTACTION' => 'Sale',
304
+					'PAYMENTREQUEST_0_AMT'           => $payment->amount(),
305
+					'PAYMENTREQUEST_0_CURRENCYCODE'  => $payment->currency_code(),
306
+					// EE will blow up if you change this
307
+					'BUTTONSOURCE'                   => 'EventEspresso_SP',
308
+				);
309
+				 // Include itemized list.
310
+				$itemized_list = $this->itemize_list(
311
+					$payment,
312
+					$transaction,
313
+					$cdata_response_args
314
+				);
315
+				$docheckout_request_dtls = array_merge($docheckout_request_dtls, $itemized_list);
316
+				// Payment Checkout/Capture.
317
+				$docheckout_request_response = $this->_ppExpress_request(
318
+					$docheckout_request_dtls,
319
+					'Do Payment',
320
+					$payment
321
+				);
322
+				$docheckout_rstatus = $this->_ppExpress_check_response($docheckout_request_response);
323
+				$docheckout_response_args = (isset($docheckout_rstatus['args']) && is_array($docheckout_rstatus['args']))
324
+					? $docheckout_rstatus['args']
325
+					: array();
326
+				if ($docheckout_rstatus['status']) {
327
+					// All is well, payment approved.
328
+					$primary_registration_code = $primary_registrant instanceof EE_Registration ?
329
+						$primary_registrant->reg_code()
330
+						: '';
331
+					$payment->set_extra_accntng($primary_registration_code);
332
+					$payment->set_amount(isset($docheckout_response_args['PAYMENTINFO_0_AMT'])
333
+						? (float) $docheckout_response_args['PAYMENTINFO_0_AMT']
334
+						: 0);
335
+					$payment->set_txn_id_chq_nmbr(isset($docheckout_response_args['PAYMENTINFO_0_TRANSACTIONID'])
336
+						? $docheckout_response_args['PAYMENTINFO_0_TRANSACTIONID']
337
+						: null);
338
+					$payment->set_details($cdata_response_args);
339
+					$payment->set_gateway_response(isset($docheckout_response_args['PAYMENTINFO_0_ACK'])
340
+						? $docheckout_response_args['PAYMENTINFO_0_ACK']
341
+						: '');
342
+					$payment->set_status($this->_pay_model->approved_status());
343
+				} else {
344
+					if (isset($docheckout_response_args['L_ERRORCODE'])) {
345
+						$payment->set_gateway_response(
346
+							$docheckout_response_args['L_ERRORCODE']
347
+							. '; '
348
+							. $docheckout_response_args['L_SHORTMESSAGE']
349
+						);
350
+					} else {
351
+						$payment->set_gateway_response(
352
+							esc_html__(
353
+								'Error occurred while trying to Capture the funds.',
354
+								'event_espresso'
355
+							)
356
+						);
357
+					}
358
+					$payment->set_details($docheckout_response_args);
359
+					$payment->set_status($this->_pay_model->declined_status());
360
+				}
361
+			} else {
362
+				if (isset($cdata_response_args['L_ERRORCODE'])) {
363
+					$payment->set_gateway_response(
364
+						$cdata_response_args['L_ERRORCODE']
365
+						. '; '
366
+						. $cdata_response_args['L_SHORTMESSAGE']
367
+					);
368
+				} else {
369
+					$payment->set_gateway_response(
370
+						esc_html__(
371
+							'Error occurred while trying to get payment Details from PayPal.',
372
+							'event_espresso'
373
+						)
374
+					);
375
+				}
376
+				$payment->set_details($cdata_response_args);
377
+				$payment->set_status($this->_pay_model->failed_status());
378
+			}
379
+		} else {
380
+			$payment->set_gateway_response(
381
+				esc_html__(
382
+					'Error occurred while trying to process the payment.',
383
+					'event_espresso'
384
+				)
385
+			);
386
+			$payment->set_status($this->_pay_model->failed_status());
387
+		}
388
+		return $payment;
389
+	}
390
+
391
+
392
+
393
+	/**
394
+	 *  Make a list of items that are in the giver transaction.
395
+	 *
396
+	 * @param EEI_Payment     $payment
397
+	 * @param EEI_Transaction $transaction
398
+	 * @param array           $request_response_args Data from a previous communication with PP.
399
+	 * @return array
400
+	 */
401
+	public function itemize_list(EEI_Payment $payment, EEI_Transaction $transaction, $request_response_args = array())
402
+	{
403
+		$itemized_list = array();
404
+		$gateway_formatter = $this->_get_gateway_formatter();
405
+		// If we have data from a previous communication with PP (on this transaction) we may use that for our list...
406
+		if (! empty($request_response_args)
407
+			&& array_key_exists('L_PAYMENTREQUEST_0_AMT0', $request_response_args)
408
+			&& array_key_exists('PAYMENTREQUEST_0_ITEMAMT', $request_response_args)
409
+		) {
410
+			foreach ($request_response_args as $arg_key => $arg_val) {
411
+				if (strpos($arg_key, 'PAYMENTREQUEST_') !== false
412
+					&& strpos($arg_key, 'NOTIFYURL') === false
413
+				) {
414
+					$itemized_list[ $arg_key ] = $arg_val;
415
+				}
416
+			}
417
+			// If we got only a few Items then something is not right.
418
+			if (count($itemized_list) > 2) {
419
+				return $itemized_list;
420
+			} else {
421
+				if (WP_DEBUG) {
422
+					throw new EE_Error(
423
+						sprintf(
424
+							esc_html__(
425
+								// @codingStandardsIgnoreStart
426
+								'Unable to continue with the checkout because a proper purchase list could not be generated. The purchased list we could have sent was %1$s',
427
+								// @codingStandardsIgnoreEnd
428
+								'event_espresso'
429
+							),
430
+							wp_json_encode($itemized_list)
431
+						)
432
+					);
433
+				}
434
+				// Reset the list and log an error, maybe allow to try and generate a new list (below).
435
+				$itemized_list = array();
436
+				$this->log(
437
+					array(
438
+						esc_html__(
439
+							'Could not generate a proper item list with:',
440
+							'event_espresso'
441
+						) => $request_response_args
442
+					),
443
+					$payment
444
+				);
445
+			}
446
+		}
447
+		// ...otherwise we generate a new list for this transaction.
448
+		if ($this->_money->compare_floats($payment->amount(), $transaction->total(), '==')) {
449
+			$item_num = 0;
450
+			$itemized_sum = 0;
451
+			$total_line_items = $transaction->total_line_item();
452
+			// Go through each item in the list.
453
+			foreach ($total_line_items->get_items() as $line_item) {
454
+				if ($line_item instanceof EE_Line_Item) {
455
+					// PayPal doesn't like line items with 0.00 amount, so we may skip those.
456
+					if (EEH_Money::compare_floats($line_item->total(), '0.00', '==')) {
457
+						continue;
458
+					}
459
+					$unit_price = $line_item->unit_price();
460
+					$line_item_quantity = $line_item->quantity();
461
+					// This is a discount.
462
+					if ($line_item->is_percent()) {
463
+						$unit_price = $line_item->total();
464
+						$line_item_quantity = 1;
465
+					}
466
+					// Item Name.
467
+					$itemized_list[ 'L_PAYMENTREQUEST_0_NAME' . $item_num ] = mb_strcut(
468
+						$gateway_formatter->formatLineItemName($line_item, $payment),
469
+						0,
470
+						127
471
+					);
472
+					// Item description.
473
+					$itemized_list[ 'L_PAYMENTREQUEST_0_DESC' . $item_num ] = mb_strcut(
474
+						$gateway_formatter->formatLineItemDesc($line_item, $payment),
475
+						0,
476
+						127
477
+					);
478
+					// Cost of individual item.
479
+					$itemized_list[ 'L_PAYMENTREQUEST_0_AMT' . $item_num ] = $gateway_formatter->formatCurrency($unit_price);
480
+					// Item Number.
481
+					$itemized_list[ 'L_PAYMENTREQUEST_0_NUMBER' . $item_num ] = $item_num + 1;
482
+					// Item quantity.
483
+					$itemized_list[ 'L_PAYMENTREQUEST_0_QTY' . $item_num ] = $line_item_quantity;
484
+					// Digital item is sold.
485
+					$itemized_list[ 'L_PAYMENTREQUEST_0_ITEMCATEGORY' . $item_num ] = 'Physical';
486
+					$itemized_sum += $line_item->total();
487
+					++$item_num;
488
+				}
489
+			}
490
+			// Item's sales S/H and tax amount.
491
+			$itemized_list['PAYMENTREQUEST_0_ITEMAMT'] = $total_line_items->get_items_total();
492
+			$itemized_list['PAYMENTREQUEST_0_TAXAMT'] = $total_line_items->get_total_tax();
493
+			$itemized_list['PAYMENTREQUEST_0_SHIPPINGAMT'] = '0';
494
+			$itemized_list['PAYMENTREQUEST_0_HANDLINGAMT'] = '0';
495
+			$itemized_sum_diff_from_txn_total = round(
496
+				$transaction->total() - $itemized_sum - $total_line_items->get_total_tax(),
497
+				2
498
+			);
499
+			// If we were not able to recognize some item like promotion, surcharge or cancellation,
500
+			// add the difference as an extra line item.
501
+			if ($this->_money->compare_floats($itemized_sum_diff_from_txn_total, 0, '!=')) {
502
+				// Item Name.
503
+				$itemized_list[ 'L_PAYMENTREQUEST_0_NAME' . $item_num ] = mb_strcut(
504
+					esc_html__(
505
+						'Other (promotion/surcharge/cancellation)',
506
+						'event_espresso'
507
+					),
508
+					0,
509
+					127
510
+				);
511
+				// Item description.
512
+				$itemized_list[ 'L_PAYMENTREQUEST_0_DESC' . $item_num ] = '';
513
+				// Cost of individual item.
514
+				$itemized_list[ 'L_PAYMENTREQUEST_0_AMT' . $item_num ] = $gateway_formatter->formatCurrency(
515
+					$itemized_sum_diff_from_txn_total
516
+				);
517
+				// Item Number.
518
+				$itemized_list[ 'L_PAYMENTREQUEST_0_NUMBER' . $item_num ] = $item_num + 1;
519
+				// Item quantity.
520
+				$itemized_list[ 'L_PAYMENTREQUEST_0_QTY' . $item_num ] = 1;
521
+				// Digital item is sold.
522
+				$itemized_list[ 'L_PAYMENTREQUEST_0_ITEMCATEGORY' . $item_num ] = 'Physical';
523
+				$item_num++;
524
+			}
525
+		} else {
526
+			// Just one Item.
527
+			// Item Name.
528
+			$itemized_list['L_PAYMENTREQUEST_0_NAME0'] = mb_strcut(
529
+				$gateway_formatter->formatPartialPaymentLineItemName($payment),
530
+				0,
531
+				127
532
+			);
533
+			// Item description.
534
+			$itemized_list['L_PAYMENTREQUEST_0_DESC0'] = mb_strcut(
535
+				$gateway_formatter->formatPartialPaymentLineItemDesc($payment),
536
+				0,
537
+				127
538
+			);
539
+			// Cost of individual item.
540
+			$itemized_list['L_PAYMENTREQUEST_0_AMT0'] = $gateway_formatter->formatCurrency($payment->amount());
541
+			// Item Number.
542
+			$itemized_list['L_PAYMENTREQUEST_0_NUMBER0'] = 1;
543
+			// Item quantity.
544
+			$itemized_list['L_PAYMENTREQUEST_0_QTY0'] = 1;
545
+			// Digital item is sold.
546
+			$itemized_list['L_PAYMENTREQUEST_0_ITEMCATEGORY0'] = 'Physical';
547
+			// Item's sales S/H and tax amount.
548
+			$itemized_list['PAYMENTREQUEST_0_ITEMAMT'] = $gateway_formatter->formatCurrency($payment->amount());
549
+			$itemized_list['PAYMENTREQUEST_0_TAXAMT'] = '0';
550
+			$itemized_list['PAYMENTREQUEST_0_SHIPPINGAMT'] = '0';
551
+			$itemized_list['PAYMENTREQUEST_0_HANDLINGAMT'] = '0';
552
+		}
553
+		return $itemized_list;
554
+	}
555
+
556
+
557
+
558
+	/**
559
+	 *  Make the Express checkout request.
560
+	 *
561
+	 * @param array       $request_params
562
+	 * @param string      $request_text
563
+	 * @param EEI_Payment $payment
564
+	 * @return mixed
565
+	 */
566
+	public function _ppExpress_request($request_params, $request_text, $payment)
567
+	{
568
+		$request_dtls = array(
569
+			'VERSION'   => '204.0',
570
+			'USER'      => urlencode($this->_api_username),
571
+			'PWD'       => urlencode($this->_api_password),
572
+			'SIGNATURE' => urlencode($this->_api_signature),
573
+		);
574
+		$dtls = array_merge($request_dtls, $request_params);
575
+		$this->_log_clean_request($dtls, $payment, $request_text . ' Request');
576
+		// Request Customer Details.
577
+		$request_response = wp_remote_post(
578
+			$this->_base_gateway_url,
579
+			array(
580
+				'method'      => 'POST',
581
+				'timeout'     => 45,
582
+				'httpversion' => '1.1',
583
+				'cookies'     => array(),
584
+				'headers'     => array(),
585
+				'body'        => http_build_query($dtls, '', '&'),
586
+			)
587
+		);
588
+		// Log the response.
589
+		$this->log(array($request_text . ' Response' => $request_response), $payment);
590
+		return $request_response;
591
+	}
592
+
593
+
594
+
595
+	/**
596
+	 *  Check the response status.
597
+	 *
598
+	 * @param mixed $request_response
599
+	 * @return array
600
+	 */
601
+	public function _ppExpress_check_response($request_response)
602
+	{
603
+		if (is_wp_error($request_response) || empty($request_response['body'])) {
604
+			// If we got here then there was an error in this request.
605
+			return array('status' => false, 'args' => $request_response);
606
+		}
607
+		$response_args = array();
608
+		parse_str(urldecode($request_response['body']), $response_args);
609
+		if (! isset($response_args['ACK'])) {
610
+			return array('status' => false, 'args' => $request_response);
611
+		}
612
+		if ((
613
+				isset($response_args['PAYERID'])
614
+				|| isset($response_args['TOKEN'])
615
+				|| isset($response_args['PAYMENTINFO_0_TRANSACTIONID'])
616
+				|| (isset($response_args['PAYMENTSTATUS']) && $response_args['PAYMENTSTATUS'] === 'Completed')
617
+			)
618
+			&& in_array($response_args['ACK'], array('Success', 'SuccessWithWarning'), true)
619
+		) {
620
+			// Response status OK, return response parameters for further processing.
621
+			return array('status' => true, 'args' => $response_args);
622
+		}
623
+		$errors = $this->_get_errors($response_args);
624
+		return array('status' => false, 'args' => $errors);
625
+	}
626
+
627
+
628
+
629
+	/**
630
+	 *  Log a "Cleared" request.
631
+	 *
632
+	 * @param array       $request
633
+	 * @param EEI_Payment $payment
634
+	 * @param string      $info
635
+	 * @return void
636
+	 */
637
+	private function _log_clean_request($request, $payment, $info)
638
+	{
639
+		$cleaned_request_data = $request;
640
+		unset($cleaned_request_data['PWD'], $cleaned_request_data['USER'], $cleaned_request_data['SIGNATURE']);
641
+		$this->log(array($info => $cleaned_request_data), $payment);
642
+	}
643
+
644
+
645
+
646
+	/**
647
+	 *  Get error from the response data.
648
+	 *
649
+	 * @param array $data_array
650
+	 * @return array
651
+	 */
652
+	private function _get_errors($data_array)
653
+	{
654
+		$errors = array();
655
+		$n = 0;
656
+		while (isset($data_array[ "L_ERRORCODE{$n}" ])) {
657
+			$l_error_code = isset($data_array[ "L_ERRORCODE{$n}" ])
658
+				? $data_array[ "L_ERRORCODE{$n}" ]
659
+				: '';
660
+			$l_severity_code = isset($data_array[ "L_SEVERITYCODE{$n}" ])
661
+				? $data_array[ "L_SEVERITYCODE{$n}" ]
662
+				: '';
663
+			$l_short_message = isset($data_array[ "L_SHORTMESSAGE{$n}" ])
664
+				? $data_array[ "L_SHORTMESSAGE{$n}" ]
665
+				: '';
666
+			$l_long_message = isset($data_array[ "L_LONGMESSAGE{$n}" ])
667
+				? $data_array[ "L_LONGMESSAGE{$n}" ]
668
+				: '';
669
+			if ($n === 0) {
670
+				$errors = array(
671
+					'L_ERRORCODE'    => $l_error_code,
672
+					'L_SHORTMESSAGE' => $l_short_message,
673
+					'L_LONGMESSAGE'  => $l_long_message,
674
+					'L_SEVERITYCODE' => $l_severity_code,
675
+				);
676
+			} else {
677
+				$errors['L_ERRORCODE'] .= ', ' . $l_error_code;
678
+				$errors['L_SHORTMESSAGE'] .= ', ' . $l_short_message;
679
+				$errors['L_LONGMESSAGE'] .= ', ' . $l_long_message;
680
+				$errors['L_SEVERITYCODE'] .= ', ' . $l_severity_code;
681
+			}
682
+			$n++;
683
+		}
684
+		return $errors;
685
+	}
686 686
 }
Please login to merge, or discard this patch.
caffeinated/payment_methods/Aim/EEG_Aim.gateway.php 1 patch
Indentation   +605 added lines, -605 removed lines patch added patch discarded remove patch
@@ -25,427 +25,427 @@  discard block
 block discarded – undo
25 25
 class EEG_Aim extends EE_Onsite_Gateway
26 26
 {
27 27
 
28
-    const LIVE_URL    = 'https://secure2.authorize.net/gateway/transact.dll'; // Authnet URL
29
-
30
-    const SANDBOX_URL = 'https://test.authorize.net/gateway/transact.dll';
31
-
32
-    protected $_login_id;
33
-
34
-    protected $_transaction_key;
35
-
36
-    protected $_server;
37
-
38
-    protected $_currencies_supported = array(
39
-        'AUD',
40
-        'USD',
41
-        'CAD',
42
-        'EUR',
43
-        'GBP',
44
-        'NZD',
45
-    );
46
-
47
-    /**
48
-     * Whether to send test transactions (even to live site)
49
-     *
50
-     * @var boolean
51
-     */
52
-    protected $_test_transactions;
53
-
54
-    private $VERIFY_PEER = false;
55
-
56
-    private $_x_post_fields = array(
57
-        "version"        => "3.1",
58
-        "delim_char"     => ",",
59
-        "delim_data"     => "TRUE",
60
-        "relay_response" => "FALSE",
61
-        "encap_char"     => "|",
62
-    );
63
-
64
-    private $_additional_line_items = array();
65
-
66
-    /**
67
-     * A list of all fields in the AIM API.
68
-     * Used to warn user if they try to set a field not offered in the API.
69
-     */
70
-    private $_all_aim_fields = array(
71
-        "address",
72
-        "allow_partial_auth",
73
-        "amount",
74
-        "auth_code",
75
-        "authentication_indicator",
76
-        "bank_aba_code",
77
-        "bank_acct_name",
78
-        "bank_acct_num",
79
-        "bank_acct_type",
80
-        "bank_check_number",
81
-        "bank_name",
82
-        "card_code",
83
-        "card_num",
84
-        "cardholder_authentication_value",
85
-        "city",
86
-        "company",
87
-        "country",
88
-        "cust_id",
89
-        "customer_ip",
90
-        "delim_char",
91
-        "delim_data",
92
-        "description",
93
-        "duplicate_window",
94
-        "duty",
95
-        "echeck_type",
96
-        "email",
97
-        "email_customer",
98
-        "encap_char",
99
-        "exp_date",
100
-        "fax",
101
-        "first_name",
102
-        "footer_email_receipt",
103
-        "freight",
104
-        "header_email_receipt",
105
-        "invoice_num",
106
-        "last_name",
107
-        "line_item",
108
-        "login",
109
-        "method",
110
-        "phone",
111
-        "po_num",
112
-        "recurring_billing",
113
-        "relay_response",
114
-        "ship_to_address",
115
-        "ship_to_city",
116
-        "ship_to_company",
117
-        "ship_to_country",
118
-        "ship_to_first_name",
119
-        "ship_to_last_name",
120
-        "ship_to_state",
121
-        "ship_to_zip",
122
-        "split_tender_id",
123
-        "state",
124
-        "tax",
125
-        "tax_exempt",
126
-        "test_request",
127
-        "tran_key",
128
-        "trans_id",
129
-        "type",
130
-        "version",
131
-        "zip",
132
-        "solution_id",
133
-        "currency_code"
134
-    );
135
-
136
-
137
-    /**
138
-     * Gets the URL where the request should go. This is filterable
139
-     *
140
-     * @return string
141
-     */
142
-    protected function _get_server_url()
143
-    {
144
-        return apply_filters(
145
-            'FHEE__EEG_Aim___get_server_url',
146
-            $this->_debug_mode ? self::SANDBOX_URL : self::LIVE_URL,
147
-            $this
148
-        );
149
-    }
150
-
151
-
152
-    /**
153
-     * TEMPORARY CALLBACK! Do not use
154
-     * Callback which filters the server url. This is added so site admins can revert to using
155
-     * the old AIM server in case Akamai service breaks their integration.
156
-     * Using Akamai will, however, be mandatory on June 30th 2016 Authorize.net
157
-     * (see http://www.authorize.net/support/akamaifaqs/#firewall?utm_campaign=April%202016%20Technical%20Updates%20for%20Merchants.html&utm_medium=email&utm_source=Eloqua&elqTrackId=46103bdc375c411a979c2f658fc99074&elq=7026706360154fee9b6d588b27d8eb6a&elqaid=506&elqat=1&elqCampaignId=343)
158
-     * Once that happens, this will be obsolete and WILL BE REMOVED.
159
-     *
160
-     * @param string $url
161
-     * @param EEG_Aim $gateway_object
162
-     * @return string
163
-     */
164
-    public function possibly_use_deprecated_aim_server($url, EEG_Aim $gateway_object)
165
-    {
166
-        if ($gateway_object->_server === 'authorize.net' && ! $gateway_object->_debug_mode) {
167
-            return 'https://secure.authorize.net/gateway/transact.dll';
168
-        } else {
169
-            return $url;
170
-        }
171
-    }
172
-
173
-
174
-    /**
175
-     * Asks the gateway to do whatever it does to process the payment. Onsite gateways will
176
-     * usually send a request directly to the payment provider and update the payment's status based on that;
177
-     * whereas offsite gateways will usually just update the payment with the URL and query parameters to use
178
-     * for sending the request via http_remote_request()
179
-     *
180
-     * @param EEI_Payment $payment
181
-     * @param array $billing_info {
182
-     *  @type $credit_card string
183
-     *  @type $cvv string
184
-     *  @type $exp_month string
185
-     *  @type $exp_year string
186
-     *  @see parent::do_direct_payment
187
-     * }
188
-     * @return EEI_Payment updated
189
-     */
190
-    public function do_direct_payment($payment, $billing_info = null)
191
-    {
192
-        add_filter('FHEE__EEG_Aim___get_server_url', array($this, 'possibly_use_deprecated_aim_server'), 10, 2);
193
-        // Enable test mode if needed
194
-        // 4007000000027  <-- test successful visa
195
-        // 4222222222222  <-- test failure card number
196
-
197
-        $item_num = 1;
198
-        $transaction = $payment->transaction();
199
-        $gateway_formatter = $this->_get_gateway_formatter();
200
-        $order_description = $gateway_formatter->formatOrderDescription($payment);
201
-        $primary_registrant = $transaction->primary_registration();
202
-        // if we're are charging for the full amount, show the normal line items
203
-        // and the itemized total adds up properly
204
-        if ($this->_can_easily_itemize_transaction_for($payment)) {
205
-            $total_line_item = $transaction->total_line_item();
206
-            foreach ($total_line_item->get_items() as $line_item) {
207
-                if ($line_item->quantity() == 0) {
208
-                    continue;
209
-                }
210
-                $this->addLineItem(
211
-                    $item_num++,
212
-                    $gateway_formatter->formatLineItemName($line_item, $payment),
213
-                    $gateway_formatter->formatLineItemDesc($line_item, $payment),
214
-                    $line_item->quantity(),
215
-                    $line_item->unit_price(),
216
-                    'N'
217
-                );
218
-                $order_description .= $line_item->desc().', ';
219
-            }
220
-            foreach ($total_line_item->tax_descendants() as $tax_line_item) {
221
-                $this->addLineItem(
222
-                    $item_num++,
223
-                    $tax_line_item->name(),
224
-                    $tax_line_item->desc(),
225
-                    1,
226
-                    $tax_line_item->total(),
227
-                    'N'
228
-                );
229
-            }
230
-        }
231
-
232
-        // start transaction
233
-        // if in debug mode, use authorize.net's sandbox id; otherwise use the Event Espresso partner id
234
-        $partner_id = $this->_debug_mode ? 'AAA100302' : 'AAA105363';
235
-        $this->setField('solution_id', $partner_id);
236
-        $this->setField('amount', $gateway_formatter->formatCurrency($payment->amount()));
237
-        $this->setField('description', substr(rtrim($order_description, ', '), 0, 255));
238
-        $this->_set_sensitive_billing_data($billing_info);
239
-        $this->setField('first_name', $billing_info['first_name']);
240
-        $this->setField('last_name', $billing_info['last_name']);
241
-        $this->setField('email', $billing_info['email']);
242
-        $this->setField('company', $billing_info['company']);
243
-        $this->setField('address', $billing_info['address'].' '.$billing_info['address2']);
244
-        $this->setField('city', $billing_info['city']);
245
-        $this->setField('state', $billing_info['state']);
246
-        $this->setField('country', $billing_info['country']);
247
-        $this->setField('zip', $billing_info['zip']);
248
-        $this->setField('fax', $billing_info['fax']);
249
-        $this->setField('cust_id', $primary_registrant->ID());
250
-        $this->setField('phone', $billing_info['phone']);
251
-        $currency_config = LoaderFactory::getLoader()->load('EE_Currency_Config');
252
-        $this->setField('currency_code', $currency_config->code);
253
-        // invoice_num would be nice to have it be unique per SPCO page-load, that way if users
254
-        // press back, they don't submit a duplicate. However, we may be keeping the user on teh same spco page
255
-        // in which case, we need to generate teh invoice num per request right here...
256
-        $this->setField('invoice_num', wp_generate_password(12, false));// $billing_info['_reg-page-billing-invoice-'.$this->_gateway_name]['value']);
257
-        // tell AIM that any duplicates sent in the next 5 minutes are to be ignored
258
-        $this->setField('duplicate_window', 5 * MINUTE_IN_SECONDS);
259
-
260
-        if ($this->_test_transactions) {
261
-            $this->test_request = "true";
262
-        }
263
-
264
-        // Capture response
265
-        $this->type = "AUTH_CAPTURE";
266
-        $response = $this->_sendRequest($payment);
267
-        if (! empty($response)) {
268
-            if ($response->error_message) {
269
-                $payment->set_status($this->_pay_model->failed_status());
270
-                $payment->set_gateway_response($response->error_message);
271
-            } else {
272
-                $payment_status = $response->approved
273
-                    ? $this->_pay_model->approved_status()
274
-                    : $this->_pay_model->declined_status();
275
-                $payment->set_status($payment_status);
276
-                // make sure we interpret the AMT as a float, not an international string (where periods are thousand separators)
277
-                $payment->set_amount((float) $response->amount);
278
-                $payment->set_gateway_response(
279
-                    sprintf(
280
-                        esc_html__('%1$s (Reason Code: %2$s)', 'event_espresso'),
281
-                        $response->response_reason_text,
282
-                        $response->response_reason_code
283
-                    )
284
-                );
285
-                if ($this->_debug_mode) {
286
-                    $txn_id = $response->invoice_number;
287
-                } else {
288
-                    $txn_id = $response->transaction_id;
289
-                }
290
-                $payment->set_txn_id_chq_nmbr($txn_id);
291
-            }
292
-            $payment->set_extra_accntng($primary_registrant->reg_code());
293
-            $payment->set_details(print_r($response, true));
294
-        } else {
295
-            $payment->set_status($this->_pay_model->failed_status());
296
-            $payment->set_gateway_response(__("There was no response from Authorize.net", 'event_espresso'));
297
-            $payment->set_details(print_r($response, true));
298
-        }
299
-        return $payment;
300
-    }
301
-
302
-
303
-    /**
304
-     * Sets billing data for the upcoming request to AIM that is considered sensitive;
305
-     * also this method can be overridden by children classes to easily change
306
-     * what billing data gets sent
307
-     *
308
-     * @param array $billing_info
309
-     */
310
-    protected function _set_sensitive_billing_data($billing_info)
311
-    {
312
-        $this->setField('card_num', $billing_info['credit_card']);
313
-        $this->setField('exp_date', $billing_info['exp_month'] . $billing_info['exp_year']);
314
-        $this->setField('card_code', $billing_info['cvv']);
315
-    }
316
-
317
-
318
-    /**
319
-     * Add a line item.
320
-     *
321
-     * @param string $item_id
322
-     * @param string $item_name
323
-     * @param string $item_description
324
-     * @param string $item_quantity
325
-     * @param string $item_unit_price
326
-     * @param string $item_taxable
327
-     */
328
-    public function addLineItem($item_id, $item_name, $item_description, $item_quantity, $item_unit_price, $item_taxable)
329
-    {
330
-        $args = array(
331
-            substr($item_id, 0, 31),
332
-            substr($item_name, 0, 31),
333
-            substr($item_description, 0, 255),
334
-            number_format(abs($item_quantity), 2, '.', ''),
335
-            number_format(abs($item_unit_price), 2, '.', ''),
336
-            $item_taxable === 'N' ? 'N' : 'Y'
337
-        );
338
-        $this->_additional_line_items[] = implode('<|>', $args);
339
-    }
340
-
341
-
342
-    /**
343
-     * Set an individual name/value pair. This will append x_ to the name
344
-     * before posting.
345
-     *
346
-     * @param string $name
347
-     * @param string $value
348
-     * @throws AuthorizeNetException
349
-     */
350
-    protected function setField($name, $value)
351
-    {
352
-        if (in_array($name, $this->_all_aim_fields)) {
353
-            $this->_x_post_fields[ $name ] = $value;
354
-        } else {
355
-            throw new AuthorizeNetException("Error: no field $name exists in the AIM API.
28
+	const LIVE_URL    = 'https://secure2.authorize.net/gateway/transact.dll'; // Authnet URL
29
+
30
+	const SANDBOX_URL = 'https://test.authorize.net/gateway/transact.dll';
31
+
32
+	protected $_login_id;
33
+
34
+	protected $_transaction_key;
35
+
36
+	protected $_server;
37
+
38
+	protected $_currencies_supported = array(
39
+		'AUD',
40
+		'USD',
41
+		'CAD',
42
+		'EUR',
43
+		'GBP',
44
+		'NZD',
45
+	);
46
+
47
+	/**
48
+	 * Whether to send test transactions (even to live site)
49
+	 *
50
+	 * @var boolean
51
+	 */
52
+	protected $_test_transactions;
53
+
54
+	private $VERIFY_PEER = false;
55
+
56
+	private $_x_post_fields = array(
57
+		"version"        => "3.1",
58
+		"delim_char"     => ",",
59
+		"delim_data"     => "TRUE",
60
+		"relay_response" => "FALSE",
61
+		"encap_char"     => "|",
62
+	);
63
+
64
+	private $_additional_line_items = array();
65
+
66
+	/**
67
+	 * A list of all fields in the AIM API.
68
+	 * Used to warn user if they try to set a field not offered in the API.
69
+	 */
70
+	private $_all_aim_fields = array(
71
+		"address",
72
+		"allow_partial_auth",
73
+		"amount",
74
+		"auth_code",
75
+		"authentication_indicator",
76
+		"bank_aba_code",
77
+		"bank_acct_name",
78
+		"bank_acct_num",
79
+		"bank_acct_type",
80
+		"bank_check_number",
81
+		"bank_name",
82
+		"card_code",
83
+		"card_num",
84
+		"cardholder_authentication_value",
85
+		"city",
86
+		"company",
87
+		"country",
88
+		"cust_id",
89
+		"customer_ip",
90
+		"delim_char",
91
+		"delim_data",
92
+		"description",
93
+		"duplicate_window",
94
+		"duty",
95
+		"echeck_type",
96
+		"email",
97
+		"email_customer",
98
+		"encap_char",
99
+		"exp_date",
100
+		"fax",
101
+		"first_name",
102
+		"footer_email_receipt",
103
+		"freight",
104
+		"header_email_receipt",
105
+		"invoice_num",
106
+		"last_name",
107
+		"line_item",
108
+		"login",
109
+		"method",
110
+		"phone",
111
+		"po_num",
112
+		"recurring_billing",
113
+		"relay_response",
114
+		"ship_to_address",
115
+		"ship_to_city",
116
+		"ship_to_company",
117
+		"ship_to_country",
118
+		"ship_to_first_name",
119
+		"ship_to_last_name",
120
+		"ship_to_state",
121
+		"ship_to_zip",
122
+		"split_tender_id",
123
+		"state",
124
+		"tax",
125
+		"tax_exempt",
126
+		"test_request",
127
+		"tran_key",
128
+		"trans_id",
129
+		"type",
130
+		"version",
131
+		"zip",
132
+		"solution_id",
133
+		"currency_code"
134
+	);
135
+
136
+
137
+	/**
138
+	 * Gets the URL where the request should go. This is filterable
139
+	 *
140
+	 * @return string
141
+	 */
142
+	protected function _get_server_url()
143
+	{
144
+		return apply_filters(
145
+			'FHEE__EEG_Aim___get_server_url',
146
+			$this->_debug_mode ? self::SANDBOX_URL : self::LIVE_URL,
147
+			$this
148
+		);
149
+	}
150
+
151
+
152
+	/**
153
+	 * TEMPORARY CALLBACK! Do not use
154
+	 * Callback which filters the server url. This is added so site admins can revert to using
155
+	 * the old AIM server in case Akamai service breaks their integration.
156
+	 * Using Akamai will, however, be mandatory on June 30th 2016 Authorize.net
157
+	 * (see http://www.authorize.net/support/akamaifaqs/#firewall?utm_campaign=April%202016%20Technical%20Updates%20for%20Merchants.html&utm_medium=email&utm_source=Eloqua&elqTrackId=46103bdc375c411a979c2f658fc99074&elq=7026706360154fee9b6d588b27d8eb6a&elqaid=506&elqat=1&elqCampaignId=343)
158
+	 * Once that happens, this will be obsolete and WILL BE REMOVED.
159
+	 *
160
+	 * @param string $url
161
+	 * @param EEG_Aim $gateway_object
162
+	 * @return string
163
+	 */
164
+	public function possibly_use_deprecated_aim_server($url, EEG_Aim $gateway_object)
165
+	{
166
+		if ($gateway_object->_server === 'authorize.net' && ! $gateway_object->_debug_mode) {
167
+			return 'https://secure.authorize.net/gateway/transact.dll';
168
+		} else {
169
+			return $url;
170
+		}
171
+	}
172
+
173
+
174
+	/**
175
+	 * Asks the gateway to do whatever it does to process the payment. Onsite gateways will
176
+	 * usually send a request directly to the payment provider and update the payment's status based on that;
177
+	 * whereas offsite gateways will usually just update the payment with the URL and query parameters to use
178
+	 * for sending the request via http_remote_request()
179
+	 *
180
+	 * @param EEI_Payment $payment
181
+	 * @param array $billing_info {
182
+	 *  @type $credit_card string
183
+	 *  @type $cvv string
184
+	 *  @type $exp_month string
185
+	 *  @type $exp_year string
186
+	 *  @see parent::do_direct_payment
187
+	 * }
188
+	 * @return EEI_Payment updated
189
+	 */
190
+	public function do_direct_payment($payment, $billing_info = null)
191
+	{
192
+		add_filter('FHEE__EEG_Aim___get_server_url', array($this, 'possibly_use_deprecated_aim_server'), 10, 2);
193
+		// Enable test mode if needed
194
+		// 4007000000027  <-- test successful visa
195
+		// 4222222222222  <-- test failure card number
196
+
197
+		$item_num = 1;
198
+		$transaction = $payment->transaction();
199
+		$gateway_formatter = $this->_get_gateway_formatter();
200
+		$order_description = $gateway_formatter->formatOrderDescription($payment);
201
+		$primary_registrant = $transaction->primary_registration();
202
+		// if we're are charging for the full amount, show the normal line items
203
+		// and the itemized total adds up properly
204
+		if ($this->_can_easily_itemize_transaction_for($payment)) {
205
+			$total_line_item = $transaction->total_line_item();
206
+			foreach ($total_line_item->get_items() as $line_item) {
207
+				if ($line_item->quantity() == 0) {
208
+					continue;
209
+				}
210
+				$this->addLineItem(
211
+					$item_num++,
212
+					$gateway_formatter->formatLineItemName($line_item, $payment),
213
+					$gateway_formatter->formatLineItemDesc($line_item, $payment),
214
+					$line_item->quantity(),
215
+					$line_item->unit_price(),
216
+					'N'
217
+				);
218
+				$order_description .= $line_item->desc().', ';
219
+			}
220
+			foreach ($total_line_item->tax_descendants() as $tax_line_item) {
221
+				$this->addLineItem(
222
+					$item_num++,
223
+					$tax_line_item->name(),
224
+					$tax_line_item->desc(),
225
+					1,
226
+					$tax_line_item->total(),
227
+					'N'
228
+				);
229
+			}
230
+		}
231
+
232
+		// start transaction
233
+		// if in debug mode, use authorize.net's sandbox id; otherwise use the Event Espresso partner id
234
+		$partner_id = $this->_debug_mode ? 'AAA100302' : 'AAA105363';
235
+		$this->setField('solution_id', $partner_id);
236
+		$this->setField('amount', $gateway_formatter->formatCurrency($payment->amount()));
237
+		$this->setField('description', substr(rtrim($order_description, ', '), 0, 255));
238
+		$this->_set_sensitive_billing_data($billing_info);
239
+		$this->setField('first_name', $billing_info['first_name']);
240
+		$this->setField('last_name', $billing_info['last_name']);
241
+		$this->setField('email', $billing_info['email']);
242
+		$this->setField('company', $billing_info['company']);
243
+		$this->setField('address', $billing_info['address'].' '.$billing_info['address2']);
244
+		$this->setField('city', $billing_info['city']);
245
+		$this->setField('state', $billing_info['state']);
246
+		$this->setField('country', $billing_info['country']);
247
+		$this->setField('zip', $billing_info['zip']);
248
+		$this->setField('fax', $billing_info['fax']);
249
+		$this->setField('cust_id', $primary_registrant->ID());
250
+		$this->setField('phone', $billing_info['phone']);
251
+		$currency_config = LoaderFactory::getLoader()->load('EE_Currency_Config');
252
+		$this->setField('currency_code', $currency_config->code);
253
+		// invoice_num would be nice to have it be unique per SPCO page-load, that way if users
254
+		// press back, they don't submit a duplicate. However, we may be keeping the user on teh same spco page
255
+		// in which case, we need to generate teh invoice num per request right here...
256
+		$this->setField('invoice_num', wp_generate_password(12, false));// $billing_info['_reg-page-billing-invoice-'.$this->_gateway_name]['value']);
257
+		// tell AIM that any duplicates sent in the next 5 minutes are to be ignored
258
+		$this->setField('duplicate_window', 5 * MINUTE_IN_SECONDS);
259
+
260
+		if ($this->_test_transactions) {
261
+			$this->test_request = "true";
262
+		}
263
+
264
+		// Capture response
265
+		$this->type = "AUTH_CAPTURE";
266
+		$response = $this->_sendRequest($payment);
267
+		if (! empty($response)) {
268
+			if ($response->error_message) {
269
+				$payment->set_status($this->_pay_model->failed_status());
270
+				$payment->set_gateway_response($response->error_message);
271
+			} else {
272
+				$payment_status = $response->approved
273
+					? $this->_pay_model->approved_status()
274
+					: $this->_pay_model->declined_status();
275
+				$payment->set_status($payment_status);
276
+				// make sure we interpret the AMT as a float, not an international string (where periods are thousand separators)
277
+				$payment->set_amount((float) $response->amount);
278
+				$payment->set_gateway_response(
279
+					sprintf(
280
+						esc_html__('%1$s (Reason Code: %2$s)', 'event_espresso'),
281
+						$response->response_reason_text,
282
+						$response->response_reason_code
283
+					)
284
+				);
285
+				if ($this->_debug_mode) {
286
+					$txn_id = $response->invoice_number;
287
+				} else {
288
+					$txn_id = $response->transaction_id;
289
+				}
290
+				$payment->set_txn_id_chq_nmbr($txn_id);
291
+			}
292
+			$payment->set_extra_accntng($primary_registrant->reg_code());
293
+			$payment->set_details(print_r($response, true));
294
+		} else {
295
+			$payment->set_status($this->_pay_model->failed_status());
296
+			$payment->set_gateway_response(__("There was no response from Authorize.net", 'event_espresso'));
297
+			$payment->set_details(print_r($response, true));
298
+		}
299
+		return $payment;
300
+	}
301
+
302
+
303
+	/**
304
+	 * Sets billing data for the upcoming request to AIM that is considered sensitive;
305
+	 * also this method can be overridden by children classes to easily change
306
+	 * what billing data gets sent
307
+	 *
308
+	 * @param array $billing_info
309
+	 */
310
+	protected function _set_sensitive_billing_data($billing_info)
311
+	{
312
+		$this->setField('card_num', $billing_info['credit_card']);
313
+		$this->setField('exp_date', $billing_info['exp_month'] . $billing_info['exp_year']);
314
+		$this->setField('card_code', $billing_info['cvv']);
315
+	}
316
+
317
+
318
+	/**
319
+	 * Add a line item.
320
+	 *
321
+	 * @param string $item_id
322
+	 * @param string $item_name
323
+	 * @param string $item_description
324
+	 * @param string $item_quantity
325
+	 * @param string $item_unit_price
326
+	 * @param string $item_taxable
327
+	 */
328
+	public function addLineItem($item_id, $item_name, $item_description, $item_quantity, $item_unit_price, $item_taxable)
329
+	{
330
+		$args = array(
331
+			substr($item_id, 0, 31),
332
+			substr($item_name, 0, 31),
333
+			substr($item_description, 0, 255),
334
+			number_format(abs($item_quantity), 2, '.', ''),
335
+			number_format(abs($item_unit_price), 2, '.', ''),
336
+			$item_taxable === 'N' ? 'N' : 'Y'
337
+		);
338
+		$this->_additional_line_items[] = implode('<|>', $args);
339
+	}
340
+
341
+
342
+	/**
343
+	 * Set an individual name/value pair. This will append x_ to the name
344
+	 * before posting.
345
+	 *
346
+	 * @param string $name
347
+	 * @param string $value
348
+	 * @throws AuthorizeNetException
349
+	 */
350
+	protected function setField($name, $value)
351
+	{
352
+		if (in_array($name, $this->_all_aim_fields)) {
353
+			$this->_x_post_fields[ $name ] = $value;
354
+		} else {
355
+			throw new AuthorizeNetException("Error: no field $name exists in the AIM API.
356 356
             To set a custom field use setCustomField('field','value') instead.");
357
-        }
358
-    }
359
-
360
-
361
-    /**
362
-     * Posts the request to AuthorizeNet & returns response.
363
-     *
364
-     * @param $payment
365
-     * @return \EE_AuthorizeNetAIM_Response
366
-     */
367
-    private function _sendRequest($payment)
368
-    {
369
-        $this->_x_post_fields['login'] = $this->_login_id;
370
-        $this->_x_post_fields['tran_key'] = $this->_transaction_key;
371
-        $x_keys = array();
372
-        foreach ($this->_x_post_fields as $key => $value) {
373
-            $x_keys[] = "x_$key=" . urlencode($this->_get_unsupported_character_remover()->format($value));
374
-        }
375
-        // Add line items
376
-        foreach ($this->_additional_line_items as $key => $value) {
377
-            $x_keys[] =  "x_line_item=" . urlencode($this->_get_unsupported_character_remover()->format($value));
378
-        }
379
-        $this->_log_clean_request($x_keys, $payment);
380
-        $post_url = $this->_get_server_url();
381
-        $curl_request = curl_init($post_url);
382
-        $post_body = implode("&", $x_keys);
383
-        curl_setopt($curl_request, CURLOPT_POSTFIELDS, $post_body);
384
-        curl_setopt($curl_request, CURLOPT_HEADER, 0);
385
-        curl_setopt($curl_request, CURLOPT_TIMEOUT, 45);
386
-        curl_setopt($curl_request, CURLOPT_RETURNTRANSFER, 1);
387
-        curl_setopt($curl_request, CURLOPT_SSL_VERIFYHOST, 2);
388
-        if ($this->VERIFY_PEER) {
389
-            curl_setopt($curl_request, CURLOPT_CAINFO, dirname(__DIR__) . '/ssl/cert.pem');
390
-        } else {
391
-            curl_setopt($curl_request, CURLOPT_SSL_VERIFYPEER, false);
392
-        }
393
-
394
-        if (preg_match('/xml/', $post_url)) {
395
-            curl_setopt($curl_request, CURLOPT_HTTPHEADER, array("Content-Type: text/xml"));
396
-        }
397
-
398
-        $response = curl_exec($curl_request);
399
-
400
-        curl_close($curl_request);
401
-        $response_obj =  new EE_AuthorizeNetAIM_Response($response);
402
-
403
-        return $this->_log_and_clean_response($response_obj, $payment);
404
-    }
405
-
406
-
407
-    /**
408
-     * Logs the clean data only
409
-     *
410
-     * @param array $request_array
411
-     * @param EEI_Payment $payment
412
-     */
413
-    protected function _log_clean_request($request_array, $payment)
414
-    {
415
-        $keys_to_filter_out = array('x_card_num', 'x_card_code', 'x_exp_date');
416
-        foreach ($request_array as $index => $keyvaltogether) {
417
-            foreach ($keys_to_filter_out as $key) {
418
-                if (strpos($keyvaltogether, $key) === 0) {
419
-                    // found it at the first character
420
-                    // so its one of them
421
-                    unset($request_array[ $index ]);
422
-                }
423
-            }
424
-        }
425
-        $this->log(
426
-            array(
427
-                'AIM Request sent:' => $request_array,
428
-                'Server URL'        => $this->_get_server_url()
429
-            ),
430
-            $payment
431
-        );
432
-    }
433
-
434
-
435
-
436
-    /**
437
-     * Logs the response and cleans it
438
-     *
439
-     * @param EE_AuthorizeNetAIM_Response $response_obj
440
-     * @param EE_Payment                  $payment
441
-     * @return \EE_AuthorizeNetAIM_Response
442
-     */
443
-    private function _log_and_clean_response($response_obj, $payment)
444
-    {
445
-        $response_obj->account_number = '';
446
-        $this->log(array('AIM Response received:' => (array) $response_obj), $payment);
447
-        return $response_obj;
448
-    }
357
+		}
358
+	}
359
+
360
+
361
+	/**
362
+	 * Posts the request to AuthorizeNet & returns response.
363
+	 *
364
+	 * @param $payment
365
+	 * @return \EE_AuthorizeNetAIM_Response
366
+	 */
367
+	private function _sendRequest($payment)
368
+	{
369
+		$this->_x_post_fields['login'] = $this->_login_id;
370
+		$this->_x_post_fields['tran_key'] = $this->_transaction_key;
371
+		$x_keys = array();
372
+		foreach ($this->_x_post_fields as $key => $value) {
373
+			$x_keys[] = "x_$key=" . urlencode($this->_get_unsupported_character_remover()->format($value));
374
+		}
375
+		// Add line items
376
+		foreach ($this->_additional_line_items as $key => $value) {
377
+			$x_keys[] =  "x_line_item=" . urlencode($this->_get_unsupported_character_remover()->format($value));
378
+		}
379
+		$this->_log_clean_request($x_keys, $payment);
380
+		$post_url = $this->_get_server_url();
381
+		$curl_request = curl_init($post_url);
382
+		$post_body = implode("&", $x_keys);
383
+		curl_setopt($curl_request, CURLOPT_POSTFIELDS, $post_body);
384
+		curl_setopt($curl_request, CURLOPT_HEADER, 0);
385
+		curl_setopt($curl_request, CURLOPT_TIMEOUT, 45);
386
+		curl_setopt($curl_request, CURLOPT_RETURNTRANSFER, 1);
387
+		curl_setopt($curl_request, CURLOPT_SSL_VERIFYHOST, 2);
388
+		if ($this->VERIFY_PEER) {
389
+			curl_setopt($curl_request, CURLOPT_CAINFO, dirname(__DIR__) . '/ssl/cert.pem');
390
+		} else {
391
+			curl_setopt($curl_request, CURLOPT_SSL_VERIFYPEER, false);
392
+		}
393
+
394
+		if (preg_match('/xml/', $post_url)) {
395
+			curl_setopt($curl_request, CURLOPT_HTTPHEADER, array("Content-Type: text/xml"));
396
+		}
397
+
398
+		$response = curl_exec($curl_request);
399
+
400
+		curl_close($curl_request);
401
+		$response_obj =  new EE_AuthorizeNetAIM_Response($response);
402
+
403
+		return $this->_log_and_clean_response($response_obj, $payment);
404
+	}
405
+
406
+
407
+	/**
408
+	 * Logs the clean data only
409
+	 *
410
+	 * @param array $request_array
411
+	 * @param EEI_Payment $payment
412
+	 */
413
+	protected function _log_clean_request($request_array, $payment)
414
+	{
415
+		$keys_to_filter_out = array('x_card_num', 'x_card_code', 'x_exp_date');
416
+		foreach ($request_array as $index => $keyvaltogether) {
417
+			foreach ($keys_to_filter_out as $key) {
418
+				if (strpos($keyvaltogether, $key) === 0) {
419
+					// found it at the first character
420
+					// so its one of them
421
+					unset($request_array[ $index ]);
422
+				}
423
+			}
424
+		}
425
+		$this->log(
426
+			array(
427
+				'AIM Request sent:' => $request_array,
428
+				'Server URL'        => $this->_get_server_url()
429
+			),
430
+			$payment
431
+		);
432
+	}
433
+
434
+
435
+
436
+	/**
437
+	 * Logs the response and cleans it
438
+	 *
439
+	 * @param EE_AuthorizeNetAIM_Response $response_obj
440
+	 * @param EE_Payment                  $payment
441
+	 * @return \EE_AuthorizeNetAIM_Response
442
+	 */
443
+	private function _log_and_clean_response($response_obj, $payment)
444
+	{
445
+		$response_obj->account_number = '';
446
+		$this->log(array('AIM Response received:' => (array) $response_obj), $payment);
447
+		return $response_obj;
448
+	}
449 449
 }
450 450
 
451 451
 
@@ -461,192 +461,192 @@  discard block
 block discarded – undo
461 461
 class EE_AuthorizeNetAIM_Response
462 462
 {
463 463
 
464
-    const APPROVED = '1';
465
-    const DECLINED = '2';
466
-    const ERROR = '3';
467
-    const HELD = '4';
468
-
469
-    protected $_x_post_fields = array(
470
-        "version"        => "3.1",
471
-        "delim_char"     => ",",
472
-        "delim_data"     => "TRUE",
473
-        "relay_response" => "FALSE",
474
-        "encap_char"     => "|",
475
-    );
476
-    public $approved;
477
-    public $declined;
478
-    public $error;
479
-    public $held;
480
-    public $response_code;
481
-    public $response_subcode;
482
-    public $response_reason_code;
483
-    public $response_reason_text;
484
-    public $authorization_code;
485
-    public $avs_response;
486
-    public $transaction_id;
487
-    public $invoice_number;
488
-    public $description;
489
-    public $amount;
490
-    public $method;
491
-    public $transaction_type;
492
-    public $customer_id;
493
-    public $first_name;
494
-    public $last_name;
495
-    public $company;
496
-    public $address;
497
-    public $city;
498
-    public $state;
499
-    public $zip_code;
500
-    public $country;
501
-    public $phone;
502
-    public $fax;
503
-    public $email_address;
504
-    public $ship_to_first_name;
505
-    public $ship_to_last_name;
506
-    public $ship_to_company;
507
-    public $ship_to_address;
508
-    public $ship_to_city;
509
-    public $ship_to_state;
510
-    public $ship_to_zip_code;
511
-    public $ship_to_country;
512
-    public $tax;
513
-    public $duty;
514
-    public $freight;
515
-    public $tax_exempt;
516
-    public $purchase_order_number;
517
-    public $md5_hash;
518
-    public $card_code_response;
519
-    public $cavv_response; // cardholder_authentication_verification_response
520
-    public $account_number;
521
-    public $card_type;
522
-    public $split_tender_id;
523
-    public $requested_amount;
524
-    public $balance_on_card;
525
-    public $response; // The response string from AuthorizeNet.
526
-    public $error_message;
527
-    private $_response_array = array(); // An array with the split response.
528
-
529
-
530
-    /**
531
-     * Constructor. Parses the AuthorizeNet response string
532
-     *
533
-     * @param string $response The response from the AuthNet server.
534
-     * @var string   $delimiter The delimiter used (default is ",")
535
-     * @var string   $encap_char The encap_char used (default is "|")
536
-     * @var array    $custom_fields Any custom fields set in the request.
537
-     */
538
-
539
-    public function __construct($response)
540
-    {
541
-        $encap_char = $this->_x_post_fields['encap_char'];
542
-        $delimiter = $this->_x_post_fields['delim_char'];
543
-        if ($response) {
544
-            // Split Array
545
-            $this->response = $response;
546
-            if ($encap_char) {
547
-                $this->_response_array = explode($encap_char . $delimiter . $encap_char, substr($response, 1, -1));
548
-            } else {
549
-                $this->_response_array = explode($delimiter, $response);
550
-            }
551
-
552
-            /**
553
-             * If AuthorizeNet doesn't return a delimited response.
554
-             */
555
-            if (count($this->_response_array) < 10) {
556
-                $this->approved = false;
557
-                $this->error = true;
558
-                $this->error_message = sprintf(
559
-                    esc_html__('Unrecognized response from Authorize.net: %1$s', 'event_espresso'),
560
-                    esc_html($response)
561
-                );
562
-                return;
563
-            }
564
-
565
-
566
-
567
-            // Set all fields
568
-            $this->response_code = $this->_response_array[0];
569
-            $this->response_subcode = $this->_response_array[1];
570
-            $this->response_reason_code = $this->_response_array[2];
571
-            $this->response_reason_text = $this->_response_array[3];
572
-            $this->authorization_code = $this->_response_array[4];
573
-            $this->avs_response = $this->_response_array[5];
574
-            $this->transaction_id = $this->_response_array[6];
575
-            $this->invoice_number = $this->_response_array[7];
576
-            $this->description = $this->_response_array[8];
577
-            $this->amount = $this->_response_array[9];
578
-            $this->method = $this->_response_array[10];
579
-            $this->transaction_type = $this->_response_array[11];
580
-            $this->customer_id = $this->_response_array[12];
581
-            $this->first_name = $this->_response_array[13];
582
-            $this->last_name = $this->_response_array[14];
583
-            $this->company = $this->_response_array[15];
584
-            $this->address = $this->_response_array[16];
585
-            $this->city = $this->_response_array[17];
586
-            $this->state = $this->_response_array[18];
587
-            $this->zip_code = $this->_response_array[19];
588
-            $this->country = $this->_response_array[20];
589
-            $this->phone = $this->_response_array[21];
590
-            $this->fax = $this->_response_array[22];
591
-            $this->email_address = $this->_response_array[23];
592
-            $this->ship_to_first_name = $this->_response_array[24];
593
-            $this->ship_to_last_name = $this->_response_array[25];
594
-            $this->ship_to_company = $this->_response_array[26];
595
-            $this->ship_to_address = $this->_response_array[27];
596
-            $this->ship_to_city = $this->_response_array[28];
597
-            $this->ship_to_state = $this->_response_array[29];
598
-            $this->ship_to_zip_code = $this->_response_array[30];
599
-            $this->ship_to_country = $this->_response_array[31];
600
-            $this->tax = $this->_response_array[32];
601
-            $this->duty = $this->_response_array[33];
602
-            $this->freight = $this->_response_array[34];
603
-            $this->tax_exempt = $this->_response_array[35];
604
-            $this->purchase_order_number = $this->_response_array[36];
605
-            $this->md5_hash = $this->_response_array[37];
606
-            $this->card_code_response = $this->_response_array[38];
607
-            $this->cavv_response = $this->_response_array[39];
608
-            $this->account_number = $this->_response_array[50];
609
-            $this->card_type = $this->_response_array[51];
610
-            $this->split_tender_id = $this->_response_array[52];
611
-            $this->requested_amount = $this->_response_array[53];
612
-            $this->balance_on_card = $this->_response_array[54];
613
-
614
-            $this->approved = ($this->response_code === self::APPROVED);
615
-            $this->declined = ($this->response_code === self::DECLINED);
616
-            $this->error = ($this->response_code === self::ERROR);
617
-            $this->held = ($this->response_code === self::HELD);
618
-        } else {
619
-            $this->approved = false;
620
-            $this->error = true;
621
-            $this->error_message = esc_html__(
622
-                'Error connecting to Authorize.net',
623
-                'event_espresso'
624
-            );
625
-        }
626
-    }
464
+	const APPROVED = '1';
465
+	const DECLINED = '2';
466
+	const ERROR = '3';
467
+	const HELD = '4';
468
+
469
+	protected $_x_post_fields = array(
470
+		"version"        => "3.1",
471
+		"delim_char"     => ",",
472
+		"delim_data"     => "TRUE",
473
+		"relay_response" => "FALSE",
474
+		"encap_char"     => "|",
475
+	);
476
+	public $approved;
477
+	public $declined;
478
+	public $error;
479
+	public $held;
480
+	public $response_code;
481
+	public $response_subcode;
482
+	public $response_reason_code;
483
+	public $response_reason_text;
484
+	public $authorization_code;
485
+	public $avs_response;
486
+	public $transaction_id;
487
+	public $invoice_number;
488
+	public $description;
489
+	public $amount;
490
+	public $method;
491
+	public $transaction_type;
492
+	public $customer_id;
493
+	public $first_name;
494
+	public $last_name;
495
+	public $company;
496
+	public $address;
497
+	public $city;
498
+	public $state;
499
+	public $zip_code;
500
+	public $country;
501
+	public $phone;
502
+	public $fax;
503
+	public $email_address;
504
+	public $ship_to_first_name;
505
+	public $ship_to_last_name;
506
+	public $ship_to_company;
507
+	public $ship_to_address;
508
+	public $ship_to_city;
509
+	public $ship_to_state;
510
+	public $ship_to_zip_code;
511
+	public $ship_to_country;
512
+	public $tax;
513
+	public $duty;
514
+	public $freight;
515
+	public $tax_exempt;
516
+	public $purchase_order_number;
517
+	public $md5_hash;
518
+	public $card_code_response;
519
+	public $cavv_response; // cardholder_authentication_verification_response
520
+	public $account_number;
521
+	public $card_type;
522
+	public $split_tender_id;
523
+	public $requested_amount;
524
+	public $balance_on_card;
525
+	public $response; // The response string from AuthorizeNet.
526
+	public $error_message;
527
+	private $_response_array = array(); // An array with the split response.
528
+
529
+
530
+	/**
531
+	 * Constructor. Parses the AuthorizeNet response string
532
+	 *
533
+	 * @param string $response The response from the AuthNet server.
534
+	 * @var string   $delimiter The delimiter used (default is ",")
535
+	 * @var string   $encap_char The encap_char used (default is "|")
536
+	 * @var array    $custom_fields Any custom fields set in the request.
537
+	 */
538
+
539
+	public function __construct($response)
540
+	{
541
+		$encap_char = $this->_x_post_fields['encap_char'];
542
+		$delimiter = $this->_x_post_fields['delim_char'];
543
+		if ($response) {
544
+			// Split Array
545
+			$this->response = $response;
546
+			if ($encap_char) {
547
+				$this->_response_array = explode($encap_char . $delimiter . $encap_char, substr($response, 1, -1));
548
+			} else {
549
+				$this->_response_array = explode($delimiter, $response);
550
+			}
551
+
552
+			/**
553
+			 * If AuthorizeNet doesn't return a delimited response.
554
+			 */
555
+			if (count($this->_response_array) < 10) {
556
+				$this->approved = false;
557
+				$this->error = true;
558
+				$this->error_message = sprintf(
559
+					esc_html__('Unrecognized response from Authorize.net: %1$s', 'event_espresso'),
560
+					esc_html($response)
561
+				);
562
+				return;
563
+			}
564
+
565
+
566
+
567
+			// Set all fields
568
+			$this->response_code = $this->_response_array[0];
569
+			$this->response_subcode = $this->_response_array[1];
570
+			$this->response_reason_code = $this->_response_array[2];
571
+			$this->response_reason_text = $this->_response_array[3];
572
+			$this->authorization_code = $this->_response_array[4];
573
+			$this->avs_response = $this->_response_array[5];
574
+			$this->transaction_id = $this->_response_array[6];
575
+			$this->invoice_number = $this->_response_array[7];
576
+			$this->description = $this->_response_array[8];
577
+			$this->amount = $this->_response_array[9];
578
+			$this->method = $this->_response_array[10];
579
+			$this->transaction_type = $this->_response_array[11];
580
+			$this->customer_id = $this->_response_array[12];
581
+			$this->first_name = $this->_response_array[13];
582
+			$this->last_name = $this->_response_array[14];
583
+			$this->company = $this->_response_array[15];
584
+			$this->address = $this->_response_array[16];
585
+			$this->city = $this->_response_array[17];
586
+			$this->state = $this->_response_array[18];
587
+			$this->zip_code = $this->_response_array[19];
588
+			$this->country = $this->_response_array[20];
589
+			$this->phone = $this->_response_array[21];
590
+			$this->fax = $this->_response_array[22];
591
+			$this->email_address = $this->_response_array[23];
592
+			$this->ship_to_first_name = $this->_response_array[24];
593
+			$this->ship_to_last_name = $this->_response_array[25];
594
+			$this->ship_to_company = $this->_response_array[26];
595
+			$this->ship_to_address = $this->_response_array[27];
596
+			$this->ship_to_city = $this->_response_array[28];
597
+			$this->ship_to_state = $this->_response_array[29];
598
+			$this->ship_to_zip_code = $this->_response_array[30];
599
+			$this->ship_to_country = $this->_response_array[31];
600
+			$this->tax = $this->_response_array[32];
601
+			$this->duty = $this->_response_array[33];
602
+			$this->freight = $this->_response_array[34];
603
+			$this->tax_exempt = $this->_response_array[35];
604
+			$this->purchase_order_number = $this->_response_array[36];
605
+			$this->md5_hash = $this->_response_array[37];
606
+			$this->card_code_response = $this->_response_array[38];
607
+			$this->cavv_response = $this->_response_array[39];
608
+			$this->account_number = $this->_response_array[50];
609
+			$this->card_type = $this->_response_array[51];
610
+			$this->split_tender_id = $this->_response_array[52];
611
+			$this->requested_amount = $this->_response_array[53];
612
+			$this->balance_on_card = $this->_response_array[54];
613
+
614
+			$this->approved = ($this->response_code === self::APPROVED);
615
+			$this->declined = ($this->response_code === self::DECLINED);
616
+			$this->error = ($this->response_code === self::ERROR);
617
+			$this->held = ($this->response_code === self::HELD);
618
+		} else {
619
+			$this->approved = false;
620
+			$this->error = true;
621
+			$this->error_message = esc_html__(
622
+				'Error connecting to Authorize.net',
623
+				'event_espresso'
624
+			);
625
+		}
626
+	}
627 627
 }
628 628
 
629 629
 if (! class_exists('AuthorizeNetException')) {
630
-    /**
631
-     * Class AuthorizeNetException
632
-     *
633
-     * @package    AuthorizeNet
634
-     */
635
-    class AuthorizeNetException extends Exception
636
-    {
637
-
638
-        /**
639
-         * Construct the exception. Note: The message is NOT binary safe.
640
-         *
641
-         * @link http://php.net/manual/en/exception.construct.php
642
-         * @param string $message [optional] The Exception message to throw.
643
-         * @param int $code [optional] The Exception code.
644
-         * @param Exception $previous [optional] The previous exception used for the exception chaining. Since 5.3.0
645
-         * @since 5.1.0
646
-         */
647
-        public function __construct($message = "", $code = 0, Exception $previous = null)
648
-        {
649
-            parent::__construct($message, $code, $previous);
650
-        }
651
-    }
630
+	/**
631
+	 * Class AuthorizeNetException
632
+	 *
633
+	 * @package    AuthorizeNet
634
+	 */
635
+	class AuthorizeNetException extends Exception
636
+	{
637
+
638
+		/**
639
+		 * Construct the exception. Note: The message is NOT binary safe.
640
+		 *
641
+		 * @link http://php.net/manual/en/exception.construct.php
642
+		 * @param string $message [optional] The Exception message to throw.
643
+		 * @param int $code [optional] The Exception code.
644
+		 * @param Exception $previous [optional] The previous exception used for the exception chaining. Since 5.3.0
645
+		 * @since 5.1.0
646
+		 */
647
+		public function __construct($message = "", $code = 0, Exception $previous = null)
648
+		{
649
+			parent::__construct($message, $code, $previous);
650
+		}
651
+	}
652 652
 }
Please login to merge, or discard this patch.
core/domain/services/assets/CoreAssetManager.php 2 patches
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -238,7 +238,7 @@  discard block
 block discarded – undo
238 238
             //js.api
239 239
             $this->addJavascript(
240 240
                 CoreAssetManager::JS_HANDLE_EE_JS_API,
241
-                EE_LIBRARIES_URL . 'rest_api/assets/js/eejs-api.min.js',
241
+                EE_LIBRARIES_URL.'rest_api/assets/js/eejs-api.min.js',
242 242
                 array(
243 243
                     CoreAssetManager::JS_HANDLE_UNDERSCORE,
244 244
                     CoreAssetManager::JS_HANDLE_EE_JS_CORE
@@ -267,11 +267,11 @@  discard block
 block discarded – undo
267 267
 
268 268
         $this->addJavascript(
269 269
             CoreAssetManager::JS_HANDLE_EE_CORE,
270
-            EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js',
270
+            EE_GLOBAL_ASSETS_URL.'scripts/espresso_core.js',
271 271
             array(CoreAssetManager::JS_HANDLE_JQUERY)
272 272
         )
273 273
         ->setInlineDataCallback(
274
-            function () {
274
+            function() {
275 275
                 wp_localize_script(
276 276
                     CoreAssetManager::JS_HANDLE_EE_CORE,
277 277
                     CoreAssetManager::JS_HANDLE_EE_I18N,
@@ -340,16 +340,16 @@  discard block
 block discarded – undo
340 340
         if ($this->template_config->enable_default_style && ! is_admin()) {
341 341
             $this->addStylesheet(
342 342
                 CoreAssetManager::CSS_HANDLE_EE_DEFAULT,
343
-                is_readable(EVENT_ESPRESSO_UPLOAD_DIR . 'css/style.css')
343
+                is_readable(EVENT_ESPRESSO_UPLOAD_DIR.'css/style.css')
344 344
                     ? EVENT_ESPRESSO_UPLOAD_DIR . 'css/espresso_default.css'
345
-                    : EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css',
345
+                    : EE_GLOBAL_ASSETS_URL.'css/espresso_default.css',
346 346
                 array('dashicons')
347 347
             );
348 348
             //Load custom style sheet if available
349 349
             if ($this->template_config->custom_style_sheet !== null) {
350 350
                 $this->addStylesheet(
351 351
                     CoreAssetManager::CSS_HANDLE_EE_CUSTOM,
352
-                    EVENT_ESPRESSO_UPLOAD_URL . 'css/' . $this->template_config->custom_style_sheet,
352
+                    EVENT_ESPRESSO_UPLOAD_URL.'css/'.$this->template_config->custom_style_sheet,
353 353
                     array(CoreAssetManager::CSS_HANDLE_EE_DEFAULT)
354 354
                 );
355 355
             }
@@ -376,14 +376,14 @@  discard block
 block discarded – undo
376 376
     {
377 377
         $this->addJavascript(
378 378
             CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE,
379
-            EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.min.js',
379
+            EE_GLOBAL_ASSETS_URL.'scripts/jquery.validate.min.js',
380 380
             array(CoreAssetManager::JS_HANDLE_JQUERY)
381 381
         )
382 382
         ->setVersion('1.15.0');
383 383
 
384 384
         $this->addJavascript(
385 385
             CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE_EXTRA,
386
-            EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.additional-methods.min.js',
386
+            EE_GLOBAL_ASSETS_URL.'scripts/jquery.validate.additional-methods.min.js',
387 387
             array(CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE)
388 388
         )
389 389
         ->setVersion('1.15.0');
@@ -404,18 +404,18 @@  discard block
 block discarded – undo
404 404
         // @link http://josscrowcroft.github.io/accounting.js/
405 405
         $this->addJavascript(
406 406
             CoreAssetManager::JS_HANDLE_ACCOUNTING_CORE,
407
-            EE_THIRD_PARTY_URL . 'accounting/accounting.js',
407
+            EE_THIRD_PARTY_URL.'accounting/accounting.js',
408 408
             array(CoreAssetManager::JS_HANDLE_UNDERSCORE)
409 409
         )
410 410
         ->setVersion('0.3.2');
411 411
 
412 412
         $this->addJavascript(
413 413
             CoreAssetManager::JS_HANDLE_EE_ACCOUNTING,
414
-            EE_GLOBAL_ASSETS_URL . 'scripts/ee-accounting-config.js',
414
+            EE_GLOBAL_ASSETS_URL.'scripts/ee-accounting-config.js',
415 415
             array(CoreAssetManager::JS_HANDLE_ACCOUNTING_CORE)
416 416
         )
417 417
         ->setInlineDataCallback(
418
-            function () {
418
+            function() {
419 419
                  wp_localize_script(
420 420
                      CoreAssetManager::JS_HANDLE_EE_ACCOUNTING,
421 421
                      'EE_ACCOUNTING_CFG',
Please login to merge, or discard this patch.
Indentation   +428 added lines, -428 removed lines patch added patch discarded remove patch
@@ -29,449 +29,449 @@
 block discarded – undo
29 29
 class CoreAssetManager extends AssetManager
30 30
 {
31 31
 
32
-    // WordPress core / Third party JS asset handles
33
-    const JS_HANDLE_JQUERY = 'jquery';
32
+	// WordPress core / Third party JS asset handles
33
+	const JS_HANDLE_JQUERY = 'jquery';
34 34
 
35
-    const JS_HANDLE_JQUERY_VALIDATE = 'jquery-validate';
35
+	const JS_HANDLE_JQUERY_VALIDATE = 'jquery-validate';
36 36
 
37
-    const JS_HANDLE_JQUERY_VALIDATE_EXTRA = 'jquery-validate-extra-methods';
37
+	const JS_HANDLE_JQUERY_VALIDATE_EXTRA = 'jquery-validate-extra-methods';
38 38
 
39
-    const JS_HANDLE_UNDERSCORE = 'underscore';
39
+	const JS_HANDLE_UNDERSCORE = 'underscore';
40 40
 
41
-    const JS_HANDLE_ACCOUNTING_CORE = 'ee-accounting-core';
41
+	const JS_HANDLE_ACCOUNTING_CORE = 'ee-accounting-core';
42 42
 
43
-    // EE JS assets handles
44
-    const JS_HANDLE_EE_MANIFEST = 'ee-manifest';
43
+	// EE JS assets handles
44
+	const JS_HANDLE_EE_MANIFEST = 'ee-manifest';
45 45
 
46
-    const JS_HANDLE_EE_JS_CORE = 'eejs-core';
46
+	const JS_HANDLE_EE_JS_CORE = 'eejs-core';
47 47
 
48
-    const JS_HANDLE_EE_VENDOR = 'eventespresso-vendor';
48
+	const JS_HANDLE_EE_VENDOR = 'eventespresso-vendor';
49 49
 
50
-    const JS_HANDLE_EE_DATA_STORES = 'eventespresso-data-stores';
50
+	const JS_HANDLE_EE_DATA_STORES = 'eventespresso-data-stores';
51 51
 
52
-    const JS_HANDLE_EE_HELPERS = 'eventespresso-helpers';
52
+	const JS_HANDLE_EE_HELPERS = 'eventespresso-helpers';
53 53
 
54
-    const JS_HANDLE_EE_MODEL = 'eventespresso-model';
54
+	const JS_HANDLE_EE_MODEL = 'eventespresso-model';
55 55
 
56
-    const JS_HANDLE_EE_VALUE_OBJECTS = 'eventespresso-value-objects';
56
+	const JS_HANDLE_EE_VALUE_OBJECTS = 'eventespresso-value-objects';
57 57
 
58
-    const JS_HANDLE_EE_HOC_COMPONENTS = 'eventespresso-hoc-components';
58
+	const JS_HANDLE_EE_HOC_COMPONENTS = 'eventespresso-hoc-components';
59 59
 
60
-    const JS_HANDLE_EE_COMPONENTS = 'eventespresso-components';
60
+	const JS_HANDLE_EE_COMPONENTS = 'eventespresso-components';
61 61
 
62
-    const JS_HANDLE_EE_JS_API = 'eejs-api';
62
+	const JS_HANDLE_EE_JS_API = 'eejs-api';
63 63
 
64
-    const JS_HANDLE_EE_CORE = 'espresso_core';
64
+	const JS_HANDLE_EE_CORE = 'espresso_core';
65 65
 
66
-    const JS_HANDLE_EE_I18N = 'eei18n';
67
-
68
-    const JS_HANDLE_EE_ACCOUNTING = 'ee-accounting';
69
-
70
-    const JS_HANDLE_EE_WP_PLUGINS_PAGE = 'ee-wp-plugins-page';
71
-
72
-    // EE CSS assets handles
73
-    const CSS_HANDLE_EE_DEFAULT = 'espresso_default';
74
-
75
-    const CSS_HANDLE_EE_CUSTOM = 'espresso_custom_css';
76
-
77
-    const CSS_HANDLE_EE_COMPONENTS = 'eventespresso-components';
78
-
79
-    /**
80
-     * @var EE_Currency_Config $currency_config
81
-     */
82
-    protected $currency_config;
83
-
84
-    /**
85
-     * @var EE_Template_Config $template_config
86
-     */
87
-    protected $template_config;
88
-
89
-
90
-    /**
91
-     * CoreAssetRegister constructor.
92
-     *
93
-     * @param AssetCollection    $assets
94
-     * @param EE_Currency_Config $currency_config
95
-     * @param EE_Template_Config $template_config
96
-     * @param DomainInterface    $domain
97
-     * @param Registry           $registry
98
-     */
99
-    public function __construct(
100
-        AssetCollection $assets,
101
-        EE_Currency_Config $currency_config,
102
-        EE_Template_Config $template_config,
103
-        DomainInterface $domain,
104
-        Registry $registry
105
-    ) {
106
-        $this->currency_config = $currency_config;
107
-        $this->template_config = $template_config;
108
-        parent::__construct($domain, $assets, $registry);
109
-    }
110
-
111
-
112
-    /**
113
-     * @since 4.9.62.p
114
-     * @throws DuplicateCollectionIdentifierException
115
-     * @throws InvalidArgumentException
116
-     * @throws InvalidDataTypeException
117
-     * @throws InvalidEntityException
118
-     */
119
-    public function addAssets()
120
-    {
121
-        $this->addJavascriptFiles();
122
-        $this->addStylesheetFiles();
123
-    }
124
-
125
-
126
-    /**
127
-     * @since 4.9.62.p
128
-     * @throws DuplicateCollectionIdentifierException
129
-     * @throws InvalidArgumentException
130
-     * @throws InvalidDataTypeException
131
-     * @throws InvalidEntityException
132
-     */
133
-    public function addJavascriptFiles()
134
-    {
135
-        $this->loadCoreJs();
136
-        $this->loadJqueryValidate();
137
-        $this->loadAccountingJs();
138
-        add_action(
139
-            'AHEE__EventEspresso_core_services_assets_Registry__registerScripts__before_script',
140
-            array($this, 'loadQtipJs')
141
-        );
142
-        $this->registerAdminAssets();
143
-    }
144
-
145
-
146
-    /**
147
-     * @since 4.9.62.p
148
-     * @throws DuplicateCollectionIdentifierException
149
-     * @throws InvalidDataTypeException
150
-     * @throws InvalidEntityException
151
-     */
152
-    public function addStylesheetFiles()
153
-    {
154
-        $this->loadCoreCss();
155
-    }
156
-
157
-
158
-    /**
159
-     * core default javascript
160
-     *
161
-     * @since 4.9.62.p
162
-     * @throws DuplicateCollectionIdentifierException
163
-     * @throws InvalidArgumentException
164
-     * @throws InvalidDataTypeException
165
-     * @throws InvalidEntityException
166
-     */
167
-    private function loadCoreJs()
168
-    {
169
-        $this->addJavascript(
170
-            CoreAssetManager::JS_HANDLE_EE_MANIFEST,
171
-            $this->registry->getJsUrl($this->domain->assetNamespace(), 'manifest')
172
-        );
173
-
174
-        $this->addJavascript(
175
-            CoreAssetManager::JS_HANDLE_EE_JS_CORE,
176
-            $this->registry->getJsUrl($this->domain->assetNamespace(), 'eejs'),
177
-            array(CoreAssetManager::JS_HANDLE_EE_MANIFEST)
178
-        )
179
-        ->setHasInlineData();
180
-
181
-        $this->addJavascript(
182
-            CoreAssetManager::JS_HANDLE_EE_VENDOR,
183
-            $this->registry->getJsUrl($this->domain->assetNamespace(), 'vendor'),
184
-            array(CoreAssetManager::JS_HANDLE_EE_JS_CORE)
185
-        );
186
-
187
-        $this->addJavascript(
188
-            CoreAssetManager::JS_HANDLE_EE_DATA_STORES,
189
-            $this->registry->getJsUrl($this->domain->assetNamespace(), 'data-stores'),
190
-            array(CoreAssetManager::JS_HANDLE_EE_VENDOR, 'wp-data', 'wp-api-request')
191
-        )
192
-        ->setRequiresTranslation();
193
-
194
-        $this->addJavascript(
195
-            CoreAssetManager::JS_HANDLE_EE_HELPERS,
196
-            $this->registry->getJsUrl($this->domain->assetNamespace(), 'helpers')
197
-        )->setRequiresTranslation();
198
-
199
-        $this->addJavascript(
200
-            CoreAssetManager::JS_HANDLE_EE_MODEL,
201
-            $this->registry->getJsUrl($this->domain->assetNamespace(), 'model'),
202
-            array(
203
-                CoreAssetManager::JS_HANDLE_EE_HELPERS
204
-            )
205
-        )->setRequiresTranslation();
206
-
207
-        $this->addJavascript(
208
-            CoreAssetManager::JS_HANDLE_EE_VALUE_OBJECTS,
209
-            $this->registry->getJsUrl($this->domain->assetNamespace(), 'valueObjects'),
210
-            array(
211
-                CoreAssetManager::JS_HANDLE_EE_MODEL
212
-            )
213
-        )->setRequiresTranslation();
214
-
215
-        $this->addJavascript(
216
-            CoreAssetManager::JS_HANDLE_EE_HOC_COMPONENTS,
217
-            $this->registry->getJsUrl($this->domain->assetNamespace(), 'hocComponents'),
218
-            array(
219
-                CoreAssetManager::JS_HANDLE_EE_DATA_STORES,
220
-                CoreAssetManager::JS_HANDLE_EE_VALUE_OBJECTS,
221
-                'wp-components',
222
-            )
223
-        )->setRequiresTranslation();
224
-
225
-        $this->addJavascript(
226
-            CoreAssetManager::JS_HANDLE_EE_COMPONENTS,
227
-            $this->registry->getJsUrl($this->domain->assetNamespace(), 'components'),
228
-            array(
229
-                CoreAssetManager::JS_HANDLE_EE_DATA_STORES,
230
-                CoreAssetManager::JS_HANDLE_EE_VALUE_OBJECTS,
231
-                'wp-components',
232
-            )
233
-        )
234
-        ->setRequiresTranslation();
235
-
236
-        global $wp_version;
237
-        if (version_compare($wp_version, '4.4.0', '>')) {
238
-            //js.api
239
-            $this->addJavascript(
240
-                CoreAssetManager::JS_HANDLE_EE_JS_API,
241
-                EE_LIBRARIES_URL . 'rest_api/assets/js/eejs-api.min.js',
242
-                array(
243
-                    CoreAssetManager::JS_HANDLE_UNDERSCORE,
244
-                    CoreAssetManager::JS_HANDLE_EE_JS_CORE
245
-                )
246
-            );
247
-            $this->registry->addData('eejs_api_nonce', wp_create_nonce('wp_rest'));
248
-            $this->registry->addData(
249
-                'paths',
250
-                array(
251
-                    'rest_route' => rest_url('ee/v4.8.36/'),
252
-                    'collection_endpoints' => EED_Core_Rest_Api::getCollectionRoutesIndexedByModelName(),
253
-                    'primary_keys' => EED_Core_Rest_Api::getPrimaryKeyNamesIndexedByModelName(),
66
+	const JS_HANDLE_EE_I18N = 'eei18n';
67
+
68
+	const JS_HANDLE_EE_ACCOUNTING = 'ee-accounting';
69
+
70
+	const JS_HANDLE_EE_WP_PLUGINS_PAGE = 'ee-wp-plugins-page';
71
+
72
+	// EE CSS assets handles
73
+	const CSS_HANDLE_EE_DEFAULT = 'espresso_default';
74
+
75
+	const CSS_HANDLE_EE_CUSTOM = 'espresso_custom_css';
76
+
77
+	const CSS_HANDLE_EE_COMPONENTS = 'eventespresso-components';
78
+
79
+	/**
80
+	 * @var EE_Currency_Config $currency_config
81
+	 */
82
+	protected $currency_config;
83
+
84
+	/**
85
+	 * @var EE_Template_Config $template_config
86
+	 */
87
+	protected $template_config;
88
+
89
+
90
+	/**
91
+	 * CoreAssetRegister constructor.
92
+	 *
93
+	 * @param AssetCollection    $assets
94
+	 * @param EE_Currency_Config $currency_config
95
+	 * @param EE_Template_Config $template_config
96
+	 * @param DomainInterface    $domain
97
+	 * @param Registry           $registry
98
+	 */
99
+	public function __construct(
100
+		AssetCollection $assets,
101
+		EE_Currency_Config $currency_config,
102
+		EE_Template_Config $template_config,
103
+		DomainInterface $domain,
104
+		Registry $registry
105
+	) {
106
+		$this->currency_config = $currency_config;
107
+		$this->template_config = $template_config;
108
+		parent::__construct($domain, $assets, $registry);
109
+	}
110
+
111
+
112
+	/**
113
+	 * @since 4.9.62.p
114
+	 * @throws DuplicateCollectionIdentifierException
115
+	 * @throws InvalidArgumentException
116
+	 * @throws InvalidDataTypeException
117
+	 * @throws InvalidEntityException
118
+	 */
119
+	public function addAssets()
120
+	{
121
+		$this->addJavascriptFiles();
122
+		$this->addStylesheetFiles();
123
+	}
124
+
125
+
126
+	/**
127
+	 * @since 4.9.62.p
128
+	 * @throws DuplicateCollectionIdentifierException
129
+	 * @throws InvalidArgumentException
130
+	 * @throws InvalidDataTypeException
131
+	 * @throws InvalidEntityException
132
+	 */
133
+	public function addJavascriptFiles()
134
+	{
135
+		$this->loadCoreJs();
136
+		$this->loadJqueryValidate();
137
+		$this->loadAccountingJs();
138
+		add_action(
139
+			'AHEE__EventEspresso_core_services_assets_Registry__registerScripts__before_script',
140
+			array($this, 'loadQtipJs')
141
+		);
142
+		$this->registerAdminAssets();
143
+	}
144
+
145
+
146
+	/**
147
+	 * @since 4.9.62.p
148
+	 * @throws DuplicateCollectionIdentifierException
149
+	 * @throws InvalidDataTypeException
150
+	 * @throws InvalidEntityException
151
+	 */
152
+	public function addStylesheetFiles()
153
+	{
154
+		$this->loadCoreCss();
155
+	}
156
+
157
+
158
+	/**
159
+	 * core default javascript
160
+	 *
161
+	 * @since 4.9.62.p
162
+	 * @throws DuplicateCollectionIdentifierException
163
+	 * @throws InvalidArgumentException
164
+	 * @throws InvalidDataTypeException
165
+	 * @throws InvalidEntityException
166
+	 */
167
+	private function loadCoreJs()
168
+	{
169
+		$this->addJavascript(
170
+			CoreAssetManager::JS_HANDLE_EE_MANIFEST,
171
+			$this->registry->getJsUrl($this->domain->assetNamespace(), 'manifest')
172
+		);
173
+
174
+		$this->addJavascript(
175
+			CoreAssetManager::JS_HANDLE_EE_JS_CORE,
176
+			$this->registry->getJsUrl($this->domain->assetNamespace(), 'eejs'),
177
+			array(CoreAssetManager::JS_HANDLE_EE_MANIFEST)
178
+		)
179
+		->setHasInlineData();
180
+
181
+		$this->addJavascript(
182
+			CoreAssetManager::JS_HANDLE_EE_VENDOR,
183
+			$this->registry->getJsUrl($this->domain->assetNamespace(), 'vendor'),
184
+			array(CoreAssetManager::JS_HANDLE_EE_JS_CORE)
185
+		);
186
+
187
+		$this->addJavascript(
188
+			CoreAssetManager::JS_HANDLE_EE_DATA_STORES,
189
+			$this->registry->getJsUrl($this->domain->assetNamespace(), 'data-stores'),
190
+			array(CoreAssetManager::JS_HANDLE_EE_VENDOR, 'wp-data', 'wp-api-request')
191
+		)
192
+		->setRequiresTranslation();
193
+
194
+		$this->addJavascript(
195
+			CoreAssetManager::JS_HANDLE_EE_HELPERS,
196
+			$this->registry->getJsUrl($this->domain->assetNamespace(), 'helpers')
197
+		)->setRequiresTranslation();
198
+
199
+		$this->addJavascript(
200
+			CoreAssetManager::JS_HANDLE_EE_MODEL,
201
+			$this->registry->getJsUrl($this->domain->assetNamespace(), 'model'),
202
+			array(
203
+				CoreAssetManager::JS_HANDLE_EE_HELPERS
204
+			)
205
+		)->setRequiresTranslation();
206
+
207
+		$this->addJavascript(
208
+			CoreAssetManager::JS_HANDLE_EE_VALUE_OBJECTS,
209
+			$this->registry->getJsUrl($this->domain->assetNamespace(), 'valueObjects'),
210
+			array(
211
+				CoreAssetManager::JS_HANDLE_EE_MODEL
212
+			)
213
+		)->setRequiresTranslation();
214
+
215
+		$this->addJavascript(
216
+			CoreAssetManager::JS_HANDLE_EE_HOC_COMPONENTS,
217
+			$this->registry->getJsUrl($this->domain->assetNamespace(), 'hocComponents'),
218
+			array(
219
+				CoreAssetManager::JS_HANDLE_EE_DATA_STORES,
220
+				CoreAssetManager::JS_HANDLE_EE_VALUE_OBJECTS,
221
+				'wp-components',
222
+			)
223
+		)->setRequiresTranslation();
224
+
225
+		$this->addJavascript(
226
+			CoreAssetManager::JS_HANDLE_EE_COMPONENTS,
227
+			$this->registry->getJsUrl($this->domain->assetNamespace(), 'components'),
228
+			array(
229
+				CoreAssetManager::JS_HANDLE_EE_DATA_STORES,
230
+				CoreAssetManager::JS_HANDLE_EE_VALUE_OBJECTS,
231
+				'wp-components',
232
+			)
233
+		)
234
+		->setRequiresTranslation();
235
+
236
+		global $wp_version;
237
+		if (version_compare($wp_version, '4.4.0', '>')) {
238
+			//js.api
239
+			$this->addJavascript(
240
+				CoreAssetManager::JS_HANDLE_EE_JS_API,
241
+				EE_LIBRARIES_URL . 'rest_api/assets/js/eejs-api.min.js',
242
+				array(
243
+					CoreAssetManager::JS_HANDLE_UNDERSCORE,
244
+					CoreAssetManager::JS_HANDLE_EE_JS_CORE
245
+				)
246
+			);
247
+			$this->registry->addData('eejs_api_nonce', wp_create_nonce('wp_rest'));
248
+			$this->registry->addData(
249
+				'paths',
250
+				array(
251
+					'rest_route' => rest_url('ee/v4.8.36/'),
252
+					'collection_endpoints' => EED_Core_Rest_Api::getCollectionRoutesIndexedByModelName(),
253
+					'primary_keys' => EED_Core_Rest_Api::getPrimaryKeyNamesIndexedByModelName(),
254 254
 					'site_url' => site_url('/'),
255
-                    'admin_url' => admin_url('/'),
256
-                )
257
-            );
258
-            /** site formatting values **/
259
-            $this->registry->addData(
260
-                'site_formats',
261
-                array(
262
-                    'date_formats' => EEH_DTT_Helper::convert_php_to_js_and_moment_date_formats()
263
-                )
264
-            );
265
-            /** currency data **/
266
-            $this->registry->addData(
267
-                'currency_config',
268
-                $this->getCurrencySettings()
269
-            );
270
-        }
271
-
272
-        $this->addJavascript(
273
-            CoreAssetManager::JS_HANDLE_EE_CORE,
274
-            EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js',
275
-            array(CoreAssetManager::JS_HANDLE_JQUERY)
276
-        )
277
-        ->setInlineDataCallback(
278
-            function () {
279
-                wp_localize_script(
280
-                    CoreAssetManager::JS_HANDLE_EE_CORE,
281
-                    CoreAssetManager::JS_HANDLE_EE_I18N,
282
-                    EE_Registry::$i18n_js_strings
283
-                );
284
-            }
285
-        );
286
-    }
287
-
288
-
289
-    /**
290
-     * Returns configuration data for the accounting-js library.
291
-     * @since $VID:$
292
-     * @return array
293
-     */
294
-    private function getAccountingSettings() {
295
-        return array(
296
-            'currency' => array(
297
-                'symbol'    => $this->currency_config->sign,
298
-                'format'    => array(
299
-                    'pos'  => $this->currency_config->sign_b4 ? '%s%v' : '%v%s',
300
-                    'neg'  => $this->currency_config->sign_b4 ? '- %s%v' : '- %v%s',
301
-                    'zero' => $this->currency_config->sign_b4 ? '%s--' : '--%s',
302
-                ),
303
-                'decimal'   => $this->currency_config->dec_mrk,
304
-                'thousand'  => $this->currency_config->thsnds,
305
-                'precision' => $this->currency_config->dec_plc,
306
-            ),
307
-            'number'   => array(
308
-                'precision' => $this->currency_config->dec_plc,
309
-                'thousand'  => $this->currency_config->thsnds,
310
-                'decimal'   => $this->currency_config->dec_mrk,
311
-            ),
312
-        );
313
-    }
314
-
315
-
316
-    /**
317
-     * Returns configuration data for the js Currency VO.
318
-     * @sinc $VID:$
319
-     * @return array
320
-     */
321
-    private function getCurrencySettings()
322
-    {
323
-        return array(
324
-            'code' => $this->currency_config->code,
325
-            'singularLabel' => $this->currency_config->name,
326
-            'pluralLabel' => $this->currency_config->plural,
327
-            'sign' => $this->currency_config->sign,
328
-            'signB4' => $this->currency_config->sign_b4,
329
-            'decimalPlaces' => $this->currency_config->dec_plc,
330
-            'decimalMark' => $this->currency_config->dec_mrk,
331
-            'thousandsSeparator' => $this->currency_config->thsnds,
332
-        );
333
-    }
334
-
335
-
336
-    /**
337
-     * @since 4.9.62.p
338
-     * @throws DuplicateCollectionIdentifierException
339
-     * @throws InvalidDataTypeException
340
-     * @throws InvalidEntityException
341
-     */
342
-    private function loadCoreCss()
343
-    {
344
-        if ($this->template_config->enable_default_style && ! is_admin()) {
345
-            $this->addStylesheet(
346
-                CoreAssetManager::CSS_HANDLE_EE_DEFAULT,
347
-                is_readable(EVENT_ESPRESSO_UPLOAD_DIR . 'css/style.css')
348
-                    ? EVENT_ESPRESSO_UPLOAD_DIR . 'css/espresso_default.css'
349
-                    : EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css',
350
-                array('dashicons')
351
-            );
352
-            //Load custom style sheet if available
353
-            if ($this->template_config->custom_style_sheet !== null) {
354
-                $this->addStylesheet(
355
-                    CoreAssetManager::CSS_HANDLE_EE_CUSTOM,
356
-                    EVENT_ESPRESSO_UPLOAD_URL . 'css/' . $this->template_config->custom_style_sheet,
357
-                    array(CoreAssetManager::CSS_HANDLE_EE_DEFAULT)
358
-                );
359
-            }
360
-        }
361
-        $this->addStylesheet(
362
-            CoreAssetManager::CSS_HANDLE_EE_COMPONENTS,
363
-            $this->registry->getCssUrl(
364
-                $this->domain->assetNamespace(),
365
-                'components'
366
-            )
367
-        );
368
-    }
369
-
370
-
371
-    /**
372
-     * jQuery Validate for form validation
373
-     *
374
-     * @since 4.9.62.p
375
-     * @throws DuplicateCollectionIdentifierException
376
-     * @throws InvalidDataTypeException
377
-     * @throws InvalidEntityException
378
-     */
379
-    private function loadJqueryValidate()
380
-    {
381
-        $this->addJavascript(
382
-            CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE,
383
-            EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.min.js',
384
-            array(CoreAssetManager::JS_HANDLE_JQUERY)
385
-        )
386
-        ->setVersion('1.15.0');
387
-
388
-        $this->addJavascript(
389
-            CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE_EXTRA,
390
-            EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.additional-methods.min.js',
391
-            array(CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE)
392
-        )
393
-        ->setVersion('1.15.0');
394
-    }
395
-
396
-
397
-    /**
398
-     * accounting.js for performing client-side calculations
399
-     *
400
-     * @since 4.9.62.p
401
-     * @throws DuplicateCollectionIdentifierException
402
-     * @throws InvalidDataTypeException
403
-     * @throws InvalidEntityException
404
-     */
405
-    private function loadAccountingJs()
406
-    {
407
-        //accounting.js library
408
-        // @link http://josscrowcroft.github.io/accounting.js/
409
-        $this->addJavascript(
410
-            CoreAssetManager::JS_HANDLE_ACCOUNTING_CORE,
411
-            EE_THIRD_PARTY_URL . 'accounting/accounting.js',
412
-            array(CoreAssetManager::JS_HANDLE_UNDERSCORE)
413
-        )
414
-        ->setVersion('0.3.2');
415
-
416
-        $this->addJavascript(
417
-            CoreAssetManager::JS_HANDLE_EE_ACCOUNTING,
418
-            EE_GLOBAL_ASSETS_URL . 'scripts/ee-accounting-config.js',
419
-            array(CoreAssetManager::JS_HANDLE_ACCOUNTING_CORE)
420
-        )
421
-        ->setInlineDataCallback(
422
-            function () {
423
-                 wp_localize_script(
424
-                     CoreAssetManager::JS_HANDLE_EE_ACCOUNTING,
425
-                     'EE_ACCOUNTING_CFG',
426
-                     $this->getAccountingSettings()
427
-                 );
428
-            }
429
-        )
430
-        ->setVersion();
431
-    }
432
-
433
-
434
-    /**
435
-     * registers assets for cleaning your ears
436
-     *
437
-     * @param JavascriptAsset $script
438
-     */
439
-    public function loadQtipJs(JavascriptAsset $script)
440
-    {
441
-        // qtip is turned OFF by default, but prior to the wp_enqueue_scripts hook,
442
-        // can be turned back on again via: add_filter('FHEE_load_qtip', '__return_true' );
443
-        if (
444
-            $script->handle() === CoreAssetManager::JS_HANDLE_EE_WP_PLUGINS_PAGE
445
-            && apply_filters('FHEE_load_qtip', false)
446
-        ) {
447
-            EEH_Qtip_Loader::instance()->register_and_enqueue();
448
-        }
449
-    }
450
-
451
-
452
-    /**
453
-     * assets that are used in the WordPress admin
454
-     *
455
-     * @since 4.9.62.p
456
-     * @throws DuplicateCollectionIdentifierException
457
-     * @throws InvalidDataTypeException
458
-     * @throws InvalidEntityException
459
-     */
460
-    private function registerAdminAssets()
461
-    {
462
-        $this->addJavascript(
463
-            CoreAssetManager::JS_HANDLE_EE_WP_PLUGINS_PAGE,
464
-            $this->registry->getJsUrl($this->domain->assetNamespace(), 'wp-plugins-page'),
465
-            array(
466
-                CoreAssetManager::JS_HANDLE_JQUERY,
467
-                CoreAssetManager::JS_HANDLE_EE_VENDOR,
468
-            )
469
-        )
470
-        ->setRequiresTranslation();
471
-
472
-        $this->addStylesheet(
473
-            CoreAssetManager::JS_HANDLE_EE_WP_PLUGINS_PAGE,
474
-            $this->registry->getCssUrl($this->domain->assetNamespace(), 'wp-plugins-page')
475
-        );
476
-    }
255
+					'admin_url' => admin_url('/'),
256
+				)
257
+			);
258
+			/** site formatting values **/
259
+			$this->registry->addData(
260
+				'site_formats',
261
+				array(
262
+					'date_formats' => EEH_DTT_Helper::convert_php_to_js_and_moment_date_formats()
263
+				)
264
+			);
265
+			/** currency data **/
266
+			$this->registry->addData(
267
+				'currency_config',
268
+				$this->getCurrencySettings()
269
+			);
270
+		}
271
+
272
+		$this->addJavascript(
273
+			CoreAssetManager::JS_HANDLE_EE_CORE,
274
+			EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js',
275
+			array(CoreAssetManager::JS_HANDLE_JQUERY)
276
+		)
277
+		->setInlineDataCallback(
278
+			function () {
279
+				wp_localize_script(
280
+					CoreAssetManager::JS_HANDLE_EE_CORE,
281
+					CoreAssetManager::JS_HANDLE_EE_I18N,
282
+					EE_Registry::$i18n_js_strings
283
+				);
284
+			}
285
+		);
286
+	}
287
+
288
+
289
+	/**
290
+	 * Returns configuration data for the accounting-js library.
291
+	 * @since $VID:$
292
+	 * @return array
293
+	 */
294
+	private function getAccountingSettings() {
295
+		return array(
296
+			'currency' => array(
297
+				'symbol'    => $this->currency_config->sign,
298
+				'format'    => array(
299
+					'pos'  => $this->currency_config->sign_b4 ? '%s%v' : '%v%s',
300
+					'neg'  => $this->currency_config->sign_b4 ? '- %s%v' : '- %v%s',
301
+					'zero' => $this->currency_config->sign_b4 ? '%s--' : '--%s',
302
+				),
303
+				'decimal'   => $this->currency_config->dec_mrk,
304
+				'thousand'  => $this->currency_config->thsnds,
305
+				'precision' => $this->currency_config->dec_plc,
306
+			),
307
+			'number'   => array(
308
+				'precision' => $this->currency_config->dec_plc,
309
+				'thousand'  => $this->currency_config->thsnds,
310
+				'decimal'   => $this->currency_config->dec_mrk,
311
+			),
312
+		);
313
+	}
314
+
315
+
316
+	/**
317
+	 * Returns configuration data for the js Currency VO.
318
+	 * @sinc $VID:$
319
+	 * @return array
320
+	 */
321
+	private function getCurrencySettings()
322
+	{
323
+		return array(
324
+			'code' => $this->currency_config->code,
325
+			'singularLabel' => $this->currency_config->name,
326
+			'pluralLabel' => $this->currency_config->plural,
327
+			'sign' => $this->currency_config->sign,
328
+			'signB4' => $this->currency_config->sign_b4,
329
+			'decimalPlaces' => $this->currency_config->dec_plc,
330
+			'decimalMark' => $this->currency_config->dec_mrk,
331
+			'thousandsSeparator' => $this->currency_config->thsnds,
332
+		);
333
+	}
334
+
335
+
336
+	/**
337
+	 * @since 4.9.62.p
338
+	 * @throws DuplicateCollectionIdentifierException
339
+	 * @throws InvalidDataTypeException
340
+	 * @throws InvalidEntityException
341
+	 */
342
+	private function loadCoreCss()
343
+	{
344
+		if ($this->template_config->enable_default_style && ! is_admin()) {
345
+			$this->addStylesheet(
346
+				CoreAssetManager::CSS_HANDLE_EE_DEFAULT,
347
+				is_readable(EVENT_ESPRESSO_UPLOAD_DIR . 'css/style.css')
348
+					? EVENT_ESPRESSO_UPLOAD_DIR . 'css/espresso_default.css'
349
+					: EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css',
350
+				array('dashicons')
351
+			);
352
+			//Load custom style sheet if available
353
+			if ($this->template_config->custom_style_sheet !== null) {
354
+				$this->addStylesheet(
355
+					CoreAssetManager::CSS_HANDLE_EE_CUSTOM,
356
+					EVENT_ESPRESSO_UPLOAD_URL . 'css/' . $this->template_config->custom_style_sheet,
357
+					array(CoreAssetManager::CSS_HANDLE_EE_DEFAULT)
358
+				);
359
+			}
360
+		}
361
+		$this->addStylesheet(
362
+			CoreAssetManager::CSS_HANDLE_EE_COMPONENTS,
363
+			$this->registry->getCssUrl(
364
+				$this->domain->assetNamespace(),
365
+				'components'
366
+			)
367
+		);
368
+	}
369
+
370
+
371
+	/**
372
+	 * jQuery Validate for form validation
373
+	 *
374
+	 * @since 4.9.62.p
375
+	 * @throws DuplicateCollectionIdentifierException
376
+	 * @throws InvalidDataTypeException
377
+	 * @throws InvalidEntityException
378
+	 */
379
+	private function loadJqueryValidate()
380
+	{
381
+		$this->addJavascript(
382
+			CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE,
383
+			EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.min.js',
384
+			array(CoreAssetManager::JS_HANDLE_JQUERY)
385
+		)
386
+		->setVersion('1.15.0');
387
+
388
+		$this->addJavascript(
389
+			CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE_EXTRA,
390
+			EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.additional-methods.min.js',
391
+			array(CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE)
392
+		)
393
+		->setVersion('1.15.0');
394
+	}
395
+
396
+
397
+	/**
398
+	 * accounting.js for performing client-side calculations
399
+	 *
400
+	 * @since 4.9.62.p
401
+	 * @throws DuplicateCollectionIdentifierException
402
+	 * @throws InvalidDataTypeException
403
+	 * @throws InvalidEntityException
404
+	 */
405
+	private function loadAccountingJs()
406
+	{
407
+		//accounting.js library
408
+		// @link http://josscrowcroft.github.io/accounting.js/
409
+		$this->addJavascript(
410
+			CoreAssetManager::JS_HANDLE_ACCOUNTING_CORE,
411
+			EE_THIRD_PARTY_URL . 'accounting/accounting.js',
412
+			array(CoreAssetManager::JS_HANDLE_UNDERSCORE)
413
+		)
414
+		->setVersion('0.3.2');
415
+
416
+		$this->addJavascript(
417
+			CoreAssetManager::JS_HANDLE_EE_ACCOUNTING,
418
+			EE_GLOBAL_ASSETS_URL . 'scripts/ee-accounting-config.js',
419
+			array(CoreAssetManager::JS_HANDLE_ACCOUNTING_CORE)
420
+		)
421
+		->setInlineDataCallback(
422
+			function () {
423
+				 wp_localize_script(
424
+					 CoreAssetManager::JS_HANDLE_EE_ACCOUNTING,
425
+					 'EE_ACCOUNTING_CFG',
426
+					 $this->getAccountingSettings()
427
+				 );
428
+			}
429
+		)
430
+		->setVersion();
431
+	}
432
+
433
+
434
+	/**
435
+	 * registers assets for cleaning your ears
436
+	 *
437
+	 * @param JavascriptAsset $script
438
+	 */
439
+	public function loadQtipJs(JavascriptAsset $script)
440
+	{
441
+		// qtip is turned OFF by default, but prior to the wp_enqueue_scripts hook,
442
+		// can be turned back on again via: add_filter('FHEE_load_qtip', '__return_true' );
443
+		if (
444
+			$script->handle() === CoreAssetManager::JS_HANDLE_EE_WP_PLUGINS_PAGE
445
+			&& apply_filters('FHEE_load_qtip', false)
446
+		) {
447
+			EEH_Qtip_Loader::instance()->register_and_enqueue();
448
+		}
449
+	}
450
+
451
+
452
+	/**
453
+	 * assets that are used in the WordPress admin
454
+	 *
455
+	 * @since 4.9.62.p
456
+	 * @throws DuplicateCollectionIdentifierException
457
+	 * @throws InvalidDataTypeException
458
+	 * @throws InvalidEntityException
459
+	 */
460
+	private function registerAdminAssets()
461
+	{
462
+		$this->addJavascript(
463
+			CoreAssetManager::JS_HANDLE_EE_WP_PLUGINS_PAGE,
464
+			$this->registry->getJsUrl($this->domain->assetNamespace(), 'wp-plugins-page'),
465
+			array(
466
+				CoreAssetManager::JS_HANDLE_JQUERY,
467
+				CoreAssetManager::JS_HANDLE_EE_VENDOR,
468
+			)
469
+		)
470
+		->setRequiresTranslation();
471
+
472
+		$this->addStylesheet(
473
+			CoreAssetManager::JS_HANDLE_EE_WP_PLUGINS_PAGE,
474
+			$this->registry->getCssUrl($this->domain->assetNamespace(), 'wp-plugins-page')
475
+		);
476
+	}
477 477
 }
Please login to merge, or discard this patch.
public/template_tags.php 1 patch
Spacing   +291 added lines, -291 removed lines patch added patch discarded remove patch
@@ -14,12 +14,12 @@  discard block
 block discarded – undo
14 14
  * @param int | \EE_Event $event
15 15
  * @return bool
16 16
  */
17
-function is_espresso_event( $event = NULL ) {
18
-	if ( can_use_espresso_conditionals( __FUNCTION__ )) {
17
+function is_espresso_event($event = NULL) {
18
+	if (can_use_espresso_conditionals(__FUNCTION__)) {
19 19
 		// extract EE_Event object from passed param regardless of what it is (within reason of course)
20
-		$event = EEH_Event_View::get_event( $event );
20
+		$event = EEH_Event_View::get_event($event);
21 21
 		// do we have a valid event ?
22
-		return $event instanceof EE_Event  ? TRUE : FALSE;
22
+		return $event instanceof EE_Event ? TRUE : FALSE;
23 23
 	}
24 24
 	return FALSE;
25 25
 }
@@ -31,7 +31,7 @@  discard block
 block discarded – undo
31 31
  * @return bool
32 32
  */
33 33
 function is_espresso_event_single() {
34
-	if ( can_use_espresso_conditionals( __FUNCTION__ )) {
34
+	if (can_use_espresso_conditionals(__FUNCTION__)) {
35 35
 		global $wp_query;
36 36
 		// return conditionals set by CPTs
37 37
 		return $wp_query instanceof WP_Query ? $wp_query->is_espresso_event_single : FALSE;
@@ -46,7 +46,7 @@  discard block
 block discarded – undo
46 46
  * @return bool
47 47
  */
48 48
 function is_espresso_event_archive() {
49
-	if ( can_use_espresso_conditionals( __FUNCTION__ )) {
49
+	if (can_use_espresso_conditionals(__FUNCTION__)) {
50 50
 		global $wp_query;
51 51
 		return $wp_query instanceof WP_Query ? $wp_query->is_espresso_event_archive : FALSE;
52 52
 	}
@@ -60,7 +60,7 @@  discard block
 block discarded – undo
60 60
  * @return bool
61 61
  */
62 62
 function is_espresso_event_taxonomy() {
63
-	if ( can_use_espresso_conditionals( __FUNCTION__ )) {
63
+	if (can_use_espresso_conditionals(__FUNCTION__)) {
64 64
 		global $wp_query;
65 65
 		return $wp_query instanceof WP_Query ? $wp_query->is_espresso_event_taxonomy : FALSE;
66 66
 	}
@@ -74,10 +74,10 @@  discard block
 block discarded – undo
74 74
  * @param int | \EE_Venue $venue
75 75
  * @return bool
76 76
  */
77
-function is_espresso_venue( $venue = NULL ) {
78
-	if ( can_use_espresso_conditionals( __FUNCTION__ )) {
77
+function is_espresso_venue($venue = NULL) {
78
+	if (can_use_espresso_conditionals(__FUNCTION__)) {
79 79
 		// extract EE_Venue object from passed param regardless of what it is (within reason of course)
80
-		$venue = EEH_Venue_View::get_venue( $venue, FALSE );
80
+		$venue = EEH_Venue_View::get_venue($venue, FALSE);
81 81
 		// do we have a valid event ?
82 82
 		return $venue instanceof EE_Venue ? TRUE : FALSE;
83 83
 	}
@@ -91,7 +91,7 @@  discard block
 block discarded – undo
91 91
  * @return bool
92 92
  */
93 93
 function is_espresso_venue_single() {
94
-	if ( can_use_espresso_conditionals( __FUNCTION__ )) {
94
+	if (can_use_espresso_conditionals(__FUNCTION__)) {
95 95
 		global $wp_query;
96 96
 		return $wp_query instanceof WP_Query ? $wp_query->is_espresso_venue_single : FALSE;
97 97
 	}
@@ -105,7 +105,7 @@  discard block
 block discarded – undo
105 105
  * @return bool
106 106
  */
107 107
 function is_espresso_venue_archive() {
108
-	if ( can_use_espresso_conditionals( __FUNCTION__ )) {
108
+	if (can_use_espresso_conditionals(__FUNCTION__)) {
109 109
 		global $wp_query;
110 110
 		return $wp_query instanceof WP_Query ? $wp_query->is_espresso_venue_archive : FALSE;
111 111
 	}
@@ -119,7 +119,7 @@  discard block
 block discarded – undo
119 119
  * @return bool
120 120
  */
121 121
 function is_espresso_venue_taxonomy() {
122
-	if ( can_use_espresso_conditionals( __FUNCTION__ )) {
122
+	if (can_use_espresso_conditionals(__FUNCTION__)) {
123 123
 		global $wp_query;
124 124
 		return $wp_query instanceof WP_Query ? $wp_query->is_espresso_venue_taxonomy : FALSE;
125 125
 	}
@@ -133,12 +133,12 @@  discard block
 block discarded – undo
133 133
  * @param $conditional_tag
134 134
  * @return bool
135 135
  */
136
-function can_use_espresso_conditionals( $conditional_tag ) {
137
-	if ( ! did_action( 'AHEE__EE_System__initialize' )) {
136
+function can_use_espresso_conditionals($conditional_tag) {
137
+	if ( ! did_action('AHEE__EE_System__initialize')) {
138 138
 		EE_Error::doing_it_wrong(
139 139
 			__FUNCTION__,
140 140
 			sprintf(
141
-				__( 'The "%s" conditional tag can not be used until after the "init" hook has run, but works best when used within a theme\'s template files.','event_espresso'),
141
+				__('The "%s" conditional tag can not be used until after the "init" hook has run, but works best when used within a theme\'s template files.', 'event_espresso'),
142 142
 				$conditional_tag
143 143
 			),
144 144
 			'4.4.0'
@@ -153,13 +153,13 @@  discard block
 block discarded – undo
153 153
 
154 154
 /*************************** Event Queries ***************************/
155 155
 
156
-if ( ! function_exists( 'espresso_get_events' )) {
156
+if ( ! function_exists('espresso_get_events')) {
157 157
 	/**
158 158
 	 * 	espresso_get_events
159 159
 	 * @param array $params
160 160
 	 * @return array
161 161
 	 */
162
-	function espresso_get_events( $params = array() ) {
162
+	function espresso_get_events($params = array()) {
163 163
 		//set default params
164 164
 		$default_espresso_events_params = array(
165 165
 			'limit' => 10,
@@ -170,18 +170,18 @@  discard block
 block discarded – undo
170 170
 			'sort' => 'ASC'
171 171
 		);
172 172
 		// allow the defaults to be filtered
173
-		$default_espresso_events_params = apply_filters( 'espresso_get_events__default_espresso_events_params', $default_espresso_events_params );
173
+		$default_espresso_events_params = apply_filters('espresso_get_events__default_espresso_events_params', $default_espresso_events_params);
174 174
 		// grab params and merge with defaults, then extract
175
-		$params = array_merge( $default_espresso_events_params, $params );
175
+		$params = array_merge($default_espresso_events_params, $params);
176 176
 		// run the query
177
-		$events_query = new EventEspresso\core\domain\services\wp_queries\EventListQuery( $params );
177
+		$events_query = new EventEspresso\core\domain\services\wp_queries\EventListQuery($params);
178 178
 		// assign results to a variable so we can return it
179 179
 		$events = $events_query->have_posts() ? $events_query->posts : array();
180 180
 		// but first reset the query and postdata
181 181
 		wp_reset_query();
182 182
 		wp_reset_postdata();
183 183
 		EED_Events_Archive::remove_all_events_archive_filters();
184
-		unset( $events_query );
184
+		unset($events_query);
185 185
 		return $events;
186 186
 	}
187 187
 }
@@ -195,33 +195,33 @@  discard block
 block discarded – undo
195 195
  * espresso_load_ticket_selector
196 196
  */
197 197
 function espresso_load_ticket_selector() {
198
-	EE_Registry::instance()->load_file( EE_MODULES . 'ticket_selector', 'EED_Ticket_Selector', 'module' );
198
+	EE_Registry::instance()->load_file(EE_MODULES.'ticket_selector', 'EED_Ticket_Selector', 'module');
199 199
 }
200 200
 
201
-if ( ! function_exists( 'espresso_ticket_selector' )) {
201
+if ( ! function_exists('espresso_ticket_selector')) {
202 202
 	/**
203 203
 	 * espresso_ticket_selector
204 204
 	 * @param null $event
205 205
 	 */
206
-	function espresso_ticket_selector( $event = NULL ) {
207
-		if (  ! apply_filters( 'FHEE_disable_espresso_ticket_selector', FALSE ) ) {
206
+	function espresso_ticket_selector($event = NULL) {
207
+		if ( ! apply_filters('FHEE_disable_espresso_ticket_selector', FALSE)) {
208 208
 			espresso_load_ticket_selector();
209 209
             \EED_Ticket_Selector::set_definitions();
210
-			echo EED_Ticket_Selector::display_ticket_selector( $event );
210
+			echo EED_Ticket_Selector::display_ticket_selector($event);
211 211
 		}
212 212
 	}
213 213
 }
214 214
 
215 215
 
216
-	if ( ! function_exists( 'espresso_view_details_btn' )) {
216
+	if ( ! function_exists('espresso_view_details_btn')) {
217 217
 	/**
218 218
 	 * espresso_view_details_btn
219 219
 	 * @param null $event
220 220
 	 */
221
-	function espresso_view_details_btn( $event = NULL ) {
222
-		if (  ! apply_filters( 'FHEE_disable_espresso_view_details_btn', FALSE ) ) {
221
+	function espresso_view_details_btn($event = NULL) {
222
+		if ( ! apply_filters('FHEE_disable_espresso_view_details_btn', FALSE)) {
223 223
 			espresso_load_ticket_selector();
224
-			echo EED_Ticket_Selector::display_ticket_selector( $event, TRUE );
224
+			echo EED_Ticket_Selector::display_ticket_selector($event, TRUE);
225 225
 		}
226 226
 	}
227 227
 }
@@ -231,7 +231,7 @@  discard block
 block discarded – undo
231 231
 
232 232
 /*************************** EEH_Event_View ***************************/
233 233
 
234
-if ( ! function_exists( 'espresso_load_event_list_assets' )) {
234
+if ( ! function_exists('espresso_load_event_list_assets')) {
235 235
 	/**
236 236
 	 * espresso_load_event_list_assets
237 237
 	 * ensures that event list styles and scripts are loaded
@@ -240,13 +240,13 @@  discard block
 block discarded – undo
240 240
 	 */
241 241
 	function espresso_load_event_list_assets() {
242 242
 		$event_list = EED_Events_Archive::instance();
243
-		add_action( 'AHEE__EE_System__initialize_last', array( $event_list, 'load_event_list_assets' ), 10 );
244
-		add_filter( 'FHEE_enable_default_espresso_css', '__return_true' );
243
+		add_action('AHEE__EE_System__initialize_last', array($event_list, 'load_event_list_assets'), 10);
244
+		add_filter('FHEE_enable_default_espresso_css', '__return_true');
245 245
 	}
246 246
 }
247 247
 
248 248
 
249
-if ( ! function_exists( 'espresso_event_reg_button' )) {
249
+if ( ! function_exists('espresso_event_reg_button')) {
250 250
 	/**
251 251
 	 * espresso_event_reg_button
252 252
 	 * returns the "Register Now" button if event is active,
@@ -258,9 +258,9 @@  discard block
 block discarded – undo
258 258
 	 * @param bool $EVT_ID
259 259
 	 * @return string
260 260
 	 */
261
-	function espresso_event_reg_button( $btn_text_if_active = NULL, $btn_text_if_inactive = FALSE, $EVT_ID = FALSE ) {
262
-		$event_status = EEH_Event_View::event_active_status( $EVT_ID );
263
-		switch ( $event_status ) {
261
+	function espresso_event_reg_button($btn_text_if_active = NULL, $btn_text_if_inactive = FALSE, $EVT_ID = FALSE) {
262
+		$event_status = EEH_Event_View::event_active_status($EVT_ID);
263
+		switch ($event_status) {
264 264
 			case EE_Datetime::sold_out :
265 265
 				$btn_text = __('Sold Out', 'event_espresso');
266 266
 				$class = 'ee-pink';
@@ -276,10 +276,10 @@  discard block
 block discarded – undo
276 276
 			case EE_Datetime::upcoming :
277 277
 			case EE_Datetime::active :
278 278
 			default :
279
-				$btn_text =! empty( $btn_text_if_active ) ? $btn_text_if_active : __( 'Register Now', 'event_espresso' );
279
+				$btn_text = ! empty($btn_text_if_active) ? $btn_text_if_active : __('Register Now', 'event_espresso');
280 280
 				$class = 'ee-green';
281 281
 		}
282
-		if ( $event_status < 1 && ! empty( $btn_text_if_inactive )) {
282
+		if ($event_status < 1 && ! empty($btn_text_if_inactive)) {
283 283
 			$btn_text = $btn_text_if_inactive;
284 284
 			$class = 'ee-grey';
285 285
 		}
@@ -293,7 +293,7 @@  discard block
 block discarded – undo
293 293
 
294 294
 
295 295
 
296
-if ( ! function_exists( 'espresso_display_ticket_selector' )) {
296
+if ( ! function_exists('espresso_display_ticket_selector')) {
297 297
 	/**
298 298
 	 * espresso_display_ticket_selector
299 299
 	 * whether or not to display the Ticket Selector for an event
@@ -301,14 +301,14 @@  discard block
 block discarded – undo
301 301
 	 * @param bool $EVT_ID
302 302
 	 * @return boolean
303 303
 	 */
304
-	function espresso_display_ticket_selector( $EVT_ID = FALSE ) {
305
-		return EEH_Event_View::display_ticket_selector( $EVT_ID );
304
+	function espresso_display_ticket_selector($EVT_ID = FALSE) {
305
+		return EEH_Event_View::display_ticket_selector($EVT_ID);
306 306
 	}
307 307
 }
308 308
 
309 309
 
310 310
 
311
-if ( ! function_exists( 'espresso_event_status_banner' )) {
311
+if ( ! function_exists('espresso_event_status_banner')) {
312 312
 	/**
313 313
 	 * espresso_event_status
314 314
 	 * returns a banner showing the event status if it is sold out, expired, or inactive
@@ -316,13 +316,13 @@  discard block
 block discarded – undo
316 316
 	 * @param bool $EVT_ID
317 317
 	 * @return string
318 318
 	 */
319
-	function espresso_event_status_banner( $EVT_ID = FALSE ) {
320
-		return EEH_Event_View::event_status( $EVT_ID );
319
+	function espresso_event_status_banner($EVT_ID = FALSE) {
320
+		return EEH_Event_View::event_status($EVT_ID);
321 321
 	}
322 322
 }
323 323
 
324 324
 
325
-if ( ! function_exists( 'espresso_event_status' )) {
325
+if ( ! function_exists('espresso_event_status')) {
326 326
 	/**
327 327
 	 * espresso_event_status
328 328
 	 * returns the event status if it is sold out, expired, or inactive
@@ -331,17 +331,17 @@  discard block
 block discarded – undo
331 331
 	 * @param bool $echo
332 332
 	 * @return string
333 333
 	 */
334
-	function espresso_event_status( $EVT_ID = 0, $echo = TRUE ) {
335
-		if ( $echo ) {
336
-			echo EEH_Event_View::event_active_status( $EVT_ID );
334
+	function espresso_event_status($EVT_ID = 0, $echo = TRUE) {
335
+		if ($echo) {
336
+			echo EEH_Event_View::event_active_status($EVT_ID);
337 337
 			return '';
338 338
 		}
339
-		return EEH_Event_View::event_active_status( $EVT_ID );
339
+		return EEH_Event_View::event_active_status($EVT_ID);
340 340
 	}
341 341
 }
342 342
 
343 343
 
344
-if ( ! function_exists( 'espresso_event_categories' )) {
344
+if ( ! function_exists('espresso_event_categories')) {
345 345
 	/**
346 346
 	 * espresso_event_categories
347 347
 	 * returns the terms associated with an event
@@ -351,17 +351,17 @@  discard block
 block discarded – undo
351 351
 	 * @param bool $echo
352 352
 	 * @return string
353 353
 	 */
354
-	function espresso_event_categories( $EVT_ID = 0, $hide_uncategorized = TRUE, $echo = TRUE ) {
355
-		if ( $echo ) {
356
-			echo EEH_Event_View::event_categories( $EVT_ID, $hide_uncategorized );
354
+	function espresso_event_categories($EVT_ID = 0, $hide_uncategorized = TRUE, $echo = TRUE) {
355
+		if ($echo) {
356
+			echo EEH_Event_View::event_categories($EVT_ID, $hide_uncategorized);
357 357
 			return '';
358 358
 		}
359
-		return EEH_Event_View::event_categories( $EVT_ID, $hide_uncategorized );
359
+		return EEH_Event_View::event_categories($EVT_ID, $hide_uncategorized);
360 360
 	}
361 361
 }
362 362
 
363 363
 
364
-if ( ! function_exists( 'espresso_event_tickets_available' )) {
364
+if ( ! function_exists('espresso_event_tickets_available')) {
365 365
 	/**
366 366
 	 * espresso_event_tickets_available
367 367
 	 * returns the ticket types available for purchase for an event
@@ -371,26 +371,26 @@  discard block
 block discarded – undo
371 371
 	 * @param bool $format
372 372
 	 * @return string
373 373
 	 */
374
-	function espresso_event_tickets_available( $EVT_ID = 0, $echo = TRUE, $format = TRUE ) {
375
-		$tickets = EEH_Event_View::event_tickets_available( $EVT_ID );
376
-		if ( is_array( $tickets ) && ! empty( $tickets )) {
374
+	function espresso_event_tickets_available($EVT_ID = 0, $echo = TRUE, $format = TRUE) {
375
+		$tickets = EEH_Event_View::event_tickets_available($EVT_ID);
376
+		if (is_array($tickets) && ! empty($tickets)) {
377 377
 			// if formatting then $html will be a string, else it will be an array of ticket objects
378
-			$html = $format ? '<ul id="ee-event-tickets-ul-' . $EVT_ID . '" class="ee-event-tickets-ul">' : array();
379
-			foreach ( $tickets as $ticket ) {
380
-				if ( $ticket instanceof EE_Ticket ) {
381
-					if ( $format ) {
382
-						$html .= '<li id="ee-event-tickets-li-' . $ticket->ID() . '" class="ee-event-tickets-li">';
383
-						$html .= $ticket->name() . ' ' . EEH_Template::format_currency( $ticket->get_ticket_total_with_taxes() );
378
+			$html = $format ? '<ul id="ee-event-tickets-ul-'.$EVT_ID.'" class="ee-event-tickets-ul">' : array();
379
+			foreach ($tickets as $ticket) {
380
+				if ($ticket instanceof EE_Ticket) {
381
+					if ($format) {
382
+						$html .= '<li id="ee-event-tickets-li-'.$ticket->ID().'" class="ee-event-tickets-li">';
383
+						$html .= $ticket->name().' '.EEH_Template::format_currency($ticket->get_ticket_total_with_taxes());
384 384
 						$html .= '</li>';
385 385
 					} else {
386 386
 						$html[] = $ticket;
387 387
 					}
388 388
 				}
389 389
 			}
390
-			if ( $format ) {
390
+			if ($format) {
391 391
 				$html .= '</ul>';
392 392
 			}
393
-			if ( $echo && $format ) {
393
+			if ($echo && $format) {
394 394
 				echo $html;
395 395
 				return '';
396 396
 			}
@@ -400,7 +400,7 @@  discard block
 block discarded – undo
400 400
 	}
401 401
 }
402 402
 
403
-if ( ! function_exists( 'espresso_event_date_obj' )) {
403
+if ( ! function_exists('espresso_event_date_obj')) {
404 404
 	/**
405 405
 	 * espresso_event_date_obj
406 406
 	 * returns the primary date object for an event
@@ -408,13 +408,13 @@  discard block
 block discarded – undo
408 408
 	 * @param bool $EVT_ID
409 409
 	 * @return object
410 410
 	 */
411
-	function espresso_event_date_obj( $EVT_ID = FALSE ) {
412
-		return EEH_Event_View::get_primary_date_obj( $EVT_ID );
411
+	function espresso_event_date_obj($EVT_ID = FALSE) {
412
+		return EEH_Event_View::get_primary_date_obj($EVT_ID);
413 413
 	}
414 414
 }
415 415
 
416 416
 
417
-if ( ! function_exists( 'espresso_event_date' )) {
417
+if ( ! function_exists('espresso_event_date')) {
418 418
 	/**
419 419
 	 * espresso_event_date
420 420
 	 * returns the primary date for an event
@@ -425,22 +425,22 @@  discard block
 block discarded – undo
425 425
 	 * @param bool $echo
426 426
 	 * @return string
427 427
 	 */
428
-	function espresso_event_date( $date_format = '', $time_format = '', $EVT_ID = FALSE, $echo = TRUE ) {
429
-		$date_format = ! empty( $date_format ) ? $date_format : get_option( 'date_format' );
430
-		$time_format = ! empty( $time_format ) ? $time_format : get_option( 'time_format' );
431
-		$date_format = apply_filters( 'FHEE__espresso_event_date__date_format', $date_format );
432
-		$time_format = apply_filters( 'FHEE__espresso_event_date__time_format', $time_format );
433
-		if($echo){
434
-			echo EEH_Event_View::the_event_date( $date_format, $time_format, $EVT_ID );
428
+	function espresso_event_date($date_format = '', $time_format = '', $EVT_ID = FALSE, $echo = TRUE) {
429
+		$date_format = ! empty($date_format) ? $date_format : get_option('date_format');
430
+		$time_format = ! empty($time_format) ? $time_format : get_option('time_format');
431
+		$date_format = apply_filters('FHEE__espresso_event_date__date_format', $date_format);
432
+		$time_format = apply_filters('FHEE__espresso_event_date__time_format', $time_format);
433
+		if ($echo) {
434
+			echo EEH_Event_View::the_event_date($date_format, $time_format, $EVT_ID);
435 435
 			return '';
436 436
 		}
437
-		return EEH_Event_View::the_event_date( $date_format, $time_format, $EVT_ID );
437
+		return EEH_Event_View::the_event_date($date_format, $time_format, $EVT_ID);
438 438
 
439 439
 	}
440 440
 }
441 441
 
442 442
 
443
-if ( ! function_exists( 'espresso_list_of_event_dates' )) {
443
+if ( ! function_exists('espresso_list_of_event_dates')) {
444 444
 	/**
445 445
 	 * espresso_list_of_event_dates
446 446
 	 * returns a unordered list of dates for an event
@@ -455,40 +455,40 @@  discard block
 block discarded – undo
455 455
 	 * @param null   $limit
456 456
 	 * @return string
457 457
 	 */
458
-	function espresso_list_of_event_dates( $EVT_ID = 0, $date_format = '', $time_format = '', $echo = TRUE, $show_expired = NULL, $format = TRUE, $add_breaks = TRUE, $limit = NULL ) {
459
-		$date_format = ! empty( $date_format ) ? $date_format : get_option( 'date_format' );
460
-		$time_format = ! empty( $time_format ) ? $time_format : get_option( 'time_format' );
461
-		$date_format = apply_filters( 'FHEE__espresso_list_of_event_dates__date_format', $date_format );
462
-		$time_format = apply_filters( 'FHEE__espresso_list_of_event_dates__time_format', $time_format );
463
-		$datetimes = EEH_Event_View::get_all_date_obj( $EVT_ID, $show_expired, FALSE, $limit );
464
-		if ( ! $format ) {
465
-			return apply_filters( 'FHEE__espresso_list_of_event_dates__datetimes', $datetimes );
458
+	function espresso_list_of_event_dates($EVT_ID = 0, $date_format = '', $time_format = '', $echo = TRUE, $show_expired = NULL, $format = TRUE, $add_breaks = TRUE, $limit = NULL) {
459
+		$date_format = ! empty($date_format) ? $date_format : get_option('date_format');
460
+		$time_format = ! empty($time_format) ? $time_format : get_option('time_format');
461
+		$date_format = apply_filters('FHEE__espresso_list_of_event_dates__date_format', $date_format);
462
+		$time_format = apply_filters('FHEE__espresso_list_of_event_dates__time_format', $time_format);
463
+		$datetimes = EEH_Event_View::get_all_date_obj($EVT_ID, $show_expired, FALSE, $limit);
464
+		if ( ! $format) {
465
+			return apply_filters('FHEE__espresso_list_of_event_dates__datetimes', $datetimes);
466 466
 		}
467 467
 		//d( $datetimes );
468
-		if ( is_array( $datetimes ) && ! empty( $datetimes )) {
468
+		if (is_array($datetimes) && ! empty($datetimes)) {
469 469
 			global $post;
470
-			$html = $format ? '<ul id="ee-event-datetimes-ul-' . $post->ID . '" class="ee-event-datetimes-ul ee-clearfix">' : '';
471
-			foreach ( $datetimes as $datetime ) {
472
-				if ( $datetime instanceof EE_Datetime ) {
473
-					$html .= '<li id="ee-event-datetimes-li-' . $datetime->ID();
474
-					$html .= '" class="ee-event-datetimes-li ee-event-datetimes-li-' . $datetime->get_active_status() . '">';
470
+			$html = $format ? '<ul id="ee-event-datetimes-ul-'.$post->ID.'" class="ee-event-datetimes-ul ee-clearfix">' : '';
471
+			foreach ($datetimes as $datetime) {
472
+				if ($datetime instanceof EE_Datetime) {
473
+					$html .= '<li id="ee-event-datetimes-li-'.$datetime->ID();
474
+					$html .= '" class="ee-event-datetimes-li ee-event-datetimes-li-'.$datetime->get_active_status().'">';
475 475
 					$datetime_name = $datetime->name();
476
-					$html .= ! empty( $datetime_name ) ? '<strong>' . $datetime_name . '</strong>' : '';
477
-					$html .= ! empty( $datetime_name )  && $add_breaks ? '<br />' : '';
478
-					$html .= '<span class="dashicons dashicons-calendar"></span><span class="ee-event-datetimes-li-daterange">' . $datetime->date_range( $date_format ) . '</span><br/>';
479
-					$html .= '<span class="dashicons dashicons-clock"></span><span class="ee-event-datetimes-li-timerange">' . $datetime->time_range( $time_format ) . '</span>';
476
+					$html .= ! empty($datetime_name) ? '<strong>'.$datetime_name.'</strong>' : '';
477
+					$html .= ! empty($datetime_name) && $add_breaks ? '<br />' : '';
478
+					$html .= '<span class="dashicons dashicons-calendar"></span><span class="ee-event-datetimes-li-daterange">'.$datetime->date_range($date_format).'</span><br/>';
479
+					$html .= '<span class="dashicons dashicons-clock"></span><span class="ee-event-datetimes-li-timerange">'.$datetime->time_range($time_format).'</span>';
480 480
 					$datetime_description = $datetime->description();
481
-					$html .= ! empty( $datetime_description )  && $add_breaks ? '<br />' : '';
482
-					$html .= ! empty( $datetime_description ) ? ' - ' . $datetime_description : '';
483
-					$html = apply_filters( 'FHEE__espresso_list_of_event_dates__datetime_html', $html, $datetime );
481
+					$html .= ! empty($datetime_description) && $add_breaks ? '<br />' : '';
482
+					$html .= ! empty($datetime_description) ? ' - '.$datetime_description : '';
483
+					$html = apply_filters('FHEE__espresso_list_of_event_dates__datetime_html', $html, $datetime);
484 484
 					$html .= '</li>';
485 485
 				}
486 486
 			}
487 487
 			$html .= $format ? '</ul>' : '';
488 488
 		} else {
489
-			$html = $format ?  '<p><span class="dashicons dashicons-marker pink-text"></span>' . __( 'There are no upcoming dates for this event.', 'event_espresso' ) . '</p><br/>' : '';
489
+			$html = $format ? '<p><span class="dashicons dashicons-marker pink-text"></span>'.__('There are no upcoming dates for this event.', 'event_espresso').'</p><br/>' : '';
490 490
 		}
491
-		if ( $echo ) {
491
+		if ($echo) {
492 492
 			echo $html;
493 493
 			return '';
494 494
 		}
@@ -497,7 +497,7 @@  discard block
 block discarded – undo
497 497
 }
498 498
 
499 499
 
500
-if ( ! function_exists( 'espresso_event_end_date' )) {
500
+if ( ! function_exists('espresso_event_end_date')) {
501 501
 	/**
502 502
 	 * espresso_event_end_date
503 503
 	 * returns the last date for an event
@@ -508,20 +508,20 @@  discard block
 block discarded – undo
508 508
 	 * @param bool   $echo
509 509
 	 * @return string
510 510
 	 */
511
-	function espresso_event_end_date( $date_format = '', $time_format = '', $EVT_ID = FALSE, $echo = TRUE ) {
512
-		$date_format = ! empty( $date_format ) ? $date_format : get_option( 'date_format' );
513
-		$time_format = ! empty( $time_format ) ? $time_format : get_option( 'time_format' );
514
-		$date_format = apply_filters( 'FHEE__espresso_event_end_date__date_format', $date_format );
515
-		$time_format = apply_filters( 'FHEE__espresso_event_end_date__time_format', $time_format );
516
-		if($echo){
517
-			echo EEH_Event_View::the_event_end_date( $date_format, $time_format, $EVT_ID );
511
+	function espresso_event_end_date($date_format = '', $time_format = '', $EVT_ID = FALSE, $echo = TRUE) {
512
+		$date_format = ! empty($date_format) ? $date_format : get_option('date_format');
513
+		$time_format = ! empty($time_format) ? $time_format : get_option('time_format');
514
+		$date_format = apply_filters('FHEE__espresso_event_end_date__date_format', $date_format);
515
+		$time_format = apply_filters('FHEE__espresso_event_end_date__time_format', $time_format);
516
+		if ($echo) {
517
+			echo EEH_Event_View::the_event_end_date($date_format, $time_format, $EVT_ID);
518 518
 			return '';
519 519
 		}
520
-		return EEH_Event_View::the_event_end_date( $date_format, $time_format, $EVT_ID );
520
+		return EEH_Event_View::the_event_end_date($date_format, $time_format, $EVT_ID);
521 521
 	}
522 522
 }
523 523
 
524
-if ( ! function_exists( 'espresso_event_date_range' )) {
524
+if ( ! function_exists('espresso_event_date_range')) {
525 525
 	/**
526 526
 	 * espresso_event_date_range
527 527
 	 * returns the first and last chronologically ordered dates for an event (if different)
@@ -534,31 +534,31 @@  discard block
 block discarded – undo
534 534
 	 * @param bool   $echo
535 535
 	 * @return string
536 536
 	 */
537
-	function espresso_event_date_range( $date_format = '', $time_format = '', $single_date_format = '', $single_time_format = '', $EVT_ID = FALSE, $echo = TRUE ) {
537
+	function espresso_event_date_range($date_format = '', $time_format = '', $single_date_format = '', $single_time_format = '', $EVT_ID = FALSE, $echo = TRUE) {
538 538
 		// set and filter date and time formats when a range is returned
539
-		$date_format = ! empty( $date_format ) ? $date_format : get_option( 'date_format' );
540
-		$date_format = apply_filters( 'FHEE__espresso_event_date_range__date_format', $date_format );
539
+		$date_format = ! empty($date_format) ? $date_format : get_option('date_format');
540
+		$date_format = apply_filters('FHEE__espresso_event_date_range__date_format', $date_format);
541 541
 		// get the start and end date with NO time portion
542
-		$the_event_date = EEH_Event_View::the_earliest_event_date( $date_format, '', $EVT_ID );
543
-		$the_event_end_date = EEH_Event_View::the_latest_event_date( $date_format, '', $EVT_ID );
542
+		$the_event_date = EEH_Event_View::the_earliest_event_date($date_format, '', $EVT_ID);
543
+		$the_event_end_date = EEH_Event_View::the_latest_event_date($date_format, '', $EVT_ID);
544 544
 		// now we can determine if date range spans more than one day
545
-		if ( $the_event_date != $the_event_end_date ) {
546
-			$time_format = ! empty( $time_format ) ? $time_format : get_option( 'time_format' );
547
-			$time_format = apply_filters( 'FHEE__espresso_event_date_range__time_format', $time_format );
545
+		if ($the_event_date != $the_event_end_date) {
546
+			$time_format = ! empty($time_format) ? $time_format : get_option('time_format');
547
+			$time_format = apply_filters('FHEE__espresso_event_date_range__time_format', $time_format);
548 548
 			$html = sprintf(
549
-				__( '%1$s - %2$s', 'event_espresso' ),
550
-				EEH_Event_View::the_earliest_event_date( $date_format, $time_format, $EVT_ID ),
551
-				EEH_Event_View::the_latest_event_date( $date_format, $time_format, $EVT_ID )
549
+				__('%1$s - %2$s', 'event_espresso'),
550
+				EEH_Event_View::the_earliest_event_date($date_format, $time_format, $EVT_ID),
551
+				EEH_Event_View::the_latest_event_date($date_format, $time_format, $EVT_ID)
552 552
 			);
553 553
 		} else {
554 554
 			// set and filter date and time formats when only a single datetime is returned
555
-			$single_date_format = ! empty( $single_date_format ) ? $single_date_format : get_option( 'date_format' );
556
-			$single_time_format = ! empty( $single_time_format ) ? $single_time_format : get_option( 'time_format' );
557
-			$single_date_format = apply_filters( 'FHEE__espresso_event_date_range__single_date_format', $single_date_format );
558
-			$single_time_format = apply_filters( 'FHEE__espresso_event_date_range__single_time_format', $single_time_format );
559
-			$html = EEH_Event_View::the_earliest_event_date( $single_date_format, $single_time_format, $EVT_ID );
555
+			$single_date_format = ! empty($single_date_format) ? $single_date_format : get_option('date_format');
556
+			$single_time_format = ! empty($single_time_format) ? $single_time_format : get_option('time_format');
557
+			$single_date_format = apply_filters('FHEE__espresso_event_date_range__single_date_format', $single_date_format);
558
+			$single_time_format = apply_filters('FHEE__espresso_event_date_range__single_time_format', $single_time_format);
559
+			$html = EEH_Event_View::the_earliest_event_date($single_date_format, $single_time_format, $EVT_ID);
560 560
 		}
561
-		if ( $echo ) {
561
+		if ($echo) {
562 562
 			echo $html;
563 563
 			return '';
564 564
 		}
@@ -566,7 +566,7 @@  discard block
 block discarded – undo
566 566
 	}
567 567
 }
568 568
 
569
-if ( ! function_exists( 'espresso_next_upcoming_datetime_obj' )) {
569
+if ( ! function_exists('espresso_next_upcoming_datetime_obj')) {
570 570
 	/**
571 571
 	 * espresso_next_upcoming_datetime_obj
572 572
 	 * returns the next upcoming datetime object for an event
@@ -574,12 +574,12 @@  discard block
 block discarded – undo
574 574
 	 * @param int $EVT_ID
575 575
 	 * @return EE_Datetime|null
576 576
 	 */
577
-	function espresso_next_upcoming_datetime_obj( $EVT_ID = 0 ) {
578
-		return EEH_Event_View::get_next_upcoming_date_obj( $EVT_ID );
577
+	function espresso_next_upcoming_datetime_obj($EVT_ID = 0) {
578
+		return EEH_Event_View::get_next_upcoming_date_obj($EVT_ID);
579 579
 	}
580 580
 }
581 581
 
582
-if ( ! function_exists( 'espresso_next_upcoming_datetime' ) ) {
582
+if ( ! function_exists('espresso_next_upcoming_datetime')) {
583 583
 	/**
584 584
 	 * espresso_next_upcoming_datetime
585 585
 	 * returns the start date and time for the next upcoming event.
@@ -590,30 +590,30 @@  discard block
 block discarded – undo
590 590
 	 * @param bool $echo
591 591
 	 * @return string
592 592
 	 */
593
-	function espresso_next_upcoming_datetime( $date_format = '', $time_format = '', $EVT_ID = 0, $echo = true ) {
593
+	function espresso_next_upcoming_datetime($date_format = '', $time_format = '', $EVT_ID = 0, $echo = true) {
594 594
 
595
-		$date_format = ! empty( $date_format ) ? $date_format : get_option( 'date_format' );
596
-		$date_format = apply_filters( 'FHEE__espresso_next_upcoming_datetime__date_format', $date_format );
595
+		$date_format = ! empty($date_format) ? $date_format : get_option('date_format');
596
+		$date_format = apply_filters('FHEE__espresso_next_upcoming_datetime__date_format', $date_format);
597 597
 
598
-		$time_format = ! empty( $time_format ) ? $time_format : get_option( 'time_format' );
599
-		$time_format = apply_filters( 'FHEE__espresso_next_upcoming_datetime__time_format', $time_format );
598
+		$time_format = ! empty($time_format) ? $time_format : get_option('time_format');
599
+		$time_format = apply_filters('FHEE__espresso_next_upcoming_datetime__time_format', $time_format);
600 600
 
601
-		$datetime_format = trim( $date_format . ' ' . $time_format);
601
+		$datetime_format = trim($date_format.' '.$time_format);
602 602
 
603
-		$datetime = espresso_next_upcoming_datetime_obj( $EVT_ID );
603
+		$datetime = espresso_next_upcoming_datetime_obj($EVT_ID);
604 604
 
605
-		if( ! $datetime instanceof EE_Datetime ) {
605
+		if ( ! $datetime instanceof EE_Datetime) {
606 606
 			return '';
607 607
 		}
608
-		if ( $echo ){
609
-			echo $datetime->get_i18n_datetime( 'DTT_EVT_start', $datetime_format );
608
+		if ($echo) {
609
+			echo $datetime->get_i18n_datetime('DTT_EVT_start', $datetime_format);
610 610
 			return '';
611 611
 		}
612
-		return $datetime->get_i18n_datetime( 'DTT_EVT_start', $datetime_format );
612
+		return $datetime->get_i18n_datetime('DTT_EVT_start', $datetime_format);
613 613
 	}
614 614
 }
615 615
 
616
-if ( ! function_exists( 'espresso_event_date_as_calendar_page' )) {
616
+if ( ! function_exists('espresso_event_date_as_calendar_page')) {
617 617
 	/**
618 618
 	 * espresso_event_date_as_calendar_page
619 619
 	 * returns the primary date for an event, stylized to appear as the page of a calendar
@@ -621,15 +621,15 @@  discard block
 block discarded – undo
621 621
 	 * @param bool $EVT_ID
622 622
 	 * @return string
623 623
 	 */
624
-	function espresso_event_date_as_calendar_page( $EVT_ID = FALSE ) {
625
-		EEH_Event_View::event_date_as_calendar_page( $EVT_ID );
624
+	function espresso_event_date_as_calendar_page($EVT_ID = FALSE) {
625
+		EEH_Event_View::event_date_as_calendar_page($EVT_ID);
626 626
 	}
627 627
 }
628 628
 
629 629
 
630 630
 
631 631
 
632
-if ( ! function_exists( 'espresso_event_link_url' )) {
632
+if ( ! function_exists('espresso_event_link_url')) {
633 633
 	/**
634 634
 	 * espresso_event_link_url
635 635
 	 *
@@ -637,18 +637,18 @@  discard block
 block discarded – undo
637 637
 	 * @param bool $echo
638 638
 	 * @return string
639 639
 	 */
640
-	function espresso_event_link_url( $EVT_ID = 0, $echo = TRUE ) {
641
-		if ( $echo ) {
642
-			echo EEH_Event_View::event_link_url( $EVT_ID );
640
+	function espresso_event_link_url($EVT_ID = 0, $echo = TRUE) {
641
+		if ($echo) {
642
+			echo EEH_Event_View::event_link_url($EVT_ID);
643 643
 			return '';
644 644
 		}
645
-		return EEH_Event_View::event_link_url( $EVT_ID );
645
+		return EEH_Event_View::event_link_url($EVT_ID);
646 646
 	}
647 647
 }
648 648
 
649 649
 
650 650
 
651
-if ( ! function_exists( 'espresso_event_has_content_or_excerpt' )) {
651
+if ( ! function_exists('espresso_event_has_content_or_excerpt')) {
652 652
 	/**
653 653
 	 *    espresso_event_has_content_or_excerpt
654 654
 	 *
@@ -656,15 +656,15 @@  discard block
 block discarded – undo
656 656
 	 * @param bool $EVT_ID
657 657
 	 * @return    boolean
658 658
 	 */
659
-	function espresso_event_has_content_or_excerpt( $EVT_ID = FALSE ) {
660
-		return EEH_Event_View::event_has_content_or_excerpt( $EVT_ID );
659
+	function espresso_event_has_content_or_excerpt($EVT_ID = FALSE) {
660
+		return EEH_Event_View::event_has_content_or_excerpt($EVT_ID);
661 661
 	}
662 662
 }
663 663
 
664 664
 
665 665
 
666 666
 
667
-if ( ! function_exists( 'espresso_event_content_or_excerpt' )) {
667
+if ( ! function_exists('espresso_event_content_or_excerpt')) {
668 668
 	/**
669 669
 	 * espresso_event_content_or_excerpt
670 670
 	 *
@@ -673,18 +673,18 @@  discard block
 block discarded – undo
673 673
 	 * @param bool $echo
674 674
 	 * @return string
675 675
 	 */
676
-	function espresso_event_content_or_excerpt( $num_words = 55, $more = NULL, $echo = TRUE ) {
677
-		if ( $echo ) {
678
-			echo EEH_Event_View::event_content_or_excerpt( $num_words, $more );
676
+	function espresso_event_content_or_excerpt($num_words = 55, $more = NULL, $echo = TRUE) {
677
+		if ($echo) {
678
+			echo EEH_Event_View::event_content_or_excerpt($num_words, $more);
679 679
 			return '';
680 680
 		}
681
-		return EEH_Event_View::event_content_or_excerpt( $num_words, $more );
681
+		return EEH_Event_View::event_content_or_excerpt($num_words, $more);
682 682
 	}
683 683
 }
684 684
 
685 685
 
686 686
 
687
-if ( ! function_exists( 'espresso_event_phone' )) {
687
+if ( ! function_exists('espresso_event_phone')) {
688 688
 	/**
689 689
 	 * espresso_event_phone
690 690
 	 *
@@ -692,18 +692,18 @@  discard block
 block discarded – undo
692 692
 	 * @param bool $echo
693 693
 	 * @return string
694 694
 	 */
695
-	function espresso_event_phone( $EVT_ID = 0, $echo = TRUE ) {
696
-		if ( $echo ) {
697
-			echo EEH_Event_View::event_phone( $EVT_ID );
695
+	function espresso_event_phone($EVT_ID = 0, $echo = TRUE) {
696
+		if ($echo) {
697
+			echo EEH_Event_View::event_phone($EVT_ID);
698 698
 			return '';
699 699
 		}
700
-		return EEH_Event_View::event_phone( $EVT_ID );
700
+		return EEH_Event_View::event_phone($EVT_ID);
701 701
 	}
702 702
 }
703 703
 
704 704
 
705 705
 
706
-if ( ! function_exists( 'espresso_edit_event_link' )) {
706
+if ( ! function_exists('espresso_edit_event_link')) {
707 707
 	/**
708 708
 	 * espresso_edit_event_link
709 709
 	 * returns a link to edit an event
@@ -712,39 +712,39 @@  discard block
 block discarded – undo
712 712
 	 * @param bool $echo
713 713
 	 * @return string
714 714
 	 */
715
-	function espresso_edit_event_link( $EVT_ID = 0, $echo = TRUE ) {
716
-		if ( $echo ) {
717
-			echo EEH_Event_View::edit_event_link( $EVT_ID );
715
+	function espresso_edit_event_link($EVT_ID = 0, $echo = TRUE) {
716
+		if ($echo) {
717
+			echo EEH_Event_View::edit_event_link($EVT_ID);
718 718
 			return '';
719 719
 		}
720
-		return EEH_Event_View::edit_event_link( $EVT_ID );
720
+		return EEH_Event_View::edit_event_link($EVT_ID);
721 721
 	}
722 722
 }
723 723
 
724 724
 
725
-if ( ! function_exists( 'espresso_organization_name' )) {
725
+if ( ! function_exists('espresso_organization_name')) {
726 726
 	/**
727 727
 	 * espresso_organization_name
728 728
 	 * @param bool $echo
729 729
 	 * @return string
730 730
 	 */
731 731
 	function espresso_organization_name($echo = TRUE) {
732
-		if($echo){
733
-			echo EE_Registry::instance()->CFG->organization->get_pretty( 'name' );
732
+		if ($echo) {
733
+			echo EE_Registry::instance()->CFG->organization->get_pretty('name');
734 734
 			return '';
735 735
 		}
736
-		return EE_Registry::instance()->CFG->organization->get_pretty( 'name' );
736
+		return EE_Registry::instance()->CFG->organization->get_pretty('name');
737 737
 	}
738 738
 }
739 739
 
740
-if ( ! function_exists( 'espresso_organization_address' )) {
740
+if ( ! function_exists('espresso_organization_address')) {
741 741
 	/**
742 742
 	 * espresso_organization_address
743 743
 	 * @param string $type
744 744
 	 * @return string
745 745
 	 */
746
-	function espresso_organization_address( $type = 'inline' ) {
747
-		if ( EE_Registry::instance()->CFG->organization instanceof EE_Organization_Config ) {
746
+	function espresso_organization_address($type = 'inline') {
747
+		if (EE_Registry::instance()->CFG->organization instanceof EE_Organization_Config) {
748 748
 			$address = new EventEspresso\core\domain\entities\GenericAddress(
749 749
 				EE_Registry::instance()->CFG->organization->address_1,
750 750
 				EE_Registry::instance()->CFG->organization->address_2,
@@ -753,129 +753,129 @@  discard block
 block discarded – undo
753 753
 				EE_Registry::instance()->CFG->organization->zip,
754 754
 				EE_Registry::instance()->CFG->organization->CNT_ISO
755 755
 			);
756
-			return EEH_Address::format( $address, $type );
756
+			return EEH_Address::format($address, $type);
757 757
 		}
758 758
 		return '';
759 759
 	}
760 760
 }
761 761
 
762
-if ( ! function_exists( 'espresso_organization_email' )) {
762
+if ( ! function_exists('espresso_organization_email')) {
763 763
 	/**
764 764
 	 * espresso_organization_email
765 765
 	 * @param bool $echo
766 766
 	 * @return string
767 767
 	 */
768
-	function espresso_organization_email( $echo = TRUE ) {
769
-		if($echo){
770
-			echo EE_Registry::instance()->CFG->organization->get_pretty( 'email' );
768
+	function espresso_organization_email($echo = TRUE) {
769
+		if ($echo) {
770
+			echo EE_Registry::instance()->CFG->organization->get_pretty('email');
771 771
 			return '';
772 772
 		}
773
-		return EE_Registry::instance()->CFG->organization->get_pretty( 'email' );
773
+		return EE_Registry::instance()->CFG->organization->get_pretty('email');
774 774
 	}
775 775
 }
776 776
 
777
-if ( ! function_exists( 'espresso_organization_logo_url' )) {
777
+if ( ! function_exists('espresso_organization_logo_url')) {
778 778
 	/**
779 779
 	 * espresso_organization_logo_url
780 780
 	 * @param bool $echo
781 781
 	 * @return string
782 782
 	 */
783
-	function espresso_organization_logo_url( $echo = TRUE ) {
784
-		if($echo){
785
-			echo EE_Registry::instance()->CFG->organization->get_pretty( 'logo_url' );
783
+	function espresso_organization_logo_url($echo = TRUE) {
784
+		if ($echo) {
785
+			echo EE_Registry::instance()->CFG->organization->get_pretty('logo_url');
786 786
 			return '';
787 787
 		}
788
-		return EE_Registry::instance()->CFG->organization->get_pretty( 'logo_url' );
788
+		return EE_Registry::instance()->CFG->organization->get_pretty('logo_url');
789 789
 	}
790 790
 }
791 791
 
792
-if ( ! function_exists( 'espresso_organization_facebook' )) {
792
+if ( ! function_exists('espresso_organization_facebook')) {
793 793
 	/**
794 794
 	 * espresso_organization_facebook
795 795
 	 * @param bool $echo
796 796
 	 * @return string
797 797
 	 */
798
-	function espresso_organization_facebook( $echo = TRUE ) {
799
-		if($echo){
800
-			echo EE_Registry::instance()->CFG->organization->get_pretty( 'facebook' );
798
+	function espresso_organization_facebook($echo = TRUE) {
799
+		if ($echo) {
800
+			echo EE_Registry::instance()->CFG->organization->get_pretty('facebook');
801 801
 			return '';
802 802
 		}
803
-		return EE_Registry::instance()->CFG->organization->get_pretty( 'facebook' );
803
+		return EE_Registry::instance()->CFG->organization->get_pretty('facebook');
804 804
 	}
805 805
 }
806 806
 
807
-if ( ! function_exists( 'espresso_organization_twitter' )) {
807
+if ( ! function_exists('espresso_organization_twitter')) {
808 808
 	/**
809 809
 	 * espresso_organization_twitter
810 810
 	 * @param bool $echo
811 811
 	 * @return string
812 812
 	 */
813
-	function espresso_organization_twitter( $echo = TRUE ) {
814
-		if($echo){
815
-			echo EE_Registry::instance()->CFG->organization->get_pretty( 'twitter' );
813
+	function espresso_organization_twitter($echo = TRUE) {
814
+		if ($echo) {
815
+			echo EE_Registry::instance()->CFG->organization->get_pretty('twitter');
816 816
 			return '';
817 817
 		}
818
-		return EE_Registry::instance()->CFG->organization->get_pretty( 'twitter' );
818
+		return EE_Registry::instance()->CFG->organization->get_pretty('twitter');
819 819
 	}
820 820
 }
821 821
 
822
-if ( ! function_exists( 'espresso_organization_linkedin' )) {
822
+if ( ! function_exists('espresso_organization_linkedin')) {
823 823
 	/**
824 824
 	 * espresso_organization_linkedin
825 825
 	 * @param bool $echo
826 826
 	 * @return string
827 827
 	 */
828
-	function espresso_organization_linkedin( $echo = TRUE ) {
829
-		if($echo){
830
-			echo EE_Registry::instance()->CFG->organization->get_pretty( 'linkedin' );
828
+	function espresso_organization_linkedin($echo = TRUE) {
829
+		if ($echo) {
830
+			echo EE_Registry::instance()->CFG->organization->get_pretty('linkedin');
831 831
 			return '';
832 832
 		}
833
-		return EE_Registry::instance()->CFG->organization->get_pretty( 'linkedin' );
833
+		return EE_Registry::instance()->CFG->organization->get_pretty('linkedin');
834 834
 	}
835 835
 }
836 836
 
837
-if ( ! function_exists( 'espresso_organization_pinterest' )) {
837
+if ( ! function_exists('espresso_organization_pinterest')) {
838 838
 	/**
839 839
 	 * espresso_organization_pinterest
840 840
 	 * @param bool $echo
841 841
 	 * @return string
842 842
 	 */
843
-	function espresso_organization_pinterest( $echo = TRUE ) {
844
-		if($echo){
845
-			echo EE_Registry::instance()->CFG->organization->get_pretty( 'pinterest' );
843
+	function espresso_organization_pinterest($echo = TRUE) {
844
+		if ($echo) {
845
+			echo EE_Registry::instance()->CFG->organization->get_pretty('pinterest');
846 846
 			return '';
847 847
 		}
848
-		return EE_Registry::instance()->CFG->organization->get_pretty( 'pinterest' );
848
+		return EE_Registry::instance()->CFG->organization->get_pretty('pinterest');
849 849
 	}
850 850
 }
851 851
 
852
-if ( ! function_exists( 'espresso_organization_google' )) {
852
+if ( ! function_exists('espresso_organization_google')) {
853 853
 	/**
854 854
 	 * espresso_organization_google
855 855
 	 * @param bool $echo
856 856
 	 * @return string
857 857
 	 */
858
-	function espresso_organization_google( $echo = TRUE ) {
859
-		if($echo){
860
-			echo EE_Registry::instance()->CFG->organization->get_pretty( 'google' );
858
+	function espresso_organization_google($echo = TRUE) {
859
+		if ($echo) {
860
+			echo EE_Registry::instance()->CFG->organization->get_pretty('google');
861 861
 			return '';
862 862
 		}
863
-		return EE_Registry::instance()->CFG->organization->get_pretty( 'google' );
863
+		return EE_Registry::instance()->CFG->organization->get_pretty('google');
864 864
 	}
865 865
 }
866 866
 
867
-if ( ! function_exists( 'espresso_organization_instagram' )) {
867
+if ( ! function_exists('espresso_organization_instagram')) {
868 868
 	/**
869 869
 	 * espresso_organization_instagram
870 870
 	 * @param bool $echo
871 871
 	 * @return string
872 872
 	 */
873
-	function espresso_organization_instagram( $echo = TRUE ) {
874
-		if($echo){
875
-			echo EE_Registry::instance()->CFG->organization->get_pretty( 'instagram' );
873
+	function espresso_organization_instagram($echo = TRUE) {
874
+		if ($echo) {
875
+			echo EE_Registry::instance()->CFG->organization->get_pretty('instagram');
876 876
 			return '';
877 877
 		}
878
-		return EE_Registry::instance()->CFG->organization->get_pretty( 'instagram' );
878
+		return EE_Registry::instance()->CFG->organization->get_pretty('instagram');
879 879
 	}
880 880
 }
881 881
 
@@ -885,7 +885,7 @@  discard block
 block discarded – undo
885 885
 
886 886
 
887 887
 
888
-if ( ! function_exists( 'espresso_event_venues' )) {
888
+if ( ! function_exists('espresso_event_venues')) {
889 889
 	/**
890 890
 	 * espresso_event_venues
891 891
 	 *
@@ -899,7 +899,7 @@  discard block
 block discarded – undo
899 899
 
900 900
 
901 901
 
902
-if ( ! function_exists( 'espresso_venue_id' )) {
902
+if ( ! function_exists('espresso_venue_id')) {
903 903
 	/**
904 904
 	 *    espresso_venue_name
905 905
 	 *
@@ -907,15 +907,15 @@  discard block
 block discarded – undo
907 907
 	 * @param     int $EVT_ID
908 908
 	 * @return    string
909 909
 	 */
910
-	function espresso_venue_id( $EVT_ID = 0 ) {
911
-		$venue = EEH_Venue_View::get_venue( $EVT_ID );
910
+	function espresso_venue_id($EVT_ID = 0) {
911
+		$venue = EEH_Venue_View::get_venue($EVT_ID);
912 912
 		return $venue instanceof EE_Venue ? $venue->ID() : 0;
913 913
 	}
914 914
 }
915 915
 
916 916
 
917 917
 
918
-if ( ! function_exists( 'espresso_is_venue_private' ) ) {
918
+if ( ! function_exists('espresso_is_venue_private')) {
919 919
 	/**
920 920
 	 * Return whether a venue is private or not.
921 921
 	 * @see EEH_Venue_View::get_venue() for more info on expected return results.
@@ -924,45 +924,45 @@  discard block
 block discarded – undo
924 924
 	 *
925 925
 	 * @return bool | null
926 926
 	 */
927
-	function espresso_is_venue_private( $VNU_ID = 0 ) {
928
-		return EEH_Venue_View::is_venue_private( $VNU_ID );
927
+	function espresso_is_venue_private($VNU_ID = 0) {
928
+		return EEH_Venue_View::is_venue_private($VNU_ID);
929 929
 	}
930 930
 }
931 931
 
932 932
 
933 933
 
934
-if ( ! function_exists( 'espresso_venue_is_password_protected' ) ) {
934
+if ( ! function_exists('espresso_venue_is_password_protected')) {
935 935
 	/**
936 936
 	 * returns true or false if a venue is password protected or not
937 937
 	 *
938 938
 	 * @param int     $VNU_ID optional, the venue id to check.
939 939
 	 * @return string
940 940
 	 */
941
-	function espresso_venue_is_password_protected( $VNU_ID = 0 ) {
942
-		EE_Registry::instance()->load_helper( 'Venue_View' );
943
-		return EEH_Venue_View::is_venue_password_protected( $VNU_ID );
941
+	function espresso_venue_is_password_protected($VNU_ID = 0) {
942
+		EE_Registry::instance()->load_helper('Venue_View');
943
+		return EEH_Venue_View::is_venue_password_protected($VNU_ID);
944 944
 	}
945 945
 }
946 946
 
947 947
 
948 948
 
949
-if ( ! function_exists( 'espresso_password_protected_venue_form' ) ) {
949
+if ( ! function_exists('espresso_password_protected_venue_form')) {
950 950
 	/**
951 951
 	 * Returns a password form if venue is password protected.
952 952
 	 *
953 953
 	 * @param int     $VNU_ID optional, the venue id to check.
954 954
 	 * @return string
955 955
 	 */
956
-	function espresso_password_protected_venue_form( $VNU_ID = 0 ) {
957
-		EE_Registry::instance()->load_helper( 'Venue_View' );
958
-		return EEH_Venue_View::password_protected_venue_form( $VNU_ID );
956
+	function espresso_password_protected_venue_form($VNU_ID = 0) {
957
+		EE_Registry::instance()->load_helper('Venue_View');
958
+		return EEH_Venue_View::password_protected_venue_form($VNU_ID);
959 959
 	}
960 960
 }
961 961
 
962 962
 
963 963
 
964 964
 
965
-if ( ! function_exists( 'espresso_venue_name' )) {
965
+if ( ! function_exists('espresso_venue_name')) {
966 966
 	/**
967 967
 	 *    espresso_venue_name
968 968
 	 *
@@ -972,19 +972,19 @@  discard block
 block discarded – undo
972 972
 	 * @param bool   $echo
973 973
 	 * @return    string
974 974
 	 */
975
-	function espresso_venue_name( $VNU_ID = 0, $link_to = 'details', $echo = TRUE ) {
976
-		if($echo){
977
-			echo EEH_Venue_View::venue_name( $link_to, $VNU_ID );
975
+	function espresso_venue_name($VNU_ID = 0, $link_to = 'details', $echo = TRUE) {
976
+		if ($echo) {
977
+			echo EEH_Venue_View::venue_name($link_to, $VNU_ID);
978 978
 			return '';
979 979
 		}
980
-		return EEH_Venue_View::venue_name( $link_to, $VNU_ID );
980
+		return EEH_Venue_View::venue_name($link_to, $VNU_ID);
981 981
 	}
982 982
 }
983 983
 
984 984
 
985 985
 
986 986
 
987
-if ( ! function_exists( 'espresso_venue_link' )) {
987
+if ( ! function_exists('espresso_venue_link')) {
988 988
 	/**
989 989
 	 * 	espresso_venue_link
990 990
 	 *
@@ -993,14 +993,14 @@  discard block
 block discarded – undo
993 993
 	 *  @param 	string 	$text
994 994
 	 *  @return 	string
995 995
 	 */
996
-	function espresso_venue_link( $VNU_ID = 0, $text = '' ) {
997
-		return EEH_Venue_View::venue_details_link( $VNU_ID, $text );
996
+	function espresso_venue_link($VNU_ID = 0, $text = '') {
997
+		return EEH_Venue_View::venue_details_link($VNU_ID, $text);
998 998
 	}
999 999
 }
1000 1000
 
1001 1001
 
1002 1002
 
1003
-if ( ! function_exists( 'espresso_venue_description' )) {
1003
+if ( ! function_exists('espresso_venue_description')) {
1004 1004
 	/**
1005 1005
 	 *    espresso_venue_description
1006 1006
 	 *
@@ -1009,17 +1009,17 @@  discard block
 block discarded – undo
1009 1009
 	 * @param bool $echo
1010 1010
 	 * @return    string
1011 1011
 	 */
1012
-	function espresso_venue_description( $VNU_ID = FALSE, $echo = TRUE ) {
1013
-		if($echo){
1014
-			echo EEH_Venue_View::venue_description( $VNU_ID );
1012
+	function espresso_venue_description($VNU_ID = FALSE, $echo = TRUE) {
1013
+		if ($echo) {
1014
+			echo EEH_Venue_View::venue_description($VNU_ID);
1015 1015
 			return '';
1016 1016
 		}
1017
-		return EEH_Venue_View::venue_description( $VNU_ID );
1017
+		return EEH_Venue_View::venue_description($VNU_ID);
1018 1018
 	}
1019 1019
 }
1020 1020
 
1021 1021
 
1022
-if ( ! function_exists( 'espresso_venue_excerpt' )) {
1022
+if ( ! function_exists('espresso_venue_excerpt')) {
1023 1023
 	/**
1024 1024
 	 *    espresso_venue_excerpt
1025 1025
 	 *
@@ -1028,18 +1028,18 @@  discard block
 block discarded – undo
1028 1028
 	 * @param bool $echo
1029 1029
 	 * @return    string
1030 1030
 	 */
1031
-	function espresso_venue_excerpt( $VNU_ID = 0,  $echo = TRUE ) {
1032
-		if ( $echo ) {
1033
-			echo EEH_Venue_View::venue_excerpt( $VNU_ID );
1031
+	function espresso_venue_excerpt($VNU_ID = 0, $echo = TRUE) {
1032
+		if ($echo) {
1033
+			echo EEH_Venue_View::venue_excerpt($VNU_ID);
1034 1034
 			return '';
1035 1035
 		}
1036
-		return EEH_Venue_View::venue_excerpt( $VNU_ID );
1036
+		return EEH_Venue_View::venue_excerpt($VNU_ID);
1037 1037
 	}
1038 1038
 }
1039 1039
 
1040 1040
 
1041 1041
 
1042
-if ( ! function_exists( 'espresso_venue_categories' )) {
1042
+if ( ! function_exists('espresso_venue_categories')) {
1043 1043
 	/**
1044 1044
 	 * espresso_venue_categories
1045 1045
 	 * returns the terms associated with a venue
@@ -1049,17 +1049,17 @@  discard block
 block discarded – undo
1049 1049
 	 * @param bool $echo
1050 1050
 	 * @return string
1051 1051
 	 */
1052
-	function espresso_venue_categories( $VNU_ID = 0, $hide_uncategorized = TRUE,  $echo = TRUE ) {
1053
-		if ( $echo ) {
1054
-			echo EEH_Venue_View::venue_categories( $VNU_ID, $hide_uncategorized );
1052
+	function espresso_venue_categories($VNU_ID = 0, $hide_uncategorized = TRUE, $echo = TRUE) {
1053
+		if ($echo) {
1054
+			echo EEH_Venue_View::venue_categories($VNU_ID, $hide_uncategorized);
1055 1055
 			return '';
1056 1056
 		}
1057
-		return EEH_Venue_View::venue_categories( $VNU_ID, $hide_uncategorized );
1057
+		return EEH_Venue_View::venue_categories($VNU_ID, $hide_uncategorized);
1058 1058
 	}
1059 1059
 }
1060 1060
 
1061 1061
 
1062
-if ( ! function_exists( 'espresso_venue_address' )) {
1062
+if ( ! function_exists('espresso_venue_address')) {
1063 1063
 	/**
1064 1064
 	 * espresso_venue_address
1065 1065
 	 * returns a formatted block of html  for displaying a venue's address
@@ -1069,17 +1069,17 @@  discard block
 block discarded – undo
1069 1069
 	 * @param bool   $echo
1070 1070
 	 * @return string
1071 1071
 	 */
1072
-	function espresso_venue_address( $type = 'multiline', $VNU_ID = 0, $echo = TRUE ) {
1073
-		if ( $echo ) {
1074
-			echo EEH_Venue_View::venue_address( $type, $VNU_ID );
1072
+	function espresso_venue_address($type = 'multiline', $VNU_ID = 0, $echo = TRUE) {
1073
+		if ($echo) {
1074
+			echo EEH_Venue_View::venue_address($type, $VNU_ID);
1075 1075
 			return '';
1076 1076
 		}
1077
-		return EEH_Venue_View::venue_address( $type, $VNU_ID );
1077
+		return EEH_Venue_View::venue_address($type, $VNU_ID);
1078 1078
 	}
1079 1079
 }
1080 1080
 
1081 1081
 
1082
-if ( ! function_exists( 'espresso_venue_raw_address' )) {
1082
+if ( ! function_exists('espresso_venue_raw_address')) {
1083 1083
 	/**
1084 1084
 	 * espresso_venue_address
1085 1085
 	 * returns an UN-formatted string containing a venue's address
@@ -1089,17 +1089,17 @@  discard block
 block discarded – undo
1089 1089
 	 * @param bool     $echo
1090 1090
 	 * @return string
1091 1091
 	 */
1092
-	function espresso_venue_raw_address( $type = 'multiline', $VNU_ID = 0, $echo = TRUE ) {
1093
-		if ( $echo ) {
1094
-			echo EEH_Venue_View::venue_address( $type, $VNU_ID, FALSE, FALSE );
1092
+	function espresso_venue_raw_address($type = 'multiline', $VNU_ID = 0, $echo = TRUE) {
1093
+		if ($echo) {
1094
+			echo EEH_Venue_View::venue_address($type, $VNU_ID, FALSE, FALSE);
1095 1095
 			return '';
1096 1096
 		}
1097
-		return EEH_Venue_View::venue_address( $type, $VNU_ID, FALSE, FALSE );
1097
+		return EEH_Venue_View::venue_address($type, $VNU_ID, FALSE, FALSE);
1098 1098
 	}
1099 1099
 }
1100 1100
 
1101 1101
 
1102
-if ( ! function_exists( 'espresso_venue_has_address' )) {
1102
+if ( ! function_exists('espresso_venue_has_address')) {
1103 1103
 	/**
1104 1104
 	 * espresso_venue_has_address
1105 1105
 	 * returns TRUE or FALSE if a Venue has address information
@@ -1107,13 +1107,13 @@  discard block
 block discarded – undo
1107 1107
 	 * @param int $VNU_ID
1108 1108
 	 * @return bool
1109 1109
 	 */
1110
-	function espresso_venue_has_address( $VNU_ID = 0 ) {
1111
-		return EEH_Venue_View::venue_has_address( $VNU_ID );
1110
+	function espresso_venue_has_address($VNU_ID = 0) {
1111
+		return EEH_Venue_View::venue_has_address($VNU_ID);
1112 1112
 	}
1113 1113
 }
1114 1114
 
1115 1115
 
1116
-if ( ! function_exists( 'espresso_venue_gmap' )) {
1116
+if ( ! function_exists('espresso_venue_gmap')) {
1117 1117
 	/**
1118 1118
 	 * espresso_venue_gmap
1119 1119
 	 * returns a google map for the venue address
@@ -1124,17 +1124,17 @@  discard block
 block discarded – undo
1124 1124
 	 * @param bool     $echo
1125 1125
 	 * @return string
1126 1126
 	 */
1127
-	function espresso_venue_gmap( $VNU_ID = 0, $map_ID = FALSE, $gmap = array(), $echo = TRUE  ) {
1128
-		if ( $echo ) {
1129
-			echo EEH_Venue_View::venue_gmap( $VNU_ID, $map_ID, $gmap );
1127
+	function espresso_venue_gmap($VNU_ID = 0, $map_ID = FALSE, $gmap = array(), $echo = TRUE) {
1128
+		if ($echo) {
1129
+			echo EEH_Venue_View::venue_gmap($VNU_ID, $map_ID, $gmap);
1130 1130
 			return '';
1131 1131
 		}
1132
-		return EEH_Venue_View::venue_gmap( $VNU_ID, $map_ID, $gmap );
1132
+		return EEH_Venue_View::venue_gmap($VNU_ID, $map_ID, $gmap);
1133 1133
 	}
1134 1134
 }
1135 1135
 
1136 1136
 
1137
-if ( ! function_exists( 'espresso_venue_phone' )) {
1137
+if ( ! function_exists('espresso_venue_phone')) {
1138 1138
 	/**
1139 1139
 	 * espresso_venue_phone
1140 1140
 	 *
@@ -1142,18 +1142,18 @@  discard block
 block discarded – undo
1142 1142
 	 * @param bool $echo
1143 1143
 	 * @return string
1144 1144
 	 */
1145
-	function espresso_venue_phone( $VNU_ID = 0, $echo = TRUE ) {
1146
-		if ( $echo ) {
1147
-			echo EEH_Venue_View::venue_phone( $VNU_ID );
1145
+	function espresso_venue_phone($VNU_ID = 0, $echo = TRUE) {
1146
+		if ($echo) {
1147
+			echo EEH_Venue_View::venue_phone($VNU_ID);
1148 1148
 			return '';
1149 1149
 		}
1150
-		return EEH_Venue_View::venue_phone( $VNU_ID );
1150
+		return EEH_Venue_View::venue_phone($VNU_ID);
1151 1151
 	}
1152 1152
 }
1153 1153
 
1154 1154
 
1155 1155
 
1156
-if ( ! function_exists( 'espresso_venue_website' )) {
1156
+if ( ! function_exists('espresso_venue_website')) {
1157 1157
 	/**
1158 1158
 	 * espresso_venue_website
1159 1159
 	 *
@@ -1161,18 +1161,18 @@  discard block
 block discarded – undo
1161 1161
 	 * @param bool $echo
1162 1162
 	 * @return string
1163 1163
 	 */
1164
-	function espresso_venue_website( $VNU_ID = 0, $echo = TRUE ) {
1165
-		if ( $echo ) {
1166
-			echo EEH_Venue_View::venue_website_link( $VNU_ID );
1164
+	function espresso_venue_website($VNU_ID = 0, $echo = TRUE) {
1165
+		if ($echo) {
1166
+			echo EEH_Venue_View::venue_website_link($VNU_ID);
1167 1167
 			return '';
1168 1168
 		}
1169
-		return EEH_Venue_View::venue_website_link( $VNU_ID );
1169
+		return EEH_Venue_View::venue_website_link($VNU_ID);
1170 1170
 	}
1171 1171
 }
1172 1172
 
1173 1173
 
1174 1174
 
1175
-if ( ! function_exists( 'espresso_edit_venue_link' )) {
1175
+if ( ! function_exists('espresso_edit_venue_link')) {
1176 1176
 	/**
1177 1177
 	 * espresso_edit_venue_link
1178 1178
 	 *
@@ -1180,12 +1180,12 @@  discard block
 block discarded – undo
1180 1180
 	 * @param bool $echo
1181 1181
 	 * @return string
1182 1182
 	 */
1183
-	function espresso_edit_venue_link( $VNU_ID = 0, $echo = TRUE ) {
1184
-		if($echo){
1185
-			echo EEH_Venue_View::edit_venue_link( $VNU_ID );
1183
+	function espresso_edit_venue_link($VNU_ID = 0, $echo = TRUE) {
1184
+		if ($echo) {
1185
+			echo EEH_Venue_View::edit_venue_link($VNU_ID);
1186 1186
 			return '';
1187 1187
 		}
1188
-		return EEH_Venue_View::edit_venue_link( $VNU_ID );
1188
+		return EEH_Venue_View::edit_venue_link($VNU_ID);
1189 1189
 	}
1190 1190
 }
1191 1191
 
Please login to merge, or discard this patch.
core/services/notifications/PersistentAdminNoticeManager.php 2 patches
Indentation   +381 added lines, -381 removed lines patch added patch discarded remove patch
@@ -31,385 +31,385 @@
 block discarded – undo
31 31
 class PersistentAdminNoticeManager
32 32
 {
33 33
 
34
-    const WP_OPTION_KEY = 'ee_pers_admin_notices';
35
-
36
-    /**
37
-     * @var Collection|PersistentAdminNotice[] $notice_collection
38
-     */
39
-    private $notice_collection;
40
-
41
-    /**
42
-     * if AJAX is not enabled, then the return URL will be used for redirecting back to the admin page where the
43
-     * persistent admin notice was displayed, and ultimately dismissed from.
44
-     *
45
-     * @var string $return_url
46
-     */
47
-    private $return_url;
48
-
49
-    /**
50
-     * @var CapabilitiesChecker $capabilities_checker
51
-     */
52
-    private $capabilities_checker;
53
-
54
-    /**
55
-     * @var RequestInterface $request
56
-     */
57
-    private $request;
58
-
59
-
60
-    /**
61
-     * PersistentAdminNoticeManager constructor
62
-     *
63
-     * @param string              $return_url where to  redirect to after dismissing notices
64
-     * @param CapabilitiesChecker $capabilities_checker
65
-     * @param RequestInterface          $request
66
-     * @throws InvalidDataTypeException
67
-     */
68
-    public function __construct($return_url = '', CapabilitiesChecker $capabilities_checker, RequestInterface $request)
69
-    {
70
-        $this->setReturnUrl($return_url);
71
-        $this->capabilities_checker = $capabilities_checker;
72
-        $this->request = $request;
73
-        // setup up notices at priority 9 because `EE_Admin::display_admin_notices()` runs at priority 10,
74
-        // and we want to retrieve and generate any nag notices at the last possible moment
75
-        add_action('admin_notices', array($this, 'displayNotices'), 9);
76
-        add_action('network_admin_notices', array($this, 'displayNotices'), 9);
77
-        add_action('wp_ajax_dismiss_ee_nag_notice', array($this, 'dismissNotice'));
78
-        add_action('shutdown', array($this, 'registerAndSaveNotices'), 998);
79
-    }
80
-
81
-
82
-    /**
83
-     * @param string $return_url
84
-     * @throws InvalidDataTypeException
85
-     */
86
-    public function setReturnUrl($return_url)
87
-    {
88
-        if (! is_string($return_url)) {
89
-            throw new InvalidDataTypeException('$return_url', $return_url, 'string');
90
-        }
91
-        $this->return_url = $return_url;
92
-    }
93
-
94
-
95
-    /**
96
-     * @return Collection
97
-     * @throws InvalidEntityException
98
-     * @throws InvalidInterfaceException
99
-     * @throws InvalidDataTypeException
100
-     * @throws DomainException
101
-     * @throws DuplicateCollectionIdentifierException
102
-     */
103
-    protected function getPersistentAdminNoticeCollection()
104
-    {
105
-        if (! $this->notice_collection instanceof Collection) {
106
-            $this->notice_collection = new Collection(
107
-                'EventEspresso\core\domain\entities\notifications\PersistentAdminNotice'
108
-            );
109
-            $this->retrieveStoredNotices();
110
-            $this->registerNotices();
111
-        }
112
-        return $this->notice_collection;
113
-    }
114
-
115
-
116
-    /**
117
-     * generates PersistentAdminNotice objects for all non-dismissed notices saved to the db
118
-     *
119
-     * @return void
120
-     * @throws InvalidEntityException
121
-     * @throws DomainException
122
-     * @throws InvalidDataTypeException
123
-     * @throws DuplicateCollectionIdentifierException
124
-     */
125
-    protected function retrieveStoredNotices()
126
-    {
127
-        $persistent_admin_notices = get_option(PersistentAdminNoticeManager::WP_OPTION_KEY, array());
128
-        if (! empty($persistent_admin_notices)) {
129
-            foreach ($persistent_admin_notices as $name => $details) {
130
-                if (is_array($details)) {
131
-                    if (! isset(
132
-                        $details['message'],
133
-                        $details['capability'],
134
-                        $details['cap_context'],
135
-                        $details['dismissed']
136
-                    )) {
137
-                        throw new DomainException(
138
-                            sprintf(
139
-                                esc_html__(
140
-                                    'The "%1$s" PersistentAdminNotice could not be retrieved from the database.',
141
-                                    'event_espresso'
142
-                                ),
143
-                                $name
144
-                            )
145
-                        );
146
-                    }
147
-                    // new format for nag notices
148
-                    $this->notice_collection->add(
149
-                        new PersistentAdminNotice(
150
-                            $name,
151
-                            $details['message'],
152
-                            false,
153
-                            $details['capability'],
154
-                            $details['cap_context'],
155
-                            $details['dismissed']
156
-                        ),
157
-                        sanitize_key($name)
158
-                    );
159
-                } else {
160
-                    try {
161
-                        // old nag notices, that we want to convert to the new format
162
-                        $this->notice_collection->add(
163
-                            new PersistentAdminNotice(
164
-                                $name,
165
-                                (string) $details,
166
-                                false,
167
-                                '',
168
-                                '',
169
-                                empty($details)
170
-                            ),
171
-                            sanitize_key($name)
172
-                        );
173
-                    } catch (Exception $e) {
174
-                        EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
175
-                    }
176
-                }
177
-                // each notice will self register when the action hook in registerNotices is triggered
178
-            }
179
-        }
180
-    }
181
-
182
-
183
-    /**
184
-     * exposes the Persistent Admin Notice Collection via an action
185
-     * so that PersistentAdminNotice objects can be added and/or removed
186
-     * without compromising the actual collection like a filter would
187
-     */
188
-    protected function registerNotices()
189
-    {
190
-        do_action(
191
-            'AHEE__EventEspresso_core_services_notifications_PersistentAdminNoticeManager__registerNotices',
192
-            $this->notice_collection
193
-        );
194
-    }
195
-
196
-
197
-    /**
198
-     * @throws DomainException
199
-     * @throws InvalidClassException
200
-     * @throws InvalidDataTypeException
201
-     * @throws InvalidInterfaceException
202
-     * @throws InvalidEntityException
203
-     * @throws DuplicateCollectionIdentifierException
204
-     */
205
-    public function displayNotices()
206
-    {
207
-        $this->notice_collection = $this->getPersistentAdminNoticeCollection();
208
-        if ($this->notice_collection->hasObjects()) {
209
-            $enqueue_assets = false;
210
-            // and display notices
211
-            foreach ($this->notice_collection as $persistent_admin_notice) {
212
-                /** @var PersistentAdminNotice $persistent_admin_notice */
213
-                // don't display notices that have already been dismissed
214
-                if ($persistent_admin_notice->getDismissed()) {
215
-                    continue;
216
-                }
217
-                try {
218
-                    $this->capabilities_checker->processCapCheck(
219
-                        $persistent_admin_notice->getCapCheck()
220
-                    );
221
-                } catch (InsufficientPermissionsException $e) {
222
-                    // user does not have required cap, so skip to next notice
223
-                    // and just eat the exception - nom nom nom nom
224
-                    continue;
225
-                }
226
-                if ($persistent_admin_notice->getMessage() === '') {
227
-                    continue;
228
-                }
229
-                $this->displayPersistentAdminNotice($persistent_admin_notice);
230
-                $enqueue_assets = true;
231
-            }
232
-            if ($enqueue_assets) {
233
-                $this->enqueueAssets();
234
-            }
235
-        }
236
-    }
237
-
238
-
239
-    /**
240
-     * does what it's named
241
-     *
242
-     * @return void
243
-     */
244
-    public function enqueueAssets()
245
-    {
246
-        wp_register_script(
247
-            'espresso_core',
248
-            EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js',
249
-            array('jquery'),
250
-            EVENT_ESPRESSO_VERSION,
251
-            true
252
-        );
253
-        wp_register_script(
254
-            'ee_error_js',
255
-            EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js',
256
-            array('espresso_core'),
257
-            EVENT_ESPRESSO_VERSION,
258
-            true
259
-        );
260
-        wp_localize_script(
261
-            'ee_error_js',
262
-            'ee_dismiss',
263
-            array(
264
-                'return_url'    => urlencode($this->return_url),
265
-                'ajax_url'      => WP_AJAX_URL,
266
-                'unknown_error' => esc_html__(
267
-                    'An unknown error has occurred on the server while attempting to dismiss this notice.',
268
-                    'event_espresso'
269
-                ),
270
-            )
271
-        );
272
-        wp_enqueue_script('ee_error_js');
273
-    }
274
-
275
-
276
-    /**
277
-     * displayPersistentAdminNoticeHtml
278
-     *
279
-     * @param  PersistentAdminNotice $persistent_admin_notice
280
-     */
281
-    protected function displayPersistentAdminNotice(PersistentAdminNotice $persistent_admin_notice)
282
-    {
283
-        // used in template
284
-        $persistent_admin_notice_name = $persistent_admin_notice->getName();
285
-        $persistent_admin_notice_message = $persistent_admin_notice->getMessage();
286
-        require EE_TEMPLATES . DS . 'notifications' . DS . 'persistent_admin_notice.template.php';
287
-    }
288
-
289
-
290
-    /**
291
-     * dismissNotice
292
-     *
293
-     * @param string $pan_name the name, or key of the Persistent Admin Notice to be dismissed
294
-     * @param bool   $purge    if true, then delete it from the db
295
-     * @param bool   $return   forget all of this AJAX or redirect nonsense, and just return
296
-     * @return void
297
-     * @throws InvalidEntityException
298
-     * @throws InvalidInterfaceException
299
-     * @throws InvalidDataTypeException
300
-     * @throws DomainException
301
-     * @throws InvalidArgumentException
302
-     * @throws InvalidArgumentException
303
-     * @throws InvalidArgumentException
304
-     * @throws InvalidArgumentException
305
-     * @throws DuplicateCollectionIdentifierException
306
-     */
307
-    public function dismissNotice($pan_name = '', $purge = false, $return = false)
308
-    {
309
-        $pan_name = $this->request->getRequestParam('ee_nag_notice', $pan_name);
310
-        $this->notice_collection = $this->getPersistentAdminNoticeCollection();
311
-        if (! empty($pan_name) && $this->notice_collection->has($pan_name)) {
312
-            /** @var PersistentAdminNotice $persistent_admin_notice */
313
-            $persistent_admin_notice = $this->notice_collection->get($pan_name);
314
-            $persistent_admin_notice->setDismissed(true);
315
-            $persistent_admin_notice->setPurge($purge);
316
-            $this->saveNotices();
317
-        }
318
-        if ($return) {
319
-            return;
320
-        }
321
-        if ($this->request->isAjax()) {
322
-            // grab any notices and concatenate into string
323
-            echo wp_json_encode(
324
-                array(
325
-                    'errors' => implode('<br />', EE_Error::get_notices(false)),
326
-                )
327
-            );
328
-            exit();
329
-        }
330
-        // save errors to a transient to be displayed on next request (after redirect)
331
-        EE_Error::get_notices(false, true);
332
-        wp_safe_redirect(
333
-            urldecode(
334
-                $this->request->getRequestParam('return_url', '')
335
-            )
336
-        );
337
-    }
338
-
339
-
340
-    /**
341
-     * saveNotices
342
-     *
343
-     * @throws DomainException
344
-     * @throws InvalidDataTypeException
345
-     * @throws InvalidInterfaceException
346
-     * @throws InvalidEntityException
347
-     * @throws DuplicateCollectionIdentifierException
348
-     */
349
-    public function saveNotices()
350
-    {
351
-        $this->notice_collection = $this->getPersistentAdminNoticeCollection();
352
-        if ($this->notice_collection->hasObjects()) {
353
-            $persistent_admin_notices = get_option(PersistentAdminNoticeManager::WP_OPTION_KEY, array());
354
-            // maybe initialize persistent_admin_notices
355
-            if (empty($persistent_admin_notices)) {
356
-                add_option(PersistentAdminNoticeManager::WP_OPTION_KEY, array(), '', 'no');
357
-            }
358
-            foreach ($this->notice_collection as $persistent_admin_notice) {
359
-                // are we deleting this notice ?
360
-                if ($persistent_admin_notice->getPurge()) {
361
-                    unset($persistent_admin_notices[ $persistent_admin_notice->getName() ]);
362
-                } else {
363
-                    /** @var PersistentAdminNotice $persistent_admin_notice */
364
-                    $persistent_admin_notices[ $persistent_admin_notice->getName() ] = array(
365
-                        'message'     => $persistent_admin_notice->getMessage(),
366
-                        'capability'  => $persistent_admin_notice->getCapability(),
367
-                        'cap_context' => $persistent_admin_notice->getCapContext(),
368
-                        'dismissed'   => $persistent_admin_notice->getDismissed(),
369
-                    );
370
-                }
371
-            }
372
-            update_option(PersistentAdminNoticeManager::WP_OPTION_KEY, $persistent_admin_notices);
373
-        }
374
-    }
375
-
376
-
377
-    /**
378
-     * @throws DomainException
379
-     * @throws InvalidDataTypeException
380
-     * @throws InvalidEntityException
381
-     * @throws InvalidInterfaceException
382
-     * @throws DuplicateCollectionIdentifierException
383
-     */
384
-    public function registerAndSaveNotices()
385
-    {
386
-        $this->getPersistentAdminNoticeCollection();
387
-        $this->registerNotices();
388
-        $this->saveNotices();
389
-        add_filter(
390
-            'PersistentAdminNoticeManager__registerAndSaveNotices__complete',
391
-            '__return_true'
392
-        );
393
-    }
394
-
395
-
396
-    /**
397
-     * @throws DomainException
398
-     * @throws InvalidDataTypeException
399
-     * @throws InvalidEntityException
400
-     * @throws InvalidInterfaceException
401
-     * @throws InvalidArgumentException
402
-     * @throws DuplicateCollectionIdentifierException
403
-     */
404
-    public static function loadRegisterAndSaveNotices()
405
-    {
406
-        /** @var PersistentAdminNoticeManager $persistent_admin_notice_manager */
407
-        $persistent_admin_notice_manager = LoaderFactory::getLoader()->getShared(
408
-            'EventEspresso\core\services\notifications\PersistentAdminNoticeManager'
409
-        );
410
-        // if shutdown has already run, then call registerAndSaveNotices() manually
411
-        if (did_action('shutdown')) {
412
-            $persistent_admin_notice_manager->registerAndSaveNotices();
413
-        }
414
-    }
34
+	const WP_OPTION_KEY = 'ee_pers_admin_notices';
35
+
36
+	/**
37
+	 * @var Collection|PersistentAdminNotice[] $notice_collection
38
+	 */
39
+	private $notice_collection;
40
+
41
+	/**
42
+	 * if AJAX is not enabled, then the return URL will be used for redirecting back to the admin page where the
43
+	 * persistent admin notice was displayed, and ultimately dismissed from.
44
+	 *
45
+	 * @var string $return_url
46
+	 */
47
+	private $return_url;
48
+
49
+	/**
50
+	 * @var CapabilitiesChecker $capabilities_checker
51
+	 */
52
+	private $capabilities_checker;
53
+
54
+	/**
55
+	 * @var RequestInterface $request
56
+	 */
57
+	private $request;
58
+
59
+
60
+	/**
61
+	 * PersistentAdminNoticeManager constructor
62
+	 *
63
+	 * @param string              $return_url where to  redirect to after dismissing notices
64
+	 * @param CapabilitiesChecker $capabilities_checker
65
+	 * @param RequestInterface          $request
66
+	 * @throws InvalidDataTypeException
67
+	 */
68
+	public function __construct($return_url = '', CapabilitiesChecker $capabilities_checker, RequestInterface $request)
69
+	{
70
+		$this->setReturnUrl($return_url);
71
+		$this->capabilities_checker = $capabilities_checker;
72
+		$this->request = $request;
73
+		// setup up notices at priority 9 because `EE_Admin::display_admin_notices()` runs at priority 10,
74
+		// and we want to retrieve and generate any nag notices at the last possible moment
75
+		add_action('admin_notices', array($this, 'displayNotices'), 9);
76
+		add_action('network_admin_notices', array($this, 'displayNotices'), 9);
77
+		add_action('wp_ajax_dismiss_ee_nag_notice', array($this, 'dismissNotice'));
78
+		add_action('shutdown', array($this, 'registerAndSaveNotices'), 998);
79
+	}
80
+
81
+
82
+	/**
83
+	 * @param string $return_url
84
+	 * @throws InvalidDataTypeException
85
+	 */
86
+	public function setReturnUrl($return_url)
87
+	{
88
+		if (! is_string($return_url)) {
89
+			throw new InvalidDataTypeException('$return_url', $return_url, 'string');
90
+		}
91
+		$this->return_url = $return_url;
92
+	}
93
+
94
+
95
+	/**
96
+	 * @return Collection
97
+	 * @throws InvalidEntityException
98
+	 * @throws InvalidInterfaceException
99
+	 * @throws InvalidDataTypeException
100
+	 * @throws DomainException
101
+	 * @throws DuplicateCollectionIdentifierException
102
+	 */
103
+	protected function getPersistentAdminNoticeCollection()
104
+	{
105
+		if (! $this->notice_collection instanceof Collection) {
106
+			$this->notice_collection = new Collection(
107
+				'EventEspresso\core\domain\entities\notifications\PersistentAdminNotice'
108
+			);
109
+			$this->retrieveStoredNotices();
110
+			$this->registerNotices();
111
+		}
112
+		return $this->notice_collection;
113
+	}
114
+
115
+
116
+	/**
117
+	 * generates PersistentAdminNotice objects for all non-dismissed notices saved to the db
118
+	 *
119
+	 * @return void
120
+	 * @throws InvalidEntityException
121
+	 * @throws DomainException
122
+	 * @throws InvalidDataTypeException
123
+	 * @throws DuplicateCollectionIdentifierException
124
+	 */
125
+	protected function retrieveStoredNotices()
126
+	{
127
+		$persistent_admin_notices = get_option(PersistentAdminNoticeManager::WP_OPTION_KEY, array());
128
+		if (! empty($persistent_admin_notices)) {
129
+			foreach ($persistent_admin_notices as $name => $details) {
130
+				if (is_array($details)) {
131
+					if (! isset(
132
+						$details['message'],
133
+						$details['capability'],
134
+						$details['cap_context'],
135
+						$details['dismissed']
136
+					)) {
137
+						throw new DomainException(
138
+							sprintf(
139
+								esc_html__(
140
+									'The "%1$s" PersistentAdminNotice could not be retrieved from the database.',
141
+									'event_espresso'
142
+								),
143
+								$name
144
+							)
145
+						);
146
+					}
147
+					// new format for nag notices
148
+					$this->notice_collection->add(
149
+						new PersistentAdminNotice(
150
+							$name,
151
+							$details['message'],
152
+							false,
153
+							$details['capability'],
154
+							$details['cap_context'],
155
+							$details['dismissed']
156
+						),
157
+						sanitize_key($name)
158
+					);
159
+				} else {
160
+					try {
161
+						// old nag notices, that we want to convert to the new format
162
+						$this->notice_collection->add(
163
+							new PersistentAdminNotice(
164
+								$name,
165
+								(string) $details,
166
+								false,
167
+								'',
168
+								'',
169
+								empty($details)
170
+							),
171
+							sanitize_key($name)
172
+						);
173
+					} catch (Exception $e) {
174
+						EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
175
+					}
176
+				}
177
+				// each notice will self register when the action hook in registerNotices is triggered
178
+			}
179
+		}
180
+	}
181
+
182
+
183
+	/**
184
+	 * exposes the Persistent Admin Notice Collection via an action
185
+	 * so that PersistentAdminNotice objects can be added and/or removed
186
+	 * without compromising the actual collection like a filter would
187
+	 */
188
+	protected function registerNotices()
189
+	{
190
+		do_action(
191
+			'AHEE__EventEspresso_core_services_notifications_PersistentAdminNoticeManager__registerNotices',
192
+			$this->notice_collection
193
+		);
194
+	}
195
+
196
+
197
+	/**
198
+	 * @throws DomainException
199
+	 * @throws InvalidClassException
200
+	 * @throws InvalidDataTypeException
201
+	 * @throws InvalidInterfaceException
202
+	 * @throws InvalidEntityException
203
+	 * @throws DuplicateCollectionIdentifierException
204
+	 */
205
+	public function displayNotices()
206
+	{
207
+		$this->notice_collection = $this->getPersistentAdminNoticeCollection();
208
+		if ($this->notice_collection->hasObjects()) {
209
+			$enqueue_assets = false;
210
+			// and display notices
211
+			foreach ($this->notice_collection as $persistent_admin_notice) {
212
+				/** @var PersistentAdminNotice $persistent_admin_notice */
213
+				// don't display notices that have already been dismissed
214
+				if ($persistent_admin_notice->getDismissed()) {
215
+					continue;
216
+				}
217
+				try {
218
+					$this->capabilities_checker->processCapCheck(
219
+						$persistent_admin_notice->getCapCheck()
220
+					);
221
+				} catch (InsufficientPermissionsException $e) {
222
+					// user does not have required cap, so skip to next notice
223
+					// and just eat the exception - nom nom nom nom
224
+					continue;
225
+				}
226
+				if ($persistent_admin_notice->getMessage() === '') {
227
+					continue;
228
+				}
229
+				$this->displayPersistentAdminNotice($persistent_admin_notice);
230
+				$enqueue_assets = true;
231
+			}
232
+			if ($enqueue_assets) {
233
+				$this->enqueueAssets();
234
+			}
235
+		}
236
+	}
237
+
238
+
239
+	/**
240
+	 * does what it's named
241
+	 *
242
+	 * @return void
243
+	 */
244
+	public function enqueueAssets()
245
+	{
246
+		wp_register_script(
247
+			'espresso_core',
248
+			EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js',
249
+			array('jquery'),
250
+			EVENT_ESPRESSO_VERSION,
251
+			true
252
+		);
253
+		wp_register_script(
254
+			'ee_error_js',
255
+			EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js',
256
+			array('espresso_core'),
257
+			EVENT_ESPRESSO_VERSION,
258
+			true
259
+		);
260
+		wp_localize_script(
261
+			'ee_error_js',
262
+			'ee_dismiss',
263
+			array(
264
+				'return_url'    => urlencode($this->return_url),
265
+				'ajax_url'      => WP_AJAX_URL,
266
+				'unknown_error' => esc_html__(
267
+					'An unknown error has occurred on the server while attempting to dismiss this notice.',
268
+					'event_espresso'
269
+				),
270
+			)
271
+		);
272
+		wp_enqueue_script('ee_error_js');
273
+	}
274
+
275
+
276
+	/**
277
+	 * displayPersistentAdminNoticeHtml
278
+	 *
279
+	 * @param  PersistentAdminNotice $persistent_admin_notice
280
+	 */
281
+	protected function displayPersistentAdminNotice(PersistentAdminNotice $persistent_admin_notice)
282
+	{
283
+		// used in template
284
+		$persistent_admin_notice_name = $persistent_admin_notice->getName();
285
+		$persistent_admin_notice_message = $persistent_admin_notice->getMessage();
286
+		require EE_TEMPLATES . DS . 'notifications' . DS . 'persistent_admin_notice.template.php';
287
+	}
288
+
289
+
290
+	/**
291
+	 * dismissNotice
292
+	 *
293
+	 * @param string $pan_name the name, or key of the Persistent Admin Notice to be dismissed
294
+	 * @param bool   $purge    if true, then delete it from the db
295
+	 * @param bool   $return   forget all of this AJAX or redirect nonsense, and just return
296
+	 * @return void
297
+	 * @throws InvalidEntityException
298
+	 * @throws InvalidInterfaceException
299
+	 * @throws InvalidDataTypeException
300
+	 * @throws DomainException
301
+	 * @throws InvalidArgumentException
302
+	 * @throws InvalidArgumentException
303
+	 * @throws InvalidArgumentException
304
+	 * @throws InvalidArgumentException
305
+	 * @throws DuplicateCollectionIdentifierException
306
+	 */
307
+	public function dismissNotice($pan_name = '', $purge = false, $return = false)
308
+	{
309
+		$pan_name = $this->request->getRequestParam('ee_nag_notice', $pan_name);
310
+		$this->notice_collection = $this->getPersistentAdminNoticeCollection();
311
+		if (! empty($pan_name) && $this->notice_collection->has($pan_name)) {
312
+			/** @var PersistentAdminNotice $persistent_admin_notice */
313
+			$persistent_admin_notice = $this->notice_collection->get($pan_name);
314
+			$persistent_admin_notice->setDismissed(true);
315
+			$persistent_admin_notice->setPurge($purge);
316
+			$this->saveNotices();
317
+		}
318
+		if ($return) {
319
+			return;
320
+		}
321
+		if ($this->request->isAjax()) {
322
+			// grab any notices and concatenate into string
323
+			echo wp_json_encode(
324
+				array(
325
+					'errors' => implode('<br />', EE_Error::get_notices(false)),
326
+				)
327
+			);
328
+			exit();
329
+		}
330
+		// save errors to a transient to be displayed on next request (after redirect)
331
+		EE_Error::get_notices(false, true);
332
+		wp_safe_redirect(
333
+			urldecode(
334
+				$this->request->getRequestParam('return_url', '')
335
+			)
336
+		);
337
+	}
338
+
339
+
340
+	/**
341
+	 * saveNotices
342
+	 *
343
+	 * @throws DomainException
344
+	 * @throws InvalidDataTypeException
345
+	 * @throws InvalidInterfaceException
346
+	 * @throws InvalidEntityException
347
+	 * @throws DuplicateCollectionIdentifierException
348
+	 */
349
+	public function saveNotices()
350
+	{
351
+		$this->notice_collection = $this->getPersistentAdminNoticeCollection();
352
+		if ($this->notice_collection->hasObjects()) {
353
+			$persistent_admin_notices = get_option(PersistentAdminNoticeManager::WP_OPTION_KEY, array());
354
+			// maybe initialize persistent_admin_notices
355
+			if (empty($persistent_admin_notices)) {
356
+				add_option(PersistentAdminNoticeManager::WP_OPTION_KEY, array(), '', 'no');
357
+			}
358
+			foreach ($this->notice_collection as $persistent_admin_notice) {
359
+				// are we deleting this notice ?
360
+				if ($persistent_admin_notice->getPurge()) {
361
+					unset($persistent_admin_notices[ $persistent_admin_notice->getName() ]);
362
+				} else {
363
+					/** @var PersistentAdminNotice $persistent_admin_notice */
364
+					$persistent_admin_notices[ $persistent_admin_notice->getName() ] = array(
365
+						'message'     => $persistent_admin_notice->getMessage(),
366
+						'capability'  => $persistent_admin_notice->getCapability(),
367
+						'cap_context' => $persistent_admin_notice->getCapContext(),
368
+						'dismissed'   => $persistent_admin_notice->getDismissed(),
369
+					);
370
+				}
371
+			}
372
+			update_option(PersistentAdminNoticeManager::WP_OPTION_KEY, $persistent_admin_notices);
373
+		}
374
+	}
375
+
376
+
377
+	/**
378
+	 * @throws DomainException
379
+	 * @throws InvalidDataTypeException
380
+	 * @throws InvalidEntityException
381
+	 * @throws InvalidInterfaceException
382
+	 * @throws DuplicateCollectionIdentifierException
383
+	 */
384
+	public function registerAndSaveNotices()
385
+	{
386
+		$this->getPersistentAdminNoticeCollection();
387
+		$this->registerNotices();
388
+		$this->saveNotices();
389
+		add_filter(
390
+			'PersistentAdminNoticeManager__registerAndSaveNotices__complete',
391
+			'__return_true'
392
+		);
393
+	}
394
+
395
+
396
+	/**
397
+	 * @throws DomainException
398
+	 * @throws InvalidDataTypeException
399
+	 * @throws InvalidEntityException
400
+	 * @throws InvalidInterfaceException
401
+	 * @throws InvalidArgumentException
402
+	 * @throws DuplicateCollectionIdentifierException
403
+	 */
404
+	public static function loadRegisterAndSaveNotices()
405
+	{
406
+		/** @var PersistentAdminNoticeManager $persistent_admin_notice_manager */
407
+		$persistent_admin_notice_manager = LoaderFactory::getLoader()->getShared(
408
+			'EventEspresso\core\services\notifications\PersistentAdminNoticeManager'
409
+		);
410
+		// if shutdown has already run, then call registerAndSaveNotices() manually
411
+		if (did_action('shutdown')) {
412
+			$persistent_admin_notice_manager->registerAndSaveNotices();
413
+		}
414
+	}
415 415
 }
Please login to merge, or discard this patch.
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -85,7 +85,7 @@  discard block
 block discarded – undo
85 85
      */
86 86
     public function setReturnUrl($return_url)
87 87
     {
88
-        if (! is_string($return_url)) {
88
+        if ( ! is_string($return_url)) {
89 89
             throw new InvalidDataTypeException('$return_url', $return_url, 'string');
90 90
         }
91 91
         $this->return_url = $return_url;
@@ -102,7 +102,7 @@  discard block
 block discarded – undo
102 102
      */
103 103
     protected function getPersistentAdminNoticeCollection()
104 104
     {
105
-        if (! $this->notice_collection instanceof Collection) {
105
+        if ( ! $this->notice_collection instanceof Collection) {
106 106
             $this->notice_collection = new Collection(
107 107
                 'EventEspresso\core\domain\entities\notifications\PersistentAdminNotice'
108 108
             );
@@ -125,10 +125,10 @@  discard block
 block discarded – undo
125 125
     protected function retrieveStoredNotices()
126 126
     {
127 127
         $persistent_admin_notices = get_option(PersistentAdminNoticeManager::WP_OPTION_KEY, array());
128
-        if (! empty($persistent_admin_notices)) {
128
+        if ( ! empty($persistent_admin_notices)) {
129 129
             foreach ($persistent_admin_notices as $name => $details) {
130 130
                 if (is_array($details)) {
131
-                    if (! isset(
131
+                    if ( ! isset(
132 132
                         $details['message'],
133 133
                         $details['capability'],
134 134
                         $details['cap_context'],
@@ -245,14 +245,14 @@  discard block
 block discarded – undo
245 245
     {
246 246
         wp_register_script(
247 247
             'espresso_core',
248
-            EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js',
248
+            EE_GLOBAL_ASSETS_URL.'scripts/espresso_core.js',
249 249
             array('jquery'),
250 250
             EVENT_ESPRESSO_VERSION,
251 251
             true
252 252
         );
253 253
         wp_register_script(
254 254
             'ee_error_js',
255
-            EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js',
255
+            EE_GLOBAL_ASSETS_URL.'scripts/EE_Error.js',
256 256
             array('espresso_core'),
257 257
             EVENT_ESPRESSO_VERSION,
258 258
             true
@@ -283,7 +283,7 @@  discard block
 block discarded – undo
283 283
         // used in template
284 284
         $persistent_admin_notice_name = $persistent_admin_notice->getName();
285 285
         $persistent_admin_notice_message = $persistent_admin_notice->getMessage();
286
-        require EE_TEMPLATES . DS . 'notifications' . DS . 'persistent_admin_notice.template.php';
286
+        require EE_TEMPLATES.DS.'notifications'.DS.'persistent_admin_notice.template.php';
287 287
     }
288 288
 
289 289
 
@@ -308,7 +308,7 @@  discard block
 block discarded – undo
308 308
     {
309 309
         $pan_name = $this->request->getRequestParam('ee_nag_notice', $pan_name);
310 310
         $this->notice_collection = $this->getPersistentAdminNoticeCollection();
311
-        if (! empty($pan_name) && $this->notice_collection->has($pan_name)) {
311
+        if ( ! empty($pan_name) && $this->notice_collection->has($pan_name)) {
312 312
             /** @var PersistentAdminNotice $persistent_admin_notice */
313 313
             $persistent_admin_notice = $this->notice_collection->get($pan_name);
314 314
             $persistent_admin_notice->setDismissed(true);
@@ -358,10 +358,10 @@  discard block
 block discarded – undo
358 358
             foreach ($this->notice_collection as $persistent_admin_notice) {
359 359
                 // are we deleting this notice ?
360 360
                 if ($persistent_admin_notice->getPurge()) {
361
-                    unset($persistent_admin_notices[ $persistent_admin_notice->getName() ]);
361
+                    unset($persistent_admin_notices[$persistent_admin_notice->getName()]);
362 362
                 } else {
363 363
                     /** @var PersistentAdminNotice $persistent_admin_notice */
364
-                    $persistent_admin_notices[ $persistent_admin_notice->getName() ] = array(
364
+                    $persistent_admin_notices[$persistent_admin_notice->getName()] = array(
365 365
                         'message'     => $persistent_admin_notice->getMessage(),
366 366
                         'capability'  => $persistent_admin_notice->getCapability(),
367 367
                         'cap_context' => $persistent_admin_notice->getCapContext(),
Please login to merge, or discard this patch.
core/domain/entities/notifications/PersistentAdminNotice.php 1 patch
Indentation   +312 added lines, -312 removed lines patch added patch discarded remove patch
@@ -25,316 +25,316 @@
 block discarded – undo
25 25
 class PersistentAdminNotice implements RequiresCapCheckInterface
26 26
 {
27 27
 
28
-    /**
29
-     * @var string $name
30
-     */
31
-    protected $name = '';
32
-
33
-    /**
34
-     * @var string $message
35
-     */
36
-    protected $message = '';
37
-
38
-    /**
39
-     * @var boolean $force_update
40
-     */
41
-    protected $force_update = false;
42
-
43
-    /**
44
-     * @var string $capability
45
-     */
46
-    protected $capability = 'manage_options';
47
-
48
-    /**
49
-     * @var string $cap_context
50
-     */
51
-    protected $cap_context = 'view persistent admin notice';
52
-
53
-    /**
54
-     * @var boolean $dismissed
55
-     */
56
-    protected $dismissed = false;
57
-
58
-    /**
59
-     * @var CapCheckInterface $cap_check
60
-     */
61
-    protected $cap_check;
62
-
63
-    /**
64
-     * if true, then this notice will be deleted from the database
65
-     *
66
-     * @var boolean $purge
67
-     */
68
-    protected $purge = false;
69
-
70
-    /**
71
-     * gets set to true if notice is successfully registered with the PersistentAdminNoticeManager
72
-     * if false, and WP_DEBUG is on, then an exception will be thrown in the admin footer
73
-     *
74
-     * @var boolean $registered
75
-     */
76
-    private $registered = false;
77
-
78
-
79
-    /**
80
-     * PersistentAdminNotice constructor
81
-     *
82
-     * @param string $name         [required] the name, or key of the Persistent Admin Notice to be stored
83
-     * @param string $message      [required] the message to be stored persistently until dismissed
84
-     * @param bool   $force_update enforce the reappearance of a persistent message
85
-     * @param string $capability   user capability required to view this notice
86
-     * @param string $cap_context  description for why the cap check is being performed
87
-     * @param bool   $dismissed    whether or not the user has already dismissed/viewed this notice
88
-     * @throws InvalidDataTypeException
89
-     */
90
-    public function __construct(
91
-        $name,
92
-        $message,
93
-        $force_update = false,
94
-        $capability = 'manage_options',
95
-        $cap_context = 'view persistent admin notice',
96
-        $dismissed = false
97
-    ) {
98
-        $this->setName($name);
99
-        $this->setMessage($message);
100
-        $this->setForceUpdate($force_update);
101
-        $this->setCapability($capability);
102
-        $this->setCapContext($cap_context);
103
-        $this->setDismissed($dismissed);
104
-        add_action(
105
-            'AHEE__EventEspresso_core_services_notifications_PersistentAdminNoticeManager__registerNotices',
106
-            array($this, 'registerPersistentAdminNotice')
107
-        );
108
-        add_action('shutdown', array($this, 'confirmRegistered'), 999);
109
-    }
110
-
111
-
112
-    /**
113
-     * @return string
114
-     */
115
-    public function getName()
116
-    {
117
-        return $this->name;
118
-    }
119
-
120
-
121
-    /**
122
-     * @param string $name
123
-     * @throws InvalidDataTypeException
124
-     */
125
-    private function setName($name)
126
-    {
127
-        if (! is_string($name)) {
128
-            throw new InvalidDataTypeException('$name', $name, 'string');
129
-        }
130
-        $this->name = sanitize_key($name);
131
-    }
132
-
133
-
134
-    /**
135
-     * @return string
136
-     */
137
-    public function getMessage()
138
-    {
139
-        return $this->message;
140
-    }
141
-
142
-
143
-    /**
144
-     * @param string $message
145
-     * @throws InvalidDataTypeException
146
-     */
147
-    private function setMessage($message)
148
-    {
149
-        if (! is_string($message)) {
150
-            throw new InvalidDataTypeException('$message', $message, 'string');
151
-        }
152
-        global $allowedtags;
153
-        $allowedtags['br'] = array();
154
-        $this->message = wp_kses($message, $allowedtags);
155
-    }
156
-
157
-
158
-    /**
159
-     * @return bool
160
-     */
161
-    public function getForceUpdate()
162
-    {
163
-        return $this->force_update;
164
-    }
165
-
166
-
167
-    /**
168
-     * @param bool $force_update
169
-     */
170
-    private function setForceUpdate($force_update)
171
-    {
172
-        $this->force_update = filter_var($force_update, FILTER_VALIDATE_BOOLEAN);
173
-    }
174
-
175
-
176
-    /**
177
-     * @return string
178
-     */
179
-    public function getCapability()
180
-    {
181
-        return $this->capability;
182
-    }
183
-
184
-
185
-    /**
186
-     * @param string $capability
187
-     * @throws InvalidDataTypeException
188
-     */
189
-    private function setCapability($capability)
190
-    {
191
-        if (! is_string($capability)) {
192
-            throw new InvalidDataTypeException('$capability', $capability, 'string');
193
-        }
194
-        $this->capability = ! empty($capability) ? $capability : 'manage_options';
195
-    }
196
-
197
-
198
-    /**
199
-     * @return string
200
-     */
201
-    public function getCapContext()
202
-    {
203
-        return $this->cap_context;
204
-    }
205
-
206
-
207
-    /**
208
-     * @param string $cap_context
209
-     * @throws InvalidDataTypeException
210
-     */
211
-    private function setCapContext($cap_context)
212
-    {
213
-        if (! is_string($cap_context)) {
214
-            throw new InvalidDataTypeException('$cap_context', $cap_context, 'string');
215
-        }
216
-        $this->cap_context = ! empty($cap_context) ? $cap_context : 'view persistent admin notice';
217
-    }
218
-
219
-
220
-    /**
221
-     * @return bool
222
-     */
223
-    public function getDismissed()
224
-    {
225
-        return $this->dismissed;
226
-    }
227
-
228
-
229
-    /**
230
-     * @param bool $dismissed
231
-     */
232
-    public function setDismissed($dismissed)
233
-    {
234
-        $this->dismissed = filter_var($dismissed, FILTER_VALIDATE_BOOLEAN);
235
-    }
236
-
237
-
238
-    /**
239
-     * @return CapCheckInterface
240
-     * @throws InvalidDataTypeException
241
-     */
242
-    public function getCapCheck()
243
-    {
244
-        if (! $this->cap_check instanceof CapCheckInterface) {
245
-            $this->setCapCheck(
246
-                new CapCheck(
247
-                    $this->capability,
248
-                    $this->cap_context
249
-                )
250
-            );
251
-        }
252
-        return $this->cap_check;
253
-    }
254
-
255
-
256
-    /**
257
-     * @param CapCheckInterface $cap_check
258
-     */
259
-    private function setCapCheck(CapCheckInterface $cap_check)
260
-    {
261
-        $this->cap_check = $cap_check;
262
-    }
263
-
264
-
265
-    /**
266
-     * @return bool
267
-     */
268
-    public function getPurge()
269
-    {
270
-        return $this->purge;
271
-    }
272
-
273
-
274
-    /**
275
-     * @param bool $purge
276
-     */
277
-    public function setPurge($purge)
278
-    {
279
-        $this->purge = filter_var($purge, FILTER_VALIDATE_BOOLEAN);
280
-    }
281
-
282
-
283
-    /**
284
-     * given a valid PersistentAdminNotice Collection,
285
-     * this notice will be added if it is not already found in the collection (using its name as the identifier)
286
-     * if an existing notice is found that has already been dismissed,
287
-     * but we are overriding with a forced update, then we will toggle its dismissed state,
288
-     * so that the notice is displayed again
289
-     *
290
-     * @param Collection $persistent_admin_notice_collection
291
-     * @throws InvalidEntityException
292
-     * @throws InvalidDataTypeException
293
-     * @throws DuplicateCollectionIdentifierException
294
-     */
295
-    public function registerPersistentAdminNotice(Collection $persistent_admin_notice_collection)
296
-    {
297
-        if ($this->registered) {
298
-            return;
299
-        }
300
-        // first check if this notice has already been added to the collection
301
-        if ($persistent_admin_notice_collection->has($this->name)) {
302
-            /** @var PersistentAdminNotice $existing */
303
-            $existing = $persistent_admin_notice_collection->get($this->name);
304
-            // we don't need to add it again (we can't actually)
305
-            // but if it has already been dismissed, and we are overriding with a forced update
306
-            if ($existing->getDismissed() && $this->getForceUpdate()) {
307
-                // then toggle the notice's dismissed state to true
308
-                // so that it gets displayed again
309
-                $existing->setDismissed(false);
310
-                // and make sure the message is set
311
-                $existing->setMessage($this->message);
312
-            }
313
-        } else {
314
-            $persistent_admin_notice_collection->add($this, $this->name);
315
-        }
316
-        $this->registered = true;
317
-    }
318
-
319
-
320
-    /**
321
-     * @throws Exception
322
-     */
323
-    public function confirmRegistered()
324
-    {
325
-        if (! apply_filters('PersistentAdminNoticeManager__registerAndSaveNotices__complete', false)) {
326
-            PersistentAdminNoticeManager::loadRegisterAndSaveNotices();
327
-        }
328
-        if (! $this->registered && WP_DEBUG) {
329
-            throw new DomainException(
330
-                sprintf(
331
-                    esc_html__(
332
-                        'The "%1$s" PersistentAdminNotice was not successfully registered. Please ensure that it is being created prior to either the "admin_notices" or "network_admin_notices" hooks being triggered.',
333
-                        'event_espresso'
334
-                    ),
335
-                    $this->name
336
-                )
337
-            );
338
-        }
339
-    }
28
+	/**
29
+	 * @var string $name
30
+	 */
31
+	protected $name = '';
32
+
33
+	/**
34
+	 * @var string $message
35
+	 */
36
+	protected $message = '';
37
+
38
+	/**
39
+	 * @var boolean $force_update
40
+	 */
41
+	protected $force_update = false;
42
+
43
+	/**
44
+	 * @var string $capability
45
+	 */
46
+	protected $capability = 'manage_options';
47
+
48
+	/**
49
+	 * @var string $cap_context
50
+	 */
51
+	protected $cap_context = 'view persistent admin notice';
52
+
53
+	/**
54
+	 * @var boolean $dismissed
55
+	 */
56
+	protected $dismissed = false;
57
+
58
+	/**
59
+	 * @var CapCheckInterface $cap_check
60
+	 */
61
+	protected $cap_check;
62
+
63
+	/**
64
+	 * if true, then this notice will be deleted from the database
65
+	 *
66
+	 * @var boolean $purge
67
+	 */
68
+	protected $purge = false;
69
+
70
+	/**
71
+	 * gets set to true if notice is successfully registered with the PersistentAdminNoticeManager
72
+	 * if false, and WP_DEBUG is on, then an exception will be thrown in the admin footer
73
+	 *
74
+	 * @var boolean $registered
75
+	 */
76
+	private $registered = false;
77
+
78
+
79
+	/**
80
+	 * PersistentAdminNotice constructor
81
+	 *
82
+	 * @param string $name         [required] the name, or key of the Persistent Admin Notice to be stored
83
+	 * @param string $message      [required] the message to be stored persistently until dismissed
84
+	 * @param bool   $force_update enforce the reappearance of a persistent message
85
+	 * @param string $capability   user capability required to view this notice
86
+	 * @param string $cap_context  description for why the cap check is being performed
87
+	 * @param bool   $dismissed    whether or not the user has already dismissed/viewed this notice
88
+	 * @throws InvalidDataTypeException
89
+	 */
90
+	public function __construct(
91
+		$name,
92
+		$message,
93
+		$force_update = false,
94
+		$capability = 'manage_options',
95
+		$cap_context = 'view persistent admin notice',
96
+		$dismissed = false
97
+	) {
98
+		$this->setName($name);
99
+		$this->setMessage($message);
100
+		$this->setForceUpdate($force_update);
101
+		$this->setCapability($capability);
102
+		$this->setCapContext($cap_context);
103
+		$this->setDismissed($dismissed);
104
+		add_action(
105
+			'AHEE__EventEspresso_core_services_notifications_PersistentAdminNoticeManager__registerNotices',
106
+			array($this, 'registerPersistentAdminNotice')
107
+		);
108
+		add_action('shutdown', array($this, 'confirmRegistered'), 999);
109
+	}
110
+
111
+
112
+	/**
113
+	 * @return string
114
+	 */
115
+	public function getName()
116
+	{
117
+		return $this->name;
118
+	}
119
+
120
+
121
+	/**
122
+	 * @param string $name
123
+	 * @throws InvalidDataTypeException
124
+	 */
125
+	private function setName($name)
126
+	{
127
+		if (! is_string($name)) {
128
+			throw new InvalidDataTypeException('$name', $name, 'string');
129
+		}
130
+		$this->name = sanitize_key($name);
131
+	}
132
+
133
+
134
+	/**
135
+	 * @return string
136
+	 */
137
+	public function getMessage()
138
+	{
139
+		return $this->message;
140
+	}
141
+
142
+
143
+	/**
144
+	 * @param string $message
145
+	 * @throws InvalidDataTypeException
146
+	 */
147
+	private function setMessage($message)
148
+	{
149
+		if (! is_string($message)) {
150
+			throw new InvalidDataTypeException('$message', $message, 'string');
151
+		}
152
+		global $allowedtags;
153
+		$allowedtags['br'] = array();
154
+		$this->message = wp_kses($message, $allowedtags);
155
+	}
156
+
157
+
158
+	/**
159
+	 * @return bool
160
+	 */
161
+	public function getForceUpdate()
162
+	{
163
+		return $this->force_update;
164
+	}
165
+
166
+
167
+	/**
168
+	 * @param bool $force_update
169
+	 */
170
+	private function setForceUpdate($force_update)
171
+	{
172
+		$this->force_update = filter_var($force_update, FILTER_VALIDATE_BOOLEAN);
173
+	}
174
+
175
+
176
+	/**
177
+	 * @return string
178
+	 */
179
+	public function getCapability()
180
+	{
181
+		return $this->capability;
182
+	}
183
+
184
+
185
+	/**
186
+	 * @param string $capability
187
+	 * @throws InvalidDataTypeException
188
+	 */
189
+	private function setCapability($capability)
190
+	{
191
+		if (! is_string($capability)) {
192
+			throw new InvalidDataTypeException('$capability', $capability, 'string');
193
+		}
194
+		$this->capability = ! empty($capability) ? $capability : 'manage_options';
195
+	}
196
+
197
+
198
+	/**
199
+	 * @return string
200
+	 */
201
+	public function getCapContext()
202
+	{
203
+		return $this->cap_context;
204
+	}
205
+
206
+
207
+	/**
208
+	 * @param string $cap_context
209
+	 * @throws InvalidDataTypeException
210
+	 */
211
+	private function setCapContext($cap_context)
212
+	{
213
+		if (! is_string($cap_context)) {
214
+			throw new InvalidDataTypeException('$cap_context', $cap_context, 'string');
215
+		}
216
+		$this->cap_context = ! empty($cap_context) ? $cap_context : 'view persistent admin notice';
217
+	}
218
+
219
+
220
+	/**
221
+	 * @return bool
222
+	 */
223
+	public function getDismissed()
224
+	{
225
+		return $this->dismissed;
226
+	}
227
+
228
+
229
+	/**
230
+	 * @param bool $dismissed
231
+	 */
232
+	public function setDismissed($dismissed)
233
+	{
234
+		$this->dismissed = filter_var($dismissed, FILTER_VALIDATE_BOOLEAN);
235
+	}
236
+
237
+
238
+	/**
239
+	 * @return CapCheckInterface
240
+	 * @throws InvalidDataTypeException
241
+	 */
242
+	public function getCapCheck()
243
+	{
244
+		if (! $this->cap_check instanceof CapCheckInterface) {
245
+			$this->setCapCheck(
246
+				new CapCheck(
247
+					$this->capability,
248
+					$this->cap_context
249
+				)
250
+			);
251
+		}
252
+		return $this->cap_check;
253
+	}
254
+
255
+
256
+	/**
257
+	 * @param CapCheckInterface $cap_check
258
+	 */
259
+	private function setCapCheck(CapCheckInterface $cap_check)
260
+	{
261
+		$this->cap_check = $cap_check;
262
+	}
263
+
264
+
265
+	/**
266
+	 * @return bool
267
+	 */
268
+	public function getPurge()
269
+	{
270
+		return $this->purge;
271
+	}
272
+
273
+
274
+	/**
275
+	 * @param bool $purge
276
+	 */
277
+	public function setPurge($purge)
278
+	{
279
+		$this->purge = filter_var($purge, FILTER_VALIDATE_BOOLEAN);
280
+	}
281
+
282
+
283
+	/**
284
+	 * given a valid PersistentAdminNotice Collection,
285
+	 * this notice will be added if it is not already found in the collection (using its name as the identifier)
286
+	 * if an existing notice is found that has already been dismissed,
287
+	 * but we are overriding with a forced update, then we will toggle its dismissed state,
288
+	 * so that the notice is displayed again
289
+	 *
290
+	 * @param Collection $persistent_admin_notice_collection
291
+	 * @throws InvalidEntityException
292
+	 * @throws InvalidDataTypeException
293
+	 * @throws DuplicateCollectionIdentifierException
294
+	 */
295
+	public function registerPersistentAdminNotice(Collection $persistent_admin_notice_collection)
296
+	{
297
+		if ($this->registered) {
298
+			return;
299
+		}
300
+		// first check if this notice has already been added to the collection
301
+		if ($persistent_admin_notice_collection->has($this->name)) {
302
+			/** @var PersistentAdminNotice $existing */
303
+			$existing = $persistent_admin_notice_collection->get($this->name);
304
+			// we don't need to add it again (we can't actually)
305
+			// but if it has already been dismissed, and we are overriding with a forced update
306
+			if ($existing->getDismissed() && $this->getForceUpdate()) {
307
+				// then toggle the notice's dismissed state to true
308
+				// so that it gets displayed again
309
+				$existing->setDismissed(false);
310
+				// and make sure the message is set
311
+				$existing->setMessage($this->message);
312
+			}
313
+		} else {
314
+			$persistent_admin_notice_collection->add($this, $this->name);
315
+		}
316
+		$this->registered = true;
317
+	}
318
+
319
+
320
+	/**
321
+	 * @throws Exception
322
+	 */
323
+	public function confirmRegistered()
324
+	{
325
+		if (! apply_filters('PersistentAdminNoticeManager__registerAndSaveNotices__complete', false)) {
326
+			PersistentAdminNoticeManager::loadRegisterAndSaveNotices();
327
+		}
328
+		if (! $this->registered && WP_DEBUG) {
329
+			throw new DomainException(
330
+				sprintf(
331
+					esc_html__(
332
+						'The "%1$s" PersistentAdminNotice was not successfully registered. Please ensure that it is being created prior to either the "admin_notices" or "network_admin_notices" hooks being triggered.',
333
+						'event_espresso'
334
+					),
335
+					$this->name
336
+				)
337
+			);
338
+		}
339
+	}
340 340
 }
Please login to merge, or discard this patch.
espresso.php 1 patch
Indentation   +80 added lines, -80 removed lines patch added patch discarded remove patch
@@ -38,103 +38,103 @@
 block discarded – undo
38 38
  * @since           4.0
39 39
  */
40 40
 if (function_exists('espresso_version')) {
41
-    if (! function_exists('espresso_duplicate_plugin_error')) {
42
-        /**
43
-         *    espresso_duplicate_plugin_error
44
-         *    displays if more than one version of EE is activated at the same time
45
-         */
46
-        function espresso_duplicate_plugin_error()
47
-        {
48
-            ?>
41
+	if (! function_exists('espresso_duplicate_plugin_error')) {
42
+		/**
43
+		 *    espresso_duplicate_plugin_error
44
+		 *    displays if more than one version of EE is activated at the same time
45
+		 */
46
+		function espresso_duplicate_plugin_error()
47
+		{
48
+			?>
49 49
             <div class="error">
50 50
                 <p>
51 51
                     <?php
52
-                    echo esc_html__(
53
-                        'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.',
54
-                        'event_espresso'
55
-                    ); ?>
52
+					echo esc_html__(
53
+						'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.',
54
+						'event_espresso'
55
+					); ?>
56 56
                 </p>
57 57
             </div>
58 58
             <?php
59
-            espresso_deactivate_plugin(plugin_basename(__FILE__));
60
-        }
61
-    }
62
-    add_action('admin_notices', 'espresso_duplicate_plugin_error', 1);
59
+			espresso_deactivate_plugin(plugin_basename(__FILE__));
60
+		}
61
+	}
62
+	add_action('admin_notices', 'espresso_duplicate_plugin_error', 1);
63 63
 } else {
64
-    define('EE_MIN_PHP_VER_REQUIRED', '5.4.0');
65
-    if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
66
-        /**
67
-         * espresso_minimum_php_version_error
68
-         *
69
-         * @return void
70
-         */
71
-        function espresso_minimum_php_version_error()
72
-        {
73
-            ?>
64
+	define('EE_MIN_PHP_VER_REQUIRED', '5.4.0');
65
+	if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
66
+		/**
67
+		 * espresso_minimum_php_version_error
68
+		 *
69
+		 * @return void
70
+		 */
71
+		function espresso_minimum_php_version_error()
72
+		{
73
+			?>
74 74
             <div class="error">
75 75
                 <p>
76 76
                     <?php
77
-                    printf(
78
-                        esc_html__(
79
-                            'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.',
80
-                            'event_espresso'
81
-                        ),
82
-                        EE_MIN_PHP_VER_REQUIRED,
83
-                        PHP_VERSION,
84
-                        '<br/>',
85
-                        '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>'
86
-                    );
87
-                    ?>
77
+					printf(
78
+						esc_html__(
79
+							'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.',
80
+							'event_espresso'
81
+						),
82
+						EE_MIN_PHP_VER_REQUIRED,
83
+						PHP_VERSION,
84
+						'<br/>',
85
+						'<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>'
86
+					);
87
+					?>
88 88
                 </p>
89 89
             </div>
90 90
             <?php
91
-            espresso_deactivate_plugin(plugin_basename(__FILE__));
92
-        }
91
+			espresso_deactivate_plugin(plugin_basename(__FILE__));
92
+		}
93 93
 
94
-        add_action('admin_notices', 'espresso_minimum_php_version_error', 1);
95
-    } else {
96
-        define('EVENT_ESPRESSO_MAIN_FILE', __FILE__);
97
-        /**
98
-         * espresso_version
99
-         * Returns the plugin version
100
-         *
101
-         * @return string
102
-         */
103
-        function espresso_version()
104
-        {
105
-            return apply_filters('FHEE__espresso__espresso_version', '4.9.66.rc.022');
106
-        }
94
+		add_action('admin_notices', 'espresso_minimum_php_version_error', 1);
95
+	} else {
96
+		define('EVENT_ESPRESSO_MAIN_FILE', __FILE__);
97
+		/**
98
+		 * espresso_version
99
+		 * Returns the plugin version
100
+		 *
101
+		 * @return string
102
+		 */
103
+		function espresso_version()
104
+		{
105
+			return apply_filters('FHEE__espresso__espresso_version', '4.9.66.rc.022');
106
+		}
107 107
 
108
-        /**
109
-         * espresso_plugin_activation
110
-         * adds a wp-option to indicate that EE has been activated via the WP admin plugins page
111
-         */
112
-        function espresso_plugin_activation()
113
-        {
114
-            update_option('ee_espresso_activation', true);
115
-        }
108
+		/**
109
+		 * espresso_plugin_activation
110
+		 * adds a wp-option to indicate that EE has been activated via the WP admin plugins page
111
+		 */
112
+		function espresso_plugin_activation()
113
+		{
114
+			update_option('ee_espresso_activation', true);
115
+		}
116 116
 
117
-        register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
117
+		register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
118 118
 
119
-        require_once __DIR__ . '/core/bootstrap_espresso.php';
120
-        bootstrap_espresso();
121
-    }
119
+		require_once __DIR__ . '/core/bootstrap_espresso.php';
120
+		bootstrap_espresso();
121
+	}
122 122
 }
123 123
 if (! function_exists('espresso_deactivate_plugin')) {
124
-    /**
125
-     *    deactivate_plugin
126
-     * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
127
-     *
128
-     * @access public
129
-     * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
130
-     * @return    void
131
-     */
132
-    function espresso_deactivate_plugin($plugin_basename = '')
133
-    {
134
-        if (! function_exists('deactivate_plugins')) {
135
-            require_once ABSPATH . 'wp-admin/includes/plugin.php';
136
-        }
137
-        unset($_GET['activate'], $_REQUEST['activate']);
138
-        deactivate_plugins($plugin_basename);
139
-    }
124
+	/**
125
+	 *    deactivate_plugin
126
+	 * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
127
+	 *
128
+	 * @access public
129
+	 * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
130
+	 * @return    void
131
+	 */
132
+	function espresso_deactivate_plugin($plugin_basename = '')
133
+	{
134
+		if (! function_exists('deactivate_plugins')) {
135
+			require_once ABSPATH . 'wp-admin/includes/plugin.php';
136
+		}
137
+		unset($_GET['activate'], $_REQUEST['activate']);
138
+		deactivate_plugins($plugin_basename);
139
+	}
140 140
 }
Please login to merge, or discard this patch.
core/EE_Dependency_Map.core.php 1 patch
Indentation   +1007 added lines, -1007 removed lines patch added patch discarded remove patch
@@ -20,1011 +20,1011 @@
 block discarded – undo
20 20
 class EE_Dependency_Map
21 21
 {
22 22
 
23
-    /**
24
-     * This means that the requested class dependency is not present in the dependency map
25
-     */
26
-    const not_registered = 0;
27
-
28
-    /**
29
-     * This instructs class loaders to ALWAYS return a newly instantiated object for the requested class.
30
-     */
31
-    const load_new_object = 1;
32
-
33
-    /**
34
-     * This instructs class loaders to return a previously instantiated and cached object for the requested class.
35
-     * IF a previously instantiated object does not exist, a new one will be created and added to the cache.
36
-     */
37
-    const load_from_cache = 2;
38
-
39
-    /**
40
-     * When registering a dependency,
41
-     * this indicates to keep any existing dependencies that already exist,
42
-     * and simply discard any new dependencies declared in the incoming data
43
-     */
44
-    const KEEP_EXISTING_DEPENDENCIES = 0;
45
-
46
-    /**
47
-     * When registering a dependency,
48
-     * this indicates to overwrite any existing dependencies that already exist using the incoming data
49
-     */
50
-    const OVERWRITE_DEPENDENCIES = 1;
51
-
52
-
53
-    /**
54
-     * @type EE_Dependency_Map $_instance
55
-     */
56
-    protected static $_instance;
57
-
58
-    /**
59
-     * @var ClassInterfaceCache $class_cache
60
-     */
61
-    private $class_cache;
62
-
63
-    /**
64
-     * @type RequestInterface $request
65
-     */
66
-    protected $request;
67
-
68
-    /**
69
-     * @type LegacyRequestInterface $legacy_request
70
-     */
71
-    protected $legacy_request;
72
-
73
-    /**
74
-     * @type ResponseInterface $response
75
-     */
76
-    protected $response;
77
-
78
-    /**
79
-     * @type LoaderInterface $loader
80
-     */
81
-    protected $loader;
82
-
83
-    /**
84
-     * @type array $_dependency_map
85
-     */
86
-    protected $_dependency_map = array();
87
-
88
-    /**
89
-     * @type array $_class_loaders
90
-     */
91
-    protected $_class_loaders = array();
92
-
93
-
94
-    /**
95
-     * EE_Dependency_Map constructor.
96
-     *
97
-     * @param ClassInterfaceCache $class_cache
98
-     */
99
-    protected function __construct(ClassInterfaceCache $class_cache)
100
-    {
101
-        $this->class_cache = $class_cache;
102
-        do_action('EE_Dependency_Map____construct', $this);
103
-    }
104
-
105
-
106
-    /**
107
-     * @return void
108
-     */
109
-    public function initialize()
110
-    {
111
-        $this->_register_core_dependencies();
112
-        $this->_register_core_class_loaders();
113
-        $this->_register_core_aliases();
114
-    }
115
-
116
-
117
-    /**
118
-     * @singleton method used to instantiate class object
119
-     * @param ClassInterfaceCache|null $class_cache
120
-     * @return EE_Dependency_Map
121
-     */
122
-    public static function instance(ClassInterfaceCache $class_cache = null)
123
-    {
124
-        // check if class object is instantiated, and instantiated properly
125
-        if (! self::$_instance instanceof EE_Dependency_Map
126
-            && $class_cache instanceof ClassInterfaceCache
127
-        ) {
128
-            self::$_instance = new EE_Dependency_Map($class_cache);
129
-        }
130
-        return self::$_instance;
131
-    }
132
-
133
-
134
-    /**
135
-     * @param RequestInterface $request
136
-     */
137
-    public function setRequest(RequestInterface $request)
138
-    {
139
-        $this->request = $request;
140
-    }
141
-
142
-
143
-    /**
144
-     * @param LegacyRequestInterface $legacy_request
145
-     */
146
-    public function setLegacyRequest(LegacyRequestInterface $legacy_request)
147
-    {
148
-        $this->legacy_request = $legacy_request;
149
-    }
150
-
151
-
152
-    /**
153
-     * @param ResponseInterface $response
154
-     */
155
-    public function setResponse(ResponseInterface $response)
156
-    {
157
-        $this->response = $response;
158
-    }
159
-
160
-
161
-    /**
162
-     * @param LoaderInterface $loader
163
-     */
164
-    public function setLoader(LoaderInterface $loader)
165
-    {
166
-        $this->loader = $loader;
167
-    }
168
-
169
-
170
-    /**
171
-     * @param string $class
172
-     * @param array  $dependencies
173
-     * @param int    $overwrite
174
-     * @return bool
175
-     */
176
-    public static function register_dependencies(
177
-        $class,
178
-        array $dependencies,
179
-        $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES
180
-    ) {
181
-        return self::$_instance->registerDependencies($class, $dependencies, $overwrite);
182
-    }
183
-
184
-
185
-    /**
186
-     * Assigns an array of class names and corresponding load sources (new or cached)
187
-     * to the class specified by the first parameter.
188
-     * IMPORTANT !!!
189
-     * The order of elements in the incoming $dependencies array MUST match
190
-     * the order of the constructor parameters for the class in question.
191
-     * This is especially important when overriding any existing dependencies that are registered.
192
-     * the third parameter controls whether any duplicate dependencies are overwritten or not.
193
-     *
194
-     * @param string $class
195
-     * @param array  $dependencies
196
-     * @param int    $overwrite
197
-     * @return bool
198
-     */
199
-    public function registerDependencies(
200
-        $class,
201
-        array $dependencies,
202
-        $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES
203
-    ) {
204
-        $class = trim($class, '\\');
205
-        $registered = false;
206
-        if (empty(self::$_instance->_dependency_map[ $class ])) {
207
-            self::$_instance->_dependency_map[ $class ] = array();
208
-        }
209
-        // we need to make sure that any aliases used when registering a dependency
210
-        // get resolved to the correct class name
211
-        foreach ($dependencies as $dependency => $load_source) {
212
-            $alias = self::$_instance->getFqnForAlias($dependency);
213
-            if ($overwrite === EE_Dependency_Map::OVERWRITE_DEPENDENCIES
214
-                || ! isset(self::$_instance->_dependency_map[ $class ][ $alias ])
215
-            ) {
216
-                unset($dependencies[ $dependency ]);
217
-                $dependencies[ $alias ] = $load_source;
218
-                $registered = true;
219
-            }
220
-        }
221
-        // now add our two lists of dependencies together.
222
-        // using Union (+=) favours the arrays in precedence from left to right,
223
-        // so $dependencies is NOT overwritten because it is listed first
224
-        // ie: with A = B + C, entries in B take precedence over duplicate entries in C
225
-        // Union is way faster than array_merge() but should be used with caution...
226
-        // especially with numerically indexed arrays
227
-        $dependencies += self::$_instance->_dependency_map[ $class ];
228
-        // now we need to ensure that the resulting dependencies
229
-        // array only has the entries that are required for the class
230
-        // so first count how many dependencies were originally registered for the class
231
-        $dependency_count = count(self::$_instance->_dependency_map[ $class ]);
232
-        // if that count is non-zero (meaning dependencies were already registered)
233
-        self::$_instance->_dependency_map[ $class ] = $dependency_count
234
-            // then truncate the  final array to match that count
235
-            ? array_slice($dependencies, 0, $dependency_count)
236
-            // otherwise just take the incoming array because nothing previously existed
237
-            : $dependencies;
238
-        return $registered;
239
-    }
240
-
241
-
242
-    /**
243
-     * @param string $class_name
244
-     * @param string $loader
245
-     * @return bool
246
-     * @throws DomainException
247
-     */
248
-    public static function register_class_loader($class_name, $loader = 'load_core')
249
-    {
250
-        if (! $loader instanceof Closure && strpos($class_name, '\\') !== false) {
251
-            throw new DomainException(
252
-                esc_html__('Don\'t use class loaders for FQCNs.', 'event_espresso')
253
-            );
254
-        }
255
-        // check that loader is callable or method starts with "load_" and exists in EE_Registry
256
-        if (! is_callable($loader)
257
-            && (
258
-                strpos($loader, 'load_') !== 0
259
-                || ! method_exists('EE_Registry', $loader)
260
-            )
261
-        ) {
262
-            throw new DomainException(
263
-                sprintf(
264
-                    esc_html__(
265
-                        '"%1$s" is not a valid loader method on EE_Registry.',
266
-                        'event_espresso'
267
-                    ),
268
-                    $loader
269
-                )
270
-            );
271
-        }
272
-        $class_name = self::$_instance->getFqnForAlias($class_name);
273
-        if (! isset(self::$_instance->_class_loaders[ $class_name ])) {
274
-            self::$_instance->_class_loaders[ $class_name ] = $loader;
275
-            return true;
276
-        }
277
-        return false;
278
-    }
279
-
280
-
281
-    /**
282
-     * @return array
283
-     */
284
-    public function dependency_map()
285
-    {
286
-        return $this->_dependency_map;
287
-    }
288
-
289
-
290
-    /**
291
-     * returns TRUE if dependency map contains a listing for the provided class name
292
-     *
293
-     * @param string $class_name
294
-     * @return boolean
295
-     */
296
-    public function has($class_name = '')
297
-    {
298
-        // all legacy models have the same dependencies
299
-        if (strpos($class_name, 'EEM_') === 0) {
300
-            $class_name = 'LEGACY_MODELS';
301
-        }
302
-        return isset($this->_dependency_map[ $class_name ]) ? true : false;
303
-    }
304
-
305
-
306
-    /**
307
-     * returns TRUE if dependency map contains a listing for the provided class name AND dependency
308
-     *
309
-     * @param string $class_name
310
-     * @param string $dependency
311
-     * @return bool
312
-     */
313
-    public function has_dependency_for_class($class_name = '', $dependency = '')
314
-    {
315
-        // all legacy models have the same dependencies
316
-        if (strpos($class_name, 'EEM_') === 0) {
317
-            $class_name = 'LEGACY_MODELS';
318
-        }
319
-        $dependency = $this->getFqnForAlias($dependency, $class_name);
320
-        return isset($this->_dependency_map[ $class_name ][ $dependency ])
321
-            ? true
322
-            : false;
323
-    }
324
-
325
-
326
-    /**
327
-     * returns loading strategy for whether a previously cached dependency should be loaded or a new instance returned
328
-     *
329
-     * @param string $class_name
330
-     * @param string $dependency
331
-     * @return int
332
-     */
333
-    public function loading_strategy_for_class_dependency($class_name = '', $dependency = '')
334
-    {
335
-        // all legacy models have the same dependencies
336
-        if (strpos($class_name, 'EEM_') === 0) {
337
-            $class_name = 'LEGACY_MODELS';
338
-        }
339
-        $dependency = $this->getFqnForAlias($dependency);
340
-        return $this->has_dependency_for_class($class_name, $dependency)
341
-            ? $this->_dependency_map[ $class_name ][ $dependency ]
342
-            : EE_Dependency_Map::not_registered;
343
-    }
344
-
345
-
346
-    /**
347
-     * @param string $class_name
348
-     * @return string | Closure
349
-     */
350
-    public function class_loader($class_name)
351
-    {
352
-        // all legacy models use load_model()
353
-        if (strpos($class_name, 'EEM_') === 0) {
354
-            return 'load_model';
355
-        }
356
-        // EE_CPT_*_Strategy classes like EE_CPT_Event_Strategy, EE_CPT_Venue_Strategy, etc
357
-        // perform strpos() first to avoid loading regex every time we load a class
358
-        if (strpos($class_name, 'EE_CPT_') === 0
359
-            && preg_match('/^EE_CPT_([a-zA-Z]+)_Strategy$/', $class_name)
360
-        ) {
361
-            return 'load_core';
362
-        }
363
-        $class_name = $this->getFqnForAlias($class_name);
364
-        return isset($this->_class_loaders[ $class_name ]) ? $this->_class_loaders[ $class_name ] : '';
365
-    }
366
-
367
-
368
-    /**
369
-     * @return array
370
-     */
371
-    public function class_loaders()
372
-    {
373
-        return $this->_class_loaders;
374
-    }
375
-
376
-
377
-    /**
378
-     * adds an alias for a classname
379
-     *
380
-     * @param string $fqcn      the class name that should be used (concrete class to replace interface)
381
-     * @param string $alias     the class name that would be type hinted for (abstract parent or interface)
382
-     * @param string $for_class the class that has the dependency (is type hinting for the interface)
383
-     */
384
-    public function add_alias($fqcn, $alias, $for_class = '')
385
-    {
386
-        $this->class_cache->addAlias($fqcn, $alias, $for_class);
387
-    }
388
-
389
-
390
-    /**
391
-     * Returns TRUE if the provided fully qualified name IS an alias
392
-     * WHY?
393
-     * Because if a class is type hinting for a concretion,
394
-     * then why would we need to find another class to supply it?
395
-     * ie: if a class asks for `Fully/Qualified/Namespace/SpecificClassName`,
396
-     * then give it an instance of `Fully/Qualified/Namespace/SpecificClassName`.
397
-     * Don't go looking for some substitute.
398
-     * Whereas if a class is type hinting for an interface...
399
-     * then we need to find an actual class to use.
400
-     * So the interface IS the alias for some other FQN,
401
-     * and we need to find out if `Fully/Qualified/Namespace/SomeInterface`
402
-     * represents some other class.
403
-     *
404
-     * @param string $fqn
405
-     * @param string $for_class
406
-     * @return bool
407
-     */
408
-    public function isAlias($fqn = '', $for_class = '')
409
-    {
410
-        return $this->class_cache->isAlias($fqn, $for_class);
411
-    }
412
-
413
-
414
-    /**
415
-     * Returns a FQN for provided alias if one exists, otherwise returns the original $alias
416
-     * functions recursively, so that multiple aliases can be used to drill down to a FQN
417
-     *  for example:
418
-     *      if the following two entries were added to the _aliases array:
419
-     *          array(
420
-     *              'interface_alias'           => 'some\namespace\interface'
421
-     *              'some\namespace\interface'  => 'some\namespace\classname'
422
-     *          )
423
-     *      then one could use EE_Registry::instance()->create( 'interface_alias' )
424
-     *      to load an instance of 'some\namespace\classname'
425
-     *
426
-     * @param string $alias
427
-     * @param string $for_class
428
-     * @return string
429
-     */
430
-    public function getFqnForAlias($alias = '', $for_class = '')
431
-    {
432
-        return (string) $this->class_cache->getFqnForAlias($alias, $for_class);
433
-    }
434
-
435
-
436
-    /**
437
-     * Registers the core dependencies and whether a previously instantiated object should be loaded from the cache,
438
-     * if one exists, or whether a new object should be generated every time the requested class is loaded.
439
-     * This is done by using the following class constants:
440
-     *        EE_Dependency_Map::load_from_cache - loads previously instantiated object
441
-     *        EE_Dependency_Map::load_new_object - generates a new object every time
442
-     */
443
-    protected function _register_core_dependencies()
444
-    {
445
-        $this->_dependency_map = array(
446
-            'EE_Request_Handler'                                                                                          => array(
447
-                'EE_Request' => EE_Dependency_Map::load_from_cache,
448
-            ),
449
-            'EE_System'                                                                                                   => array(
450
-                'EE_Registry'                                 => EE_Dependency_Map::load_from_cache,
451
-                'EventEspresso\core\services\loaders\Loader'  => EE_Dependency_Map::load_from_cache,
452
-                'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache,
453
-                'EE_Maintenance_Mode'                         => EE_Dependency_Map::load_from_cache,
454
-            ),
455
-            'EE_Session'                                                                                                  => array(
456
-                'EventEspresso\core\services\cache\TransientCacheStorage'  => EE_Dependency_Map::load_from_cache,
457
-                'EventEspresso\core\domain\values\session\SessionLifespan' => EE_Dependency_Map::load_from_cache,
458
-                'EventEspresso\core\services\request\Request'              => EE_Dependency_Map::load_from_cache,
459
-                'EE_Encryption'                                            => EE_Dependency_Map::load_from_cache,
460
-            ),
461
-            'EE_Cart'                                                                                                     => array(
462
-                'EE_Session' => EE_Dependency_Map::load_from_cache,
463
-            ),
464
-            'EE_Front_Controller'                                                                                         => array(
465
-                'EE_Registry'              => EE_Dependency_Map::load_from_cache,
466
-                'EE_Request_Handler'       => EE_Dependency_Map::load_from_cache,
467
-                'EE_Module_Request_Router' => EE_Dependency_Map::load_from_cache,
468
-            ),
469
-            'EE_Messenger_Collection_Loader'                                                                              => array(
470
-                'EE_Messenger_Collection' => EE_Dependency_Map::load_new_object,
471
-            ),
472
-            'EE_Message_Type_Collection_Loader'                                                                           => array(
473
-                'EE_Message_Type_Collection' => EE_Dependency_Map::load_new_object,
474
-            ),
475
-            'EE_Message_Resource_Manager'                                                                                 => array(
476
-                'EE_Messenger_Collection_Loader'    => EE_Dependency_Map::load_new_object,
477
-                'EE_Message_Type_Collection_Loader' => EE_Dependency_Map::load_new_object,
478
-                'EEM_Message_Template_Group'        => EE_Dependency_Map::load_from_cache,
479
-            ),
480
-            'EE_Message_Factory'                                                                                          => array(
481
-                'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache,
482
-            ),
483
-            'EE_messages'                                                                                                 => array(
484
-                'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache,
485
-            ),
486
-            'EE_Messages_Generator'                                                                                       => array(
487
-                'EE_Messages_Queue'                    => EE_Dependency_Map::load_new_object,
488
-                'EE_Messages_Data_Handler_Collection'  => EE_Dependency_Map::load_new_object,
489
-                'EE_Message_Template_Group_Collection' => EE_Dependency_Map::load_new_object,
490
-                'EEH_Parse_Shortcodes'                 => EE_Dependency_Map::load_from_cache,
491
-            ),
492
-            'EE_Messages_Processor'                                                                                       => array(
493
-                'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache,
494
-            ),
495
-            'EE_Messages_Queue'                                                                                           => array(
496
-                'EE_Message_Repository' => EE_Dependency_Map::load_new_object,
497
-            ),
498
-            'EE_Messages_Template_Defaults'                                                                               => array(
499
-                'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache,
500
-                'EEM_Message_Template'       => EE_Dependency_Map::load_from_cache,
501
-            ),
502
-            'EE_Message_To_Generate_From_Request'                                                                         => array(
503
-                'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache,
504
-                'EE_Request_Handler'          => EE_Dependency_Map::load_from_cache,
505
-            ),
506
-            'EventEspresso\core\services\commands\CommandBus'                                                             => array(
507
-                'EventEspresso\core\services\commands\CommandHandlerManager' => EE_Dependency_Map::load_from_cache,
508
-            ),
509
-            'EventEspresso\services\commands\CommandHandler'                                                              => array(
510
-                'EE_Registry'         => EE_Dependency_Map::load_from_cache,
511
-                'CommandBusInterface' => EE_Dependency_Map::load_from_cache,
512
-            ),
513
-            'EventEspresso\core\services\commands\CommandHandlerManager'                                                  => array(
514
-                'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache,
515
-            ),
516
-            'EventEspresso\core\services\commands\CompositeCommandHandler'                                                => array(
517
-                'EventEspresso\core\services\commands\CommandBus'     => EE_Dependency_Map::load_from_cache,
518
-                'EventEspresso\core\services\commands\CommandFactory' => EE_Dependency_Map::load_from_cache,
519
-            ),
520
-            'EventEspresso\core\services\commands\CommandFactory'                                                         => array(
521
-                'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache,
522
-            ),
523
-            'EventEspresso\core\services\commands\middleware\CapChecker'                                                  => array(
524
-                'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache,
525
-            ),
526
-            'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker'                                         => array(
527
-                'EE_Capabilities' => EE_Dependency_Map::load_from_cache,
528
-            ),
529
-            'EventEspresso\core\domain\services\capabilities\RegistrationsCapChecker'                                     => array(
530
-                'EE_Capabilities' => EE_Dependency_Map::load_from_cache,
531
-            ),
532
-            'EventEspresso\core\services\commands\registration\CreateRegistrationCommandHandler'                          => array(
533
-                'EventEspresso\core\domain\services\registration\CreateRegistrationService' => EE_Dependency_Map::load_from_cache,
534
-            ),
535
-            'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommandHandler'                     => array(
536
-                'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache,
537
-            ),
538
-            'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommandHandler'                    => array(
539
-                'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache,
540
-            ),
541
-            'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler'         => array(
542
-                'EventEspresso\core\domain\services\registration\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache,
543
-            ),
544
-            'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler' => array(
545
-                'EventEspresso\core\domain\services\registration\UpdateRegistrationService' => EE_Dependency_Map::load_from_cache,
546
-            ),
547
-            'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommandHandler'                              => array(
548
-                'EventEspresso\core\domain\services\ticket\CreateTicketLineItemService' => EE_Dependency_Map::load_from_cache,
549
-            ),
550
-            'EventEspresso\core\services\commands\ticket\CancelTicketLineItemCommandHandler'                              => array(
551
-                'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache,
552
-            ),
553
-            'EventEspresso\core\domain\services\registration\CancelRegistrationService'                                   => array(
554
-                'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache,
555
-            ),
556
-            'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler'                                  => array(
557
-                'EEM_Attendee' => EE_Dependency_Map::load_from_cache,
558
-            ),
559
-            'EventEspresso\core\services\database\TableManager'                                                           => array(
560
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
561
-            ),
562
-            'EE_Data_Migration_Class_Base'                                                                                => array(
563
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
564
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
565
-            ),
566
-            'EE_DMS_Core_4_1_0'                                                                                           => array(
567
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
568
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
569
-            ),
570
-            'EE_DMS_Core_4_2_0'                                                                                           => array(
571
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
572
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
573
-            ),
574
-            'EE_DMS_Core_4_3_0'                                                                                           => array(
575
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
576
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
577
-            ),
578
-            'EE_DMS_Core_4_4_0'                                                                                           => array(
579
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
580
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
581
-            ),
582
-            'EE_DMS_Core_4_5_0'                                                                                           => array(
583
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
584
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
585
-            ),
586
-            'EE_DMS_Core_4_6_0'                                                                                           => array(
587
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
588
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
589
-            ),
590
-            'EE_DMS_Core_4_7_0'                                                                                           => array(
591
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
592
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
593
-            ),
594
-            'EE_DMS_Core_4_8_0'                                                                                           => array(
595
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
596
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
597
-            ),
598
-            'EE_DMS_Core_4_9_0'                                                                                           => array(
599
-                'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
600
-                'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
601
-            ),
602
-            'EventEspresso\core\services\assets\I18nRegistry'                                                             => array(
603
-                array(),
604
-                'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache,
605
-            ),
606
-            'EventEspresso\core\services\assets\Registry'                                                                 => array(
607
-                'EventEspresso\core\services\assets\AssetCollection' => EE_Dependency_Map::load_from_cache,
608
-                'EventEspresso\core\services\assets\I18nRegistry'    => EE_Dependency_Map::load_from_cache,
609
-            ),
610
-            'EventEspresso\core\domain\entities\shortcodes\EspressoCancelled'                                             => array(
611
-                'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
612
-            ),
613
-            'EventEspresso\core\domain\entities\shortcodes\EspressoCheckout'                                              => array(
614
-                'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
615
-            ),
616
-            'EventEspresso\core\domain\entities\shortcodes\EspressoEventAttendees'                                        => array(
617
-                'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
618
-            ),
619
-            'EventEspresso\core\domain\entities\shortcodes\EspressoEvents'                                                => array(
620
-                'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
621
-            ),
622
-            'EventEspresso\core\domain\entities\shortcodes\EspressoThankYou'                                              => array(
623
-                'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
624
-            ),
625
-            'EventEspresso\core\domain\entities\shortcodes\EspressoTicketSelector'                                        => array(
626
-                'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
627
-            ),
628
-            'EventEspresso\core\domain\entities\shortcodes\EspressoTxnPage'                                               => array(
629
-                'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
630
-            ),
631
-            'EventEspresso\core\services\cache\BasicCacheManager'                                                         => array(
632
-                'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache,
633
-            ),
634
-            'EventEspresso\core\services\cache\PostRelatedCacheManager'                                                   => array(
635
-                'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache,
636
-            ),
637
-            'EventEspresso\core\domain\services\validation\email\EmailValidationService'                                  => array(
638
-                'EE_Registration_Config'                     => EE_Dependency_Map::load_from_cache,
639
-                'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache,
640
-            ),
641
-            'EventEspresso\core\domain\values\EmailAddress'                                                               => array(
642
-                null,
643
-                'EventEspresso\core\domain\services\validation\email\EmailValidationService' => EE_Dependency_Map::load_from_cache,
644
-            ),
645
-            'EventEspresso\core\services\orm\ModelFieldFactory'                                                           => array(
646
-                'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache,
647
-            ),
648
-            'LEGACY_MODELS'                                                                                               => array(
649
-                null,
650
-                'EventEspresso\core\services\database\ModelFieldFactory' => EE_Dependency_Map::load_from_cache,
651
-            ),
652
-            'EE_Module_Request_Router'                                                                                    => array(
653
-                'EE_Request' => EE_Dependency_Map::load_from_cache,
654
-            ),
655
-            'EE_Registration_Processor'                                                                                   => array(
656
-                'EE_Request' => EE_Dependency_Map::load_from_cache,
657
-            ),
658
-            'EventEspresso\core\services\notifications\PersistentAdminNoticeManager'                                      => array(
659
-                null,
660
-                'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache,
661
-                'EventEspresso\core\services\request\Request'                         => EE_Dependency_Map::load_from_cache,
662
-            ),
663
-            'EventEspresso\core\services\licensing\LicenseService'                                                        => array(
664
-                'EventEspresso\core\domain\services\pue\Stats'  => EE_Dependency_Map::load_from_cache,
665
-                'EventEspresso\core\domain\services\pue\Config' => EE_Dependency_Map::load_from_cache,
666
-            ),
667
-            'EE_Admin_Transactions_List_Table'                                                                            => array(
668
-                null,
669
-                'EventEspresso\core\domain\values\session\SessionLifespan' => EE_Dependency_Map::load_from_cache,
670
-            ),
671
-            'EventEspresso\core\domain\services\pue\Stats'                                                                => array(
672
-                'EventEspresso\core\domain\services\pue\Config'        => EE_Dependency_Map::load_from_cache,
673
-                'EE_Maintenance_Mode'                                  => EE_Dependency_Map::load_from_cache,
674
-                'EventEspresso\core\domain\services\pue\StatsGatherer' => EE_Dependency_Map::load_from_cache,
675
-            ),
676
-            'EventEspresso\core\domain\services\pue\Config'                                                               => array(
677
-                'EE_Network_Config' => EE_Dependency_Map::load_from_cache,
678
-                'EE_Config'         => EE_Dependency_Map::load_from_cache,
679
-            ),
680
-            'EventEspresso\core\domain\services\pue\StatsGatherer'                                                        => array(
681
-                'EEM_Payment_Method' => EE_Dependency_Map::load_from_cache,
682
-                'EEM_Event'          => EE_Dependency_Map::load_from_cache,
683
-                'EEM_Datetime'       => EE_Dependency_Map::load_from_cache,
684
-                'EEM_Ticket'         => EE_Dependency_Map::load_from_cache,
685
-                'EEM_Registration'   => EE_Dependency_Map::load_from_cache,
686
-                'EEM_Transaction'    => EE_Dependency_Map::load_from_cache,
687
-                'EE_Config'          => EE_Dependency_Map::load_from_cache,
688
-            ),
689
-            'EventEspresso\core\domain\services\admin\ExitModal'                                                          => array(
690
-                'EventEspresso\core\services\assets\Registry' => EE_Dependency_Map::load_from_cache,
691
-            ),
692
-            'EventEspresso\core\domain\services\admin\PluginUpsells'                                                      => array(
693
-                'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache,
694
-            ),
695
-            'EventEspresso\caffeinated\modules\recaptcha_invisible\InvisibleRecaptcha'                                    => array(
696
-                'EE_Registration_Config' => EE_Dependency_Map::load_from_cache,
697
-                'EE_Session'             => EE_Dependency_Map::load_from_cache,
698
-            ),
699
-            'EventEspresso\caffeinated\modules\recaptcha_invisible\RecaptchaAdminSettings'                                => array(
700
-                'EE_Registration_Config' => EE_Dependency_Map::load_from_cache,
701
-            ),
702
-            'EventEspresso\modules\ticket_selector\ProcessTicketSelector'                                                 => array(
703
-                'EE_Core_Config'                                                          => EE_Dependency_Map::load_from_cache,
704
-                'EventEspresso\core\services\request\Request'                             => EE_Dependency_Map::load_from_cache,
705
-                'EE_Session'                                                              => EE_Dependency_Map::load_from_cache,
706
-                'EEM_Ticket'                                                              => EE_Dependency_Map::load_from_cache,
707
-                'EventEspresso\modules\ticket_selector\TicketDatetimeAvailabilityTracker' => EE_Dependency_Map::load_from_cache,
708
-            ),
709
-            'EventEspresso\modules\ticket_selector\TicketDatetimeAvailabilityTracker'                                     => array(
710
-                'EEM_Datetime' => EE_Dependency_Map::load_from_cache,
711
-            ),
712
-            'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions'                              => array(
713
-                'EE_Core_Config'                             => EE_Dependency_Map::load_from_cache,
714
-                'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache,
715
-            ),
716
-            'EventEspresso\core\domain\services\custom_post_types\RegisterCustomPostTypes'                                => array(
717
-                'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' => EE_Dependency_Map::load_from_cache,
718
-            ),
719
-            'EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomies'                               => array(
720
-                'EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions' => EE_Dependency_Map::load_from_cache,
721
-            ),
722
-            'EE_CPT_Strategy'                                                                                             => array(
723
-                'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' => EE_Dependency_Map::load_from_cache,
724
-                'EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions' => EE_Dependency_Map::load_from_cache,
725
-            ),
726
-            'EventEspresso\core\services\loaders\ObjectIdentifier'                                                        => array(
727
-                'EventEspresso\core\services\loaders\ClassInterfaceCache' => EE_Dependency_Map::load_from_cache,
728
-            ),
729
-            'EventEspresso\core\domain\services\assets\CoreAssetManager'                                                  => array(
730
-                'EventEspresso\core\services\assets\AssetCollection' => EE_Dependency_Map::load_from_cache,
731
-                'EE_Currency_Config'                                 => EE_Dependency_Map::load_from_cache,
732
-                'EE_Template_Config'                                 => EE_Dependency_Map::load_from_cache,
733
-                'EventEspresso\core\domain\Domain'                   => EE_Dependency_Map::load_from_cache,
734
-                'EventEspresso\core\services\assets\Registry'        => EE_Dependency_Map::load_from_cache,
735
-            ),
736
-            'EventEspresso\core\domain\services\admin\privacy\policy\PrivacyPolicy' => array(
737
-                'EEM_Payment_Method' => EE_Dependency_Map::load_from_cache,
738
-                'EventEspresso\core\domain\values\session\SessionLifespan' => EE_Dependency_Map::load_from_cache
739
-            ),
740
-            'EventEspresso\core\domain\services\admin\privacy\export\ExportAttendee' => array(
741
-                'EEM_Attendee' => EE_Dependency_Map::load_from_cache,
742
-            ),
743
-            'EventEspresso\core\domain\services\admin\privacy\export\ExportAttendeeBillingData' => array(
744
-                'EEM_Attendee' => EE_Dependency_Map::load_from_cache,
745
-                'EEM_Payment_Method' => EE_Dependency_Map::load_from_cache
746
-            ),
747
-            'EventEspresso\core\domain\services\admin\privacy\export\ExportCheckins' => array(
748
-                'EEM_Checkin' => EE_Dependency_Map::load_from_cache,
749
-            ),
750
-            'EventEspresso\core\domain\services\admin\privacy\export\ExportRegistration' => array(
751
-                'EEM_Registration' => EE_Dependency_Map::load_from_cache,
752
-            ),
753
-            'EventEspresso\core\domain\services\admin\privacy\export\ExportTransaction' => array(
754
-                'EEM_Transaction' => EE_Dependency_Map::load_from_cache,
755
-            ),
756
-            'EventEspresso\core\domain\services\admin\privacy\erasure\EraseAttendeeData' => array(
757
-                'EEM_Attendee' => EE_Dependency_Map::load_from_cache,
758
-            ),
759
-            'EventEspresso\core\domain\services\admin\privacy\erasure\EraseAnswers' => array(
760
-                'EEM_Answer' => EE_Dependency_Map::load_from_cache,
761
-                'EEM_Question' => EE_Dependency_Map::load_from_cache,
762
-            ),
763
-            'EventEspresso\core\CPTs\CptQueryModifier' => array(
764
-                null,
765
-                null,
766
-                null,
767
-                'EE_Request_Handler'                          => EE_Dependency_Map::load_from_cache,
768
-                'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache,
769
-                'EventEspresso\core\services\loaders\Loader'  => EE_Dependency_Map::load_from_cache,
770
-            ),
771
-            'EventEspresso\core\domain\services\admin\privacy\forms\PrivacySettingsFormHandler' => array(
772
-                'EE_Registry' => EE_Dependency_Map::load_from_cache,
773
-                'EE_Config' => EE_Dependency_Map::load_from_cache
774
-            ),
775
-            'EventEspresso\core\services\editor\BlockRegistrationManager'                                                 => array(
776
-                'EventEspresso\core\services\assets\BlockAssetManagerCollection' => EE_Dependency_Map::load_from_cache,
777
-                'EventEspresso\core\domain\entities\editor\BlockCollection'      => EE_Dependency_Map::load_from_cache,
778
-                'EventEspresso\core\services\request\Request'                    => EE_Dependency_Map::load_from_cache,
779
-            ),
780
-            'EventEspresso\core\domain\entities\editor\blocks\CoreBlocksAssetManager' => array(
781
-                'EventEspresso\core\domain\Domain'                   => EE_Dependency_Map::load_from_cache,
782
-                'EventEspresso\core\services\assets\AssetCollection' => EE_Dependency_Map::load_from_cache,
783
-                'EventEspresso\core\services\assets\Registry'        => EE_Dependency_Map::load_from_cache,
784
-            ),
785
-            'EventEspresso\core\domain\entities\editor\blocks\widgets\EventAttendees' => array(
786
-                'EventEspresso\core\domain\entities\editor\blocks\CoreBlocksAssetManager' => self::load_from_cache,
787
-            ),
788
-        );
789
-    }
790
-
791
-
792
-    /**
793
-     * Registers how core classes are loaded.
794
-     * This can either be done by simply providing the name of one of the EE_Registry loader methods such as:
795
-     *        'EE_Request_Handler' => 'load_core'
796
-     *        'EE_Messages_Queue'  => 'load_lib'
797
-     *        'EEH_Debug_Tools'    => 'load_helper'
798
-     * or, if greater control is required, by providing a custom closure. For example:
799
-     *        'Some_Class' => function () {
800
-     *            return new Some_Class();
801
-     *        },
802
-     * This is required for instantiating dependencies
803
-     * where an interface has been type hinted in a class constructor. For example:
804
-     *        'Required_Interface' => function () {
805
-     *            return new A_Class_That_Implements_Required_Interface();
806
-     *        },
807
-     */
808
-    protected function _register_core_class_loaders()
809
-    {
810
-        // for PHP5.3 compat, we need to register any properties called here in a variable because `$this` cannot
811
-        // be used in a closure.
812
-        $request = &$this->request;
813
-        $response = &$this->response;
814
-        $legacy_request = &$this->legacy_request;
815
-        // $loader = &$this->loader;
816
-        $this->_class_loaders = array(
817
-            // load_core
818
-            'EE_Capabilities'                              => 'load_core',
819
-            'EE_Encryption'                                => 'load_core',
820
-            'EE_Front_Controller'                          => 'load_core',
821
-            'EE_Module_Request_Router'                     => 'load_core',
822
-            'EE_Registry'                                  => 'load_core',
823
-            'EE_Request'                                   => function () use (&$legacy_request) {
824
-                return $legacy_request;
825
-            },
826
-            'EventEspresso\core\services\request\Request'  => function () use (&$request) {
827
-                return $request;
828
-            },
829
-            'EventEspresso\core\services\request\Response' => function () use (&$response) {
830
-                return $response;
831
-            },
832
-            'EE_Base'                                      => 'load_core',
833
-            'EE_Request_Handler'                           => 'load_core',
834
-            'EE_Session'                                   => 'load_core',
835
-            'EE_Cron_Tasks'                                => 'load_core',
836
-            'EE_System'                                    => 'load_core',
837
-            'EE_Maintenance_Mode'                          => 'load_core',
838
-            'EE_Register_CPTs'                             => 'load_core',
839
-            'EE_Admin'                                     => 'load_core',
840
-            'EE_CPT_Strategy'                              => 'load_core',
841
-            // load_lib
842
-            'EE_Message_Resource_Manager'                  => 'load_lib',
843
-            'EE_Message_Type_Collection'                   => 'load_lib',
844
-            'EE_Message_Type_Collection_Loader'            => 'load_lib',
845
-            'EE_Messenger_Collection'                      => 'load_lib',
846
-            'EE_Messenger_Collection_Loader'               => 'load_lib',
847
-            'EE_Messages_Processor'                        => 'load_lib',
848
-            'EE_Message_Repository'                        => 'load_lib',
849
-            'EE_Messages_Queue'                            => 'load_lib',
850
-            'EE_Messages_Data_Handler_Collection'          => 'load_lib',
851
-            'EE_Message_Template_Group_Collection'         => 'load_lib',
852
-            'EE_Payment_Method_Manager'                    => 'load_lib',
853
-            'EE_Messages_Generator'                        => function () {
854
-                return EE_Registry::instance()->load_lib(
855
-                    'Messages_Generator',
856
-                    array(),
857
-                    false,
858
-                    false
859
-                );
860
-            },
861
-            'EE_Messages_Template_Defaults'                => function ($arguments = array()) {
862
-                return EE_Registry::instance()->load_lib(
863
-                    'Messages_Template_Defaults',
864
-                    $arguments,
865
-                    false,
866
-                    false
867
-                );
868
-            },
869
-            // load_helper
870
-            'EEH_Parse_Shortcodes'                         => function () {
871
-                if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) {
872
-                    return new EEH_Parse_Shortcodes();
873
-                }
874
-                return null;
875
-            },
876
-            'EE_Template_Config'                           => function () {
877
-                return EE_Config::instance()->template_settings;
878
-            },
879
-            'EE_Currency_Config'                           => function () {
880
-                return EE_Config::instance()->currency;
881
-            },
882
-            'EE_Registration_Config'                       => function () {
883
-                return EE_Config::instance()->registration;
884
-            },
885
-            'EE_Core_Config'                               => function () {
886
-                return EE_Config::instance()->core;
887
-            },
888
-            'EventEspresso\core\services\loaders\Loader'   => function () {
889
-                return LoaderFactory::getLoader();
890
-            },
891
-            'EE_Network_Config'                            => function () {
892
-                return EE_Network_Config::instance();
893
-            },
894
-            'EE_Config'                                    => function () {
895
-                return EE_Config::instance();
896
-            },
897
-            'EventEspresso\core\domain\Domain'             => function () {
898
-                return DomainFactory::getEventEspressoCoreDomain();
899
-            },
900
-            'EE_Admin_Config'                              => function () {
901
-                return EE_Config::instance()->admin;
902
-            },
903
-        );
904
-    }
905
-
906
-
907
-    /**
908
-     * can be used for supplying alternate names for classes,
909
-     * or for connecting interface names to instantiable classes
910
-     */
911
-    protected function _register_core_aliases()
912
-    {
913
-        $aliases = array(
914
-            'CommandBusInterface'                                                          => 'EventEspresso\core\services\commands\CommandBusInterface',
915
-            'EventEspresso\core\services\commands\CommandBusInterface'                     => 'EventEspresso\core\services\commands\CommandBus',
916
-            'CommandHandlerManagerInterface'                                               => 'EventEspresso\core\services\commands\CommandHandlerManagerInterface',
917
-            'EventEspresso\core\services\commands\CommandHandlerManagerInterface'          => 'EventEspresso\core\services\commands\CommandHandlerManager',
918
-            'CapChecker'                                                                   => 'EventEspresso\core\services\commands\middleware\CapChecker',
919
-            'AddActionHook'                                                                => 'EventEspresso\core\services\commands\middleware\AddActionHook',
920
-            'CapabilitiesChecker'                                                          => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker',
921
-            'CapabilitiesCheckerInterface'                                                 => 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface',
922
-            'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker',
923
-            'CreateRegistrationService'                                                    => 'EventEspresso\core\domain\services\registration\CreateRegistrationService',
924
-            'CreateRegistrationCommandHandler'                                             => 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand',
925
-            'CopyRegistrationDetailsCommandHandler'                                        => 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommand',
926
-            'CopyRegistrationPaymentsCommandHandler'                                       => 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommand',
927
-            'CancelRegistrationAndTicketLineItemCommandHandler'                            => 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler',
928
-            'UpdateRegistrationAndTransactionAfterChangeCommandHandler'                    => 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler',
929
-            'CreateTicketLineItemCommandHandler'                                           => 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommand',
930
-            'CreateTransactionCommandHandler'                                              => 'EventEspresso\core\services\commands\transaction\CreateTransactionCommandHandler',
931
-            'CreateAttendeeCommandHandler'                                                 => 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler',
932
-            'TableManager'                                                                 => 'EventEspresso\core\services\database\TableManager',
933
-            'TableAnalysis'                                                                => 'EventEspresso\core\services\database\TableAnalysis',
934
-            'EspressoShortcode'                                                            => 'EventEspresso\core\services\shortcodes\EspressoShortcode',
935
-            'ShortcodeInterface'                                                           => 'EventEspresso\core\services\shortcodes\ShortcodeInterface',
936
-            'EventEspresso\core\services\shortcodes\ShortcodeInterface'                    => 'EventEspresso\core\services\shortcodes\EspressoShortcode',
937
-            'EventEspresso\core\services\cache\CacheStorageInterface'                      => 'EventEspresso\core\services\cache\TransientCacheStorage',
938
-            'LoaderInterface'                                                              => 'EventEspresso\core\services\loaders\LoaderInterface',
939
-            'EventEspresso\core\services\loaders\LoaderInterface'                          => 'EventEspresso\core\services\loaders\Loader',
940
-            'CommandFactoryInterface'                                                      => 'EventEspresso\core\services\commands\CommandFactoryInterface',
941
-            'EventEspresso\core\services\commands\CommandFactoryInterface'                 => 'EventEspresso\core\services\commands\CommandFactory',
942
-            'EventEspresso\core\domain\services\session\SessionIdentifierInterface'        => 'EE_Session',
943
-            'EmailValidatorInterface'                                                      => 'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface',
944
-            'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface'  => 'EventEspresso\core\domain\services\validation\email\EmailValidationService',
945
-            'NoticeConverterInterface'                                                     => 'EventEspresso\core\services\notices\NoticeConverterInterface',
946
-            'EventEspresso\core\services\notices\NoticeConverterInterface'                 => 'EventEspresso\core\services\notices\ConvertNoticesToEeErrors',
947
-            'NoticesContainerInterface'                                                    => 'EventEspresso\core\services\notices\NoticesContainerInterface',
948
-            'EventEspresso\core\services\notices\NoticesContainerInterface'                => 'EventEspresso\core\services\notices\NoticesContainer',
949
-            'EventEspresso\core\services\request\RequestInterface'                         => 'EventEspresso\core\services\request\Request',
950
-            'EventEspresso\core\services\request\ResponseInterface'                        => 'EventEspresso\core\services\request\Response',
951
-            'EventEspresso\core\domain\DomainInterface'                                    => 'EventEspresso\core\domain\Domain',
952
-        );
953
-        foreach ($aliases as $alias => $fqn) {
954
-            if (is_array($fqn)) {
955
-                foreach ($fqn as $class => $for_class) {
956
-                    $this->class_cache->addAlias($class, $alias, $for_class);
957
-                }
958
-                continue;
959
-            }
960
-            $this->class_cache->addAlias($fqn, $alias);
961
-        }
962
-        if (! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) {
963
-            $this->class_cache->addAlias(
964
-                'EventEspresso\core\services\notices\ConvertNoticesToAdminNotices',
965
-                'EventEspresso\core\services\notices\NoticeConverterInterface'
966
-            );
967
-        }
968
-    }
969
-
970
-
971
-    /**
972
-     * This is used to reset the internal map and class_loaders to their original default state at the beginning of the
973
-     * request Primarily used by unit tests.
974
-     */
975
-    public function reset()
976
-    {
977
-        $this->_register_core_class_loaders();
978
-        $this->_register_core_dependencies();
979
-    }
980
-
981
-
982
-    /**
983
-     * PLZ NOTE: a better name for this method would be is_alias()
984
-     * because it returns TRUE if the provided fully qualified name IS an alias
985
-     * WHY?
986
-     * Because if a class is type hinting for a concretion,
987
-     * then why would we need to find another class to supply it?
988
-     * ie: if a class asks for `Fully/Qualified/Namespace/SpecificClassName`,
989
-     * then give it an instance of `Fully/Qualified/Namespace/SpecificClassName`.
990
-     * Don't go looking for some substitute.
991
-     * Whereas if a class is type hinting for an interface...
992
-     * then we need to find an actual class to use.
993
-     * So the interface IS the alias for some other FQN,
994
-     * and we need to find out if `Fully/Qualified/Namespace/SomeInterface`
995
-     * represents some other class.
996
-     *
997
-     * @deprecated 4.9.62.p
998
-     * @param string $fqn
999
-     * @param string $for_class
1000
-     * @return bool
1001
-     */
1002
-    public function has_alias($fqn = '', $for_class = '')
1003
-    {
1004
-        return $this->isAlias($fqn, $for_class);
1005
-    }
1006
-
1007
-
1008
-    /**
1009
-     * PLZ NOTE: a better name for this method would be get_fqn_for_alias()
1010
-     * because it returns a FQN for provided alias if one exists, otherwise returns the original $alias
1011
-     * functions recursively, so that multiple aliases can be used to drill down to a FQN
1012
-     *  for example:
1013
-     *      if the following two entries were added to the _aliases array:
1014
-     *          array(
1015
-     *              'interface_alias'           => 'some\namespace\interface'
1016
-     *              'some\namespace\interface'  => 'some\namespace\classname'
1017
-     *          )
1018
-     *      then one could use EE_Registry::instance()->create( 'interface_alias' )
1019
-     *      to load an instance of 'some\namespace\classname'
1020
-     *
1021
-     * @deprecated 4.9.62.p
1022
-     * @param string $alias
1023
-     * @param string $for_class
1024
-     * @return string
1025
-     */
1026
-    public function get_alias($alias = '', $for_class = '')
1027
-    {
1028
-        return $this->getFqnForAlias($alias, $for_class);
1029
-    }
23
+	/**
24
+	 * This means that the requested class dependency is not present in the dependency map
25
+	 */
26
+	const not_registered = 0;
27
+
28
+	/**
29
+	 * This instructs class loaders to ALWAYS return a newly instantiated object for the requested class.
30
+	 */
31
+	const load_new_object = 1;
32
+
33
+	/**
34
+	 * This instructs class loaders to return a previously instantiated and cached object for the requested class.
35
+	 * IF a previously instantiated object does not exist, a new one will be created and added to the cache.
36
+	 */
37
+	const load_from_cache = 2;
38
+
39
+	/**
40
+	 * When registering a dependency,
41
+	 * this indicates to keep any existing dependencies that already exist,
42
+	 * and simply discard any new dependencies declared in the incoming data
43
+	 */
44
+	const KEEP_EXISTING_DEPENDENCIES = 0;
45
+
46
+	/**
47
+	 * When registering a dependency,
48
+	 * this indicates to overwrite any existing dependencies that already exist using the incoming data
49
+	 */
50
+	const OVERWRITE_DEPENDENCIES = 1;
51
+
52
+
53
+	/**
54
+	 * @type EE_Dependency_Map $_instance
55
+	 */
56
+	protected static $_instance;
57
+
58
+	/**
59
+	 * @var ClassInterfaceCache $class_cache
60
+	 */
61
+	private $class_cache;
62
+
63
+	/**
64
+	 * @type RequestInterface $request
65
+	 */
66
+	protected $request;
67
+
68
+	/**
69
+	 * @type LegacyRequestInterface $legacy_request
70
+	 */
71
+	protected $legacy_request;
72
+
73
+	/**
74
+	 * @type ResponseInterface $response
75
+	 */
76
+	protected $response;
77
+
78
+	/**
79
+	 * @type LoaderInterface $loader
80
+	 */
81
+	protected $loader;
82
+
83
+	/**
84
+	 * @type array $_dependency_map
85
+	 */
86
+	protected $_dependency_map = array();
87
+
88
+	/**
89
+	 * @type array $_class_loaders
90
+	 */
91
+	protected $_class_loaders = array();
92
+
93
+
94
+	/**
95
+	 * EE_Dependency_Map constructor.
96
+	 *
97
+	 * @param ClassInterfaceCache $class_cache
98
+	 */
99
+	protected function __construct(ClassInterfaceCache $class_cache)
100
+	{
101
+		$this->class_cache = $class_cache;
102
+		do_action('EE_Dependency_Map____construct', $this);
103
+	}
104
+
105
+
106
+	/**
107
+	 * @return void
108
+	 */
109
+	public function initialize()
110
+	{
111
+		$this->_register_core_dependencies();
112
+		$this->_register_core_class_loaders();
113
+		$this->_register_core_aliases();
114
+	}
115
+
116
+
117
+	/**
118
+	 * @singleton method used to instantiate class object
119
+	 * @param ClassInterfaceCache|null $class_cache
120
+	 * @return EE_Dependency_Map
121
+	 */
122
+	public static function instance(ClassInterfaceCache $class_cache = null)
123
+	{
124
+		// check if class object is instantiated, and instantiated properly
125
+		if (! self::$_instance instanceof EE_Dependency_Map
126
+			&& $class_cache instanceof ClassInterfaceCache
127
+		) {
128
+			self::$_instance = new EE_Dependency_Map($class_cache);
129
+		}
130
+		return self::$_instance;
131
+	}
132
+
133
+
134
+	/**
135
+	 * @param RequestInterface $request
136
+	 */
137
+	public function setRequest(RequestInterface $request)
138
+	{
139
+		$this->request = $request;
140
+	}
141
+
142
+
143
+	/**
144
+	 * @param LegacyRequestInterface $legacy_request
145
+	 */
146
+	public function setLegacyRequest(LegacyRequestInterface $legacy_request)
147
+	{
148
+		$this->legacy_request = $legacy_request;
149
+	}
150
+
151
+
152
+	/**
153
+	 * @param ResponseInterface $response
154
+	 */
155
+	public function setResponse(ResponseInterface $response)
156
+	{
157
+		$this->response = $response;
158
+	}
159
+
160
+
161
+	/**
162
+	 * @param LoaderInterface $loader
163
+	 */
164
+	public function setLoader(LoaderInterface $loader)
165
+	{
166
+		$this->loader = $loader;
167
+	}
168
+
169
+
170
+	/**
171
+	 * @param string $class
172
+	 * @param array  $dependencies
173
+	 * @param int    $overwrite
174
+	 * @return bool
175
+	 */
176
+	public static function register_dependencies(
177
+		$class,
178
+		array $dependencies,
179
+		$overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES
180
+	) {
181
+		return self::$_instance->registerDependencies($class, $dependencies, $overwrite);
182
+	}
183
+
184
+
185
+	/**
186
+	 * Assigns an array of class names and corresponding load sources (new or cached)
187
+	 * to the class specified by the first parameter.
188
+	 * IMPORTANT !!!
189
+	 * The order of elements in the incoming $dependencies array MUST match
190
+	 * the order of the constructor parameters for the class in question.
191
+	 * This is especially important when overriding any existing dependencies that are registered.
192
+	 * the third parameter controls whether any duplicate dependencies are overwritten or not.
193
+	 *
194
+	 * @param string $class
195
+	 * @param array  $dependencies
196
+	 * @param int    $overwrite
197
+	 * @return bool
198
+	 */
199
+	public function registerDependencies(
200
+		$class,
201
+		array $dependencies,
202
+		$overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES
203
+	) {
204
+		$class = trim($class, '\\');
205
+		$registered = false;
206
+		if (empty(self::$_instance->_dependency_map[ $class ])) {
207
+			self::$_instance->_dependency_map[ $class ] = array();
208
+		}
209
+		// we need to make sure that any aliases used when registering a dependency
210
+		// get resolved to the correct class name
211
+		foreach ($dependencies as $dependency => $load_source) {
212
+			$alias = self::$_instance->getFqnForAlias($dependency);
213
+			if ($overwrite === EE_Dependency_Map::OVERWRITE_DEPENDENCIES
214
+				|| ! isset(self::$_instance->_dependency_map[ $class ][ $alias ])
215
+			) {
216
+				unset($dependencies[ $dependency ]);
217
+				$dependencies[ $alias ] = $load_source;
218
+				$registered = true;
219
+			}
220
+		}
221
+		// now add our two lists of dependencies together.
222
+		// using Union (+=) favours the arrays in precedence from left to right,
223
+		// so $dependencies is NOT overwritten because it is listed first
224
+		// ie: with A = B + C, entries in B take precedence over duplicate entries in C
225
+		// Union is way faster than array_merge() but should be used with caution...
226
+		// especially with numerically indexed arrays
227
+		$dependencies += self::$_instance->_dependency_map[ $class ];
228
+		// now we need to ensure that the resulting dependencies
229
+		// array only has the entries that are required for the class
230
+		// so first count how many dependencies were originally registered for the class
231
+		$dependency_count = count(self::$_instance->_dependency_map[ $class ]);
232
+		// if that count is non-zero (meaning dependencies were already registered)
233
+		self::$_instance->_dependency_map[ $class ] = $dependency_count
234
+			// then truncate the  final array to match that count
235
+			? array_slice($dependencies, 0, $dependency_count)
236
+			// otherwise just take the incoming array because nothing previously existed
237
+			: $dependencies;
238
+		return $registered;
239
+	}
240
+
241
+
242
+	/**
243
+	 * @param string $class_name
244
+	 * @param string $loader
245
+	 * @return bool
246
+	 * @throws DomainException
247
+	 */
248
+	public static function register_class_loader($class_name, $loader = 'load_core')
249
+	{
250
+		if (! $loader instanceof Closure && strpos($class_name, '\\') !== false) {
251
+			throw new DomainException(
252
+				esc_html__('Don\'t use class loaders for FQCNs.', 'event_espresso')
253
+			);
254
+		}
255
+		// check that loader is callable or method starts with "load_" and exists in EE_Registry
256
+		if (! is_callable($loader)
257
+			&& (
258
+				strpos($loader, 'load_') !== 0
259
+				|| ! method_exists('EE_Registry', $loader)
260
+			)
261
+		) {
262
+			throw new DomainException(
263
+				sprintf(
264
+					esc_html__(
265
+						'"%1$s" is not a valid loader method on EE_Registry.',
266
+						'event_espresso'
267
+					),
268
+					$loader
269
+				)
270
+			);
271
+		}
272
+		$class_name = self::$_instance->getFqnForAlias($class_name);
273
+		if (! isset(self::$_instance->_class_loaders[ $class_name ])) {
274
+			self::$_instance->_class_loaders[ $class_name ] = $loader;
275
+			return true;
276
+		}
277
+		return false;
278
+	}
279
+
280
+
281
+	/**
282
+	 * @return array
283
+	 */
284
+	public function dependency_map()
285
+	{
286
+		return $this->_dependency_map;
287
+	}
288
+
289
+
290
+	/**
291
+	 * returns TRUE if dependency map contains a listing for the provided class name
292
+	 *
293
+	 * @param string $class_name
294
+	 * @return boolean
295
+	 */
296
+	public function has($class_name = '')
297
+	{
298
+		// all legacy models have the same dependencies
299
+		if (strpos($class_name, 'EEM_') === 0) {
300
+			$class_name = 'LEGACY_MODELS';
301
+		}
302
+		return isset($this->_dependency_map[ $class_name ]) ? true : false;
303
+	}
304
+
305
+
306
+	/**
307
+	 * returns TRUE if dependency map contains a listing for the provided class name AND dependency
308
+	 *
309
+	 * @param string $class_name
310
+	 * @param string $dependency
311
+	 * @return bool
312
+	 */
313
+	public function has_dependency_for_class($class_name = '', $dependency = '')
314
+	{
315
+		// all legacy models have the same dependencies
316
+		if (strpos($class_name, 'EEM_') === 0) {
317
+			$class_name = 'LEGACY_MODELS';
318
+		}
319
+		$dependency = $this->getFqnForAlias($dependency, $class_name);
320
+		return isset($this->_dependency_map[ $class_name ][ $dependency ])
321
+			? true
322
+			: false;
323
+	}
324
+
325
+
326
+	/**
327
+	 * returns loading strategy for whether a previously cached dependency should be loaded or a new instance returned
328
+	 *
329
+	 * @param string $class_name
330
+	 * @param string $dependency
331
+	 * @return int
332
+	 */
333
+	public function loading_strategy_for_class_dependency($class_name = '', $dependency = '')
334
+	{
335
+		// all legacy models have the same dependencies
336
+		if (strpos($class_name, 'EEM_') === 0) {
337
+			$class_name = 'LEGACY_MODELS';
338
+		}
339
+		$dependency = $this->getFqnForAlias($dependency);
340
+		return $this->has_dependency_for_class($class_name, $dependency)
341
+			? $this->_dependency_map[ $class_name ][ $dependency ]
342
+			: EE_Dependency_Map::not_registered;
343
+	}
344
+
345
+
346
+	/**
347
+	 * @param string $class_name
348
+	 * @return string | Closure
349
+	 */
350
+	public function class_loader($class_name)
351
+	{
352
+		// all legacy models use load_model()
353
+		if (strpos($class_name, 'EEM_') === 0) {
354
+			return 'load_model';
355
+		}
356
+		// EE_CPT_*_Strategy classes like EE_CPT_Event_Strategy, EE_CPT_Venue_Strategy, etc
357
+		// perform strpos() first to avoid loading regex every time we load a class
358
+		if (strpos($class_name, 'EE_CPT_') === 0
359
+			&& preg_match('/^EE_CPT_([a-zA-Z]+)_Strategy$/', $class_name)
360
+		) {
361
+			return 'load_core';
362
+		}
363
+		$class_name = $this->getFqnForAlias($class_name);
364
+		return isset($this->_class_loaders[ $class_name ]) ? $this->_class_loaders[ $class_name ] : '';
365
+	}
366
+
367
+
368
+	/**
369
+	 * @return array
370
+	 */
371
+	public function class_loaders()
372
+	{
373
+		return $this->_class_loaders;
374
+	}
375
+
376
+
377
+	/**
378
+	 * adds an alias for a classname
379
+	 *
380
+	 * @param string $fqcn      the class name that should be used (concrete class to replace interface)
381
+	 * @param string $alias     the class name that would be type hinted for (abstract parent or interface)
382
+	 * @param string $for_class the class that has the dependency (is type hinting for the interface)
383
+	 */
384
+	public function add_alias($fqcn, $alias, $for_class = '')
385
+	{
386
+		$this->class_cache->addAlias($fqcn, $alias, $for_class);
387
+	}
388
+
389
+
390
+	/**
391
+	 * Returns TRUE if the provided fully qualified name IS an alias
392
+	 * WHY?
393
+	 * Because if a class is type hinting for a concretion,
394
+	 * then why would we need to find another class to supply it?
395
+	 * ie: if a class asks for `Fully/Qualified/Namespace/SpecificClassName`,
396
+	 * then give it an instance of `Fully/Qualified/Namespace/SpecificClassName`.
397
+	 * Don't go looking for some substitute.
398
+	 * Whereas if a class is type hinting for an interface...
399
+	 * then we need to find an actual class to use.
400
+	 * So the interface IS the alias for some other FQN,
401
+	 * and we need to find out if `Fully/Qualified/Namespace/SomeInterface`
402
+	 * represents some other class.
403
+	 *
404
+	 * @param string $fqn
405
+	 * @param string $for_class
406
+	 * @return bool
407
+	 */
408
+	public function isAlias($fqn = '', $for_class = '')
409
+	{
410
+		return $this->class_cache->isAlias($fqn, $for_class);
411
+	}
412
+
413
+
414
+	/**
415
+	 * Returns a FQN for provided alias if one exists, otherwise returns the original $alias
416
+	 * functions recursively, so that multiple aliases can be used to drill down to a FQN
417
+	 *  for example:
418
+	 *      if the following two entries were added to the _aliases array:
419
+	 *          array(
420
+	 *              'interface_alias'           => 'some\namespace\interface'
421
+	 *              'some\namespace\interface'  => 'some\namespace\classname'
422
+	 *          )
423
+	 *      then one could use EE_Registry::instance()->create( 'interface_alias' )
424
+	 *      to load an instance of 'some\namespace\classname'
425
+	 *
426
+	 * @param string $alias
427
+	 * @param string $for_class
428
+	 * @return string
429
+	 */
430
+	public function getFqnForAlias($alias = '', $for_class = '')
431
+	{
432
+		return (string) $this->class_cache->getFqnForAlias($alias, $for_class);
433
+	}
434
+
435
+
436
+	/**
437
+	 * Registers the core dependencies and whether a previously instantiated object should be loaded from the cache,
438
+	 * if one exists, or whether a new object should be generated every time the requested class is loaded.
439
+	 * This is done by using the following class constants:
440
+	 *        EE_Dependency_Map::load_from_cache - loads previously instantiated object
441
+	 *        EE_Dependency_Map::load_new_object - generates a new object every time
442
+	 */
443
+	protected function _register_core_dependencies()
444
+	{
445
+		$this->_dependency_map = array(
446
+			'EE_Request_Handler'                                                                                          => array(
447
+				'EE_Request' => EE_Dependency_Map::load_from_cache,
448
+			),
449
+			'EE_System'                                                                                                   => array(
450
+				'EE_Registry'                                 => EE_Dependency_Map::load_from_cache,
451
+				'EventEspresso\core\services\loaders\Loader'  => EE_Dependency_Map::load_from_cache,
452
+				'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache,
453
+				'EE_Maintenance_Mode'                         => EE_Dependency_Map::load_from_cache,
454
+			),
455
+			'EE_Session'                                                                                                  => array(
456
+				'EventEspresso\core\services\cache\TransientCacheStorage'  => EE_Dependency_Map::load_from_cache,
457
+				'EventEspresso\core\domain\values\session\SessionLifespan' => EE_Dependency_Map::load_from_cache,
458
+				'EventEspresso\core\services\request\Request'              => EE_Dependency_Map::load_from_cache,
459
+				'EE_Encryption'                                            => EE_Dependency_Map::load_from_cache,
460
+			),
461
+			'EE_Cart'                                                                                                     => array(
462
+				'EE_Session' => EE_Dependency_Map::load_from_cache,
463
+			),
464
+			'EE_Front_Controller'                                                                                         => array(
465
+				'EE_Registry'              => EE_Dependency_Map::load_from_cache,
466
+				'EE_Request_Handler'       => EE_Dependency_Map::load_from_cache,
467
+				'EE_Module_Request_Router' => EE_Dependency_Map::load_from_cache,
468
+			),
469
+			'EE_Messenger_Collection_Loader'                                                                              => array(
470
+				'EE_Messenger_Collection' => EE_Dependency_Map::load_new_object,
471
+			),
472
+			'EE_Message_Type_Collection_Loader'                                                                           => array(
473
+				'EE_Message_Type_Collection' => EE_Dependency_Map::load_new_object,
474
+			),
475
+			'EE_Message_Resource_Manager'                                                                                 => array(
476
+				'EE_Messenger_Collection_Loader'    => EE_Dependency_Map::load_new_object,
477
+				'EE_Message_Type_Collection_Loader' => EE_Dependency_Map::load_new_object,
478
+				'EEM_Message_Template_Group'        => EE_Dependency_Map::load_from_cache,
479
+			),
480
+			'EE_Message_Factory'                                                                                          => array(
481
+				'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache,
482
+			),
483
+			'EE_messages'                                                                                                 => array(
484
+				'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache,
485
+			),
486
+			'EE_Messages_Generator'                                                                                       => array(
487
+				'EE_Messages_Queue'                    => EE_Dependency_Map::load_new_object,
488
+				'EE_Messages_Data_Handler_Collection'  => EE_Dependency_Map::load_new_object,
489
+				'EE_Message_Template_Group_Collection' => EE_Dependency_Map::load_new_object,
490
+				'EEH_Parse_Shortcodes'                 => EE_Dependency_Map::load_from_cache,
491
+			),
492
+			'EE_Messages_Processor'                                                                                       => array(
493
+				'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache,
494
+			),
495
+			'EE_Messages_Queue'                                                                                           => array(
496
+				'EE_Message_Repository' => EE_Dependency_Map::load_new_object,
497
+			),
498
+			'EE_Messages_Template_Defaults'                                                                               => array(
499
+				'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache,
500
+				'EEM_Message_Template'       => EE_Dependency_Map::load_from_cache,
501
+			),
502
+			'EE_Message_To_Generate_From_Request'                                                                         => array(
503
+				'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache,
504
+				'EE_Request_Handler'          => EE_Dependency_Map::load_from_cache,
505
+			),
506
+			'EventEspresso\core\services\commands\CommandBus'                                                             => array(
507
+				'EventEspresso\core\services\commands\CommandHandlerManager' => EE_Dependency_Map::load_from_cache,
508
+			),
509
+			'EventEspresso\services\commands\CommandHandler'                                                              => array(
510
+				'EE_Registry'         => EE_Dependency_Map::load_from_cache,
511
+				'CommandBusInterface' => EE_Dependency_Map::load_from_cache,
512
+			),
513
+			'EventEspresso\core\services\commands\CommandHandlerManager'                                                  => array(
514
+				'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache,
515
+			),
516
+			'EventEspresso\core\services\commands\CompositeCommandHandler'                                                => array(
517
+				'EventEspresso\core\services\commands\CommandBus'     => EE_Dependency_Map::load_from_cache,
518
+				'EventEspresso\core\services\commands\CommandFactory' => EE_Dependency_Map::load_from_cache,
519
+			),
520
+			'EventEspresso\core\services\commands\CommandFactory'                                                         => array(
521
+				'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache,
522
+			),
523
+			'EventEspresso\core\services\commands\middleware\CapChecker'                                                  => array(
524
+				'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache,
525
+			),
526
+			'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker'                                         => array(
527
+				'EE_Capabilities' => EE_Dependency_Map::load_from_cache,
528
+			),
529
+			'EventEspresso\core\domain\services\capabilities\RegistrationsCapChecker'                                     => array(
530
+				'EE_Capabilities' => EE_Dependency_Map::load_from_cache,
531
+			),
532
+			'EventEspresso\core\services\commands\registration\CreateRegistrationCommandHandler'                          => array(
533
+				'EventEspresso\core\domain\services\registration\CreateRegistrationService' => EE_Dependency_Map::load_from_cache,
534
+			),
535
+			'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommandHandler'                     => array(
536
+				'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache,
537
+			),
538
+			'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommandHandler'                    => array(
539
+				'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache,
540
+			),
541
+			'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler'         => array(
542
+				'EventEspresso\core\domain\services\registration\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache,
543
+			),
544
+			'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler' => array(
545
+				'EventEspresso\core\domain\services\registration\UpdateRegistrationService' => EE_Dependency_Map::load_from_cache,
546
+			),
547
+			'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommandHandler'                              => array(
548
+				'EventEspresso\core\domain\services\ticket\CreateTicketLineItemService' => EE_Dependency_Map::load_from_cache,
549
+			),
550
+			'EventEspresso\core\services\commands\ticket\CancelTicketLineItemCommandHandler'                              => array(
551
+				'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache,
552
+			),
553
+			'EventEspresso\core\domain\services\registration\CancelRegistrationService'                                   => array(
554
+				'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache,
555
+			),
556
+			'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler'                                  => array(
557
+				'EEM_Attendee' => EE_Dependency_Map::load_from_cache,
558
+			),
559
+			'EventEspresso\core\services\database\TableManager'                                                           => array(
560
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
561
+			),
562
+			'EE_Data_Migration_Class_Base'                                                                                => array(
563
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
564
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
565
+			),
566
+			'EE_DMS_Core_4_1_0'                                                                                           => array(
567
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
568
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
569
+			),
570
+			'EE_DMS_Core_4_2_0'                                                                                           => array(
571
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
572
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
573
+			),
574
+			'EE_DMS_Core_4_3_0'                                                                                           => array(
575
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
576
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
577
+			),
578
+			'EE_DMS_Core_4_4_0'                                                                                           => array(
579
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
580
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
581
+			),
582
+			'EE_DMS_Core_4_5_0'                                                                                           => array(
583
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
584
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
585
+			),
586
+			'EE_DMS_Core_4_6_0'                                                                                           => array(
587
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
588
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
589
+			),
590
+			'EE_DMS_Core_4_7_0'                                                                                           => array(
591
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
592
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
593
+			),
594
+			'EE_DMS_Core_4_8_0'                                                                                           => array(
595
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
596
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
597
+			),
598
+			'EE_DMS_Core_4_9_0'                                                                                           => array(
599
+				'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache,
600
+				'EventEspresso\core\services\database\TableManager'  => EE_Dependency_Map::load_from_cache,
601
+			),
602
+			'EventEspresso\core\services\assets\I18nRegistry'                                                             => array(
603
+				array(),
604
+				'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache,
605
+			),
606
+			'EventEspresso\core\services\assets\Registry'                                                                 => array(
607
+				'EventEspresso\core\services\assets\AssetCollection' => EE_Dependency_Map::load_from_cache,
608
+				'EventEspresso\core\services\assets\I18nRegistry'    => EE_Dependency_Map::load_from_cache,
609
+			),
610
+			'EventEspresso\core\domain\entities\shortcodes\EspressoCancelled'                                             => array(
611
+				'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
612
+			),
613
+			'EventEspresso\core\domain\entities\shortcodes\EspressoCheckout'                                              => array(
614
+				'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
615
+			),
616
+			'EventEspresso\core\domain\entities\shortcodes\EspressoEventAttendees'                                        => array(
617
+				'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
618
+			),
619
+			'EventEspresso\core\domain\entities\shortcodes\EspressoEvents'                                                => array(
620
+				'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
621
+			),
622
+			'EventEspresso\core\domain\entities\shortcodes\EspressoThankYou'                                              => array(
623
+				'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
624
+			),
625
+			'EventEspresso\core\domain\entities\shortcodes\EspressoTicketSelector'                                        => array(
626
+				'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
627
+			),
628
+			'EventEspresso\core\domain\entities\shortcodes\EspressoTxnPage'                                               => array(
629
+				'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache,
630
+			),
631
+			'EventEspresso\core\services\cache\BasicCacheManager'                                                         => array(
632
+				'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache,
633
+			),
634
+			'EventEspresso\core\services\cache\PostRelatedCacheManager'                                                   => array(
635
+				'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache,
636
+			),
637
+			'EventEspresso\core\domain\services\validation\email\EmailValidationService'                                  => array(
638
+				'EE_Registration_Config'                     => EE_Dependency_Map::load_from_cache,
639
+				'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache,
640
+			),
641
+			'EventEspresso\core\domain\values\EmailAddress'                                                               => array(
642
+				null,
643
+				'EventEspresso\core\domain\services\validation\email\EmailValidationService' => EE_Dependency_Map::load_from_cache,
644
+			),
645
+			'EventEspresso\core\services\orm\ModelFieldFactory'                                                           => array(
646
+				'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache,
647
+			),
648
+			'LEGACY_MODELS'                                                                                               => array(
649
+				null,
650
+				'EventEspresso\core\services\database\ModelFieldFactory' => EE_Dependency_Map::load_from_cache,
651
+			),
652
+			'EE_Module_Request_Router'                                                                                    => array(
653
+				'EE_Request' => EE_Dependency_Map::load_from_cache,
654
+			),
655
+			'EE_Registration_Processor'                                                                                   => array(
656
+				'EE_Request' => EE_Dependency_Map::load_from_cache,
657
+			),
658
+			'EventEspresso\core\services\notifications\PersistentAdminNoticeManager'                                      => array(
659
+				null,
660
+				'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache,
661
+				'EventEspresso\core\services\request\Request'                         => EE_Dependency_Map::load_from_cache,
662
+			),
663
+			'EventEspresso\core\services\licensing\LicenseService'                                                        => array(
664
+				'EventEspresso\core\domain\services\pue\Stats'  => EE_Dependency_Map::load_from_cache,
665
+				'EventEspresso\core\domain\services\pue\Config' => EE_Dependency_Map::load_from_cache,
666
+			),
667
+			'EE_Admin_Transactions_List_Table'                                                                            => array(
668
+				null,
669
+				'EventEspresso\core\domain\values\session\SessionLifespan' => EE_Dependency_Map::load_from_cache,
670
+			),
671
+			'EventEspresso\core\domain\services\pue\Stats'                                                                => array(
672
+				'EventEspresso\core\domain\services\pue\Config'        => EE_Dependency_Map::load_from_cache,
673
+				'EE_Maintenance_Mode'                                  => EE_Dependency_Map::load_from_cache,
674
+				'EventEspresso\core\domain\services\pue\StatsGatherer' => EE_Dependency_Map::load_from_cache,
675
+			),
676
+			'EventEspresso\core\domain\services\pue\Config'                                                               => array(
677
+				'EE_Network_Config' => EE_Dependency_Map::load_from_cache,
678
+				'EE_Config'         => EE_Dependency_Map::load_from_cache,
679
+			),
680
+			'EventEspresso\core\domain\services\pue\StatsGatherer'                                                        => array(
681
+				'EEM_Payment_Method' => EE_Dependency_Map::load_from_cache,
682
+				'EEM_Event'          => EE_Dependency_Map::load_from_cache,
683
+				'EEM_Datetime'       => EE_Dependency_Map::load_from_cache,
684
+				'EEM_Ticket'         => EE_Dependency_Map::load_from_cache,
685
+				'EEM_Registration'   => EE_Dependency_Map::load_from_cache,
686
+				'EEM_Transaction'    => EE_Dependency_Map::load_from_cache,
687
+				'EE_Config'          => EE_Dependency_Map::load_from_cache,
688
+			),
689
+			'EventEspresso\core\domain\services\admin\ExitModal'                                                          => array(
690
+				'EventEspresso\core\services\assets\Registry' => EE_Dependency_Map::load_from_cache,
691
+			),
692
+			'EventEspresso\core\domain\services\admin\PluginUpsells'                                                      => array(
693
+				'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache,
694
+			),
695
+			'EventEspresso\caffeinated\modules\recaptcha_invisible\InvisibleRecaptcha'                                    => array(
696
+				'EE_Registration_Config' => EE_Dependency_Map::load_from_cache,
697
+				'EE_Session'             => EE_Dependency_Map::load_from_cache,
698
+			),
699
+			'EventEspresso\caffeinated\modules\recaptcha_invisible\RecaptchaAdminSettings'                                => array(
700
+				'EE_Registration_Config' => EE_Dependency_Map::load_from_cache,
701
+			),
702
+			'EventEspresso\modules\ticket_selector\ProcessTicketSelector'                                                 => array(
703
+				'EE_Core_Config'                                                          => EE_Dependency_Map::load_from_cache,
704
+				'EventEspresso\core\services\request\Request'                             => EE_Dependency_Map::load_from_cache,
705
+				'EE_Session'                                                              => EE_Dependency_Map::load_from_cache,
706
+				'EEM_Ticket'                                                              => EE_Dependency_Map::load_from_cache,
707
+				'EventEspresso\modules\ticket_selector\TicketDatetimeAvailabilityTracker' => EE_Dependency_Map::load_from_cache,
708
+			),
709
+			'EventEspresso\modules\ticket_selector\TicketDatetimeAvailabilityTracker'                                     => array(
710
+				'EEM_Datetime' => EE_Dependency_Map::load_from_cache,
711
+			),
712
+			'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions'                              => array(
713
+				'EE_Core_Config'                             => EE_Dependency_Map::load_from_cache,
714
+				'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache,
715
+			),
716
+			'EventEspresso\core\domain\services\custom_post_types\RegisterCustomPostTypes'                                => array(
717
+				'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' => EE_Dependency_Map::load_from_cache,
718
+			),
719
+			'EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomies'                               => array(
720
+				'EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions' => EE_Dependency_Map::load_from_cache,
721
+			),
722
+			'EE_CPT_Strategy'                                                                                             => array(
723
+				'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' => EE_Dependency_Map::load_from_cache,
724
+				'EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions' => EE_Dependency_Map::load_from_cache,
725
+			),
726
+			'EventEspresso\core\services\loaders\ObjectIdentifier'                                                        => array(
727
+				'EventEspresso\core\services\loaders\ClassInterfaceCache' => EE_Dependency_Map::load_from_cache,
728
+			),
729
+			'EventEspresso\core\domain\services\assets\CoreAssetManager'                                                  => array(
730
+				'EventEspresso\core\services\assets\AssetCollection' => EE_Dependency_Map::load_from_cache,
731
+				'EE_Currency_Config'                                 => EE_Dependency_Map::load_from_cache,
732
+				'EE_Template_Config'                                 => EE_Dependency_Map::load_from_cache,
733
+				'EventEspresso\core\domain\Domain'                   => EE_Dependency_Map::load_from_cache,
734
+				'EventEspresso\core\services\assets\Registry'        => EE_Dependency_Map::load_from_cache,
735
+			),
736
+			'EventEspresso\core\domain\services\admin\privacy\policy\PrivacyPolicy' => array(
737
+				'EEM_Payment_Method' => EE_Dependency_Map::load_from_cache,
738
+				'EventEspresso\core\domain\values\session\SessionLifespan' => EE_Dependency_Map::load_from_cache
739
+			),
740
+			'EventEspresso\core\domain\services\admin\privacy\export\ExportAttendee' => array(
741
+				'EEM_Attendee' => EE_Dependency_Map::load_from_cache,
742
+			),
743
+			'EventEspresso\core\domain\services\admin\privacy\export\ExportAttendeeBillingData' => array(
744
+				'EEM_Attendee' => EE_Dependency_Map::load_from_cache,
745
+				'EEM_Payment_Method' => EE_Dependency_Map::load_from_cache
746
+			),
747
+			'EventEspresso\core\domain\services\admin\privacy\export\ExportCheckins' => array(
748
+				'EEM_Checkin' => EE_Dependency_Map::load_from_cache,
749
+			),
750
+			'EventEspresso\core\domain\services\admin\privacy\export\ExportRegistration' => array(
751
+				'EEM_Registration' => EE_Dependency_Map::load_from_cache,
752
+			),
753
+			'EventEspresso\core\domain\services\admin\privacy\export\ExportTransaction' => array(
754
+				'EEM_Transaction' => EE_Dependency_Map::load_from_cache,
755
+			),
756
+			'EventEspresso\core\domain\services\admin\privacy\erasure\EraseAttendeeData' => array(
757
+				'EEM_Attendee' => EE_Dependency_Map::load_from_cache,
758
+			),
759
+			'EventEspresso\core\domain\services\admin\privacy\erasure\EraseAnswers' => array(
760
+				'EEM_Answer' => EE_Dependency_Map::load_from_cache,
761
+				'EEM_Question' => EE_Dependency_Map::load_from_cache,
762
+			),
763
+			'EventEspresso\core\CPTs\CptQueryModifier' => array(
764
+				null,
765
+				null,
766
+				null,
767
+				'EE_Request_Handler'                          => EE_Dependency_Map::load_from_cache,
768
+				'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache,
769
+				'EventEspresso\core\services\loaders\Loader'  => EE_Dependency_Map::load_from_cache,
770
+			),
771
+			'EventEspresso\core\domain\services\admin\privacy\forms\PrivacySettingsFormHandler' => array(
772
+				'EE_Registry' => EE_Dependency_Map::load_from_cache,
773
+				'EE_Config' => EE_Dependency_Map::load_from_cache
774
+			),
775
+			'EventEspresso\core\services\editor\BlockRegistrationManager'                                                 => array(
776
+				'EventEspresso\core\services\assets\BlockAssetManagerCollection' => EE_Dependency_Map::load_from_cache,
777
+				'EventEspresso\core\domain\entities\editor\BlockCollection'      => EE_Dependency_Map::load_from_cache,
778
+				'EventEspresso\core\services\request\Request'                    => EE_Dependency_Map::load_from_cache,
779
+			),
780
+			'EventEspresso\core\domain\entities\editor\blocks\CoreBlocksAssetManager' => array(
781
+				'EventEspresso\core\domain\Domain'                   => EE_Dependency_Map::load_from_cache,
782
+				'EventEspresso\core\services\assets\AssetCollection' => EE_Dependency_Map::load_from_cache,
783
+				'EventEspresso\core\services\assets\Registry'        => EE_Dependency_Map::load_from_cache,
784
+			),
785
+			'EventEspresso\core\domain\entities\editor\blocks\widgets\EventAttendees' => array(
786
+				'EventEspresso\core\domain\entities\editor\blocks\CoreBlocksAssetManager' => self::load_from_cache,
787
+			),
788
+		);
789
+	}
790
+
791
+
792
+	/**
793
+	 * Registers how core classes are loaded.
794
+	 * This can either be done by simply providing the name of one of the EE_Registry loader methods such as:
795
+	 *        'EE_Request_Handler' => 'load_core'
796
+	 *        'EE_Messages_Queue'  => 'load_lib'
797
+	 *        'EEH_Debug_Tools'    => 'load_helper'
798
+	 * or, if greater control is required, by providing a custom closure. For example:
799
+	 *        'Some_Class' => function () {
800
+	 *            return new Some_Class();
801
+	 *        },
802
+	 * This is required for instantiating dependencies
803
+	 * where an interface has been type hinted in a class constructor. For example:
804
+	 *        'Required_Interface' => function () {
805
+	 *            return new A_Class_That_Implements_Required_Interface();
806
+	 *        },
807
+	 */
808
+	protected function _register_core_class_loaders()
809
+	{
810
+		// for PHP5.3 compat, we need to register any properties called here in a variable because `$this` cannot
811
+		// be used in a closure.
812
+		$request = &$this->request;
813
+		$response = &$this->response;
814
+		$legacy_request = &$this->legacy_request;
815
+		// $loader = &$this->loader;
816
+		$this->_class_loaders = array(
817
+			// load_core
818
+			'EE_Capabilities'                              => 'load_core',
819
+			'EE_Encryption'                                => 'load_core',
820
+			'EE_Front_Controller'                          => 'load_core',
821
+			'EE_Module_Request_Router'                     => 'load_core',
822
+			'EE_Registry'                                  => 'load_core',
823
+			'EE_Request'                                   => function () use (&$legacy_request) {
824
+				return $legacy_request;
825
+			},
826
+			'EventEspresso\core\services\request\Request'  => function () use (&$request) {
827
+				return $request;
828
+			},
829
+			'EventEspresso\core\services\request\Response' => function () use (&$response) {
830
+				return $response;
831
+			},
832
+			'EE_Base'                                      => 'load_core',
833
+			'EE_Request_Handler'                           => 'load_core',
834
+			'EE_Session'                                   => 'load_core',
835
+			'EE_Cron_Tasks'                                => 'load_core',
836
+			'EE_System'                                    => 'load_core',
837
+			'EE_Maintenance_Mode'                          => 'load_core',
838
+			'EE_Register_CPTs'                             => 'load_core',
839
+			'EE_Admin'                                     => 'load_core',
840
+			'EE_CPT_Strategy'                              => 'load_core',
841
+			// load_lib
842
+			'EE_Message_Resource_Manager'                  => 'load_lib',
843
+			'EE_Message_Type_Collection'                   => 'load_lib',
844
+			'EE_Message_Type_Collection_Loader'            => 'load_lib',
845
+			'EE_Messenger_Collection'                      => 'load_lib',
846
+			'EE_Messenger_Collection_Loader'               => 'load_lib',
847
+			'EE_Messages_Processor'                        => 'load_lib',
848
+			'EE_Message_Repository'                        => 'load_lib',
849
+			'EE_Messages_Queue'                            => 'load_lib',
850
+			'EE_Messages_Data_Handler_Collection'          => 'load_lib',
851
+			'EE_Message_Template_Group_Collection'         => 'load_lib',
852
+			'EE_Payment_Method_Manager'                    => 'load_lib',
853
+			'EE_Messages_Generator'                        => function () {
854
+				return EE_Registry::instance()->load_lib(
855
+					'Messages_Generator',
856
+					array(),
857
+					false,
858
+					false
859
+				);
860
+			},
861
+			'EE_Messages_Template_Defaults'                => function ($arguments = array()) {
862
+				return EE_Registry::instance()->load_lib(
863
+					'Messages_Template_Defaults',
864
+					$arguments,
865
+					false,
866
+					false
867
+				);
868
+			},
869
+			// load_helper
870
+			'EEH_Parse_Shortcodes'                         => function () {
871
+				if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) {
872
+					return new EEH_Parse_Shortcodes();
873
+				}
874
+				return null;
875
+			},
876
+			'EE_Template_Config'                           => function () {
877
+				return EE_Config::instance()->template_settings;
878
+			},
879
+			'EE_Currency_Config'                           => function () {
880
+				return EE_Config::instance()->currency;
881
+			},
882
+			'EE_Registration_Config'                       => function () {
883
+				return EE_Config::instance()->registration;
884
+			},
885
+			'EE_Core_Config'                               => function () {
886
+				return EE_Config::instance()->core;
887
+			},
888
+			'EventEspresso\core\services\loaders\Loader'   => function () {
889
+				return LoaderFactory::getLoader();
890
+			},
891
+			'EE_Network_Config'                            => function () {
892
+				return EE_Network_Config::instance();
893
+			},
894
+			'EE_Config'                                    => function () {
895
+				return EE_Config::instance();
896
+			},
897
+			'EventEspresso\core\domain\Domain'             => function () {
898
+				return DomainFactory::getEventEspressoCoreDomain();
899
+			},
900
+			'EE_Admin_Config'                              => function () {
901
+				return EE_Config::instance()->admin;
902
+			},
903
+		);
904
+	}
905
+
906
+
907
+	/**
908
+	 * can be used for supplying alternate names for classes,
909
+	 * or for connecting interface names to instantiable classes
910
+	 */
911
+	protected function _register_core_aliases()
912
+	{
913
+		$aliases = array(
914
+			'CommandBusInterface'                                                          => 'EventEspresso\core\services\commands\CommandBusInterface',
915
+			'EventEspresso\core\services\commands\CommandBusInterface'                     => 'EventEspresso\core\services\commands\CommandBus',
916
+			'CommandHandlerManagerInterface'                                               => 'EventEspresso\core\services\commands\CommandHandlerManagerInterface',
917
+			'EventEspresso\core\services\commands\CommandHandlerManagerInterface'          => 'EventEspresso\core\services\commands\CommandHandlerManager',
918
+			'CapChecker'                                                                   => 'EventEspresso\core\services\commands\middleware\CapChecker',
919
+			'AddActionHook'                                                                => 'EventEspresso\core\services\commands\middleware\AddActionHook',
920
+			'CapabilitiesChecker'                                                          => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker',
921
+			'CapabilitiesCheckerInterface'                                                 => 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface',
922
+			'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker',
923
+			'CreateRegistrationService'                                                    => 'EventEspresso\core\domain\services\registration\CreateRegistrationService',
924
+			'CreateRegistrationCommandHandler'                                             => 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand',
925
+			'CopyRegistrationDetailsCommandHandler'                                        => 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommand',
926
+			'CopyRegistrationPaymentsCommandHandler'                                       => 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommand',
927
+			'CancelRegistrationAndTicketLineItemCommandHandler'                            => 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler',
928
+			'UpdateRegistrationAndTransactionAfterChangeCommandHandler'                    => 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler',
929
+			'CreateTicketLineItemCommandHandler'                                           => 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommand',
930
+			'CreateTransactionCommandHandler'                                              => 'EventEspresso\core\services\commands\transaction\CreateTransactionCommandHandler',
931
+			'CreateAttendeeCommandHandler'                                                 => 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler',
932
+			'TableManager'                                                                 => 'EventEspresso\core\services\database\TableManager',
933
+			'TableAnalysis'                                                                => 'EventEspresso\core\services\database\TableAnalysis',
934
+			'EspressoShortcode'                                                            => 'EventEspresso\core\services\shortcodes\EspressoShortcode',
935
+			'ShortcodeInterface'                                                           => 'EventEspresso\core\services\shortcodes\ShortcodeInterface',
936
+			'EventEspresso\core\services\shortcodes\ShortcodeInterface'                    => 'EventEspresso\core\services\shortcodes\EspressoShortcode',
937
+			'EventEspresso\core\services\cache\CacheStorageInterface'                      => 'EventEspresso\core\services\cache\TransientCacheStorage',
938
+			'LoaderInterface'                                                              => 'EventEspresso\core\services\loaders\LoaderInterface',
939
+			'EventEspresso\core\services\loaders\LoaderInterface'                          => 'EventEspresso\core\services\loaders\Loader',
940
+			'CommandFactoryInterface'                                                      => 'EventEspresso\core\services\commands\CommandFactoryInterface',
941
+			'EventEspresso\core\services\commands\CommandFactoryInterface'                 => 'EventEspresso\core\services\commands\CommandFactory',
942
+			'EventEspresso\core\domain\services\session\SessionIdentifierInterface'        => 'EE_Session',
943
+			'EmailValidatorInterface'                                                      => 'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface',
944
+			'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface'  => 'EventEspresso\core\domain\services\validation\email\EmailValidationService',
945
+			'NoticeConverterInterface'                                                     => 'EventEspresso\core\services\notices\NoticeConverterInterface',
946
+			'EventEspresso\core\services\notices\NoticeConverterInterface'                 => 'EventEspresso\core\services\notices\ConvertNoticesToEeErrors',
947
+			'NoticesContainerInterface'                                                    => 'EventEspresso\core\services\notices\NoticesContainerInterface',
948
+			'EventEspresso\core\services\notices\NoticesContainerInterface'                => 'EventEspresso\core\services\notices\NoticesContainer',
949
+			'EventEspresso\core\services\request\RequestInterface'                         => 'EventEspresso\core\services\request\Request',
950
+			'EventEspresso\core\services\request\ResponseInterface'                        => 'EventEspresso\core\services\request\Response',
951
+			'EventEspresso\core\domain\DomainInterface'                                    => 'EventEspresso\core\domain\Domain',
952
+		);
953
+		foreach ($aliases as $alias => $fqn) {
954
+			if (is_array($fqn)) {
955
+				foreach ($fqn as $class => $for_class) {
956
+					$this->class_cache->addAlias($class, $alias, $for_class);
957
+				}
958
+				continue;
959
+			}
960
+			$this->class_cache->addAlias($fqn, $alias);
961
+		}
962
+		if (! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) {
963
+			$this->class_cache->addAlias(
964
+				'EventEspresso\core\services\notices\ConvertNoticesToAdminNotices',
965
+				'EventEspresso\core\services\notices\NoticeConverterInterface'
966
+			);
967
+		}
968
+	}
969
+
970
+
971
+	/**
972
+	 * This is used to reset the internal map and class_loaders to their original default state at the beginning of the
973
+	 * request Primarily used by unit tests.
974
+	 */
975
+	public function reset()
976
+	{
977
+		$this->_register_core_class_loaders();
978
+		$this->_register_core_dependencies();
979
+	}
980
+
981
+
982
+	/**
983
+	 * PLZ NOTE: a better name for this method would be is_alias()
984
+	 * because it returns TRUE if the provided fully qualified name IS an alias
985
+	 * WHY?
986
+	 * Because if a class is type hinting for a concretion,
987
+	 * then why would we need to find another class to supply it?
988
+	 * ie: if a class asks for `Fully/Qualified/Namespace/SpecificClassName`,
989
+	 * then give it an instance of `Fully/Qualified/Namespace/SpecificClassName`.
990
+	 * Don't go looking for some substitute.
991
+	 * Whereas if a class is type hinting for an interface...
992
+	 * then we need to find an actual class to use.
993
+	 * So the interface IS the alias for some other FQN,
994
+	 * and we need to find out if `Fully/Qualified/Namespace/SomeInterface`
995
+	 * represents some other class.
996
+	 *
997
+	 * @deprecated 4.9.62.p
998
+	 * @param string $fqn
999
+	 * @param string $for_class
1000
+	 * @return bool
1001
+	 */
1002
+	public function has_alias($fqn = '', $for_class = '')
1003
+	{
1004
+		return $this->isAlias($fqn, $for_class);
1005
+	}
1006
+
1007
+
1008
+	/**
1009
+	 * PLZ NOTE: a better name for this method would be get_fqn_for_alias()
1010
+	 * because it returns a FQN for provided alias if one exists, otherwise returns the original $alias
1011
+	 * functions recursively, so that multiple aliases can be used to drill down to a FQN
1012
+	 *  for example:
1013
+	 *      if the following two entries were added to the _aliases array:
1014
+	 *          array(
1015
+	 *              'interface_alias'           => 'some\namespace\interface'
1016
+	 *              'some\namespace\interface'  => 'some\namespace\classname'
1017
+	 *          )
1018
+	 *      then one could use EE_Registry::instance()->create( 'interface_alias' )
1019
+	 *      to load an instance of 'some\namespace\classname'
1020
+	 *
1021
+	 * @deprecated 4.9.62.p
1022
+	 * @param string $alias
1023
+	 * @param string $for_class
1024
+	 * @return string
1025
+	 */
1026
+	public function get_alias($alias = '', $for_class = '')
1027
+	{
1028
+		return $this->getFqnForAlias($alias, $for_class);
1029
+	}
1030 1030
 }
Please login to merge, or discard this patch.