Completed
Branch fix/events-archive-config-rese... (0ef832)
by
unknown
12:05 queued 09:36
created
caffeinated/payment_methods/Aim/EEG_Aim.gateway.php 2 patches
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -191,7 +191,7 @@  discard block
 block discarded – undo
191 191
                     $line_item->unit_price(),
192 192
                     'N'
193 193
                 );
194
-                $order_description .= $this->prepareStringForAuthnet($line_item->desc()) . ', ';
194
+                $order_description .= $this->prepareStringForAuthnet($line_item->desc()).', ';
195 195
             }
196 196
             foreach ($total_line_item->tax_descendants() as $tax_line_item) {
197 197
                 $this->addLineItem(
@@ -216,7 +216,7 @@  discard block
 block discarded – undo
216 216
         $this->setField('last_name', $billing_info['last_name']);
217 217
         $this->setField('email', $billing_info['email']);
218 218
         $this->setField('company', $billing_info['company']);
219
-        $this->setField('address', $billing_info['address'] . ' ' . $billing_info['address2']);
219
+        $this->setField('address', $billing_info['address'].' '.$billing_info['address2']);
220 220
         $this->setField('city', $billing_info['city']);
221 221
         $this->setField('state', $billing_info['state']);
222 222
         $this->setField('country', $billing_info['country']);
@@ -229,7 +229,7 @@  discard block
 block discarded – undo
229 229
         // invoice_num would be nice to have it be unique per SPCO page-load, that way if users
230 230
         // press back, they don't submit a duplicate. However, we may be keeping the user on teh same spco page
231 231
         // in which case, we need to generate teh invoice num per request right here...
232
-        $this->setField('invoice_num', wp_generate_password(12, false));// $billing_info['_reg-page-billing-invoice-'.$this->_gateway_name]['value']);
232
+        $this->setField('invoice_num', wp_generate_password(12, false)); // $billing_info['_reg-page-billing-invoice-'.$this->_gateway_name]['value']);
233 233
         // tell AIM that any duplicates sent in the next 5 minutes are to be ignored
234 234
         $this->setField('duplicate_window', 5 * MINUTE_IN_SECONDS);
235 235
 
@@ -240,7 +240,7 @@  discard block
 block discarded – undo
240 240
         // Capture response
241 241
         $this->type = "AUTH_CAPTURE";
242 242
         $response = $this->_sendRequest($payment);
243
-        if (! empty($response)) {
243
+        if ( ! empty($response)) {
244 244
             if ($response->error_message) {
245 245
                 $payment->set_status($this->_pay_model->failed_status());
246 246
                 $payment->set_gateway_response($response->error_message);
@@ -286,7 +286,7 @@  discard block
 block discarded – undo
286 286
     protected function _set_sensitive_billing_data($billing_info)
287 287
     {
288 288
         $this->setField('card_num', $billing_info['credit_card']);
289
-        $this->setField('exp_date', $billing_info['exp_month'] . $billing_info['exp_year']);
289
+        $this->setField('exp_date', $billing_info['exp_month'].$billing_info['exp_year']);
290 290
         $this->setField('card_code', $billing_info['cvv']);
291 291
     }
292 292
 
@@ -326,7 +326,7 @@  discard block
 block discarded – undo
326 326
     protected function setField($name, $value)
327 327
     {
328 328
         if (in_array($name, $this->_all_aim_fields)) {
329
-            $this->_x_post_fields[ $name ] = $value;
329
+            $this->_x_post_fields[$name] = $value;
330 330
         } else {
331 331
             throw new AuthorizeNetException("Error: no field $name exists in the AIM API.
332 332
             To set a custom field use setCustomField('field','value') instead.");
@@ -346,11 +346,11 @@  discard block
 block discarded – undo
346 346
         $this->_x_post_fields['tran_key'] = $this->_transaction_key;
347 347
         $x_keys = array();
348 348
         foreach ($this->_x_post_fields as $key => $value) {
349
-            $x_keys[] = "x_$key=" . urlencode($this->_get_unsupported_character_remover()->format($value));
349
+            $x_keys[] = "x_$key=".urlencode($this->_get_unsupported_character_remover()->format($value));
350 350
         }
351 351
         // Add line items
352 352
         foreach ($this->_additional_line_items as $key => $value) {
353
-            $x_keys[] =  "x_line_item=" . urlencode($this->_get_unsupported_character_remover()->format($value));
353
+            $x_keys[] = "x_line_item=".urlencode($this->_get_unsupported_character_remover()->format($value));
354 354
         }
355 355
         $this->_log_clean_request($x_keys, $payment);
356 356
         $post_url = $this->_get_server_url();
@@ -362,7 +362,7 @@  discard block
 block discarded – undo
362 362
         curl_setopt($curl_request, CURLOPT_RETURNTRANSFER, 1);
363 363
         curl_setopt($curl_request, CURLOPT_SSL_VERIFYHOST, 2);
364 364
         if ($this->VERIFY_PEER) {
365
-            curl_setopt($curl_request, CURLOPT_CAINFO, dirname(__DIR__) . '/ssl/cert.pem');
365
+            curl_setopt($curl_request, CURLOPT_CAINFO, dirname(__DIR__).'/ssl/cert.pem');
366 366
         } else {
367 367
             curl_setopt($curl_request, CURLOPT_SSL_VERIFYPEER, false);
368 368
         }
@@ -374,7 +374,7 @@  discard block
 block discarded – undo
374 374
         $response = curl_exec($curl_request);
375 375
 
376 376
         curl_close($curl_request);
377
-        $response_obj =  new EE_AuthorizeNetAIM_Response($response);
377
+        $response_obj = new EE_AuthorizeNetAIM_Response($response);
378 378
 
379 379
         return $this->_log_and_clean_response($response_obj, $payment);
380 380
     }
@@ -394,7 +394,7 @@  discard block
 block discarded – undo
394 394
                 if (strpos($keyvaltogether, $key) === 0) {
395 395
                     // found it at the first character
396 396
                     // so its one of them
397
-                    unset($request_array[ $index ]);
397
+                    unset($request_array[$index]);
398 398
                 }
399 399
             }
400 400
         }
@@ -535,7 +535,7 @@  discard block
 block discarded – undo
535 535
             // Split Array
536 536
             $this->response = $response;
537 537
             if ($encap_char) {
538
-                $this->_response_array = explode($encap_char . $delimiter . $encap_char, substr($response, 1, -1));
538
+                $this->_response_array = explode($encap_char.$delimiter.$encap_char, substr($response, 1, -1));
539 539
             } else {
540 540
                 $this->_response_array = explode($delimiter, $response);
541 541
             }
@@ -617,7 +617,7 @@  discard block
 block discarded – undo
617 617
     }
618 618
 }
619 619
 
620
-if (! class_exists('AuthorizeNetException')) {
620
+if ( ! class_exists('AuthorizeNetException')) {
621 621
     /**
622 622
      * Class AuthorizeNetException
623 623
      *
Please login to merge, or discard this patch.
Indentation   +595 added lines, -595 removed lines patch added patch discarded remove patch
@@ -26,417 +26,417 @@  discard block
 block discarded – undo
26 26
 class EEG_Aim extends EE_Onsite_Gateway
27 27
 {
28 28
 
29
-    const LIVE_URL    = 'https://secure2.authorize.net/gateway/transact.dll'; // Authnet URL
30
-
31
-    const SANDBOX_URL = 'https://test.authorize.net/gateway/transact.dll';
32
-
33
-    protected $_login_id;
34
-
35
-    protected $_transaction_key;
36
-
37
-    protected $_currencies_supported = array(
38
-        'AUD',
39
-        'USD',
40
-        'CAD',
41
-        'EUR',
42
-        'GBP',
43
-        'NZD',
44
-    );
45
-
46
-    /**
47
-     * Whether to send test transactions (even to live site)
48
-     *
49
-     * @var boolean
50
-     */
51
-    protected $_test_transactions;
52
-
53
-    private $VERIFY_PEER = false;
54
-
55
-    private $_x_post_fields = array(
56
-        "version"        => "3.1",
57
-        "delim_char"     => ",",
58
-        "delim_data"     => "TRUE",
59
-        "relay_response" => "FALSE",
60
-        "encap_char"     => "|",
61
-    );
62
-
63
-    private $_additional_line_items = array();
64
-
65
-    /**
66
-     * A list of all fields in the AIM API.
67
-     * Used to warn user if they try to set a field not offered in the API.
68
-     */
69
-    private $_all_aim_fields = array(
70
-        "address",
71
-        "allow_partial_auth",
72
-        "amount",
73
-        "auth_code",
74
-        "authentication_indicator",
75
-        "bank_aba_code",
76
-        "bank_acct_name",
77
-        "bank_acct_num",
78
-        "bank_acct_type",
79
-        "bank_check_number",
80
-        "bank_name",
81
-        "card_code",
82
-        "card_num",
83
-        "cardholder_authentication_value",
84
-        "city",
85
-        "company",
86
-        "country",
87
-        "cust_id",
88
-        "customer_ip",
89
-        "delim_char",
90
-        "delim_data",
91
-        "description",
92
-        "duplicate_window",
93
-        "duty",
94
-        "echeck_type",
95
-        "email",
96
-        "email_customer",
97
-        "encap_char",
98
-        "exp_date",
99
-        "fax",
100
-        "first_name",
101
-        "footer_email_receipt",
102
-        "freight",
103
-        "header_email_receipt",
104
-        "invoice_num",
105
-        "last_name",
106
-        "line_item",
107
-        "login",
108
-        "method",
109
-        "phone",
110
-        "po_num",
111
-        "recurring_billing",
112
-        "relay_response",
113
-        "ship_to_address",
114
-        "ship_to_city",
115
-        "ship_to_company",
116
-        "ship_to_country",
117
-        "ship_to_first_name",
118
-        "ship_to_last_name",
119
-        "ship_to_state",
120
-        "ship_to_zip",
121
-        "split_tender_id",
122
-        "state",
123
-        "tax",
124
-        "tax_exempt",
125
-        "test_request",
126
-        "tran_key",
127
-        "trans_id",
128
-        "type",
129
-        "version",
130
-        "zip",
131
-        "solution_id",
132
-        "currency_code"
133
-    );
134
-
135
-
136
-    /**
137
-     * Gets the URL where the request should go. This is filterable
138
-     *
139
-     * @return string
140
-     */
141
-    protected function _get_server_url()
142
-    {
143
-        return apply_filters(
144
-            'FHEE__EEG_Aim___get_server_url',
145
-            $this->_debug_mode ? self::SANDBOX_URL : self::LIVE_URL,
146
-            $this
147
-        );
148
-    }
149
-
150
-
151
-    /**
152
-     * Asks the gateway to do whatever it does to process the payment. Onsite gateways will
153
-     * usually send a request directly to the payment provider and update the payment's status based on that;
154
-     * whereas offsite gateways will usually just update the payment with the URL and query parameters to use
155
-     * for sending the request via http_remote_request()
156
-     *
157
-     * @param EEI_Payment $payment
158
-     * @param array $billing_info {
159
-     *  @type $credit_card string
160
-     *  @type $cvv string
161
-     *  @type $exp_month string
162
-     *  @type $exp_year string
163
-     *  @see parent::do_direct_payment
164
-     * }
165
-     * @return EEI_Payment updated
166
-     */
167
-    public function do_direct_payment($payment, $billing_info = null)
168
-    {
169
-        // Enable test mode if needed
170
-        // 4007000000027  <-- test successful visa
171
-        // 4222222222222  <-- test failure card number
172
-
173
-        $item_num = 1;
174
-        $transaction = $payment->transaction();
175
-        $gateway_formatter = $this->_get_gateway_formatter();
176
-        $order_description = $this->prepareStringForAuthnet($gateway_formatter->formatOrderDescription($payment));
177
-        $primary_registrant = $transaction->primary_registration();
178
-        // if we're are charging for the full amount, show the normal line items
179
-        // and the itemized total adds up properly
180
-        if ($this->_can_easily_itemize_transaction_for($payment)) {
181
-            $total_line_item = $transaction->total_line_item();
182
-            foreach ($total_line_item->get_items() as $line_item) {
183
-                if ($line_item->quantity() == 0) {
184
-                    continue;
185
-                }
186
-                $this->addLineItem(
187
-                    $item_num++,
188
-                    $gateway_formatter->formatLineItemName($line_item, $payment),
189
-                    $gateway_formatter->formatLineItemDesc($line_item, $payment),
190
-                    $line_item->quantity(),
191
-                    $line_item->unit_price(),
192
-                    'N'
193
-                );
194
-                $order_description .= $this->prepareStringForAuthnet($line_item->desc()) . ', ';
195
-            }
196
-            foreach ($total_line_item->tax_descendants() as $tax_line_item) {
197
-                $this->addLineItem(
198
-                    $item_num++,
199
-                    $tax_line_item->name(),
200
-                    $tax_line_item->desc(),
201
-                    1,
202
-                    $tax_line_item->total(),
203
-                    'N'
204
-                );
205
-            }
206
-        }
207
-
208
-        // start transaction
209
-        // if in debug mode, use authorize.net's sandbox id; otherwise use the Event Espresso partner id
210
-        $partner_id = $this->_debug_mode ? 'AAA100302' : 'AAA105363';
211
-        $this->setField('solution_id', $partner_id);
212
-        $this->setField('amount', $gateway_formatter->formatCurrency($payment->amount()));
213
-        $this->setField('description', substr(rtrim($order_description, ', '), 0, 255));
214
-        $this->_set_sensitive_billing_data($billing_info);
215
-        $this->setField('first_name', $billing_info['first_name']);
216
-        $this->setField('last_name', $billing_info['last_name']);
217
-        $this->setField('email', $billing_info['email']);
218
-        $this->setField('company', $billing_info['company']);
219
-        $this->setField('address', $billing_info['address'] . ' ' . $billing_info['address2']);
220
-        $this->setField('city', $billing_info['city']);
221
-        $this->setField('state', $billing_info['state']);
222
-        $this->setField('country', $billing_info['country']);
223
-        $this->setField('zip', $billing_info['zip']);
224
-        $this->setField('fax', $billing_info['fax']);
225
-        $this->setField('cust_id', $primary_registrant->ID());
226
-        $this->setField('phone', $billing_info['phone']);
227
-        $currency_config = LoaderFactory::getLoader()->load('EE_Currency_Config');
228
-        $this->setField('currency_code', $currency_config->code);
229
-        // invoice_num would be nice to have it be unique per SPCO page-load, that way if users
230
-        // press back, they don't submit a duplicate. However, we may be keeping the user on teh same spco page
231
-        // in which case, we need to generate teh invoice num per request right here...
232
-        $this->setField('invoice_num', wp_generate_password(12, false));// $billing_info['_reg-page-billing-invoice-'.$this->_gateway_name]['value']);
233
-        // tell AIM that any duplicates sent in the next 5 minutes are to be ignored
234
-        $this->setField('duplicate_window', 5 * MINUTE_IN_SECONDS);
235
-
236
-        if ($this->_test_transactions) {
237
-            $this->test_request = "true";
238
-        }
239
-
240
-        // Capture response
241
-        $this->type = "AUTH_CAPTURE";
242
-        $response = $this->_sendRequest($payment);
243
-        if (! empty($response)) {
244
-            if ($response->error_message) {
245
-                $payment->set_status($this->_pay_model->failed_status());
246
-                $payment->set_gateway_response($response->error_message);
247
-            } else {
248
-                $payment_status = $response->approved
249
-                    ? $this->_pay_model->approved_status()
250
-                    : $this->_pay_model->declined_status();
251
-                $payment->set_status($payment_status);
252
-                // make sure we interpret the AMT as a float, not an international string (where periods are thousand separators)
253
-                $payment->set_amount((float) $response->amount);
254
-                $payment->set_gateway_response(
255
-                    sprintf(
256
-                        esc_html__('%1$s (Reason Code: %2$s)', 'event_espresso'),
257
-                        $response->response_reason_text,
258
-                        $response->response_reason_code
259
-                    )
260
-                );
261
-                if ($this->_debug_mode) {
262
-                    $txn_id = $response->invoice_number;
263
-                } else {
264
-                    $txn_id = $response->transaction_id;
265
-                }
266
-                $payment->set_txn_id_chq_nmbr($txn_id);
267
-            }
268
-            $payment->set_extra_accntng($primary_registrant->reg_code());
269
-            $payment->set_details(print_r($response, true));
270
-        } else {
271
-            $payment->set_status($this->_pay_model->failed_status());
272
-            $payment->set_gateway_response(esc_html__("There was no response from Authorize.net", 'event_espresso'));
273
-            $payment->set_details(print_r($response, true));
274
-        }
275
-        return $payment;
276
-    }
277
-
278
-
279
-    /**
280
-     * Sets billing data for the upcoming request to AIM that is considered sensitive;
281
-     * also this method can be overridden by children classes to easily change
282
-     * what billing data gets sent
283
-     *
284
-     * @param array $billing_info
285
-     */
286
-    protected function _set_sensitive_billing_data($billing_info)
287
-    {
288
-        $this->setField('card_num', $billing_info['credit_card']);
289
-        $this->setField('exp_date', $billing_info['exp_month'] . $billing_info['exp_year']);
290
-        $this->setField('card_code', $billing_info['cvv']);
291
-    }
292
-
293
-
294
-    /**
295
-     * Add a line item.
296
-     *
297
-     * @param string $item_id
298
-     * @param string $item_name
299
-     * @param string $item_description
300
-     * @param string $item_quantity
301
-     * @param string $item_unit_price
302
-     * @param string $item_taxable
303
-     */
304
-    public function addLineItem($item_id, $item_name, $item_description, $item_quantity, $item_unit_price, $item_taxable)
305
-    {
306
-        $args = array(
307
-            substr($item_id, 0, 31),
308
-            substr($this->prepareStringForAuthnet($item_name), 0, 31),
309
-            substr($this->prepareStringForAuthnet($item_description), 0, 255),
310
-            number_format(abs($item_quantity), 2, '.', ''),
311
-            number_format(abs($item_unit_price), 2, '.', ''),
312
-            $item_taxable === 'N' ? 'N' : 'Y'
313
-        );
314
-        $this->_additional_line_items[] = implode('<|>', $args);
315
-    }
316
-
317
-
318
-    /**
319
-     * Set an individual name/value pair. This will append x_ to the name
320
-     * before posting.
321
-     *
322
-     * @param string $name
323
-     * @param string $value
324
-     * @throws AuthorizeNetException
325
-     */
326
-    protected function setField($name, $value)
327
-    {
328
-        if (in_array($name, $this->_all_aim_fields)) {
329
-            $this->_x_post_fields[ $name ] = $value;
330
-        } else {
331
-            throw new AuthorizeNetException("Error: no field $name exists in the AIM API.
29
+	const LIVE_URL    = 'https://secure2.authorize.net/gateway/transact.dll'; // Authnet URL
30
+
31
+	const SANDBOX_URL = 'https://test.authorize.net/gateway/transact.dll';
32
+
33
+	protected $_login_id;
34
+
35
+	protected $_transaction_key;
36
+
37
+	protected $_currencies_supported = array(
38
+		'AUD',
39
+		'USD',
40
+		'CAD',
41
+		'EUR',
42
+		'GBP',
43
+		'NZD',
44
+	);
45
+
46
+	/**
47
+	 * Whether to send test transactions (even to live site)
48
+	 *
49
+	 * @var boolean
50
+	 */
51
+	protected $_test_transactions;
52
+
53
+	private $VERIFY_PEER = false;
54
+
55
+	private $_x_post_fields = array(
56
+		"version"        => "3.1",
57
+		"delim_char"     => ",",
58
+		"delim_data"     => "TRUE",
59
+		"relay_response" => "FALSE",
60
+		"encap_char"     => "|",
61
+	);
62
+
63
+	private $_additional_line_items = array();
64
+
65
+	/**
66
+	 * A list of all fields in the AIM API.
67
+	 * Used to warn user if they try to set a field not offered in the API.
68
+	 */
69
+	private $_all_aim_fields = array(
70
+		"address",
71
+		"allow_partial_auth",
72
+		"amount",
73
+		"auth_code",
74
+		"authentication_indicator",
75
+		"bank_aba_code",
76
+		"bank_acct_name",
77
+		"bank_acct_num",
78
+		"bank_acct_type",
79
+		"bank_check_number",
80
+		"bank_name",
81
+		"card_code",
82
+		"card_num",
83
+		"cardholder_authentication_value",
84
+		"city",
85
+		"company",
86
+		"country",
87
+		"cust_id",
88
+		"customer_ip",
89
+		"delim_char",
90
+		"delim_data",
91
+		"description",
92
+		"duplicate_window",
93
+		"duty",
94
+		"echeck_type",
95
+		"email",
96
+		"email_customer",
97
+		"encap_char",
98
+		"exp_date",
99
+		"fax",
100
+		"first_name",
101
+		"footer_email_receipt",
102
+		"freight",
103
+		"header_email_receipt",
104
+		"invoice_num",
105
+		"last_name",
106
+		"line_item",
107
+		"login",
108
+		"method",
109
+		"phone",
110
+		"po_num",
111
+		"recurring_billing",
112
+		"relay_response",
113
+		"ship_to_address",
114
+		"ship_to_city",
115
+		"ship_to_company",
116
+		"ship_to_country",
117
+		"ship_to_first_name",
118
+		"ship_to_last_name",
119
+		"ship_to_state",
120
+		"ship_to_zip",
121
+		"split_tender_id",
122
+		"state",
123
+		"tax",
124
+		"tax_exempt",
125
+		"test_request",
126
+		"tran_key",
127
+		"trans_id",
128
+		"type",
129
+		"version",
130
+		"zip",
131
+		"solution_id",
132
+		"currency_code"
133
+	);
134
+
135
+
136
+	/**
137
+	 * Gets the URL where the request should go. This is filterable
138
+	 *
139
+	 * @return string
140
+	 */
141
+	protected function _get_server_url()
142
+	{
143
+		return apply_filters(
144
+			'FHEE__EEG_Aim___get_server_url',
145
+			$this->_debug_mode ? self::SANDBOX_URL : self::LIVE_URL,
146
+			$this
147
+		);
148
+	}
149
+
150
+
151
+	/**
152
+	 * Asks the gateway to do whatever it does to process the payment. Onsite gateways will
153
+	 * usually send a request directly to the payment provider and update the payment's status based on that;
154
+	 * whereas offsite gateways will usually just update the payment with the URL and query parameters to use
155
+	 * for sending the request via http_remote_request()
156
+	 *
157
+	 * @param EEI_Payment $payment
158
+	 * @param array $billing_info {
159
+	 *  @type $credit_card string
160
+	 *  @type $cvv string
161
+	 *  @type $exp_month string
162
+	 *  @type $exp_year string
163
+	 *  @see parent::do_direct_payment
164
+	 * }
165
+	 * @return EEI_Payment updated
166
+	 */
167
+	public function do_direct_payment($payment, $billing_info = null)
168
+	{
169
+		// Enable test mode if needed
170
+		// 4007000000027  <-- test successful visa
171
+		// 4222222222222  <-- test failure card number
172
+
173
+		$item_num = 1;
174
+		$transaction = $payment->transaction();
175
+		$gateway_formatter = $this->_get_gateway_formatter();
176
+		$order_description = $this->prepareStringForAuthnet($gateway_formatter->formatOrderDescription($payment));
177
+		$primary_registrant = $transaction->primary_registration();
178
+		// if we're are charging for the full amount, show the normal line items
179
+		// and the itemized total adds up properly
180
+		if ($this->_can_easily_itemize_transaction_for($payment)) {
181
+			$total_line_item = $transaction->total_line_item();
182
+			foreach ($total_line_item->get_items() as $line_item) {
183
+				if ($line_item->quantity() == 0) {
184
+					continue;
185
+				}
186
+				$this->addLineItem(
187
+					$item_num++,
188
+					$gateway_formatter->formatLineItemName($line_item, $payment),
189
+					$gateway_formatter->formatLineItemDesc($line_item, $payment),
190
+					$line_item->quantity(),
191
+					$line_item->unit_price(),
192
+					'N'
193
+				);
194
+				$order_description .= $this->prepareStringForAuthnet($line_item->desc()) . ', ';
195
+			}
196
+			foreach ($total_line_item->tax_descendants() as $tax_line_item) {
197
+				$this->addLineItem(
198
+					$item_num++,
199
+					$tax_line_item->name(),
200
+					$tax_line_item->desc(),
201
+					1,
202
+					$tax_line_item->total(),
203
+					'N'
204
+				);
205
+			}
206
+		}
207
+
208
+		// start transaction
209
+		// if in debug mode, use authorize.net's sandbox id; otherwise use the Event Espresso partner id
210
+		$partner_id = $this->_debug_mode ? 'AAA100302' : 'AAA105363';
211
+		$this->setField('solution_id', $partner_id);
212
+		$this->setField('amount', $gateway_formatter->formatCurrency($payment->amount()));
213
+		$this->setField('description', substr(rtrim($order_description, ', '), 0, 255));
214
+		$this->_set_sensitive_billing_data($billing_info);
215
+		$this->setField('first_name', $billing_info['first_name']);
216
+		$this->setField('last_name', $billing_info['last_name']);
217
+		$this->setField('email', $billing_info['email']);
218
+		$this->setField('company', $billing_info['company']);
219
+		$this->setField('address', $billing_info['address'] . ' ' . $billing_info['address2']);
220
+		$this->setField('city', $billing_info['city']);
221
+		$this->setField('state', $billing_info['state']);
222
+		$this->setField('country', $billing_info['country']);
223
+		$this->setField('zip', $billing_info['zip']);
224
+		$this->setField('fax', $billing_info['fax']);
225
+		$this->setField('cust_id', $primary_registrant->ID());
226
+		$this->setField('phone', $billing_info['phone']);
227
+		$currency_config = LoaderFactory::getLoader()->load('EE_Currency_Config');
228
+		$this->setField('currency_code', $currency_config->code);
229
+		// invoice_num would be nice to have it be unique per SPCO page-load, that way if users
230
+		// press back, they don't submit a duplicate. However, we may be keeping the user on teh same spco page
231
+		// in which case, we need to generate teh invoice num per request right here...
232
+		$this->setField('invoice_num', wp_generate_password(12, false));// $billing_info['_reg-page-billing-invoice-'.$this->_gateway_name]['value']);
233
+		// tell AIM that any duplicates sent in the next 5 minutes are to be ignored
234
+		$this->setField('duplicate_window', 5 * MINUTE_IN_SECONDS);
235
+
236
+		if ($this->_test_transactions) {
237
+			$this->test_request = "true";
238
+		}
239
+
240
+		// Capture response
241
+		$this->type = "AUTH_CAPTURE";
242
+		$response = $this->_sendRequest($payment);
243
+		if (! empty($response)) {
244
+			if ($response->error_message) {
245
+				$payment->set_status($this->_pay_model->failed_status());
246
+				$payment->set_gateway_response($response->error_message);
247
+			} else {
248
+				$payment_status = $response->approved
249
+					? $this->_pay_model->approved_status()
250
+					: $this->_pay_model->declined_status();
251
+				$payment->set_status($payment_status);
252
+				// make sure we interpret the AMT as a float, not an international string (where periods are thousand separators)
253
+				$payment->set_amount((float) $response->amount);
254
+				$payment->set_gateway_response(
255
+					sprintf(
256
+						esc_html__('%1$s (Reason Code: %2$s)', 'event_espresso'),
257
+						$response->response_reason_text,
258
+						$response->response_reason_code
259
+					)
260
+				);
261
+				if ($this->_debug_mode) {
262
+					$txn_id = $response->invoice_number;
263
+				} else {
264
+					$txn_id = $response->transaction_id;
265
+				}
266
+				$payment->set_txn_id_chq_nmbr($txn_id);
267
+			}
268
+			$payment->set_extra_accntng($primary_registrant->reg_code());
269
+			$payment->set_details(print_r($response, true));
270
+		} else {
271
+			$payment->set_status($this->_pay_model->failed_status());
272
+			$payment->set_gateway_response(esc_html__("There was no response from Authorize.net", 'event_espresso'));
273
+			$payment->set_details(print_r($response, true));
274
+		}
275
+		return $payment;
276
+	}
277
+
278
+
279
+	/**
280
+	 * Sets billing data for the upcoming request to AIM that is considered sensitive;
281
+	 * also this method can be overridden by children classes to easily change
282
+	 * what billing data gets sent
283
+	 *
284
+	 * @param array $billing_info
285
+	 */
286
+	protected function _set_sensitive_billing_data($billing_info)
287
+	{
288
+		$this->setField('card_num', $billing_info['credit_card']);
289
+		$this->setField('exp_date', $billing_info['exp_month'] . $billing_info['exp_year']);
290
+		$this->setField('card_code', $billing_info['cvv']);
291
+	}
292
+
293
+
294
+	/**
295
+	 * Add a line item.
296
+	 *
297
+	 * @param string $item_id
298
+	 * @param string $item_name
299
+	 * @param string $item_description
300
+	 * @param string $item_quantity
301
+	 * @param string $item_unit_price
302
+	 * @param string $item_taxable
303
+	 */
304
+	public function addLineItem($item_id, $item_name, $item_description, $item_quantity, $item_unit_price, $item_taxable)
305
+	{
306
+		$args = array(
307
+			substr($item_id, 0, 31),
308
+			substr($this->prepareStringForAuthnet($item_name), 0, 31),
309
+			substr($this->prepareStringForAuthnet($item_description), 0, 255),
310
+			number_format(abs($item_quantity), 2, '.', ''),
311
+			number_format(abs($item_unit_price), 2, '.', ''),
312
+			$item_taxable === 'N' ? 'N' : 'Y'
313
+		);
314
+		$this->_additional_line_items[] = implode('<|>', $args);
315
+	}
316
+
317
+
318
+	/**
319
+	 * Set an individual name/value pair. This will append x_ to the name
320
+	 * before posting.
321
+	 *
322
+	 * @param string $name
323
+	 * @param string $value
324
+	 * @throws AuthorizeNetException
325
+	 */
326
+	protected function setField($name, $value)
327
+	{
328
+		if (in_array($name, $this->_all_aim_fields)) {
329
+			$this->_x_post_fields[ $name ] = $value;
330
+		} else {
331
+			throw new AuthorizeNetException("Error: no field $name exists in the AIM API.
332 332
             To set a custom field use setCustomField('field','value') instead.");
333
-        }
334
-    }
335
-
336
-
337
-    /**
338
-     * Posts the request to AuthorizeNet & returns response.
339
-     *
340
-     * @param $payment
341
-     * @return \EE_AuthorizeNetAIM_Response
342
-     */
343
-    private function _sendRequest($payment)
344
-    {
345
-        $this->_x_post_fields['login'] = $this->_login_id;
346
-        $this->_x_post_fields['tran_key'] = $this->_transaction_key;
347
-        $x_keys = array();
348
-        foreach ($this->_x_post_fields as $key => $value) {
349
-            $x_keys[] = "x_$key=" . urlencode($this->_get_unsupported_character_remover()->format($value));
350
-        }
351
-        // Add line items
352
-        foreach ($this->_additional_line_items as $key => $value) {
353
-            $x_keys[] =  "x_line_item=" . urlencode($this->_get_unsupported_character_remover()->format($value));
354
-        }
355
-        $this->_log_clean_request($x_keys, $payment);
356
-        $post_url = $this->_get_server_url();
357
-        $curl_request = curl_init($post_url);
358
-        $post_body = implode("&", $x_keys);
359
-        curl_setopt($curl_request, CURLOPT_POSTFIELDS, $post_body);
360
-        curl_setopt($curl_request, CURLOPT_HEADER, 0);
361
-        curl_setopt($curl_request, CURLOPT_TIMEOUT, 45);
362
-        curl_setopt($curl_request, CURLOPT_RETURNTRANSFER, 1);
363
-        curl_setopt($curl_request, CURLOPT_SSL_VERIFYHOST, 2);
364
-        if ($this->VERIFY_PEER) {
365
-            curl_setopt($curl_request, CURLOPT_CAINFO, dirname(__DIR__) . '/ssl/cert.pem');
366
-        } else {
367
-            curl_setopt($curl_request, CURLOPT_SSL_VERIFYPEER, false);
368
-        }
369
-
370
-        if (preg_match('/xml/', $post_url)) {
371
-            curl_setopt($curl_request, CURLOPT_HTTPHEADER, array("Content-Type: text/xml"));
372
-        }
373
-
374
-        $response = curl_exec($curl_request);
375
-
376
-        curl_close($curl_request);
377
-        $response_obj =  new EE_AuthorizeNetAIM_Response($response);
378
-
379
-        return $this->_log_and_clean_response($response_obj, $payment);
380
-    }
381
-
382
-
383
-    /**
384
-     * Logs the clean data only
385
-     *
386
-     * @param array $request_array
387
-     * @param EEI_Payment $payment
388
-     */
389
-    protected function _log_clean_request($request_array, $payment)
390
-    {
391
-        $keys_to_filter_out = array('x_card_num', 'x_card_code', 'x_exp_date');
392
-        foreach ($request_array as $index => $keyvaltogether) {
393
-            foreach ($keys_to_filter_out as $key) {
394
-                if (strpos($keyvaltogether, $key) === 0) {
395
-                    // found it at the first character
396
-                    // so its one of them
397
-                    unset($request_array[ $index ]);
398
-                }
399
-            }
400
-        }
401
-        $this->log(
402
-            array(
403
-                'AIM Request sent:' => $request_array,
404
-                'Server URL'        => $this->_get_server_url()
405
-            ),
406
-            $payment
407
-        );
408
-    }
409
-
410
-
411
-
412
-    /**
413
-     * Logs the response and cleans it
414
-     *
415
-     * @param EE_AuthorizeNetAIM_Response $response_obj
416
-     * @param EE_Payment                  $payment
417
-     * @return \EE_AuthorizeNetAIM_Response
418
-     */
419
-    private function _log_and_clean_response($response_obj, $payment)
420
-    {
421
-        $response_obj->account_number = '';
422
-        $this->log(array('AIM Response received:' => (array) $response_obj), $payment);
423
-        return $response_obj;
424
-    }
425
-
426
-    /**
427
-     * Removes characters Authorize.net doesn't handle well.
428
-     * @since 4.9.82.p
429
-     * @param $text
430
-     * @return string
431
-     */
432
-    private function prepareStringForAuthnet($text)
433
-    {
434
-        return str_replace(
435
-            '\'',
436
-            '',
437
-            $text
438
-        );
439
-    }
333
+		}
334
+	}
335
+
336
+
337
+	/**
338
+	 * Posts the request to AuthorizeNet & returns response.
339
+	 *
340
+	 * @param $payment
341
+	 * @return \EE_AuthorizeNetAIM_Response
342
+	 */
343
+	private function _sendRequest($payment)
344
+	{
345
+		$this->_x_post_fields['login'] = $this->_login_id;
346
+		$this->_x_post_fields['tran_key'] = $this->_transaction_key;
347
+		$x_keys = array();
348
+		foreach ($this->_x_post_fields as $key => $value) {
349
+			$x_keys[] = "x_$key=" . urlencode($this->_get_unsupported_character_remover()->format($value));
350
+		}
351
+		// Add line items
352
+		foreach ($this->_additional_line_items as $key => $value) {
353
+			$x_keys[] =  "x_line_item=" . urlencode($this->_get_unsupported_character_remover()->format($value));
354
+		}
355
+		$this->_log_clean_request($x_keys, $payment);
356
+		$post_url = $this->_get_server_url();
357
+		$curl_request = curl_init($post_url);
358
+		$post_body = implode("&", $x_keys);
359
+		curl_setopt($curl_request, CURLOPT_POSTFIELDS, $post_body);
360
+		curl_setopt($curl_request, CURLOPT_HEADER, 0);
361
+		curl_setopt($curl_request, CURLOPT_TIMEOUT, 45);
362
+		curl_setopt($curl_request, CURLOPT_RETURNTRANSFER, 1);
363
+		curl_setopt($curl_request, CURLOPT_SSL_VERIFYHOST, 2);
364
+		if ($this->VERIFY_PEER) {
365
+			curl_setopt($curl_request, CURLOPT_CAINFO, dirname(__DIR__) . '/ssl/cert.pem');
366
+		} else {
367
+			curl_setopt($curl_request, CURLOPT_SSL_VERIFYPEER, false);
368
+		}
369
+
370
+		if (preg_match('/xml/', $post_url)) {
371
+			curl_setopt($curl_request, CURLOPT_HTTPHEADER, array("Content-Type: text/xml"));
372
+		}
373
+
374
+		$response = curl_exec($curl_request);
375
+
376
+		curl_close($curl_request);
377
+		$response_obj =  new EE_AuthorizeNetAIM_Response($response);
378
+
379
+		return $this->_log_and_clean_response($response_obj, $payment);
380
+	}
381
+
382
+
383
+	/**
384
+	 * Logs the clean data only
385
+	 *
386
+	 * @param array $request_array
387
+	 * @param EEI_Payment $payment
388
+	 */
389
+	protected function _log_clean_request($request_array, $payment)
390
+	{
391
+		$keys_to_filter_out = array('x_card_num', 'x_card_code', 'x_exp_date');
392
+		foreach ($request_array as $index => $keyvaltogether) {
393
+			foreach ($keys_to_filter_out as $key) {
394
+				if (strpos($keyvaltogether, $key) === 0) {
395
+					// found it at the first character
396
+					// so its one of them
397
+					unset($request_array[ $index ]);
398
+				}
399
+			}
400
+		}
401
+		$this->log(
402
+			array(
403
+				'AIM Request sent:' => $request_array,
404
+				'Server URL'        => $this->_get_server_url()
405
+			),
406
+			$payment
407
+		);
408
+	}
409
+
410
+
411
+
412
+	/**
413
+	 * Logs the response and cleans it
414
+	 *
415
+	 * @param EE_AuthorizeNetAIM_Response $response_obj
416
+	 * @param EE_Payment                  $payment
417
+	 * @return \EE_AuthorizeNetAIM_Response
418
+	 */
419
+	private function _log_and_clean_response($response_obj, $payment)
420
+	{
421
+		$response_obj->account_number = '';
422
+		$this->log(array('AIM Response received:' => (array) $response_obj), $payment);
423
+		return $response_obj;
424
+	}
425
+
426
+	/**
427
+	 * Removes characters Authorize.net doesn't handle well.
428
+	 * @since 4.9.82.p
429
+	 * @param $text
430
+	 * @return string
431
+	 */
432
+	private function prepareStringForAuthnet($text)
433
+	{
434
+		return str_replace(
435
+			'\'',
436
+			'',
437
+			$text
438
+		);
439
+	}
440 440
 }
441 441
 
442 442
 
@@ -452,192 +452,192 @@  discard block
 block discarded – undo
452 452
 class EE_AuthorizeNetAIM_Response
453 453
 {
454 454
 
455
-    const APPROVED = '1';
456
-    const DECLINED = '2';
457
-    const ERROR = '3';
458
-    const HELD = '4';
459
-
460
-    protected $_x_post_fields = array(
461
-        "version"        => "3.1",
462
-        "delim_char"     => ",",
463
-        "delim_data"     => "TRUE",
464
-        "relay_response" => "FALSE",
465
-        "encap_char"     => "|",
466
-    );
467
-    public $approved;
468
-    public $declined;
469
-    public $error;
470
-    public $held;
471
-    public $response_code;
472
-    public $response_subcode;
473
-    public $response_reason_code;
474
-    public $response_reason_text;
475
-    public $authorization_code;
476
-    public $avs_response;
477
-    public $transaction_id;
478
-    public $invoice_number;
479
-    public $description;
480
-    public $amount;
481
-    public $method;
482
-    public $transaction_type;
483
-    public $customer_id;
484
-    public $first_name;
485
-    public $last_name;
486
-    public $company;
487
-    public $address;
488
-    public $city;
489
-    public $state;
490
-    public $zip_code;
491
-    public $country;
492
-    public $phone;
493
-    public $fax;
494
-    public $email_address;
495
-    public $ship_to_first_name;
496
-    public $ship_to_last_name;
497
-    public $ship_to_company;
498
-    public $ship_to_address;
499
-    public $ship_to_city;
500
-    public $ship_to_state;
501
-    public $ship_to_zip_code;
502
-    public $ship_to_country;
503
-    public $tax;
504
-    public $duty;
505
-    public $freight;
506
-    public $tax_exempt;
507
-    public $purchase_order_number;
508
-    public $md5_hash;
509
-    public $card_code_response;
510
-    public $cavv_response; // cardholder_authentication_verification_response
511
-    public $account_number;
512
-    public $card_type;
513
-    public $split_tender_id;
514
-    public $requested_amount;
515
-    public $balance_on_card;
516
-    public $response; // The response string from AuthorizeNet.
517
-    public $error_message;
518
-    private $_response_array = array(); // An array with the split response.
519
-
520
-
521
-    /**
522
-     * Constructor. Parses the AuthorizeNet response string
523
-     *
524
-     * @param string $response The response from the AuthNet server.
525
-     * @var string   $delimiter The delimiter used (default is ",")
526
-     * @var string   $encap_char The encap_char used (default is "|")
527
-     * @var array    $custom_fields Any custom fields set in the request.
528
-     */
529
-
530
-    public function __construct($response)
531
-    {
532
-        $encap_char = $this->_x_post_fields['encap_char'];
533
-        $delimiter = $this->_x_post_fields['delim_char'];
534
-        if ($response) {
535
-            // Split Array
536
-            $this->response = $response;
537
-            if ($encap_char) {
538
-                $this->_response_array = explode($encap_char . $delimiter . $encap_char, substr($response, 1, -1));
539
-            } else {
540
-                $this->_response_array = explode($delimiter, $response);
541
-            }
542
-
543
-            /**
544
-             * If AuthorizeNet doesn't return a delimited response.
545
-             */
546
-            if (count($this->_response_array) < 10) {
547
-                $this->approved = false;
548
-                $this->error = true;
549
-                $this->error_message = sprintf(
550
-                    esc_html__('Unrecognized response from Authorize.net: %1$s', 'event_espresso'),
551
-                    esc_html($response)
552
-                );
553
-                return;
554
-            }
555
-
556
-
557
-
558
-            // Set all fields
559
-            $this->response_code = $this->_response_array[0];
560
-            $this->response_subcode = $this->_response_array[1];
561
-            $this->response_reason_code = $this->_response_array[2];
562
-            $this->response_reason_text = $this->_response_array[3];
563
-            $this->authorization_code = $this->_response_array[4];
564
-            $this->avs_response = $this->_response_array[5];
565
-            $this->transaction_id = $this->_response_array[6];
566
-            $this->invoice_number = $this->_response_array[7];
567
-            $this->description = $this->_response_array[8];
568
-            $this->amount = $this->_response_array[9];
569
-            $this->method = $this->_response_array[10];
570
-            $this->transaction_type = $this->_response_array[11];
571
-            $this->customer_id = $this->_response_array[12];
572
-            $this->first_name = $this->_response_array[13];
573
-            $this->last_name = $this->_response_array[14];
574
-            $this->company = $this->_response_array[15];
575
-            $this->address = $this->_response_array[16];
576
-            $this->city = $this->_response_array[17];
577
-            $this->state = $this->_response_array[18];
578
-            $this->zip_code = $this->_response_array[19];
579
-            $this->country = $this->_response_array[20];
580
-            $this->phone = $this->_response_array[21];
581
-            $this->fax = $this->_response_array[22];
582
-            $this->email_address = $this->_response_array[23];
583
-            $this->ship_to_first_name = $this->_response_array[24];
584
-            $this->ship_to_last_name = $this->_response_array[25];
585
-            $this->ship_to_company = $this->_response_array[26];
586
-            $this->ship_to_address = $this->_response_array[27];
587
-            $this->ship_to_city = $this->_response_array[28];
588
-            $this->ship_to_state = $this->_response_array[29];
589
-            $this->ship_to_zip_code = $this->_response_array[30];
590
-            $this->ship_to_country = $this->_response_array[31];
591
-            $this->tax = $this->_response_array[32];
592
-            $this->duty = $this->_response_array[33];
593
-            $this->freight = $this->_response_array[34];
594
-            $this->tax_exempt = $this->_response_array[35];
595
-            $this->purchase_order_number = $this->_response_array[36];
596
-            $this->md5_hash = $this->_response_array[37];
597
-            $this->card_code_response = $this->_response_array[38];
598
-            $this->cavv_response = $this->_response_array[39];
599
-            $this->account_number = $this->_response_array[50];
600
-            $this->card_type = $this->_response_array[51];
601
-            $this->split_tender_id = $this->_response_array[52];
602
-            $this->requested_amount = $this->_response_array[53];
603
-            $this->balance_on_card = $this->_response_array[54];
604
-
605
-            $this->approved = ($this->response_code === self::APPROVED);
606
-            $this->declined = ($this->response_code === self::DECLINED);
607
-            $this->error = ($this->response_code === self::ERROR);
608
-            $this->held = ($this->response_code === self::HELD);
609
-        } else {
610
-            $this->approved = false;
611
-            $this->error = true;
612
-            $this->error_message = esc_html__(
613
-                'Error connecting to Authorize.net',
614
-                'event_espresso'
615
-            );
616
-        }
617
-    }
455
+	const APPROVED = '1';
456
+	const DECLINED = '2';
457
+	const ERROR = '3';
458
+	const HELD = '4';
459
+
460
+	protected $_x_post_fields = array(
461
+		"version"        => "3.1",
462
+		"delim_char"     => ",",
463
+		"delim_data"     => "TRUE",
464
+		"relay_response" => "FALSE",
465
+		"encap_char"     => "|",
466
+	);
467
+	public $approved;
468
+	public $declined;
469
+	public $error;
470
+	public $held;
471
+	public $response_code;
472
+	public $response_subcode;
473
+	public $response_reason_code;
474
+	public $response_reason_text;
475
+	public $authorization_code;
476
+	public $avs_response;
477
+	public $transaction_id;
478
+	public $invoice_number;
479
+	public $description;
480
+	public $amount;
481
+	public $method;
482
+	public $transaction_type;
483
+	public $customer_id;
484
+	public $first_name;
485
+	public $last_name;
486
+	public $company;
487
+	public $address;
488
+	public $city;
489
+	public $state;
490
+	public $zip_code;
491
+	public $country;
492
+	public $phone;
493
+	public $fax;
494
+	public $email_address;
495
+	public $ship_to_first_name;
496
+	public $ship_to_last_name;
497
+	public $ship_to_company;
498
+	public $ship_to_address;
499
+	public $ship_to_city;
500
+	public $ship_to_state;
501
+	public $ship_to_zip_code;
502
+	public $ship_to_country;
503
+	public $tax;
504
+	public $duty;
505
+	public $freight;
506
+	public $tax_exempt;
507
+	public $purchase_order_number;
508
+	public $md5_hash;
509
+	public $card_code_response;
510
+	public $cavv_response; // cardholder_authentication_verification_response
511
+	public $account_number;
512
+	public $card_type;
513
+	public $split_tender_id;
514
+	public $requested_amount;
515
+	public $balance_on_card;
516
+	public $response; // The response string from AuthorizeNet.
517
+	public $error_message;
518
+	private $_response_array = array(); // An array with the split response.
519
+
520
+
521
+	/**
522
+	 * Constructor. Parses the AuthorizeNet response string
523
+	 *
524
+	 * @param string $response The response from the AuthNet server.
525
+	 * @var string   $delimiter The delimiter used (default is ",")
526
+	 * @var string   $encap_char The encap_char used (default is "|")
527
+	 * @var array    $custom_fields Any custom fields set in the request.
528
+	 */
529
+
530
+	public function __construct($response)
531
+	{
532
+		$encap_char = $this->_x_post_fields['encap_char'];
533
+		$delimiter = $this->_x_post_fields['delim_char'];
534
+		if ($response) {
535
+			// Split Array
536
+			$this->response = $response;
537
+			if ($encap_char) {
538
+				$this->_response_array = explode($encap_char . $delimiter . $encap_char, substr($response, 1, -1));
539
+			} else {
540
+				$this->_response_array = explode($delimiter, $response);
541
+			}
542
+
543
+			/**
544
+			 * If AuthorizeNet doesn't return a delimited response.
545
+			 */
546
+			if (count($this->_response_array) < 10) {
547
+				$this->approved = false;
548
+				$this->error = true;
549
+				$this->error_message = sprintf(
550
+					esc_html__('Unrecognized response from Authorize.net: %1$s', 'event_espresso'),
551
+					esc_html($response)
552
+				);
553
+				return;
554
+			}
555
+
556
+
557
+
558
+			// Set all fields
559
+			$this->response_code = $this->_response_array[0];
560
+			$this->response_subcode = $this->_response_array[1];
561
+			$this->response_reason_code = $this->_response_array[2];
562
+			$this->response_reason_text = $this->_response_array[3];
563
+			$this->authorization_code = $this->_response_array[4];
564
+			$this->avs_response = $this->_response_array[5];
565
+			$this->transaction_id = $this->_response_array[6];
566
+			$this->invoice_number = $this->_response_array[7];
567
+			$this->description = $this->_response_array[8];
568
+			$this->amount = $this->_response_array[9];
569
+			$this->method = $this->_response_array[10];
570
+			$this->transaction_type = $this->_response_array[11];
571
+			$this->customer_id = $this->_response_array[12];
572
+			$this->first_name = $this->_response_array[13];
573
+			$this->last_name = $this->_response_array[14];
574
+			$this->company = $this->_response_array[15];
575
+			$this->address = $this->_response_array[16];
576
+			$this->city = $this->_response_array[17];
577
+			$this->state = $this->_response_array[18];
578
+			$this->zip_code = $this->_response_array[19];
579
+			$this->country = $this->_response_array[20];
580
+			$this->phone = $this->_response_array[21];
581
+			$this->fax = $this->_response_array[22];
582
+			$this->email_address = $this->_response_array[23];
583
+			$this->ship_to_first_name = $this->_response_array[24];
584
+			$this->ship_to_last_name = $this->_response_array[25];
585
+			$this->ship_to_company = $this->_response_array[26];
586
+			$this->ship_to_address = $this->_response_array[27];
587
+			$this->ship_to_city = $this->_response_array[28];
588
+			$this->ship_to_state = $this->_response_array[29];
589
+			$this->ship_to_zip_code = $this->_response_array[30];
590
+			$this->ship_to_country = $this->_response_array[31];
591
+			$this->tax = $this->_response_array[32];
592
+			$this->duty = $this->_response_array[33];
593
+			$this->freight = $this->_response_array[34];
594
+			$this->tax_exempt = $this->_response_array[35];
595
+			$this->purchase_order_number = $this->_response_array[36];
596
+			$this->md5_hash = $this->_response_array[37];
597
+			$this->card_code_response = $this->_response_array[38];
598
+			$this->cavv_response = $this->_response_array[39];
599
+			$this->account_number = $this->_response_array[50];
600
+			$this->card_type = $this->_response_array[51];
601
+			$this->split_tender_id = $this->_response_array[52];
602
+			$this->requested_amount = $this->_response_array[53];
603
+			$this->balance_on_card = $this->_response_array[54];
604
+
605
+			$this->approved = ($this->response_code === self::APPROVED);
606
+			$this->declined = ($this->response_code === self::DECLINED);
607
+			$this->error = ($this->response_code === self::ERROR);
608
+			$this->held = ($this->response_code === self::HELD);
609
+		} else {
610
+			$this->approved = false;
611
+			$this->error = true;
612
+			$this->error_message = esc_html__(
613
+				'Error connecting to Authorize.net',
614
+				'event_espresso'
615
+			);
616
+		}
617
+	}
618 618
 }
619 619
 
620 620
 if (! class_exists('AuthorizeNetException')) {
621
-    /**
622
-     * Class AuthorizeNetException
623
-     *
624
-     * @package    AuthorizeNet
625
-     */
626
-    class AuthorizeNetException extends Exception
627
-    {
628
-
629
-        /**
630
-         * Construct the exception. Note: The message is NOT binary safe.
631
-         *
632
-         * @link http://php.net/manual/en/exception.construct.php
633
-         * @param string $message [optional] The Exception message to throw.
634
-         * @param int $code [optional] The Exception code.
635
-         * @param Exception $previous [optional] The previous exception used for the exception chaining. Since 5.3.0
636
-         * @since 5.1.0
637
-         */
638
-        public function __construct($message = "", $code = 0, Exception $previous = null)
639
-        {
640
-            parent::__construct($message, $code, $previous);
641
-        }
642
-    }
621
+	/**
622
+	 * Class AuthorizeNetException
623
+	 *
624
+	 * @package    AuthorizeNet
625
+	 */
626
+	class AuthorizeNetException extends Exception
627
+	{
628
+
629
+		/**
630
+		 * Construct the exception. Note: The message is NOT binary safe.
631
+		 *
632
+		 * @link http://php.net/manual/en/exception.construct.php
633
+		 * @param string $message [optional] The Exception message to throw.
634
+		 * @param int $code [optional] The Exception code.
635
+		 * @param Exception $previous [optional] The previous exception used for the exception chaining. Since 5.3.0
636
+		 * @since 5.1.0
637
+		 */
638
+		public function __construct($message = "", $code = 0, Exception $previous = null)
639
+		{
640
+			parent::__construct($message, $code, $previous);
641
+		}
642
+	}
643 643
 }
Please login to merge, or discard this patch.
caffeinated/payment_methods/Aim/templates/aim_intro.template.php 1 patch
Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -1,10 +1,10 @@
 block discarded – undo
1 1
 <?php
2 2
 
3 3
 printf(
4
-    esc_html__(
5
-        'Authorize.Net AIM is an on-site payment method for accepting credit and debit card payments and is available to event organizers in the United States, Canada, United Kingdom, and Australia. An account with Authorize.Net is required to accept payments. Need an Authorize.Net account? %1$sClick here to sign up for a merchant account%2$s.',
6
-        'event_espresso'
7
-    ),
8
-    '<a href="https://eventespresso.com/go/authorizenetaim/" target="_blank">',
9
-    '</a>'
4
+	esc_html__(
5
+		'Authorize.Net AIM is an on-site payment method for accepting credit and debit card payments and is available to event organizers in the United States, Canada, United Kingdom, and Australia. An account with Authorize.Net is required to accept payments. Need an Authorize.Net account? %1$sClick here to sign up for a merchant account%2$s.',
6
+		'event_espresso'
7
+	),
8
+	'<a href="https://eventespresso.com/go/authorizenetaim/" target="_blank">',
9
+	'</a>'
10 10
 );
Please login to merge, or discard this patch.
caffeinated/modules/recaptcha/autoload.php 2 patches
Indentation   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -7,33 +7,33 @@
 block discarded – undo
7 7
  */
8 8
 
9 9
 spl_autoload_register(function ($class) {
10
-    if (substr($class, 0, 10) !== 'ReCaptcha\\') {
11
-        /* If the class does not lie under the "ReCaptcha" namespace,
10
+	if (substr($class, 0, 10) !== 'ReCaptcha\\') {
11
+		/* If the class does not lie under the "ReCaptcha" namespace,
12 12
          * then we can exit immediately.
13 13
          */
14
-        return;
15
-    }
14
+		return;
15
+	}
16 16
 
17
-    /* All of the classes have names like "ReCaptcha\Foo", so we need
17
+	/* All of the classes have names like "ReCaptcha\Foo", so we need
18 18
      * to replace the backslashes with frontslashes if we want the
19 19
      * name to map directly to a location in the filesystem.
20 20
      */
21
-    $class = str_replace('\\', '/', $class);
21
+	$class = str_replace('\\', '/', $class);
22 22
 
23
-    /* First, check under the current directory. It is important that
23
+	/* First, check under the current directory. It is important that
24 24
      * we look here first, so that we don't waste time searching for
25 25
      * test classes in the common case.
26 26
      */
27
-    $path = dirname(__FILE__) . '/' . $class . '.php';
28
-    if (is_readable($path)) {
29
-        require_once $path;
30
-    }
27
+	$path = dirname(__FILE__) . '/' . $class . '.php';
28
+	if (is_readable($path)) {
29
+		require_once $path;
30
+	}
31 31
 
32
-    /* If we didn't find what we're looking for already, maybe it's
32
+	/* If we didn't find what we're looking for already, maybe it's
33 33
      * a test class?
34 34
      */
35
-    $path = dirname(__FILE__) . '/../tests/' . $class . '.php';
36
-    if (is_readable($path)) {
37
-        require_once $path;
38
-    }
35
+	$path = dirname(__FILE__) . '/../tests/' . $class . '.php';
36
+	if (is_readable($path)) {
37
+		require_once $path;
38
+	}
39 39
 });
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@  discard block
 block discarded – undo
6 6
  * classes.
7 7
  */
8 8
 
9
-spl_autoload_register(function ($class) {
9
+spl_autoload_register(function($class) {
10 10
     if (substr($class, 0, 10) !== 'ReCaptcha\\') {
11 11
         /* If the class does not lie under the "ReCaptcha" namespace,
12 12
          * then we can exit immediately.
@@ -24,7 +24,7 @@  discard block
 block discarded – undo
24 24
      * we look here first, so that we don't waste time searching for
25 25
      * test classes in the common case.
26 26
      */
27
-    $path = dirname(__FILE__) . '/' . $class . '.php';
27
+    $path = dirname(__FILE__).'/'.$class.'.php';
28 28
     if (is_readable($path)) {
29 29
         require_once $path;
30 30
     }
@@ -32,7 +32,7 @@  discard block
 block discarded – undo
32 32
     /* If we didn't find what we're looking for already, maybe it's
33 33
      * a test class?
34 34
      */
35
-    $path = dirname(__FILE__) . '/../tests/' . $class . '.php';
35
+    $path = dirname(__FILE__).'/../tests/'.$class.'.php';
36 36
     if (is_readable($path)) {
37 37
         require_once $path;
38 38
     }
Please login to merge, or discard this patch.
modules/ticket_selector_caff/EED_Ticket_Selector_Caff.module.php 2 patches
Indentation   +294 added lines, -294 removed lines patch added patch discarded remove patch
@@ -17,319 +17,319 @@
 block discarded – undo
17 17
 {
18 18
 
19 19
 
20
-    /**
21
-     * @return EED_Module|EED_Ticket_Selector_Caff
22
-     */
23
-    public static function instance()
24
-    {
25
-        return parent::get_instance(__CLASS__);
26
-    }
20
+	/**
21
+	 * @return EED_Module|EED_Ticket_Selector_Caff
22
+	 */
23
+	public static function instance()
24
+	{
25
+		return parent::get_instance(__CLASS__);
26
+	}
27 27
 
28 28
 
29
-    /**
30
-     *    set_hooks - for hooking into EE Core, other modules, etc
31
-     *
32
-     * @access    public
33
-     * @return    void
34
-     */
35
-    public static function set_hooks()
36
-    {
37
-        add_action(
38
-            'AHEE__ticket_selector_chart_template__ticket_details__after_description',
39
-            array('EED_Ticket_Selector_Caff', 'ticket_price_details'),
40
-            10,
41
-            3
42
-        );
43
-    }
29
+	/**
30
+	 *    set_hooks - for hooking into EE Core, other modules, etc
31
+	 *
32
+	 * @access    public
33
+	 * @return    void
34
+	 */
35
+	public static function set_hooks()
36
+	{
37
+		add_action(
38
+			'AHEE__ticket_selector_chart_template__ticket_details__after_description',
39
+			array('EED_Ticket_Selector_Caff', 'ticket_price_details'),
40
+			10,
41
+			3
42
+		);
43
+	}
44 44
 
45
-    /**
46
-     *    set_hooks_admin - for hooking into EE Admin Core, other modules, etc
47
-     *
48
-     * @access    public
49
-     * @return    void
50
-     */
51
-    public static function set_hooks_admin()
52
-    {
53
-        define(
54
-            'TICKET_SELECTOR_CAFF_TEMPLATES_PATH',
55
-            str_replace('\\', '/', plugin_dir_path(__FILE__)) . 'templates/'
56
-        );
57
-        add_action(
58
-            'AHEE__template_settings__template__before_settings_form',
59
-            array('EED_Ticket_Selector_Caff', 'template_settings_form'),
60
-            10
61
-        );
62
-        add_filter(
63
-            'FHEE__General_Settings_Admin_Page__update_template_settings__data',
64
-            array('EED_Ticket_Selector_Caff', 'update_template_settings'),
65
-            10,
66
-            2
67
-        );
68
-    }
45
+	/**
46
+	 *    set_hooks_admin - for hooking into EE Admin Core, other modules, etc
47
+	 *
48
+	 * @access    public
49
+	 * @return    void
50
+	 */
51
+	public static function set_hooks_admin()
52
+	{
53
+		define(
54
+			'TICKET_SELECTOR_CAFF_TEMPLATES_PATH',
55
+			str_replace('\\', '/', plugin_dir_path(__FILE__)) . 'templates/'
56
+		);
57
+		add_action(
58
+			'AHEE__template_settings__template__before_settings_form',
59
+			array('EED_Ticket_Selector_Caff', 'template_settings_form'),
60
+			10
61
+		);
62
+		add_filter(
63
+			'FHEE__General_Settings_Admin_Page__update_template_settings__data',
64
+			array('EED_Ticket_Selector_Caff', 'update_template_settings'),
65
+			10,
66
+			2
67
+		);
68
+	}
69 69
 
70 70
 
71
-    /**
72
-     * @param \WP $WP
73
-     */
74
-    public function run($WP)
75
-    {
76
-        $this->set_config();
77
-    }
71
+	/**
72
+	 * @param \WP $WP
73
+	 */
74
+	public function run($WP)
75
+	{
76
+		$this->set_config();
77
+	}
78 78
 
79 79
 
80
-    /**
81
-     * @static
82
-     * @return void
83
-     * @throws EE_Error
84
-     * @throws InvalidArgumentException
85
-     * @throws InvalidDataTypeException
86
-     * @throws InvalidInterfaceException
87
-     */
88
-    public static function template_settings_form()
89
-    {
90
-        echo EED_Ticket_Selector_Caff::_ticket_selector_settings_form()->get_html();
91
-    }
80
+	/**
81
+	 * @static
82
+	 * @return void
83
+	 * @throws EE_Error
84
+	 * @throws InvalidArgumentException
85
+	 * @throws InvalidDataTypeException
86
+	 * @throws InvalidInterfaceException
87
+	 */
88
+	public static function template_settings_form()
89
+	{
90
+		echo EED_Ticket_Selector_Caff::_ticket_selector_settings_form()->get_html();
91
+	}
92 92
 
93 93
 
94
-    /**
95
-     * @return \EE_Form_Section_Proper
96
-     * @throws \EE_Error
97
-     */
98
-    public static function _ticket_selector_settings_form()
99
-    {
94
+	/**
95
+	 * @return \EE_Form_Section_Proper
96
+	 * @throws \EE_Error
97
+	 */
98
+	public static function _ticket_selector_settings_form()
99
+	{
100 100
 
101
-        return new EE_Form_Section_Proper(
102
-            array(
103
-                'name'            => 'ticket_selector_settings_form',
104
-                'html_id'         => 'ticket_selector_settings_form',
105
-                'layout_strategy' => new EE_Div_Per_Section_Layout(),
106
-                'subsections'     => apply_filters(
107
-                    'FHEE__EED_Ticket_Selector_Caff___ticket_selector_settings_form__form_subsections',
108
-                    array(
109
-                        'appearance_settings_hdr' => new EE_Form_Section_HTML(
110
-                            EEH_HTML::br(2) .
111
-                            EEH_HTML::h2(esc_html__('Ticket Selector Template Settings', 'event_espresso'))
112
-                        ),
113
-                        'appearance_settings'     => EED_Ticket_Selector_Caff::_ticket_selector_appearance_settings(),
114
-                    )
115
-                ),
116
-            )
117
-        );
118
-    }
101
+		return new EE_Form_Section_Proper(
102
+			array(
103
+				'name'            => 'ticket_selector_settings_form',
104
+				'html_id'         => 'ticket_selector_settings_form',
105
+				'layout_strategy' => new EE_Div_Per_Section_Layout(),
106
+				'subsections'     => apply_filters(
107
+					'FHEE__EED_Ticket_Selector_Caff___ticket_selector_settings_form__form_subsections',
108
+					array(
109
+						'appearance_settings_hdr' => new EE_Form_Section_HTML(
110
+							EEH_HTML::br(2) .
111
+							EEH_HTML::h2(esc_html__('Ticket Selector Template Settings', 'event_espresso'))
112
+						),
113
+						'appearance_settings'     => EED_Ticket_Selector_Caff::_ticket_selector_appearance_settings(),
114
+					)
115
+				),
116
+			)
117
+		);
118
+	}
119 119
 
120 120
 
121
-    /**
122
-     * @return \EE_Form_Section_Proper
123
-     * @throws \EE_Error
124
-     */
125
-    public static function _ticket_selector_appearance_settings()
126
-    {
127
-        if (
128
-            ! EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector instanceof EE_Ticket_Selector_Config
129
-        ) {
130
-            EED_Ticket_Selector::instance()->set_config();
131
-            EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector = EED_Ticket_Selector::instance()
132
-                                                                                                      ->config();
133
-        }
134
-        $EE_Ticket_Selector_Config = EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector;
135
-        // get option for whether to show datetime selector in TS
136
-        $show_datetime_selector = $EE_Ticket_Selector_Config->getShowDatetimeSelector();
137
-        // and option for how may datetimes must exist if display is conditional
138
-        $datetime_selector_threshold = $EE_Ticket_Selector_Config->getDatetimeSelectorThreshold();
121
+	/**
122
+	 * @return \EE_Form_Section_Proper
123
+	 * @throws \EE_Error
124
+	 */
125
+	public static function _ticket_selector_appearance_settings()
126
+	{
127
+		if (
128
+			! EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector instanceof EE_Ticket_Selector_Config
129
+		) {
130
+			EED_Ticket_Selector::instance()->set_config();
131
+			EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector = EED_Ticket_Selector::instance()
132
+																									  ->config();
133
+		}
134
+		$EE_Ticket_Selector_Config = EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector;
135
+		// get option for whether to show datetime selector in TS
136
+		$show_datetime_selector = $EE_Ticket_Selector_Config->getShowDatetimeSelector();
137
+		// and option for how may datetimes must exist if display is conditional
138
+		$datetime_selector_threshold = $EE_Ticket_Selector_Config->getDatetimeSelectorThreshold();
139 139
 
140
-        return new EE_Form_Section_Proper(
141
-            array(
142
-                'name'            => 'ticket_selector_settings_tbl',
143
-                'html_id'         => 'ticket_selector_settings_tbl',
144
-                'html_class'      => 'form-table',
145
-                'layout_strategy' => new EE_Admin_Two_Column_Layout(),
146
-                'subsections'     => apply_filters(
147
-                    'FHEE__EED_Ticket_Selector_Caff___ticket_selector_appearance_settings__form_subsections',
148
-                    array(
149
-                        'show_ticket_details'         => new EE_Yes_No_Input(
150
-                            array(
151
-                                'html_label_text'         => esc_html__(
152
-                                    'Show Ticket Details?',
153
-                                    'event_espresso'
154
-                                ),
155
-                                'html_help_text'          => esc_html__(
156
-                                    'This lets you choose whether the extra ticket details section is displayed with the ticket selector.',
157
-                                    'event_espresso'
158
-                                ),
159
-                                'default'                 => isset($EE_Ticket_Selector_Config->show_ticket_details)
160
-                                    ? $EE_Ticket_Selector_Config->show_ticket_details
161
-                                    : true,
162
-                                'display_html_label_text' => false,
163
-                            )
164
-                        ),
165
-                        'show_ticket_sale_columns'    => new EE_Yes_No_Input(
166
-                            array(
167
-                                'html_label_text'         => esc_html__(
168
-                                    'Show Ticket Sale Info?',
169
-                                    'event_espresso'
170
-                                ),
171
-                                'html_help_text'          => esc_html__(
172
-                                    'This lets you indicate whether information about ticket sales is shown with ticket details in the ticket selector.',
173
-                                    'event_espresso'
174
-                                ),
175
-                                'default'                 => isset($EE_Ticket_Selector_Config->show_ticket_sale_columns)
176
-                                    ? $EE_Ticket_Selector_Config->show_ticket_sale_columns
177
-                                    : true,
178
-                                'display_html_label_text' => false,
179
-                            )
180
-                        ),
181
-                        'show_expired_tickets'        => new EE_Yes_No_Input(
182
-                            array(
183
-                                'html_label_text'         => esc_html__(
184
-                                    'Show Expired Tickets?',
185
-                                    'event_espresso'
186
-                                ),
187
-                                'html_help_text'          => esc_html__(
188
-                                    'Indicate whether to show expired tickets in the ticket selector',
189
-                                    'event_espresso'
190
-                                ),
191
-                                'default'                 => isset($EE_Ticket_Selector_Config->show_expired_tickets)
192
-                                    ? $EE_Ticket_Selector_Config->show_expired_tickets
193
-                                    : true,
194
-                                'display_html_label_text' => false,
195
-                            )
196
-                        ),
197
-                        'show_datetime_selector'      => new EE_Select_Input(
198
-                            $EE_Ticket_Selector_Config->getShowDatetimeSelectorOptions(false),
199
-                            array(
200
-                                'html_label_text'         => esc_html__(
201
-                                    'Show Date & Time Filter?',
202
-                                    'event_espresso'
203
-                                ),
204
-                                'html_help_text'          => sprintf(
205
-                                    esc_html__(
206
-                                        'Indicates whether or not to display a dropdown select box above each ticket selector that displays dates and times for the available tickets. Ticket options can be unselected, which removes (hides) them from the list of tickets being displayed.%1$sOptions include:%1$s &bull; %2$sdo not show date & time filter%3$s%1$s &nbsp; this option will NEVER display a date filter, regardless of how many dates exist.%1$s &bull; %2$smaybe show date & time filter%3$s%1$s &nbsp; this option will conditionally display the date filter when the number of dates for the event matches the value set for "Date Filter Threshold".',
207
-                                        'event_espresso'
208
-                                    ),
209
-                                    '<br>',
210
-                                    '<strong>',
211
-                                    '</strong>'
212
-                                ),
213
-                                'default'                 => ! empty($show_datetime_selector)
214
-                                    ? $show_datetime_selector
215
-                                    : EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR,
216
-                                'display_html_label_text' => false,
217
-                            )
218
-                        ),
219
-                        'datetime_selector_threshold' => new EE_Select_Input(
220
-                            array_combine($r = range(1, 10), $r),
221
-                            array(
222
-                                'html_label_text'         => esc_html__(
223
-                                    'Date & Time Filter Threshold',
224
-                                    'event_espresso'
225
-                                ),
226
-                                'html_help_text'          => esc_html__(
227
-                                    'The number of unique dates an event has to have before conditionally displaying a date & time filter',
228
-                                    'event_espresso'
229
-                                ),
230
-                                'default'                 => ! empty($datetime_selector_threshold)
231
-                                    ? $datetime_selector_threshold
232
-                                    : 3,
233
-                                'display_html_label_text' => false,
234
-                            )
235
-                        ),
236
-                        'datetime_selector_max_checked' => new EE_Integer_Input(
237
-                            array(
238
-                                'html_label_text'         => esc_html__(
239
-                                    'Date & Time Filter Max Checked',
240
-                                    'event_espresso'
241
-                                ),
242
-                                'html_help_text'          => sprintf(
243
-                                    esc_html__(
244
-                                        'Determines the maximum number of dates that will be checked upon initial loading for a Date and Time Filter.%1$sIf set to zero or left blank, then ALL dates will be checked upon initial loading.',
245
-                                        'event_espresso'
246
-                                    ),
247
-                                    '<br>'
248
-                                ),
249
-                                'default'                 => $EE_Ticket_Selector_Config->getDatetimeSelectorMaxChecked(),
250
-                                'display_html_label_text' => false,
251
-                                'min_value'               => 0,
252
-                            )
253
-                        ),
254
-                    )
255
-                ),
256
-            )
257
-        );
258
-    }
140
+		return new EE_Form_Section_Proper(
141
+			array(
142
+				'name'            => 'ticket_selector_settings_tbl',
143
+				'html_id'         => 'ticket_selector_settings_tbl',
144
+				'html_class'      => 'form-table',
145
+				'layout_strategy' => new EE_Admin_Two_Column_Layout(),
146
+				'subsections'     => apply_filters(
147
+					'FHEE__EED_Ticket_Selector_Caff___ticket_selector_appearance_settings__form_subsections',
148
+					array(
149
+						'show_ticket_details'         => new EE_Yes_No_Input(
150
+							array(
151
+								'html_label_text'         => esc_html__(
152
+									'Show Ticket Details?',
153
+									'event_espresso'
154
+								),
155
+								'html_help_text'          => esc_html__(
156
+									'This lets you choose whether the extra ticket details section is displayed with the ticket selector.',
157
+									'event_espresso'
158
+								),
159
+								'default'                 => isset($EE_Ticket_Selector_Config->show_ticket_details)
160
+									? $EE_Ticket_Selector_Config->show_ticket_details
161
+									: true,
162
+								'display_html_label_text' => false,
163
+							)
164
+						),
165
+						'show_ticket_sale_columns'    => new EE_Yes_No_Input(
166
+							array(
167
+								'html_label_text'         => esc_html__(
168
+									'Show Ticket Sale Info?',
169
+									'event_espresso'
170
+								),
171
+								'html_help_text'          => esc_html__(
172
+									'This lets you indicate whether information about ticket sales is shown with ticket details in the ticket selector.',
173
+									'event_espresso'
174
+								),
175
+								'default'                 => isset($EE_Ticket_Selector_Config->show_ticket_sale_columns)
176
+									? $EE_Ticket_Selector_Config->show_ticket_sale_columns
177
+									: true,
178
+								'display_html_label_text' => false,
179
+							)
180
+						),
181
+						'show_expired_tickets'        => new EE_Yes_No_Input(
182
+							array(
183
+								'html_label_text'         => esc_html__(
184
+									'Show Expired Tickets?',
185
+									'event_espresso'
186
+								),
187
+								'html_help_text'          => esc_html__(
188
+									'Indicate whether to show expired tickets in the ticket selector',
189
+									'event_espresso'
190
+								),
191
+								'default'                 => isset($EE_Ticket_Selector_Config->show_expired_tickets)
192
+									? $EE_Ticket_Selector_Config->show_expired_tickets
193
+									: true,
194
+								'display_html_label_text' => false,
195
+							)
196
+						),
197
+						'show_datetime_selector'      => new EE_Select_Input(
198
+							$EE_Ticket_Selector_Config->getShowDatetimeSelectorOptions(false),
199
+							array(
200
+								'html_label_text'         => esc_html__(
201
+									'Show Date & Time Filter?',
202
+									'event_espresso'
203
+								),
204
+								'html_help_text'          => sprintf(
205
+									esc_html__(
206
+										'Indicates whether or not to display a dropdown select box above each ticket selector that displays dates and times for the available tickets. Ticket options can be unselected, which removes (hides) them from the list of tickets being displayed.%1$sOptions include:%1$s &bull; %2$sdo not show date & time filter%3$s%1$s &nbsp; this option will NEVER display a date filter, regardless of how many dates exist.%1$s &bull; %2$smaybe show date & time filter%3$s%1$s &nbsp; this option will conditionally display the date filter when the number of dates for the event matches the value set for "Date Filter Threshold".',
207
+										'event_espresso'
208
+									),
209
+									'<br>',
210
+									'<strong>',
211
+									'</strong>'
212
+								),
213
+								'default'                 => ! empty($show_datetime_selector)
214
+									? $show_datetime_selector
215
+									: EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR,
216
+								'display_html_label_text' => false,
217
+							)
218
+						),
219
+						'datetime_selector_threshold' => new EE_Select_Input(
220
+							array_combine($r = range(1, 10), $r),
221
+							array(
222
+								'html_label_text'         => esc_html__(
223
+									'Date & Time Filter Threshold',
224
+									'event_espresso'
225
+								),
226
+								'html_help_text'          => esc_html__(
227
+									'The number of unique dates an event has to have before conditionally displaying a date & time filter',
228
+									'event_espresso'
229
+								),
230
+								'default'                 => ! empty($datetime_selector_threshold)
231
+									? $datetime_selector_threshold
232
+									: 3,
233
+								'display_html_label_text' => false,
234
+							)
235
+						),
236
+						'datetime_selector_max_checked' => new EE_Integer_Input(
237
+							array(
238
+								'html_label_text'         => esc_html__(
239
+									'Date & Time Filter Max Checked',
240
+									'event_espresso'
241
+								),
242
+								'html_help_text'          => sprintf(
243
+									esc_html__(
244
+										'Determines the maximum number of dates that will be checked upon initial loading for a Date and Time Filter.%1$sIf set to zero or left blank, then ALL dates will be checked upon initial loading.',
245
+										'event_espresso'
246
+									),
247
+									'<br>'
248
+								),
249
+								'default'                 => $EE_Ticket_Selector_Config->getDatetimeSelectorMaxChecked(),
250
+								'display_html_label_text' => false,
251
+								'min_value'               => 0,
252
+							)
253
+						),
254
+					)
255
+				),
256
+			)
257
+		);
258
+	}
259 259
 
260 260
 
261
-    /**
262
-     * callback for updating template settings
263
-     *
264
-     * @since 4.6.18.rc.006
265
-     * @param EE_Template_Config $CFG
266
-     * @param array              $REQ incoming request
267
-     * @return EE_Template_Config
268
-     * @throws EE_Error
269
-     * @throws InvalidArgumentException
270
-     * @throws ReflectionException
271
-     * @throws InvalidDataTypeException
272
-     * @throws InvalidInterfaceException
273
-     */
274
-    public static function update_template_settings(EE_Template_Config $CFG, $REQ)
275
-    {
276
-        if (! $CFG->EED_Ticket_Selector instanceof EE_Ticket_Selector_Config) {
277
-            EED_Ticket_Selector::instance()->set_config();
278
-            $CFG->EED_Ticket_Selector = EED_Ticket_Selector::instance()->config();
279
-        }
280
-        try {
281
-            $ticket_selector_form = EED_Ticket_Selector_Caff::_ticket_selector_settings_form();
261
+	/**
262
+	 * callback for updating template settings
263
+	 *
264
+	 * @since 4.6.18.rc.006
265
+	 * @param EE_Template_Config $CFG
266
+	 * @param array              $REQ incoming request
267
+	 * @return EE_Template_Config
268
+	 * @throws EE_Error
269
+	 * @throws InvalidArgumentException
270
+	 * @throws ReflectionException
271
+	 * @throws InvalidDataTypeException
272
+	 * @throws InvalidInterfaceException
273
+	 */
274
+	public static function update_template_settings(EE_Template_Config $CFG, $REQ)
275
+	{
276
+		if (! $CFG->EED_Ticket_Selector instanceof EE_Ticket_Selector_Config) {
277
+			EED_Ticket_Selector::instance()->set_config();
278
+			$CFG->EED_Ticket_Selector = EED_Ticket_Selector::instance()->config();
279
+		}
280
+		try {
281
+			$ticket_selector_form = EED_Ticket_Selector_Caff::_ticket_selector_settings_form();
282 282
 
283
-            // check for form submission
284
-            if ($ticket_selector_form->was_submitted()) {
285
-                // capture form data
286
-                $ticket_selector_form->receive_form_submission();
283
+			// check for form submission
284
+			if ($ticket_selector_form->was_submitted()) {
285
+				// capture form data
286
+				$ticket_selector_form->receive_form_submission();
287 287
 
288
-                // validate form data
289
-                if ($ticket_selector_form->is_valid()) {
290
-                    // grab validated data from form
291
-                    $valid_data = $ticket_selector_form->valid_data();
288
+				// validate form data
289
+				if ($ticket_selector_form->is_valid()) {
290
+					// grab validated data from form
291
+					$valid_data = $ticket_selector_form->valid_data();
292 292
 
293
-                    // set data on config
294
-                    $CFG->EED_Ticket_Selector->show_ticket_sale_columns = $valid_data['appearance_settings']['show_ticket_sale_columns'];
295
-                    $CFG->EED_Ticket_Selector->show_ticket_details = $valid_data['appearance_settings']['show_ticket_details'];
296
-                    $CFG->EED_Ticket_Selector->show_expired_tickets = $valid_data['appearance_settings']['show_expired_tickets'];
297
-                    $CFG->EED_Ticket_Selector->setShowDatetimeSelector(
298
-                        $valid_data['appearance_settings']['show_datetime_selector']
299
-                    );
300
-                    $CFG->EED_Ticket_Selector->setDatetimeSelectorThreshold(
301
-                        $valid_data['appearance_settings']['datetime_selector_threshold']
302
-                    );
303
-                    $CFG->EED_Ticket_Selector->setDatetimeSelectorMaxChecked(
304
-                        $valid_data['appearance_settings']['datetime_selector_max_checked']
305
-                    );
306
-                } else {
307
-                    if ($ticket_selector_form->submission_error_message() !== '') {
308
-                        EE_Error::add_error(
309
-                            $ticket_selector_form->submission_error_message(),
310
-                            __FILE__,
311
-                            __FUNCTION__,
312
-                            __LINE__
313
-                        );
314
-                    }
315
-                }
316
-            }
317
-        } catch (EE_Error $e) {
318
-            $e->get_error();
319
-        }
293
+					// set data on config
294
+					$CFG->EED_Ticket_Selector->show_ticket_sale_columns = $valid_data['appearance_settings']['show_ticket_sale_columns'];
295
+					$CFG->EED_Ticket_Selector->show_ticket_details = $valid_data['appearance_settings']['show_ticket_details'];
296
+					$CFG->EED_Ticket_Selector->show_expired_tickets = $valid_data['appearance_settings']['show_expired_tickets'];
297
+					$CFG->EED_Ticket_Selector->setShowDatetimeSelector(
298
+						$valid_data['appearance_settings']['show_datetime_selector']
299
+					);
300
+					$CFG->EED_Ticket_Selector->setDatetimeSelectorThreshold(
301
+						$valid_data['appearance_settings']['datetime_selector_threshold']
302
+					);
303
+					$CFG->EED_Ticket_Selector->setDatetimeSelectorMaxChecked(
304
+						$valid_data['appearance_settings']['datetime_selector_max_checked']
305
+					);
306
+				} else {
307
+					if ($ticket_selector_form->submission_error_message() !== '') {
308
+						EE_Error::add_error(
309
+							$ticket_selector_form->submission_error_message(),
310
+							__FILE__,
311
+							__FUNCTION__,
312
+							__LINE__
313
+						);
314
+					}
315
+				}
316
+			}
317
+		} catch (EE_Error $e) {
318
+			$e->get_error();
319
+		}
320 320
 
321
-        return $CFG;
322
-    }
321
+		return $CFG;
322
+	}
323 323
 
324 324
 
325
-    /**
326
-     * @param \EE_Ticket $ticket
327
-     * @param int        $ticket_price
328
-     * @param bool       $display_ticket_price
329
-     */
330
-    public static function ticket_price_details(EE_Ticket $ticket, $ticket_price = 0, $display_ticket_price = false)
331
-    {
332
-        require str_replace('\\', '/', plugin_dir_path(__FILE__))
333
-                . 'templates/ticket_selector_price_details.template.php';
334
-    }
325
+	/**
326
+	 * @param \EE_Ticket $ticket
327
+	 * @param int        $ticket_price
328
+	 * @param bool       $display_ticket_price
329
+	 */
330
+	public static function ticket_price_details(EE_Ticket $ticket, $ticket_price = 0, $display_ticket_price = false)
331
+	{
332
+		require str_replace('\\', '/', plugin_dir_path(__FILE__))
333
+				. 'templates/ticket_selector_price_details.template.php';
334
+	}
335 335
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -52,7 +52,7 @@  discard block
 block discarded – undo
52 52
     {
53 53
         define(
54 54
             'TICKET_SELECTOR_CAFF_TEMPLATES_PATH',
55
-            str_replace('\\', '/', plugin_dir_path(__FILE__)) . 'templates/'
55
+            str_replace('\\', '/', plugin_dir_path(__FILE__)).'templates/'
56 56
         );
57 57
         add_action(
58 58
             'AHEE__template_settings__template__before_settings_form',
@@ -107,7 +107,7 @@  discard block
 block discarded – undo
107 107
                     'FHEE__EED_Ticket_Selector_Caff___ticket_selector_settings_form__form_subsections',
108 108
                     array(
109 109
                         'appearance_settings_hdr' => new EE_Form_Section_HTML(
110
-                            EEH_HTML::br(2) .
110
+                            EEH_HTML::br(2).
111 111
                             EEH_HTML::h2(esc_html__('Ticket Selector Template Settings', 'event_espresso'))
112 112
                         ),
113 113
                         'appearance_settings'     => EED_Ticket_Selector_Caff::_ticket_selector_appearance_settings(),
@@ -273,7 +273,7 @@  discard block
 block discarded – undo
273 273
      */
274 274
     public static function update_template_settings(EE_Template_Config $CFG, $REQ)
275 275
     {
276
-        if (! $CFG->EED_Ticket_Selector instanceof EE_Ticket_Selector_Config) {
276
+        if ( ! $CFG->EED_Ticket_Selector instanceof EE_Ticket_Selector_Config) {
277 277
             EED_Ticket_Selector::instance()->set_config();
278 278
             $CFG->EED_Ticket_Selector = EED_Ticket_Selector::instance()->config();
279 279
         }
Please login to merge, or discard this patch.
caffeinated/modules/recaptcha_invisible/RecaptchaAdminSettings.php 1 patch
Indentation   +346 added lines, -346 removed lines patch added patch discarded remove patch
@@ -31,362 +31,362 @@
 block discarded – undo
31 31
 class RecaptchaAdminSettings
32 32
 {
33 33
 
34
-    /**
35
-     * @var EE_Registration_Config $config
36
-     */
37
-    private $config;
34
+	/**
35
+	 * @var EE_Registration_Config $config
36
+	 */
37
+	private $config;
38 38
 
39 39
 
40
-    /**
41
-     * RecaptchaAdminSettings constructor.
42
-     *
43
-     * @param EE_Registration_Config $registration_config
44
-     */
45
-    public function __construct(EE_Registration_Config $registration_config)
46
-    {
47
-        $this->config = $registration_config;
48
-    }
40
+	/**
41
+	 * RecaptchaAdminSettings constructor.
42
+	 *
43
+	 * @param EE_Registration_Config $registration_config
44
+	 */
45
+	public function __construct(EE_Registration_Config $registration_config)
46
+	{
47
+		$this->config = $registration_config;
48
+	}
49 49
 
50 50
 
51
-    /**
52
-     * @throws InvalidArgumentException
53
-     * @throws InvalidInterfaceException
54
-     * @throws InvalidDataTypeException
55
-     * @throws EE_Error
56
-     */
57
-    public function adminSettings()
58
-    {
59
-        echo $this->settingsForm()->get_html_and_js();
60
-    }
51
+	/**
52
+	 * @throws InvalidArgumentException
53
+	 * @throws InvalidInterfaceException
54
+	 * @throws InvalidDataTypeException
55
+	 * @throws EE_Error
56
+	 */
57
+	public function adminSettings()
58
+	{
59
+		echo $this->settingsForm()->get_html_and_js();
60
+	}
61 61
 
62 62
 
63
-    /**
64
-     * @return EE_Form_Section_Proper
65
-     * @throws EE_Error
66
-     */
67
-    protected function settingsForm()
68
-    {
69
-        return new EE_Form_Section_Proper(
70
-            array(
71
-                'name'            => 'recaptcha_settings_form',
72
-                'html_id'         => 'recaptcha_settings_form',
73
-                'layout_strategy' => new EE_Div_Per_Section_Layout(),
74
-                'subsections'     => apply_filters(
75
-                    'FHEE__EED_Recaptcha___recaptcha_settings_form__form_subsections',
76
-                    array(
77
-                        'main_settings_hdr'       => new EE_Form_Section_HTML(
78
-                            EEH_HTML::h2(
79
-                                esc_html__('reCAPTCHA Anti-spam Settings', 'event_espresso')
80
-                                . EEH_Template::get_help_tab_link('recaptcha_info')
81
-                            )
82
-                        ),
83
-                        'main_settings'           => $this->mainSettings(),
84
-                        'appearance_settings_hdr' => new EE_Form_Section_HTML(
85
-                            EEH_HTML::h2(esc_html__('reCAPTCHA Appearance', 'event_espresso'))
86
-                        ),
87
-                        'appearance_settings'     => $this->appearanceSettings(),
88
-                        'required_fields_note'    => new EE_Form_Section_HTML(
89
-                            EEH_HTML::p(
90
-                                esc_html__('All fields marked with a * are required fields', 'event_espresso'),
91
-                                '',
92
-                                'grey-text'
93
-                            )
94
-                        ),
95
-                    )
96
-                ),
97
-            )
98
-        );
99
-    }
63
+	/**
64
+	 * @return EE_Form_Section_Proper
65
+	 * @throws EE_Error
66
+	 */
67
+	protected function settingsForm()
68
+	{
69
+		return new EE_Form_Section_Proper(
70
+			array(
71
+				'name'            => 'recaptcha_settings_form',
72
+				'html_id'         => 'recaptcha_settings_form',
73
+				'layout_strategy' => new EE_Div_Per_Section_Layout(),
74
+				'subsections'     => apply_filters(
75
+					'FHEE__EED_Recaptcha___recaptcha_settings_form__form_subsections',
76
+					array(
77
+						'main_settings_hdr'       => new EE_Form_Section_HTML(
78
+							EEH_HTML::h2(
79
+								esc_html__('reCAPTCHA Anti-spam Settings', 'event_espresso')
80
+								. EEH_Template::get_help_tab_link('recaptcha_info')
81
+							)
82
+						),
83
+						'main_settings'           => $this->mainSettings(),
84
+						'appearance_settings_hdr' => new EE_Form_Section_HTML(
85
+							EEH_HTML::h2(esc_html__('reCAPTCHA Appearance', 'event_espresso'))
86
+						),
87
+						'appearance_settings'     => $this->appearanceSettings(),
88
+						'required_fields_note'    => new EE_Form_Section_HTML(
89
+							EEH_HTML::p(
90
+								esc_html__('All fields marked with a * are required fields', 'event_espresso'),
91
+								'',
92
+								'grey-text'
93
+							)
94
+						),
95
+					)
96
+				),
97
+			)
98
+		);
99
+	}
100 100
 
101 101
 
102
-    /**
103
-     * @return EE_Form_Section_Proper
104
-     * @throws EE_Error
105
-     */
106
-    protected function mainSettings()
107
-    {
108
-        return new EE_Form_Section_Proper(
109
-            array(
110
-                'name'            => 'recaptcha_settings_tbl',
111
-                'html_id'         => 'recaptcha_settings_tbl',
112
-                'html_class'      => 'form-table',
113
-                'layout_strategy' => new EE_Admin_Two_Column_Layout(),
114
-                'subsections'     => apply_filters(
115
-                    'FHEE__EED_Recaptcha___recaptcha_main_settings__form_subsections',
116
-                    array(
117
-                        'use_captcha'          => new EE_Yes_No_Input(
118
-                            array(
119
-                                'html_label_text'         => esc_html__('Use reCAPTCHA', 'event_espresso'),
120
-                                'html_help_text'          => sprintf(
121
-                                    esc_html__(
122
-                                        'reCAPTCHA is a free service that  protects your website from spam and abuse. It employs advanced risk analysis technology to separate humans from abusive actors. Sign up %1$shere%2$s to receive your Public and Private keys.',
123
-                                        'event_espresso'
124
-                                    ),
125
-                                    '<a href="https://www.google.com/recaptcha/intro/index.html">',
126
-                                    '</a>'
127
-                                ),
128
-                                'default'                 => $this->config->use_captcha !== null
129
-                                    ? $this->config->use_captcha : false,
130
-                                'display_html_label_text' => false,
131
-                            )
132
-                        ),
133
-                        'recaptcha_publickey'  => new EE_Text_Input(
134
-                            array(
135
-                                'html_label_text' => esc_html__('Site Key', 'event_espresso'),
136
-                                'html_help_text'  => esc_html__(
137
-                                    'The site key is used to display the widget on your site.',
138
-                                    'event_espresso'
139
-                                ),
140
-                                'default'         => $this->config->recaptcha_publickey !== null
141
-                                    ? stripslashes($this->config->recaptcha_publickey) : '',
142
-                            )
143
-                        ),
144
-                        'recaptcha_privatekey' => new EE_Text_Input(
145
-                            array(
146
-                                'html_label_text' => esc_html__('Secret Key', 'event_espresso'),
147
-                                'html_help_text'  => esc_html__(
148
-                                    'The secret key authorizes communication between your application backend and the reCAPTCHA server to verify the user\'s response. The secret key needs to be kept safe for security purposes.',
149
-                                    'event_espresso'
150
-                                ),
151
-                                'default'         => $this->config->recaptcha_privatekey !== null
152
-                                    ? stripslashes($this->config->recaptcha_privatekey)
153
-                                    : '',
154
-                            )
155
-                        ),
156
-                        'recaptcha_protected_forms' => new EE_Checkbox_Multi_Input(
157
-                            array(
158
-                                'ticket_selector'   => esc_html__('Ticket Selector', 'event_espresso'),
159
-                                'registration_form' => esc_html__('Registration Form', 'event_espresso'),
160
-                            ),
161
-                            array(
162
-                                'html_label_text'         => esc_html__(
163
-                                    'Invisible reCAPTCHA Protection',
164
-                                    'event_espresso'
165
-                                ),
166
-                                'html_help_text'          => esc_html__(
167
-                                    'Select which Event Espresso forms you would like to enable Invisible reCAPTCHA on.',
168
-                                    'event_espresso'
169
-                                ),
170
-                                'default'                 => is_array($this->config->recaptcha_protected_forms)
171
-                                    ? $this->config->recaptcha_protected_forms
172
-                                    : array(),
173
-                                'display_html_label_text' => false,
174
-                            )
175
-                        ),
176
-                    )
177
-                ),
178
-            )
179
-        );
180
-    }
102
+	/**
103
+	 * @return EE_Form_Section_Proper
104
+	 * @throws EE_Error
105
+	 */
106
+	protected function mainSettings()
107
+	{
108
+		return new EE_Form_Section_Proper(
109
+			array(
110
+				'name'            => 'recaptcha_settings_tbl',
111
+				'html_id'         => 'recaptcha_settings_tbl',
112
+				'html_class'      => 'form-table',
113
+				'layout_strategy' => new EE_Admin_Two_Column_Layout(),
114
+				'subsections'     => apply_filters(
115
+					'FHEE__EED_Recaptcha___recaptcha_main_settings__form_subsections',
116
+					array(
117
+						'use_captcha'          => new EE_Yes_No_Input(
118
+							array(
119
+								'html_label_text'         => esc_html__('Use reCAPTCHA', 'event_espresso'),
120
+								'html_help_text'          => sprintf(
121
+									esc_html__(
122
+										'reCAPTCHA is a free service that  protects your website from spam and abuse. It employs advanced risk analysis technology to separate humans from abusive actors. Sign up %1$shere%2$s to receive your Public and Private keys.',
123
+										'event_espresso'
124
+									),
125
+									'<a href="https://www.google.com/recaptcha/intro/index.html">',
126
+									'</a>'
127
+								),
128
+								'default'                 => $this->config->use_captcha !== null
129
+									? $this->config->use_captcha : false,
130
+								'display_html_label_text' => false,
131
+							)
132
+						),
133
+						'recaptcha_publickey'  => new EE_Text_Input(
134
+							array(
135
+								'html_label_text' => esc_html__('Site Key', 'event_espresso'),
136
+								'html_help_text'  => esc_html__(
137
+									'The site key is used to display the widget on your site.',
138
+									'event_espresso'
139
+								),
140
+								'default'         => $this->config->recaptcha_publickey !== null
141
+									? stripslashes($this->config->recaptcha_publickey) : '',
142
+							)
143
+						),
144
+						'recaptcha_privatekey' => new EE_Text_Input(
145
+							array(
146
+								'html_label_text' => esc_html__('Secret Key', 'event_espresso'),
147
+								'html_help_text'  => esc_html__(
148
+									'The secret key authorizes communication between your application backend and the reCAPTCHA server to verify the user\'s response. The secret key needs to be kept safe for security purposes.',
149
+									'event_espresso'
150
+								),
151
+								'default'         => $this->config->recaptcha_privatekey !== null
152
+									? stripslashes($this->config->recaptcha_privatekey)
153
+									: '',
154
+							)
155
+						),
156
+						'recaptcha_protected_forms' => new EE_Checkbox_Multi_Input(
157
+							array(
158
+								'ticket_selector'   => esc_html__('Ticket Selector', 'event_espresso'),
159
+								'registration_form' => esc_html__('Registration Form', 'event_espresso'),
160
+							),
161
+							array(
162
+								'html_label_text'         => esc_html__(
163
+									'Invisible reCAPTCHA Protection',
164
+									'event_espresso'
165
+								),
166
+								'html_help_text'          => esc_html__(
167
+									'Select which Event Espresso forms you would like to enable Invisible reCAPTCHA on.',
168
+									'event_espresso'
169
+								),
170
+								'default'                 => is_array($this->config->recaptcha_protected_forms)
171
+									? $this->config->recaptcha_protected_forms
172
+									: array(),
173
+								'display_html_label_text' => false,
174
+							)
175
+						),
176
+					)
177
+				),
178
+			)
179
+		);
180
+	}
181 181
 
182 182
 
183
-    /**
184
-     * @return EE_Form_Section_Proper
185
-     * @throws EE_Error
186
-     */
187
-    protected function appearanceSettings()
188
-    {
189
-        return new EE_Form_Section_Proper(
190
-            array(
191
-                'name'            => 'recaptcha_appearance_settings_tbl',
192
-                'html_id'         => 'recaptcha_appearance_settings_tbl',
193
-                'html_class'      => 'form-table',
194
-                'layout_strategy' => new EE_Admin_Two_Column_Layout(),
195
-                'subsections'     => apply_filters(
196
-                    'FHEE__EED_Recaptcha___recaptcha_appearance_settings__form_subsections',
197
-                    array(
198
-                        'recaptcha_theme'    => new EE_Radio_Button_Input(
199
-                            array(
200
-                                'invisible' => esc_html__('Invisible', 'event_espresso'),
201
-                                'light'     => esc_html__('Light', 'event_espresso'),
202
-                                'dark'      => esc_html__('Dark', 'event_espresso'),
203
-                            ),
204
-                            array(
205
-                                'html_label_text'         => esc_html__('Theme', 'event_espresso'),
206
-                                'html_help_text'          => esc_html__(
207
-                                    'The color theme of the widget.',
208
-                                    'event_espresso'
209
-                                ),
210
-                                'default'                 => $this->config->recaptcha_theme !== null
211
-                                    ? $this->config->recaptcha_theme
212
-                                    : 'invisible',
213
-                                'display_html_label_text' => false,
214
-                            )
215
-                        ),
216
-                        'recaptcha_badge'     => new EE_Radio_Button_Input(
217
-                            array(
218
-                                'bottomleft' => esc_html__('Bottom Left', 'event_espresso'),
219
-                                'bottomright' => esc_html__('Bottom Right', 'event_espresso'),
220
-                                'inline' => esc_html__('Inline', 'event_espresso'),
221
-                            ),
222
-                            array(
223
-                                'html_label_text'         => esc_html__(
224
-                                    'Invisible reCAPTCHA Badge Position',
225
-                                    'event_espresso'
226
-                                ),
227
-                                'html_help_text'          => esc_html__(
228
-                                    'If using Invisible reCAPTCHA, then this determines the position of the reCAPTCHA badge. "Bottom Left" and "Bottom Right" both will float at the bottom of the screen. "Inline" appears beside the submit button but allows you to control the CSS.',
229
-                                    'event_espresso'
230
-                                ),
231
-                                'default'                 => $this->config->recaptcha_badge !== null
232
-                                    ? $this->config->recaptcha_badge
233
-                                    : 'bottomleft',
234
-                                'display_html_label_text' => false,
235
-                            )
236
-                        ),
237
-                        'recaptcha_type'     => new EE_Radio_Button_Input(
238
-                            array(
239
-                                'image' => esc_html__('Image', 'event_espresso'),
240
-                                'audio' => esc_html__('Audio', 'event_espresso'),
241
-                            ),
242
-                            array(
243
-                                'html_label_text'         => esc_html__('Type', 'event_espresso'),
244
-                                'html_help_text'          => esc_html__(
245
-                                    'The type of CAPTCHA to serve.',
246
-                                    'event_espresso'
247
-                                ),
248
-                                'default'                 => $this->config->recaptcha_type !== null
249
-                                    ? $this->config->recaptcha_type
250
-                                    : 'image',
251
-                                'display_html_label_text' => false,
252
-                            )
253
-                        ),
254
-                        'recaptcha_language' => new EE_Select_Input(
255
-                            array(
256
-                                'ar'     => esc_html__('Arabic', 'event_espresso'),
257
-                                'bg'     => esc_html__('Bulgarian', 'event_espresso'),
258
-                                'ca'     => esc_html__('Catalan', 'event_espresso'),
259
-                                'zh-CN'  => esc_html__('Chinese (Simplified)', 'event_espresso'),
260
-                                'zh-TW'  => esc_html__('Chinese (Traditional)	', 'event_espresso'),
261
-                                'hr'     => esc_html__('Croatian', 'event_espresso'),
262
-                                'cs'     => esc_html__('Czech', 'event_espresso'),
263
-                                'da'     => esc_html__('Danish', 'event_espresso'),
264
-                                'nl'     => esc_html__('Dutch', 'event_espresso'),
265
-                                'en-GB'  => esc_html__('English (UK)', 'event_espresso'),
266
-                                'en'     => esc_html__('English (US)', 'event_espresso'),
267
-                                'fil'    => esc_html__('Filipino', 'event_espresso'),
268
-                                'fi'     => esc_html__('Finnish', 'event_espresso'),
269
-                                'fr'     => esc_html__('French', 'event_espresso'),
270
-                                'fr-CA'  => esc_html__('French (Canadian)', 'event_espresso'),
271
-                                'de'     => esc_html__('German', 'event_espresso'),
272
-                                'de-AT'  => esc_html__('German (Austria)', 'event_espresso'),
273
-                                'de-CH'  => esc_html__('German (Switzerland)', 'event_espresso'),
274
-                                'el'     => esc_html__('Greek', 'event_espresso'),
275
-                                'iw'     => esc_html__('Hebrew', 'event_espresso'),
276
-                                'hi'     => esc_html__('Hindi', 'event_espresso'),
277
-                                'hu'     => esc_html__('Hungarian', 'event_espresso'),
278
-                                'id'     => esc_html__('Indonesian', 'event_espresso'),
279
-                                'it'     => esc_html__('Italian', 'event_espresso'),
280
-                                'ja'     => esc_html__('Japanese', 'event_espresso'),
281
-                                'ko'     => esc_html__('Korean', 'event_espresso'),
282
-                                'lv'     => esc_html__('Latvian', 'event_espresso'),
283
-                                'lt'     => esc_html__('Lithuanian', 'event_espresso'),
284
-                                'no'     => esc_html__('Norwegian', 'event_espresso'),
285
-                                'fa'     => esc_html__('Persian', 'event_espresso'),
286
-                                'pl'     => esc_html__('Polish', 'event_espresso'),
287
-                                'pt'     => esc_html__('Portuguese', 'event_espresso'),
288
-                                'pt-BR'  => esc_html__('Portuguese (Brazil)', 'event_espresso'),
289
-                                'pt-PT'  => esc_html__('Portuguese (Portugal)', 'event_espresso'),
290
-                                'ro'     => esc_html__('Romanian', 'event_espresso'),
291
-                                'ru'     => esc_html__('Russian', 'event_espresso'),
292
-                                'sr'     => esc_html__('Serbian', 'event_espresso'),
293
-                                'sk'     => esc_html__('Slovak', 'event_espresso'),
294
-                                'sl'     => esc_html__('Slovenian', 'event_espresso'),
295
-                                'es'     => esc_html__('Spanish', 'event_espresso'),
296
-                                'es-419' => esc_html__('Spanish (Latin America)', 'event_espresso'),
297
-                                'sv'     => esc_html__('Swedish', 'event_espresso'),
298
-                                'th'     => esc_html__('Thai', 'event_espresso'),
299
-                                'tr'     => esc_html__('Turkish', 'event_espresso'),
300
-                                'uk'     => esc_html__('Ukrainian', 'event_espresso'),
301
-                                'vi'     => esc_html__('Vietnamese', 'event_espresso'),
302
-                            ),
303
-                            array(
304
-                                'html_label_text' => esc_html__('Language', 'event_espresso'),
305
-                                'html_help_text'  => esc_html__(
306
-                                    'Forces the widget to render in a specific language.',
307
-                                    'event_espresso'
308
-                                ),
309
-                                'default'         => $this->config->recaptcha_language !== null
310
-                                    ? $this->config->recaptcha_language : 'en',
311
-                            )
312
-                        ),
313
-                    )
314
-                ),
315
-            )
316
-        );
317
-    }
183
+	/**
184
+	 * @return EE_Form_Section_Proper
185
+	 * @throws EE_Error
186
+	 */
187
+	protected function appearanceSettings()
188
+	{
189
+		return new EE_Form_Section_Proper(
190
+			array(
191
+				'name'            => 'recaptcha_appearance_settings_tbl',
192
+				'html_id'         => 'recaptcha_appearance_settings_tbl',
193
+				'html_class'      => 'form-table',
194
+				'layout_strategy' => new EE_Admin_Two_Column_Layout(),
195
+				'subsections'     => apply_filters(
196
+					'FHEE__EED_Recaptcha___recaptcha_appearance_settings__form_subsections',
197
+					array(
198
+						'recaptcha_theme'    => new EE_Radio_Button_Input(
199
+							array(
200
+								'invisible' => esc_html__('Invisible', 'event_espresso'),
201
+								'light'     => esc_html__('Light', 'event_espresso'),
202
+								'dark'      => esc_html__('Dark', 'event_espresso'),
203
+							),
204
+							array(
205
+								'html_label_text'         => esc_html__('Theme', 'event_espresso'),
206
+								'html_help_text'          => esc_html__(
207
+									'The color theme of the widget.',
208
+									'event_espresso'
209
+								),
210
+								'default'                 => $this->config->recaptcha_theme !== null
211
+									? $this->config->recaptcha_theme
212
+									: 'invisible',
213
+								'display_html_label_text' => false,
214
+							)
215
+						),
216
+						'recaptcha_badge'     => new EE_Radio_Button_Input(
217
+							array(
218
+								'bottomleft' => esc_html__('Bottom Left', 'event_espresso'),
219
+								'bottomright' => esc_html__('Bottom Right', 'event_espresso'),
220
+								'inline' => esc_html__('Inline', 'event_espresso'),
221
+							),
222
+							array(
223
+								'html_label_text'         => esc_html__(
224
+									'Invisible reCAPTCHA Badge Position',
225
+									'event_espresso'
226
+								),
227
+								'html_help_text'          => esc_html__(
228
+									'If using Invisible reCAPTCHA, then this determines the position of the reCAPTCHA badge. "Bottom Left" and "Bottom Right" both will float at the bottom of the screen. "Inline" appears beside the submit button but allows you to control the CSS.',
229
+									'event_espresso'
230
+								),
231
+								'default'                 => $this->config->recaptcha_badge !== null
232
+									? $this->config->recaptcha_badge
233
+									: 'bottomleft',
234
+								'display_html_label_text' => false,
235
+							)
236
+						),
237
+						'recaptcha_type'     => new EE_Radio_Button_Input(
238
+							array(
239
+								'image' => esc_html__('Image', 'event_espresso'),
240
+								'audio' => esc_html__('Audio', 'event_espresso'),
241
+							),
242
+							array(
243
+								'html_label_text'         => esc_html__('Type', 'event_espresso'),
244
+								'html_help_text'          => esc_html__(
245
+									'The type of CAPTCHA to serve.',
246
+									'event_espresso'
247
+								),
248
+								'default'                 => $this->config->recaptcha_type !== null
249
+									? $this->config->recaptcha_type
250
+									: 'image',
251
+								'display_html_label_text' => false,
252
+							)
253
+						),
254
+						'recaptcha_language' => new EE_Select_Input(
255
+							array(
256
+								'ar'     => esc_html__('Arabic', 'event_espresso'),
257
+								'bg'     => esc_html__('Bulgarian', 'event_espresso'),
258
+								'ca'     => esc_html__('Catalan', 'event_espresso'),
259
+								'zh-CN'  => esc_html__('Chinese (Simplified)', 'event_espresso'),
260
+								'zh-TW'  => esc_html__('Chinese (Traditional)	', 'event_espresso'),
261
+								'hr'     => esc_html__('Croatian', 'event_espresso'),
262
+								'cs'     => esc_html__('Czech', 'event_espresso'),
263
+								'da'     => esc_html__('Danish', 'event_espresso'),
264
+								'nl'     => esc_html__('Dutch', 'event_espresso'),
265
+								'en-GB'  => esc_html__('English (UK)', 'event_espresso'),
266
+								'en'     => esc_html__('English (US)', 'event_espresso'),
267
+								'fil'    => esc_html__('Filipino', 'event_espresso'),
268
+								'fi'     => esc_html__('Finnish', 'event_espresso'),
269
+								'fr'     => esc_html__('French', 'event_espresso'),
270
+								'fr-CA'  => esc_html__('French (Canadian)', 'event_espresso'),
271
+								'de'     => esc_html__('German', 'event_espresso'),
272
+								'de-AT'  => esc_html__('German (Austria)', 'event_espresso'),
273
+								'de-CH'  => esc_html__('German (Switzerland)', 'event_espresso'),
274
+								'el'     => esc_html__('Greek', 'event_espresso'),
275
+								'iw'     => esc_html__('Hebrew', 'event_espresso'),
276
+								'hi'     => esc_html__('Hindi', 'event_espresso'),
277
+								'hu'     => esc_html__('Hungarian', 'event_espresso'),
278
+								'id'     => esc_html__('Indonesian', 'event_espresso'),
279
+								'it'     => esc_html__('Italian', 'event_espresso'),
280
+								'ja'     => esc_html__('Japanese', 'event_espresso'),
281
+								'ko'     => esc_html__('Korean', 'event_espresso'),
282
+								'lv'     => esc_html__('Latvian', 'event_espresso'),
283
+								'lt'     => esc_html__('Lithuanian', 'event_espresso'),
284
+								'no'     => esc_html__('Norwegian', 'event_espresso'),
285
+								'fa'     => esc_html__('Persian', 'event_espresso'),
286
+								'pl'     => esc_html__('Polish', 'event_espresso'),
287
+								'pt'     => esc_html__('Portuguese', 'event_espresso'),
288
+								'pt-BR'  => esc_html__('Portuguese (Brazil)', 'event_espresso'),
289
+								'pt-PT'  => esc_html__('Portuguese (Portugal)', 'event_espresso'),
290
+								'ro'     => esc_html__('Romanian', 'event_espresso'),
291
+								'ru'     => esc_html__('Russian', 'event_espresso'),
292
+								'sr'     => esc_html__('Serbian', 'event_espresso'),
293
+								'sk'     => esc_html__('Slovak', 'event_espresso'),
294
+								'sl'     => esc_html__('Slovenian', 'event_espresso'),
295
+								'es'     => esc_html__('Spanish', 'event_espresso'),
296
+								'es-419' => esc_html__('Spanish (Latin America)', 'event_espresso'),
297
+								'sv'     => esc_html__('Swedish', 'event_espresso'),
298
+								'th'     => esc_html__('Thai', 'event_espresso'),
299
+								'tr'     => esc_html__('Turkish', 'event_espresso'),
300
+								'uk'     => esc_html__('Ukrainian', 'event_espresso'),
301
+								'vi'     => esc_html__('Vietnamese', 'event_espresso'),
302
+							),
303
+							array(
304
+								'html_label_text' => esc_html__('Language', 'event_espresso'),
305
+								'html_help_text'  => esc_html__(
306
+									'Forces the widget to render in a specific language.',
307
+									'event_espresso'
308
+								),
309
+								'default'         => $this->config->recaptcha_language !== null
310
+									? $this->config->recaptcha_language : 'en',
311
+							)
312
+						),
313
+					)
314
+				),
315
+			)
316
+		);
317
+	}
318 318
 
319 319
 
320
-    /**
321
-     * @param EE_Registration_Config $EE_Registration_Config
322
-     * @return EE_Registration_Config
323
-     * @throws InvalidArgumentException
324
-     * @throws InvalidInterfaceException
325
-     * @throws InvalidDataTypeException
326
-     * @throws EE_Error
327
-     * @throws ReflectionException
328
-     */
329
-    public function updateAdminSettings(EE_Registration_Config $EE_Registration_Config)
330
-    {
331
-        try {
332
-            $recaptcha_settings_form = $this->settingsForm();
333
-            // if not displaying a form, then check for form submission
334
-            if ($recaptcha_settings_form->was_submitted()) {
335
-                // capture form data
336
-                $recaptcha_settings_form->receive_form_submission();
337
-                // validate form data
338
-                if ($recaptcha_settings_form->is_valid()) {
339
-                    // grab validated data from form
340
-                    $valid_data = $recaptcha_settings_form->valid_data();
341
-                    // user proofing recaptcha:  If Use reCAPTCHA is set to yes but we dont' have site or secret keys then set Use reCAPTCHA to FALSE and give error message.
342
-                    if (
343
-                        $valid_data['main_settings']['use_captcha']
344
-                        && (
345
-                            ! $EE_Registration_Config->use_captcha
346
-                            && (
347
-                                empty($valid_data['main_settings']['recaptcha_publickey'])
348
-                                || empty($valid_data['main_settings']['recaptcha_privatekey'])
349
-                            )
350
-                        )
351
-                        && apply_filters(
352
-                            'FHEE__Extend_Registration_Form_Admin_Page__check_for_recaptcha_keys',
353
-                            true,
354
-                            $EE_Registration_Config
355
-                        )
356
-                    ) {
357
-                        $valid_data['main_settings']['use_captcha'] = false;
358
-                        EE_Error::add_error(
359
-                            esc_html__(
360
-                                'The use reCAPTCHA setting has been reset to "no". In order to enable the reCAPTCHA service, you must enter a Site Key and Secret Key.',
361
-                                'event_espresso'
362
-                            ),
363
-                            __FILE__,
364
-                            __FUNCTION__,
365
-                            __LINE__
366
-                        );
367
-                    }
368
-                    $EE_Registration_Config->use_captcha          = $valid_data['main_settings']['use_captcha'];
369
-                    $EE_Registration_Config->recaptcha_publickey  = $valid_data['main_settings']['recaptcha_publickey'];
370
-                    $EE_Registration_Config->recaptcha_protected_forms = $valid_data['main_settings']['recaptcha_protected_forms'];
371
-                    $EE_Registration_Config->recaptcha_privatekey = $valid_data['main_settings']['recaptcha_privatekey'];
372
-                    $EE_Registration_Config->recaptcha_type       = $valid_data['appearance_settings']['recaptcha_type'];
373
-                    $EE_Registration_Config->recaptcha_theme      = $valid_data['appearance_settings']['recaptcha_theme'];
374
-                    $EE_Registration_Config->recaptcha_badge      = $valid_data['appearance_settings']['recaptcha_badge'];
375
-                    $EE_Registration_Config->recaptcha_language   = $valid_data['appearance_settings']['recaptcha_language'];
376
-                } else {
377
-                    if ($recaptcha_settings_form->submission_error_message() !== '') {
378
-                        EE_Error::add_error(
379
-                            $recaptcha_settings_form->submission_error_message(),
380
-                            __FILE__,
381
-                            __FUNCTION__,
382
-                            __LINE__
383
-                        );
384
-                    }
385
-                }
386
-            }
387
-        } catch (EE_Error $e) {
388
-            $e->get_error();
389
-        }
390
-        return $EE_Registration_Config;
391
-    }
320
+	/**
321
+	 * @param EE_Registration_Config $EE_Registration_Config
322
+	 * @return EE_Registration_Config
323
+	 * @throws InvalidArgumentException
324
+	 * @throws InvalidInterfaceException
325
+	 * @throws InvalidDataTypeException
326
+	 * @throws EE_Error
327
+	 * @throws ReflectionException
328
+	 */
329
+	public function updateAdminSettings(EE_Registration_Config $EE_Registration_Config)
330
+	{
331
+		try {
332
+			$recaptcha_settings_form = $this->settingsForm();
333
+			// if not displaying a form, then check for form submission
334
+			if ($recaptcha_settings_form->was_submitted()) {
335
+				// capture form data
336
+				$recaptcha_settings_form->receive_form_submission();
337
+				// validate form data
338
+				if ($recaptcha_settings_form->is_valid()) {
339
+					// grab validated data from form
340
+					$valid_data = $recaptcha_settings_form->valid_data();
341
+					// user proofing recaptcha:  If Use reCAPTCHA is set to yes but we dont' have site or secret keys then set Use reCAPTCHA to FALSE and give error message.
342
+					if (
343
+						$valid_data['main_settings']['use_captcha']
344
+						&& (
345
+							! $EE_Registration_Config->use_captcha
346
+							&& (
347
+								empty($valid_data['main_settings']['recaptcha_publickey'])
348
+								|| empty($valid_data['main_settings']['recaptcha_privatekey'])
349
+							)
350
+						)
351
+						&& apply_filters(
352
+							'FHEE__Extend_Registration_Form_Admin_Page__check_for_recaptcha_keys',
353
+							true,
354
+							$EE_Registration_Config
355
+						)
356
+					) {
357
+						$valid_data['main_settings']['use_captcha'] = false;
358
+						EE_Error::add_error(
359
+							esc_html__(
360
+								'The use reCAPTCHA setting has been reset to "no". In order to enable the reCAPTCHA service, you must enter a Site Key and Secret Key.',
361
+								'event_espresso'
362
+							),
363
+							__FILE__,
364
+							__FUNCTION__,
365
+							__LINE__
366
+						);
367
+					}
368
+					$EE_Registration_Config->use_captcha          = $valid_data['main_settings']['use_captcha'];
369
+					$EE_Registration_Config->recaptcha_publickey  = $valid_data['main_settings']['recaptcha_publickey'];
370
+					$EE_Registration_Config->recaptcha_protected_forms = $valid_data['main_settings']['recaptcha_protected_forms'];
371
+					$EE_Registration_Config->recaptcha_privatekey = $valid_data['main_settings']['recaptcha_privatekey'];
372
+					$EE_Registration_Config->recaptcha_type       = $valid_data['appearance_settings']['recaptcha_type'];
373
+					$EE_Registration_Config->recaptcha_theme      = $valid_data['appearance_settings']['recaptcha_theme'];
374
+					$EE_Registration_Config->recaptcha_badge      = $valid_data['appearance_settings']['recaptcha_badge'];
375
+					$EE_Registration_Config->recaptcha_language   = $valid_data['appearance_settings']['recaptcha_language'];
376
+				} else {
377
+					if ($recaptcha_settings_form->submission_error_message() !== '') {
378
+						EE_Error::add_error(
379
+							$recaptcha_settings_form->submission_error_message(),
380
+							__FILE__,
381
+							__FUNCTION__,
382
+							__LINE__
383
+						);
384
+					}
385
+				}
386
+			}
387
+		} catch (EE_Error $e) {
388
+			$e->get_error();
389
+		}
390
+		return $EE_Registration_Config;
391
+	}
392 392
 }
Please login to merge, or discard this patch.
core/libraries/line_item_display/EE_Line_Item_Display.class.php 1 patch
Indentation   +52 added lines, -52 removed lines patch added patch discarded remove patch
@@ -15,63 +15,63 @@
 block discarded – undo
15 15
 class EE_Line_Item_Display
16 16
 {
17 17
 
18
-    private $strategy = null;
18
+	private $strategy = null;
19 19
 
20 20
 
21
-    /**
22
-     * @param string $context - where/how the line items are being displayed
23
-     * @param string $other_line_item_display_strategy
24
-     */
25
-    public function __construct($context = '', $other_line_item_display_strategy = '')
26
-    {
27
-        $context = strtolower($context);
28
-        switch ($context) {
29
-            case 'invoice':
30
-                $this->strategy = new EE_Invoice_Line_Item_Display_Strategy();
31
-                break;
32
-            case 'receipt':
33
-                $this->strategy = new EE_Receipt_Line_Item_Display_Strategy();
34
-                break;
35
-            case 'spco':
36
-                $this->strategy = new EE_SPCO_Line_Item_Display_Strategy();
37
-                break;
38
-            default:
39
-                if (
40
-                    ! empty($other_line_item_display_strategy) &&
41
-                    class_exists($other_line_item_display_strategy)
42
-                ) {
43
-                    $this->strategy = new  $other_line_item_display_strategy();
44
-                } else {
45
-                    $this->strategy = new EE_Default_Line_Item_Display_Strategy();
46
-                }
47
-        }
48
-    }
21
+	/**
22
+	 * @param string $context - where/how the line items are being displayed
23
+	 * @param string $other_line_item_display_strategy
24
+	 */
25
+	public function __construct($context = '', $other_line_item_display_strategy = '')
26
+	{
27
+		$context = strtolower($context);
28
+		switch ($context) {
29
+			case 'invoice':
30
+				$this->strategy = new EE_Invoice_Line_Item_Display_Strategy();
31
+				break;
32
+			case 'receipt':
33
+				$this->strategy = new EE_Receipt_Line_Item_Display_Strategy();
34
+				break;
35
+			case 'spco':
36
+				$this->strategy = new EE_SPCO_Line_Item_Display_Strategy();
37
+				break;
38
+			default:
39
+				if (
40
+					! empty($other_line_item_display_strategy) &&
41
+					class_exists($other_line_item_display_strategy)
42
+				) {
43
+					$this->strategy = new  $other_line_item_display_strategy();
44
+				} else {
45
+					$this->strategy = new EE_Default_Line_Item_Display_Strategy();
46
+				}
47
+		}
48
+	}
49 49
 
50
-    /**
51
-     * @param EE_Line_Item $line_item
52
-     * @param array        $options
53
-     * @return mixed
54
-     */
55
-    public function display_line_item(EE_Line_Item $line_item, $options = array())
56
-    {
57
-        return $this->strategy->display_line_item($line_item, $options);
58
-    }
50
+	/**
51
+	 * @param EE_Line_Item $line_item
52
+	 * @param array        $options
53
+	 * @return mixed
54
+	 */
55
+	public function display_line_item(EE_Line_Item $line_item, $options = array())
56
+	{
57
+		return $this->strategy->display_line_item($line_item, $options);
58
+	}
59 59
 
60 60
 
61
-    /**
62
-     * @return float
63
-     */
64
-    public function grand_total()
65
-    {
66
-        return $this->strategy->grand_total();
67
-    }
61
+	/**
62
+	 * @return float
63
+	 */
64
+	public function grand_total()
65
+	{
66
+		return $this->strategy->grand_total();
67
+	}
68 68
 
69 69
 
70
-    /**
71
-     * @return float
72
-     */
73
-    public function total_items()
74
-    {
75
-        return $this->strategy->total_items();
76
-    }
70
+	/**
71
+	 * @return float
72
+	 */
73
+	public function total_items()
74
+	{
75
+		return $this->strategy->total_items();
76
+	}
77 77
 }
Please login to merge, or discard this patch.
libraries/line_item_display/EE_SPCO_Line_Item_Display_Strategy.strategy.php 2 patches
Indentation   +659 added lines, -659 removed lines patch added patch discarded remove patch
@@ -12,663 +12,663 @@
 block discarded – undo
12 12
 class EE_SPCO_Line_Item_Display_Strategy implements EEI_Line_Item_Display
13 13
 {
14 14
 
15
-    /**
16
-     * array of events
17
-     *
18
-     * @type EE_Line_Item[] $_events
19
-     */
20
-    private $_events = array();
21
-
22
-    /**
23
-     * whether to display the taxes row or not
24
-     *
25
-     * @type bool $_show_taxes
26
-     */
27
-    private $_show_taxes = false;
28
-
29
-    /**
30
-     * html for any tax rows
31
-     *
32
-     * @type string $_show_taxes
33
-     */
34
-    private $_taxes_html = '';
35
-
36
-    /**
37
-     * total amount including tax we can bill for at this time
38
-     *
39
-     * @type float $_grand_total
40
-     */
41
-    private $_grand_total = 0.00;
42
-
43
-    /**
44
-     * total number of items being billed for
45
-     *
46
-     * @type int $_total_items
47
-     */
48
-    private $_total_items = 0;
49
-
50
-
51
-
52
-    /**
53
-     * @return float
54
-     */
55
-    public function grand_total()
56
-    {
57
-        return $this->_grand_total;
58
-    }
59
-
60
-
61
-
62
-    /**
63
-     * @return int
64
-     */
65
-    public function total_items()
66
-    {
67
-        return $this->_total_items;
68
-    }
69
-
70
-
71
-
72
-    /**
73
-     * @param EE_Line_Item $line_item
74
-     * @param array        $options
75
-     * @param EE_Line_Item $parent_line_item
76
-     * @return mixed
77
-     * @throws EE_Error
78
-     */
79
-    public function display_line_item(
80
-        EE_Line_Item $line_item,
81
-        $options = array(),
82
-        EE_Line_Item $parent_line_item = null
83
-    ) {
84
-        $html = '';
85
-        // set some default options and merge with incoming
86
-        $default_options = array(
87
-            'show_desc' => true,  //    true        false
88
-            'odd'       => false,
89
-        );
90
-        $options = array_merge($default_options, (array) $options);
91
-        switch ($line_item->type()) {
92
-            case EEM_Line_Item::type_line_item:
93
-                $this->_show_taxes = $line_item->is_taxable() ? true : $this->_show_taxes;
94
-                if ($line_item->OBJ_type() === 'Ticket') {
95
-                    // item row
96
-                    $html .= $this->_ticket_row($line_item, $options);
97
-                } else {
98
-                    // item row
99
-                    $html .= $this->_item_row($line_item, $options);
100
-                }
101
-                if (
102
-                    apply_filters(
103
-                        'FHEE__EE_SPCO_Line_Item_Display_Strategy__display_line_item__display_sub_line_items',
104
-                        true
105
-                    )
106
-                ) {
107
-                    // got any kids?
108
-                    foreach ($line_item->children() as $child_line_item) {
109
-                        $html .= $this->display_line_item($child_line_item, $options, $line_item);
110
-                    }
111
-                }
112
-                break;
113
-            case EEM_Line_Item::type_sub_line_item:
114
-                $html .= $this->_sub_item_row($line_item, $options, $parent_line_item);
115
-                break;
116
-            case EEM_Line_Item::type_sub_total:
117
-                static $sub_total = 0;
118
-                $event_sub_total = 0;
119
-                $text = esc_html__('Sub-Total', 'event_espresso');
120
-                if ($line_item->OBJ_type() === 'Event') {
121
-                    $options['event_id'] = $event_id = $line_item->OBJ_ID();
122
-                    if (! isset($this->_events[ $options['event_id'] ])) {
123
-                        $event = EEM_Event::instance()->get_one_by_ID($options['event_id']);
124
-                        // if event has default reg status of Not Approved, then don't display info on it
125
-                        if (
126
-                            $event instanceof EE_Event
127
-                            && $event->default_registration_status() === EEM_Registration::status_id_not_approved
128
-                        ) {
129
-                            $display_event = false;
130
-                            // unless there are registrations for it that are returning to pay
131
-                            if (isset($options['registrations']) && is_array($options['registrations'])) {
132
-                                foreach ($options['registrations'] as $registration) {
133
-                                    if (! $registration instanceof EE_Registration) {
134
-                                        continue;
135
-                                    }
136
-                                    $display_event = $registration->event_ID() === $options['event_id']
137
-                                                     && $registration->status_ID() !== EEM_Registration::status_id_not_approved
138
-                                        ? true
139
-                                        : $display_event;
140
-                                }
141
-                            }
142
-                            if (! $display_event) {
143
-                                return '';
144
-                            }
145
-                        }
146
-                        $this->_events[ $options['event_id'] ] = 0;
147
-                        $html .= $this->_event_row($line_item);
148
-                        $text = esc_html__('Event Sub-Total', 'event_espresso');
149
-                    }
150
-                }
151
-                $child_line_items = $line_item->children();
152
-                // loop thru children
153
-                foreach ($child_line_items as $child_line_item) {
154
-                    // recursively feed children back into this method
155
-                    $html .= $this->display_line_item($child_line_item, $options, $line_item);
156
-                }
157
-                $event_sub_total += isset($options['event_id']) ? $this->_events[ $options['event_id'] ] : 0;
158
-                $sub_total += $event_sub_total;
159
-                if (
160
-                    (
161
-                        // event subtotals
162
-                        $line_item->code() !== 'pre-tax-subtotal' && count($child_line_items) > 1
163
-                    )
164
-                    || (
165
-                        // pre-tax subtotals
166
-                        $line_item->code() === 'pre-tax-subtotal' && count($this->_events) > 1
167
-                    )
168
-                ) {
169
-                    $options['sub_total'] = $line_item->OBJ_type() === 'Event' ? $event_sub_total : $sub_total;
170
-                    $html .= $this->_sub_total_row($line_item, $text, $options);
171
-                }
172
-                break;
173
-            case EEM_Line_Item::type_tax:
174
-                if ($this->_show_taxes) {
175
-                    $this->_taxes_html .= $this->_tax_row($line_item, $options);
176
-                }
177
-                break;
178
-            case EEM_Line_Item::type_tax_sub_total:
179
-                if ($this->_show_taxes) {
180
-                    $child_line_items = $line_item->children();
181
-                    // loop thru children
182
-                    foreach ($child_line_items as $child_line_item) {
183
-                        // recursively feed children back into this method
184
-                        $html .= $this->display_line_item($child_line_item, $options, $line_item);
185
-                    }
186
-                    if (count($child_line_items) > 1) {
187
-                        $this->_taxes_html .= $this->_total_tax_row($line_item, esc_html__('Tax Total', 'event_espresso'));
188
-                    }
189
-                }
190
-                break;
191
-            case EEM_Line_Item::type_total:
192
-                // get all child line items
193
-                $children = $line_item->children();
194
-                // loop thru all non-tax child line items
195
-                foreach ($children as $child_line_item) {
196
-                    if ($child_line_item->type() !== EEM_Line_Item::type_tax_sub_total) {
197
-                        // recursively feed children back into this method
198
-                        $html .= $this->display_line_item($child_line_item, $options, $line_item);
199
-                    }
200
-                }
201
-                // now loop thru  tax child line items
202
-                foreach ($children as $child_line_item) {
203
-                    if ($child_line_item->type() === EEM_Line_Item::type_tax_sub_total) {
204
-                        // recursively feed children back into this method
205
-                        $html .= $this->display_line_item($child_line_item, $options, $line_item);
206
-                    }
207
-                }
208
-                $html .= $this->_taxes_html;
209
-                $html .= $this->_total_row($line_item, esc_html__('Total', 'event_espresso'));
210
-                $html .= $this->_payments_and_amount_owing_rows($line_item, $options);
211
-                break;
212
-        }
213
-        return $html;
214
-    }
215
-
216
-
217
-
218
-    /**
219
-     * _event_row - basically a Heading row displayed once above each event's ticket rows
220
-     *
221
-     * @param EE_Line_Item $line_item
222
-     * @return mixed
223
-     */
224
-    private function _event_row(EE_Line_Item $line_item)
225
-    {
226
-        // start of row
227
-        $html = EEH_HTML::tr('', 'event-cart-total-row', 'total_tr odd');
228
-        // event name td
229
-        $html .= EEH_HTML::td(
230
-            EEH_HTML::strong($line_item->name()),
231
-            '',
232
-            'event-header',
233
-            '',
234
-            ' colspan="4"'
235
-        );
236
-        // end of row
237
-        $html .= EEH_HTML::trx();
238
-        return $html;
239
-    }
240
-
241
-
242
-
243
-    /**
244
-     * _ticket_row
245
-     *
246
-     * @param EE_Line_Item $line_item
247
-     * @param array        $options
248
-     * @return mixed
249
-     * @throws EE_Error
250
-     */
251
-    private function _ticket_row(EE_Line_Item $line_item, $options = array())
252
-    {
253
-        // start of row
254
-        $row_class = $options['odd'] ? 'item odd' : 'item';
255
-        $html = EEH_HTML::tr('', '', $row_class);
256
-        // name && desc
257
-        $name_and_desc = apply_filters(
258
-            'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__name',
259
-            $line_item->name(),
260
-            $line_item
261
-        );
262
-        $name_and_desc .= apply_filters(
263
-            'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__desc',
264
-            (
265
-                $options['show_desc']
266
-                    ? '<span class="line-item-desc-spn smaller-text">: ' . $line_item->desc() . '</span>'
267
-                    : ''
268
-            ),
269
-            $line_item,
270
-            $options
271
-        );
272
-        $name_and_desc .= $line_item->is_taxable() ? ' * ' : '';
273
-        $name_and_desc = apply_filters(
274
-            'FHEE__EE_SPCO_Line_Item_Display_Strategy___ticket_row__name_and_desc',
275
-            $name_and_desc,
276
-            $line_item,
277
-            $options
278
-        );
279
-
280
-        // name td
281
-        $html .= EEH_HTML::td( /*__FUNCTION__ .*/
282
-            $name_and_desc,
283
-            '',
284
-            'item_l'
285
-        );
286
-        // price td
287
-        $price = apply_filters(
288
-            'FHEE__EE_SPCO_Line_Item_Display_Strategy___ticket_row__price',
289
-            $line_item->unit_price_no_code(),
290
-            $line_item
291
-        );
292
-        $html .= EEH_HTML::td($price, '', 'item_c jst-rght');
293
-        // quantity td
294
-        $html .= EEH_HTML::td($line_item->quantity(), '', 'item_l jst-rght');
295
-        $this->_total_items += $line_item->quantity();
296
-        // determine total for line item
297
-        $total = apply_filters(
298
-            'FHEE__EE_SPCO_Line_Item_Display_Strategy___ticket_row__total',
299
-            $line_item->total(),
300
-            $line_item
301
-        );
302
-        $this->_events[ $options['event_id'] ] += $total;
303
-        // total td
304
-        $html .= EEH_HTML::td(
305
-            EEH_Template::format_currency($total, false, false),
306
-            '',
307
-            'item_r jst-rght'
308
-        );
309
-        // end of row
310
-        $html .= EEH_HTML::trx();
311
-        return $html;
312
-    }
313
-
314
-
315
-
316
-    /**
317
-     * _item_row
318
-     *
319
-     * @param EE_Line_Item $line_item
320
-     * @param array        $options
321
-     * @return mixed
322
-     * @throws EE_Error
323
-     */
324
-    private function _item_row(EE_Line_Item $line_item, $options = array())
325
-    {
326
-        // start of row
327
-        $row_class = $options['odd'] ? 'item odd' : 'item';
328
-        $html = EEH_HTML::tr('', '', $row_class);
329
-        $obj_name = $line_item->OBJ_type() ? $line_item->OBJ_type_i18n() . ': ' : '';
330
-        // name && desc
331
-        $name_and_desc = apply_filters(
332
-            'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__name',
333
-            $obj_name . $line_item->name(),
334
-            $line_item
335
-        );
336
-        $name_and_desc .= apply_filters(
337
-            'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__desc',
338
-            (
339
-                $options['show_desc']
340
-                ? '<span class="line-item-desc-spn smaller-text">: ' . $line_item->desc() . '</span>'
341
-                : ''
342
-            ),
343
-            $line_item,
344
-            $options
345
-        );
346
-        $name_and_desc .= $line_item->is_taxable() ? ' * ' : '';
347
-        $name_and_desc = apply_filters(
348
-            'FHEE__EE_SPCO_Line_Item_Display_Strategy___item_row__name_and_desc',
349
-            $name_and_desc,
350
-            $line_item,
351
-            $options
352
-        );
353
-
354
-        // name td
355
-        $html .= EEH_HTML::td($name_and_desc, '', 'item_l');
356
-        // price td
357
-        if ($line_item->is_percent()) {
358
-            $html .= EEH_HTML::td($line_item->percent() . '%', '', 'item_c jst-rght');
359
-        } else {
360
-            $html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'item_c jst-rght');
361
-        }
362
-        // quantity td
363
-        $html .= EEH_HTML::td($line_item->quantity(), '', 'item_l jst-rght');
364
-        // $total = $line_item->total() * $line_item->quantity();
365
-        $total = $line_item->total();
366
-        if (isset($options['event_id'], $this->_events[ $options['event_id'] ])) {
367
-            $this->_events[ $options['event_id'] ] += $total;
368
-        }
369
-        // total td
370
-        $html .= EEH_HTML::td(
371
-            EEH_Template::format_currency($total, false, false),
372
-            '',
373
-            'item_r jst-rght'
374
-        );
375
-        // end of row
376
-        $html .= EEH_HTML::trx();
377
-        return $html;
378
-    }
379
-
380
-
381
-
382
-    /**
383
-     * _sub_item_row
384
-     *
385
-     * @param EE_Line_Item $line_item
386
-     * @param array        $options
387
-     * @param EE_Line_Item $parent_line_item
388
-     * @return mixed
389
-     * @throws EE_Error
390
-     */
391
-    private function _sub_item_row(EE_Line_Item $line_item, $options = array(), EE_Line_Item $parent_line_item = null)
392
-    {
393
-        if (
394
-            $parent_line_item instanceof  EE_Line_Item
395
-            && $line_item->children() === array()
396
-            && $line_item->name() === $parent_line_item->name()
397
-            && apply_filters(
398
-                'FHEE__EE_SPCO_Line_Item_Display_Strategy___sub_item_row__hide_main_sub_line_item',
399
-                true
400
-            )
401
-        ) {
402
-            return '';
403
-        }
404
-        // start of row
405
-        $html = EEH_HTML::tr('', '', 'item sub-item-row');
406
-        // name && desc
407
-        $name_and_desc = EEH_HTML::span('', '', 'sub-item-row-bullet dashicons dashicons-arrow-right')
408
-                         . $line_item->name();
409
-        $name_and_desc .= $options['show_desc'] ? '<span class="line-sub-item-desc-spn smaller-text">: '
410
-                                                  . $line_item->desc()
411
-                                                  . '</span>' : '';
412
-        // name td
413
-        $html .= EEH_HTML::td($name_and_desc, '', 'item_l sub-item');
414
-        $qty = $parent_line_item instanceof EE_Line_Item ? $parent_line_item->quantity() : 1;
415
-        // discount/surcharge td
416
-        if ($line_item->is_percent()) {
417
-            $html .= EEH_HTML::td(
418
-                EEH_Template::format_currency(
419
-                    $line_item->total() / $qty,
420
-                    false,
421
-                    false
422
-                ),
423
-                '',
424
-                'item_c jst-rght'
425
-            );
426
-        } else {
427
-            $html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'item_c jst-rght');
428
-        }
429
-        // no quantity td
430
-        $html .= EEH_HTML::td();
431
-        // no total td
432
-        $html .= EEH_HTML::td();
433
-        // end of row
434
-        $html .= EEH_HTML::trx();
435
-        $html = apply_filters(
436
-            'FHEE__EE_SPCO_Line_Item_Display_Strategy___sub_item_row__html',
437
-            $html,
438
-            $line_item,
439
-            $options,
440
-            $parent_line_item
441
-        );
442
-        return $html;
443
-    }
444
-
445
-
446
-
447
-    /**
448
-     * _tax_row
449
-     *
450
-     * @param EE_Line_Item $line_item
451
-     * @param array        $options
452
-     * @return mixed
453
-     * @throws EE_Error
454
-     */
455
-    private function _tax_row(EE_Line_Item $line_item, $options = array())
456
-    {
457
-        // start of row
458
-        $html = EEH_HTML::tr('', 'item sub-item tax-total');
459
-        // name && desc
460
-        $name_and_desc = $line_item->name();
461
-        $name_and_desc .= '<span class="smaller-text lt-grey-text" style="margin:0 0 0 2em;">'
462
-                          . esc_html__(' * taxable items', 'event_espresso') . '</span>';
463
-        $name_and_desc .= $options['show_desc'] ? '<br/>' . $line_item->desc() : '';
464
-        // name td
465
-        $html .= EEH_HTML::td( /*__FUNCTION__ .*/
466
-            $name_and_desc,
467
-            '',
468
-            'item_l sub-item'
469
-        );
470
-        // percent td
471
-        $html .= EEH_HTML::td($line_item->percent() . '%', '', ' jst-rght', '');
472
-        // empty td (price)
473
-        $html .= EEH_HTML::td(EEH_HTML::nbsp());
474
-        // total td
475
-        $html .= EEH_HTML::td(
476
-            EEH_Template::format_currency(
477
-                $line_item->total(),
478
-                false,
479
-                false
480
-            ),
481
-            '',
482
-            'item_r jst-rght'
483
-        );
484
-        // end of row
485
-        $html .= EEH_HTML::trx();
486
-        return $html;
487
-    }
488
-
489
-
490
-
491
-    /**
492
-     * _total_row
493
-     *
494
-     * @param EE_Line_Item $line_item
495
-     * @param string       $text
496
-     * @return mixed
497
-     * @throws EE_Error
498
-     */
499
-    private function _total_tax_row(EE_Line_Item $line_item, $text = '')
500
-    {
501
-        $html = '';
502
-        if ($line_item->total()) {
503
-            // start of row
504
-            $html = EEH_HTML::tr('', '', 'total_tr odd');
505
-            // total td
506
-            $html .= EEH_HTML::td(
507
-                $text,
508
-                '',
509
-                'total_currency total jst-rght',
510
-                '',
511
-                ' colspan="2"'
512
-            );
513
-            // empty td (price)
514
-            $html .= EEH_HTML::td(EEH_HTML::nbsp());
515
-            // total td
516
-            $html .= EEH_HTML::td(
517
-                EEH_Template::format_currency($line_item->total(), false, false),
518
-                '',
519
-                'total jst-rght'
520
-            );
521
-            // end of row
522
-            $html .= EEH_HTML::trx();
523
-        }
524
-        return $html;
525
-    }
526
-
527
-
528
-
529
-    /**
530
-     * _total_row
531
-     *
532
-     * @param EE_Line_Item $line_item
533
-     * @param string       $text
534
-     * @param array        $options
535
-     * @return mixed
536
-     * @throws EE_Error
537
-     */
538
-    private function _sub_total_row(EE_Line_Item $line_item, $text = '', $options = array())
539
-    {
540
-        $html = '';
541
-        if ($line_item->total()) {
542
-            // start of row
543
-            $html = EEH_HTML::tr('', '', 'total_tr odd');
544
-            // total td
545
-            $html .= EEH_HTML::td(
546
-                $text,
547
-                '',
548
-                'total_currency total jst-rght',
549
-                '',
550
-                ' colspan="3"'
551
-            );
552
-            // total td
553
-            $html .= EEH_HTML::td(
554
-                EEH_Template::format_currency($options['sub_total'], false, false),
555
-                '',
556
-                'total jst-rght'
557
-            );
558
-            // end of row
559
-            $html .= EEH_HTML::trx();
560
-        }
561
-        return $html;
562
-    }
563
-
564
-
565
-
566
-    /**
567
-     * _total_row
568
-     *
569
-     * @param EE_Line_Item $line_item
570
-     * @param string       $text
571
-     * @return mixed
572
-     * @throws EE_Error
573
-     */
574
-    private function _total_row(EE_Line_Item $line_item, $text = '')
575
-    {
576
-        // start of row
577
-        $html = EEH_HTML::tr('', '', 'spco-grand-total total_tr odd');
578
-        // total td
579
-        $html .= EEH_HTML::td($text, '', 'total_currency total jst-rght', '', ' colspan="3"');
580
-        // total td
581
-        $html .= EEH_HTML::td(
582
-            EEH_Template::format_currency($line_item->total(), false, false),
583
-            '',
584
-            'total jst-rght'
585
-        );
586
-        // end of row
587
-        $html .= EEH_HTML::trx();
588
-        return $html;
589
-    }
590
-
591
-
592
-
593
-    /**
594
-     * _payments_and_amount_owing_rows
595
-     *
596
-     * @param EE_Line_Item $line_item
597
-     * @param array        $options
598
-     * @return mixed
599
-     * @throws EE_Error
600
-     */
601
-    private function _payments_and_amount_owing_rows(EE_Line_Item $line_item, $options = array())
602
-    {
603
-        $html = '';
604
-        $owing = $line_item->total();
605
-        $transaction = EEM_Transaction::instance()->get_one_by_ID($line_item->TXN_ID());
606
-        if ($transaction instanceof EE_Transaction) {
607
-            $registration_payments = array();
608
-            $registrations = ! empty($options['registrations'])
609
-                ? $options['registrations']
610
-                : $transaction->registrations();
611
-            foreach ($registrations as $registration) {
612
-                if ($registration instanceof EE_Registration && $registration->owes_monies_and_can_pay()) {
613
-                    $registration_payments += $registration->registration_payments();
614
-                }
615
-            }
616
-            if (! empty($registration_payments)) {
617
-                foreach ($registration_payments as $registration_payment) {
618
-                    if ($registration_payment instanceof EE_Registration_Payment) {
619
-                        $owing -= $registration_payment->amount();
620
-                        $payment = $registration_payment->payment();
621
-                        $payment_desc = '';
622
-                        if ($payment instanceof EE_Payment) {
623
-                            $payment_desc = sprintf(
624
-                                esc_html__('Payment%1$s Received: %2$s', 'event_espresso'),
625
-                                $payment->txn_id_chq_nmbr() !== ''
626
-                                    ? ' <span class="small-text">(#' . $payment->txn_id_chq_nmbr() . ')</span> '
627
-                                    : '',
628
-                                $payment->timestamp()
629
-                            );
630
-                        }
631
-                        // start of row
632
-                        $html .= EEH_HTML::tr('', '', 'total_tr odd');
633
-                        // payment desc
634
-                        $html .= EEH_HTML::td($payment_desc, '', '', '', ' colspan="3"');
635
-                        // total td
636
-                        $html .= EEH_HTML::td(
637
-                            EEH_Template::format_currency(
638
-                                $registration_payment->amount(),
639
-                                false,
640
-                                false
641
-                            ),
642
-                            '',
643
-                            'total jst-rght'
644
-                        );
645
-                        // end of row
646
-                        $html .= EEH_HTML::trx();
647
-                    }
648
-                }
649
-                if ($line_item->total()) {
650
-                    // start of row
651
-                    $html .= EEH_HTML::tr('', '', 'total_tr odd');
652
-                    // total td
653
-                    $html .= EEH_HTML::td(
654
-                        esc_html__('Amount Owing', 'event_espresso'),
655
-                        '',
656
-                        'total_currency total jst-rght',
657
-                        '',
658
-                        ' colspan="3"'
659
-                    );
660
-                    // total td
661
-                    $html .= EEH_HTML::td(
662
-                        EEH_Template::format_currency($owing, false, false),
663
-                        '',
664
-                        'total jst-rght'
665
-                    );
666
-                    // end of row
667
-                    $html .= EEH_HTML::trx();
668
-                }
669
-            }
670
-        }
671
-        $this->_grand_total = $owing;
672
-        return $html;
673
-    }
15
+	/**
16
+	 * array of events
17
+	 *
18
+	 * @type EE_Line_Item[] $_events
19
+	 */
20
+	private $_events = array();
21
+
22
+	/**
23
+	 * whether to display the taxes row or not
24
+	 *
25
+	 * @type bool $_show_taxes
26
+	 */
27
+	private $_show_taxes = false;
28
+
29
+	/**
30
+	 * html for any tax rows
31
+	 *
32
+	 * @type string $_show_taxes
33
+	 */
34
+	private $_taxes_html = '';
35
+
36
+	/**
37
+	 * total amount including tax we can bill for at this time
38
+	 *
39
+	 * @type float $_grand_total
40
+	 */
41
+	private $_grand_total = 0.00;
42
+
43
+	/**
44
+	 * total number of items being billed for
45
+	 *
46
+	 * @type int $_total_items
47
+	 */
48
+	private $_total_items = 0;
49
+
50
+
51
+
52
+	/**
53
+	 * @return float
54
+	 */
55
+	public function grand_total()
56
+	{
57
+		return $this->_grand_total;
58
+	}
59
+
60
+
61
+
62
+	/**
63
+	 * @return int
64
+	 */
65
+	public function total_items()
66
+	{
67
+		return $this->_total_items;
68
+	}
69
+
70
+
71
+
72
+	/**
73
+	 * @param EE_Line_Item $line_item
74
+	 * @param array        $options
75
+	 * @param EE_Line_Item $parent_line_item
76
+	 * @return mixed
77
+	 * @throws EE_Error
78
+	 */
79
+	public function display_line_item(
80
+		EE_Line_Item $line_item,
81
+		$options = array(),
82
+		EE_Line_Item $parent_line_item = null
83
+	) {
84
+		$html = '';
85
+		// set some default options and merge with incoming
86
+		$default_options = array(
87
+			'show_desc' => true,  //    true        false
88
+			'odd'       => false,
89
+		);
90
+		$options = array_merge($default_options, (array) $options);
91
+		switch ($line_item->type()) {
92
+			case EEM_Line_Item::type_line_item:
93
+				$this->_show_taxes = $line_item->is_taxable() ? true : $this->_show_taxes;
94
+				if ($line_item->OBJ_type() === 'Ticket') {
95
+					// item row
96
+					$html .= $this->_ticket_row($line_item, $options);
97
+				} else {
98
+					// item row
99
+					$html .= $this->_item_row($line_item, $options);
100
+				}
101
+				if (
102
+					apply_filters(
103
+						'FHEE__EE_SPCO_Line_Item_Display_Strategy__display_line_item__display_sub_line_items',
104
+						true
105
+					)
106
+				) {
107
+					// got any kids?
108
+					foreach ($line_item->children() as $child_line_item) {
109
+						$html .= $this->display_line_item($child_line_item, $options, $line_item);
110
+					}
111
+				}
112
+				break;
113
+			case EEM_Line_Item::type_sub_line_item:
114
+				$html .= $this->_sub_item_row($line_item, $options, $parent_line_item);
115
+				break;
116
+			case EEM_Line_Item::type_sub_total:
117
+				static $sub_total = 0;
118
+				$event_sub_total = 0;
119
+				$text = esc_html__('Sub-Total', 'event_espresso');
120
+				if ($line_item->OBJ_type() === 'Event') {
121
+					$options['event_id'] = $event_id = $line_item->OBJ_ID();
122
+					if (! isset($this->_events[ $options['event_id'] ])) {
123
+						$event = EEM_Event::instance()->get_one_by_ID($options['event_id']);
124
+						// if event has default reg status of Not Approved, then don't display info on it
125
+						if (
126
+							$event instanceof EE_Event
127
+							&& $event->default_registration_status() === EEM_Registration::status_id_not_approved
128
+						) {
129
+							$display_event = false;
130
+							// unless there are registrations for it that are returning to pay
131
+							if (isset($options['registrations']) && is_array($options['registrations'])) {
132
+								foreach ($options['registrations'] as $registration) {
133
+									if (! $registration instanceof EE_Registration) {
134
+										continue;
135
+									}
136
+									$display_event = $registration->event_ID() === $options['event_id']
137
+													 && $registration->status_ID() !== EEM_Registration::status_id_not_approved
138
+										? true
139
+										: $display_event;
140
+								}
141
+							}
142
+							if (! $display_event) {
143
+								return '';
144
+							}
145
+						}
146
+						$this->_events[ $options['event_id'] ] = 0;
147
+						$html .= $this->_event_row($line_item);
148
+						$text = esc_html__('Event Sub-Total', 'event_espresso');
149
+					}
150
+				}
151
+				$child_line_items = $line_item->children();
152
+				// loop thru children
153
+				foreach ($child_line_items as $child_line_item) {
154
+					// recursively feed children back into this method
155
+					$html .= $this->display_line_item($child_line_item, $options, $line_item);
156
+				}
157
+				$event_sub_total += isset($options['event_id']) ? $this->_events[ $options['event_id'] ] : 0;
158
+				$sub_total += $event_sub_total;
159
+				if (
160
+					(
161
+						// event subtotals
162
+						$line_item->code() !== 'pre-tax-subtotal' && count($child_line_items) > 1
163
+					)
164
+					|| (
165
+						// pre-tax subtotals
166
+						$line_item->code() === 'pre-tax-subtotal' && count($this->_events) > 1
167
+					)
168
+				) {
169
+					$options['sub_total'] = $line_item->OBJ_type() === 'Event' ? $event_sub_total : $sub_total;
170
+					$html .= $this->_sub_total_row($line_item, $text, $options);
171
+				}
172
+				break;
173
+			case EEM_Line_Item::type_tax:
174
+				if ($this->_show_taxes) {
175
+					$this->_taxes_html .= $this->_tax_row($line_item, $options);
176
+				}
177
+				break;
178
+			case EEM_Line_Item::type_tax_sub_total:
179
+				if ($this->_show_taxes) {
180
+					$child_line_items = $line_item->children();
181
+					// loop thru children
182
+					foreach ($child_line_items as $child_line_item) {
183
+						// recursively feed children back into this method
184
+						$html .= $this->display_line_item($child_line_item, $options, $line_item);
185
+					}
186
+					if (count($child_line_items) > 1) {
187
+						$this->_taxes_html .= $this->_total_tax_row($line_item, esc_html__('Tax Total', 'event_espresso'));
188
+					}
189
+				}
190
+				break;
191
+			case EEM_Line_Item::type_total:
192
+				// get all child line items
193
+				$children = $line_item->children();
194
+				// loop thru all non-tax child line items
195
+				foreach ($children as $child_line_item) {
196
+					if ($child_line_item->type() !== EEM_Line_Item::type_tax_sub_total) {
197
+						// recursively feed children back into this method
198
+						$html .= $this->display_line_item($child_line_item, $options, $line_item);
199
+					}
200
+				}
201
+				// now loop thru  tax child line items
202
+				foreach ($children as $child_line_item) {
203
+					if ($child_line_item->type() === EEM_Line_Item::type_tax_sub_total) {
204
+						// recursively feed children back into this method
205
+						$html .= $this->display_line_item($child_line_item, $options, $line_item);
206
+					}
207
+				}
208
+				$html .= $this->_taxes_html;
209
+				$html .= $this->_total_row($line_item, esc_html__('Total', 'event_espresso'));
210
+				$html .= $this->_payments_and_amount_owing_rows($line_item, $options);
211
+				break;
212
+		}
213
+		return $html;
214
+	}
215
+
216
+
217
+
218
+	/**
219
+	 * _event_row - basically a Heading row displayed once above each event's ticket rows
220
+	 *
221
+	 * @param EE_Line_Item $line_item
222
+	 * @return mixed
223
+	 */
224
+	private function _event_row(EE_Line_Item $line_item)
225
+	{
226
+		// start of row
227
+		$html = EEH_HTML::tr('', 'event-cart-total-row', 'total_tr odd');
228
+		// event name td
229
+		$html .= EEH_HTML::td(
230
+			EEH_HTML::strong($line_item->name()),
231
+			'',
232
+			'event-header',
233
+			'',
234
+			' colspan="4"'
235
+		);
236
+		// end of row
237
+		$html .= EEH_HTML::trx();
238
+		return $html;
239
+	}
240
+
241
+
242
+
243
+	/**
244
+	 * _ticket_row
245
+	 *
246
+	 * @param EE_Line_Item $line_item
247
+	 * @param array        $options
248
+	 * @return mixed
249
+	 * @throws EE_Error
250
+	 */
251
+	private function _ticket_row(EE_Line_Item $line_item, $options = array())
252
+	{
253
+		// start of row
254
+		$row_class = $options['odd'] ? 'item odd' : 'item';
255
+		$html = EEH_HTML::tr('', '', $row_class);
256
+		// name && desc
257
+		$name_and_desc = apply_filters(
258
+			'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__name',
259
+			$line_item->name(),
260
+			$line_item
261
+		);
262
+		$name_and_desc .= apply_filters(
263
+			'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__desc',
264
+			(
265
+				$options['show_desc']
266
+					? '<span class="line-item-desc-spn smaller-text">: ' . $line_item->desc() . '</span>'
267
+					: ''
268
+			),
269
+			$line_item,
270
+			$options
271
+		);
272
+		$name_and_desc .= $line_item->is_taxable() ? ' * ' : '';
273
+		$name_and_desc = apply_filters(
274
+			'FHEE__EE_SPCO_Line_Item_Display_Strategy___ticket_row__name_and_desc',
275
+			$name_and_desc,
276
+			$line_item,
277
+			$options
278
+		);
279
+
280
+		// name td
281
+		$html .= EEH_HTML::td( /*__FUNCTION__ .*/
282
+			$name_and_desc,
283
+			'',
284
+			'item_l'
285
+		);
286
+		// price td
287
+		$price = apply_filters(
288
+			'FHEE__EE_SPCO_Line_Item_Display_Strategy___ticket_row__price',
289
+			$line_item->unit_price_no_code(),
290
+			$line_item
291
+		);
292
+		$html .= EEH_HTML::td($price, '', 'item_c jst-rght');
293
+		// quantity td
294
+		$html .= EEH_HTML::td($line_item->quantity(), '', 'item_l jst-rght');
295
+		$this->_total_items += $line_item->quantity();
296
+		// determine total for line item
297
+		$total = apply_filters(
298
+			'FHEE__EE_SPCO_Line_Item_Display_Strategy___ticket_row__total',
299
+			$line_item->total(),
300
+			$line_item
301
+		);
302
+		$this->_events[ $options['event_id'] ] += $total;
303
+		// total td
304
+		$html .= EEH_HTML::td(
305
+			EEH_Template::format_currency($total, false, false),
306
+			'',
307
+			'item_r jst-rght'
308
+		);
309
+		// end of row
310
+		$html .= EEH_HTML::trx();
311
+		return $html;
312
+	}
313
+
314
+
315
+
316
+	/**
317
+	 * _item_row
318
+	 *
319
+	 * @param EE_Line_Item $line_item
320
+	 * @param array        $options
321
+	 * @return mixed
322
+	 * @throws EE_Error
323
+	 */
324
+	private function _item_row(EE_Line_Item $line_item, $options = array())
325
+	{
326
+		// start of row
327
+		$row_class = $options['odd'] ? 'item odd' : 'item';
328
+		$html = EEH_HTML::tr('', '', $row_class);
329
+		$obj_name = $line_item->OBJ_type() ? $line_item->OBJ_type_i18n() . ': ' : '';
330
+		// name && desc
331
+		$name_and_desc = apply_filters(
332
+			'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__name',
333
+			$obj_name . $line_item->name(),
334
+			$line_item
335
+		);
336
+		$name_and_desc .= apply_filters(
337
+			'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__desc',
338
+			(
339
+				$options['show_desc']
340
+				? '<span class="line-item-desc-spn smaller-text">: ' . $line_item->desc() . '</span>'
341
+				: ''
342
+			),
343
+			$line_item,
344
+			$options
345
+		);
346
+		$name_and_desc .= $line_item->is_taxable() ? ' * ' : '';
347
+		$name_and_desc = apply_filters(
348
+			'FHEE__EE_SPCO_Line_Item_Display_Strategy___item_row__name_and_desc',
349
+			$name_and_desc,
350
+			$line_item,
351
+			$options
352
+		);
353
+
354
+		// name td
355
+		$html .= EEH_HTML::td($name_and_desc, '', 'item_l');
356
+		// price td
357
+		if ($line_item->is_percent()) {
358
+			$html .= EEH_HTML::td($line_item->percent() . '%', '', 'item_c jst-rght');
359
+		} else {
360
+			$html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'item_c jst-rght');
361
+		}
362
+		// quantity td
363
+		$html .= EEH_HTML::td($line_item->quantity(), '', 'item_l jst-rght');
364
+		// $total = $line_item->total() * $line_item->quantity();
365
+		$total = $line_item->total();
366
+		if (isset($options['event_id'], $this->_events[ $options['event_id'] ])) {
367
+			$this->_events[ $options['event_id'] ] += $total;
368
+		}
369
+		// total td
370
+		$html .= EEH_HTML::td(
371
+			EEH_Template::format_currency($total, false, false),
372
+			'',
373
+			'item_r jst-rght'
374
+		);
375
+		// end of row
376
+		$html .= EEH_HTML::trx();
377
+		return $html;
378
+	}
379
+
380
+
381
+
382
+	/**
383
+	 * _sub_item_row
384
+	 *
385
+	 * @param EE_Line_Item $line_item
386
+	 * @param array        $options
387
+	 * @param EE_Line_Item $parent_line_item
388
+	 * @return mixed
389
+	 * @throws EE_Error
390
+	 */
391
+	private function _sub_item_row(EE_Line_Item $line_item, $options = array(), EE_Line_Item $parent_line_item = null)
392
+	{
393
+		if (
394
+			$parent_line_item instanceof  EE_Line_Item
395
+			&& $line_item->children() === array()
396
+			&& $line_item->name() === $parent_line_item->name()
397
+			&& apply_filters(
398
+				'FHEE__EE_SPCO_Line_Item_Display_Strategy___sub_item_row__hide_main_sub_line_item',
399
+				true
400
+			)
401
+		) {
402
+			return '';
403
+		}
404
+		// start of row
405
+		$html = EEH_HTML::tr('', '', 'item sub-item-row');
406
+		// name && desc
407
+		$name_and_desc = EEH_HTML::span('', '', 'sub-item-row-bullet dashicons dashicons-arrow-right')
408
+						 . $line_item->name();
409
+		$name_and_desc .= $options['show_desc'] ? '<span class="line-sub-item-desc-spn smaller-text">: '
410
+												  . $line_item->desc()
411
+												  . '</span>' : '';
412
+		// name td
413
+		$html .= EEH_HTML::td($name_and_desc, '', 'item_l sub-item');
414
+		$qty = $parent_line_item instanceof EE_Line_Item ? $parent_line_item->quantity() : 1;
415
+		// discount/surcharge td
416
+		if ($line_item->is_percent()) {
417
+			$html .= EEH_HTML::td(
418
+				EEH_Template::format_currency(
419
+					$line_item->total() / $qty,
420
+					false,
421
+					false
422
+				),
423
+				'',
424
+				'item_c jst-rght'
425
+			);
426
+		} else {
427
+			$html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'item_c jst-rght');
428
+		}
429
+		// no quantity td
430
+		$html .= EEH_HTML::td();
431
+		// no total td
432
+		$html .= EEH_HTML::td();
433
+		// end of row
434
+		$html .= EEH_HTML::trx();
435
+		$html = apply_filters(
436
+			'FHEE__EE_SPCO_Line_Item_Display_Strategy___sub_item_row__html',
437
+			$html,
438
+			$line_item,
439
+			$options,
440
+			$parent_line_item
441
+		);
442
+		return $html;
443
+	}
444
+
445
+
446
+
447
+	/**
448
+	 * _tax_row
449
+	 *
450
+	 * @param EE_Line_Item $line_item
451
+	 * @param array        $options
452
+	 * @return mixed
453
+	 * @throws EE_Error
454
+	 */
455
+	private function _tax_row(EE_Line_Item $line_item, $options = array())
456
+	{
457
+		// start of row
458
+		$html = EEH_HTML::tr('', 'item sub-item tax-total');
459
+		// name && desc
460
+		$name_and_desc = $line_item->name();
461
+		$name_and_desc .= '<span class="smaller-text lt-grey-text" style="margin:0 0 0 2em;">'
462
+						  . esc_html__(' * taxable items', 'event_espresso') . '</span>';
463
+		$name_and_desc .= $options['show_desc'] ? '<br/>' . $line_item->desc() : '';
464
+		// name td
465
+		$html .= EEH_HTML::td( /*__FUNCTION__ .*/
466
+			$name_and_desc,
467
+			'',
468
+			'item_l sub-item'
469
+		);
470
+		// percent td
471
+		$html .= EEH_HTML::td($line_item->percent() . '%', '', ' jst-rght', '');
472
+		// empty td (price)
473
+		$html .= EEH_HTML::td(EEH_HTML::nbsp());
474
+		// total td
475
+		$html .= EEH_HTML::td(
476
+			EEH_Template::format_currency(
477
+				$line_item->total(),
478
+				false,
479
+				false
480
+			),
481
+			'',
482
+			'item_r jst-rght'
483
+		);
484
+		// end of row
485
+		$html .= EEH_HTML::trx();
486
+		return $html;
487
+	}
488
+
489
+
490
+
491
+	/**
492
+	 * _total_row
493
+	 *
494
+	 * @param EE_Line_Item $line_item
495
+	 * @param string       $text
496
+	 * @return mixed
497
+	 * @throws EE_Error
498
+	 */
499
+	private function _total_tax_row(EE_Line_Item $line_item, $text = '')
500
+	{
501
+		$html = '';
502
+		if ($line_item->total()) {
503
+			// start of row
504
+			$html = EEH_HTML::tr('', '', 'total_tr odd');
505
+			// total td
506
+			$html .= EEH_HTML::td(
507
+				$text,
508
+				'',
509
+				'total_currency total jst-rght',
510
+				'',
511
+				' colspan="2"'
512
+			);
513
+			// empty td (price)
514
+			$html .= EEH_HTML::td(EEH_HTML::nbsp());
515
+			// total td
516
+			$html .= EEH_HTML::td(
517
+				EEH_Template::format_currency($line_item->total(), false, false),
518
+				'',
519
+				'total jst-rght'
520
+			);
521
+			// end of row
522
+			$html .= EEH_HTML::trx();
523
+		}
524
+		return $html;
525
+	}
526
+
527
+
528
+
529
+	/**
530
+	 * _total_row
531
+	 *
532
+	 * @param EE_Line_Item $line_item
533
+	 * @param string       $text
534
+	 * @param array        $options
535
+	 * @return mixed
536
+	 * @throws EE_Error
537
+	 */
538
+	private function _sub_total_row(EE_Line_Item $line_item, $text = '', $options = array())
539
+	{
540
+		$html = '';
541
+		if ($line_item->total()) {
542
+			// start of row
543
+			$html = EEH_HTML::tr('', '', 'total_tr odd');
544
+			// total td
545
+			$html .= EEH_HTML::td(
546
+				$text,
547
+				'',
548
+				'total_currency total jst-rght',
549
+				'',
550
+				' colspan="3"'
551
+			);
552
+			// total td
553
+			$html .= EEH_HTML::td(
554
+				EEH_Template::format_currency($options['sub_total'], false, false),
555
+				'',
556
+				'total jst-rght'
557
+			);
558
+			// end of row
559
+			$html .= EEH_HTML::trx();
560
+		}
561
+		return $html;
562
+	}
563
+
564
+
565
+
566
+	/**
567
+	 * _total_row
568
+	 *
569
+	 * @param EE_Line_Item $line_item
570
+	 * @param string       $text
571
+	 * @return mixed
572
+	 * @throws EE_Error
573
+	 */
574
+	private function _total_row(EE_Line_Item $line_item, $text = '')
575
+	{
576
+		// start of row
577
+		$html = EEH_HTML::tr('', '', 'spco-grand-total total_tr odd');
578
+		// total td
579
+		$html .= EEH_HTML::td($text, '', 'total_currency total jst-rght', '', ' colspan="3"');
580
+		// total td
581
+		$html .= EEH_HTML::td(
582
+			EEH_Template::format_currency($line_item->total(), false, false),
583
+			'',
584
+			'total jst-rght'
585
+		);
586
+		// end of row
587
+		$html .= EEH_HTML::trx();
588
+		return $html;
589
+	}
590
+
591
+
592
+
593
+	/**
594
+	 * _payments_and_amount_owing_rows
595
+	 *
596
+	 * @param EE_Line_Item $line_item
597
+	 * @param array        $options
598
+	 * @return mixed
599
+	 * @throws EE_Error
600
+	 */
601
+	private function _payments_and_amount_owing_rows(EE_Line_Item $line_item, $options = array())
602
+	{
603
+		$html = '';
604
+		$owing = $line_item->total();
605
+		$transaction = EEM_Transaction::instance()->get_one_by_ID($line_item->TXN_ID());
606
+		if ($transaction instanceof EE_Transaction) {
607
+			$registration_payments = array();
608
+			$registrations = ! empty($options['registrations'])
609
+				? $options['registrations']
610
+				: $transaction->registrations();
611
+			foreach ($registrations as $registration) {
612
+				if ($registration instanceof EE_Registration && $registration->owes_monies_and_can_pay()) {
613
+					$registration_payments += $registration->registration_payments();
614
+				}
615
+			}
616
+			if (! empty($registration_payments)) {
617
+				foreach ($registration_payments as $registration_payment) {
618
+					if ($registration_payment instanceof EE_Registration_Payment) {
619
+						$owing -= $registration_payment->amount();
620
+						$payment = $registration_payment->payment();
621
+						$payment_desc = '';
622
+						if ($payment instanceof EE_Payment) {
623
+							$payment_desc = sprintf(
624
+								esc_html__('Payment%1$s Received: %2$s', 'event_espresso'),
625
+								$payment->txn_id_chq_nmbr() !== ''
626
+									? ' <span class="small-text">(#' . $payment->txn_id_chq_nmbr() . ')</span> '
627
+									: '',
628
+								$payment->timestamp()
629
+							);
630
+						}
631
+						// start of row
632
+						$html .= EEH_HTML::tr('', '', 'total_tr odd');
633
+						// payment desc
634
+						$html .= EEH_HTML::td($payment_desc, '', '', '', ' colspan="3"');
635
+						// total td
636
+						$html .= EEH_HTML::td(
637
+							EEH_Template::format_currency(
638
+								$registration_payment->amount(),
639
+								false,
640
+								false
641
+							),
642
+							'',
643
+							'total jst-rght'
644
+						);
645
+						// end of row
646
+						$html .= EEH_HTML::trx();
647
+					}
648
+				}
649
+				if ($line_item->total()) {
650
+					// start of row
651
+					$html .= EEH_HTML::tr('', '', 'total_tr odd');
652
+					// total td
653
+					$html .= EEH_HTML::td(
654
+						esc_html__('Amount Owing', 'event_espresso'),
655
+						'',
656
+						'total_currency total jst-rght',
657
+						'',
658
+						' colspan="3"'
659
+					);
660
+					// total td
661
+					$html .= EEH_HTML::td(
662
+						EEH_Template::format_currency($owing, false, false),
663
+						'',
664
+						'total jst-rght'
665
+					);
666
+					// end of row
667
+					$html .= EEH_HTML::trx();
668
+				}
669
+			}
670
+		}
671
+		$this->_grand_total = $owing;
672
+		return $html;
673
+	}
674 674
 }
Please login to merge, or discard this patch.
Spacing   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -84,7 +84,7 @@  discard block
 block discarded – undo
84 84
         $html = '';
85 85
         // set some default options and merge with incoming
86 86
         $default_options = array(
87
-            'show_desc' => true,  //    true        false
87
+            'show_desc' => true, //    true        false
88 88
             'odd'       => false,
89 89
         );
90 90
         $options = array_merge($default_options, (array) $options);
@@ -119,7 +119,7 @@  discard block
 block discarded – undo
119 119
                 $text = esc_html__('Sub-Total', 'event_espresso');
120 120
                 if ($line_item->OBJ_type() === 'Event') {
121 121
                     $options['event_id'] = $event_id = $line_item->OBJ_ID();
122
-                    if (! isset($this->_events[ $options['event_id'] ])) {
122
+                    if ( ! isset($this->_events[$options['event_id']])) {
123 123
                         $event = EEM_Event::instance()->get_one_by_ID($options['event_id']);
124 124
                         // if event has default reg status of Not Approved, then don't display info on it
125 125
                         if (
@@ -130,7 +130,7 @@  discard block
 block discarded – undo
130 130
                             // unless there are registrations for it that are returning to pay
131 131
                             if (isset($options['registrations']) && is_array($options['registrations'])) {
132 132
                                 foreach ($options['registrations'] as $registration) {
133
-                                    if (! $registration instanceof EE_Registration) {
133
+                                    if ( ! $registration instanceof EE_Registration) {
134 134
                                         continue;
135 135
                                     }
136 136
                                     $display_event = $registration->event_ID() === $options['event_id']
@@ -139,11 +139,11 @@  discard block
 block discarded – undo
139 139
                                         : $display_event;
140 140
                                 }
141 141
                             }
142
-                            if (! $display_event) {
142
+                            if ( ! $display_event) {
143 143
                                 return '';
144 144
                             }
145 145
                         }
146
-                        $this->_events[ $options['event_id'] ] = 0;
146
+                        $this->_events[$options['event_id']] = 0;
147 147
                         $html .= $this->_event_row($line_item);
148 148
                         $text = esc_html__('Event Sub-Total', 'event_espresso');
149 149
                     }
@@ -154,7 +154,7 @@  discard block
 block discarded – undo
154 154
                     // recursively feed children back into this method
155 155
                     $html .= $this->display_line_item($child_line_item, $options, $line_item);
156 156
                 }
157
-                $event_sub_total += isset($options['event_id']) ? $this->_events[ $options['event_id'] ] : 0;
157
+                $event_sub_total += isset($options['event_id']) ? $this->_events[$options['event_id']] : 0;
158 158
                 $sub_total += $event_sub_total;
159 159
                 if (
160 160
                     (
@@ -263,7 +263,7 @@  discard block
 block discarded – undo
263 263
             'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__desc',
264 264
             (
265 265
                 $options['show_desc']
266
-                    ? '<span class="line-item-desc-spn smaller-text">: ' . $line_item->desc() . '</span>'
266
+                    ? '<span class="line-item-desc-spn smaller-text">: '.$line_item->desc().'</span>'
267 267
                     : ''
268 268
             ),
269 269
             $line_item,
@@ -299,7 +299,7 @@  discard block
 block discarded – undo
299 299
             $line_item->total(),
300 300
             $line_item
301 301
         );
302
-        $this->_events[ $options['event_id'] ] += $total;
302
+        $this->_events[$options['event_id']] += $total;
303 303
         // total td
304 304
         $html .= EEH_HTML::td(
305 305
             EEH_Template::format_currency($total, false, false),
@@ -326,18 +326,18 @@  discard block
 block discarded – undo
326 326
         // start of row
327 327
         $row_class = $options['odd'] ? 'item odd' : 'item';
328 328
         $html = EEH_HTML::tr('', '', $row_class);
329
-        $obj_name = $line_item->OBJ_type() ? $line_item->OBJ_type_i18n() . ': ' : '';
329
+        $obj_name = $line_item->OBJ_type() ? $line_item->OBJ_type_i18n().': ' : '';
330 330
         // name && desc
331 331
         $name_and_desc = apply_filters(
332 332
             'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__name',
333
-            $obj_name . $line_item->name(),
333
+            $obj_name.$line_item->name(),
334 334
             $line_item
335 335
         );
336 336
         $name_and_desc .= apply_filters(
337 337
             'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__desc',
338 338
             (
339 339
                 $options['show_desc']
340
-                ? '<span class="line-item-desc-spn smaller-text">: ' . $line_item->desc() . '</span>'
340
+                ? '<span class="line-item-desc-spn smaller-text">: '.$line_item->desc().'</span>'
341 341
                 : ''
342 342
             ),
343 343
             $line_item,
@@ -355,7 +355,7 @@  discard block
 block discarded – undo
355 355
         $html .= EEH_HTML::td($name_and_desc, '', 'item_l');
356 356
         // price td
357 357
         if ($line_item->is_percent()) {
358
-            $html .= EEH_HTML::td($line_item->percent() . '%', '', 'item_c jst-rght');
358
+            $html .= EEH_HTML::td($line_item->percent().'%', '', 'item_c jst-rght');
359 359
         } else {
360 360
             $html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'item_c jst-rght');
361 361
         }
@@ -363,8 +363,8 @@  discard block
 block discarded – undo
363 363
         $html .= EEH_HTML::td($line_item->quantity(), '', 'item_l jst-rght');
364 364
         // $total = $line_item->total() * $line_item->quantity();
365 365
         $total = $line_item->total();
366
-        if (isset($options['event_id'], $this->_events[ $options['event_id'] ])) {
367
-            $this->_events[ $options['event_id'] ] += $total;
366
+        if (isset($options['event_id'], $this->_events[$options['event_id']])) {
367
+            $this->_events[$options['event_id']] += $total;
368 368
         }
369 369
         // total td
370 370
         $html .= EEH_HTML::td(
@@ -459,8 +459,8 @@  discard block
 block discarded – undo
459 459
         // name && desc
460 460
         $name_and_desc = $line_item->name();
461 461
         $name_and_desc .= '<span class="smaller-text lt-grey-text" style="margin:0 0 0 2em;">'
462
-                          . esc_html__(' * taxable items', 'event_espresso') . '</span>';
463
-        $name_and_desc .= $options['show_desc'] ? '<br/>' . $line_item->desc() : '';
462
+                          . esc_html__(' * taxable items', 'event_espresso').'</span>';
463
+        $name_and_desc .= $options['show_desc'] ? '<br/>'.$line_item->desc() : '';
464 464
         // name td
465 465
         $html .= EEH_HTML::td( /*__FUNCTION__ .*/
466 466
             $name_and_desc,
@@ -468,7 +468,7 @@  discard block
 block discarded – undo
468 468
             'item_l sub-item'
469 469
         );
470 470
         // percent td
471
-        $html .= EEH_HTML::td($line_item->percent() . '%', '', ' jst-rght', '');
471
+        $html .= EEH_HTML::td($line_item->percent().'%', '', ' jst-rght', '');
472 472
         // empty td (price)
473 473
         $html .= EEH_HTML::td(EEH_HTML::nbsp());
474 474
         // total td
@@ -613,7 +613,7 @@  discard block
 block discarded – undo
613 613
                     $registration_payments += $registration->registration_payments();
614 614
                 }
615 615
             }
616
-            if (! empty($registration_payments)) {
616
+            if ( ! empty($registration_payments)) {
617 617
                 foreach ($registration_payments as $registration_payment) {
618 618
                     if ($registration_payment instanceof EE_Registration_Payment) {
619 619
                         $owing -= $registration_payment->amount();
@@ -623,7 +623,7 @@  discard block
 block discarded – undo
623 623
                             $payment_desc = sprintf(
624 624
                                 esc_html__('Payment%1$s Received: %2$s', 'event_espresso'),
625 625
                                 $payment->txn_id_chq_nmbr() !== ''
626
-                                    ? ' <span class="small-text">(#' . $payment->txn_id_chq_nmbr() . ')</span> '
626
+                                    ? ' <span class="small-text">(#'.$payment->txn_id_chq_nmbr().')</span> '
627 627
                                     : '',
628 628
                                 $payment->timestamp()
629 629
                             );
Please login to merge, or discard this patch.
core/libraries/rest_api/Capabilities.php 2 patches
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -99,7 +99,7 @@  discard block
 block discarded – undo
99 99
     ) {
100 100
         $has_password = $model->hasPassword();
101 101
         if ($has_password) {
102
-            $entity[ $model->getPasswordField()->get_name() ] = ModelDataTranslator::prepareFieldValueForJson(
102
+            $entity[$model->getPasswordField()->get_name()] = ModelDataTranslator::prepareFieldValueForJson(
103 103
                 $model->getPasswordField(),
104 104
                 $model->getPasswordField()->get_default_value(),
105 105
                 $model_version_info->requestedVersion()
@@ -109,7 +109,7 @@  discard block
 block discarded – undo
109 109
             if (
110 110
                 $has_password
111 111
                 && $model->getPasswordField()->fieldIsProtected($field_name)
112
-                && $entity[ $field_name ]
112
+                && $entity[$field_name]
113 113
             ) {
114 114
                 $replacement_value = ModelDataTranslator::prepareFieldValueForJson(
115 115
                     $field_obj,
@@ -117,10 +117,10 @@  discard block
 block discarded – undo
117 117
                     $model_version_info->requestedVersion()
118 118
                 );
119 119
                 if ($model_version_info->fieldHasRenderedFormat($field_obj)) {
120
-                    $entity[ $field_name ]['rendered'] = $replacement_value;
120
+                    $entity[$field_name]['rendered'] = $replacement_value;
121 121
                 } elseif ($model_version_info->fieldHasPrettyFormat($field_obj)) {
122
-                    $entity[ $field_name ]['raw'] = $replacement_value;
123
-                    $entity[ $field_name ]['pretty'] = ModelDataTranslator::prepareFieldValueForJson(
122
+                    $entity[$field_name]['raw'] = $replacement_value;
123
+                    $entity[$field_name]['pretty'] = ModelDataTranslator::prepareFieldValueForJson(
124 124
                         $field_obj,
125 125
                         $field_obj->prepare_for_pretty_echoing($field_obj->get_default_value()),
126 126
                         $model_version_info->requestedVersion()
@@ -131,7 +131,7 @@  discard block
 block discarded – undo
131 131
                     // so just remove it (or rather, set its default)
132 132
                     // API clients will just need to look to fields with rendered formats to know if these have
133 133
                     // been redacted. Sorry.
134
-                    $entity[ $field_name ] = $replacement_value;
134
+                    $entity[$field_name] = $replacement_value;
135 135
                 }
136 136
             }
137 137
         }
@@ -160,11 +160,11 @@  discard block
 block discarded – undo
160 160
         foreach ($model->field_settings() as $field_name => $field_obj) {
161 161
             if (
162 162
                 $model_version_info->fieldHasRenderedFormat($field_obj)
163
-                && isset($entity[ $field_name ])
164
-                && is_array($entity[ $field_name ])
165
-                && isset($entity[ $field_name ]['raw'])
163
+                && isset($entity[$field_name])
164
+                && is_array($entity[$field_name])
165
+                && isset($entity[$field_name]['raw'])
166 166
             ) {
167
-                unset($entity[ $field_name ]['raw']);
167
+                unset($entity[$field_name]['raw']);
168 168
             }
169 169
         }
170 170
         // theoretically we may want to filter out specific fields for specific models
@@ -190,7 +190,7 @@  discard block
 block discarded – undo
190 190
      */
191 191
     public static function verifyAtLeastPartialAccessTo($model, $model_action_context, $action_name = 'list')
192 192
     {
193
-        if (! Capabilities::currentUserHasPartialAccessTo($model, $model_action_context)) {
193
+        if ( ! Capabilities::currentUserHasPartialAccessTo($model, $model_action_context)) {
194 194
             $model_name_plural = EEH_Inflector::pluralize_and_lower($model->get_this_model_name());
195 195
             throw new RestException(
196 196
                 sprintf('rest_cannot_%s_%s', strtolower($action_name), $model_name_plural),
Please login to merge, or discard this patch.
Indentation   +177 added lines, -177 removed lines patch added patch discarded remove patch
@@ -18,190 +18,190 @@
 block discarded – undo
18 18
 class Capabilities
19 19
 {
20 20
 
21
-    /**
22
-     * The current user can see at least SOME of these entities.
23
-     *
24
-     * @param EEM_Base $model
25
-     * @param string   $model_context one of the return values from EEM_Base::valid_cap_contexts()
26
-     * @return boolean
27
-     */
28
-    public static function currentUserHasPartialAccessTo($model, $model_context = EEM_Base::caps_read)
29
-    {
30
-        if (
31
-            apply_filters(
32
-                'FHEE__Capabilities__current_user_has_partial_access_to__override_begin',
33
-                false,
34
-                $model,
35
-                $model
36
-            )
37
-        ) {
38
-            return true;
39
-        }
40
-        foreach ($model->caps_missing($model_context) as $capability_name => $restriction_obj) {
41
-            if ($restriction_obj instanceof \EE_Return_None_Where_Conditions) {
42
-                return false;
43
-            }
44
-        }
45
-        if (
46
-            apply_filters(
47
-                'FHEE__Capabilities__current_user_has_partial_access_to__override_end',
48
-                false,
49
-                $model,
50
-                $model
51
-            )
52
-        ) {
53
-            return false;
54
-        }
55
-        return true;
56
-    }
21
+	/**
22
+	 * The current user can see at least SOME of these entities.
23
+	 *
24
+	 * @param EEM_Base $model
25
+	 * @param string   $model_context one of the return values from EEM_Base::valid_cap_contexts()
26
+	 * @return boolean
27
+	 */
28
+	public static function currentUserHasPartialAccessTo($model, $model_context = EEM_Base::caps_read)
29
+	{
30
+		if (
31
+			apply_filters(
32
+				'FHEE__Capabilities__current_user_has_partial_access_to__override_begin',
33
+				false,
34
+				$model,
35
+				$model
36
+			)
37
+		) {
38
+			return true;
39
+		}
40
+		foreach ($model->caps_missing($model_context) as $capability_name => $restriction_obj) {
41
+			if ($restriction_obj instanceof \EE_Return_None_Where_Conditions) {
42
+				return false;
43
+			}
44
+		}
45
+		if (
46
+			apply_filters(
47
+				'FHEE__Capabilities__current_user_has_partial_access_to__override_end',
48
+				false,
49
+				$model,
50
+				$model
51
+			)
52
+		) {
53
+			return false;
54
+		}
55
+		return true;
56
+	}
57 57
 
58 58
 
59
-    /**
60
-     * Gets an array of all the capabilities the current user is missing that affected
61
-     * the query
62
-     *
63
-     * @param EEM_Base $model
64
-     * @param string   $request_type one of the constants on WP_JSON_Server
65
-     * @return array
66
-     */
67
-    public static function getMissingPermissions($model, $request_type = EEM_Base::caps_read)
68
-    {
69
-        return $model->caps_missing($request_type);
70
-    }
59
+	/**
60
+	 * Gets an array of all the capabilities the current user is missing that affected
61
+	 * the query
62
+	 *
63
+	 * @param EEM_Base $model
64
+	 * @param string   $request_type one of the constants on WP_JSON_Server
65
+	 * @return array
66
+	 */
67
+	public static function getMissingPermissions($model, $request_type = EEM_Base::caps_read)
68
+	{
69
+		return $model->caps_missing($request_type);
70
+	}
71 71
 
72 72
 
73
-    /**
74
-     * Gets a string of all the capabilities the current user is missing that affected
75
-     * the query
76
-     *
77
-     * @param EEM_Base $model
78
-     * @param string   $model_context one of the return values from EEM_Base::valid_cap_contexts()
79
-     * @return string
80
-     */
81
-    public static function getMissingPermissionsString($model, $model_context = EEM_Base::caps_read)
82
-    {
83
-        return implode(',', array_keys(self::getMissingPermissions($model, $model_context)));
84
-    }
73
+	/**
74
+	 * Gets a string of all the capabilities the current user is missing that affected
75
+	 * the query
76
+	 *
77
+	 * @param EEM_Base $model
78
+	 * @param string   $model_context one of the return values from EEM_Base::valid_cap_contexts()
79
+	 * @return string
80
+	 */
81
+	public static function getMissingPermissionsString($model, $model_context = EEM_Base::caps_read)
82
+	{
83
+		return implode(',', array_keys(self::getMissingPermissions($model, $model_context)));
84
+	}
85 85
 
86
-    /**
87
-     * "Removes" password-protected fields. Currently that means setting their values to their default.
88
-     * @since 4.9.74.p
89
-     * @param array $entity
90
-     * @param EEM_Base $model
91
-     * @param ModelVersionInfo $model_version_info
92
-     * @return array
93
-     * @throws EE_Error
94
-     */
95
-    public static function filterOutPasswordProtectedFields(
96
-        $entity,
97
-        EEM_Base $model,
98
-        ModelVersionInfo $model_version_info
99
-    ) {
100
-        $has_password = $model->hasPassword();
101
-        if ($has_password) {
102
-            $entity[ $model->getPasswordField()->get_name() ] = ModelDataTranslator::prepareFieldValueForJson(
103
-                $model->getPasswordField(),
104
-                $model->getPasswordField()->get_default_value(),
105
-                $model_version_info->requestedVersion()
106
-            );
107
-        }
108
-        foreach ($model->field_settings() as $field_name => $field_obj) {
109
-            if (
110
-                $has_password
111
-                && $model->getPasswordField()->fieldIsProtected($field_name)
112
-                && $entity[ $field_name ]
113
-            ) {
114
-                $replacement_value = ModelDataTranslator::prepareFieldValueForJson(
115
-                    $field_obj,
116
-                    $field_obj->get_default_value(),
117
-                    $model_version_info->requestedVersion()
118
-                );
119
-                if ($model_version_info->fieldHasRenderedFormat($field_obj)) {
120
-                    $entity[ $field_name ]['rendered'] = $replacement_value;
121
-                } elseif ($model_version_info->fieldHasPrettyFormat($field_obj)) {
122
-                    $entity[ $field_name ]['raw'] = $replacement_value;
123
-                    $entity[ $field_name ]['pretty'] = ModelDataTranslator::prepareFieldValueForJson(
124
-                        $field_obj,
125
-                        $field_obj->prepare_for_pretty_echoing($field_obj->get_default_value()),
126
-                        $model_version_info->requestedVersion()
127
-                    );
128
-                } else {
129
-                    // this is most likely an excerpt field. (These should have also had "rendered" and "raw"
130
-                    // versions, but we missed that, and can't change it without breaking backward compatibility)
131
-                    // so just remove it (or rather, set its default)
132
-                    // API clients will just need to look to fields with rendered formats to know if these have
133
-                    // been redacted. Sorry.
134
-                    $entity[ $field_name ] = $replacement_value;
135
-                }
136
-            }
137
-        }
138
-        return $entity;
139
-    }
86
+	/**
87
+	 * "Removes" password-protected fields. Currently that means setting their values to their default.
88
+	 * @since 4.9.74.p
89
+	 * @param array $entity
90
+	 * @param EEM_Base $model
91
+	 * @param ModelVersionInfo $model_version_info
92
+	 * @return array
93
+	 * @throws EE_Error
94
+	 */
95
+	public static function filterOutPasswordProtectedFields(
96
+		$entity,
97
+		EEM_Base $model,
98
+		ModelVersionInfo $model_version_info
99
+	) {
100
+		$has_password = $model->hasPassword();
101
+		if ($has_password) {
102
+			$entity[ $model->getPasswordField()->get_name() ] = ModelDataTranslator::prepareFieldValueForJson(
103
+				$model->getPasswordField(),
104
+				$model->getPasswordField()->get_default_value(),
105
+				$model_version_info->requestedVersion()
106
+			);
107
+		}
108
+		foreach ($model->field_settings() as $field_name => $field_obj) {
109
+			if (
110
+				$has_password
111
+				&& $model->getPasswordField()->fieldIsProtected($field_name)
112
+				&& $entity[ $field_name ]
113
+			) {
114
+				$replacement_value = ModelDataTranslator::prepareFieldValueForJson(
115
+					$field_obj,
116
+					$field_obj->get_default_value(),
117
+					$model_version_info->requestedVersion()
118
+				);
119
+				if ($model_version_info->fieldHasRenderedFormat($field_obj)) {
120
+					$entity[ $field_name ]['rendered'] = $replacement_value;
121
+				} elseif ($model_version_info->fieldHasPrettyFormat($field_obj)) {
122
+					$entity[ $field_name ]['raw'] = $replacement_value;
123
+					$entity[ $field_name ]['pretty'] = ModelDataTranslator::prepareFieldValueForJson(
124
+						$field_obj,
125
+						$field_obj->prepare_for_pretty_echoing($field_obj->get_default_value()),
126
+						$model_version_info->requestedVersion()
127
+					);
128
+				} else {
129
+					// this is most likely an excerpt field. (These should have also had "rendered" and "raw"
130
+					// versions, but we missed that, and can't change it without breaking backward compatibility)
131
+					// so just remove it (or rather, set its default)
132
+					// API clients will just need to look to fields with rendered formats to know if these have
133
+					// been redacted. Sorry.
134
+					$entity[ $field_name ] = $replacement_value;
135
+				}
136
+			}
137
+		}
138
+		return $entity;
139
+	}
140 140
 
141 141
 
142
-    /**
143
-     * Takes a entity that's ready to be returned and removes fields which the user shouldn't be able to access.
144
-     *
145
-     * @param array $entity
146
-     * @param EEM_Base $model
147
-     * @param string $request_type one of the return values from EEM_Base::valid_cap_contexts()
148
-     * @param ModelVersionInfo $model_version_info
149
-     * @param string $primary_key_string result of EEM_Base::get_index_primary_key_string(), so that we can
150
-     *                                               use this with models that have no primary key
151
-     * @return array ready for converting into json
152
-     */
153
-    public static function filterOutInaccessibleEntityFields(
154
-        $entity,
155
-        $model,
156
-        $request_type,
157
-        $model_version_info,
158
-        $primary_key_string = null
159
-    ) {
160
-        foreach ($model->field_settings() as $field_name => $field_obj) {
161
-            if (
162
-                $model_version_info->fieldHasRenderedFormat($field_obj)
163
-                && isset($entity[ $field_name ])
164
-                && is_array($entity[ $field_name ])
165
-                && isset($entity[ $field_name ]['raw'])
166
-            ) {
167
-                unset($entity[ $field_name ]['raw']);
168
-            }
169
-        }
170
-        // theoretically we may want to filter out specific fields for specific models
171
-        return apply_filters(
172
-            'FHEE__Capabilities__filter_out_inaccessible_entity_fields',
173
-            $entity,
174
-            $model,
175
-            $request_type
176
-        );
177
-    }
142
+	/**
143
+	 * Takes a entity that's ready to be returned and removes fields which the user shouldn't be able to access.
144
+	 *
145
+	 * @param array $entity
146
+	 * @param EEM_Base $model
147
+	 * @param string $request_type one of the return values from EEM_Base::valid_cap_contexts()
148
+	 * @param ModelVersionInfo $model_version_info
149
+	 * @param string $primary_key_string result of EEM_Base::get_index_primary_key_string(), so that we can
150
+	 *                                               use this with models that have no primary key
151
+	 * @return array ready for converting into json
152
+	 */
153
+	public static function filterOutInaccessibleEntityFields(
154
+		$entity,
155
+		$model,
156
+		$request_type,
157
+		$model_version_info,
158
+		$primary_key_string = null
159
+	) {
160
+		foreach ($model->field_settings() as $field_name => $field_obj) {
161
+			if (
162
+				$model_version_info->fieldHasRenderedFormat($field_obj)
163
+				&& isset($entity[ $field_name ])
164
+				&& is_array($entity[ $field_name ])
165
+				&& isset($entity[ $field_name ]['raw'])
166
+			) {
167
+				unset($entity[ $field_name ]['raw']);
168
+			}
169
+		}
170
+		// theoretically we may want to filter out specific fields for specific models
171
+		return apply_filters(
172
+			'FHEE__Capabilities__filter_out_inaccessible_entity_fields',
173
+			$entity,
174
+			$model,
175
+			$request_type
176
+		);
177
+	}
178 178
 
179 179
 
180
-    /**
181
-     * Verifies the current user has at least partial access to do this action on this model.
182
-     * If not, throws an exception (so we can define the code that sets up this error object
183
-     * once)
184
-     *
185
-     * @param EEM_Base $model
186
-     * @param string   $model_action_context
187
-     * @param string   $action_name
188
-     * @return void
189
-     * @throws RestException
190
-     */
191
-    public static function verifyAtLeastPartialAccessTo($model, $model_action_context, $action_name = 'list')
192
-    {
193
-        if (! Capabilities::currentUserHasPartialAccessTo($model, $model_action_context)) {
194
-            $model_name_plural = EEH_Inflector::pluralize_and_lower($model->get_this_model_name());
195
-            throw new RestException(
196
-                sprintf('rest_cannot_%s_%s', strtolower($action_name), $model_name_plural),
197
-                sprintf(
198
-                    esc_html__('Sorry, you are not allowed to %1$s %2$s. Missing permissions: %3$s', 'event_espresso'),
199
-                    $action_name,
200
-                    $model_name_plural,
201
-                    Capabilities::getMissingPermissionsString($model, $model_action_context)
202
-                ),
203
-                array('status' => 403)
204
-            );
205
-        }
206
-    }
180
+	/**
181
+	 * Verifies the current user has at least partial access to do this action on this model.
182
+	 * If not, throws an exception (so we can define the code that sets up this error object
183
+	 * once)
184
+	 *
185
+	 * @param EEM_Base $model
186
+	 * @param string   $model_action_context
187
+	 * @param string   $action_name
188
+	 * @return void
189
+	 * @throws RestException
190
+	 */
191
+	public static function verifyAtLeastPartialAccessTo($model, $model_action_context, $action_name = 'list')
192
+	{
193
+		if (! Capabilities::currentUserHasPartialAccessTo($model, $model_action_context)) {
194
+			$model_name_plural = EEH_Inflector::pluralize_and_lower($model->get_this_model_name());
195
+			throw new RestException(
196
+				sprintf('rest_cannot_%s_%s', strtolower($action_name), $model_name_plural),
197
+				sprintf(
198
+					esc_html__('Sorry, you are not allowed to %1$s %2$s. Missing permissions: %3$s', 'event_espresso'),
199
+					$action_name,
200
+					$model_name_plural,
201
+					Capabilities::getMissingPermissionsString($model, $model_action_context)
202
+				),
203
+				array('status' => 403)
204
+			);
205
+		}
206
+	}
207 207
 }
Please login to merge, or discard this patch.
core/libraries/rest_api/RestIncomingQueryParamMetadata.php 2 patches
Indentation   +701 added lines, -701 removed lines patch added patch discarded remove patch
@@ -28,707 +28,707 @@
 block discarded – undo
28 28
  */
29 29
 class RestIncomingQueryParamMetadata
30 30
 {
31
-    private $query_param_key;
32
-    private $query_param_value;
33
-    /**
34
-     * @var RestIncomingQueryParamContext
35
-     */
36
-    private $context;
37
-
38
-    /**
39
-     * @var EE_Model_Field_Base|null
40
-     */
41
-    private $field;
42
-
43
-    /**
44
-     * @var string same as $query_param_key but has the * and anything after it removed
45
-     */
46
-    private $query_param_key_sans_stars;
47
-
48
-    /**
49
-     * @var string for timezone or timezone offset
50
-     */
51
-    private $timezone;
52
-
53
-    /**
54
-     * @var boolean if the field in $query_param_key is for a GMT field (eg `EVT_modified_gmt`)
55
-     */
56
-    private $is_gmt_field = false;
57
-
58
-    /**
59
-     * RestIncomingQueryParamMetadata constructor.
60
-     * You probably want to call
61
-     * @param string $query_param_key
62
-     * @param string $query_param_value
63
-     * @param RestIncomingQueryParamContext $context
64
-     */
65
-    public function __construct($query_param_key, $query_param_value, RestIncomingQueryParamContext $context)
66
-    {
67
-        $this->query_param_key = $query_param_key;
68
-        $this->query_param_value = $query_param_value;
69
-        $this->context = $context;
70
-        $this->determineFieldAndTimezone();
71
-    }
72
-
73
-    /**
74
-     * Gets the query parameter key. This may have been modified (see setQueryParamValue())
75
-     * @return string
76
-     */
77
-    public function getQueryParamKey()
78
-    {
79
-        return $this->query_param_key;
80
-    }
81
-
82
-    /**
83
-     * Modifies the query parameter key passed in (Eg this is done when rewriting the simplified specified operator REST
84
-     * query parameters into the legacy structure)
85
-     * @param string|array|int|float $query_param_value
86
-     */
87
-    private function setQueryParamValue($query_param_value)
88
-    {
89
-        $this->query_param_value = $query_param_value;
90
-    }
91
-
92
-    /**
93
-     * Gets the original query parameter value passed in.
94
-     * @return string
95
-     */
96
-    public function getQueryParamValue()
97
-    {
98
-        return $this->query_param_value;
99
-    }
100
-
101
-    /**
102
-     * Gets the context object.
103
-     * @return RestIncomingQueryParamContext
104
-     */
105
-    public function getContext()
106
-    {
107
-        return $this->context;
108
-    }
109
-
110
-    /**
111
-     * Sets the query parameter key. This may be used to rewrite a key into its non-GMT alternative.
112
-     * @param string $query_param_key
113
-     */
114
-    private function setQueryParamKey($query_param_key)
115
-    {
116
-        $this->query_param_key = $query_param_key;
117
-    }
118
-
119
-    /**
120
-     * Gets the field the query parameter key indicated. This may be null (in cases where the query parameter key
121
-     * did not indicate a field, eg if it were `OR`).
122
-     * @return EE_Model_Field_Base|null
123
-     */
124
-    public function getField()
125
-    {
126
-        return $this->field;
127
-    }
128
-
129
-    /**
130
-     * Gets the query parameter key (with the star and everything afterwards removed).
131
-     * @return string
132
-     */
133
-    public function getQueryParamKeySansStars()
134
-    {
135
-        return $this->query_param_key_sans_stars;
136
-    }
137
-
138
-    /**
139
-     * Gets the timezone associated with this model (the site timezone, except for GMT datetime fields).
140
-     * @return string
141
-     */
142
-    public function getTimezone()
143
-    {
144
-        return $this->timezone;
145
-    }
146
-
147
-    /**
148
-     * Returns whether or not this is a GMT field
149
-     * @return boolean
150
-     */
151
-    public function isGmtField()
152
-    {
153
-        return $this->is_gmt_field;
154
-    }
155
-
156
-    /**
157
-     * Sets the field indicated by the query parameter key (might be null).
158
-     * @param EE_Model_Field_Base|null $field
159
-     */
160
-    private function setField(EE_Model_Field_Base $field = null)
161
-    {
162
-        $this->field = $field;
163
-    }
164
-
165
-    /**
166
-     * Sets the query parameter key-with-stars-removed.
167
-     * @param string $query_param_key_sans_stars
168
-     */
169
-    private function setQueryParamKeySansStars($query_param_key_sans_stars)
170
-    {
171
-        $this->query_param_key_sans_stars = $query_param_key_sans_stars;
172
-    }
173
-
174
-    /**
175
-     * Sets the timezone (this could be a timezeon offset string).
176
-     * @param string $timezone
177
-     */
178
-    private function setTimezone($timezone)
179
-    {
180
-        $this->timezone = $timezone;
181
-    }
182
-
183
-    /**
184
-     * @param mixed $is_gmt_field
185
-     */
186
-    private function setIsGmtField($is_gmt_field)
187
-    {
188
-        $this->is_gmt_field = $is_gmt_field;
189
-    }
190
-
191
-    /**
192
-     * Determines what field, query param name, and query param name without stars, and timezone to use.
193
-     * @since 4.9.72.p
194
-     * @type EE_Model_Field_Base $field
195
-     * @return void {
196
-     * @throws EE_Error
197
-     * @throws InvalidDataTypeException
198
-     * @throws InvalidInterfaceException
199
-     * @throws InvalidArgumentException
200
-     */
201
-    private function determineFieldAndTimezone()
202
-    {
203
-        $this->setQueryParamKeySansStars(ModelDataTranslator::removeStarsAndAnythingAfterFromConditionQueryParamKey(
204
-            $this->getQueryParamKey()
205
-        ));
206
-        $this->setField(ModelDataTranslator::deduceFieldFromQueryParam(
207
-            $this->getQueryParamKeySansStars(),
208
-            $this->getContext()->getModel()
209
-        ));
210
-        // double-check is it a *_gmt field?
211
-        if (
212
-            !$this->getField() instanceof EE_Model_Field_Base
213
-            && ModelDataTranslator::isGmtDateFieldName($this->getQueryParamKeySansStars())
214
-        ) {
215
-            // yep, take off '_gmt', and find the field
216
-            $this->setQueryParamKey(ModelDataTranslator::removeGmtFromFieldName($this->getQueryParamKeySansStars()));
217
-            $this->setField(ModelDataTranslator::deduceFieldFromQueryParam(
218
-                $this->getQueryParamKey(),
219
-                $this->context->getModel()
220
-            ));
221
-            $this->setTimezone('UTC');
222
-            $this->setIsGmtField(true);
223
-        } elseif ($this->getField() instanceof EE_Datetime_Field) {
224
-            // so it's not a GMT field. Set the timezone on the model to the default
225
-            $this->setTimezone(EEH_DTT_Helper::get_valid_timezone_string());
226
-        } else {
227
-            // just keep using what's already set for the timezone
228
-            $this->setTimezone($this->context->getModel()->get_timezone());
229
-        }
230
-        $this->assertOnlyAdminCanReadPasswordFields();
231
-    }
232
-
233
-    /**
234
-     * Throws an exception if a non-admin is trying to query by password.
235
-     * @since 4.9.74.p
236
-     * @throws RestException
237
-     */
238
-    private function assertOnlyAdminCanReadPasswordFields()
239
-    {
240
-        if (
241
-            $this->getField() instanceof EE_Password_Field
242
-            && ! current_user_can(EE_Restriction_Generator_Base::get_default_restrictions_cap())
243
-        ) {
244
-            // only full admins can query by password. sorry bub!
245
-            throw new RestException(
246
-                'only_admins_can_query_by_password',
247
-                // @codingStandardsIgnoreStart
248
-                esc_html__('You attempted to filter by a password field without the needed privileges. Only a full admin is allowed to do that.', 'event_espresso'),
249
-                // @codingStandardsIgnoreEnd
250
-                array(
251
-                    'status' => 403
252
-                )
253
-            );
254
-        }
255
-    }
256
-
257
-    /**
258
-     * Given a ton of input, determines the value to use for the models.
259
-     * @since 4.9.72.p
260
-     * @return array|null
261
-     * @throws DomainException
262
-     * @throws EE_Error
263
-     * @throws RestException
264
-     * @throws DomainException
265
-     */
266
-    public function determineConditionsQueryParameterValue()
267
-    {
268
-        if ($this->valueIsArrayDuringRead()) {
269
-            return $this->determineModelValueGivenRestInputArray();
270
-        }
271
-        return ModelDataTranslator::prepareFieldValueFromJson(
272
-            $this->getField(),
273
-            $this->getQueryParamValue(),
274
-            $this->getContext()->getRequestedVersion(),
275
-            $this->getTimezone()
276
-        );
277
-    }
278
-
279
-    /**
280
-     * Given that the array value provided was itself an array, handles finding the correct value to pass to the model.
281
-     * @since 4.9.72.p
282
-     * @return array|null
283
-     * @throws RestException
284
-     */
285
-    private function determineModelValueGivenRestInputArray()
286
-    {
287
-        $this->transformSimplifiedSpecifiedOperatorSyntaxIntoStandardSyntax();
288
-        // did they specify an operator?
289
-        if ($this->valueIsLegacySpecifiedOperator()) {
290
-            $query_param_value = $this->getQueryParamValue();
291
-            $sub_array_key = $query_param_value[0];
292
-            $translated_value = array($sub_array_key);
293
-            if ($this->operatorIsNAry($sub_array_key)) {
294
-                $translated_value[] = $this->prepareValuesFromJson($query_param_value[1]);
295
-            } elseif ($this->operatorIsTernary($sub_array_key)) {
296
-                $translated_value[] = array(
297
-                    $this->prepareValuesFromJson($query_param_value[1][0]),
298
-                    $this->prepareValuesFromJson($query_param_value[1][1])
299
-                );
300
-            } elseif ($this->operatorIsLike($sub_array_key)) {
301
-                // we want to leave this value mostly-as-is (eg don't force it to be a float
302
-                // or a boolean or an enum value. Leave it as-is with wildcards etc)
303
-                // but do verify it at least doesn't have any serialized data
304
-                ModelDataTranslator::throwExceptionIfContainsSerializedData($query_param_value[1]);
305
-                $translated_value[] = $query_param_value[1];
306
-            } elseif ($this->operatorIsUnary($sub_array_key)) {
307
-                // no arguments should have been provided, so don't look for any
308
-            } elseif ($this->operatorisBinary($sub_array_key)) {
309
-                // it's a valid operator, but none of the exceptions. Treat it normally.
310
-                $translated_value[] = $this->prepareValuesFromJson($query_param_value[1]);
311
-            } else {
312
-                // so they provided a valid operator, but wrong number of arguments
313
-                $this->throwWrongNumberOfArgsExceptionIfDebugging($sub_array_key);
314
-                $translated_value = null;
315
-            }
316
-        } else {
317
-            // so they didn't provide a valid operator
318
-            // if we aren't in debug mode, then just try our best to fulfill the user's request
319
-            $this->throwInvalidOperatorExceptionIfDebugging();
320
-            $translated_value = null;
321
-        }
322
-        return $translated_value;
323
-    }
324
-
325
-    /**
326
-     * Returns if this request is a "read" request and the value provided was an array.
327
-     * This will indicate is such things as `array('<', 123)` and `array('IN', array(1,2,3))` are acceptable or not.
328
-     * @since 4.9.72.p
329
-     * @return boolean
330
-     */
331
-    private function valueIsArrayDuringRead()
332
-    {
333
-        return !$this->getContext()->isWriting() && is_array($this->getQueryParamValue());
334
-    }
335
-
336
-    /**
337
-     * Returns if the value provided was an associative array (we should have already verified it's an array of some
338
-     * sort). If the value is an associative array, it had better be in the simplified specified operator structure.
339
-     * @since 4.9.72.p
340
-     * @return boolean
341
-     */
342
-    private function valueIsAssociativeArray()
343
-    {
344
-        return !EEH_Array::is_array_numerically_and_sequentially_indexed($this->getQueryParamValue());
345
-    }
346
-
347
-    /**
348
-     * Checks if the array value is itself an array that fits into the simplified specified operator structure
349
-     * (eg `array('!=' => 123)`).
350
-     * @since 4.9.72.p
351
-     * @return boolean
352
-     */
353
-    private function valueIsSimplifiedSpecifiedOperator()
354
-    {
355
-        return count($this->getQueryParamValue()) === 1
356
-            && array_key_exists(
357
-                key($this->getQueryParamValue()),
358
-                $this->getContext()->getModel()->valid_operators()
359
-            );
360
-    }
361
-
362
-    /**
363
-     * Throws an exception if the sub-value is an array (eg `array('!=' => array())`). It needs to just be a string,
364
-     * of either comma-separated-values, or a JSON array.
365
-     * @since 4.9.72.p
366
-     * @param $sub_array_key
367
-     * @param $sub_array_value
368
-     * @throws RestException
369
-     */
370
-    private function assertSubValueIsntArray($sub_array_key, $sub_array_value)
371
-    {
372
-        if (is_array($sub_array_value) && EED_Core_Rest_Api::debugMode()) {
373
-            throw new RestException(
374
-                'csv_or_json_string_only',
375
-                sprintf(
376
-                    /* translators: 1: variable name*/
377
-                    esc_html__(
378
-                        'The value provided for the operator "%1$s" should be comma-separated value string or a JSON array.',
379
-                        'event_espresso'
380
-                    ),
381
-                    $sub_array_key
382
-                ),
383
-                array(
384
-                    'status' => 400,
385
-                )
386
-            );
387
-        }
388
-    }
389
-
390
-    /**
391
-     * Determines if the sub-array key is an operator taking 3 or more operators.
392
-     * @since 4.9.72.p
393
-     * @param $sub_array_key
394
-     * @return boolean
395
-     */
396
-    private function subArrayKeyIsNonBinaryOperator($sub_array_key)
397
-    {
398
-        return array_key_exists(
399
-            $sub_array_key,
400
-            array_merge(
401
-                $this->getContext()->getModel()->valid_in_style_operators(),
402
-                $this->getContext()->getModel()->valid_between_style_operators()
403
-            )
404
-        );
405
-    }
406
-
407
-    /**
408
-     * Given that the $sub_array_key is a string, checks if it's an operator taking only 1 argument.
409
-     * @since 4.9.72.p
410
-     * @param string $sub_array_key
411
-     * @return boolean
412
-     */
413
-    private function subArrayKeyIsUnaryOperator($sub_array_key)
414
-    {
415
-        return array_key_exists(
416
-            $sub_array_key,
417
-            $this->getContext()->getModel()->valid_null_style_operators()
418
-        );
419
-    }
420
-
421
-    /**
422
-     * Parses the $sub_array_value string into an array (given it could either be a comma-separated-list or a JSON
423
-     * array). eg `"1,2,3"` or `"[1,2,3]"` into `array(1,2,3)`.
424
-     * @since 4.9.72.p
425
-     * @param $sub_array_value
426
-     * @return array|mixed|object
427
-     */
428
-    private function extractQuickStyleSpecifiedOperatorValue($sub_array_value)
429
-    {
430
-        // the value should be JSON or CSV
431
-        $values = json_decode($sub_array_value);
432
-        if (!is_array($values)) {
433
-            $values = array_filter(
434
-                array_map(
435
-                    'trim',
436
-                    explode(
437
-                        ',',
438
-                        $sub_array_value
439
-                    )
440
-                )
441
-            );
442
-        }
443
-        return $values;
444
-    }
445
-
446
-    /**
447
-     * Throws an exception if the value isn't a simplified specified operator (only called when we expect that).
448
-     * @since 4.9.72.p
449
-     * @throws RestException
450
-     */
451
-    private function assertSimplifiedSpecifiedOperator()
452
-    {
453
-        if (!$this->valueIsSimplifiedSpecifiedOperator() && EED_Core_Rest_Api::debugMode()) {
454
-            throw new RestException(
455
-                'numerically_indexed_array_of_values_only',
456
-                sprintf(
457
-                    /* translators: 1: variable name*/
458
-                    esc_html__(
459
-                        'The array provided for the parameter "%1$s" should be numerically indexed.',
460
-                        'event_espresso'
461
-                    ),
462
-                    $this->getQueryParamKey()
463
-                ),
464
-                array(
465
-                    'status' => 400,
466
-                )
467
-            );
468
-        }
469
-    }
470
-
471
-    /**
472
-     * If query_param_value were in the simplified specific operator structure, change it into the legacy structure.
473
-     * @since 4.9.72.p
474
-     * @throws RestException
475
-     */
476
-    private function transformSimplifiedSpecifiedOperatorSyntaxIntoStandardSyntax()
477
-    {
478
-        if ($this->valueIsAssociativeArray()) {
479
-            $this->assertSimplifiedSpecifiedOperator();
480
-            $query_param_value = $this->getQueryParamValue();
481
-            $sub_array_value = reset($query_param_value);
482
-            $sub_array_key = key($query_param_value);
483
-            $this->assertSubValueIsntArray($sub_array_key, $sub_array_value);
484
-            // they're doing something like "&where[EVT_ID][IN]=1,2,3" or "&where[EVT_ID][>]=5"
485
-            if ($this->subArrayKeyIsNonBinaryOperator($sub_array_key)) {
486
-                $this->setQueryParamValue(array(
487
-                    $sub_array_key,
488
-                    $this->extractQuickStyleSpecifiedOperatorValue($sub_array_value)
489
-                ));
490
-            } elseif ($this->subArrayKeyIsUnaryOperator($sub_array_key)) {
491
-                $this->setQueryParamValue(array($sub_array_key));
492
-            } else {
493
-                $this->setQueryParamValue(array($sub_array_key, $sub_array_value));
494
-            }
495
-        }
496
-    }
497
-
498
-    /**
499
-     * Returns true is the value is an array using the legacy structure to specify the operator. Eg `array('!=',123)`.
500
-     * @since 4.9.72.p
501
-     * @return boolean
502
-     */
503
-    private function valueIsLegacySpecifiedOperator()
504
-    {
505
-        $valid_operators = $this->getContext()->getModel()->valid_operators();
506
-        $query_param_value = $this->getQueryParamValue();
507
-        return isset($query_param_value[0])
508
-            && isset($valid_operators[ $query_param_value[0] ]);
509
-    }
510
-
511
-    /**
512
-     * Returns true if the value specified operator accepts arbitrary number of arguments, like "IN".
513
-     * @since 4.9.72.p
514
-     * @param $operator
515
-     * @return boolean
516
-     */
517
-    private function operatorIsNAry($operator)
518
-    {
519
-        $valueArray = $this->getQueryParamValue();
520
-        return array_key_exists(
521
-            $operator,
522
-            $this->getContext()->getModel()->valid_in_style_operators()
523
-        )
524
-            && isset($valueArray[1])
525
-            && is_array($valueArray[1])
526
-            && !isset($valueArray[2]);
527
-    }
528
-
529
-    /**
530
-     * Returns true if the operator accepts 3 arguments (eg "BETWEEN").
531
-     * So we're looking for a value that looks like
532
-     * `array('BETWEEN', array('2015-01-01T00:00:00', '2016-01-01T00:00:00'))`.
533
-     * @since 4.9.72.p
534
-     * @param $operator
535
-     * @return boolean
536
-     */
537
-    private function operatorIsTernary($operator)
538
-    {
539
-        $query_param_value = $this->getQueryParamValue();
540
-        return array_key_exists($operator, $this->getContext()->getModel()->valid_between_style_operators())
541
-            && isset($query_param_value[1])
542
-            && is_array($query_param_value[1])
543
-            && isset($query_param_value[1][0], $query_param_value[1][1])
544
-            && !isset($query_param_value[1][2])
545
-            && !isset($query_param_value[2]);
546
-    }
547
-
548
-    /**
549
-     * Returns true if the operator is a similar to LIKE, indicating the value may have wildcards we should leave alone.
550
-     * @since 4.9.72.p
551
-     * @param $operator
552
-     * @return boolean
553
-     */
554
-    private function operatorIsLike($operator)
555
-    {
556
-        $query_param_value = $this->getQueryParamValue();
557
-        return array_key_exists($operator, $this->getContext()->getModel()->valid_like_style_operators())
558
-            && isset($query_param_value[1])
559
-            && !isset($query_param_value[2]);
560
-    }
561
-
562
-    /**
563
-     * Returns true if the operator only takes one argument (eg it's like `IS NULL`).
564
-     * @since 4.9.72.p
565
-     * @param $operator
566
-     * @return boolean
567
-     */
568
-    private function operatorIsUnary($operator)
569
-    {
570
-        $query_param_value = $this->getQueryParamValue();
571
-        return array_key_exists($operator, $this->getContext()->getModel()->valid_null_style_operators())
572
-            && !isset($query_param_value[1]);
573
-    }
574
-
575
-    /**
576
-     * Returns true if the operator specified is a binary opeator (eg `=`, `!=`)
577
-     * @since 4.9.72.p
578
-     * @param $operator
579
-     * @return boolean
580
-     */
581
-    private function operatorisBinary($operator)
582
-    {
583
-        $query_param_value = $this->getQueryParamValue();
584
-        $model = $this->getContext()->getModel();
585
-        return isset($query_param_value[1])
586
-            && !isset($query_param_value[2])
587
-            && !array_key_exists(
588
-                $operator,
589
-                array_merge(
590
-                    $model->valid_in_style_operators(),
591
-                    $model->valid_null_style_operators(),
592
-                    $model->valid_like_style_operators(),
593
-                    $model->valid_between_style_operators()
594
-                )
595
-            );
596
-    }
597
-
598
-    /**
599
-     * If we're debugging, throws an exception saying that the wrong number of arguments was provided.
600
-     * @since 4.9.72.p
601
-     * @param $operator
602
-     * @throws RestException
603
-     */
604
-    private function throwWrongNumberOfArgsExceptionIfDebugging($operator)
605
-    {
606
-        if (EED_Core_Rest_Api::debugMode()) {
607
-            throw new RestException(
608
-                'wrong_number_of_arguments',
609
-                sprintf(
610
-                    esc_html__(
611
-                        'The operator you provided, "%1$s" had the wrong number of arguments',
612
-                        'event_espresso'
613
-                    ),
614
-                    $operator
615
-                ),
616
-                array(
617
-                    'status' => 400,
618
-                )
619
-            );
620
-        }
621
-    }
622
-
623
-    /**
624
-     * Wrapper for ModelDataTranslator::prepareFieldValuesFromJson(), just a tad more DRY.
625
-     * @since 4.9.72.p
626
-     * @param $value
627
-     * @return mixed
628
-     * @throws RestException
629
-     */
630
-    private function prepareValuesFromJson($value)
631
-    {
632
-        return ModelDataTranslator::prepareFieldValuesFromJson(
633
-            $this->getField(),
634
-            $value,
635
-            $this->getContext()->getRequestedVersion(),
636
-            $this->getTimezone()
637
-        );
638
-    }
639
-
640
-    /**
641
-     * Throws an exception if an invalid operator was specified and we're debugging.
642
-     * @since 4.9.72.p
643
-     * @throws RestException
644
-     */
645
-    private function throwInvalidOperatorExceptionIfDebugging()
646
-    {
647
-        // so they didn't provide a valid operator
648
-        if (EED_Core_Rest_Api::debugMode()) {
649
-            throw new RestException(
650
-                'invalid_operator',
651
-                sprintf(
652
-                    esc_html__(
653
-                        'You provided an invalid parameter, with key "%1$s" and value "%2$s"',
654
-                        'event_espresso'
655
-                    ),
656
-                    $this->getQueryParamKey(),
657
-                    $this->getQueryParamValue()
658
-                ),
659
-                array(
660
-                    'status' => 400,
661
-                )
662
-            );
663
-        }
664
-    }
665
-
666
-    /**
667
-     * Returns true if the query_param_key was a logic query parameter, eg `OR`, `AND`, `NOT`, `OR*`, etc.
668
-     * @since 4.9.72.p
669
-     * @return boolean
670
-     */
671
-    private function isLogicQueryParam()
672
-    {
673
-        return in_array($this->getQueryParamKeySansStars(), $this->getContext()->getModel()->logic_query_param_keys());
674
-    }
675
-
676
-
677
-    /**
678
-     * If the query param isn't for a field, it must be a nested query parameter which requires different logic.
679
-     * @since 4.9.72.p
680
-     * @return array
681
-     * @throws DomainException
682
-     * @throws EE_Error
683
-     * @throws RestException
684
-     * @throws InvalidDataTypeException
685
-     * @throws InvalidInterfaceException
686
-     * @throws InvalidArgumentException
687
-     */
688
-    public function determineNestedConditionQueryParameters()
689
-    {
690
-
691
-        // so this param doesn't correspond to a field eh?
692
-        if ($this->getContext()->isWriting()) {
693
-            // always tell API clients about invalid parameters when they're creating data. Otherwise,
694
-            // they are probably going to create invalid data
695
-            throw new RestException(
696
-                'invalid_field',
697
-                sprintf(
698
-                    /* translators: 1: variable name */
699
-                    esc_html__('You have provided an invalid parameter: "%1$s"', 'event_espresso'),
700
-                    $this->getQueryParamKey()
701
-                )
702
-            );
703
-        }
704
-        // so it's not for a field, is it a logic query param key?
705
-        if ($this->isLogicQueryParam()) {
706
-            return ModelDataTranslator::prepareConditionsQueryParamsForModels(
707
-                $this->getQueryParamValue(),
708
-                $this->getContext()->getModel(),
709
-                $this->getContext()->getRequestedVersion()
710
-            );
711
-        }
712
-        if (EED_Core_Rest_Api::debugMode()) {
713
-            // only tell API clients they got it wrong if we're in debug mode
714
-            // otherwise try our best ot fulfill their request by ignoring this invalid data
715
-            throw new RestException(
716
-                'invalid_parameter',
717
-                sprintf(
718
-                    /* translators: 1: variable name */
719
-                    esc_html__(
720
-                        'You provided an invalid parameter, with key "%1$s"',
721
-                        'event_espresso'
722
-                    ),
723
-                    $this->getQueryParamKey()
724
-                ),
725
-                array(
726
-                    'status' => 400,
727
-                )
728
-            );
729
-        }
730
-        return null;
731
-    }
31
+	private $query_param_key;
32
+	private $query_param_value;
33
+	/**
34
+	 * @var RestIncomingQueryParamContext
35
+	 */
36
+	private $context;
37
+
38
+	/**
39
+	 * @var EE_Model_Field_Base|null
40
+	 */
41
+	private $field;
42
+
43
+	/**
44
+	 * @var string same as $query_param_key but has the * and anything after it removed
45
+	 */
46
+	private $query_param_key_sans_stars;
47
+
48
+	/**
49
+	 * @var string for timezone or timezone offset
50
+	 */
51
+	private $timezone;
52
+
53
+	/**
54
+	 * @var boolean if the field in $query_param_key is for a GMT field (eg `EVT_modified_gmt`)
55
+	 */
56
+	private $is_gmt_field = false;
57
+
58
+	/**
59
+	 * RestIncomingQueryParamMetadata constructor.
60
+	 * You probably want to call
61
+	 * @param string $query_param_key
62
+	 * @param string $query_param_value
63
+	 * @param RestIncomingQueryParamContext $context
64
+	 */
65
+	public function __construct($query_param_key, $query_param_value, RestIncomingQueryParamContext $context)
66
+	{
67
+		$this->query_param_key = $query_param_key;
68
+		$this->query_param_value = $query_param_value;
69
+		$this->context = $context;
70
+		$this->determineFieldAndTimezone();
71
+	}
72
+
73
+	/**
74
+	 * Gets the query parameter key. This may have been modified (see setQueryParamValue())
75
+	 * @return string
76
+	 */
77
+	public function getQueryParamKey()
78
+	{
79
+		return $this->query_param_key;
80
+	}
81
+
82
+	/**
83
+	 * Modifies the query parameter key passed in (Eg this is done when rewriting the simplified specified operator REST
84
+	 * query parameters into the legacy structure)
85
+	 * @param string|array|int|float $query_param_value
86
+	 */
87
+	private function setQueryParamValue($query_param_value)
88
+	{
89
+		$this->query_param_value = $query_param_value;
90
+	}
91
+
92
+	/**
93
+	 * Gets the original query parameter value passed in.
94
+	 * @return string
95
+	 */
96
+	public function getQueryParamValue()
97
+	{
98
+		return $this->query_param_value;
99
+	}
100
+
101
+	/**
102
+	 * Gets the context object.
103
+	 * @return RestIncomingQueryParamContext
104
+	 */
105
+	public function getContext()
106
+	{
107
+		return $this->context;
108
+	}
109
+
110
+	/**
111
+	 * Sets the query parameter key. This may be used to rewrite a key into its non-GMT alternative.
112
+	 * @param string $query_param_key
113
+	 */
114
+	private function setQueryParamKey($query_param_key)
115
+	{
116
+		$this->query_param_key = $query_param_key;
117
+	}
118
+
119
+	/**
120
+	 * Gets the field the query parameter key indicated. This may be null (in cases where the query parameter key
121
+	 * did not indicate a field, eg if it were `OR`).
122
+	 * @return EE_Model_Field_Base|null
123
+	 */
124
+	public function getField()
125
+	{
126
+		return $this->field;
127
+	}
128
+
129
+	/**
130
+	 * Gets the query parameter key (with the star and everything afterwards removed).
131
+	 * @return string
132
+	 */
133
+	public function getQueryParamKeySansStars()
134
+	{
135
+		return $this->query_param_key_sans_stars;
136
+	}
137
+
138
+	/**
139
+	 * Gets the timezone associated with this model (the site timezone, except for GMT datetime fields).
140
+	 * @return string
141
+	 */
142
+	public function getTimezone()
143
+	{
144
+		return $this->timezone;
145
+	}
146
+
147
+	/**
148
+	 * Returns whether or not this is a GMT field
149
+	 * @return boolean
150
+	 */
151
+	public function isGmtField()
152
+	{
153
+		return $this->is_gmt_field;
154
+	}
155
+
156
+	/**
157
+	 * Sets the field indicated by the query parameter key (might be null).
158
+	 * @param EE_Model_Field_Base|null $field
159
+	 */
160
+	private function setField(EE_Model_Field_Base $field = null)
161
+	{
162
+		$this->field = $field;
163
+	}
164
+
165
+	/**
166
+	 * Sets the query parameter key-with-stars-removed.
167
+	 * @param string $query_param_key_sans_stars
168
+	 */
169
+	private function setQueryParamKeySansStars($query_param_key_sans_stars)
170
+	{
171
+		$this->query_param_key_sans_stars = $query_param_key_sans_stars;
172
+	}
173
+
174
+	/**
175
+	 * Sets the timezone (this could be a timezeon offset string).
176
+	 * @param string $timezone
177
+	 */
178
+	private function setTimezone($timezone)
179
+	{
180
+		$this->timezone = $timezone;
181
+	}
182
+
183
+	/**
184
+	 * @param mixed $is_gmt_field
185
+	 */
186
+	private function setIsGmtField($is_gmt_field)
187
+	{
188
+		$this->is_gmt_field = $is_gmt_field;
189
+	}
190
+
191
+	/**
192
+	 * Determines what field, query param name, and query param name without stars, and timezone to use.
193
+	 * @since 4.9.72.p
194
+	 * @type EE_Model_Field_Base $field
195
+	 * @return void {
196
+	 * @throws EE_Error
197
+	 * @throws InvalidDataTypeException
198
+	 * @throws InvalidInterfaceException
199
+	 * @throws InvalidArgumentException
200
+	 */
201
+	private function determineFieldAndTimezone()
202
+	{
203
+		$this->setQueryParamKeySansStars(ModelDataTranslator::removeStarsAndAnythingAfterFromConditionQueryParamKey(
204
+			$this->getQueryParamKey()
205
+		));
206
+		$this->setField(ModelDataTranslator::deduceFieldFromQueryParam(
207
+			$this->getQueryParamKeySansStars(),
208
+			$this->getContext()->getModel()
209
+		));
210
+		// double-check is it a *_gmt field?
211
+		if (
212
+			!$this->getField() instanceof EE_Model_Field_Base
213
+			&& ModelDataTranslator::isGmtDateFieldName($this->getQueryParamKeySansStars())
214
+		) {
215
+			// yep, take off '_gmt', and find the field
216
+			$this->setQueryParamKey(ModelDataTranslator::removeGmtFromFieldName($this->getQueryParamKeySansStars()));
217
+			$this->setField(ModelDataTranslator::deduceFieldFromQueryParam(
218
+				$this->getQueryParamKey(),
219
+				$this->context->getModel()
220
+			));
221
+			$this->setTimezone('UTC');
222
+			$this->setIsGmtField(true);
223
+		} elseif ($this->getField() instanceof EE_Datetime_Field) {
224
+			// so it's not a GMT field. Set the timezone on the model to the default
225
+			$this->setTimezone(EEH_DTT_Helper::get_valid_timezone_string());
226
+		} else {
227
+			// just keep using what's already set for the timezone
228
+			$this->setTimezone($this->context->getModel()->get_timezone());
229
+		}
230
+		$this->assertOnlyAdminCanReadPasswordFields();
231
+	}
232
+
233
+	/**
234
+	 * Throws an exception if a non-admin is trying to query by password.
235
+	 * @since 4.9.74.p
236
+	 * @throws RestException
237
+	 */
238
+	private function assertOnlyAdminCanReadPasswordFields()
239
+	{
240
+		if (
241
+			$this->getField() instanceof EE_Password_Field
242
+			&& ! current_user_can(EE_Restriction_Generator_Base::get_default_restrictions_cap())
243
+		) {
244
+			// only full admins can query by password. sorry bub!
245
+			throw new RestException(
246
+				'only_admins_can_query_by_password',
247
+				// @codingStandardsIgnoreStart
248
+				esc_html__('You attempted to filter by a password field without the needed privileges. Only a full admin is allowed to do that.', 'event_espresso'),
249
+				// @codingStandardsIgnoreEnd
250
+				array(
251
+					'status' => 403
252
+				)
253
+			);
254
+		}
255
+	}
256
+
257
+	/**
258
+	 * Given a ton of input, determines the value to use for the models.
259
+	 * @since 4.9.72.p
260
+	 * @return array|null
261
+	 * @throws DomainException
262
+	 * @throws EE_Error
263
+	 * @throws RestException
264
+	 * @throws DomainException
265
+	 */
266
+	public function determineConditionsQueryParameterValue()
267
+	{
268
+		if ($this->valueIsArrayDuringRead()) {
269
+			return $this->determineModelValueGivenRestInputArray();
270
+		}
271
+		return ModelDataTranslator::prepareFieldValueFromJson(
272
+			$this->getField(),
273
+			$this->getQueryParamValue(),
274
+			$this->getContext()->getRequestedVersion(),
275
+			$this->getTimezone()
276
+		);
277
+	}
278
+
279
+	/**
280
+	 * Given that the array value provided was itself an array, handles finding the correct value to pass to the model.
281
+	 * @since 4.9.72.p
282
+	 * @return array|null
283
+	 * @throws RestException
284
+	 */
285
+	private function determineModelValueGivenRestInputArray()
286
+	{
287
+		$this->transformSimplifiedSpecifiedOperatorSyntaxIntoStandardSyntax();
288
+		// did they specify an operator?
289
+		if ($this->valueIsLegacySpecifiedOperator()) {
290
+			$query_param_value = $this->getQueryParamValue();
291
+			$sub_array_key = $query_param_value[0];
292
+			$translated_value = array($sub_array_key);
293
+			if ($this->operatorIsNAry($sub_array_key)) {
294
+				$translated_value[] = $this->prepareValuesFromJson($query_param_value[1]);
295
+			} elseif ($this->operatorIsTernary($sub_array_key)) {
296
+				$translated_value[] = array(
297
+					$this->prepareValuesFromJson($query_param_value[1][0]),
298
+					$this->prepareValuesFromJson($query_param_value[1][1])
299
+				);
300
+			} elseif ($this->operatorIsLike($sub_array_key)) {
301
+				// we want to leave this value mostly-as-is (eg don't force it to be a float
302
+				// or a boolean or an enum value. Leave it as-is with wildcards etc)
303
+				// but do verify it at least doesn't have any serialized data
304
+				ModelDataTranslator::throwExceptionIfContainsSerializedData($query_param_value[1]);
305
+				$translated_value[] = $query_param_value[1];
306
+			} elseif ($this->operatorIsUnary($sub_array_key)) {
307
+				// no arguments should have been provided, so don't look for any
308
+			} elseif ($this->operatorisBinary($sub_array_key)) {
309
+				// it's a valid operator, but none of the exceptions. Treat it normally.
310
+				$translated_value[] = $this->prepareValuesFromJson($query_param_value[1]);
311
+			} else {
312
+				// so they provided a valid operator, but wrong number of arguments
313
+				$this->throwWrongNumberOfArgsExceptionIfDebugging($sub_array_key);
314
+				$translated_value = null;
315
+			}
316
+		} else {
317
+			// so they didn't provide a valid operator
318
+			// if we aren't in debug mode, then just try our best to fulfill the user's request
319
+			$this->throwInvalidOperatorExceptionIfDebugging();
320
+			$translated_value = null;
321
+		}
322
+		return $translated_value;
323
+	}
324
+
325
+	/**
326
+	 * Returns if this request is a "read" request and the value provided was an array.
327
+	 * This will indicate is such things as `array('<', 123)` and `array('IN', array(1,2,3))` are acceptable or not.
328
+	 * @since 4.9.72.p
329
+	 * @return boolean
330
+	 */
331
+	private function valueIsArrayDuringRead()
332
+	{
333
+		return !$this->getContext()->isWriting() && is_array($this->getQueryParamValue());
334
+	}
335
+
336
+	/**
337
+	 * Returns if the value provided was an associative array (we should have already verified it's an array of some
338
+	 * sort). If the value is an associative array, it had better be in the simplified specified operator structure.
339
+	 * @since 4.9.72.p
340
+	 * @return boolean
341
+	 */
342
+	private function valueIsAssociativeArray()
343
+	{
344
+		return !EEH_Array::is_array_numerically_and_sequentially_indexed($this->getQueryParamValue());
345
+	}
346
+
347
+	/**
348
+	 * Checks if the array value is itself an array that fits into the simplified specified operator structure
349
+	 * (eg `array('!=' => 123)`).
350
+	 * @since 4.9.72.p
351
+	 * @return boolean
352
+	 */
353
+	private function valueIsSimplifiedSpecifiedOperator()
354
+	{
355
+		return count($this->getQueryParamValue()) === 1
356
+			&& array_key_exists(
357
+				key($this->getQueryParamValue()),
358
+				$this->getContext()->getModel()->valid_operators()
359
+			);
360
+	}
361
+
362
+	/**
363
+	 * Throws an exception if the sub-value is an array (eg `array('!=' => array())`). It needs to just be a string,
364
+	 * of either comma-separated-values, or a JSON array.
365
+	 * @since 4.9.72.p
366
+	 * @param $sub_array_key
367
+	 * @param $sub_array_value
368
+	 * @throws RestException
369
+	 */
370
+	private function assertSubValueIsntArray($sub_array_key, $sub_array_value)
371
+	{
372
+		if (is_array($sub_array_value) && EED_Core_Rest_Api::debugMode()) {
373
+			throw new RestException(
374
+				'csv_or_json_string_only',
375
+				sprintf(
376
+					/* translators: 1: variable name*/
377
+					esc_html__(
378
+						'The value provided for the operator "%1$s" should be comma-separated value string or a JSON array.',
379
+						'event_espresso'
380
+					),
381
+					$sub_array_key
382
+				),
383
+				array(
384
+					'status' => 400,
385
+				)
386
+			);
387
+		}
388
+	}
389
+
390
+	/**
391
+	 * Determines if the sub-array key is an operator taking 3 or more operators.
392
+	 * @since 4.9.72.p
393
+	 * @param $sub_array_key
394
+	 * @return boolean
395
+	 */
396
+	private function subArrayKeyIsNonBinaryOperator($sub_array_key)
397
+	{
398
+		return array_key_exists(
399
+			$sub_array_key,
400
+			array_merge(
401
+				$this->getContext()->getModel()->valid_in_style_operators(),
402
+				$this->getContext()->getModel()->valid_between_style_operators()
403
+			)
404
+		);
405
+	}
406
+
407
+	/**
408
+	 * Given that the $sub_array_key is a string, checks if it's an operator taking only 1 argument.
409
+	 * @since 4.9.72.p
410
+	 * @param string $sub_array_key
411
+	 * @return boolean
412
+	 */
413
+	private function subArrayKeyIsUnaryOperator($sub_array_key)
414
+	{
415
+		return array_key_exists(
416
+			$sub_array_key,
417
+			$this->getContext()->getModel()->valid_null_style_operators()
418
+		);
419
+	}
420
+
421
+	/**
422
+	 * Parses the $sub_array_value string into an array (given it could either be a comma-separated-list or a JSON
423
+	 * array). eg `"1,2,3"` or `"[1,2,3]"` into `array(1,2,3)`.
424
+	 * @since 4.9.72.p
425
+	 * @param $sub_array_value
426
+	 * @return array|mixed|object
427
+	 */
428
+	private function extractQuickStyleSpecifiedOperatorValue($sub_array_value)
429
+	{
430
+		// the value should be JSON or CSV
431
+		$values = json_decode($sub_array_value);
432
+		if (!is_array($values)) {
433
+			$values = array_filter(
434
+				array_map(
435
+					'trim',
436
+					explode(
437
+						',',
438
+						$sub_array_value
439
+					)
440
+				)
441
+			);
442
+		}
443
+		return $values;
444
+	}
445
+
446
+	/**
447
+	 * Throws an exception if the value isn't a simplified specified operator (only called when we expect that).
448
+	 * @since 4.9.72.p
449
+	 * @throws RestException
450
+	 */
451
+	private function assertSimplifiedSpecifiedOperator()
452
+	{
453
+		if (!$this->valueIsSimplifiedSpecifiedOperator() && EED_Core_Rest_Api::debugMode()) {
454
+			throw new RestException(
455
+				'numerically_indexed_array_of_values_only',
456
+				sprintf(
457
+					/* translators: 1: variable name*/
458
+					esc_html__(
459
+						'The array provided for the parameter "%1$s" should be numerically indexed.',
460
+						'event_espresso'
461
+					),
462
+					$this->getQueryParamKey()
463
+				),
464
+				array(
465
+					'status' => 400,
466
+				)
467
+			);
468
+		}
469
+	}
470
+
471
+	/**
472
+	 * If query_param_value were in the simplified specific operator structure, change it into the legacy structure.
473
+	 * @since 4.9.72.p
474
+	 * @throws RestException
475
+	 */
476
+	private function transformSimplifiedSpecifiedOperatorSyntaxIntoStandardSyntax()
477
+	{
478
+		if ($this->valueIsAssociativeArray()) {
479
+			$this->assertSimplifiedSpecifiedOperator();
480
+			$query_param_value = $this->getQueryParamValue();
481
+			$sub_array_value = reset($query_param_value);
482
+			$sub_array_key = key($query_param_value);
483
+			$this->assertSubValueIsntArray($sub_array_key, $sub_array_value);
484
+			// they're doing something like "&where[EVT_ID][IN]=1,2,3" or "&where[EVT_ID][>]=5"
485
+			if ($this->subArrayKeyIsNonBinaryOperator($sub_array_key)) {
486
+				$this->setQueryParamValue(array(
487
+					$sub_array_key,
488
+					$this->extractQuickStyleSpecifiedOperatorValue($sub_array_value)
489
+				));
490
+			} elseif ($this->subArrayKeyIsUnaryOperator($sub_array_key)) {
491
+				$this->setQueryParamValue(array($sub_array_key));
492
+			} else {
493
+				$this->setQueryParamValue(array($sub_array_key, $sub_array_value));
494
+			}
495
+		}
496
+	}
497
+
498
+	/**
499
+	 * Returns true is the value is an array using the legacy structure to specify the operator. Eg `array('!=',123)`.
500
+	 * @since 4.9.72.p
501
+	 * @return boolean
502
+	 */
503
+	private function valueIsLegacySpecifiedOperator()
504
+	{
505
+		$valid_operators = $this->getContext()->getModel()->valid_operators();
506
+		$query_param_value = $this->getQueryParamValue();
507
+		return isset($query_param_value[0])
508
+			&& isset($valid_operators[ $query_param_value[0] ]);
509
+	}
510
+
511
+	/**
512
+	 * Returns true if the value specified operator accepts arbitrary number of arguments, like "IN".
513
+	 * @since 4.9.72.p
514
+	 * @param $operator
515
+	 * @return boolean
516
+	 */
517
+	private function operatorIsNAry($operator)
518
+	{
519
+		$valueArray = $this->getQueryParamValue();
520
+		return array_key_exists(
521
+			$operator,
522
+			$this->getContext()->getModel()->valid_in_style_operators()
523
+		)
524
+			&& isset($valueArray[1])
525
+			&& is_array($valueArray[1])
526
+			&& !isset($valueArray[2]);
527
+	}
528
+
529
+	/**
530
+	 * Returns true if the operator accepts 3 arguments (eg "BETWEEN").
531
+	 * So we're looking for a value that looks like
532
+	 * `array('BETWEEN', array('2015-01-01T00:00:00', '2016-01-01T00:00:00'))`.
533
+	 * @since 4.9.72.p
534
+	 * @param $operator
535
+	 * @return boolean
536
+	 */
537
+	private function operatorIsTernary($operator)
538
+	{
539
+		$query_param_value = $this->getQueryParamValue();
540
+		return array_key_exists($operator, $this->getContext()->getModel()->valid_between_style_operators())
541
+			&& isset($query_param_value[1])
542
+			&& is_array($query_param_value[1])
543
+			&& isset($query_param_value[1][0], $query_param_value[1][1])
544
+			&& !isset($query_param_value[1][2])
545
+			&& !isset($query_param_value[2]);
546
+	}
547
+
548
+	/**
549
+	 * Returns true if the operator is a similar to LIKE, indicating the value may have wildcards we should leave alone.
550
+	 * @since 4.9.72.p
551
+	 * @param $operator
552
+	 * @return boolean
553
+	 */
554
+	private function operatorIsLike($operator)
555
+	{
556
+		$query_param_value = $this->getQueryParamValue();
557
+		return array_key_exists($operator, $this->getContext()->getModel()->valid_like_style_operators())
558
+			&& isset($query_param_value[1])
559
+			&& !isset($query_param_value[2]);
560
+	}
561
+
562
+	/**
563
+	 * Returns true if the operator only takes one argument (eg it's like `IS NULL`).
564
+	 * @since 4.9.72.p
565
+	 * @param $operator
566
+	 * @return boolean
567
+	 */
568
+	private function operatorIsUnary($operator)
569
+	{
570
+		$query_param_value = $this->getQueryParamValue();
571
+		return array_key_exists($operator, $this->getContext()->getModel()->valid_null_style_operators())
572
+			&& !isset($query_param_value[1]);
573
+	}
574
+
575
+	/**
576
+	 * Returns true if the operator specified is a binary opeator (eg `=`, `!=`)
577
+	 * @since 4.9.72.p
578
+	 * @param $operator
579
+	 * @return boolean
580
+	 */
581
+	private function operatorisBinary($operator)
582
+	{
583
+		$query_param_value = $this->getQueryParamValue();
584
+		$model = $this->getContext()->getModel();
585
+		return isset($query_param_value[1])
586
+			&& !isset($query_param_value[2])
587
+			&& !array_key_exists(
588
+				$operator,
589
+				array_merge(
590
+					$model->valid_in_style_operators(),
591
+					$model->valid_null_style_operators(),
592
+					$model->valid_like_style_operators(),
593
+					$model->valid_between_style_operators()
594
+				)
595
+			);
596
+	}
597
+
598
+	/**
599
+	 * If we're debugging, throws an exception saying that the wrong number of arguments was provided.
600
+	 * @since 4.9.72.p
601
+	 * @param $operator
602
+	 * @throws RestException
603
+	 */
604
+	private function throwWrongNumberOfArgsExceptionIfDebugging($operator)
605
+	{
606
+		if (EED_Core_Rest_Api::debugMode()) {
607
+			throw new RestException(
608
+				'wrong_number_of_arguments',
609
+				sprintf(
610
+					esc_html__(
611
+						'The operator you provided, "%1$s" had the wrong number of arguments',
612
+						'event_espresso'
613
+					),
614
+					$operator
615
+				),
616
+				array(
617
+					'status' => 400,
618
+				)
619
+			);
620
+		}
621
+	}
622
+
623
+	/**
624
+	 * Wrapper for ModelDataTranslator::prepareFieldValuesFromJson(), just a tad more DRY.
625
+	 * @since 4.9.72.p
626
+	 * @param $value
627
+	 * @return mixed
628
+	 * @throws RestException
629
+	 */
630
+	private function prepareValuesFromJson($value)
631
+	{
632
+		return ModelDataTranslator::prepareFieldValuesFromJson(
633
+			$this->getField(),
634
+			$value,
635
+			$this->getContext()->getRequestedVersion(),
636
+			$this->getTimezone()
637
+		);
638
+	}
639
+
640
+	/**
641
+	 * Throws an exception if an invalid operator was specified and we're debugging.
642
+	 * @since 4.9.72.p
643
+	 * @throws RestException
644
+	 */
645
+	private function throwInvalidOperatorExceptionIfDebugging()
646
+	{
647
+		// so they didn't provide a valid operator
648
+		if (EED_Core_Rest_Api::debugMode()) {
649
+			throw new RestException(
650
+				'invalid_operator',
651
+				sprintf(
652
+					esc_html__(
653
+						'You provided an invalid parameter, with key "%1$s" and value "%2$s"',
654
+						'event_espresso'
655
+					),
656
+					$this->getQueryParamKey(),
657
+					$this->getQueryParamValue()
658
+				),
659
+				array(
660
+					'status' => 400,
661
+				)
662
+			);
663
+		}
664
+	}
665
+
666
+	/**
667
+	 * Returns true if the query_param_key was a logic query parameter, eg `OR`, `AND`, `NOT`, `OR*`, etc.
668
+	 * @since 4.9.72.p
669
+	 * @return boolean
670
+	 */
671
+	private function isLogicQueryParam()
672
+	{
673
+		return in_array($this->getQueryParamKeySansStars(), $this->getContext()->getModel()->logic_query_param_keys());
674
+	}
675
+
676
+
677
+	/**
678
+	 * If the query param isn't for a field, it must be a nested query parameter which requires different logic.
679
+	 * @since 4.9.72.p
680
+	 * @return array
681
+	 * @throws DomainException
682
+	 * @throws EE_Error
683
+	 * @throws RestException
684
+	 * @throws InvalidDataTypeException
685
+	 * @throws InvalidInterfaceException
686
+	 * @throws InvalidArgumentException
687
+	 */
688
+	public function determineNestedConditionQueryParameters()
689
+	{
690
+
691
+		// so this param doesn't correspond to a field eh?
692
+		if ($this->getContext()->isWriting()) {
693
+			// always tell API clients about invalid parameters when they're creating data. Otherwise,
694
+			// they are probably going to create invalid data
695
+			throw new RestException(
696
+				'invalid_field',
697
+				sprintf(
698
+					/* translators: 1: variable name */
699
+					esc_html__('You have provided an invalid parameter: "%1$s"', 'event_espresso'),
700
+					$this->getQueryParamKey()
701
+				)
702
+			);
703
+		}
704
+		// so it's not for a field, is it a logic query param key?
705
+		if ($this->isLogicQueryParam()) {
706
+			return ModelDataTranslator::prepareConditionsQueryParamsForModels(
707
+				$this->getQueryParamValue(),
708
+				$this->getContext()->getModel(),
709
+				$this->getContext()->getRequestedVersion()
710
+			);
711
+		}
712
+		if (EED_Core_Rest_Api::debugMode()) {
713
+			// only tell API clients they got it wrong if we're in debug mode
714
+			// otherwise try our best ot fulfill their request by ignoring this invalid data
715
+			throw new RestException(
716
+				'invalid_parameter',
717
+				sprintf(
718
+					/* translators: 1: variable name */
719
+					esc_html__(
720
+						'You provided an invalid parameter, with key "%1$s"',
721
+						'event_espresso'
722
+					),
723
+					$this->getQueryParamKey()
724
+				),
725
+				array(
726
+					'status' => 400,
727
+				)
728
+			);
729
+		}
730
+		return null;
731
+	}
732 732
 }
733 733
 // End of file RestQueryParamMetadata.php
734 734
 // Location: EventEspresso\core\libraries\rest_api/RestQueryParamMetadata.php
Please login to merge, or discard this patch.
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -209,7 +209,7 @@  discard block
 block discarded – undo
209 209
         ));
210 210
         // double-check is it a *_gmt field?
211 211
         if (
212
-            !$this->getField() instanceof EE_Model_Field_Base
212
+            ! $this->getField() instanceof EE_Model_Field_Base
213 213
             && ModelDataTranslator::isGmtDateFieldName($this->getQueryParamKeySansStars())
214 214
         ) {
215 215
             // yep, take off '_gmt', and find the field
@@ -330,7 +330,7 @@  discard block
 block discarded – undo
330 330
      */
331 331
     private function valueIsArrayDuringRead()
332 332
     {
333
-        return !$this->getContext()->isWriting() && is_array($this->getQueryParamValue());
333
+        return ! $this->getContext()->isWriting() && is_array($this->getQueryParamValue());
334 334
     }
335 335
 
336 336
     /**
@@ -341,7 +341,7 @@  discard block
 block discarded – undo
341 341
      */
342 342
     private function valueIsAssociativeArray()
343 343
     {
344
-        return !EEH_Array::is_array_numerically_and_sequentially_indexed($this->getQueryParamValue());
344
+        return ! EEH_Array::is_array_numerically_and_sequentially_indexed($this->getQueryParamValue());
345 345
     }
346 346
 
347 347
     /**
@@ -429,7 +429,7 @@  discard block
 block discarded – undo
429 429
     {
430 430
         // the value should be JSON or CSV
431 431
         $values = json_decode($sub_array_value);
432
-        if (!is_array($values)) {
432
+        if ( ! is_array($values)) {
433 433
             $values = array_filter(
434 434
                 array_map(
435 435
                     'trim',
@@ -450,7 +450,7 @@  discard block
 block discarded – undo
450 450
      */
451 451
     private function assertSimplifiedSpecifiedOperator()
452 452
     {
453
-        if (!$this->valueIsSimplifiedSpecifiedOperator() && EED_Core_Rest_Api::debugMode()) {
453
+        if ( ! $this->valueIsSimplifiedSpecifiedOperator() && EED_Core_Rest_Api::debugMode()) {
454 454
             throw new RestException(
455 455
                 'numerically_indexed_array_of_values_only',
456 456
                 sprintf(
@@ -505,7 +505,7 @@  discard block
 block discarded – undo
505 505
         $valid_operators = $this->getContext()->getModel()->valid_operators();
506 506
         $query_param_value = $this->getQueryParamValue();
507 507
         return isset($query_param_value[0])
508
-            && isset($valid_operators[ $query_param_value[0] ]);
508
+            && isset($valid_operators[$query_param_value[0]]);
509 509
     }
510 510
 
511 511
     /**
@@ -523,7 +523,7 @@  discard block
 block discarded – undo
523 523
         )
524 524
             && isset($valueArray[1])
525 525
             && is_array($valueArray[1])
526
-            && !isset($valueArray[2]);
526
+            && ! isset($valueArray[2]);
527 527
     }
528 528
 
529 529
     /**
@@ -541,8 +541,8 @@  discard block
 block discarded – undo
541 541
             && isset($query_param_value[1])
542 542
             && is_array($query_param_value[1])
543 543
             && isset($query_param_value[1][0], $query_param_value[1][1])
544
-            && !isset($query_param_value[1][2])
545
-            && !isset($query_param_value[2]);
544
+            && ! isset($query_param_value[1][2])
545
+            && ! isset($query_param_value[2]);
546 546
     }
547 547
 
548 548
     /**
@@ -556,7 +556,7 @@  discard block
 block discarded – undo
556 556
         $query_param_value = $this->getQueryParamValue();
557 557
         return array_key_exists($operator, $this->getContext()->getModel()->valid_like_style_operators())
558 558
             && isset($query_param_value[1])
559
-            && !isset($query_param_value[2]);
559
+            && ! isset($query_param_value[2]);
560 560
     }
561 561
 
562 562
     /**
@@ -569,7 +569,7 @@  discard block
 block discarded – undo
569 569
     {
570 570
         $query_param_value = $this->getQueryParamValue();
571 571
         return array_key_exists($operator, $this->getContext()->getModel()->valid_null_style_operators())
572
-            && !isset($query_param_value[1]);
572
+            && ! isset($query_param_value[1]);
573 573
     }
574 574
 
575 575
     /**
@@ -583,8 +583,8 @@  discard block
 block discarded – undo
583 583
         $query_param_value = $this->getQueryParamValue();
584 584
         $model = $this->getContext()->getModel();
585 585
         return isset($query_param_value[1])
586
-            && !isset($query_param_value[2])
587
-            && !array_key_exists(
586
+            && ! isset($query_param_value[2])
587
+            && ! array_key_exists(
588 588
                 $operator,
589 589
                 array_merge(
590 590
                     $model->valid_in_style_operators(),
Please login to merge, or discard this patch.