@@ -20,8 +20,8 @@ |
||
| 20 | 20 | * Very simple mimic of mb_substr (which WP ensures exists in wp-includes/compat.php). Still has all the problems of mb_substr |
| 21 | 21 | * (namely, that we might send too many characters to PayPal; however in this case they just issue a warning but nothing breaks) |
| 22 | 22 | * @param $string |
| 23 | - * @param $start |
|
| 24 | - * @param $length |
|
| 23 | + * @param integer $start |
|
| 24 | + * @param integer $length |
|
| 25 | 25 | * @return bool|string |
| 26 | 26 | */ |
| 27 | 27 | function mb_strcut($string, $start, $length = null) |
@@ -10,7 +10,7 @@ discard block |
||
| 10 | 10 | * ---------------------------------------------- |
| 11 | 11 | */ |
| 12 | 12 | // Quickfix to address https://events.codebasehq.com/projects/event-espresso/tickets/11089 ASAP |
| 13 | -if (! function_exists('mb_strcut')) { |
|
| 13 | +if ( ! function_exists('mb_strcut')) { |
|
| 14 | 14 | /** |
| 15 | 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 | 16 | * (namely, that we might send too many characters to PayPal; however in this case they just issue a warning but nothing breaks) |
@@ -141,7 +141,7 @@ discard block |
||
| 141 | 141 | $notify_url = null, |
| 142 | 142 | $cancel_url = null |
| 143 | 143 | ) { |
| 144 | - if (! $payment instanceof EEI_Payment) { |
|
| 144 | + if ( ! $payment instanceof EEI_Payment) { |
|
| 145 | 145 | $payment->set_gateway_response( |
| 146 | 146 | esc_html__( |
| 147 | 147 | 'Error. No associated payment was found.', |
@@ -152,7 +152,7 @@ discard block |
||
| 152 | 152 | return $payment; |
| 153 | 153 | } |
| 154 | 154 | $transaction = $payment->transaction(); |
| 155 | - if (! $transaction instanceof EEI_Transaction) { |
|
| 155 | + if ( ! $transaction instanceof EEI_Transaction) { |
|
| 156 | 156 | $payment->set_gateway_response( |
| 157 | 157 | esc_html__( |
| 158 | 158 | 'Could not process this payment because it has no associated transaction.', |
@@ -199,13 +199,13 @@ discard block |
||
| 199 | 199 | $token_request_dtls['PAYMENTREQUEST_0_SHIPTOZIP'] = $primary_attendee->zip(); |
| 200 | 200 | $token_request_dtls['PAYMENTREQUEST_0_EMAIL'] = $primary_attendee->email(); |
| 201 | 201 | $token_request_dtls['PAYMENTREQUEST_0_SHIPTOPHONENUM'] = $primary_attendee->phone(); |
| 202 | - } elseif (! $this->_request_shipping_addr) { |
|
| 202 | + } elseif ( ! $this->_request_shipping_addr) { |
|
| 203 | 203 | // Do not request shipping details on the PP Checkout page. |
| 204 | 204 | $token_request_dtls['NOSHIPPING'] = '1'; |
| 205 | 205 | $token_request_dtls['REQCONFIRMSHIPPING'] = '0'; |
| 206 | 206 | } |
| 207 | 207 | // Used a business/personal logo on the PayPal page. |
| 208 | - if (! empty($this->_image_url)) { |
|
| 208 | + if ( ! empty($this->_image_url)) { |
|
| 209 | 209 | $token_request_dtls['LOGOIMG'] = $this->_image_url; |
| 210 | 210 | } |
| 211 | 211 | $token_request_dtls = apply_filters( |
@@ -230,7 +230,7 @@ discard block |
||
| 230 | 230 | ); |
| 231 | 231 | } else { |
| 232 | 232 | if (isset($response_args['L_ERRORCODE'])) { |
| 233 | - $payment->set_gateway_response($response_args['L_ERRORCODE'] . '; ' . $response_args['L_SHORTMESSAGE']); |
|
| 233 | + $payment->set_gateway_response($response_args['L_ERRORCODE'].'; '.$response_args['L_SHORTMESSAGE']); |
|
| 234 | 234 | } else { |
| 235 | 235 | $payment->set_gateway_response( |
| 236 | 236 | esc_html__( |
@@ -261,7 +261,7 @@ discard block |
||
| 261 | 261 | if ($payment instanceof EEI_Payment) { |
| 262 | 262 | $this->log(array('Return from Authorization' => $update_info), $payment); |
| 263 | 263 | $transaction = $payment->transaction(); |
| 264 | - if (! $transaction instanceof EEI_Transaction) { |
|
| 264 | + if ( ! $transaction instanceof EEI_Transaction) { |
|
| 265 | 265 | $payment->set_gateway_response( |
| 266 | 266 | esc_html__( |
| 267 | 267 | 'Could not process this payment because it has no associated transaction.', |
@@ -274,7 +274,7 @@ discard block |
||
| 274 | 274 | $primary_registrant = $transaction->primary_registration(); |
| 275 | 275 | $payment_details = $payment->details(); |
| 276 | 276 | // Check if we still have the token. |
| 277 | - if (! isset($payment_details['TOKEN']) || empty($payment_details['TOKEN'])) { |
|
| 277 | + if ( ! isset($payment_details['TOKEN']) || empty($payment_details['TOKEN'])) { |
|
| 278 | 278 | $payment->set_status($this->_pay_model->failed_status()); |
| 279 | 279 | return $payment; |
| 280 | 280 | } |
@@ -399,7 +399,7 @@ discard block |
||
| 399 | 399 | $itemized_list = array(); |
| 400 | 400 | $gateway_formatter = $this->_get_gateway_formatter(); |
| 401 | 401 | // If we have data from a previous communication with PP (on this transaction) we may use that for our list... |
| 402 | - if (! empty($request_response_args) |
|
| 402 | + if ( ! empty($request_response_args) |
|
| 403 | 403 | && array_key_exists('L_PAYMENTREQUEST_0_AMT0', $request_response_args) |
| 404 | 404 | && array_key_exists('PAYMENTREQUEST_0_ITEMAMT', $request_response_args) |
| 405 | 405 | ) { |
@@ -407,7 +407,7 @@ discard block |
||
| 407 | 407 | if (strpos($arg_key, 'PAYMENTREQUEST_') !== false |
| 408 | 408 | && strpos($arg_key, 'NOTIFYURL') === false |
| 409 | 409 | ) { |
| 410 | - $itemized_list[ $arg_key ] = $arg_val; |
|
| 410 | + $itemized_list[$arg_key] = $arg_val; |
|
| 411 | 411 | } |
| 412 | 412 | } |
| 413 | 413 | // If we got only a few Items then something is not right. |
@@ -460,25 +460,25 @@ discard block |
||
| 460 | 460 | $line_item_quantity = 1; |
| 461 | 461 | } |
| 462 | 462 | // Item Name. |
| 463 | - $itemized_list[ 'L_PAYMENTREQUEST_0_NAME' . $item_num ] = mb_strcut( |
|
| 463 | + $itemized_list['L_PAYMENTREQUEST_0_NAME'.$item_num] = mb_strcut( |
|
| 464 | 464 | $gateway_formatter->formatLineItemName($line_item, $payment), |
| 465 | 465 | 0, |
| 466 | 466 | 127 |
| 467 | 467 | ); |
| 468 | 468 | // Item description. |
| 469 | - $itemized_list[ 'L_PAYMENTREQUEST_0_DESC' . $item_num ] = mb_strcut( |
|
| 469 | + $itemized_list['L_PAYMENTREQUEST_0_DESC'.$item_num] = mb_strcut( |
|
| 470 | 470 | $gateway_formatter->formatLineItemDesc($line_item, $payment), |
| 471 | 471 | 0, |
| 472 | 472 | 127 |
| 473 | 473 | ); |
| 474 | 474 | // Cost of individual item. |
| 475 | - $itemized_list[ 'L_PAYMENTREQUEST_0_AMT' . $item_num ] = $gateway_formatter->formatCurrency($unit_price); |
|
| 475 | + $itemized_list['L_PAYMENTREQUEST_0_AMT'.$item_num] = $gateway_formatter->formatCurrency($unit_price); |
|
| 476 | 476 | // Item Number. |
| 477 | - $itemized_list[ 'L_PAYMENTREQUEST_0_NUMBER' . $item_num ] = $item_num + 1; |
|
| 477 | + $itemized_list['L_PAYMENTREQUEST_0_NUMBER'.$item_num] = $item_num + 1; |
|
| 478 | 478 | // Item quantity. |
| 479 | - $itemized_list[ 'L_PAYMENTREQUEST_0_QTY' . $item_num ] = $line_item_quantity; |
|
| 479 | + $itemized_list['L_PAYMENTREQUEST_0_QTY'.$item_num] = $line_item_quantity; |
|
| 480 | 480 | // Digital item is sold. |
| 481 | - $itemized_list[ 'L_PAYMENTREQUEST_0_ITEMCATEGORY' . $item_num ] = 'Physical'; |
|
| 481 | + $itemized_list['L_PAYMENTREQUEST_0_ITEMCATEGORY'.$item_num] = 'Physical'; |
|
| 482 | 482 | $itemized_sum += $line_item->total(); |
| 483 | 483 | ++$item_num; |
| 484 | 484 | } |
@@ -496,7 +496,7 @@ discard block |
||
| 496 | 496 | // add the difference as an extra line item. |
| 497 | 497 | if ($this->_money->compare_floats($itemized_sum_diff_from_txn_total, 0, '!=')) { |
| 498 | 498 | // Item Name. |
| 499 | - $itemized_list[ 'L_PAYMENTREQUEST_0_NAME' . $item_num ] = mb_strcut( |
|
| 499 | + $itemized_list['L_PAYMENTREQUEST_0_NAME'.$item_num] = mb_strcut( |
|
| 500 | 500 | esc_html__( |
| 501 | 501 | 'Other (promotion/surcharge/cancellation)', |
| 502 | 502 | 'event_espresso' |
@@ -505,17 +505,17 @@ discard block |
||
| 505 | 505 | 127 |
| 506 | 506 | ); |
| 507 | 507 | // Item description. |
| 508 | - $itemized_list[ 'L_PAYMENTREQUEST_0_DESC' . $item_num ] = ''; |
|
| 508 | + $itemized_list['L_PAYMENTREQUEST_0_DESC'.$item_num] = ''; |
|
| 509 | 509 | // Cost of individual item. |
| 510 | - $itemized_list[ 'L_PAYMENTREQUEST_0_AMT' . $item_num ] = $gateway_formatter->formatCurrency( |
|
| 510 | + $itemized_list['L_PAYMENTREQUEST_0_AMT'.$item_num] = $gateway_formatter->formatCurrency( |
|
| 511 | 511 | $itemized_sum_diff_from_txn_total |
| 512 | 512 | ); |
| 513 | 513 | // Item Number. |
| 514 | - $itemized_list[ 'L_PAYMENTREQUEST_0_NUMBER' . $item_num ] = $item_num + 1; |
|
| 514 | + $itemized_list['L_PAYMENTREQUEST_0_NUMBER'.$item_num] = $item_num + 1; |
|
| 515 | 515 | // Item quantity. |
| 516 | - $itemized_list[ 'L_PAYMENTREQUEST_0_QTY' . $item_num ] = 1; |
|
| 516 | + $itemized_list['L_PAYMENTREQUEST_0_QTY'.$item_num] = 1; |
|
| 517 | 517 | // Digital item is sold. |
| 518 | - $itemized_list[ 'L_PAYMENTREQUEST_0_ITEMCATEGORY' . $item_num ] = 'Physical'; |
|
| 518 | + $itemized_list['L_PAYMENTREQUEST_0_ITEMCATEGORY'.$item_num] = 'Physical'; |
|
| 519 | 519 | $item_num++; |
| 520 | 520 | } |
| 521 | 521 | } else { |
@@ -570,7 +570,7 @@ discard block |
||
| 570 | 570 | 'BUTTONSOURCE' => 'EventEspresso_SP', |
| 571 | 571 | ); |
| 572 | 572 | $dtls = array_merge($request_dtls, $request_params); |
| 573 | - $this->_log_clean_request($dtls, $payment, $request_text . ' Request'); |
|
| 573 | + $this->_log_clean_request($dtls, $payment, $request_text.' Request'); |
|
| 574 | 574 | // Request Customer Details. |
| 575 | 575 | $request_response = wp_remote_post( |
| 576 | 576 | $this->_base_gateway_url, |
@@ -584,7 +584,7 @@ discard block |
||
| 584 | 584 | ) |
| 585 | 585 | ); |
| 586 | 586 | // Log the response. |
| 587 | - $this->log(array($request_text . ' Response' => $request_response), $payment); |
|
| 587 | + $this->log(array($request_text.' Response' => $request_response), $payment); |
|
| 588 | 588 | return $request_response; |
| 589 | 589 | } |
| 590 | 590 | |
@@ -604,7 +604,7 @@ discard block |
||
| 604 | 604 | } |
| 605 | 605 | $response_args = array(); |
| 606 | 606 | parse_str(urldecode($request_response['body']), $response_args); |
| 607 | - if (! isset($response_args['ACK'])) { |
|
| 607 | + if ( ! isset($response_args['ACK'])) { |
|
| 608 | 608 | return array('status' => false, 'args' => $request_response); |
| 609 | 609 | } |
| 610 | 610 | if (( |
@@ -651,18 +651,18 @@ discard block |
||
| 651 | 651 | { |
| 652 | 652 | $errors = array(); |
| 653 | 653 | $n = 0; |
| 654 | - while (isset($data_array[ "L_ERRORCODE{$n}" ])) { |
|
| 655 | - $l_error_code = isset($data_array[ "L_ERRORCODE{$n}" ]) |
|
| 656 | - ? $data_array[ "L_ERRORCODE{$n}" ] |
|
| 654 | + while (isset($data_array["L_ERRORCODE{$n}"])) { |
|
| 655 | + $l_error_code = isset($data_array["L_ERRORCODE{$n}"]) |
|
| 656 | + ? $data_array["L_ERRORCODE{$n}"] |
|
| 657 | 657 | : ''; |
| 658 | - $l_severity_code = isset($data_array[ "L_SEVERITYCODE{$n}" ]) |
|
| 659 | - ? $data_array[ "L_SEVERITYCODE{$n}" ] |
|
| 658 | + $l_severity_code = isset($data_array["L_SEVERITYCODE{$n}"]) |
|
| 659 | + ? $data_array["L_SEVERITYCODE{$n}"] |
|
| 660 | 660 | : ''; |
| 661 | - $l_short_message = isset($data_array[ "L_SHORTMESSAGE{$n}" ]) |
|
| 662 | - ? $data_array[ "L_SHORTMESSAGE{$n}" ] |
|
| 661 | + $l_short_message = isset($data_array["L_SHORTMESSAGE{$n}"]) |
|
| 662 | + ? $data_array["L_SHORTMESSAGE{$n}"] |
|
| 663 | 663 | : ''; |
| 664 | - $l_long_message = isset($data_array[ "L_LONGMESSAGE{$n}" ]) |
|
| 665 | - ? $data_array[ "L_LONGMESSAGE{$n}" ] |
|
| 664 | + $l_long_message = isset($data_array["L_LONGMESSAGE{$n}"]) |
|
| 665 | + ? $data_array["L_LONGMESSAGE{$n}"] |
|
| 666 | 666 | : ''; |
| 667 | 667 | if ($n === 0) { |
| 668 | 668 | $errors = array( |
@@ -672,10 +672,10 @@ discard block |
||
| 672 | 672 | 'L_SEVERITYCODE' => $l_severity_code, |
| 673 | 673 | ); |
| 674 | 674 | } else { |
| 675 | - $errors['L_ERRORCODE'] .= ', ' . $l_error_code; |
|
| 676 | - $errors['L_SHORTMESSAGE'] .= ', ' . $l_short_message; |
|
| 677 | - $errors['L_LONGMESSAGE'] .= ', ' . $l_long_message; |
|
| 678 | - $errors['L_SEVERITYCODE'] .= ', ' . $l_severity_code; |
|
| 675 | + $errors['L_ERRORCODE'] .= ', '.$l_error_code; |
|
| 676 | + $errors['L_SHORTMESSAGE'] .= ', '.$l_short_message; |
|
| 677 | + $errors['L_LONGMESSAGE'] .= ', '.$l_long_message; |
|
| 678 | + $errors['L_SEVERITYCODE'] .= ', '.$l_severity_code; |
|
| 679 | 679 | } |
| 680 | 680 | $n++; |
| 681 | 681 | } |
@@ -11,674 +11,674 @@ |
||
| 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 | - // Locale of the pages displayed by PayPal during Express Checkout. |
|
| 185 | - 'LOCALECODE' => $locale[1] |
|
| 186 | - ); |
|
| 187 | - // Show itemized list. |
|
| 188 | - $itemized_list = $this->itemize_list($payment, $transaction); |
|
| 189 | - $token_request_dtls = array_merge($token_request_dtls, $itemized_list); |
|
| 190 | - // Automatically filling out shipping and contact information. |
|
| 191 | - if ($this->_request_shipping_addr && $primary_attendee instanceof EEI_Attendee) { |
|
| 192 | - // If you do not pass the shipping address, PayPal obtains it from the buyer's account profile. |
|
| 193 | - $token_request_dtls['NOSHIPPING'] = '2'; |
|
| 194 | - $token_request_dtls['PAYMENTREQUEST_0_SHIPTOSTREET'] = $primary_attendee->address(); |
|
| 195 | - $token_request_dtls['PAYMENTREQUEST_0_SHIPTOSTREET2'] = $primary_attendee->address2(); |
|
| 196 | - $token_request_dtls['PAYMENTREQUEST_0_SHIPTOCITY'] = $primary_attendee->city(); |
|
| 197 | - $token_request_dtls['PAYMENTREQUEST_0_SHIPTOSTATE'] = $primary_attendee->state_abbrev(); |
|
| 198 | - $token_request_dtls['PAYMENTREQUEST_0_SHIPTOCOUNTRYCODE'] = $primary_attendee->country_ID(); |
|
| 199 | - $token_request_dtls['PAYMENTREQUEST_0_SHIPTOZIP'] = $primary_attendee->zip(); |
|
| 200 | - $token_request_dtls['PAYMENTREQUEST_0_EMAIL'] = $primary_attendee->email(); |
|
| 201 | - $token_request_dtls['PAYMENTREQUEST_0_SHIPTOPHONENUM'] = $primary_attendee->phone(); |
|
| 202 | - } elseif (! $this->_request_shipping_addr) { |
|
| 203 | - // Do not request shipping details on the PP Checkout page. |
|
| 204 | - $token_request_dtls['NOSHIPPING'] = '1'; |
|
| 205 | - $token_request_dtls['REQCONFIRMSHIPPING'] = '0'; |
|
| 206 | - } |
|
| 207 | - // Used a business/personal logo on the PayPal page. |
|
| 208 | - if (! empty($this->_image_url)) { |
|
| 209 | - $token_request_dtls['LOGOIMG'] = $this->_image_url; |
|
| 210 | - } |
|
| 211 | - $token_request_dtls = apply_filters( |
|
| 212 | - 'FHEE__EEG_Paypal_Express__set_redirection_info__arguments', |
|
| 213 | - $token_request_dtls, |
|
| 214 | - $this |
|
| 215 | - ); |
|
| 216 | - // Request PayPal token. |
|
| 217 | - $token_request_response = $this->_ppExpress_request($token_request_dtls, 'Payment Token', $payment); |
|
| 218 | - $token_rstatus = $this->_ppExpress_check_response($token_request_response); |
|
| 219 | - $response_args = (isset($token_rstatus['args']) && is_array($token_rstatus['args'])) |
|
| 220 | - ? $token_rstatus['args'] |
|
| 221 | - : array(); |
|
| 222 | - if ($token_rstatus['status']) { |
|
| 223 | - // We got the Token so we may continue with the payment and redirect the client. |
|
| 224 | - $payment->set_details($response_args); |
|
| 225 | - $gateway_url = $this->_debug_mode ? 'https://www.sandbox.paypal.com' : 'https://www.paypal.com'; |
|
| 226 | - $payment->set_redirect_url( |
|
| 227 | - $gateway_url |
|
| 228 | - . '/checkoutnow?useraction=commit&cmd=_express-checkout&token=' |
|
| 229 | - . $response_args['TOKEN'] |
|
| 230 | - ); |
|
| 231 | - } else { |
|
| 232 | - if (isset($response_args['L_ERRORCODE'])) { |
|
| 233 | - $payment->set_gateway_response($response_args['L_ERRORCODE'] . '; ' . $response_args['L_SHORTMESSAGE']); |
|
| 234 | - } else { |
|
| 235 | - $payment->set_gateway_response( |
|
| 236 | - esc_html__( |
|
| 237 | - 'Error occurred while trying to setup the Express Checkout.', |
|
| 238 | - 'event_espresso' |
|
| 239 | - ) |
|
| 240 | - ); |
|
| 241 | - } |
|
| 242 | - $payment->set_details($response_args); |
|
| 243 | - $payment->set_status($this->_pay_model->failed_status()); |
|
| 244 | - } |
|
| 245 | - return $payment; |
|
| 246 | - } |
|
| 247 | - |
|
| 248 | - |
|
| 249 | - |
|
| 250 | - /** |
|
| 251 | - * @param array $update_info { |
|
| 252 | - * @type string $gateway_txn_id |
|
| 253 | - * @type string status an EEMI_Payment status |
|
| 254 | - * } |
|
| 255 | - * @param EEI_Transaction $transaction |
|
| 256 | - * @return EEI_Payment |
|
| 257 | - */ |
|
| 258 | - public function handle_payment_update($update_info, $transaction) |
|
| 259 | - { |
|
| 260 | - $payment = $transaction instanceof EEI_Transaction ? $transaction->last_payment() : null; |
|
| 261 | - if ($payment instanceof EEI_Payment) { |
|
| 262 | - $this->log(array('Return from Authorization' => $update_info), $payment); |
|
| 263 | - $transaction = $payment->transaction(); |
|
| 264 | - if (! $transaction instanceof EEI_Transaction) { |
|
| 265 | - $payment->set_gateway_response( |
|
| 266 | - esc_html__( |
|
| 267 | - 'Could not process this payment because it has no associated transaction.', |
|
| 268 | - 'event_espresso' |
|
| 269 | - ) |
|
| 270 | - ); |
|
| 271 | - $payment->set_status($this->_pay_model->failed_status()); |
|
| 272 | - return $payment; |
|
| 273 | - } |
|
| 274 | - $primary_registrant = $transaction->primary_registration(); |
|
| 275 | - $payment_details = $payment->details(); |
|
| 276 | - // Check if we still have the token. |
|
| 277 | - if (! isset($payment_details['TOKEN']) || empty($payment_details['TOKEN'])) { |
|
| 278 | - $payment->set_status($this->_pay_model->failed_status()); |
|
| 279 | - return $payment; |
|
| 280 | - } |
|
| 281 | - $cdetails_request_dtls = array( |
|
| 282 | - 'METHOD' => 'GetExpressCheckoutDetails', |
|
| 283 | - 'TOKEN' => $payment_details['TOKEN'], |
|
| 284 | - ); |
|
| 285 | - // Request Customer Details. |
|
| 286 | - $cdetails_request_response = $this->_ppExpress_request( |
|
| 287 | - $cdetails_request_dtls, |
|
| 288 | - 'Customer Details', |
|
| 289 | - $payment |
|
| 290 | - ); |
|
| 291 | - $cdetails_rstatus = $this->_ppExpress_check_response($cdetails_request_response); |
|
| 292 | - $cdata_response_args = (isset($cdetails_rstatus['args']) && is_array($cdetails_rstatus['args'])) |
|
| 293 | - ? $cdetails_rstatus['args'] |
|
| 294 | - : array(); |
|
| 295 | - if ($cdetails_rstatus['status']) { |
|
| 296 | - // We got the PayerID so now we can Complete the transaction. |
|
| 297 | - $docheckout_request_dtls = array( |
|
| 298 | - 'METHOD' => 'DoExpressCheckoutPayment', |
|
| 299 | - 'PAYERID' => $cdata_response_args['PAYERID'], |
|
| 300 | - 'TOKEN' => $payment_details['TOKEN'], |
|
| 301 | - 'PAYMENTREQUEST_0_PAYMENTACTION' => 'Sale', |
|
| 302 | - 'PAYMENTREQUEST_0_AMT' => $payment->amount(), |
|
| 303 | - 'PAYMENTREQUEST_0_CURRENCYCODE' => $payment->currency_code(), |
|
| 304 | - ); |
|
| 305 | - // Include itemized list. |
|
| 306 | - $itemized_list = $this->itemize_list( |
|
| 307 | - $payment, |
|
| 308 | - $transaction, |
|
| 309 | - $cdata_response_args |
|
| 310 | - ); |
|
| 311 | - $docheckout_request_dtls = array_merge($docheckout_request_dtls, $itemized_list); |
|
| 312 | - // Payment Checkout/Capture. |
|
| 313 | - $docheckout_request_response = $this->_ppExpress_request( |
|
| 314 | - $docheckout_request_dtls, |
|
| 315 | - 'Do Payment', |
|
| 316 | - $payment |
|
| 317 | - ); |
|
| 318 | - $docheckout_rstatus = $this->_ppExpress_check_response($docheckout_request_response); |
|
| 319 | - $docheckout_response_args = (isset($docheckout_rstatus['args']) && is_array($docheckout_rstatus['args'])) |
|
| 320 | - ? $docheckout_rstatus['args'] |
|
| 321 | - : array(); |
|
| 322 | - if ($docheckout_rstatus['status']) { |
|
| 323 | - // All is well, payment approved. |
|
| 324 | - $primary_registration_code = $primary_registrant instanceof EE_Registration ? |
|
| 325 | - $primary_registrant->reg_code() |
|
| 326 | - : ''; |
|
| 327 | - $payment->set_extra_accntng($primary_registration_code); |
|
| 328 | - $payment->set_amount(isset($docheckout_response_args['PAYMENTINFO_0_AMT']) |
|
| 329 | - ? (float) $docheckout_response_args['PAYMENTINFO_0_AMT'] |
|
| 330 | - : 0); |
|
| 331 | - $payment->set_txn_id_chq_nmbr(isset($docheckout_response_args['PAYMENTINFO_0_TRANSACTIONID']) |
|
| 332 | - ? $docheckout_response_args['PAYMENTINFO_0_TRANSACTIONID'] |
|
| 333 | - : null); |
|
| 334 | - $payment->set_details($cdata_response_args); |
|
| 335 | - $payment->set_gateway_response(isset($docheckout_response_args['PAYMENTINFO_0_ACK']) |
|
| 336 | - ? $docheckout_response_args['PAYMENTINFO_0_ACK'] |
|
| 337 | - : ''); |
|
| 338 | - $payment->set_status($this->_pay_model->approved_status()); |
|
| 339 | - } else { |
|
| 340 | - if (isset($docheckout_response_args['L_ERRORCODE'])) { |
|
| 341 | - $payment->set_gateway_response( |
|
| 342 | - $docheckout_response_args['L_ERRORCODE'] |
|
| 343 | - . '; ' |
|
| 344 | - . $docheckout_response_args['L_SHORTMESSAGE'] |
|
| 345 | - ); |
|
| 346 | - } else { |
|
| 347 | - $payment->set_gateway_response( |
|
| 348 | - esc_html__( |
|
| 349 | - 'Error occurred while trying to Capture the funds.', |
|
| 350 | - 'event_espresso' |
|
| 351 | - ) |
|
| 352 | - ); |
|
| 353 | - } |
|
| 354 | - $payment->set_details($docheckout_response_args); |
|
| 355 | - $payment->set_status($this->_pay_model->declined_status()); |
|
| 356 | - } |
|
| 357 | - } else { |
|
| 358 | - if (isset($cdata_response_args['L_ERRORCODE'])) { |
|
| 359 | - $payment->set_gateway_response( |
|
| 360 | - $cdata_response_args['L_ERRORCODE'] |
|
| 361 | - . '; ' |
|
| 362 | - . $cdata_response_args['L_SHORTMESSAGE'] |
|
| 363 | - ); |
|
| 364 | - } else { |
|
| 365 | - $payment->set_gateway_response( |
|
| 366 | - esc_html__( |
|
| 367 | - 'Error occurred while trying to get payment Details from PayPal.', |
|
| 368 | - 'event_espresso' |
|
| 369 | - ) |
|
| 370 | - ); |
|
| 371 | - } |
|
| 372 | - $payment->set_details($cdata_response_args); |
|
| 373 | - $payment->set_status($this->_pay_model->failed_status()); |
|
| 374 | - } |
|
| 375 | - } else { |
|
| 376 | - $payment->set_gateway_response( |
|
| 377 | - esc_html__( |
|
| 378 | - 'Error occurred while trying to process the payment.', |
|
| 379 | - 'event_espresso' |
|
| 380 | - ) |
|
| 381 | - ); |
|
| 382 | - $payment->set_status($this->_pay_model->failed_status()); |
|
| 383 | - } |
|
| 384 | - return $payment; |
|
| 385 | - } |
|
| 386 | - |
|
| 387 | - |
|
| 388 | - |
|
| 389 | - /** |
|
| 390 | - * Make a list of items that are in the giver transaction. |
|
| 391 | - * |
|
| 392 | - * @param EEI_Payment $payment |
|
| 393 | - * @param EEI_Transaction $transaction |
|
| 394 | - * @param array $request_response_args Data from a previous communication with PP. |
|
| 395 | - * @return array |
|
| 396 | - */ |
|
| 397 | - public function itemize_list(EEI_Payment $payment, EEI_Transaction $transaction, $request_response_args = array()) |
|
| 398 | - { |
|
| 399 | - $itemized_list = array(); |
|
| 400 | - $gateway_formatter = $this->_get_gateway_formatter(); |
|
| 401 | - // If we have data from a previous communication with PP (on this transaction) we may use that for our list... |
|
| 402 | - if (! empty($request_response_args) |
|
| 403 | - && array_key_exists('L_PAYMENTREQUEST_0_AMT0', $request_response_args) |
|
| 404 | - && array_key_exists('PAYMENTREQUEST_0_ITEMAMT', $request_response_args) |
|
| 405 | - ) { |
|
| 406 | - foreach ($request_response_args as $arg_key => $arg_val) { |
|
| 407 | - if (strpos($arg_key, 'PAYMENTREQUEST_') !== false |
|
| 408 | - && strpos($arg_key, 'NOTIFYURL') === false |
|
| 409 | - ) { |
|
| 410 | - $itemized_list[ $arg_key ] = $arg_val; |
|
| 411 | - } |
|
| 412 | - } |
|
| 413 | - // If we got only a few Items then something is not right. |
|
| 414 | - if (count($itemized_list) > 2) { |
|
| 415 | - return $itemized_list; |
|
| 416 | - } else { |
|
| 417 | - if (WP_DEBUG) { |
|
| 418 | - throw new EE_Error( |
|
| 419 | - sprintf( |
|
| 420 | - esc_html__( |
|
| 421 | - // @codingStandardsIgnoreStart |
|
| 422 | - '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', |
|
| 423 | - // @codingStandardsIgnoreEnd |
|
| 424 | - 'event_espresso' |
|
| 425 | - ), |
|
| 426 | - wp_json_encode($itemized_list) |
|
| 427 | - ) |
|
| 428 | - ); |
|
| 429 | - } |
|
| 430 | - // Reset the list and log an error, maybe allow to try and generate a new list (below). |
|
| 431 | - $itemized_list = array(); |
|
| 432 | - $this->log( |
|
| 433 | - array( |
|
| 434 | - (string) esc_html__( |
|
| 435 | - 'Could not generate a proper item list with:', |
|
| 436 | - 'event_espresso' |
|
| 437 | - ) => $request_response_args |
|
| 438 | - ), |
|
| 439 | - $payment |
|
| 440 | - ); |
|
| 441 | - } |
|
| 442 | - } |
|
| 443 | - // ...otherwise we generate a new list for this transaction. |
|
| 444 | - if ($this->_money->compare_floats($payment->amount(), $transaction->total(), '==')) { |
|
| 445 | - $item_num = 0; |
|
| 446 | - $itemized_sum = 0; |
|
| 447 | - $total_line_items = $transaction->total_line_item(); |
|
| 448 | - // Go through each item in the list. |
|
| 449 | - foreach ($total_line_items->get_items() as $line_item) { |
|
| 450 | - if ($line_item instanceof EE_Line_Item) { |
|
| 451 | - // PayPal doesn't like line items with 0.00 amount, so we may skip those. |
|
| 452 | - if (EEH_Money::compare_floats($line_item->total(), '0.00', '==')) { |
|
| 453 | - continue; |
|
| 454 | - } |
|
| 455 | - $unit_price = $line_item->unit_price(); |
|
| 456 | - $line_item_quantity = $line_item->quantity(); |
|
| 457 | - // This is a discount. |
|
| 458 | - if ($line_item->is_percent()) { |
|
| 459 | - $unit_price = $line_item->total(); |
|
| 460 | - $line_item_quantity = 1; |
|
| 461 | - } |
|
| 462 | - // Item Name. |
|
| 463 | - $itemized_list[ 'L_PAYMENTREQUEST_0_NAME' . $item_num ] = mb_strcut( |
|
| 464 | - $gateway_formatter->formatLineItemName($line_item, $payment), |
|
| 465 | - 0, |
|
| 466 | - 127 |
|
| 467 | - ); |
|
| 468 | - // Item description. |
|
| 469 | - $itemized_list[ 'L_PAYMENTREQUEST_0_DESC' . $item_num ] = mb_strcut( |
|
| 470 | - $gateway_formatter->formatLineItemDesc($line_item, $payment), |
|
| 471 | - 0, |
|
| 472 | - 127 |
|
| 473 | - ); |
|
| 474 | - // Cost of individual item. |
|
| 475 | - $itemized_list[ 'L_PAYMENTREQUEST_0_AMT' . $item_num ] = $gateway_formatter->formatCurrency($unit_price); |
|
| 476 | - // Item Number. |
|
| 477 | - $itemized_list[ 'L_PAYMENTREQUEST_0_NUMBER' . $item_num ] = $item_num + 1; |
|
| 478 | - // Item quantity. |
|
| 479 | - $itemized_list[ 'L_PAYMENTREQUEST_0_QTY' . $item_num ] = $line_item_quantity; |
|
| 480 | - // Digital item is sold. |
|
| 481 | - $itemized_list[ 'L_PAYMENTREQUEST_0_ITEMCATEGORY' . $item_num ] = 'Physical'; |
|
| 482 | - $itemized_sum += $line_item->total(); |
|
| 483 | - ++$item_num; |
|
| 484 | - } |
|
| 485 | - } |
|
| 486 | - // Item's sales S/H and tax amount. |
|
| 487 | - $itemized_list['PAYMENTREQUEST_0_ITEMAMT'] = $total_line_items->get_items_total(); |
|
| 488 | - $itemized_list['PAYMENTREQUEST_0_TAXAMT'] = $total_line_items->get_total_tax(); |
|
| 489 | - $itemized_list['PAYMENTREQUEST_0_SHIPPINGAMT'] = '0'; |
|
| 490 | - $itemized_list['PAYMENTREQUEST_0_HANDLINGAMT'] = '0'; |
|
| 491 | - $itemized_sum_diff_from_txn_total = round( |
|
| 492 | - $transaction->total() - $itemized_sum - $total_line_items->get_total_tax(), |
|
| 493 | - 2 |
|
| 494 | - ); |
|
| 495 | - // If we were not able to recognize some item like promotion, surcharge or cancellation, |
|
| 496 | - // add the difference as an extra line item. |
|
| 497 | - if ($this->_money->compare_floats($itemized_sum_diff_from_txn_total, 0, '!=')) { |
|
| 498 | - // Item Name. |
|
| 499 | - $itemized_list[ 'L_PAYMENTREQUEST_0_NAME' . $item_num ] = mb_strcut( |
|
| 500 | - esc_html__( |
|
| 501 | - 'Other (promotion/surcharge/cancellation)', |
|
| 502 | - 'event_espresso' |
|
| 503 | - ), |
|
| 504 | - 0, |
|
| 505 | - 127 |
|
| 506 | - ); |
|
| 507 | - // Item description. |
|
| 508 | - $itemized_list[ 'L_PAYMENTREQUEST_0_DESC' . $item_num ] = ''; |
|
| 509 | - // Cost of individual item. |
|
| 510 | - $itemized_list[ 'L_PAYMENTREQUEST_0_AMT' . $item_num ] = $gateway_formatter->formatCurrency( |
|
| 511 | - $itemized_sum_diff_from_txn_total |
|
| 512 | - ); |
|
| 513 | - // Item Number. |
|
| 514 | - $itemized_list[ 'L_PAYMENTREQUEST_0_NUMBER' . $item_num ] = $item_num + 1; |
|
| 515 | - // Item quantity. |
|
| 516 | - $itemized_list[ 'L_PAYMENTREQUEST_0_QTY' . $item_num ] = 1; |
|
| 517 | - // Digital item is sold. |
|
| 518 | - $itemized_list[ 'L_PAYMENTREQUEST_0_ITEMCATEGORY' . $item_num ] = 'Physical'; |
|
| 519 | - $item_num++; |
|
| 520 | - } |
|
| 521 | - } else { |
|
| 522 | - // Just one Item. |
|
| 523 | - // Item Name. |
|
| 524 | - $itemized_list['L_PAYMENTREQUEST_0_NAME0'] = mb_strcut( |
|
| 525 | - $gateway_formatter->formatPartialPaymentLineItemName($payment), |
|
| 526 | - 0, |
|
| 527 | - 127 |
|
| 528 | - ); |
|
| 529 | - // Item description. |
|
| 530 | - $itemized_list['L_PAYMENTREQUEST_0_DESC0'] = mb_strcut( |
|
| 531 | - $gateway_formatter->formatPartialPaymentLineItemDesc($payment), |
|
| 532 | - 0, |
|
| 533 | - 127 |
|
| 534 | - ); |
|
| 535 | - // Cost of individual item. |
|
| 536 | - $itemized_list['L_PAYMENTREQUEST_0_AMT0'] = $gateway_formatter->formatCurrency($payment->amount()); |
|
| 537 | - // Item Number. |
|
| 538 | - $itemized_list['L_PAYMENTREQUEST_0_NUMBER0'] = 1; |
|
| 539 | - // Item quantity. |
|
| 540 | - $itemized_list['L_PAYMENTREQUEST_0_QTY0'] = 1; |
|
| 541 | - // Digital item is sold. |
|
| 542 | - $itemized_list['L_PAYMENTREQUEST_0_ITEMCATEGORY0'] = 'Physical'; |
|
| 543 | - // Item's sales S/H and tax amount. |
|
| 544 | - $itemized_list['PAYMENTREQUEST_0_ITEMAMT'] = $gateway_formatter->formatCurrency($payment->amount()); |
|
| 545 | - $itemized_list['PAYMENTREQUEST_0_TAXAMT'] = '0'; |
|
| 546 | - $itemized_list['PAYMENTREQUEST_0_SHIPPINGAMT'] = '0'; |
|
| 547 | - $itemized_list['PAYMENTREQUEST_0_HANDLINGAMT'] = '0'; |
|
| 548 | - } |
|
| 549 | - return $itemized_list; |
|
| 550 | - } |
|
| 551 | - |
|
| 552 | - |
|
| 553 | - |
|
| 554 | - /** |
|
| 555 | - * Make the Express checkout request. |
|
| 556 | - * |
|
| 557 | - * @param array $request_params |
|
| 558 | - * @param string $request_text |
|
| 559 | - * @param EEI_Payment $payment |
|
| 560 | - * @return mixed |
|
| 561 | - */ |
|
| 562 | - public function _ppExpress_request($request_params, $request_text, $payment) |
|
| 563 | - { |
|
| 564 | - $request_dtls = array( |
|
| 565 | - 'VERSION' => '204.0', |
|
| 566 | - 'USER' => $this->_api_username, |
|
| 567 | - 'PWD' => $this->_api_password, |
|
| 568 | - 'SIGNATURE' => $this->_api_signature, |
|
| 569 | - // EE will blow up if you change this |
|
| 570 | - 'BUTTONSOURCE' => 'EventEspresso_SP', |
|
| 571 | - ); |
|
| 572 | - $dtls = array_merge($request_dtls, $request_params); |
|
| 573 | - $this->_log_clean_request($dtls, $payment, $request_text . ' Request'); |
|
| 574 | - // Request Customer Details. |
|
| 575 | - $request_response = wp_remote_post( |
|
| 576 | - $this->_base_gateway_url, |
|
| 577 | - array( |
|
| 578 | - 'method' => 'POST', |
|
| 579 | - 'timeout' => 45, |
|
| 580 | - 'httpversion' => '1.1', |
|
| 581 | - 'cookies' => array(), |
|
| 582 | - 'headers' => array(), |
|
| 583 | - 'body' => http_build_query($dtls, '', '&'), |
|
| 584 | - ) |
|
| 585 | - ); |
|
| 586 | - // Log the response. |
|
| 587 | - $this->log(array($request_text . ' Response' => $request_response), $payment); |
|
| 588 | - return $request_response; |
|
| 589 | - } |
|
| 590 | - |
|
| 591 | - |
|
| 592 | - |
|
| 593 | - /** |
|
| 594 | - * Check the response status. |
|
| 595 | - * |
|
| 596 | - * @param mixed $request_response |
|
| 597 | - * @return array |
|
| 598 | - */ |
|
| 599 | - public function _ppExpress_check_response($request_response) |
|
| 600 | - { |
|
| 601 | - if (is_wp_error($request_response) || empty($request_response['body'])) { |
|
| 602 | - // If we got here then there was an error in this request. |
|
| 603 | - return array('status' => false, 'args' => $request_response); |
|
| 604 | - } |
|
| 605 | - $response_args = array(); |
|
| 606 | - parse_str(urldecode($request_response['body']), $response_args); |
|
| 607 | - if (! isset($response_args['ACK'])) { |
|
| 608 | - return array('status' => false, 'args' => $request_response); |
|
| 609 | - } |
|
| 610 | - if (( |
|
| 611 | - isset($response_args['PAYERID']) |
|
| 612 | - || isset($response_args['TOKEN']) |
|
| 613 | - || isset($response_args['PAYMENTINFO_0_TRANSACTIONID']) |
|
| 614 | - || (isset($response_args['PAYMENTSTATUS']) && $response_args['PAYMENTSTATUS'] === 'Completed') |
|
| 615 | - ) |
|
| 616 | - && in_array($response_args['ACK'], array('Success', 'SuccessWithWarning'), true) |
|
| 617 | - ) { |
|
| 618 | - // Response status OK, return response parameters for further processing. |
|
| 619 | - return array('status' => true, 'args' => $response_args); |
|
| 620 | - } |
|
| 621 | - $errors = $this->_get_errors($response_args); |
|
| 622 | - return array('status' => false, 'args' => $errors); |
|
| 623 | - } |
|
| 624 | - |
|
| 625 | - |
|
| 626 | - |
|
| 627 | - /** |
|
| 628 | - * Log a "Cleared" request. |
|
| 629 | - * |
|
| 630 | - * @param array $request |
|
| 631 | - * @param EEI_Payment $payment |
|
| 632 | - * @param string $info |
|
| 633 | - * @return void |
|
| 634 | - */ |
|
| 635 | - private function _log_clean_request($request, $payment, $info) |
|
| 636 | - { |
|
| 637 | - $cleaned_request_data = $request; |
|
| 638 | - unset($cleaned_request_data['PWD'], $cleaned_request_data['USER'], $cleaned_request_data['SIGNATURE']); |
|
| 639 | - $this->log(array($info => $cleaned_request_data), $payment); |
|
| 640 | - } |
|
| 641 | - |
|
| 642 | - |
|
| 643 | - |
|
| 644 | - /** |
|
| 645 | - * Get error from the response data. |
|
| 646 | - * |
|
| 647 | - * @param array $data_array |
|
| 648 | - * @return array |
|
| 649 | - */ |
|
| 650 | - private function _get_errors($data_array) |
|
| 651 | - { |
|
| 652 | - $errors = array(); |
|
| 653 | - $n = 0; |
|
| 654 | - while (isset($data_array[ "L_ERRORCODE{$n}" ])) { |
|
| 655 | - $l_error_code = isset($data_array[ "L_ERRORCODE{$n}" ]) |
|
| 656 | - ? $data_array[ "L_ERRORCODE{$n}" ] |
|
| 657 | - : ''; |
|
| 658 | - $l_severity_code = isset($data_array[ "L_SEVERITYCODE{$n}" ]) |
|
| 659 | - ? $data_array[ "L_SEVERITYCODE{$n}" ] |
|
| 660 | - : ''; |
|
| 661 | - $l_short_message = isset($data_array[ "L_SHORTMESSAGE{$n}" ]) |
|
| 662 | - ? $data_array[ "L_SHORTMESSAGE{$n}" ] |
|
| 663 | - : ''; |
|
| 664 | - $l_long_message = isset($data_array[ "L_LONGMESSAGE{$n}" ]) |
|
| 665 | - ? $data_array[ "L_LONGMESSAGE{$n}" ] |
|
| 666 | - : ''; |
|
| 667 | - if ($n === 0) { |
|
| 668 | - $errors = array( |
|
| 669 | - 'L_ERRORCODE' => $l_error_code, |
|
| 670 | - 'L_SHORTMESSAGE' => $l_short_message, |
|
| 671 | - 'L_LONGMESSAGE' => $l_long_message, |
|
| 672 | - 'L_SEVERITYCODE' => $l_severity_code, |
|
| 673 | - ); |
|
| 674 | - } else { |
|
| 675 | - $errors['L_ERRORCODE'] .= ', ' . $l_error_code; |
|
| 676 | - $errors['L_SHORTMESSAGE'] .= ', ' . $l_short_message; |
|
| 677 | - $errors['L_LONGMESSAGE'] .= ', ' . $l_long_message; |
|
| 678 | - $errors['L_SEVERITYCODE'] .= ', ' . $l_severity_code; |
|
| 679 | - } |
|
| 680 | - $n++; |
|
| 681 | - } |
|
| 682 | - return $errors; |
|
| 683 | - } |
|
| 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 | + // Locale of the pages displayed by PayPal during Express Checkout. |
|
| 185 | + 'LOCALECODE' => $locale[1] |
|
| 186 | + ); |
|
| 187 | + // Show itemized list. |
|
| 188 | + $itemized_list = $this->itemize_list($payment, $transaction); |
|
| 189 | + $token_request_dtls = array_merge($token_request_dtls, $itemized_list); |
|
| 190 | + // Automatically filling out shipping and contact information. |
|
| 191 | + if ($this->_request_shipping_addr && $primary_attendee instanceof EEI_Attendee) { |
|
| 192 | + // If you do not pass the shipping address, PayPal obtains it from the buyer's account profile. |
|
| 193 | + $token_request_dtls['NOSHIPPING'] = '2'; |
|
| 194 | + $token_request_dtls['PAYMENTREQUEST_0_SHIPTOSTREET'] = $primary_attendee->address(); |
|
| 195 | + $token_request_dtls['PAYMENTREQUEST_0_SHIPTOSTREET2'] = $primary_attendee->address2(); |
|
| 196 | + $token_request_dtls['PAYMENTREQUEST_0_SHIPTOCITY'] = $primary_attendee->city(); |
|
| 197 | + $token_request_dtls['PAYMENTREQUEST_0_SHIPTOSTATE'] = $primary_attendee->state_abbrev(); |
|
| 198 | + $token_request_dtls['PAYMENTREQUEST_0_SHIPTOCOUNTRYCODE'] = $primary_attendee->country_ID(); |
|
| 199 | + $token_request_dtls['PAYMENTREQUEST_0_SHIPTOZIP'] = $primary_attendee->zip(); |
|
| 200 | + $token_request_dtls['PAYMENTREQUEST_0_EMAIL'] = $primary_attendee->email(); |
|
| 201 | + $token_request_dtls['PAYMENTREQUEST_0_SHIPTOPHONENUM'] = $primary_attendee->phone(); |
|
| 202 | + } elseif (! $this->_request_shipping_addr) { |
|
| 203 | + // Do not request shipping details on the PP Checkout page. |
|
| 204 | + $token_request_dtls['NOSHIPPING'] = '1'; |
|
| 205 | + $token_request_dtls['REQCONFIRMSHIPPING'] = '0'; |
|
| 206 | + } |
|
| 207 | + // Used a business/personal logo on the PayPal page. |
|
| 208 | + if (! empty($this->_image_url)) { |
|
| 209 | + $token_request_dtls['LOGOIMG'] = $this->_image_url; |
|
| 210 | + } |
|
| 211 | + $token_request_dtls = apply_filters( |
|
| 212 | + 'FHEE__EEG_Paypal_Express__set_redirection_info__arguments', |
|
| 213 | + $token_request_dtls, |
|
| 214 | + $this |
|
| 215 | + ); |
|
| 216 | + // Request PayPal token. |
|
| 217 | + $token_request_response = $this->_ppExpress_request($token_request_dtls, 'Payment Token', $payment); |
|
| 218 | + $token_rstatus = $this->_ppExpress_check_response($token_request_response); |
|
| 219 | + $response_args = (isset($token_rstatus['args']) && is_array($token_rstatus['args'])) |
|
| 220 | + ? $token_rstatus['args'] |
|
| 221 | + : array(); |
|
| 222 | + if ($token_rstatus['status']) { |
|
| 223 | + // We got the Token so we may continue with the payment and redirect the client. |
|
| 224 | + $payment->set_details($response_args); |
|
| 225 | + $gateway_url = $this->_debug_mode ? 'https://www.sandbox.paypal.com' : 'https://www.paypal.com'; |
|
| 226 | + $payment->set_redirect_url( |
|
| 227 | + $gateway_url |
|
| 228 | + . '/checkoutnow?useraction=commit&cmd=_express-checkout&token=' |
|
| 229 | + . $response_args['TOKEN'] |
|
| 230 | + ); |
|
| 231 | + } else { |
|
| 232 | + if (isset($response_args['L_ERRORCODE'])) { |
|
| 233 | + $payment->set_gateway_response($response_args['L_ERRORCODE'] . '; ' . $response_args['L_SHORTMESSAGE']); |
|
| 234 | + } else { |
|
| 235 | + $payment->set_gateway_response( |
|
| 236 | + esc_html__( |
|
| 237 | + 'Error occurred while trying to setup the Express Checkout.', |
|
| 238 | + 'event_espresso' |
|
| 239 | + ) |
|
| 240 | + ); |
|
| 241 | + } |
|
| 242 | + $payment->set_details($response_args); |
|
| 243 | + $payment->set_status($this->_pay_model->failed_status()); |
|
| 244 | + } |
|
| 245 | + return $payment; |
|
| 246 | + } |
|
| 247 | + |
|
| 248 | + |
|
| 249 | + |
|
| 250 | + /** |
|
| 251 | + * @param array $update_info { |
|
| 252 | + * @type string $gateway_txn_id |
|
| 253 | + * @type string status an EEMI_Payment status |
|
| 254 | + * } |
|
| 255 | + * @param EEI_Transaction $transaction |
|
| 256 | + * @return EEI_Payment |
|
| 257 | + */ |
|
| 258 | + public function handle_payment_update($update_info, $transaction) |
|
| 259 | + { |
|
| 260 | + $payment = $transaction instanceof EEI_Transaction ? $transaction->last_payment() : null; |
|
| 261 | + if ($payment instanceof EEI_Payment) { |
|
| 262 | + $this->log(array('Return from Authorization' => $update_info), $payment); |
|
| 263 | + $transaction = $payment->transaction(); |
|
| 264 | + if (! $transaction instanceof EEI_Transaction) { |
|
| 265 | + $payment->set_gateway_response( |
|
| 266 | + esc_html__( |
|
| 267 | + 'Could not process this payment because it has no associated transaction.', |
|
| 268 | + 'event_espresso' |
|
| 269 | + ) |
|
| 270 | + ); |
|
| 271 | + $payment->set_status($this->_pay_model->failed_status()); |
|
| 272 | + return $payment; |
|
| 273 | + } |
|
| 274 | + $primary_registrant = $transaction->primary_registration(); |
|
| 275 | + $payment_details = $payment->details(); |
|
| 276 | + // Check if we still have the token. |
|
| 277 | + if (! isset($payment_details['TOKEN']) || empty($payment_details['TOKEN'])) { |
|
| 278 | + $payment->set_status($this->_pay_model->failed_status()); |
|
| 279 | + return $payment; |
|
| 280 | + } |
|
| 281 | + $cdetails_request_dtls = array( |
|
| 282 | + 'METHOD' => 'GetExpressCheckoutDetails', |
|
| 283 | + 'TOKEN' => $payment_details['TOKEN'], |
|
| 284 | + ); |
|
| 285 | + // Request Customer Details. |
|
| 286 | + $cdetails_request_response = $this->_ppExpress_request( |
|
| 287 | + $cdetails_request_dtls, |
|
| 288 | + 'Customer Details', |
|
| 289 | + $payment |
|
| 290 | + ); |
|
| 291 | + $cdetails_rstatus = $this->_ppExpress_check_response($cdetails_request_response); |
|
| 292 | + $cdata_response_args = (isset($cdetails_rstatus['args']) && is_array($cdetails_rstatus['args'])) |
|
| 293 | + ? $cdetails_rstatus['args'] |
|
| 294 | + : array(); |
|
| 295 | + if ($cdetails_rstatus['status']) { |
|
| 296 | + // We got the PayerID so now we can Complete the transaction. |
|
| 297 | + $docheckout_request_dtls = array( |
|
| 298 | + 'METHOD' => 'DoExpressCheckoutPayment', |
|
| 299 | + 'PAYERID' => $cdata_response_args['PAYERID'], |
|
| 300 | + 'TOKEN' => $payment_details['TOKEN'], |
|
| 301 | + 'PAYMENTREQUEST_0_PAYMENTACTION' => 'Sale', |
|
| 302 | + 'PAYMENTREQUEST_0_AMT' => $payment->amount(), |
|
| 303 | + 'PAYMENTREQUEST_0_CURRENCYCODE' => $payment->currency_code(), |
|
| 304 | + ); |
|
| 305 | + // Include itemized list. |
|
| 306 | + $itemized_list = $this->itemize_list( |
|
| 307 | + $payment, |
|
| 308 | + $transaction, |
|
| 309 | + $cdata_response_args |
|
| 310 | + ); |
|
| 311 | + $docheckout_request_dtls = array_merge($docheckout_request_dtls, $itemized_list); |
|
| 312 | + // Payment Checkout/Capture. |
|
| 313 | + $docheckout_request_response = $this->_ppExpress_request( |
|
| 314 | + $docheckout_request_dtls, |
|
| 315 | + 'Do Payment', |
|
| 316 | + $payment |
|
| 317 | + ); |
|
| 318 | + $docheckout_rstatus = $this->_ppExpress_check_response($docheckout_request_response); |
|
| 319 | + $docheckout_response_args = (isset($docheckout_rstatus['args']) && is_array($docheckout_rstatus['args'])) |
|
| 320 | + ? $docheckout_rstatus['args'] |
|
| 321 | + : array(); |
|
| 322 | + if ($docheckout_rstatus['status']) { |
|
| 323 | + // All is well, payment approved. |
|
| 324 | + $primary_registration_code = $primary_registrant instanceof EE_Registration ? |
|
| 325 | + $primary_registrant->reg_code() |
|
| 326 | + : ''; |
|
| 327 | + $payment->set_extra_accntng($primary_registration_code); |
|
| 328 | + $payment->set_amount(isset($docheckout_response_args['PAYMENTINFO_0_AMT']) |
|
| 329 | + ? (float) $docheckout_response_args['PAYMENTINFO_0_AMT'] |
|
| 330 | + : 0); |
|
| 331 | + $payment->set_txn_id_chq_nmbr(isset($docheckout_response_args['PAYMENTINFO_0_TRANSACTIONID']) |
|
| 332 | + ? $docheckout_response_args['PAYMENTINFO_0_TRANSACTIONID'] |
|
| 333 | + : null); |
|
| 334 | + $payment->set_details($cdata_response_args); |
|
| 335 | + $payment->set_gateway_response(isset($docheckout_response_args['PAYMENTINFO_0_ACK']) |
|
| 336 | + ? $docheckout_response_args['PAYMENTINFO_0_ACK'] |
|
| 337 | + : ''); |
|
| 338 | + $payment->set_status($this->_pay_model->approved_status()); |
|
| 339 | + } else { |
|
| 340 | + if (isset($docheckout_response_args['L_ERRORCODE'])) { |
|
| 341 | + $payment->set_gateway_response( |
|
| 342 | + $docheckout_response_args['L_ERRORCODE'] |
|
| 343 | + . '; ' |
|
| 344 | + . $docheckout_response_args['L_SHORTMESSAGE'] |
|
| 345 | + ); |
|
| 346 | + } else { |
|
| 347 | + $payment->set_gateway_response( |
|
| 348 | + esc_html__( |
|
| 349 | + 'Error occurred while trying to Capture the funds.', |
|
| 350 | + 'event_espresso' |
|
| 351 | + ) |
|
| 352 | + ); |
|
| 353 | + } |
|
| 354 | + $payment->set_details($docheckout_response_args); |
|
| 355 | + $payment->set_status($this->_pay_model->declined_status()); |
|
| 356 | + } |
|
| 357 | + } else { |
|
| 358 | + if (isset($cdata_response_args['L_ERRORCODE'])) { |
|
| 359 | + $payment->set_gateway_response( |
|
| 360 | + $cdata_response_args['L_ERRORCODE'] |
|
| 361 | + . '; ' |
|
| 362 | + . $cdata_response_args['L_SHORTMESSAGE'] |
|
| 363 | + ); |
|
| 364 | + } else { |
|
| 365 | + $payment->set_gateway_response( |
|
| 366 | + esc_html__( |
|
| 367 | + 'Error occurred while trying to get payment Details from PayPal.', |
|
| 368 | + 'event_espresso' |
|
| 369 | + ) |
|
| 370 | + ); |
|
| 371 | + } |
|
| 372 | + $payment->set_details($cdata_response_args); |
|
| 373 | + $payment->set_status($this->_pay_model->failed_status()); |
|
| 374 | + } |
|
| 375 | + } else { |
|
| 376 | + $payment->set_gateway_response( |
|
| 377 | + esc_html__( |
|
| 378 | + 'Error occurred while trying to process the payment.', |
|
| 379 | + 'event_espresso' |
|
| 380 | + ) |
|
| 381 | + ); |
|
| 382 | + $payment->set_status($this->_pay_model->failed_status()); |
|
| 383 | + } |
|
| 384 | + return $payment; |
|
| 385 | + } |
|
| 386 | + |
|
| 387 | + |
|
| 388 | + |
|
| 389 | + /** |
|
| 390 | + * Make a list of items that are in the giver transaction. |
|
| 391 | + * |
|
| 392 | + * @param EEI_Payment $payment |
|
| 393 | + * @param EEI_Transaction $transaction |
|
| 394 | + * @param array $request_response_args Data from a previous communication with PP. |
|
| 395 | + * @return array |
|
| 396 | + */ |
|
| 397 | + public function itemize_list(EEI_Payment $payment, EEI_Transaction $transaction, $request_response_args = array()) |
|
| 398 | + { |
|
| 399 | + $itemized_list = array(); |
|
| 400 | + $gateway_formatter = $this->_get_gateway_formatter(); |
|
| 401 | + // If we have data from a previous communication with PP (on this transaction) we may use that for our list... |
|
| 402 | + if (! empty($request_response_args) |
|
| 403 | + && array_key_exists('L_PAYMENTREQUEST_0_AMT0', $request_response_args) |
|
| 404 | + && array_key_exists('PAYMENTREQUEST_0_ITEMAMT', $request_response_args) |
|
| 405 | + ) { |
|
| 406 | + foreach ($request_response_args as $arg_key => $arg_val) { |
|
| 407 | + if (strpos($arg_key, 'PAYMENTREQUEST_') !== false |
|
| 408 | + && strpos($arg_key, 'NOTIFYURL') === false |
|
| 409 | + ) { |
|
| 410 | + $itemized_list[ $arg_key ] = $arg_val; |
|
| 411 | + } |
|
| 412 | + } |
|
| 413 | + // If we got only a few Items then something is not right. |
|
| 414 | + if (count($itemized_list) > 2) { |
|
| 415 | + return $itemized_list; |
|
| 416 | + } else { |
|
| 417 | + if (WP_DEBUG) { |
|
| 418 | + throw new EE_Error( |
|
| 419 | + sprintf( |
|
| 420 | + esc_html__( |
|
| 421 | + // @codingStandardsIgnoreStart |
|
| 422 | + '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', |
|
| 423 | + // @codingStandardsIgnoreEnd |
|
| 424 | + 'event_espresso' |
|
| 425 | + ), |
|
| 426 | + wp_json_encode($itemized_list) |
|
| 427 | + ) |
|
| 428 | + ); |
|
| 429 | + } |
|
| 430 | + // Reset the list and log an error, maybe allow to try and generate a new list (below). |
|
| 431 | + $itemized_list = array(); |
|
| 432 | + $this->log( |
|
| 433 | + array( |
|
| 434 | + (string) esc_html__( |
|
| 435 | + 'Could not generate a proper item list with:', |
|
| 436 | + 'event_espresso' |
|
| 437 | + ) => $request_response_args |
|
| 438 | + ), |
|
| 439 | + $payment |
|
| 440 | + ); |
|
| 441 | + } |
|
| 442 | + } |
|
| 443 | + // ...otherwise we generate a new list for this transaction. |
|
| 444 | + if ($this->_money->compare_floats($payment->amount(), $transaction->total(), '==')) { |
|
| 445 | + $item_num = 0; |
|
| 446 | + $itemized_sum = 0; |
|
| 447 | + $total_line_items = $transaction->total_line_item(); |
|
| 448 | + // Go through each item in the list. |
|
| 449 | + foreach ($total_line_items->get_items() as $line_item) { |
|
| 450 | + if ($line_item instanceof EE_Line_Item) { |
|
| 451 | + // PayPal doesn't like line items with 0.00 amount, so we may skip those. |
|
| 452 | + if (EEH_Money::compare_floats($line_item->total(), '0.00', '==')) { |
|
| 453 | + continue; |
|
| 454 | + } |
|
| 455 | + $unit_price = $line_item->unit_price(); |
|
| 456 | + $line_item_quantity = $line_item->quantity(); |
|
| 457 | + // This is a discount. |
|
| 458 | + if ($line_item->is_percent()) { |
|
| 459 | + $unit_price = $line_item->total(); |
|
| 460 | + $line_item_quantity = 1; |
|
| 461 | + } |
|
| 462 | + // Item Name. |
|
| 463 | + $itemized_list[ 'L_PAYMENTREQUEST_0_NAME' . $item_num ] = mb_strcut( |
|
| 464 | + $gateway_formatter->formatLineItemName($line_item, $payment), |
|
| 465 | + 0, |
|
| 466 | + 127 |
|
| 467 | + ); |
|
| 468 | + // Item description. |
|
| 469 | + $itemized_list[ 'L_PAYMENTREQUEST_0_DESC' . $item_num ] = mb_strcut( |
|
| 470 | + $gateway_formatter->formatLineItemDesc($line_item, $payment), |
|
| 471 | + 0, |
|
| 472 | + 127 |
|
| 473 | + ); |
|
| 474 | + // Cost of individual item. |
|
| 475 | + $itemized_list[ 'L_PAYMENTREQUEST_0_AMT' . $item_num ] = $gateway_formatter->formatCurrency($unit_price); |
|
| 476 | + // Item Number. |
|
| 477 | + $itemized_list[ 'L_PAYMENTREQUEST_0_NUMBER' . $item_num ] = $item_num + 1; |
|
| 478 | + // Item quantity. |
|
| 479 | + $itemized_list[ 'L_PAYMENTREQUEST_0_QTY' . $item_num ] = $line_item_quantity; |
|
| 480 | + // Digital item is sold. |
|
| 481 | + $itemized_list[ 'L_PAYMENTREQUEST_0_ITEMCATEGORY' . $item_num ] = 'Physical'; |
|
| 482 | + $itemized_sum += $line_item->total(); |
|
| 483 | + ++$item_num; |
|
| 484 | + } |
|
| 485 | + } |
|
| 486 | + // Item's sales S/H and tax amount. |
|
| 487 | + $itemized_list['PAYMENTREQUEST_0_ITEMAMT'] = $total_line_items->get_items_total(); |
|
| 488 | + $itemized_list['PAYMENTREQUEST_0_TAXAMT'] = $total_line_items->get_total_tax(); |
|
| 489 | + $itemized_list['PAYMENTREQUEST_0_SHIPPINGAMT'] = '0'; |
|
| 490 | + $itemized_list['PAYMENTREQUEST_0_HANDLINGAMT'] = '0'; |
|
| 491 | + $itemized_sum_diff_from_txn_total = round( |
|
| 492 | + $transaction->total() - $itemized_sum - $total_line_items->get_total_tax(), |
|
| 493 | + 2 |
|
| 494 | + ); |
|
| 495 | + // If we were not able to recognize some item like promotion, surcharge or cancellation, |
|
| 496 | + // add the difference as an extra line item. |
|
| 497 | + if ($this->_money->compare_floats($itemized_sum_diff_from_txn_total, 0, '!=')) { |
|
| 498 | + // Item Name. |
|
| 499 | + $itemized_list[ 'L_PAYMENTREQUEST_0_NAME' . $item_num ] = mb_strcut( |
|
| 500 | + esc_html__( |
|
| 501 | + 'Other (promotion/surcharge/cancellation)', |
|
| 502 | + 'event_espresso' |
|
| 503 | + ), |
|
| 504 | + 0, |
|
| 505 | + 127 |
|
| 506 | + ); |
|
| 507 | + // Item description. |
|
| 508 | + $itemized_list[ 'L_PAYMENTREQUEST_0_DESC' . $item_num ] = ''; |
|
| 509 | + // Cost of individual item. |
|
| 510 | + $itemized_list[ 'L_PAYMENTREQUEST_0_AMT' . $item_num ] = $gateway_formatter->formatCurrency( |
|
| 511 | + $itemized_sum_diff_from_txn_total |
|
| 512 | + ); |
|
| 513 | + // Item Number. |
|
| 514 | + $itemized_list[ 'L_PAYMENTREQUEST_0_NUMBER' . $item_num ] = $item_num + 1; |
|
| 515 | + // Item quantity. |
|
| 516 | + $itemized_list[ 'L_PAYMENTREQUEST_0_QTY' . $item_num ] = 1; |
|
| 517 | + // Digital item is sold. |
|
| 518 | + $itemized_list[ 'L_PAYMENTREQUEST_0_ITEMCATEGORY' . $item_num ] = 'Physical'; |
|
| 519 | + $item_num++; |
|
| 520 | + } |
|
| 521 | + } else { |
|
| 522 | + // Just one Item. |
|
| 523 | + // Item Name. |
|
| 524 | + $itemized_list['L_PAYMENTREQUEST_0_NAME0'] = mb_strcut( |
|
| 525 | + $gateway_formatter->formatPartialPaymentLineItemName($payment), |
|
| 526 | + 0, |
|
| 527 | + 127 |
|
| 528 | + ); |
|
| 529 | + // Item description. |
|
| 530 | + $itemized_list['L_PAYMENTREQUEST_0_DESC0'] = mb_strcut( |
|
| 531 | + $gateway_formatter->formatPartialPaymentLineItemDesc($payment), |
|
| 532 | + 0, |
|
| 533 | + 127 |
|
| 534 | + ); |
|
| 535 | + // Cost of individual item. |
|
| 536 | + $itemized_list['L_PAYMENTREQUEST_0_AMT0'] = $gateway_formatter->formatCurrency($payment->amount()); |
|
| 537 | + // Item Number. |
|
| 538 | + $itemized_list['L_PAYMENTREQUEST_0_NUMBER0'] = 1; |
|
| 539 | + // Item quantity. |
|
| 540 | + $itemized_list['L_PAYMENTREQUEST_0_QTY0'] = 1; |
|
| 541 | + // Digital item is sold. |
|
| 542 | + $itemized_list['L_PAYMENTREQUEST_0_ITEMCATEGORY0'] = 'Physical'; |
|
| 543 | + // Item's sales S/H and tax amount. |
|
| 544 | + $itemized_list['PAYMENTREQUEST_0_ITEMAMT'] = $gateway_formatter->formatCurrency($payment->amount()); |
|
| 545 | + $itemized_list['PAYMENTREQUEST_0_TAXAMT'] = '0'; |
|
| 546 | + $itemized_list['PAYMENTREQUEST_0_SHIPPINGAMT'] = '0'; |
|
| 547 | + $itemized_list['PAYMENTREQUEST_0_HANDLINGAMT'] = '0'; |
|
| 548 | + } |
|
| 549 | + return $itemized_list; |
|
| 550 | + } |
|
| 551 | + |
|
| 552 | + |
|
| 553 | + |
|
| 554 | + /** |
|
| 555 | + * Make the Express checkout request. |
|
| 556 | + * |
|
| 557 | + * @param array $request_params |
|
| 558 | + * @param string $request_text |
|
| 559 | + * @param EEI_Payment $payment |
|
| 560 | + * @return mixed |
|
| 561 | + */ |
|
| 562 | + public function _ppExpress_request($request_params, $request_text, $payment) |
|
| 563 | + { |
|
| 564 | + $request_dtls = array( |
|
| 565 | + 'VERSION' => '204.0', |
|
| 566 | + 'USER' => $this->_api_username, |
|
| 567 | + 'PWD' => $this->_api_password, |
|
| 568 | + 'SIGNATURE' => $this->_api_signature, |
|
| 569 | + // EE will blow up if you change this |
|
| 570 | + 'BUTTONSOURCE' => 'EventEspresso_SP', |
|
| 571 | + ); |
|
| 572 | + $dtls = array_merge($request_dtls, $request_params); |
|
| 573 | + $this->_log_clean_request($dtls, $payment, $request_text . ' Request'); |
|
| 574 | + // Request Customer Details. |
|
| 575 | + $request_response = wp_remote_post( |
|
| 576 | + $this->_base_gateway_url, |
|
| 577 | + array( |
|
| 578 | + 'method' => 'POST', |
|
| 579 | + 'timeout' => 45, |
|
| 580 | + 'httpversion' => '1.1', |
|
| 581 | + 'cookies' => array(), |
|
| 582 | + 'headers' => array(), |
|
| 583 | + 'body' => http_build_query($dtls, '', '&'), |
|
| 584 | + ) |
|
| 585 | + ); |
|
| 586 | + // Log the response. |
|
| 587 | + $this->log(array($request_text . ' Response' => $request_response), $payment); |
|
| 588 | + return $request_response; |
|
| 589 | + } |
|
| 590 | + |
|
| 591 | + |
|
| 592 | + |
|
| 593 | + /** |
|
| 594 | + * Check the response status. |
|
| 595 | + * |
|
| 596 | + * @param mixed $request_response |
|
| 597 | + * @return array |
|
| 598 | + */ |
|
| 599 | + public function _ppExpress_check_response($request_response) |
|
| 600 | + { |
|
| 601 | + if (is_wp_error($request_response) || empty($request_response['body'])) { |
|
| 602 | + // If we got here then there was an error in this request. |
|
| 603 | + return array('status' => false, 'args' => $request_response); |
|
| 604 | + } |
|
| 605 | + $response_args = array(); |
|
| 606 | + parse_str(urldecode($request_response['body']), $response_args); |
|
| 607 | + if (! isset($response_args['ACK'])) { |
|
| 608 | + return array('status' => false, 'args' => $request_response); |
|
| 609 | + } |
|
| 610 | + if (( |
|
| 611 | + isset($response_args['PAYERID']) |
|
| 612 | + || isset($response_args['TOKEN']) |
|
| 613 | + || isset($response_args['PAYMENTINFO_0_TRANSACTIONID']) |
|
| 614 | + || (isset($response_args['PAYMENTSTATUS']) && $response_args['PAYMENTSTATUS'] === 'Completed') |
|
| 615 | + ) |
|
| 616 | + && in_array($response_args['ACK'], array('Success', 'SuccessWithWarning'), true) |
|
| 617 | + ) { |
|
| 618 | + // Response status OK, return response parameters for further processing. |
|
| 619 | + return array('status' => true, 'args' => $response_args); |
|
| 620 | + } |
|
| 621 | + $errors = $this->_get_errors($response_args); |
|
| 622 | + return array('status' => false, 'args' => $errors); |
|
| 623 | + } |
|
| 624 | + |
|
| 625 | + |
|
| 626 | + |
|
| 627 | + /** |
|
| 628 | + * Log a "Cleared" request. |
|
| 629 | + * |
|
| 630 | + * @param array $request |
|
| 631 | + * @param EEI_Payment $payment |
|
| 632 | + * @param string $info |
|
| 633 | + * @return void |
|
| 634 | + */ |
|
| 635 | + private function _log_clean_request($request, $payment, $info) |
|
| 636 | + { |
|
| 637 | + $cleaned_request_data = $request; |
|
| 638 | + unset($cleaned_request_data['PWD'], $cleaned_request_data['USER'], $cleaned_request_data['SIGNATURE']); |
|
| 639 | + $this->log(array($info => $cleaned_request_data), $payment); |
|
| 640 | + } |
|
| 641 | + |
|
| 642 | + |
|
| 643 | + |
|
| 644 | + /** |
|
| 645 | + * Get error from the response data. |
|
| 646 | + * |
|
| 647 | + * @param array $data_array |
|
| 648 | + * @return array |
|
| 649 | + */ |
|
| 650 | + private function _get_errors($data_array) |
|
| 651 | + { |
|
| 652 | + $errors = array(); |
|
| 653 | + $n = 0; |
|
| 654 | + while (isset($data_array[ "L_ERRORCODE{$n}" ])) { |
|
| 655 | + $l_error_code = isset($data_array[ "L_ERRORCODE{$n}" ]) |
|
| 656 | + ? $data_array[ "L_ERRORCODE{$n}" ] |
|
| 657 | + : ''; |
|
| 658 | + $l_severity_code = isset($data_array[ "L_SEVERITYCODE{$n}" ]) |
|
| 659 | + ? $data_array[ "L_SEVERITYCODE{$n}" ] |
|
| 660 | + : ''; |
|
| 661 | + $l_short_message = isset($data_array[ "L_SHORTMESSAGE{$n}" ]) |
|
| 662 | + ? $data_array[ "L_SHORTMESSAGE{$n}" ] |
|
| 663 | + : ''; |
|
| 664 | + $l_long_message = isset($data_array[ "L_LONGMESSAGE{$n}" ]) |
|
| 665 | + ? $data_array[ "L_LONGMESSAGE{$n}" ] |
|
| 666 | + : ''; |
|
| 667 | + if ($n === 0) { |
|
| 668 | + $errors = array( |
|
| 669 | + 'L_ERRORCODE' => $l_error_code, |
|
| 670 | + 'L_SHORTMESSAGE' => $l_short_message, |
|
| 671 | + 'L_LONGMESSAGE' => $l_long_message, |
|
| 672 | + 'L_SEVERITYCODE' => $l_severity_code, |
|
| 673 | + ); |
|
| 674 | + } else { |
|
| 675 | + $errors['L_ERRORCODE'] .= ', ' . $l_error_code; |
|
| 676 | + $errors['L_SHORTMESSAGE'] .= ', ' . $l_short_message; |
|
| 677 | + $errors['L_LONGMESSAGE'] .= ', ' . $l_long_message; |
|
| 678 | + $errors['L_SEVERITYCODE'] .= ', ' . $l_severity_code; |
|
| 679 | + } |
|
| 680 | + $n++; |
|
| 681 | + } |
|
| 682 | + return $errors; |
|
| 683 | + } |
|
| 684 | 684 | } |
@@ -924,7 +924,7 @@ |
||
| 924 | 924 | * handles toggling the checkin status for the registration, |
| 925 | 925 | * |
| 926 | 926 | * @access protected |
| 927 | - * @return int|void |
|
| 927 | + * @return integer |
|
| 928 | 928 | * @throws EE_Error |
| 929 | 929 | * @throws InvalidArgumentException |
| 930 | 930 | * @throws InvalidDataTypeException |
@@ -32,10 +32,10 @@ discard block |
||
| 32 | 32 | public function __construct($routing = true) |
| 33 | 33 | { |
| 34 | 34 | parent::__construct($routing); |
| 35 | - if (! defined('REG_CAF_TEMPLATE_PATH')) { |
|
| 36 | - define('REG_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'registrations/templates/'); |
|
| 37 | - define('REG_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'registrations/assets/'); |
|
| 38 | - define('REG_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'registrations/assets/'); |
|
| 35 | + if ( ! defined('REG_CAF_TEMPLATE_PATH')) { |
|
| 36 | + define('REG_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND.'registrations/templates/'); |
|
| 37 | + define('REG_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND.'registrations/assets/'); |
|
| 38 | + define('REG_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL.'registrations/assets/'); |
|
| 39 | 39 | } |
| 40 | 40 | } |
| 41 | 41 | |
@@ -45,7 +45,7 @@ discard block |
||
| 45 | 45 | */ |
| 46 | 46 | protected function _extend_page_config() |
| 47 | 47 | { |
| 48 | - $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'registrations'; |
|
| 48 | + $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND.'registrations'; |
|
| 49 | 49 | $reg_id = ! empty($this->_req_data['_REG_ID']) && ! is_array($this->_req_data['_REG_ID']) |
| 50 | 50 | ? $this->_req_data['_REG_ID'] |
| 51 | 51 | : 0; |
@@ -185,14 +185,14 @@ discard block |
||
| 185 | 185 | // enqueue newsletter js |
| 186 | 186 | wp_enqueue_script( |
| 187 | 187 | 'ee-newsletter-trigger', |
| 188 | - REG_CAF_ASSETS_URL . 'ee-newsletter-trigger.js', |
|
| 188 | + REG_CAF_ASSETS_URL.'ee-newsletter-trigger.js', |
|
| 189 | 189 | array('ee-dialog'), |
| 190 | 190 | EVENT_ESPRESSO_VERSION, |
| 191 | 191 | true |
| 192 | 192 | ); |
| 193 | 193 | wp_enqueue_style( |
| 194 | 194 | 'ee-newsletter-trigger-css', |
| 195 | - REG_CAF_ASSETS_URL . 'ee-newsletter-trigger.css', |
|
| 195 | + REG_CAF_ASSETS_URL.'ee-newsletter-trigger.css', |
|
| 196 | 196 | array(), |
| 197 | 197 | EVENT_ESPRESSO_VERSION |
| 198 | 198 | ); |
@@ -213,7 +213,7 @@ discard block |
||
| 213 | 213 | { |
| 214 | 214 | wp_register_script( |
| 215 | 215 | 'ee-reg-reports-js', |
| 216 | - REG_CAF_ASSETS_URL . 'ee-registration-admin-reports.js', |
|
| 216 | + REG_CAF_ASSETS_URL.'ee-registration-admin-reports.js', |
|
| 217 | 217 | array('google-charts'), |
| 218 | 218 | EVENT_ESPRESSO_VERSION, |
| 219 | 219 | true |
@@ -299,7 +299,7 @@ discard block |
||
| 299 | 299 | $nonce_ref = 'get_newsletter_form_content_nonce'; |
| 300 | 300 | $this->_verify_nonce($nonce, $nonce_ref); |
| 301 | 301 | // let's get the mtp for the incoming MTP_ ID |
| 302 | - if (! isset($this->_req_data['GRP_ID'])) { |
|
| 302 | + if ( ! isset($this->_req_data['GRP_ID'])) { |
|
| 303 | 303 | EE_Error::add_error( |
| 304 | 304 | esc_html__( |
| 305 | 305 | 'There must be something broken with the js or html structure because the required data for getting a message template group is not present (need an GRP_ID).', |
@@ -314,7 +314,7 @@ discard block |
||
| 314 | 314 | $this->_return_json(); |
| 315 | 315 | } |
| 316 | 316 | $MTPG = EEM_Message_Template_Group::instance()->get_one_by_ID($this->_req_data['GRP_ID']); |
| 317 | - if (! $MTPG instanceof EE_Message_Template_Group) { |
|
| 317 | + if ( ! $MTPG instanceof EE_Message_Template_Group) { |
|
| 318 | 318 | EE_Error::add_error( |
| 319 | 319 | sprintf( |
| 320 | 320 | esc_html__( |
@@ -339,12 +339,12 @@ discard block |
||
| 339 | 339 | $field = $MTP->get('MTP_template_field'); |
| 340 | 340 | if ($field === 'content') { |
| 341 | 341 | $content = $MTP->get('MTP_content'); |
| 342 | - if (! empty($content['newsletter_content'])) { |
|
| 342 | + if ( ! empty($content['newsletter_content'])) { |
|
| 343 | 343 | $template_fields['newsletter_content'] = $content['newsletter_content']; |
| 344 | 344 | } |
| 345 | 345 | continue; |
| 346 | 346 | } |
| 347 | - $template_fields[ $MTP->get('MTP_template_field') ] = $MTP->get('MTP_content'); |
|
| 347 | + $template_fields[$MTP->get('MTP_template_field')] = $MTP->get('MTP_content'); |
|
| 348 | 348 | } |
| 349 | 349 | $this->_template_args['success'] = true; |
| 350 | 350 | $this->_template_args['error'] = false; |
@@ -375,7 +375,7 @@ discard block |
||
| 375 | 375 | */ |
| 376 | 376 | public function add_newsletter_action_buttons(EE_Admin_List_Table $list_table) |
| 377 | 377 | { |
| 378 | - if (! EE_Registry::instance()->CAP->current_user_can( |
|
| 378 | + if ( ! EE_Registry::instance()->CAP->current_user_can( |
|
| 379 | 379 | 'ee_send_message', |
| 380 | 380 | 'espresso_registrations_newsletter_selected_send' |
| 381 | 381 | ) |
@@ -444,17 +444,17 @@ discard block |
||
| 444 | 444 | $field_id = $field === '[NEWSLETTER_CONTENT]' |
| 445 | 445 | ? 'content' |
| 446 | 446 | : $field; |
| 447 | - $field_id = 'batch-message-' . strtolower($field_id); |
|
| 447 | + $field_id = 'batch-message-'.strtolower($field_id); |
|
| 448 | 448 | $available_shortcodes[] = '<span class="js-shortcode-selection" data-value="' |
| 449 | 449 | . $shortcode |
| 450 | - . '" data-linked-input-id="' . $field_id . '">' |
|
| 450 | + . '" data-linked-input-id="'.$field_id.'">' |
|
| 451 | 451 | . $shortcode |
| 452 | 452 | . '</span>'; |
| 453 | 453 | } |
| 454 | - $codes[ $field ] = implode(', ', $available_shortcodes); |
|
| 454 | + $codes[$field] = implode(', ', $available_shortcodes); |
|
| 455 | 455 | } |
| 456 | 456 | $shortcodes = $codes; |
| 457 | - $form_template = REG_CAF_TEMPLATE_PATH . 'newsletter-send-form.template.php'; |
|
| 457 | + $form_template = REG_CAF_TEMPLATE_PATH.'newsletter-send-form.template.php'; |
|
| 458 | 458 | $form_template_args = array( |
| 459 | 459 | 'form_action' => admin_url('admin.php?page=espresso_registrations'), |
| 460 | 460 | 'form_route' => 'newsletter_selected_send', |
@@ -622,7 +622,7 @@ discard block |
||
| 622 | 622 | */ |
| 623 | 623 | protected function _registration_reports() |
| 624 | 624 | { |
| 625 | - $template_path = EE_ADMIN_TEMPLATE . 'admin_reports.template.php'; |
|
| 625 | + $template_path = EE_ADMIN_TEMPLATE.'admin_reports.template.php'; |
|
| 626 | 626 | $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
| 627 | 627 | $template_path, |
| 628 | 628 | $this->_reports_template_data, |
@@ -677,7 +677,7 @@ discard block |
||
| 677 | 677 | array_unshift($regs, $column_titles); |
| 678 | 678 | // setup the date range. |
| 679 | 679 | $DateTimeZone = new DateTimeZone(EEH_DTT_Helper::get_timezone()); |
| 680 | - $beginning_date = new DateTime("now " . $period, $DateTimeZone); |
|
| 680 | + $beginning_date = new DateTime("now ".$period, $DateTimeZone); |
|
| 681 | 681 | $ending_date = new DateTime("now", $DateTimeZone); |
| 682 | 682 | $subtitle = sprintf( |
| 683 | 683 | _x('For the period: %1$s to %2$s', 'Used to give date range', 'event_espresso'), |
@@ -697,7 +697,7 @@ discard block |
||
| 697 | 697 | '%sThere are currently no registration records in the last month for this report.%s', |
| 698 | 698 | 'event_espresso' |
| 699 | 699 | ), |
| 700 | - '<h2>' . $report_title . '</h2><p>', |
|
| 700 | + '<h2>'.$report_title.'</h2><p>', |
|
| 701 | 701 | '</p>' |
| 702 | 702 | ), |
| 703 | 703 | ); |
@@ -750,7 +750,7 @@ discard block |
||
| 750 | 750 | array_unshift($regs, $column_titles); |
| 751 | 751 | // setup the date range. |
| 752 | 752 | $DateTimeZone = new DateTimeZone(EEH_DTT_Helper::get_timezone()); |
| 753 | - $beginning_date = new DateTime("now " . $period, $DateTimeZone); |
|
| 753 | + $beginning_date = new DateTime("now ".$period, $DateTimeZone); |
|
| 754 | 754 | $ending_date = new DateTime("now", $DateTimeZone); |
| 755 | 755 | $subtitle = sprintf( |
| 756 | 756 | _x('For the period: %1$s to %2$s', 'Used to give date range', 'event_espresso'), |
@@ -770,7 +770,7 @@ discard block |
||
| 770 | 770 | '%sThere are currently no registration records in the last month for this report.%s', |
| 771 | 771 | 'event_espresso' |
| 772 | 772 | ), |
| 773 | - '<h2>' . $report_title . '</h2><p>', |
|
| 773 | + '<h2>'.$report_title.'</h2><p>', |
|
| 774 | 774 | '</p>' |
| 775 | 775 | ), |
| 776 | 776 | ); |
@@ -796,7 +796,7 @@ discard block |
||
| 796 | 796 | $reg_id = isset($this->_req_data['_REG_ID']) ? $this->_req_data['_REG_ID'] : null; |
| 797 | 797 | /** @var EE_Registration $registration */ |
| 798 | 798 | $registration = EEM_Registration::instance()->get_one_by_ID($reg_id); |
| 799 | - if (! $registration instanceof EE_Registration) { |
|
| 799 | + if ( ! $registration instanceof EE_Registration) { |
|
| 800 | 800 | throw new EE_Error( |
| 801 | 801 | sprintf( |
| 802 | 802 | esc_html__('An error occurred. There is no registration with ID (%d)', 'event_espresso'), |
@@ -831,7 +831,7 @@ discard block |
||
| 831 | 831 | if ($datetime instanceof EE_Datetime) { |
| 832 | 832 | $datetime_label = $datetime->get_dtt_display_name(true); |
| 833 | 833 | $datetime_label .= ! empty($datetime_label) |
| 834 | - ? ' (' . $datetime->get_dtt_display_name() . ')' |
|
| 834 | + ? ' ('.$datetime->get_dtt_display_name().')' |
|
| 835 | 835 | : $datetime->get_dtt_display_name(); |
| 836 | 836 | } |
| 837 | 837 | $datetime_link = ! empty($dtt_id) && $registration instanceof EE_Registration |
@@ -845,7 +845,7 @@ discard block |
||
| 845 | 845 | ) |
| 846 | 846 | : ''; |
| 847 | 847 | $datetime_link = ! empty($datetime_link) |
| 848 | - ? '<a href="' . $datetime_link . '">' |
|
| 848 | + ? '<a href="'.$datetime_link.'">' |
|
| 849 | 849 | . '<span id="checkin-dtt">' |
| 850 | 850 | . $datetime_label |
| 851 | 851 | . '</span></a>' |
@@ -857,8 +857,8 @@ discard block |
||
| 857 | 857 | ? $attendee->get_admin_details_link() |
| 858 | 858 | : ''; |
| 859 | 859 | $attendee_link = ! empty($attendee_link) |
| 860 | - ? '<a href="' . $attendee->get_admin_details_link() . '"' |
|
| 861 | - . ' title="' . esc_html__('Click for attendee details', 'event_espresso') . '">' |
|
| 860 | + ? '<a href="'.$attendee->get_admin_details_link().'"' |
|
| 861 | + . ' title="'.esc_html__('Click for attendee details', 'event_espresso').'">' |
|
| 862 | 862 | . '<span id="checkin-attendee-name">' |
| 863 | 863 | . $attendee_name |
| 864 | 864 | . '</span></a>' |
@@ -867,25 +867,25 @@ discard block |
||
| 867 | 867 | ? $registration->event()->get_admin_details_link() |
| 868 | 868 | : ''; |
| 869 | 869 | $event_link = ! empty($event_link) |
| 870 | - ? '<a href="' . $event_link . '"' |
|
| 871 | - . ' title="' . esc_html__('Click here to edit event.', 'event_espresso') . '">' |
|
| 870 | + ? '<a href="'.$event_link.'"' |
|
| 871 | + . ' title="'.esc_html__('Click here to edit event.', 'event_espresso').'">' |
|
| 872 | 872 | . '<span id="checkin-event-name">' |
| 873 | 873 | . $registration->event_name() |
| 874 | 874 | . '</span>' |
| 875 | 875 | . '</a>' |
| 876 | 876 | : ''; |
| 877 | 877 | $this->_template_args['before_list_table'] = ! empty($reg_id) && ! empty($dtt_id) |
| 878 | - ? '<h2>' . sprintf( |
|
| 878 | + ? '<h2>'.sprintf( |
|
| 879 | 879 | esc_html__('Displaying check in records for %1$s for %2$s at the event, %3$s', 'event_espresso'), |
| 880 | 880 | $attendee_link, |
| 881 | 881 | $datetime_link, |
| 882 | 882 | $event_link |
| 883 | - ) . '</h2>' |
|
| 883 | + ).'</h2>' |
|
| 884 | 884 | : ''; |
| 885 | 885 | $this->_template_args['list_table_hidden_fields'] = ! empty($reg_id) |
| 886 | - ? '<input type="hidden" name="_REG_ID" value="' . $reg_id . '">' : ''; |
|
| 886 | + ? '<input type="hidden" name="_REG_ID" value="'.$reg_id.'">' : ''; |
|
| 887 | 887 | $this->_template_args['list_table_hidden_fields'] .= ! empty($dtt_id) |
| 888 | - ? '<input type="hidden" name="DTT_ID" value="' . $dtt_id . '">' : ''; |
|
| 888 | + ? '<input type="hidden" name="DTT_ID" value="'.$dtt_id.'">' : ''; |
|
| 889 | 889 | $this->display_admin_list_table_page_with_no_sidebar(); |
| 890 | 890 | } |
| 891 | 891 | |
@@ -902,7 +902,7 @@ discard block |
||
| 902 | 902 | public function toggle_checkin_status() |
| 903 | 903 | { |
| 904 | 904 | // first make sure we have the necessary data |
| 905 | - if (! isset($this->_req_data['_regid'])) { |
|
| 905 | + if ( ! isset($this->_req_data['_regid'])) { |
|
| 906 | 906 | EE_Error::add_error( |
| 907 | 907 | esc_html__( |
| 908 | 908 | 'There must be something broken with the html structure because the required data for toggling the Check-in status is not being sent via ajax', |
@@ -924,7 +924,7 @@ discard block |
||
| 924 | 924 | // beautiful! Made it this far so let's get the status. |
| 925 | 925 | $new_status = new CheckinStatusDashicon($this->_toggle_checkin_status()); |
| 926 | 926 | // setup new class to return via ajax |
| 927 | - $this->_template_args['admin_page_content'] = 'clickable trigger-checkin ' . $new_status->cssClasses(); |
|
| 927 | + $this->_template_args['admin_page_content'] = 'clickable trigger-checkin '.$new_status->cssClasses(); |
|
| 928 | 928 | $this->_template_args['success'] = true; |
| 929 | 929 | $this->_return_json(); |
| 930 | 930 | } |
@@ -950,7 +950,7 @@ discard block |
||
| 950 | 950 | ); |
| 951 | 951 | $new_status = false; |
| 952 | 952 | // bulk action check in toggle |
| 953 | - if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
| 953 | + if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
| 954 | 954 | // cycle thru checkboxes |
| 955 | 955 | while (list($REG_ID, $value) = each($this->_req_data['checkbox'])) { |
| 956 | 956 | $DTT_ID = isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : null; |
@@ -1020,9 +1020,9 @@ discard block |
||
| 1020 | 1020 | '_REG_ID' => isset($this->_req_data['_REG_ID']) ? $this->_req_data['_REG_ID'] : 0, |
| 1021 | 1021 | ); |
| 1022 | 1022 | $errors = 0; |
| 1023 | - if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
| 1023 | + if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
| 1024 | 1024 | while (list($CHK_ID, $value) = each($this->_req_data['checkbox'])) { |
| 1025 | - if (! EEM_Checkin::instance()->delete_by_ID($CHK_ID)) { |
|
| 1025 | + if ( ! EEM_Checkin::instance()->delete_by_ID($CHK_ID)) { |
|
| 1026 | 1026 | $errors++; |
| 1027 | 1027 | } |
| 1028 | 1028 | } |
@@ -1068,8 +1068,8 @@ discard block |
||
| 1068 | 1068 | 'DTT_ID' => isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : 0, |
| 1069 | 1069 | '_REG_ID' => isset($this->_req_data['_REG_ID']) ? $this->_req_data['_REG_ID'] : 0, |
| 1070 | 1070 | ); |
| 1071 | - if (! empty($this->_req_data['CHK_ID'])) { |
|
| 1072 | - if (! EEM_Checkin::instance()->delete_by_ID($this->_req_data['CHK_ID'])) { |
|
| 1071 | + if ( ! empty($this->_req_data['CHK_ID'])) { |
|
| 1072 | + if ( ! EEM_Checkin::instance()->delete_by_ID($this->_req_data['CHK_ID'])) { |
|
| 1073 | 1073 | EE_Error::add_error( |
| 1074 | 1074 | esc_html__('Something went wrong and this check-in record was not deleted', 'event_espresso'), |
| 1075 | 1075 | __FILE__, |
@@ -1138,27 +1138,27 @@ discard block |
||
| 1138 | 1138 | 'desc' => $checked_never->legendLabel(), |
| 1139 | 1139 | ), |
| 1140 | 1140 | 'approved_status' => array( |
| 1141 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_approved, |
|
| 1141 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_approved, |
|
| 1142 | 1142 | 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_approved, false, 'sentence'), |
| 1143 | 1143 | ), |
| 1144 | 1144 | 'cancelled_status' => array( |
| 1145 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_cancelled, |
|
| 1145 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_cancelled, |
|
| 1146 | 1146 | 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_cancelled, false, 'sentence'), |
| 1147 | 1147 | ), |
| 1148 | 1148 | 'declined_status' => array( |
| 1149 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_declined, |
|
| 1149 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_declined, |
|
| 1150 | 1150 | 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_declined, false, 'sentence'), |
| 1151 | 1151 | ), |
| 1152 | 1152 | 'not_approved' => array( |
| 1153 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_not_approved, |
|
| 1153 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_not_approved, |
|
| 1154 | 1154 | 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, false, 'sentence'), |
| 1155 | 1155 | ), |
| 1156 | 1156 | 'pending_status' => array( |
| 1157 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_pending_payment, |
|
| 1157 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_pending_payment, |
|
| 1158 | 1158 | 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, false, 'sentence'), |
| 1159 | 1159 | ), |
| 1160 | 1160 | 'wait_list' => array( |
| 1161 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_wait_list, |
|
| 1161 | + 'class' => 'ee-status-legend ee-status-legend-'.EEM_Registration::status_id_wait_list, |
|
| 1162 | 1162 | 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_wait_list, false, 'sentence'), |
| 1163 | 1163 | ), |
| 1164 | 1164 | ); |
@@ -1167,10 +1167,10 @@ discard block |
||
| 1167 | 1167 | /** @var EE_Event $event */ |
| 1168 | 1168 | $event = EEM_Event::instance()->get_one_by_ID($event_id); |
| 1169 | 1169 | $this->_template_args['before_list_table'] = $event instanceof EE_Event |
| 1170 | - ? '<h2>' . sprintf( |
|
| 1170 | + ? '<h2>'.sprintf( |
|
| 1171 | 1171 | esc_html__('Viewing Registrations for Event: %s', 'event_espresso'), |
| 1172 | 1172 | EEM_Event::instance()->get_one_by_ID($event_id)->get('EVT_name') |
| 1173 | - ) . '</h2>' |
|
| 1173 | + ).'</h2>' |
|
| 1174 | 1174 | : ''; |
| 1175 | 1175 | // need to get the number of datetimes on the event and set default datetime_id if there is only one datetime on |
| 1176 | 1176 | // the event. |
@@ -1188,12 +1188,12 @@ discard block |
||
| 1188 | 1188 | $this->_template_args['before_list_table'] .= ' <span class="drk-grey-text">'; |
| 1189 | 1189 | $this->_template_args['before_list_table'] .= '<span class="dashicons dashicons-calendar"></span>'; |
| 1190 | 1190 | $this->_template_args['before_list_table'] .= $datetime->name(); |
| 1191 | - $this->_template_args['before_list_table'] .= ' ( ' . $datetime->date_and_time_range() . ' )'; |
|
| 1191 | + $this->_template_args['before_list_table'] .= ' ( '.$datetime->date_and_time_range().' )'; |
|
| 1192 | 1192 | $this->_template_args['before_list_table'] .= '</span></h2>'; |
| 1193 | 1193 | } |
| 1194 | 1194 | // if no datetime, then we're on the initial view, so let's give some helpful instructions on what the status |
| 1195 | 1195 | // column represents |
| 1196 | - if (! $datetime instanceof EE_Datetime) { |
|
| 1196 | + if ( ! $datetime instanceof EE_Datetime) { |
|
| 1197 | 1197 | $this->_template_args['before_list_table'] .= '<br><p class="description">' |
| 1198 | 1198 | . esc_html__( |
| 1199 | 1199 | 'In this view, the check-in status represents the latest check-in record for the registration in that row.', |
@@ -16,1267 +16,1267 @@ |
||
| 16 | 16 | { |
| 17 | 17 | |
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * This is used to hold the reports template data which is setup early in the request. |
|
| 21 | - * |
|
| 22 | - * @type array |
|
| 23 | - */ |
|
| 24 | - protected $_reports_template_data = array(); |
|
| 19 | + /** |
|
| 20 | + * This is used to hold the reports template data which is setup early in the request. |
|
| 21 | + * |
|
| 22 | + * @type array |
|
| 23 | + */ |
|
| 24 | + protected $_reports_template_data = array(); |
|
| 25 | 25 | |
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * Extend_Registrations_Admin_Page constructor. |
|
| 29 | - * |
|
| 30 | - * @param bool $routing |
|
| 31 | - */ |
|
| 32 | - public function __construct($routing = true) |
|
| 33 | - { |
|
| 34 | - parent::__construct($routing); |
|
| 35 | - if (! defined('REG_CAF_TEMPLATE_PATH')) { |
|
| 36 | - define('REG_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'registrations/templates/'); |
|
| 37 | - define('REG_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'registrations/assets/'); |
|
| 38 | - define('REG_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'registrations/assets/'); |
|
| 39 | - } |
|
| 40 | - } |
|
| 27 | + /** |
|
| 28 | + * Extend_Registrations_Admin_Page constructor. |
|
| 29 | + * |
|
| 30 | + * @param bool $routing |
|
| 31 | + */ |
|
| 32 | + public function __construct($routing = true) |
|
| 33 | + { |
|
| 34 | + parent::__construct($routing); |
|
| 35 | + if (! defined('REG_CAF_TEMPLATE_PATH')) { |
|
| 36 | + define('REG_CAF_TEMPLATE_PATH', EE_CORE_CAF_ADMIN_EXTEND . 'registrations/templates/'); |
|
| 37 | + define('REG_CAF_ASSETS', EE_CORE_CAF_ADMIN_EXTEND . 'registrations/assets/'); |
|
| 38 | + define('REG_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'registrations/assets/'); |
|
| 39 | + } |
|
| 40 | + } |
|
| 41 | 41 | |
| 42 | 42 | |
| 43 | - /** |
|
| 44 | - * Extending page configuration. |
|
| 45 | - */ |
|
| 46 | - protected function _extend_page_config() |
|
| 47 | - { |
|
| 48 | - $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'registrations'; |
|
| 49 | - $reg_id = ! empty($this->_req_data['_REG_ID']) && ! is_array($this->_req_data['_REG_ID']) |
|
| 50 | - ? $this->_req_data['_REG_ID'] |
|
| 51 | - : 0; |
|
| 52 | - $new_page_routes = array( |
|
| 53 | - 'reports' => array( |
|
| 54 | - 'func' => '_registration_reports', |
|
| 55 | - 'capability' => 'ee_read_registrations', |
|
| 56 | - ), |
|
| 57 | - 'registration_checkins' => array( |
|
| 58 | - 'func' => '_registration_checkin_list_table', |
|
| 59 | - 'capability' => 'ee_read_checkins', |
|
| 60 | - ), |
|
| 61 | - 'newsletter_selected_send' => array( |
|
| 62 | - 'func' => '_newsletter_selected_send', |
|
| 63 | - 'noheader' => true, |
|
| 64 | - 'capability' => 'ee_send_message', |
|
| 65 | - ), |
|
| 66 | - 'delete_checkin_rows' => array( |
|
| 67 | - 'func' => '_delete_checkin_rows', |
|
| 68 | - 'noheader' => true, |
|
| 69 | - 'capability' => 'ee_delete_checkins', |
|
| 70 | - ), |
|
| 71 | - 'delete_checkin_row' => array( |
|
| 72 | - 'func' => '_delete_checkin_row', |
|
| 73 | - 'noheader' => true, |
|
| 74 | - 'capability' => 'ee_delete_checkin', |
|
| 75 | - 'obj_id' => $reg_id, |
|
| 76 | - ), |
|
| 77 | - 'toggle_checkin_status' => array( |
|
| 78 | - 'func' => '_toggle_checkin_status', |
|
| 79 | - 'noheader' => true, |
|
| 80 | - 'capability' => 'ee_edit_checkin', |
|
| 81 | - 'obj_id' => $reg_id, |
|
| 82 | - ), |
|
| 83 | - 'toggle_checkin_status_bulk' => array( |
|
| 84 | - 'func' => '_toggle_checkin_status', |
|
| 85 | - 'noheader' => true, |
|
| 86 | - 'capability' => 'ee_edit_checkins', |
|
| 87 | - ), |
|
| 88 | - 'event_registrations' => array( |
|
| 89 | - 'func' => '_event_registrations_list_table', |
|
| 90 | - 'capability' => 'ee_read_checkins', |
|
| 91 | - ), |
|
| 92 | - 'registrations_checkin_report' => array( |
|
| 93 | - 'func' => '_registrations_checkin_report', |
|
| 94 | - 'noheader' => true, |
|
| 95 | - 'capability' => 'ee_read_registrations', |
|
| 96 | - ), |
|
| 97 | - ); |
|
| 98 | - $this->_page_routes = array_merge($this->_page_routes, $new_page_routes); |
|
| 99 | - $new_page_config = array( |
|
| 100 | - 'reports' => array( |
|
| 101 | - 'nav' => array( |
|
| 102 | - 'label' => esc_html__('Reports', 'event_espresso'), |
|
| 103 | - 'order' => 30, |
|
| 104 | - ), |
|
| 105 | - 'help_tabs' => array( |
|
| 106 | - 'registrations_reports_help_tab' => array( |
|
| 107 | - 'title' => esc_html__('Registration Reports', 'event_espresso'), |
|
| 108 | - 'filename' => 'registrations_reports', |
|
| 109 | - ), |
|
| 110 | - ), |
|
| 111 | - /*'help_tour' => array( 'Registration_Reports_Help_Tour' ),*/ |
|
| 112 | - 'require_nonce' => false, |
|
| 113 | - ), |
|
| 114 | - 'event_registrations' => array( |
|
| 115 | - 'nav' => array( |
|
| 116 | - 'label' => esc_html__('Event Check-In', 'event_espresso'), |
|
| 117 | - 'order' => 10, |
|
| 118 | - 'persistent' => true, |
|
| 119 | - ), |
|
| 120 | - 'help_tabs' => array( |
|
| 121 | - 'registrations_event_checkin_help_tab' => array( |
|
| 122 | - 'title' => esc_html__('Registrations Event Check-In', 'event_espresso'), |
|
| 123 | - 'filename' => 'registrations_event_checkin', |
|
| 124 | - ), |
|
| 125 | - 'registrations_event_checkin_table_column_headings_help_tab' => array( |
|
| 126 | - 'title' => esc_html__('Event Check-In Table Column Headings', 'event_espresso'), |
|
| 127 | - 'filename' => 'registrations_event_checkin_table_column_headings', |
|
| 128 | - ), |
|
| 129 | - 'registrations_event_checkin_filters_help_tab' => array( |
|
| 130 | - 'title' => esc_html__('Event Check-In Filters', 'event_espresso'), |
|
| 131 | - 'filename' => 'registrations_event_checkin_filters', |
|
| 132 | - ), |
|
| 133 | - 'registrations_event_checkin_views_help_tab' => array( |
|
| 134 | - 'title' => esc_html__('Event Check-In Views', 'event_espresso'), |
|
| 135 | - 'filename' => 'registrations_event_checkin_views', |
|
| 136 | - ), |
|
| 137 | - 'registrations_event_checkin_other_help_tab' => array( |
|
| 138 | - 'title' => esc_html__('Event Check-In Other', 'event_espresso'), |
|
| 139 | - 'filename' => 'registrations_event_checkin_other', |
|
| 140 | - ), |
|
| 141 | - ), |
|
| 142 | - 'help_tour' => array('Event_Checkin_Help_Tour'), |
|
| 143 | - 'qtips' => array('Registration_List_Table_Tips'), |
|
| 144 | - 'list_table' => 'EE_Event_Registrations_List_Table', |
|
| 145 | - 'metaboxes' => array(), |
|
| 146 | - 'require_nonce' => false, |
|
| 147 | - ), |
|
| 148 | - 'registration_checkins' => array( |
|
| 149 | - 'nav' => array( |
|
| 150 | - 'label' => esc_html__('Check-In Records', 'event_espresso'), |
|
| 151 | - 'order' => 15, |
|
| 152 | - 'persistent' => false, |
|
| 153 | - 'url' => '', |
|
| 154 | - ), |
|
| 155 | - 'list_table' => 'EE_Registration_CheckIn_List_Table', |
|
| 156 | - // 'help_tour' => array( 'Checkin_Toggle_View_Help_Tour' ), |
|
| 157 | - 'metaboxes' => array(), |
|
| 158 | - 'require_nonce' => false, |
|
| 159 | - ), |
|
| 160 | - ); |
|
| 161 | - $this->_page_config = array_merge($this->_page_config, $new_page_config); |
|
| 162 | - $this->_page_config['contact_list']['list_table'] = 'Extend_EE_Attendee_Contact_List_Table'; |
|
| 163 | - $this->_page_config['default']['list_table'] = 'Extend_EE_Registrations_List_Table'; |
|
| 164 | - } |
|
| 43 | + /** |
|
| 44 | + * Extending page configuration. |
|
| 45 | + */ |
|
| 46 | + protected function _extend_page_config() |
|
| 47 | + { |
|
| 48 | + $this->_admin_base_path = EE_CORE_CAF_ADMIN_EXTEND . 'registrations'; |
|
| 49 | + $reg_id = ! empty($this->_req_data['_REG_ID']) && ! is_array($this->_req_data['_REG_ID']) |
|
| 50 | + ? $this->_req_data['_REG_ID'] |
|
| 51 | + : 0; |
|
| 52 | + $new_page_routes = array( |
|
| 53 | + 'reports' => array( |
|
| 54 | + 'func' => '_registration_reports', |
|
| 55 | + 'capability' => 'ee_read_registrations', |
|
| 56 | + ), |
|
| 57 | + 'registration_checkins' => array( |
|
| 58 | + 'func' => '_registration_checkin_list_table', |
|
| 59 | + 'capability' => 'ee_read_checkins', |
|
| 60 | + ), |
|
| 61 | + 'newsletter_selected_send' => array( |
|
| 62 | + 'func' => '_newsletter_selected_send', |
|
| 63 | + 'noheader' => true, |
|
| 64 | + 'capability' => 'ee_send_message', |
|
| 65 | + ), |
|
| 66 | + 'delete_checkin_rows' => array( |
|
| 67 | + 'func' => '_delete_checkin_rows', |
|
| 68 | + 'noheader' => true, |
|
| 69 | + 'capability' => 'ee_delete_checkins', |
|
| 70 | + ), |
|
| 71 | + 'delete_checkin_row' => array( |
|
| 72 | + 'func' => '_delete_checkin_row', |
|
| 73 | + 'noheader' => true, |
|
| 74 | + 'capability' => 'ee_delete_checkin', |
|
| 75 | + 'obj_id' => $reg_id, |
|
| 76 | + ), |
|
| 77 | + 'toggle_checkin_status' => array( |
|
| 78 | + 'func' => '_toggle_checkin_status', |
|
| 79 | + 'noheader' => true, |
|
| 80 | + 'capability' => 'ee_edit_checkin', |
|
| 81 | + 'obj_id' => $reg_id, |
|
| 82 | + ), |
|
| 83 | + 'toggle_checkin_status_bulk' => array( |
|
| 84 | + 'func' => '_toggle_checkin_status', |
|
| 85 | + 'noheader' => true, |
|
| 86 | + 'capability' => 'ee_edit_checkins', |
|
| 87 | + ), |
|
| 88 | + 'event_registrations' => array( |
|
| 89 | + 'func' => '_event_registrations_list_table', |
|
| 90 | + 'capability' => 'ee_read_checkins', |
|
| 91 | + ), |
|
| 92 | + 'registrations_checkin_report' => array( |
|
| 93 | + 'func' => '_registrations_checkin_report', |
|
| 94 | + 'noheader' => true, |
|
| 95 | + 'capability' => 'ee_read_registrations', |
|
| 96 | + ), |
|
| 97 | + ); |
|
| 98 | + $this->_page_routes = array_merge($this->_page_routes, $new_page_routes); |
|
| 99 | + $new_page_config = array( |
|
| 100 | + 'reports' => array( |
|
| 101 | + 'nav' => array( |
|
| 102 | + 'label' => esc_html__('Reports', 'event_espresso'), |
|
| 103 | + 'order' => 30, |
|
| 104 | + ), |
|
| 105 | + 'help_tabs' => array( |
|
| 106 | + 'registrations_reports_help_tab' => array( |
|
| 107 | + 'title' => esc_html__('Registration Reports', 'event_espresso'), |
|
| 108 | + 'filename' => 'registrations_reports', |
|
| 109 | + ), |
|
| 110 | + ), |
|
| 111 | + /*'help_tour' => array( 'Registration_Reports_Help_Tour' ),*/ |
|
| 112 | + 'require_nonce' => false, |
|
| 113 | + ), |
|
| 114 | + 'event_registrations' => array( |
|
| 115 | + 'nav' => array( |
|
| 116 | + 'label' => esc_html__('Event Check-In', 'event_espresso'), |
|
| 117 | + 'order' => 10, |
|
| 118 | + 'persistent' => true, |
|
| 119 | + ), |
|
| 120 | + 'help_tabs' => array( |
|
| 121 | + 'registrations_event_checkin_help_tab' => array( |
|
| 122 | + 'title' => esc_html__('Registrations Event Check-In', 'event_espresso'), |
|
| 123 | + 'filename' => 'registrations_event_checkin', |
|
| 124 | + ), |
|
| 125 | + 'registrations_event_checkin_table_column_headings_help_tab' => array( |
|
| 126 | + 'title' => esc_html__('Event Check-In Table Column Headings', 'event_espresso'), |
|
| 127 | + 'filename' => 'registrations_event_checkin_table_column_headings', |
|
| 128 | + ), |
|
| 129 | + 'registrations_event_checkin_filters_help_tab' => array( |
|
| 130 | + 'title' => esc_html__('Event Check-In Filters', 'event_espresso'), |
|
| 131 | + 'filename' => 'registrations_event_checkin_filters', |
|
| 132 | + ), |
|
| 133 | + 'registrations_event_checkin_views_help_tab' => array( |
|
| 134 | + 'title' => esc_html__('Event Check-In Views', 'event_espresso'), |
|
| 135 | + 'filename' => 'registrations_event_checkin_views', |
|
| 136 | + ), |
|
| 137 | + 'registrations_event_checkin_other_help_tab' => array( |
|
| 138 | + 'title' => esc_html__('Event Check-In Other', 'event_espresso'), |
|
| 139 | + 'filename' => 'registrations_event_checkin_other', |
|
| 140 | + ), |
|
| 141 | + ), |
|
| 142 | + 'help_tour' => array('Event_Checkin_Help_Tour'), |
|
| 143 | + 'qtips' => array('Registration_List_Table_Tips'), |
|
| 144 | + 'list_table' => 'EE_Event_Registrations_List_Table', |
|
| 145 | + 'metaboxes' => array(), |
|
| 146 | + 'require_nonce' => false, |
|
| 147 | + ), |
|
| 148 | + 'registration_checkins' => array( |
|
| 149 | + 'nav' => array( |
|
| 150 | + 'label' => esc_html__('Check-In Records', 'event_espresso'), |
|
| 151 | + 'order' => 15, |
|
| 152 | + 'persistent' => false, |
|
| 153 | + 'url' => '', |
|
| 154 | + ), |
|
| 155 | + 'list_table' => 'EE_Registration_CheckIn_List_Table', |
|
| 156 | + // 'help_tour' => array( 'Checkin_Toggle_View_Help_Tour' ), |
|
| 157 | + 'metaboxes' => array(), |
|
| 158 | + 'require_nonce' => false, |
|
| 159 | + ), |
|
| 160 | + ); |
|
| 161 | + $this->_page_config = array_merge($this->_page_config, $new_page_config); |
|
| 162 | + $this->_page_config['contact_list']['list_table'] = 'Extend_EE_Attendee_Contact_List_Table'; |
|
| 163 | + $this->_page_config['default']['list_table'] = 'Extend_EE_Registrations_List_Table'; |
|
| 164 | + } |
|
| 165 | 165 | |
| 166 | 166 | |
| 167 | - /** |
|
| 168 | - * Ajax hooks for all routes in this page. |
|
| 169 | - */ |
|
| 170 | - protected function _ajax_hooks() |
|
| 171 | - { |
|
| 172 | - parent::_ajax_hooks(); |
|
| 173 | - add_action('wp_ajax_get_newsletter_form_content', array($this, 'get_newsletter_form_content')); |
|
| 174 | - } |
|
| 167 | + /** |
|
| 168 | + * Ajax hooks for all routes in this page. |
|
| 169 | + */ |
|
| 170 | + protected function _ajax_hooks() |
|
| 171 | + { |
|
| 172 | + parent::_ajax_hooks(); |
|
| 173 | + add_action('wp_ajax_get_newsletter_form_content', array($this, 'get_newsletter_form_content')); |
|
| 174 | + } |
|
| 175 | 175 | |
| 176 | 176 | |
| 177 | - /** |
|
| 178 | - * Global scripts for all routes in this page. |
|
| 179 | - */ |
|
| 180 | - public function load_scripts_styles() |
|
| 181 | - { |
|
| 182 | - parent::load_scripts_styles(); |
|
| 183 | - // if newsletter message type is active then let's add filter and load js for it. |
|
| 184 | - if (EEH_MSG_Template::is_mt_active('newsletter')) { |
|
| 185 | - // enqueue newsletter js |
|
| 186 | - wp_enqueue_script( |
|
| 187 | - 'ee-newsletter-trigger', |
|
| 188 | - REG_CAF_ASSETS_URL . 'ee-newsletter-trigger.js', |
|
| 189 | - array('ee-dialog'), |
|
| 190 | - EVENT_ESPRESSO_VERSION, |
|
| 191 | - true |
|
| 192 | - ); |
|
| 193 | - wp_enqueue_style( |
|
| 194 | - 'ee-newsletter-trigger-css', |
|
| 195 | - REG_CAF_ASSETS_URL . 'ee-newsletter-trigger.css', |
|
| 196 | - array(), |
|
| 197 | - EVENT_ESPRESSO_VERSION |
|
| 198 | - ); |
|
| 199 | - // hook in buttons for newsletter message type trigger. |
|
| 200 | - add_action( |
|
| 201 | - 'AHEE__EE_Admin_List_Table__extra_tablenav__after_bottom_buttons', |
|
| 202 | - array($this, 'add_newsletter_action_buttons'), |
|
| 203 | - 10 |
|
| 204 | - ); |
|
| 205 | - } |
|
| 206 | - } |
|
| 177 | + /** |
|
| 178 | + * Global scripts for all routes in this page. |
|
| 179 | + */ |
|
| 180 | + public function load_scripts_styles() |
|
| 181 | + { |
|
| 182 | + parent::load_scripts_styles(); |
|
| 183 | + // if newsletter message type is active then let's add filter and load js for it. |
|
| 184 | + if (EEH_MSG_Template::is_mt_active('newsletter')) { |
|
| 185 | + // enqueue newsletter js |
|
| 186 | + wp_enqueue_script( |
|
| 187 | + 'ee-newsletter-trigger', |
|
| 188 | + REG_CAF_ASSETS_URL . 'ee-newsletter-trigger.js', |
|
| 189 | + array('ee-dialog'), |
|
| 190 | + EVENT_ESPRESSO_VERSION, |
|
| 191 | + true |
|
| 192 | + ); |
|
| 193 | + wp_enqueue_style( |
|
| 194 | + 'ee-newsletter-trigger-css', |
|
| 195 | + REG_CAF_ASSETS_URL . 'ee-newsletter-trigger.css', |
|
| 196 | + array(), |
|
| 197 | + EVENT_ESPRESSO_VERSION |
|
| 198 | + ); |
|
| 199 | + // hook in buttons for newsletter message type trigger. |
|
| 200 | + add_action( |
|
| 201 | + 'AHEE__EE_Admin_List_Table__extra_tablenav__after_bottom_buttons', |
|
| 202 | + array($this, 'add_newsletter_action_buttons'), |
|
| 203 | + 10 |
|
| 204 | + ); |
|
| 205 | + } |
|
| 206 | + } |
|
| 207 | 207 | |
| 208 | 208 | |
| 209 | - /** |
|
| 210 | - * Scripts and styles for just the reports route. |
|
| 211 | - */ |
|
| 212 | - public function load_scripts_styles_reports() |
|
| 213 | - { |
|
| 214 | - wp_register_script( |
|
| 215 | - 'ee-reg-reports-js', |
|
| 216 | - REG_CAF_ASSETS_URL . 'ee-registration-admin-reports.js', |
|
| 217 | - array('google-charts'), |
|
| 218 | - EVENT_ESPRESSO_VERSION, |
|
| 219 | - true |
|
| 220 | - ); |
|
| 221 | - wp_enqueue_script('ee-reg-reports-js'); |
|
| 222 | - $this->_registration_reports_js_setup(); |
|
| 223 | - } |
|
| 209 | + /** |
|
| 210 | + * Scripts and styles for just the reports route. |
|
| 211 | + */ |
|
| 212 | + public function load_scripts_styles_reports() |
|
| 213 | + { |
|
| 214 | + wp_register_script( |
|
| 215 | + 'ee-reg-reports-js', |
|
| 216 | + REG_CAF_ASSETS_URL . 'ee-registration-admin-reports.js', |
|
| 217 | + array('google-charts'), |
|
| 218 | + EVENT_ESPRESSO_VERSION, |
|
| 219 | + true |
|
| 220 | + ); |
|
| 221 | + wp_enqueue_script('ee-reg-reports-js'); |
|
| 222 | + $this->_registration_reports_js_setup(); |
|
| 223 | + } |
|
| 224 | 224 | |
| 225 | 225 | |
| 226 | - /** |
|
| 227 | - * Register screen options for event_registrations route. |
|
| 228 | - */ |
|
| 229 | - protected function _add_screen_options_event_registrations() |
|
| 230 | - { |
|
| 231 | - $this->_per_page_screen_option(); |
|
| 232 | - } |
|
| 226 | + /** |
|
| 227 | + * Register screen options for event_registrations route. |
|
| 228 | + */ |
|
| 229 | + protected function _add_screen_options_event_registrations() |
|
| 230 | + { |
|
| 231 | + $this->_per_page_screen_option(); |
|
| 232 | + } |
|
| 233 | 233 | |
| 234 | 234 | |
| 235 | - /** |
|
| 236 | - * Register screen options for registration_checkins route |
|
| 237 | - */ |
|
| 238 | - protected function _add_screen_options_registration_checkins() |
|
| 239 | - { |
|
| 240 | - $page_title = $this->_admin_page_title; |
|
| 241 | - $this->_admin_page_title = esc_html__('Check-In Records', 'event_espresso'); |
|
| 242 | - $this->_per_page_screen_option(); |
|
| 243 | - $this->_admin_page_title = $page_title; |
|
| 244 | - } |
|
| 235 | + /** |
|
| 236 | + * Register screen options for registration_checkins route |
|
| 237 | + */ |
|
| 238 | + protected function _add_screen_options_registration_checkins() |
|
| 239 | + { |
|
| 240 | + $page_title = $this->_admin_page_title; |
|
| 241 | + $this->_admin_page_title = esc_html__('Check-In Records', 'event_espresso'); |
|
| 242 | + $this->_per_page_screen_option(); |
|
| 243 | + $this->_admin_page_title = $page_title; |
|
| 244 | + } |
|
| 245 | 245 | |
| 246 | 246 | |
| 247 | - /** |
|
| 248 | - * Set views property for event_registrations route. |
|
| 249 | - */ |
|
| 250 | - protected function _set_list_table_views_event_registrations() |
|
| 251 | - { |
|
| 252 | - $this->_views = array( |
|
| 253 | - 'all' => array( |
|
| 254 | - 'slug' => 'all', |
|
| 255 | - 'label' => esc_html__('All', 'event_espresso'), |
|
| 256 | - 'count' => 0, |
|
| 257 | - 'bulk_action' => ! isset($this->_req_data['event_id']) |
|
| 258 | - ? array() |
|
| 259 | - : array( |
|
| 260 | - 'toggle_checkin_status_bulk' => esc_html__('Toggle Check-In', 'event_espresso'), |
|
| 261 | - ), |
|
| 262 | - ), |
|
| 263 | - ); |
|
| 264 | - } |
|
| 247 | + /** |
|
| 248 | + * Set views property for event_registrations route. |
|
| 249 | + */ |
|
| 250 | + protected function _set_list_table_views_event_registrations() |
|
| 251 | + { |
|
| 252 | + $this->_views = array( |
|
| 253 | + 'all' => array( |
|
| 254 | + 'slug' => 'all', |
|
| 255 | + 'label' => esc_html__('All', 'event_espresso'), |
|
| 256 | + 'count' => 0, |
|
| 257 | + 'bulk_action' => ! isset($this->_req_data['event_id']) |
|
| 258 | + ? array() |
|
| 259 | + : array( |
|
| 260 | + 'toggle_checkin_status_bulk' => esc_html__('Toggle Check-In', 'event_espresso'), |
|
| 261 | + ), |
|
| 262 | + ), |
|
| 263 | + ); |
|
| 264 | + } |
|
| 265 | 265 | |
| 266 | 266 | |
| 267 | - /** |
|
| 268 | - * Set views property for registration_checkins route. |
|
| 269 | - */ |
|
| 270 | - protected function _set_list_table_views_registration_checkins() |
|
| 271 | - { |
|
| 272 | - $this->_views = array( |
|
| 273 | - 'all' => array( |
|
| 274 | - 'slug' => 'all', |
|
| 275 | - 'label' => esc_html__('All', 'event_espresso'), |
|
| 276 | - 'count' => 0, |
|
| 277 | - 'bulk_action' => array('delete_checkin_rows' => esc_html__('Delete Check-In Rows', 'event_espresso')), |
|
| 278 | - ), |
|
| 279 | - ); |
|
| 280 | - } |
|
| 267 | + /** |
|
| 268 | + * Set views property for registration_checkins route. |
|
| 269 | + */ |
|
| 270 | + protected function _set_list_table_views_registration_checkins() |
|
| 271 | + { |
|
| 272 | + $this->_views = array( |
|
| 273 | + 'all' => array( |
|
| 274 | + 'slug' => 'all', |
|
| 275 | + 'label' => esc_html__('All', 'event_espresso'), |
|
| 276 | + 'count' => 0, |
|
| 277 | + 'bulk_action' => array('delete_checkin_rows' => esc_html__('Delete Check-In Rows', 'event_espresso')), |
|
| 278 | + ), |
|
| 279 | + ); |
|
| 280 | + } |
|
| 281 | 281 | |
| 282 | 282 | |
| 283 | - /** |
|
| 284 | - * callback for ajax action. |
|
| 285 | - * |
|
| 286 | - * @since 4.3.0 |
|
| 287 | - * @return void (JSON) |
|
| 288 | - * @throws EE_Error |
|
| 289 | - * @throws InvalidArgumentException |
|
| 290 | - * @throws InvalidDataTypeException |
|
| 291 | - * @throws InvalidInterfaceException |
|
| 292 | - */ |
|
| 293 | - public function get_newsletter_form_content() |
|
| 294 | - { |
|
| 295 | - // do a nonce check cause we're not coming in from an normal route here. |
|
| 296 | - $nonce = isset($this->_req_data['get_newsletter_form_content_nonce']) ? sanitize_text_field( |
|
| 297 | - $this->_req_data['get_newsletter_form_content_nonce'] |
|
| 298 | - ) : ''; |
|
| 299 | - $nonce_ref = 'get_newsletter_form_content_nonce'; |
|
| 300 | - $this->_verify_nonce($nonce, $nonce_ref); |
|
| 301 | - // let's get the mtp for the incoming MTP_ ID |
|
| 302 | - if (! isset($this->_req_data['GRP_ID'])) { |
|
| 303 | - EE_Error::add_error( |
|
| 304 | - esc_html__( |
|
| 305 | - 'There must be something broken with the js or html structure because the required data for getting a message template group is not present (need an GRP_ID).', |
|
| 306 | - 'event_espresso' |
|
| 307 | - ), |
|
| 308 | - __FILE__, |
|
| 309 | - __FUNCTION__, |
|
| 310 | - __LINE__ |
|
| 311 | - ); |
|
| 312 | - $this->_template_args['success'] = false; |
|
| 313 | - $this->_template_args['error'] = true; |
|
| 314 | - $this->_return_json(); |
|
| 315 | - } |
|
| 316 | - $MTPG = EEM_Message_Template_Group::instance()->get_one_by_ID($this->_req_data['GRP_ID']); |
|
| 317 | - if (! $MTPG instanceof EE_Message_Template_Group) { |
|
| 318 | - EE_Error::add_error( |
|
| 319 | - sprintf( |
|
| 320 | - esc_html__( |
|
| 321 | - 'The GRP_ID given (%d) does not appear to have a corresponding row in the database.', |
|
| 322 | - 'event_espresso' |
|
| 323 | - ), |
|
| 324 | - $this->_req_data['GRP_ID'] |
|
| 325 | - ), |
|
| 326 | - __FILE__, |
|
| 327 | - __FUNCTION__, |
|
| 328 | - __LINE__ |
|
| 329 | - ); |
|
| 330 | - $this->_template_args['success'] = false; |
|
| 331 | - $this->_template_args['error'] = true; |
|
| 332 | - $this->_return_json(); |
|
| 333 | - } |
|
| 334 | - $MTPs = $MTPG->context_templates(); |
|
| 335 | - $MTPs = $MTPs['attendee']; |
|
| 336 | - $template_fields = array(); |
|
| 337 | - /** @var EE_Message_Template $MTP */ |
|
| 338 | - foreach ($MTPs as $MTP) { |
|
| 339 | - $field = $MTP->get('MTP_template_field'); |
|
| 340 | - if ($field === 'content') { |
|
| 341 | - $content = $MTP->get('MTP_content'); |
|
| 342 | - if (! empty($content['newsletter_content'])) { |
|
| 343 | - $template_fields['newsletter_content'] = $content['newsletter_content']; |
|
| 344 | - } |
|
| 345 | - continue; |
|
| 346 | - } |
|
| 347 | - $template_fields[ $MTP->get('MTP_template_field') ] = $MTP->get('MTP_content'); |
|
| 348 | - } |
|
| 349 | - $this->_template_args['success'] = true; |
|
| 350 | - $this->_template_args['error'] = false; |
|
| 351 | - $this->_template_args['data'] = array( |
|
| 352 | - 'batch_message_from' => isset($template_fields['from']) |
|
| 353 | - ? $template_fields['from'] |
|
| 354 | - : '', |
|
| 355 | - 'batch_message_subject' => isset($template_fields['subject']) |
|
| 356 | - ? $template_fields['subject'] |
|
| 357 | - : '', |
|
| 358 | - 'batch_message_content' => isset($template_fields['newsletter_content']) |
|
| 359 | - ? $template_fields['newsletter_content'] |
|
| 360 | - : '', |
|
| 361 | - ); |
|
| 362 | - $this->_return_json(); |
|
| 363 | - } |
|
| 283 | + /** |
|
| 284 | + * callback for ajax action. |
|
| 285 | + * |
|
| 286 | + * @since 4.3.0 |
|
| 287 | + * @return void (JSON) |
|
| 288 | + * @throws EE_Error |
|
| 289 | + * @throws InvalidArgumentException |
|
| 290 | + * @throws InvalidDataTypeException |
|
| 291 | + * @throws InvalidInterfaceException |
|
| 292 | + */ |
|
| 293 | + public function get_newsletter_form_content() |
|
| 294 | + { |
|
| 295 | + // do a nonce check cause we're not coming in from an normal route here. |
|
| 296 | + $nonce = isset($this->_req_data['get_newsletter_form_content_nonce']) ? sanitize_text_field( |
|
| 297 | + $this->_req_data['get_newsletter_form_content_nonce'] |
|
| 298 | + ) : ''; |
|
| 299 | + $nonce_ref = 'get_newsletter_form_content_nonce'; |
|
| 300 | + $this->_verify_nonce($nonce, $nonce_ref); |
|
| 301 | + // let's get the mtp for the incoming MTP_ ID |
|
| 302 | + if (! isset($this->_req_data['GRP_ID'])) { |
|
| 303 | + EE_Error::add_error( |
|
| 304 | + esc_html__( |
|
| 305 | + 'There must be something broken with the js or html structure because the required data for getting a message template group is not present (need an GRP_ID).', |
|
| 306 | + 'event_espresso' |
|
| 307 | + ), |
|
| 308 | + __FILE__, |
|
| 309 | + __FUNCTION__, |
|
| 310 | + __LINE__ |
|
| 311 | + ); |
|
| 312 | + $this->_template_args['success'] = false; |
|
| 313 | + $this->_template_args['error'] = true; |
|
| 314 | + $this->_return_json(); |
|
| 315 | + } |
|
| 316 | + $MTPG = EEM_Message_Template_Group::instance()->get_one_by_ID($this->_req_data['GRP_ID']); |
|
| 317 | + if (! $MTPG instanceof EE_Message_Template_Group) { |
|
| 318 | + EE_Error::add_error( |
|
| 319 | + sprintf( |
|
| 320 | + esc_html__( |
|
| 321 | + 'The GRP_ID given (%d) does not appear to have a corresponding row in the database.', |
|
| 322 | + 'event_espresso' |
|
| 323 | + ), |
|
| 324 | + $this->_req_data['GRP_ID'] |
|
| 325 | + ), |
|
| 326 | + __FILE__, |
|
| 327 | + __FUNCTION__, |
|
| 328 | + __LINE__ |
|
| 329 | + ); |
|
| 330 | + $this->_template_args['success'] = false; |
|
| 331 | + $this->_template_args['error'] = true; |
|
| 332 | + $this->_return_json(); |
|
| 333 | + } |
|
| 334 | + $MTPs = $MTPG->context_templates(); |
|
| 335 | + $MTPs = $MTPs['attendee']; |
|
| 336 | + $template_fields = array(); |
|
| 337 | + /** @var EE_Message_Template $MTP */ |
|
| 338 | + foreach ($MTPs as $MTP) { |
|
| 339 | + $field = $MTP->get('MTP_template_field'); |
|
| 340 | + if ($field === 'content') { |
|
| 341 | + $content = $MTP->get('MTP_content'); |
|
| 342 | + if (! empty($content['newsletter_content'])) { |
|
| 343 | + $template_fields['newsletter_content'] = $content['newsletter_content']; |
|
| 344 | + } |
|
| 345 | + continue; |
|
| 346 | + } |
|
| 347 | + $template_fields[ $MTP->get('MTP_template_field') ] = $MTP->get('MTP_content'); |
|
| 348 | + } |
|
| 349 | + $this->_template_args['success'] = true; |
|
| 350 | + $this->_template_args['error'] = false; |
|
| 351 | + $this->_template_args['data'] = array( |
|
| 352 | + 'batch_message_from' => isset($template_fields['from']) |
|
| 353 | + ? $template_fields['from'] |
|
| 354 | + : '', |
|
| 355 | + 'batch_message_subject' => isset($template_fields['subject']) |
|
| 356 | + ? $template_fields['subject'] |
|
| 357 | + : '', |
|
| 358 | + 'batch_message_content' => isset($template_fields['newsletter_content']) |
|
| 359 | + ? $template_fields['newsletter_content'] |
|
| 360 | + : '', |
|
| 361 | + ); |
|
| 362 | + $this->_return_json(); |
|
| 363 | + } |
|
| 364 | 364 | |
| 365 | 365 | |
| 366 | - /** |
|
| 367 | - * callback for AHEE__EE_Admin_List_Table__extra_tablenav__after_bottom_buttons action |
|
| 368 | - * |
|
| 369 | - * @since 4.3.0 |
|
| 370 | - * @param EE_Admin_List_Table $list_table |
|
| 371 | - * @return void |
|
| 372 | - * @throws InvalidArgumentException |
|
| 373 | - * @throws InvalidDataTypeException |
|
| 374 | - * @throws InvalidInterfaceException |
|
| 375 | - */ |
|
| 376 | - public function add_newsletter_action_buttons(EE_Admin_List_Table $list_table) |
|
| 377 | - { |
|
| 378 | - if (! EE_Registry::instance()->CAP->current_user_can( |
|
| 379 | - 'ee_send_message', |
|
| 380 | - 'espresso_registrations_newsletter_selected_send' |
|
| 381 | - ) |
|
| 382 | - ) { |
|
| 383 | - return; |
|
| 384 | - } |
|
| 385 | - $routes_to_add_to = array( |
|
| 386 | - 'contact_list', |
|
| 387 | - 'event_registrations', |
|
| 388 | - 'default', |
|
| 389 | - ); |
|
| 390 | - if ($this->_current_page === 'espresso_registrations' && in_array($this->_req_action, $routes_to_add_to)) { |
|
| 391 | - if (($this->_req_action === 'event_registrations' && empty($this->_req_data['event_id'])) |
|
| 392 | - || (isset($this->_req_data['status']) && $this->_req_data['status'] === 'trash') |
|
| 393 | - ) { |
|
| 394 | - echo ''; |
|
| 395 | - } else { |
|
| 396 | - $button_text = sprintf( |
|
| 397 | - esc_html__('Send Batch Message (%s selected)', 'event_espresso'), |
|
| 398 | - '<span class="send-selected-newsletter-count">0</span>' |
|
| 399 | - ); |
|
| 400 | - echo '<button id="selected-batch-send-trigger" class="button secondary-button">' |
|
| 401 | - . '<span class="dashicons dashicons-email "></span>' |
|
| 402 | - . $button_text |
|
| 403 | - . '</button>'; |
|
| 404 | - add_action('admin_footer', array($this, 'newsletter_send_form_skeleton')); |
|
| 405 | - } |
|
| 406 | - } |
|
| 407 | - } |
|
| 366 | + /** |
|
| 367 | + * callback for AHEE__EE_Admin_List_Table__extra_tablenav__after_bottom_buttons action |
|
| 368 | + * |
|
| 369 | + * @since 4.3.0 |
|
| 370 | + * @param EE_Admin_List_Table $list_table |
|
| 371 | + * @return void |
|
| 372 | + * @throws InvalidArgumentException |
|
| 373 | + * @throws InvalidDataTypeException |
|
| 374 | + * @throws InvalidInterfaceException |
|
| 375 | + */ |
|
| 376 | + public function add_newsletter_action_buttons(EE_Admin_List_Table $list_table) |
|
| 377 | + { |
|
| 378 | + if (! EE_Registry::instance()->CAP->current_user_can( |
|
| 379 | + 'ee_send_message', |
|
| 380 | + 'espresso_registrations_newsletter_selected_send' |
|
| 381 | + ) |
|
| 382 | + ) { |
|
| 383 | + return; |
|
| 384 | + } |
|
| 385 | + $routes_to_add_to = array( |
|
| 386 | + 'contact_list', |
|
| 387 | + 'event_registrations', |
|
| 388 | + 'default', |
|
| 389 | + ); |
|
| 390 | + if ($this->_current_page === 'espresso_registrations' && in_array($this->_req_action, $routes_to_add_to)) { |
|
| 391 | + if (($this->_req_action === 'event_registrations' && empty($this->_req_data['event_id'])) |
|
| 392 | + || (isset($this->_req_data['status']) && $this->_req_data['status'] === 'trash') |
|
| 393 | + ) { |
|
| 394 | + echo ''; |
|
| 395 | + } else { |
|
| 396 | + $button_text = sprintf( |
|
| 397 | + esc_html__('Send Batch Message (%s selected)', 'event_espresso'), |
|
| 398 | + '<span class="send-selected-newsletter-count">0</span>' |
|
| 399 | + ); |
|
| 400 | + echo '<button id="selected-batch-send-trigger" class="button secondary-button">' |
|
| 401 | + . '<span class="dashicons dashicons-email "></span>' |
|
| 402 | + . $button_text |
|
| 403 | + . '</button>'; |
|
| 404 | + add_action('admin_footer', array($this, 'newsletter_send_form_skeleton')); |
|
| 405 | + } |
|
| 406 | + } |
|
| 407 | + } |
|
| 408 | 408 | |
| 409 | 409 | |
| 410 | - /** |
|
| 411 | - * @throws DomainException |
|
| 412 | - * @throws EE_Error |
|
| 413 | - * @throws InvalidArgumentException |
|
| 414 | - * @throws InvalidDataTypeException |
|
| 415 | - * @throws InvalidInterfaceException |
|
| 416 | - */ |
|
| 417 | - public function newsletter_send_form_skeleton() |
|
| 418 | - { |
|
| 419 | - $list_table = $this->_list_table_object; |
|
| 420 | - $codes = array(); |
|
| 421 | - // need to templates for the newsletter message type for the template selector. |
|
| 422 | - $values[] = array('text' => esc_html__('Select Template to Use', 'event_espresso'), 'id' => 0); |
|
| 423 | - $mtps = EEM_Message_Template_Group::instance()->get_all( |
|
| 424 | - array(array('MTP_message_type' => 'newsletter', 'MTP_messenger' => 'email')) |
|
| 425 | - ); |
|
| 426 | - foreach ($mtps as $mtp) { |
|
| 427 | - $name = $mtp->name(); |
|
| 428 | - $values[] = array( |
|
| 429 | - 'text' => empty($name) ? esc_html__('Global', 'event_espresso') : $name, |
|
| 430 | - 'id' => $mtp->ID(), |
|
| 431 | - ); |
|
| 432 | - } |
|
| 433 | - // need to get a list of shortcodes that are available for the newsletter message type. |
|
| 434 | - $shortcodes = EEH_MSG_Template::get_shortcodes( |
|
| 435 | - 'newsletter', |
|
| 436 | - 'email', |
|
| 437 | - array(), |
|
| 438 | - 'attendee', |
|
| 439 | - false |
|
| 440 | - ); |
|
| 441 | - foreach ($shortcodes as $field => $shortcode_array) { |
|
| 442 | - $available_shortcodes = array(); |
|
| 443 | - foreach ($shortcode_array as $shortcode => $shortcode_details) { |
|
| 444 | - $field_id = $field === '[NEWSLETTER_CONTENT]' |
|
| 445 | - ? 'content' |
|
| 446 | - : $field; |
|
| 447 | - $field_id = 'batch-message-' . strtolower($field_id); |
|
| 448 | - $available_shortcodes[] = '<span class="js-shortcode-selection" data-value="' |
|
| 449 | - . $shortcode |
|
| 450 | - . '" data-linked-input-id="' . $field_id . '">' |
|
| 451 | - . $shortcode |
|
| 452 | - . '</span>'; |
|
| 453 | - } |
|
| 454 | - $codes[ $field ] = implode(', ', $available_shortcodes); |
|
| 455 | - } |
|
| 456 | - $shortcodes = $codes; |
|
| 457 | - $form_template = REG_CAF_TEMPLATE_PATH . 'newsletter-send-form.template.php'; |
|
| 458 | - $form_template_args = array( |
|
| 459 | - 'form_action' => admin_url('admin.php?page=espresso_registrations'), |
|
| 460 | - 'form_route' => 'newsletter_selected_send', |
|
| 461 | - 'form_nonce_name' => 'newsletter_selected_send_nonce', |
|
| 462 | - 'form_nonce' => wp_create_nonce('newsletter_selected_send_nonce'), |
|
| 463 | - 'redirect_back_to' => $this->_req_action, |
|
| 464 | - 'ajax_nonce' => wp_create_nonce('get_newsletter_form_content_nonce'), |
|
| 465 | - 'template_selector' => EEH_Form_Fields::select_input('newsletter_mtp_selected', $values), |
|
| 466 | - 'shortcodes' => $shortcodes, |
|
| 467 | - 'id_type' => $list_table instanceof EE_Attendee_Contact_List_Table ? 'contact' : 'registration', |
|
| 468 | - ); |
|
| 469 | - EEH_Template::display_template($form_template, $form_template_args); |
|
| 470 | - } |
|
| 410 | + /** |
|
| 411 | + * @throws DomainException |
|
| 412 | + * @throws EE_Error |
|
| 413 | + * @throws InvalidArgumentException |
|
| 414 | + * @throws InvalidDataTypeException |
|
| 415 | + * @throws InvalidInterfaceException |
|
| 416 | + */ |
|
| 417 | + public function newsletter_send_form_skeleton() |
|
| 418 | + { |
|
| 419 | + $list_table = $this->_list_table_object; |
|
| 420 | + $codes = array(); |
|
| 421 | + // need to templates for the newsletter message type for the template selector. |
|
| 422 | + $values[] = array('text' => esc_html__('Select Template to Use', 'event_espresso'), 'id' => 0); |
|
| 423 | + $mtps = EEM_Message_Template_Group::instance()->get_all( |
|
| 424 | + array(array('MTP_message_type' => 'newsletter', 'MTP_messenger' => 'email')) |
|
| 425 | + ); |
|
| 426 | + foreach ($mtps as $mtp) { |
|
| 427 | + $name = $mtp->name(); |
|
| 428 | + $values[] = array( |
|
| 429 | + 'text' => empty($name) ? esc_html__('Global', 'event_espresso') : $name, |
|
| 430 | + 'id' => $mtp->ID(), |
|
| 431 | + ); |
|
| 432 | + } |
|
| 433 | + // need to get a list of shortcodes that are available for the newsletter message type. |
|
| 434 | + $shortcodes = EEH_MSG_Template::get_shortcodes( |
|
| 435 | + 'newsletter', |
|
| 436 | + 'email', |
|
| 437 | + array(), |
|
| 438 | + 'attendee', |
|
| 439 | + false |
|
| 440 | + ); |
|
| 441 | + foreach ($shortcodes as $field => $shortcode_array) { |
|
| 442 | + $available_shortcodes = array(); |
|
| 443 | + foreach ($shortcode_array as $shortcode => $shortcode_details) { |
|
| 444 | + $field_id = $field === '[NEWSLETTER_CONTENT]' |
|
| 445 | + ? 'content' |
|
| 446 | + : $field; |
|
| 447 | + $field_id = 'batch-message-' . strtolower($field_id); |
|
| 448 | + $available_shortcodes[] = '<span class="js-shortcode-selection" data-value="' |
|
| 449 | + . $shortcode |
|
| 450 | + . '" data-linked-input-id="' . $field_id . '">' |
|
| 451 | + . $shortcode |
|
| 452 | + . '</span>'; |
|
| 453 | + } |
|
| 454 | + $codes[ $field ] = implode(', ', $available_shortcodes); |
|
| 455 | + } |
|
| 456 | + $shortcodes = $codes; |
|
| 457 | + $form_template = REG_CAF_TEMPLATE_PATH . 'newsletter-send-form.template.php'; |
|
| 458 | + $form_template_args = array( |
|
| 459 | + 'form_action' => admin_url('admin.php?page=espresso_registrations'), |
|
| 460 | + 'form_route' => 'newsletter_selected_send', |
|
| 461 | + 'form_nonce_name' => 'newsletter_selected_send_nonce', |
|
| 462 | + 'form_nonce' => wp_create_nonce('newsletter_selected_send_nonce'), |
|
| 463 | + 'redirect_back_to' => $this->_req_action, |
|
| 464 | + 'ajax_nonce' => wp_create_nonce('get_newsletter_form_content_nonce'), |
|
| 465 | + 'template_selector' => EEH_Form_Fields::select_input('newsletter_mtp_selected', $values), |
|
| 466 | + 'shortcodes' => $shortcodes, |
|
| 467 | + 'id_type' => $list_table instanceof EE_Attendee_Contact_List_Table ? 'contact' : 'registration', |
|
| 468 | + ); |
|
| 469 | + EEH_Template::display_template($form_template, $form_template_args); |
|
| 470 | + } |
|
| 471 | 471 | |
| 472 | 472 | |
| 473 | - /** |
|
| 474 | - * Handles sending selected registrations/contacts a newsletter. |
|
| 475 | - * |
|
| 476 | - * @since 4.3.0 |
|
| 477 | - * @return void |
|
| 478 | - * @throws EE_Error |
|
| 479 | - * @throws InvalidArgumentException |
|
| 480 | - * @throws InvalidDataTypeException |
|
| 481 | - * @throws InvalidInterfaceException |
|
| 482 | - */ |
|
| 483 | - protected function _newsletter_selected_send() |
|
| 484 | - { |
|
| 485 | - $success = true; |
|
| 486 | - // first we need to make sure we have a GRP_ID so we know what template we're sending and updating! |
|
| 487 | - if (empty($this->_req_data['newsletter_mtp_selected'])) { |
|
| 488 | - EE_Error::add_error( |
|
| 489 | - esc_html__( |
|
| 490 | - 'In order to send a message, a Message Template GRP_ID is needed. It was not provided so messages were not sent.', |
|
| 491 | - 'event_espresso' |
|
| 492 | - ), |
|
| 493 | - __FILE__, |
|
| 494 | - __FUNCTION__, |
|
| 495 | - __LINE__ |
|
| 496 | - ); |
|
| 497 | - $success = false; |
|
| 498 | - } |
|
| 499 | - if ($success) { |
|
| 500 | - // update Message template in case there are any changes |
|
| 501 | - $Message_Template_Group = EEM_Message_Template_Group::instance()->get_one_by_ID( |
|
| 502 | - $this->_req_data['newsletter_mtp_selected'] |
|
| 503 | - ); |
|
| 504 | - $Message_Templates = $Message_Template_Group instanceof EE_Message_Template_Group |
|
| 505 | - ? $Message_Template_Group->context_templates() |
|
| 506 | - : array(); |
|
| 507 | - if (empty($Message_Templates)) { |
|
| 508 | - EE_Error::add_error( |
|
| 509 | - esc_html__( |
|
| 510 | - 'Unable to retrieve message template fields from the db. Messages not sent.', |
|
| 511 | - 'event_espresso' |
|
| 512 | - ), |
|
| 513 | - __FILE__, |
|
| 514 | - __FUNCTION__, |
|
| 515 | - __LINE__ |
|
| 516 | - ); |
|
| 517 | - } |
|
| 518 | - // let's just update the specific fields |
|
| 519 | - foreach ($Message_Templates['attendee'] as $Message_Template) { |
|
| 520 | - if ($Message_Template instanceof EE_Message_Template) { |
|
| 521 | - $field = $Message_Template->get('MTP_template_field'); |
|
| 522 | - $content = $Message_Template->get('MTP_content'); |
|
| 523 | - $new_content = $content; |
|
| 524 | - switch ($field) { |
|
| 525 | - case 'from': |
|
| 526 | - $new_content = ! empty($this->_req_data['batch_message']['from']) |
|
| 527 | - ? $this->_req_data['batch_message']['from'] |
|
| 528 | - : $content; |
|
| 529 | - break; |
|
| 530 | - case 'subject': |
|
| 531 | - $new_content = ! empty($this->_req_data['batch_message']['subject']) |
|
| 532 | - ? $this->_req_data['batch_message']['subject'] |
|
| 533 | - : $content; |
|
| 534 | - break; |
|
| 535 | - case 'content': |
|
| 536 | - $new_content = $content; |
|
| 537 | - $new_content['newsletter_content'] = ! empty($this->_req_data['batch_message']['content']) |
|
| 538 | - ? $this->_req_data['batch_message']['content'] |
|
| 539 | - : $content['newsletter_content']; |
|
| 540 | - break; |
|
| 541 | - default: |
|
| 542 | - // continue the foreach loop, we don't want to set $new_content nor save. |
|
| 543 | - continue 2; |
|
| 544 | - } |
|
| 545 | - $Message_Template->set('MTP_content', $new_content); |
|
| 546 | - $Message_Template->save(); |
|
| 547 | - } |
|
| 548 | - } |
|
| 549 | - // great fields are updated! now let's make sure we just have contact objects (EE_Attendee). |
|
| 550 | - $id_type = ! empty($this->_req_data['batch_message']['id_type']) |
|
| 551 | - ? $this->_req_data['batch_message']['id_type'] |
|
| 552 | - : 'registration'; |
|
| 553 | - // id_type will affect how we assemble the ids. |
|
| 554 | - $ids = ! empty($this->_req_data['batch_message']['ids']) |
|
| 555 | - ? json_decode(stripslashes($this->_req_data['batch_message']['ids'])) |
|
| 556 | - : array(); |
|
| 557 | - $registrations_used_for_contact_data = array(); |
|
| 558 | - // using switch because eventually we'll have other contexts that will be used for generating messages. |
|
| 559 | - switch ($id_type) { |
|
| 560 | - case 'registration': |
|
| 561 | - $registrations_used_for_contact_data = EEM_Registration::instance()->get_all( |
|
| 562 | - array( |
|
| 563 | - array( |
|
| 564 | - 'REG_ID' => array('IN', $ids), |
|
| 565 | - ), |
|
| 566 | - ) |
|
| 567 | - ); |
|
| 568 | - break; |
|
| 569 | - case 'contact': |
|
| 570 | - $registrations_used_for_contact_data = EEM_Registration::instance() |
|
| 571 | - ->get_latest_registration_for_each_of_given_contacts( |
|
| 572 | - $ids |
|
| 573 | - ); |
|
| 574 | - break; |
|
| 575 | - } |
|
| 576 | - do_action_ref_array( |
|
| 577 | - 'AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send__with_registrations', |
|
| 578 | - array( |
|
| 579 | - $registrations_used_for_contact_data, |
|
| 580 | - $Message_Template_Group->ID(), |
|
| 581 | - ) |
|
| 582 | - ); |
|
| 583 | - // kept for backward compat, internally we no longer use this action. |
|
| 584 | - // @deprecated 4.8.36.rc.002 |
|
| 585 | - $contacts = $id_type === 'registration' |
|
| 586 | - ? EEM_Attendee::instance()->get_array_of_contacts_from_reg_ids($ids) |
|
| 587 | - : EEM_Attendee::instance()->get_all(array(array('ATT_ID' => array('in', $ids)))); |
|
| 588 | - do_action_ref_array( |
|
| 589 | - 'AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send', |
|
| 590 | - array( |
|
| 591 | - $contacts, |
|
| 592 | - $Message_Template_Group->ID(), |
|
| 593 | - ) |
|
| 594 | - ); |
|
| 595 | - } |
|
| 596 | - $query_args = array( |
|
| 597 | - 'action' => ! empty($this->_req_data['redirect_back_to']) |
|
| 598 | - ? $this->_req_data['redirect_back_to'] |
|
| 599 | - : 'default', |
|
| 600 | - ); |
|
| 601 | - $this->_redirect_after_action(false, '', '', $query_args, true); |
|
| 602 | - } |
|
| 473 | + /** |
|
| 474 | + * Handles sending selected registrations/contacts a newsletter. |
|
| 475 | + * |
|
| 476 | + * @since 4.3.0 |
|
| 477 | + * @return void |
|
| 478 | + * @throws EE_Error |
|
| 479 | + * @throws InvalidArgumentException |
|
| 480 | + * @throws InvalidDataTypeException |
|
| 481 | + * @throws InvalidInterfaceException |
|
| 482 | + */ |
|
| 483 | + protected function _newsletter_selected_send() |
|
| 484 | + { |
|
| 485 | + $success = true; |
|
| 486 | + // first we need to make sure we have a GRP_ID so we know what template we're sending and updating! |
|
| 487 | + if (empty($this->_req_data['newsletter_mtp_selected'])) { |
|
| 488 | + EE_Error::add_error( |
|
| 489 | + esc_html__( |
|
| 490 | + 'In order to send a message, a Message Template GRP_ID is needed. It was not provided so messages were not sent.', |
|
| 491 | + 'event_espresso' |
|
| 492 | + ), |
|
| 493 | + __FILE__, |
|
| 494 | + __FUNCTION__, |
|
| 495 | + __LINE__ |
|
| 496 | + ); |
|
| 497 | + $success = false; |
|
| 498 | + } |
|
| 499 | + if ($success) { |
|
| 500 | + // update Message template in case there are any changes |
|
| 501 | + $Message_Template_Group = EEM_Message_Template_Group::instance()->get_one_by_ID( |
|
| 502 | + $this->_req_data['newsletter_mtp_selected'] |
|
| 503 | + ); |
|
| 504 | + $Message_Templates = $Message_Template_Group instanceof EE_Message_Template_Group |
|
| 505 | + ? $Message_Template_Group->context_templates() |
|
| 506 | + : array(); |
|
| 507 | + if (empty($Message_Templates)) { |
|
| 508 | + EE_Error::add_error( |
|
| 509 | + esc_html__( |
|
| 510 | + 'Unable to retrieve message template fields from the db. Messages not sent.', |
|
| 511 | + 'event_espresso' |
|
| 512 | + ), |
|
| 513 | + __FILE__, |
|
| 514 | + __FUNCTION__, |
|
| 515 | + __LINE__ |
|
| 516 | + ); |
|
| 517 | + } |
|
| 518 | + // let's just update the specific fields |
|
| 519 | + foreach ($Message_Templates['attendee'] as $Message_Template) { |
|
| 520 | + if ($Message_Template instanceof EE_Message_Template) { |
|
| 521 | + $field = $Message_Template->get('MTP_template_field'); |
|
| 522 | + $content = $Message_Template->get('MTP_content'); |
|
| 523 | + $new_content = $content; |
|
| 524 | + switch ($field) { |
|
| 525 | + case 'from': |
|
| 526 | + $new_content = ! empty($this->_req_data['batch_message']['from']) |
|
| 527 | + ? $this->_req_data['batch_message']['from'] |
|
| 528 | + : $content; |
|
| 529 | + break; |
|
| 530 | + case 'subject': |
|
| 531 | + $new_content = ! empty($this->_req_data['batch_message']['subject']) |
|
| 532 | + ? $this->_req_data['batch_message']['subject'] |
|
| 533 | + : $content; |
|
| 534 | + break; |
|
| 535 | + case 'content': |
|
| 536 | + $new_content = $content; |
|
| 537 | + $new_content['newsletter_content'] = ! empty($this->_req_data['batch_message']['content']) |
|
| 538 | + ? $this->_req_data['batch_message']['content'] |
|
| 539 | + : $content['newsletter_content']; |
|
| 540 | + break; |
|
| 541 | + default: |
|
| 542 | + // continue the foreach loop, we don't want to set $new_content nor save. |
|
| 543 | + continue 2; |
|
| 544 | + } |
|
| 545 | + $Message_Template->set('MTP_content', $new_content); |
|
| 546 | + $Message_Template->save(); |
|
| 547 | + } |
|
| 548 | + } |
|
| 549 | + // great fields are updated! now let's make sure we just have contact objects (EE_Attendee). |
|
| 550 | + $id_type = ! empty($this->_req_data['batch_message']['id_type']) |
|
| 551 | + ? $this->_req_data['batch_message']['id_type'] |
|
| 552 | + : 'registration'; |
|
| 553 | + // id_type will affect how we assemble the ids. |
|
| 554 | + $ids = ! empty($this->_req_data['batch_message']['ids']) |
|
| 555 | + ? json_decode(stripslashes($this->_req_data['batch_message']['ids'])) |
|
| 556 | + : array(); |
|
| 557 | + $registrations_used_for_contact_data = array(); |
|
| 558 | + // using switch because eventually we'll have other contexts that will be used for generating messages. |
|
| 559 | + switch ($id_type) { |
|
| 560 | + case 'registration': |
|
| 561 | + $registrations_used_for_contact_data = EEM_Registration::instance()->get_all( |
|
| 562 | + array( |
|
| 563 | + array( |
|
| 564 | + 'REG_ID' => array('IN', $ids), |
|
| 565 | + ), |
|
| 566 | + ) |
|
| 567 | + ); |
|
| 568 | + break; |
|
| 569 | + case 'contact': |
|
| 570 | + $registrations_used_for_contact_data = EEM_Registration::instance() |
|
| 571 | + ->get_latest_registration_for_each_of_given_contacts( |
|
| 572 | + $ids |
|
| 573 | + ); |
|
| 574 | + break; |
|
| 575 | + } |
|
| 576 | + do_action_ref_array( |
|
| 577 | + 'AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send__with_registrations', |
|
| 578 | + array( |
|
| 579 | + $registrations_used_for_contact_data, |
|
| 580 | + $Message_Template_Group->ID(), |
|
| 581 | + ) |
|
| 582 | + ); |
|
| 583 | + // kept for backward compat, internally we no longer use this action. |
|
| 584 | + // @deprecated 4.8.36.rc.002 |
|
| 585 | + $contacts = $id_type === 'registration' |
|
| 586 | + ? EEM_Attendee::instance()->get_array_of_contacts_from_reg_ids($ids) |
|
| 587 | + : EEM_Attendee::instance()->get_all(array(array('ATT_ID' => array('in', $ids)))); |
|
| 588 | + do_action_ref_array( |
|
| 589 | + 'AHEE__Extend_Registrations_Admin_Page___newsletter_selected_send', |
|
| 590 | + array( |
|
| 591 | + $contacts, |
|
| 592 | + $Message_Template_Group->ID(), |
|
| 593 | + ) |
|
| 594 | + ); |
|
| 595 | + } |
|
| 596 | + $query_args = array( |
|
| 597 | + 'action' => ! empty($this->_req_data['redirect_back_to']) |
|
| 598 | + ? $this->_req_data['redirect_back_to'] |
|
| 599 | + : 'default', |
|
| 600 | + ); |
|
| 601 | + $this->_redirect_after_action(false, '', '', $query_args, true); |
|
| 602 | + } |
|
| 603 | 603 | |
| 604 | 604 | |
| 605 | - /** |
|
| 606 | - * This is called when javascript is being enqueued to setup the various data needed for the reports js. |
|
| 607 | - * Also $this->{$_reports_template_data} property is set for later usage by the _registration_reports method. |
|
| 608 | - */ |
|
| 609 | - protected function _registration_reports_js_setup() |
|
| 610 | - { |
|
| 611 | - $this->_reports_template_data['admin_reports'][] = $this->_registrations_per_day_report(); |
|
| 612 | - $this->_reports_template_data['admin_reports'][] = $this->_registrations_per_event_report(); |
|
| 613 | - } |
|
| 605 | + /** |
|
| 606 | + * This is called when javascript is being enqueued to setup the various data needed for the reports js. |
|
| 607 | + * Also $this->{$_reports_template_data} property is set for later usage by the _registration_reports method. |
|
| 608 | + */ |
|
| 609 | + protected function _registration_reports_js_setup() |
|
| 610 | + { |
|
| 611 | + $this->_reports_template_data['admin_reports'][] = $this->_registrations_per_day_report(); |
|
| 612 | + $this->_reports_template_data['admin_reports'][] = $this->_registrations_per_event_report(); |
|
| 613 | + } |
|
| 614 | 614 | |
| 615 | 615 | |
| 616 | - /** |
|
| 617 | - * generates Business Reports regarding Registrations |
|
| 618 | - * |
|
| 619 | - * @access protected |
|
| 620 | - * @return void |
|
| 621 | - * @throws DomainException |
|
| 622 | - */ |
|
| 623 | - protected function _registration_reports() |
|
| 624 | - { |
|
| 625 | - $template_path = EE_ADMIN_TEMPLATE . 'admin_reports.template.php'; |
|
| 626 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 627 | - $template_path, |
|
| 628 | - $this->_reports_template_data, |
|
| 629 | - true |
|
| 630 | - ); |
|
| 631 | - // the final template wrapper |
|
| 632 | - $this->display_admin_page_with_no_sidebar(); |
|
| 633 | - } |
|
| 616 | + /** |
|
| 617 | + * generates Business Reports regarding Registrations |
|
| 618 | + * |
|
| 619 | + * @access protected |
|
| 620 | + * @return void |
|
| 621 | + * @throws DomainException |
|
| 622 | + */ |
|
| 623 | + protected function _registration_reports() |
|
| 624 | + { |
|
| 625 | + $template_path = EE_ADMIN_TEMPLATE . 'admin_reports.template.php'; |
|
| 626 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
| 627 | + $template_path, |
|
| 628 | + $this->_reports_template_data, |
|
| 629 | + true |
|
| 630 | + ); |
|
| 631 | + // the final template wrapper |
|
| 632 | + $this->display_admin_page_with_no_sidebar(); |
|
| 633 | + } |
|
| 634 | 634 | |
| 635 | 635 | |
| 636 | - /** |
|
| 637 | - * Generates Business Report showing total registrations per day. |
|
| 638 | - * |
|
| 639 | - * @param string $period The period (acceptable by PHP Datetime constructor) for which the report is generated. |
|
| 640 | - * @return string |
|
| 641 | - * @throws EE_Error |
|
| 642 | - * @throws InvalidArgumentException |
|
| 643 | - * @throws InvalidDataTypeException |
|
| 644 | - * @throws InvalidInterfaceException |
|
| 645 | - */ |
|
| 646 | - private function _registrations_per_day_report($period = '-1 month') |
|
| 647 | - { |
|
| 648 | - $report_ID = 'reg-admin-registrations-per-day-report-dv'; |
|
| 649 | - $results = EEM_Registration::instance()->get_registrations_per_day_and_per_status_report($period); |
|
| 650 | - $results = (array) $results; |
|
| 651 | - $regs = array(); |
|
| 652 | - $subtitle = ''; |
|
| 653 | - if ($results) { |
|
| 654 | - $column_titles = array(); |
|
| 655 | - $tracker = 0; |
|
| 656 | - foreach ($results as $result) { |
|
| 657 | - $report_column_values = array(); |
|
| 658 | - foreach ($result as $property_name => $property_value) { |
|
| 659 | - $property_value = $property_name === 'Registration_REG_date' ? $property_value |
|
| 660 | - : (int) $property_value; |
|
| 661 | - $report_column_values[] = $property_value; |
|
| 662 | - if ($tracker === 0) { |
|
| 663 | - if ($property_name === 'Registration_REG_date') { |
|
| 664 | - $column_titles[] = esc_html__( |
|
| 665 | - 'Date (only days with registrations are shown)', |
|
| 666 | - 'event_espresso' |
|
| 667 | - ); |
|
| 668 | - } else { |
|
| 669 | - $column_titles[] = EEH_Template::pretty_status($property_name, false, 'sentence'); |
|
| 670 | - } |
|
| 671 | - } |
|
| 672 | - } |
|
| 673 | - $tracker++; |
|
| 674 | - $regs[] = $report_column_values; |
|
| 675 | - } |
|
| 676 | - // make sure the column_titles is pushed to the beginning of the array |
|
| 677 | - array_unshift($regs, $column_titles); |
|
| 678 | - // setup the date range. |
|
| 679 | - $DateTimeZone = new DateTimeZone(EEH_DTT_Helper::get_timezone()); |
|
| 680 | - $beginning_date = new DateTime("now " . $period, $DateTimeZone); |
|
| 681 | - $ending_date = new DateTime("now", $DateTimeZone); |
|
| 682 | - $subtitle = sprintf( |
|
| 683 | - _x('For the period: %1$s to %2$s', 'Used to give date range', 'event_espresso'), |
|
| 684 | - $beginning_date->format('Y-m-d'), |
|
| 685 | - $ending_date->format('Y-m-d') |
|
| 686 | - ); |
|
| 687 | - } |
|
| 688 | - $report_title = esc_html__('Total Registrations per Day', 'event_espresso'); |
|
| 689 | - $report_params = array( |
|
| 690 | - 'title' => $report_title, |
|
| 691 | - 'subtitle' => $subtitle, |
|
| 692 | - 'id' => $report_ID, |
|
| 693 | - 'regs' => $regs, |
|
| 694 | - 'noResults' => empty($regs), |
|
| 695 | - 'noRegsMsg' => sprintf( |
|
| 696 | - esc_html__( |
|
| 697 | - '%sThere are currently no registration records in the last month for this report.%s', |
|
| 698 | - 'event_espresso' |
|
| 699 | - ), |
|
| 700 | - '<h2>' . $report_title . '</h2><p>', |
|
| 701 | - '</p>' |
|
| 702 | - ), |
|
| 703 | - ); |
|
| 704 | - wp_localize_script('ee-reg-reports-js', 'regPerDay', $report_params); |
|
| 705 | - return $report_ID; |
|
| 706 | - } |
|
| 636 | + /** |
|
| 637 | + * Generates Business Report showing total registrations per day. |
|
| 638 | + * |
|
| 639 | + * @param string $period The period (acceptable by PHP Datetime constructor) for which the report is generated. |
|
| 640 | + * @return string |
|
| 641 | + * @throws EE_Error |
|
| 642 | + * @throws InvalidArgumentException |
|
| 643 | + * @throws InvalidDataTypeException |
|
| 644 | + * @throws InvalidInterfaceException |
|
| 645 | + */ |
|
| 646 | + private function _registrations_per_day_report($period = '-1 month') |
|
| 647 | + { |
|
| 648 | + $report_ID = 'reg-admin-registrations-per-day-report-dv'; |
|
| 649 | + $results = EEM_Registration::instance()->get_registrations_per_day_and_per_status_report($period); |
|
| 650 | + $results = (array) $results; |
|
| 651 | + $regs = array(); |
|
| 652 | + $subtitle = ''; |
|
| 653 | + if ($results) { |
|
| 654 | + $column_titles = array(); |
|
| 655 | + $tracker = 0; |
|
| 656 | + foreach ($results as $result) { |
|
| 657 | + $report_column_values = array(); |
|
| 658 | + foreach ($result as $property_name => $property_value) { |
|
| 659 | + $property_value = $property_name === 'Registration_REG_date' ? $property_value |
|
| 660 | + : (int) $property_value; |
|
| 661 | + $report_column_values[] = $property_value; |
|
| 662 | + if ($tracker === 0) { |
|
| 663 | + if ($property_name === 'Registration_REG_date') { |
|
| 664 | + $column_titles[] = esc_html__( |
|
| 665 | + 'Date (only days with registrations are shown)', |
|
| 666 | + 'event_espresso' |
|
| 667 | + ); |
|
| 668 | + } else { |
|
| 669 | + $column_titles[] = EEH_Template::pretty_status($property_name, false, 'sentence'); |
|
| 670 | + } |
|
| 671 | + } |
|
| 672 | + } |
|
| 673 | + $tracker++; |
|
| 674 | + $regs[] = $report_column_values; |
|
| 675 | + } |
|
| 676 | + // make sure the column_titles is pushed to the beginning of the array |
|
| 677 | + array_unshift($regs, $column_titles); |
|
| 678 | + // setup the date range. |
|
| 679 | + $DateTimeZone = new DateTimeZone(EEH_DTT_Helper::get_timezone()); |
|
| 680 | + $beginning_date = new DateTime("now " . $period, $DateTimeZone); |
|
| 681 | + $ending_date = new DateTime("now", $DateTimeZone); |
|
| 682 | + $subtitle = sprintf( |
|
| 683 | + _x('For the period: %1$s to %2$s', 'Used to give date range', 'event_espresso'), |
|
| 684 | + $beginning_date->format('Y-m-d'), |
|
| 685 | + $ending_date->format('Y-m-d') |
|
| 686 | + ); |
|
| 687 | + } |
|
| 688 | + $report_title = esc_html__('Total Registrations per Day', 'event_espresso'); |
|
| 689 | + $report_params = array( |
|
| 690 | + 'title' => $report_title, |
|
| 691 | + 'subtitle' => $subtitle, |
|
| 692 | + 'id' => $report_ID, |
|
| 693 | + 'regs' => $regs, |
|
| 694 | + 'noResults' => empty($regs), |
|
| 695 | + 'noRegsMsg' => sprintf( |
|
| 696 | + esc_html__( |
|
| 697 | + '%sThere are currently no registration records in the last month for this report.%s', |
|
| 698 | + 'event_espresso' |
|
| 699 | + ), |
|
| 700 | + '<h2>' . $report_title . '</h2><p>', |
|
| 701 | + '</p>' |
|
| 702 | + ), |
|
| 703 | + ); |
|
| 704 | + wp_localize_script('ee-reg-reports-js', 'regPerDay', $report_params); |
|
| 705 | + return $report_ID; |
|
| 706 | + } |
|
| 707 | 707 | |
| 708 | 708 | |
| 709 | - /** |
|
| 710 | - * Generates Business Report showing total registrations per event. |
|
| 711 | - * |
|
| 712 | - * @param string $period The period (acceptable by PHP Datetime constructor) for which the report is generated. |
|
| 713 | - * @return string |
|
| 714 | - * @throws EE_Error |
|
| 715 | - * @throws InvalidArgumentException |
|
| 716 | - * @throws InvalidDataTypeException |
|
| 717 | - * @throws InvalidInterfaceException |
|
| 718 | - */ |
|
| 719 | - private function _registrations_per_event_report($period = '-1 month') |
|
| 720 | - { |
|
| 721 | - $report_ID = 'reg-admin-registrations-per-event-report-dv'; |
|
| 722 | - $results = EEM_Registration::instance()->get_registrations_per_event_and_per_status_report($period); |
|
| 723 | - $results = (array) $results; |
|
| 724 | - $regs = array(); |
|
| 725 | - $subtitle = ''; |
|
| 726 | - if ($results) { |
|
| 727 | - $column_titles = array(); |
|
| 728 | - $tracker = 0; |
|
| 729 | - foreach ($results as $result) { |
|
| 730 | - $report_column_values = array(); |
|
| 731 | - foreach ($result as $property_name => $property_value) { |
|
| 732 | - $property_value = $property_name === 'Registration_Event' ? wp_trim_words( |
|
| 733 | - $property_value, |
|
| 734 | - 4, |
|
| 735 | - '...' |
|
| 736 | - ) : (int) $property_value; |
|
| 737 | - $report_column_values[] = $property_value; |
|
| 738 | - if ($tracker === 0) { |
|
| 739 | - if ($property_name === 'Registration_Event') { |
|
| 740 | - $column_titles[] = esc_html__('Event', 'event_espresso'); |
|
| 741 | - } else { |
|
| 742 | - $column_titles[] = EEH_Template::pretty_status($property_name, false, 'sentence'); |
|
| 743 | - } |
|
| 744 | - } |
|
| 745 | - } |
|
| 746 | - $tracker++; |
|
| 747 | - $regs[] = $report_column_values; |
|
| 748 | - } |
|
| 749 | - // make sure the column_titles is pushed to the beginning of the array |
|
| 750 | - array_unshift($regs, $column_titles); |
|
| 751 | - // setup the date range. |
|
| 752 | - $DateTimeZone = new DateTimeZone(EEH_DTT_Helper::get_timezone()); |
|
| 753 | - $beginning_date = new DateTime("now " . $period, $DateTimeZone); |
|
| 754 | - $ending_date = new DateTime("now", $DateTimeZone); |
|
| 755 | - $subtitle = sprintf( |
|
| 756 | - _x('For the period: %1$s to %2$s', 'Used to give date range', 'event_espresso'), |
|
| 757 | - $beginning_date->format('Y-m-d'), |
|
| 758 | - $ending_date->format('Y-m-d') |
|
| 759 | - ); |
|
| 760 | - } |
|
| 761 | - $report_title = esc_html__('Total Registrations per Event', 'event_espresso'); |
|
| 762 | - $report_params = array( |
|
| 763 | - 'title' => $report_title, |
|
| 764 | - 'subtitle' => $subtitle, |
|
| 765 | - 'id' => $report_ID, |
|
| 766 | - 'regs' => $regs, |
|
| 767 | - 'noResults' => empty($regs), |
|
| 768 | - 'noRegsMsg' => sprintf( |
|
| 769 | - esc_html__( |
|
| 770 | - '%sThere are currently no registration records in the last month for this report.%s', |
|
| 771 | - 'event_espresso' |
|
| 772 | - ), |
|
| 773 | - '<h2>' . $report_title . '</h2><p>', |
|
| 774 | - '</p>' |
|
| 775 | - ), |
|
| 776 | - ); |
|
| 777 | - wp_localize_script('ee-reg-reports-js', 'regPerEvent', $report_params); |
|
| 778 | - return $report_ID; |
|
| 779 | - } |
|
| 709 | + /** |
|
| 710 | + * Generates Business Report showing total registrations per event. |
|
| 711 | + * |
|
| 712 | + * @param string $period The period (acceptable by PHP Datetime constructor) for which the report is generated. |
|
| 713 | + * @return string |
|
| 714 | + * @throws EE_Error |
|
| 715 | + * @throws InvalidArgumentException |
|
| 716 | + * @throws InvalidDataTypeException |
|
| 717 | + * @throws InvalidInterfaceException |
|
| 718 | + */ |
|
| 719 | + private function _registrations_per_event_report($period = '-1 month') |
|
| 720 | + { |
|
| 721 | + $report_ID = 'reg-admin-registrations-per-event-report-dv'; |
|
| 722 | + $results = EEM_Registration::instance()->get_registrations_per_event_and_per_status_report($period); |
|
| 723 | + $results = (array) $results; |
|
| 724 | + $regs = array(); |
|
| 725 | + $subtitle = ''; |
|
| 726 | + if ($results) { |
|
| 727 | + $column_titles = array(); |
|
| 728 | + $tracker = 0; |
|
| 729 | + foreach ($results as $result) { |
|
| 730 | + $report_column_values = array(); |
|
| 731 | + foreach ($result as $property_name => $property_value) { |
|
| 732 | + $property_value = $property_name === 'Registration_Event' ? wp_trim_words( |
|
| 733 | + $property_value, |
|
| 734 | + 4, |
|
| 735 | + '...' |
|
| 736 | + ) : (int) $property_value; |
|
| 737 | + $report_column_values[] = $property_value; |
|
| 738 | + if ($tracker === 0) { |
|
| 739 | + if ($property_name === 'Registration_Event') { |
|
| 740 | + $column_titles[] = esc_html__('Event', 'event_espresso'); |
|
| 741 | + } else { |
|
| 742 | + $column_titles[] = EEH_Template::pretty_status($property_name, false, 'sentence'); |
|
| 743 | + } |
|
| 744 | + } |
|
| 745 | + } |
|
| 746 | + $tracker++; |
|
| 747 | + $regs[] = $report_column_values; |
|
| 748 | + } |
|
| 749 | + // make sure the column_titles is pushed to the beginning of the array |
|
| 750 | + array_unshift($regs, $column_titles); |
|
| 751 | + // setup the date range. |
|
| 752 | + $DateTimeZone = new DateTimeZone(EEH_DTT_Helper::get_timezone()); |
|
| 753 | + $beginning_date = new DateTime("now " . $period, $DateTimeZone); |
|
| 754 | + $ending_date = new DateTime("now", $DateTimeZone); |
|
| 755 | + $subtitle = sprintf( |
|
| 756 | + _x('For the period: %1$s to %2$s', 'Used to give date range', 'event_espresso'), |
|
| 757 | + $beginning_date->format('Y-m-d'), |
|
| 758 | + $ending_date->format('Y-m-d') |
|
| 759 | + ); |
|
| 760 | + } |
|
| 761 | + $report_title = esc_html__('Total Registrations per Event', 'event_espresso'); |
|
| 762 | + $report_params = array( |
|
| 763 | + 'title' => $report_title, |
|
| 764 | + 'subtitle' => $subtitle, |
|
| 765 | + 'id' => $report_ID, |
|
| 766 | + 'regs' => $regs, |
|
| 767 | + 'noResults' => empty($regs), |
|
| 768 | + 'noRegsMsg' => sprintf( |
|
| 769 | + esc_html__( |
|
| 770 | + '%sThere are currently no registration records in the last month for this report.%s', |
|
| 771 | + 'event_espresso' |
|
| 772 | + ), |
|
| 773 | + '<h2>' . $report_title . '</h2><p>', |
|
| 774 | + '</p>' |
|
| 775 | + ), |
|
| 776 | + ); |
|
| 777 | + wp_localize_script('ee-reg-reports-js', 'regPerEvent', $report_params); |
|
| 778 | + return $report_ID; |
|
| 779 | + } |
|
| 780 | 780 | |
| 781 | 781 | |
| 782 | - /** |
|
| 783 | - * generates HTML for the Registration Check-in list table (showing all Check-ins for a specific registration) |
|
| 784 | - * |
|
| 785 | - * @access protected |
|
| 786 | - * @return void |
|
| 787 | - * @throws EE_Error |
|
| 788 | - * @throws InvalidArgumentException |
|
| 789 | - * @throws InvalidDataTypeException |
|
| 790 | - * @throws InvalidInterfaceException |
|
| 791 | - * @throws \EventEspresso\core\exceptions\EntityNotFoundException |
|
| 792 | - */ |
|
| 793 | - protected function _registration_checkin_list_table() |
|
| 794 | - { |
|
| 795 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 796 | - $reg_id = isset($this->_req_data['_REG_ID']) ? $this->_req_data['_REG_ID'] : null; |
|
| 797 | - /** @var EE_Registration $registration */ |
|
| 798 | - $registration = EEM_Registration::instance()->get_one_by_ID($reg_id); |
|
| 799 | - if (! $registration instanceof EE_Registration) { |
|
| 800 | - throw new EE_Error( |
|
| 801 | - sprintf( |
|
| 802 | - esc_html__('An error occurred. There is no registration with ID (%d)', 'event_espresso'), |
|
| 803 | - $reg_id |
|
| 804 | - ) |
|
| 805 | - ); |
|
| 806 | - } |
|
| 807 | - $attendee = $registration->attendee(); |
|
| 808 | - $this->_admin_page_title .= $this->get_action_link_or_button( |
|
| 809 | - 'new_registration', |
|
| 810 | - 'add-registrant', |
|
| 811 | - array('event_id' => $registration->event_ID()), |
|
| 812 | - 'add-new-h2' |
|
| 813 | - ); |
|
| 814 | - $checked_in = new CheckinStatusDashicon(EE_Checkin::status_checked_in); |
|
| 815 | - $checked_out = new CheckinStatusDashicon(EE_Checkin::status_checked_out); |
|
| 816 | - $legend_items = array( |
|
| 817 | - 'checkin' => array( |
|
| 818 | - 'class' => $checked_in->cssClasses(), |
|
| 819 | - 'desc' => $checked_in->legendLabel(), |
|
| 820 | - ), |
|
| 821 | - 'checkout' => array( |
|
| 822 | - 'class' => $checked_out->cssClasses(), |
|
| 823 | - 'desc' => $checked_out->legendLabel(), |
|
| 824 | - ), |
|
| 825 | - ); |
|
| 826 | - $this->_template_args['after_list_table'] = $this->_display_legend($legend_items); |
|
| 827 | - $dtt_id = isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : null; |
|
| 828 | - /** @var EE_Datetime $datetime */ |
|
| 829 | - $datetime = EEM_Datetime::instance()->get_one_by_ID($dtt_id); |
|
| 830 | - $datetime_label = ''; |
|
| 831 | - if ($datetime instanceof EE_Datetime) { |
|
| 832 | - $datetime_label = $datetime->get_dtt_display_name(true); |
|
| 833 | - $datetime_label .= ! empty($datetime_label) |
|
| 834 | - ? ' (' . $datetime->get_dtt_display_name() . ')' |
|
| 835 | - : $datetime->get_dtt_display_name(); |
|
| 836 | - } |
|
| 837 | - $datetime_link = ! empty($dtt_id) && $registration instanceof EE_Registration |
|
| 838 | - ? EE_Admin_Page::add_query_args_and_nonce( |
|
| 839 | - array( |
|
| 840 | - 'action' => 'event_registrations', |
|
| 841 | - 'event_id' => $registration->event_ID(), |
|
| 842 | - 'DTT_ID' => $dtt_id, |
|
| 843 | - ), |
|
| 844 | - $this->_admin_base_url |
|
| 845 | - ) |
|
| 846 | - : ''; |
|
| 847 | - $datetime_link = ! empty($datetime_link) |
|
| 848 | - ? '<a href="' . $datetime_link . '">' |
|
| 849 | - . '<span id="checkin-dtt">' |
|
| 850 | - . $datetime_label |
|
| 851 | - . '</span></a>' |
|
| 852 | - : $datetime_label; |
|
| 853 | - $attendee_name = $attendee instanceof EE_Attendee |
|
| 854 | - ? $attendee->full_name() |
|
| 855 | - : ''; |
|
| 856 | - $attendee_link = $attendee instanceof EE_Attendee |
|
| 857 | - ? $attendee->get_admin_details_link() |
|
| 858 | - : ''; |
|
| 859 | - $attendee_link = ! empty($attendee_link) |
|
| 860 | - ? '<a href="' . $attendee->get_admin_details_link() . '"' |
|
| 861 | - . ' title="' . esc_html__('Click for attendee details', 'event_espresso') . '">' |
|
| 862 | - . '<span id="checkin-attendee-name">' |
|
| 863 | - . $attendee_name |
|
| 864 | - . '</span></a>' |
|
| 865 | - : ''; |
|
| 866 | - $event_link = $registration->event() instanceof EE_Event |
|
| 867 | - ? $registration->event()->get_admin_details_link() |
|
| 868 | - : ''; |
|
| 869 | - $event_link = ! empty($event_link) |
|
| 870 | - ? '<a href="' . $event_link . '"' |
|
| 871 | - . ' title="' . esc_html__('Click here to edit event.', 'event_espresso') . '">' |
|
| 872 | - . '<span id="checkin-event-name">' |
|
| 873 | - . $registration->event_name() |
|
| 874 | - . '</span>' |
|
| 875 | - . '</a>' |
|
| 876 | - : ''; |
|
| 877 | - $this->_template_args['before_list_table'] = ! empty($reg_id) && ! empty($dtt_id) |
|
| 878 | - ? '<h2>' . sprintf( |
|
| 879 | - esc_html__('Displaying check in records for %1$s for %2$s at the event, %3$s', 'event_espresso'), |
|
| 880 | - $attendee_link, |
|
| 881 | - $datetime_link, |
|
| 882 | - $event_link |
|
| 883 | - ) . '</h2>' |
|
| 884 | - : ''; |
|
| 885 | - $this->_template_args['list_table_hidden_fields'] = ! empty($reg_id) |
|
| 886 | - ? '<input type="hidden" name="_REG_ID" value="' . $reg_id . '">' : ''; |
|
| 887 | - $this->_template_args['list_table_hidden_fields'] .= ! empty($dtt_id) |
|
| 888 | - ? '<input type="hidden" name="DTT_ID" value="' . $dtt_id . '">' : ''; |
|
| 889 | - $this->display_admin_list_table_page_with_no_sidebar(); |
|
| 890 | - } |
|
| 782 | + /** |
|
| 783 | + * generates HTML for the Registration Check-in list table (showing all Check-ins for a specific registration) |
|
| 784 | + * |
|
| 785 | + * @access protected |
|
| 786 | + * @return void |
|
| 787 | + * @throws EE_Error |
|
| 788 | + * @throws InvalidArgumentException |
|
| 789 | + * @throws InvalidDataTypeException |
|
| 790 | + * @throws InvalidInterfaceException |
|
| 791 | + * @throws \EventEspresso\core\exceptions\EntityNotFoundException |
|
| 792 | + */ |
|
| 793 | + protected function _registration_checkin_list_table() |
|
| 794 | + { |
|
| 795 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 796 | + $reg_id = isset($this->_req_data['_REG_ID']) ? $this->_req_data['_REG_ID'] : null; |
|
| 797 | + /** @var EE_Registration $registration */ |
|
| 798 | + $registration = EEM_Registration::instance()->get_one_by_ID($reg_id); |
|
| 799 | + if (! $registration instanceof EE_Registration) { |
|
| 800 | + throw new EE_Error( |
|
| 801 | + sprintf( |
|
| 802 | + esc_html__('An error occurred. There is no registration with ID (%d)', 'event_espresso'), |
|
| 803 | + $reg_id |
|
| 804 | + ) |
|
| 805 | + ); |
|
| 806 | + } |
|
| 807 | + $attendee = $registration->attendee(); |
|
| 808 | + $this->_admin_page_title .= $this->get_action_link_or_button( |
|
| 809 | + 'new_registration', |
|
| 810 | + 'add-registrant', |
|
| 811 | + array('event_id' => $registration->event_ID()), |
|
| 812 | + 'add-new-h2' |
|
| 813 | + ); |
|
| 814 | + $checked_in = new CheckinStatusDashicon(EE_Checkin::status_checked_in); |
|
| 815 | + $checked_out = new CheckinStatusDashicon(EE_Checkin::status_checked_out); |
|
| 816 | + $legend_items = array( |
|
| 817 | + 'checkin' => array( |
|
| 818 | + 'class' => $checked_in->cssClasses(), |
|
| 819 | + 'desc' => $checked_in->legendLabel(), |
|
| 820 | + ), |
|
| 821 | + 'checkout' => array( |
|
| 822 | + 'class' => $checked_out->cssClasses(), |
|
| 823 | + 'desc' => $checked_out->legendLabel(), |
|
| 824 | + ), |
|
| 825 | + ); |
|
| 826 | + $this->_template_args['after_list_table'] = $this->_display_legend($legend_items); |
|
| 827 | + $dtt_id = isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : null; |
|
| 828 | + /** @var EE_Datetime $datetime */ |
|
| 829 | + $datetime = EEM_Datetime::instance()->get_one_by_ID($dtt_id); |
|
| 830 | + $datetime_label = ''; |
|
| 831 | + if ($datetime instanceof EE_Datetime) { |
|
| 832 | + $datetime_label = $datetime->get_dtt_display_name(true); |
|
| 833 | + $datetime_label .= ! empty($datetime_label) |
|
| 834 | + ? ' (' . $datetime->get_dtt_display_name() . ')' |
|
| 835 | + : $datetime->get_dtt_display_name(); |
|
| 836 | + } |
|
| 837 | + $datetime_link = ! empty($dtt_id) && $registration instanceof EE_Registration |
|
| 838 | + ? EE_Admin_Page::add_query_args_and_nonce( |
|
| 839 | + array( |
|
| 840 | + 'action' => 'event_registrations', |
|
| 841 | + 'event_id' => $registration->event_ID(), |
|
| 842 | + 'DTT_ID' => $dtt_id, |
|
| 843 | + ), |
|
| 844 | + $this->_admin_base_url |
|
| 845 | + ) |
|
| 846 | + : ''; |
|
| 847 | + $datetime_link = ! empty($datetime_link) |
|
| 848 | + ? '<a href="' . $datetime_link . '">' |
|
| 849 | + . '<span id="checkin-dtt">' |
|
| 850 | + . $datetime_label |
|
| 851 | + . '</span></a>' |
|
| 852 | + : $datetime_label; |
|
| 853 | + $attendee_name = $attendee instanceof EE_Attendee |
|
| 854 | + ? $attendee->full_name() |
|
| 855 | + : ''; |
|
| 856 | + $attendee_link = $attendee instanceof EE_Attendee |
|
| 857 | + ? $attendee->get_admin_details_link() |
|
| 858 | + : ''; |
|
| 859 | + $attendee_link = ! empty($attendee_link) |
|
| 860 | + ? '<a href="' . $attendee->get_admin_details_link() . '"' |
|
| 861 | + . ' title="' . esc_html__('Click for attendee details', 'event_espresso') . '">' |
|
| 862 | + . '<span id="checkin-attendee-name">' |
|
| 863 | + . $attendee_name |
|
| 864 | + . '</span></a>' |
|
| 865 | + : ''; |
|
| 866 | + $event_link = $registration->event() instanceof EE_Event |
|
| 867 | + ? $registration->event()->get_admin_details_link() |
|
| 868 | + : ''; |
|
| 869 | + $event_link = ! empty($event_link) |
|
| 870 | + ? '<a href="' . $event_link . '"' |
|
| 871 | + . ' title="' . esc_html__('Click here to edit event.', 'event_espresso') . '">' |
|
| 872 | + . '<span id="checkin-event-name">' |
|
| 873 | + . $registration->event_name() |
|
| 874 | + . '</span>' |
|
| 875 | + . '</a>' |
|
| 876 | + : ''; |
|
| 877 | + $this->_template_args['before_list_table'] = ! empty($reg_id) && ! empty($dtt_id) |
|
| 878 | + ? '<h2>' . sprintf( |
|
| 879 | + esc_html__('Displaying check in records for %1$s for %2$s at the event, %3$s', 'event_espresso'), |
|
| 880 | + $attendee_link, |
|
| 881 | + $datetime_link, |
|
| 882 | + $event_link |
|
| 883 | + ) . '</h2>' |
|
| 884 | + : ''; |
|
| 885 | + $this->_template_args['list_table_hidden_fields'] = ! empty($reg_id) |
|
| 886 | + ? '<input type="hidden" name="_REG_ID" value="' . $reg_id . '">' : ''; |
|
| 887 | + $this->_template_args['list_table_hidden_fields'] .= ! empty($dtt_id) |
|
| 888 | + ? '<input type="hidden" name="DTT_ID" value="' . $dtt_id . '">' : ''; |
|
| 889 | + $this->display_admin_list_table_page_with_no_sidebar(); |
|
| 890 | + } |
|
| 891 | 891 | |
| 892 | 892 | |
| 893 | - /** |
|
| 894 | - * toggle the Check-in status for the given registration (coming from ajax) |
|
| 895 | - * |
|
| 896 | - * @return void (JSON) |
|
| 897 | - * @throws EE_Error |
|
| 898 | - * @throws InvalidArgumentException |
|
| 899 | - * @throws InvalidDataTypeException |
|
| 900 | - * @throws InvalidInterfaceException |
|
| 901 | - */ |
|
| 902 | - public function toggle_checkin_status() |
|
| 903 | - { |
|
| 904 | - // first make sure we have the necessary data |
|
| 905 | - if (! isset($this->_req_data['_regid'])) { |
|
| 906 | - EE_Error::add_error( |
|
| 907 | - esc_html__( |
|
| 908 | - 'There must be something broken with the html structure because the required data for toggling the Check-in status is not being sent via ajax', |
|
| 909 | - 'event_espresso' |
|
| 910 | - ), |
|
| 911 | - __FILE__, |
|
| 912 | - __FUNCTION__, |
|
| 913 | - __LINE__ |
|
| 914 | - ); |
|
| 915 | - $this->_template_args['success'] = false; |
|
| 916 | - $this->_template_args['error'] = true; |
|
| 917 | - $this->_return_json(); |
|
| 918 | - }; |
|
| 919 | - // do a nonce check cause we're not coming in from an normal route here. |
|
| 920 | - $nonce = isset($this->_req_data['checkinnonce']) ? sanitize_text_field($this->_req_data['checkinnonce']) |
|
| 921 | - : ''; |
|
| 922 | - $nonce_ref = 'checkin_nonce'; |
|
| 923 | - $this->_verify_nonce($nonce, $nonce_ref); |
|
| 924 | - // beautiful! Made it this far so let's get the status. |
|
| 925 | - $new_status = new CheckinStatusDashicon($this->_toggle_checkin_status()); |
|
| 926 | - // setup new class to return via ajax |
|
| 927 | - $this->_template_args['admin_page_content'] = 'clickable trigger-checkin ' . $new_status->cssClasses(); |
|
| 928 | - $this->_template_args['success'] = true; |
|
| 929 | - $this->_return_json(); |
|
| 930 | - } |
|
| 893 | + /** |
|
| 894 | + * toggle the Check-in status for the given registration (coming from ajax) |
|
| 895 | + * |
|
| 896 | + * @return void (JSON) |
|
| 897 | + * @throws EE_Error |
|
| 898 | + * @throws InvalidArgumentException |
|
| 899 | + * @throws InvalidDataTypeException |
|
| 900 | + * @throws InvalidInterfaceException |
|
| 901 | + */ |
|
| 902 | + public function toggle_checkin_status() |
|
| 903 | + { |
|
| 904 | + // first make sure we have the necessary data |
|
| 905 | + if (! isset($this->_req_data['_regid'])) { |
|
| 906 | + EE_Error::add_error( |
|
| 907 | + esc_html__( |
|
| 908 | + 'There must be something broken with the html structure because the required data for toggling the Check-in status is not being sent via ajax', |
|
| 909 | + 'event_espresso' |
|
| 910 | + ), |
|
| 911 | + __FILE__, |
|
| 912 | + __FUNCTION__, |
|
| 913 | + __LINE__ |
|
| 914 | + ); |
|
| 915 | + $this->_template_args['success'] = false; |
|
| 916 | + $this->_template_args['error'] = true; |
|
| 917 | + $this->_return_json(); |
|
| 918 | + }; |
|
| 919 | + // do a nonce check cause we're not coming in from an normal route here. |
|
| 920 | + $nonce = isset($this->_req_data['checkinnonce']) ? sanitize_text_field($this->_req_data['checkinnonce']) |
|
| 921 | + : ''; |
|
| 922 | + $nonce_ref = 'checkin_nonce'; |
|
| 923 | + $this->_verify_nonce($nonce, $nonce_ref); |
|
| 924 | + // beautiful! Made it this far so let's get the status. |
|
| 925 | + $new_status = new CheckinStatusDashicon($this->_toggle_checkin_status()); |
|
| 926 | + // setup new class to return via ajax |
|
| 927 | + $this->_template_args['admin_page_content'] = 'clickable trigger-checkin ' . $new_status->cssClasses(); |
|
| 928 | + $this->_template_args['success'] = true; |
|
| 929 | + $this->_return_json(); |
|
| 930 | + } |
|
| 931 | 931 | |
| 932 | 932 | |
| 933 | - /** |
|
| 934 | - * handles toggling the checkin status for the registration, |
|
| 935 | - * |
|
| 936 | - * @access protected |
|
| 937 | - * @return int|void |
|
| 938 | - * @throws EE_Error |
|
| 939 | - * @throws InvalidArgumentException |
|
| 940 | - * @throws InvalidDataTypeException |
|
| 941 | - * @throws InvalidInterfaceException |
|
| 942 | - */ |
|
| 943 | - protected function _toggle_checkin_status() |
|
| 944 | - { |
|
| 945 | - // first let's get the query args out of the way for the redirect |
|
| 946 | - $query_args = array( |
|
| 947 | - 'action' => 'event_registrations', |
|
| 948 | - 'event_id' => isset($this->_req_data['event_id']) ? $this->_req_data['event_id'] : null, |
|
| 949 | - 'DTT_ID' => isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : null, |
|
| 950 | - ); |
|
| 951 | - $new_status = false; |
|
| 952 | - // bulk action check in toggle |
|
| 953 | - if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
| 954 | - // cycle thru checkboxes |
|
| 955 | - while (list($REG_ID, $value) = each($this->_req_data['checkbox'])) { |
|
| 956 | - $DTT_ID = isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : null; |
|
| 957 | - $new_status = $this->_toggle_checkin($REG_ID, $DTT_ID); |
|
| 958 | - } |
|
| 959 | - } elseif (isset($this->_req_data['_regid'])) { |
|
| 960 | - // coming from ajax request |
|
| 961 | - $DTT_ID = isset($this->_req_data['dttid']) ? $this->_req_data['dttid'] : null; |
|
| 962 | - $query_args['DTT_ID'] = $DTT_ID; |
|
| 963 | - $new_status = $this->_toggle_checkin($this->_req_data['_regid'], $DTT_ID); |
|
| 964 | - } else { |
|
| 965 | - EE_Error::add_error( |
|
| 966 | - esc_html__('Missing some required data to toggle the Check-in', 'event_espresso'), |
|
| 967 | - __FILE__, |
|
| 968 | - __FUNCTION__, |
|
| 969 | - __LINE__ |
|
| 970 | - ); |
|
| 971 | - } |
|
| 972 | - if (defined('DOING_AJAX')) { |
|
| 973 | - return $new_status; |
|
| 974 | - } |
|
| 975 | - $this->_redirect_after_action(false, '', '', $query_args, true); |
|
| 976 | - } |
|
| 933 | + /** |
|
| 934 | + * handles toggling the checkin status for the registration, |
|
| 935 | + * |
|
| 936 | + * @access protected |
|
| 937 | + * @return int|void |
|
| 938 | + * @throws EE_Error |
|
| 939 | + * @throws InvalidArgumentException |
|
| 940 | + * @throws InvalidDataTypeException |
|
| 941 | + * @throws InvalidInterfaceException |
|
| 942 | + */ |
|
| 943 | + protected function _toggle_checkin_status() |
|
| 944 | + { |
|
| 945 | + // first let's get the query args out of the way for the redirect |
|
| 946 | + $query_args = array( |
|
| 947 | + 'action' => 'event_registrations', |
|
| 948 | + 'event_id' => isset($this->_req_data['event_id']) ? $this->_req_data['event_id'] : null, |
|
| 949 | + 'DTT_ID' => isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : null, |
|
| 950 | + ); |
|
| 951 | + $new_status = false; |
|
| 952 | + // bulk action check in toggle |
|
| 953 | + if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
| 954 | + // cycle thru checkboxes |
|
| 955 | + while (list($REG_ID, $value) = each($this->_req_data['checkbox'])) { |
|
| 956 | + $DTT_ID = isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : null; |
|
| 957 | + $new_status = $this->_toggle_checkin($REG_ID, $DTT_ID); |
|
| 958 | + } |
|
| 959 | + } elseif (isset($this->_req_data['_regid'])) { |
|
| 960 | + // coming from ajax request |
|
| 961 | + $DTT_ID = isset($this->_req_data['dttid']) ? $this->_req_data['dttid'] : null; |
|
| 962 | + $query_args['DTT_ID'] = $DTT_ID; |
|
| 963 | + $new_status = $this->_toggle_checkin($this->_req_data['_regid'], $DTT_ID); |
|
| 964 | + } else { |
|
| 965 | + EE_Error::add_error( |
|
| 966 | + esc_html__('Missing some required data to toggle the Check-in', 'event_espresso'), |
|
| 967 | + __FILE__, |
|
| 968 | + __FUNCTION__, |
|
| 969 | + __LINE__ |
|
| 970 | + ); |
|
| 971 | + } |
|
| 972 | + if (defined('DOING_AJAX')) { |
|
| 973 | + return $new_status; |
|
| 974 | + } |
|
| 975 | + $this->_redirect_after_action(false, '', '', $query_args, true); |
|
| 976 | + } |
|
| 977 | 977 | |
| 978 | 978 | |
| 979 | - /** |
|
| 980 | - * This is toggles a single Check-in for the given registration and datetime. |
|
| 981 | - * |
|
| 982 | - * @param int $REG_ID The registration we're toggling |
|
| 983 | - * @param int $DTT_ID The datetime we're toggling |
|
| 984 | - * @return int The new status toggled to. |
|
| 985 | - * @throws EE_Error |
|
| 986 | - * @throws InvalidArgumentException |
|
| 987 | - * @throws InvalidDataTypeException |
|
| 988 | - * @throws InvalidInterfaceException |
|
| 989 | - */ |
|
| 990 | - private function _toggle_checkin($REG_ID, $DTT_ID) |
|
| 991 | - { |
|
| 992 | - /** @var EE_Registration $REG */ |
|
| 993 | - $REG = EEM_Registration::instance()->get_one_by_ID($REG_ID); |
|
| 994 | - $new_status = $REG->toggle_checkin_status($DTT_ID); |
|
| 995 | - if ($new_status !== false) { |
|
| 996 | - EE_Error::add_success($REG->get_checkin_msg($DTT_ID)); |
|
| 997 | - } else { |
|
| 998 | - EE_Error::add_error($REG->get_checkin_msg($DTT_ID, true), __FILE__, __FUNCTION__, __LINE__); |
|
| 999 | - $new_status = false; |
|
| 1000 | - } |
|
| 1001 | - return $new_status; |
|
| 1002 | - } |
|
| 979 | + /** |
|
| 980 | + * This is toggles a single Check-in for the given registration and datetime. |
|
| 981 | + * |
|
| 982 | + * @param int $REG_ID The registration we're toggling |
|
| 983 | + * @param int $DTT_ID The datetime we're toggling |
|
| 984 | + * @return int The new status toggled to. |
|
| 985 | + * @throws EE_Error |
|
| 986 | + * @throws InvalidArgumentException |
|
| 987 | + * @throws InvalidDataTypeException |
|
| 988 | + * @throws InvalidInterfaceException |
|
| 989 | + */ |
|
| 990 | + private function _toggle_checkin($REG_ID, $DTT_ID) |
|
| 991 | + { |
|
| 992 | + /** @var EE_Registration $REG */ |
|
| 993 | + $REG = EEM_Registration::instance()->get_one_by_ID($REG_ID); |
|
| 994 | + $new_status = $REG->toggle_checkin_status($DTT_ID); |
|
| 995 | + if ($new_status !== false) { |
|
| 996 | + EE_Error::add_success($REG->get_checkin_msg($DTT_ID)); |
|
| 997 | + } else { |
|
| 998 | + EE_Error::add_error($REG->get_checkin_msg($DTT_ID, true), __FILE__, __FUNCTION__, __LINE__); |
|
| 999 | + $new_status = false; |
|
| 1000 | + } |
|
| 1001 | + return $new_status; |
|
| 1002 | + } |
|
| 1003 | 1003 | |
| 1004 | 1004 | |
| 1005 | - /** |
|
| 1006 | - * Takes care of deleting multiple EE_Checkin table rows |
|
| 1007 | - * |
|
| 1008 | - * @access protected |
|
| 1009 | - * @return void |
|
| 1010 | - * @throws EE_Error |
|
| 1011 | - * @throws InvalidArgumentException |
|
| 1012 | - * @throws InvalidDataTypeException |
|
| 1013 | - * @throws InvalidInterfaceException |
|
| 1014 | - */ |
|
| 1015 | - protected function _delete_checkin_rows() |
|
| 1016 | - { |
|
| 1017 | - $query_args = array( |
|
| 1018 | - 'action' => 'registration_checkins', |
|
| 1019 | - 'DTT_ID' => isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : 0, |
|
| 1020 | - '_REG_ID' => isset($this->_req_data['_REG_ID']) ? $this->_req_data['_REG_ID'] : 0, |
|
| 1021 | - ); |
|
| 1022 | - $errors = 0; |
|
| 1023 | - if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
| 1024 | - while (list($CHK_ID, $value) = each($this->_req_data['checkbox'])) { |
|
| 1025 | - if (! EEM_Checkin::instance()->delete_by_ID($CHK_ID)) { |
|
| 1026 | - $errors++; |
|
| 1027 | - } |
|
| 1028 | - } |
|
| 1029 | - } else { |
|
| 1030 | - EE_Error::add_error( |
|
| 1031 | - esc_html__( |
|
| 1032 | - 'So, something went wrong with the bulk delete because there was no data received for instructions on WHAT to delete!', |
|
| 1033 | - 'event_espresso' |
|
| 1034 | - ), |
|
| 1035 | - __FILE__, |
|
| 1036 | - __FUNCTION__, |
|
| 1037 | - __LINE__ |
|
| 1038 | - ); |
|
| 1039 | - $this->_redirect_after_action(false, '', '', $query_args, true); |
|
| 1040 | - } |
|
| 1041 | - if ($errors > 0) { |
|
| 1042 | - EE_Error::add_error( |
|
| 1043 | - sprintf(__('There were %d records that did not delete successfully', 'event_espresso'), $errors), |
|
| 1044 | - __FILE__, |
|
| 1045 | - __FUNCTION__, |
|
| 1046 | - __LINE__ |
|
| 1047 | - ); |
|
| 1048 | - } else { |
|
| 1049 | - EE_Error::add_success(__('Records were successfully deleted', 'event_espresso')); |
|
| 1050 | - } |
|
| 1051 | - $this->_redirect_after_action(false, '', '', $query_args, true); |
|
| 1052 | - } |
|
| 1005 | + /** |
|
| 1006 | + * Takes care of deleting multiple EE_Checkin table rows |
|
| 1007 | + * |
|
| 1008 | + * @access protected |
|
| 1009 | + * @return void |
|
| 1010 | + * @throws EE_Error |
|
| 1011 | + * @throws InvalidArgumentException |
|
| 1012 | + * @throws InvalidDataTypeException |
|
| 1013 | + * @throws InvalidInterfaceException |
|
| 1014 | + */ |
|
| 1015 | + protected function _delete_checkin_rows() |
|
| 1016 | + { |
|
| 1017 | + $query_args = array( |
|
| 1018 | + 'action' => 'registration_checkins', |
|
| 1019 | + 'DTT_ID' => isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : 0, |
|
| 1020 | + '_REG_ID' => isset($this->_req_data['_REG_ID']) ? $this->_req_data['_REG_ID'] : 0, |
|
| 1021 | + ); |
|
| 1022 | + $errors = 0; |
|
| 1023 | + if (! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
| 1024 | + while (list($CHK_ID, $value) = each($this->_req_data['checkbox'])) { |
|
| 1025 | + if (! EEM_Checkin::instance()->delete_by_ID($CHK_ID)) { |
|
| 1026 | + $errors++; |
|
| 1027 | + } |
|
| 1028 | + } |
|
| 1029 | + } else { |
|
| 1030 | + EE_Error::add_error( |
|
| 1031 | + esc_html__( |
|
| 1032 | + 'So, something went wrong with the bulk delete because there was no data received for instructions on WHAT to delete!', |
|
| 1033 | + 'event_espresso' |
|
| 1034 | + ), |
|
| 1035 | + __FILE__, |
|
| 1036 | + __FUNCTION__, |
|
| 1037 | + __LINE__ |
|
| 1038 | + ); |
|
| 1039 | + $this->_redirect_after_action(false, '', '', $query_args, true); |
|
| 1040 | + } |
|
| 1041 | + if ($errors > 0) { |
|
| 1042 | + EE_Error::add_error( |
|
| 1043 | + sprintf(__('There were %d records that did not delete successfully', 'event_espresso'), $errors), |
|
| 1044 | + __FILE__, |
|
| 1045 | + __FUNCTION__, |
|
| 1046 | + __LINE__ |
|
| 1047 | + ); |
|
| 1048 | + } else { |
|
| 1049 | + EE_Error::add_success(__('Records were successfully deleted', 'event_espresso')); |
|
| 1050 | + } |
|
| 1051 | + $this->_redirect_after_action(false, '', '', $query_args, true); |
|
| 1052 | + } |
|
| 1053 | 1053 | |
| 1054 | 1054 | |
| 1055 | - /** |
|
| 1056 | - * Deletes a single EE_Checkin row |
|
| 1057 | - * |
|
| 1058 | - * @return void |
|
| 1059 | - * @throws EE_Error |
|
| 1060 | - * @throws InvalidArgumentException |
|
| 1061 | - * @throws InvalidDataTypeException |
|
| 1062 | - * @throws InvalidInterfaceException |
|
| 1063 | - */ |
|
| 1064 | - protected function _delete_checkin_row() |
|
| 1065 | - { |
|
| 1066 | - $query_args = array( |
|
| 1067 | - 'action' => 'registration_checkins', |
|
| 1068 | - 'DTT_ID' => isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : 0, |
|
| 1069 | - '_REG_ID' => isset($this->_req_data['_REG_ID']) ? $this->_req_data['_REG_ID'] : 0, |
|
| 1070 | - ); |
|
| 1071 | - if (! empty($this->_req_data['CHK_ID'])) { |
|
| 1072 | - if (! EEM_Checkin::instance()->delete_by_ID($this->_req_data['CHK_ID'])) { |
|
| 1073 | - EE_Error::add_error( |
|
| 1074 | - esc_html__('Something went wrong and this check-in record was not deleted', 'event_espresso'), |
|
| 1075 | - __FILE__, |
|
| 1076 | - __FUNCTION__, |
|
| 1077 | - __LINE__ |
|
| 1078 | - ); |
|
| 1079 | - } else { |
|
| 1080 | - EE_Error::add_success(__('Check-In record successfully deleted', 'event_espresso')); |
|
| 1081 | - } |
|
| 1082 | - } else { |
|
| 1083 | - EE_Error::add_error( |
|
| 1084 | - esc_html__( |
|
| 1085 | - 'In order to delete a Check-in record, there must be a Check-In ID available. There is not. It is not your fault, there is just a gremlin living in the code', |
|
| 1086 | - 'event_espresso' |
|
| 1087 | - ), |
|
| 1088 | - __FILE__, |
|
| 1089 | - __FUNCTION__, |
|
| 1090 | - __LINE__ |
|
| 1091 | - ); |
|
| 1092 | - } |
|
| 1093 | - $this->_redirect_after_action(false, '', '', $query_args, true); |
|
| 1094 | - } |
|
| 1055 | + /** |
|
| 1056 | + * Deletes a single EE_Checkin row |
|
| 1057 | + * |
|
| 1058 | + * @return void |
|
| 1059 | + * @throws EE_Error |
|
| 1060 | + * @throws InvalidArgumentException |
|
| 1061 | + * @throws InvalidDataTypeException |
|
| 1062 | + * @throws InvalidInterfaceException |
|
| 1063 | + */ |
|
| 1064 | + protected function _delete_checkin_row() |
|
| 1065 | + { |
|
| 1066 | + $query_args = array( |
|
| 1067 | + 'action' => 'registration_checkins', |
|
| 1068 | + 'DTT_ID' => isset($this->_req_data['DTT_ID']) ? $this->_req_data['DTT_ID'] : 0, |
|
| 1069 | + '_REG_ID' => isset($this->_req_data['_REG_ID']) ? $this->_req_data['_REG_ID'] : 0, |
|
| 1070 | + ); |
|
| 1071 | + if (! empty($this->_req_data['CHK_ID'])) { |
|
| 1072 | + if (! EEM_Checkin::instance()->delete_by_ID($this->_req_data['CHK_ID'])) { |
|
| 1073 | + EE_Error::add_error( |
|
| 1074 | + esc_html__('Something went wrong and this check-in record was not deleted', 'event_espresso'), |
|
| 1075 | + __FILE__, |
|
| 1076 | + __FUNCTION__, |
|
| 1077 | + __LINE__ |
|
| 1078 | + ); |
|
| 1079 | + } else { |
|
| 1080 | + EE_Error::add_success(__('Check-In record successfully deleted', 'event_espresso')); |
|
| 1081 | + } |
|
| 1082 | + } else { |
|
| 1083 | + EE_Error::add_error( |
|
| 1084 | + esc_html__( |
|
| 1085 | + 'In order to delete a Check-in record, there must be a Check-In ID available. There is not. It is not your fault, there is just a gremlin living in the code', |
|
| 1086 | + 'event_espresso' |
|
| 1087 | + ), |
|
| 1088 | + __FILE__, |
|
| 1089 | + __FUNCTION__, |
|
| 1090 | + __LINE__ |
|
| 1091 | + ); |
|
| 1092 | + } |
|
| 1093 | + $this->_redirect_after_action(false, '', '', $query_args, true); |
|
| 1094 | + } |
|
| 1095 | 1095 | |
| 1096 | 1096 | |
| 1097 | - /** |
|
| 1098 | - * generates HTML for the Event Registrations List Table |
|
| 1099 | - * |
|
| 1100 | - * @access protected |
|
| 1101 | - * @return void |
|
| 1102 | - * @throws EE_Error |
|
| 1103 | - * @throws InvalidArgumentException |
|
| 1104 | - * @throws InvalidDataTypeException |
|
| 1105 | - * @throws InvalidInterfaceException |
|
| 1106 | - */ |
|
| 1107 | - protected function _event_registrations_list_table() |
|
| 1108 | - { |
|
| 1109 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1110 | - $this->_admin_page_title .= isset($this->_req_data['event_id']) |
|
| 1111 | - ? $this->get_action_link_or_button( |
|
| 1112 | - 'new_registration', |
|
| 1113 | - 'add-registrant', |
|
| 1114 | - array('event_id' => $this->_req_data['event_id']), |
|
| 1115 | - 'add-new-h2', |
|
| 1116 | - '', |
|
| 1117 | - false |
|
| 1118 | - ) |
|
| 1119 | - : ''; |
|
| 1120 | - $checked_in = new CheckinStatusDashicon(EE_Checkin::status_checked_in); |
|
| 1121 | - $checked_out = new CheckinStatusDashicon(EE_Checkin::status_checked_out); |
|
| 1122 | - $checked_never = new CheckinStatusDashicon(EE_Checkin::status_checked_never); |
|
| 1123 | - $legend_items = array( |
|
| 1124 | - 'star-icon' => array( |
|
| 1125 | - 'class' => 'dashicons dashicons-star-filled yellow-icon ee-icon-size-8', |
|
| 1126 | - 'desc' => esc_html__('This Registrant is the Primary Registrant', 'event_espresso'), |
|
| 1127 | - ), |
|
| 1128 | - 'checkin' => array( |
|
| 1129 | - 'class' => $checked_in->cssClasses(), |
|
| 1130 | - 'desc' => $checked_in->legendLabel(), |
|
| 1131 | - ), |
|
| 1132 | - 'checkout' => array( |
|
| 1133 | - 'class' => $checked_out->cssClasses(), |
|
| 1134 | - 'desc' => $checked_out->legendLabel(), |
|
| 1135 | - ), |
|
| 1136 | - 'nocheckinrecord' => array( |
|
| 1137 | - 'class' => $checked_never->cssClasses(), |
|
| 1138 | - 'desc' => $checked_never->legendLabel(), |
|
| 1139 | - ), |
|
| 1140 | - 'approved_status' => array( |
|
| 1141 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_approved, |
|
| 1142 | - 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_approved, false, 'sentence'), |
|
| 1143 | - ), |
|
| 1144 | - 'cancelled_status' => array( |
|
| 1145 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_cancelled, |
|
| 1146 | - 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_cancelled, false, 'sentence'), |
|
| 1147 | - ), |
|
| 1148 | - 'declined_status' => array( |
|
| 1149 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_declined, |
|
| 1150 | - 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_declined, false, 'sentence'), |
|
| 1151 | - ), |
|
| 1152 | - 'not_approved' => array( |
|
| 1153 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_not_approved, |
|
| 1154 | - 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, false, 'sentence'), |
|
| 1155 | - ), |
|
| 1156 | - 'pending_status' => array( |
|
| 1157 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_pending_payment, |
|
| 1158 | - 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, false, 'sentence'), |
|
| 1159 | - ), |
|
| 1160 | - 'wait_list' => array( |
|
| 1161 | - 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_wait_list, |
|
| 1162 | - 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_wait_list, false, 'sentence'), |
|
| 1163 | - ), |
|
| 1164 | - ); |
|
| 1165 | - $this->_template_args['after_list_table'] = $this->_display_legend($legend_items); |
|
| 1166 | - $event_id = isset($this->_req_data['event_id']) ? $this->_req_data['event_id'] : null; |
|
| 1167 | - /** @var EE_Event $event */ |
|
| 1168 | - $event = EEM_Event::instance()->get_one_by_ID($event_id); |
|
| 1169 | - $this->_template_args['before_list_table'] = $event instanceof EE_Event |
|
| 1170 | - ? '<h2>' . sprintf( |
|
| 1171 | - esc_html__('Viewing Registrations for Event: %s', 'event_espresso'), |
|
| 1172 | - EEM_Event::instance()->get_one_by_ID($event_id)->get('EVT_name') |
|
| 1173 | - ) . '</h2>' |
|
| 1174 | - : ''; |
|
| 1175 | - // need to get the number of datetimes on the event and set default datetime_id if there is only one datetime on |
|
| 1176 | - // the event. |
|
| 1177 | - $DTT_ID = ! empty($this->_req_data['DTT_ID']) ? absint($this->_req_data['DTT_ID']) : 0; |
|
| 1178 | - $datetime = null; |
|
| 1179 | - if ($event instanceof EE_Event) { |
|
| 1180 | - $datetimes_on_event = $event->datetimes(); |
|
| 1181 | - if (count($datetimes_on_event) === 1) { |
|
| 1182 | - $datetime = reset($datetimes_on_event); |
|
| 1183 | - } |
|
| 1184 | - } |
|
| 1185 | - $datetime = $datetime instanceof EE_Datetime ? $datetime : EEM_Datetime::instance()->get_one_by_ID($DTT_ID); |
|
| 1186 | - if ($datetime instanceof EE_Datetime && $this->_template_args['before_list_table'] !== '') { |
|
| 1187 | - $this->_template_args['before_list_table'] = substr($this->_template_args['before_list_table'], 0, -5); |
|
| 1188 | - $this->_template_args['before_list_table'] .= ' <span class="drk-grey-text">'; |
|
| 1189 | - $this->_template_args['before_list_table'] .= '<span class="dashicons dashicons-calendar"></span>'; |
|
| 1190 | - $this->_template_args['before_list_table'] .= $datetime->name(); |
|
| 1191 | - $this->_template_args['before_list_table'] .= ' ( ' . $datetime->date_and_time_range() . ' )'; |
|
| 1192 | - $this->_template_args['before_list_table'] .= '</span></h2>'; |
|
| 1193 | - } |
|
| 1194 | - // if no datetime, then we're on the initial view, so let's give some helpful instructions on what the status |
|
| 1195 | - // column represents |
|
| 1196 | - if (! $datetime instanceof EE_Datetime) { |
|
| 1197 | - $this->_template_args['before_list_table'] .= '<br><p class="description">' |
|
| 1198 | - . esc_html__( |
|
| 1199 | - 'In this view, the check-in status represents the latest check-in record for the registration in that row.', |
|
| 1200 | - 'event_espresso' |
|
| 1201 | - ) |
|
| 1202 | - . '</p>'; |
|
| 1203 | - } |
|
| 1204 | - $this->display_admin_list_table_page_with_no_sidebar(); |
|
| 1205 | - } |
|
| 1097 | + /** |
|
| 1098 | + * generates HTML for the Event Registrations List Table |
|
| 1099 | + * |
|
| 1100 | + * @access protected |
|
| 1101 | + * @return void |
|
| 1102 | + * @throws EE_Error |
|
| 1103 | + * @throws InvalidArgumentException |
|
| 1104 | + * @throws InvalidDataTypeException |
|
| 1105 | + * @throws InvalidInterfaceException |
|
| 1106 | + */ |
|
| 1107 | + protected function _event_registrations_list_table() |
|
| 1108 | + { |
|
| 1109 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
| 1110 | + $this->_admin_page_title .= isset($this->_req_data['event_id']) |
|
| 1111 | + ? $this->get_action_link_or_button( |
|
| 1112 | + 'new_registration', |
|
| 1113 | + 'add-registrant', |
|
| 1114 | + array('event_id' => $this->_req_data['event_id']), |
|
| 1115 | + 'add-new-h2', |
|
| 1116 | + '', |
|
| 1117 | + false |
|
| 1118 | + ) |
|
| 1119 | + : ''; |
|
| 1120 | + $checked_in = new CheckinStatusDashicon(EE_Checkin::status_checked_in); |
|
| 1121 | + $checked_out = new CheckinStatusDashicon(EE_Checkin::status_checked_out); |
|
| 1122 | + $checked_never = new CheckinStatusDashicon(EE_Checkin::status_checked_never); |
|
| 1123 | + $legend_items = array( |
|
| 1124 | + 'star-icon' => array( |
|
| 1125 | + 'class' => 'dashicons dashicons-star-filled yellow-icon ee-icon-size-8', |
|
| 1126 | + 'desc' => esc_html__('This Registrant is the Primary Registrant', 'event_espresso'), |
|
| 1127 | + ), |
|
| 1128 | + 'checkin' => array( |
|
| 1129 | + 'class' => $checked_in->cssClasses(), |
|
| 1130 | + 'desc' => $checked_in->legendLabel(), |
|
| 1131 | + ), |
|
| 1132 | + 'checkout' => array( |
|
| 1133 | + 'class' => $checked_out->cssClasses(), |
|
| 1134 | + 'desc' => $checked_out->legendLabel(), |
|
| 1135 | + ), |
|
| 1136 | + 'nocheckinrecord' => array( |
|
| 1137 | + 'class' => $checked_never->cssClasses(), |
|
| 1138 | + 'desc' => $checked_never->legendLabel(), |
|
| 1139 | + ), |
|
| 1140 | + 'approved_status' => array( |
|
| 1141 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_approved, |
|
| 1142 | + 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_approved, false, 'sentence'), |
|
| 1143 | + ), |
|
| 1144 | + 'cancelled_status' => array( |
|
| 1145 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_cancelled, |
|
| 1146 | + 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_cancelled, false, 'sentence'), |
|
| 1147 | + ), |
|
| 1148 | + 'declined_status' => array( |
|
| 1149 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_declined, |
|
| 1150 | + 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_declined, false, 'sentence'), |
|
| 1151 | + ), |
|
| 1152 | + 'not_approved' => array( |
|
| 1153 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_not_approved, |
|
| 1154 | + 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_not_approved, false, 'sentence'), |
|
| 1155 | + ), |
|
| 1156 | + 'pending_status' => array( |
|
| 1157 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_pending_payment, |
|
| 1158 | + 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_pending_payment, false, 'sentence'), |
|
| 1159 | + ), |
|
| 1160 | + 'wait_list' => array( |
|
| 1161 | + 'class' => 'ee-status-legend ee-status-legend-' . EEM_Registration::status_id_wait_list, |
|
| 1162 | + 'desc' => EEH_Template::pretty_status(EEM_Registration::status_id_wait_list, false, 'sentence'), |
|
| 1163 | + ), |
|
| 1164 | + ); |
|
| 1165 | + $this->_template_args['after_list_table'] = $this->_display_legend($legend_items); |
|
| 1166 | + $event_id = isset($this->_req_data['event_id']) ? $this->_req_data['event_id'] : null; |
|
| 1167 | + /** @var EE_Event $event */ |
|
| 1168 | + $event = EEM_Event::instance()->get_one_by_ID($event_id); |
|
| 1169 | + $this->_template_args['before_list_table'] = $event instanceof EE_Event |
|
| 1170 | + ? '<h2>' . sprintf( |
|
| 1171 | + esc_html__('Viewing Registrations for Event: %s', 'event_espresso'), |
|
| 1172 | + EEM_Event::instance()->get_one_by_ID($event_id)->get('EVT_name') |
|
| 1173 | + ) . '</h2>' |
|
| 1174 | + : ''; |
|
| 1175 | + // need to get the number of datetimes on the event and set default datetime_id if there is only one datetime on |
|
| 1176 | + // the event. |
|
| 1177 | + $DTT_ID = ! empty($this->_req_data['DTT_ID']) ? absint($this->_req_data['DTT_ID']) : 0; |
|
| 1178 | + $datetime = null; |
|
| 1179 | + if ($event instanceof EE_Event) { |
|
| 1180 | + $datetimes_on_event = $event->datetimes(); |
|
| 1181 | + if (count($datetimes_on_event) === 1) { |
|
| 1182 | + $datetime = reset($datetimes_on_event); |
|
| 1183 | + } |
|
| 1184 | + } |
|
| 1185 | + $datetime = $datetime instanceof EE_Datetime ? $datetime : EEM_Datetime::instance()->get_one_by_ID($DTT_ID); |
|
| 1186 | + if ($datetime instanceof EE_Datetime && $this->_template_args['before_list_table'] !== '') { |
|
| 1187 | + $this->_template_args['before_list_table'] = substr($this->_template_args['before_list_table'], 0, -5); |
|
| 1188 | + $this->_template_args['before_list_table'] .= ' <span class="drk-grey-text">'; |
|
| 1189 | + $this->_template_args['before_list_table'] .= '<span class="dashicons dashicons-calendar"></span>'; |
|
| 1190 | + $this->_template_args['before_list_table'] .= $datetime->name(); |
|
| 1191 | + $this->_template_args['before_list_table'] .= ' ( ' . $datetime->date_and_time_range() . ' )'; |
|
| 1192 | + $this->_template_args['before_list_table'] .= '</span></h2>'; |
|
| 1193 | + } |
|
| 1194 | + // if no datetime, then we're on the initial view, so let's give some helpful instructions on what the status |
|
| 1195 | + // column represents |
|
| 1196 | + if (! $datetime instanceof EE_Datetime) { |
|
| 1197 | + $this->_template_args['before_list_table'] .= '<br><p class="description">' |
|
| 1198 | + . esc_html__( |
|
| 1199 | + 'In this view, the check-in status represents the latest check-in record for the registration in that row.', |
|
| 1200 | + 'event_espresso' |
|
| 1201 | + ) |
|
| 1202 | + . '</p>'; |
|
| 1203 | + } |
|
| 1204 | + $this->display_admin_list_table_page_with_no_sidebar(); |
|
| 1205 | + } |
|
| 1206 | 1206 | |
| 1207 | - /** |
|
| 1208 | - * Download the registrations check-in report (same as the normal registration report, but with different where |
|
| 1209 | - * conditions) |
|
| 1210 | - * |
|
| 1211 | - * @return void ends the request by a redirect or download |
|
| 1212 | - */ |
|
| 1213 | - public function _registrations_checkin_report() |
|
| 1214 | - { |
|
| 1215 | - $this->_registrations_report_base('_get_checkin_query_params_from_request'); |
|
| 1216 | - } |
|
| 1207 | + /** |
|
| 1208 | + * Download the registrations check-in report (same as the normal registration report, but with different where |
|
| 1209 | + * conditions) |
|
| 1210 | + * |
|
| 1211 | + * @return void ends the request by a redirect or download |
|
| 1212 | + */ |
|
| 1213 | + public function _registrations_checkin_report() |
|
| 1214 | + { |
|
| 1215 | + $this->_registrations_report_base('_get_checkin_query_params_from_request'); |
|
| 1216 | + } |
|
| 1217 | 1217 | |
| 1218 | - /** |
|
| 1219 | - * Gets the query params from the request, plus adds a where condition for the registration status, |
|
| 1220 | - * because on the checkin page we only ever want to see approved and pending-approval registrations |
|
| 1221 | - * |
|
| 1222 | - * @param array $request |
|
| 1223 | - * @param int $per_page |
|
| 1224 | - * @param bool $count |
|
| 1225 | - * @return array |
|
| 1226 | - * @throws EE_Error |
|
| 1227 | - */ |
|
| 1228 | - protected function _get_checkin_query_params_from_request( |
|
| 1229 | - $request, |
|
| 1230 | - $per_page = 10, |
|
| 1231 | - $count = false |
|
| 1232 | - ) { |
|
| 1233 | - $query_params = $this->_get_registration_query_parameters($request, $per_page, $count); |
|
| 1234 | - // unlike the regular registrations list table, |
|
| 1235 | - $status_ids_array = apply_filters( |
|
| 1236 | - 'FHEE__Extend_Registrations_Admin_Page__get_event_attendees__status_ids_array', |
|
| 1237 | - array(EEM_Registration::status_id_pending_payment, EEM_Registration::status_id_approved) |
|
| 1238 | - ); |
|
| 1239 | - $query_params[0]['STS_ID'] = array('IN', $status_ids_array); |
|
| 1240 | - return $query_params; |
|
| 1241 | - } |
|
| 1218 | + /** |
|
| 1219 | + * Gets the query params from the request, plus adds a where condition for the registration status, |
|
| 1220 | + * because on the checkin page we only ever want to see approved and pending-approval registrations |
|
| 1221 | + * |
|
| 1222 | + * @param array $request |
|
| 1223 | + * @param int $per_page |
|
| 1224 | + * @param bool $count |
|
| 1225 | + * @return array |
|
| 1226 | + * @throws EE_Error |
|
| 1227 | + */ |
|
| 1228 | + protected function _get_checkin_query_params_from_request( |
|
| 1229 | + $request, |
|
| 1230 | + $per_page = 10, |
|
| 1231 | + $count = false |
|
| 1232 | + ) { |
|
| 1233 | + $query_params = $this->_get_registration_query_parameters($request, $per_page, $count); |
|
| 1234 | + // unlike the regular registrations list table, |
|
| 1235 | + $status_ids_array = apply_filters( |
|
| 1236 | + 'FHEE__Extend_Registrations_Admin_Page__get_event_attendees__status_ids_array', |
|
| 1237 | + array(EEM_Registration::status_id_pending_payment, EEM_Registration::status_id_approved) |
|
| 1238 | + ); |
|
| 1239 | + $query_params[0]['STS_ID'] = array('IN', $status_ids_array); |
|
| 1240 | + return $query_params; |
|
| 1241 | + } |
|
| 1242 | 1242 | |
| 1243 | 1243 | |
| 1244 | - /** |
|
| 1245 | - * Gets registrations for an event |
|
| 1246 | - * |
|
| 1247 | - * @param int $per_page |
|
| 1248 | - * @param bool $count whether to return count or data. |
|
| 1249 | - * @param bool $trash |
|
| 1250 | - * @param string $orderby |
|
| 1251 | - * @return EE_Registration[]|int |
|
| 1252 | - * @throws EE_Error |
|
| 1253 | - * @throws InvalidArgumentException |
|
| 1254 | - * @throws InvalidDataTypeException |
|
| 1255 | - * @throws InvalidInterfaceException |
|
| 1256 | - */ |
|
| 1257 | - public function get_event_attendees($per_page = 10, $count = false, $trash = false, $orderby = 'ATT_fname') |
|
| 1258 | - { |
|
| 1259 | - // normalize some request params that get setup by the parent `get_registrations` method. |
|
| 1260 | - $request = $this->_req_data; |
|
| 1261 | - $request['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : $orderby; |
|
| 1262 | - $request['order'] = ! empty($this->_req_data['order']) ? $this->_req_data['order'] : 'ASC'; |
|
| 1263 | - if ($trash) { |
|
| 1264 | - $request['status'] = 'trash'; |
|
| 1265 | - } |
|
| 1266 | - $query_params = $this->_get_checkin_query_params_from_request($request, $per_page, $count); |
|
| 1267 | - /** |
|
| 1268 | - * Override the default groupby added by EEM_Base so that sorts with multiple order bys work as expected |
|
| 1269 | - * |
|
| 1270 | - * @link https://events.codebasehq.com/projects/event-espresso/tickets/10093 |
|
| 1271 | - * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 1272 | - * or if you have the development copy of EE you can view this at the path: |
|
| 1273 | - * /docs/G--Model-System/model-query-params.md |
|
| 1274 | - */ |
|
| 1275 | - $query_params['group_by'] = ''; |
|
| 1244 | + /** |
|
| 1245 | + * Gets registrations for an event |
|
| 1246 | + * |
|
| 1247 | + * @param int $per_page |
|
| 1248 | + * @param bool $count whether to return count or data. |
|
| 1249 | + * @param bool $trash |
|
| 1250 | + * @param string $orderby |
|
| 1251 | + * @return EE_Registration[]|int |
|
| 1252 | + * @throws EE_Error |
|
| 1253 | + * @throws InvalidArgumentException |
|
| 1254 | + * @throws InvalidDataTypeException |
|
| 1255 | + * @throws InvalidInterfaceException |
|
| 1256 | + */ |
|
| 1257 | + public function get_event_attendees($per_page = 10, $count = false, $trash = false, $orderby = 'ATT_fname') |
|
| 1258 | + { |
|
| 1259 | + // normalize some request params that get setup by the parent `get_registrations` method. |
|
| 1260 | + $request = $this->_req_data; |
|
| 1261 | + $request['orderby'] = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : $orderby; |
|
| 1262 | + $request['order'] = ! empty($this->_req_data['order']) ? $this->_req_data['order'] : 'ASC'; |
|
| 1263 | + if ($trash) { |
|
| 1264 | + $request['status'] = 'trash'; |
|
| 1265 | + } |
|
| 1266 | + $query_params = $this->_get_checkin_query_params_from_request($request, $per_page, $count); |
|
| 1267 | + /** |
|
| 1268 | + * Override the default groupby added by EEM_Base so that sorts with multiple order bys work as expected |
|
| 1269 | + * |
|
| 1270 | + * @link https://events.codebasehq.com/projects/event-espresso/tickets/10093 |
|
| 1271 | + * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
| 1272 | + * or if you have the development copy of EE you can view this at the path: |
|
| 1273 | + * /docs/G--Model-System/model-query-params.md |
|
| 1274 | + */ |
|
| 1275 | + $query_params['group_by'] = ''; |
|
| 1276 | 1276 | |
| 1277 | - return $count |
|
| 1278 | - ? EEM_Registration::instance()->count($query_params) |
|
| 1279 | - /** @type EE_Registration[] */ |
|
| 1280 | - : EEM_Registration::instance()->get_all($query_params); |
|
| 1281 | - } |
|
| 1277 | + return $count |
|
| 1278 | + ? EEM_Registration::instance()->count($query_params) |
|
| 1279 | + /** @type EE_Registration[] */ |
|
| 1280 | + : EEM_Registration::instance()->get_all($query_params); |
|
| 1281 | + } |
|
| 1282 | 1282 | } |
@@ -12,32 +12,32 @@ |
||
| 12 | 12 | class EE_Button_Display_Strategy extends EE_Display_Strategy_Base |
| 13 | 13 | { |
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * @return string of html to display the input |
|
| 17 | - */ |
|
| 18 | - public function display() |
|
| 19 | - { |
|
| 20 | - $default_value = $this->_input->get_default(); |
|
| 21 | - if ($this->_input->get_normalization_strategy() instanceof EE_Normalization_Strategy_Base) { |
|
| 22 | - $default_value = $this->_input->get_normalization_strategy()->unnormalize($default_value); |
|
| 23 | - } |
|
| 24 | - $html = $this->_opening_tag('button'); |
|
| 25 | - $html .= $this->_attributes_string( |
|
| 26 | - array_merge( |
|
| 27 | - $this->_standard_attributes_array(), |
|
| 28 | - array( |
|
| 29 | - 'value' => $default_value, |
|
| 30 | - ) |
|
| 31 | - ) |
|
| 32 | - ); |
|
| 33 | - if ($this->_input instanceof EE_Button_Input) { |
|
| 34 | - $button_content = $this->_input->button_content(); |
|
| 35 | - } else { |
|
| 36 | - $button_content = $this->_input->get_default(); |
|
| 37 | - } |
|
| 38 | - $html .= '>'; |
|
| 39 | - $html .= $button_content; |
|
| 40 | - $html .= $this->_closing_tag(); |
|
| 41 | - return $html; |
|
| 42 | - } |
|
| 15 | + /** |
|
| 16 | + * @return string of html to display the input |
|
| 17 | + */ |
|
| 18 | + public function display() |
|
| 19 | + { |
|
| 20 | + $default_value = $this->_input->get_default(); |
|
| 21 | + if ($this->_input->get_normalization_strategy() instanceof EE_Normalization_Strategy_Base) { |
|
| 22 | + $default_value = $this->_input->get_normalization_strategy()->unnormalize($default_value); |
|
| 23 | + } |
|
| 24 | + $html = $this->_opening_tag('button'); |
|
| 25 | + $html .= $this->_attributes_string( |
|
| 26 | + array_merge( |
|
| 27 | + $this->_standard_attributes_array(), |
|
| 28 | + array( |
|
| 29 | + 'value' => $default_value, |
|
| 30 | + ) |
|
| 31 | + ) |
|
| 32 | + ); |
|
| 33 | + if ($this->_input instanceof EE_Button_Input) { |
|
| 34 | + $button_content = $this->_input->button_content(); |
|
| 35 | + } else { |
|
| 36 | + $button_content = $this->_input->get_default(); |
|
| 37 | + } |
|
| 38 | + $html .= '>'; |
|
| 39 | + $html .= $button_content; |
|
| 40 | + $html .= $this->_closing_tag(); |
|
| 41 | + return $html; |
|
| 42 | + } |
|
| 43 | 43 | } |
@@ -20,42 +20,42 @@ |
||
| 20 | 20 | class FilePath |
| 21 | 21 | { |
| 22 | 22 | |
| 23 | - /** |
|
| 24 | - * @var string file_path |
|
| 25 | - */ |
|
| 26 | - private $file_path; |
|
| 27 | - |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * FilePath constructor. |
|
| 31 | - * |
|
| 32 | - * @param string $file_path |
|
| 33 | - * @throws InvalidDataTypeException |
|
| 34 | - * @throws InvalidFilePathException |
|
| 35 | - */ |
|
| 36 | - public function __construct($file_path) |
|
| 37 | - { |
|
| 38 | - if (! is_string($file_path)) { |
|
| 39 | - throw new InvalidDataTypeException( |
|
| 40 | - '$file_path', |
|
| 41 | - $file_path, |
|
| 42 | - 'string' |
|
| 43 | - ); |
|
| 44 | - } |
|
| 45 | - if (! is_readable($file_path)) { |
|
| 46 | - throw new InvalidFilePathException($file_path); |
|
| 47 | - } |
|
| 48 | - $this->file_path = $file_path; |
|
| 49 | - } |
|
| 50 | - |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * @return string |
|
| 54 | - */ |
|
| 55 | - public function __toString() |
|
| 56 | - { |
|
| 57 | - return $this->file_path; |
|
| 58 | - } |
|
| 23 | + /** |
|
| 24 | + * @var string file_path |
|
| 25 | + */ |
|
| 26 | + private $file_path; |
|
| 27 | + |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * FilePath constructor. |
|
| 31 | + * |
|
| 32 | + * @param string $file_path |
|
| 33 | + * @throws InvalidDataTypeException |
|
| 34 | + * @throws InvalidFilePathException |
|
| 35 | + */ |
|
| 36 | + public function __construct($file_path) |
|
| 37 | + { |
|
| 38 | + if (! is_string($file_path)) { |
|
| 39 | + throw new InvalidDataTypeException( |
|
| 40 | + '$file_path', |
|
| 41 | + $file_path, |
|
| 42 | + 'string' |
|
| 43 | + ); |
|
| 44 | + } |
|
| 45 | + if (! is_readable($file_path)) { |
|
| 46 | + throw new InvalidFilePathException($file_path); |
|
| 47 | + } |
|
| 48 | + $this->file_path = $file_path; |
|
| 49 | + } |
|
| 50 | + |
|
| 51 | + |
|
| 52 | + /** |
|
| 53 | + * @return string |
|
| 54 | + */ |
|
| 55 | + public function __toString() |
|
| 56 | + { |
|
| 57 | + return $this->file_path; |
|
| 58 | + } |
|
| 59 | 59 | |
| 60 | 60 | |
| 61 | 61 | } |
@@ -35,14 +35,14 @@ |
||
| 35 | 35 | */ |
| 36 | 36 | public function __construct($file_path) |
| 37 | 37 | { |
| 38 | - if (! is_string($file_path)) { |
|
| 38 | + if ( ! is_string($file_path)) { |
|
| 39 | 39 | throw new InvalidDataTypeException( |
| 40 | 40 | '$file_path', |
| 41 | 41 | $file_path, |
| 42 | 42 | 'string' |
| 43 | 43 | ); |
| 44 | 44 | } |
| 45 | - if (! is_readable($file_path)) { |
|
| 45 | + if ( ! is_readable($file_path)) { |
|
| 46 | 46 | throw new InvalidFilePathException($file_path); |
| 47 | 47 | } |
| 48 | 48 | $this->file_path = $file_path; |
@@ -37,14 +37,14 @@ |
||
| 37 | 37 | */ |
| 38 | 38 | public function __construct($fully_qualified_name) |
| 39 | 39 | { |
| 40 | - if (! is_string($fully_qualified_name)) { |
|
| 40 | + if ( ! is_string($fully_qualified_name)) { |
|
| 41 | 41 | throw new InvalidDataTypeException( |
| 42 | 42 | '$fully_qualified_name', |
| 43 | 43 | $fully_qualified_name, |
| 44 | 44 | 'string' |
| 45 | 45 | ); |
| 46 | 46 | } |
| 47 | - if (! class_exists($fully_qualified_name) && ! interface_exists($fully_qualified_name)) { |
|
| 47 | + if ( ! class_exists($fully_qualified_name) && ! interface_exists($fully_qualified_name)) { |
|
| 48 | 48 | if (strpos($fully_qualified_name, 'Interface') !== false) { |
| 49 | 49 | throw new InvalidInterfaceException($fully_qualified_name); |
| 50 | 50 | } |
@@ -21,54 +21,54 @@ |
||
| 21 | 21 | class FullyQualifiedName |
| 22 | 22 | { |
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * @var string $fully_qualified_name |
|
| 26 | - */ |
|
| 27 | - private $fully_qualified_name; |
|
| 24 | + /** |
|
| 25 | + * @var string $fully_qualified_name |
|
| 26 | + */ |
|
| 27 | + private $fully_qualified_name; |
|
| 28 | 28 | |
| 29 | 29 | |
| 30 | - /** |
|
| 31 | - * FullyQualifiedName constructor. |
|
| 32 | - * |
|
| 33 | - * @param string $fully_qualified_name |
|
| 34 | - * @throws InvalidClassException |
|
| 35 | - * @throws InvalidInterfaceException |
|
| 36 | - * @throws InvalidDataTypeException |
|
| 37 | - */ |
|
| 38 | - public function __construct($fully_qualified_name) |
|
| 39 | - { |
|
| 40 | - if (! is_string($fully_qualified_name)) { |
|
| 41 | - throw new InvalidDataTypeException( |
|
| 42 | - '$fully_qualified_name', |
|
| 43 | - $fully_qualified_name, |
|
| 44 | - 'string' |
|
| 45 | - ); |
|
| 46 | - } |
|
| 47 | - if (! class_exists($fully_qualified_name) && ! interface_exists($fully_qualified_name)) { |
|
| 48 | - if (strpos($fully_qualified_name, 'Interface') !== false) { |
|
| 49 | - throw new InvalidInterfaceException($fully_qualified_name); |
|
| 50 | - } |
|
| 51 | - throw new InvalidClassException($fully_qualified_name); |
|
| 52 | - } |
|
| 53 | - $this->fully_qualified_name = $fully_qualified_name; |
|
| 54 | - } |
|
| 30 | + /** |
|
| 31 | + * FullyQualifiedName constructor. |
|
| 32 | + * |
|
| 33 | + * @param string $fully_qualified_name |
|
| 34 | + * @throws InvalidClassException |
|
| 35 | + * @throws InvalidInterfaceException |
|
| 36 | + * @throws InvalidDataTypeException |
|
| 37 | + */ |
|
| 38 | + public function __construct($fully_qualified_name) |
|
| 39 | + { |
|
| 40 | + if (! is_string($fully_qualified_name)) { |
|
| 41 | + throw new InvalidDataTypeException( |
|
| 42 | + '$fully_qualified_name', |
|
| 43 | + $fully_qualified_name, |
|
| 44 | + 'string' |
|
| 45 | + ); |
|
| 46 | + } |
|
| 47 | + if (! class_exists($fully_qualified_name) && ! interface_exists($fully_qualified_name)) { |
|
| 48 | + if (strpos($fully_qualified_name, 'Interface') !== false) { |
|
| 49 | + throw new InvalidInterfaceException($fully_qualified_name); |
|
| 50 | + } |
|
| 51 | + throw new InvalidClassException($fully_qualified_name); |
|
| 52 | + } |
|
| 53 | + $this->fully_qualified_name = $fully_qualified_name; |
|
| 54 | + } |
|
| 55 | 55 | |
| 56 | 56 | |
| 57 | - /** |
|
| 58 | - * @return string |
|
| 59 | - */ |
|
| 60 | - public function string() |
|
| 61 | - { |
|
| 62 | - return $this->fully_qualified_name; |
|
| 63 | - } |
|
| 57 | + /** |
|
| 58 | + * @return string |
|
| 59 | + */ |
|
| 60 | + public function string() |
|
| 61 | + { |
|
| 62 | + return $this->fully_qualified_name; |
|
| 63 | + } |
|
| 64 | 64 | |
| 65 | 65 | |
| 66 | - /** |
|
| 67 | - * @return string |
|
| 68 | - */ |
|
| 69 | - public function __toString() |
|
| 70 | - { |
|
| 71 | - return $this->fully_qualified_name; |
|
| 72 | - } |
|
| 66 | + /** |
|
| 67 | + * @return string |
|
| 68 | + */ |
|
| 69 | + public function __toString() |
|
| 70 | + { |
|
| 71 | + return $this->fully_qualified_name; |
|
| 72 | + } |
|
| 73 | 73 | |
| 74 | 74 | } |
@@ -121,7 +121,7 @@ |
||
| 121 | 121 | |
| 122 | 122 | |
| 123 | 123 | /** |
| 124 | - * @return Version |
|
| 124 | + * @return string |
|
| 125 | 125 | */ |
| 126 | 126 | public function versionValueObject() |
| 127 | 127 | { |
@@ -17,218 +17,218 @@ |
||
| 17 | 17 | abstract class DomainBase implements DomainInterface |
| 18 | 18 | { |
| 19 | 19 | |
| 20 | - const ASSETS_FOLDER = 'assets/'; |
|
| 21 | - |
|
| 22 | - /** |
|
| 23 | - * Equivalent to `__FILE__` for main plugin file. |
|
| 24 | - * |
|
| 25 | - * @var FilePath |
|
| 26 | - */ |
|
| 27 | - private $plugin_file; |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * String indicating version for plugin |
|
| 31 | - * |
|
| 32 | - * @var string |
|
| 33 | - */ |
|
| 34 | - private $version; |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * @var string $plugin_basename |
|
| 38 | - */ |
|
| 39 | - private $plugin_basename; |
|
| 40 | - |
|
| 41 | - /** |
|
| 42 | - * @var string $plugin_path |
|
| 43 | - */ |
|
| 44 | - private $plugin_path; |
|
| 45 | - |
|
| 46 | - /** |
|
| 47 | - * @var string $plugin_url |
|
| 48 | - */ |
|
| 49 | - private $plugin_url; |
|
| 50 | - |
|
| 51 | - /** |
|
| 52 | - * @var string $asset_namespace |
|
| 53 | - */ |
|
| 54 | - private $asset_namespace; |
|
| 55 | - |
|
| 56 | - /** |
|
| 57 | - * @var string $assets_path |
|
| 58 | - */ |
|
| 59 | - private $assets_path; |
|
| 60 | - |
|
| 61 | - /** |
|
| 62 | - * @var bool |
|
| 63 | - */ |
|
| 64 | - protected $initialized = false; |
|
| 65 | - |
|
| 66 | - |
|
| 67 | - /** |
|
| 68 | - * Initializes internal properties. |
|
| 69 | - * |
|
| 70 | - * @param FilePath $plugin_file |
|
| 71 | - * @param Version $version |
|
| 72 | - * @param string $asset_namespace |
|
| 73 | - */ |
|
| 74 | - public function __construct(FilePath $plugin_file, Version $version, $asset_namespace = Domain::ASSET_NAMESPACE) |
|
| 75 | - { |
|
| 76 | - $this->plugin_file = $plugin_file; |
|
| 77 | - $this->version = $version; |
|
| 78 | - $this->initialize($asset_namespace); |
|
| 79 | - } |
|
| 80 | - |
|
| 81 | - |
|
| 82 | - /** |
|
| 83 | - * @param string $asset_namespace |
|
| 84 | - * @return void |
|
| 85 | - * @since $VID:$ |
|
| 86 | - */ |
|
| 87 | - public function initialize($asset_namespace = Domain::ASSET_NAMESPACE) |
|
| 88 | - { |
|
| 89 | - if (! $this->initialized) { |
|
| 90 | - $this->plugin_basename = plugin_basename($this->pluginFile()); |
|
| 91 | - $this->plugin_path = plugin_dir_path($this->pluginFile()); |
|
| 92 | - $this->plugin_url = plugin_dir_url($this->pluginFile()); |
|
| 93 | - $this->setAssetNamespace($asset_namespace); |
|
| 94 | - $this->setDistributionAssetsPath(); |
|
| 95 | - $this->initialized = true; |
|
| 96 | - } |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - |
|
| 100 | - /** |
|
| 101 | - * @param string $asset_namespace |
|
| 102 | - * @return void |
|
| 103 | - */ |
|
| 104 | - public function setAssetNamespace($asset_namespace = Domain::ASSET_NAMESPACE) |
|
| 105 | - { |
|
| 106 | - if (! $this->asset_namespace) { |
|
| 107 | - $this->asset_namespace = sanitize_key( |
|
| 108 | - // convert directory separators to dashes and remove file extension |
|
| 109 | - str_replace(['/', '.php'], ['-', ''], $asset_namespace) |
|
| 110 | - ); |
|
| 111 | - } |
|
| 112 | - } |
|
| 113 | - |
|
| 114 | - |
|
| 115 | - /** |
|
| 116 | - * @throws DomainException |
|
| 117 | - * @since $VID:$ |
|
| 118 | - */ |
|
| 119 | - private function setDistributionAssetsPath() |
|
| 120 | - { |
|
| 121 | - $assets_path = $this->pluginPath() . DomainBase::ASSETS_FOLDER; |
|
| 122 | - if (! is_readable($assets_path)) { |
|
| 123 | - throw new DomainException( |
|
| 124 | - sprintf( |
|
| 125 | - esc_html__( |
|
| 126 | - 'The assets distribution folder was not found or is not readable. Please verify that "%1$s" exists and has valid permissions.', |
|
| 127 | - 'event_espresso' |
|
| 128 | - ), |
|
| 129 | - $assets_path |
|
| 130 | - ) |
|
| 131 | - ); |
|
| 132 | - } |
|
| 133 | - $this->assets_path = trailingslashit($assets_path); |
|
| 134 | - } |
|
| 135 | - |
|
| 136 | - |
|
| 137 | - /** |
|
| 138 | - * @return string |
|
| 139 | - */ |
|
| 140 | - public function pluginFile() |
|
| 141 | - { |
|
| 142 | - return (string) $this->plugin_file; |
|
| 143 | - } |
|
| 144 | - |
|
| 145 | - |
|
| 146 | - /** |
|
| 147 | - * @return string |
|
| 148 | - */ |
|
| 149 | - public function pluginBasename() |
|
| 150 | - { |
|
| 151 | - return $this->plugin_basename; |
|
| 152 | - } |
|
| 153 | - |
|
| 154 | - |
|
| 155 | - /** |
|
| 156 | - * @param string $additional_path |
|
| 157 | - * @return string |
|
| 158 | - */ |
|
| 159 | - public function pluginPath($additional_path = '') |
|
| 160 | - { |
|
| 161 | - return is_string($additional_path) && $additional_path !== '' |
|
| 162 | - ? $this->plugin_path . $additional_path |
|
| 163 | - : $this->plugin_path; |
|
| 164 | - } |
|
| 165 | - |
|
| 166 | - |
|
| 167 | - /** |
|
| 168 | - * @return string |
|
| 169 | - */ |
|
| 170 | - public function pluginUrl() |
|
| 171 | - { |
|
| 172 | - return $this->plugin_url; |
|
| 173 | - } |
|
| 174 | - |
|
| 175 | - |
|
| 176 | - /** |
|
| 177 | - * @return string |
|
| 178 | - */ |
|
| 179 | - public function version() |
|
| 180 | - { |
|
| 181 | - return (string) $this->version; |
|
| 182 | - } |
|
| 183 | - |
|
| 184 | - |
|
| 185 | - /** |
|
| 186 | - * @return Version |
|
| 187 | - */ |
|
| 188 | - public function versionValueObject() |
|
| 189 | - { |
|
| 190 | - return $this->version; |
|
| 191 | - } |
|
| 192 | - |
|
| 193 | - |
|
| 194 | - /** |
|
| 195 | - * @return string |
|
| 196 | - */ |
|
| 197 | - public function distributionAssetsFolder() |
|
| 198 | - { |
|
| 199 | - return DomainBase::ASSETS_FOLDER; |
|
| 200 | - } |
|
| 201 | - |
|
| 202 | - |
|
| 203 | - /** |
|
| 204 | - * @param string $additional_path |
|
| 205 | - * @return string |
|
| 206 | - */ |
|
| 207 | - public function distributionAssetsPath($additional_path = '') |
|
| 208 | - { |
|
| 209 | - return is_string($additional_path) && $additional_path !== '' |
|
| 210 | - ? $this->assets_path . $additional_path |
|
| 211 | - : $this->assets_path; |
|
| 212 | - } |
|
| 213 | - |
|
| 214 | - |
|
| 215 | - /** |
|
| 216 | - * @param string $additional_path |
|
| 217 | - * @return string |
|
| 218 | - */ |
|
| 219 | - public function distributionAssetsUrl($additional_path = '') |
|
| 220 | - { |
|
| 221 | - return is_string($additional_path) && $additional_path !== '' |
|
| 222 | - ? $this->plugin_url . DomainBase::ASSETS_FOLDER . $additional_path |
|
| 223 | - : $this->plugin_url . DomainBase::ASSETS_FOLDER; |
|
| 224 | - } |
|
| 225 | - |
|
| 226 | - |
|
| 227 | - /** |
|
| 228 | - * @return string |
|
| 229 | - */ |
|
| 230 | - public function assetNamespace() |
|
| 231 | - { |
|
| 232 | - return $this->asset_namespace; |
|
| 233 | - } |
|
| 20 | + const ASSETS_FOLDER = 'assets/'; |
|
| 21 | + |
|
| 22 | + /** |
|
| 23 | + * Equivalent to `__FILE__` for main plugin file. |
|
| 24 | + * |
|
| 25 | + * @var FilePath |
|
| 26 | + */ |
|
| 27 | + private $plugin_file; |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * String indicating version for plugin |
|
| 31 | + * |
|
| 32 | + * @var string |
|
| 33 | + */ |
|
| 34 | + private $version; |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * @var string $plugin_basename |
|
| 38 | + */ |
|
| 39 | + private $plugin_basename; |
|
| 40 | + |
|
| 41 | + /** |
|
| 42 | + * @var string $plugin_path |
|
| 43 | + */ |
|
| 44 | + private $plugin_path; |
|
| 45 | + |
|
| 46 | + /** |
|
| 47 | + * @var string $plugin_url |
|
| 48 | + */ |
|
| 49 | + private $plugin_url; |
|
| 50 | + |
|
| 51 | + /** |
|
| 52 | + * @var string $asset_namespace |
|
| 53 | + */ |
|
| 54 | + private $asset_namespace; |
|
| 55 | + |
|
| 56 | + /** |
|
| 57 | + * @var string $assets_path |
|
| 58 | + */ |
|
| 59 | + private $assets_path; |
|
| 60 | + |
|
| 61 | + /** |
|
| 62 | + * @var bool |
|
| 63 | + */ |
|
| 64 | + protected $initialized = false; |
|
| 65 | + |
|
| 66 | + |
|
| 67 | + /** |
|
| 68 | + * Initializes internal properties. |
|
| 69 | + * |
|
| 70 | + * @param FilePath $plugin_file |
|
| 71 | + * @param Version $version |
|
| 72 | + * @param string $asset_namespace |
|
| 73 | + */ |
|
| 74 | + public function __construct(FilePath $plugin_file, Version $version, $asset_namespace = Domain::ASSET_NAMESPACE) |
|
| 75 | + { |
|
| 76 | + $this->plugin_file = $plugin_file; |
|
| 77 | + $this->version = $version; |
|
| 78 | + $this->initialize($asset_namespace); |
|
| 79 | + } |
|
| 80 | + |
|
| 81 | + |
|
| 82 | + /** |
|
| 83 | + * @param string $asset_namespace |
|
| 84 | + * @return void |
|
| 85 | + * @since $VID:$ |
|
| 86 | + */ |
|
| 87 | + public function initialize($asset_namespace = Domain::ASSET_NAMESPACE) |
|
| 88 | + { |
|
| 89 | + if (! $this->initialized) { |
|
| 90 | + $this->plugin_basename = plugin_basename($this->pluginFile()); |
|
| 91 | + $this->plugin_path = plugin_dir_path($this->pluginFile()); |
|
| 92 | + $this->plugin_url = plugin_dir_url($this->pluginFile()); |
|
| 93 | + $this->setAssetNamespace($asset_namespace); |
|
| 94 | + $this->setDistributionAssetsPath(); |
|
| 95 | + $this->initialized = true; |
|
| 96 | + } |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + |
|
| 100 | + /** |
|
| 101 | + * @param string $asset_namespace |
|
| 102 | + * @return void |
|
| 103 | + */ |
|
| 104 | + public function setAssetNamespace($asset_namespace = Domain::ASSET_NAMESPACE) |
|
| 105 | + { |
|
| 106 | + if (! $this->asset_namespace) { |
|
| 107 | + $this->asset_namespace = sanitize_key( |
|
| 108 | + // convert directory separators to dashes and remove file extension |
|
| 109 | + str_replace(['/', '.php'], ['-', ''], $asset_namespace) |
|
| 110 | + ); |
|
| 111 | + } |
|
| 112 | + } |
|
| 113 | + |
|
| 114 | + |
|
| 115 | + /** |
|
| 116 | + * @throws DomainException |
|
| 117 | + * @since $VID:$ |
|
| 118 | + */ |
|
| 119 | + private function setDistributionAssetsPath() |
|
| 120 | + { |
|
| 121 | + $assets_path = $this->pluginPath() . DomainBase::ASSETS_FOLDER; |
|
| 122 | + if (! is_readable($assets_path)) { |
|
| 123 | + throw new DomainException( |
|
| 124 | + sprintf( |
|
| 125 | + esc_html__( |
|
| 126 | + 'The assets distribution folder was not found or is not readable. Please verify that "%1$s" exists and has valid permissions.', |
|
| 127 | + 'event_espresso' |
|
| 128 | + ), |
|
| 129 | + $assets_path |
|
| 130 | + ) |
|
| 131 | + ); |
|
| 132 | + } |
|
| 133 | + $this->assets_path = trailingslashit($assets_path); |
|
| 134 | + } |
|
| 135 | + |
|
| 136 | + |
|
| 137 | + /** |
|
| 138 | + * @return string |
|
| 139 | + */ |
|
| 140 | + public function pluginFile() |
|
| 141 | + { |
|
| 142 | + return (string) $this->plugin_file; |
|
| 143 | + } |
|
| 144 | + |
|
| 145 | + |
|
| 146 | + /** |
|
| 147 | + * @return string |
|
| 148 | + */ |
|
| 149 | + public function pluginBasename() |
|
| 150 | + { |
|
| 151 | + return $this->plugin_basename; |
|
| 152 | + } |
|
| 153 | + |
|
| 154 | + |
|
| 155 | + /** |
|
| 156 | + * @param string $additional_path |
|
| 157 | + * @return string |
|
| 158 | + */ |
|
| 159 | + public function pluginPath($additional_path = '') |
|
| 160 | + { |
|
| 161 | + return is_string($additional_path) && $additional_path !== '' |
|
| 162 | + ? $this->plugin_path . $additional_path |
|
| 163 | + : $this->plugin_path; |
|
| 164 | + } |
|
| 165 | + |
|
| 166 | + |
|
| 167 | + /** |
|
| 168 | + * @return string |
|
| 169 | + */ |
|
| 170 | + public function pluginUrl() |
|
| 171 | + { |
|
| 172 | + return $this->plugin_url; |
|
| 173 | + } |
|
| 174 | + |
|
| 175 | + |
|
| 176 | + /** |
|
| 177 | + * @return string |
|
| 178 | + */ |
|
| 179 | + public function version() |
|
| 180 | + { |
|
| 181 | + return (string) $this->version; |
|
| 182 | + } |
|
| 183 | + |
|
| 184 | + |
|
| 185 | + /** |
|
| 186 | + * @return Version |
|
| 187 | + */ |
|
| 188 | + public function versionValueObject() |
|
| 189 | + { |
|
| 190 | + return $this->version; |
|
| 191 | + } |
|
| 192 | + |
|
| 193 | + |
|
| 194 | + /** |
|
| 195 | + * @return string |
|
| 196 | + */ |
|
| 197 | + public function distributionAssetsFolder() |
|
| 198 | + { |
|
| 199 | + return DomainBase::ASSETS_FOLDER; |
|
| 200 | + } |
|
| 201 | + |
|
| 202 | + |
|
| 203 | + /** |
|
| 204 | + * @param string $additional_path |
|
| 205 | + * @return string |
|
| 206 | + */ |
|
| 207 | + public function distributionAssetsPath($additional_path = '') |
|
| 208 | + { |
|
| 209 | + return is_string($additional_path) && $additional_path !== '' |
|
| 210 | + ? $this->assets_path . $additional_path |
|
| 211 | + : $this->assets_path; |
|
| 212 | + } |
|
| 213 | + |
|
| 214 | + |
|
| 215 | + /** |
|
| 216 | + * @param string $additional_path |
|
| 217 | + * @return string |
|
| 218 | + */ |
|
| 219 | + public function distributionAssetsUrl($additional_path = '') |
|
| 220 | + { |
|
| 221 | + return is_string($additional_path) && $additional_path !== '' |
|
| 222 | + ? $this->plugin_url . DomainBase::ASSETS_FOLDER . $additional_path |
|
| 223 | + : $this->plugin_url . DomainBase::ASSETS_FOLDER; |
|
| 224 | + } |
|
| 225 | + |
|
| 226 | + |
|
| 227 | + /** |
|
| 228 | + * @return string |
|
| 229 | + */ |
|
| 230 | + public function assetNamespace() |
|
| 231 | + { |
|
| 232 | + return $this->asset_namespace; |
|
| 233 | + } |
|
| 234 | 234 | } |
@@ -86,7 +86,7 @@ discard block |
||
| 86 | 86 | */ |
| 87 | 87 | public function initialize($asset_namespace = Domain::ASSET_NAMESPACE) |
| 88 | 88 | { |
| 89 | - if (! $this->initialized) { |
|
| 89 | + if ( ! $this->initialized) { |
|
| 90 | 90 | $this->plugin_basename = plugin_basename($this->pluginFile()); |
| 91 | 91 | $this->plugin_path = plugin_dir_path($this->pluginFile()); |
| 92 | 92 | $this->plugin_url = plugin_dir_url($this->pluginFile()); |
@@ -103,7 +103,7 @@ discard block |
||
| 103 | 103 | */ |
| 104 | 104 | public function setAssetNamespace($asset_namespace = Domain::ASSET_NAMESPACE) |
| 105 | 105 | { |
| 106 | - if (! $this->asset_namespace) { |
|
| 106 | + if ( ! $this->asset_namespace) { |
|
| 107 | 107 | $this->asset_namespace = sanitize_key( |
| 108 | 108 | // convert directory separators to dashes and remove file extension |
| 109 | 109 | str_replace(['/', '.php'], ['-', ''], $asset_namespace) |
@@ -118,8 +118,8 @@ discard block |
||
| 118 | 118 | */ |
| 119 | 119 | private function setDistributionAssetsPath() |
| 120 | 120 | { |
| 121 | - $assets_path = $this->pluginPath() . DomainBase::ASSETS_FOLDER; |
|
| 122 | - if (! is_readable($assets_path)) { |
|
| 121 | + $assets_path = $this->pluginPath().DomainBase::ASSETS_FOLDER; |
|
| 122 | + if ( ! is_readable($assets_path)) { |
|
| 123 | 123 | throw new DomainException( |
| 124 | 124 | sprintf( |
| 125 | 125 | esc_html__( |
@@ -159,7 +159,7 @@ discard block |
||
| 159 | 159 | public function pluginPath($additional_path = '') |
| 160 | 160 | { |
| 161 | 161 | return is_string($additional_path) && $additional_path !== '' |
| 162 | - ? $this->plugin_path . $additional_path |
|
| 162 | + ? $this->plugin_path.$additional_path |
|
| 163 | 163 | : $this->plugin_path; |
| 164 | 164 | } |
| 165 | 165 | |
@@ -207,7 +207,7 @@ discard block |
||
| 207 | 207 | public function distributionAssetsPath($additional_path = '') |
| 208 | 208 | { |
| 209 | 209 | return is_string($additional_path) && $additional_path !== '' |
| 210 | - ? $this->assets_path . $additional_path |
|
| 210 | + ? $this->assets_path.$additional_path |
|
| 211 | 211 | : $this->assets_path; |
| 212 | 212 | } |
| 213 | 213 | |
@@ -219,8 +219,8 @@ discard block |
||
| 219 | 219 | public function distributionAssetsUrl($additional_path = '') |
| 220 | 220 | { |
| 221 | 221 | return is_string($additional_path) && $additional_path !== '' |
| 222 | - ? $this->plugin_url . DomainBase::ASSETS_FOLDER . $additional_path |
|
| 223 | - : $this->plugin_url . DomainBase::ASSETS_FOLDER; |
|
| 222 | + ? $this->plugin_url.DomainBase::ASSETS_FOLDER.$additional_path |
|
| 223 | + : $this->plugin_url.DomainBase::ASSETS_FOLDER; |
|
| 224 | 224 | } |
| 225 | 225 | |
| 226 | 226 | |
@@ -91,7 +91,7 @@ |
||
| 91 | 91 | public function __construct($slug, $description) |
| 92 | 92 | { |
| 93 | 93 | parent::__construct($slug, $description); |
| 94 | - if (! in_array($this->slug(), $this->validRequestTypes(), true)) { |
|
| 94 | + if ( ! in_array($this->slug(), $this->validRequestTypes(), true)) { |
|
| 95 | 95 | throw new InvalidArgumentException( |
| 96 | 96 | sprintf( |
| 97 | 97 | esc_html__( |
@@ -16,185 +16,185 @@ |
||
| 16 | 16 | class RequestTypeContext extends Context |
| 17 | 17 | { |
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * indicates that the current request involves some form of activation |
|
| 21 | - */ |
|
| 22 | - const ACTIVATION = 'activation-request'; |
|
| 23 | - |
|
| 24 | - /** |
|
| 25 | - * indicates that the current request is for the admin but is not being made via AJAX |
|
| 26 | - */ |
|
| 27 | - const ADMIN = 'non-ajax-admin-request'; |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * indicates that the current request is for the admin AND is being made via AJAX |
|
| 31 | - */ |
|
| 32 | - const AJAX_ADMIN = 'admin-ajax-request'; |
|
| 33 | - |
|
| 34 | - /** |
|
| 35 | - * indicates that the current request is for the frontend AND is being made via AJAX |
|
| 36 | - */ |
|
| 37 | - const AJAX_FRONT = 'frontend-ajax-request'; |
|
| 38 | - |
|
| 39 | - /** |
|
| 40 | - * indicates that the current request is for the WP Heartbeat |
|
| 41 | - */ |
|
| 42 | - const AJAX_HEARTBEAT = 'admin-ajax-heartbeat'; |
|
| 43 | - |
|
| 44 | - /** |
|
| 45 | - * indicates that the current request is being made via AJAX, but is NOT for EE |
|
| 46 | - */ |
|
| 47 | - const AJAX_OTHER = 'other-ajax-request'; |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * indicates that the current request is for the EE REST API |
|
| 51 | - */ |
|
| 52 | - const API = 'rest-api'; |
|
| 53 | - |
|
| 54 | - /** |
|
| 55 | - * indicates that the current request is from the command line |
|
| 56 | - */ |
|
| 57 | - const CLI = 'command-line'; |
|
| 58 | - |
|
| 59 | - /** |
|
| 60 | - * indicates that the current request is for a WP_Cron |
|
| 61 | - */ |
|
| 62 | - const CRON = 'wp-cron'; |
|
| 63 | - |
|
| 64 | - /** |
|
| 65 | - * indicates that the current request is for a feed (ie: RSS) |
|
| 66 | - */ |
|
| 67 | - const FEED = 'feed-request'; |
|
| 68 | - |
|
| 69 | - /** |
|
| 70 | - * indicates that the current request is for the frontend but is not being made via AJAX |
|
| 71 | - */ |
|
| 72 | - const FRONTEND = 'non-ajax-frontend-request'; |
|
| 73 | - |
|
| 74 | - /** |
|
| 75 | - * indicates that the current request is for content that is to be displayed within an iframe |
|
| 76 | - */ |
|
| 77 | - const IFRAME = 'iframe-request'; |
|
| 78 | - |
|
| 79 | - /** |
|
| 80 | - * indicates that the current request is for the EE GraphQL manager |
|
| 81 | - */ |
|
| 82 | - const GQL = 'graphql'; |
|
| 83 | - |
|
| 84 | - /** |
|
| 85 | - * indicates that the current request is for the WP REST API |
|
| 86 | - */ |
|
| 87 | - const WP_API = 'wp-rest-api'; |
|
| 88 | - |
|
| 89 | - /** |
|
| 90 | - * indicates that the current request is a loopback sent from WP core to test for errors |
|
| 91 | - */ |
|
| 92 | - const WP_SCRAPE = 'wordpress-scrape'; |
|
| 93 | - |
|
| 94 | - /** |
|
| 95 | - * @var boolean $is_activation |
|
| 96 | - */ |
|
| 97 | - private $is_activation = false; |
|
| 98 | - |
|
| 99 | - /** |
|
| 100 | - * @var boolean $is_unit_testing |
|
| 101 | - */ |
|
| 102 | - private $is_unit_testing = false; |
|
| 103 | - |
|
| 104 | - /** |
|
| 105 | - * @var array $valid_request_types |
|
| 106 | - */ |
|
| 107 | - private $valid_request_types = array(); |
|
| 108 | - |
|
| 109 | - |
|
| 110 | - /** |
|
| 111 | - * RequestTypeContext constructor. |
|
| 112 | - * |
|
| 113 | - * @param string $slug |
|
| 114 | - * @param string $description |
|
| 115 | - * @throws InvalidArgumentException |
|
| 116 | - */ |
|
| 117 | - public function __construct($slug, $description) |
|
| 118 | - { |
|
| 119 | - parent::__construct($slug, $description); |
|
| 120 | - if (! in_array($this->slug(), $this->validRequestTypes(), true)) { |
|
| 121 | - throw new InvalidArgumentException( |
|
| 122 | - sprintf( |
|
| 123 | - esc_html__( |
|
| 124 | - 'The RequestTypeContext slug must be one of the following values: %1$s %2$s', |
|
| 125 | - 'event_espresso' |
|
| 126 | - ), |
|
| 127 | - '<br />', |
|
| 128 | - var_export($this->validRequestTypes(), true) |
|
| 129 | - ) |
|
| 130 | - ); |
|
| 131 | - } |
|
| 132 | - } |
|
| 133 | - |
|
| 134 | - |
|
| 135 | - /** |
|
| 136 | - * @return array |
|
| 137 | - */ |
|
| 138 | - public function validRequestTypes() |
|
| 139 | - { |
|
| 140 | - if (empty($this->valid_request_types)) { |
|
| 141 | - $this->valid_request_types = apply_filters( |
|
| 142 | - 'FHEE__EventEspresso_core_domain_entities_contexts_RequestTypeContext__validRequestTypes', |
|
| 143 | - array( |
|
| 144 | - RequestTypeContext::ACTIVATION, |
|
| 145 | - RequestTypeContext::ADMIN, |
|
| 146 | - RequestTypeContext::AJAX_ADMIN, |
|
| 147 | - RequestTypeContext::AJAX_FRONT, |
|
| 148 | - RequestTypeContext::AJAX_HEARTBEAT, |
|
| 149 | - RequestTypeContext::AJAX_OTHER, |
|
| 150 | - RequestTypeContext::API, |
|
| 151 | - RequestTypeContext::CLI, |
|
| 152 | - RequestTypeContext::CRON, |
|
| 153 | - RequestTypeContext::FEED, |
|
| 154 | - RequestTypeContext::FRONTEND, |
|
| 155 | - RequestTypeContext::GQL, |
|
| 156 | - RequestTypeContext::IFRAME, |
|
| 157 | - RequestTypeContext::WP_API, |
|
| 158 | - RequestTypeContext::WP_SCRAPE, |
|
| 159 | - ) |
|
| 160 | - ); |
|
| 161 | - } |
|
| 162 | - return $this->valid_request_types; |
|
| 163 | - } |
|
| 164 | - |
|
| 165 | - |
|
| 166 | - /** |
|
| 167 | - * @return bool |
|
| 168 | - */ |
|
| 169 | - public function isActivation() |
|
| 170 | - { |
|
| 171 | - return $this->is_activation; |
|
| 172 | - } |
|
| 173 | - |
|
| 174 | - |
|
| 175 | - /** |
|
| 176 | - * @param bool $is_activation |
|
| 177 | - */ |
|
| 178 | - public function setIsActivation($is_activation = false) |
|
| 179 | - { |
|
| 180 | - $this->is_activation = filter_var($is_activation, FILTER_VALIDATE_BOOLEAN); |
|
| 181 | - } |
|
| 182 | - |
|
| 183 | - |
|
| 184 | - /** |
|
| 185 | - * @return bool |
|
| 186 | - */ |
|
| 187 | - public function isUnitTesting() |
|
| 188 | - { |
|
| 189 | - return $this->is_unit_testing; |
|
| 190 | - } |
|
| 191 | - |
|
| 192 | - |
|
| 193 | - /** |
|
| 194 | - * @param bool $is_unit_testing |
|
| 195 | - */ |
|
| 196 | - public function setIsUnitTesting($is_unit_testing = false) |
|
| 197 | - { |
|
| 198 | - $this->is_unit_testing = filter_var($is_unit_testing, FILTER_VALIDATE_BOOLEAN); |
|
| 199 | - } |
|
| 19 | + /** |
|
| 20 | + * indicates that the current request involves some form of activation |
|
| 21 | + */ |
|
| 22 | + const ACTIVATION = 'activation-request'; |
|
| 23 | + |
|
| 24 | + /** |
|
| 25 | + * indicates that the current request is for the admin but is not being made via AJAX |
|
| 26 | + */ |
|
| 27 | + const ADMIN = 'non-ajax-admin-request'; |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * indicates that the current request is for the admin AND is being made via AJAX |
|
| 31 | + */ |
|
| 32 | + const AJAX_ADMIN = 'admin-ajax-request'; |
|
| 33 | + |
|
| 34 | + /** |
|
| 35 | + * indicates that the current request is for the frontend AND is being made via AJAX |
|
| 36 | + */ |
|
| 37 | + const AJAX_FRONT = 'frontend-ajax-request'; |
|
| 38 | + |
|
| 39 | + /** |
|
| 40 | + * indicates that the current request is for the WP Heartbeat |
|
| 41 | + */ |
|
| 42 | + const AJAX_HEARTBEAT = 'admin-ajax-heartbeat'; |
|
| 43 | + |
|
| 44 | + /** |
|
| 45 | + * indicates that the current request is being made via AJAX, but is NOT for EE |
|
| 46 | + */ |
|
| 47 | + const AJAX_OTHER = 'other-ajax-request'; |
|
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * indicates that the current request is for the EE REST API |
|
| 51 | + */ |
|
| 52 | + const API = 'rest-api'; |
|
| 53 | + |
|
| 54 | + /** |
|
| 55 | + * indicates that the current request is from the command line |
|
| 56 | + */ |
|
| 57 | + const CLI = 'command-line'; |
|
| 58 | + |
|
| 59 | + /** |
|
| 60 | + * indicates that the current request is for a WP_Cron |
|
| 61 | + */ |
|
| 62 | + const CRON = 'wp-cron'; |
|
| 63 | + |
|
| 64 | + /** |
|
| 65 | + * indicates that the current request is for a feed (ie: RSS) |
|
| 66 | + */ |
|
| 67 | + const FEED = 'feed-request'; |
|
| 68 | + |
|
| 69 | + /** |
|
| 70 | + * indicates that the current request is for the frontend but is not being made via AJAX |
|
| 71 | + */ |
|
| 72 | + const FRONTEND = 'non-ajax-frontend-request'; |
|
| 73 | + |
|
| 74 | + /** |
|
| 75 | + * indicates that the current request is for content that is to be displayed within an iframe |
|
| 76 | + */ |
|
| 77 | + const IFRAME = 'iframe-request'; |
|
| 78 | + |
|
| 79 | + /** |
|
| 80 | + * indicates that the current request is for the EE GraphQL manager |
|
| 81 | + */ |
|
| 82 | + const GQL = 'graphql'; |
|
| 83 | + |
|
| 84 | + /** |
|
| 85 | + * indicates that the current request is for the WP REST API |
|
| 86 | + */ |
|
| 87 | + const WP_API = 'wp-rest-api'; |
|
| 88 | + |
|
| 89 | + /** |
|
| 90 | + * indicates that the current request is a loopback sent from WP core to test for errors |
|
| 91 | + */ |
|
| 92 | + const WP_SCRAPE = 'wordpress-scrape'; |
|
| 93 | + |
|
| 94 | + /** |
|
| 95 | + * @var boolean $is_activation |
|
| 96 | + */ |
|
| 97 | + private $is_activation = false; |
|
| 98 | + |
|
| 99 | + /** |
|
| 100 | + * @var boolean $is_unit_testing |
|
| 101 | + */ |
|
| 102 | + private $is_unit_testing = false; |
|
| 103 | + |
|
| 104 | + /** |
|
| 105 | + * @var array $valid_request_types |
|
| 106 | + */ |
|
| 107 | + private $valid_request_types = array(); |
|
| 108 | + |
|
| 109 | + |
|
| 110 | + /** |
|
| 111 | + * RequestTypeContext constructor. |
|
| 112 | + * |
|
| 113 | + * @param string $slug |
|
| 114 | + * @param string $description |
|
| 115 | + * @throws InvalidArgumentException |
|
| 116 | + */ |
|
| 117 | + public function __construct($slug, $description) |
|
| 118 | + { |
|
| 119 | + parent::__construct($slug, $description); |
|
| 120 | + if (! in_array($this->slug(), $this->validRequestTypes(), true)) { |
|
| 121 | + throw new InvalidArgumentException( |
|
| 122 | + sprintf( |
|
| 123 | + esc_html__( |
|
| 124 | + 'The RequestTypeContext slug must be one of the following values: %1$s %2$s', |
|
| 125 | + 'event_espresso' |
|
| 126 | + ), |
|
| 127 | + '<br />', |
|
| 128 | + var_export($this->validRequestTypes(), true) |
|
| 129 | + ) |
|
| 130 | + ); |
|
| 131 | + } |
|
| 132 | + } |
|
| 133 | + |
|
| 134 | + |
|
| 135 | + /** |
|
| 136 | + * @return array |
|
| 137 | + */ |
|
| 138 | + public function validRequestTypes() |
|
| 139 | + { |
|
| 140 | + if (empty($this->valid_request_types)) { |
|
| 141 | + $this->valid_request_types = apply_filters( |
|
| 142 | + 'FHEE__EventEspresso_core_domain_entities_contexts_RequestTypeContext__validRequestTypes', |
|
| 143 | + array( |
|
| 144 | + RequestTypeContext::ACTIVATION, |
|
| 145 | + RequestTypeContext::ADMIN, |
|
| 146 | + RequestTypeContext::AJAX_ADMIN, |
|
| 147 | + RequestTypeContext::AJAX_FRONT, |
|
| 148 | + RequestTypeContext::AJAX_HEARTBEAT, |
|
| 149 | + RequestTypeContext::AJAX_OTHER, |
|
| 150 | + RequestTypeContext::API, |
|
| 151 | + RequestTypeContext::CLI, |
|
| 152 | + RequestTypeContext::CRON, |
|
| 153 | + RequestTypeContext::FEED, |
|
| 154 | + RequestTypeContext::FRONTEND, |
|
| 155 | + RequestTypeContext::GQL, |
|
| 156 | + RequestTypeContext::IFRAME, |
|
| 157 | + RequestTypeContext::WP_API, |
|
| 158 | + RequestTypeContext::WP_SCRAPE, |
|
| 159 | + ) |
|
| 160 | + ); |
|
| 161 | + } |
|
| 162 | + return $this->valid_request_types; |
|
| 163 | + } |
|
| 164 | + |
|
| 165 | + |
|
| 166 | + /** |
|
| 167 | + * @return bool |
|
| 168 | + */ |
|
| 169 | + public function isActivation() |
|
| 170 | + { |
|
| 171 | + return $this->is_activation; |
|
| 172 | + } |
|
| 173 | + |
|
| 174 | + |
|
| 175 | + /** |
|
| 176 | + * @param bool $is_activation |
|
| 177 | + */ |
|
| 178 | + public function setIsActivation($is_activation = false) |
|
| 179 | + { |
|
| 180 | + $this->is_activation = filter_var($is_activation, FILTER_VALIDATE_BOOLEAN); |
|
| 181 | + } |
|
| 182 | + |
|
| 183 | + |
|
| 184 | + /** |
|
| 185 | + * @return bool |
|
| 186 | + */ |
|
| 187 | + public function isUnitTesting() |
|
| 188 | + { |
|
| 189 | + return $this->is_unit_testing; |
|
| 190 | + } |
|
| 191 | + |
|
| 192 | + |
|
| 193 | + /** |
|
| 194 | + * @param bool $is_unit_testing |
|
| 195 | + */ |
|
| 196 | + public function setIsUnitTesting($is_unit_testing = false) |
|
| 197 | + { |
|
| 198 | + $this->is_unit_testing = filter_var($is_unit_testing, FILTER_VALIDATE_BOOLEAN); |
|
| 199 | + } |
|
| 200 | 200 | } |
@@ -251,7 +251,7 @@ |
||
| 251 | 251 | /** |
| 252 | 252 | * Identical in functionality to EEH_current_url except it removes any provided query_parameters from it. |
| 253 | 253 | * |
| 254 | - * @param array $query_parameters An array of query_parameters to remove from the current url. |
|
| 254 | + * @param string[] $query_parameters An array of query_parameters to remove from the current url. |
|
| 255 | 255 | * @since 4.9.46.rc.029 |
| 256 | 256 | * @return string |
| 257 | 257 | */ |
@@ -12,270 +12,270 @@ |
||
| 12 | 12 | class EEH_URL |
| 13 | 13 | { |
| 14 | 14 | |
| 15 | - /** |
|
| 16 | - * _add_query_arg |
|
| 17 | - * adds nonce to array of arguments then calls WP add_query_arg function |
|
| 18 | - * |
|
| 19 | - * @access public |
|
| 20 | - * @param array $args |
|
| 21 | - * @param string $url |
|
| 22 | - * @param bool $exclude_nonce If true then the nonce will be excluded from the generated url. |
|
| 23 | - * @return string |
|
| 24 | - */ |
|
| 25 | - public static function add_query_args_and_nonce($args = array(), $url = '', $exclude_nonce = false) |
|
| 26 | - { |
|
| 27 | - // check that an action exists and add nonce |
|
| 28 | - if (! $exclude_nonce) { |
|
| 29 | - if (isset($args['action']) && ! empty($args['action'])) { |
|
| 30 | - $args = array_merge( |
|
| 31 | - $args, |
|
| 32 | - array( |
|
| 33 | - $args['action'] . '_nonce' => wp_create_nonce($args['action'] . '_nonce') |
|
| 34 | - ) |
|
| 35 | - ); |
|
| 36 | - } else { |
|
| 37 | - $args = array_merge( |
|
| 38 | - $args, |
|
| 39 | - array( |
|
| 40 | - 'action' => 'default', 'default_nonce' => wp_create_nonce('default_nonce') |
|
| 41 | - ) |
|
| 42 | - ); |
|
| 43 | - } |
|
| 44 | - } |
|
| 15 | + /** |
|
| 16 | + * _add_query_arg |
|
| 17 | + * adds nonce to array of arguments then calls WP add_query_arg function |
|
| 18 | + * |
|
| 19 | + * @access public |
|
| 20 | + * @param array $args |
|
| 21 | + * @param string $url |
|
| 22 | + * @param bool $exclude_nonce If true then the nonce will be excluded from the generated url. |
|
| 23 | + * @return string |
|
| 24 | + */ |
|
| 25 | + public static function add_query_args_and_nonce($args = array(), $url = '', $exclude_nonce = false) |
|
| 26 | + { |
|
| 27 | + // check that an action exists and add nonce |
|
| 28 | + if (! $exclude_nonce) { |
|
| 29 | + if (isset($args['action']) && ! empty($args['action'])) { |
|
| 30 | + $args = array_merge( |
|
| 31 | + $args, |
|
| 32 | + array( |
|
| 33 | + $args['action'] . '_nonce' => wp_create_nonce($args['action'] . '_nonce') |
|
| 34 | + ) |
|
| 35 | + ); |
|
| 36 | + } else { |
|
| 37 | + $args = array_merge( |
|
| 38 | + $args, |
|
| 39 | + array( |
|
| 40 | + 'action' => 'default', 'default_nonce' => wp_create_nonce('default_nonce') |
|
| 41 | + ) |
|
| 42 | + ); |
|
| 43 | + } |
|
| 44 | + } |
|
| 45 | 45 | |
| 46 | - // finally, let's always add a return address (if present) :) |
|
| 47 | - $args = ! empty($_REQUEST['action']) && ! isset($_REQUEST['return']) |
|
| 48 | - ? array_merge($args, array('return' => $_REQUEST['action'])) |
|
| 49 | - : $args; |
|
| 46 | + // finally, let's always add a return address (if present) :) |
|
| 47 | + $args = ! empty($_REQUEST['action']) && ! isset($_REQUEST['return']) |
|
| 48 | + ? array_merge($args, array('return' => $_REQUEST['action'])) |
|
| 49 | + : $args; |
|
| 50 | 50 | |
| 51 | - return add_query_arg($args, $url); |
|
| 52 | - } |
|
| 51 | + return add_query_arg($args, $url); |
|
| 52 | + } |
|
| 53 | 53 | |
| 54 | 54 | |
| 55 | - /** |
|
| 56 | - * Returns whether not the remote file exists. |
|
| 57 | - * Checking via GET because HEAD requests are blocked on some server configurations. |
|
| 58 | - * |
|
| 59 | - * @param string $url |
|
| 60 | - * @param array $args the arguments that should be passed through to the wp_remote_request call. |
|
| 61 | - * @return boolean |
|
| 62 | - */ |
|
| 63 | - public static function remote_file_exists($url, $args = array()) |
|
| 64 | - { |
|
| 65 | - $results = wp_remote_request( |
|
| 66 | - $url, |
|
| 67 | - array_merge( |
|
| 68 | - array( |
|
| 69 | - 'method' => 'GET', |
|
| 70 | - 'redirection' => 1, |
|
| 71 | - ), |
|
| 72 | - $args |
|
| 73 | - ) |
|
| 74 | - ); |
|
| 75 | - if (! $results instanceof WP_Error && |
|
| 76 | - isset($results['response']) && |
|
| 77 | - isset($results['response']['code']) && |
|
| 78 | - $results['response']['code'] == '200') { |
|
| 79 | - return true; |
|
| 80 | - } else { |
|
| 81 | - return false; |
|
| 82 | - } |
|
| 83 | - } |
|
| 55 | + /** |
|
| 56 | + * Returns whether not the remote file exists. |
|
| 57 | + * Checking via GET because HEAD requests are blocked on some server configurations. |
|
| 58 | + * |
|
| 59 | + * @param string $url |
|
| 60 | + * @param array $args the arguments that should be passed through to the wp_remote_request call. |
|
| 61 | + * @return boolean |
|
| 62 | + */ |
|
| 63 | + public static function remote_file_exists($url, $args = array()) |
|
| 64 | + { |
|
| 65 | + $results = wp_remote_request( |
|
| 66 | + $url, |
|
| 67 | + array_merge( |
|
| 68 | + array( |
|
| 69 | + 'method' => 'GET', |
|
| 70 | + 'redirection' => 1, |
|
| 71 | + ), |
|
| 72 | + $args |
|
| 73 | + ) |
|
| 74 | + ); |
|
| 75 | + if (! $results instanceof WP_Error && |
|
| 76 | + isset($results['response']) && |
|
| 77 | + isset($results['response']['code']) && |
|
| 78 | + $results['response']['code'] == '200') { |
|
| 79 | + return true; |
|
| 80 | + } else { |
|
| 81 | + return false; |
|
| 82 | + } |
|
| 83 | + } |
|
| 84 | 84 | |
| 85 | 85 | |
| 86 | - /** |
|
| 87 | - * refactor_url |
|
| 88 | - * primarily used for removing the query string from a URL |
|
| 89 | - * |
|
| 90 | - * @param string $url |
|
| 91 | - * @param bool $remove_query - TRUE (default) will strip off any URL params, ie: ?this=1&that=2 |
|
| 92 | - * @param bool $base_url_only - TRUE will only return the scheme and host with no other parameters |
|
| 93 | - * @return string |
|
| 94 | - */ |
|
| 95 | - public static function refactor_url($url = '', $remove_query = true, $base_url_only = false) |
|
| 96 | - { |
|
| 97 | - // break apart incoming URL |
|
| 98 | - $url_bits = parse_url($url); |
|
| 99 | - // HTTP or HTTPS ? |
|
| 100 | - $scheme = isset($url_bits['scheme']) ? $url_bits['scheme'] . '://' : 'http://'; |
|
| 101 | - // domain |
|
| 102 | - $host = isset($url_bits['host']) ? $url_bits['host'] : ''; |
|
| 103 | - // if only the base URL is requested, then return that now |
|
| 104 | - if ($base_url_only) { |
|
| 105 | - return $scheme . $host; |
|
| 106 | - } |
|
| 107 | - $port = isset($url_bits['port']) ? ':' . $url_bits['port'] : ''; |
|
| 108 | - $user = isset($url_bits['user']) ? $url_bits['user'] : ''; |
|
| 109 | - $pass = isset($url_bits['pass']) ? ':' . $url_bits['pass'] : ''; |
|
| 110 | - $pass = ($user || $pass) ? $pass . '@' : ''; |
|
| 111 | - $path = isset($url_bits['path']) ? $url_bits['path'] : ''; |
|
| 112 | - // if the query string is not required, then return what we have so far |
|
| 113 | - if ($remove_query) { |
|
| 114 | - return $scheme . $user . $pass . $host . $port . $path; |
|
| 115 | - } |
|
| 116 | - $query = isset($url_bits['query']) ? '?' . $url_bits['query'] : ''; |
|
| 117 | - $fragment = isset($url_bits['fragment']) ? '#' . $url_bits['fragment'] : ''; |
|
| 118 | - return $scheme . $user . $pass . $host . $port . $path . $query . $fragment; |
|
| 119 | - } |
|
| 86 | + /** |
|
| 87 | + * refactor_url |
|
| 88 | + * primarily used for removing the query string from a URL |
|
| 89 | + * |
|
| 90 | + * @param string $url |
|
| 91 | + * @param bool $remove_query - TRUE (default) will strip off any URL params, ie: ?this=1&that=2 |
|
| 92 | + * @param bool $base_url_only - TRUE will only return the scheme and host with no other parameters |
|
| 93 | + * @return string |
|
| 94 | + */ |
|
| 95 | + public static function refactor_url($url = '', $remove_query = true, $base_url_only = false) |
|
| 96 | + { |
|
| 97 | + // break apart incoming URL |
|
| 98 | + $url_bits = parse_url($url); |
|
| 99 | + // HTTP or HTTPS ? |
|
| 100 | + $scheme = isset($url_bits['scheme']) ? $url_bits['scheme'] . '://' : 'http://'; |
|
| 101 | + // domain |
|
| 102 | + $host = isset($url_bits['host']) ? $url_bits['host'] : ''; |
|
| 103 | + // if only the base URL is requested, then return that now |
|
| 104 | + if ($base_url_only) { |
|
| 105 | + return $scheme . $host; |
|
| 106 | + } |
|
| 107 | + $port = isset($url_bits['port']) ? ':' . $url_bits['port'] : ''; |
|
| 108 | + $user = isset($url_bits['user']) ? $url_bits['user'] : ''; |
|
| 109 | + $pass = isset($url_bits['pass']) ? ':' . $url_bits['pass'] : ''; |
|
| 110 | + $pass = ($user || $pass) ? $pass . '@' : ''; |
|
| 111 | + $path = isset($url_bits['path']) ? $url_bits['path'] : ''; |
|
| 112 | + // if the query string is not required, then return what we have so far |
|
| 113 | + if ($remove_query) { |
|
| 114 | + return $scheme . $user . $pass . $host . $port . $path; |
|
| 115 | + } |
|
| 116 | + $query = isset($url_bits['query']) ? '?' . $url_bits['query'] : ''; |
|
| 117 | + $fragment = isset($url_bits['fragment']) ? '#' . $url_bits['fragment'] : ''; |
|
| 118 | + return $scheme . $user . $pass . $host . $port . $path . $query . $fragment; |
|
| 119 | + } |
|
| 120 | 120 | |
| 121 | 121 | |
| 122 | - /** |
|
| 123 | - * get_query_string |
|
| 124 | - * returns just the query string from a URL, formatted by default into an array of key value pairs |
|
| 125 | - * |
|
| 126 | - * @param string $url |
|
| 127 | - * @param bool $as_array TRUE (default) will return query params as an array of key value pairs, FALSE will |
|
| 128 | - * simply return the query string |
|
| 129 | - * @return string|array |
|
| 130 | - */ |
|
| 131 | - public static function get_query_string($url = '', $as_array = true) |
|
| 132 | - { |
|
| 133 | - // decode, then break apart incoming URL |
|
| 134 | - $url_bits = parse_url(html_entity_decode($url)); |
|
| 135 | - // grab query string from URL |
|
| 136 | - $query = isset($url_bits['query']) ? $url_bits['query'] : ''; |
|
| 137 | - // if we don't want the query string formatted into an array of key => value pairs, then just return it as is |
|
| 138 | - if (! $as_array) { |
|
| 139 | - return $query; |
|
| 140 | - } |
|
| 141 | - // if no query string exists then just return an empty array now |
|
| 142 | - if (empty($query)) { |
|
| 143 | - return array(); |
|
| 144 | - } |
|
| 145 | - // empty array to hold results |
|
| 146 | - $query_params = array(); |
|
| 147 | - // now break apart the query string into separate params |
|
| 148 | - $query = explode('&', $query); |
|
| 149 | - // loop thru our query params |
|
| 150 | - foreach ($query as $query_args) { |
|
| 151 | - // break apart the key value pairs |
|
| 152 | - $query_args = explode('=', $query_args); |
|
| 153 | - // and add to our results array |
|
| 154 | - $query_params[ $query_args[0] ] = $query_args[1]; |
|
| 155 | - } |
|
| 156 | - return $query_params; |
|
| 157 | - } |
|
| 122 | + /** |
|
| 123 | + * get_query_string |
|
| 124 | + * returns just the query string from a URL, formatted by default into an array of key value pairs |
|
| 125 | + * |
|
| 126 | + * @param string $url |
|
| 127 | + * @param bool $as_array TRUE (default) will return query params as an array of key value pairs, FALSE will |
|
| 128 | + * simply return the query string |
|
| 129 | + * @return string|array |
|
| 130 | + */ |
|
| 131 | + public static function get_query_string($url = '', $as_array = true) |
|
| 132 | + { |
|
| 133 | + // decode, then break apart incoming URL |
|
| 134 | + $url_bits = parse_url(html_entity_decode($url)); |
|
| 135 | + // grab query string from URL |
|
| 136 | + $query = isset($url_bits['query']) ? $url_bits['query'] : ''; |
|
| 137 | + // if we don't want the query string formatted into an array of key => value pairs, then just return it as is |
|
| 138 | + if (! $as_array) { |
|
| 139 | + return $query; |
|
| 140 | + } |
|
| 141 | + // if no query string exists then just return an empty array now |
|
| 142 | + if (empty($query)) { |
|
| 143 | + return array(); |
|
| 144 | + } |
|
| 145 | + // empty array to hold results |
|
| 146 | + $query_params = array(); |
|
| 147 | + // now break apart the query string into separate params |
|
| 148 | + $query = explode('&', $query); |
|
| 149 | + // loop thru our query params |
|
| 150 | + foreach ($query as $query_args) { |
|
| 151 | + // break apart the key value pairs |
|
| 152 | + $query_args = explode('=', $query_args); |
|
| 153 | + // and add to our results array |
|
| 154 | + $query_params[ $query_args[0] ] = $query_args[1]; |
|
| 155 | + } |
|
| 156 | + return $query_params; |
|
| 157 | + } |
|
| 158 | 158 | |
| 159 | 159 | |
| 160 | - /** |
|
| 161 | - * prevent_prefetching |
|
| 162 | - * |
|
| 163 | - * @return void |
|
| 164 | - */ |
|
| 165 | - public static function prevent_prefetching() |
|
| 166 | - { |
|
| 167 | - // prevent browsers from prefetching of the rel='next' link, because it may contain content that interferes |
|
| 168 | - // with the registration process |
|
| 169 | - remove_action('wp_head', 'adjacent_posts_rel_link_wp_head'); |
|
| 170 | - } |
|
| 160 | + /** |
|
| 161 | + * prevent_prefetching |
|
| 162 | + * |
|
| 163 | + * @return void |
|
| 164 | + */ |
|
| 165 | + public static function prevent_prefetching() |
|
| 166 | + { |
|
| 167 | + // prevent browsers from prefetching of the rel='next' link, because it may contain content that interferes |
|
| 168 | + // with the registration process |
|
| 169 | + remove_action('wp_head', 'adjacent_posts_rel_link_wp_head'); |
|
| 170 | + } |
|
| 171 | 171 | |
| 172 | 172 | |
| 173 | - /** |
|
| 174 | - * This generates a unique site-specific string. |
|
| 175 | - * An example usage for this string would be to save as a unique identifier for a record in the db for usage in |
|
| 176 | - * urls. |
|
| 177 | - * |
|
| 178 | - * @param string $prefix Use this to prefix the string with something. |
|
| 179 | - * @return string |
|
| 180 | - */ |
|
| 181 | - public static function generate_unique_token($prefix = '') |
|
| 182 | - { |
|
| 183 | - $token = md5(uniqid() . mt_rand()); |
|
| 184 | - return $prefix ? $prefix . '_' . $token : $token; |
|
| 185 | - } |
|
| 173 | + /** |
|
| 174 | + * This generates a unique site-specific string. |
|
| 175 | + * An example usage for this string would be to save as a unique identifier for a record in the db for usage in |
|
| 176 | + * urls. |
|
| 177 | + * |
|
| 178 | + * @param string $prefix Use this to prefix the string with something. |
|
| 179 | + * @return string |
|
| 180 | + */ |
|
| 181 | + public static function generate_unique_token($prefix = '') |
|
| 182 | + { |
|
| 183 | + $token = md5(uniqid() . mt_rand()); |
|
| 184 | + return $prefix ? $prefix . '_' . $token : $token; |
|
| 185 | + } |
|
| 186 | 186 | |
| 187 | 187 | |
| 188 | - /** |
|
| 189 | - * filter_input_server_url |
|
| 190 | - * uses filter_input() to sanitize one of the INPUT_SERVER URL values |
|
| 191 | - * but adds a backup in case filter_input() returns nothing, which can erringly happen on some servers |
|
| 192 | - * |
|
| 193 | - * @param string $server_variable |
|
| 194 | - * @return string |
|
| 195 | - */ |
|
| 196 | - public static function filter_input_server_url($server_variable = 'REQUEST_URI') |
|
| 197 | - { |
|
| 198 | - $URL = ''; |
|
| 199 | - $server_variables = array( |
|
| 200 | - 'REQUEST_URI' => 1, |
|
| 201 | - 'HTTP_HOST' => 1, |
|
| 202 | - 'PHP_SELF' => 1, |
|
| 203 | - ); |
|
| 204 | - $server_variable = strtoupper($server_variable); |
|
| 205 | - // whitelist INPUT_SERVER var |
|
| 206 | - if (isset($server_variables[ $server_variable ])) { |
|
| 207 | - $URL = filter_input(INPUT_SERVER, $server_variable, FILTER_SANITIZE_URL, FILTER_NULL_ON_FAILURE); |
|
| 208 | - if (empty($URL)) { |
|
| 209 | - // fallback sanitization if the above fails |
|
| 210 | - $URL = wp_sanitize_redirect($_SERVER[ $server_variable ]); |
|
| 211 | - } |
|
| 212 | - } |
|
| 213 | - return $URL; |
|
| 214 | - } |
|
| 188 | + /** |
|
| 189 | + * filter_input_server_url |
|
| 190 | + * uses filter_input() to sanitize one of the INPUT_SERVER URL values |
|
| 191 | + * but adds a backup in case filter_input() returns nothing, which can erringly happen on some servers |
|
| 192 | + * |
|
| 193 | + * @param string $server_variable |
|
| 194 | + * @return string |
|
| 195 | + */ |
|
| 196 | + public static function filter_input_server_url($server_variable = 'REQUEST_URI') |
|
| 197 | + { |
|
| 198 | + $URL = ''; |
|
| 199 | + $server_variables = array( |
|
| 200 | + 'REQUEST_URI' => 1, |
|
| 201 | + 'HTTP_HOST' => 1, |
|
| 202 | + 'PHP_SELF' => 1, |
|
| 203 | + ); |
|
| 204 | + $server_variable = strtoupper($server_variable); |
|
| 205 | + // whitelist INPUT_SERVER var |
|
| 206 | + if (isset($server_variables[ $server_variable ])) { |
|
| 207 | + $URL = filter_input(INPUT_SERVER, $server_variable, FILTER_SANITIZE_URL, FILTER_NULL_ON_FAILURE); |
|
| 208 | + if (empty($URL)) { |
|
| 209 | + // fallback sanitization if the above fails |
|
| 210 | + $URL = wp_sanitize_redirect($_SERVER[ $server_variable ]); |
|
| 211 | + } |
|
| 212 | + } |
|
| 213 | + return $URL; |
|
| 214 | + } |
|
| 215 | 215 | |
| 216 | 216 | |
| 217 | - /** |
|
| 218 | - * Gets the current page's full URL. |
|
| 219 | - * |
|
| 220 | - * @return string |
|
| 221 | - */ |
|
| 222 | - public static function current_url() |
|
| 223 | - { |
|
| 224 | - $url = ''; |
|
| 225 | - if (isset($_SERVER['HTTP_HOST'], $_SERVER['REQUEST_URI'])) { |
|
| 226 | - $url = is_ssl() ? 'https://' : 'http://'; |
|
| 227 | - $url .= \EEH_URL::filter_input_server_url('HTTP_HOST'); |
|
| 228 | - $url .= \EEH_URL::filter_input_server_url('REQUEST_URI'); |
|
| 229 | - } |
|
| 230 | - return $url; |
|
| 231 | - } |
|
| 217 | + /** |
|
| 218 | + * Gets the current page's full URL. |
|
| 219 | + * |
|
| 220 | + * @return string |
|
| 221 | + */ |
|
| 222 | + public static function current_url() |
|
| 223 | + { |
|
| 224 | + $url = ''; |
|
| 225 | + if (isset($_SERVER['HTTP_HOST'], $_SERVER['REQUEST_URI'])) { |
|
| 226 | + $url = is_ssl() ? 'https://' : 'http://'; |
|
| 227 | + $url .= \EEH_URL::filter_input_server_url('HTTP_HOST'); |
|
| 228 | + $url .= \EEH_URL::filter_input_server_url('REQUEST_URI'); |
|
| 229 | + } |
|
| 230 | + return $url; |
|
| 231 | + } |
|
| 232 | 232 | |
| 233 | 233 | |
| 234 | - /** |
|
| 235 | - * Identical in functionality to EEH_current_url except it removes any provided query_parameters from it. |
|
| 236 | - * |
|
| 237 | - * @param array $query_parameters An array of query_parameters to remove from the current url. |
|
| 238 | - * @since 4.9.46.rc.029 |
|
| 239 | - * @return string |
|
| 240 | - */ |
|
| 241 | - public static function current_url_without_query_paramaters(array $query_parameters) |
|
| 242 | - { |
|
| 243 | - return remove_query_arg($query_parameters, EEH_URL::current_url()); |
|
| 244 | - } |
|
| 234 | + /** |
|
| 235 | + * Identical in functionality to EEH_current_url except it removes any provided query_parameters from it. |
|
| 236 | + * |
|
| 237 | + * @param array $query_parameters An array of query_parameters to remove from the current url. |
|
| 238 | + * @since 4.9.46.rc.029 |
|
| 239 | + * @return string |
|
| 240 | + */ |
|
| 241 | + public static function current_url_without_query_paramaters(array $query_parameters) |
|
| 242 | + { |
|
| 243 | + return remove_query_arg($query_parameters, EEH_URL::current_url()); |
|
| 244 | + } |
|
| 245 | 245 | |
| 246 | 246 | |
| 247 | - /** |
|
| 248 | - * @param string $location |
|
| 249 | - * @param int $status |
|
| 250 | - * @param string $exit_notice |
|
| 251 | - */ |
|
| 252 | - public static function safeRedirectAndExit($location, $status = 302, $exit_notice = '') |
|
| 253 | - { |
|
| 254 | - EE_Error::get_notices(false, true); |
|
| 255 | - wp_safe_redirect($location, $status); |
|
| 256 | - exit($exit_notice); |
|
| 257 | - } |
|
| 247 | + /** |
|
| 248 | + * @param string $location |
|
| 249 | + * @param int $status |
|
| 250 | + * @param string $exit_notice |
|
| 251 | + */ |
|
| 252 | + public static function safeRedirectAndExit($location, $status = 302, $exit_notice = '') |
|
| 253 | + { |
|
| 254 | + EE_Error::get_notices(false, true); |
|
| 255 | + wp_safe_redirect($location, $status); |
|
| 256 | + exit($exit_notice); |
|
| 257 | + } |
|
| 258 | 258 | |
| 259 | - /** |
|
| 260 | - * Slugifies text for usage in a URL. |
|
| 261 | - * |
|
| 262 | - * Currently, this isn't just calling `sanitize_title()` on it, because that percent-encodes unicode characters, |
|
| 263 | - * and WordPress chokes on them when used as CPT and custom taxonomy slugs. |
|
| 264 | - * |
|
| 265 | - * @since 4.9.66.p |
|
| 266 | - * @param string $text |
|
| 267 | - * @param string $fallback |
|
| 268 | - * @return string which can be used in a URL |
|
| 269 | - */ |
|
| 270 | - public static function slugify($text, $fallback) |
|
| 271 | - { |
|
| 272 | - // url decode after sanitizing title to restore unicode characters, |
|
| 273 | - // see https://github.com/eventespresso/event-espresso-core/issues/575 |
|
| 274 | - return urldecode( |
|
| 275 | - sanitize_title( |
|
| 276 | - $text, |
|
| 277 | - $fallback |
|
| 278 | - ) |
|
| 279 | - ); |
|
| 280 | - } |
|
| 259 | + /** |
|
| 260 | + * Slugifies text for usage in a URL. |
|
| 261 | + * |
|
| 262 | + * Currently, this isn't just calling `sanitize_title()` on it, because that percent-encodes unicode characters, |
|
| 263 | + * and WordPress chokes on them when used as CPT and custom taxonomy slugs. |
|
| 264 | + * |
|
| 265 | + * @since 4.9.66.p |
|
| 266 | + * @param string $text |
|
| 267 | + * @param string $fallback |
|
| 268 | + * @return string which can be used in a URL |
|
| 269 | + */ |
|
| 270 | + public static function slugify($text, $fallback) |
|
| 271 | + { |
|
| 272 | + // url decode after sanitizing title to restore unicode characters, |
|
| 273 | + // see https://github.com/eventespresso/event-espresso-core/issues/575 |
|
| 274 | + return urldecode( |
|
| 275 | + sanitize_title( |
|
| 276 | + $text, |
|
| 277 | + $fallback |
|
| 278 | + ) |
|
| 279 | + ); |
|
| 280 | + } |
|
| 281 | 281 | } |
@@ -25,12 +25,12 @@ discard block |
||
| 25 | 25 | public static function add_query_args_and_nonce($args = array(), $url = '', $exclude_nonce = false) |
| 26 | 26 | { |
| 27 | 27 | // check that an action exists and add nonce |
| 28 | - if (! $exclude_nonce) { |
|
| 28 | + if ( ! $exclude_nonce) { |
|
| 29 | 29 | if (isset($args['action']) && ! empty($args['action'])) { |
| 30 | 30 | $args = array_merge( |
| 31 | 31 | $args, |
| 32 | 32 | array( |
| 33 | - $args['action'] . '_nonce' => wp_create_nonce($args['action'] . '_nonce') |
|
| 33 | + $args['action'].'_nonce' => wp_create_nonce($args['action'].'_nonce') |
|
| 34 | 34 | ) |
| 35 | 35 | ); |
| 36 | 36 | } else { |
@@ -72,7 +72,7 @@ discard block |
||
| 72 | 72 | $args |
| 73 | 73 | ) |
| 74 | 74 | ); |
| 75 | - if (! $results instanceof WP_Error && |
|
| 75 | + if ( ! $results instanceof WP_Error && |
|
| 76 | 76 | isset($results['response']) && |
| 77 | 77 | isset($results['response']['code']) && |
| 78 | 78 | $results['response']['code'] == '200') { |
@@ -97,25 +97,25 @@ discard block |
||
| 97 | 97 | // break apart incoming URL |
| 98 | 98 | $url_bits = parse_url($url); |
| 99 | 99 | // HTTP or HTTPS ? |
| 100 | - $scheme = isset($url_bits['scheme']) ? $url_bits['scheme'] . '://' : 'http://'; |
|
| 100 | + $scheme = isset($url_bits['scheme']) ? $url_bits['scheme'].'://' : 'http://'; |
|
| 101 | 101 | // domain |
| 102 | 102 | $host = isset($url_bits['host']) ? $url_bits['host'] : ''; |
| 103 | 103 | // if only the base URL is requested, then return that now |
| 104 | 104 | if ($base_url_only) { |
| 105 | - return $scheme . $host; |
|
| 105 | + return $scheme.$host; |
|
| 106 | 106 | } |
| 107 | - $port = isset($url_bits['port']) ? ':' . $url_bits['port'] : ''; |
|
| 107 | + $port = isset($url_bits['port']) ? ':'.$url_bits['port'] : ''; |
|
| 108 | 108 | $user = isset($url_bits['user']) ? $url_bits['user'] : ''; |
| 109 | - $pass = isset($url_bits['pass']) ? ':' . $url_bits['pass'] : ''; |
|
| 110 | - $pass = ($user || $pass) ? $pass . '@' : ''; |
|
| 109 | + $pass = isset($url_bits['pass']) ? ':'.$url_bits['pass'] : ''; |
|
| 110 | + $pass = ($user || $pass) ? $pass.'@' : ''; |
|
| 111 | 111 | $path = isset($url_bits['path']) ? $url_bits['path'] : ''; |
| 112 | 112 | // if the query string is not required, then return what we have so far |
| 113 | 113 | if ($remove_query) { |
| 114 | - return $scheme . $user . $pass . $host . $port . $path; |
|
| 114 | + return $scheme.$user.$pass.$host.$port.$path; |
|
| 115 | 115 | } |
| 116 | - $query = isset($url_bits['query']) ? '?' . $url_bits['query'] : ''; |
|
| 117 | - $fragment = isset($url_bits['fragment']) ? '#' . $url_bits['fragment'] : ''; |
|
| 118 | - return $scheme . $user . $pass . $host . $port . $path . $query . $fragment; |
|
| 116 | + $query = isset($url_bits['query']) ? '?'.$url_bits['query'] : ''; |
|
| 117 | + $fragment = isset($url_bits['fragment']) ? '#'.$url_bits['fragment'] : ''; |
|
| 118 | + return $scheme.$user.$pass.$host.$port.$path.$query.$fragment; |
|
| 119 | 119 | } |
| 120 | 120 | |
| 121 | 121 | |
@@ -135,7 +135,7 @@ discard block |
||
| 135 | 135 | // grab query string from URL |
| 136 | 136 | $query = isset($url_bits['query']) ? $url_bits['query'] : ''; |
| 137 | 137 | // if we don't want the query string formatted into an array of key => value pairs, then just return it as is |
| 138 | - if (! $as_array) { |
|
| 138 | + if ( ! $as_array) { |
|
| 139 | 139 | return $query; |
| 140 | 140 | } |
| 141 | 141 | // if no query string exists then just return an empty array now |
@@ -151,7 +151,7 @@ discard block |
||
| 151 | 151 | // break apart the key value pairs |
| 152 | 152 | $query_args = explode('=', $query_args); |
| 153 | 153 | // and add to our results array |
| 154 | - $query_params[ $query_args[0] ] = $query_args[1]; |
|
| 154 | + $query_params[$query_args[0]] = $query_args[1]; |
|
| 155 | 155 | } |
| 156 | 156 | return $query_params; |
| 157 | 157 | } |
@@ -180,8 +180,8 @@ discard block |
||
| 180 | 180 | */ |
| 181 | 181 | public static function generate_unique_token($prefix = '') |
| 182 | 182 | { |
| 183 | - $token = md5(uniqid() . mt_rand()); |
|
| 184 | - return $prefix ? $prefix . '_' . $token : $token; |
|
| 183 | + $token = md5(uniqid().mt_rand()); |
|
| 184 | + return $prefix ? $prefix.'_'.$token : $token; |
|
| 185 | 185 | } |
| 186 | 186 | |
| 187 | 187 | |
@@ -201,13 +201,13 @@ discard block |
||
| 201 | 201 | 'HTTP_HOST' => 1, |
| 202 | 202 | 'PHP_SELF' => 1, |
| 203 | 203 | ); |
| 204 | - $server_variable = strtoupper($server_variable); |
|
| 204 | + $server_variable = strtoupper($server_variable); |
|
| 205 | 205 | // whitelist INPUT_SERVER var |
| 206 | - if (isset($server_variables[ $server_variable ])) { |
|
| 206 | + if (isset($server_variables[$server_variable])) { |
|
| 207 | 207 | $URL = filter_input(INPUT_SERVER, $server_variable, FILTER_SANITIZE_URL, FILTER_NULL_ON_FAILURE); |
| 208 | 208 | if (empty($URL)) { |
| 209 | 209 | // fallback sanitization if the above fails |
| 210 | - $URL = wp_sanitize_redirect($_SERVER[ $server_variable ]); |
|
| 210 | + $URL = wp_sanitize_redirect($_SERVER[$server_variable]); |
|
| 211 | 211 | } |
| 212 | 212 | } |
| 213 | 213 | return $URL; |
@@ -505,7 +505,7 @@ |
||
| 505 | 505 | * |
| 506 | 506 | * @param string $value string to evaluate |
| 507 | 507 | * @param array $valid_shortcodes array of shortcodes that are acceptable. |
| 508 | - * @return mixed (bool|string) return either a list of invalid shortcodes OR false if the shortcodes validate. |
|
| 508 | + * @return false|string (bool|string) return either a list of invalid shortcodes OR false if the shortcodes validate. |
|
| 509 | 509 | */ |
| 510 | 510 | protected function _invalid_shortcodes($value, $valid_shortcodes) |
| 511 | 511 | { |
@@ -18,626 +18,626 @@ |
||
| 18 | 18 | { |
| 19 | 19 | |
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * These properties just hold the name for the Messenger and Message Type (defined by child classes). |
|
| 23 | - * These are used for retrieving objects etc. |
|
| 24 | - * |
|
| 25 | - * @var string |
|
| 26 | - */ |
|
| 27 | - protected $_m_name; |
|
| 28 | - protected $_mt_name; |
|
| 29 | - |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * This will hold any error messages from the validation process. |
|
| 33 | - * The _errors property holds an associative array of error messages |
|
| 34 | - * listing the field as the key and the message as the value. |
|
| 35 | - * |
|
| 36 | - * @var array() |
|
| 37 | - */ |
|
| 38 | - private $_errors = array(); |
|
| 39 | - |
|
| 40 | - |
|
| 41 | - /** |
|
| 42 | - * holds an array of fields being validated |
|
| 43 | - * |
|
| 44 | - * @var array |
|
| 45 | - */ |
|
| 46 | - protected $_fields; |
|
| 47 | - |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * this will hold the incoming context |
|
| 51 | - * |
|
| 52 | - * @var string |
|
| 53 | - */ |
|
| 54 | - protected $_context; |
|
| 55 | - |
|
| 56 | - |
|
| 57 | - /** |
|
| 58 | - * this holds an array of fields and the relevant validation information |
|
| 59 | - * that the incoming fields data get validated against. |
|
| 60 | - * This gets setup in the _set_props() method. |
|
| 61 | - * |
|
| 62 | - * @var array |
|
| 63 | - */ |
|
| 64 | - protected $_validators; |
|
| 65 | - |
|
| 66 | - |
|
| 67 | - /** |
|
| 68 | - * holds the messenger object |
|
| 69 | - * |
|
| 70 | - * @var object |
|
| 71 | - */ |
|
| 72 | - protected $_messenger; |
|
| 73 | - |
|
| 74 | - |
|
| 75 | - /** |
|
| 76 | - * holds the message type object |
|
| 77 | - * |
|
| 78 | - * @var object |
|
| 79 | - */ |
|
| 80 | - protected $_message_type; |
|
| 81 | - |
|
| 82 | - |
|
| 83 | - /** |
|
| 84 | - * will hold any valid_shortcode modifications made by the _modify_validator() method. |
|
| 85 | - * |
|
| 86 | - * @var array |
|
| 87 | - */ |
|
| 88 | - protected $_valid_shortcodes_modifier; |
|
| 89 | - |
|
| 90 | - |
|
| 91 | - /** |
|
| 92 | - * There may be times where a message type wants to include a shortcode group but exclude specific |
|
| 93 | - * shortcodes. If that's the case then it can set this property as an array of shortcodes to exclude and |
|
| 94 | - * they will not be allowed. |
|
| 95 | - * Array should be indexed by field and values are an array of specific shortcodes to exclude. |
|
| 96 | - * |
|
| 97 | - * @var array |
|
| 98 | - */ |
|
| 99 | - protected $_specific_shortcode_excludes = array(); |
|
| 100 | - |
|
| 101 | - |
|
| 102 | - /** |
|
| 103 | - * Runs the validator using the incoming fields array as the fields/values to check. |
|
| 104 | - * |
|
| 105 | - * @param array $fields The fields sent by the EEM object. |
|
| 106 | - * @param $context |
|
| 107 | - * @throws EE_Error |
|
| 108 | - * @throws ReflectionException |
|
| 109 | - */ |
|
| 110 | - public function __construct($fields, $context) |
|
| 111 | - { |
|
| 112 | - // check that _m_name and _mt_name have been set by child class otherwise we get out. |
|
| 113 | - if (empty($this->_m_name) || empty($this->_mt_name)) { |
|
| 114 | - throw new EE_Error( |
|
| 115 | - esc_html__( |
|
| 116 | - 'EE_Messages_Validator child classes MUST set the $_m_name and $_mt_name property. Check that the child class is doing this', |
|
| 117 | - 'event_espresso' |
|
| 118 | - ) |
|
| 119 | - ); |
|
| 120 | - } |
|
| 121 | - $this->_fields = $fields; |
|
| 122 | - $this->_context = $context; |
|
| 123 | - |
|
| 124 | - // load messenger and message_type objects and the related shortcode objects. |
|
| 125 | - $this->_load_objects(); |
|
| 126 | - |
|
| 127 | - |
|
| 128 | - // modify any messenger/message_type specific validation instructions. This is what child classes define. |
|
| 129 | - $this->_modify_validator(); |
|
| 130 | - |
|
| 131 | - |
|
| 132 | - // let's set validators property |
|
| 133 | - $this->_set_validators(); |
|
| 134 | - } |
|
| 135 | - |
|
| 136 | - |
|
| 137 | - /** |
|
| 138 | - * Child classes instantiate this and use it to modify the _validator_config array property |
|
| 139 | - * for the messenger using messengers set_validate_config() method. |
|
| 140 | - * This is so we can specify specific validation instructions for a messenger/message_type combo |
|
| 141 | - * that aren't handled by the defaults setup in the messenger. |
|
| 142 | - * |
|
| 143 | - * @abstract |
|
| 144 | - * @access protected |
|
| 145 | - * @return void |
|
| 146 | - */ |
|
| 147 | - abstract protected function _modify_validator(); |
|
| 148 | - |
|
| 149 | - |
|
| 150 | - /** |
|
| 151 | - * loads all objects used by validator |
|
| 152 | - * |
|
| 153 | - * @access private |
|
| 154 | - * @throws \EE_Error |
|
| 155 | - */ |
|
| 156 | - private function _load_objects() |
|
| 157 | - { |
|
| 158 | - // load messenger |
|
| 159 | - $messenger = ucwords(str_replace('_', ' ', $this->_m_name)); |
|
| 160 | - $messenger = str_replace(' ', '_', $messenger); |
|
| 161 | - $messenger = 'EE_' . $messenger . '_messenger'; |
|
| 162 | - |
|
| 163 | - if (! class_exists($messenger)) { |
|
| 164 | - throw new EE_Error( |
|
| 165 | - sprintf( |
|
| 166 | - esc_html__('There is no messenger class for the given string (%s)', 'event_espresso'), |
|
| 167 | - $this->_m_name |
|
| 168 | - ) |
|
| 169 | - ); |
|
| 170 | - } |
|
| 171 | - |
|
| 172 | - $this->_messenger = new $messenger(); |
|
| 173 | - |
|
| 174 | - // load message type |
|
| 175 | - $message_type = ucwords(str_replace('_', ' ', $this->_mt_name)); |
|
| 176 | - $message_type = str_replace(' ', '_', $message_type); |
|
| 177 | - $message_type = 'EE_' . $message_type . '_message_type'; |
|
| 178 | - |
|
| 179 | - if (! class_exists($message_type)) { |
|
| 180 | - throw new EE_Error( |
|
| 181 | - sprintf( |
|
| 182 | - esc_html__('There is no message type class for the given string (%s)', 'event_espresso'), |
|
| 183 | - $this->_mt_name |
|
| 184 | - ) |
|
| 185 | - ); |
|
| 186 | - } |
|
| 187 | - |
|
| 188 | - $this->_message_type = new $message_type(); |
|
| 189 | - } |
|
| 190 | - |
|
| 191 | - |
|
| 192 | - /** |
|
| 193 | - * used to set the $_validators property |
|
| 194 | - * |
|
| 195 | - * @access private |
|
| 196 | - * @return void |
|
| 197 | - * @throws ReflectionException |
|
| 198 | - */ |
|
| 199 | - private function _set_validators() |
|
| 200 | - { |
|
| 201 | - // let's get all valid shortcodes from mt and message type |
|
| 202 | - // (messenger will have its set in the _validator_config property for the messenger) |
|
| 203 | - $mt_codes = $this->_message_type->get_valid_shortcodes(); |
|
| 204 | - |
|
| 205 | - |
|
| 206 | - // get messenger validator_config |
|
| 207 | - $msgr_validator = $this->_messenger->get_validator_config(); |
|
| 208 | - |
|
| 209 | - |
|
| 210 | - // we only want the valid shortcodes for the given context! |
|
| 211 | - $context = $this->_context; |
|
| 212 | - $mt_codes = $mt_codes[ $context ]; |
|
| 213 | - |
|
| 214 | - // in this first loop we're just getting all shortcode group indexes from the msgr_validator |
|
| 215 | - // into a single array (so we can get the appropriate shortcode objects for the groups) |
|
| 216 | - $shortcode_groups = $mt_codes; |
|
| 217 | - $groups_per_field = array(); |
|
| 218 | - |
|
| 219 | - foreach ($msgr_validator as $field => $config) { |
|
| 220 | - if (empty($config) || ! isset($config['shortcodes'])) { |
|
| 221 | - continue; |
|
| 222 | - } //Nothing to see here. |
|
| 223 | - $groups_per_field[ $field ] = array_intersect($config['shortcodes'], $mt_codes); |
|
| 224 | - $shortcode_groups = array_merge($config['shortcodes'], $shortcode_groups); |
|
| 225 | - } |
|
| 226 | - |
|
| 227 | - $shortcode_groups = array_unique($shortcode_groups); |
|
| 228 | - |
|
| 229 | - // okay now we've got our groups. |
|
| 230 | - // Let's get the codes from the objects into an array indexed by group for easy retrieval later. |
|
| 231 | - $codes_from_objs = array(); |
|
| 232 | - |
|
| 233 | - foreach ($shortcode_groups as $group) { |
|
| 234 | - $ref = ucwords(str_replace('_', ' ', $group)); |
|
| 235 | - $ref = str_replace(' ', '_', $ref); |
|
| 236 | - $classname = 'EE_' . $ref . '_Shortcodes'; |
|
| 237 | - if (class_exists($classname)) { |
|
| 238 | - $a = new ReflectionClass($classname); |
|
| 239 | - $obj = $a->newInstance(); |
|
| 240 | - $codes_from_objs[ $group ] = $obj->get_shortcodes(); |
|
| 241 | - } |
|
| 242 | - } |
|
| 243 | - |
|
| 244 | - |
|
| 245 | - // let's just replace the $mt shortcode group indexes with the actual shortcodes (unique) |
|
| 246 | - $final_mt_codes = array(); |
|
| 247 | - foreach ($mt_codes as $group) { |
|
| 248 | - $final_mt_codes = array_merge($final_mt_codes, $codes_from_objs[ $group ]); |
|
| 249 | - } |
|
| 250 | - |
|
| 251 | - $mt_codes = $final_mt_codes; |
|
| 252 | - |
|
| 253 | - |
|
| 254 | - // k now in this next loop we're going to loop through $msgr_validator again |
|
| 255 | - // and setup the _validators property from the data we've setup so far. |
|
| 256 | - foreach ($msgr_validator as $field => $config) { |
|
| 257 | - // if required shortcode is not in our list of codes for the given field, then we skip this field. |
|
| 258 | - $required = isset($config['required']) |
|
| 259 | - ? array_intersect($config['required'], array_keys($mt_codes)) |
|
| 260 | - : true; |
|
| 261 | - if (empty($required)) { |
|
| 262 | - continue; |
|
| 263 | - } |
|
| 264 | - |
|
| 265 | - // If we have an override then we use it to indicate the codes we want. |
|
| 266 | - if (isset($this->_valid_shortcodes_modifier[ $context ][ $field ])) { |
|
| 267 | - $this->_validators[ $field ]['shortcodes'] = $this->_reassemble_valid_shortcodes_from_group( |
|
| 268 | - $this->_valid_shortcodes_modifier[ $context ][ $field ], |
|
| 269 | - $codes_from_objs |
|
| 270 | - ); |
|
| 271 | - } //if we have specific shortcodes for a field then we need to use them |
|
| 272 | - elseif (isset($groups_per_field[ $field ])) { |
|
| 273 | - $this->_validators[ $field ]['shortcodes'] = $this->_reassemble_valid_shortcodes_from_group( |
|
| 274 | - $groups_per_field[ $field ], |
|
| 275 | - $codes_from_objs |
|
| 276 | - ); |
|
| 277 | - } //if empty config then we're assuming we're just going to use the shortcodes from the message type context |
|
| 278 | - elseif (empty($config)) { |
|
| 279 | - $this->_validators[ $field ]['shortcodes'] = $mt_codes; |
|
| 280 | - } //if we have specific shortcodes then we need to use them |
|
| 281 | - elseif (isset($config['specific_shortcodes'])) { |
|
| 282 | - $this->_validators[ $field ]['shortcodes'] = $config['specific_shortcodes']; |
|
| 283 | - } //otherwise the shortcodes are what is set by the messenger for that field |
|
| 284 | - else { |
|
| 285 | - foreach ($config['shortcodes'] as $group) { |
|
| 286 | - $this->_validators[ $field ]['shortcodes'] = isset($this->_validators[ $field ]['shortcodes']) |
|
| 287 | - ? array_merge($this->_validators[ $field ]['shortcodes'], $codes_from_objs[ $group ]) |
|
| 288 | - : $codes_from_objs[ $group ]; |
|
| 289 | - } |
|
| 290 | - } |
|
| 291 | - |
|
| 292 | - // now let's just make sure that any excluded specific shortcodes are removed. |
|
| 293 | - $specific_excludes = $this->get_specific_shortcode_excludes(); |
|
| 294 | - if (isset($specific_excludes[ $field ])) { |
|
| 295 | - foreach ($specific_excludes[ $field ] as $sex) { |
|
| 296 | - if (isset($this->_validators[ $field ]['shortcodes'][ $sex ])) { |
|
| 297 | - unset($this->_validators[ $field ]['shortcodes'][ $sex ]); |
|
| 298 | - } |
|
| 299 | - } |
|
| 300 | - } |
|
| 301 | - |
|
| 302 | - // hey! don't forget to include the type if present! |
|
| 303 | - $this->_validators[ $field ]['type'] = isset($config['type']) ? $config['type'] : null; |
|
| 304 | - } |
|
| 305 | - } |
|
| 306 | - |
|
| 307 | - |
|
| 308 | - /** |
|
| 309 | - * This just returns the validators property that contains information |
|
| 310 | - * about the various shortcodes and their availability with each field |
|
| 311 | - * |
|
| 312 | - * @return array |
|
| 313 | - */ |
|
| 314 | - public function get_validators() |
|
| 315 | - { |
|
| 316 | - return $this->_validators; |
|
| 317 | - } |
|
| 318 | - |
|
| 319 | - |
|
| 320 | - /** |
|
| 321 | - * This simply returns the specific shortcode_excludes property that is set. |
|
| 322 | - * |
|
| 323 | - * @since 4.5.0 |
|
| 324 | - * @return array |
|
| 325 | - */ |
|
| 326 | - public function get_specific_shortcode_excludes() |
|
| 327 | - { |
|
| 328 | - // specific validator filter |
|
| 329 | - $shortcode_excludes = apply_filters( |
|
| 330 | - 'FHEE__' . get_class($this) . '__get_specific_shortcode_excludes;', |
|
| 331 | - $this->_specific_shortcode_excludes, |
|
| 332 | - $this->_context |
|
| 333 | - ); |
|
| 334 | - // global filter |
|
| 335 | - return apply_filters( |
|
| 336 | - 'FHEE__EE_Messages_Validator__get_specific_shortcode_excludes', |
|
| 337 | - $shortcode_excludes, |
|
| 338 | - $this->_context, |
|
| 339 | - $this |
|
| 340 | - ); |
|
| 341 | - } |
|
| 342 | - |
|
| 343 | - |
|
| 344 | - /** |
|
| 345 | - * This is the main method that handles validation |
|
| 346 | - * What it does is loop through the _fields (the ones that get validated) |
|
| 347 | - * and checks them against the shortcodes array for the field and the 'type' indicated by the |
|
| 348 | - * |
|
| 349 | - * @access public |
|
| 350 | - * @return mixed (bool|array) if errors present we return the array otherwise true |
|
| 351 | - */ |
|
| 352 | - public function validate() |
|
| 353 | - { |
|
| 354 | - // some defaults |
|
| 355 | - $template_fields = $this->_messenger->get_template_fields(); |
|
| 356 | - // loop through the fields and check! |
|
| 357 | - foreach ($this->_fields as $field => $value) { |
|
| 358 | - $this->_errors[ $field ] = array(); |
|
| 359 | - $err_msg = ''; |
|
| 360 | - $field_label = ''; |
|
| 361 | - // if field is not present in the _validators array then we continue |
|
| 362 | - if (! isset($this->_validators[ $field ])) { |
|
| 363 | - unset($this->_errors[ $field ]); |
|
| 364 | - continue; |
|
| 365 | - } |
|
| 366 | - |
|
| 367 | - // get the translated field label! |
|
| 368 | - // first check if it's in the main fields list |
|
| 369 | - if (isset($template_fields[ $field ])) { |
|
| 370 | - if (empty($template_fields[ $field ])) { |
|
| 371 | - $field_label = $field; |
|
| 372 | - } //most likely the field is found in the 'extra' array. |
|
| 373 | - else { |
|
| 374 | - $field_label = $template_fields[ $field ]['label']; |
|
| 375 | - } |
|
| 376 | - } |
|
| 377 | - |
|
| 378 | - // if field label is empty OR is equal to the current field |
|
| 379 | - // then we need to loop through the 'extra' fields in the template_fields config (if present) |
|
| 380 | - if (isset($template_fields['extra']) && (empty($field_label) || $field_label === $field)) { |
|
| 381 | - foreach ($template_fields['extra'] as $main_field => $secondary_field) { |
|
| 382 | - foreach ($secondary_field as $name => $values) { |
|
| 383 | - if ($name === $field) { |
|
| 384 | - $field_label = $values['label']; |
|
| 385 | - } |
|
| 386 | - |
|
| 387 | - // if we've got a 'main' secondary field, let's see if that matches what field we're on |
|
| 388 | - // which means it contains the label for this field. |
|
| 389 | - if ($name === 'main' && $main_field === $field_label) { |
|
| 390 | - $field_label = $values['label']; |
|
| 391 | - } |
|
| 392 | - } |
|
| 393 | - } |
|
| 394 | - } |
|
| 395 | - |
|
| 396 | - // field is present. Let's validate shortcodes first (but only if shortcodes present). |
|
| 397 | - if (isset($this->_validators[ $field ]['shortcodes']) |
|
| 398 | - && ! empty($this->_validators[ $field ]['shortcodes']) |
|
| 399 | - ) { |
|
| 400 | - $invalid_shortcodes = $this->_invalid_shortcodes($value, $this->_validators[ $field ]['shortcodes']); |
|
| 401 | - // if true then that means there is a returned error message |
|
| 402 | - // that we'll need to add to the _errors array for this field. |
|
| 403 | - if ($invalid_shortcodes) { |
|
| 404 | - $v_s = array_keys($this->_validators[ $field ]['shortcodes']); |
|
| 405 | - $err_msg = sprintf( |
|
| 406 | - esc_html__( |
|
| 407 | - '%3$sThe following shortcodes were found in the "%1$s" field that ARE not valid: %2$s%4$s', |
|
| 408 | - 'event_espresso' |
|
| 409 | - ), |
|
| 410 | - '<strong>' . $field_label . '</strong>', |
|
| 411 | - $invalid_shortcodes, |
|
| 412 | - '<p>', |
|
| 413 | - '</p >' |
|
| 414 | - ); |
|
| 415 | - $err_msg .= sprintf( |
|
| 416 | - esc_html__('%2$sValid shortcodes for this field are: %1$s%3$s', 'event_espresso'), |
|
| 417 | - implode(', ', $v_s), |
|
| 418 | - '<strong>', |
|
| 419 | - '</strong>' |
|
| 420 | - ); |
|
| 421 | - } |
|
| 422 | - } |
|
| 423 | - |
|
| 424 | - // if there's a "type" to be validated then let's do that too. |
|
| 425 | - if (isset($this->_validators[ $field ]['type']) && ! empty($this->_validators[ $field ]['type'])) { |
|
| 426 | - switch ($this->_validators[ $field ]['type']) { |
|
| 427 | - case 'number': |
|
| 428 | - if (! is_numeric($value)) { |
|
| 429 | - $err_msg .= sprintf( |
|
| 430 | - esc_html__( |
|
| 431 | - '%3$sThe %1$s field is supposed to be a number. The value given (%2$s) is not. Please double-check and make sure the field contains a number%4$s', |
|
| 432 | - 'event_espresso' |
|
| 433 | - ), |
|
| 434 | - $field_label, |
|
| 435 | - $value, |
|
| 436 | - '<p>', |
|
| 437 | - '</p >' |
|
| 438 | - ); |
|
| 439 | - } |
|
| 440 | - break; |
|
| 441 | - case 'email': |
|
| 442 | - $valid_email = $this->_validate_email($value); |
|
| 443 | - if (! $valid_email) { |
|
| 444 | - $err_msg .= htmlentities( |
|
| 445 | - sprintf( |
|
| 446 | - esc_html__( |
|
| 447 | - 'The %1$s field has at least one string that is not a valid email address record. Valid emails are in the format: "Name <[email protected]>" or "[email protected]" and multiple emails can be separated by a comma.', |
|
| 448 | - 'event_espresso' |
|
| 449 | - ), |
|
| 450 | - $field_label |
|
| 451 | - ) |
|
| 452 | - ); |
|
| 453 | - } |
|
| 454 | - break; |
|
| 455 | - default: |
|
| 456 | - break; |
|
| 457 | - } |
|
| 458 | - } |
|
| 459 | - |
|
| 460 | - // if $err_msg isn't empty let's setup the _errors array for this field. |
|
| 461 | - if (! empty($err_msg)) { |
|
| 462 | - $this->_errors[ $field ]['msg'] = $err_msg; |
|
| 463 | - } else { |
|
| 464 | - unset($this->_errors[ $field ]); |
|
| 465 | - } |
|
| 466 | - } |
|
| 467 | - |
|
| 468 | - // if we have ANY errors, then we want to make sure we return the values |
|
| 469 | - // for ALL the fields so the user doesn't have to retype them all. |
|
| 470 | - if (! empty($this->_errors)) { |
|
| 471 | - foreach ($this->_fields as $field => $value) { |
|
| 472 | - $this->_errors[ $field ]['value'] = stripslashes($value); |
|
| 473 | - } |
|
| 474 | - } |
|
| 475 | - |
|
| 476 | - // return any errors or just TRUE if everything validates |
|
| 477 | - return empty($this->_errors) ? true : $this->_errors; |
|
| 478 | - } |
|
| 479 | - |
|
| 480 | - |
|
| 481 | - /** |
|
| 482 | - * Reassembles and returns an array of valid shortcodes |
|
| 483 | - * given the array of groups and array of shortcodes indexed by group. |
|
| 484 | - * |
|
| 485 | - * @param array $groups array of shortcode groups that we want shortcodes for |
|
| 486 | - * @param array $codes_from_objs All the codes available. |
|
| 487 | - * @return array an array of actual shortcodes (that will be used for validation). |
|
| 488 | - */ |
|
| 489 | - private function _reassemble_valid_shortcodes_from_group($groups, $codes_from_objs) |
|
| 490 | - { |
|
| 491 | - $shortcodes = array(); |
|
| 492 | - foreach ($groups as $group) { |
|
| 493 | - $shortcodes = array_merge($shortcodes, $codes_from_objs[ $group ]); |
|
| 494 | - } |
|
| 495 | - return $shortcodes; |
|
| 496 | - } |
|
| 497 | - |
|
| 498 | - |
|
| 499 | - /** |
|
| 500 | - * Validates a string against a list of accepted shortcodes |
|
| 501 | - * This function takes in an array of shortcodes |
|
| 502 | - * and makes sure that the given string ONLY contains shortcodes in that array. |
|
| 503 | - * |
|
| 504 | - * @param string $value string to evaluate |
|
| 505 | - * @param array $valid_shortcodes array of shortcodes that are acceptable. |
|
| 506 | - * @return mixed (bool|string) return either a list of invalid shortcodes OR false if the shortcodes validate. |
|
| 507 | - */ |
|
| 508 | - protected function _invalid_shortcodes($value, $valid_shortcodes) |
|
| 509 | - { |
|
| 510 | - // first we need to go through the string and get the shortcodes in the string |
|
| 511 | - preg_match_all('/(\[.+?\])/', $value, $matches); |
|
| 512 | - $incoming_shortcodes = (array) $matches[0]; |
|
| 513 | - |
|
| 514 | - // get a diff of the shortcodes in the string vs the valid shortcodes |
|
| 515 | - $diff = array_diff($incoming_shortcodes, array_keys($valid_shortcodes)); |
|
| 516 | - |
|
| 517 | - // we need to account for custom codes so let's loop through the diff and remove any of those type of codes |
|
| 518 | - foreach ($diff as $ind => $code) { |
|
| 519 | - if (preg_match('/(\[[A-Za-z0-9\_]+_\*)/', $code)) { |
|
| 520 | - // strip the shortcode so we just have the BASE string (i.e. [ANSWER_*] ) |
|
| 521 | - $dynamic_sc = preg_replace('/(_\*+.+)/', '_*]', $code); |
|
| 522 | - // does this exist in the $valid_shortcodes? If so then unset. |
|
| 523 | - if (isset($valid_shortcodes[ $dynamic_sc ])) { |
|
| 524 | - unset($diff[ $ind ]); |
|
| 525 | - } |
|
| 526 | - } |
|
| 527 | - } |
|
| 528 | - |
|
| 529 | - if (empty($diff)) { |
|
| 530 | - return false; |
|
| 531 | - } //there is no diff, we have no invalid shortcodes, so return |
|
| 532 | - |
|
| 533 | - // made it here? then let's assemble the error message |
|
| 534 | - $invalid_shortcodes = implode('</strong>,<strong>', $diff); |
|
| 535 | - $invalid_shortcodes = '<strong>' . $invalid_shortcodes . '</strong>'; |
|
| 536 | - return $invalid_shortcodes; |
|
| 537 | - } |
|
| 538 | - |
|
| 539 | - |
|
| 540 | - /** |
|
| 541 | - * Validates an incoming string and makes sure we have valid emails in the string. |
|
| 542 | - * |
|
| 543 | - * @param string $value incoming value to validate |
|
| 544 | - * @return bool true if the string validates, false if it doesn't |
|
| 545 | - */ |
|
| 546 | - protected function _validate_email($value) |
|
| 547 | - { |
|
| 548 | - $validate = true; |
|
| 549 | - $or_val = $value; |
|
| 550 | - |
|
| 551 | - // empty strings will validate because this is how a message template |
|
| 552 | - // for a particular context can be "turned off" (if there is no email then no message) |
|
| 553 | - if (empty($value)) { |
|
| 554 | - return $validate; |
|
| 555 | - } |
|
| 556 | - |
|
| 557 | - // first determine if there ARE any shortcodes. |
|
| 558 | - // If there are shortcodes and then later we find that there were no other valid emails |
|
| 559 | - // but the field isn't empty... |
|
| 560 | - // that means we've got extra commas that were left after stripping out shortcodes so probably still valid. |
|
| 561 | - $has_shortcodes = preg_match('/(\[.+?\])/', $value); |
|
| 562 | - |
|
| 563 | - // first we need to strip out all the shortcodes! |
|
| 564 | - $value = preg_replace('/(\[.+?\])/', '', $value); |
|
| 565 | - |
|
| 566 | - // if original value is not empty and new value is, then we've parsed out a shortcode |
|
| 567 | - // and we now have an empty string which DOES validate. |
|
| 568 | - // We also validate complete empty field for email because |
|
| 569 | - // its possible that this message is being "turned off" for a particular context |
|
| 570 | - |
|
| 571 | - |
|
| 572 | - if (! empty($or_val) && empty($value)) { |
|
| 573 | - return $validate; |
|
| 574 | - } |
|
| 575 | - |
|
| 576 | - // trim any commas from beginning and end of string ( after whitespace trimmed ); |
|
| 577 | - $value = trim(trim($value), ','); |
|
| 578 | - |
|
| 579 | - |
|
| 580 | - // next we need to split up the string if its comma delimited. |
|
| 581 | - $emails = explode(',', $value); |
|
| 582 | - $empty = false; // used to indicate that there is an empty comma. |
|
| 583 | - // now let's loop through the emails and do our checks |
|
| 584 | - foreach ($emails as $email) { |
|
| 585 | - if (empty($email)) { |
|
| 586 | - $empty = true; |
|
| 587 | - continue; |
|
| 588 | - } |
|
| 589 | - |
|
| 590 | - // trim whitespace |
|
| 591 | - $email = trim($email); |
|
| 592 | - // either its of type "[email protected]", or its of type "fname lname <[email protected]>" |
|
| 593 | - if (is_email($email)) { |
|
| 594 | - continue; |
|
| 595 | - } |
|
| 596 | - $matches = array(); |
|
| 597 | - $validate = preg_match('/(.*)<(.+)>/', $email, $matches) ? true : false; |
|
| 598 | - if ($validate && is_email($matches[2])) { |
|
| 599 | - continue; |
|
| 600 | - } |
|
| 601 | - return false; |
|
| 602 | - } |
|
| 603 | - |
|
| 604 | - $validate = $empty && ! $has_shortcodes ? false : $validate; |
|
| 605 | - |
|
| 606 | - return $validate; |
|
| 607 | - } |
|
| 608 | - |
|
| 609 | - |
|
| 610 | - /** |
|
| 611 | - * Magic getter |
|
| 612 | - * Using this to provide back compat with add-ons referencing deprecated properties. |
|
| 613 | - * |
|
| 614 | - * @param string $property Property being requested |
|
| 615 | - * @throws Exception |
|
| 616 | - * @return mixed |
|
| 617 | - */ |
|
| 618 | - public function __get($property) |
|
| 619 | - { |
|
| 620 | - $expected_properties_map = array( |
|
| 621 | - /** |
|
| 622 | - * @deprecated 4.9.0 |
|
| 623 | - */ |
|
| 624 | - '_MSGR' => '_messenger', |
|
| 625 | - /** |
|
| 626 | - * @deprecated 4.9.0 |
|
| 627 | - */ |
|
| 628 | - '_MSGTYP' => '_message_type', |
|
| 629 | - ); |
|
| 630 | - |
|
| 631 | - if (isset($expected_properties_map[ $property ])) { |
|
| 632 | - return $this->{$expected_properties_map[ $property ]}; |
|
| 633 | - } |
|
| 634 | - |
|
| 635 | - throw new Exception( |
|
| 636 | - sprintf( |
|
| 637 | - esc_html__('The property %1$s being requested on %2$s does not exist', 'event_espresso'), |
|
| 638 | - $property, |
|
| 639 | - get_class($this) |
|
| 640 | - ) |
|
| 641 | - ); |
|
| 642 | - } |
|
| 21 | + /** |
|
| 22 | + * These properties just hold the name for the Messenger and Message Type (defined by child classes). |
|
| 23 | + * These are used for retrieving objects etc. |
|
| 24 | + * |
|
| 25 | + * @var string |
|
| 26 | + */ |
|
| 27 | + protected $_m_name; |
|
| 28 | + protected $_mt_name; |
|
| 29 | + |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * This will hold any error messages from the validation process. |
|
| 33 | + * The _errors property holds an associative array of error messages |
|
| 34 | + * listing the field as the key and the message as the value. |
|
| 35 | + * |
|
| 36 | + * @var array() |
|
| 37 | + */ |
|
| 38 | + private $_errors = array(); |
|
| 39 | + |
|
| 40 | + |
|
| 41 | + /** |
|
| 42 | + * holds an array of fields being validated |
|
| 43 | + * |
|
| 44 | + * @var array |
|
| 45 | + */ |
|
| 46 | + protected $_fields; |
|
| 47 | + |
|
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * this will hold the incoming context |
|
| 51 | + * |
|
| 52 | + * @var string |
|
| 53 | + */ |
|
| 54 | + protected $_context; |
|
| 55 | + |
|
| 56 | + |
|
| 57 | + /** |
|
| 58 | + * this holds an array of fields and the relevant validation information |
|
| 59 | + * that the incoming fields data get validated against. |
|
| 60 | + * This gets setup in the _set_props() method. |
|
| 61 | + * |
|
| 62 | + * @var array |
|
| 63 | + */ |
|
| 64 | + protected $_validators; |
|
| 65 | + |
|
| 66 | + |
|
| 67 | + /** |
|
| 68 | + * holds the messenger object |
|
| 69 | + * |
|
| 70 | + * @var object |
|
| 71 | + */ |
|
| 72 | + protected $_messenger; |
|
| 73 | + |
|
| 74 | + |
|
| 75 | + /** |
|
| 76 | + * holds the message type object |
|
| 77 | + * |
|
| 78 | + * @var object |
|
| 79 | + */ |
|
| 80 | + protected $_message_type; |
|
| 81 | + |
|
| 82 | + |
|
| 83 | + /** |
|
| 84 | + * will hold any valid_shortcode modifications made by the _modify_validator() method. |
|
| 85 | + * |
|
| 86 | + * @var array |
|
| 87 | + */ |
|
| 88 | + protected $_valid_shortcodes_modifier; |
|
| 89 | + |
|
| 90 | + |
|
| 91 | + /** |
|
| 92 | + * There may be times where a message type wants to include a shortcode group but exclude specific |
|
| 93 | + * shortcodes. If that's the case then it can set this property as an array of shortcodes to exclude and |
|
| 94 | + * they will not be allowed. |
|
| 95 | + * Array should be indexed by field and values are an array of specific shortcodes to exclude. |
|
| 96 | + * |
|
| 97 | + * @var array |
|
| 98 | + */ |
|
| 99 | + protected $_specific_shortcode_excludes = array(); |
|
| 100 | + |
|
| 101 | + |
|
| 102 | + /** |
|
| 103 | + * Runs the validator using the incoming fields array as the fields/values to check. |
|
| 104 | + * |
|
| 105 | + * @param array $fields The fields sent by the EEM object. |
|
| 106 | + * @param $context |
|
| 107 | + * @throws EE_Error |
|
| 108 | + * @throws ReflectionException |
|
| 109 | + */ |
|
| 110 | + public function __construct($fields, $context) |
|
| 111 | + { |
|
| 112 | + // check that _m_name and _mt_name have been set by child class otherwise we get out. |
|
| 113 | + if (empty($this->_m_name) || empty($this->_mt_name)) { |
|
| 114 | + throw new EE_Error( |
|
| 115 | + esc_html__( |
|
| 116 | + 'EE_Messages_Validator child classes MUST set the $_m_name and $_mt_name property. Check that the child class is doing this', |
|
| 117 | + 'event_espresso' |
|
| 118 | + ) |
|
| 119 | + ); |
|
| 120 | + } |
|
| 121 | + $this->_fields = $fields; |
|
| 122 | + $this->_context = $context; |
|
| 123 | + |
|
| 124 | + // load messenger and message_type objects and the related shortcode objects. |
|
| 125 | + $this->_load_objects(); |
|
| 126 | + |
|
| 127 | + |
|
| 128 | + // modify any messenger/message_type specific validation instructions. This is what child classes define. |
|
| 129 | + $this->_modify_validator(); |
|
| 130 | + |
|
| 131 | + |
|
| 132 | + // let's set validators property |
|
| 133 | + $this->_set_validators(); |
|
| 134 | + } |
|
| 135 | + |
|
| 136 | + |
|
| 137 | + /** |
|
| 138 | + * Child classes instantiate this and use it to modify the _validator_config array property |
|
| 139 | + * for the messenger using messengers set_validate_config() method. |
|
| 140 | + * This is so we can specify specific validation instructions for a messenger/message_type combo |
|
| 141 | + * that aren't handled by the defaults setup in the messenger. |
|
| 142 | + * |
|
| 143 | + * @abstract |
|
| 144 | + * @access protected |
|
| 145 | + * @return void |
|
| 146 | + */ |
|
| 147 | + abstract protected function _modify_validator(); |
|
| 148 | + |
|
| 149 | + |
|
| 150 | + /** |
|
| 151 | + * loads all objects used by validator |
|
| 152 | + * |
|
| 153 | + * @access private |
|
| 154 | + * @throws \EE_Error |
|
| 155 | + */ |
|
| 156 | + private function _load_objects() |
|
| 157 | + { |
|
| 158 | + // load messenger |
|
| 159 | + $messenger = ucwords(str_replace('_', ' ', $this->_m_name)); |
|
| 160 | + $messenger = str_replace(' ', '_', $messenger); |
|
| 161 | + $messenger = 'EE_' . $messenger . '_messenger'; |
|
| 162 | + |
|
| 163 | + if (! class_exists($messenger)) { |
|
| 164 | + throw new EE_Error( |
|
| 165 | + sprintf( |
|
| 166 | + esc_html__('There is no messenger class for the given string (%s)', 'event_espresso'), |
|
| 167 | + $this->_m_name |
|
| 168 | + ) |
|
| 169 | + ); |
|
| 170 | + } |
|
| 171 | + |
|
| 172 | + $this->_messenger = new $messenger(); |
|
| 173 | + |
|
| 174 | + // load message type |
|
| 175 | + $message_type = ucwords(str_replace('_', ' ', $this->_mt_name)); |
|
| 176 | + $message_type = str_replace(' ', '_', $message_type); |
|
| 177 | + $message_type = 'EE_' . $message_type . '_message_type'; |
|
| 178 | + |
|
| 179 | + if (! class_exists($message_type)) { |
|
| 180 | + throw new EE_Error( |
|
| 181 | + sprintf( |
|
| 182 | + esc_html__('There is no message type class for the given string (%s)', 'event_espresso'), |
|
| 183 | + $this->_mt_name |
|
| 184 | + ) |
|
| 185 | + ); |
|
| 186 | + } |
|
| 187 | + |
|
| 188 | + $this->_message_type = new $message_type(); |
|
| 189 | + } |
|
| 190 | + |
|
| 191 | + |
|
| 192 | + /** |
|
| 193 | + * used to set the $_validators property |
|
| 194 | + * |
|
| 195 | + * @access private |
|
| 196 | + * @return void |
|
| 197 | + * @throws ReflectionException |
|
| 198 | + */ |
|
| 199 | + private function _set_validators() |
|
| 200 | + { |
|
| 201 | + // let's get all valid shortcodes from mt and message type |
|
| 202 | + // (messenger will have its set in the _validator_config property for the messenger) |
|
| 203 | + $mt_codes = $this->_message_type->get_valid_shortcodes(); |
|
| 204 | + |
|
| 205 | + |
|
| 206 | + // get messenger validator_config |
|
| 207 | + $msgr_validator = $this->_messenger->get_validator_config(); |
|
| 208 | + |
|
| 209 | + |
|
| 210 | + // we only want the valid shortcodes for the given context! |
|
| 211 | + $context = $this->_context; |
|
| 212 | + $mt_codes = $mt_codes[ $context ]; |
|
| 213 | + |
|
| 214 | + // in this first loop we're just getting all shortcode group indexes from the msgr_validator |
|
| 215 | + // into a single array (so we can get the appropriate shortcode objects for the groups) |
|
| 216 | + $shortcode_groups = $mt_codes; |
|
| 217 | + $groups_per_field = array(); |
|
| 218 | + |
|
| 219 | + foreach ($msgr_validator as $field => $config) { |
|
| 220 | + if (empty($config) || ! isset($config['shortcodes'])) { |
|
| 221 | + continue; |
|
| 222 | + } //Nothing to see here. |
|
| 223 | + $groups_per_field[ $field ] = array_intersect($config['shortcodes'], $mt_codes); |
|
| 224 | + $shortcode_groups = array_merge($config['shortcodes'], $shortcode_groups); |
|
| 225 | + } |
|
| 226 | + |
|
| 227 | + $shortcode_groups = array_unique($shortcode_groups); |
|
| 228 | + |
|
| 229 | + // okay now we've got our groups. |
|
| 230 | + // Let's get the codes from the objects into an array indexed by group for easy retrieval later. |
|
| 231 | + $codes_from_objs = array(); |
|
| 232 | + |
|
| 233 | + foreach ($shortcode_groups as $group) { |
|
| 234 | + $ref = ucwords(str_replace('_', ' ', $group)); |
|
| 235 | + $ref = str_replace(' ', '_', $ref); |
|
| 236 | + $classname = 'EE_' . $ref . '_Shortcodes'; |
|
| 237 | + if (class_exists($classname)) { |
|
| 238 | + $a = new ReflectionClass($classname); |
|
| 239 | + $obj = $a->newInstance(); |
|
| 240 | + $codes_from_objs[ $group ] = $obj->get_shortcodes(); |
|
| 241 | + } |
|
| 242 | + } |
|
| 243 | + |
|
| 244 | + |
|
| 245 | + // let's just replace the $mt shortcode group indexes with the actual shortcodes (unique) |
|
| 246 | + $final_mt_codes = array(); |
|
| 247 | + foreach ($mt_codes as $group) { |
|
| 248 | + $final_mt_codes = array_merge($final_mt_codes, $codes_from_objs[ $group ]); |
|
| 249 | + } |
|
| 250 | + |
|
| 251 | + $mt_codes = $final_mt_codes; |
|
| 252 | + |
|
| 253 | + |
|
| 254 | + // k now in this next loop we're going to loop through $msgr_validator again |
|
| 255 | + // and setup the _validators property from the data we've setup so far. |
|
| 256 | + foreach ($msgr_validator as $field => $config) { |
|
| 257 | + // if required shortcode is not in our list of codes for the given field, then we skip this field. |
|
| 258 | + $required = isset($config['required']) |
|
| 259 | + ? array_intersect($config['required'], array_keys($mt_codes)) |
|
| 260 | + : true; |
|
| 261 | + if (empty($required)) { |
|
| 262 | + continue; |
|
| 263 | + } |
|
| 264 | + |
|
| 265 | + // If we have an override then we use it to indicate the codes we want. |
|
| 266 | + if (isset($this->_valid_shortcodes_modifier[ $context ][ $field ])) { |
|
| 267 | + $this->_validators[ $field ]['shortcodes'] = $this->_reassemble_valid_shortcodes_from_group( |
|
| 268 | + $this->_valid_shortcodes_modifier[ $context ][ $field ], |
|
| 269 | + $codes_from_objs |
|
| 270 | + ); |
|
| 271 | + } //if we have specific shortcodes for a field then we need to use them |
|
| 272 | + elseif (isset($groups_per_field[ $field ])) { |
|
| 273 | + $this->_validators[ $field ]['shortcodes'] = $this->_reassemble_valid_shortcodes_from_group( |
|
| 274 | + $groups_per_field[ $field ], |
|
| 275 | + $codes_from_objs |
|
| 276 | + ); |
|
| 277 | + } //if empty config then we're assuming we're just going to use the shortcodes from the message type context |
|
| 278 | + elseif (empty($config)) { |
|
| 279 | + $this->_validators[ $field ]['shortcodes'] = $mt_codes; |
|
| 280 | + } //if we have specific shortcodes then we need to use them |
|
| 281 | + elseif (isset($config['specific_shortcodes'])) { |
|
| 282 | + $this->_validators[ $field ]['shortcodes'] = $config['specific_shortcodes']; |
|
| 283 | + } //otherwise the shortcodes are what is set by the messenger for that field |
|
| 284 | + else { |
|
| 285 | + foreach ($config['shortcodes'] as $group) { |
|
| 286 | + $this->_validators[ $field ]['shortcodes'] = isset($this->_validators[ $field ]['shortcodes']) |
|
| 287 | + ? array_merge($this->_validators[ $field ]['shortcodes'], $codes_from_objs[ $group ]) |
|
| 288 | + : $codes_from_objs[ $group ]; |
|
| 289 | + } |
|
| 290 | + } |
|
| 291 | + |
|
| 292 | + // now let's just make sure that any excluded specific shortcodes are removed. |
|
| 293 | + $specific_excludes = $this->get_specific_shortcode_excludes(); |
|
| 294 | + if (isset($specific_excludes[ $field ])) { |
|
| 295 | + foreach ($specific_excludes[ $field ] as $sex) { |
|
| 296 | + if (isset($this->_validators[ $field ]['shortcodes'][ $sex ])) { |
|
| 297 | + unset($this->_validators[ $field ]['shortcodes'][ $sex ]); |
|
| 298 | + } |
|
| 299 | + } |
|
| 300 | + } |
|
| 301 | + |
|
| 302 | + // hey! don't forget to include the type if present! |
|
| 303 | + $this->_validators[ $field ]['type'] = isset($config['type']) ? $config['type'] : null; |
|
| 304 | + } |
|
| 305 | + } |
|
| 306 | + |
|
| 307 | + |
|
| 308 | + /** |
|
| 309 | + * This just returns the validators property that contains information |
|
| 310 | + * about the various shortcodes and their availability with each field |
|
| 311 | + * |
|
| 312 | + * @return array |
|
| 313 | + */ |
|
| 314 | + public function get_validators() |
|
| 315 | + { |
|
| 316 | + return $this->_validators; |
|
| 317 | + } |
|
| 318 | + |
|
| 319 | + |
|
| 320 | + /** |
|
| 321 | + * This simply returns the specific shortcode_excludes property that is set. |
|
| 322 | + * |
|
| 323 | + * @since 4.5.0 |
|
| 324 | + * @return array |
|
| 325 | + */ |
|
| 326 | + public function get_specific_shortcode_excludes() |
|
| 327 | + { |
|
| 328 | + // specific validator filter |
|
| 329 | + $shortcode_excludes = apply_filters( |
|
| 330 | + 'FHEE__' . get_class($this) . '__get_specific_shortcode_excludes;', |
|
| 331 | + $this->_specific_shortcode_excludes, |
|
| 332 | + $this->_context |
|
| 333 | + ); |
|
| 334 | + // global filter |
|
| 335 | + return apply_filters( |
|
| 336 | + 'FHEE__EE_Messages_Validator__get_specific_shortcode_excludes', |
|
| 337 | + $shortcode_excludes, |
|
| 338 | + $this->_context, |
|
| 339 | + $this |
|
| 340 | + ); |
|
| 341 | + } |
|
| 342 | + |
|
| 343 | + |
|
| 344 | + /** |
|
| 345 | + * This is the main method that handles validation |
|
| 346 | + * What it does is loop through the _fields (the ones that get validated) |
|
| 347 | + * and checks them against the shortcodes array for the field and the 'type' indicated by the |
|
| 348 | + * |
|
| 349 | + * @access public |
|
| 350 | + * @return mixed (bool|array) if errors present we return the array otherwise true |
|
| 351 | + */ |
|
| 352 | + public function validate() |
|
| 353 | + { |
|
| 354 | + // some defaults |
|
| 355 | + $template_fields = $this->_messenger->get_template_fields(); |
|
| 356 | + // loop through the fields and check! |
|
| 357 | + foreach ($this->_fields as $field => $value) { |
|
| 358 | + $this->_errors[ $field ] = array(); |
|
| 359 | + $err_msg = ''; |
|
| 360 | + $field_label = ''; |
|
| 361 | + // if field is not present in the _validators array then we continue |
|
| 362 | + if (! isset($this->_validators[ $field ])) { |
|
| 363 | + unset($this->_errors[ $field ]); |
|
| 364 | + continue; |
|
| 365 | + } |
|
| 366 | + |
|
| 367 | + // get the translated field label! |
|
| 368 | + // first check if it's in the main fields list |
|
| 369 | + if (isset($template_fields[ $field ])) { |
|
| 370 | + if (empty($template_fields[ $field ])) { |
|
| 371 | + $field_label = $field; |
|
| 372 | + } //most likely the field is found in the 'extra' array. |
|
| 373 | + else { |
|
| 374 | + $field_label = $template_fields[ $field ]['label']; |
|
| 375 | + } |
|
| 376 | + } |
|
| 377 | + |
|
| 378 | + // if field label is empty OR is equal to the current field |
|
| 379 | + // then we need to loop through the 'extra' fields in the template_fields config (if present) |
|
| 380 | + if (isset($template_fields['extra']) && (empty($field_label) || $field_label === $field)) { |
|
| 381 | + foreach ($template_fields['extra'] as $main_field => $secondary_field) { |
|
| 382 | + foreach ($secondary_field as $name => $values) { |
|
| 383 | + if ($name === $field) { |
|
| 384 | + $field_label = $values['label']; |
|
| 385 | + } |
|
| 386 | + |
|
| 387 | + // if we've got a 'main' secondary field, let's see if that matches what field we're on |
|
| 388 | + // which means it contains the label for this field. |
|
| 389 | + if ($name === 'main' && $main_field === $field_label) { |
|
| 390 | + $field_label = $values['label']; |
|
| 391 | + } |
|
| 392 | + } |
|
| 393 | + } |
|
| 394 | + } |
|
| 395 | + |
|
| 396 | + // field is present. Let's validate shortcodes first (but only if shortcodes present). |
|
| 397 | + if (isset($this->_validators[ $field ]['shortcodes']) |
|
| 398 | + && ! empty($this->_validators[ $field ]['shortcodes']) |
|
| 399 | + ) { |
|
| 400 | + $invalid_shortcodes = $this->_invalid_shortcodes($value, $this->_validators[ $field ]['shortcodes']); |
|
| 401 | + // if true then that means there is a returned error message |
|
| 402 | + // that we'll need to add to the _errors array for this field. |
|
| 403 | + if ($invalid_shortcodes) { |
|
| 404 | + $v_s = array_keys($this->_validators[ $field ]['shortcodes']); |
|
| 405 | + $err_msg = sprintf( |
|
| 406 | + esc_html__( |
|
| 407 | + '%3$sThe following shortcodes were found in the "%1$s" field that ARE not valid: %2$s%4$s', |
|
| 408 | + 'event_espresso' |
|
| 409 | + ), |
|
| 410 | + '<strong>' . $field_label . '</strong>', |
|
| 411 | + $invalid_shortcodes, |
|
| 412 | + '<p>', |
|
| 413 | + '</p >' |
|
| 414 | + ); |
|
| 415 | + $err_msg .= sprintf( |
|
| 416 | + esc_html__('%2$sValid shortcodes for this field are: %1$s%3$s', 'event_espresso'), |
|
| 417 | + implode(', ', $v_s), |
|
| 418 | + '<strong>', |
|
| 419 | + '</strong>' |
|
| 420 | + ); |
|
| 421 | + } |
|
| 422 | + } |
|
| 423 | + |
|
| 424 | + // if there's a "type" to be validated then let's do that too. |
|
| 425 | + if (isset($this->_validators[ $field ]['type']) && ! empty($this->_validators[ $field ]['type'])) { |
|
| 426 | + switch ($this->_validators[ $field ]['type']) { |
|
| 427 | + case 'number': |
|
| 428 | + if (! is_numeric($value)) { |
|
| 429 | + $err_msg .= sprintf( |
|
| 430 | + esc_html__( |
|
| 431 | + '%3$sThe %1$s field is supposed to be a number. The value given (%2$s) is not. Please double-check and make sure the field contains a number%4$s', |
|
| 432 | + 'event_espresso' |
|
| 433 | + ), |
|
| 434 | + $field_label, |
|
| 435 | + $value, |
|
| 436 | + '<p>', |
|
| 437 | + '</p >' |
|
| 438 | + ); |
|
| 439 | + } |
|
| 440 | + break; |
|
| 441 | + case 'email': |
|
| 442 | + $valid_email = $this->_validate_email($value); |
|
| 443 | + if (! $valid_email) { |
|
| 444 | + $err_msg .= htmlentities( |
|
| 445 | + sprintf( |
|
| 446 | + esc_html__( |
|
| 447 | + 'The %1$s field has at least one string that is not a valid email address record. Valid emails are in the format: "Name <[email protected]>" or "[email protected]" and multiple emails can be separated by a comma.', |
|
| 448 | + 'event_espresso' |
|
| 449 | + ), |
|
| 450 | + $field_label |
|
| 451 | + ) |
|
| 452 | + ); |
|
| 453 | + } |
|
| 454 | + break; |
|
| 455 | + default: |
|
| 456 | + break; |
|
| 457 | + } |
|
| 458 | + } |
|
| 459 | + |
|
| 460 | + // if $err_msg isn't empty let's setup the _errors array for this field. |
|
| 461 | + if (! empty($err_msg)) { |
|
| 462 | + $this->_errors[ $field ]['msg'] = $err_msg; |
|
| 463 | + } else { |
|
| 464 | + unset($this->_errors[ $field ]); |
|
| 465 | + } |
|
| 466 | + } |
|
| 467 | + |
|
| 468 | + // if we have ANY errors, then we want to make sure we return the values |
|
| 469 | + // for ALL the fields so the user doesn't have to retype them all. |
|
| 470 | + if (! empty($this->_errors)) { |
|
| 471 | + foreach ($this->_fields as $field => $value) { |
|
| 472 | + $this->_errors[ $field ]['value'] = stripslashes($value); |
|
| 473 | + } |
|
| 474 | + } |
|
| 475 | + |
|
| 476 | + // return any errors or just TRUE if everything validates |
|
| 477 | + return empty($this->_errors) ? true : $this->_errors; |
|
| 478 | + } |
|
| 479 | + |
|
| 480 | + |
|
| 481 | + /** |
|
| 482 | + * Reassembles and returns an array of valid shortcodes |
|
| 483 | + * given the array of groups and array of shortcodes indexed by group. |
|
| 484 | + * |
|
| 485 | + * @param array $groups array of shortcode groups that we want shortcodes for |
|
| 486 | + * @param array $codes_from_objs All the codes available. |
|
| 487 | + * @return array an array of actual shortcodes (that will be used for validation). |
|
| 488 | + */ |
|
| 489 | + private function _reassemble_valid_shortcodes_from_group($groups, $codes_from_objs) |
|
| 490 | + { |
|
| 491 | + $shortcodes = array(); |
|
| 492 | + foreach ($groups as $group) { |
|
| 493 | + $shortcodes = array_merge($shortcodes, $codes_from_objs[ $group ]); |
|
| 494 | + } |
|
| 495 | + return $shortcodes; |
|
| 496 | + } |
|
| 497 | + |
|
| 498 | + |
|
| 499 | + /** |
|
| 500 | + * Validates a string against a list of accepted shortcodes |
|
| 501 | + * This function takes in an array of shortcodes |
|
| 502 | + * and makes sure that the given string ONLY contains shortcodes in that array. |
|
| 503 | + * |
|
| 504 | + * @param string $value string to evaluate |
|
| 505 | + * @param array $valid_shortcodes array of shortcodes that are acceptable. |
|
| 506 | + * @return mixed (bool|string) return either a list of invalid shortcodes OR false if the shortcodes validate. |
|
| 507 | + */ |
|
| 508 | + protected function _invalid_shortcodes($value, $valid_shortcodes) |
|
| 509 | + { |
|
| 510 | + // first we need to go through the string and get the shortcodes in the string |
|
| 511 | + preg_match_all('/(\[.+?\])/', $value, $matches); |
|
| 512 | + $incoming_shortcodes = (array) $matches[0]; |
|
| 513 | + |
|
| 514 | + // get a diff of the shortcodes in the string vs the valid shortcodes |
|
| 515 | + $diff = array_diff($incoming_shortcodes, array_keys($valid_shortcodes)); |
|
| 516 | + |
|
| 517 | + // we need to account for custom codes so let's loop through the diff and remove any of those type of codes |
|
| 518 | + foreach ($diff as $ind => $code) { |
|
| 519 | + if (preg_match('/(\[[A-Za-z0-9\_]+_\*)/', $code)) { |
|
| 520 | + // strip the shortcode so we just have the BASE string (i.e. [ANSWER_*] ) |
|
| 521 | + $dynamic_sc = preg_replace('/(_\*+.+)/', '_*]', $code); |
|
| 522 | + // does this exist in the $valid_shortcodes? If so then unset. |
|
| 523 | + if (isset($valid_shortcodes[ $dynamic_sc ])) { |
|
| 524 | + unset($diff[ $ind ]); |
|
| 525 | + } |
|
| 526 | + } |
|
| 527 | + } |
|
| 528 | + |
|
| 529 | + if (empty($diff)) { |
|
| 530 | + return false; |
|
| 531 | + } //there is no diff, we have no invalid shortcodes, so return |
|
| 532 | + |
|
| 533 | + // made it here? then let's assemble the error message |
|
| 534 | + $invalid_shortcodes = implode('</strong>,<strong>', $diff); |
|
| 535 | + $invalid_shortcodes = '<strong>' . $invalid_shortcodes . '</strong>'; |
|
| 536 | + return $invalid_shortcodes; |
|
| 537 | + } |
|
| 538 | + |
|
| 539 | + |
|
| 540 | + /** |
|
| 541 | + * Validates an incoming string and makes sure we have valid emails in the string. |
|
| 542 | + * |
|
| 543 | + * @param string $value incoming value to validate |
|
| 544 | + * @return bool true if the string validates, false if it doesn't |
|
| 545 | + */ |
|
| 546 | + protected function _validate_email($value) |
|
| 547 | + { |
|
| 548 | + $validate = true; |
|
| 549 | + $or_val = $value; |
|
| 550 | + |
|
| 551 | + // empty strings will validate because this is how a message template |
|
| 552 | + // for a particular context can be "turned off" (if there is no email then no message) |
|
| 553 | + if (empty($value)) { |
|
| 554 | + return $validate; |
|
| 555 | + } |
|
| 556 | + |
|
| 557 | + // first determine if there ARE any shortcodes. |
|
| 558 | + // If there are shortcodes and then later we find that there were no other valid emails |
|
| 559 | + // but the field isn't empty... |
|
| 560 | + // that means we've got extra commas that were left after stripping out shortcodes so probably still valid. |
|
| 561 | + $has_shortcodes = preg_match('/(\[.+?\])/', $value); |
|
| 562 | + |
|
| 563 | + // first we need to strip out all the shortcodes! |
|
| 564 | + $value = preg_replace('/(\[.+?\])/', '', $value); |
|
| 565 | + |
|
| 566 | + // if original value is not empty and new value is, then we've parsed out a shortcode |
|
| 567 | + // and we now have an empty string which DOES validate. |
|
| 568 | + // We also validate complete empty field for email because |
|
| 569 | + // its possible that this message is being "turned off" for a particular context |
|
| 570 | + |
|
| 571 | + |
|
| 572 | + if (! empty($or_val) && empty($value)) { |
|
| 573 | + return $validate; |
|
| 574 | + } |
|
| 575 | + |
|
| 576 | + // trim any commas from beginning and end of string ( after whitespace trimmed ); |
|
| 577 | + $value = trim(trim($value), ','); |
|
| 578 | + |
|
| 579 | + |
|
| 580 | + // next we need to split up the string if its comma delimited. |
|
| 581 | + $emails = explode(',', $value); |
|
| 582 | + $empty = false; // used to indicate that there is an empty comma. |
|
| 583 | + // now let's loop through the emails and do our checks |
|
| 584 | + foreach ($emails as $email) { |
|
| 585 | + if (empty($email)) { |
|
| 586 | + $empty = true; |
|
| 587 | + continue; |
|
| 588 | + } |
|
| 589 | + |
|
| 590 | + // trim whitespace |
|
| 591 | + $email = trim($email); |
|
| 592 | + // either its of type "[email protected]", or its of type "fname lname <[email protected]>" |
|
| 593 | + if (is_email($email)) { |
|
| 594 | + continue; |
|
| 595 | + } |
|
| 596 | + $matches = array(); |
|
| 597 | + $validate = preg_match('/(.*)<(.+)>/', $email, $matches) ? true : false; |
|
| 598 | + if ($validate && is_email($matches[2])) { |
|
| 599 | + continue; |
|
| 600 | + } |
|
| 601 | + return false; |
|
| 602 | + } |
|
| 603 | + |
|
| 604 | + $validate = $empty && ! $has_shortcodes ? false : $validate; |
|
| 605 | + |
|
| 606 | + return $validate; |
|
| 607 | + } |
|
| 608 | + |
|
| 609 | + |
|
| 610 | + /** |
|
| 611 | + * Magic getter |
|
| 612 | + * Using this to provide back compat with add-ons referencing deprecated properties. |
|
| 613 | + * |
|
| 614 | + * @param string $property Property being requested |
|
| 615 | + * @throws Exception |
|
| 616 | + * @return mixed |
|
| 617 | + */ |
|
| 618 | + public function __get($property) |
|
| 619 | + { |
|
| 620 | + $expected_properties_map = array( |
|
| 621 | + /** |
|
| 622 | + * @deprecated 4.9.0 |
|
| 623 | + */ |
|
| 624 | + '_MSGR' => '_messenger', |
|
| 625 | + /** |
|
| 626 | + * @deprecated 4.9.0 |
|
| 627 | + */ |
|
| 628 | + '_MSGTYP' => '_message_type', |
|
| 629 | + ); |
|
| 630 | + |
|
| 631 | + if (isset($expected_properties_map[ $property ])) { |
|
| 632 | + return $this->{$expected_properties_map[ $property ]}; |
|
| 633 | + } |
|
| 634 | + |
|
| 635 | + throw new Exception( |
|
| 636 | + sprintf( |
|
| 637 | + esc_html__('The property %1$s being requested on %2$s does not exist', 'event_espresso'), |
|
| 638 | + $property, |
|
| 639 | + get_class($this) |
|
| 640 | + ) |
|
| 641 | + ); |
|
| 642 | + } |
|
| 643 | 643 | } |
@@ -158,9 +158,9 @@ discard block |
||
| 158 | 158 | // load messenger |
| 159 | 159 | $messenger = ucwords(str_replace('_', ' ', $this->_m_name)); |
| 160 | 160 | $messenger = str_replace(' ', '_', $messenger); |
| 161 | - $messenger = 'EE_' . $messenger . '_messenger'; |
|
| 161 | + $messenger = 'EE_'.$messenger.'_messenger'; |
|
| 162 | 162 | |
| 163 | - if (! class_exists($messenger)) { |
|
| 163 | + if ( ! class_exists($messenger)) { |
|
| 164 | 164 | throw new EE_Error( |
| 165 | 165 | sprintf( |
| 166 | 166 | esc_html__('There is no messenger class for the given string (%s)', 'event_espresso'), |
@@ -174,9 +174,9 @@ discard block |
||
| 174 | 174 | // load message type |
| 175 | 175 | $message_type = ucwords(str_replace('_', ' ', $this->_mt_name)); |
| 176 | 176 | $message_type = str_replace(' ', '_', $message_type); |
| 177 | - $message_type = 'EE_' . $message_type . '_message_type'; |
|
| 177 | + $message_type = 'EE_'.$message_type.'_message_type'; |
|
| 178 | 178 | |
| 179 | - if (! class_exists($message_type)) { |
|
| 179 | + if ( ! class_exists($message_type)) { |
|
| 180 | 180 | throw new EE_Error( |
| 181 | 181 | sprintf( |
| 182 | 182 | esc_html__('There is no message type class for the given string (%s)', 'event_espresso'), |
@@ -209,7 +209,7 @@ discard block |
||
| 209 | 209 | |
| 210 | 210 | // we only want the valid shortcodes for the given context! |
| 211 | 211 | $context = $this->_context; |
| 212 | - $mt_codes = $mt_codes[ $context ]; |
|
| 212 | + $mt_codes = $mt_codes[$context]; |
|
| 213 | 213 | |
| 214 | 214 | // in this first loop we're just getting all shortcode group indexes from the msgr_validator |
| 215 | 215 | // into a single array (so we can get the appropriate shortcode objects for the groups) |
@@ -220,8 +220,8 @@ discard block |
||
| 220 | 220 | if (empty($config) || ! isset($config['shortcodes'])) { |
| 221 | 221 | continue; |
| 222 | 222 | } //Nothing to see here. |
| 223 | - $groups_per_field[ $field ] = array_intersect($config['shortcodes'], $mt_codes); |
|
| 224 | - $shortcode_groups = array_merge($config['shortcodes'], $shortcode_groups); |
|
| 223 | + $groups_per_field[$field] = array_intersect($config['shortcodes'], $mt_codes); |
|
| 224 | + $shortcode_groups = array_merge($config['shortcodes'], $shortcode_groups); |
|
| 225 | 225 | } |
| 226 | 226 | |
| 227 | 227 | $shortcode_groups = array_unique($shortcode_groups); |
@@ -233,11 +233,11 @@ discard block |
||
| 233 | 233 | foreach ($shortcode_groups as $group) { |
| 234 | 234 | $ref = ucwords(str_replace('_', ' ', $group)); |
| 235 | 235 | $ref = str_replace(' ', '_', $ref); |
| 236 | - $classname = 'EE_' . $ref . '_Shortcodes'; |
|
| 236 | + $classname = 'EE_'.$ref.'_Shortcodes'; |
|
| 237 | 237 | if (class_exists($classname)) { |
| 238 | 238 | $a = new ReflectionClass($classname); |
| 239 | 239 | $obj = $a->newInstance(); |
| 240 | - $codes_from_objs[ $group ] = $obj->get_shortcodes(); |
|
| 240 | + $codes_from_objs[$group] = $obj->get_shortcodes(); |
|
| 241 | 241 | } |
| 242 | 242 | } |
| 243 | 243 | |
@@ -245,7 +245,7 @@ discard block |
||
| 245 | 245 | // let's just replace the $mt shortcode group indexes with the actual shortcodes (unique) |
| 246 | 246 | $final_mt_codes = array(); |
| 247 | 247 | foreach ($mt_codes as $group) { |
| 248 | - $final_mt_codes = array_merge($final_mt_codes, $codes_from_objs[ $group ]); |
|
| 248 | + $final_mt_codes = array_merge($final_mt_codes, $codes_from_objs[$group]); |
|
| 249 | 249 | } |
| 250 | 250 | |
| 251 | 251 | $mt_codes = $final_mt_codes; |
@@ -263,44 +263,44 @@ discard block |
||
| 263 | 263 | } |
| 264 | 264 | |
| 265 | 265 | // If we have an override then we use it to indicate the codes we want. |
| 266 | - if (isset($this->_valid_shortcodes_modifier[ $context ][ $field ])) { |
|
| 267 | - $this->_validators[ $field ]['shortcodes'] = $this->_reassemble_valid_shortcodes_from_group( |
|
| 268 | - $this->_valid_shortcodes_modifier[ $context ][ $field ], |
|
| 266 | + if (isset($this->_valid_shortcodes_modifier[$context][$field])) { |
|
| 267 | + $this->_validators[$field]['shortcodes'] = $this->_reassemble_valid_shortcodes_from_group( |
|
| 268 | + $this->_valid_shortcodes_modifier[$context][$field], |
|
| 269 | 269 | $codes_from_objs |
| 270 | 270 | ); |
| 271 | 271 | } //if we have specific shortcodes for a field then we need to use them |
| 272 | - elseif (isset($groups_per_field[ $field ])) { |
|
| 273 | - $this->_validators[ $field ]['shortcodes'] = $this->_reassemble_valid_shortcodes_from_group( |
|
| 274 | - $groups_per_field[ $field ], |
|
| 272 | + elseif (isset($groups_per_field[$field])) { |
|
| 273 | + $this->_validators[$field]['shortcodes'] = $this->_reassemble_valid_shortcodes_from_group( |
|
| 274 | + $groups_per_field[$field], |
|
| 275 | 275 | $codes_from_objs |
| 276 | 276 | ); |
| 277 | 277 | } //if empty config then we're assuming we're just going to use the shortcodes from the message type context |
| 278 | 278 | elseif (empty($config)) { |
| 279 | - $this->_validators[ $field ]['shortcodes'] = $mt_codes; |
|
| 279 | + $this->_validators[$field]['shortcodes'] = $mt_codes; |
|
| 280 | 280 | } //if we have specific shortcodes then we need to use them |
| 281 | 281 | elseif (isset($config['specific_shortcodes'])) { |
| 282 | - $this->_validators[ $field ]['shortcodes'] = $config['specific_shortcodes']; |
|
| 282 | + $this->_validators[$field]['shortcodes'] = $config['specific_shortcodes']; |
|
| 283 | 283 | } //otherwise the shortcodes are what is set by the messenger for that field |
| 284 | 284 | else { |
| 285 | 285 | foreach ($config['shortcodes'] as $group) { |
| 286 | - $this->_validators[ $field ]['shortcodes'] = isset($this->_validators[ $field ]['shortcodes']) |
|
| 287 | - ? array_merge($this->_validators[ $field ]['shortcodes'], $codes_from_objs[ $group ]) |
|
| 288 | - : $codes_from_objs[ $group ]; |
|
| 286 | + $this->_validators[$field]['shortcodes'] = isset($this->_validators[$field]['shortcodes']) |
|
| 287 | + ? array_merge($this->_validators[$field]['shortcodes'], $codes_from_objs[$group]) |
|
| 288 | + : $codes_from_objs[$group]; |
|
| 289 | 289 | } |
| 290 | 290 | } |
| 291 | 291 | |
| 292 | 292 | // now let's just make sure that any excluded specific shortcodes are removed. |
| 293 | 293 | $specific_excludes = $this->get_specific_shortcode_excludes(); |
| 294 | - if (isset($specific_excludes[ $field ])) { |
|
| 295 | - foreach ($specific_excludes[ $field ] as $sex) { |
|
| 296 | - if (isset($this->_validators[ $field ]['shortcodes'][ $sex ])) { |
|
| 297 | - unset($this->_validators[ $field ]['shortcodes'][ $sex ]); |
|
| 294 | + if (isset($specific_excludes[$field])) { |
|
| 295 | + foreach ($specific_excludes[$field] as $sex) { |
|
| 296 | + if (isset($this->_validators[$field]['shortcodes'][$sex])) { |
|
| 297 | + unset($this->_validators[$field]['shortcodes'][$sex]); |
|
| 298 | 298 | } |
| 299 | 299 | } |
| 300 | 300 | } |
| 301 | 301 | |
| 302 | 302 | // hey! don't forget to include the type if present! |
| 303 | - $this->_validators[ $field ]['type'] = isset($config['type']) ? $config['type'] : null; |
|
| 303 | + $this->_validators[$field]['type'] = isset($config['type']) ? $config['type'] : null; |
|
| 304 | 304 | } |
| 305 | 305 | } |
| 306 | 306 | |
@@ -327,7 +327,7 @@ discard block |
||
| 327 | 327 | { |
| 328 | 328 | // specific validator filter |
| 329 | 329 | $shortcode_excludes = apply_filters( |
| 330 | - 'FHEE__' . get_class($this) . '__get_specific_shortcode_excludes;', |
|
| 330 | + 'FHEE__'.get_class($this).'__get_specific_shortcode_excludes;', |
|
| 331 | 331 | $this->_specific_shortcode_excludes, |
| 332 | 332 | $this->_context |
| 333 | 333 | ); |
@@ -355,23 +355,23 @@ discard block |
||
| 355 | 355 | $template_fields = $this->_messenger->get_template_fields(); |
| 356 | 356 | // loop through the fields and check! |
| 357 | 357 | foreach ($this->_fields as $field => $value) { |
| 358 | - $this->_errors[ $field ] = array(); |
|
| 358 | + $this->_errors[$field] = array(); |
|
| 359 | 359 | $err_msg = ''; |
| 360 | 360 | $field_label = ''; |
| 361 | 361 | // if field is not present in the _validators array then we continue |
| 362 | - if (! isset($this->_validators[ $field ])) { |
|
| 363 | - unset($this->_errors[ $field ]); |
|
| 362 | + if ( ! isset($this->_validators[$field])) { |
|
| 363 | + unset($this->_errors[$field]); |
|
| 364 | 364 | continue; |
| 365 | 365 | } |
| 366 | 366 | |
| 367 | 367 | // get the translated field label! |
| 368 | 368 | // first check if it's in the main fields list |
| 369 | - if (isset($template_fields[ $field ])) { |
|
| 370 | - if (empty($template_fields[ $field ])) { |
|
| 369 | + if (isset($template_fields[$field])) { |
|
| 370 | + if (empty($template_fields[$field])) { |
|
| 371 | 371 | $field_label = $field; |
| 372 | 372 | } //most likely the field is found in the 'extra' array. |
| 373 | 373 | else { |
| 374 | - $field_label = $template_fields[ $field ]['label']; |
|
| 374 | + $field_label = $template_fields[$field]['label']; |
|
| 375 | 375 | } |
| 376 | 376 | } |
| 377 | 377 | |
@@ -394,20 +394,20 @@ discard block |
||
| 394 | 394 | } |
| 395 | 395 | |
| 396 | 396 | // field is present. Let's validate shortcodes first (but only if shortcodes present). |
| 397 | - if (isset($this->_validators[ $field ]['shortcodes']) |
|
| 398 | - && ! empty($this->_validators[ $field ]['shortcodes']) |
|
| 397 | + if (isset($this->_validators[$field]['shortcodes']) |
|
| 398 | + && ! empty($this->_validators[$field]['shortcodes']) |
|
| 399 | 399 | ) { |
| 400 | - $invalid_shortcodes = $this->_invalid_shortcodes($value, $this->_validators[ $field ]['shortcodes']); |
|
| 400 | + $invalid_shortcodes = $this->_invalid_shortcodes($value, $this->_validators[$field]['shortcodes']); |
|
| 401 | 401 | // if true then that means there is a returned error message |
| 402 | 402 | // that we'll need to add to the _errors array for this field. |
| 403 | 403 | if ($invalid_shortcodes) { |
| 404 | - $v_s = array_keys($this->_validators[ $field ]['shortcodes']); |
|
| 404 | + $v_s = array_keys($this->_validators[$field]['shortcodes']); |
|
| 405 | 405 | $err_msg = sprintf( |
| 406 | 406 | esc_html__( |
| 407 | 407 | '%3$sThe following shortcodes were found in the "%1$s" field that ARE not valid: %2$s%4$s', |
| 408 | 408 | 'event_espresso' |
| 409 | 409 | ), |
| 410 | - '<strong>' . $field_label . '</strong>', |
|
| 410 | + '<strong>'.$field_label.'</strong>', |
|
| 411 | 411 | $invalid_shortcodes, |
| 412 | 412 | '<p>', |
| 413 | 413 | '</p >' |
@@ -422,10 +422,10 @@ discard block |
||
| 422 | 422 | } |
| 423 | 423 | |
| 424 | 424 | // if there's a "type" to be validated then let's do that too. |
| 425 | - if (isset($this->_validators[ $field ]['type']) && ! empty($this->_validators[ $field ]['type'])) { |
|
| 426 | - switch ($this->_validators[ $field ]['type']) { |
|
| 425 | + if (isset($this->_validators[$field]['type']) && ! empty($this->_validators[$field]['type'])) { |
|
| 426 | + switch ($this->_validators[$field]['type']) { |
|
| 427 | 427 | case 'number': |
| 428 | - if (! is_numeric($value)) { |
|
| 428 | + if ( ! is_numeric($value)) { |
|
| 429 | 429 | $err_msg .= sprintf( |
| 430 | 430 | esc_html__( |
| 431 | 431 | '%3$sThe %1$s field is supposed to be a number. The value given (%2$s) is not. Please double-check and make sure the field contains a number%4$s', |
@@ -440,7 +440,7 @@ discard block |
||
| 440 | 440 | break; |
| 441 | 441 | case 'email': |
| 442 | 442 | $valid_email = $this->_validate_email($value); |
| 443 | - if (! $valid_email) { |
|
| 443 | + if ( ! $valid_email) { |
|
| 444 | 444 | $err_msg .= htmlentities( |
| 445 | 445 | sprintf( |
| 446 | 446 | esc_html__( |
@@ -458,18 +458,18 @@ discard block |
||
| 458 | 458 | } |
| 459 | 459 | |
| 460 | 460 | // if $err_msg isn't empty let's setup the _errors array for this field. |
| 461 | - if (! empty($err_msg)) { |
|
| 462 | - $this->_errors[ $field ]['msg'] = $err_msg; |
|
| 461 | + if ( ! empty($err_msg)) { |
|
| 462 | + $this->_errors[$field]['msg'] = $err_msg; |
|
| 463 | 463 | } else { |
| 464 | - unset($this->_errors[ $field ]); |
|
| 464 | + unset($this->_errors[$field]); |
|
| 465 | 465 | } |
| 466 | 466 | } |
| 467 | 467 | |
| 468 | 468 | // if we have ANY errors, then we want to make sure we return the values |
| 469 | 469 | // for ALL the fields so the user doesn't have to retype them all. |
| 470 | - if (! empty($this->_errors)) { |
|
| 470 | + if ( ! empty($this->_errors)) { |
|
| 471 | 471 | foreach ($this->_fields as $field => $value) { |
| 472 | - $this->_errors[ $field ]['value'] = stripslashes($value); |
|
| 472 | + $this->_errors[$field]['value'] = stripslashes($value); |
|
| 473 | 473 | } |
| 474 | 474 | } |
| 475 | 475 | |
@@ -490,7 +490,7 @@ discard block |
||
| 490 | 490 | { |
| 491 | 491 | $shortcodes = array(); |
| 492 | 492 | foreach ($groups as $group) { |
| 493 | - $shortcodes = array_merge($shortcodes, $codes_from_objs[ $group ]); |
|
| 493 | + $shortcodes = array_merge($shortcodes, $codes_from_objs[$group]); |
|
| 494 | 494 | } |
| 495 | 495 | return $shortcodes; |
| 496 | 496 | } |
@@ -520,8 +520,8 @@ discard block |
||
| 520 | 520 | // strip the shortcode so we just have the BASE string (i.e. [ANSWER_*] ) |
| 521 | 521 | $dynamic_sc = preg_replace('/(_\*+.+)/', '_*]', $code); |
| 522 | 522 | // does this exist in the $valid_shortcodes? If so then unset. |
| 523 | - if (isset($valid_shortcodes[ $dynamic_sc ])) { |
|
| 524 | - unset($diff[ $ind ]); |
|
| 523 | + if (isset($valid_shortcodes[$dynamic_sc])) { |
|
| 524 | + unset($diff[$ind]); |
|
| 525 | 525 | } |
| 526 | 526 | } |
| 527 | 527 | } |
@@ -532,7 +532,7 @@ discard block |
||
| 532 | 532 | |
| 533 | 533 | // made it here? then let's assemble the error message |
| 534 | 534 | $invalid_shortcodes = implode('</strong>,<strong>', $diff); |
| 535 | - $invalid_shortcodes = '<strong>' . $invalid_shortcodes . '</strong>'; |
|
| 535 | + $invalid_shortcodes = '<strong>'.$invalid_shortcodes.'</strong>'; |
|
| 536 | 536 | return $invalid_shortcodes; |
| 537 | 537 | } |
| 538 | 538 | |
@@ -569,7 +569,7 @@ discard block |
||
| 569 | 569 | // its possible that this message is being "turned off" for a particular context |
| 570 | 570 | |
| 571 | 571 | |
| 572 | - if (! empty($or_val) && empty($value)) { |
|
| 572 | + if ( ! empty($or_val) && empty($value)) { |
|
| 573 | 573 | return $validate; |
| 574 | 574 | } |
| 575 | 575 | |
@@ -628,8 +628,8 @@ discard block |
||
| 628 | 628 | '_MSGTYP' => '_message_type', |
| 629 | 629 | ); |
| 630 | 630 | |
| 631 | - if (isset($expected_properties_map[ $property ])) { |
|
| 632 | - return $this->{$expected_properties_map[ $property ]}; |
|
| 631 | + if (isset($expected_properties_map[$property])) { |
|
| 632 | + return $this->{$expected_properties_map[$property]}; |
|
| 633 | 633 | } |
| 634 | 634 | |
| 635 | 635 | throw new Exception( |