@@ -3,7 +3,7 @@ discard block |
||
3 | 3 | use EventEspresso\core\exceptions\IpnException; |
4 | 4 | |
5 | 5 | if (! defined('EVENT_ESPRESSO_VERSION')) { |
6 | - exit('NO direct script access allowed'); |
|
6 | + exit('NO direct script access allowed'); |
|
7 | 7 | } |
8 | 8 | |
9 | 9 | |
@@ -25,607 +25,607 @@ discard block |
||
25 | 25 | class EEG_Paypal_Standard extends EE_Offsite_Gateway |
26 | 26 | { |
27 | 27 | |
28 | - /** |
|
29 | - * Name for the wp option used to save the itemized payment |
|
30 | - */ |
|
31 | - const itemized_payment_option_name = '_itemized_payment'; |
|
32 | - |
|
33 | - protected $_paypal_id; |
|
34 | - |
|
35 | - protected $_image_url; |
|
36 | - |
|
37 | - protected $_shipping_details; |
|
38 | - |
|
39 | - protected $_paypal_shipping; |
|
40 | - |
|
41 | - protected $_paypal_taxes; |
|
42 | - |
|
43 | - protected $_gateway_url; |
|
44 | - |
|
45 | - protected $_currencies_supported = array( |
|
46 | - 'USD', |
|
47 | - 'GBP', |
|
48 | - 'CAD', |
|
49 | - 'AUD', |
|
50 | - 'BRL', |
|
51 | - 'CHF', |
|
52 | - 'CZK', |
|
53 | - 'DKK', |
|
54 | - 'EUR', |
|
55 | - 'HKD', |
|
56 | - 'HUF', |
|
57 | - 'ILS', |
|
58 | - 'JPY', |
|
59 | - 'MXN', |
|
60 | - 'MYR', |
|
61 | - 'NOK', |
|
62 | - 'NZD', |
|
63 | - 'PHP', |
|
64 | - 'PLN', |
|
65 | - 'SEK', |
|
66 | - 'SGD', |
|
67 | - 'THB', |
|
68 | - 'TRY', |
|
69 | - 'TWD', |
|
70 | - 'RUB' |
|
71 | - ); |
|
72 | - |
|
73 | - |
|
74 | - /** |
|
75 | - * EEG_Paypal_Standard constructor. |
|
76 | - * |
|
77 | - * @return EEG_Paypal_Standard |
|
78 | - */ |
|
79 | - public function __construct() |
|
80 | - { |
|
81 | - $this->set_uses_separate_IPN_request(true); |
|
82 | - parent::__construct(); |
|
83 | - } |
|
84 | - |
|
85 | - |
|
86 | - /** |
|
87 | - * Also sets the gateway url class variable based on whether debug mode is enabled or not. |
|
88 | - * |
|
89 | - * @param array $settings_array |
|
90 | - */ |
|
91 | - public function set_settings($settings_array) |
|
92 | - { |
|
93 | - parent::set_settings($settings_array); |
|
94 | - $this->_gateway_url = $this->_debug_mode |
|
95 | - ? 'https://www.sandbox.paypal.com/cgi-bin/webscr' |
|
96 | - : 'https://www.paypal.com/cgi-bin/webscr'; |
|
97 | - } |
|
98 | - |
|
99 | - |
|
100 | - /** |
|
101 | - * @param EEI_Payment $payment the payment to process |
|
102 | - * @param array $billing_info but should be empty for this gateway |
|
103 | - * @param string $return_url URL to send the user to after payment on the payment provider's website |
|
104 | - * @param string $notify_url URL to send the instant payment notification |
|
105 | - * @param string $cancel_url URL to send the user to after a cancelled payment attempt |
|
106 | - * on the payment provider's website |
|
107 | - * @return EEI_Payment |
|
108 | - * @throws \EE_Error |
|
109 | - */ |
|
110 | - public function set_redirection_info( |
|
111 | - $payment, |
|
112 | - $billing_info = array(), |
|
113 | - $return_url = null, |
|
114 | - $notify_url = null, |
|
115 | - $cancel_url = null |
|
116 | - ) { |
|
117 | - $redirect_args = array(); |
|
118 | - $transaction = $payment->transaction(); |
|
119 | - $gateway_formatter = $this->_get_gateway_formatter(); |
|
120 | - $item_num = 1; |
|
121 | - /** @type EE_Line_Item $total_line_item */ |
|
122 | - $total_line_item = $transaction->total_line_item(); |
|
123 | - |
|
124 | - $total_discounts_to_cart_total = $transaction->paid(); |
|
125 | - //only itemize the order if we're paying for the rest of the order's amount |
|
126 | - if (EEH_Money::compare_floats($payment->amount(), $transaction->total(), '==')) { |
|
127 | - $payment->update_extra_meta(EEG_Paypal_Standard::itemized_payment_option_name, true); |
|
128 | - //this payment is for the remaining transaction amount, |
|
129 | - //keep track of exactly how much the itemized order amount equals |
|
130 | - $itemized_sum = 0; |
|
131 | - $shipping_previously_added = 0; |
|
132 | - //so let's show all the line items |
|
133 | - foreach ($total_line_item->get_items() as $line_item) { |
|
134 | - if ($line_item instanceof EE_Line_Item) { |
|
135 | - //it's some kind of discount |
|
136 | - if ($line_item->total() < 0) { |
|
137 | - $total_discounts_to_cart_total += abs($line_item->total()); |
|
138 | - $itemized_sum += $line_item->total(); |
|
139 | - continue; |
|
140 | - } |
|
141 | - //dont include shipping again. |
|
142 | - if (strpos($line_item->code(), 'paypal_shipping_') === 0) { |
|
143 | - $shipping_previously_added = $line_item->total(); |
|
144 | - continue; |
|
145 | - } |
|
146 | - $redirect_args['item_name_' . $item_num] = substr( |
|
147 | - $gateway_formatter->formatLineItemName($line_item, $payment), |
|
148 | - 0, 127 |
|
149 | - ); |
|
150 | - $redirect_args['amount_' . $item_num] = $line_item->unit_price(); |
|
151 | - $redirect_args['quantity_' . $item_num] = $line_item->quantity(); |
|
152 | - //if we're not letting PayPal calculate shipping, tell them its 0 |
|
153 | - if (! $this->_paypal_shipping) { |
|
154 | - $redirect_args['shipping_' . $item_num] = '0'; |
|
155 | - $redirect_args['shipping2_' . $item_num] = '0'; |
|
156 | - } |
|
157 | - $item_num++; |
|
158 | - $itemized_sum += $line_item->total(); |
|
159 | - } |
|
160 | - } |
|
161 | - $taxes_li = $this->_line_item->get_taxes_subtotal($total_line_item); |
|
162 | - //ideally itemized sum equals the transaction total. but if not (which is weird) |
|
163 | - //and the itemized sum is LESS than the transaction total |
|
164 | - //add another line item |
|
165 | - //if the itemized sum is MORE than the transaction total, |
|
166 | - //add the difference it to the discounts |
|
167 | - $itemized_sum_diff_from_txn_total = round( |
|
168 | - $transaction->total() - $itemized_sum - $taxes_li->total() - $shipping_previously_added, |
|
169 | - 2 |
|
170 | - ); |
|
171 | - if ($itemized_sum_diff_from_txn_total < 0) { |
|
172 | - //itemized sum is too big |
|
173 | - $total_discounts_to_cart_total += abs($itemized_sum_diff_from_txn_total); |
|
174 | - } elseif ($itemized_sum_diff_from_txn_total > 0) { |
|
175 | - $redirect_args['item_name_' . $item_num] = substr( |
|
176 | - __('Other charges', 'event_espresso' ), 0, 127); |
|
177 | - $redirect_args['amount_' . $item_num] = $gateway_formatter->formatCurrency( |
|
178 | - $itemized_sum_diff_from_txn_total |
|
179 | - ); |
|
180 | - $redirect_args['quantity_' . $item_num] = 1; |
|
181 | - $item_num++; |
|
182 | - } |
|
183 | - if ($total_discounts_to_cart_total > 0) { |
|
184 | - $redirect_args['discount_amount_cart'] = $gateway_formatter->formatCurrency( |
|
185 | - $total_discounts_to_cart_total |
|
186 | - ); |
|
187 | - } |
|
188 | - //add our taxes to the order if we're NOT using PayPal's |
|
189 | - if (! $this->_paypal_taxes) { |
|
190 | - $redirect_args['tax_cart'] = $total_line_item->get_total_tax(); |
|
191 | - } |
|
192 | - } else { |
|
193 | - $payment->update_extra_meta(EEG_Paypal_Standard::itemized_payment_option_name, false); |
|
194 | - //partial payment that's not for the remaining amount, so we can't send an itemized list |
|
195 | - $redirect_args['item_name_' . $item_num] = substr( |
|
196 | - $gateway_formatter->formatPartialPaymentLineItemName($payment), |
|
197 | - 0, |
|
198 | - 127 |
|
199 | - ); |
|
200 | - $redirect_args['amount_' . $item_num] = $payment->amount(); |
|
201 | - $redirect_args['shipping_' . $item_num] = '0'; |
|
202 | - $redirect_args['shipping2_' . $item_num] = '0'; |
|
203 | - $redirect_args['tax_cart'] = '0'; |
|
204 | - $item_num++; |
|
205 | - } |
|
206 | - |
|
207 | - if ($this->_debug_mode) { |
|
208 | - $redirect_args['item_name_' . $item_num] = 'DEBUG INFO (this item only added in sandbox mode'; |
|
209 | - $redirect_args['amount_' . $item_num] = 0; |
|
210 | - $redirect_args['on0_'.$item_num] = 'NOTIFY URL'; |
|
211 | - $redirect_args['os0_' . $item_num] = $notify_url; |
|
212 | - $redirect_args['on1_'.$item_num] = 'RETURN URL'; |
|
213 | - $redirect_args['os1_' . $item_num] = $return_url; |
|
28 | + /** |
|
29 | + * Name for the wp option used to save the itemized payment |
|
30 | + */ |
|
31 | + const itemized_payment_option_name = '_itemized_payment'; |
|
32 | + |
|
33 | + protected $_paypal_id; |
|
34 | + |
|
35 | + protected $_image_url; |
|
36 | + |
|
37 | + protected $_shipping_details; |
|
38 | + |
|
39 | + protected $_paypal_shipping; |
|
40 | + |
|
41 | + protected $_paypal_taxes; |
|
42 | + |
|
43 | + protected $_gateway_url; |
|
44 | + |
|
45 | + protected $_currencies_supported = array( |
|
46 | + 'USD', |
|
47 | + 'GBP', |
|
48 | + 'CAD', |
|
49 | + 'AUD', |
|
50 | + 'BRL', |
|
51 | + 'CHF', |
|
52 | + 'CZK', |
|
53 | + 'DKK', |
|
54 | + 'EUR', |
|
55 | + 'HKD', |
|
56 | + 'HUF', |
|
57 | + 'ILS', |
|
58 | + 'JPY', |
|
59 | + 'MXN', |
|
60 | + 'MYR', |
|
61 | + 'NOK', |
|
62 | + 'NZD', |
|
63 | + 'PHP', |
|
64 | + 'PLN', |
|
65 | + 'SEK', |
|
66 | + 'SGD', |
|
67 | + 'THB', |
|
68 | + 'TRY', |
|
69 | + 'TWD', |
|
70 | + 'RUB' |
|
71 | + ); |
|
72 | + |
|
73 | + |
|
74 | + /** |
|
75 | + * EEG_Paypal_Standard constructor. |
|
76 | + * |
|
77 | + * @return EEG_Paypal_Standard |
|
78 | + */ |
|
79 | + public function __construct() |
|
80 | + { |
|
81 | + $this->set_uses_separate_IPN_request(true); |
|
82 | + parent::__construct(); |
|
83 | + } |
|
84 | + |
|
85 | + |
|
86 | + /** |
|
87 | + * Also sets the gateway url class variable based on whether debug mode is enabled or not. |
|
88 | + * |
|
89 | + * @param array $settings_array |
|
90 | + */ |
|
91 | + public function set_settings($settings_array) |
|
92 | + { |
|
93 | + parent::set_settings($settings_array); |
|
94 | + $this->_gateway_url = $this->_debug_mode |
|
95 | + ? 'https://www.sandbox.paypal.com/cgi-bin/webscr' |
|
96 | + : 'https://www.paypal.com/cgi-bin/webscr'; |
|
97 | + } |
|
98 | + |
|
99 | + |
|
100 | + /** |
|
101 | + * @param EEI_Payment $payment the payment to process |
|
102 | + * @param array $billing_info but should be empty for this gateway |
|
103 | + * @param string $return_url URL to send the user to after payment on the payment provider's website |
|
104 | + * @param string $notify_url URL to send the instant payment notification |
|
105 | + * @param string $cancel_url URL to send the user to after a cancelled payment attempt |
|
106 | + * on the payment provider's website |
|
107 | + * @return EEI_Payment |
|
108 | + * @throws \EE_Error |
|
109 | + */ |
|
110 | + public function set_redirection_info( |
|
111 | + $payment, |
|
112 | + $billing_info = array(), |
|
113 | + $return_url = null, |
|
114 | + $notify_url = null, |
|
115 | + $cancel_url = null |
|
116 | + ) { |
|
117 | + $redirect_args = array(); |
|
118 | + $transaction = $payment->transaction(); |
|
119 | + $gateway_formatter = $this->_get_gateway_formatter(); |
|
120 | + $item_num = 1; |
|
121 | + /** @type EE_Line_Item $total_line_item */ |
|
122 | + $total_line_item = $transaction->total_line_item(); |
|
123 | + |
|
124 | + $total_discounts_to_cart_total = $transaction->paid(); |
|
125 | + //only itemize the order if we're paying for the rest of the order's amount |
|
126 | + if (EEH_Money::compare_floats($payment->amount(), $transaction->total(), '==')) { |
|
127 | + $payment->update_extra_meta(EEG_Paypal_Standard::itemized_payment_option_name, true); |
|
128 | + //this payment is for the remaining transaction amount, |
|
129 | + //keep track of exactly how much the itemized order amount equals |
|
130 | + $itemized_sum = 0; |
|
131 | + $shipping_previously_added = 0; |
|
132 | + //so let's show all the line items |
|
133 | + foreach ($total_line_item->get_items() as $line_item) { |
|
134 | + if ($line_item instanceof EE_Line_Item) { |
|
135 | + //it's some kind of discount |
|
136 | + if ($line_item->total() < 0) { |
|
137 | + $total_discounts_to_cart_total += abs($line_item->total()); |
|
138 | + $itemized_sum += $line_item->total(); |
|
139 | + continue; |
|
140 | + } |
|
141 | + //dont include shipping again. |
|
142 | + if (strpos($line_item->code(), 'paypal_shipping_') === 0) { |
|
143 | + $shipping_previously_added = $line_item->total(); |
|
144 | + continue; |
|
145 | + } |
|
146 | + $redirect_args['item_name_' . $item_num] = substr( |
|
147 | + $gateway_formatter->formatLineItemName($line_item, $payment), |
|
148 | + 0, 127 |
|
149 | + ); |
|
150 | + $redirect_args['amount_' . $item_num] = $line_item->unit_price(); |
|
151 | + $redirect_args['quantity_' . $item_num] = $line_item->quantity(); |
|
152 | + //if we're not letting PayPal calculate shipping, tell them its 0 |
|
153 | + if (! $this->_paypal_shipping) { |
|
154 | + $redirect_args['shipping_' . $item_num] = '0'; |
|
155 | + $redirect_args['shipping2_' . $item_num] = '0'; |
|
156 | + } |
|
157 | + $item_num++; |
|
158 | + $itemized_sum += $line_item->total(); |
|
159 | + } |
|
160 | + } |
|
161 | + $taxes_li = $this->_line_item->get_taxes_subtotal($total_line_item); |
|
162 | + //ideally itemized sum equals the transaction total. but if not (which is weird) |
|
163 | + //and the itemized sum is LESS than the transaction total |
|
164 | + //add another line item |
|
165 | + //if the itemized sum is MORE than the transaction total, |
|
166 | + //add the difference it to the discounts |
|
167 | + $itemized_sum_diff_from_txn_total = round( |
|
168 | + $transaction->total() - $itemized_sum - $taxes_li->total() - $shipping_previously_added, |
|
169 | + 2 |
|
170 | + ); |
|
171 | + if ($itemized_sum_diff_from_txn_total < 0) { |
|
172 | + //itemized sum is too big |
|
173 | + $total_discounts_to_cart_total += abs($itemized_sum_diff_from_txn_total); |
|
174 | + } elseif ($itemized_sum_diff_from_txn_total > 0) { |
|
175 | + $redirect_args['item_name_' . $item_num] = substr( |
|
176 | + __('Other charges', 'event_espresso' ), 0, 127); |
|
177 | + $redirect_args['amount_' . $item_num] = $gateway_formatter->formatCurrency( |
|
178 | + $itemized_sum_diff_from_txn_total |
|
179 | + ); |
|
180 | + $redirect_args['quantity_' . $item_num] = 1; |
|
181 | + $item_num++; |
|
182 | + } |
|
183 | + if ($total_discounts_to_cart_total > 0) { |
|
184 | + $redirect_args['discount_amount_cart'] = $gateway_formatter->formatCurrency( |
|
185 | + $total_discounts_to_cart_total |
|
186 | + ); |
|
187 | + } |
|
188 | + //add our taxes to the order if we're NOT using PayPal's |
|
189 | + if (! $this->_paypal_taxes) { |
|
190 | + $redirect_args['tax_cart'] = $total_line_item->get_total_tax(); |
|
191 | + } |
|
192 | + } else { |
|
193 | + $payment->update_extra_meta(EEG_Paypal_Standard::itemized_payment_option_name, false); |
|
194 | + //partial payment that's not for the remaining amount, so we can't send an itemized list |
|
195 | + $redirect_args['item_name_' . $item_num] = substr( |
|
196 | + $gateway_formatter->formatPartialPaymentLineItemName($payment), |
|
197 | + 0, |
|
198 | + 127 |
|
199 | + ); |
|
200 | + $redirect_args['amount_' . $item_num] = $payment->amount(); |
|
201 | + $redirect_args['shipping_' . $item_num] = '0'; |
|
202 | + $redirect_args['shipping2_' . $item_num] = '0'; |
|
203 | + $redirect_args['tax_cart'] = '0'; |
|
204 | + $item_num++; |
|
205 | + } |
|
206 | + |
|
207 | + if ($this->_debug_mode) { |
|
208 | + $redirect_args['item_name_' . $item_num] = 'DEBUG INFO (this item only added in sandbox mode'; |
|
209 | + $redirect_args['amount_' . $item_num] = 0; |
|
210 | + $redirect_args['on0_'.$item_num] = 'NOTIFY URL'; |
|
211 | + $redirect_args['os0_' . $item_num] = $notify_url; |
|
212 | + $redirect_args['on1_'.$item_num] = 'RETURN URL'; |
|
213 | + $redirect_args['os1_' . $item_num] = $return_url; |
|
214 | 214 | // $redirect_args['option_index_' . $item_num] = 1; // <-- dunno if this is needed ? |
215 | - $redirect_args['shipping_' . $item_num] = '0'; |
|
216 | - $redirect_args['shipping2_' . $item_num] = '0'; |
|
217 | - } |
|
218 | - |
|
219 | - $redirect_args['business'] = $this->_paypal_id; |
|
220 | - $redirect_args['return'] = $return_url; |
|
221 | - $redirect_args['cancel_return'] = $cancel_url; |
|
222 | - $redirect_args['notify_url'] = $notify_url; |
|
223 | - $redirect_args['cmd'] = '_cart'; |
|
224 | - $redirect_args['upload'] = 1; |
|
225 | - $redirect_args['currency_code'] = $payment->currency_code(); |
|
226 | - $redirect_args['rm'] = 2;//makes the user return with method=POST |
|
227 | - if ($this->_image_url) { |
|
228 | - $redirect_args['image_url'] = $this->_image_url; |
|
229 | - } |
|
230 | - $redirect_args['no_shipping'] = $this->_shipping_details; |
|
231 | - $redirect_args['bn'] = 'EventEspresso_SP';//EE will blow up if you change this |
|
232 | - |
|
233 | - $redirect_args = apply_filters("FHEE__EEG_Paypal_Standard__set_redirection_info__arguments", $redirect_args, $this); |
|
234 | - |
|
235 | - $payment->set_redirect_url($this->_gateway_url); |
|
236 | - $payment->set_redirect_args($redirect_args); |
|
237 | - // log the results |
|
238 | - $this->log( |
|
239 | - array( |
|
240 | - 'message' => sprintf( |
|
241 | - __('PayPal payment request initiated.', 'event_espresso') |
|
242 | - ), |
|
243 | - 'transaction' => $transaction->model_field_array(), |
|
244 | - ), |
|
245 | - $payment |
|
246 | - ); |
|
247 | - return $payment; |
|
248 | - } |
|
249 | - |
|
250 | - |
|
251 | - /** |
|
252 | - * Often used for IPNs. But applies the info in $update_info to the payment. |
|
253 | - * What is $update_info? Often the contents of $_REQUEST, but not necessarily. Whatever |
|
254 | - * the payment method passes in. |
|
255 | - * |
|
256 | - * @param array $update_info like $_POST |
|
257 | - * @param EEI_Transaction $transaction |
|
258 | - * @return \EEI_Payment updated |
|
259 | - * @throws \EE_Error, IpnException |
|
260 | - */ |
|
261 | - public function handle_payment_update($update_info, $transaction) |
|
262 | - { |
|
263 | - // verify there's payment data that's been sent |
|
264 | - if (empty($update_info['payment_status'] ) || empty($update_info['txn_id'])) { |
|
265 | - // log the results |
|
266 | - $this->log( |
|
267 | - array( |
|
268 | - 'message' => sprintf( |
|
269 | - // @codingStandardsIgnoreStart |
|
270 | - __('PayPal IPN response is missing critical payment data. This may indicate a PDT request and require your PayPal account settings to be corrected.', 'event_espresso') |
|
271 | - // @codingStandardsIgnoreEnd |
|
272 | - ), |
|
273 | - 'update_info' => $update_info, |
|
274 | - ), |
|
275 | - $transaction |
|
276 | - ); |
|
277 | - // waaaait... is this a PDT request? (see https://developer.paypal.com/docs/classic/products/payment-data-transfer/) |
|
278 | - // indicated by the "tx" argument? If so, we don't need it. We'll just use the IPN data when it comes |
|
279 | - if (isset($update_info['tx'])) { |
|
280 | - return $transaction->last_payment(); |
|
281 | - } else { |
|
282 | - return null; |
|
283 | - } |
|
284 | - } |
|
285 | - $payment = $this->_pay_model->get_payment_by_txn_id_chq_nmbr($update_info['txn_id']); |
|
286 | - if (! $payment instanceof EEI_Payment) { |
|
287 | - $payment = $transaction->last_payment(); |
|
288 | - } |
|
289 | - // ok, then validate the IPN. Even if we've already processed this payment, |
|
290 | - // let PayPal know we don't want to hear from them anymore! |
|
291 | - if (! $this->validate_ipn($update_info, $payment)) { |
|
292 | - return $payment; |
|
293 | - } |
|
294 | - // kill request here if this is a refund, we don't support them yet (we'd need to adjust the transaction, |
|
295 | - // registrations, ticket counts, etc) |
|
296 | - if ( |
|
297 | - ( |
|
298 | - $update_info['payment_status'] === 'Refunded' |
|
299 | - || $update_info['payment_status'] === 'Partially_Refunded' |
|
300 | - ) |
|
301 | - && apply_filters('FHEE__EEG_Paypal_Standard__handle_payment_update__kill_refund_request', true) |
|
302 | - ) { |
|
303 | - throw new EventEspresso\core\exceptions\IpnException( |
|
304 | - sprintf( |
|
305 | - esc_html__('Event Espresso does not yet support %1$s IPNs from PayPal', 'event_espresso'), |
|
306 | - $update_info['payment_status'] |
|
307 | - ), |
|
308 | - EventEspresso\core\exceptions\IpnException::UNSUPPORTED, |
|
309 | - null, |
|
310 | - $payment, |
|
311 | - $update_info |
|
312 | - ); |
|
313 | - } |
|
314 | - //ok, well let's process this payment then! |
|
315 | - switch ($update_info['payment_status']) { |
|
316 | - |
|
317 | - case 'Completed' : |
|
318 | - $status = $this->_pay_model->approved_status(); |
|
319 | - $gateway_response = esc_html__('The payment is approved.', 'event_espresso'); |
|
320 | - break; |
|
321 | - |
|
322 | - case 'Pending' : |
|
323 | - $status = $this->_pay_model->pending_status(); |
|
324 | - $gateway_response = esc_html__( |
|
325 | - 'The payment is in progress. Another message will be sent when payment is approved.', |
|
326 | - 'event_espresso' |
|
327 | - ); |
|
328 | - break; |
|
329 | - |
|
330 | - case 'Denied' : |
|
331 | - $status = $this->_pay_model->declined_status(); |
|
332 | - $gateway_response = esc_html__('The payment has been declined.', 'event_espresso'); |
|
333 | - break; |
|
334 | - |
|
335 | - case 'Expired' : |
|
336 | - case 'Failed' : |
|
337 | - $status = $this->_pay_model->failed_status(); |
|
338 | - $gateway_response = esc_html__('The payment failed for technical reasons or expired.', 'event_espresso'); |
|
339 | - break; |
|
340 | - |
|
341 | - case 'Refunded' : |
|
342 | - case 'Partially_Refunded' : |
|
343 | - // even though it's a refund, we consider the payment as approved, it just has a negative value |
|
344 | - $status = $this->_pay_model->approved_status(); |
|
345 | - $gateway_response = esc_html__( |
|
346 | - 'The payment has been refunded. Please update registrations accordingly.', |
|
347 | - 'event_espresso' |
|
348 | - ); |
|
349 | - break; |
|
350 | - |
|
351 | - case 'Voided' : |
|
352 | - case 'Reversed' : |
|
353 | - case 'Canceled_Reversal' : |
|
354 | - default : |
|
355 | - $status = $this->_pay_model->cancelled_status(); |
|
356 | - $gateway_response = esc_html__( |
|
357 | - 'The payment was cancelled, reversed, or voided. Please update registrations accordingly.', |
|
358 | - 'event_espresso' |
|
359 | - ); |
|
360 | - break; |
|
361 | - |
|
362 | - } |
|
363 | - |
|
364 | - //check if we've already processed this payment |
|
365 | - if ($payment instanceof EEI_Payment) { |
|
366 | - //payment exists. if this has the exact same status and amount, don't bother updating. just return |
|
367 | - if ($payment->status() === $status && (float)$payment->amount() === (float)$update_info['mc_gross']) { |
|
368 | - // DUPLICATED IPN! don't bother updating transaction |
|
369 | - throw new IpnException( |
|
370 | - sprintf( |
|
371 | - esc_html__('It appears we have received a duplicate IPN from PayPal for payment %d', |
|
372 | - 'event_espresso' |
|
373 | - ), |
|
374 | - $payment->ID() |
|
375 | - ), |
|
376 | - IpnException::DUPLICATE, |
|
377 | - null, |
|
378 | - $payment, |
|
379 | - $update_info |
|
380 | - ); |
|
381 | - } else { |
|
382 | - // new payment yippee !!! |
|
383 | - $payment->set_status($status); |
|
384 | - $payment->set_amount((float)$update_info['mc_gross']); |
|
385 | - $payment->set_gateway_response($gateway_response); |
|
386 | - $payment->set_details($update_info); |
|
387 | - $payment->set_txn_id_chq_nmbr($update_info['txn_id']); |
|
388 | - $this->log( |
|
389 | - array( |
|
390 | - 'message' => esc_html__( |
|
391 | - 'Updated payment either from IPN or as part of POST from PayPal', |
|
392 | - 'event_espresso' |
|
393 | - ), |
|
394 | - 'url' => $this->_process_response_url(), |
|
395 | - 'payment' => $payment->model_field_array(), |
|
396 | - 'IPN_data' => $update_info |
|
397 | - ), |
|
398 | - $payment |
|
399 | - ); |
|
400 | - } |
|
401 | - |
|
402 | - } |
|
403 | - do_action('FHEE__EEG_Paypal_Standard__handle_payment_update__payment_processed', $payment, $this); |
|
404 | - return $payment; |
|
405 | - } |
|
406 | - |
|
407 | - |
|
408 | - /** |
|
409 | - * Validate the IPN notification. |
|
410 | - * |
|
411 | - * @param array $update_info like $_REQUEST |
|
412 | - * @param EE_Payment|EEI_Payment $payment |
|
413 | - * @return boolean |
|
414 | - * @throws \EE_Error |
|
415 | - */ |
|
416 | - public function validate_ipn($update_info, $payment) |
|
417 | - { |
|
418 | - //allow us to skip validating IPNs with PayPal (useful for testing) |
|
419 | - if (apply_filters('FHEE__EEG_Paypal_Standard__validate_ipn__skip', false)) { |
|
420 | - return true; |
|
421 | - } |
|
422 | - //...otherwise, we actually don't care what the $update_info is, we need to look |
|
423 | - //at the request directly because we can't use $update_info because it has issues with quotes |
|
424 | - // Reading POSTed data directly from $_POST causes serialization issues with array data in the POST. |
|
425 | - // Instead, read raw POST data from the input stream. |
|
426 | - // @see https://gist.github.com/xcommerce-gists/3440401 |
|
427 | - $raw_post_data = file_get_contents('php://input'); |
|
428 | - $raw_post_array = explode('&', $raw_post_data); |
|
429 | - $update_info = array(); |
|
430 | - foreach ($raw_post_array as $keyval) { |
|
431 | - $keyval = explode('=', $keyval); |
|
432 | - if (count($keyval) === 2) { |
|
433 | - $update_info[$keyval[0]] = urldecode($keyval[1]); |
|
434 | - } |
|
435 | - } |
|
436 | - // read the IPN message sent from PayPal and prepend 'cmd=_notify-validate' |
|
437 | - $req = 'cmd=_notify-validate'; |
|
438 | - $uses_get_magic_quotes = function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc() === 1 |
|
439 | - ? true |
|
440 | - : false; |
|
441 | - foreach ($update_info as $key => $value) { |
|
442 | - $value = $uses_get_magic_quotes ? urlencode(stripslashes($value)) : urlencode($value); |
|
443 | - $req .= "&$key=$value"; |
|
444 | - } |
|
445 | - // HTTP POST the complete, unaltered IPN back to PayPal |
|
446 | - $response = wp_remote_post( |
|
447 | - $this->_gateway_url, |
|
448 | - array( |
|
449 | - 'body' => $req, |
|
450 | - 'sslverify' => false, |
|
451 | - 'timeout' => 60, |
|
452 | - // make sure to set a site specific unique "user-agent" string since the WordPres default gets declined by PayPal |
|
453 | - // plz see: https://github.com/websharks/s2member/issues/610 |
|
454 | - 'user-agent' => 'Event Espresso v' . EVENT_ESPRESSO_VERSION . '; ' . home_url(), |
|
455 | - 'httpversion' => '1.1' |
|
456 | - ) |
|
457 | - ); |
|
458 | - // then check the response |
|
459 | - if ( |
|
460 | - array_key_exists('body', $response) |
|
461 | - && ! is_wp_error($response) |
|
462 | - && strcmp($response['body'], "VERIFIED") === 0 |
|
463 | - ) { |
|
464 | - return true; |
|
465 | - } |
|
466 | - // huh, something's wack... the IPN didn't validate. We must have replied to the IPN incorrectly, |
|
467 | - // or their API must have changed: http://www.paypalobjects.com/en_US/ebook/PP_OrderManagement_IntegrationGuide/ipn.html |
|
468 | - if ($response instanceof WP_Error) { |
|
469 | - $error_msg = sprintf( |
|
470 | - esc_html__('WP Error. Code: "%1$s", Message: "%2$s", Data: "%3$s"', 'event_espresso'), |
|
471 | - $response->get_error_code(), |
|
472 | - $response->get_error_message(), |
|
473 | - print_r($response->get_error_data(), true) |
|
474 | - ); |
|
475 | - } elseif(is_array($response) && isset($response['body'])) { |
|
476 | - $error_msg = $response['body']; |
|
477 | - } else { |
|
478 | - $error_msg = print_r($response, true); |
|
479 | - } |
|
480 | - $payment->set_gateway_response( |
|
481 | - sprintf( |
|
482 | - esc_html__("IPN Validation failed! Paypal responded with '%s'", "event_espresso"), |
|
483 | - $error_msg |
|
484 | - ) |
|
485 | - ); |
|
486 | - $payment->set_details(array('REQUEST' => $update_info, 'VALIDATION_RESPONSE' => $response)); |
|
487 | - $payment->set_status(EEM_Payment::status_id_failed); |
|
488 | - // log the results |
|
489 | - $this->log( |
|
490 | - array( |
|
491 | - 'url' => $this->_process_response_url(), |
|
492 | - 'message' => $payment->gateway_response(), |
|
493 | - 'details' => $payment->details(), |
|
494 | - ), |
|
495 | - $payment |
|
496 | - ); |
|
497 | - return false; |
|
498 | - } |
|
499 | - |
|
500 | - |
|
501 | - /** |
|
502 | - * _process_response_url |
|
503 | - * @return string |
|
504 | - */ |
|
505 | - protected function _process_response_url() |
|
506 | - { |
|
507 | - if (isset($_SERVER['HTTP_HOST'], $_SERVER['REQUEST_URI'])) { |
|
508 | - $url = is_ssl() ? 'https://' : 'http://'; |
|
509 | - $url .= EEH_URL::filter_input_server_url('HTTP_HOST'); |
|
510 | - $url .= EEH_URL::filter_input_server_url(); |
|
511 | - } else { |
|
512 | - $url = 'unknown'; |
|
513 | - } |
|
514 | - return $url; |
|
515 | - } |
|
516 | - |
|
517 | - |
|
518 | - /** |
|
519 | - * Updates the transaction and line items based on the payment IPN data from PayPal, |
|
520 | - * like the taxes or shipping |
|
521 | - * |
|
522 | - * @param EEI_Payment $payment |
|
523 | - * @throws \EE_Error |
|
524 | - */ |
|
525 | - public function update_txn_based_on_payment($payment) |
|
526 | - { |
|
527 | - $update_info = $payment->details(); |
|
528 | - /** @var EE_Transaction $transaction */ |
|
529 | - $transaction = $payment->transaction(); |
|
530 | - $payment_was_itemized = $payment->get_extra_meta(EEG_Paypal_Standard::itemized_payment_option_name, true, false); |
|
531 | - if (! $transaction) { |
|
532 | - $this->log( |
|
533 | - esc_html__( |
|
534 | - // @codingStandardsIgnoreStart |
|
535 | - 'Payment with ID %d has no related transaction, and so update_txn_based_on_payment couldn\'t be executed properly', |
|
536 | - // @codingStandardsIgnoreEnd |
|
537 | - 'event_espresso' |
|
538 | - ), |
|
539 | - $payment |
|
540 | - ); |
|
541 | - return; |
|
542 | - } |
|
543 | - if ( |
|
544 | - ! is_array($update_info) |
|
545 | - || ! isset($update_info['mc_shipping']) |
|
546 | - || ! isset($update_info['tax']) |
|
547 | - ) { |
|
548 | - $this->log( |
|
549 | - array( |
|
550 | - 'message' => esc_html__( |
|
551 | - // @codingStandardsIgnoreStart |
|
552 | - 'Could not update transaction based on payment because the payment details have not yet been put on the payment. This normally happens during the IPN or returning from PayPal', |
|
553 | - // @codingStandardsIgnoreEnd |
|
554 | - 'event_espresso' |
|
555 | - ), |
|
556 | - 'url' => $this->_process_response_url(), |
|
557 | - 'payment' => $payment->model_field_array() |
|
558 | - ), |
|
559 | - $payment |
|
560 | - ); |
|
561 | - return; |
|
562 | - } |
|
563 | - if ($payment->status() !== $this->_pay_model->approved_status()) { |
|
564 | - $this->log( |
|
565 | - array( |
|
566 | - 'message' => esc_html__( |
|
567 | - 'We shouldn\'t update transactions taxes or shipping data from non-approved payments', |
|
568 | - 'event_espresso' |
|
569 | - ), |
|
570 | - 'url' => $this->_process_response_url(), |
|
571 | - 'payment' => $payment->model_field_array() |
|
572 | - ), |
|
573 | - $payment |
|
574 | - ); |
|
575 | - return; |
|
576 | - } |
|
577 | - $grand_total_needs_resaving = false; |
|
578 | - /** @var EE_Line_Item $transaction_total_line_item */ |
|
579 | - $transaction_total_line_item = $transaction->total_line_item(); |
|
580 | - |
|
581 | - //might paypal have changed the taxes? |
|
582 | - if ($this->_paypal_taxes && $payment_was_itemized) { |
|
583 | - // note that we're doing this BEFORE adding shipping; |
|
584 | - // we actually want PayPal's shipping to remain non-taxable |
|
585 | - $this->_line_item->set_line_items_taxable($transaction_total_line_item, true, 'paypal_shipping'); |
|
586 | - $this->_line_item->set_total_tax_to( |
|
587 | - $transaction_total_line_item, |
|
588 | - (float)$update_info['tax'], |
|
589 | - esc_html__('Taxes', 'event_espresso'), |
|
590 | - esc_html__('Calculated by Paypal', 'event_espresso'), |
|
591 | - 'paypal_tax' |
|
592 | - ); |
|
593 | - $grand_total_needs_resaving = TRUE; |
|
594 | - } |
|
595 | - |
|
596 | - $shipping_amount = (float)$update_info['mc_shipping']; |
|
597 | - //might paypal have added shipping? |
|
598 | - if ($this->_paypal_shipping && $shipping_amount && $payment_was_itemized) { |
|
599 | - $this->_line_item->add_unrelated_item( |
|
600 | - $transaction_total_line_item, |
|
601 | - sprintf(esc_html__('Shipping for transaction %1$s', 'event_espresso'), $transaction->ID()), |
|
602 | - $shipping_amount, |
|
603 | - esc_html__('Shipping charges calculated by Paypal', 'event_espresso'), |
|
604 | - 1, |
|
605 | - false, |
|
606 | - 'paypal_shipping_' . $transaction->ID() |
|
607 | - ); |
|
608 | - $grand_total_needs_resaving = true; |
|
609 | - } |
|
610 | - |
|
611 | - if ($grand_total_needs_resaving) { |
|
612 | - $transaction_total_line_item->save_this_and_descendants_to_txn($transaction->ID()); |
|
613 | - /** @var EE_Registration_Processor $registration_processor */ |
|
614 | - $registration_processor = EE_Registry::instance()->load_class('Registration_Processor'); |
|
615 | - $registration_processor->update_registration_final_prices($transaction); |
|
616 | - } |
|
617 | - $this->log( |
|
618 | - array( |
|
619 | - 'message' => esc_html__('Updated transaction related to payment', 'event_espresso'), |
|
620 | - 'url' => $this->_process_response_url(), |
|
621 | - 'transaction (updated)' => $transaction->model_field_array(), |
|
622 | - 'payment (updated)' => $payment->model_field_array(), |
|
623 | - 'use_paypal_shipping' => $this->_paypal_shipping, |
|
624 | - 'use_paypal_tax' => $this->_paypal_taxes, |
|
625 | - 'grand_total_needed_resaving' => $grand_total_needs_resaving, |
|
626 | - ), |
|
627 | - $payment |
|
628 | - ); |
|
629 | - } |
|
215 | + $redirect_args['shipping_' . $item_num] = '0'; |
|
216 | + $redirect_args['shipping2_' . $item_num] = '0'; |
|
217 | + } |
|
218 | + |
|
219 | + $redirect_args['business'] = $this->_paypal_id; |
|
220 | + $redirect_args['return'] = $return_url; |
|
221 | + $redirect_args['cancel_return'] = $cancel_url; |
|
222 | + $redirect_args['notify_url'] = $notify_url; |
|
223 | + $redirect_args['cmd'] = '_cart'; |
|
224 | + $redirect_args['upload'] = 1; |
|
225 | + $redirect_args['currency_code'] = $payment->currency_code(); |
|
226 | + $redirect_args['rm'] = 2;//makes the user return with method=POST |
|
227 | + if ($this->_image_url) { |
|
228 | + $redirect_args['image_url'] = $this->_image_url; |
|
229 | + } |
|
230 | + $redirect_args['no_shipping'] = $this->_shipping_details; |
|
231 | + $redirect_args['bn'] = 'EventEspresso_SP';//EE will blow up if you change this |
|
232 | + |
|
233 | + $redirect_args = apply_filters("FHEE__EEG_Paypal_Standard__set_redirection_info__arguments", $redirect_args, $this); |
|
234 | + |
|
235 | + $payment->set_redirect_url($this->_gateway_url); |
|
236 | + $payment->set_redirect_args($redirect_args); |
|
237 | + // log the results |
|
238 | + $this->log( |
|
239 | + array( |
|
240 | + 'message' => sprintf( |
|
241 | + __('PayPal payment request initiated.', 'event_espresso') |
|
242 | + ), |
|
243 | + 'transaction' => $transaction->model_field_array(), |
|
244 | + ), |
|
245 | + $payment |
|
246 | + ); |
|
247 | + return $payment; |
|
248 | + } |
|
249 | + |
|
250 | + |
|
251 | + /** |
|
252 | + * Often used for IPNs. But applies the info in $update_info to the payment. |
|
253 | + * What is $update_info? Often the contents of $_REQUEST, but not necessarily. Whatever |
|
254 | + * the payment method passes in. |
|
255 | + * |
|
256 | + * @param array $update_info like $_POST |
|
257 | + * @param EEI_Transaction $transaction |
|
258 | + * @return \EEI_Payment updated |
|
259 | + * @throws \EE_Error, IpnException |
|
260 | + */ |
|
261 | + public function handle_payment_update($update_info, $transaction) |
|
262 | + { |
|
263 | + // verify there's payment data that's been sent |
|
264 | + if (empty($update_info['payment_status'] ) || empty($update_info['txn_id'])) { |
|
265 | + // log the results |
|
266 | + $this->log( |
|
267 | + array( |
|
268 | + 'message' => sprintf( |
|
269 | + // @codingStandardsIgnoreStart |
|
270 | + __('PayPal IPN response is missing critical payment data. This may indicate a PDT request and require your PayPal account settings to be corrected.', 'event_espresso') |
|
271 | + // @codingStandardsIgnoreEnd |
|
272 | + ), |
|
273 | + 'update_info' => $update_info, |
|
274 | + ), |
|
275 | + $transaction |
|
276 | + ); |
|
277 | + // waaaait... is this a PDT request? (see https://developer.paypal.com/docs/classic/products/payment-data-transfer/) |
|
278 | + // indicated by the "tx" argument? If so, we don't need it. We'll just use the IPN data when it comes |
|
279 | + if (isset($update_info['tx'])) { |
|
280 | + return $transaction->last_payment(); |
|
281 | + } else { |
|
282 | + return null; |
|
283 | + } |
|
284 | + } |
|
285 | + $payment = $this->_pay_model->get_payment_by_txn_id_chq_nmbr($update_info['txn_id']); |
|
286 | + if (! $payment instanceof EEI_Payment) { |
|
287 | + $payment = $transaction->last_payment(); |
|
288 | + } |
|
289 | + // ok, then validate the IPN. Even if we've already processed this payment, |
|
290 | + // let PayPal know we don't want to hear from them anymore! |
|
291 | + if (! $this->validate_ipn($update_info, $payment)) { |
|
292 | + return $payment; |
|
293 | + } |
|
294 | + // kill request here if this is a refund, we don't support them yet (we'd need to adjust the transaction, |
|
295 | + // registrations, ticket counts, etc) |
|
296 | + if ( |
|
297 | + ( |
|
298 | + $update_info['payment_status'] === 'Refunded' |
|
299 | + || $update_info['payment_status'] === 'Partially_Refunded' |
|
300 | + ) |
|
301 | + && apply_filters('FHEE__EEG_Paypal_Standard__handle_payment_update__kill_refund_request', true) |
|
302 | + ) { |
|
303 | + throw new EventEspresso\core\exceptions\IpnException( |
|
304 | + sprintf( |
|
305 | + esc_html__('Event Espresso does not yet support %1$s IPNs from PayPal', 'event_espresso'), |
|
306 | + $update_info['payment_status'] |
|
307 | + ), |
|
308 | + EventEspresso\core\exceptions\IpnException::UNSUPPORTED, |
|
309 | + null, |
|
310 | + $payment, |
|
311 | + $update_info |
|
312 | + ); |
|
313 | + } |
|
314 | + //ok, well let's process this payment then! |
|
315 | + switch ($update_info['payment_status']) { |
|
316 | + |
|
317 | + case 'Completed' : |
|
318 | + $status = $this->_pay_model->approved_status(); |
|
319 | + $gateway_response = esc_html__('The payment is approved.', 'event_espresso'); |
|
320 | + break; |
|
321 | + |
|
322 | + case 'Pending' : |
|
323 | + $status = $this->_pay_model->pending_status(); |
|
324 | + $gateway_response = esc_html__( |
|
325 | + 'The payment is in progress. Another message will be sent when payment is approved.', |
|
326 | + 'event_espresso' |
|
327 | + ); |
|
328 | + break; |
|
329 | + |
|
330 | + case 'Denied' : |
|
331 | + $status = $this->_pay_model->declined_status(); |
|
332 | + $gateway_response = esc_html__('The payment has been declined.', 'event_espresso'); |
|
333 | + break; |
|
334 | + |
|
335 | + case 'Expired' : |
|
336 | + case 'Failed' : |
|
337 | + $status = $this->_pay_model->failed_status(); |
|
338 | + $gateway_response = esc_html__('The payment failed for technical reasons or expired.', 'event_espresso'); |
|
339 | + break; |
|
340 | + |
|
341 | + case 'Refunded' : |
|
342 | + case 'Partially_Refunded' : |
|
343 | + // even though it's a refund, we consider the payment as approved, it just has a negative value |
|
344 | + $status = $this->_pay_model->approved_status(); |
|
345 | + $gateway_response = esc_html__( |
|
346 | + 'The payment has been refunded. Please update registrations accordingly.', |
|
347 | + 'event_espresso' |
|
348 | + ); |
|
349 | + break; |
|
350 | + |
|
351 | + case 'Voided' : |
|
352 | + case 'Reversed' : |
|
353 | + case 'Canceled_Reversal' : |
|
354 | + default : |
|
355 | + $status = $this->_pay_model->cancelled_status(); |
|
356 | + $gateway_response = esc_html__( |
|
357 | + 'The payment was cancelled, reversed, or voided. Please update registrations accordingly.', |
|
358 | + 'event_espresso' |
|
359 | + ); |
|
360 | + break; |
|
361 | + |
|
362 | + } |
|
363 | + |
|
364 | + //check if we've already processed this payment |
|
365 | + if ($payment instanceof EEI_Payment) { |
|
366 | + //payment exists. if this has the exact same status and amount, don't bother updating. just return |
|
367 | + if ($payment->status() === $status && (float)$payment->amount() === (float)$update_info['mc_gross']) { |
|
368 | + // DUPLICATED IPN! don't bother updating transaction |
|
369 | + throw new IpnException( |
|
370 | + sprintf( |
|
371 | + esc_html__('It appears we have received a duplicate IPN from PayPal for payment %d', |
|
372 | + 'event_espresso' |
|
373 | + ), |
|
374 | + $payment->ID() |
|
375 | + ), |
|
376 | + IpnException::DUPLICATE, |
|
377 | + null, |
|
378 | + $payment, |
|
379 | + $update_info |
|
380 | + ); |
|
381 | + } else { |
|
382 | + // new payment yippee !!! |
|
383 | + $payment->set_status($status); |
|
384 | + $payment->set_amount((float)$update_info['mc_gross']); |
|
385 | + $payment->set_gateway_response($gateway_response); |
|
386 | + $payment->set_details($update_info); |
|
387 | + $payment->set_txn_id_chq_nmbr($update_info['txn_id']); |
|
388 | + $this->log( |
|
389 | + array( |
|
390 | + 'message' => esc_html__( |
|
391 | + 'Updated payment either from IPN or as part of POST from PayPal', |
|
392 | + 'event_espresso' |
|
393 | + ), |
|
394 | + 'url' => $this->_process_response_url(), |
|
395 | + 'payment' => $payment->model_field_array(), |
|
396 | + 'IPN_data' => $update_info |
|
397 | + ), |
|
398 | + $payment |
|
399 | + ); |
|
400 | + } |
|
401 | + |
|
402 | + } |
|
403 | + do_action('FHEE__EEG_Paypal_Standard__handle_payment_update__payment_processed', $payment, $this); |
|
404 | + return $payment; |
|
405 | + } |
|
406 | + |
|
407 | + |
|
408 | + /** |
|
409 | + * Validate the IPN notification. |
|
410 | + * |
|
411 | + * @param array $update_info like $_REQUEST |
|
412 | + * @param EE_Payment|EEI_Payment $payment |
|
413 | + * @return boolean |
|
414 | + * @throws \EE_Error |
|
415 | + */ |
|
416 | + public function validate_ipn($update_info, $payment) |
|
417 | + { |
|
418 | + //allow us to skip validating IPNs with PayPal (useful for testing) |
|
419 | + if (apply_filters('FHEE__EEG_Paypal_Standard__validate_ipn__skip', false)) { |
|
420 | + return true; |
|
421 | + } |
|
422 | + //...otherwise, we actually don't care what the $update_info is, we need to look |
|
423 | + //at the request directly because we can't use $update_info because it has issues with quotes |
|
424 | + // Reading POSTed data directly from $_POST causes serialization issues with array data in the POST. |
|
425 | + // Instead, read raw POST data from the input stream. |
|
426 | + // @see https://gist.github.com/xcommerce-gists/3440401 |
|
427 | + $raw_post_data = file_get_contents('php://input'); |
|
428 | + $raw_post_array = explode('&', $raw_post_data); |
|
429 | + $update_info = array(); |
|
430 | + foreach ($raw_post_array as $keyval) { |
|
431 | + $keyval = explode('=', $keyval); |
|
432 | + if (count($keyval) === 2) { |
|
433 | + $update_info[$keyval[0]] = urldecode($keyval[1]); |
|
434 | + } |
|
435 | + } |
|
436 | + // read the IPN message sent from PayPal and prepend 'cmd=_notify-validate' |
|
437 | + $req = 'cmd=_notify-validate'; |
|
438 | + $uses_get_magic_quotes = function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc() === 1 |
|
439 | + ? true |
|
440 | + : false; |
|
441 | + foreach ($update_info as $key => $value) { |
|
442 | + $value = $uses_get_magic_quotes ? urlencode(stripslashes($value)) : urlencode($value); |
|
443 | + $req .= "&$key=$value"; |
|
444 | + } |
|
445 | + // HTTP POST the complete, unaltered IPN back to PayPal |
|
446 | + $response = wp_remote_post( |
|
447 | + $this->_gateway_url, |
|
448 | + array( |
|
449 | + 'body' => $req, |
|
450 | + 'sslverify' => false, |
|
451 | + 'timeout' => 60, |
|
452 | + // make sure to set a site specific unique "user-agent" string since the WordPres default gets declined by PayPal |
|
453 | + // plz see: https://github.com/websharks/s2member/issues/610 |
|
454 | + 'user-agent' => 'Event Espresso v' . EVENT_ESPRESSO_VERSION . '; ' . home_url(), |
|
455 | + 'httpversion' => '1.1' |
|
456 | + ) |
|
457 | + ); |
|
458 | + // then check the response |
|
459 | + if ( |
|
460 | + array_key_exists('body', $response) |
|
461 | + && ! is_wp_error($response) |
|
462 | + && strcmp($response['body'], "VERIFIED") === 0 |
|
463 | + ) { |
|
464 | + return true; |
|
465 | + } |
|
466 | + // huh, something's wack... the IPN didn't validate. We must have replied to the IPN incorrectly, |
|
467 | + // or their API must have changed: http://www.paypalobjects.com/en_US/ebook/PP_OrderManagement_IntegrationGuide/ipn.html |
|
468 | + if ($response instanceof WP_Error) { |
|
469 | + $error_msg = sprintf( |
|
470 | + esc_html__('WP Error. Code: "%1$s", Message: "%2$s", Data: "%3$s"', 'event_espresso'), |
|
471 | + $response->get_error_code(), |
|
472 | + $response->get_error_message(), |
|
473 | + print_r($response->get_error_data(), true) |
|
474 | + ); |
|
475 | + } elseif(is_array($response) && isset($response['body'])) { |
|
476 | + $error_msg = $response['body']; |
|
477 | + } else { |
|
478 | + $error_msg = print_r($response, true); |
|
479 | + } |
|
480 | + $payment->set_gateway_response( |
|
481 | + sprintf( |
|
482 | + esc_html__("IPN Validation failed! Paypal responded with '%s'", "event_espresso"), |
|
483 | + $error_msg |
|
484 | + ) |
|
485 | + ); |
|
486 | + $payment->set_details(array('REQUEST' => $update_info, 'VALIDATION_RESPONSE' => $response)); |
|
487 | + $payment->set_status(EEM_Payment::status_id_failed); |
|
488 | + // log the results |
|
489 | + $this->log( |
|
490 | + array( |
|
491 | + 'url' => $this->_process_response_url(), |
|
492 | + 'message' => $payment->gateway_response(), |
|
493 | + 'details' => $payment->details(), |
|
494 | + ), |
|
495 | + $payment |
|
496 | + ); |
|
497 | + return false; |
|
498 | + } |
|
499 | + |
|
500 | + |
|
501 | + /** |
|
502 | + * _process_response_url |
|
503 | + * @return string |
|
504 | + */ |
|
505 | + protected function _process_response_url() |
|
506 | + { |
|
507 | + if (isset($_SERVER['HTTP_HOST'], $_SERVER['REQUEST_URI'])) { |
|
508 | + $url = is_ssl() ? 'https://' : 'http://'; |
|
509 | + $url .= EEH_URL::filter_input_server_url('HTTP_HOST'); |
|
510 | + $url .= EEH_URL::filter_input_server_url(); |
|
511 | + } else { |
|
512 | + $url = 'unknown'; |
|
513 | + } |
|
514 | + return $url; |
|
515 | + } |
|
516 | + |
|
517 | + |
|
518 | + /** |
|
519 | + * Updates the transaction and line items based on the payment IPN data from PayPal, |
|
520 | + * like the taxes or shipping |
|
521 | + * |
|
522 | + * @param EEI_Payment $payment |
|
523 | + * @throws \EE_Error |
|
524 | + */ |
|
525 | + public function update_txn_based_on_payment($payment) |
|
526 | + { |
|
527 | + $update_info = $payment->details(); |
|
528 | + /** @var EE_Transaction $transaction */ |
|
529 | + $transaction = $payment->transaction(); |
|
530 | + $payment_was_itemized = $payment->get_extra_meta(EEG_Paypal_Standard::itemized_payment_option_name, true, false); |
|
531 | + if (! $transaction) { |
|
532 | + $this->log( |
|
533 | + esc_html__( |
|
534 | + // @codingStandardsIgnoreStart |
|
535 | + 'Payment with ID %d has no related transaction, and so update_txn_based_on_payment couldn\'t be executed properly', |
|
536 | + // @codingStandardsIgnoreEnd |
|
537 | + 'event_espresso' |
|
538 | + ), |
|
539 | + $payment |
|
540 | + ); |
|
541 | + return; |
|
542 | + } |
|
543 | + if ( |
|
544 | + ! is_array($update_info) |
|
545 | + || ! isset($update_info['mc_shipping']) |
|
546 | + || ! isset($update_info['tax']) |
|
547 | + ) { |
|
548 | + $this->log( |
|
549 | + array( |
|
550 | + 'message' => esc_html__( |
|
551 | + // @codingStandardsIgnoreStart |
|
552 | + 'Could not update transaction based on payment because the payment details have not yet been put on the payment. This normally happens during the IPN or returning from PayPal', |
|
553 | + // @codingStandardsIgnoreEnd |
|
554 | + 'event_espresso' |
|
555 | + ), |
|
556 | + 'url' => $this->_process_response_url(), |
|
557 | + 'payment' => $payment->model_field_array() |
|
558 | + ), |
|
559 | + $payment |
|
560 | + ); |
|
561 | + return; |
|
562 | + } |
|
563 | + if ($payment->status() !== $this->_pay_model->approved_status()) { |
|
564 | + $this->log( |
|
565 | + array( |
|
566 | + 'message' => esc_html__( |
|
567 | + 'We shouldn\'t update transactions taxes or shipping data from non-approved payments', |
|
568 | + 'event_espresso' |
|
569 | + ), |
|
570 | + 'url' => $this->_process_response_url(), |
|
571 | + 'payment' => $payment->model_field_array() |
|
572 | + ), |
|
573 | + $payment |
|
574 | + ); |
|
575 | + return; |
|
576 | + } |
|
577 | + $grand_total_needs_resaving = false; |
|
578 | + /** @var EE_Line_Item $transaction_total_line_item */ |
|
579 | + $transaction_total_line_item = $transaction->total_line_item(); |
|
580 | + |
|
581 | + //might paypal have changed the taxes? |
|
582 | + if ($this->_paypal_taxes && $payment_was_itemized) { |
|
583 | + // note that we're doing this BEFORE adding shipping; |
|
584 | + // we actually want PayPal's shipping to remain non-taxable |
|
585 | + $this->_line_item->set_line_items_taxable($transaction_total_line_item, true, 'paypal_shipping'); |
|
586 | + $this->_line_item->set_total_tax_to( |
|
587 | + $transaction_total_line_item, |
|
588 | + (float)$update_info['tax'], |
|
589 | + esc_html__('Taxes', 'event_espresso'), |
|
590 | + esc_html__('Calculated by Paypal', 'event_espresso'), |
|
591 | + 'paypal_tax' |
|
592 | + ); |
|
593 | + $grand_total_needs_resaving = TRUE; |
|
594 | + } |
|
595 | + |
|
596 | + $shipping_amount = (float)$update_info['mc_shipping']; |
|
597 | + //might paypal have added shipping? |
|
598 | + if ($this->_paypal_shipping && $shipping_amount && $payment_was_itemized) { |
|
599 | + $this->_line_item->add_unrelated_item( |
|
600 | + $transaction_total_line_item, |
|
601 | + sprintf(esc_html__('Shipping for transaction %1$s', 'event_espresso'), $transaction->ID()), |
|
602 | + $shipping_amount, |
|
603 | + esc_html__('Shipping charges calculated by Paypal', 'event_espresso'), |
|
604 | + 1, |
|
605 | + false, |
|
606 | + 'paypal_shipping_' . $transaction->ID() |
|
607 | + ); |
|
608 | + $grand_total_needs_resaving = true; |
|
609 | + } |
|
610 | + |
|
611 | + if ($grand_total_needs_resaving) { |
|
612 | + $transaction_total_line_item->save_this_and_descendants_to_txn($transaction->ID()); |
|
613 | + /** @var EE_Registration_Processor $registration_processor */ |
|
614 | + $registration_processor = EE_Registry::instance()->load_class('Registration_Processor'); |
|
615 | + $registration_processor->update_registration_final_prices($transaction); |
|
616 | + } |
|
617 | + $this->log( |
|
618 | + array( |
|
619 | + 'message' => esc_html__('Updated transaction related to payment', 'event_espresso'), |
|
620 | + 'url' => $this->_process_response_url(), |
|
621 | + 'transaction (updated)' => $transaction->model_field_array(), |
|
622 | + 'payment (updated)' => $payment->model_field_array(), |
|
623 | + 'use_paypal_shipping' => $this->_paypal_shipping, |
|
624 | + 'use_paypal_tax' => $this->_paypal_taxes, |
|
625 | + 'grand_total_needed_resaving' => $grand_total_needs_resaving, |
|
626 | + ), |
|
627 | + $payment |
|
628 | + ); |
|
629 | + } |
|
630 | 630 | } |
631 | 631 | // End of file EEG_Paypal_Standard.gateway.php |
632 | 632 | \ No newline at end of file |
@@ -2,7 +2,7 @@ discard block |
||
2 | 2 | |
3 | 3 | use EventEspresso\core\exceptions\IpnException; |
4 | 4 | |
5 | -if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
5 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
6 | 6 | exit('NO direct script access allowed'); |
7 | 7 | } |
8 | 8 | |
@@ -143,16 +143,16 @@ discard block |
||
143 | 143 | $shipping_previously_added = $line_item->total(); |
144 | 144 | continue; |
145 | 145 | } |
146 | - $redirect_args['item_name_' . $item_num] = substr( |
|
146 | + $redirect_args['item_name_'.$item_num] = substr( |
|
147 | 147 | $gateway_formatter->formatLineItemName($line_item, $payment), |
148 | 148 | 0, 127 |
149 | 149 | ); |
150 | - $redirect_args['amount_' . $item_num] = $line_item->unit_price(); |
|
151 | - $redirect_args['quantity_' . $item_num] = $line_item->quantity(); |
|
150 | + $redirect_args['amount_'.$item_num] = $line_item->unit_price(); |
|
151 | + $redirect_args['quantity_'.$item_num] = $line_item->quantity(); |
|
152 | 152 | //if we're not letting PayPal calculate shipping, tell them its 0 |
153 | - if (! $this->_paypal_shipping) { |
|
154 | - $redirect_args['shipping_' . $item_num] = '0'; |
|
155 | - $redirect_args['shipping2_' . $item_num] = '0'; |
|
153 | + if ( ! $this->_paypal_shipping) { |
|
154 | + $redirect_args['shipping_'.$item_num] = '0'; |
|
155 | + $redirect_args['shipping2_'.$item_num] = '0'; |
|
156 | 156 | } |
157 | 157 | $item_num++; |
158 | 158 | $itemized_sum += $line_item->total(); |
@@ -172,12 +172,12 @@ discard block |
||
172 | 172 | //itemized sum is too big |
173 | 173 | $total_discounts_to_cart_total += abs($itemized_sum_diff_from_txn_total); |
174 | 174 | } elseif ($itemized_sum_diff_from_txn_total > 0) { |
175 | - $redirect_args['item_name_' . $item_num] = substr( |
|
176 | - __('Other charges', 'event_espresso' ), 0, 127); |
|
177 | - $redirect_args['amount_' . $item_num] = $gateway_formatter->formatCurrency( |
|
175 | + $redirect_args['item_name_'.$item_num] = substr( |
|
176 | + __('Other charges', 'event_espresso'), 0, 127); |
|
177 | + $redirect_args['amount_'.$item_num] = $gateway_formatter->formatCurrency( |
|
178 | 178 | $itemized_sum_diff_from_txn_total |
179 | 179 | ); |
180 | - $redirect_args['quantity_' . $item_num] = 1; |
|
180 | + $redirect_args['quantity_'.$item_num] = 1; |
|
181 | 181 | $item_num++; |
182 | 182 | } |
183 | 183 | if ($total_discounts_to_cart_total > 0) { |
@@ -186,34 +186,34 @@ discard block |
||
186 | 186 | ); |
187 | 187 | } |
188 | 188 | //add our taxes to the order if we're NOT using PayPal's |
189 | - if (! $this->_paypal_taxes) { |
|
189 | + if ( ! $this->_paypal_taxes) { |
|
190 | 190 | $redirect_args['tax_cart'] = $total_line_item->get_total_tax(); |
191 | 191 | } |
192 | 192 | } else { |
193 | 193 | $payment->update_extra_meta(EEG_Paypal_Standard::itemized_payment_option_name, false); |
194 | 194 | //partial payment that's not for the remaining amount, so we can't send an itemized list |
195 | - $redirect_args['item_name_' . $item_num] = substr( |
|
195 | + $redirect_args['item_name_'.$item_num] = substr( |
|
196 | 196 | $gateway_formatter->formatPartialPaymentLineItemName($payment), |
197 | 197 | 0, |
198 | 198 | 127 |
199 | 199 | ); |
200 | - $redirect_args['amount_' . $item_num] = $payment->amount(); |
|
201 | - $redirect_args['shipping_' . $item_num] = '0'; |
|
202 | - $redirect_args['shipping2_' . $item_num] = '0'; |
|
200 | + $redirect_args['amount_'.$item_num] = $payment->amount(); |
|
201 | + $redirect_args['shipping_'.$item_num] = '0'; |
|
202 | + $redirect_args['shipping2_'.$item_num] = '0'; |
|
203 | 203 | $redirect_args['tax_cart'] = '0'; |
204 | 204 | $item_num++; |
205 | 205 | } |
206 | 206 | |
207 | 207 | if ($this->_debug_mode) { |
208 | - $redirect_args['item_name_' . $item_num] = 'DEBUG INFO (this item only added in sandbox mode'; |
|
209 | - $redirect_args['amount_' . $item_num] = 0; |
|
208 | + $redirect_args['item_name_'.$item_num] = 'DEBUG INFO (this item only added in sandbox mode'; |
|
209 | + $redirect_args['amount_'.$item_num] = 0; |
|
210 | 210 | $redirect_args['on0_'.$item_num] = 'NOTIFY URL'; |
211 | - $redirect_args['os0_' . $item_num] = $notify_url; |
|
211 | + $redirect_args['os0_'.$item_num] = $notify_url; |
|
212 | 212 | $redirect_args['on1_'.$item_num] = 'RETURN URL'; |
213 | - $redirect_args['os1_' . $item_num] = $return_url; |
|
213 | + $redirect_args['os1_'.$item_num] = $return_url; |
|
214 | 214 | // $redirect_args['option_index_' . $item_num] = 1; // <-- dunno if this is needed ? |
215 | - $redirect_args['shipping_' . $item_num] = '0'; |
|
216 | - $redirect_args['shipping2_' . $item_num] = '0'; |
|
215 | + $redirect_args['shipping_'.$item_num] = '0'; |
|
216 | + $redirect_args['shipping2_'.$item_num] = '0'; |
|
217 | 217 | } |
218 | 218 | |
219 | 219 | $redirect_args['business'] = $this->_paypal_id; |
@@ -223,12 +223,12 @@ discard block |
||
223 | 223 | $redirect_args['cmd'] = '_cart'; |
224 | 224 | $redirect_args['upload'] = 1; |
225 | 225 | $redirect_args['currency_code'] = $payment->currency_code(); |
226 | - $redirect_args['rm'] = 2;//makes the user return with method=POST |
|
226 | + $redirect_args['rm'] = 2; //makes the user return with method=POST |
|
227 | 227 | if ($this->_image_url) { |
228 | 228 | $redirect_args['image_url'] = $this->_image_url; |
229 | 229 | } |
230 | 230 | $redirect_args['no_shipping'] = $this->_shipping_details; |
231 | - $redirect_args['bn'] = 'EventEspresso_SP';//EE will blow up if you change this |
|
231 | + $redirect_args['bn'] = 'EventEspresso_SP'; //EE will blow up if you change this |
|
232 | 232 | |
233 | 233 | $redirect_args = apply_filters("FHEE__EEG_Paypal_Standard__set_redirection_info__arguments", $redirect_args, $this); |
234 | 234 | |
@@ -261,7 +261,7 @@ discard block |
||
261 | 261 | public function handle_payment_update($update_info, $transaction) |
262 | 262 | { |
263 | 263 | // verify there's payment data that's been sent |
264 | - if (empty($update_info['payment_status'] ) || empty($update_info['txn_id'])) { |
|
264 | + if (empty($update_info['payment_status']) || empty($update_info['txn_id'])) { |
|
265 | 265 | // log the results |
266 | 266 | $this->log( |
267 | 267 | array( |
@@ -283,12 +283,12 @@ discard block |
||
283 | 283 | } |
284 | 284 | } |
285 | 285 | $payment = $this->_pay_model->get_payment_by_txn_id_chq_nmbr($update_info['txn_id']); |
286 | - if (! $payment instanceof EEI_Payment) { |
|
286 | + if ( ! $payment instanceof EEI_Payment) { |
|
287 | 287 | $payment = $transaction->last_payment(); |
288 | 288 | } |
289 | 289 | // ok, then validate the IPN. Even if we've already processed this payment, |
290 | 290 | // let PayPal know we don't want to hear from them anymore! |
291 | - if (! $this->validate_ipn($update_info, $payment)) { |
|
291 | + if ( ! $this->validate_ipn($update_info, $payment)) { |
|
292 | 292 | return $payment; |
293 | 293 | } |
294 | 294 | // kill request here if this is a refund, we don't support them yet (we'd need to adjust the transaction, |
@@ -364,7 +364,7 @@ discard block |
||
364 | 364 | //check if we've already processed this payment |
365 | 365 | if ($payment instanceof EEI_Payment) { |
366 | 366 | //payment exists. if this has the exact same status and amount, don't bother updating. just return |
367 | - if ($payment->status() === $status && (float)$payment->amount() === (float)$update_info['mc_gross']) { |
|
367 | + if ($payment->status() === $status && (float) $payment->amount() === (float) $update_info['mc_gross']) { |
|
368 | 368 | // DUPLICATED IPN! don't bother updating transaction |
369 | 369 | throw new IpnException( |
370 | 370 | sprintf( |
@@ -381,7 +381,7 @@ discard block |
||
381 | 381 | } else { |
382 | 382 | // new payment yippee !!! |
383 | 383 | $payment->set_status($status); |
384 | - $payment->set_amount((float)$update_info['mc_gross']); |
|
384 | + $payment->set_amount((float) $update_info['mc_gross']); |
|
385 | 385 | $payment->set_gateway_response($gateway_response); |
386 | 386 | $payment->set_details($update_info); |
387 | 387 | $payment->set_txn_id_chq_nmbr($update_info['txn_id']); |
@@ -451,7 +451,7 @@ discard block |
||
451 | 451 | 'timeout' => 60, |
452 | 452 | // make sure to set a site specific unique "user-agent" string since the WordPres default gets declined by PayPal |
453 | 453 | // plz see: https://github.com/websharks/s2member/issues/610 |
454 | - 'user-agent' => 'Event Espresso v' . EVENT_ESPRESSO_VERSION . '; ' . home_url(), |
|
454 | + 'user-agent' => 'Event Espresso v'.EVENT_ESPRESSO_VERSION.'; '.home_url(), |
|
455 | 455 | 'httpversion' => '1.1' |
456 | 456 | ) |
457 | 457 | ); |
@@ -472,7 +472,7 @@ discard block |
||
472 | 472 | $response->get_error_message(), |
473 | 473 | print_r($response->get_error_data(), true) |
474 | 474 | ); |
475 | - } elseif(is_array($response) && isset($response['body'])) { |
|
475 | + } elseif (is_array($response) && isset($response['body'])) { |
|
476 | 476 | $error_msg = $response['body']; |
477 | 477 | } else { |
478 | 478 | $error_msg = print_r($response, true); |
@@ -528,7 +528,7 @@ discard block |
||
528 | 528 | /** @var EE_Transaction $transaction */ |
529 | 529 | $transaction = $payment->transaction(); |
530 | 530 | $payment_was_itemized = $payment->get_extra_meta(EEG_Paypal_Standard::itemized_payment_option_name, true, false); |
531 | - if (! $transaction) { |
|
531 | + if ( ! $transaction) { |
|
532 | 532 | $this->log( |
533 | 533 | esc_html__( |
534 | 534 | // @codingStandardsIgnoreStart |
@@ -585,7 +585,7 @@ discard block |
||
585 | 585 | $this->_line_item->set_line_items_taxable($transaction_total_line_item, true, 'paypal_shipping'); |
586 | 586 | $this->_line_item->set_total_tax_to( |
587 | 587 | $transaction_total_line_item, |
588 | - (float)$update_info['tax'], |
|
588 | + (float) $update_info['tax'], |
|
589 | 589 | esc_html__('Taxes', 'event_espresso'), |
590 | 590 | esc_html__('Calculated by Paypal', 'event_espresso'), |
591 | 591 | 'paypal_tax' |
@@ -593,7 +593,7 @@ discard block |
||
593 | 593 | $grand_total_needs_resaving = TRUE; |
594 | 594 | } |
595 | 595 | |
596 | - $shipping_amount = (float)$update_info['mc_shipping']; |
|
596 | + $shipping_amount = (float) $update_info['mc_shipping']; |
|
597 | 597 | //might paypal have added shipping? |
598 | 598 | if ($this->_paypal_shipping && $shipping_amount && $payment_was_itemized) { |
599 | 599 | $this->_line_item->add_unrelated_item( |
@@ -603,7 +603,7 @@ discard block |
||
603 | 603 | esc_html__('Shipping charges calculated by Paypal', 'event_espresso'), |
604 | 604 | 1, |
605 | 605 | false, |
606 | - 'paypal_shipping_' . $transaction->ID() |
|
606 | + 'paypal_shipping_'.$transaction->ID() |
|
607 | 607 | ); |
608 | 608 | $grand_total_needs_resaving = true; |
609 | 609 | } |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -class EE_Text_Area_Display_Strategy extends EE_Display_Strategy_Base{ |
|
2 | +class EE_Text_Area_Display_Strategy extends EE_Display_Strategy_Base { |
|
3 | 3 | |
4 | 4 | |
5 | 5 | |
@@ -7,32 +7,32 @@ discard block |
||
7 | 7 | * |
8 | 8 | * @return string of html to display the field |
9 | 9 | */ |
10 | - function display(){ |
|
10 | + function display() { |
|
11 | 11 | $input = $this->_input; |
12 | 12 | $raw_value = maybe_serialize($input->raw_value()); |
13 | - if( $input instanceof EE_Text_Area_Input ) { |
|
13 | + if ($input instanceof EE_Text_Area_Input) { |
|
14 | 14 | $rows = $input->get_rows(); |
15 | 15 | $cols = $input->get_cols(); |
16 | - }else{ |
|
16 | + } else { |
|
17 | 17 | $rows = 4; |
18 | 18 | $cols = 20; |
19 | 19 | } |
20 | 20 | $html = '<textarea'; |
21 | - $html .= ' id="' . $input->html_id() . '"'; |
|
22 | - $html .= ' name="' . $input->html_name() . '"'; |
|
23 | - $html .= ' class="' . $input->html_class() . '"' ; |
|
24 | - $html .= ' style="' . $input->html_style() . '"'; |
|
21 | + $html .= ' id="'.$input->html_id().'"'; |
|
22 | + $html .= ' name="'.$input->html_name().'"'; |
|
23 | + $html .= ' class="'.$input->html_class().'"'; |
|
24 | + $html .= ' style="'.$input->html_style().'"'; |
|
25 | 25 | $html .= $input->other_html_attributes(); |
26 | - $html .= ' rows= "' . $rows . '" cols="' . $cols . '">'; |
|
26 | + $html .= ' rows= "'.$rows.'" cols="'.$cols.'">'; |
|
27 | 27 | $html .= esc_textarea($raw_value); |
28 | 28 | $html .= '</textarea>'; |
29 | - foreach ( $this->_input->get_validation_strategies() as $validation_strategy ) { |
|
29 | + foreach ($this->_input->get_validation_strategies() as $validation_strategy) { |
|
30 | 30 | if ( |
31 | 31 | $validation_strategy instanceof EE_Simple_HTML_Validation_Strategy |
32 | 32 | || $validation_strategy instanceof EE_Full_HTML_Validation_Strategy |
33 | 33 | ) { |
34 | 34 | $html .= sprintf( |
35 | - __( '%1$s(allowed tags: %2$s)%3$s', 'event_espresso' ), |
|
35 | + __('%1$s(allowed tags: %2$s)%3$s', 'event_espresso'), |
|
36 | 36 | '<p class="ee-question-desc">', |
37 | 37 | $validation_strategy->get_list_of_allowed_tags(), |
38 | 38 | '</p>' |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if (!defined('EVENT_ESPRESSO_VERSION') ) |
|
2 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) |
|
3 | 3 | exit('NO direct script access allowed'); |
4 | 4 | |
5 | 5 | /** |
@@ -62,10 +62,10 @@ discard block |
||
62 | 62 | |
63 | 63 | |
64 | 64 | protected function _init_page_props() { |
65 | - require_once( EE_MODELS . 'EEM_Venue.model.php' ); |
|
65 | + require_once(EE_MODELS.'EEM_Venue.model.php'); |
|
66 | 66 | $this->page_slug = EE_VENUES_PG_SLUG; |
67 | 67 | $this->_admin_base_url = EE_VENUES_ADMIN_URL; |
68 | - $this->_admin_base_path = EE_ADMIN_PAGES . 'venues'; |
|
68 | + $this->_admin_base_path = EE_ADMIN_PAGES.'venues'; |
|
69 | 69 | $this->page_label = __('Event Venues', 'event_espresso'); |
70 | 70 | $this->_cpt_model_names = array( |
71 | 71 | 'create_new' => 'EEM_Venue', |
@@ -108,7 +108,7 @@ discard block |
||
108 | 108 | 'edit' => __('Update Venue', 'event_espresso'), |
109 | 109 | 'add_category' => __('Save New Category', 'event_espresso'), |
110 | 110 | 'edit_category' => __('Update Category', 'event_espresso'), |
111 | - 'google_map_settings' => __( 'Update Settings', 'event_espresso' ) |
|
111 | + 'google_map_settings' => __('Update Settings', 'event_espresso') |
|
112 | 112 | ) |
113 | 113 | ); |
114 | 114 | } |
@@ -123,8 +123,8 @@ discard block |
||
123 | 123 | //load field generator helper |
124 | 124 | |
125 | 125 | //is there a vnu_id in the request? |
126 | - $vnu_id = ! empty( $this->_req_data['VNU_ID'] ) && ! is_array( $this->_req_data['VNU_ID'] ) ? $this->_req_data['VNU_ID'] : 0; |
|
127 | - $vnu_id = ! empty( $this->_req_data['post'] ) ? $this->_req_data['post'] : $vnu_id; |
|
126 | + $vnu_id = ! empty($this->_req_data['VNU_ID']) && ! is_array($this->_req_data['VNU_ID']) ? $this->_req_data['VNU_ID'] : 0; |
|
127 | + $vnu_id = ! empty($this->_req_data['post']) ? $this->_req_data['post'] : $vnu_id; |
|
128 | 128 | |
129 | 129 | $this->_page_routes = array( |
130 | 130 | 'default' => array( |
@@ -142,27 +142,27 @@ discard block |
||
142 | 142 | ), |
143 | 143 | 'trash_venue' => array( |
144 | 144 | 'func' => '_trash_or_restore_venue', |
145 | - 'args' => array( 'venue_status' => 'trash' ), |
|
145 | + 'args' => array('venue_status' => 'trash'), |
|
146 | 146 | 'noheader' => TRUE, |
147 | 147 | 'capability' => 'ee_delete_venue', |
148 | 148 | 'obj_id' => $vnu_id |
149 | 149 | ), |
150 | 150 | 'trash_venues' => array( |
151 | 151 | 'func' => '_trash_or_restore_venues', |
152 | - 'args' => array( 'venue_status' => 'trash' ), |
|
152 | + 'args' => array('venue_status' => 'trash'), |
|
153 | 153 | 'noheader' => TRUE, |
154 | 154 | 'capability' => 'ee_delete_venues' |
155 | 155 | ), |
156 | 156 | 'restore_venue' => array( |
157 | 157 | 'func' => '_trash_or_restore_venue', |
158 | - 'args' => array( 'venue_status' => 'draft' ), |
|
158 | + 'args' => array('venue_status' => 'draft'), |
|
159 | 159 | 'noheader' => TRUE, |
160 | 160 | 'capability' => 'ee_delete_venue', |
161 | 161 | 'obj_id' => $vnu_id |
162 | 162 | ), |
163 | 163 | 'restore_venues' => array( |
164 | 164 | 'func' => '_trash_or_restore_venues', |
165 | - 'args' => array( 'venue_status' => 'draft' ), |
|
165 | + 'args' => array('venue_status' => 'draft'), |
|
166 | 166 | 'noheader' => TRUE, |
167 | 167 | 'capability' => 'ee_delete_venues' |
168 | 168 | ), |
@@ -264,7 +264,7 @@ discard block |
||
264 | 264 | 'filename' => 'venues_overview_views_bulk_actions_search' |
265 | 265 | ) |
266 | 266 | ), |
267 | - 'help_tour' => array( 'Venues_Overview_Help_Tour' ), |
|
267 | + 'help_tour' => array('Venues_Overview_Help_Tour'), |
|
268 | 268 | 'metaboxes' => array('_espresso_news_post_box', '_espresso_links_post_box'), |
269 | 269 | 'require_nonce' => FALSE |
270 | 270 | ), |
@@ -300,7 +300,7 @@ discard block |
||
300 | 300 | 'filename' => 'venues_editor_other' |
301 | 301 | ) |
302 | 302 | ), |
303 | - 'help_tour' => array( 'Venues_Add_Venue_Help_Tour' ), |
|
303 | + 'help_tour' => array('Venues_Add_Venue_Help_Tour'), |
|
304 | 304 | 'metaboxes' => array('_venue_editor_metaboxes'), |
305 | 305 | 'require_nonce' => FALSE |
306 | 306 | ), |
@@ -309,7 +309,7 @@ discard block |
||
309 | 309 | 'label' => __('Edit Venue', 'event_espresso'), |
310 | 310 | 'order' => 5, |
311 | 311 | 'persistent' => FALSE, |
312 | - 'url' => isset($this->_req_data['post']) ? add_query_arg(array('post' => $this->_req_data['post'] ), $this->_current_page_view_url ) : $this->_admin_base_url |
|
312 | + 'url' => isset($this->_req_data['post']) ? add_query_arg(array('post' => $this->_req_data['post']), $this->_current_page_view_url) : $this->_admin_base_url |
|
313 | 313 | ), |
314 | 314 | 'help_tabs' => array( |
315 | 315 | 'venues_editor_help_tab' => array( |
@@ -343,17 +343,17 @@ discard block |
||
343 | 343 | ), |
344 | 344 | 'google_map_settings' => array( |
345 | 345 | 'nav' => array( |
346 | - 'label' => esc_html__('Google Maps', 'event_espresso' ), |
|
346 | + 'label' => esc_html__('Google Maps', 'event_espresso'), |
|
347 | 347 | 'order' => 40 |
348 | 348 | ), |
349 | - 'metaboxes' => array_merge( $this->_default_espresso_metaboxes, array('_publish_post_box' ) ), |
|
349 | + 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
350 | 350 | 'help_tabs' => array( |
351 | 351 | 'general_settings_google_maps_help_tab' => array( |
352 | 352 | 'title' => __('Google Maps', 'event_espresso'), |
353 | 353 | 'filename' => 'general_settings_google_maps' |
354 | 354 | ) |
355 | 355 | ), |
356 | - 'help_tour' => array( 'Google_Maps_Help_Tour' ), |
|
356 | + 'help_tour' => array('Google_Maps_Help_Tour'), |
|
357 | 357 | 'require_nonce' => FALSE |
358 | 358 | ), |
359 | 359 | //venue category stuff |
@@ -369,7 +369,7 @@ discard block |
||
369 | 369 | 'filename' => 'venues_add_category' |
370 | 370 | ) |
371 | 371 | ), |
372 | - 'help_tour' => array( 'Venues_Add_Category_Help_Tour' ), |
|
372 | + 'help_tour' => array('Venues_Add_Category_Help_Tour'), |
|
373 | 373 | 'require_nonce' => FALSE |
374 | 374 | ), |
375 | 375 | 'edit_category' => array( |
@@ -377,7 +377,7 @@ discard block |
||
377 | 377 | 'label' => __('Edit Category', 'event_espresso'), |
378 | 378 | 'order' => 15, |
379 | 379 | 'persistent' => FALSE, |
380 | - 'url' => isset($this->_req_data['EVT_CAT_ID']) ? add_query_arg(array('EVT_CAT_ID' => $this->_req_data['EVT_CAT_ID'] ), $this->_current_page_view_url ) : $this->_admin_base_url |
|
380 | + 'url' => isset($this->_req_data['EVT_CAT_ID']) ? add_query_arg(array('EVT_CAT_ID' => $this->_req_data['EVT_CAT_ID']), $this->_current_page_view_url) : $this->_admin_base_url |
|
381 | 381 | ), |
382 | 382 | 'metaboxes' => array('_publish_post_box'), |
383 | 383 | 'help_tabs' => array( |
@@ -413,7 +413,7 @@ discard block |
||
413 | 413 | 'filename' => 'venues_categories_other' |
414 | 414 | ) |
415 | 415 | ), |
416 | - 'help_tour' => array( 'Venues_Categories_Help_Tour' ), |
|
416 | + 'help_tour' => array('Venues_Categories_Help_Tour'), |
|
417 | 417 | 'metaboxes' => $this->_default_espresso_metaboxes, |
418 | 418 | 'require_nonce' => FALSE |
419 | 419 | ) |
@@ -470,7 +470,7 @@ discard block |
||
470 | 470 | |
471 | 471 | |
472 | 472 | public function load_scripts_styles() { |
473 | - wp_register_style('ee-cat-admin', EVENTS_ASSETS_URL . 'ee-cat-admin.css', array(), EVENT_ESPRESSO_VERSION ); |
|
473 | + wp_register_style('ee-cat-admin', EVENTS_ASSETS_URL.'ee-cat-admin.css', array(), EVENT_ESPRESSO_VERSION); |
|
474 | 474 | wp_enqueue_style('ee-cat-admin'); |
475 | 475 | } |
476 | 476 | |
@@ -493,7 +493,7 @@ discard block |
||
493 | 493 | public function load_scripts_styles_edit() { |
494 | 494 | //styles |
495 | 495 | wp_enqueue_style('espresso-ui-theme'); |
496 | - wp_register_style( 'espresso_venues', EE_VENUES_ASSETS_URL . 'ee-venues-admin.css', array(), EVENT_ESPRESSO_VERSION ); |
|
496 | + wp_register_style('espresso_venues', EE_VENUES_ASSETS_URL.'ee-venues-admin.css', array(), EVENT_ESPRESSO_VERSION); |
|
497 | 497 | wp_enqueue_style('espresso_venues'); |
498 | 498 | } |
499 | 499 | |
@@ -512,13 +512,13 @@ discard block |
||
512 | 512 | ) |
513 | 513 | ); |
514 | 514 | |
515 | - if ( EE_Registry::instance()->CAP->current_user_can( 'ee_delete_venues', 'espresso_venues_trash_venues' ) ) { |
|
515 | + if (EE_Registry::instance()->CAP->current_user_can('ee_delete_venues', 'espresso_venues_trash_venues')) { |
|
516 | 516 | $this->_views['all']['bulk_action'] = array( |
517 | 517 | 'trash_venues' => __('Move to Trash', 'event_espresso') |
518 | 518 | ); |
519 | 519 | $this->_views['trash'] = array( |
520 | 520 | 'slug' => 'trash', |
521 | - 'label' => __( 'Trash', 'event_espresso' ), |
|
521 | + 'label' => __('Trash', 'event_espresso'), |
|
522 | 522 | 'count' => 0, |
523 | 523 | 'bulk_action' => array( |
524 | 524 | 'restore_venues' => __('Restore from Trash', 'event_espresso'), |
@@ -551,9 +551,9 @@ discard block |
||
551 | 551 | |
552 | 552 | |
553 | 553 | protected function _overview_list_table() { |
554 | - do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' ); |
|
555 | - $this->_template_args['after_list_table'] = EEH_Template::get_button_or_link( get_post_type_archive_link('espresso_venues'), __("View Venue Archive Page", "event_espresso"), 'button' ); |
|
556 | - $this->_admin_page_title .= ' ' . $this->get_action_link_or_button('create_new', 'add', array(), 'add-new-h2'); |
|
554 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
555 | + $this->_template_args['after_list_table'] = EEH_Template::get_button_or_link(get_post_type_archive_link('espresso_venues'), __("View Venue Archive Page", "event_espresso"), 'button'); |
|
556 | + $this->_admin_page_title .= ' '.$this->get_action_link_or_button('create_new', 'add', array(), 'add-new-h2'); |
|
557 | 557 | $this->_search_btn_label = __('Venues', 'event_espresso'); |
558 | 558 | $this->display_admin_list_table_page_with_sidebar(); |
559 | 559 | } |
@@ -566,8 +566,8 @@ discard block |
||
566 | 566 | 'vnu_url' => $this->_cpt_model_obj->get_f('VNU_url'), |
567 | 567 | 'vnu_phone' => $this->_cpt_model_obj->get_f('VNU_phone') |
568 | 568 | ); |
569 | - $template = EE_VENUES_TEMPLATE_PATH . 'venue_publish_box_extras.template.php'; |
|
570 | - EEH_Template::display_template( $template, $extra_rows ); |
|
569 | + $template = EE_VENUES_TEMPLATE_PATH.'venue_publish_box_extras.template.php'; |
|
570 | + EEH_Template::display_template($template, $extra_rows); |
|
571 | 571 | } |
572 | 572 | |
573 | 573 | |
@@ -583,31 +583,31 @@ discard block |
||
583 | 583 | $default_map_settings->use_google_maps = TRUE; |
584 | 584 | $default_map_settings->google_map_api_key = ''; |
585 | 585 | // for event details pages (reg page) |
586 | - $default_map_settings->event_details_map_width = 585; // ee_map_width_single |
|
587 | - $default_map_settings->event_details_map_height = 362; // ee_map_height_single |
|
588 | - $default_map_settings->event_details_map_zoom = 14; // ee_map_zoom_single |
|
589 | - $default_map_settings->event_details_display_nav = TRUE; // ee_map_nav_display_single |
|
590 | - $default_map_settings->event_details_nav_size = FALSE; // ee_map_nav_size_single |
|
591 | - $default_map_settings->event_details_control_type = 'default'; // ee_map_type_control_single |
|
592 | - $default_map_settings->event_details_map_align = 'center'; // ee_map_align_single |
|
586 | + $default_map_settings->event_details_map_width = 585; // ee_map_width_single |
|
587 | + $default_map_settings->event_details_map_height = 362; // ee_map_height_single |
|
588 | + $default_map_settings->event_details_map_zoom = 14; // ee_map_zoom_single |
|
589 | + $default_map_settings->event_details_display_nav = TRUE; // ee_map_nav_display_single |
|
590 | + $default_map_settings->event_details_nav_size = FALSE; // ee_map_nav_size_single |
|
591 | + $default_map_settings->event_details_control_type = 'default'; // ee_map_type_control_single |
|
592 | + $default_map_settings->event_details_map_align = 'center'; // ee_map_align_single |
|
593 | 593 | // for event list pages |
594 | - $default_map_settings->event_list_map_width = 300; // ee_map_width |
|
595 | - $default_map_settings->event_list_map_height = 185; // ee_map_height |
|
596 | - $default_map_settings->event_list_map_zoom = 12; // ee_map_zoom |
|
597 | - $default_map_settings->event_list_display_nav = FALSE; // ee_map_nav_display |
|
598 | - $default_map_settings->event_list_nav_size = TRUE; // ee_map_nav_size |
|
599 | - $default_map_settings->event_list_control_type = 'dropdown'; // ee_map_type_control |
|
600 | - $default_map_settings->event_list_map_align = 'center'; // ee_map_align |
|
594 | + $default_map_settings->event_list_map_width = 300; // ee_map_width |
|
595 | + $default_map_settings->event_list_map_height = 185; // ee_map_height |
|
596 | + $default_map_settings->event_list_map_zoom = 12; // ee_map_zoom |
|
597 | + $default_map_settings->event_list_display_nav = FALSE; // ee_map_nav_display |
|
598 | + $default_map_settings->event_list_nav_size = TRUE; // ee_map_nav_size |
|
599 | + $default_map_settings->event_list_control_type = 'dropdown'; // ee_map_type_control |
|
600 | + $default_map_settings->event_list_map_align = 'center'; // ee_map_align |
|
601 | 601 | |
602 | 602 | $this->_template_args['map_settings'] = |
603 | - isset( EE_Registry::instance()->CFG->map_settings ) && ! empty( EE_Registry::instance()->CFG->map_settings ) |
|
604 | - ? (object)array_merge( (array)$default_map_settings, (array)EE_Registry::instance()->CFG->map_settings ) |
|
603 | + isset(EE_Registry::instance()->CFG->map_settings) && ! empty(EE_Registry::instance()->CFG->map_settings) |
|
604 | + ? (object) array_merge((array) $default_map_settings, (array) EE_Registry::instance()->CFG->map_settings) |
|
605 | 605 | : $default_map_settings; |
606 | 606 | |
607 | - $this->_set_add_edit_form_tags( 'update_google_map_settings' ); |
|
608 | - $this->_set_publish_post_box_vars( NULL, FALSE, FALSE, NULL, FALSE ); |
|
607 | + $this->_set_add_edit_form_tags('update_google_map_settings'); |
|
608 | + $this->_set_publish_post_box_vars(NULL, FALSE, FALSE, NULL, FALSE); |
|
609 | 609 | $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
610 | - EE_VENUES_TEMPLATE_PATH . 'google_map.template.php', |
|
610 | + EE_VENUES_TEMPLATE_PATH.'google_map.template.php', |
|
611 | 611 | $this->_template_args, |
612 | 612 | true |
613 | 613 | ); |
@@ -617,83 +617,83 @@ discard block |
||
617 | 617 | protected function _update_google_map_settings() { |
618 | 618 | |
619 | 619 | EE_Registry::instance()->CFG->map_settings->use_google_maps = |
620 | - isset( $this->_req_data['use_google_maps'] ) |
|
621 | - ? absint( $this->_req_data['use_google_maps'] ) |
|
620 | + isset($this->_req_data['use_google_maps']) |
|
621 | + ? absint($this->_req_data['use_google_maps']) |
|
622 | 622 | : EE_Registry::instance()->CFG->map_settings->use_google_maps; |
623 | 623 | |
624 | 624 | EE_Registry::instance()->CFG->map_settings->google_map_api_key = |
625 | - isset( $this->_req_data['google_map_api_key'] ) |
|
626 | - ? sanitize_text_field( $this->_req_data['google_map_api_key'] ) |
|
625 | + isset($this->_req_data['google_map_api_key']) |
|
626 | + ? sanitize_text_field($this->_req_data['google_map_api_key']) |
|
627 | 627 | : EE_Registry::instance()->CFG->map_settings->google_map_api_key; |
628 | 628 | |
629 | 629 | EE_Registry::instance()->CFG->map_settings->event_details_map_width = |
630 | - isset( $this->_req_data['event_details_map_width'] ) |
|
631 | - ? absint( $this->_req_data['event_details_map_width'] ) |
|
630 | + isset($this->_req_data['event_details_map_width']) |
|
631 | + ? absint($this->_req_data['event_details_map_width']) |
|
632 | 632 | : EE_Registry::instance()->CFG->map_settings->event_details_map_width; |
633 | 633 | |
634 | 634 | EE_Registry::instance()->CFG->map_settings->event_details_map_height = |
635 | - isset( $this->_req_data['event_details_map_height'] ) |
|
636 | - ? absint( $this->_req_data['event_details_map_height'] ) |
|
635 | + isset($this->_req_data['event_details_map_height']) |
|
636 | + ? absint($this->_req_data['event_details_map_height']) |
|
637 | 637 | : EE_Registry::instance()->CFG->map_settings->event_details_map_height; |
638 | 638 | |
639 | 639 | EE_Registry::instance()->CFG->map_settings->event_details_map_zoom = |
640 | - isset( $this->_req_data['event_details_map_zoom'] ) |
|
641 | - ? absint( $this->_req_data['event_details_map_zoom'] ) |
|
640 | + isset($this->_req_data['event_details_map_zoom']) |
|
641 | + ? absint($this->_req_data['event_details_map_zoom']) |
|
642 | 642 | : EE_Registry::instance()->CFG->map_settings->event_details_map_zoom; |
643 | 643 | |
644 | 644 | EE_Registry::instance()->CFG->map_settings->event_details_display_nav = |
645 | - isset( $this->_req_data['event_details_display_nav'] ) |
|
646 | - ? absint( $this->_req_data['event_details_display_nav'] ) |
|
645 | + isset($this->_req_data['event_details_display_nav']) |
|
646 | + ? absint($this->_req_data['event_details_display_nav']) |
|
647 | 647 | : EE_Registry::instance()->CFG->map_settings->event_details_display_nav; |
648 | 648 | |
649 | 649 | EE_Registry::instance()->CFG->map_settings->event_details_nav_size = |
650 | - isset( $this->_req_data['event_details_nav_size'] ) |
|
651 | - ? absint( $this->_req_data['event_details_nav_size'] ) |
|
650 | + isset($this->_req_data['event_details_nav_size']) |
|
651 | + ? absint($this->_req_data['event_details_nav_size']) |
|
652 | 652 | : EE_Registry::instance()->CFG->map_settings->event_details_nav_size; |
653 | 653 | |
654 | 654 | EE_Registry::instance()->CFG->map_settings->event_details_control_type = |
655 | - isset( $this->_req_data['event_details_control_type'] ) |
|
656 | - ? sanitize_text_field( $this->_req_data['event_details_control_type'] ) |
|
655 | + isset($this->_req_data['event_details_control_type']) |
|
656 | + ? sanitize_text_field($this->_req_data['event_details_control_type']) |
|
657 | 657 | : EE_Registry::instance()->CFG->map_settings->event_details_control_type; |
658 | 658 | |
659 | 659 | EE_Registry::instance()->CFG->map_settings->event_details_map_align = |
660 | - isset( $this->_req_data['event_details_map_align'] ) |
|
661 | - ? sanitize_text_field( $this->_req_data['event_details_map_align'] ) |
|
660 | + isset($this->_req_data['event_details_map_align']) |
|
661 | + ? sanitize_text_field($this->_req_data['event_details_map_align']) |
|
662 | 662 | : EE_Registry::instance()->CFG->map_settings->event_details_map_align; |
663 | 663 | |
664 | 664 | EE_Registry::instance()->CFG->map_settings->event_list_map_width = |
665 | - isset( $this->_req_data['event_list_map_width'] ) |
|
666 | - ? absint( $this->_req_data['event_list_map_width'] ) |
|
665 | + isset($this->_req_data['event_list_map_width']) |
|
666 | + ? absint($this->_req_data['event_list_map_width']) |
|
667 | 667 | : EE_Registry::instance()->CFG->map_settings->event_list_map_width; |
668 | 668 | |
669 | 669 | EE_Registry::instance()->CFG->map_settings->event_list_map_height = |
670 | - isset( $this->_req_data['event_list_map_height'] ) |
|
671 | - ? absint( $this->_req_data['event_list_map_height'] ) |
|
670 | + isset($this->_req_data['event_list_map_height']) |
|
671 | + ? absint($this->_req_data['event_list_map_height']) |
|
672 | 672 | : EE_Registry::instance()->CFG->map_settings->event_list_map_height; |
673 | 673 | |
674 | 674 | EE_Registry::instance()->CFG->map_settings->event_list_map_zoom = |
675 | - isset( $this->_req_data['event_list_map_zoom'] ) |
|
676 | - ? absint( $this->_req_data['event_list_map_zoom'] ) |
|
675 | + isset($this->_req_data['event_list_map_zoom']) |
|
676 | + ? absint($this->_req_data['event_list_map_zoom']) |
|
677 | 677 | : EE_Registry::instance()->CFG->map_settings->event_list_map_zoom; |
678 | 678 | |
679 | 679 | EE_Registry::instance()->CFG->map_settings->event_list_display_nav = |
680 | - isset( $this->_req_data['event_list_display_nav'] ) |
|
681 | - ? absint( $this->_req_data['event_list_display_nav'] ) |
|
680 | + isset($this->_req_data['event_list_display_nav']) |
|
681 | + ? absint($this->_req_data['event_list_display_nav']) |
|
682 | 682 | : EE_Registry::instance()->CFG->map_settings->event_list_display_nav; |
683 | 683 | |
684 | 684 | EE_Registry::instance()->CFG->map_settings->event_list_nav_size = |
685 | - isset( $this->_req_data['event_list_nav_size'] ) |
|
686 | - ? absint( $this->_req_data['event_list_nav_size'] ) |
|
685 | + isset($this->_req_data['event_list_nav_size']) |
|
686 | + ? absint($this->_req_data['event_list_nav_size']) |
|
687 | 687 | : EE_Registry::instance()->CFG->map_settings->event_list_nav_size; |
688 | 688 | |
689 | 689 | EE_Registry::instance()->CFG->map_settings->event_list_control_type = |
690 | - isset( $this->_req_data['event_list_control_type'] ) |
|
691 | - ? sanitize_text_field( $this->_req_data['event_list_control_type'] ) |
|
690 | + isset($this->_req_data['event_list_control_type']) |
|
691 | + ? sanitize_text_field($this->_req_data['event_list_control_type']) |
|
692 | 692 | : EE_Registry::instance()->CFG->map_settings->event_list_control_type; |
693 | 693 | |
694 | 694 | EE_Registry::instance()->CFG->map_settings->event_list_map_align = |
695 | - isset( $this->_req_data['event_list_map_align'] ) |
|
696 | - ? sanitize_text_field( $this->_req_data['event_list_map_align'] ) |
|
695 | + isset($this->_req_data['event_list_map_align']) |
|
696 | + ? sanitize_text_field($this->_req_data['event_list_map_align']) |
|
697 | 697 | : EE_Registry::instance()->CFG->map_settings->event_list_map_align; |
698 | 698 | |
699 | 699 | EE_Registry::instance()->CFG->map_settings = apply_filters( |
@@ -707,7 +707,7 @@ discard block |
||
707 | 707 | EE_Registry::instance()->CFG->map_settings, |
708 | 708 | __FILE__, __FUNCTION__, __LINE__ |
709 | 709 | ); |
710 | - $this->_redirect_after_action( $success, $what, 'updated', array( 'action' => 'google_map_settings' ) ); |
|
710 | + $this->_redirect_after_action($success, $what, 'updated', array('action' => 'google_map_settings')); |
|
711 | 711 | |
712 | 712 | } |
713 | 713 | |
@@ -716,9 +716,9 @@ discard block |
||
716 | 716 | protected function _venue_editor_metaboxes() { |
717 | 717 | $this->verify_cpt_object(); |
718 | 718 | |
719 | - add_meta_box( 'espresso_venue_address_options', __('Physical Location', 'event_espresso'), array( $this, 'venue_address_metabox'), $this->page_slug, 'side', 'default' ); |
|
720 | - add_meta_box( 'espresso_venue_gmap_options', __('Google Map', 'event_espresso'), array( $this, 'venue_gmap_metabox'), $this->page_slug, 'side', 'default' ); |
|
721 | - add_meta_box( 'espresso_venue_virtual_loc_options', __('Virtual Location', 'event_espresso'), array( $this, 'venue_virtual_loc_metabox'), $this->page_slug, 'side', 'default' ); |
|
719 | + add_meta_box('espresso_venue_address_options', __('Physical Location', 'event_espresso'), array($this, 'venue_address_metabox'), $this->page_slug, 'side', 'default'); |
|
720 | + add_meta_box('espresso_venue_gmap_options', __('Google Map', 'event_espresso'), array($this, 'venue_gmap_metabox'), $this->page_slug, 'side', 'default'); |
|
721 | + add_meta_box('espresso_venue_virtual_loc_options', __('Virtual Location', 'event_espresso'), array($this, 'venue_virtual_loc_metabox'), $this->page_slug, 'side', 'default'); |
|
722 | 722 | |
723 | 723 | } |
724 | 724 | |
@@ -726,23 +726,23 @@ discard block |
||
726 | 726 | |
727 | 727 | public function venue_gmap_metabox() { |
728 | 728 | $template_args = array( |
729 | - 'vnu_enable_for_gmap' => EEH_Form_Fields::select_input('vnu_enable_for_gmap', $this->get_yes_no_values(), $this->_cpt_model_obj->enable_for_gmap() ), |
|
729 | + 'vnu_enable_for_gmap' => EEH_Form_Fields::select_input('vnu_enable_for_gmap', $this->get_yes_no_values(), $this->_cpt_model_obj->enable_for_gmap()), |
|
730 | 730 | 'vnu_google_map_link' => $this->_cpt_model_obj->google_map_link(), |
731 | 731 | ); |
732 | - $template = EE_VENUES_TEMPLATE_PATH . 'venue_gmap_metabox_content.template.php'; |
|
733 | - EEH_Template::display_template( $template, $template_args ); |
|
732 | + $template = EE_VENUES_TEMPLATE_PATH.'venue_gmap_metabox_content.template.php'; |
|
733 | + EEH_Template::display_template($template, $template_args); |
|
734 | 734 | } |
735 | 735 | |
736 | 736 | |
737 | 737 | |
738 | 738 | public function venue_address_metabox() { |
739 | 739 | |
740 | - $template_args['_venue'] =$this->_cpt_model_obj; |
|
740 | + $template_args['_venue'] = $this->_cpt_model_obj; |
|
741 | 741 | |
742 | 742 | $template_args['states_dropdown'] = EEH_Form_Fields::generate_form_input( |
743 | 743 | $QFI = new EE_Question_Form_Input( |
744 | - EE_Question::new_instance( array( 'QST_display_text' => esc_html__( 'State', 'event_espresso' ), 'QST_system' => 'state' )), |
|
745 | - EE_Answer::new_instance( array( 'ANS_value'=> $this->_cpt_model_obj->state_ID() )), |
|
744 | + EE_Question::new_instance(array('QST_display_text' => esc_html__('State', 'event_espresso'), 'QST_system' => 'state')), |
|
745 | + EE_Answer::new_instance(array('ANS_value'=> $this->_cpt_model_obj->state_ID())), |
|
746 | 746 | array( |
747 | 747 | 'input_name' => 'sta_id', |
748 | 748 | 'input_id' => 'sta_id', |
@@ -754,8 +754,8 @@ discard block |
||
754 | 754 | ); |
755 | 755 | $template_args['countries_dropdown'] = EEH_Form_Fields::generate_form_input( |
756 | 756 | $QFI = new EE_Question_Form_Input( |
757 | - EE_Question::new_instance( array( 'QST_display_text' => esc_html__( 'Country', 'event_espresso' ), 'QST_system' => 'country' )), |
|
758 | - EE_Answer::new_instance( array( 'ANS_value'=> $this->_cpt_model_obj->country_ID() )), |
|
757 | + EE_Question::new_instance(array('QST_display_text' => esc_html__('Country', 'event_espresso'), 'QST_system' => 'country')), |
|
758 | + EE_Answer::new_instance(array('ANS_value'=> $this->_cpt_model_obj->country_ID())), |
|
759 | 759 | array( |
760 | 760 | 'input_name' => 'cnt_iso', |
761 | 761 | 'input_id' => 'cnt_iso', |
@@ -766,8 +766,8 @@ discard block |
||
766 | 766 | ) |
767 | 767 | ); |
768 | 768 | |
769 | - $template = EE_VENUES_TEMPLATE_PATH . 'venue_address_metabox_content.template.php'; |
|
770 | - EEH_Template::display_template( $template, $template_args ); |
|
769 | + $template = EE_VENUES_TEMPLATE_PATH.'venue_address_metabox_content.template.php'; |
|
770 | + EEH_Template::display_template($template, $template_args); |
|
771 | 771 | } |
772 | 772 | |
773 | 773 | |
@@ -779,8 +779,8 @@ discard block |
||
779 | 779 | $template_args = array( |
780 | 780 | '_venue' => $this->_cpt_model_obj |
781 | 781 | ); |
782 | - $template = EE_VENUES_TEMPLATE_PATH . 'venue_virtual_location_metabox_content.template.php'; |
|
783 | - EEH_Template::display_template( $template, $template_args ); |
|
782 | + $template = EE_VENUES_TEMPLATE_PATH.'venue_virtual_location_metabox_content.template.php'; |
|
783 | + EEH_Template::display_template($template, $template_args); |
|
784 | 784 | } |
785 | 785 | |
786 | 786 | |
@@ -803,52 +803,52 @@ discard block |
||
803 | 803 | * @param object $post Post object (with "blessed" WP properties) |
804 | 804 | * @return void |
805 | 805 | */ |
806 | - protected function _insert_update_cpt_item( $post_id, $post ) { |
|
806 | + protected function _insert_update_cpt_item($post_id, $post) { |
|
807 | 807 | |
808 | - if ( $post instanceof WP_Post && $post->post_type !== 'espresso_venues' ) { |
|
809 | - return;// get out we're not processing the saving of venues. |
|
808 | + if ($post instanceof WP_Post && $post->post_type !== 'espresso_venues') { |
|
809 | + return; // get out we're not processing the saving of venues. |
|
810 | 810 | } |
811 | 811 | |
812 | - $wheres = array( $this->_venue_model->primary_key_name() => $post_id ); |
|
812 | + $wheres = array($this->_venue_model->primary_key_name() => $post_id); |
|
813 | 813 | |
814 | 814 | $venue_values = array( |
815 | - 'VNU_address' => !empty( $this->_req_data['vnu_address'] ) ? $this->_req_data['vnu_address'] : NULL, |
|
816 | - 'VNU_address2' => !empty( $this->_req_data['vnu_address2'] ) ? $this->_req_data['vnu_address2'] : NULL, |
|
817 | - 'VNU_city' => !empty( $this->_req_data['vnu_city'] ) ? $this->_req_data['vnu_city'] : NULL, |
|
818 | - 'STA_ID' => !empty( $this->_req_data['sta_id'] ) ? $this->_req_data['sta_id'] : NULL, |
|
819 | - 'CNT_ISO' => !empty( $this->_req_data['cnt_iso'] ) ? $this->_req_data['cnt_iso'] : NULL, |
|
820 | - 'VNU_zip' => !empty( $this->_req_data['vnu_zip'] ) ? $this->_req_data['vnu_zip'] : NULL, |
|
821 | - 'VNU_phone' => !empty( $this->_req_data['vnu_phone'] ) ? $this->_req_data['vnu_phone'] : NULL, |
|
822 | - 'VNU_capacity' => !empty( $this->_req_data['vnu_capacity'] ) ? str_replace( ',', '', $this->_req_data['vnu_capacity'] ) : EE_INF, |
|
823 | - 'VNU_url' => !empty( $this->_req_data['vnu_url'] ) ? $this->_req_data['vnu_url'] : NULL, |
|
824 | - 'VNU_virtual_phone' => !empty( $this->_req_data['vnu_virtual_phone'] ) ? $this->_req_data['vnu_virtual_phone'] : NULL, |
|
825 | - 'VNU_virtual_url' => !empty( $this->_req_data['vnu_virtual_url'] ) ? $this->_req_data['vnu_virtual_url'] : NULL, |
|
826 | - 'VNU_enable_for_gmap' => !empty( $this->_req_data['vnu_enable_for_gmap'] ) ? TRUE : FALSE, |
|
827 | - 'VNU_google_map_link' => !empty( $this->_req_data['vnu_google_map_link'] ) ? $this->_req_data['vnu_google_map_link'] : NULL |
|
815 | + 'VNU_address' => ! empty($this->_req_data['vnu_address']) ? $this->_req_data['vnu_address'] : NULL, |
|
816 | + 'VNU_address2' => ! empty($this->_req_data['vnu_address2']) ? $this->_req_data['vnu_address2'] : NULL, |
|
817 | + 'VNU_city' => ! empty($this->_req_data['vnu_city']) ? $this->_req_data['vnu_city'] : NULL, |
|
818 | + 'STA_ID' => ! empty($this->_req_data['sta_id']) ? $this->_req_data['sta_id'] : NULL, |
|
819 | + 'CNT_ISO' => ! empty($this->_req_data['cnt_iso']) ? $this->_req_data['cnt_iso'] : NULL, |
|
820 | + 'VNU_zip' => ! empty($this->_req_data['vnu_zip']) ? $this->_req_data['vnu_zip'] : NULL, |
|
821 | + 'VNU_phone' => ! empty($this->_req_data['vnu_phone']) ? $this->_req_data['vnu_phone'] : NULL, |
|
822 | + 'VNU_capacity' => ! empty($this->_req_data['vnu_capacity']) ? str_replace(',', '', $this->_req_data['vnu_capacity']) : EE_INF, |
|
823 | + 'VNU_url' => ! empty($this->_req_data['vnu_url']) ? $this->_req_data['vnu_url'] : NULL, |
|
824 | + 'VNU_virtual_phone' => ! empty($this->_req_data['vnu_virtual_phone']) ? $this->_req_data['vnu_virtual_phone'] : NULL, |
|
825 | + 'VNU_virtual_url' => ! empty($this->_req_data['vnu_virtual_url']) ? $this->_req_data['vnu_virtual_url'] : NULL, |
|
826 | + 'VNU_enable_for_gmap' => ! empty($this->_req_data['vnu_enable_for_gmap']) ? TRUE : FALSE, |
|
827 | + 'VNU_google_map_link' => ! empty($this->_req_data['vnu_google_map_link']) ? $this->_req_data['vnu_google_map_link'] : NULL |
|
828 | 828 | ); |
829 | 829 | |
830 | 830 | //update venue |
831 | - $success = $this->_venue_model->update( $venue_values, array( $wheres ) ); |
|
831 | + $success = $this->_venue_model->update($venue_values, array($wheres)); |
|
832 | 832 | |
833 | 833 | //get venue_object for other metaboxes that might be added via the filter... though it would seem to make sense to just use $this->_venue_model->get_one_by_ID( $post_id ).. i have to setup where conditions to override the filters in the model that filter out autodraft and inherit statuses so we GET the inherit id! |
834 | - $get_one_where = array( $this->_venue_model->primary_key_name() => $post_id, 'status' => $post->post_status ); |
|
835 | - $venue = $this->_venue_model->get_one( array( $get_one_where ) ); |
|
834 | + $get_one_where = array($this->_venue_model->primary_key_name() => $post_id, 'status' => $post->post_status); |
|
835 | + $venue = $this->_venue_model->get_one(array($get_one_where)); |
|
836 | 836 | |
837 | 837 | //notice we've applied a filter for venue metabox callbacks but we don't actually have any default venue metaboxes in use. So this is just here for addons to more easily hook into venue saves. |
838 | - $venue_update_callbacks = apply_filters( 'FHEE__Venues_Admin_Page___insert_update_cpt_item__venue_update_callbacks', array() ); |
|
838 | + $venue_update_callbacks = apply_filters('FHEE__Venues_Admin_Page___insert_update_cpt_item__venue_update_callbacks', array()); |
|
839 | 839 | |
840 | 840 | $att_success = TRUE; |
841 | 841 | |
842 | - foreach ( $venue_update_callbacks as $v_callback ) { |
|
843 | - $_succ = call_user_func_array( $v_callback, array( $venue, $this->_req_data ) ); |
|
844 | - $att_success = !$att_success ? $att_success : $_succ; //if ANY of these updates fail then we want the appropriate global error message |
|
842 | + foreach ($venue_update_callbacks as $v_callback) { |
|
843 | + $_succ = call_user_func_array($v_callback, array($venue, $this->_req_data)); |
|
844 | + $att_success = ! $att_success ? $att_success : $_succ; //if ANY of these updates fail then we want the appropriate global error message |
|
845 | 845 | } |
846 | 846 | |
847 | 847 | //any errors? |
848 | - if ( $success && !$att_success ) { |
|
849 | - EE_Error::add_error( __('Venue Details saved successfully but something went wrong with saving attachments.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__ ); |
|
850 | - } else if ( $success === FALSE ) { |
|
851 | - EE_Error::add_error( __('Venue Details did not save successfully.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__ ); |
|
848 | + if ($success && ! $att_success) { |
|
849 | + EE_Error::add_error(__('Venue Details saved successfully but something went wrong with saving attachments.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
850 | + } else if ($success === FALSE) { |
|
851 | + EE_Error::add_error(__('Venue Details did not save successfully.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
852 | 852 | } |
853 | 853 | } |
854 | 854 | |
@@ -856,9 +856,9 @@ discard block |
||
856 | 856 | |
857 | 857 | |
858 | 858 | |
859 | - public function trash_cpt_item( $post_id ) { |
|
859 | + public function trash_cpt_item($post_id) { |
|
860 | 860 | $this->_req_data['VNU_ID'] = $post_id; |
861 | - $this->_trash_or_restore_venue( 'trash', FALSE ); |
|
861 | + $this->_trash_or_restore_venue('trash', FALSE); |
|
862 | 862 | } |
863 | 863 | |
864 | 864 | |
@@ -866,18 +866,18 @@ discard block |
||
866 | 866 | |
867 | 867 | |
868 | 868 | |
869 | - public function restore_cpt_item( $post_id ) { |
|
869 | + public function restore_cpt_item($post_id) { |
|
870 | 870 | $this->_req_data['VNU_ID'] = $post_id; |
871 | - $this->_trash_or_restore_venue( 'draft', FALSE ); |
|
871 | + $this->_trash_or_restore_venue('draft', FALSE); |
|
872 | 872 | } |
873 | 873 | |
874 | 874 | |
875 | 875 | |
876 | 876 | |
877 | 877 | |
878 | - public function delete_cpt_item( $post_id ) { |
|
878 | + public function delete_cpt_item($post_id) { |
|
879 | 879 | $this->_req_data['VNU_ID'] = $post_id; |
880 | - $this->_delete_venue( FALSE ); |
|
880 | + $this->_delete_venue(FALSE); |
|
881 | 881 | } |
882 | 882 | |
883 | 883 | |
@@ -892,15 +892,15 @@ discard block |
||
892 | 892 | |
893 | 893 | |
894 | 894 | |
895 | - protected function _trash_or_restore_venue( $venue_status = 'trash', $redirect_after = TRUE ) { |
|
896 | - $VNU_ID = isset( $this->_req_data['VNU_ID'] ) ? absint( $this->_req_data['VNU_ID'] ) : FALSE; |
|
895 | + protected function _trash_or_restore_venue($venue_status = 'trash', $redirect_after = TRUE) { |
|
896 | + $VNU_ID = isset($this->_req_data['VNU_ID']) ? absint($this->_req_data['VNU_ID']) : FALSE; |
|
897 | 897 | |
898 | 898 | //loop thru venues |
899 | - if ( $VNU_ID ) { |
|
899 | + if ($VNU_ID) { |
|
900 | 900 | //clean status |
901 | - $venue_status = sanitize_key( $venue_status ); |
|
901 | + $venue_status = sanitize_key($venue_status); |
|
902 | 902 | // grab status |
903 | - if (!empty($venue_status)) { |
|
903 | + if ( ! empty($venue_status)) { |
|
904 | 904 | $success = $this->_change_venue_status($VNU_ID, $venue_status); |
905 | 905 | } else { |
906 | 906 | $success = FALSE; |
@@ -914,7 +914,7 @@ discard block |
||
914 | 914 | } |
915 | 915 | $action = $venue_status == 'trash' ? 'moved to the trash' : 'restored from the trash'; |
916 | 916 | |
917 | - if ( $redirect_after ) |
|
917 | + if ($redirect_after) |
|
918 | 918 | $this->_redirect_after_action($success, 'Venue', $action, array('action' => 'default')); |
919 | 919 | |
920 | 920 | } |
@@ -923,11 +923,11 @@ discard block |
||
923 | 923 | |
924 | 924 | |
925 | 925 | |
926 | - protected function _trash_or_restore_venues( $venue_status = 'trash' ) { |
|
926 | + protected function _trash_or_restore_venues($venue_status = 'trash') { |
|
927 | 927 | // clean status |
928 | 928 | $venue_status = sanitize_key($venue_status); |
929 | 929 | // grab status |
930 | - if (!empty($venue_status)) { |
|
930 | + if ( ! empty($venue_status)) { |
|
931 | 931 | $success = TRUE; |
932 | 932 | //determine the event id and set to array. |
933 | 933 | $VNU_IDs = isset($this->_req_data['venue_id']) ? (array) $this->_req_data['venue_id'] : array(); |
@@ -967,20 +967,20 @@ discard block |
||
967 | 967 | * @param string $venue_status |
968 | 968 | * @return void |
969 | 969 | */ |
970 | - private function _change_venue_status( $VNU_ID = 0, $venue_status = '' ) { |
|
970 | + private function _change_venue_status($VNU_ID = 0, $venue_status = '') { |
|
971 | 971 | // grab venue id |
972 | - if (! $VNU_ID) { |
|
972 | + if ( ! $VNU_ID) { |
|
973 | 973 | $msg = __('An error occurred. No Venue ID or an invalid Venue ID was received.', 'event_espresso'); |
974 | 974 | EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
975 | 975 | return FALSE; |
976 | 976 | } |
977 | 977 | |
978 | - $this->_cpt_model_obj = EEM_Venue::instance()->get_one_by_ID( $VNU_ID ); |
|
978 | + $this->_cpt_model_obj = EEM_Venue::instance()->get_one_by_ID($VNU_ID); |
|
979 | 979 | |
980 | 980 | // clean status |
981 | 981 | $venue_status = sanitize_key($venue_status); |
982 | 982 | // grab status |
983 | - if ( ! $venue_status ) { |
|
983 | + if ( ! $venue_status) { |
|
984 | 984 | $msg = __('An error occurred. No Venue Status or an invalid Venue Status was received.', 'event_espresso'); |
985 | 985 | EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
986 | 986 | return FALSE; |
@@ -1001,7 +1001,7 @@ discard block |
||
1001 | 1001 | $hook = FALSE; |
1002 | 1002 | } |
1003 | 1003 | //use class to change status |
1004 | - $this->_cpt_model_obj->set_status( $venue_status ); |
|
1004 | + $this->_cpt_model_obj->set_status($venue_status); |
|
1005 | 1005 | $success = $this->_cpt_model_obj->save(); |
1006 | 1006 | |
1007 | 1007 | if ($success === FALSE) { |
@@ -1020,21 +1020,21 @@ discard block |
||
1020 | 1020 | * @param bool $redirect_after |
1021 | 1021 | * @return void |
1022 | 1022 | */ |
1023 | - protected function _delete_venue( $redirect_after = true ) { |
|
1023 | + protected function _delete_venue($redirect_after = true) { |
|
1024 | 1024 | //determine the venue id and set to array. |
1025 | 1025 | $VNU_ID = isset($this->_req_data['VNU_ID']) ? absint($this->_req_data['VNU_ID']) : NULL; |
1026 | - $VNU_ID = isset( $this->_req_data['post'] ) ? absint( $this->_req_data['post'] ) : $VNU_ID; |
|
1026 | + $VNU_ID = isset($this->_req_data['post']) ? absint($this->_req_data['post']) : $VNU_ID; |
|
1027 | 1027 | |
1028 | 1028 | |
1029 | 1029 | // loop thru venues |
1030 | 1030 | if ($VNU_ID) { |
1031 | - $success = $this->_delete_or_trash_venue( $VNU_ID ); |
|
1031 | + $success = $this->_delete_or_trash_venue($VNU_ID); |
|
1032 | 1032 | } else { |
1033 | 1033 | $success = FALSE; |
1034 | 1034 | $msg = __('An error occurred. An venue could not be deleted because a valid venue ID was not not supplied.', 'event_espresso'); |
1035 | 1035 | EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
1036 | 1036 | } |
1037 | - if ( $redirect_after ) |
|
1037 | + if ($redirect_after) |
|
1038 | 1038 | $this->_redirect_after_action($success, 'Venue', 'deleted', array('action' => 'default')); |
1039 | 1039 | } |
1040 | 1040 | |
@@ -1066,7 +1066,7 @@ discard block |
||
1066 | 1066 | //todo: put in parent |
1067 | 1067 | private function _delete_or_trash_venue($VNU_ID = FALSE) { |
1068 | 1068 | // grab event id |
1069 | - if (!$VNU_ID = absint($VNU_ID)) { |
|
1069 | + if ( ! $VNU_ID = absint($VNU_ID)) { |
|
1070 | 1070 | $msg = __('An error occurred. No Venue ID or an invalid Venue ID was received.', 'event_espresso'); |
1071 | 1071 | EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
1072 | 1072 | return FALSE; |
@@ -1086,7 +1086,7 @@ discard block |
||
1086 | 1086 | EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
1087 | 1087 | return FALSE; |
1088 | 1088 | } |
1089 | - do_action( 'AHEE__Venues_Admin_Page___delete_or_trash_venue__after_venue_deleted' ); |
|
1089 | + do_action('AHEE__Venues_Admin_Page___delete_or_trash_venue__after_venue_deleted'); |
|
1090 | 1090 | return TRUE; |
1091 | 1091 | } |
1092 | 1092 | |
@@ -1097,11 +1097,11 @@ discard block |
||
1097 | 1097 | /* QUERIES */ |
1098 | 1098 | |
1099 | 1099 | |
1100 | - public function get_venues( $per_page = 10, $count = FALSE ) { |
|
1100 | + public function get_venues($per_page = 10, $count = FALSE) { |
|
1101 | 1101 | |
1102 | - $_orderby = !empty( $this->_req_data['orderby'] ) ? $this->_req_data['orderby'] : ''; |
|
1102 | + $_orderby = ! empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : ''; |
|
1103 | 1103 | |
1104 | - switch ( $_orderby ) { |
|
1104 | + switch ($_orderby) { |
|
1105 | 1105 | case 'id': |
1106 | 1106 | $orderby = 'VNU_ID'; |
1107 | 1107 | break; |
@@ -1119,43 +1119,43 @@ discard block |
||
1119 | 1119 | } |
1120 | 1120 | |
1121 | 1121 | |
1122 | - $sort = ( isset( $this->_req_data['order'] ) && ! empty( $this->_req_data['order'] )) ? $this->_req_data['order'] : 'ASC'; |
|
1122 | + $sort = (isset($this->_req_data['order']) && ! empty($this->_req_data['order'])) ? $this->_req_data['order'] : 'ASC'; |
|
1123 | 1123 | |
1124 | - $current_page = isset( $this->_req_data['paged'] ) && !empty( $this->_req_data['paged'] ) ? $this->_req_data['paged'] : 1; |
|
1125 | - $per_page = isset( $per_page ) && !empty( $per_page ) ? $per_page : 10; |
|
1126 | - $per_page = isset( $this->_req_data['perpage'] ) && !empty( $this->_req_data['perpage'] ) ? $this->_req_data['perpage'] : $per_page; |
|
1124 | + $current_page = isset($this->_req_data['paged']) && ! empty($this->_req_data['paged']) ? $this->_req_data['paged'] : 1; |
|
1125 | + $per_page = isset($per_page) && ! empty($per_page) ? $per_page : 10; |
|
1126 | + $per_page = isset($this->_req_data['perpage']) && ! empty($this->_req_data['perpage']) ? $this->_req_data['perpage'] : $per_page; |
|
1127 | 1127 | |
1128 | 1128 | |
1129 | - $offset = ($current_page-1)*$per_page; |
|
1129 | + $offset = ($current_page - 1) * $per_page; |
|
1130 | 1130 | $limit = array($offset, $per_page); |
1131 | 1131 | |
1132 | - $category = isset( $this->_req_data['category'] ) && $this->_req_data['category'] > 0 ? $this->_req_data['category'] : NULL; |
|
1132 | + $category = isset($this->_req_data['category']) && $this->_req_data['category'] > 0 ? $this->_req_data['category'] : NULL; |
|
1133 | 1133 | $where = array(); |
1134 | 1134 | |
1135 | 1135 | //only set initial status if it is in the incoming request. Otherwise the "all" view display's all statuses. |
1136 | - if ( isset( $this->_req_data['status'] ) && $this->_req_data['status'] != 'all' ) { |
|
1136 | + if (isset($this->_req_data['status']) && $this->_req_data['status'] != 'all') { |
|
1137 | 1137 | $where['status'] = $this->_req_data['status']; |
1138 | 1138 | } |
1139 | 1139 | |
1140 | - if ( isset( $this->_req_data['venue_status'] ) ) { |
|
1140 | + if (isset($this->_req_data['venue_status'])) { |
|
1141 | 1141 | $where['status'] = $this->_req_data['venue_status']; |
1142 | 1142 | } |
1143 | 1143 | |
1144 | 1144 | |
1145 | - if ( $category ) { |
|
1145 | + if ($category) { |
|
1146 | 1146 | $where['Term_Taxonomy.taxonomy'] = 'espresso_venue_categories'; |
1147 | 1147 | $where['Term_Taxonomy.term_id'] = $category; |
1148 | 1148 | } |
1149 | 1149 | |
1150 | 1150 | |
1151 | - if ( ! EE_Registry::instance()->CAP->current_user_can( 'ee_read_others_venues', 'get_venues' ) ) { |
|
1152 | - $where['VNU_wp_user'] = get_current_user_id(); |
|
1151 | + if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_others_venues', 'get_venues')) { |
|
1152 | + $where['VNU_wp_user'] = get_current_user_id(); |
|
1153 | 1153 | } else { |
1154 | - if ( ! EE_Registry::instance()->CAP->current_user_can( 'ee_read_private_venues', 'get_venues' ) ) { |
|
1154 | + if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_private_venues', 'get_venues')) { |
|
1155 | 1155 | $where['OR'] = array( |
1156 | - 'status*restrict_private' => array( '!=', 'private' ), |
|
1156 | + 'status*restrict_private' => array('!=', 'private'), |
|
1157 | 1157 | 'AND' => array( |
1158 | - 'status*inclusive' => array( '=', 'private' ), |
|
1158 | + 'status*inclusive' => array('=', 'private'), |
|
1159 | 1159 | 'VNU_wp_user' => get_current_user_id() |
1160 | 1160 | ) |
1161 | 1161 | ); |
@@ -1165,30 +1165,30 @@ discard block |
||
1165 | 1165 | |
1166 | 1166 | |
1167 | 1167 | |
1168 | - if ( isset( $this->_req_data['s'] ) ) { |
|
1169 | - $sstr = '%' . $this->_req_data['s'] . '%'; |
|
1168 | + if (isset($this->_req_data['s'])) { |
|
1169 | + $sstr = '%'.$this->_req_data['s'].'%'; |
|
1170 | 1170 | $where['OR'] = array( |
1171 | - 'VNU_name' => array('LIKE',$sstr ), |
|
1172 | - 'VNU_desc' => array('LIKE',$sstr ), |
|
1173 | - 'VNU_short_desc' => array( 'LIKE',$sstr ), |
|
1174 | - 'VNU_address' => array( 'LIKE', $sstr ), |
|
1175 | - 'VNU_address2' => array( 'LIKE', $sstr ), |
|
1176 | - 'VNU_city' => array( 'LIKE', $sstr ), |
|
1177 | - 'VNU_zip' => array( 'LIKE', $sstr ), |
|
1178 | - 'VNU_phone' => array( 'LIKE', $sstr ), |
|
1179 | - 'VNU_url' => array( 'LIKE', $sstr ), |
|
1180 | - 'VNU_virtual_phone' => array( 'LIKE', $sstr ), |
|
1181 | - 'VNU_virtual_url' => array( 'LIKE', $sstr ), |
|
1182 | - 'VNU_google_map_link' => array( 'LIKE', $sstr ), |
|
1183 | - 'Event.EVT_name' => array('LIKE', $sstr ), |
|
1184 | - 'Event.EVT_desc' => array('LIKE', $sstr ), |
|
1185 | - 'Event.EVT_phone' => array('LIKE', $sstr ), |
|
1186 | - 'Event.EVT_external_URL' => array('LIKE', $sstr ), |
|
1171 | + 'VNU_name' => array('LIKE', $sstr), |
|
1172 | + 'VNU_desc' => array('LIKE', $sstr), |
|
1173 | + 'VNU_short_desc' => array('LIKE', $sstr), |
|
1174 | + 'VNU_address' => array('LIKE', $sstr), |
|
1175 | + 'VNU_address2' => array('LIKE', $sstr), |
|
1176 | + 'VNU_city' => array('LIKE', $sstr), |
|
1177 | + 'VNU_zip' => array('LIKE', $sstr), |
|
1178 | + 'VNU_phone' => array('LIKE', $sstr), |
|
1179 | + 'VNU_url' => array('LIKE', $sstr), |
|
1180 | + 'VNU_virtual_phone' => array('LIKE', $sstr), |
|
1181 | + 'VNU_virtual_url' => array('LIKE', $sstr), |
|
1182 | + 'VNU_google_map_link' => array('LIKE', $sstr), |
|
1183 | + 'Event.EVT_name' => array('LIKE', $sstr), |
|
1184 | + 'Event.EVT_desc' => array('LIKE', $sstr), |
|
1185 | + 'Event.EVT_phone' => array('LIKE', $sstr), |
|
1186 | + 'Event.EVT_external_URL' => array('LIKE', $sstr), |
|
1187 | 1187 | ); |
1188 | 1188 | } |
1189 | 1189 | |
1190 | 1190 | |
1191 | - $venues = $count ? $this->_venue_model->count( array($where), 'VNU_ID' ) : $this->_venue_model->get_all( array( $where, 'limit' => $limit, 'order_by' => $orderby, 'order' => $sort ) ); |
|
1191 | + $venues = $count ? $this->_venue_model->count(array($where), 'VNU_ID') : $this->_venue_model->get_all(array($where, 'limit' => $limit, 'order_by' => $orderby, 'order' => $sort)); |
|
1192 | 1192 | |
1193 | 1193 | return $venues; |
1194 | 1194 | |
@@ -1206,22 +1206,22 @@ discard block |
||
1206 | 1206 | * @return void |
1207 | 1207 | */ |
1208 | 1208 | private function _set_category_object() { |
1209 | - if ( isset( $this->_category->id ) && !empty( $this->_category->id ) ) |
|
1209 | + if (isset($this->_category->id) && ! empty($this->_category->id)) |
|
1210 | 1210 | return; //already have the category object so get out. |
1211 | 1211 | |
1212 | 1212 | //set default category object |
1213 | 1213 | $this->_set_empty_category_object(); |
1214 | 1214 | |
1215 | 1215 | //only set if we've got an id |
1216 | - if ( !isset($this->_req_data['VEN_CAT_ID'] ) ) { |
|
1216 | + if ( ! isset($this->_req_data['VEN_CAT_ID'])) { |
|
1217 | 1217 | return; |
1218 | 1218 | } |
1219 | 1219 | |
1220 | 1220 | $category_id = absint($this->_req_data['VEN_CAT_ID']); |
1221 | - $term = get_term( $category_id, 'espresso_venue_categories' ); |
|
1221 | + $term = get_term($category_id, 'espresso_venue_categories'); |
|
1222 | 1222 | |
1223 | 1223 | |
1224 | - if ( !empty( $term ) ) { |
|
1224 | + if ( ! empty($term)) { |
|
1225 | 1225 | $this->_category->category_name = $term->name; |
1226 | 1226 | $this->_category->category_identifier = $term->slug; |
1227 | 1227 | $this->_category->category_desc = $term->description; |
@@ -1235,15 +1235,15 @@ discard block |
||
1235 | 1235 | |
1236 | 1236 | private function _set_empty_category_object() { |
1237 | 1237 | $this->_category = new stdClass(); |
1238 | - $this->_category->category_name = $this->_category->category_identifier = $this->_category->category_desc = ''; |
|
1238 | + $this->_category->category_name = $this->_category->category_identifier = $this->_category->category_desc = ''; |
|
1239 | 1239 | $this->_category->id = $this->_category->parent = 0; |
1240 | 1240 | } |
1241 | 1241 | |
1242 | 1242 | |
1243 | 1243 | |
1244 | 1244 | protected function _category_list_table() { |
1245 | - do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' ); |
|
1246 | - $this->_admin_page_title .= ' ' . $this->get_action_link_or_button( |
|
1245 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
1246 | + $this->_admin_page_title .= ' '.$this->get_action_link_or_button( |
|
1247 | 1247 | 'add_category', |
1248 | 1248 | 'add_category', |
1249 | 1249 | array(), |
@@ -1263,13 +1263,13 @@ discard block |
||
1263 | 1263 | $this->_set_add_edit_form_tags($route); |
1264 | 1264 | |
1265 | 1265 | $this->_set_category_object(); |
1266 | - $id = !empty($this->_category->id) ? $this->_category->id : ''; |
|
1266 | + $id = ! empty($this->_category->id) ? $this->_category->id : ''; |
|
1267 | 1267 | |
1268 | 1268 | $delete_action = 'delete_category'; |
1269 | 1269 | |
1270 | - $redirect = EE_Admin_Page::add_query_args_and_nonce( array( 'action' => 'category_list' ), $this->_admin_base_url ); |
|
1270 | + $redirect = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'category_list'), $this->_admin_base_url); |
|
1271 | 1271 | |
1272 | - $this->_set_publish_post_box_vars( 'VEN_CAT_ID', $id, $delete_action, $redirect ); |
|
1272 | + $this->_set_publish_post_box_vars('VEN_CAT_ID', $id, $delete_action, $redirect); |
|
1273 | 1273 | |
1274 | 1274 | //take care of contents |
1275 | 1275 | $this->_template_args['admin_page_content'] = $this->_category_details_content(); |
@@ -1283,25 +1283,25 @@ discard block |
||
1283 | 1283 | 'type' => 'wp_editor', |
1284 | 1284 | 'value' => EEH_Formatter::admin_format_content($this->_category->category_desc), |
1285 | 1285 | 'class' => 'my_editor_custom', |
1286 | - 'wpeditor_args' => array( 'media_buttons' => FALSE ) |
|
1286 | + 'wpeditor_args' => array('media_buttons' => FALSE) |
|
1287 | 1287 | ); |
1288 | - $_wp_editor = $this->_generate_admin_form_fields( $editor_args, 'array' ); |
|
1288 | + $_wp_editor = $this->_generate_admin_form_fields($editor_args, 'array'); |
|
1289 | 1289 | |
1290 | - $all_terms = get_terms( array('espresso_venue_categories' ), array( 'hide_empty' => 0, 'exclude' => array( $this->_category->id ) ) ); |
|
1290 | + $all_terms = get_terms(array('espresso_venue_categories'), array('hide_empty' => 0, 'exclude' => array($this->_category->id))); |
|
1291 | 1291 | |
1292 | 1292 | //setup category select for term parents. |
1293 | 1293 | $category_select_values[] = array( |
1294 | 1294 | 'text' => __('No Parent', 'event_espresso'), |
1295 | 1295 | 'id' => 0 |
1296 | 1296 | ); |
1297 | - foreach ( $all_terms as $term ) { |
|
1297 | + foreach ($all_terms as $term) { |
|
1298 | 1298 | $category_select_values[] = array( |
1299 | 1299 | 'text' => $term->name, |
1300 | 1300 | 'id' => $term->term_id |
1301 | 1301 | ); |
1302 | 1302 | } |
1303 | 1303 | |
1304 | - $category_select = EEH_Form_Fields::select_input( 'category_parent', $category_select_values, $this->_category->parent ); |
|
1304 | + $category_select = EEH_Form_Fields::select_input('category_parent', $category_select_values, $this->_category->parent); |
|
1305 | 1305 | $template_args = array( |
1306 | 1306 | 'category' => $this->_category, |
1307 | 1307 | 'category_select' => $category_select, |
@@ -1310,15 +1310,15 @@ discard block |
||
1310 | 1310 | 'disable' => '', |
1311 | 1311 | 'disabled_message' =>FALSE |
1312 | 1312 | ); |
1313 | - $template = EVENTS_TEMPLATE_PATH . 'event_category_details.template.php'; |
|
1314 | - return EEH_Template::display_template($template, $template_args, TRUE ); |
|
1313 | + $template = EVENTS_TEMPLATE_PATH.'event_category_details.template.php'; |
|
1314 | + return EEH_Template::display_template($template, $template_args, TRUE); |
|
1315 | 1315 | } |
1316 | 1316 | |
1317 | 1317 | |
1318 | 1318 | protected function _delete_categories() { |
1319 | - $cat_ids = isset( $this->_req_data['VEN_CAT_ID'] ) ? (array) $this->_req_data['VEN_CAT_ID'] : (array) $this->_req_data['category_id']; |
|
1319 | + $cat_ids = isset($this->_req_data['VEN_CAT_ID']) ? (array) $this->_req_data['VEN_CAT_ID'] : (array) $this->_req_data['category_id']; |
|
1320 | 1320 | |
1321 | - foreach ( $cat_ids as $cat_id ) { |
|
1321 | + foreach ($cat_ids as $cat_id) { |
|
1322 | 1322 | $this->_delete_category($cat_id); |
1323 | 1323 | } |
1324 | 1324 | |
@@ -1326,7 +1326,7 @@ discard block |
||
1326 | 1326 | $query_args = array( |
1327 | 1327 | 'action' => 'category_list' |
1328 | 1328 | ); |
1329 | - $this->_redirect_after_action(0,'','',$query_args); |
|
1329 | + $this->_redirect_after_action(0, '', '', $query_args); |
|
1330 | 1330 | |
1331 | 1331 | } |
1332 | 1332 | |
@@ -1335,58 +1335,58 @@ discard block |
||
1335 | 1335 | |
1336 | 1336 | |
1337 | 1337 | protected function _delete_category($cat_id) { |
1338 | - $cat_id = absint( $cat_id ); |
|
1339 | - wp_delete_term( $cat_id, 'espresso_venue_categories' ); |
|
1338 | + $cat_id = absint($cat_id); |
|
1339 | + wp_delete_term($cat_id, 'espresso_venue_categories'); |
|
1340 | 1340 | } |
1341 | 1341 | |
1342 | 1342 | |
1343 | 1343 | |
1344 | 1344 | protected function _insert_or_update_category($new_category) { |
1345 | 1345 | |
1346 | - $cat_id = $new_category ? $this->_insert_category() : $this->_insert_category( TRUE ); |
|
1346 | + $cat_id = $new_category ? $this->_insert_category() : $this->_insert_category(TRUE); |
|
1347 | 1347 | $success = 0; //we already have a success message so lets not send another. |
1348 | - if ( $cat_id ) { |
|
1348 | + if ($cat_id) { |
|
1349 | 1349 | $query_args = array( |
1350 | 1350 | 'action' => 'edit_category', |
1351 | 1351 | 'VEN_CAT_ID' => $cat_id |
1352 | 1352 | ); |
1353 | 1353 | } else { |
1354 | - $query_args = array( 'action' => 'add_category' ); |
|
1354 | + $query_args = array('action' => 'add_category'); |
|
1355 | 1355 | } |
1356 | - $this->_redirect_after_action( $success, '','', $query_args, TRUE ); |
|
1356 | + $this->_redirect_after_action($success, '', '', $query_args, TRUE); |
|
1357 | 1357 | |
1358 | 1358 | } |
1359 | 1359 | |
1360 | 1360 | |
1361 | 1361 | |
1362 | - private function _insert_category( $update = FALSE ) { |
|
1362 | + private function _insert_category($update = FALSE) { |
|
1363 | 1363 | $cat_id = $update ? $this->_req_data['VEN_CAT_ID'] : ''; |
1364 | - $category_name= isset( $this->_req_data['category_name'] ) ? $this->_req_data['category_name'] : ''; |
|
1365 | - $category_desc= isset( $this->_req_data['category_desc'] ) ? $this->_req_data['category_desc'] : ''; |
|
1366 | - $category_parent = isset( $this->_req_data['category_parent'] ) ? $this->_req_data['category_parent'] : 0; |
|
1364 | + $category_name = isset($this->_req_data['category_name']) ? $this->_req_data['category_name'] : ''; |
|
1365 | + $category_desc = isset($this->_req_data['category_desc']) ? $this->_req_data['category_desc'] : ''; |
|
1366 | + $category_parent = isset($this->_req_data['category_parent']) ? $this->_req_data['category_parent'] : 0; |
|
1367 | 1367 | |
1368 | - if ( empty( $category_name ) ) { |
|
1369 | - $msg = __( 'You must add a name for the category.', 'event_espresso' ); |
|
1370 | - EE_Error::add_error( $msg, __FILE__, __FUNCTION__, __LINE__ ); |
|
1368 | + if (empty($category_name)) { |
|
1369 | + $msg = __('You must add a name for the category.', 'event_espresso'); |
|
1370 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
1371 | 1371 | return false; |
1372 | 1372 | } |
1373 | 1373 | |
1374 | 1374 | |
1375 | - $term_args=array( |
|
1375 | + $term_args = array( |
|
1376 | 1376 | 'name'=>$category_name, |
1377 | 1377 | 'description'=>$category_desc, |
1378 | 1378 | 'parent'=>$category_parent |
1379 | 1379 | ); |
1380 | 1380 | |
1381 | - $insert_ids = $update ? wp_update_term( $cat_id, 'espresso_venue_categories', $term_args ) :wp_insert_term( $category_name, 'espresso_venue_categories', $term_args ); |
|
1381 | + $insert_ids = $update ? wp_update_term($cat_id, 'espresso_venue_categories', $term_args) : wp_insert_term($category_name, 'espresso_venue_categories', $term_args); |
|
1382 | 1382 | |
1383 | - if ( !is_array( $insert_ids ) ) { |
|
1384 | - $msg = __( 'An error occurred and the category has not been saved to the database.', 'event_espresso' ); |
|
1385 | - EE_Error::add_error( $msg, __FILE__, __FUNCTION__, __LINE__ ); |
|
1383 | + if ( ! is_array($insert_ids)) { |
|
1384 | + $msg = __('An error occurred and the category has not been saved to the database.', 'event_espresso'); |
|
1385 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
1386 | 1386 | } else { |
1387 | 1387 | $cat_id = $insert_ids['term_id']; |
1388 | - $msg = sprintf ( __('The category %s was successfully created', 'event_espresso'), $category_name ); |
|
1389 | - EE_Error::add_success( $msg ); |
|
1388 | + $msg = sprintf(__('The category %s was successfully created', 'event_espresso'), $category_name); |
|
1389 | + EE_Error::add_success($msg); |
|
1390 | 1390 | } |
1391 | 1391 | |
1392 | 1392 | return $cat_id; |
@@ -1406,11 +1406,11 @@ discard block |
||
1406 | 1406 | 'category_ids' => $this->_req_data['VEN_CAT_ID'] |
1407 | 1407 | ); |
1408 | 1408 | |
1409 | - $this->_req_data = array_merge( $this->_req_data, $new_request_args ); |
|
1409 | + $this->_req_data = array_merge($this->_req_data, $new_request_args); |
|
1410 | 1410 | |
1411 | - if ( is_readable( EE_CLASSES . 'EE_Export.class.php') ) { |
|
1412 | - require_once( EE_CLASSES . 'EE_Export.class.php'); |
|
1413 | - $EE_Export = EE_Export::instance( $this->_req_data ); |
|
1411 | + if (is_readable(EE_CLASSES.'EE_Export.class.php')) { |
|
1412 | + require_once(EE_CLASSES.'EE_Export.class.php'); |
|
1413 | + $EE_Export = EE_Export::instance($this->_req_data); |
|
1414 | 1414 | $EE_Export->export(); |
1415 | 1415 | } |
1416 | 1416 | |
@@ -1422,7 +1422,7 @@ discard block |
||
1422 | 1422 | |
1423 | 1423 | protected function _import_categories() { |
1424 | 1424 | |
1425 | - require_once(EE_CLASSES . 'EE_Import.class.php'); |
|
1425 | + require_once(EE_CLASSES.'EE_Import.class.php'); |
|
1426 | 1426 | EE_Import::instance()->import(); |
1427 | 1427 | |
1428 | 1428 | } |
@@ -1430,29 +1430,29 @@ discard block |
||
1430 | 1430 | |
1431 | 1431 | |
1432 | 1432 | |
1433 | - public function get_categories( $per_page = 10, $current_page = 1, $count = FALSE ) { |
|
1433 | + public function get_categories($per_page = 10, $current_page = 1, $count = FALSE) { |
|
1434 | 1434 | |
1435 | 1435 | //testing term stuff |
1436 | - $orderby = isset( $this->_req_data['orderby'] ) ? $this->_req_data['orderby'] : 'Term.term_id'; |
|
1437 | - $order = isset( $this->_req_data['order'] ) ? $this->_req_data['order'] : 'DESC'; |
|
1438 | - $limit = ($current_page-1)*$per_page; |
|
1439 | - $where = array( 'taxonomy' => 'espresso_venue_categories' ); |
|
1440 | - if ( isset( $this->_req_data['s'] ) ) { |
|
1441 | - $sstr = '%' . $this->_req_data['s'] . '%'; |
|
1436 | + $orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'Term.term_id'; |
|
1437 | + $order = isset($this->_req_data['order']) ? $this->_req_data['order'] : 'DESC'; |
|
1438 | + $limit = ($current_page - 1) * $per_page; |
|
1439 | + $where = array('taxonomy' => 'espresso_venue_categories'); |
|
1440 | + if (isset($this->_req_data['s'])) { |
|
1441 | + $sstr = '%'.$this->_req_data['s'].'%'; |
|
1442 | 1442 | $where['OR'] = array( |
1443 | - 'Term.name' => array( 'LIKE', $sstr), |
|
1444 | - 'description' => array( 'LIKE', $sstr ) |
|
1443 | + 'Term.name' => array('LIKE', $sstr), |
|
1444 | + 'description' => array('LIKE', $sstr) |
|
1445 | 1445 | ); |
1446 | 1446 | } |
1447 | 1447 | |
1448 | 1448 | $query_params = array( |
1449 | 1449 | $where, |
1450 | - 'order_by' => array( $orderby => $order ), |
|
1451 | - 'limit' => $limit . ',' . $per_page, |
|
1450 | + 'order_by' => array($orderby => $order), |
|
1451 | + 'limit' => $limit.','.$per_page, |
|
1452 | 1452 | 'force_join' => array('Term') |
1453 | 1453 | ); |
1454 | 1454 | |
1455 | - $categories = $count ? EEM_Term_Taxonomy::instance()->count( $query_params, 'term_id' ) :EEM_Term_Taxonomy::instance()->get_all( $query_params ); |
|
1455 | + $categories = $count ? EEM_Term_Taxonomy::instance()->count($query_params, 'term_id') : EEM_Term_Taxonomy::instance()->get_all($query_params); |
|
1456 | 1456 | |
1457 | 1457 | return $categories; |
1458 | 1458 | } |
@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <div class="padding"> |
2 | 2 | <?php |
3 | 3 | //we'll only show site-license keys if this is main_site() (which works for both multi-site and single-site wp installations) |
4 | - if ( is_main_site() ) { ?> |
|
4 | + if (is_main_site()) { ?> |
|
5 | 5 | <h2 class="ee-admin-settings-hdr" style="width:300px;"> |
6 | 6 | <?php _e('Your Event Espresso License Key', 'event_espresso'); ?> |
7 | 7 | </h2> |
@@ -11,13 +11,13 @@ discard block |
||
11 | 11 | <tr <?php echo isset($_REQUEST['license_key']) && $_REQUEST['license_key'] == true ? 'class="yellow_alert"' : '' ?>> |
12 | 12 | <th> |
13 | 13 | <label for="site_license_key"> |
14 | - <?php _e('Support License Key', 'event_espresso'); ?> <?php echo EEH_Template::get_help_tab_link('site_license_key_info');?> |
|
14 | + <?php _e('Support License Key', 'event_espresso'); ?> <?php echo EEH_Template::get_help_tab_link('site_license_key_info'); ?> |
|
15 | 15 | </label> |
16 | 16 | </th> |
17 | 17 | <td> |
18 | 18 | <input name="site_license_key" id="site_license_key" size="10" class="regular-text" type="text" value="<?php echo esc_attr($site_license_key); ?>" /><?php echo $site_license_key_verified; ?><br/> |
19 | 19 | <p class="description"> |
20 | - <?php printf( __('Adding a valid Support License Key will enable automatic update notifications and backend updates for Event Espresso Core and any installed add-ons. If this is a Development or Test site, %sDO NOT%s enter your Support License Key.', 'event_espresso'), '<strong>', '</strong>' ); ?> |
|
20 | + <?php printf(__('Adding a valid Support License Key will enable automatic update notifications and backend updates for Event Espresso Core and any installed add-ons. If this is a Development or Test site, %sDO NOT%s enter your Support License Key.', 'event_espresso'), '<strong>', '</strong>'); ?> |
|
21 | 21 | </p> |
22 | 22 | </td> |
23 | 23 | </tr> |
@@ -30,7 +30,7 @@ discard block |
||
30 | 30 | |
31 | 31 | |
32 | 32 | <h2 id="contact_info_h4" class="ee-admin-settings-hdr"> |
33 | - <?php _e('Contact Information', 'event_espresso'); ?> <?php echo EEH_Template::get_help_tab_link('contact_info_info');?> |
|
33 | + <?php _e('Contact Information', 'event_espresso'); ?> <?php echo EEH_Template::get_help_tab_link('contact_info_info'); ?> |
|
34 | 34 | </h2> |
35 | 35 | |
36 | 36 | <table class="form-table"> |
@@ -78,8 +78,8 @@ discard block |
||
78 | 78 | <input id="organization_city" class="regular-text" type="text" name="organization_city" value="<?php echo esc_textarea($organization_city); ?>" /> |
79 | 79 | </td> |
80 | 80 | </tr> |
81 | - <?php echo EEH_Form_Fields::generate_form_input( $states ); ?> |
|
82 | - <?php echo EEH_Form_Fields::generate_form_input( $countries ); ?> |
|
81 | + <?php echo EEH_Form_Fields::generate_form_input($states); ?> |
|
82 | + <?php echo EEH_Form_Fields::generate_form_input($countries); ?> |
|
83 | 83 | <tr> |
84 | 84 | <th> |
85 | 85 | <label for="organization_zip"> |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | <td> |
100 | 100 | <input class="regular-text" type="text" name="organization_email" value="<?php echo esc_textarea($organization_email); ?>" /> |
101 | 101 | <p class="description"> |
102 | - <?php echo sprintf( esc_html__('This is where notifications go to when you use the %1$s and %2$s shortcodes in the message templates.', 'event_espresso'), '<code>[CO_FORMATTED_EMAIL]</code>', '<code>[CO_EMAIL]</code>' ); ?> |
|
102 | + <?php echo sprintf(esc_html__('This is where notifications go to when you use the %1$s and %2$s shortcodes in the message templates.', 'event_espresso'), '<code>[CO_FORMATTED_EMAIL]</code>', '<code>[CO_EMAIL]</code>'); ?> |
|
103 | 103 | </p> |
104 | 104 | </td> |
105 | 105 | </tr> |
@@ -133,7 +133,7 @@ discard block |
||
133 | 133 | </table> |
134 | 134 | |
135 | 135 | <h2 class="ee-admin-settings-hdr"> |
136 | - <?php _e('Company Logo', 'event_espresso'); ?> <?php echo EEH_Template::get_help_tab_link('organization_logo_info');?> |
|
136 | + <?php _e('Company Logo', 'event_espresso'); ?> <?php echo EEH_Template::get_help_tab_link('organization_logo_info'); ?> |
|
137 | 137 | </h2> |
138 | 138 | |
139 | 139 | <table class="form-table"> |
@@ -161,7 +161,7 @@ discard block |
||
161 | 161 | </th> |
162 | 162 | <td> |
163 | 163 | <?php |
164 | - if ( $organization_logo_url ) { |
|
164 | + if ($organization_logo_url) { |
|
165 | 165 | ?> |
166 | 166 | <p id="default-logo-thumb"> |
167 | 167 | <img id="current-image-thumb" src="<?php echo esc_url($organization_logo_url) ?>" alt="" /><br /> |
@@ -179,7 +179,7 @@ discard block |
||
179 | 179 | <br/><br/> |
180 | 180 | |
181 | 181 | <h2 class="ee-admin-settings-hdr"> |
182 | - <?php _e('Social Links', 'event_espresso'); ?> <?php echo EEH_Template::get_help_tab_link('social_links_info');?> |
|
182 | + <?php _e('Social Links', 'event_espresso'); ?> <?php echo EEH_Template::get_help_tab_link('social_links_info'); ?> |
|
183 | 183 | </h2> |
184 | 184 | <p class="description"><?php _e('Enter any links to social accounts for your organization here', 'event_espresso'); ?></p> |
185 | 185 | |
@@ -256,9 +256,9 @@ discard block |
||
256 | 256 | <br/><br/> |
257 | 257 | |
258 | 258 | |
259 | - <?php if ( is_main_site() ) : ?> |
|
259 | + <?php if (is_main_site()) : ?> |
|
260 | 260 | <p> |
261 | - <?php echo EE_PUE::espresso_data_collection_optin_text( FALSE ); ?> |
|
261 | + <?php echo EE_PUE::espresso_data_collection_optin_text(FALSE); ?> |
|
262 | 262 | </p> |
263 | 263 | |
264 | 264 | <table class="form-table"> |
@@ -272,11 +272,11 @@ discard block |
||
272 | 272 | </th> |
273 | 273 | <td> |
274 | 274 | <?php |
275 | - $values=array( |
|
276 | - array('id'=>'yes','text'=> __('Yes! I want to help improve Event Espresso!','event_espresso')), |
|
277 | - array('id'=>'no','text'=> __('Not at this time. Maybe later.','event_espresso')) |
|
275 | + $values = array( |
|
276 | + array('id'=>'yes', 'text'=> __('Yes! I want to help improve Event Espresso!', 'event_espresso')), |
|
277 | + array('id'=>'no', 'text'=> __('Not at this time. Maybe later.', 'event_espresso')) |
|
278 | 278 | ); |
279 | - echo EEH_Form_Fields::select_input('ueip_optin', $values, !empty($ee_ueip_optin) ? $ee_ueip_optin : 'yes'); |
|
279 | + echo EEH_Form_Fields::select_input('ueip_optin', $values, ! empty($ee_ueip_optin) ? $ee_ueip_optin : 'yes'); |
|
280 | 280 | ?> |
281 | 281 | </td> |
282 | 282 | </tr> |
@@ -3,9 +3,9 @@ discard block |
||
3 | 3 | <table class="form-table"> |
4 | 4 | <tbody> |
5 | 5 | <tr valign="top"> |
6 | - <th><label for="PRT_ID"><?php _e('Type', 'event_espresso'); ?></label> <?php echo EEH_Template::get_help_tab_link('type_field_info');?></th> |
|
6 | + <th><label for="PRT_ID"><?php _e('Type', 'event_espresso'); ?></label> <?php echo EEH_Template::get_help_tab_link('type_field_info'); ?></th> |
|
7 | 7 | <td> |
8 | - <?php if ( $price->type_obj() && $price->type_obj()->base_type() === 1 ) : ?> |
|
8 | + <?php if ($price->type_obj() && $price->type_obj()->base_type() === 1) : ?> |
|
9 | 9 | <input type="hidden" name="PRT_ID" id="PRT_ID" value="<?php echo $price->type(); ?>" /> |
10 | 10 | <p><strong><?php _e('Price', 'event_espresso'); ?></strong></p> |
11 | 11 | <p class="description"><?php _e('This is the default base price. Every new ticket created will start off with this base price.', 'event_espresso'); ?></p> |
@@ -16,13 +16,13 @@ discard block |
||
16 | 16 | </td> |
17 | 17 | </tr> |
18 | 18 | <tr valign="top"> |
19 | - <th><label for="PRC_name"><?php _e('Name', 'event_espresso'); ?></label> <?php echo EEH_Template::get_help_tab_link('name_field_info');?></th> |
|
19 | + <th><label for="PRC_name"><?php _e('Name', 'event_espresso'); ?></label> <?php echo EEH_Template::get_help_tab_link('name_field_info'); ?></th> |
|
20 | 20 | <td> |
21 | 21 | <input class="regular-text" type="text" id="PRC_name" name="PRC_name" value="<?php $price->f('PRC_name'); ?>"/> |
22 | 22 | </td> |
23 | 23 | </tr> |
24 | 24 | <tr valign="top"> |
25 | - <th><label for="PRC_desc"><?php _e('Description', 'event_espresso'); ?></label> <?php echo EEH_Template::get_help_tab_link('description_field_info');?></th> |
|
25 | + <th><label for="PRC_desc"><?php _e('Description', 'event_espresso'); ?></label> <?php echo EEH_Template::get_help_tab_link('description_field_info'); ?></th> |
|
26 | 26 | <td> |
27 | 27 | <textarea class="regular-text" id="PRC_desc" name="PRC_desc" rows="5" ><?php |
28 | 28 | $price->f('PRC_desc'); |
@@ -30,7 +30,7 @@ discard block |
||
30 | 30 | </td> |
31 | 31 | </tr> |
32 | 32 | <tr valign="top"> |
33 | - <th><label for="PRC_amount"><?php _e('Amount', 'event_espresso'); ?> <?php echo EEH_Template::get_help_tab_link('amount_field_info');?></label></th> |
|
33 | + <th><label for="PRC_amount"><?php _e('Amount', 'event_espresso'); ?> <?php echo EEH_Template::get_help_tab_link('amount_field_info'); ?></label></th> |
|
34 | 34 | <td> |
35 | 35 | <input class="small-text ee-numeric" type="text" id="PRC_amount" name="PRC_amount" value="<?php echo $price->amount(); ?>"/> |
36 | 36 | </td> |
@@ -9,8 +9,8 @@ discard block |
||
9 | 9 | assert($question_group); |
10 | 10 | assert($question_group instanceof EE_Question_Group); |
11 | 11 | /* @var EE_Question[] $all_questions */ |
12 | -assert(isset($all_questions) && (empty($all_questions) || is_array($all_questions)));//list of unused questions |
|
13 | -foreach($all_questions as $unused_question){ |
|
12 | +assert(isset($all_questions) && (empty($all_questions) || is_array($all_questions))); //list of unused questions |
|
13 | +foreach ($all_questions as $unused_question) { |
|
14 | 14 | assert($unused_question); |
15 | 15 | assert($unused_question instanceof EE_Question); |
16 | 16 | } |
@@ -19,8 +19,8 @@ discard block |
||
19 | 19 | |
20 | 20 | $QSG_system = $question_group->system_group(); |
21 | 21 | |
22 | -$disabled = ! empty( $QSG_system ) ? ' disabled="disabled"' : ''; |
|
23 | -$id = ! empty( $QST_system ) ? '_disabled' : ''; |
|
22 | +$disabled = ! empty($QSG_system) ? ' disabled="disabled"' : ''; |
|
23 | +$id = ! empty($QST_system) ? '_disabled' : ''; |
|
24 | 24 | ?> |
25 | 25 | |
26 | 26 | <div id="group-details" class="edit-group padding"> |
@@ -30,7 +30,7 @@ discard block |
||
30 | 30 | <tr> |
31 | 31 | <th> |
32 | 32 | <label for="QSG_name"> |
33 | - <?php _e('Group Name','event_espresso');?> <?php echo EEH_Template::get_help_tab_link('group_name_info');?> |
|
33 | + <?php _e('Group Name', 'event_espresso'); ?> <?php echo EEH_Template::get_help_tab_link('group_name_info'); ?> |
|
34 | 34 | </label> |
35 | 35 | </th> |
36 | 36 | <td> |
@@ -42,14 +42,14 @@ discard block |
||
42 | 42 | <tr> |
43 | 43 | <th> |
44 | 44 | <label for="QSG_identifier"> |
45 | - <?php _e('Group Identifier','event_espresso');?> <?php echo EEH_Template::get_help_tab_link('group_identifier_info');?> |
|
45 | + <?php _e('Group Identifier', 'event_espresso'); ?> <?php echo EEH_Template::get_help_tab_link('group_identifier_info'); ?> |
|
46 | 46 | </label> |
47 | 47 | </th> |
48 | 48 | <td> |
49 | 49 | <input id="QSG_identifier" name="QSG_identifier<?php echo $id; ?>" value="<?php $question_group->f('QSG_identifier')?>" type="text" class="regular-text"<?php echo $disabled; ?>> |
50 | - <?php if ( ! empty( $QSG_system )) { ?> |
|
50 | + <?php if ( ! empty($QSG_system)) { ?> |
|
51 | 51 | <p><span class="description" style="color:#D54E21;"> |
52 | - <?php _e('System question group! This field cannot be changed.','event_espresso')?> |
|
52 | + <?php _e('System question group! This field cannot be changed.', 'event_espresso')?> |
|
53 | 53 | </span><br/></p> |
54 | 54 | <?php } ?> |
55 | 55 | |
@@ -58,7 +58,7 @@ discard block |
||
58 | 58 | <tr> |
59 | 59 | <th> |
60 | 60 | <label for="QSG_desc"> |
61 | - <?php _e('Description','event_espresso');?> <?php echo EEH_Template::get_help_tab_link('group_description_info');?> |
|
61 | + <?php _e('Description', 'event_espresso'); ?> <?php echo EEH_Template::get_help_tab_link('group_description_info'); ?> |
|
62 | 62 | </label> |
63 | 63 | </th> |
64 | 64 | <td> |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | <tr> |
70 | 70 | <th> |
71 | 71 | <label for="QSG_order"> |
72 | - <?php _e('Question Group Order','event_espresso');?> <?php echo EEH_Template::get_help_tab_link('group_order_info');?> |
|
72 | + <?php _e('Question Group Order', 'event_espresso'); ?> <?php echo EEH_Template::get_help_tab_link('group_order_info'); ?> |
|
73 | 73 | </label> |
74 | 74 | </th> |
75 | 75 | <td> |
@@ -80,13 +80,13 @@ discard block |
||
80 | 80 | <tr> |
81 | 81 | <th> |
82 | 82 | <label> |
83 | - <?php _e('Show Name','event_espresso');?> <?php echo EEH_Template::get_help_tab_link('show_group_name_info');?> |
|
83 | + <?php _e('Show Name', 'event_espresso'); ?> <?php echo EEH_Template::get_help_tab_link('show_group_name_info'); ?> |
|
84 | 84 | </label> |
85 | 85 | </th> |
86 | 86 | <td> |
87 | 87 | <label for="QSG_show_group_name"> |
88 | - <?php echo EEH_Form_Fields::select_input( 'QSG_show_group_name', $values, $question_group->show_group_name() ); ?> |
|
89 | - <p class="description"><?php _e('Show Group Name on Registration Page?','event_espresso');?></p> |
|
88 | + <?php echo EEH_Form_Fields::select_input('QSG_show_group_name', $values, $question_group->show_group_name()); ?> |
|
89 | + <p class="description"><?php _e('Show Group Name on Registration Page?', 'event_espresso'); ?></p> |
|
90 | 90 | </label> |
91 | 91 | </td> |
92 | 92 | </tr> |
@@ -94,13 +94,13 @@ discard block |
||
94 | 94 | <tr> |
95 | 95 | <th> |
96 | 96 | <label> |
97 | - <?php _e(' Show Description','event_espresso');?> <?php echo EEH_Template::get_help_tab_link('show_group_description_info');?> |
|
97 | + <?php _e(' Show Description', 'event_espresso'); ?> <?php echo EEH_Template::get_help_tab_link('show_group_description_info'); ?> |
|
98 | 98 | </label> |
99 | 99 | </th> |
100 | 100 | <td> |
101 | 101 | <label for="QSG_show_group_order"> |
102 | - <?php echo EEH_Form_Fields::select_input( 'QSG_show_group_desc', $values, $question_group->show_group_desc() ); ?> |
|
103 | - <p class="description"><?php _e(' Show Group Description on Registration Page?','event_espresso');?></p> |
|
102 | + <?php echo EEH_Form_Fields::select_input('QSG_show_group_desc', $values, $question_group->show_group_desc()); ?> |
|
103 | + <p class="description"><?php _e(' Show Group Description on Registration Page?', 'event_espresso'); ?></p> |
|
104 | 104 | </label> |
105 | 105 | <input type="hidden" name="QSG_system" value="<?php echo $question_group->system_group(); ?>"> |
106 | 106 | </td> |
@@ -111,8 +111,8 @@ discard block |
||
111 | 111 | </div> |
112 | 112 | |
113 | 113 | <div id="group-questions" class="edit-group padding question-group-questions-container postbox"> |
114 | - <div class="handlediv" title="<?php esc_attr_e( 'Click to toggle', 'event_espresso' ); ?>"><br></div> |
|
115 | - <h2 class="handle"><?php _e('Questions','event_espresso');?></h2> |
|
114 | + <div class="handlediv" title="<?php esc_attr_e('Click to toggle', 'event_espresso'); ?>"><br></div> |
|
115 | + <h2 class="handle"><?php _e('Questions', 'event_espresso'); ?></h2> |
|
116 | 116 | <div class="form-table question-group-questions inside"> |
117 | 117 | <div class="padding"> |
118 | 118 | <p><span class="description"><?php _e('Select which questions should be shown in this group by checking or unchecking boxes. You can drag and drop questions to reorder them. Your changes will be updated when you save.', 'event_espresso'); ?></span></p> |
@@ -121,26 +121,26 @@ discard block |
||
121 | 121 | <?php |
122 | 122 | $question_order = 0; |
123 | 123 | $question_group_questions = $question_group->questions(); |
124 | - foreach( $all_questions as $question_ID => $question ){ |
|
125 | - if ( $question instanceof EE_Question ) { |
|
124 | + foreach ($all_questions as $question_ID => $question) { |
|
125 | + if ($question instanceof EE_Question) { |
|
126 | 126 | /*@var $question EE_Question*/ |
127 | - $checked = isset( $question_group_questions[ $question_ID ] ) ? ' checked="checked"' : ''; |
|
127 | + $checked = isset($question_group_questions[$question_ID]) ? ' checked="checked"' : ''; |
|
128 | 128 | // disable questions from the personal information question group |
129 | 129 | // is it required in the current question group? if so don't allow admins to remove it |
130 | - $disabled = in_array( $question->system_ID(), EEM_Question::instance()->required_system_questions_in_system_question_group( $QSG_system ) ) ? 'disabled="disabled"' : ''; |
|
130 | + $disabled = in_array($question->system_ID(), EEM_Question::instance()->required_system_questions_in_system_question_group($QSG_system)) ? 'disabled="disabled"' : ''; |
|
131 | 131 | //limit where system questions can appear |
132 | 132 | if ( |
133 | 133 | $question->system_ID() && |
134 | - ! in_array( $question->system_ID(), EEM_Question::instance()->allowed_system_questions_in_system_question_group( $QSG_system ) ) |
|
134 | + ! in_array($question->system_ID(), EEM_Question::instance()->allowed_system_questions_in_system_question_group($QSG_system)) |
|
135 | 135 | ) { |
136 | 136 | continue; //skip over system question not assigned to this group except for the address system group cause we want the address questions to display even if they aren't selected (but still not show the personal system questions). The third condition checks if we're displaying a non system question group and the question is a system question, then we skip because for non-system question groups we only want to show non-system questions. |
137 | 137 | } |
138 | 138 | ?> |
139 | 139 | <li class="ee-question-sortable"> |
140 | 140 | <label for="question-<?php echo $question_ID?>"> |
141 | - <input type="checkbox" name="questions[<?php echo $question_ID;?>]" id="question-<?php echo $question_ID; ?>" value="<?php echo $question_ID;?>"<?php echo $disabled; ?><?php echo $checked; ?>/> |
|
141 | + <input type="checkbox" name="questions[<?php echo $question_ID; ?>]" id="question-<?php echo $question_ID; ?>" value="<?php echo $question_ID; ?>"<?php echo $disabled; ?><?php echo $checked; ?>/> |
|
142 | 142 | <span class="question-text"> |
143 | - <?php echo trim( $question->display_text() ) . ( 95 <= strlen( trim( $question->display_text() ) ) ? "…" : '' ); ?> |
|
143 | + <?php echo trim($question->display_text()).(95 <= strlen(trim($question->display_text())) ? "…" : ''); ?> |
|
144 | 144 | </span> |
145 | 145 | <input class="question-group-QGQ_order" type="hidden" name="question_orders[<?php echo $question_ID; ?>]" value="<?php echo $question_order; ?>"> |
146 | 146 | </label> |
@@ -23,1585 +23,1585 @@ |
||
23 | 23 | class EE_Registry implements ResettableInterface |
24 | 24 | { |
25 | 25 | |
26 | - /** |
|
27 | - * @var EE_Registry $_instance |
|
28 | - */ |
|
29 | - private static $_instance; |
|
30 | - |
|
31 | - /** |
|
32 | - * @var EE_Dependency_Map $_dependency_map |
|
33 | - */ |
|
34 | - protected $_dependency_map; |
|
35 | - |
|
36 | - /** |
|
37 | - * @var array $_class_abbreviations |
|
38 | - */ |
|
39 | - protected $_class_abbreviations = array(); |
|
40 | - |
|
41 | - /** |
|
42 | - * @var CommandBusInterface $BUS |
|
43 | - */ |
|
44 | - public $BUS; |
|
45 | - |
|
46 | - /** |
|
47 | - * @var EE_Cart $CART |
|
48 | - */ |
|
49 | - public $CART; |
|
50 | - |
|
51 | - /** |
|
52 | - * @var EE_Config $CFG |
|
53 | - */ |
|
54 | - public $CFG; |
|
55 | - |
|
56 | - /** |
|
57 | - * @var EE_Network_Config $NET_CFG |
|
58 | - */ |
|
59 | - public $NET_CFG; |
|
60 | - |
|
61 | - /** |
|
62 | - * StdClass object for storing library classes in |
|
63 | - * |
|
64 | - * @var StdClass $LIB |
|
65 | - */ |
|
66 | - public $LIB; |
|
67 | - |
|
68 | - /** |
|
69 | - * @var EE_Request_Handler $REQ |
|
70 | - */ |
|
71 | - public $REQ; |
|
72 | - |
|
73 | - /** |
|
74 | - * @var EE_Session $SSN |
|
75 | - */ |
|
76 | - public $SSN; |
|
77 | - |
|
78 | - /** |
|
79 | - * @since 4.5.0 |
|
80 | - * @var EE_Capabilities $CAP |
|
81 | - */ |
|
82 | - public $CAP; |
|
83 | - |
|
84 | - /** |
|
85 | - * @since 4.9.0 |
|
86 | - * @var EE_Message_Resource_Manager $MRM |
|
87 | - */ |
|
88 | - public $MRM; |
|
89 | - |
|
90 | - |
|
91 | - /** |
|
92 | - * @var Registry $AssetsRegistry |
|
93 | - */ |
|
94 | - public $AssetsRegistry; |
|
95 | - |
|
96 | - /** |
|
97 | - * StdClass object for holding addons which have registered themselves to work with EE core |
|
98 | - * |
|
99 | - * @var EE_Addon[] $addons |
|
100 | - */ |
|
101 | - public $addons; |
|
102 | - |
|
103 | - /** |
|
104 | - * keys are 'short names' (eg Event), values are class names (eg 'EEM_Event') |
|
105 | - * |
|
106 | - * @var EEM_Base[] $models |
|
107 | - */ |
|
108 | - public $models = array(); |
|
109 | - |
|
110 | - /** |
|
111 | - * @var EED_Module[] $modules |
|
112 | - */ |
|
113 | - public $modules; |
|
114 | - |
|
115 | - /** |
|
116 | - * @var EES_Shortcode[] $shortcodes |
|
117 | - */ |
|
118 | - public $shortcodes; |
|
119 | - |
|
120 | - /** |
|
121 | - * @var WP_Widget[] $widgets |
|
122 | - */ |
|
123 | - public $widgets; |
|
124 | - |
|
125 | - /** |
|
126 | - * this is an array of all implemented model names (i.e. not the parent abstract models, or models |
|
127 | - * which don't actually fetch items from the DB in the normal way (ie, are not children of EEM_Base)). |
|
128 | - * Keys are model "short names" (eg "Event") as used in model relations, and values are |
|
129 | - * classnames (eg "EEM_Event") |
|
130 | - * |
|
131 | - * @var array $non_abstract_db_models |
|
132 | - */ |
|
133 | - public $non_abstract_db_models = array(); |
|
134 | - |
|
135 | - |
|
136 | - /** |
|
137 | - * internationalization for JS strings |
|
138 | - * usage: EE_Registry::i18n_js_strings['string_key'] = esc_html__( 'string to translate.', 'event_espresso' ); |
|
139 | - * in js file: var translatedString = eei18n.string_key; |
|
140 | - * |
|
141 | - * @var array $i18n_js_strings |
|
142 | - */ |
|
143 | - public static $i18n_js_strings = array(); |
|
144 | - |
|
145 | - |
|
146 | - /** |
|
147 | - * $main_file - path to espresso.php |
|
148 | - * |
|
149 | - * @var array $main_file |
|
150 | - */ |
|
151 | - public $main_file; |
|
152 | - |
|
153 | - /** |
|
154 | - * array of ReflectionClass objects where the key is the class name |
|
155 | - * |
|
156 | - * @var ReflectionClass[] $_reflectors |
|
157 | - */ |
|
158 | - public $_reflectors; |
|
159 | - |
|
160 | - /** |
|
161 | - * boolean flag to indicate whether or not to load/save dependencies from/to the cache |
|
162 | - * |
|
163 | - * @var boolean $_cache_on |
|
164 | - */ |
|
165 | - protected $_cache_on = true; |
|
166 | - |
|
167 | - |
|
168 | - |
|
169 | - /** |
|
170 | - * @singleton method used to instantiate class object |
|
171 | - * @param EE_Dependency_Map $dependency_map |
|
172 | - * @return EE_Registry instance |
|
173 | - * @throws InvalidArgumentException |
|
174 | - * @throws InvalidInterfaceException |
|
175 | - * @throws InvalidDataTypeException |
|
176 | - */ |
|
177 | - public static function instance(EE_Dependency_Map $dependency_map = null) |
|
178 | - { |
|
179 | - // check if class object is instantiated |
|
180 | - if (! self::$_instance instanceof EE_Registry) { |
|
181 | - self::$_instance = new self($dependency_map); |
|
182 | - } |
|
183 | - return self::$_instance; |
|
184 | - } |
|
185 | - |
|
186 | - |
|
187 | - |
|
188 | - /** |
|
189 | - * protected constructor to prevent direct creation |
|
190 | - * |
|
191 | - * @Constructor |
|
192 | - * @param EE_Dependency_Map $dependency_map |
|
193 | - * @throws InvalidDataTypeException |
|
194 | - * @throws InvalidInterfaceException |
|
195 | - * @throws InvalidArgumentException |
|
196 | - */ |
|
197 | - protected function __construct(EE_Dependency_Map $dependency_map) |
|
198 | - { |
|
199 | - $this->_dependency_map = $dependency_map; |
|
200 | - // $registry_container = new RegistryContainer(); |
|
201 | - $this->LIB = new RegistryContainer(); |
|
202 | - $this->addons = new RegistryContainer(); |
|
203 | - $this->modules = new RegistryContainer(); |
|
204 | - $this->shortcodes = new RegistryContainer(); |
|
205 | - $this->widgets = new RegistryContainer(); |
|
206 | - add_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading', array($this, 'initialize')); |
|
207 | - } |
|
208 | - |
|
209 | - |
|
210 | - |
|
211 | - /** |
|
212 | - * initialize |
|
213 | - * |
|
214 | - * @throws EE_Error |
|
215 | - * @throws ReflectionException |
|
216 | - */ |
|
217 | - public function initialize() |
|
218 | - { |
|
219 | - $this->_class_abbreviations = apply_filters( |
|
220 | - 'FHEE__EE_Registry____construct___class_abbreviations', |
|
221 | - array( |
|
222 | - 'EE_Config' => 'CFG', |
|
223 | - 'EE_Session' => 'SSN', |
|
224 | - 'EE_Capabilities' => 'CAP', |
|
225 | - 'EE_Cart' => 'CART', |
|
226 | - 'EE_Network_Config' => 'NET_CFG', |
|
227 | - 'EE_Request_Handler' => 'REQ', |
|
228 | - 'EE_Message_Resource_Manager' => 'MRM', |
|
229 | - 'EventEspresso\core\services\commands\CommandBus' => 'BUS', |
|
230 | - 'EventEspresso\core\services\assets\Registry' => 'AssetsRegistry', |
|
231 | - ) |
|
232 | - ); |
|
233 | - $this->load_core('Base', array(), true); |
|
234 | - // add our request and response objects to the cache |
|
235 | - $request_loader = $this->_dependency_map->class_loader('EE_Request'); |
|
236 | - $this->_set_cached_class( |
|
237 | - $request_loader(), |
|
238 | - 'EE_Request' |
|
239 | - ); |
|
240 | - $response_loader = $this->_dependency_map->class_loader('EE_Response'); |
|
241 | - $this->_set_cached_class( |
|
242 | - $response_loader(), |
|
243 | - 'EE_Response' |
|
244 | - ); |
|
245 | - add_action('AHEE__EE_System__set_hooks_for_core', array($this, 'init')); |
|
246 | - } |
|
247 | - |
|
248 | - |
|
249 | - |
|
250 | - /** |
|
251 | - * @return void |
|
252 | - */ |
|
253 | - public function init() |
|
254 | - { |
|
255 | - // Get current page protocol |
|
256 | - $protocol = isset($_SERVER['HTTPS']) ? 'https://' : 'http://'; |
|
257 | - // Output admin-ajax.php URL with same protocol as current page |
|
258 | - self::$i18n_js_strings['ajax_url'] = admin_url('admin-ajax.php', $protocol); |
|
259 | - self::$i18n_js_strings['wp_debug'] = defined('WP_DEBUG') ? WP_DEBUG : false; |
|
260 | - } |
|
261 | - |
|
262 | - |
|
263 | - |
|
264 | - /** |
|
265 | - * localize_i18n_js_strings |
|
266 | - * |
|
267 | - * @return string |
|
268 | - */ |
|
269 | - public static function localize_i18n_js_strings() |
|
270 | - { |
|
271 | - $i18n_js_strings = (array)self::$i18n_js_strings; |
|
272 | - foreach ($i18n_js_strings as $key => $value) { |
|
273 | - if (is_scalar($value)) { |
|
274 | - $i18n_js_strings[$key] = html_entity_decode((string)$value, ENT_QUOTES, 'UTF-8'); |
|
275 | - } |
|
276 | - } |
|
277 | - return '/* <![CDATA[ */ var eei18n = ' . wp_json_encode($i18n_js_strings) . '; /* ]]> */'; |
|
278 | - } |
|
279 | - |
|
280 | - |
|
281 | - |
|
282 | - /** |
|
283 | - * @param mixed string | EED_Module $module |
|
284 | - * @throws EE_Error |
|
285 | - * @throws ReflectionException |
|
286 | - */ |
|
287 | - public function add_module($module) |
|
288 | - { |
|
289 | - if ($module instanceof EED_Module) { |
|
290 | - $module_class = get_class($module); |
|
291 | - $this->modules->{$module_class} = $module; |
|
292 | - } else { |
|
293 | - if ( ! class_exists('EE_Module_Request_Router', false)) { |
|
294 | - $this->load_core('Module_Request_Router'); |
|
295 | - } |
|
296 | - EE_Module_Request_Router::module_factory($module); |
|
297 | - } |
|
298 | - } |
|
299 | - |
|
300 | - |
|
301 | - |
|
302 | - /** |
|
303 | - * @param string $module_name |
|
304 | - * @return mixed EED_Module | NULL |
|
305 | - */ |
|
306 | - public function get_module($module_name = '') |
|
307 | - { |
|
308 | - return isset($this->modules->{$module_name}) |
|
309 | - ? $this->modules->{$module_name} |
|
310 | - : null; |
|
311 | - } |
|
312 | - |
|
313 | - |
|
314 | - |
|
315 | - /** |
|
316 | - * loads core classes - must be singletons |
|
317 | - * |
|
318 | - * @param string $class_name - simple class name ie: session |
|
319 | - * @param mixed $arguments |
|
320 | - * @param bool $load_only |
|
321 | - * @return mixed |
|
322 | - * @throws EE_Error |
|
323 | - * @throws ReflectionException |
|
324 | - */ |
|
325 | - public function load_core($class_name, $arguments = array(), $load_only = false) |
|
326 | - { |
|
327 | - $core_paths = apply_filters( |
|
328 | - 'FHEE__EE_Registry__load_core__core_paths', |
|
329 | - array( |
|
330 | - EE_CORE, |
|
331 | - EE_ADMIN, |
|
332 | - EE_CPTS, |
|
333 | - EE_CORE . 'data_migration_scripts' . DS, |
|
334 | - EE_CORE . 'capabilities' . DS, |
|
335 | - EE_CORE . 'request_stack' . DS, |
|
336 | - EE_CORE . 'middleware' . DS, |
|
337 | - ) |
|
338 | - ); |
|
339 | - // retrieve instantiated class |
|
340 | - return $this->_load( |
|
341 | - $core_paths, |
|
342 | - 'EE_', |
|
343 | - $class_name, |
|
344 | - 'core', |
|
345 | - $arguments, |
|
346 | - false, |
|
347 | - true, |
|
348 | - $load_only |
|
349 | - ); |
|
350 | - } |
|
351 | - |
|
352 | - |
|
353 | - |
|
354 | - /** |
|
355 | - * loads service classes |
|
356 | - * |
|
357 | - * @param string $class_name - simple class name ie: session |
|
358 | - * @param mixed $arguments |
|
359 | - * @param bool $load_only |
|
360 | - * @return mixed |
|
361 | - * @throws EE_Error |
|
362 | - * @throws ReflectionException |
|
363 | - */ |
|
364 | - public function load_service($class_name, $arguments = array(), $load_only = false) |
|
365 | - { |
|
366 | - $service_paths = apply_filters( |
|
367 | - 'FHEE__EE_Registry__load_service__service_paths', |
|
368 | - array( |
|
369 | - EE_CORE . 'services' . DS, |
|
370 | - ) |
|
371 | - ); |
|
372 | - // retrieve instantiated class |
|
373 | - return $this->_load( |
|
374 | - $service_paths, |
|
375 | - 'EE_', |
|
376 | - $class_name, |
|
377 | - 'class', |
|
378 | - $arguments, |
|
379 | - false, |
|
380 | - true, |
|
381 | - $load_only |
|
382 | - ); |
|
383 | - } |
|
384 | - |
|
385 | - |
|
386 | - |
|
387 | - /** |
|
388 | - * loads data_migration_scripts |
|
389 | - * |
|
390 | - * @param string $class_name - class name for the DMS ie: EE_DMS_Core_4_2_0 |
|
391 | - * @param mixed $arguments |
|
392 | - * @return EE_Data_Migration_Script_Base|mixed |
|
393 | - * @throws EE_Error |
|
394 | - * @throws ReflectionException |
|
395 | - */ |
|
396 | - public function load_dms($class_name, $arguments = array()) |
|
397 | - { |
|
398 | - // retrieve instantiated class |
|
399 | - return $this->_load( |
|
400 | - EE_Data_Migration_Manager::instance()->get_data_migration_script_folders(), |
|
401 | - 'EE_DMS_', |
|
402 | - $class_name, |
|
403 | - 'dms', |
|
404 | - $arguments, |
|
405 | - false, |
|
406 | - false |
|
407 | - ); |
|
408 | - } |
|
409 | - |
|
410 | - |
|
411 | - |
|
412 | - /** |
|
413 | - * loads object creating classes - must be singletons |
|
414 | - * |
|
415 | - * @param string $class_name - simple class name ie: attendee |
|
416 | - * @param mixed $arguments - an array of arguments to pass to the class |
|
417 | - * @param bool $from_db - some classes are instantiated from the db and thus call a different method to |
|
418 | - * instantiate |
|
419 | - * @param bool $cache if you don't want the class to be stored in the internal cache (non-persistent) then |
|
420 | - * set this to FALSE (ie. when instantiating model objects from client in a loop) |
|
421 | - * @param bool $load_only whether or not to just load the file and NOT instantiate, or load AND instantiate |
|
422 | - * (default) |
|
423 | - * @return EE_Base_Class | bool |
|
424 | - * @throws EE_Error |
|
425 | - * @throws ReflectionException |
|
426 | - */ |
|
427 | - public function load_class($class_name, $arguments = array(), $from_db = false, $cache = true, $load_only = false) |
|
428 | - { |
|
429 | - $paths = apply_filters( |
|
430 | - 'FHEE__EE_Registry__load_class__paths', array( |
|
431 | - EE_CORE, |
|
432 | - EE_CLASSES, |
|
433 | - EE_BUSINESS, |
|
434 | - ) |
|
435 | - ); |
|
436 | - // retrieve instantiated class |
|
437 | - return $this->_load( |
|
438 | - $paths, |
|
439 | - 'EE_', |
|
440 | - $class_name, |
|
441 | - 'class', |
|
442 | - $arguments, |
|
443 | - $from_db, |
|
444 | - $cache, |
|
445 | - $load_only |
|
446 | - ); |
|
447 | - } |
|
448 | - |
|
449 | - |
|
450 | - |
|
451 | - /** |
|
452 | - * loads helper classes - must be singletons |
|
453 | - * |
|
454 | - * @param string $class_name - simple class name ie: price |
|
455 | - * @param mixed $arguments |
|
456 | - * @param bool $load_only |
|
457 | - * @return EEH_Base | bool |
|
458 | - * @throws EE_Error |
|
459 | - * @throws ReflectionException |
|
460 | - */ |
|
461 | - public function load_helper($class_name, $arguments = array(), $load_only = true) |
|
462 | - { |
|
463 | - // todo: add doing_it_wrong() in a few versions after all addons have had calls to this method removed |
|
464 | - $helper_paths = apply_filters('FHEE__EE_Registry__load_helper__helper_paths', array(EE_HELPERS)); |
|
465 | - // retrieve instantiated class |
|
466 | - return $this->_load( |
|
467 | - $helper_paths, |
|
468 | - 'EEH_', |
|
469 | - $class_name, |
|
470 | - 'helper', |
|
471 | - $arguments, |
|
472 | - false, |
|
473 | - true, |
|
474 | - $load_only |
|
475 | - ); |
|
476 | - } |
|
477 | - |
|
478 | - |
|
479 | - |
|
480 | - /** |
|
481 | - * loads core classes - must be singletons |
|
482 | - * |
|
483 | - * @param string $class_name - simple class name ie: session |
|
484 | - * @param mixed $arguments |
|
485 | - * @param bool $load_only |
|
486 | - * @param bool $cache whether to cache the object or not. |
|
487 | - * @return mixed |
|
488 | - * @throws EE_Error |
|
489 | - * @throws ReflectionException |
|
490 | - */ |
|
491 | - public function load_lib($class_name, $arguments = array(), $load_only = false, $cache = true) |
|
492 | - { |
|
493 | - $paths = array( |
|
494 | - EE_LIBRARIES, |
|
495 | - EE_LIBRARIES . 'messages' . DS, |
|
496 | - EE_LIBRARIES . 'shortcodes' . DS, |
|
497 | - EE_LIBRARIES . 'qtips' . DS, |
|
498 | - EE_LIBRARIES . 'payment_methods' . DS, |
|
499 | - ); |
|
500 | - // retrieve instantiated class |
|
501 | - return $this->_load( |
|
502 | - $paths, |
|
503 | - 'EE_', |
|
504 | - $class_name, |
|
505 | - 'lib', |
|
506 | - $arguments, |
|
507 | - false, |
|
508 | - $cache, |
|
509 | - $load_only |
|
510 | - ); |
|
511 | - } |
|
512 | - |
|
513 | - |
|
514 | - |
|
515 | - /** |
|
516 | - * loads model classes - must be singletons |
|
517 | - * |
|
518 | - * @param string $class_name - simple class name ie: price |
|
519 | - * @param mixed $arguments |
|
520 | - * @param bool $load_only |
|
521 | - * @return EEM_Base | bool |
|
522 | - * @throws EE_Error |
|
523 | - * @throws ReflectionException |
|
524 | - */ |
|
525 | - public function load_model($class_name, $arguments = array(), $load_only = false) |
|
526 | - { |
|
527 | - $paths = apply_filters( |
|
528 | - 'FHEE__EE_Registry__load_model__paths', array( |
|
529 | - EE_MODELS, |
|
530 | - EE_CORE, |
|
531 | - ) |
|
532 | - ); |
|
533 | - // retrieve instantiated class |
|
534 | - return $this->_load( |
|
535 | - $paths, |
|
536 | - 'EEM_', |
|
537 | - $class_name, |
|
538 | - 'model', |
|
539 | - $arguments, |
|
540 | - false, |
|
541 | - true, |
|
542 | - $load_only |
|
543 | - ); |
|
544 | - } |
|
545 | - |
|
546 | - |
|
547 | - |
|
548 | - /** |
|
549 | - * loads model classes - must be singletons |
|
550 | - * |
|
551 | - * @param string $class_name - simple class name ie: price |
|
552 | - * @param mixed $arguments |
|
553 | - * @param bool $load_only |
|
554 | - * @return mixed | bool |
|
555 | - * @throws EE_Error |
|
556 | - * @throws ReflectionException |
|
557 | - */ |
|
558 | - public function load_model_class($class_name, $arguments = array(), $load_only = true) |
|
559 | - { |
|
560 | - $paths = array( |
|
561 | - EE_MODELS . 'fields' . DS, |
|
562 | - EE_MODELS . 'helpers' . DS, |
|
563 | - EE_MODELS . 'relations' . DS, |
|
564 | - EE_MODELS . 'strategies' . DS, |
|
565 | - ); |
|
566 | - // retrieve instantiated class |
|
567 | - return $this->_load( |
|
568 | - $paths, |
|
569 | - 'EE_', |
|
570 | - $class_name, |
|
571 | - '', |
|
572 | - $arguments, |
|
573 | - false, |
|
574 | - true, |
|
575 | - $load_only |
|
576 | - ); |
|
577 | - } |
|
578 | - |
|
579 | - |
|
580 | - |
|
581 | - /** |
|
582 | - * Determines if $model_name is the name of an actual EE model. |
|
583 | - * |
|
584 | - * @param string $model_name like Event, Attendee, Question_Group_Question, etc. |
|
585 | - * @return boolean |
|
586 | - */ |
|
587 | - public function is_model_name($model_name) |
|
588 | - { |
|
589 | - return isset($this->models[$model_name]); |
|
590 | - } |
|
591 | - |
|
592 | - |
|
593 | - |
|
594 | - /** |
|
595 | - * generic class loader |
|
596 | - * |
|
597 | - * @param string $path_to_file - directory path to file location, not including filename |
|
598 | - * @param string $file_name - file name ie: my_file.php, including extension |
|
599 | - * @param string $type - file type - core? class? helper? model? |
|
600 | - * @param mixed $arguments |
|
601 | - * @param bool $load_only |
|
602 | - * @return mixed |
|
603 | - * @throws EE_Error |
|
604 | - * @throws ReflectionException |
|
605 | - */ |
|
606 | - public function load_file($path_to_file, $file_name, $type = '', $arguments = array(), $load_only = true) |
|
607 | - { |
|
608 | - // retrieve instantiated class |
|
609 | - return $this->_load( |
|
610 | - $path_to_file, |
|
611 | - '', |
|
612 | - $file_name, |
|
613 | - $type, |
|
614 | - $arguments, |
|
615 | - false, |
|
616 | - true, |
|
617 | - $load_only |
|
618 | - ); |
|
619 | - } |
|
620 | - |
|
621 | - |
|
622 | - |
|
623 | - /** |
|
624 | - * @param string $path_to_file - directory path to file location, not including filename |
|
625 | - * @param string $class_name - full class name ie: My_Class |
|
626 | - * @param string $type - file type - core? class? helper? model? |
|
627 | - * @param mixed $arguments |
|
628 | - * @param bool $load_only |
|
629 | - * @return bool|EE_Addon|object |
|
630 | - * @throws EE_Error |
|
631 | - * @throws ReflectionException |
|
632 | - */ |
|
633 | - public function load_addon($path_to_file, $class_name, $type = 'class', $arguments = array(), $load_only = false) |
|
634 | - { |
|
635 | - // retrieve instantiated class |
|
636 | - return $this->_load( |
|
637 | - $path_to_file, |
|
638 | - 'addon', |
|
639 | - $class_name, |
|
640 | - $type, |
|
641 | - $arguments, |
|
642 | - false, |
|
643 | - true, |
|
644 | - $load_only |
|
645 | - ); |
|
646 | - } |
|
647 | - |
|
648 | - |
|
649 | - |
|
650 | - /** |
|
651 | - * instantiates, caches, and automatically resolves dependencies |
|
652 | - * for classes that use a Fully Qualified Class Name. |
|
653 | - * if the class is not capable of being loaded using PSR-4 autoloading, |
|
654 | - * then you need to use one of the existing load_*() methods |
|
655 | - * which can resolve the classname and filepath from the passed arguments |
|
656 | - * |
|
657 | - * @param bool|string $class_name Fully Qualified Class Name |
|
658 | - * @param array $arguments an argument, or array of arguments to pass to the class upon instantiation |
|
659 | - * @param bool $cache whether to cache the instantiated object for reuse |
|
660 | - * @param bool $from_db some classes are instantiated from the db |
|
661 | - * and thus call a different method to instantiate |
|
662 | - * @param bool $load_only if true, will only load the file, but will NOT instantiate an object |
|
663 | - * @param bool|string $addon if true, will cache the object in the EE_Registry->$addons array |
|
664 | - * @return bool|null|mixed null = failure to load or instantiate class object. |
|
665 | - * object = class loaded and instantiated successfully. |
|
666 | - * bool = fail or success when $load_only is true |
|
667 | - * @throws EE_Error |
|
668 | - * @throws ReflectionException |
|
669 | - */ |
|
670 | - public function create( |
|
671 | - $class_name = false, |
|
672 | - $arguments = array(), |
|
673 | - $cache = false, |
|
674 | - $from_db = false, |
|
675 | - $load_only = false, |
|
676 | - $addon = false |
|
677 | - ) { |
|
678 | - $class_name = ltrim($class_name, '\\'); |
|
679 | - $class_name = $this->_dependency_map->get_alias($class_name); |
|
680 | - $class_exists = $this->loadOrVerifyClassExists($class_name, $arguments); |
|
681 | - // if a non-FQCN was passed, then verifyClassExists() might return an object |
|
682 | - // or it could return null if the class just could not be found anywhere |
|
683 | - if ($class_exists instanceof $class_name || $class_exists === null){ |
|
684 | - // either way, return the results |
|
685 | - return $class_exists; |
|
686 | - } |
|
687 | - $class_name = $class_exists; |
|
688 | - // if we're only loading the class and it already exists, then let's just return true immediately |
|
689 | - if ($load_only) { |
|
690 | - return true; |
|
691 | - } |
|
692 | - $addon = $addon |
|
693 | - ? 'addon' |
|
694 | - : ''; |
|
695 | - // $this->_cache_on is toggled during the recursive loading that can occur with dependency injection |
|
696 | - // $cache is controlled by individual calls to separate Registry loader methods like load_class() |
|
697 | - // $load_only is also controlled by individual calls to separate Registry loader methods like load_file() |
|
698 | - if ($this->_cache_on && $cache && ! $load_only) { |
|
699 | - // return object if it's already cached |
|
700 | - $cached_class = $this->_get_cached_class($class_name, $addon); |
|
701 | - if ($cached_class !== null) { |
|
702 | - return $cached_class; |
|
703 | - } |
|
704 | - } |
|
705 | - // obtain the loader method from the dependency map |
|
706 | - $loader = $this->_dependency_map->class_loader($class_name); |
|
707 | - // instantiate the requested object |
|
708 | - if ($loader instanceof Closure) { |
|
709 | - $class_obj = $loader($arguments); |
|
710 | - } else if ($loader && method_exists($this, $loader)) { |
|
711 | - $class_obj = $this->{$loader}($class_name, $arguments); |
|
712 | - } else { |
|
713 | - $class_obj = $this->_create_object($class_name, $arguments, $addon, $from_db); |
|
714 | - } |
|
715 | - if (($this->_cache_on && $cache) || $this->get_class_abbreviation($class_name, '')) { |
|
716 | - // save it for later... kinda like gum { : $ |
|
717 | - $this->_set_cached_class($class_obj, $class_name, $addon, $from_db); |
|
718 | - } |
|
719 | - $this->_cache_on = true; |
|
720 | - return $class_obj; |
|
721 | - } |
|
722 | - |
|
723 | - |
|
724 | - |
|
725 | - /** |
|
726 | - * Recursively checks that a class exists and potentially attempts to load classes with non-FQCNs |
|
727 | - * |
|
728 | - * @param string $class_name |
|
729 | - * @param array $arguments |
|
730 | - * @param int $attempt |
|
731 | - * @return mixed |
|
732 | - */ |
|
733 | - private function loadOrVerifyClassExists($class_name, array $arguments, $attempt = 1) { |
|
734 | - if (is_object($class_name) || class_exists($class_name)) { |
|
735 | - return $class_name; |
|
736 | - } |
|
737 | - switch ($attempt) { |
|
738 | - case 1: |
|
739 | - // if it's a FQCN then maybe the class is registered with a preceding \ |
|
740 | - $class_name = strpos($class_name, '\\') !== false |
|
741 | - ? '\\' . ltrim($class_name, '\\') |
|
742 | - : $class_name; |
|
743 | - break; |
|
744 | - case 2: |
|
745 | - // |
|
746 | - $loader = $this->_dependency_map->class_loader($class_name); |
|
747 | - if ($loader && method_exists($this, $loader)) { |
|
748 | - return $this->{$loader}($class_name, $arguments); |
|
749 | - } |
|
750 | - break; |
|
751 | - case 3: |
|
752 | - default; |
|
753 | - return null; |
|
754 | - } |
|
755 | - $attempt++; |
|
756 | - return $this->loadOrVerifyClassExists($class_name, $arguments, $attempt); |
|
757 | - } |
|
758 | - |
|
759 | - |
|
760 | - |
|
761 | - /** |
|
762 | - * instantiates, caches, and injects dependencies for classes |
|
763 | - * |
|
764 | - * @param array $file_paths an array of paths to folders to look in |
|
765 | - * @param string $class_prefix EE or EEM or... ??? |
|
766 | - * @param bool|string $class_name $class name |
|
767 | - * @param string $type file type - core? class? helper? model? |
|
768 | - * @param mixed $arguments an argument or array of arguments to pass to the class upon instantiation |
|
769 | - * @param bool $from_db some classes are instantiated from the db |
|
770 | - * and thus call a different method to instantiate |
|
771 | - * @param bool $cache whether to cache the instantiated object for reuse |
|
772 | - * @param bool $load_only if true, will only load the file, but will NOT instantiate an object |
|
773 | - * @return bool|null|object null = failure to load or instantiate class object. |
|
774 | - * object = class loaded and instantiated successfully. |
|
775 | - * bool = fail or success when $load_only is true |
|
776 | - * @throws EE_Error |
|
777 | - * @throws ReflectionException |
|
778 | - */ |
|
779 | - protected function _load( |
|
780 | - $file_paths = array(), |
|
781 | - $class_prefix = 'EE_', |
|
782 | - $class_name = false, |
|
783 | - $type = 'class', |
|
784 | - $arguments = array(), |
|
785 | - $from_db = false, |
|
786 | - $cache = true, |
|
787 | - $load_only = false |
|
788 | - ) { |
|
789 | - $class_name = ltrim($class_name, '\\'); |
|
790 | - // strip php file extension |
|
791 | - $class_name = str_replace('.php', '', trim($class_name)); |
|
792 | - // does the class have a prefix ? |
|
793 | - if (! empty($class_prefix) && $class_prefix !== 'addon') { |
|
794 | - // make sure $class_prefix is uppercase |
|
795 | - $class_prefix = strtoupper(trim($class_prefix)); |
|
796 | - // add class prefix ONCE!!! |
|
797 | - $class_name = $class_prefix . str_replace($class_prefix, '', $class_name); |
|
798 | - } |
|
799 | - $class_name = $this->_dependency_map->get_alias($class_name); |
|
800 | - $class_exists = class_exists($class_name, false); |
|
801 | - // if we're only loading the class and it already exists, then let's just return true immediately |
|
802 | - if ($load_only && $class_exists) { |
|
803 | - return true; |
|
804 | - } |
|
805 | - // $this->_cache_on is toggled during the recursive loading that can occur with dependency injection |
|
806 | - // $cache is controlled by individual calls to separate Registry loader methods like load_class() |
|
807 | - // $load_only is also controlled by individual calls to separate Registry loader methods like load_file() |
|
808 | - if ($this->_cache_on && $cache && ! $load_only) { |
|
809 | - // return object if it's already cached |
|
810 | - $cached_class = $this->_get_cached_class($class_name, $class_prefix); |
|
811 | - if ($cached_class !== null) { |
|
812 | - return $cached_class; |
|
813 | - } |
|
814 | - } |
|
815 | - // if the class doesn't already exist.. then we need to try and find the file and load it |
|
816 | - if (! $class_exists) { |
|
817 | - // get full path to file |
|
818 | - $path = $this->_resolve_path($class_name, $type, $file_paths); |
|
819 | - // load the file |
|
820 | - $loaded = $this->_require_file($path, $class_name, $type, $file_paths); |
|
821 | - // if loading failed, or we are only loading a file but NOT instantiating an object |
|
822 | - if (! $loaded || $load_only) { |
|
823 | - // return boolean if only loading, or null if an object was expected |
|
824 | - return $load_only |
|
825 | - ? $loaded |
|
826 | - : null; |
|
827 | - } |
|
828 | - } |
|
829 | - // instantiate the requested object |
|
830 | - $class_obj = $this->_create_object($class_name, $arguments, $type, $from_db); |
|
831 | - if ($this->_cache_on && $cache) { |
|
832 | - // save it for later... kinda like gum { : $ |
|
833 | - $this->_set_cached_class($class_obj, $class_name, $class_prefix, $from_db); |
|
834 | - } |
|
835 | - $this->_cache_on = true; |
|
836 | - return $class_obj; |
|
837 | - } |
|
838 | - |
|
839 | - |
|
840 | - |
|
841 | - /** |
|
842 | - * @param string $class_name |
|
843 | - * @param string $default have to specify something, but not anything that will conflict |
|
844 | - * @return mixed|string |
|
845 | - */ |
|
846 | - protected function get_class_abbreviation($class_name, $default = 'FANCY_BATMAN_PANTS') |
|
847 | - { |
|
848 | - return isset($this->_class_abbreviations[$class_name]) |
|
849 | - ? $this->_class_abbreviations[$class_name] |
|
850 | - : $default; |
|
851 | - } |
|
852 | - |
|
853 | - /** |
|
854 | - * attempts to find a cached version of the requested class |
|
855 | - * by looking in the following places: |
|
856 | - * $this->{$class_abbreviation} ie: $this->CART |
|
857 | - * $this->{$class_name} ie: $this->Some_Class |
|
858 | - * $this->LIB->{$class_name} ie: $this->LIB->Some_Class |
|
859 | - * $this->addon->{$class_name} ie: $this->addon->Some_Addon_Class |
|
860 | - * |
|
861 | - * @param string $class_name |
|
862 | - * @param string $class_prefix |
|
863 | - * @return mixed |
|
864 | - */ |
|
865 | - protected function _get_cached_class($class_name, $class_prefix = '') |
|
866 | - { |
|
867 | - if ($class_name === 'EE_Registry') { |
|
868 | - return $this; |
|
869 | - } |
|
870 | - $class_abbreviation = $this->get_class_abbreviation($class_name); |
|
871 | - $class_name = str_replace('\\', '_', $class_name); |
|
872 | - // check if class has already been loaded, and return it if it has been |
|
873 | - if (isset($this->{$class_abbreviation})) { |
|
874 | - return $this->{$class_abbreviation}; |
|
875 | - } |
|
876 | - if (isset ($this->{$class_name})) { |
|
877 | - return $this->{$class_name}; |
|
878 | - } |
|
879 | - if (isset ($this->LIB->{$class_name})) { |
|
880 | - return $this->LIB->{$class_name}; |
|
881 | - } |
|
882 | - if ($class_prefix === 'addon' && isset ($this->addons->{$class_name})) { |
|
883 | - return $this->addons->{$class_name}; |
|
884 | - } |
|
885 | - return null; |
|
886 | - } |
|
887 | - |
|
888 | - |
|
889 | - |
|
890 | - /** |
|
891 | - * removes a cached version of the requested class |
|
892 | - * |
|
893 | - * @param string $class_name |
|
894 | - * @param boolean $addon |
|
895 | - * @return boolean |
|
896 | - */ |
|
897 | - public function clear_cached_class($class_name, $addon = false) |
|
898 | - { |
|
899 | - $class_abbreviation = $this->get_class_abbreviation($class_name); |
|
900 | - $class_name = str_replace('\\', '_', $class_name); |
|
901 | - // check if class has already been loaded, and return it if it has been |
|
902 | - if (isset($this->{$class_abbreviation})) { |
|
903 | - $this->{$class_abbreviation} = null; |
|
904 | - return true; |
|
905 | - } |
|
906 | - if (isset($this->{$class_name})) { |
|
907 | - $this->{$class_name} = null; |
|
908 | - return true; |
|
909 | - } |
|
910 | - if (isset($this->LIB->{$class_name})) { |
|
911 | - unset($this->LIB->{$class_name}); |
|
912 | - return true; |
|
913 | - } |
|
914 | - if ($addon && isset($this->addons->{$class_name})) { |
|
915 | - unset($this->addons->{$class_name}); |
|
916 | - return true; |
|
917 | - } |
|
918 | - return false; |
|
919 | - } |
|
920 | - |
|
921 | - |
|
922 | - |
|
923 | - /** |
|
924 | - * attempts to find a full valid filepath for the requested class. |
|
925 | - * loops thru each of the base paths in the $file_paths array and appends : "{classname} . {file type} . php" |
|
926 | - * then returns that path if the target file has been found and is readable |
|
927 | - * |
|
928 | - * @param string $class_name |
|
929 | - * @param string $type |
|
930 | - * @param array $file_paths |
|
931 | - * @return string | bool |
|
932 | - */ |
|
933 | - protected function _resolve_path($class_name, $type = '', $file_paths = array()) |
|
934 | - { |
|
935 | - // make sure $file_paths is an array |
|
936 | - $file_paths = is_array($file_paths) |
|
937 | - ? $file_paths |
|
938 | - : array($file_paths); |
|
939 | - // cycle thru paths |
|
940 | - foreach ($file_paths as $key => $file_path) { |
|
941 | - // convert all separators to proper DS, if no filepath, then use EE_CLASSES |
|
942 | - $file_path = $file_path |
|
943 | - ? str_replace(array('/', '\\'), DS, $file_path) |
|
944 | - : EE_CLASSES; |
|
945 | - // prep file type |
|
946 | - $type = ! empty($type) |
|
947 | - ? trim($type, '.') . '.' |
|
948 | - : ''; |
|
949 | - // build full file path |
|
950 | - $file_paths[$key] = rtrim($file_path, DS) . DS . $class_name . '.' . $type . 'php'; |
|
951 | - //does the file exist and can be read ? |
|
952 | - if (is_readable($file_paths[$key])) { |
|
953 | - return $file_paths[$key]; |
|
954 | - } |
|
955 | - } |
|
956 | - return false; |
|
957 | - } |
|
958 | - |
|
959 | - |
|
960 | - |
|
961 | - /** |
|
962 | - * basically just performs a require_once() |
|
963 | - * but with some error handling |
|
964 | - * |
|
965 | - * @param string $path |
|
966 | - * @param string $class_name |
|
967 | - * @param string $type |
|
968 | - * @param array $file_paths |
|
969 | - * @return bool |
|
970 | - * @throws EE_Error |
|
971 | - * @throws ReflectionException |
|
972 | - */ |
|
973 | - protected function _require_file($path, $class_name, $type = '', $file_paths = array()) |
|
974 | - { |
|
975 | - $this->resolve_legacy_class_parent($class_name); |
|
976 | - // don't give up! you gotta... |
|
977 | - try { |
|
978 | - //does the file exist and can it be read ? |
|
979 | - if (! $path) { |
|
980 | - // just in case the file has already been autoloaded, |
|
981 | - // but discrepancies in the naming schema are preventing it from |
|
982 | - // being loaded via one of the EE_Registry::load_*() methods, |
|
983 | - // then let's try one last hail mary before throwing an exception |
|
984 | - // and call class_exists() again, but with autoloading turned ON |
|
985 | - if(class_exists($class_name)) { |
|
986 | - return true; |
|
987 | - } |
|
988 | - // so sorry, can't find the file |
|
989 | - throw new EE_Error ( |
|
990 | - sprintf( |
|
991 | - esc_html__( |
|
992 | - 'The %1$s file %2$s could not be located or is not readable due to file permissions. Please ensure that the following filepath(s) are correct: %3$s', |
|
993 | - 'event_espresso' |
|
994 | - ), |
|
995 | - trim($type, '.'), |
|
996 | - $class_name, |
|
997 | - '<br />' . implode(',<br />', $file_paths) |
|
998 | - ) |
|
999 | - ); |
|
1000 | - } |
|
1001 | - // get the file |
|
1002 | - require_once($path); |
|
1003 | - // if the class isn't already declared somewhere |
|
1004 | - if (class_exists($class_name, false) === false) { |
|
1005 | - // so sorry, not a class |
|
1006 | - throw new EE_Error( |
|
1007 | - sprintf( |
|
1008 | - esc_html__('The %s file %s does not appear to contain the %s Class.', 'event_espresso'), |
|
1009 | - $type, |
|
1010 | - $path, |
|
1011 | - $class_name |
|
1012 | - ) |
|
1013 | - ); |
|
1014 | - } |
|
1015 | - } catch (EE_Error $e) { |
|
1016 | - $e->get_error(); |
|
1017 | - return false; |
|
1018 | - } |
|
1019 | - return true; |
|
1020 | - } |
|
1021 | - |
|
1022 | - |
|
1023 | - |
|
1024 | - /** |
|
1025 | - * Some of our legacy classes that extended a parent class would simply use a require() statement |
|
1026 | - * before their class declaration in order to ensure that the parent class was loaded. |
|
1027 | - * This is not ideal, but it's nearly impossible to determine the parent class of a non-namespaced class, |
|
1028 | - * without triggering a fatal error because the parent class has yet to be loaded and therefore doesn't exist. |
|
1029 | - * |
|
1030 | - * @param string $class_name |
|
1031 | - */ |
|
1032 | - protected function resolve_legacy_class_parent($class_name = '') |
|
1033 | - { |
|
1034 | - try { |
|
1035 | - $legacy_parent_class_map = array( |
|
1036 | - 'EE_Payment_Processor' => 'core/business/EE_Processor_Base.class.php' |
|
1037 | - ); |
|
1038 | - if(isset($legacy_parent_class_map[$class_name])) { |
|
1039 | - require_once EE_PLUGIN_DIR_PATH . $legacy_parent_class_map[$class_name]; |
|
1040 | - } |
|
1041 | - } catch (Exception $exception) { |
|
1042 | - } |
|
1043 | - } |
|
1044 | - |
|
1045 | - |
|
1046 | - |
|
1047 | - /** |
|
1048 | - * _create_object |
|
1049 | - * Attempts to instantiate the requested class via any of the |
|
1050 | - * commonly used instantiation methods employed throughout EE. |
|
1051 | - * The priority for instantiation is as follows: |
|
1052 | - * - abstract classes or any class flagged as "load only" (no instantiation occurs) |
|
1053 | - * - model objects via their 'new_instance_from_db' method |
|
1054 | - * - model objects via their 'new_instance' method |
|
1055 | - * - "singleton" classes" via their 'instance' method |
|
1056 | - * - standard instantiable classes via their __constructor |
|
1057 | - * Prior to instantiation, if the classname exists in the dependency_map, |
|
1058 | - * then the constructor for the requested class will be examined to determine |
|
1059 | - * if any dependencies exist, and if they can be injected. |
|
1060 | - * If so, then those classes will be added to the array of arguments passed to the constructor |
|
1061 | - * |
|
1062 | - * @param string $class_name |
|
1063 | - * @param array $arguments |
|
1064 | - * @param string $type |
|
1065 | - * @param bool $from_db |
|
1066 | - * @return null|object |
|
1067 | - * @throws EE_Error |
|
1068 | - * @throws ReflectionException |
|
1069 | - */ |
|
1070 | - protected function _create_object($class_name, $arguments = array(), $type = '', $from_db = false) |
|
1071 | - { |
|
1072 | - // create reflection |
|
1073 | - $reflector = $this->get_ReflectionClass($class_name); |
|
1074 | - // make sure arguments are an array |
|
1075 | - $arguments = is_array($arguments) |
|
1076 | - ? $arguments |
|
1077 | - : array($arguments); |
|
1078 | - // and if arguments array is numerically and sequentially indexed, then we want it to remain as is, |
|
1079 | - // else wrap it in an additional array so that it doesn't get split into multiple parameters |
|
1080 | - $arguments = $this->_array_is_numerically_and_sequentially_indexed($arguments) |
|
1081 | - ? $arguments |
|
1082 | - : array($arguments); |
|
1083 | - // attempt to inject dependencies ? |
|
1084 | - if ($this->_dependency_map->has($class_name)) { |
|
1085 | - $arguments = $this->_resolve_dependencies($reflector, $class_name, $arguments); |
|
1086 | - } |
|
1087 | - // instantiate the class if possible |
|
1088 | - if ($reflector->isAbstract()) { |
|
1089 | - // nothing to instantiate, loading file was enough |
|
1090 | - // does not throw an exception so $instantiation_mode is unused |
|
1091 | - // $instantiation_mode = "1) no constructor abstract class"; |
|
1092 | - return true; |
|
1093 | - } |
|
1094 | - if (empty($arguments) && $reflector->getConstructor() === null && $reflector->isInstantiable()) { |
|
1095 | - // no constructor = static methods only... nothing to instantiate, loading file was enough |
|
1096 | - // $instantiation_mode = "2) no constructor but instantiable"; |
|
1097 | - return $reflector->newInstance(); |
|
1098 | - } |
|
1099 | - if ($from_db && method_exists($class_name, 'new_instance_from_db')) { |
|
1100 | - // $instantiation_mode = "3) new_instance_from_db()"; |
|
1101 | - return call_user_func_array(array($class_name, 'new_instance_from_db'), $arguments); |
|
1102 | - } |
|
1103 | - if (method_exists($class_name, 'new_instance')) { |
|
1104 | - // $instantiation_mode = "4) new_instance()"; |
|
1105 | - return call_user_func_array(array($class_name, 'new_instance'), $arguments); |
|
1106 | - } |
|
1107 | - if (method_exists($class_name, 'instance')) { |
|
1108 | - // $instantiation_mode = "5) instance()"; |
|
1109 | - return call_user_func_array(array($class_name, 'instance'), $arguments); |
|
1110 | - } |
|
1111 | - if ($reflector->isInstantiable()) { |
|
1112 | - // $instantiation_mode = "6) constructor"; |
|
1113 | - return $reflector->newInstanceArgs($arguments); |
|
1114 | - } |
|
1115 | - // heh ? something's not right ! |
|
1116 | - throw new EE_Error( |
|
1117 | - sprintf( |
|
1118 | - __('The %s file %s could not be instantiated.', 'event_espresso'), |
|
1119 | - $type, |
|
1120 | - $class_name |
|
1121 | - ) |
|
1122 | - ); |
|
1123 | - } |
|
1124 | - |
|
1125 | - |
|
1126 | - |
|
1127 | - /** |
|
1128 | - * @see http://stackoverflow.com/questions/173400/how-to-check-if-php-array-is-associative-or-sequential |
|
1129 | - * @param array $array |
|
1130 | - * @return bool |
|
1131 | - */ |
|
1132 | - protected function _array_is_numerically_and_sequentially_indexed(array $array) |
|
1133 | - { |
|
1134 | - return ! empty($array) |
|
1135 | - ? array_keys($array) === range(0, count($array) - 1) |
|
1136 | - : true; |
|
1137 | - } |
|
1138 | - |
|
1139 | - |
|
1140 | - |
|
1141 | - /** |
|
1142 | - * getReflectionClass |
|
1143 | - * checks if a ReflectionClass object has already been generated for a class |
|
1144 | - * and returns that instead of creating a new one |
|
1145 | - * |
|
1146 | - * @param string $class_name |
|
1147 | - * @return ReflectionClass |
|
1148 | - * @throws ReflectionException |
|
1149 | - */ |
|
1150 | - public function get_ReflectionClass($class_name) |
|
1151 | - { |
|
1152 | - if ( |
|
1153 | - ! isset($this->_reflectors[$class_name]) |
|
1154 | - || ! $this->_reflectors[$class_name] instanceof ReflectionClass |
|
1155 | - ) { |
|
1156 | - $this->_reflectors[$class_name] = new ReflectionClass($class_name); |
|
1157 | - } |
|
1158 | - return $this->_reflectors[$class_name]; |
|
1159 | - } |
|
1160 | - |
|
1161 | - |
|
1162 | - |
|
1163 | - /** |
|
1164 | - * _resolve_dependencies |
|
1165 | - * examines the constructor for the requested class to determine |
|
1166 | - * if any dependencies exist, and if they can be injected. |
|
1167 | - * If so, then those classes will be added to the array of arguments passed to the constructor |
|
1168 | - * PLZ NOTE: this is achieved by type hinting the constructor params |
|
1169 | - * For example: |
|
1170 | - * if attempting to load a class "Foo" with the following constructor: |
|
1171 | - * __construct( Bar $bar_class, Fighter $grohl_class ) |
|
1172 | - * then $bar_class and $grohl_class will be added to the $arguments array, |
|
1173 | - * but only IF they are NOT already present in the incoming arguments array, |
|
1174 | - * and the correct classes can be loaded |
|
1175 | - * |
|
1176 | - * @param ReflectionClass $reflector |
|
1177 | - * @param string $class_name |
|
1178 | - * @param array $arguments |
|
1179 | - * @return array |
|
1180 | - * @throws EE_Error |
|
1181 | - * @throws ReflectionException |
|
1182 | - */ |
|
1183 | - protected function _resolve_dependencies(ReflectionClass $reflector, $class_name, $arguments = array()) |
|
1184 | - { |
|
1185 | - // let's examine the constructor |
|
1186 | - $constructor = $reflector->getConstructor(); |
|
1187 | - // whu? huh? nothing? |
|
1188 | - if (! $constructor) { |
|
1189 | - return $arguments; |
|
1190 | - } |
|
1191 | - // get constructor parameters |
|
1192 | - $params = $constructor->getParameters(); |
|
1193 | - // and the keys for the incoming arguments array so that we can compare existing arguments with what is expected |
|
1194 | - $argument_keys = array_keys($arguments); |
|
1195 | - // now loop thru all of the constructors expected parameters |
|
1196 | - foreach ($params as $index => $param) { |
|
1197 | - // is this a dependency for a specific class ? |
|
1198 | - $param_class = $param->getClass() |
|
1199 | - ? $param->getClass()->name |
|
1200 | - : null; |
|
1201 | - // BUT WAIT !!! This class may be an alias for something else (or getting replaced at runtime) |
|
1202 | - $param_class = $this->_dependency_map->has_alias($param_class, $class_name) |
|
1203 | - ? $this->_dependency_map->get_alias($param_class, $class_name) |
|
1204 | - : $param_class; |
|
1205 | - if ( |
|
1206 | - // param is not even a class |
|
1207 | - $param_class === null |
|
1208 | - // and something already exists in the incoming arguments for this param |
|
1209 | - && array_key_exists($index, $argument_keys) |
|
1210 | - && array_key_exists($argument_keys[$index], $arguments) |
|
1211 | - ) { |
|
1212 | - // so let's skip this argument and move on to the next |
|
1213 | - continue; |
|
1214 | - } |
|
1215 | - if ( |
|
1216 | - // parameter is type hinted as a class, exists as an incoming argument, AND it's the correct class |
|
1217 | - $param_class !== null |
|
1218 | - && isset($argument_keys[$index], $arguments[$argument_keys[$index]]) |
|
1219 | - && $arguments[$argument_keys[$index]] instanceof $param_class |
|
1220 | - ) { |
|
1221 | - // skip this argument and move on to the next |
|
1222 | - continue; |
|
1223 | - } |
|
1224 | - if ( |
|
1225 | - // parameter is type hinted as a class, and should be injected |
|
1226 | - $param_class !== null |
|
1227 | - && $this->_dependency_map->has_dependency_for_class($class_name, $param_class) |
|
1228 | - ) { |
|
1229 | - $arguments = $this->_resolve_dependency( |
|
1230 | - $class_name, |
|
1231 | - $param_class, |
|
1232 | - $arguments, |
|
1233 | - $index, |
|
1234 | - $argument_keys |
|
1235 | - ); |
|
1236 | - } else { |
|
1237 | - try { |
|
1238 | - $arguments[$index] = $param->isDefaultValueAvailable() |
|
1239 | - ? $param->getDefaultValue() |
|
1240 | - : null; |
|
1241 | - } catch (ReflectionException $e) { |
|
1242 | - throw new ReflectionException( |
|
1243 | - sprintf( |
|
1244 | - esc_html__('%1$s for parameter "$%2$s on classname "%3$s"', 'event_espresso'), |
|
1245 | - $e->getMessage(), |
|
1246 | - $param->getName(), |
|
1247 | - $class_name |
|
1248 | - ) |
|
1249 | - ); |
|
1250 | - } |
|
1251 | - } |
|
1252 | - } |
|
1253 | - return $arguments; |
|
1254 | - } |
|
1255 | - |
|
1256 | - |
|
1257 | - |
|
1258 | - /** |
|
1259 | - * @param string $class_name |
|
1260 | - * @param string $param_class |
|
1261 | - * @param array $arguments |
|
1262 | - * @param mixed $index |
|
1263 | - * @param array $argument_keys |
|
1264 | - * @return array |
|
1265 | - * @throws EE_Error |
|
1266 | - * @throws ReflectionException |
|
1267 | - * @throws InvalidArgumentException |
|
1268 | - * @throws InvalidInterfaceException |
|
1269 | - * @throws InvalidDataTypeException |
|
1270 | - */ |
|
1271 | - protected function _resolve_dependency($class_name, $param_class, $arguments, $index, array $argument_keys) |
|
1272 | - { |
|
1273 | - $dependency = null; |
|
1274 | - // should dependency be loaded from cache ? |
|
1275 | - $cache_on = $this->_dependency_map->loading_strategy_for_class_dependency( |
|
1276 | - $class_name, |
|
1277 | - $param_class |
|
1278 | - ); |
|
1279 | - $cache_on = $cache_on !== EE_Dependency_Map::load_new_object; |
|
1280 | - // we might have a dependency... |
|
1281 | - // let's MAYBE try and find it in our cache if that's what's been requested |
|
1282 | - $cached_class = $cache_on |
|
1283 | - ? $this->_get_cached_class($param_class) |
|
1284 | - : null; |
|
1285 | - // and grab it if it exists |
|
1286 | - if ($cached_class instanceof $param_class) { |
|
1287 | - $dependency = $cached_class; |
|
1288 | - } else if ($param_class !== $class_name) { |
|
1289 | - // obtain the loader method from the dependency map |
|
1290 | - $loader = $this->_dependency_map->class_loader($param_class); |
|
1291 | - // is loader a custom closure ? |
|
1292 | - if ($loader instanceof Closure) { |
|
1293 | - $dependency = $loader($arguments); |
|
1294 | - } else { |
|
1295 | - // set the cache on property for the recursive loading call |
|
1296 | - $this->_cache_on = $cache_on; |
|
1297 | - // if not, then let's try and load it via the registry |
|
1298 | - if ($loader && method_exists($this, $loader)) { |
|
1299 | - $dependency = $this->{$loader}($param_class); |
|
1300 | - } else { |
|
1301 | - $dependency = LoaderFactory::getLoader()->load( |
|
1302 | - $param_class, |
|
1303 | - array(), |
|
1304 | - $cache_on |
|
1305 | - ); |
|
1306 | - } |
|
1307 | - } |
|
1308 | - } |
|
1309 | - // did we successfully find the correct dependency ? |
|
1310 | - if ($dependency instanceof $param_class) { |
|
1311 | - // then let's inject it into the incoming array of arguments at the correct location |
|
1312 | - $arguments[$index] = $dependency; |
|
1313 | - } |
|
1314 | - return $arguments; |
|
1315 | - } |
|
1316 | - |
|
1317 | - |
|
1318 | - |
|
1319 | - /** |
|
1320 | - * _set_cached_class |
|
1321 | - * attempts to cache the instantiated class locally |
|
1322 | - * in one of the following places, in the following order: |
|
1323 | - * $this->{class_abbreviation} ie: $this->CART |
|
1324 | - * $this->{$class_name} ie: $this->Some_Class |
|
1325 | - * $this->addon->{$$class_name} ie: $this->addon->Some_Addon_Class |
|
1326 | - * $this->LIB->{$class_name} ie: $this->LIB->Some_Class |
|
1327 | - * |
|
1328 | - * @param object $class_obj |
|
1329 | - * @param string $class_name |
|
1330 | - * @param string $class_prefix |
|
1331 | - * @param bool $from_db |
|
1332 | - * @return void |
|
1333 | - */ |
|
1334 | - protected function _set_cached_class($class_obj, $class_name, $class_prefix = '', $from_db = false) |
|
1335 | - { |
|
1336 | - if ($class_name === 'EE_Registry' || empty($class_obj)) { |
|
1337 | - return; |
|
1338 | - } |
|
1339 | - // return newly instantiated class |
|
1340 | - $class_abbreviation = $this->get_class_abbreviation($class_name, ''); |
|
1341 | - if ($class_abbreviation) { |
|
1342 | - $this->{$class_abbreviation} = $class_obj; |
|
1343 | - return; |
|
1344 | - } |
|
1345 | - $class_name = str_replace('\\', '_', $class_name); |
|
1346 | - if (property_exists($this, $class_name)) { |
|
1347 | - $this->{$class_name} = $class_obj; |
|
1348 | - return; |
|
1349 | - } |
|
1350 | - if ($class_prefix === 'addon') { |
|
1351 | - $this->addons->{$class_name} = $class_obj; |
|
1352 | - return; |
|
1353 | - } |
|
1354 | - if (! $from_db) { |
|
1355 | - $this->LIB->{$class_name} = $class_obj; |
|
1356 | - } |
|
1357 | - } |
|
1358 | - |
|
1359 | - |
|
1360 | - |
|
1361 | - /** |
|
1362 | - * call any loader that's been registered in the EE_Dependency_Map::$_class_loaders array |
|
1363 | - * |
|
1364 | - * @param string $classname PLEASE NOTE: the class name needs to match what's registered |
|
1365 | - * in the EE_Dependency_Map::$_class_loaders array, |
|
1366 | - * including the class prefix, ie: "EE_", "EEM_", "EEH_", etc |
|
1367 | - * @param array $arguments |
|
1368 | - * @return object |
|
1369 | - */ |
|
1370 | - public static function factory($classname, $arguments = array()) |
|
1371 | - { |
|
1372 | - $loader = self::instance()->_dependency_map->class_loader($classname); |
|
1373 | - if ($loader instanceof Closure) { |
|
1374 | - return $loader($arguments); |
|
1375 | - } |
|
1376 | - if (method_exists(self::instance(), $loader)) { |
|
1377 | - return self::instance()->{$loader}($classname, $arguments); |
|
1378 | - } |
|
1379 | - return null; |
|
1380 | - } |
|
1381 | - |
|
1382 | - |
|
1383 | - |
|
1384 | - /** |
|
1385 | - * Gets the addon by its class name |
|
1386 | - * |
|
1387 | - * @param string $class_name |
|
1388 | - * @return EE_Addon |
|
1389 | - */ |
|
1390 | - public function getAddon($class_name) |
|
1391 | - { |
|
1392 | - $class_name = str_replace('\\', '_', $class_name); |
|
1393 | - return $this->addons->{$class_name}; |
|
1394 | - } |
|
1395 | - |
|
1396 | - |
|
1397 | - /** |
|
1398 | - * removes the addon from the internal cache |
|
1399 | - * |
|
1400 | - * @param string $class_name |
|
1401 | - * @return void |
|
1402 | - */ |
|
1403 | - public function removeAddon($class_name) |
|
1404 | - { |
|
1405 | - $class_name = str_replace('\\', '_', $class_name); |
|
1406 | - unset($this->addons->{$class_name}); |
|
1407 | - } |
|
1408 | - |
|
1409 | - |
|
1410 | - |
|
1411 | - /** |
|
1412 | - * Gets the addon by its name/slug (not classname. For that, just |
|
1413 | - * use the get_addon() method above |
|
1414 | - * |
|
1415 | - * @param string $name |
|
1416 | - * @return EE_Addon |
|
1417 | - */ |
|
1418 | - public function get_addon_by_name($name) |
|
1419 | - { |
|
1420 | - foreach ($this->addons as $addon) { |
|
1421 | - if ($addon->name() === $name) { |
|
1422 | - return $addon; |
|
1423 | - } |
|
1424 | - } |
|
1425 | - return null; |
|
1426 | - } |
|
1427 | - |
|
1428 | - |
|
1429 | - |
|
1430 | - /** |
|
1431 | - * Gets an array of all the registered addons, where the keys are their names. |
|
1432 | - * (ie, what each returns for their name() function) |
|
1433 | - * They're already available on EE_Registry::instance()->addons as properties, |
|
1434 | - * where each property's name is the addon's classname, |
|
1435 | - * So if you just want to get the addon by classname, |
|
1436 | - * OR use the get_addon() method above. |
|
1437 | - * PLEASE NOTE: |
|
1438 | - * addons with Fully Qualified Class Names |
|
1439 | - * have had the namespace separators converted to underscores, |
|
1440 | - * so a classname like Fully\Qualified\ClassName |
|
1441 | - * would have been converted to Fully_Qualified_ClassName |
|
1442 | - * |
|
1443 | - * @return EE_Addon[] where the KEYS are the addon's name() |
|
1444 | - */ |
|
1445 | - public function get_addons_by_name() |
|
1446 | - { |
|
1447 | - $addons = array(); |
|
1448 | - foreach ($this->addons as $addon) { |
|
1449 | - $addons[$addon->name()] = $addon; |
|
1450 | - } |
|
1451 | - return $addons; |
|
1452 | - } |
|
1453 | - |
|
1454 | - |
|
1455 | - /** |
|
1456 | - * Resets the specified model's instance AND makes sure EE_Registry doesn't keep |
|
1457 | - * a stale copy of it around |
|
1458 | - * |
|
1459 | - * @param string $model_name |
|
1460 | - * @return \EEM_Base |
|
1461 | - * @throws \EE_Error |
|
1462 | - */ |
|
1463 | - public function reset_model($model_name) |
|
1464 | - { |
|
1465 | - $model_class_name = strpos($model_name, 'EEM_') !== 0 |
|
1466 | - ? "EEM_{$model_name}" |
|
1467 | - : $model_name; |
|
1468 | - if (! isset($this->LIB->{$model_class_name}) || ! $this->LIB->{$model_class_name} instanceof EEM_Base) { |
|
1469 | - return null; |
|
1470 | - } |
|
1471 | - //get that model reset it and make sure we nuke the old reference to it |
|
1472 | - if ($this->LIB->{$model_class_name} instanceof $model_class_name |
|
1473 | - && is_callable( |
|
1474 | - array($model_class_name, 'reset') |
|
1475 | - )) { |
|
1476 | - $this->LIB->{$model_class_name} = $this->LIB->{$model_class_name}->reset(); |
|
1477 | - } else { |
|
1478 | - throw new EE_Error(sprintf(esc_html__('Model %s does not have a method "reset"', 'event_espresso'), $model_name)); |
|
1479 | - } |
|
1480 | - return $this->LIB->{$model_class_name}; |
|
1481 | - } |
|
1482 | - |
|
1483 | - |
|
1484 | - |
|
1485 | - /** |
|
1486 | - * Resets the registry. |
|
1487 | - * The criteria for what gets reset is based on what can be shared between sites on the same request when |
|
1488 | - * switch_to_blog is used in a multisite install. Here is a list of things that are NOT reset. |
|
1489 | - * - $_dependency_map |
|
1490 | - * - $_class_abbreviations |
|
1491 | - * - $NET_CFG (EE_Network_Config): The config is shared network wide so no need to reset. |
|
1492 | - * - $REQ: Still on the same request so no need to change. |
|
1493 | - * - $CAP: There is no site specific state in the EE_Capability class. |
|
1494 | - * - $SSN: Although ideally, the session should not be shared between site switches, we can't reset it because only |
|
1495 | - * one Session can be active in a single request. Resetting could resolve in "headers already sent" errors. |
|
1496 | - * - $addons: In multisite, the state of the addons is something controlled via hooks etc in a normal request. So |
|
1497 | - * for now, we won't reset the addons because it could break calls to an add-ons class/methods in the |
|
1498 | - * switch or on the restore. |
|
1499 | - * - $modules |
|
1500 | - * - $shortcodes |
|
1501 | - * - $widgets |
|
1502 | - * |
|
1503 | - * @param boolean $hard [deprecated] |
|
1504 | - * @param boolean $reinstantiate whether to create new instances of EE_Registry's singletons too, |
|
1505 | - * or just reset without re-instantiating (handy to set to FALSE if you're not |
|
1506 | - * sure if you CAN currently reinstantiate the singletons at the moment) |
|
1507 | - * @param bool $reset_models Defaults to true. When false, then the models are not reset. This is so |
|
1508 | - * client |
|
1509 | - * code instead can just change the model context to a different blog id if |
|
1510 | - * necessary |
|
1511 | - * @return EE_Registry |
|
1512 | - * @throws EE_Error |
|
1513 | - * @throws ReflectionException |
|
1514 | - */ |
|
1515 | - public static function reset($hard = false, $reinstantiate = true, $reset_models = true) |
|
1516 | - { |
|
1517 | - $instance = self::instance(); |
|
1518 | - $instance->_cache_on = true; |
|
1519 | - // reset some "special" classes |
|
1520 | - EEH_Activation::reset(); |
|
1521 | - $hard = apply_filters( 'FHEE__EE_Registry__reset__hard', $hard); |
|
1522 | - $instance->CFG = EE_Config::reset($hard, $reinstantiate); |
|
1523 | - $instance->CART = null; |
|
1524 | - $instance->MRM = null; |
|
1525 | - $instance->AssetsRegistry = $instance->create('EventEspresso\core\services\assets\Registry'); |
|
1526 | - //messages reset |
|
1527 | - EED_Messages::reset(); |
|
1528 | - //handle of objects cached on LIB |
|
1529 | - foreach (array('LIB', 'modules') as $cache) { |
|
1530 | - foreach ($instance->{$cache} as $class_name => $class) { |
|
1531 | - if (self::_reset_and_unset_object($class, $reset_models)) { |
|
1532 | - unset($instance->{$cache}->{$class_name}); |
|
1533 | - } |
|
1534 | - } |
|
1535 | - } |
|
1536 | - return $instance; |
|
1537 | - } |
|
1538 | - |
|
1539 | - |
|
1540 | - |
|
1541 | - /** |
|
1542 | - * if passed object implements ResettableInterface, then call it's reset() method |
|
1543 | - * if passed object implements InterminableInterface, then return false, |
|
1544 | - * to indicate that it should NOT be cleared from the Registry cache |
|
1545 | - * |
|
1546 | - * @param $object |
|
1547 | - * @param bool $reset_models |
|
1548 | - * @return bool returns true if cached object should be unset |
|
1549 | - */ |
|
1550 | - private static function _reset_and_unset_object($object, $reset_models) |
|
1551 | - { |
|
1552 | - if (! is_object($object)) { |
|
1553 | - // don't unset anything that's not an object |
|
1554 | - return false; |
|
1555 | - } |
|
1556 | - if ($object instanceof EED_Module) { |
|
1557 | - $object::reset(); |
|
1558 | - // don't unset modules |
|
1559 | - return false; |
|
1560 | - } |
|
1561 | - if ($object instanceof ResettableInterface) { |
|
1562 | - if ($object instanceof EEM_Base) { |
|
1563 | - if ($reset_models) { |
|
1564 | - $object->reset(); |
|
1565 | - return true; |
|
1566 | - } |
|
1567 | - return false; |
|
1568 | - } |
|
1569 | - $object->reset(); |
|
1570 | - return true; |
|
1571 | - } |
|
1572 | - if (! $object instanceof InterminableInterface) { |
|
1573 | - return true; |
|
1574 | - } |
|
1575 | - return false; |
|
1576 | - } |
|
1577 | - |
|
1578 | - |
|
1579 | - |
|
1580 | - /** |
|
1581 | - * Gets all the custom post type models defined |
|
1582 | - * |
|
1583 | - * @return array keys are model "short names" (Eg "Event") and keys are classnames (eg "EEM_Event") |
|
1584 | - */ |
|
1585 | - public function cpt_models() |
|
1586 | - { |
|
1587 | - $cpt_models = array(); |
|
1588 | - foreach ($this->non_abstract_db_models as $short_name => $classname) { |
|
1589 | - if (is_subclass_of($classname, 'EEM_CPT_Base')) { |
|
1590 | - $cpt_models[$short_name] = $classname; |
|
1591 | - } |
|
1592 | - } |
|
1593 | - return $cpt_models; |
|
1594 | - } |
|
1595 | - |
|
1596 | - |
|
1597 | - |
|
1598 | - /** |
|
1599 | - * @return \EE_Config |
|
1600 | - */ |
|
1601 | - public static function CFG() |
|
1602 | - { |
|
1603 | - return self::instance()->CFG; |
|
1604 | - } |
|
26 | + /** |
|
27 | + * @var EE_Registry $_instance |
|
28 | + */ |
|
29 | + private static $_instance; |
|
30 | + |
|
31 | + /** |
|
32 | + * @var EE_Dependency_Map $_dependency_map |
|
33 | + */ |
|
34 | + protected $_dependency_map; |
|
35 | + |
|
36 | + /** |
|
37 | + * @var array $_class_abbreviations |
|
38 | + */ |
|
39 | + protected $_class_abbreviations = array(); |
|
40 | + |
|
41 | + /** |
|
42 | + * @var CommandBusInterface $BUS |
|
43 | + */ |
|
44 | + public $BUS; |
|
45 | + |
|
46 | + /** |
|
47 | + * @var EE_Cart $CART |
|
48 | + */ |
|
49 | + public $CART; |
|
50 | + |
|
51 | + /** |
|
52 | + * @var EE_Config $CFG |
|
53 | + */ |
|
54 | + public $CFG; |
|
55 | + |
|
56 | + /** |
|
57 | + * @var EE_Network_Config $NET_CFG |
|
58 | + */ |
|
59 | + public $NET_CFG; |
|
60 | + |
|
61 | + /** |
|
62 | + * StdClass object for storing library classes in |
|
63 | + * |
|
64 | + * @var StdClass $LIB |
|
65 | + */ |
|
66 | + public $LIB; |
|
67 | + |
|
68 | + /** |
|
69 | + * @var EE_Request_Handler $REQ |
|
70 | + */ |
|
71 | + public $REQ; |
|
72 | + |
|
73 | + /** |
|
74 | + * @var EE_Session $SSN |
|
75 | + */ |
|
76 | + public $SSN; |
|
77 | + |
|
78 | + /** |
|
79 | + * @since 4.5.0 |
|
80 | + * @var EE_Capabilities $CAP |
|
81 | + */ |
|
82 | + public $CAP; |
|
83 | + |
|
84 | + /** |
|
85 | + * @since 4.9.0 |
|
86 | + * @var EE_Message_Resource_Manager $MRM |
|
87 | + */ |
|
88 | + public $MRM; |
|
89 | + |
|
90 | + |
|
91 | + /** |
|
92 | + * @var Registry $AssetsRegistry |
|
93 | + */ |
|
94 | + public $AssetsRegistry; |
|
95 | + |
|
96 | + /** |
|
97 | + * StdClass object for holding addons which have registered themselves to work with EE core |
|
98 | + * |
|
99 | + * @var EE_Addon[] $addons |
|
100 | + */ |
|
101 | + public $addons; |
|
102 | + |
|
103 | + /** |
|
104 | + * keys are 'short names' (eg Event), values are class names (eg 'EEM_Event') |
|
105 | + * |
|
106 | + * @var EEM_Base[] $models |
|
107 | + */ |
|
108 | + public $models = array(); |
|
109 | + |
|
110 | + /** |
|
111 | + * @var EED_Module[] $modules |
|
112 | + */ |
|
113 | + public $modules; |
|
114 | + |
|
115 | + /** |
|
116 | + * @var EES_Shortcode[] $shortcodes |
|
117 | + */ |
|
118 | + public $shortcodes; |
|
119 | + |
|
120 | + /** |
|
121 | + * @var WP_Widget[] $widgets |
|
122 | + */ |
|
123 | + public $widgets; |
|
124 | + |
|
125 | + /** |
|
126 | + * this is an array of all implemented model names (i.e. not the parent abstract models, or models |
|
127 | + * which don't actually fetch items from the DB in the normal way (ie, are not children of EEM_Base)). |
|
128 | + * Keys are model "short names" (eg "Event") as used in model relations, and values are |
|
129 | + * classnames (eg "EEM_Event") |
|
130 | + * |
|
131 | + * @var array $non_abstract_db_models |
|
132 | + */ |
|
133 | + public $non_abstract_db_models = array(); |
|
134 | + |
|
135 | + |
|
136 | + /** |
|
137 | + * internationalization for JS strings |
|
138 | + * usage: EE_Registry::i18n_js_strings['string_key'] = esc_html__( 'string to translate.', 'event_espresso' ); |
|
139 | + * in js file: var translatedString = eei18n.string_key; |
|
140 | + * |
|
141 | + * @var array $i18n_js_strings |
|
142 | + */ |
|
143 | + public static $i18n_js_strings = array(); |
|
144 | + |
|
145 | + |
|
146 | + /** |
|
147 | + * $main_file - path to espresso.php |
|
148 | + * |
|
149 | + * @var array $main_file |
|
150 | + */ |
|
151 | + public $main_file; |
|
152 | + |
|
153 | + /** |
|
154 | + * array of ReflectionClass objects where the key is the class name |
|
155 | + * |
|
156 | + * @var ReflectionClass[] $_reflectors |
|
157 | + */ |
|
158 | + public $_reflectors; |
|
159 | + |
|
160 | + /** |
|
161 | + * boolean flag to indicate whether or not to load/save dependencies from/to the cache |
|
162 | + * |
|
163 | + * @var boolean $_cache_on |
|
164 | + */ |
|
165 | + protected $_cache_on = true; |
|
166 | + |
|
167 | + |
|
168 | + |
|
169 | + /** |
|
170 | + * @singleton method used to instantiate class object |
|
171 | + * @param EE_Dependency_Map $dependency_map |
|
172 | + * @return EE_Registry instance |
|
173 | + * @throws InvalidArgumentException |
|
174 | + * @throws InvalidInterfaceException |
|
175 | + * @throws InvalidDataTypeException |
|
176 | + */ |
|
177 | + public static function instance(EE_Dependency_Map $dependency_map = null) |
|
178 | + { |
|
179 | + // check if class object is instantiated |
|
180 | + if (! self::$_instance instanceof EE_Registry) { |
|
181 | + self::$_instance = new self($dependency_map); |
|
182 | + } |
|
183 | + return self::$_instance; |
|
184 | + } |
|
185 | + |
|
186 | + |
|
187 | + |
|
188 | + /** |
|
189 | + * protected constructor to prevent direct creation |
|
190 | + * |
|
191 | + * @Constructor |
|
192 | + * @param EE_Dependency_Map $dependency_map |
|
193 | + * @throws InvalidDataTypeException |
|
194 | + * @throws InvalidInterfaceException |
|
195 | + * @throws InvalidArgumentException |
|
196 | + */ |
|
197 | + protected function __construct(EE_Dependency_Map $dependency_map) |
|
198 | + { |
|
199 | + $this->_dependency_map = $dependency_map; |
|
200 | + // $registry_container = new RegistryContainer(); |
|
201 | + $this->LIB = new RegistryContainer(); |
|
202 | + $this->addons = new RegistryContainer(); |
|
203 | + $this->modules = new RegistryContainer(); |
|
204 | + $this->shortcodes = new RegistryContainer(); |
|
205 | + $this->widgets = new RegistryContainer(); |
|
206 | + add_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading', array($this, 'initialize')); |
|
207 | + } |
|
208 | + |
|
209 | + |
|
210 | + |
|
211 | + /** |
|
212 | + * initialize |
|
213 | + * |
|
214 | + * @throws EE_Error |
|
215 | + * @throws ReflectionException |
|
216 | + */ |
|
217 | + public function initialize() |
|
218 | + { |
|
219 | + $this->_class_abbreviations = apply_filters( |
|
220 | + 'FHEE__EE_Registry____construct___class_abbreviations', |
|
221 | + array( |
|
222 | + 'EE_Config' => 'CFG', |
|
223 | + 'EE_Session' => 'SSN', |
|
224 | + 'EE_Capabilities' => 'CAP', |
|
225 | + 'EE_Cart' => 'CART', |
|
226 | + 'EE_Network_Config' => 'NET_CFG', |
|
227 | + 'EE_Request_Handler' => 'REQ', |
|
228 | + 'EE_Message_Resource_Manager' => 'MRM', |
|
229 | + 'EventEspresso\core\services\commands\CommandBus' => 'BUS', |
|
230 | + 'EventEspresso\core\services\assets\Registry' => 'AssetsRegistry', |
|
231 | + ) |
|
232 | + ); |
|
233 | + $this->load_core('Base', array(), true); |
|
234 | + // add our request and response objects to the cache |
|
235 | + $request_loader = $this->_dependency_map->class_loader('EE_Request'); |
|
236 | + $this->_set_cached_class( |
|
237 | + $request_loader(), |
|
238 | + 'EE_Request' |
|
239 | + ); |
|
240 | + $response_loader = $this->_dependency_map->class_loader('EE_Response'); |
|
241 | + $this->_set_cached_class( |
|
242 | + $response_loader(), |
|
243 | + 'EE_Response' |
|
244 | + ); |
|
245 | + add_action('AHEE__EE_System__set_hooks_for_core', array($this, 'init')); |
|
246 | + } |
|
247 | + |
|
248 | + |
|
249 | + |
|
250 | + /** |
|
251 | + * @return void |
|
252 | + */ |
|
253 | + public function init() |
|
254 | + { |
|
255 | + // Get current page protocol |
|
256 | + $protocol = isset($_SERVER['HTTPS']) ? 'https://' : 'http://'; |
|
257 | + // Output admin-ajax.php URL with same protocol as current page |
|
258 | + self::$i18n_js_strings['ajax_url'] = admin_url('admin-ajax.php', $protocol); |
|
259 | + self::$i18n_js_strings['wp_debug'] = defined('WP_DEBUG') ? WP_DEBUG : false; |
|
260 | + } |
|
261 | + |
|
262 | + |
|
263 | + |
|
264 | + /** |
|
265 | + * localize_i18n_js_strings |
|
266 | + * |
|
267 | + * @return string |
|
268 | + */ |
|
269 | + public static function localize_i18n_js_strings() |
|
270 | + { |
|
271 | + $i18n_js_strings = (array)self::$i18n_js_strings; |
|
272 | + foreach ($i18n_js_strings as $key => $value) { |
|
273 | + if (is_scalar($value)) { |
|
274 | + $i18n_js_strings[$key] = html_entity_decode((string)$value, ENT_QUOTES, 'UTF-8'); |
|
275 | + } |
|
276 | + } |
|
277 | + return '/* <![CDATA[ */ var eei18n = ' . wp_json_encode($i18n_js_strings) . '; /* ]]> */'; |
|
278 | + } |
|
279 | + |
|
280 | + |
|
281 | + |
|
282 | + /** |
|
283 | + * @param mixed string | EED_Module $module |
|
284 | + * @throws EE_Error |
|
285 | + * @throws ReflectionException |
|
286 | + */ |
|
287 | + public function add_module($module) |
|
288 | + { |
|
289 | + if ($module instanceof EED_Module) { |
|
290 | + $module_class = get_class($module); |
|
291 | + $this->modules->{$module_class} = $module; |
|
292 | + } else { |
|
293 | + if ( ! class_exists('EE_Module_Request_Router', false)) { |
|
294 | + $this->load_core('Module_Request_Router'); |
|
295 | + } |
|
296 | + EE_Module_Request_Router::module_factory($module); |
|
297 | + } |
|
298 | + } |
|
299 | + |
|
300 | + |
|
301 | + |
|
302 | + /** |
|
303 | + * @param string $module_name |
|
304 | + * @return mixed EED_Module | NULL |
|
305 | + */ |
|
306 | + public function get_module($module_name = '') |
|
307 | + { |
|
308 | + return isset($this->modules->{$module_name}) |
|
309 | + ? $this->modules->{$module_name} |
|
310 | + : null; |
|
311 | + } |
|
312 | + |
|
313 | + |
|
314 | + |
|
315 | + /** |
|
316 | + * loads core classes - must be singletons |
|
317 | + * |
|
318 | + * @param string $class_name - simple class name ie: session |
|
319 | + * @param mixed $arguments |
|
320 | + * @param bool $load_only |
|
321 | + * @return mixed |
|
322 | + * @throws EE_Error |
|
323 | + * @throws ReflectionException |
|
324 | + */ |
|
325 | + public function load_core($class_name, $arguments = array(), $load_only = false) |
|
326 | + { |
|
327 | + $core_paths = apply_filters( |
|
328 | + 'FHEE__EE_Registry__load_core__core_paths', |
|
329 | + array( |
|
330 | + EE_CORE, |
|
331 | + EE_ADMIN, |
|
332 | + EE_CPTS, |
|
333 | + EE_CORE . 'data_migration_scripts' . DS, |
|
334 | + EE_CORE . 'capabilities' . DS, |
|
335 | + EE_CORE . 'request_stack' . DS, |
|
336 | + EE_CORE . 'middleware' . DS, |
|
337 | + ) |
|
338 | + ); |
|
339 | + // retrieve instantiated class |
|
340 | + return $this->_load( |
|
341 | + $core_paths, |
|
342 | + 'EE_', |
|
343 | + $class_name, |
|
344 | + 'core', |
|
345 | + $arguments, |
|
346 | + false, |
|
347 | + true, |
|
348 | + $load_only |
|
349 | + ); |
|
350 | + } |
|
351 | + |
|
352 | + |
|
353 | + |
|
354 | + /** |
|
355 | + * loads service classes |
|
356 | + * |
|
357 | + * @param string $class_name - simple class name ie: session |
|
358 | + * @param mixed $arguments |
|
359 | + * @param bool $load_only |
|
360 | + * @return mixed |
|
361 | + * @throws EE_Error |
|
362 | + * @throws ReflectionException |
|
363 | + */ |
|
364 | + public function load_service($class_name, $arguments = array(), $load_only = false) |
|
365 | + { |
|
366 | + $service_paths = apply_filters( |
|
367 | + 'FHEE__EE_Registry__load_service__service_paths', |
|
368 | + array( |
|
369 | + EE_CORE . 'services' . DS, |
|
370 | + ) |
|
371 | + ); |
|
372 | + // retrieve instantiated class |
|
373 | + return $this->_load( |
|
374 | + $service_paths, |
|
375 | + 'EE_', |
|
376 | + $class_name, |
|
377 | + 'class', |
|
378 | + $arguments, |
|
379 | + false, |
|
380 | + true, |
|
381 | + $load_only |
|
382 | + ); |
|
383 | + } |
|
384 | + |
|
385 | + |
|
386 | + |
|
387 | + /** |
|
388 | + * loads data_migration_scripts |
|
389 | + * |
|
390 | + * @param string $class_name - class name for the DMS ie: EE_DMS_Core_4_2_0 |
|
391 | + * @param mixed $arguments |
|
392 | + * @return EE_Data_Migration_Script_Base|mixed |
|
393 | + * @throws EE_Error |
|
394 | + * @throws ReflectionException |
|
395 | + */ |
|
396 | + public function load_dms($class_name, $arguments = array()) |
|
397 | + { |
|
398 | + // retrieve instantiated class |
|
399 | + return $this->_load( |
|
400 | + EE_Data_Migration_Manager::instance()->get_data_migration_script_folders(), |
|
401 | + 'EE_DMS_', |
|
402 | + $class_name, |
|
403 | + 'dms', |
|
404 | + $arguments, |
|
405 | + false, |
|
406 | + false |
|
407 | + ); |
|
408 | + } |
|
409 | + |
|
410 | + |
|
411 | + |
|
412 | + /** |
|
413 | + * loads object creating classes - must be singletons |
|
414 | + * |
|
415 | + * @param string $class_name - simple class name ie: attendee |
|
416 | + * @param mixed $arguments - an array of arguments to pass to the class |
|
417 | + * @param bool $from_db - some classes are instantiated from the db and thus call a different method to |
|
418 | + * instantiate |
|
419 | + * @param bool $cache if you don't want the class to be stored in the internal cache (non-persistent) then |
|
420 | + * set this to FALSE (ie. when instantiating model objects from client in a loop) |
|
421 | + * @param bool $load_only whether or not to just load the file and NOT instantiate, or load AND instantiate |
|
422 | + * (default) |
|
423 | + * @return EE_Base_Class | bool |
|
424 | + * @throws EE_Error |
|
425 | + * @throws ReflectionException |
|
426 | + */ |
|
427 | + public function load_class($class_name, $arguments = array(), $from_db = false, $cache = true, $load_only = false) |
|
428 | + { |
|
429 | + $paths = apply_filters( |
|
430 | + 'FHEE__EE_Registry__load_class__paths', array( |
|
431 | + EE_CORE, |
|
432 | + EE_CLASSES, |
|
433 | + EE_BUSINESS, |
|
434 | + ) |
|
435 | + ); |
|
436 | + // retrieve instantiated class |
|
437 | + return $this->_load( |
|
438 | + $paths, |
|
439 | + 'EE_', |
|
440 | + $class_name, |
|
441 | + 'class', |
|
442 | + $arguments, |
|
443 | + $from_db, |
|
444 | + $cache, |
|
445 | + $load_only |
|
446 | + ); |
|
447 | + } |
|
448 | + |
|
449 | + |
|
450 | + |
|
451 | + /** |
|
452 | + * loads helper classes - must be singletons |
|
453 | + * |
|
454 | + * @param string $class_name - simple class name ie: price |
|
455 | + * @param mixed $arguments |
|
456 | + * @param bool $load_only |
|
457 | + * @return EEH_Base | bool |
|
458 | + * @throws EE_Error |
|
459 | + * @throws ReflectionException |
|
460 | + */ |
|
461 | + public function load_helper($class_name, $arguments = array(), $load_only = true) |
|
462 | + { |
|
463 | + // todo: add doing_it_wrong() in a few versions after all addons have had calls to this method removed |
|
464 | + $helper_paths = apply_filters('FHEE__EE_Registry__load_helper__helper_paths', array(EE_HELPERS)); |
|
465 | + // retrieve instantiated class |
|
466 | + return $this->_load( |
|
467 | + $helper_paths, |
|
468 | + 'EEH_', |
|
469 | + $class_name, |
|
470 | + 'helper', |
|
471 | + $arguments, |
|
472 | + false, |
|
473 | + true, |
|
474 | + $load_only |
|
475 | + ); |
|
476 | + } |
|
477 | + |
|
478 | + |
|
479 | + |
|
480 | + /** |
|
481 | + * loads core classes - must be singletons |
|
482 | + * |
|
483 | + * @param string $class_name - simple class name ie: session |
|
484 | + * @param mixed $arguments |
|
485 | + * @param bool $load_only |
|
486 | + * @param bool $cache whether to cache the object or not. |
|
487 | + * @return mixed |
|
488 | + * @throws EE_Error |
|
489 | + * @throws ReflectionException |
|
490 | + */ |
|
491 | + public function load_lib($class_name, $arguments = array(), $load_only = false, $cache = true) |
|
492 | + { |
|
493 | + $paths = array( |
|
494 | + EE_LIBRARIES, |
|
495 | + EE_LIBRARIES . 'messages' . DS, |
|
496 | + EE_LIBRARIES . 'shortcodes' . DS, |
|
497 | + EE_LIBRARIES . 'qtips' . DS, |
|
498 | + EE_LIBRARIES . 'payment_methods' . DS, |
|
499 | + ); |
|
500 | + // retrieve instantiated class |
|
501 | + return $this->_load( |
|
502 | + $paths, |
|
503 | + 'EE_', |
|
504 | + $class_name, |
|
505 | + 'lib', |
|
506 | + $arguments, |
|
507 | + false, |
|
508 | + $cache, |
|
509 | + $load_only |
|
510 | + ); |
|
511 | + } |
|
512 | + |
|
513 | + |
|
514 | + |
|
515 | + /** |
|
516 | + * loads model classes - must be singletons |
|
517 | + * |
|
518 | + * @param string $class_name - simple class name ie: price |
|
519 | + * @param mixed $arguments |
|
520 | + * @param bool $load_only |
|
521 | + * @return EEM_Base | bool |
|
522 | + * @throws EE_Error |
|
523 | + * @throws ReflectionException |
|
524 | + */ |
|
525 | + public function load_model($class_name, $arguments = array(), $load_only = false) |
|
526 | + { |
|
527 | + $paths = apply_filters( |
|
528 | + 'FHEE__EE_Registry__load_model__paths', array( |
|
529 | + EE_MODELS, |
|
530 | + EE_CORE, |
|
531 | + ) |
|
532 | + ); |
|
533 | + // retrieve instantiated class |
|
534 | + return $this->_load( |
|
535 | + $paths, |
|
536 | + 'EEM_', |
|
537 | + $class_name, |
|
538 | + 'model', |
|
539 | + $arguments, |
|
540 | + false, |
|
541 | + true, |
|
542 | + $load_only |
|
543 | + ); |
|
544 | + } |
|
545 | + |
|
546 | + |
|
547 | + |
|
548 | + /** |
|
549 | + * loads model classes - must be singletons |
|
550 | + * |
|
551 | + * @param string $class_name - simple class name ie: price |
|
552 | + * @param mixed $arguments |
|
553 | + * @param bool $load_only |
|
554 | + * @return mixed | bool |
|
555 | + * @throws EE_Error |
|
556 | + * @throws ReflectionException |
|
557 | + */ |
|
558 | + public function load_model_class($class_name, $arguments = array(), $load_only = true) |
|
559 | + { |
|
560 | + $paths = array( |
|
561 | + EE_MODELS . 'fields' . DS, |
|
562 | + EE_MODELS . 'helpers' . DS, |
|
563 | + EE_MODELS . 'relations' . DS, |
|
564 | + EE_MODELS . 'strategies' . DS, |
|
565 | + ); |
|
566 | + // retrieve instantiated class |
|
567 | + return $this->_load( |
|
568 | + $paths, |
|
569 | + 'EE_', |
|
570 | + $class_name, |
|
571 | + '', |
|
572 | + $arguments, |
|
573 | + false, |
|
574 | + true, |
|
575 | + $load_only |
|
576 | + ); |
|
577 | + } |
|
578 | + |
|
579 | + |
|
580 | + |
|
581 | + /** |
|
582 | + * Determines if $model_name is the name of an actual EE model. |
|
583 | + * |
|
584 | + * @param string $model_name like Event, Attendee, Question_Group_Question, etc. |
|
585 | + * @return boolean |
|
586 | + */ |
|
587 | + public function is_model_name($model_name) |
|
588 | + { |
|
589 | + return isset($this->models[$model_name]); |
|
590 | + } |
|
591 | + |
|
592 | + |
|
593 | + |
|
594 | + /** |
|
595 | + * generic class loader |
|
596 | + * |
|
597 | + * @param string $path_to_file - directory path to file location, not including filename |
|
598 | + * @param string $file_name - file name ie: my_file.php, including extension |
|
599 | + * @param string $type - file type - core? class? helper? model? |
|
600 | + * @param mixed $arguments |
|
601 | + * @param bool $load_only |
|
602 | + * @return mixed |
|
603 | + * @throws EE_Error |
|
604 | + * @throws ReflectionException |
|
605 | + */ |
|
606 | + public function load_file($path_to_file, $file_name, $type = '', $arguments = array(), $load_only = true) |
|
607 | + { |
|
608 | + // retrieve instantiated class |
|
609 | + return $this->_load( |
|
610 | + $path_to_file, |
|
611 | + '', |
|
612 | + $file_name, |
|
613 | + $type, |
|
614 | + $arguments, |
|
615 | + false, |
|
616 | + true, |
|
617 | + $load_only |
|
618 | + ); |
|
619 | + } |
|
620 | + |
|
621 | + |
|
622 | + |
|
623 | + /** |
|
624 | + * @param string $path_to_file - directory path to file location, not including filename |
|
625 | + * @param string $class_name - full class name ie: My_Class |
|
626 | + * @param string $type - file type - core? class? helper? model? |
|
627 | + * @param mixed $arguments |
|
628 | + * @param bool $load_only |
|
629 | + * @return bool|EE_Addon|object |
|
630 | + * @throws EE_Error |
|
631 | + * @throws ReflectionException |
|
632 | + */ |
|
633 | + public function load_addon($path_to_file, $class_name, $type = 'class', $arguments = array(), $load_only = false) |
|
634 | + { |
|
635 | + // retrieve instantiated class |
|
636 | + return $this->_load( |
|
637 | + $path_to_file, |
|
638 | + 'addon', |
|
639 | + $class_name, |
|
640 | + $type, |
|
641 | + $arguments, |
|
642 | + false, |
|
643 | + true, |
|
644 | + $load_only |
|
645 | + ); |
|
646 | + } |
|
647 | + |
|
648 | + |
|
649 | + |
|
650 | + /** |
|
651 | + * instantiates, caches, and automatically resolves dependencies |
|
652 | + * for classes that use a Fully Qualified Class Name. |
|
653 | + * if the class is not capable of being loaded using PSR-4 autoloading, |
|
654 | + * then you need to use one of the existing load_*() methods |
|
655 | + * which can resolve the classname and filepath from the passed arguments |
|
656 | + * |
|
657 | + * @param bool|string $class_name Fully Qualified Class Name |
|
658 | + * @param array $arguments an argument, or array of arguments to pass to the class upon instantiation |
|
659 | + * @param bool $cache whether to cache the instantiated object for reuse |
|
660 | + * @param bool $from_db some classes are instantiated from the db |
|
661 | + * and thus call a different method to instantiate |
|
662 | + * @param bool $load_only if true, will only load the file, but will NOT instantiate an object |
|
663 | + * @param bool|string $addon if true, will cache the object in the EE_Registry->$addons array |
|
664 | + * @return bool|null|mixed null = failure to load or instantiate class object. |
|
665 | + * object = class loaded and instantiated successfully. |
|
666 | + * bool = fail or success when $load_only is true |
|
667 | + * @throws EE_Error |
|
668 | + * @throws ReflectionException |
|
669 | + */ |
|
670 | + public function create( |
|
671 | + $class_name = false, |
|
672 | + $arguments = array(), |
|
673 | + $cache = false, |
|
674 | + $from_db = false, |
|
675 | + $load_only = false, |
|
676 | + $addon = false |
|
677 | + ) { |
|
678 | + $class_name = ltrim($class_name, '\\'); |
|
679 | + $class_name = $this->_dependency_map->get_alias($class_name); |
|
680 | + $class_exists = $this->loadOrVerifyClassExists($class_name, $arguments); |
|
681 | + // if a non-FQCN was passed, then verifyClassExists() might return an object |
|
682 | + // or it could return null if the class just could not be found anywhere |
|
683 | + if ($class_exists instanceof $class_name || $class_exists === null){ |
|
684 | + // either way, return the results |
|
685 | + return $class_exists; |
|
686 | + } |
|
687 | + $class_name = $class_exists; |
|
688 | + // if we're only loading the class and it already exists, then let's just return true immediately |
|
689 | + if ($load_only) { |
|
690 | + return true; |
|
691 | + } |
|
692 | + $addon = $addon |
|
693 | + ? 'addon' |
|
694 | + : ''; |
|
695 | + // $this->_cache_on is toggled during the recursive loading that can occur with dependency injection |
|
696 | + // $cache is controlled by individual calls to separate Registry loader methods like load_class() |
|
697 | + // $load_only is also controlled by individual calls to separate Registry loader methods like load_file() |
|
698 | + if ($this->_cache_on && $cache && ! $load_only) { |
|
699 | + // return object if it's already cached |
|
700 | + $cached_class = $this->_get_cached_class($class_name, $addon); |
|
701 | + if ($cached_class !== null) { |
|
702 | + return $cached_class; |
|
703 | + } |
|
704 | + } |
|
705 | + // obtain the loader method from the dependency map |
|
706 | + $loader = $this->_dependency_map->class_loader($class_name); |
|
707 | + // instantiate the requested object |
|
708 | + if ($loader instanceof Closure) { |
|
709 | + $class_obj = $loader($arguments); |
|
710 | + } else if ($loader && method_exists($this, $loader)) { |
|
711 | + $class_obj = $this->{$loader}($class_name, $arguments); |
|
712 | + } else { |
|
713 | + $class_obj = $this->_create_object($class_name, $arguments, $addon, $from_db); |
|
714 | + } |
|
715 | + if (($this->_cache_on && $cache) || $this->get_class_abbreviation($class_name, '')) { |
|
716 | + // save it for later... kinda like gum { : $ |
|
717 | + $this->_set_cached_class($class_obj, $class_name, $addon, $from_db); |
|
718 | + } |
|
719 | + $this->_cache_on = true; |
|
720 | + return $class_obj; |
|
721 | + } |
|
722 | + |
|
723 | + |
|
724 | + |
|
725 | + /** |
|
726 | + * Recursively checks that a class exists and potentially attempts to load classes with non-FQCNs |
|
727 | + * |
|
728 | + * @param string $class_name |
|
729 | + * @param array $arguments |
|
730 | + * @param int $attempt |
|
731 | + * @return mixed |
|
732 | + */ |
|
733 | + private function loadOrVerifyClassExists($class_name, array $arguments, $attempt = 1) { |
|
734 | + if (is_object($class_name) || class_exists($class_name)) { |
|
735 | + return $class_name; |
|
736 | + } |
|
737 | + switch ($attempt) { |
|
738 | + case 1: |
|
739 | + // if it's a FQCN then maybe the class is registered with a preceding \ |
|
740 | + $class_name = strpos($class_name, '\\') !== false |
|
741 | + ? '\\' . ltrim($class_name, '\\') |
|
742 | + : $class_name; |
|
743 | + break; |
|
744 | + case 2: |
|
745 | + // |
|
746 | + $loader = $this->_dependency_map->class_loader($class_name); |
|
747 | + if ($loader && method_exists($this, $loader)) { |
|
748 | + return $this->{$loader}($class_name, $arguments); |
|
749 | + } |
|
750 | + break; |
|
751 | + case 3: |
|
752 | + default; |
|
753 | + return null; |
|
754 | + } |
|
755 | + $attempt++; |
|
756 | + return $this->loadOrVerifyClassExists($class_name, $arguments, $attempt); |
|
757 | + } |
|
758 | + |
|
759 | + |
|
760 | + |
|
761 | + /** |
|
762 | + * instantiates, caches, and injects dependencies for classes |
|
763 | + * |
|
764 | + * @param array $file_paths an array of paths to folders to look in |
|
765 | + * @param string $class_prefix EE or EEM or... ??? |
|
766 | + * @param bool|string $class_name $class name |
|
767 | + * @param string $type file type - core? class? helper? model? |
|
768 | + * @param mixed $arguments an argument or array of arguments to pass to the class upon instantiation |
|
769 | + * @param bool $from_db some classes are instantiated from the db |
|
770 | + * and thus call a different method to instantiate |
|
771 | + * @param bool $cache whether to cache the instantiated object for reuse |
|
772 | + * @param bool $load_only if true, will only load the file, but will NOT instantiate an object |
|
773 | + * @return bool|null|object null = failure to load or instantiate class object. |
|
774 | + * object = class loaded and instantiated successfully. |
|
775 | + * bool = fail or success when $load_only is true |
|
776 | + * @throws EE_Error |
|
777 | + * @throws ReflectionException |
|
778 | + */ |
|
779 | + protected function _load( |
|
780 | + $file_paths = array(), |
|
781 | + $class_prefix = 'EE_', |
|
782 | + $class_name = false, |
|
783 | + $type = 'class', |
|
784 | + $arguments = array(), |
|
785 | + $from_db = false, |
|
786 | + $cache = true, |
|
787 | + $load_only = false |
|
788 | + ) { |
|
789 | + $class_name = ltrim($class_name, '\\'); |
|
790 | + // strip php file extension |
|
791 | + $class_name = str_replace('.php', '', trim($class_name)); |
|
792 | + // does the class have a prefix ? |
|
793 | + if (! empty($class_prefix) && $class_prefix !== 'addon') { |
|
794 | + // make sure $class_prefix is uppercase |
|
795 | + $class_prefix = strtoupper(trim($class_prefix)); |
|
796 | + // add class prefix ONCE!!! |
|
797 | + $class_name = $class_prefix . str_replace($class_prefix, '', $class_name); |
|
798 | + } |
|
799 | + $class_name = $this->_dependency_map->get_alias($class_name); |
|
800 | + $class_exists = class_exists($class_name, false); |
|
801 | + // if we're only loading the class and it already exists, then let's just return true immediately |
|
802 | + if ($load_only && $class_exists) { |
|
803 | + return true; |
|
804 | + } |
|
805 | + // $this->_cache_on is toggled during the recursive loading that can occur with dependency injection |
|
806 | + // $cache is controlled by individual calls to separate Registry loader methods like load_class() |
|
807 | + // $load_only is also controlled by individual calls to separate Registry loader methods like load_file() |
|
808 | + if ($this->_cache_on && $cache && ! $load_only) { |
|
809 | + // return object if it's already cached |
|
810 | + $cached_class = $this->_get_cached_class($class_name, $class_prefix); |
|
811 | + if ($cached_class !== null) { |
|
812 | + return $cached_class; |
|
813 | + } |
|
814 | + } |
|
815 | + // if the class doesn't already exist.. then we need to try and find the file and load it |
|
816 | + if (! $class_exists) { |
|
817 | + // get full path to file |
|
818 | + $path = $this->_resolve_path($class_name, $type, $file_paths); |
|
819 | + // load the file |
|
820 | + $loaded = $this->_require_file($path, $class_name, $type, $file_paths); |
|
821 | + // if loading failed, or we are only loading a file but NOT instantiating an object |
|
822 | + if (! $loaded || $load_only) { |
|
823 | + // return boolean if only loading, or null if an object was expected |
|
824 | + return $load_only |
|
825 | + ? $loaded |
|
826 | + : null; |
|
827 | + } |
|
828 | + } |
|
829 | + // instantiate the requested object |
|
830 | + $class_obj = $this->_create_object($class_name, $arguments, $type, $from_db); |
|
831 | + if ($this->_cache_on && $cache) { |
|
832 | + // save it for later... kinda like gum { : $ |
|
833 | + $this->_set_cached_class($class_obj, $class_name, $class_prefix, $from_db); |
|
834 | + } |
|
835 | + $this->_cache_on = true; |
|
836 | + return $class_obj; |
|
837 | + } |
|
838 | + |
|
839 | + |
|
840 | + |
|
841 | + /** |
|
842 | + * @param string $class_name |
|
843 | + * @param string $default have to specify something, but not anything that will conflict |
|
844 | + * @return mixed|string |
|
845 | + */ |
|
846 | + protected function get_class_abbreviation($class_name, $default = 'FANCY_BATMAN_PANTS') |
|
847 | + { |
|
848 | + return isset($this->_class_abbreviations[$class_name]) |
|
849 | + ? $this->_class_abbreviations[$class_name] |
|
850 | + : $default; |
|
851 | + } |
|
852 | + |
|
853 | + /** |
|
854 | + * attempts to find a cached version of the requested class |
|
855 | + * by looking in the following places: |
|
856 | + * $this->{$class_abbreviation} ie: $this->CART |
|
857 | + * $this->{$class_name} ie: $this->Some_Class |
|
858 | + * $this->LIB->{$class_name} ie: $this->LIB->Some_Class |
|
859 | + * $this->addon->{$class_name} ie: $this->addon->Some_Addon_Class |
|
860 | + * |
|
861 | + * @param string $class_name |
|
862 | + * @param string $class_prefix |
|
863 | + * @return mixed |
|
864 | + */ |
|
865 | + protected function _get_cached_class($class_name, $class_prefix = '') |
|
866 | + { |
|
867 | + if ($class_name === 'EE_Registry') { |
|
868 | + return $this; |
|
869 | + } |
|
870 | + $class_abbreviation = $this->get_class_abbreviation($class_name); |
|
871 | + $class_name = str_replace('\\', '_', $class_name); |
|
872 | + // check if class has already been loaded, and return it if it has been |
|
873 | + if (isset($this->{$class_abbreviation})) { |
|
874 | + return $this->{$class_abbreviation}; |
|
875 | + } |
|
876 | + if (isset ($this->{$class_name})) { |
|
877 | + return $this->{$class_name}; |
|
878 | + } |
|
879 | + if (isset ($this->LIB->{$class_name})) { |
|
880 | + return $this->LIB->{$class_name}; |
|
881 | + } |
|
882 | + if ($class_prefix === 'addon' && isset ($this->addons->{$class_name})) { |
|
883 | + return $this->addons->{$class_name}; |
|
884 | + } |
|
885 | + return null; |
|
886 | + } |
|
887 | + |
|
888 | + |
|
889 | + |
|
890 | + /** |
|
891 | + * removes a cached version of the requested class |
|
892 | + * |
|
893 | + * @param string $class_name |
|
894 | + * @param boolean $addon |
|
895 | + * @return boolean |
|
896 | + */ |
|
897 | + public function clear_cached_class($class_name, $addon = false) |
|
898 | + { |
|
899 | + $class_abbreviation = $this->get_class_abbreviation($class_name); |
|
900 | + $class_name = str_replace('\\', '_', $class_name); |
|
901 | + // check if class has already been loaded, and return it if it has been |
|
902 | + if (isset($this->{$class_abbreviation})) { |
|
903 | + $this->{$class_abbreviation} = null; |
|
904 | + return true; |
|
905 | + } |
|
906 | + if (isset($this->{$class_name})) { |
|
907 | + $this->{$class_name} = null; |
|
908 | + return true; |
|
909 | + } |
|
910 | + if (isset($this->LIB->{$class_name})) { |
|
911 | + unset($this->LIB->{$class_name}); |
|
912 | + return true; |
|
913 | + } |
|
914 | + if ($addon && isset($this->addons->{$class_name})) { |
|
915 | + unset($this->addons->{$class_name}); |
|
916 | + return true; |
|
917 | + } |
|
918 | + return false; |
|
919 | + } |
|
920 | + |
|
921 | + |
|
922 | + |
|
923 | + /** |
|
924 | + * attempts to find a full valid filepath for the requested class. |
|
925 | + * loops thru each of the base paths in the $file_paths array and appends : "{classname} . {file type} . php" |
|
926 | + * then returns that path if the target file has been found and is readable |
|
927 | + * |
|
928 | + * @param string $class_name |
|
929 | + * @param string $type |
|
930 | + * @param array $file_paths |
|
931 | + * @return string | bool |
|
932 | + */ |
|
933 | + protected function _resolve_path($class_name, $type = '', $file_paths = array()) |
|
934 | + { |
|
935 | + // make sure $file_paths is an array |
|
936 | + $file_paths = is_array($file_paths) |
|
937 | + ? $file_paths |
|
938 | + : array($file_paths); |
|
939 | + // cycle thru paths |
|
940 | + foreach ($file_paths as $key => $file_path) { |
|
941 | + // convert all separators to proper DS, if no filepath, then use EE_CLASSES |
|
942 | + $file_path = $file_path |
|
943 | + ? str_replace(array('/', '\\'), DS, $file_path) |
|
944 | + : EE_CLASSES; |
|
945 | + // prep file type |
|
946 | + $type = ! empty($type) |
|
947 | + ? trim($type, '.') . '.' |
|
948 | + : ''; |
|
949 | + // build full file path |
|
950 | + $file_paths[$key] = rtrim($file_path, DS) . DS . $class_name . '.' . $type . 'php'; |
|
951 | + //does the file exist and can be read ? |
|
952 | + if (is_readable($file_paths[$key])) { |
|
953 | + return $file_paths[$key]; |
|
954 | + } |
|
955 | + } |
|
956 | + return false; |
|
957 | + } |
|
958 | + |
|
959 | + |
|
960 | + |
|
961 | + /** |
|
962 | + * basically just performs a require_once() |
|
963 | + * but with some error handling |
|
964 | + * |
|
965 | + * @param string $path |
|
966 | + * @param string $class_name |
|
967 | + * @param string $type |
|
968 | + * @param array $file_paths |
|
969 | + * @return bool |
|
970 | + * @throws EE_Error |
|
971 | + * @throws ReflectionException |
|
972 | + */ |
|
973 | + protected function _require_file($path, $class_name, $type = '', $file_paths = array()) |
|
974 | + { |
|
975 | + $this->resolve_legacy_class_parent($class_name); |
|
976 | + // don't give up! you gotta... |
|
977 | + try { |
|
978 | + //does the file exist and can it be read ? |
|
979 | + if (! $path) { |
|
980 | + // just in case the file has already been autoloaded, |
|
981 | + // but discrepancies in the naming schema are preventing it from |
|
982 | + // being loaded via one of the EE_Registry::load_*() methods, |
|
983 | + // then let's try one last hail mary before throwing an exception |
|
984 | + // and call class_exists() again, but with autoloading turned ON |
|
985 | + if(class_exists($class_name)) { |
|
986 | + return true; |
|
987 | + } |
|
988 | + // so sorry, can't find the file |
|
989 | + throw new EE_Error ( |
|
990 | + sprintf( |
|
991 | + esc_html__( |
|
992 | + 'The %1$s file %2$s could not be located or is not readable due to file permissions. Please ensure that the following filepath(s) are correct: %3$s', |
|
993 | + 'event_espresso' |
|
994 | + ), |
|
995 | + trim($type, '.'), |
|
996 | + $class_name, |
|
997 | + '<br />' . implode(',<br />', $file_paths) |
|
998 | + ) |
|
999 | + ); |
|
1000 | + } |
|
1001 | + // get the file |
|
1002 | + require_once($path); |
|
1003 | + // if the class isn't already declared somewhere |
|
1004 | + if (class_exists($class_name, false) === false) { |
|
1005 | + // so sorry, not a class |
|
1006 | + throw new EE_Error( |
|
1007 | + sprintf( |
|
1008 | + esc_html__('The %s file %s does not appear to contain the %s Class.', 'event_espresso'), |
|
1009 | + $type, |
|
1010 | + $path, |
|
1011 | + $class_name |
|
1012 | + ) |
|
1013 | + ); |
|
1014 | + } |
|
1015 | + } catch (EE_Error $e) { |
|
1016 | + $e->get_error(); |
|
1017 | + return false; |
|
1018 | + } |
|
1019 | + return true; |
|
1020 | + } |
|
1021 | + |
|
1022 | + |
|
1023 | + |
|
1024 | + /** |
|
1025 | + * Some of our legacy classes that extended a parent class would simply use a require() statement |
|
1026 | + * before their class declaration in order to ensure that the parent class was loaded. |
|
1027 | + * This is not ideal, but it's nearly impossible to determine the parent class of a non-namespaced class, |
|
1028 | + * without triggering a fatal error because the parent class has yet to be loaded and therefore doesn't exist. |
|
1029 | + * |
|
1030 | + * @param string $class_name |
|
1031 | + */ |
|
1032 | + protected function resolve_legacy_class_parent($class_name = '') |
|
1033 | + { |
|
1034 | + try { |
|
1035 | + $legacy_parent_class_map = array( |
|
1036 | + 'EE_Payment_Processor' => 'core/business/EE_Processor_Base.class.php' |
|
1037 | + ); |
|
1038 | + if(isset($legacy_parent_class_map[$class_name])) { |
|
1039 | + require_once EE_PLUGIN_DIR_PATH . $legacy_parent_class_map[$class_name]; |
|
1040 | + } |
|
1041 | + } catch (Exception $exception) { |
|
1042 | + } |
|
1043 | + } |
|
1044 | + |
|
1045 | + |
|
1046 | + |
|
1047 | + /** |
|
1048 | + * _create_object |
|
1049 | + * Attempts to instantiate the requested class via any of the |
|
1050 | + * commonly used instantiation methods employed throughout EE. |
|
1051 | + * The priority for instantiation is as follows: |
|
1052 | + * - abstract classes or any class flagged as "load only" (no instantiation occurs) |
|
1053 | + * - model objects via their 'new_instance_from_db' method |
|
1054 | + * - model objects via their 'new_instance' method |
|
1055 | + * - "singleton" classes" via their 'instance' method |
|
1056 | + * - standard instantiable classes via their __constructor |
|
1057 | + * Prior to instantiation, if the classname exists in the dependency_map, |
|
1058 | + * then the constructor for the requested class will be examined to determine |
|
1059 | + * if any dependencies exist, and if they can be injected. |
|
1060 | + * If so, then those classes will be added to the array of arguments passed to the constructor |
|
1061 | + * |
|
1062 | + * @param string $class_name |
|
1063 | + * @param array $arguments |
|
1064 | + * @param string $type |
|
1065 | + * @param bool $from_db |
|
1066 | + * @return null|object |
|
1067 | + * @throws EE_Error |
|
1068 | + * @throws ReflectionException |
|
1069 | + */ |
|
1070 | + protected function _create_object($class_name, $arguments = array(), $type = '', $from_db = false) |
|
1071 | + { |
|
1072 | + // create reflection |
|
1073 | + $reflector = $this->get_ReflectionClass($class_name); |
|
1074 | + // make sure arguments are an array |
|
1075 | + $arguments = is_array($arguments) |
|
1076 | + ? $arguments |
|
1077 | + : array($arguments); |
|
1078 | + // and if arguments array is numerically and sequentially indexed, then we want it to remain as is, |
|
1079 | + // else wrap it in an additional array so that it doesn't get split into multiple parameters |
|
1080 | + $arguments = $this->_array_is_numerically_and_sequentially_indexed($arguments) |
|
1081 | + ? $arguments |
|
1082 | + : array($arguments); |
|
1083 | + // attempt to inject dependencies ? |
|
1084 | + if ($this->_dependency_map->has($class_name)) { |
|
1085 | + $arguments = $this->_resolve_dependencies($reflector, $class_name, $arguments); |
|
1086 | + } |
|
1087 | + // instantiate the class if possible |
|
1088 | + if ($reflector->isAbstract()) { |
|
1089 | + // nothing to instantiate, loading file was enough |
|
1090 | + // does not throw an exception so $instantiation_mode is unused |
|
1091 | + // $instantiation_mode = "1) no constructor abstract class"; |
|
1092 | + return true; |
|
1093 | + } |
|
1094 | + if (empty($arguments) && $reflector->getConstructor() === null && $reflector->isInstantiable()) { |
|
1095 | + // no constructor = static methods only... nothing to instantiate, loading file was enough |
|
1096 | + // $instantiation_mode = "2) no constructor but instantiable"; |
|
1097 | + return $reflector->newInstance(); |
|
1098 | + } |
|
1099 | + if ($from_db && method_exists($class_name, 'new_instance_from_db')) { |
|
1100 | + // $instantiation_mode = "3) new_instance_from_db()"; |
|
1101 | + return call_user_func_array(array($class_name, 'new_instance_from_db'), $arguments); |
|
1102 | + } |
|
1103 | + if (method_exists($class_name, 'new_instance')) { |
|
1104 | + // $instantiation_mode = "4) new_instance()"; |
|
1105 | + return call_user_func_array(array($class_name, 'new_instance'), $arguments); |
|
1106 | + } |
|
1107 | + if (method_exists($class_name, 'instance')) { |
|
1108 | + // $instantiation_mode = "5) instance()"; |
|
1109 | + return call_user_func_array(array($class_name, 'instance'), $arguments); |
|
1110 | + } |
|
1111 | + if ($reflector->isInstantiable()) { |
|
1112 | + // $instantiation_mode = "6) constructor"; |
|
1113 | + return $reflector->newInstanceArgs($arguments); |
|
1114 | + } |
|
1115 | + // heh ? something's not right ! |
|
1116 | + throw new EE_Error( |
|
1117 | + sprintf( |
|
1118 | + __('The %s file %s could not be instantiated.', 'event_espresso'), |
|
1119 | + $type, |
|
1120 | + $class_name |
|
1121 | + ) |
|
1122 | + ); |
|
1123 | + } |
|
1124 | + |
|
1125 | + |
|
1126 | + |
|
1127 | + /** |
|
1128 | + * @see http://stackoverflow.com/questions/173400/how-to-check-if-php-array-is-associative-or-sequential |
|
1129 | + * @param array $array |
|
1130 | + * @return bool |
|
1131 | + */ |
|
1132 | + protected function _array_is_numerically_and_sequentially_indexed(array $array) |
|
1133 | + { |
|
1134 | + return ! empty($array) |
|
1135 | + ? array_keys($array) === range(0, count($array) - 1) |
|
1136 | + : true; |
|
1137 | + } |
|
1138 | + |
|
1139 | + |
|
1140 | + |
|
1141 | + /** |
|
1142 | + * getReflectionClass |
|
1143 | + * checks if a ReflectionClass object has already been generated for a class |
|
1144 | + * and returns that instead of creating a new one |
|
1145 | + * |
|
1146 | + * @param string $class_name |
|
1147 | + * @return ReflectionClass |
|
1148 | + * @throws ReflectionException |
|
1149 | + */ |
|
1150 | + public function get_ReflectionClass($class_name) |
|
1151 | + { |
|
1152 | + if ( |
|
1153 | + ! isset($this->_reflectors[$class_name]) |
|
1154 | + || ! $this->_reflectors[$class_name] instanceof ReflectionClass |
|
1155 | + ) { |
|
1156 | + $this->_reflectors[$class_name] = new ReflectionClass($class_name); |
|
1157 | + } |
|
1158 | + return $this->_reflectors[$class_name]; |
|
1159 | + } |
|
1160 | + |
|
1161 | + |
|
1162 | + |
|
1163 | + /** |
|
1164 | + * _resolve_dependencies |
|
1165 | + * examines the constructor for the requested class to determine |
|
1166 | + * if any dependencies exist, and if they can be injected. |
|
1167 | + * If so, then those classes will be added to the array of arguments passed to the constructor |
|
1168 | + * PLZ NOTE: this is achieved by type hinting the constructor params |
|
1169 | + * For example: |
|
1170 | + * if attempting to load a class "Foo" with the following constructor: |
|
1171 | + * __construct( Bar $bar_class, Fighter $grohl_class ) |
|
1172 | + * then $bar_class and $grohl_class will be added to the $arguments array, |
|
1173 | + * but only IF they are NOT already present in the incoming arguments array, |
|
1174 | + * and the correct classes can be loaded |
|
1175 | + * |
|
1176 | + * @param ReflectionClass $reflector |
|
1177 | + * @param string $class_name |
|
1178 | + * @param array $arguments |
|
1179 | + * @return array |
|
1180 | + * @throws EE_Error |
|
1181 | + * @throws ReflectionException |
|
1182 | + */ |
|
1183 | + protected function _resolve_dependencies(ReflectionClass $reflector, $class_name, $arguments = array()) |
|
1184 | + { |
|
1185 | + // let's examine the constructor |
|
1186 | + $constructor = $reflector->getConstructor(); |
|
1187 | + // whu? huh? nothing? |
|
1188 | + if (! $constructor) { |
|
1189 | + return $arguments; |
|
1190 | + } |
|
1191 | + // get constructor parameters |
|
1192 | + $params = $constructor->getParameters(); |
|
1193 | + // and the keys for the incoming arguments array so that we can compare existing arguments with what is expected |
|
1194 | + $argument_keys = array_keys($arguments); |
|
1195 | + // now loop thru all of the constructors expected parameters |
|
1196 | + foreach ($params as $index => $param) { |
|
1197 | + // is this a dependency for a specific class ? |
|
1198 | + $param_class = $param->getClass() |
|
1199 | + ? $param->getClass()->name |
|
1200 | + : null; |
|
1201 | + // BUT WAIT !!! This class may be an alias for something else (or getting replaced at runtime) |
|
1202 | + $param_class = $this->_dependency_map->has_alias($param_class, $class_name) |
|
1203 | + ? $this->_dependency_map->get_alias($param_class, $class_name) |
|
1204 | + : $param_class; |
|
1205 | + if ( |
|
1206 | + // param is not even a class |
|
1207 | + $param_class === null |
|
1208 | + // and something already exists in the incoming arguments for this param |
|
1209 | + && array_key_exists($index, $argument_keys) |
|
1210 | + && array_key_exists($argument_keys[$index], $arguments) |
|
1211 | + ) { |
|
1212 | + // so let's skip this argument and move on to the next |
|
1213 | + continue; |
|
1214 | + } |
|
1215 | + if ( |
|
1216 | + // parameter is type hinted as a class, exists as an incoming argument, AND it's the correct class |
|
1217 | + $param_class !== null |
|
1218 | + && isset($argument_keys[$index], $arguments[$argument_keys[$index]]) |
|
1219 | + && $arguments[$argument_keys[$index]] instanceof $param_class |
|
1220 | + ) { |
|
1221 | + // skip this argument and move on to the next |
|
1222 | + continue; |
|
1223 | + } |
|
1224 | + if ( |
|
1225 | + // parameter is type hinted as a class, and should be injected |
|
1226 | + $param_class !== null |
|
1227 | + && $this->_dependency_map->has_dependency_for_class($class_name, $param_class) |
|
1228 | + ) { |
|
1229 | + $arguments = $this->_resolve_dependency( |
|
1230 | + $class_name, |
|
1231 | + $param_class, |
|
1232 | + $arguments, |
|
1233 | + $index, |
|
1234 | + $argument_keys |
|
1235 | + ); |
|
1236 | + } else { |
|
1237 | + try { |
|
1238 | + $arguments[$index] = $param->isDefaultValueAvailable() |
|
1239 | + ? $param->getDefaultValue() |
|
1240 | + : null; |
|
1241 | + } catch (ReflectionException $e) { |
|
1242 | + throw new ReflectionException( |
|
1243 | + sprintf( |
|
1244 | + esc_html__('%1$s for parameter "$%2$s on classname "%3$s"', 'event_espresso'), |
|
1245 | + $e->getMessage(), |
|
1246 | + $param->getName(), |
|
1247 | + $class_name |
|
1248 | + ) |
|
1249 | + ); |
|
1250 | + } |
|
1251 | + } |
|
1252 | + } |
|
1253 | + return $arguments; |
|
1254 | + } |
|
1255 | + |
|
1256 | + |
|
1257 | + |
|
1258 | + /** |
|
1259 | + * @param string $class_name |
|
1260 | + * @param string $param_class |
|
1261 | + * @param array $arguments |
|
1262 | + * @param mixed $index |
|
1263 | + * @param array $argument_keys |
|
1264 | + * @return array |
|
1265 | + * @throws EE_Error |
|
1266 | + * @throws ReflectionException |
|
1267 | + * @throws InvalidArgumentException |
|
1268 | + * @throws InvalidInterfaceException |
|
1269 | + * @throws InvalidDataTypeException |
|
1270 | + */ |
|
1271 | + protected function _resolve_dependency($class_name, $param_class, $arguments, $index, array $argument_keys) |
|
1272 | + { |
|
1273 | + $dependency = null; |
|
1274 | + // should dependency be loaded from cache ? |
|
1275 | + $cache_on = $this->_dependency_map->loading_strategy_for_class_dependency( |
|
1276 | + $class_name, |
|
1277 | + $param_class |
|
1278 | + ); |
|
1279 | + $cache_on = $cache_on !== EE_Dependency_Map::load_new_object; |
|
1280 | + // we might have a dependency... |
|
1281 | + // let's MAYBE try and find it in our cache if that's what's been requested |
|
1282 | + $cached_class = $cache_on |
|
1283 | + ? $this->_get_cached_class($param_class) |
|
1284 | + : null; |
|
1285 | + // and grab it if it exists |
|
1286 | + if ($cached_class instanceof $param_class) { |
|
1287 | + $dependency = $cached_class; |
|
1288 | + } else if ($param_class !== $class_name) { |
|
1289 | + // obtain the loader method from the dependency map |
|
1290 | + $loader = $this->_dependency_map->class_loader($param_class); |
|
1291 | + // is loader a custom closure ? |
|
1292 | + if ($loader instanceof Closure) { |
|
1293 | + $dependency = $loader($arguments); |
|
1294 | + } else { |
|
1295 | + // set the cache on property for the recursive loading call |
|
1296 | + $this->_cache_on = $cache_on; |
|
1297 | + // if not, then let's try and load it via the registry |
|
1298 | + if ($loader && method_exists($this, $loader)) { |
|
1299 | + $dependency = $this->{$loader}($param_class); |
|
1300 | + } else { |
|
1301 | + $dependency = LoaderFactory::getLoader()->load( |
|
1302 | + $param_class, |
|
1303 | + array(), |
|
1304 | + $cache_on |
|
1305 | + ); |
|
1306 | + } |
|
1307 | + } |
|
1308 | + } |
|
1309 | + // did we successfully find the correct dependency ? |
|
1310 | + if ($dependency instanceof $param_class) { |
|
1311 | + // then let's inject it into the incoming array of arguments at the correct location |
|
1312 | + $arguments[$index] = $dependency; |
|
1313 | + } |
|
1314 | + return $arguments; |
|
1315 | + } |
|
1316 | + |
|
1317 | + |
|
1318 | + |
|
1319 | + /** |
|
1320 | + * _set_cached_class |
|
1321 | + * attempts to cache the instantiated class locally |
|
1322 | + * in one of the following places, in the following order: |
|
1323 | + * $this->{class_abbreviation} ie: $this->CART |
|
1324 | + * $this->{$class_name} ie: $this->Some_Class |
|
1325 | + * $this->addon->{$$class_name} ie: $this->addon->Some_Addon_Class |
|
1326 | + * $this->LIB->{$class_name} ie: $this->LIB->Some_Class |
|
1327 | + * |
|
1328 | + * @param object $class_obj |
|
1329 | + * @param string $class_name |
|
1330 | + * @param string $class_prefix |
|
1331 | + * @param bool $from_db |
|
1332 | + * @return void |
|
1333 | + */ |
|
1334 | + protected function _set_cached_class($class_obj, $class_name, $class_prefix = '', $from_db = false) |
|
1335 | + { |
|
1336 | + if ($class_name === 'EE_Registry' || empty($class_obj)) { |
|
1337 | + return; |
|
1338 | + } |
|
1339 | + // return newly instantiated class |
|
1340 | + $class_abbreviation = $this->get_class_abbreviation($class_name, ''); |
|
1341 | + if ($class_abbreviation) { |
|
1342 | + $this->{$class_abbreviation} = $class_obj; |
|
1343 | + return; |
|
1344 | + } |
|
1345 | + $class_name = str_replace('\\', '_', $class_name); |
|
1346 | + if (property_exists($this, $class_name)) { |
|
1347 | + $this->{$class_name} = $class_obj; |
|
1348 | + return; |
|
1349 | + } |
|
1350 | + if ($class_prefix === 'addon') { |
|
1351 | + $this->addons->{$class_name} = $class_obj; |
|
1352 | + return; |
|
1353 | + } |
|
1354 | + if (! $from_db) { |
|
1355 | + $this->LIB->{$class_name} = $class_obj; |
|
1356 | + } |
|
1357 | + } |
|
1358 | + |
|
1359 | + |
|
1360 | + |
|
1361 | + /** |
|
1362 | + * call any loader that's been registered in the EE_Dependency_Map::$_class_loaders array |
|
1363 | + * |
|
1364 | + * @param string $classname PLEASE NOTE: the class name needs to match what's registered |
|
1365 | + * in the EE_Dependency_Map::$_class_loaders array, |
|
1366 | + * including the class prefix, ie: "EE_", "EEM_", "EEH_", etc |
|
1367 | + * @param array $arguments |
|
1368 | + * @return object |
|
1369 | + */ |
|
1370 | + public static function factory($classname, $arguments = array()) |
|
1371 | + { |
|
1372 | + $loader = self::instance()->_dependency_map->class_loader($classname); |
|
1373 | + if ($loader instanceof Closure) { |
|
1374 | + return $loader($arguments); |
|
1375 | + } |
|
1376 | + if (method_exists(self::instance(), $loader)) { |
|
1377 | + return self::instance()->{$loader}($classname, $arguments); |
|
1378 | + } |
|
1379 | + return null; |
|
1380 | + } |
|
1381 | + |
|
1382 | + |
|
1383 | + |
|
1384 | + /** |
|
1385 | + * Gets the addon by its class name |
|
1386 | + * |
|
1387 | + * @param string $class_name |
|
1388 | + * @return EE_Addon |
|
1389 | + */ |
|
1390 | + public function getAddon($class_name) |
|
1391 | + { |
|
1392 | + $class_name = str_replace('\\', '_', $class_name); |
|
1393 | + return $this->addons->{$class_name}; |
|
1394 | + } |
|
1395 | + |
|
1396 | + |
|
1397 | + /** |
|
1398 | + * removes the addon from the internal cache |
|
1399 | + * |
|
1400 | + * @param string $class_name |
|
1401 | + * @return void |
|
1402 | + */ |
|
1403 | + public function removeAddon($class_name) |
|
1404 | + { |
|
1405 | + $class_name = str_replace('\\', '_', $class_name); |
|
1406 | + unset($this->addons->{$class_name}); |
|
1407 | + } |
|
1408 | + |
|
1409 | + |
|
1410 | + |
|
1411 | + /** |
|
1412 | + * Gets the addon by its name/slug (not classname. For that, just |
|
1413 | + * use the get_addon() method above |
|
1414 | + * |
|
1415 | + * @param string $name |
|
1416 | + * @return EE_Addon |
|
1417 | + */ |
|
1418 | + public function get_addon_by_name($name) |
|
1419 | + { |
|
1420 | + foreach ($this->addons as $addon) { |
|
1421 | + if ($addon->name() === $name) { |
|
1422 | + return $addon; |
|
1423 | + } |
|
1424 | + } |
|
1425 | + return null; |
|
1426 | + } |
|
1427 | + |
|
1428 | + |
|
1429 | + |
|
1430 | + /** |
|
1431 | + * Gets an array of all the registered addons, where the keys are their names. |
|
1432 | + * (ie, what each returns for their name() function) |
|
1433 | + * They're already available on EE_Registry::instance()->addons as properties, |
|
1434 | + * where each property's name is the addon's classname, |
|
1435 | + * So if you just want to get the addon by classname, |
|
1436 | + * OR use the get_addon() method above. |
|
1437 | + * PLEASE NOTE: |
|
1438 | + * addons with Fully Qualified Class Names |
|
1439 | + * have had the namespace separators converted to underscores, |
|
1440 | + * so a classname like Fully\Qualified\ClassName |
|
1441 | + * would have been converted to Fully_Qualified_ClassName |
|
1442 | + * |
|
1443 | + * @return EE_Addon[] where the KEYS are the addon's name() |
|
1444 | + */ |
|
1445 | + public function get_addons_by_name() |
|
1446 | + { |
|
1447 | + $addons = array(); |
|
1448 | + foreach ($this->addons as $addon) { |
|
1449 | + $addons[$addon->name()] = $addon; |
|
1450 | + } |
|
1451 | + return $addons; |
|
1452 | + } |
|
1453 | + |
|
1454 | + |
|
1455 | + /** |
|
1456 | + * Resets the specified model's instance AND makes sure EE_Registry doesn't keep |
|
1457 | + * a stale copy of it around |
|
1458 | + * |
|
1459 | + * @param string $model_name |
|
1460 | + * @return \EEM_Base |
|
1461 | + * @throws \EE_Error |
|
1462 | + */ |
|
1463 | + public function reset_model($model_name) |
|
1464 | + { |
|
1465 | + $model_class_name = strpos($model_name, 'EEM_') !== 0 |
|
1466 | + ? "EEM_{$model_name}" |
|
1467 | + : $model_name; |
|
1468 | + if (! isset($this->LIB->{$model_class_name}) || ! $this->LIB->{$model_class_name} instanceof EEM_Base) { |
|
1469 | + return null; |
|
1470 | + } |
|
1471 | + //get that model reset it and make sure we nuke the old reference to it |
|
1472 | + if ($this->LIB->{$model_class_name} instanceof $model_class_name |
|
1473 | + && is_callable( |
|
1474 | + array($model_class_name, 'reset') |
|
1475 | + )) { |
|
1476 | + $this->LIB->{$model_class_name} = $this->LIB->{$model_class_name}->reset(); |
|
1477 | + } else { |
|
1478 | + throw new EE_Error(sprintf(esc_html__('Model %s does not have a method "reset"', 'event_espresso'), $model_name)); |
|
1479 | + } |
|
1480 | + return $this->LIB->{$model_class_name}; |
|
1481 | + } |
|
1482 | + |
|
1483 | + |
|
1484 | + |
|
1485 | + /** |
|
1486 | + * Resets the registry. |
|
1487 | + * The criteria for what gets reset is based on what can be shared between sites on the same request when |
|
1488 | + * switch_to_blog is used in a multisite install. Here is a list of things that are NOT reset. |
|
1489 | + * - $_dependency_map |
|
1490 | + * - $_class_abbreviations |
|
1491 | + * - $NET_CFG (EE_Network_Config): The config is shared network wide so no need to reset. |
|
1492 | + * - $REQ: Still on the same request so no need to change. |
|
1493 | + * - $CAP: There is no site specific state in the EE_Capability class. |
|
1494 | + * - $SSN: Although ideally, the session should not be shared between site switches, we can't reset it because only |
|
1495 | + * one Session can be active in a single request. Resetting could resolve in "headers already sent" errors. |
|
1496 | + * - $addons: In multisite, the state of the addons is something controlled via hooks etc in a normal request. So |
|
1497 | + * for now, we won't reset the addons because it could break calls to an add-ons class/methods in the |
|
1498 | + * switch or on the restore. |
|
1499 | + * - $modules |
|
1500 | + * - $shortcodes |
|
1501 | + * - $widgets |
|
1502 | + * |
|
1503 | + * @param boolean $hard [deprecated] |
|
1504 | + * @param boolean $reinstantiate whether to create new instances of EE_Registry's singletons too, |
|
1505 | + * or just reset without re-instantiating (handy to set to FALSE if you're not |
|
1506 | + * sure if you CAN currently reinstantiate the singletons at the moment) |
|
1507 | + * @param bool $reset_models Defaults to true. When false, then the models are not reset. This is so |
|
1508 | + * client |
|
1509 | + * code instead can just change the model context to a different blog id if |
|
1510 | + * necessary |
|
1511 | + * @return EE_Registry |
|
1512 | + * @throws EE_Error |
|
1513 | + * @throws ReflectionException |
|
1514 | + */ |
|
1515 | + public static function reset($hard = false, $reinstantiate = true, $reset_models = true) |
|
1516 | + { |
|
1517 | + $instance = self::instance(); |
|
1518 | + $instance->_cache_on = true; |
|
1519 | + // reset some "special" classes |
|
1520 | + EEH_Activation::reset(); |
|
1521 | + $hard = apply_filters( 'FHEE__EE_Registry__reset__hard', $hard); |
|
1522 | + $instance->CFG = EE_Config::reset($hard, $reinstantiate); |
|
1523 | + $instance->CART = null; |
|
1524 | + $instance->MRM = null; |
|
1525 | + $instance->AssetsRegistry = $instance->create('EventEspresso\core\services\assets\Registry'); |
|
1526 | + //messages reset |
|
1527 | + EED_Messages::reset(); |
|
1528 | + //handle of objects cached on LIB |
|
1529 | + foreach (array('LIB', 'modules') as $cache) { |
|
1530 | + foreach ($instance->{$cache} as $class_name => $class) { |
|
1531 | + if (self::_reset_and_unset_object($class, $reset_models)) { |
|
1532 | + unset($instance->{$cache}->{$class_name}); |
|
1533 | + } |
|
1534 | + } |
|
1535 | + } |
|
1536 | + return $instance; |
|
1537 | + } |
|
1538 | + |
|
1539 | + |
|
1540 | + |
|
1541 | + /** |
|
1542 | + * if passed object implements ResettableInterface, then call it's reset() method |
|
1543 | + * if passed object implements InterminableInterface, then return false, |
|
1544 | + * to indicate that it should NOT be cleared from the Registry cache |
|
1545 | + * |
|
1546 | + * @param $object |
|
1547 | + * @param bool $reset_models |
|
1548 | + * @return bool returns true if cached object should be unset |
|
1549 | + */ |
|
1550 | + private static function _reset_and_unset_object($object, $reset_models) |
|
1551 | + { |
|
1552 | + if (! is_object($object)) { |
|
1553 | + // don't unset anything that's not an object |
|
1554 | + return false; |
|
1555 | + } |
|
1556 | + if ($object instanceof EED_Module) { |
|
1557 | + $object::reset(); |
|
1558 | + // don't unset modules |
|
1559 | + return false; |
|
1560 | + } |
|
1561 | + if ($object instanceof ResettableInterface) { |
|
1562 | + if ($object instanceof EEM_Base) { |
|
1563 | + if ($reset_models) { |
|
1564 | + $object->reset(); |
|
1565 | + return true; |
|
1566 | + } |
|
1567 | + return false; |
|
1568 | + } |
|
1569 | + $object->reset(); |
|
1570 | + return true; |
|
1571 | + } |
|
1572 | + if (! $object instanceof InterminableInterface) { |
|
1573 | + return true; |
|
1574 | + } |
|
1575 | + return false; |
|
1576 | + } |
|
1577 | + |
|
1578 | + |
|
1579 | + |
|
1580 | + /** |
|
1581 | + * Gets all the custom post type models defined |
|
1582 | + * |
|
1583 | + * @return array keys are model "short names" (Eg "Event") and keys are classnames (eg "EEM_Event") |
|
1584 | + */ |
|
1585 | + public function cpt_models() |
|
1586 | + { |
|
1587 | + $cpt_models = array(); |
|
1588 | + foreach ($this->non_abstract_db_models as $short_name => $classname) { |
|
1589 | + if (is_subclass_of($classname, 'EEM_CPT_Base')) { |
|
1590 | + $cpt_models[$short_name] = $classname; |
|
1591 | + } |
|
1592 | + } |
|
1593 | + return $cpt_models; |
|
1594 | + } |
|
1595 | + |
|
1596 | + |
|
1597 | + |
|
1598 | + /** |
|
1599 | + * @return \EE_Config |
|
1600 | + */ |
|
1601 | + public static function CFG() |
|
1602 | + { |
|
1603 | + return self::instance()->CFG; |
|
1604 | + } |
|
1605 | 1605 | |
1606 | 1606 | |
1607 | 1607 | } |
@@ -132,7 +132,7 @@ discard block |
||
132 | 132 | EE_Maintenance_Mode $maintenance_mode = null |
133 | 133 | ) { |
134 | 134 | // check if class object is instantiated |
135 | - if (! self::$_instance instanceof EE_System) { |
|
135 | + if ( ! self::$_instance instanceof EE_System) { |
|
136 | 136 | self::$_instance = new self($registry, $loader, $capabilities, $request, $maintenance_mode); |
137 | 137 | } |
138 | 138 | return self::$_instance; |
@@ -298,7 +298,7 @@ discard block |
||
298 | 298 | { |
299 | 299 | // set autoloaders for all of the classes implementing EEI_Plugin_API |
300 | 300 | // which provide helpers for EE plugin authors to more easily register certain components with EE. |
301 | - EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'plugin_api'); |
|
301 | + EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_LIBRARIES.'plugin_api'); |
|
302 | 302 | } |
303 | 303 | |
304 | 304 | |
@@ -317,14 +317,14 @@ discard block |
||
317 | 317 | $load_callback, |
318 | 318 | $plugin_file_constant |
319 | 319 | ) { |
320 | - if (! defined($version_constant)) { |
|
320 | + if ( ! defined($version_constant)) { |
|
321 | 321 | return; |
322 | 322 | } |
323 | 323 | $addon_version = constant($version_constant); |
324 | 324 | if ($addon_version && version_compare($addon_version, $min_version_required, '<')) { |
325 | 325 | remove_action('AHEE__EE_System__load_espresso_addons', $load_callback); |
326 | - if (! function_exists('deactivate_plugins')) { |
|
327 | - require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
326 | + if ( ! function_exists('deactivate_plugins')) { |
|
327 | + require_once ABSPATH.'wp-admin/includes/plugin.php'; |
|
328 | 328 | } |
329 | 329 | deactivate_plugins(plugin_basename(constant($plugin_file_constant))); |
330 | 330 | unset($_GET['activate'], $_REQUEST['activate'], $_GET['activate-multi'], $_REQUEST['activate-multi']); |
@@ -337,7 +337,7 @@ discard block |
||
337 | 337 | $addon_name, |
338 | 338 | $min_version_required |
339 | 339 | ), |
340 | - __FILE__, __FUNCTION__ . "({$addon_name})", __LINE__ |
|
340 | + __FILE__, __FUNCTION__."({$addon_name})", __LINE__ |
|
341 | 341 | ); |
342 | 342 | EE_Error::get_notices(false, true); |
343 | 343 | } |
@@ -389,7 +389,7 @@ discard block |
||
389 | 389 | && in_array($_GET['action'], array('activate', 'activate-selected'), true) |
390 | 390 | ) |
391 | 391 | ) { |
392 | - include_once EE_THIRD_PARTY . 'wp-api-basic-auth' . DS . 'basic-auth.php'; |
|
392 | + include_once EE_THIRD_PARTY.'wp-api-basic-auth'.DS.'basic-auth.php'; |
|
393 | 393 | } |
394 | 394 | do_action('AHEE__EE_System__load_espresso_addons__complete'); |
395 | 395 | } |
@@ -497,11 +497,11 @@ discard block |
||
497 | 497 | private function fix_espresso_db_upgrade_option($espresso_db_update = null) |
498 | 498 | { |
499 | 499 | do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__begin', $espresso_db_update); |
500 | - if (! $espresso_db_update) { |
|
500 | + if ( ! $espresso_db_update) { |
|
501 | 501 | $espresso_db_update = get_option('espresso_db_update'); |
502 | 502 | } |
503 | 503 | // check that option is an array |
504 | - if (! is_array($espresso_db_update)) { |
|
504 | + if ( ! is_array($espresso_db_update)) { |
|
505 | 505 | // if option is FALSE, then it never existed |
506 | 506 | if ($espresso_db_update === false) { |
507 | 507 | // make $espresso_db_update an array and save option with autoload OFF |
@@ -606,7 +606,7 @@ discard block |
||
606 | 606 | */ |
607 | 607 | public function update_list_of_installed_versions($version_history = null, $current_version_to_add = null) |
608 | 608 | { |
609 | - if (! $version_history) { |
|
609 | + if ( ! $version_history) { |
|
610 | 610 | $version_history = $this->fix_espresso_db_upgrade_option($version_history); |
611 | 611 | } |
612 | 612 | if ($current_version_to_add === null) { |
@@ -704,7 +704,7 @@ discard block |
||
704 | 704 | if ($activation_history_for_addon) { |
705 | 705 | //it exists, so this isn't a completely new install |
706 | 706 | //check if this version already in that list of previously installed versions |
707 | - if (! isset($activation_history_for_addon[$version_to_upgrade_to])) { |
|
707 | + if ( ! isset($activation_history_for_addon[$version_to_upgrade_to])) { |
|
708 | 708 | //it a version we haven't seen before |
709 | 709 | if ($version_is_higher === 1) { |
710 | 710 | $req_type = EE_System::req_type_upgrade; |
@@ -784,7 +784,7 @@ discard block |
||
784 | 784 | foreach ($activation_history as $version => $times_activated) { |
785 | 785 | //check there is a record of when this version was activated. Otherwise, |
786 | 786 | //mark it as unknown |
787 | - if (! $times_activated) { |
|
787 | + if ( ! $times_activated) { |
|
788 | 788 | $times_activated = array('unknown-date'); |
789 | 789 | } |
790 | 790 | if (is_string($times_activated)) { |
@@ -884,7 +884,7 @@ discard block |
||
884 | 884 | private function _parse_model_names() |
885 | 885 | { |
886 | 886 | //get all the files in the EE_MODELS folder that end in .model.php |
887 | - $models = glob(EE_MODELS . '*.model.php'); |
|
887 | + $models = glob(EE_MODELS.'*.model.php'); |
|
888 | 888 | $model_names = array(); |
889 | 889 | $non_abstract_db_models = array(); |
890 | 890 | foreach ($models as $model) { |
@@ -914,8 +914,8 @@ discard block |
||
914 | 914 | */ |
915 | 915 | private function _maybe_brew_regular() |
916 | 916 | { |
917 | - if ((! defined('EE_DECAF') || EE_DECAF !== true) && is_readable(EE_CAFF_PATH . 'brewing_regular.php')) { |
|
918 | - require_once EE_CAFF_PATH . 'brewing_regular.php'; |
|
917 | + if (( ! defined('EE_DECAF') || EE_DECAF !== true) && is_readable(EE_CAFF_PATH.'brewing_regular.php')) { |
|
918 | + require_once EE_CAFF_PATH.'brewing_regular.php'; |
|
919 | 919 | } |
920 | 920 | } |
921 | 921 | |
@@ -966,17 +966,17 @@ discard block |
||
966 | 966 | $class_names = EEH_Class_Tools::get_class_names_for_all_callbacks_on_hook( |
967 | 967 | 'AHEE__EE_System__register_shortcodes_modules_and_addons' |
968 | 968 | ); |
969 | - if (! empty($class_names)) { |
|
969 | + if ( ! empty($class_names)) { |
|
970 | 970 | $msg = __( |
971 | 971 | 'The following plugins, addons, or modules appear to be incompatible with this version of Event Espresso and were automatically deactivated to avoid fatal errors:', |
972 | 972 | 'event_espresso' |
973 | 973 | ); |
974 | 974 | $msg .= '<ul>'; |
975 | 975 | foreach ($class_names as $class_name) { |
976 | - $msg .= '<li><b>Event Espresso - ' . str_replace( |
|
976 | + $msg .= '<li><b>Event Espresso - '.str_replace( |
|
977 | 977 | array('EE_', 'EEM_', 'EED_', 'EES_', 'EEW_'), '', |
978 | 978 | $class_name |
979 | - ) . '</b></li>'; |
|
979 | + ).'</b></li>'; |
|
980 | 980 | } |
981 | 981 | $msg .= '</ul>'; |
982 | 982 | $msg .= __( |
@@ -1047,7 +1047,7 @@ discard block |
||
1047 | 1047 | private function _deactivate_incompatible_addons() |
1048 | 1048 | { |
1049 | 1049 | $incompatible_addons = get_option('ee_incompatible_addons', array()); |
1050 | - if (! empty($incompatible_addons)) { |
|
1050 | + if ( ! empty($incompatible_addons)) { |
|
1051 | 1051 | $active_plugins = get_option('active_plugins', array()); |
1052 | 1052 | foreach ($active_plugins as $active_plugin) { |
1053 | 1053 | foreach ($incompatible_addons as $incompatible_addon) { |
@@ -1108,10 +1108,10 @@ discard block |
||
1108 | 1108 | { |
1109 | 1109 | do_action('AHEE__EE_System__load_controllers__start'); |
1110 | 1110 | // let's get it started |
1111 | - if (! is_admin() && ! $this->maintenance_mode->level()) { |
|
1111 | + if ( ! is_admin() && ! $this->maintenance_mode->level()) { |
|
1112 | 1112 | do_action('AHEE__EE_System__load_controllers__load_front_controllers'); |
1113 | 1113 | $this->loader->getShared('EE_Front_Controller'); |
1114 | - } else if (! EE_FRONT_AJAX) { |
|
1114 | + } else if ( ! EE_FRONT_AJAX) { |
|
1115 | 1115 | do_action('AHEE__EE_System__load_controllers__load_admin_controllers'); |
1116 | 1116 | $this->loader->getShared('EE_Admin'); |
1117 | 1117 | } |
@@ -1132,8 +1132,8 @@ discard block |
||
1132 | 1132 | $this->loader->getShared('EE_Session'); |
1133 | 1133 | do_action('AHEE__EE_System__core_loaded_and_ready'); |
1134 | 1134 | // load_espresso_template_tags |
1135 | - if (is_readable(EE_PUBLIC . 'template_tags.php')) { |
|
1136 | - require_once(EE_PUBLIC . 'template_tags.php'); |
|
1135 | + if (is_readable(EE_PUBLIC.'template_tags.php')) { |
|
1136 | + require_once(EE_PUBLIC.'template_tags.php'); |
|
1137 | 1137 | } |
1138 | 1138 | do_action('AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons'); |
1139 | 1139 | $this->loader->getShared('EventEspresso\core\services\assets\Registry'); |
@@ -1195,13 +1195,13 @@ discard block |
||
1195 | 1195 | public static function do_not_cache() |
1196 | 1196 | { |
1197 | 1197 | // set no cache constants |
1198 | - if (! defined('DONOTCACHEPAGE')) { |
|
1198 | + if ( ! defined('DONOTCACHEPAGE')) { |
|
1199 | 1199 | define('DONOTCACHEPAGE', true); |
1200 | 1200 | } |
1201 | - if (! defined('DONOTCACHCEOBJECT')) { |
|
1201 | + if ( ! defined('DONOTCACHCEOBJECT')) { |
|
1202 | 1202 | define('DONOTCACHCEOBJECT', true); |
1203 | 1203 | } |
1204 | - if (! defined('DONOTCACHEDB')) { |
|
1204 | + if ( ! defined('DONOTCACHEDB')) { |
|
1205 | 1205 | define('DONOTCACHEDB', true); |
1206 | 1206 | } |
1207 | 1207 | // add no cache headers |
@@ -21,1242 +21,1242 @@ |
||
21 | 21 | { |
22 | 22 | |
23 | 23 | |
24 | - /** |
|
25 | - * indicates this is a 'normal' request. Ie, not activation, nor upgrade, nor activation. |
|
26 | - * So examples of this would be a normal GET request on the frontend or backend, or a POST, etc |
|
27 | - */ |
|
28 | - const req_type_normal = 0; |
|
29 | - |
|
30 | - /** |
|
31 | - * Indicates this is a brand new installation of EE so we should install |
|
32 | - * tables and default data etc |
|
33 | - */ |
|
34 | - const req_type_new_activation = 1; |
|
35 | - |
|
36 | - /** |
|
37 | - * we've detected that EE has been reactivated (or EE was activated during maintenance mode, |
|
38 | - * and we just exited maintenance mode). We MUST check the database is setup properly |
|
39 | - * and that default data is setup too |
|
40 | - */ |
|
41 | - const req_type_reactivation = 2; |
|
42 | - |
|
43 | - /** |
|
44 | - * indicates that EE has been upgraded since its previous request. |
|
45 | - * We may have data migration scripts to call and will want to trigger maintenance mode |
|
46 | - */ |
|
47 | - const req_type_upgrade = 3; |
|
48 | - |
|
49 | - /** |
|
50 | - * TODO will detect that EE has been DOWNGRADED. We probably don't want to run in this case... |
|
51 | - */ |
|
52 | - const req_type_downgrade = 4; |
|
53 | - |
|
54 | - /** |
|
55 | - * @deprecated since version 4.6.0.dev.006 |
|
56 | - * Now whenever a new_activation is detected the request type is still just |
|
57 | - * new_activation (same for reactivation, upgrade, downgrade etc), but if we'r ein maintenance mode |
|
58 | - * EE_System::initialize_db_if_no_migrations_required and EE_Addon::initialize_db_if_no_migrations_required |
|
59 | - * will instead enqueue that EE plugin's db initialization for when we're taken out of maintenance mode. |
|
60 | - * (Specifically, when the migration manager indicates migrations are finished |
|
61 | - * EE_Data_Migration_Manager::initialize_db_for_enqueued_ee_plugins() will be called) |
|
62 | - */ |
|
63 | - const req_type_activation_but_not_installed = 5; |
|
64 | - |
|
65 | - /** |
|
66 | - * option prefix for recording the activation history (like core's "espresso_db_update") of addons |
|
67 | - */ |
|
68 | - const addon_activation_history_option_prefix = 'ee_addon_activation_history_'; |
|
69 | - |
|
70 | - |
|
71 | - /** |
|
72 | - * @var EE_System $_instance |
|
73 | - */ |
|
74 | - private static $_instance; |
|
75 | - |
|
76 | - /** |
|
77 | - * @var EE_Registry $registry |
|
78 | - */ |
|
79 | - private $registry; |
|
80 | - |
|
81 | - /** |
|
82 | - * @var LoaderInterface $loader |
|
83 | - */ |
|
84 | - private $loader; |
|
85 | - |
|
86 | - /** |
|
87 | - * @var EE_Capabilities $capabilities |
|
88 | - */ |
|
89 | - private $capabilities; |
|
90 | - |
|
91 | - /** |
|
92 | - * @var EE_Request $request |
|
93 | - */ |
|
94 | - private $request; |
|
95 | - |
|
96 | - /** |
|
97 | - * @var EE_Maintenance_Mode $maintenance_mode |
|
98 | - */ |
|
99 | - private $maintenance_mode; |
|
100 | - |
|
101 | - /** |
|
102 | - * Stores which type of request this is, options being one of the constants on EE_System starting with req_type_*. |
|
103 | - * It can be a brand-new activation, a reactivation, an upgrade, a downgrade, or a normal request. |
|
104 | - * |
|
105 | - * @var int $_req_type |
|
106 | - */ |
|
107 | - private $_req_type; |
|
108 | - |
|
109 | - /** |
|
110 | - * Whether or not there was a non-micro version change in EE core version during this request |
|
111 | - * |
|
112 | - * @var boolean $_major_version_change |
|
113 | - */ |
|
114 | - private $_major_version_change = false; |
|
115 | - |
|
116 | - |
|
117 | - |
|
118 | - /** |
|
119 | - * @singleton method used to instantiate class object |
|
120 | - * @param EE_Registry|null $registry |
|
121 | - * @param LoaderInterface|null $loader |
|
122 | - * @param EE_Capabilities|null $capabilities |
|
123 | - * @param EE_Request|null $request |
|
124 | - * @param EE_Maintenance_Mode|null $maintenance_mode |
|
125 | - * @return EE_System |
|
126 | - */ |
|
127 | - public static function instance( |
|
128 | - EE_Registry $registry = null, |
|
129 | - LoaderInterface $loader = null, |
|
130 | - EE_Capabilities $capabilities = null, |
|
131 | - EE_Request $request = null, |
|
132 | - EE_Maintenance_Mode $maintenance_mode = null |
|
133 | - ) { |
|
134 | - // check if class object is instantiated |
|
135 | - if (! self::$_instance instanceof EE_System) { |
|
136 | - self::$_instance = new self($registry, $loader, $capabilities, $request, $maintenance_mode); |
|
137 | - } |
|
138 | - return self::$_instance; |
|
139 | - } |
|
140 | - |
|
141 | - |
|
142 | - |
|
143 | - /** |
|
144 | - * resets the instance and returns it |
|
145 | - * |
|
146 | - * @return EE_System |
|
147 | - */ |
|
148 | - public static function reset() |
|
149 | - { |
|
150 | - self::$_instance->_req_type = null; |
|
151 | - //make sure none of the old hooks are left hanging around |
|
152 | - remove_all_actions('AHEE__EE_System__perform_activations_upgrades_and_migrations'); |
|
153 | - //we need to reset the migration manager in order for it to detect DMSs properly |
|
154 | - EE_Data_Migration_Manager::reset(); |
|
155 | - self::instance()->detect_activations_or_upgrades(); |
|
156 | - self::instance()->perform_activations_upgrades_and_migrations(); |
|
157 | - return self::instance(); |
|
158 | - } |
|
159 | - |
|
160 | - |
|
161 | - |
|
162 | - /** |
|
163 | - * sets hooks for running rest of system |
|
164 | - * provides "AHEE__EE_System__construct__complete" hook for EE Addons to use as their starting point |
|
165 | - * starting EE Addons from any other point may lead to problems |
|
166 | - * |
|
167 | - * @param EE_Registry $registry |
|
168 | - * @param LoaderInterface $loader |
|
169 | - * @param EE_Capabilities $capabilities |
|
170 | - * @param EE_Request $request |
|
171 | - * @param EE_Maintenance_Mode $maintenance_mode |
|
172 | - */ |
|
173 | - private function __construct( |
|
174 | - EE_Registry $registry, |
|
175 | - LoaderInterface $loader, |
|
176 | - EE_Capabilities $capabilities, |
|
177 | - EE_Request $request, |
|
178 | - EE_Maintenance_Mode $maintenance_mode |
|
179 | - ) { |
|
180 | - $this->registry = $registry; |
|
181 | - $this->loader = $loader; |
|
182 | - $this->capabilities = $capabilities; |
|
183 | - $this->request = $request; |
|
184 | - $this->maintenance_mode = $maintenance_mode; |
|
185 | - do_action('AHEE__EE_System__construct__begin', $this); |
|
186 | - add_action( |
|
187 | - 'AHEE__EE_Bootstrap__load_espresso_addons', |
|
188 | - array($this, 'loadCapabilities'), |
|
189 | - 5 |
|
190 | - ); |
|
191 | - add_action( |
|
192 | - 'AHEE__EE_Bootstrap__load_espresso_addons', |
|
193 | - array($this, 'loadCommandBus'), |
|
194 | - 7 |
|
195 | - ); |
|
196 | - add_action( |
|
197 | - 'AHEE__EE_Bootstrap__load_espresso_addons', |
|
198 | - array($this, 'loadPluginApi'), |
|
199 | - 9 |
|
200 | - ); |
|
201 | - // allow addons to load first so that they can register autoloaders, set hooks for running DMS's, etc |
|
202 | - add_action( |
|
203 | - 'AHEE__EE_Bootstrap__load_espresso_addons', |
|
204 | - array($this, 'load_espresso_addons') |
|
205 | - ); |
|
206 | - // when an ee addon is activated, we want to call the core hook(s) again |
|
207 | - // because the newly-activated addon didn't get a chance to run at all |
|
208 | - add_action('activate_plugin', array($this, 'load_espresso_addons'), 1); |
|
209 | - // detect whether install or upgrade |
|
210 | - add_action( |
|
211 | - 'AHEE__EE_Bootstrap__detect_activations_or_upgrades', |
|
212 | - array($this, 'detect_activations_or_upgrades'), |
|
213 | - 3 |
|
214 | - ); |
|
215 | - // load EE_Config, EE_Textdomain, etc |
|
216 | - add_action( |
|
217 | - 'AHEE__EE_Bootstrap__load_core_configuration', |
|
218 | - array($this, 'load_core_configuration'), |
|
219 | - 5 |
|
220 | - ); |
|
221 | - // load EE_Config, EE_Textdomain, etc |
|
222 | - add_action( |
|
223 | - 'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets', |
|
224 | - array($this, 'register_shortcodes_modules_and_widgets'), |
|
225 | - 7 |
|
226 | - ); |
|
227 | - // you wanna get going? I wanna get going... let's get going! |
|
228 | - add_action( |
|
229 | - 'AHEE__EE_Bootstrap__brew_espresso', |
|
230 | - array($this, 'brew_espresso'), |
|
231 | - 9 |
|
232 | - ); |
|
233 | - //other housekeeping |
|
234 | - //exclude EE critical pages from wp_list_pages |
|
235 | - add_filter( |
|
236 | - 'wp_list_pages_excludes', |
|
237 | - array($this, 'remove_pages_from_wp_list_pages'), |
|
238 | - 10 |
|
239 | - ); |
|
240 | - // ALL EE Addons should use the following hook point to attach their initial setup too |
|
241 | - // it's extremely important for EE Addons to register any class autoloaders so that they can be available when the EE_Config loads |
|
242 | - do_action('AHEE__EE_System__construct__complete', $this); |
|
243 | - } |
|
244 | - |
|
245 | - |
|
246 | - |
|
247 | - /** |
|
248 | - * load and setup EE_Capabilities |
|
249 | - * |
|
250 | - * @return void |
|
251 | - * @throws EE_Error |
|
252 | - */ |
|
253 | - public function loadCapabilities() |
|
254 | - { |
|
255 | - $this->loader->getShared('EE_Capabilities'); |
|
256 | - add_action( |
|
257 | - 'AHEE__EE_Capabilities__init_caps__before_initialization', |
|
258 | - function() { |
|
259 | - LoaderFactory::getLoader()->getShared('EE_Payment_Method_Manager'); |
|
260 | - } |
|
261 | - ); |
|
262 | - } |
|
263 | - |
|
264 | - |
|
265 | - |
|
266 | - /** |
|
267 | - * create and cache the CommandBus, and also add middleware |
|
268 | - * The CapChecker middleware requires the use of EE_Capabilities |
|
269 | - * which is why we need to load the CommandBus after Caps are set up |
|
270 | - * |
|
271 | - * @return void |
|
272 | - * @throws EE_Error |
|
273 | - */ |
|
274 | - public function loadCommandBus() |
|
275 | - { |
|
276 | - $this->loader->getShared( |
|
277 | - 'CommandBusInterface', |
|
278 | - array( |
|
279 | - null, |
|
280 | - apply_filters( |
|
281 | - 'FHEE__EE_Load_Espresso_Core__handle_request__CommandBus_middleware', |
|
282 | - array( |
|
283 | - $this->loader->getShared('EventEspresso\core\services\commands\middleware\CapChecker'), |
|
284 | - $this->loader->getShared('EventEspresso\core\services\commands\middleware\AddActionHook'), |
|
285 | - ) |
|
286 | - ), |
|
287 | - ) |
|
288 | - ); |
|
289 | - } |
|
290 | - |
|
291 | - |
|
292 | - |
|
293 | - /** |
|
294 | - * @return void |
|
295 | - * @throws EE_Error |
|
296 | - */ |
|
297 | - public function loadPluginApi() |
|
298 | - { |
|
299 | - // set autoloaders for all of the classes implementing EEI_Plugin_API |
|
300 | - // which provide helpers for EE plugin authors to more easily register certain components with EE. |
|
301 | - EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'plugin_api'); |
|
302 | - } |
|
303 | - |
|
304 | - |
|
305 | - /** |
|
306 | - * @param string $addon_name |
|
307 | - * @param string $version_constant |
|
308 | - * @param string $min_version_required |
|
309 | - * @param string $load_callback |
|
310 | - * @param string $plugin_file_constant |
|
311 | - * @return void |
|
312 | - */ |
|
313 | - private function deactivateIncompatibleAddon( |
|
314 | - $addon_name, |
|
315 | - $version_constant, |
|
316 | - $min_version_required, |
|
317 | - $load_callback, |
|
318 | - $plugin_file_constant |
|
319 | - ) { |
|
320 | - if (! defined($version_constant)) { |
|
321 | - return; |
|
322 | - } |
|
323 | - $addon_version = constant($version_constant); |
|
324 | - if ($addon_version && version_compare($addon_version, $min_version_required, '<')) { |
|
325 | - remove_action('AHEE__EE_System__load_espresso_addons', $load_callback); |
|
326 | - if (! function_exists('deactivate_plugins')) { |
|
327 | - require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
328 | - } |
|
329 | - deactivate_plugins(plugin_basename(constant($plugin_file_constant))); |
|
330 | - unset($_GET['activate'], $_REQUEST['activate'], $_GET['activate-multi'], $_REQUEST['activate-multi']); |
|
331 | - EE_Error::add_error( |
|
332 | - sprintf( |
|
333 | - esc_html__( |
|
334 | - 'We\'re sorry, but the Event Espresso %1$s addon was deactivated because version %2$s or higher is required with this version of Event Espresso core.', |
|
335 | - 'event_espresso' |
|
336 | - ), |
|
337 | - $addon_name, |
|
338 | - $min_version_required |
|
339 | - ), |
|
340 | - __FILE__, __FUNCTION__ . "({$addon_name})", __LINE__ |
|
341 | - ); |
|
342 | - EE_Error::get_notices(false, true); |
|
343 | - } |
|
344 | - } |
|
345 | - |
|
346 | - |
|
347 | - /** |
|
348 | - * load_espresso_addons |
|
349 | - * allow addons to load first so that they can set hooks for running DMS's, etc |
|
350 | - * this is hooked into both: |
|
351 | - * 'AHEE__EE_Bootstrap__load_core_configuration' |
|
352 | - * which runs during the WP 'plugins_loaded' action at priority 5 |
|
353 | - * and the WP 'activate_plugin' hook point |
|
354 | - * |
|
355 | - * @access public |
|
356 | - * @return void |
|
357 | - */ |
|
358 | - public function load_espresso_addons() |
|
359 | - { |
|
360 | - $this->deactivateIncompatibleAddon( |
|
361 | - 'Wait Lists', |
|
362 | - 'EE_WAIT_LISTS_VERSION', |
|
363 | - '1.0.0.beta.074', |
|
364 | - 'load_espresso_wait_lists', |
|
365 | - 'EE_WAIT_LISTS_PLUGIN_FILE' |
|
366 | - ); |
|
367 | - $this->deactivateIncompatibleAddon( |
|
368 | - 'Automated Upcoming Event Notifications', |
|
369 | - 'EE_AUTOMATED_UPCOMING_EVENT_NOTIFICATION_VERSION', |
|
370 | - '1.0.0.beta.091', |
|
371 | - 'load_espresso_automated_upcoming_event_notification', |
|
372 | - 'EE_AUTOMATED_UPCOMING_EVENT_NOTIFICATION_PLUGIN_FILE' |
|
373 | - ); |
|
374 | - do_action('AHEE__EE_System__load_espresso_addons'); |
|
375 | - //if the WP API basic auth plugin isn't already loaded, load it now. |
|
376 | - //We want it for mobile apps. Just include the entire plugin |
|
377 | - //also, don't load the basic auth when a plugin is getting activated, because |
|
378 | - //it could be the basic auth plugin, and it doesn't check if its methods are already defined |
|
379 | - //and causes a fatal error |
|
380 | - if ( |
|
381 | - ! ( |
|
382 | - isset($_GET['activate']) |
|
383 | - && $_GET['activate'] === 'true' |
|
384 | - ) |
|
385 | - && ! function_exists('json_basic_auth_handler') |
|
386 | - && ! function_exists('json_basic_auth_error') |
|
387 | - && ! ( |
|
388 | - isset($_GET['action']) |
|
389 | - && in_array($_GET['action'], array('activate', 'activate-selected'), true) |
|
390 | - ) |
|
391 | - ) { |
|
392 | - include_once EE_THIRD_PARTY . 'wp-api-basic-auth' . DS . 'basic-auth.php'; |
|
393 | - } |
|
394 | - do_action('AHEE__EE_System__load_espresso_addons__complete'); |
|
395 | - } |
|
396 | - |
|
397 | - |
|
398 | - |
|
399 | - /** |
|
400 | - * detect_activations_or_upgrades |
|
401 | - * Checks for activation or upgrade of core first; |
|
402 | - * then also checks if any registered addons have been activated or upgraded |
|
403 | - * This is hooked into 'AHEE__EE_Bootstrap__detect_activations_or_upgrades' |
|
404 | - * which runs during the WP 'plugins_loaded' action at priority 3 |
|
405 | - * |
|
406 | - * @access public |
|
407 | - * @return void |
|
408 | - */ |
|
409 | - public function detect_activations_or_upgrades() |
|
410 | - { |
|
411 | - //first off: let's make sure to handle core |
|
412 | - $this->detect_if_activation_or_upgrade(); |
|
413 | - foreach ($this->registry->addons as $addon) { |
|
414 | - if ($addon instanceof EE_Addon) { |
|
415 | - //detect teh request type for that addon |
|
416 | - $addon->detect_activation_or_upgrade(); |
|
417 | - } |
|
418 | - } |
|
419 | - } |
|
420 | - |
|
421 | - |
|
422 | - |
|
423 | - /** |
|
424 | - * detect_if_activation_or_upgrade |
|
425 | - * Takes care of detecting whether this is a brand new install or code upgrade, |
|
426 | - * and either setting up the DB or setting up maintenance mode etc. |
|
427 | - * |
|
428 | - * @access public |
|
429 | - * @return void |
|
430 | - */ |
|
431 | - public function detect_if_activation_or_upgrade() |
|
432 | - { |
|
433 | - do_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin'); |
|
434 | - // check if db has been updated, or if its a brand-new installation |
|
435 | - $espresso_db_update = $this->fix_espresso_db_upgrade_option(); |
|
436 | - $request_type = $this->detect_req_type($espresso_db_update); |
|
437 | - //EEH_Debug_Tools::printr( $request_type, '$request_type', __FILE__, __LINE__ ); |
|
438 | - switch ($request_type) { |
|
439 | - case EE_System::req_type_new_activation: |
|
440 | - do_action('AHEE__EE_System__detect_if_activation_or_upgrade__new_activation'); |
|
441 | - $this->_handle_core_version_change($espresso_db_update); |
|
442 | - break; |
|
443 | - case EE_System::req_type_reactivation: |
|
444 | - do_action('AHEE__EE_System__detect_if_activation_or_upgrade__reactivation'); |
|
445 | - $this->_handle_core_version_change($espresso_db_update); |
|
446 | - break; |
|
447 | - case EE_System::req_type_upgrade: |
|
448 | - do_action('AHEE__EE_System__detect_if_activation_or_upgrade__upgrade'); |
|
449 | - //migrations may be required now that we've upgraded |
|
450 | - $this->maintenance_mode->set_maintenance_mode_if_db_old(); |
|
451 | - $this->_handle_core_version_change($espresso_db_update); |
|
452 | - // echo "done upgrade";die; |
|
453 | - break; |
|
454 | - case EE_System::req_type_downgrade: |
|
455 | - do_action('AHEE__EE_System__detect_if_activation_or_upgrade__downgrade'); |
|
456 | - //its possible migrations are no longer required |
|
457 | - $this->maintenance_mode->set_maintenance_mode_if_db_old(); |
|
458 | - $this->_handle_core_version_change($espresso_db_update); |
|
459 | - break; |
|
460 | - case EE_System::req_type_normal: |
|
461 | - default: |
|
462 | - // $this->_maybe_redirect_to_ee_about(); |
|
463 | - break; |
|
464 | - } |
|
465 | - do_action('AHEE__EE_System__detect_if_activation_or_upgrade__complete'); |
|
466 | - } |
|
467 | - |
|
468 | - |
|
469 | - |
|
470 | - /** |
|
471 | - * Updates the list of installed versions and sets hooks for |
|
472 | - * initializing the database later during the request |
|
473 | - * |
|
474 | - * @param array $espresso_db_update |
|
475 | - */ |
|
476 | - private function _handle_core_version_change($espresso_db_update) |
|
477 | - { |
|
478 | - $this->update_list_of_installed_versions($espresso_db_update); |
|
479 | - //get ready to verify the DB is ok (provided we aren't in maintenance mode, of course) |
|
480 | - add_action( |
|
481 | - 'AHEE__EE_System__perform_activations_upgrades_and_migrations', |
|
482 | - array($this, 'initialize_db_if_no_migrations_required') |
|
483 | - ); |
|
484 | - } |
|
485 | - |
|
486 | - |
|
487 | - |
|
488 | - /** |
|
489 | - * standardizes the wp option 'espresso_db_upgrade' which actually stores |
|
490 | - * information about what versions of EE have been installed and activated, |
|
491 | - * NOT necessarily the state of the database |
|
492 | - * |
|
493 | - * @param mixed $espresso_db_update the value of the WordPress option. |
|
494 | - * If not supplied, fetches it from the options table |
|
495 | - * @return array the correct value of 'espresso_db_upgrade', after saving it, if it needed correction |
|
496 | - */ |
|
497 | - private function fix_espresso_db_upgrade_option($espresso_db_update = null) |
|
498 | - { |
|
499 | - do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__begin', $espresso_db_update); |
|
500 | - if (! $espresso_db_update) { |
|
501 | - $espresso_db_update = get_option('espresso_db_update'); |
|
502 | - } |
|
503 | - // check that option is an array |
|
504 | - if (! is_array($espresso_db_update)) { |
|
505 | - // if option is FALSE, then it never existed |
|
506 | - if ($espresso_db_update === false) { |
|
507 | - // make $espresso_db_update an array and save option with autoload OFF |
|
508 | - $espresso_db_update = array(); |
|
509 | - add_option('espresso_db_update', $espresso_db_update, '', 'no'); |
|
510 | - } else { |
|
511 | - // option is NOT FALSE but also is NOT an array, so make it an array and save it |
|
512 | - $espresso_db_update = array($espresso_db_update => array()); |
|
513 | - update_option('espresso_db_update', $espresso_db_update); |
|
514 | - } |
|
515 | - } else { |
|
516 | - $corrected_db_update = array(); |
|
517 | - //if IS an array, but is it an array where KEYS are version numbers, and values are arrays? |
|
518 | - foreach ($espresso_db_update as $should_be_version_string => $should_be_array) { |
|
519 | - if (is_int($should_be_version_string) && ! is_array($should_be_array)) { |
|
520 | - //the key is an int, and the value IS NOT an array |
|
521 | - //so it must be numerically-indexed, where values are versions installed... |
|
522 | - //fix it! |
|
523 | - $version_string = $should_be_array; |
|
524 | - $corrected_db_update[$version_string] = array('unknown-date'); |
|
525 | - } else { |
|
526 | - //ok it checks out |
|
527 | - $corrected_db_update[$should_be_version_string] = $should_be_array; |
|
528 | - } |
|
529 | - } |
|
530 | - $espresso_db_update = $corrected_db_update; |
|
531 | - update_option('espresso_db_update', $espresso_db_update); |
|
532 | - } |
|
533 | - do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__complete', $espresso_db_update); |
|
534 | - return $espresso_db_update; |
|
535 | - } |
|
536 | - |
|
537 | - |
|
538 | - |
|
539 | - /** |
|
540 | - * Does the traditional work of setting up the plugin's database and adding default data. |
|
541 | - * If migration script/process did not exist, this is what would happen on every activation/reactivation/upgrade. |
|
542 | - * NOTE: if we're in maintenance mode (which would be the case if we detect there are data |
|
543 | - * migration scripts that need to be run and a version change happens), enqueues core for database initialization, |
|
544 | - * so that it will be done when migrations are finished |
|
545 | - * |
|
546 | - * @param boolean $initialize_addons_too if true, we double-check addons' database tables etc too; |
|
547 | - * @param boolean $verify_schema if true will re-check the database tables have the correct schema. |
|
548 | - * This is a resource-intensive job |
|
549 | - * so we prefer to only do it when necessary |
|
550 | - * @return void |
|
551 | - * @throws EE_Error |
|
552 | - */ |
|
553 | - public function initialize_db_if_no_migrations_required($initialize_addons_too = false, $verify_schema = true) |
|
554 | - { |
|
555 | - $request_type = $this->detect_req_type(); |
|
556 | - //only initialize system if we're not in maintenance mode. |
|
557 | - if ($this->maintenance_mode->level() !== EE_Maintenance_Mode::level_2_complete_maintenance) { |
|
558 | - update_option('ee_flush_rewrite_rules', true); |
|
559 | - if ($verify_schema) { |
|
560 | - EEH_Activation::initialize_db_and_folders(); |
|
561 | - } |
|
562 | - EEH_Activation::initialize_db_content(); |
|
563 | - EEH_Activation::system_initialization(); |
|
564 | - if ($initialize_addons_too) { |
|
565 | - $this->initialize_addons(); |
|
566 | - } |
|
567 | - } else { |
|
568 | - EE_Data_Migration_Manager::instance()->enqueue_db_initialization_for('Core'); |
|
569 | - } |
|
570 | - if ($request_type === EE_System::req_type_new_activation |
|
571 | - || $request_type === EE_System::req_type_reactivation |
|
572 | - || ( |
|
573 | - $request_type === EE_System::req_type_upgrade |
|
574 | - && $this->is_major_version_change() |
|
575 | - ) |
|
576 | - ) { |
|
577 | - add_action('AHEE__EE_System__initialize_last', array($this, 'redirect_to_about_ee'), 9); |
|
578 | - } |
|
579 | - } |
|
580 | - |
|
581 | - |
|
582 | - |
|
583 | - /** |
|
584 | - * Initializes the db for all registered addons |
|
585 | - * |
|
586 | - * @throws EE_Error |
|
587 | - */ |
|
588 | - public function initialize_addons() |
|
589 | - { |
|
590 | - //foreach registered addon, make sure its db is up-to-date too |
|
591 | - foreach ($this->registry->addons as $addon) { |
|
592 | - if ($addon instanceof EE_Addon) { |
|
593 | - $addon->initialize_db_if_no_migrations_required(); |
|
594 | - } |
|
595 | - } |
|
596 | - } |
|
597 | - |
|
598 | - |
|
599 | - |
|
600 | - /** |
|
601 | - * Adds the current code version to the saved wp option which stores a list of all ee versions ever installed. |
|
602 | - * |
|
603 | - * @param array $version_history |
|
604 | - * @param string $current_version_to_add version to be added to the version history |
|
605 | - * @return boolean success as to whether or not this option was changed |
|
606 | - */ |
|
607 | - public function update_list_of_installed_versions($version_history = null, $current_version_to_add = null) |
|
608 | - { |
|
609 | - if (! $version_history) { |
|
610 | - $version_history = $this->fix_espresso_db_upgrade_option($version_history); |
|
611 | - } |
|
612 | - if ($current_version_to_add === null) { |
|
613 | - $current_version_to_add = espresso_version(); |
|
614 | - } |
|
615 | - $version_history[$current_version_to_add][] = date('Y-m-d H:i:s', time()); |
|
616 | - // re-save |
|
617 | - return update_option('espresso_db_update', $version_history); |
|
618 | - } |
|
619 | - |
|
620 | - |
|
621 | - |
|
622 | - /** |
|
623 | - * Detects if the current version indicated in the has existed in the list of |
|
624 | - * previously-installed versions of EE (espresso_db_update). Does NOT modify it (ie, no side-effect) |
|
625 | - * |
|
626 | - * @param array $espresso_db_update array from the wp option stored under the name 'espresso_db_update'. |
|
627 | - * If not supplied, fetches it from the options table. |
|
628 | - * Also, caches its result so later parts of the code can also know whether |
|
629 | - * there's been an update or not. This way we can add the current version to |
|
630 | - * espresso_db_update, but still know if this is a new install or not |
|
631 | - * @return int one of the constants on EE_System::req_type_ |
|
632 | - */ |
|
633 | - public function detect_req_type($espresso_db_update = null) |
|
634 | - { |
|
635 | - if ($this->_req_type === null) { |
|
636 | - $espresso_db_update = ! empty($espresso_db_update) |
|
637 | - ? $espresso_db_update |
|
638 | - : $this->fix_espresso_db_upgrade_option(); |
|
639 | - $this->_req_type = EE_System::detect_req_type_given_activation_history( |
|
640 | - $espresso_db_update, |
|
641 | - 'ee_espresso_activation', espresso_version() |
|
642 | - ); |
|
643 | - $this->_major_version_change = $this->_detect_major_version_change($espresso_db_update); |
|
644 | - } |
|
645 | - return $this->_req_type; |
|
646 | - } |
|
647 | - |
|
648 | - |
|
649 | - |
|
650 | - /** |
|
651 | - * Returns whether or not there was a non-micro version change (ie, change in either |
|
652 | - * the first or second number in the version. Eg 4.9.0.rc.001 to 4.10.0.rc.000, |
|
653 | - * but not 4.9.0.rc.0001 to 4.9.1.rc.0001 |
|
654 | - * |
|
655 | - * @param $activation_history |
|
656 | - * @return bool |
|
657 | - */ |
|
658 | - private function _detect_major_version_change($activation_history) |
|
659 | - { |
|
660 | - $previous_version = EE_System::_get_most_recently_active_version_from_activation_history($activation_history); |
|
661 | - $previous_version_parts = explode('.', $previous_version); |
|
662 | - $current_version_parts = explode('.', espresso_version()); |
|
663 | - return isset($previous_version_parts[0], $previous_version_parts[1], $current_version_parts[0], $current_version_parts[1]) |
|
664 | - && ($previous_version_parts[0] !== $current_version_parts[0] |
|
665 | - || $previous_version_parts[1] !== $current_version_parts[1] |
|
666 | - ); |
|
667 | - } |
|
668 | - |
|
669 | - |
|
670 | - |
|
671 | - /** |
|
672 | - * Returns true if either the major or minor version of EE changed during this request. |
|
673 | - * Eg 4.9.0.rc.001 to 4.10.0.rc.000, but not 4.9.0.rc.0001 to 4.9.1.rc.0001 |
|
674 | - * |
|
675 | - * @return bool |
|
676 | - */ |
|
677 | - public function is_major_version_change() |
|
678 | - { |
|
679 | - return $this->_major_version_change; |
|
680 | - } |
|
681 | - |
|
682 | - |
|
683 | - |
|
684 | - /** |
|
685 | - * Determines the request type for any ee addon, given three piece of info: the current array of activation |
|
686 | - * histories (for core that' 'espresso_db_update' wp option); the name of the WordPress option which is temporarily |
|
687 | - * set upon activation of the plugin (for core it's 'ee_espresso_activation'); and the version that this plugin was |
|
688 | - * just activated to (for core that will always be espresso_version()) |
|
689 | - * |
|
690 | - * @param array $activation_history_for_addon the option's value which stores the activation history for this |
|
691 | - * ee plugin. for core that's 'espresso_db_update' |
|
692 | - * @param string $activation_indicator_option_name the name of the WordPress option that is temporarily set to |
|
693 | - * indicate that this plugin was just activated |
|
694 | - * @param string $version_to_upgrade_to the version that was just upgraded to (for core that will be |
|
695 | - * espresso_version()) |
|
696 | - * @return int one of the constants on EE_System::req_type_* |
|
697 | - */ |
|
698 | - public static function detect_req_type_given_activation_history( |
|
699 | - $activation_history_for_addon, |
|
700 | - $activation_indicator_option_name, |
|
701 | - $version_to_upgrade_to |
|
702 | - ) { |
|
703 | - $version_is_higher = self::_new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to); |
|
704 | - if ($activation_history_for_addon) { |
|
705 | - //it exists, so this isn't a completely new install |
|
706 | - //check if this version already in that list of previously installed versions |
|
707 | - if (! isset($activation_history_for_addon[$version_to_upgrade_to])) { |
|
708 | - //it a version we haven't seen before |
|
709 | - if ($version_is_higher === 1) { |
|
710 | - $req_type = EE_System::req_type_upgrade; |
|
711 | - } else { |
|
712 | - $req_type = EE_System::req_type_downgrade; |
|
713 | - } |
|
714 | - delete_option($activation_indicator_option_name); |
|
715 | - } else { |
|
716 | - // its not an update. maybe a reactivation? |
|
717 | - if (get_option($activation_indicator_option_name, false)) { |
|
718 | - if ($version_is_higher === -1) { |
|
719 | - $req_type = EE_System::req_type_downgrade; |
|
720 | - } else if ($version_is_higher === 0) { |
|
721 | - //we've seen this version before, but it's an activation. must be a reactivation |
|
722 | - $req_type = EE_System::req_type_reactivation; |
|
723 | - } else {//$version_is_higher === 1 |
|
724 | - $req_type = EE_System::req_type_upgrade; |
|
725 | - } |
|
726 | - delete_option($activation_indicator_option_name); |
|
727 | - } else { |
|
728 | - //we've seen this version before and the activation indicate doesn't show it was just activated |
|
729 | - if ($version_is_higher === -1) { |
|
730 | - $req_type = EE_System::req_type_downgrade; |
|
731 | - } else if ($version_is_higher === 0) { |
|
732 | - //we've seen this version before and it's not an activation. its normal request |
|
733 | - $req_type = EE_System::req_type_normal; |
|
734 | - } else {//$version_is_higher === 1 |
|
735 | - $req_type = EE_System::req_type_upgrade; |
|
736 | - } |
|
737 | - } |
|
738 | - } |
|
739 | - } else { |
|
740 | - //brand new install |
|
741 | - $req_type = EE_System::req_type_new_activation; |
|
742 | - delete_option($activation_indicator_option_name); |
|
743 | - } |
|
744 | - return $req_type; |
|
745 | - } |
|
746 | - |
|
747 | - |
|
748 | - |
|
749 | - /** |
|
750 | - * Detects if the $version_to_upgrade_to is higher than the most recent version in |
|
751 | - * the $activation_history_for_addon |
|
752 | - * |
|
753 | - * @param array $activation_history_for_addon (keys are versions, values are arrays of times activated, |
|
754 | - * sometimes containing 'unknown-date' |
|
755 | - * @param string $version_to_upgrade_to (current version) |
|
756 | - * @return int results of version_compare( $version_to_upgrade_to, $most_recently_active_version ). |
|
757 | - * ie, -1 if $version_to_upgrade_to is LOWER (downgrade); |
|
758 | - * 0 if $version_to_upgrade_to MATCHES (reactivation or normal request); |
|
759 | - * 1 if $version_to_upgrade_to is HIGHER (upgrade) ; |
|
760 | - */ |
|
761 | - private static function _new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to) |
|
762 | - { |
|
763 | - //find the most recently-activated version |
|
764 | - $most_recently_active_version = |
|
765 | - EE_System::_get_most_recently_active_version_from_activation_history($activation_history_for_addon); |
|
766 | - return version_compare($version_to_upgrade_to, $most_recently_active_version); |
|
767 | - } |
|
768 | - |
|
769 | - |
|
770 | - |
|
771 | - /** |
|
772 | - * Gets the most recently active version listed in the activation history, |
|
773 | - * and if none are found (ie, it's a brand new install) returns '0.0.0.dev.000'. |
|
774 | - * |
|
775 | - * @param array $activation_history (keys are versions, values are arrays of times activated, |
|
776 | - * sometimes containing 'unknown-date' |
|
777 | - * @return string |
|
778 | - */ |
|
779 | - private static function _get_most_recently_active_version_from_activation_history($activation_history) |
|
780 | - { |
|
781 | - $most_recently_active_version_activation = '1970-01-01 00:00:00'; |
|
782 | - $most_recently_active_version = '0.0.0.dev.000'; |
|
783 | - if (is_array($activation_history)) { |
|
784 | - foreach ($activation_history as $version => $times_activated) { |
|
785 | - //check there is a record of when this version was activated. Otherwise, |
|
786 | - //mark it as unknown |
|
787 | - if (! $times_activated) { |
|
788 | - $times_activated = array('unknown-date'); |
|
789 | - } |
|
790 | - if (is_string($times_activated)) { |
|
791 | - $times_activated = array($times_activated); |
|
792 | - } |
|
793 | - foreach ($times_activated as $an_activation) { |
|
794 | - if ($an_activation !== 'unknown-date' && $an_activation > $most_recently_active_version_activation) { |
|
795 | - $most_recently_active_version = $version; |
|
796 | - $most_recently_active_version_activation = $an_activation === 'unknown-date' |
|
797 | - ? '1970-01-01 00:00:00' |
|
798 | - : $an_activation; |
|
799 | - } |
|
800 | - } |
|
801 | - } |
|
802 | - } |
|
803 | - return $most_recently_active_version; |
|
804 | - } |
|
805 | - |
|
806 | - |
|
807 | - |
|
808 | - /** |
|
809 | - * This redirects to the about EE page after activation |
|
810 | - * |
|
811 | - * @return void |
|
812 | - */ |
|
813 | - public function redirect_to_about_ee() |
|
814 | - { |
|
815 | - $notices = EE_Error::get_notices(false); |
|
816 | - //if current user is an admin and it's not an ajax or rest request |
|
817 | - if ( |
|
818 | - ! (defined('DOING_AJAX') && DOING_AJAX) |
|
819 | - && ! (defined('REST_REQUEST') && REST_REQUEST) |
|
820 | - && ! isset($notices['errors']) |
|
821 | - && apply_filters( |
|
822 | - 'FHEE__EE_System__redirect_to_about_ee__do_redirect', |
|
823 | - $this->capabilities->current_user_can('manage_options', 'espresso_about_default') |
|
824 | - ) |
|
825 | - ) { |
|
826 | - $query_params = array('page' => 'espresso_about'); |
|
827 | - if (EE_System::instance()->detect_req_type() === EE_System::req_type_new_activation) { |
|
828 | - $query_params['new_activation'] = true; |
|
829 | - } |
|
830 | - if (EE_System::instance()->detect_req_type() === EE_System::req_type_reactivation) { |
|
831 | - $query_params['reactivation'] = true; |
|
832 | - } |
|
833 | - $url = add_query_arg($query_params, admin_url('admin.php')); |
|
834 | - wp_safe_redirect($url); |
|
835 | - exit(); |
|
836 | - } |
|
837 | - } |
|
838 | - |
|
839 | - |
|
840 | - |
|
841 | - /** |
|
842 | - * load_core_configuration |
|
843 | - * this is hooked into 'AHEE__EE_Bootstrap__load_core_configuration' |
|
844 | - * which runs during the WP 'plugins_loaded' action at priority 5 |
|
845 | - * |
|
846 | - * @return void |
|
847 | - * @throws ReflectionException |
|
848 | - */ |
|
849 | - public function load_core_configuration() |
|
850 | - { |
|
851 | - do_action('AHEE__EE_System__load_core_configuration__begin', $this); |
|
852 | - $this->loader->getShared('EE_Load_Textdomain'); |
|
853 | - //load textdomain |
|
854 | - EE_Load_Textdomain::load_textdomain(); |
|
855 | - // load and setup EE_Config and EE_Network_Config |
|
856 | - $config = $this->loader->getShared('EE_Config'); |
|
857 | - $this->loader->getShared('EE_Network_Config'); |
|
858 | - // setup autoloaders |
|
859 | - // enable logging? |
|
860 | - if ($config->admin->use_full_logging) { |
|
861 | - $this->loader->getShared('EE_Log'); |
|
862 | - } |
|
863 | - // check for activation errors |
|
864 | - $activation_errors = get_option('ee_plugin_activation_errors', false); |
|
865 | - if ($activation_errors) { |
|
866 | - EE_Error::add_error($activation_errors, __FILE__, __FUNCTION__, __LINE__); |
|
867 | - update_option('ee_plugin_activation_errors', false); |
|
868 | - } |
|
869 | - // get model names |
|
870 | - $this->_parse_model_names(); |
|
871 | - //load caf stuff a chance to play during the activation process too. |
|
872 | - $this->_maybe_brew_regular(); |
|
873 | - do_action('AHEE__EE_System__load_core_configuration__complete', $this); |
|
874 | - } |
|
875 | - |
|
876 | - |
|
877 | - |
|
878 | - /** |
|
879 | - * cycles through all of the models/*.model.php files, and assembles an array of model names |
|
880 | - * |
|
881 | - * @return void |
|
882 | - * @throws ReflectionException |
|
883 | - */ |
|
884 | - private function _parse_model_names() |
|
885 | - { |
|
886 | - //get all the files in the EE_MODELS folder that end in .model.php |
|
887 | - $models = glob(EE_MODELS . '*.model.php'); |
|
888 | - $model_names = array(); |
|
889 | - $non_abstract_db_models = array(); |
|
890 | - foreach ($models as $model) { |
|
891 | - // get model classname |
|
892 | - $classname = EEH_File::get_classname_from_filepath_with_standard_filename($model); |
|
893 | - $short_name = str_replace('EEM_', '', $classname); |
|
894 | - $reflectionClass = new ReflectionClass($classname); |
|
895 | - if ($reflectionClass->isSubclassOf('EEM_Base') && ! $reflectionClass->isAbstract()) { |
|
896 | - $non_abstract_db_models[$short_name] = $classname; |
|
897 | - } |
|
898 | - $model_names[$short_name] = $classname; |
|
899 | - } |
|
900 | - $this->registry->models = apply_filters('FHEE__EE_System__parse_model_names', $model_names); |
|
901 | - $this->registry->non_abstract_db_models = apply_filters( |
|
902 | - 'FHEE__EE_System__parse_implemented_model_names', |
|
903 | - $non_abstract_db_models |
|
904 | - ); |
|
905 | - } |
|
906 | - |
|
907 | - |
|
908 | - |
|
909 | - /** |
|
910 | - * The purpose of this method is to simply check for a file named "caffeinated/brewing_regular.php" for any hooks |
|
911 | - * that need to be setup before our EE_System launches. |
|
912 | - * |
|
913 | - * @return void |
|
914 | - */ |
|
915 | - private function _maybe_brew_regular() |
|
916 | - { |
|
917 | - if ((! defined('EE_DECAF') || EE_DECAF !== true) && is_readable(EE_CAFF_PATH . 'brewing_regular.php')) { |
|
918 | - require_once EE_CAFF_PATH . 'brewing_regular.php'; |
|
919 | - } |
|
920 | - } |
|
921 | - |
|
922 | - |
|
923 | - |
|
924 | - /** |
|
925 | - * register_shortcodes_modules_and_widgets |
|
926 | - * generate lists of shortcodes and modules, then verify paths and classes |
|
927 | - * This is hooked into 'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets' |
|
928 | - * which runs during the WP 'plugins_loaded' action at priority 7 |
|
929 | - * |
|
930 | - * @access public |
|
931 | - * @return void |
|
932 | - * @throws Exception |
|
933 | - */ |
|
934 | - public function register_shortcodes_modules_and_widgets() |
|
935 | - { |
|
936 | - try { |
|
937 | - // load, register, and add shortcodes the new way |
|
938 | - $this->loader->getShared( |
|
939 | - 'EventEspresso\core\services\shortcodes\ShortcodesManager', |
|
940 | - array( |
|
941 | - // and the old way, but we'll put it under control of the new system |
|
942 | - EE_Config::getLegacyShortcodesManager() |
|
943 | - ) |
|
944 | - ); |
|
945 | - } catch (Exception $exception) { |
|
946 | - new ExceptionStackTraceDisplay($exception); |
|
947 | - } |
|
948 | - do_action('AHEE__EE_System__register_shortcodes_modules_and_widgets'); |
|
949 | - // check for addons using old hook point |
|
950 | - if (has_action('AHEE__EE_System__register_shortcodes_modules_and_addons')) { |
|
951 | - $this->_incompatible_addon_error(); |
|
952 | - } |
|
953 | - } |
|
954 | - |
|
955 | - |
|
956 | - |
|
957 | - /** |
|
958 | - * _incompatible_addon_error |
|
959 | - * |
|
960 | - * @access public |
|
961 | - * @return void |
|
962 | - */ |
|
963 | - private function _incompatible_addon_error() |
|
964 | - { |
|
965 | - // get array of classes hooking into here |
|
966 | - $class_names = EEH_Class_Tools::get_class_names_for_all_callbacks_on_hook( |
|
967 | - 'AHEE__EE_System__register_shortcodes_modules_and_addons' |
|
968 | - ); |
|
969 | - if (! empty($class_names)) { |
|
970 | - $msg = __( |
|
971 | - 'The following plugins, addons, or modules appear to be incompatible with this version of Event Espresso and were automatically deactivated to avoid fatal errors:', |
|
972 | - 'event_espresso' |
|
973 | - ); |
|
974 | - $msg .= '<ul>'; |
|
975 | - foreach ($class_names as $class_name) { |
|
976 | - $msg .= '<li><b>Event Espresso - ' . str_replace( |
|
977 | - array('EE_', 'EEM_', 'EED_', 'EES_', 'EEW_'), '', |
|
978 | - $class_name |
|
979 | - ) . '</b></li>'; |
|
980 | - } |
|
981 | - $msg .= '</ul>'; |
|
982 | - $msg .= __( |
|
983 | - 'Compatibility issues can be avoided and/or resolved by keeping addons and plugins updated to the latest version.', |
|
984 | - 'event_espresso' |
|
985 | - ); |
|
986 | - // save list of incompatible addons to wp-options for later use |
|
987 | - add_option('ee_incompatible_addons', $class_names, '', 'no'); |
|
988 | - if (is_admin()) { |
|
989 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
990 | - } |
|
991 | - } |
|
992 | - } |
|
993 | - |
|
994 | - |
|
995 | - |
|
996 | - /** |
|
997 | - * brew_espresso |
|
998 | - * begins the process of setting hooks for initializing EE in the correct order |
|
999 | - * This is happening on the 'AHEE__EE_Bootstrap__brew_espresso' hook point |
|
1000 | - * which runs during the WP 'plugins_loaded' action at priority 9 |
|
1001 | - * |
|
1002 | - * @return void |
|
1003 | - */ |
|
1004 | - public function brew_espresso() |
|
1005 | - { |
|
1006 | - do_action('AHEE__EE_System__brew_espresso__begin', $this); |
|
1007 | - // load some final core systems |
|
1008 | - add_action('init', array($this, 'set_hooks_for_core'), 1); |
|
1009 | - add_action('init', array($this, 'perform_activations_upgrades_and_migrations'), 3); |
|
1010 | - add_action('init', array($this, 'load_CPTs_and_session'), 5); |
|
1011 | - add_action('init', array($this, 'load_controllers'), 7); |
|
1012 | - add_action('init', array($this, 'core_loaded_and_ready'), 9); |
|
1013 | - add_action('init', array($this, 'initialize'), 10); |
|
1014 | - add_action('init', array($this, 'initialize_last'), 100); |
|
1015 | - if (is_admin() && apply_filters('FHEE__EE_System__brew_espresso__load_pue', true)) { |
|
1016 | - // pew pew pew |
|
1017 | - $this->loader->getShared('EE_PUE'); |
|
1018 | - do_action('AHEE__EE_System__brew_espresso__after_pue_init'); |
|
1019 | - } |
|
1020 | - do_action('AHEE__EE_System__brew_espresso__complete', $this); |
|
1021 | - } |
|
1022 | - |
|
1023 | - |
|
1024 | - |
|
1025 | - /** |
|
1026 | - * set_hooks_for_core |
|
1027 | - * |
|
1028 | - * @access public |
|
1029 | - * @return void |
|
1030 | - * @throws EE_Error |
|
1031 | - */ |
|
1032 | - public function set_hooks_for_core() |
|
1033 | - { |
|
1034 | - $this->_deactivate_incompatible_addons(); |
|
1035 | - do_action('AHEE__EE_System__set_hooks_for_core'); |
|
1036 | - //caps need to be initialized on every request so that capability maps are set. |
|
1037 | - //@see https://events.codebasehq.com/projects/event-espresso/tickets/8674 |
|
1038 | - $this->registry->CAP->init_caps(); |
|
1039 | - } |
|
1040 | - |
|
1041 | - |
|
1042 | - |
|
1043 | - /** |
|
1044 | - * Using the information gathered in EE_System::_incompatible_addon_error, |
|
1045 | - * deactivates any addons considered incompatible with the current version of EE |
|
1046 | - */ |
|
1047 | - private function _deactivate_incompatible_addons() |
|
1048 | - { |
|
1049 | - $incompatible_addons = get_option('ee_incompatible_addons', array()); |
|
1050 | - if (! empty($incompatible_addons)) { |
|
1051 | - $active_plugins = get_option('active_plugins', array()); |
|
1052 | - foreach ($active_plugins as $active_plugin) { |
|
1053 | - foreach ($incompatible_addons as $incompatible_addon) { |
|
1054 | - if (strpos($active_plugin, $incompatible_addon) !== false) { |
|
1055 | - unset($_GET['activate']); |
|
1056 | - espresso_deactivate_plugin($active_plugin); |
|
1057 | - } |
|
1058 | - } |
|
1059 | - } |
|
1060 | - } |
|
1061 | - } |
|
1062 | - |
|
1063 | - |
|
1064 | - |
|
1065 | - /** |
|
1066 | - * perform_activations_upgrades_and_migrations |
|
1067 | - * |
|
1068 | - * @access public |
|
1069 | - * @return void |
|
1070 | - */ |
|
1071 | - public function perform_activations_upgrades_and_migrations() |
|
1072 | - { |
|
1073 | - //first check if we had previously attempted to setup EE's directories but failed |
|
1074 | - if (EEH_Activation::upload_directories_incomplete()) { |
|
1075 | - EEH_Activation::create_upload_directories(); |
|
1076 | - } |
|
1077 | - do_action('AHEE__EE_System__perform_activations_upgrades_and_migrations'); |
|
1078 | - } |
|
1079 | - |
|
1080 | - |
|
1081 | - |
|
1082 | - /** |
|
1083 | - * load_CPTs_and_session |
|
1084 | - * |
|
1085 | - * @access public |
|
1086 | - * @return void |
|
1087 | - */ |
|
1088 | - public function load_CPTs_and_session() |
|
1089 | - { |
|
1090 | - do_action('AHEE__EE_System__load_CPTs_and_session__start'); |
|
1091 | - // register Custom Post Types |
|
1092 | - $this->loader->getShared('EE_Register_CPTs'); |
|
1093 | - do_action('AHEE__EE_System__load_CPTs_and_session__complete'); |
|
1094 | - } |
|
1095 | - |
|
1096 | - |
|
1097 | - |
|
1098 | - /** |
|
1099 | - * load_controllers |
|
1100 | - * this is the best place to load any additional controllers that needs access to EE core. |
|
1101 | - * it is expected that all basic core EE systems, that are not dependant on the current request are loaded at this |
|
1102 | - * time |
|
1103 | - * |
|
1104 | - * @access public |
|
1105 | - * @return void |
|
1106 | - */ |
|
1107 | - public function load_controllers() |
|
1108 | - { |
|
1109 | - do_action('AHEE__EE_System__load_controllers__start'); |
|
1110 | - // let's get it started |
|
1111 | - if (! is_admin() && ! $this->maintenance_mode->level()) { |
|
1112 | - do_action('AHEE__EE_System__load_controllers__load_front_controllers'); |
|
1113 | - $this->loader->getShared('EE_Front_Controller'); |
|
1114 | - } else if (! EE_FRONT_AJAX) { |
|
1115 | - do_action('AHEE__EE_System__load_controllers__load_admin_controllers'); |
|
1116 | - $this->loader->getShared('EE_Admin'); |
|
1117 | - } |
|
1118 | - do_action('AHEE__EE_System__load_controllers__complete'); |
|
1119 | - } |
|
1120 | - |
|
1121 | - |
|
1122 | - |
|
1123 | - /** |
|
1124 | - * core_loaded_and_ready |
|
1125 | - * all of the basic EE core should be loaded at this point and available regardless of M-Mode |
|
1126 | - * |
|
1127 | - * @access public |
|
1128 | - * @return void |
|
1129 | - */ |
|
1130 | - public function core_loaded_and_ready() |
|
1131 | - { |
|
1132 | - $this->loader->getShared('EE_Session'); |
|
1133 | - do_action('AHEE__EE_System__core_loaded_and_ready'); |
|
1134 | - // load_espresso_template_tags |
|
1135 | - if (is_readable(EE_PUBLIC . 'template_tags.php')) { |
|
1136 | - require_once(EE_PUBLIC . 'template_tags.php'); |
|
1137 | - } |
|
1138 | - do_action('AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons'); |
|
1139 | - $this->loader->getShared('EventEspresso\core\services\assets\Registry'); |
|
1140 | - } |
|
1141 | - |
|
1142 | - |
|
1143 | - |
|
1144 | - /** |
|
1145 | - * initialize |
|
1146 | - * this is the best place to begin initializing client code |
|
1147 | - * |
|
1148 | - * @access public |
|
1149 | - * @return void |
|
1150 | - */ |
|
1151 | - public function initialize() |
|
1152 | - { |
|
1153 | - do_action('AHEE__EE_System__initialize'); |
|
1154 | - } |
|
1155 | - |
|
1156 | - |
|
1157 | - |
|
1158 | - /** |
|
1159 | - * initialize_last |
|
1160 | - * this is run really late during the WP init hook point, and ensures that mostly everything else that needs to |
|
1161 | - * initialize has done so |
|
1162 | - * |
|
1163 | - * @access public |
|
1164 | - * @return void |
|
1165 | - */ |
|
1166 | - public function initialize_last() |
|
1167 | - { |
|
1168 | - do_action('AHEE__EE_System__initialize_last'); |
|
1169 | - add_action('admin_bar_init', array($this, 'addEspressoToolbar')); |
|
1170 | - } |
|
1171 | - |
|
1172 | - |
|
1173 | - |
|
1174 | - /** |
|
1175 | - * @return void |
|
1176 | - * @throws EE_Error |
|
1177 | - */ |
|
1178 | - public function addEspressoToolbar() |
|
1179 | - { |
|
1180 | - $this->loader->getShared( |
|
1181 | - 'EventEspresso\core\domain\services\admin\AdminToolBar', |
|
1182 | - array($this->registry->CAP) |
|
1183 | - ); |
|
1184 | - } |
|
1185 | - |
|
1186 | - |
|
1187 | - |
|
1188 | - /** |
|
1189 | - * do_not_cache |
|
1190 | - * sets no cache headers and defines no cache constants for WP plugins |
|
1191 | - * |
|
1192 | - * @access public |
|
1193 | - * @return void |
|
1194 | - */ |
|
1195 | - public static function do_not_cache() |
|
1196 | - { |
|
1197 | - // set no cache constants |
|
1198 | - if (! defined('DONOTCACHEPAGE')) { |
|
1199 | - define('DONOTCACHEPAGE', true); |
|
1200 | - } |
|
1201 | - if (! defined('DONOTCACHCEOBJECT')) { |
|
1202 | - define('DONOTCACHCEOBJECT', true); |
|
1203 | - } |
|
1204 | - if (! defined('DONOTCACHEDB')) { |
|
1205 | - define('DONOTCACHEDB', true); |
|
1206 | - } |
|
1207 | - // add no cache headers |
|
1208 | - add_action('send_headers', array('EE_System', 'nocache_headers'), 10); |
|
1209 | - // plus a little extra for nginx and Google Chrome |
|
1210 | - add_filter('nocache_headers', array('EE_System', 'extra_nocache_headers'), 10, 1); |
|
1211 | - // prevent browsers from prefetching of the rel='next' link, because it may contain content that interferes with the registration process |
|
1212 | - remove_action('wp_head', 'adjacent_posts_rel_link_wp_head'); |
|
1213 | - } |
|
1214 | - |
|
1215 | - |
|
1216 | - |
|
1217 | - /** |
|
1218 | - * extra_nocache_headers |
|
1219 | - * |
|
1220 | - * @access public |
|
1221 | - * @param $headers |
|
1222 | - * @return array |
|
1223 | - */ |
|
1224 | - public static function extra_nocache_headers($headers) |
|
1225 | - { |
|
1226 | - // for NGINX |
|
1227 | - $headers['X-Accel-Expires'] = 0; |
|
1228 | - // plus extra for Google Chrome since it doesn't seem to respect "no-cache", but WILL respect "no-store" |
|
1229 | - $headers['Cache-Control'] = 'no-store, no-cache, must-revalidate, max-age=0'; |
|
1230 | - return $headers; |
|
1231 | - } |
|
1232 | - |
|
1233 | - |
|
1234 | - |
|
1235 | - /** |
|
1236 | - * nocache_headers |
|
1237 | - * |
|
1238 | - * @access public |
|
1239 | - * @return void |
|
1240 | - */ |
|
1241 | - public static function nocache_headers() |
|
1242 | - { |
|
1243 | - nocache_headers(); |
|
1244 | - } |
|
1245 | - |
|
1246 | - |
|
1247 | - |
|
1248 | - |
|
1249 | - /** |
|
1250 | - * simply hooks into "wp_list_pages_exclude" filter (for wp_list_pages method) and makes sure EE critical pages are |
|
1251 | - * never returned with the function. |
|
1252 | - * |
|
1253 | - * @param array $exclude_array any existing pages being excluded are in this array. |
|
1254 | - * @return array |
|
1255 | - */ |
|
1256 | - public function remove_pages_from_wp_list_pages($exclude_array) |
|
1257 | - { |
|
1258 | - return array_merge($exclude_array, $this->registry->CFG->core->get_critical_pages_array()); |
|
1259 | - } |
|
24 | + /** |
|
25 | + * indicates this is a 'normal' request. Ie, not activation, nor upgrade, nor activation. |
|
26 | + * So examples of this would be a normal GET request on the frontend or backend, or a POST, etc |
|
27 | + */ |
|
28 | + const req_type_normal = 0; |
|
29 | + |
|
30 | + /** |
|
31 | + * Indicates this is a brand new installation of EE so we should install |
|
32 | + * tables and default data etc |
|
33 | + */ |
|
34 | + const req_type_new_activation = 1; |
|
35 | + |
|
36 | + /** |
|
37 | + * we've detected that EE has been reactivated (or EE was activated during maintenance mode, |
|
38 | + * and we just exited maintenance mode). We MUST check the database is setup properly |
|
39 | + * and that default data is setup too |
|
40 | + */ |
|
41 | + const req_type_reactivation = 2; |
|
42 | + |
|
43 | + /** |
|
44 | + * indicates that EE has been upgraded since its previous request. |
|
45 | + * We may have data migration scripts to call and will want to trigger maintenance mode |
|
46 | + */ |
|
47 | + const req_type_upgrade = 3; |
|
48 | + |
|
49 | + /** |
|
50 | + * TODO will detect that EE has been DOWNGRADED. We probably don't want to run in this case... |
|
51 | + */ |
|
52 | + const req_type_downgrade = 4; |
|
53 | + |
|
54 | + /** |
|
55 | + * @deprecated since version 4.6.0.dev.006 |
|
56 | + * Now whenever a new_activation is detected the request type is still just |
|
57 | + * new_activation (same for reactivation, upgrade, downgrade etc), but if we'r ein maintenance mode |
|
58 | + * EE_System::initialize_db_if_no_migrations_required and EE_Addon::initialize_db_if_no_migrations_required |
|
59 | + * will instead enqueue that EE plugin's db initialization for when we're taken out of maintenance mode. |
|
60 | + * (Specifically, when the migration manager indicates migrations are finished |
|
61 | + * EE_Data_Migration_Manager::initialize_db_for_enqueued_ee_plugins() will be called) |
|
62 | + */ |
|
63 | + const req_type_activation_but_not_installed = 5; |
|
64 | + |
|
65 | + /** |
|
66 | + * option prefix for recording the activation history (like core's "espresso_db_update") of addons |
|
67 | + */ |
|
68 | + const addon_activation_history_option_prefix = 'ee_addon_activation_history_'; |
|
69 | + |
|
70 | + |
|
71 | + /** |
|
72 | + * @var EE_System $_instance |
|
73 | + */ |
|
74 | + private static $_instance; |
|
75 | + |
|
76 | + /** |
|
77 | + * @var EE_Registry $registry |
|
78 | + */ |
|
79 | + private $registry; |
|
80 | + |
|
81 | + /** |
|
82 | + * @var LoaderInterface $loader |
|
83 | + */ |
|
84 | + private $loader; |
|
85 | + |
|
86 | + /** |
|
87 | + * @var EE_Capabilities $capabilities |
|
88 | + */ |
|
89 | + private $capabilities; |
|
90 | + |
|
91 | + /** |
|
92 | + * @var EE_Request $request |
|
93 | + */ |
|
94 | + private $request; |
|
95 | + |
|
96 | + /** |
|
97 | + * @var EE_Maintenance_Mode $maintenance_mode |
|
98 | + */ |
|
99 | + private $maintenance_mode; |
|
100 | + |
|
101 | + /** |
|
102 | + * Stores which type of request this is, options being one of the constants on EE_System starting with req_type_*. |
|
103 | + * It can be a brand-new activation, a reactivation, an upgrade, a downgrade, or a normal request. |
|
104 | + * |
|
105 | + * @var int $_req_type |
|
106 | + */ |
|
107 | + private $_req_type; |
|
108 | + |
|
109 | + /** |
|
110 | + * Whether or not there was a non-micro version change in EE core version during this request |
|
111 | + * |
|
112 | + * @var boolean $_major_version_change |
|
113 | + */ |
|
114 | + private $_major_version_change = false; |
|
115 | + |
|
116 | + |
|
117 | + |
|
118 | + /** |
|
119 | + * @singleton method used to instantiate class object |
|
120 | + * @param EE_Registry|null $registry |
|
121 | + * @param LoaderInterface|null $loader |
|
122 | + * @param EE_Capabilities|null $capabilities |
|
123 | + * @param EE_Request|null $request |
|
124 | + * @param EE_Maintenance_Mode|null $maintenance_mode |
|
125 | + * @return EE_System |
|
126 | + */ |
|
127 | + public static function instance( |
|
128 | + EE_Registry $registry = null, |
|
129 | + LoaderInterface $loader = null, |
|
130 | + EE_Capabilities $capabilities = null, |
|
131 | + EE_Request $request = null, |
|
132 | + EE_Maintenance_Mode $maintenance_mode = null |
|
133 | + ) { |
|
134 | + // check if class object is instantiated |
|
135 | + if (! self::$_instance instanceof EE_System) { |
|
136 | + self::$_instance = new self($registry, $loader, $capabilities, $request, $maintenance_mode); |
|
137 | + } |
|
138 | + return self::$_instance; |
|
139 | + } |
|
140 | + |
|
141 | + |
|
142 | + |
|
143 | + /** |
|
144 | + * resets the instance and returns it |
|
145 | + * |
|
146 | + * @return EE_System |
|
147 | + */ |
|
148 | + public static function reset() |
|
149 | + { |
|
150 | + self::$_instance->_req_type = null; |
|
151 | + //make sure none of the old hooks are left hanging around |
|
152 | + remove_all_actions('AHEE__EE_System__perform_activations_upgrades_and_migrations'); |
|
153 | + //we need to reset the migration manager in order for it to detect DMSs properly |
|
154 | + EE_Data_Migration_Manager::reset(); |
|
155 | + self::instance()->detect_activations_or_upgrades(); |
|
156 | + self::instance()->perform_activations_upgrades_and_migrations(); |
|
157 | + return self::instance(); |
|
158 | + } |
|
159 | + |
|
160 | + |
|
161 | + |
|
162 | + /** |
|
163 | + * sets hooks for running rest of system |
|
164 | + * provides "AHEE__EE_System__construct__complete" hook for EE Addons to use as their starting point |
|
165 | + * starting EE Addons from any other point may lead to problems |
|
166 | + * |
|
167 | + * @param EE_Registry $registry |
|
168 | + * @param LoaderInterface $loader |
|
169 | + * @param EE_Capabilities $capabilities |
|
170 | + * @param EE_Request $request |
|
171 | + * @param EE_Maintenance_Mode $maintenance_mode |
|
172 | + */ |
|
173 | + private function __construct( |
|
174 | + EE_Registry $registry, |
|
175 | + LoaderInterface $loader, |
|
176 | + EE_Capabilities $capabilities, |
|
177 | + EE_Request $request, |
|
178 | + EE_Maintenance_Mode $maintenance_mode |
|
179 | + ) { |
|
180 | + $this->registry = $registry; |
|
181 | + $this->loader = $loader; |
|
182 | + $this->capabilities = $capabilities; |
|
183 | + $this->request = $request; |
|
184 | + $this->maintenance_mode = $maintenance_mode; |
|
185 | + do_action('AHEE__EE_System__construct__begin', $this); |
|
186 | + add_action( |
|
187 | + 'AHEE__EE_Bootstrap__load_espresso_addons', |
|
188 | + array($this, 'loadCapabilities'), |
|
189 | + 5 |
|
190 | + ); |
|
191 | + add_action( |
|
192 | + 'AHEE__EE_Bootstrap__load_espresso_addons', |
|
193 | + array($this, 'loadCommandBus'), |
|
194 | + 7 |
|
195 | + ); |
|
196 | + add_action( |
|
197 | + 'AHEE__EE_Bootstrap__load_espresso_addons', |
|
198 | + array($this, 'loadPluginApi'), |
|
199 | + 9 |
|
200 | + ); |
|
201 | + // allow addons to load first so that they can register autoloaders, set hooks for running DMS's, etc |
|
202 | + add_action( |
|
203 | + 'AHEE__EE_Bootstrap__load_espresso_addons', |
|
204 | + array($this, 'load_espresso_addons') |
|
205 | + ); |
|
206 | + // when an ee addon is activated, we want to call the core hook(s) again |
|
207 | + // because the newly-activated addon didn't get a chance to run at all |
|
208 | + add_action('activate_plugin', array($this, 'load_espresso_addons'), 1); |
|
209 | + // detect whether install or upgrade |
|
210 | + add_action( |
|
211 | + 'AHEE__EE_Bootstrap__detect_activations_or_upgrades', |
|
212 | + array($this, 'detect_activations_or_upgrades'), |
|
213 | + 3 |
|
214 | + ); |
|
215 | + // load EE_Config, EE_Textdomain, etc |
|
216 | + add_action( |
|
217 | + 'AHEE__EE_Bootstrap__load_core_configuration', |
|
218 | + array($this, 'load_core_configuration'), |
|
219 | + 5 |
|
220 | + ); |
|
221 | + // load EE_Config, EE_Textdomain, etc |
|
222 | + add_action( |
|
223 | + 'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets', |
|
224 | + array($this, 'register_shortcodes_modules_and_widgets'), |
|
225 | + 7 |
|
226 | + ); |
|
227 | + // you wanna get going? I wanna get going... let's get going! |
|
228 | + add_action( |
|
229 | + 'AHEE__EE_Bootstrap__brew_espresso', |
|
230 | + array($this, 'brew_espresso'), |
|
231 | + 9 |
|
232 | + ); |
|
233 | + //other housekeeping |
|
234 | + //exclude EE critical pages from wp_list_pages |
|
235 | + add_filter( |
|
236 | + 'wp_list_pages_excludes', |
|
237 | + array($this, 'remove_pages_from_wp_list_pages'), |
|
238 | + 10 |
|
239 | + ); |
|
240 | + // ALL EE Addons should use the following hook point to attach their initial setup too |
|
241 | + // it's extremely important for EE Addons to register any class autoloaders so that they can be available when the EE_Config loads |
|
242 | + do_action('AHEE__EE_System__construct__complete', $this); |
|
243 | + } |
|
244 | + |
|
245 | + |
|
246 | + |
|
247 | + /** |
|
248 | + * load and setup EE_Capabilities |
|
249 | + * |
|
250 | + * @return void |
|
251 | + * @throws EE_Error |
|
252 | + */ |
|
253 | + public function loadCapabilities() |
|
254 | + { |
|
255 | + $this->loader->getShared('EE_Capabilities'); |
|
256 | + add_action( |
|
257 | + 'AHEE__EE_Capabilities__init_caps__before_initialization', |
|
258 | + function() { |
|
259 | + LoaderFactory::getLoader()->getShared('EE_Payment_Method_Manager'); |
|
260 | + } |
|
261 | + ); |
|
262 | + } |
|
263 | + |
|
264 | + |
|
265 | + |
|
266 | + /** |
|
267 | + * create and cache the CommandBus, and also add middleware |
|
268 | + * The CapChecker middleware requires the use of EE_Capabilities |
|
269 | + * which is why we need to load the CommandBus after Caps are set up |
|
270 | + * |
|
271 | + * @return void |
|
272 | + * @throws EE_Error |
|
273 | + */ |
|
274 | + public function loadCommandBus() |
|
275 | + { |
|
276 | + $this->loader->getShared( |
|
277 | + 'CommandBusInterface', |
|
278 | + array( |
|
279 | + null, |
|
280 | + apply_filters( |
|
281 | + 'FHEE__EE_Load_Espresso_Core__handle_request__CommandBus_middleware', |
|
282 | + array( |
|
283 | + $this->loader->getShared('EventEspresso\core\services\commands\middleware\CapChecker'), |
|
284 | + $this->loader->getShared('EventEspresso\core\services\commands\middleware\AddActionHook'), |
|
285 | + ) |
|
286 | + ), |
|
287 | + ) |
|
288 | + ); |
|
289 | + } |
|
290 | + |
|
291 | + |
|
292 | + |
|
293 | + /** |
|
294 | + * @return void |
|
295 | + * @throws EE_Error |
|
296 | + */ |
|
297 | + public function loadPluginApi() |
|
298 | + { |
|
299 | + // set autoloaders for all of the classes implementing EEI_Plugin_API |
|
300 | + // which provide helpers for EE plugin authors to more easily register certain components with EE. |
|
301 | + EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'plugin_api'); |
|
302 | + } |
|
303 | + |
|
304 | + |
|
305 | + /** |
|
306 | + * @param string $addon_name |
|
307 | + * @param string $version_constant |
|
308 | + * @param string $min_version_required |
|
309 | + * @param string $load_callback |
|
310 | + * @param string $plugin_file_constant |
|
311 | + * @return void |
|
312 | + */ |
|
313 | + private function deactivateIncompatibleAddon( |
|
314 | + $addon_name, |
|
315 | + $version_constant, |
|
316 | + $min_version_required, |
|
317 | + $load_callback, |
|
318 | + $plugin_file_constant |
|
319 | + ) { |
|
320 | + if (! defined($version_constant)) { |
|
321 | + return; |
|
322 | + } |
|
323 | + $addon_version = constant($version_constant); |
|
324 | + if ($addon_version && version_compare($addon_version, $min_version_required, '<')) { |
|
325 | + remove_action('AHEE__EE_System__load_espresso_addons', $load_callback); |
|
326 | + if (! function_exists('deactivate_plugins')) { |
|
327 | + require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
328 | + } |
|
329 | + deactivate_plugins(plugin_basename(constant($plugin_file_constant))); |
|
330 | + unset($_GET['activate'], $_REQUEST['activate'], $_GET['activate-multi'], $_REQUEST['activate-multi']); |
|
331 | + EE_Error::add_error( |
|
332 | + sprintf( |
|
333 | + esc_html__( |
|
334 | + 'We\'re sorry, but the Event Espresso %1$s addon was deactivated because version %2$s or higher is required with this version of Event Espresso core.', |
|
335 | + 'event_espresso' |
|
336 | + ), |
|
337 | + $addon_name, |
|
338 | + $min_version_required |
|
339 | + ), |
|
340 | + __FILE__, __FUNCTION__ . "({$addon_name})", __LINE__ |
|
341 | + ); |
|
342 | + EE_Error::get_notices(false, true); |
|
343 | + } |
|
344 | + } |
|
345 | + |
|
346 | + |
|
347 | + /** |
|
348 | + * load_espresso_addons |
|
349 | + * allow addons to load first so that they can set hooks for running DMS's, etc |
|
350 | + * this is hooked into both: |
|
351 | + * 'AHEE__EE_Bootstrap__load_core_configuration' |
|
352 | + * which runs during the WP 'plugins_loaded' action at priority 5 |
|
353 | + * and the WP 'activate_plugin' hook point |
|
354 | + * |
|
355 | + * @access public |
|
356 | + * @return void |
|
357 | + */ |
|
358 | + public function load_espresso_addons() |
|
359 | + { |
|
360 | + $this->deactivateIncompatibleAddon( |
|
361 | + 'Wait Lists', |
|
362 | + 'EE_WAIT_LISTS_VERSION', |
|
363 | + '1.0.0.beta.074', |
|
364 | + 'load_espresso_wait_lists', |
|
365 | + 'EE_WAIT_LISTS_PLUGIN_FILE' |
|
366 | + ); |
|
367 | + $this->deactivateIncompatibleAddon( |
|
368 | + 'Automated Upcoming Event Notifications', |
|
369 | + 'EE_AUTOMATED_UPCOMING_EVENT_NOTIFICATION_VERSION', |
|
370 | + '1.0.0.beta.091', |
|
371 | + 'load_espresso_automated_upcoming_event_notification', |
|
372 | + 'EE_AUTOMATED_UPCOMING_EVENT_NOTIFICATION_PLUGIN_FILE' |
|
373 | + ); |
|
374 | + do_action('AHEE__EE_System__load_espresso_addons'); |
|
375 | + //if the WP API basic auth plugin isn't already loaded, load it now. |
|
376 | + //We want it for mobile apps. Just include the entire plugin |
|
377 | + //also, don't load the basic auth when a plugin is getting activated, because |
|
378 | + //it could be the basic auth plugin, and it doesn't check if its methods are already defined |
|
379 | + //and causes a fatal error |
|
380 | + if ( |
|
381 | + ! ( |
|
382 | + isset($_GET['activate']) |
|
383 | + && $_GET['activate'] === 'true' |
|
384 | + ) |
|
385 | + && ! function_exists('json_basic_auth_handler') |
|
386 | + && ! function_exists('json_basic_auth_error') |
|
387 | + && ! ( |
|
388 | + isset($_GET['action']) |
|
389 | + && in_array($_GET['action'], array('activate', 'activate-selected'), true) |
|
390 | + ) |
|
391 | + ) { |
|
392 | + include_once EE_THIRD_PARTY . 'wp-api-basic-auth' . DS . 'basic-auth.php'; |
|
393 | + } |
|
394 | + do_action('AHEE__EE_System__load_espresso_addons__complete'); |
|
395 | + } |
|
396 | + |
|
397 | + |
|
398 | + |
|
399 | + /** |
|
400 | + * detect_activations_or_upgrades |
|
401 | + * Checks for activation or upgrade of core first; |
|
402 | + * then also checks if any registered addons have been activated or upgraded |
|
403 | + * This is hooked into 'AHEE__EE_Bootstrap__detect_activations_or_upgrades' |
|
404 | + * which runs during the WP 'plugins_loaded' action at priority 3 |
|
405 | + * |
|
406 | + * @access public |
|
407 | + * @return void |
|
408 | + */ |
|
409 | + public function detect_activations_or_upgrades() |
|
410 | + { |
|
411 | + //first off: let's make sure to handle core |
|
412 | + $this->detect_if_activation_or_upgrade(); |
|
413 | + foreach ($this->registry->addons as $addon) { |
|
414 | + if ($addon instanceof EE_Addon) { |
|
415 | + //detect teh request type for that addon |
|
416 | + $addon->detect_activation_or_upgrade(); |
|
417 | + } |
|
418 | + } |
|
419 | + } |
|
420 | + |
|
421 | + |
|
422 | + |
|
423 | + /** |
|
424 | + * detect_if_activation_or_upgrade |
|
425 | + * Takes care of detecting whether this is a brand new install or code upgrade, |
|
426 | + * and either setting up the DB or setting up maintenance mode etc. |
|
427 | + * |
|
428 | + * @access public |
|
429 | + * @return void |
|
430 | + */ |
|
431 | + public function detect_if_activation_or_upgrade() |
|
432 | + { |
|
433 | + do_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin'); |
|
434 | + // check if db has been updated, or if its a brand-new installation |
|
435 | + $espresso_db_update = $this->fix_espresso_db_upgrade_option(); |
|
436 | + $request_type = $this->detect_req_type($espresso_db_update); |
|
437 | + //EEH_Debug_Tools::printr( $request_type, '$request_type', __FILE__, __LINE__ ); |
|
438 | + switch ($request_type) { |
|
439 | + case EE_System::req_type_new_activation: |
|
440 | + do_action('AHEE__EE_System__detect_if_activation_or_upgrade__new_activation'); |
|
441 | + $this->_handle_core_version_change($espresso_db_update); |
|
442 | + break; |
|
443 | + case EE_System::req_type_reactivation: |
|
444 | + do_action('AHEE__EE_System__detect_if_activation_or_upgrade__reactivation'); |
|
445 | + $this->_handle_core_version_change($espresso_db_update); |
|
446 | + break; |
|
447 | + case EE_System::req_type_upgrade: |
|
448 | + do_action('AHEE__EE_System__detect_if_activation_or_upgrade__upgrade'); |
|
449 | + //migrations may be required now that we've upgraded |
|
450 | + $this->maintenance_mode->set_maintenance_mode_if_db_old(); |
|
451 | + $this->_handle_core_version_change($espresso_db_update); |
|
452 | + // echo "done upgrade";die; |
|
453 | + break; |
|
454 | + case EE_System::req_type_downgrade: |
|
455 | + do_action('AHEE__EE_System__detect_if_activation_or_upgrade__downgrade'); |
|
456 | + //its possible migrations are no longer required |
|
457 | + $this->maintenance_mode->set_maintenance_mode_if_db_old(); |
|
458 | + $this->_handle_core_version_change($espresso_db_update); |
|
459 | + break; |
|
460 | + case EE_System::req_type_normal: |
|
461 | + default: |
|
462 | + // $this->_maybe_redirect_to_ee_about(); |
|
463 | + break; |
|
464 | + } |
|
465 | + do_action('AHEE__EE_System__detect_if_activation_or_upgrade__complete'); |
|
466 | + } |
|
467 | + |
|
468 | + |
|
469 | + |
|
470 | + /** |
|
471 | + * Updates the list of installed versions and sets hooks for |
|
472 | + * initializing the database later during the request |
|
473 | + * |
|
474 | + * @param array $espresso_db_update |
|
475 | + */ |
|
476 | + private function _handle_core_version_change($espresso_db_update) |
|
477 | + { |
|
478 | + $this->update_list_of_installed_versions($espresso_db_update); |
|
479 | + //get ready to verify the DB is ok (provided we aren't in maintenance mode, of course) |
|
480 | + add_action( |
|
481 | + 'AHEE__EE_System__perform_activations_upgrades_and_migrations', |
|
482 | + array($this, 'initialize_db_if_no_migrations_required') |
|
483 | + ); |
|
484 | + } |
|
485 | + |
|
486 | + |
|
487 | + |
|
488 | + /** |
|
489 | + * standardizes the wp option 'espresso_db_upgrade' which actually stores |
|
490 | + * information about what versions of EE have been installed and activated, |
|
491 | + * NOT necessarily the state of the database |
|
492 | + * |
|
493 | + * @param mixed $espresso_db_update the value of the WordPress option. |
|
494 | + * If not supplied, fetches it from the options table |
|
495 | + * @return array the correct value of 'espresso_db_upgrade', after saving it, if it needed correction |
|
496 | + */ |
|
497 | + private function fix_espresso_db_upgrade_option($espresso_db_update = null) |
|
498 | + { |
|
499 | + do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__begin', $espresso_db_update); |
|
500 | + if (! $espresso_db_update) { |
|
501 | + $espresso_db_update = get_option('espresso_db_update'); |
|
502 | + } |
|
503 | + // check that option is an array |
|
504 | + if (! is_array($espresso_db_update)) { |
|
505 | + // if option is FALSE, then it never existed |
|
506 | + if ($espresso_db_update === false) { |
|
507 | + // make $espresso_db_update an array and save option with autoload OFF |
|
508 | + $espresso_db_update = array(); |
|
509 | + add_option('espresso_db_update', $espresso_db_update, '', 'no'); |
|
510 | + } else { |
|
511 | + // option is NOT FALSE but also is NOT an array, so make it an array and save it |
|
512 | + $espresso_db_update = array($espresso_db_update => array()); |
|
513 | + update_option('espresso_db_update', $espresso_db_update); |
|
514 | + } |
|
515 | + } else { |
|
516 | + $corrected_db_update = array(); |
|
517 | + //if IS an array, but is it an array where KEYS are version numbers, and values are arrays? |
|
518 | + foreach ($espresso_db_update as $should_be_version_string => $should_be_array) { |
|
519 | + if (is_int($should_be_version_string) && ! is_array($should_be_array)) { |
|
520 | + //the key is an int, and the value IS NOT an array |
|
521 | + //so it must be numerically-indexed, where values are versions installed... |
|
522 | + //fix it! |
|
523 | + $version_string = $should_be_array; |
|
524 | + $corrected_db_update[$version_string] = array('unknown-date'); |
|
525 | + } else { |
|
526 | + //ok it checks out |
|
527 | + $corrected_db_update[$should_be_version_string] = $should_be_array; |
|
528 | + } |
|
529 | + } |
|
530 | + $espresso_db_update = $corrected_db_update; |
|
531 | + update_option('espresso_db_update', $espresso_db_update); |
|
532 | + } |
|
533 | + do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__complete', $espresso_db_update); |
|
534 | + return $espresso_db_update; |
|
535 | + } |
|
536 | + |
|
537 | + |
|
538 | + |
|
539 | + /** |
|
540 | + * Does the traditional work of setting up the plugin's database and adding default data. |
|
541 | + * If migration script/process did not exist, this is what would happen on every activation/reactivation/upgrade. |
|
542 | + * NOTE: if we're in maintenance mode (which would be the case if we detect there are data |
|
543 | + * migration scripts that need to be run and a version change happens), enqueues core for database initialization, |
|
544 | + * so that it will be done when migrations are finished |
|
545 | + * |
|
546 | + * @param boolean $initialize_addons_too if true, we double-check addons' database tables etc too; |
|
547 | + * @param boolean $verify_schema if true will re-check the database tables have the correct schema. |
|
548 | + * This is a resource-intensive job |
|
549 | + * so we prefer to only do it when necessary |
|
550 | + * @return void |
|
551 | + * @throws EE_Error |
|
552 | + */ |
|
553 | + public function initialize_db_if_no_migrations_required($initialize_addons_too = false, $verify_schema = true) |
|
554 | + { |
|
555 | + $request_type = $this->detect_req_type(); |
|
556 | + //only initialize system if we're not in maintenance mode. |
|
557 | + if ($this->maintenance_mode->level() !== EE_Maintenance_Mode::level_2_complete_maintenance) { |
|
558 | + update_option('ee_flush_rewrite_rules', true); |
|
559 | + if ($verify_schema) { |
|
560 | + EEH_Activation::initialize_db_and_folders(); |
|
561 | + } |
|
562 | + EEH_Activation::initialize_db_content(); |
|
563 | + EEH_Activation::system_initialization(); |
|
564 | + if ($initialize_addons_too) { |
|
565 | + $this->initialize_addons(); |
|
566 | + } |
|
567 | + } else { |
|
568 | + EE_Data_Migration_Manager::instance()->enqueue_db_initialization_for('Core'); |
|
569 | + } |
|
570 | + if ($request_type === EE_System::req_type_new_activation |
|
571 | + || $request_type === EE_System::req_type_reactivation |
|
572 | + || ( |
|
573 | + $request_type === EE_System::req_type_upgrade |
|
574 | + && $this->is_major_version_change() |
|
575 | + ) |
|
576 | + ) { |
|
577 | + add_action('AHEE__EE_System__initialize_last', array($this, 'redirect_to_about_ee'), 9); |
|
578 | + } |
|
579 | + } |
|
580 | + |
|
581 | + |
|
582 | + |
|
583 | + /** |
|
584 | + * Initializes the db for all registered addons |
|
585 | + * |
|
586 | + * @throws EE_Error |
|
587 | + */ |
|
588 | + public function initialize_addons() |
|
589 | + { |
|
590 | + //foreach registered addon, make sure its db is up-to-date too |
|
591 | + foreach ($this->registry->addons as $addon) { |
|
592 | + if ($addon instanceof EE_Addon) { |
|
593 | + $addon->initialize_db_if_no_migrations_required(); |
|
594 | + } |
|
595 | + } |
|
596 | + } |
|
597 | + |
|
598 | + |
|
599 | + |
|
600 | + /** |
|
601 | + * Adds the current code version to the saved wp option which stores a list of all ee versions ever installed. |
|
602 | + * |
|
603 | + * @param array $version_history |
|
604 | + * @param string $current_version_to_add version to be added to the version history |
|
605 | + * @return boolean success as to whether or not this option was changed |
|
606 | + */ |
|
607 | + public function update_list_of_installed_versions($version_history = null, $current_version_to_add = null) |
|
608 | + { |
|
609 | + if (! $version_history) { |
|
610 | + $version_history = $this->fix_espresso_db_upgrade_option($version_history); |
|
611 | + } |
|
612 | + if ($current_version_to_add === null) { |
|
613 | + $current_version_to_add = espresso_version(); |
|
614 | + } |
|
615 | + $version_history[$current_version_to_add][] = date('Y-m-d H:i:s', time()); |
|
616 | + // re-save |
|
617 | + return update_option('espresso_db_update', $version_history); |
|
618 | + } |
|
619 | + |
|
620 | + |
|
621 | + |
|
622 | + /** |
|
623 | + * Detects if the current version indicated in the has existed in the list of |
|
624 | + * previously-installed versions of EE (espresso_db_update). Does NOT modify it (ie, no side-effect) |
|
625 | + * |
|
626 | + * @param array $espresso_db_update array from the wp option stored under the name 'espresso_db_update'. |
|
627 | + * If not supplied, fetches it from the options table. |
|
628 | + * Also, caches its result so later parts of the code can also know whether |
|
629 | + * there's been an update or not. This way we can add the current version to |
|
630 | + * espresso_db_update, but still know if this is a new install or not |
|
631 | + * @return int one of the constants on EE_System::req_type_ |
|
632 | + */ |
|
633 | + public function detect_req_type($espresso_db_update = null) |
|
634 | + { |
|
635 | + if ($this->_req_type === null) { |
|
636 | + $espresso_db_update = ! empty($espresso_db_update) |
|
637 | + ? $espresso_db_update |
|
638 | + : $this->fix_espresso_db_upgrade_option(); |
|
639 | + $this->_req_type = EE_System::detect_req_type_given_activation_history( |
|
640 | + $espresso_db_update, |
|
641 | + 'ee_espresso_activation', espresso_version() |
|
642 | + ); |
|
643 | + $this->_major_version_change = $this->_detect_major_version_change($espresso_db_update); |
|
644 | + } |
|
645 | + return $this->_req_type; |
|
646 | + } |
|
647 | + |
|
648 | + |
|
649 | + |
|
650 | + /** |
|
651 | + * Returns whether or not there was a non-micro version change (ie, change in either |
|
652 | + * the first or second number in the version. Eg 4.9.0.rc.001 to 4.10.0.rc.000, |
|
653 | + * but not 4.9.0.rc.0001 to 4.9.1.rc.0001 |
|
654 | + * |
|
655 | + * @param $activation_history |
|
656 | + * @return bool |
|
657 | + */ |
|
658 | + private function _detect_major_version_change($activation_history) |
|
659 | + { |
|
660 | + $previous_version = EE_System::_get_most_recently_active_version_from_activation_history($activation_history); |
|
661 | + $previous_version_parts = explode('.', $previous_version); |
|
662 | + $current_version_parts = explode('.', espresso_version()); |
|
663 | + return isset($previous_version_parts[0], $previous_version_parts[1], $current_version_parts[0], $current_version_parts[1]) |
|
664 | + && ($previous_version_parts[0] !== $current_version_parts[0] |
|
665 | + || $previous_version_parts[1] !== $current_version_parts[1] |
|
666 | + ); |
|
667 | + } |
|
668 | + |
|
669 | + |
|
670 | + |
|
671 | + /** |
|
672 | + * Returns true if either the major or minor version of EE changed during this request. |
|
673 | + * Eg 4.9.0.rc.001 to 4.10.0.rc.000, but not 4.9.0.rc.0001 to 4.9.1.rc.0001 |
|
674 | + * |
|
675 | + * @return bool |
|
676 | + */ |
|
677 | + public function is_major_version_change() |
|
678 | + { |
|
679 | + return $this->_major_version_change; |
|
680 | + } |
|
681 | + |
|
682 | + |
|
683 | + |
|
684 | + /** |
|
685 | + * Determines the request type for any ee addon, given three piece of info: the current array of activation |
|
686 | + * histories (for core that' 'espresso_db_update' wp option); the name of the WordPress option which is temporarily |
|
687 | + * set upon activation of the plugin (for core it's 'ee_espresso_activation'); and the version that this plugin was |
|
688 | + * just activated to (for core that will always be espresso_version()) |
|
689 | + * |
|
690 | + * @param array $activation_history_for_addon the option's value which stores the activation history for this |
|
691 | + * ee plugin. for core that's 'espresso_db_update' |
|
692 | + * @param string $activation_indicator_option_name the name of the WordPress option that is temporarily set to |
|
693 | + * indicate that this plugin was just activated |
|
694 | + * @param string $version_to_upgrade_to the version that was just upgraded to (for core that will be |
|
695 | + * espresso_version()) |
|
696 | + * @return int one of the constants on EE_System::req_type_* |
|
697 | + */ |
|
698 | + public static function detect_req_type_given_activation_history( |
|
699 | + $activation_history_for_addon, |
|
700 | + $activation_indicator_option_name, |
|
701 | + $version_to_upgrade_to |
|
702 | + ) { |
|
703 | + $version_is_higher = self::_new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to); |
|
704 | + if ($activation_history_for_addon) { |
|
705 | + //it exists, so this isn't a completely new install |
|
706 | + //check if this version already in that list of previously installed versions |
|
707 | + if (! isset($activation_history_for_addon[$version_to_upgrade_to])) { |
|
708 | + //it a version we haven't seen before |
|
709 | + if ($version_is_higher === 1) { |
|
710 | + $req_type = EE_System::req_type_upgrade; |
|
711 | + } else { |
|
712 | + $req_type = EE_System::req_type_downgrade; |
|
713 | + } |
|
714 | + delete_option($activation_indicator_option_name); |
|
715 | + } else { |
|
716 | + // its not an update. maybe a reactivation? |
|
717 | + if (get_option($activation_indicator_option_name, false)) { |
|
718 | + if ($version_is_higher === -1) { |
|
719 | + $req_type = EE_System::req_type_downgrade; |
|
720 | + } else if ($version_is_higher === 0) { |
|
721 | + //we've seen this version before, but it's an activation. must be a reactivation |
|
722 | + $req_type = EE_System::req_type_reactivation; |
|
723 | + } else {//$version_is_higher === 1 |
|
724 | + $req_type = EE_System::req_type_upgrade; |
|
725 | + } |
|
726 | + delete_option($activation_indicator_option_name); |
|
727 | + } else { |
|
728 | + //we've seen this version before and the activation indicate doesn't show it was just activated |
|
729 | + if ($version_is_higher === -1) { |
|
730 | + $req_type = EE_System::req_type_downgrade; |
|
731 | + } else if ($version_is_higher === 0) { |
|
732 | + //we've seen this version before and it's not an activation. its normal request |
|
733 | + $req_type = EE_System::req_type_normal; |
|
734 | + } else {//$version_is_higher === 1 |
|
735 | + $req_type = EE_System::req_type_upgrade; |
|
736 | + } |
|
737 | + } |
|
738 | + } |
|
739 | + } else { |
|
740 | + //brand new install |
|
741 | + $req_type = EE_System::req_type_new_activation; |
|
742 | + delete_option($activation_indicator_option_name); |
|
743 | + } |
|
744 | + return $req_type; |
|
745 | + } |
|
746 | + |
|
747 | + |
|
748 | + |
|
749 | + /** |
|
750 | + * Detects if the $version_to_upgrade_to is higher than the most recent version in |
|
751 | + * the $activation_history_for_addon |
|
752 | + * |
|
753 | + * @param array $activation_history_for_addon (keys are versions, values are arrays of times activated, |
|
754 | + * sometimes containing 'unknown-date' |
|
755 | + * @param string $version_to_upgrade_to (current version) |
|
756 | + * @return int results of version_compare( $version_to_upgrade_to, $most_recently_active_version ). |
|
757 | + * ie, -1 if $version_to_upgrade_to is LOWER (downgrade); |
|
758 | + * 0 if $version_to_upgrade_to MATCHES (reactivation or normal request); |
|
759 | + * 1 if $version_to_upgrade_to is HIGHER (upgrade) ; |
|
760 | + */ |
|
761 | + private static function _new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to) |
|
762 | + { |
|
763 | + //find the most recently-activated version |
|
764 | + $most_recently_active_version = |
|
765 | + EE_System::_get_most_recently_active_version_from_activation_history($activation_history_for_addon); |
|
766 | + return version_compare($version_to_upgrade_to, $most_recently_active_version); |
|
767 | + } |
|
768 | + |
|
769 | + |
|
770 | + |
|
771 | + /** |
|
772 | + * Gets the most recently active version listed in the activation history, |
|
773 | + * and if none are found (ie, it's a brand new install) returns '0.0.0.dev.000'. |
|
774 | + * |
|
775 | + * @param array $activation_history (keys are versions, values are arrays of times activated, |
|
776 | + * sometimes containing 'unknown-date' |
|
777 | + * @return string |
|
778 | + */ |
|
779 | + private static function _get_most_recently_active_version_from_activation_history($activation_history) |
|
780 | + { |
|
781 | + $most_recently_active_version_activation = '1970-01-01 00:00:00'; |
|
782 | + $most_recently_active_version = '0.0.0.dev.000'; |
|
783 | + if (is_array($activation_history)) { |
|
784 | + foreach ($activation_history as $version => $times_activated) { |
|
785 | + //check there is a record of when this version was activated. Otherwise, |
|
786 | + //mark it as unknown |
|
787 | + if (! $times_activated) { |
|
788 | + $times_activated = array('unknown-date'); |
|
789 | + } |
|
790 | + if (is_string($times_activated)) { |
|
791 | + $times_activated = array($times_activated); |
|
792 | + } |
|
793 | + foreach ($times_activated as $an_activation) { |
|
794 | + if ($an_activation !== 'unknown-date' && $an_activation > $most_recently_active_version_activation) { |
|
795 | + $most_recently_active_version = $version; |
|
796 | + $most_recently_active_version_activation = $an_activation === 'unknown-date' |
|
797 | + ? '1970-01-01 00:00:00' |
|
798 | + : $an_activation; |
|
799 | + } |
|
800 | + } |
|
801 | + } |
|
802 | + } |
|
803 | + return $most_recently_active_version; |
|
804 | + } |
|
805 | + |
|
806 | + |
|
807 | + |
|
808 | + /** |
|
809 | + * This redirects to the about EE page after activation |
|
810 | + * |
|
811 | + * @return void |
|
812 | + */ |
|
813 | + public function redirect_to_about_ee() |
|
814 | + { |
|
815 | + $notices = EE_Error::get_notices(false); |
|
816 | + //if current user is an admin and it's not an ajax or rest request |
|
817 | + if ( |
|
818 | + ! (defined('DOING_AJAX') && DOING_AJAX) |
|
819 | + && ! (defined('REST_REQUEST') && REST_REQUEST) |
|
820 | + && ! isset($notices['errors']) |
|
821 | + && apply_filters( |
|
822 | + 'FHEE__EE_System__redirect_to_about_ee__do_redirect', |
|
823 | + $this->capabilities->current_user_can('manage_options', 'espresso_about_default') |
|
824 | + ) |
|
825 | + ) { |
|
826 | + $query_params = array('page' => 'espresso_about'); |
|
827 | + if (EE_System::instance()->detect_req_type() === EE_System::req_type_new_activation) { |
|
828 | + $query_params['new_activation'] = true; |
|
829 | + } |
|
830 | + if (EE_System::instance()->detect_req_type() === EE_System::req_type_reactivation) { |
|
831 | + $query_params['reactivation'] = true; |
|
832 | + } |
|
833 | + $url = add_query_arg($query_params, admin_url('admin.php')); |
|
834 | + wp_safe_redirect($url); |
|
835 | + exit(); |
|
836 | + } |
|
837 | + } |
|
838 | + |
|
839 | + |
|
840 | + |
|
841 | + /** |
|
842 | + * load_core_configuration |
|
843 | + * this is hooked into 'AHEE__EE_Bootstrap__load_core_configuration' |
|
844 | + * which runs during the WP 'plugins_loaded' action at priority 5 |
|
845 | + * |
|
846 | + * @return void |
|
847 | + * @throws ReflectionException |
|
848 | + */ |
|
849 | + public function load_core_configuration() |
|
850 | + { |
|
851 | + do_action('AHEE__EE_System__load_core_configuration__begin', $this); |
|
852 | + $this->loader->getShared('EE_Load_Textdomain'); |
|
853 | + //load textdomain |
|
854 | + EE_Load_Textdomain::load_textdomain(); |
|
855 | + // load and setup EE_Config and EE_Network_Config |
|
856 | + $config = $this->loader->getShared('EE_Config'); |
|
857 | + $this->loader->getShared('EE_Network_Config'); |
|
858 | + // setup autoloaders |
|
859 | + // enable logging? |
|
860 | + if ($config->admin->use_full_logging) { |
|
861 | + $this->loader->getShared('EE_Log'); |
|
862 | + } |
|
863 | + // check for activation errors |
|
864 | + $activation_errors = get_option('ee_plugin_activation_errors', false); |
|
865 | + if ($activation_errors) { |
|
866 | + EE_Error::add_error($activation_errors, __FILE__, __FUNCTION__, __LINE__); |
|
867 | + update_option('ee_plugin_activation_errors', false); |
|
868 | + } |
|
869 | + // get model names |
|
870 | + $this->_parse_model_names(); |
|
871 | + //load caf stuff a chance to play during the activation process too. |
|
872 | + $this->_maybe_brew_regular(); |
|
873 | + do_action('AHEE__EE_System__load_core_configuration__complete', $this); |
|
874 | + } |
|
875 | + |
|
876 | + |
|
877 | + |
|
878 | + /** |
|
879 | + * cycles through all of the models/*.model.php files, and assembles an array of model names |
|
880 | + * |
|
881 | + * @return void |
|
882 | + * @throws ReflectionException |
|
883 | + */ |
|
884 | + private function _parse_model_names() |
|
885 | + { |
|
886 | + //get all the files in the EE_MODELS folder that end in .model.php |
|
887 | + $models = glob(EE_MODELS . '*.model.php'); |
|
888 | + $model_names = array(); |
|
889 | + $non_abstract_db_models = array(); |
|
890 | + foreach ($models as $model) { |
|
891 | + // get model classname |
|
892 | + $classname = EEH_File::get_classname_from_filepath_with_standard_filename($model); |
|
893 | + $short_name = str_replace('EEM_', '', $classname); |
|
894 | + $reflectionClass = new ReflectionClass($classname); |
|
895 | + if ($reflectionClass->isSubclassOf('EEM_Base') && ! $reflectionClass->isAbstract()) { |
|
896 | + $non_abstract_db_models[$short_name] = $classname; |
|
897 | + } |
|
898 | + $model_names[$short_name] = $classname; |
|
899 | + } |
|
900 | + $this->registry->models = apply_filters('FHEE__EE_System__parse_model_names', $model_names); |
|
901 | + $this->registry->non_abstract_db_models = apply_filters( |
|
902 | + 'FHEE__EE_System__parse_implemented_model_names', |
|
903 | + $non_abstract_db_models |
|
904 | + ); |
|
905 | + } |
|
906 | + |
|
907 | + |
|
908 | + |
|
909 | + /** |
|
910 | + * The purpose of this method is to simply check for a file named "caffeinated/brewing_regular.php" for any hooks |
|
911 | + * that need to be setup before our EE_System launches. |
|
912 | + * |
|
913 | + * @return void |
|
914 | + */ |
|
915 | + private function _maybe_brew_regular() |
|
916 | + { |
|
917 | + if ((! defined('EE_DECAF') || EE_DECAF !== true) && is_readable(EE_CAFF_PATH . 'brewing_regular.php')) { |
|
918 | + require_once EE_CAFF_PATH . 'brewing_regular.php'; |
|
919 | + } |
|
920 | + } |
|
921 | + |
|
922 | + |
|
923 | + |
|
924 | + /** |
|
925 | + * register_shortcodes_modules_and_widgets |
|
926 | + * generate lists of shortcodes and modules, then verify paths and classes |
|
927 | + * This is hooked into 'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets' |
|
928 | + * which runs during the WP 'plugins_loaded' action at priority 7 |
|
929 | + * |
|
930 | + * @access public |
|
931 | + * @return void |
|
932 | + * @throws Exception |
|
933 | + */ |
|
934 | + public function register_shortcodes_modules_and_widgets() |
|
935 | + { |
|
936 | + try { |
|
937 | + // load, register, and add shortcodes the new way |
|
938 | + $this->loader->getShared( |
|
939 | + 'EventEspresso\core\services\shortcodes\ShortcodesManager', |
|
940 | + array( |
|
941 | + // and the old way, but we'll put it under control of the new system |
|
942 | + EE_Config::getLegacyShortcodesManager() |
|
943 | + ) |
|
944 | + ); |
|
945 | + } catch (Exception $exception) { |
|
946 | + new ExceptionStackTraceDisplay($exception); |
|
947 | + } |
|
948 | + do_action('AHEE__EE_System__register_shortcodes_modules_and_widgets'); |
|
949 | + // check for addons using old hook point |
|
950 | + if (has_action('AHEE__EE_System__register_shortcodes_modules_and_addons')) { |
|
951 | + $this->_incompatible_addon_error(); |
|
952 | + } |
|
953 | + } |
|
954 | + |
|
955 | + |
|
956 | + |
|
957 | + /** |
|
958 | + * _incompatible_addon_error |
|
959 | + * |
|
960 | + * @access public |
|
961 | + * @return void |
|
962 | + */ |
|
963 | + private function _incompatible_addon_error() |
|
964 | + { |
|
965 | + // get array of classes hooking into here |
|
966 | + $class_names = EEH_Class_Tools::get_class_names_for_all_callbacks_on_hook( |
|
967 | + 'AHEE__EE_System__register_shortcodes_modules_and_addons' |
|
968 | + ); |
|
969 | + if (! empty($class_names)) { |
|
970 | + $msg = __( |
|
971 | + 'The following plugins, addons, or modules appear to be incompatible with this version of Event Espresso and were automatically deactivated to avoid fatal errors:', |
|
972 | + 'event_espresso' |
|
973 | + ); |
|
974 | + $msg .= '<ul>'; |
|
975 | + foreach ($class_names as $class_name) { |
|
976 | + $msg .= '<li><b>Event Espresso - ' . str_replace( |
|
977 | + array('EE_', 'EEM_', 'EED_', 'EES_', 'EEW_'), '', |
|
978 | + $class_name |
|
979 | + ) . '</b></li>'; |
|
980 | + } |
|
981 | + $msg .= '</ul>'; |
|
982 | + $msg .= __( |
|
983 | + 'Compatibility issues can be avoided and/or resolved by keeping addons and plugins updated to the latest version.', |
|
984 | + 'event_espresso' |
|
985 | + ); |
|
986 | + // save list of incompatible addons to wp-options for later use |
|
987 | + add_option('ee_incompatible_addons', $class_names, '', 'no'); |
|
988 | + if (is_admin()) { |
|
989 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
990 | + } |
|
991 | + } |
|
992 | + } |
|
993 | + |
|
994 | + |
|
995 | + |
|
996 | + /** |
|
997 | + * brew_espresso |
|
998 | + * begins the process of setting hooks for initializing EE in the correct order |
|
999 | + * This is happening on the 'AHEE__EE_Bootstrap__brew_espresso' hook point |
|
1000 | + * which runs during the WP 'plugins_loaded' action at priority 9 |
|
1001 | + * |
|
1002 | + * @return void |
|
1003 | + */ |
|
1004 | + public function brew_espresso() |
|
1005 | + { |
|
1006 | + do_action('AHEE__EE_System__brew_espresso__begin', $this); |
|
1007 | + // load some final core systems |
|
1008 | + add_action('init', array($this, 'set_hooks_for_core'), 1); |
|
1009 | + add_action('init', array($this, 'perform_activations_upgrades_and_migrations'), 3); |
|
1010 | + add_action('init', array($this, 'load_CPTs_and_session'), 5); |
|
1011 | + add_action('init', array($this, 'load_controllers'), 7); |
|
1012 | + add_action('init', array($this, 'core_loaded_and_ready'), 9); |
|
1013 | + add_action('init', array($this, 'initialize'), 10); |
|
1014 | + add_action('init', array($this, 'initialize_last'), 100); |
|
1015 | + if (is_admin() && apply_filters('FHEE__EE_System__brew_espresso__load_pue', true)) { |
|
1016 | + // pew pew pew |
|
1017 | + $this->loader->getShared('EE_PUE'); |
|
1018 | + do_action('AHEE__EE_System__brew_espresso__after_pue_init'); |
|
1019 | + } |
|
1020 | + do_action('AHEE__EE_System__brew_espresso__complete', $this); |
|
1021 | + } |
|
1022 | + |
|
1023 | + |
|
1024 | + |
|
1025 | + /** |
|
1026 | + * set_hooks_for_core |
|
1027 | + * |
|
1028 | + * @access public |
|
1029 | + * @return void |
|
1030 | + * @throws EE_Error |
|
1031 | + */ |
|
1032 | + public function set_hooks_for_core() |
|
1033 | + { |
|
1034 | + $this->_deactivate_incompatible_addons(); |
|
1035 | + do_action('AHEE__EE_System__set_hooks_for_core'); |
|
1036 | + //caps need to be initialized on every request so that capability maps are set. |
|
1037 | + //@see https://events.codebasehq.com/projects/event-espresso/tickets/8674 |
|
1038 | + $this->registry->CAP->init_caps(); |
|
1039 | + } |
|
1040 | + |
|
1041 | + |
|
1042 | + |
|
1043 | + /** |
|
1044 | + * Using the information gathered in EE_System::_incompatible_addon_error, |
|
1045 | + * deactivates any addons considered incompatible with the current version of EE |
|
1046 | + */ |
|
1047 | + private function _deactivate_incompatible_addons() |
|
1048 | + { |
|
1049 | + $incompatible_addons = get_option('ee_incompatible_addons', array()); |
|
1050 | + if (! empty($incompatible_addons)) { |
|
1051 | + $active_plugins = get_option('active_plugins', array()); |
|
1052 | + foreach ($active_plugins as $active_plugin) { |
|
1053 | + foreach ($incompatible_addons as $incompatible_addon) { |
|
1054 | + if (strpos($active_plugin, $incompatible_addon) !== false) { |
|
1055 | + unset($_GET['activate']); |
|
1056 | + espresso_deactivate_plugin($active_plugin); |
|
1057 | + } |
|
1058 | + } |
|
1059 | + } |
|
1060 | + } |
|
1061 | + } |
|
1062 | + |
|
1063 | + |
|
1064 | + |
|
1065 | + /** |
|
1066 | + * perform_activations_upgrades_and_migrations |
|
1067 | + * |
|
1068 | + * @access public |
|
1069 | + * @return void |
|
1070 | + */ |
|
1071 | + public function perform_activations_upgrades_and_migrations() |
|
1072 | + { |
|
1073 | + //first check if we had previously attempted to setup EE's directories but failed |
|
1074 | + if (EEH_Activation::upload_directories_incomplete()) { |
|
1075 | + EEH_Activation::create_upload_directories(); |
|
1076 | + } |
|
1077 | + do_action('AHEE__EE_System__perform_activations_upgrades_and_migrations'); |
|
1078 | + } |
|
1079 | + |
|
1080 | + |
|
1081 | + |
|
1082 | + /** |
|
1083 | + * load_CPTs_and_session |
|
1084 | + * |
|
1085 | + * @access public |
|
1086 | + * @return void |
|
1087 | + */ |
|
1088 | + public function load_CPTs_and_session() |
|
1089 | + { |
|
1090 | + do_action('AHEE__EE_System__load_CPTs_and_session__start'); |
|
1091 | + // register Custom Post Types |
|
1092 | + $this->loader->getShared('EE_Register_CPTs'); |
|
1093 | + do_action('AHEE__EE_System__load_CPTs_and_session__complete'); |
|
1094 | + } |
|
1095 | + |
|
1096 | + |
|
1097 | + |
|
1098 | + /** |
|
1099 | + * load_controllers |
|
1100 | + * this is the best place to load any additional controllers that needs access to EE core. |
|
1101 | + * it is expected that all basic core EE systems, that are not dependant on the current request are loaded at this |
|
1102 | + * time |
|
1103 | + * |
|
1104 | + * @access public |
|
1105 | + * @return void |
|
1106 | + */ |
|
1107 | + public function load_controllers() |
|
1108 | + { |
|
1109 | + do_action('AHEE__EE_System__load_controllers__start'); |
|
1110 | + // let's get it started |
|
1111 | + if (! is_admin() && ! $this->maintenance_mode->level()) { |
|
1112 | + do_action('AHEE__EE_System__load_controllers__load_front_controllers'); |
|
1113 | + $this->loader->getShared('EE_Front_Controller'); |
|
1114 | + } else if (! EE_FRONT_AJAX) { |
|
1115 | + do_action('AHEE__EE_System__load_controllers__load_admin_controllers'); |
|
1116 | + $this->loader->getShared('EE_Admin'); |
|
1117 | + } |
|
1118 | + do_action('AHEE__EE_System__load_controllers__complete'); |
|
1119 | + } |
|
1120 | + |
|
1121 | + |
|
1122 | + |
|
1123 | + /** |
|
1124 | + * core_loaded_and_ready |
|
1125 | + * all of the basic EE core should be loaded at this point and available regardless of M-Mode |
|
1126 | + * |
|
1127 | + * @access public |
|
1128 | + * @return void |
|
1129 | + */ |
|
1130 | + public function core_loaded_and_ready() |
|
1131 | + { |
|
1132 | + $this->loader->getShared('EE_Session'); |
|
1133 | + do_action('AHEE__EE_System__core_loaded_and_ready'); |
|
1134 | + // load_espresso_template_tags |
|
1135 | + if (is_readable(EE_PUBLIC . 'template_tags.php')) { |
|
1136 | + require_once(EE_PUBLIC . 'template_tags.php'); |
|
1137 | + } |
|
1138 | + do_action('AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons'); |
|
1139 | + $this->loader->getShared('EventEspresso\core\services\assets\Registry'); |
|
1140 | + } |
|
1141 | + |
|
1142 | + |
|
1143 | + |
|
1144 | + /** |
|
1145 | + * initialize |
|
1146 | + * this is the best place to begin initializing client code |
|
1147 | + * |
|
1148 | + * @access public |
|
1149 | + * @return void |
|
1150 | + */ |
|
1151 | + public function initialize() |
|
1152 | + { |
|
1153 | + do_action('AHEE__EE_System__initialize'); |
|
1154 | + } |
|
1155 | + |
|
1156 | + |
|
1157 | + |
|
1158 | + /** |
|
1159 | + * initialize_last |
|
1160 | + * this is run really late during the WP init hook point, and ensures that mostly everything else that needs to |
|
1161 | + * initialize has done so |
|
1162 | + * |
|
1163 | + * @access public |
|
1164 | + * @return void |
|
1165 | + */ |
|
1166 | + public function initialize_last() |
|
1167 | + { |
|
1168 | + do_action('AHEE__EE_System__initialize_last'); |
|
1169 | + add_action('admin_bar_init', array($this, 'addEspressoToolbar')); |
|
1170 | + } |
|
1171 | + |
|
1172 | + |
|
1173 | + |
|
1174 | + /** |
|
1175 | + * @return void |
|
1176 | + * @throws EE_Error |
|
1177 | + */ |
|
1178 | + public function addEspressoToolbar() |
|
1179 | + { |
|
1180 | + $this->loader->getShared( |
|
1181 | + 'EventEspresso\core\domain\services\admin\AdminToolBar', |
|
1182 | + array($this->registry->CAP) |
|
1183 | + ); |
|
1184 | + } |
|
1185 | + |
|
1186 | + |
|
1187 | + |
|
1188 | + /** |
|
1189 | + * do_not_cache |
|
1190 | + * sets no cache headers and defines no cache constants for WP plugins |
|
1191 | + * |
|
1192 | + * @access public |
|
1193 | + * @return void |
|
1194 | + */ |
|
1195 | + public static function do_not_cache() |
|
1196 | + { |
|
1197 | + // set no cache constants |
|
1198 | + if (! defined('DONOTCACHEPAGE')) { |
|
1199 | + define('DONOTCACHEPAGE', true); |
|
1200 | + } |
|
1201 | + if (! defined('DONOTCACHCEOBJECT')) { |
|
1202 | + define('DONOTCACHCEOBJECT', true); |
|
1203 | + } |
|
1204 | + if (! defined('DONOTCACHEDB')) { |
|
1205 | + define('DONOTCACHEDB', true); |
|
1206 | + } |
|
1207 | + // add no cache headers |
|
1208 | + add_action('send_headers', array('EE_System', 'nocache_headers'), 10); |
|
1209 | + // plus a little extra for nginx and Google Chrome |
|
1210 | + add_filter('nocache_headers', array('EE_System', 'extra_nocache_headers'), 10, 1); |
|
1211 | + // prevent browsers from prefetching of the rel='next' link, because it may contain content that interferes with the registration process |
|
1212 | + remove_action('wp_head', 'adjacent_posts_rel_link_wp_head'); |
|
1213 | + } |
|
1214 | + |
|
1215 | + |
|
1216 | + |
|
1217 | + /** |
|
1218 | + * extra_nocache_headers |
|
1219 | + * |
|
1220 | + * @access public |
|
1221 | + * @param $headers |
|
1222 | + * @return array |
|
1223 | + */ |
|
1224 | + public static function extra_nocache_headers($headers) |
|
1225 | + { |
|
1226 | + // for NGINX |
|
1227 | + $headers['X-Accel-Expires'] = 0; |
|
1228 | + // plus extra for Google Chrome since it doesn't seem to respect "no-cache", but WILL respect "no-store" |
|
1229 | + $headers['Cache-Control'] = 'no-store, no-cache, must-revalidate, max-age=0'; |
|
1230 | + return $headers; |
|
1231 | + } |
|
1232 | + |
|
1233 | + |
|
1234 | + |
|
1235 | + /** |
|
1236 | + * nocache_headers |
|
1237 | + * |
|
1238 | + * @access public |
|
1239 | + * @return void |
|
1240 | + */ |
|
1241 | + public static function nocache_headers() |
|
1242 | + { |
|
1243 | + nocache_headers(); |
|
1244 | + } |
|
1245 | + |
|
1246 | + |
|
1247 | + |
|
1248 | + |
|
1249 | + /** |
|
1250 | + * simply hooks into "wp_list_pages_exclude" filter (for wp_list_pages method) and makes sure EE critical pages are |
|
1251 | + * never returned with the function. |
|
1252 | + * |
|
1253 | + * @param array $exclude_array any existing pages being excluded are in this array. |
|
1254 | + * @return array |
|
1255 | + */ |
|
1256 | + public function remove_pages_from_wp_list_pages($exclude_array) |
|
1257 | + { |
|
1258 | + return array_merge($exclude_array, $this->registry->CFG->core->get_critical_pages_array()); |
|
1259 | + } |
|
1260 | 1260 | |
1261 | 1261 | |
1262 | 1262 |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | if (! defined('EVENT_ESPRESSO_VERSION')) { |
3 | - exit('NO direct script access allowed'); |
|
3 | + exit('NO direct script access allowed'); |
|
4 | 4 | } |
5 | 5 | /** |
6 | 6 | * Event Espresso |
@@ -16,35 +16,35 @@ discard block |
||
16 | 16 | |
17 | 17 | |
18 | 18 | if ( ! function_exists('espresso_get_template_part')) { |
19 | - /** |
|
20 | - * espresso_get_template_part |
|
21 | - * basically a copy of the WordPress get_template_part() function but uses EEH_Template::locate_template() instead, and doesn't add base versions of files |
|
22 | - * so not a very useful function at all except that it adds familiarity PLUS filtering based off of the entire template part name |
|
23 | - * |
|
24 | - * @param string $slug The slug name for the generic template. |
|
25 | - * @param string $name The name of the specialised template. |
|
26 | - * @return string the html output for the formatted money value |
|
27 | - */ |
|
28 | - function espresso_get_template_part($slug = null, $name = null) |
|
29 | - { |
|
30 | - EEH_Template::get_template_part($slug, $name); |
|
31 | - } |
|
19 | + /** |
|
20 | + * espresso_get_template_part |
|
21 | + * basically a copy of the WordPress get_template_part() function but uses EEH_Template::locate_template() instead, and doesn't add base versions of files |
|
22 | + * so not a very useful function at all except that it adds familiarity PLUS filtering based off of the entire template part name |
|
23 | + * |
|
24 | + * @param string $slug The slug name for the generic template. |
|
25 | + * @param string $name The name of the specialised template. |
|
26 | + * @return string the html output for the formatted money value |
|
27 | + */ |
|
28 | + function espresso_get_template_part($slug = null, $name = null) |
|
29 | + { |
|
30 | + EEH_Template::get_template_part($slug, $name); |
|
31 | + } |
|
32 | 32 | } |
33 | 33 | |
34 | 34 | |
35 | 35 | if ( ! function_exists('espresso_get_object_css_class')) { |
36 | - /** |
|
37 | - * espresso_get_object_css_class - attempts to generate a css class based on the type of EE object passed |
|
38 | - * |
|
39 | - * @param EE_Base_Class $object the EE object the css class is being generated for |
|
40 | - * @param string $prefix added to the beginning of the generated class |
|
41 | - * @param string $suffix added to the end of the generated class |
|
42 | - * @return string |
|
43 | - */ |
|
44 | - function espresso_get_object_css_class($object = null, $prefix = '', $suffix = '') |
|
45 | - { |
|
46 | - return EEH_Template::get_object_css_class($object, $prefix, $suffix); |
|
47 | - } |
|
36 | + /** |
|
37 | + * espresso_get_object_css_class - attempts to generate a css class based on the type of EE object passed |
|
38 | + * |
|
39 | + * @param EE_Base_Class $object the EE object the css class is being generated for |
|
40 | + * @param string $prefix added to the beginning of the generated class |
|
41 | + * @param string $suffix added to the end of the generated class |
|
42 | + * @return string |
|
43 | + */ |
|
44 | + function espresso_get_object_css_class($object = null, $prefix = '', $suffix = '') |
|
45 | + { |
|
46 | + return EEH_Template::get_object_css_class($object, $prefix, $suffix); |
|
47 | + } |
|
48 | 48 | } |
49 | 49 | |
50 | 50 | |
@@ -59,650 +59,650 @@ discard block |
||
59 | 59 | class EEH_Template |
60 | 60 | { |
61 | 61 | |
62 | - private static $_espresso_themes = array(); |
|
63 | - |
|
64 | - |
|
65 | - /** |
|
66 | - * is_espresso_theme - returns TRUE or FALSE on whether the currently active WP theme is an espresso theme |
|
67 | - * |
|
68 | - * @return boolean |
|
69 | - */ |
|
70 | - public static function is_espresso_theme() |
|
71 | - { |
|
72 | - return wp_get_theme()->get('TextDomain') == 'event_espresso' ? true : false; |
|
73 | - } |
|
74 | - |
|
75 | - /** |
|
76 | - * load_espresso_theme_functions - if current theme is an espresso theme, or uses ee theme template parts, then |
|
77 | - * load it's functions.php file ( if not already loaded ) |
|
78 | - * |
|
79 | - * @return void |
|
80 | - */ |
|
81 | - public static function load_espresso_theme_functions() |
|
82 | - { |
|
83 | - if ( ! defined('EE_THEME_FUNCTIONS_LOADED')) { |
|
84 | - if (is_readable(EE_PUBLIC . EE_Config::get_current_theme() . DS . 'functions.php')) { |
|
85 | - require_once(EE_PUBLIC . EE_Config::get_current_theme() . DS . 'functions.php'); |
|
86 | - } |
|
87 | - } |
|
88 | - } |
|
89 | - |
|
90 | - |
|
91 | - /** |
|
92 | - * get_espresso_themes - returns an array of Espresso Child themes located in the /templates/ directory |
|
93 | - * |
|
94 | - * @return array |
|
95 | - */ |
|
96 | - public static function get_espresso_themes() |
|
97 | - { |
|
98 | - if (empty(EEH_Template::$_espresso_themes)) { |
|
99 | - $espresso_themes = glob(EE_PUBLIC . '*', GLOB_ONLYDIR); |
|
100 | - if (empty($espresso_themes)) { |
|
101 | - return array(); |
|
102 | - } |
|
103 | - if (($key = array_search('global_assets', $espresso_themes)) !== false) { |
|
104 | - unset($espresso_themes[$key]); |
|
105 | - } |
|
106 | - EEH_Template::$_espresso_themes = array(); |
|
107 | - foreach ($espresso_themes as $espresso_theme) { |
|
108 | - EEH_Template::$_espresso_themes[basename($espresso_theme)] = $espresso_theme; |
|
109 | - } |
|
110 | - } |
|
111 | - return EEH_Template::$_espresso_themes; |
|
112 | - } |
|
113 | - |
|
114 | - |
|
115 | - /** |
|
116 | - * EEH_Template::get_template_part |
|
117 | - * basically a copy of the WordPress get_template_part() function but uses EEH_Template::locate_template() instead, |
|
118 | - * and doesn't add base versions of files so not a very useful function at all except that it adds familiarity PLUS |
|
119 | - * filtering based off of the entire template part name |
|
120 | - * |
|
121 | - * @param string $slug The slug name for the generic template. |
|
122 | - * @param string $name The name of the specialised template. |
|
123 | - * @param array $template_args |
|
124 | - * @param bool $return_string |
|
125 | - * @return string the html output for the formatted money value |
|
126 | - */ |
|
127 | - public static function get_template_part( |
|
128 | - $slug = null, |
|
129 | - $name = null, |
|
130 | - $template_args = array(), |
|
131 | - $return_string = false |
|
132 | - ) { |
|
133 | - do_action("get_template_part_{$slug}-{$name}", $slug, $name); |
|
134 | - $templates = array(); |
|
135 | - $name = (string)$name; |
|
136 | - if ($name != '') { |
|
137 | - $templates[] = "{$slug}-{$name}.php"; |
|
138 | - } |
|
139 | - // allow template parts to be turned off via something like: add_filter( 'FHEE__content_espresso_events_tickets_template__display_datetimes', '__return_false' ); |
|
140 | - if (apply_filters("FHEE__EEH_Template__get_template_part__display__{$slug}_{$name}", true)) { |
|
141 | - EEH_Template::locate_template($templates, $template_args, true, $return_string); |
|
142 | - } |
|
143 | - } |
|
144 | - |
|
145 | - |
|
146 | - /** |
|
147 | - * locate_template |
|
148 | - * locate a template file by looking in the following places, in the following order: |
|
149 | - * <server path up to>/wp-content/themes/<current active WordPress theme>/ |
|
150 | - * <assumed full absolute server path> |
|
151 | - * <server path up to>/wp-content/uploads/espresso/templates/<current EE theme>/ |
|
152 | - * <server path up to>/wp-content/uploads/espresso/templates/ |
|
153 | - * <server path up to>/wp-content/plugins/<EE4 folder>/public/<current EE theme>/ |
|
154 | - * <server path up to>/wp-content/plugins/<EE4 folder>/core/templates/<current EE theme>/ |
|
155 | - * <server path up to>/wp-content/plugins/<EE4 folder>/ |
|
156 | - * as soon as the template is found in one of these locations, it will be returned or loaded |
|
157 | - * Example: |
|
158 | - * You are using the WordPress Twenty Sixteen theme, |
|
159 | - * and you want to customize the "some-event.template.php" template, |
|
160 | - * which is located in the "/relative/path/to/" folder relative to the main EE plugin folder. |
|
161 | - * Assuming WP is installed on your server in the "/home/public_html/" folder, |
|
162 | - * EEH_Template::locate_template() will look at the following paths in order until the template is found: |
|
163 | - * /home/public_html/wp-content/themes/twentysixteen/some-event.template.php |
|
164 | - * /relative/path/to/some-event.template.php |
|
165 | - * /home/public_html/wp-content/uploads/espresso/templates/Espresso_Arabica_2014/relative/path/to/some-event.template.php |
|
166 | - * /home/public_html/wp-content/uploads/espresso/templates/relative/path/to/some-event.template.php |
|
167 | - * /home/public_html/wp-content/plugins/event-espresso-core-reg/public/Espresso_Arabica_2014/relative/path/to/some-event.template.php |
|
168 | - * /home/public_html/wp-content/plugins/event-espresso-core-reg/core/templates/Espresso_Arabica_2014/relative/path/to/some-event.template.php |
|
169 | - * /home/public_html/wp-content/plugins/event-espresso-core-reg/relative/path/to/some-event.template.php |
|
170 | - * Had you passed an absolute path to your template that was in some other location, |
|
171 | - * ie: "/absolute/path/to/some-event.template.php" |
|
172 | - * then the search would have been : |
|
173 | - * /home/public_html/wp-content/themes/twentysixteen/some-event.template.php |
|
174 | - * /absolute/path/to/some-event.template.php |
|
175 | - * and stopped there upon finding it in the second location |
|
176 | - * |
|
177 | - * @param array|string $templates array of template file names including extension (or just a single string) |
|
178 | - * @param array $template_args an array of arguments to be extracted for use in the template |
|
179 | - * @param boolean $load whether to pass the located template path on to the |
|
180 | - * EEH_Template::display_template() method or simply return it |
|
181 | - * @param boolean $return_string whether to send output immediately to screen, or capture and return as a |
|
182 | - * string |
|
183 | - * @param boolean $check_if_custom If TRUE, this flags this method to return boolean for whether this will |
|
184 | - * generate a custom template or not. Used in places where you don't actually |
|
185 | - * load the template, you just want to know if there's a custom version of it. |
|
186 | - * @return mixed |
|
187 | - */ |
|
188 | - public static function locate_template( |
|
189 | - $templates = array(), |
|
190 | - $template_args = array(), |
|
191 | - $load = true, |
|
192 | - $return_string = true, |
|
193 | - $check_if_custom = false |
|
194 | - ) { |
|
195 | - // first use WP locate_template to check for template in the current theme folder |
|
196 | - $template_path = locate_template($templates); |
|
197 | - |
|
198 | - if ($check_if_custom && ! empty($template_path)) { |
|
199 | - return true; |
|
200 | - } |
|
201 | - |
|
202 | - // not in the theme |
|
203 | - if (empty($template_path)) { |
|
204 | - // not even a template to look for ? |
|
205 | - if (empty($templates)) { |
|
206 | - // get post_type |
|
207 | - $post_type = EE_Registry::instance()->REQ->get('post_type'); |
|
208 | - // get array of EE Custom Post Types |
|
209 | - $EE_CPTs = EE_Register_CPTs::get_CPTs(); |
|
210 | - // build template name based on request |
|
211 | - if (isset($EE_CPTs[$post_type])) { |
|
212 | - $archive_or_single = is_archive() ? 'archive' : ''; |
|
213 | - $archive_or_single = is_single() ? 'single' : $archive_or_single; |
|
214 | - $templates = $archive_or_single . '-' . $post_type . '.php'; |
|
215 | - } |
|
216 | - } |
|
217 | - // currently active EE template theme |
|
218 | - $current_theme = EE_Config::get_current_theme(); |
|
219 | - |
|
220 | - // array of paths to folders that may contain templates |
|
221 | - $template_folder_paths = array( |
|
222 | - // first check the /wp-content/uploads/espresso/templates/(current EE theme)/ folder for an EE theme template file |
|
223 | - EVENT_ESPRESSO_TEMPLATE_DIR . $current_theme, |
|
224 | - // then in the root of the /wp-content/uploads/espresso/templates/ folder |
|
225 | - EVENT_ESPRESSO_TEMPLATE_DIR, |
|
226 | - ); |
|
227 | - |
|
228 | - //add core plugin folders for checking only if we're not $check_if_custom |
|
229 | - if ( ! $check_if_custom) { |
|
230 | - $core_paths = array( |
|
231 | - // in the /wp-content/plugins/(EE4 folder)/public/(current EE theme)/ folder within the plugin |
|
232 | - EE_PUBLIC . $current_theme, |
|
233 | - // in the /wp-content/plugins/(EE4 folder)/core/templates/(current EE theme)/ folder within the plugin |
|
234 | - EE_TEMPLATES . $current_theme, |
|
235 | - // or maybe relative from the plugin root: /wp-content/plugins/(EE4 folder)/ |
|
236 | - EE_PLUGIN_DIR_PATH, |
|
237 | - ); |
|
238 | - $template_folder_paths = array_merge($template_folder_paths, $core_paths); |
|
239 | - } |
|
240 | - |
|
241 | - // now filter that array |
|
242 | - $template_folder_paths = apply_filters('FHEE__EEH_Template__locate_template__template_folder_paths', |
|
243 | - $template_folder_paths); |
|
244 | - $templates = is_array($templates) ? $templates : array($templates); |
|
245 | - $template_folder_paths = is_array($template_folder_paths) ? $template_folder_paths : array($template_folder_paths); |
|
246 | - // array to hold all possible template paths |
|
247 | - $full_template_paths = array(); |
|
248 | - |
|
249 | - // loop through $templates |
|
250 | - foreach ($templates as $template) { |
|
251 | - // normalize directory separators |
|
252 | - $template = EEH_File::standardise_directory_separators($template); |
|
253 | - $file_name = basename($template); |
|
254 | - $template_path_minus_file_name = substr($template, 0, (strlen($file_name) * -1)); |
|
255 | - // while looping through all template folder paths |
|
256 | - foreach ($template_folder_paths as $template_folder_path) { |
|
257 | - // normalize directory separators |
|
258 | - $template_folder_path = EEH_File::standardise_directory_separators($template_folder_path); |
|
259 | - // determine if any common base path exists between the two paths |
|
260 | - $common_base_path = EEH_Template::_find_common_base_path( |
|
261 | - array($template_folder_path, $template_path_minus_file_name) |
|
262 | - ); |
|
263 | - if ($common_base_path !== '') { |
|
264 | - // both paths have a common base, so just tack the filename onto our search path |
|
265 | - $resolved_path = EEH_File::end_with_directory_separator($template_folder_path) . $file_name; |
|
266 | - } else { |
|
267 | - // no common base path, so let's just concatenate |
|
268 | - $resolved_path = EEH_File::end_with_directory_separator($template_folder_path) . $template; |
|
269 | - } |
|
270 | - // build up our template locations array by adding our resolved paths |
|
271 | - $full_template_paths[] = $resolved_path; |
|
272 | - } |
|
273 | - // if $template is an absolute path, then we'll tack it onto the start of our array so that it gets searched first |
|
274 | - array_unshift($full_template_paths, $template); |
|
275 | - // path to the directory of the current theme: /wp-content/themes/(current WP theme)/ |
|
276 | - array_unshift($full_template_paths, get_stylesheet_directory() . DS . $file_name); |
|
277 | - } |
|
278 | - // filter final array of full template paths |
|
279 | - $full_template_paths = apply_filters('FHEE__EEH_Template__locate_template__full_template_paths', |
|
280 | - $full_template_paths, $file_name); |
|
281 | - // now loop through our final array of template location paths and check each location |
|
282 | - foreach ((array)$full_template_paths as $full_template_path) { |
|
283 | - if (is_readable($full_template_path)) { |
|
284 | - $template_path = str_replace(array('\\', '/'), DIRECTORY_SEPARATOR, $full_template_path); |
|
285 | - break; |
|
286 | - } |
|
287 | - } |
|
288 | - } |
|
289 | - |
|
290 | - // hook that can be used to display the full template path that will be used |
|
291 | - do_action('AHEE__EEH_Template__locate_template__full_template_path', $template_path); |
|
292 | - |
|
293 | - // if we got it and you want to see it... |
|
294 | - if ($template_path && $load && ! $check_if_custom) { |
|
295 | - if ($return_string) { |
|
296 | - return EEH_Template::display_template($template_path, $template_args, true); |
|
297 | - } else { |
|
298 | - EEH_Template::display_template($template_path, $template_args, false); |
|
299 | - } |
|
300 | - } |
|
301 | - return $check_if_custom && ! empty($template_path) ? true : $template_path; |
|
302 | - } |
|
303 | - |
|
304 | - |
|
305 | - /** |
|
306 | - * _find_common_base_path |
|
307 | - * given two paths, this determines if there is a common base path between the two |
|
308 | - * |
|
309 | - * @param array $paths |
|
310 | - * @return string |
|
311 | - */ |
|
312 | - protected static function _find_common_base_path($paths) |
|
313 | - { |
|
314 | - $last_offset = 0; |
|
315 | - $common_base_path = ''; |
|
316 | - while (($index = strpos($paths[0], DS, $last_offset)) !== false) { |
|
317 | - $dir_length = $index - $last_offset + 1; |
|
318 | - $directory = substr($paths[0], $last_offset, $dir_length); |
|
319 | - foreach ($paths as $path) { |
|
320 | - if (substr($path, $last_offset, $dir_length) != $directory) { |
|
321 | - return $common_base_path; |
|
322 | - } |
|
323 | - } |
|
324 | - $common_base_path .= $directory; |
|
325 | - $last_offset = $index + 1; |
|
326 | - } |
|
327 | - return substr($common_base_path, 0, -1); |
|
328 | - } |
|
329 | - |
|
330 | - |
|
331 | - /** |
|
332 | - * load and display a template |
|
333 | - * |
|
334 | - * @param bool|string $template_path server path to the file to be loaded, including file name and extension |
|
335 | - * @param array $template_args an array of arguments to be extracted for use in the template |
|
336 | - * @param boolean $return_string whether to send output immediately to screen, or capture and return as a string |
|
337 | - * @param bool $throw_exceptions if set to true, will throw an exception if the template is either |
|
338 | - * not found or is not readable |
|
339 | - * @return mixed string |
|
340 | - * @throws \DomainException |
|
341 | - */ |
|
62 | + private static $_espresso_themes = array(); |
|
63 | + |
|
64 | + |
|
65 | + /** |
|
66 | + * is_espresso_theme - returns TRUE or FALSE on whether the currently active WP theme is an espresso theme |
|
67 | + * |
|
68 | + * @return boolean |
|
69 | + */ |
|
70 | + public static function is_espresso_theme() |
|
71 | + { |
|
72 | + return wp_get_theme()->get('TextDomain') == 'event_espresso' ? true : false; |
|
73 | + } |
|
74 | + |
|
75 | + /** |
|
76 | + * load_espresso_theme_functions - if current theme is an espresso theme, or uses ee theme template parts, then |
|
77 | + * load it's functions.php file ( if not already loaded ) |
|
78 | + * |
|
79 | + * @return void |
|
80 | + */ |
|
81 | + public static function load_espresso_theme_functions() |
|
82 | + { |
|
83 | + if ( ! defined('EE_THEME_FUNCTIONS_LOADED')) { |
|
84 | + if (is_readable(EE_PUBLIC . EE_Config::get_current_theme() . DS . 'functions.php')) { |
|
85 | + require_once(EE_PUBLIC . EE_Config::get_current_theme() . DS . 'functions.php'); |
|
86 | + } |
|
87 | + } |
|
88 | + } |
|
89 | + |
|
90 | + |
|
91 | + /** |
|
92 | + * get_espresso_themes - returns an array of Espresso Child themes located in the /templates/ directory |
|
93 | + * |
|
94 | + * @return array |
|
95 | + */ |
|
96 | + public static function get_espresso_themes() |
|
97 | + { |
|
98 | + if (empty(EEH_Template::$_espresso_themes)) { |
|
99 | + $espresso_themes = glob(EE_PUBLIC . '*', GLOB_ONLYDIR); |
|
100 | + if (empty($espresso_themes)) { |
|
101 | + return array(); |
|
102 | + } |
|
103 | + if (($key = array_search('global_assets', $espresso_themes)) !== false) { |
|
104 | + unset($espresso_themes[$key]); |
|
105 | + } |
|
106 | + EEH_Template::$_espresso_themes = array(); |
|
107 | + foreach ($espresso_themes as $espresso_theme) { |
|
108 | + EEH_Template::$_espresso_themes[basename($espresso_theme)] = $espresso_theme; |
|
109 | + } |
|
110 | + } |
|
111 | + return EEH_Template::$_espresso_themes; |
|
112 | + } |
|
113 | + |
|
114 | + |
|
115 | + /** |
|
116 | + * EEH_Template::get_template_part |
|
117 | + * basically a copy of the WordPress get_template_part() function but uses EEH_Template::locate_template() instead, |
|
118 | + * and doesn't add base versions of files so not a very useful function at all except that it adds familiarity PLUS |
|
119 | + * filtering based off of the entire template part name |
|
120 | + * |
|
121 | + * @param string $slug The slug name for the generic template. |
|
122 | + * @param string $name The name of the specialised template. |
|
123 | + * @param array $template_args |
|
124 | + * @param bool $return_string |
|
125 | + * @return string the html output for the formatted money value |
|
126 | + */ |
|
127 | + public static function get_template_part( |
|
128 | + $slug = null, |
|
129 | + $name = null, |
|
130 | + $template_args = array(), |
|
131 | + $return_string = false |
|
132 | + ) { |
|
133 | + do_action("get_template_part_{$slug}-{$name}", $slug, $name); |
|
134 | + $templates = array(); |
|
135 | + $name = (string)$name; |
|
136 | + if ($name != '') { |
|
137 | + $templates[] = "{$slug}-{$name}.php"; |
|
138 | + } |
|
139 | + // allow template parts to be turned off via something like: add_filter( 'FHEE__content_espresso_events_tickets_template__display_datetimes', '__return_false' ); |
|
140 | + if (apply_filters("FHEE__EEH_Template__get_template_part__display__{$slug}_{$name}", true)) { |
|
141 | + EEH_Template::locate_template($templates, $template_args, true, $return_string); |
|
142 | + } |
|
143 | + } |
|
144 | + |
|
145 | + |
|
146 | + /** |
|
147 | + * locate_template |
|
148 | + * locate a template file by looking in the following places, in the following order: |
|
149 | + * <server path up to>/wp-content/themes/<current active WordPress theme>/ |
|
150 | + * <assumed full absolute server path> |
|
151 | + * <server path up to>/wp-content/uploads/espresso/templates/<current EE theme>/ |
|
152 | + * <server path up to>/wp-content/uploads/espresso/templates/ |
|
153 | + * <server path up to>/wp-content/plugins/<EE4 folder>/public/<current EE theme>/ |
|
154 | + * <server path up to>/wp-content/plugins/<EE4 folder>/core/templates/<current EE theme>/ |
|
155 | + * <server path up to>/wp-content/plugins/<EE4 folder>/ |
|
156 | + * as soon as the template is found in one of these locations, it will be returned or loaded |
|
157 | + * Example: |
|
158 | + * You are using the WordPress Twenty Sixteen theme, |
|
159 | + * and you want to customize the "some-event.template.php" template, |
|
160 | + * which is located in the "/relative/path/to/" folder relative to the main EE plugin folder. |
|
161 | + * Assuming WP is installed on your server in the "/home/public_html/" folder, |
|
162 | + * EEH_Template::locate_template() will look at the following paths in order until the template is found: |
|
163 | + * /home/public_html/wp-content/themes/twentysixteen/some-event.template.php |
|
164 | + * /relative/path/to/some-event.template.php |
|
165 | + * /home/public_html/wp-content/uploads/espresso/templates/Espresso_Arabica_2014/relative/path/to/some-event.template.php |
|
166 | + * /home/public_html/wp-content/uploads/espresso/templates/relative/path/to/some-event.template.php |
|
167 | + * /home/public_html/wp-content/plugins/event-espresso-core-reg/public/Espresso_Arabica_2014/relative/path/to/some-event.template.php |
|
168 | + * /home/public_html/wp-content/plugins/event-espresso-core-reg/core/templates/Espresso_Arabica_2014/relative/path/to/some-event.template.php |
|
169 | + * /home/public_html/wp-content/plugins/event-espresso-core-reg/relative/path/to/some-event.template.php |
|
170 | + * Had you passed an absolute path to your template that was in some other location, |
|
171 | + * ie: "/absolute/path/to/some-event.template.php" |
|
172 | + * then the search would have been : |
|
173 | + * /home/public_html/wp-content/themes/twentysixteen/some-event.template.php |
|
174 | + * /absolute/path/to/some-event.template.php |
|
175 | + * and stopped there upon finding it in the second location |
|
176 | + * |
|
177 | + * @param array|string $templates array of template file names including extension (or just a single string) |
|
178 | + * @param array $template_args an array of arguments to be extracted for use in the template |
|
179 | + * @param boolean $load whether to pass the located template path on to the |
|
180 | + * EEH_Template::display_template() method or simply return it |
|
181 | + * @param boolean $return_string whether to send output immediately to screen, or capture and return as a |
|
182 | + * string |
|
183 | + * @param boolean $check_if_custom If TRUE, this flags this method to return boolean for whether this will |
|
184 | + * generate a custom template or not. Used in places where you don't actually |
|
185 | + * load the template, you just want to know if there's a custom version of it. |
|
186 | + * @return mixed |
|
187 | + */ |
|
188 | + public static function locate_template( |
|
189 | + $templates = array(), |
|
190 | + $template_args = array(), |
|
191 | + $load = true, |
|
192 | + $return_string = true, |
|
193 | + $check_if_custom = false |
|
194 | + ) { |
|
195 | + // first use WP locate_template to check for template in the current theme folder |
|
196 | + $template_path = locate_template($templates); |
|
197 | + |
|
198 | + if ($check_if_custom && ! empty($template_path)) { |
|
199 | + return true; |
|
200 | + } |
|
201 | + |
|
202 | + // not in the theme |
|
203 | + if (empty($template_path)) { |
|
204 | + // not even a template to look for ? |
|
205 | + if (empty($templates)) { |
|
206 | + // get post_type |
|
207 | + $post_type = EE_Registry::instance()->REQ->get('post_type'); |
|
208 | + // get array of EE Custom Post Types |
|
209 | + $EE_CPTs = EE_Register_CPTs::get_CPTs(); |
|
210 | + // build template name based on request |
|
211 | + if (isset($EE_CPTs[$post_type])) { |
|
212 | + $archive_or_single = is_archive() ? 'archive' : ''; |
|
213 | + $archive_or_single = is_single() ? 'single' : $archive_or_single; |
|
214 | + $templates = $archive_or_single . '-' . $post_type . '.php'; |
|
215 | + } |
|
216 | + } |
|
217 | + // currently active EE template theme |
|
218 | + $current_theme = EE_Config::get_current_theme(); |
|
219 | + |
|
220 | + // array of paths to folders that may contain templates |
|
221 | + $template_folder_paths = array( |
|
222 | + // first check the /wp-content/uploads/espresso/templates/(current EE theme)/ folder for an EE theme template file |
|
223 | + EVENT_ESPRESSO_TEMPLATE_DIR . $current_theme, |
|
224 | + // then in the root of the /wp-content/uploads/espresso/templates/ folder |
|
225 | + EVENT_ESPRESSO_TEMPLATE_DIR, |
|
226 | + ); |
|
227 | + |
|
228 | + //add core plugin folders for checking only if we're not $check_if_custom |
|
229 | + if ( ! $check_if_custom) { |
|
230 | + $core_paths = array( |
|
231 | + // in the /wp-content/plugins/(EE4 folder)/public/(current EE theme)/ folder within the plugin |
|
232 | + EE_PUBLIC . $current_theme, |
|
233 | + // in the /wp-content/plugins/(EE4 folder)/core/templates/(current EE theme)/ folder within the plugin |
|
234 | + EE_TEMPLATES . $current_theme, |
|
235 | + // or maybe relative from the plugin root: /wp-content/plugins/(EE4 folder)/ |
|
236 | + EE_PLUGIN_DIR_PATH, |
|
237 | + ); |
|
238 | + $template_folder_paths = array_merge($template_folder_paths, $core_paths); |
|
239 | + } |
|
240 | + |
|
241 | + // now filter that array |
|
242 | + $template_folder_paths = apply_filters('FHEE__EEH_Template__locate_template__template_folder_paths', |
|
243 | + $template_folder_paths); |
|
244 | + $templates = is_array($templates) ? $templates : array($templates); |
|
245 | + $template_folder_paths = is_array($template_folder_paths) ? $template_folder_paths : array($template_folder_paths); |
|
246 | + // array to hold all possible template paths |
|
247 | + $full_template_paths = array(); |
|
248 | + |
|
249 | + // loop through $templates |
|
250 | + foreach ($templates as $template) { |
|
251 | + // normalize directory separators |
|
252 | + $template = EEH_File::standardise_directory_separators($template); |
|
253 | + $file_name = basename($template); |
|
254 | + $template_path_minus_file_name = substr($template, 0, (strlen($file_name) * -1)); |
|
255 | + // while looping through all template folder paths |
|
256 | + foreach ($template_folder_paths as $template_folder_path) { |
|
257 | + // normalize directory separators |
|
258 | + $template_folder_path = EEH_File::standardise_directory_separators($template_folder_path); |
|
259 | + // determine if any common base path exists between the two paths |
|
260 | + $common_base_path = EEH_Template::_find_common_base_path( |
|
261 | + array($template_folder_path, $template_path_minus_file_name) |
|
262 | + ); |
|
263 | + if ($common_base_path !== '') { |
|
264 | + // both paths have a common base, so just tack the filename onto our search path |
|
265 | + $resolved_path = EEH_File::end_with_directory_separator($template_folder_path) . $file_name; |
|
266 | + } else { |
|
267 | + // no common base path, so let's just concatenate |
|
268 | + $resolved_path = EEH_File::end_with_directory_separator($template_folder_path) . $template; |
|
269 | + } |
|
270 | + // build up our template locations array by adding our resolved paths |
|
271 | + $full_template_paths[] = $resolved_path; |
|
272 | + } |
|
273 | + // if $template is an absolute path, then we'll tack it onto the start of our array so that it gets searched first |
|
274 | + array_unshift($full_template_paths, $template); |
|
275 | + // path to the directory of the current theme: /wp-content/themes/(current WP theme)/ |
|
276 | + array_unshift($full_template_paths, get_stylesheet_directory() . DS . $file_name); |
|
277 | + } |
|
278 | + // filter final array of full template paths |
|
279 | + $full_template_paths = apply_filters('FHEE__EEH_Template__locate_template__full_template_paths', |
|
280 | + $full_template_paths, $file_name); |
|
281 | + // now loop through our final array of template location paths and check each location |
|
282 | + foreach ((array)$full_template_paths as $full_template_path) { |
|
283 | + if (is_readable($full_template_path)) { |
|
284 | + $template_path = str_replace(array('\\', '/'), DIRECTORY_SEPARATOR, $full_template_path); |
|
285 | + break; |
|
286 | + } |
|
287 | + } |
|
288 | + } |
|
289 | + |
|
290 | + // hook that can be used to display the full template path that will be used |
|
291 | + do_action('AHEE__EEH_Template__locate_template__full_template_path', $template_path); |
|
292 | + |
|
293 | + // if we got it and you want to see it... |
|
294 | + if ($template_path && $load && ! $check_if_custom) { |
|
295 | + if ($return_string) { |
|
296 | + return EEH_Template::display_template($template_path, $template_args, true); |
|
297 | + } else { |
|
298 | + EEH_Template::display_template($template_path, $template_args, false); |
|
299 | + } |
|
300 | + } |
|
301 | + return $check_if_custom && ! empty($template_path) ? true : $template_path; |
|
302 | + } |
|
303 | + |
|
304 | + |
|
305 | + /** |
|
306 | + * _find_common_base_path |
|
307 | + * given two paths, this determines if there is a common base path between the two |
|
308 | + * |
|
309 | + * @param array $paths |
|
310 | + * @return string |
|
311 | + */ |
|
312 | + protected static function _find_common_base_path($paths) |
|
313 | + { |
|
314 | + $last_offset = 0; |
|
315 | + $common_base_path = ''; |
|
316 | + while (($index = strpos($paths[0], DS, $last_offset)) !== false) { |
|
317 | + $dir_length = $index - $last_offset + 1; |
|
318 | + $directory = substr($paths[0], $last_offset, $dir_length); |
|
319 | + foreach ($paths as $path) { |
|
320 | + if (substr($path, $last_offset, $dir_length) != $directory) { |
|
321 | + return $common_base_path; |
|
322 | + } |
|
323 | + } |
|
324 | + $common_base_path .= $directory; |
|
325 | + $last_offset = $index + 1; |
|
326 | + } |
|
327 | + return substr($common_base_path, 0, -1); |
|
328 | + } |
|
329 | + |
|
330 | + |
|
331 | + /** |
|
332 | + * load and display a template |
|
333 | + * |
|
334 | + * @param bool|string $template_path server path to the file to be loaded, including file name and extension |
|
335 | + * @param array $template_args an array of arguments to be extracted for use in the template |
|
336 | + * @param boolean $return_string whether to send output immediately to screen, or capture and return as a string |
|
337 | + * @param bool $throw_exceptions if set to true, will throw an exception if the template is either |
|
338 | + * not found or is not readable |
|
339 | + * @return mixed string |
|
340 | + * @throws \DomainException |
|
341 | + */ |
|
342 | 342 | public static function display_template( |
343 | - $template_path = false, |
|
344 | - $template_args = array(), |
|
345 | - $return_string = false, |
|
346 | - $throw_exceptions = false |
|
347 | - ) { |
|
348 | - |
|
349 | - /** |
|
350 | - * These two filters are intended for last minute changes to templates being loaded and/or template arg |
|
351 | - * modifications. NOTE... modifying these things can cause breakage as most templates running through |
|
352 | - * the display_template method are templates we DON'T want modified (usually because of js |
|
353 | - * dependencies etc). So unless you know what you are doing, do NOT filter templates or template args |
|
354 | - * using this. |
|
355 | - * |
|
356 | - * @since 4.6.0 |
|
357 | - */ |
|
358 | - $template_path = (string) apply_filters('FHEE__EEH_Template__display_template__template_path', $template_path); |
|
359 | - $template_args = (array) apply_filters('FHEE__EEH_Template__display_template__template_args', $template_args); |
|
360 | - |
|
361 | - // you gimme nuttin - YOU GET NUTTIN !! |
|
362 | - if ( ! $template_path || ! is_readable($template_path)) { |
|
363 | - return ''; |
|
364 | - } |
|
365 | - // if $template_args are not in an array, then make it so |
|
366 | - if ( ! is_array($template_args) && ! is_object($template_args)) { |
|
367 | - $template_args = array($template_args); |
|
368 | - } |
|
369 | - extract( $template_args, EXTR_SKIP ); |
|
370 | - // ignore whether template is accessible ? |
|
371 | - if ( $throw_exceptions && ! is_readable( $template_path ) ) { |
|
372 | - throw new \DomainException( |
|
373 | - esc_html__( |
|
374 | - 'Invalid, unreadable, or missing file.', |
|
375 | - 'event_espresso' |
|
376 | - ) |
|
377 | - ); |
|
378 | - } |
|
379 | - |
|
380 | - |
|
381 | - if ($return_string) { |
|
382 | - // because we want to return a string, we are going to capture the output |
|
383 | - ob_start(); |
|
384 | - include($template_path); |
|
385 | - return ob_get_clean(); |
|
386 | - } else { |
|
387 | - include($template_path); |
|
388 | - } |
|
389 | - return ''; |
|
390 | - } |
|
391 | - |
|
392 | - |
|
393 | - /** |
|
394 | - * get_object_css_class - attempts to generate a css class based on the type of EE object passed |
|
395 | - * |
|
396 | - * @param EE_Base_Class $object the EE object the css class is being generated for |
|
397 | - * @param string $prefix added to the beginning of the generated class |
|
398 | - * @param string $suffix added to the end of the generated class |
|
399 | - * @return string |
|
400 | - */ |
|
401 | - public static function get_object_css_class($object = null, $prefix = '', $suffix = '') |
|
402 | - { |
|
403 | - // in the beginning... |
|
404 | - $prefix = ! empty($prefix) ? rtrim($prefix, '-') . '-' : ''; |
|
405 | - // da muddle |
|
406 | - $class = ''; |
|
407 | - // the end |
|
408 | - $suffix = ! empty($suffix) ? '-' . ltrim($suffix, '-') : ''; |
|
409 | - // is the passed object an EE object ? |
|
410 | - if ($object instanceof EE_Base_Class) { |
|
411 | - // grab the exact type of object |
|
412 | - $obj_class = get_class($object); |
|
413 | - // depending on the type of object... |
|
414 | - switch ($obj_class) { |
|
415 | - // no specifics just yet... |
|
416 | - default : |
|
417 | - $class = strtolower(str_replace('_', '-', $obj_class)); |
|
418 | - $class .= method_exists($obj_class, 'name') ? '-' . sanitize_title($object->name()) : ''; |
|
419 | - |
|
420 | - } |
|
421 | - } |
|
422 | - return $prefix . $class . $suffix; |
|
423 | - } |
|
424 | - |
|
425 | - |
|
426 | - |
|
427 | - /** |
|
428 | - * EEH_Template::format_currency |
|
429 | - * This helper takes a raw float value and formats it according to the default config country currency settings, or |
|
430 | - * the country currency settings from the supplied country ISO code |
|
431 | - * |
|
432 | - * @param float $amount raw money value |
|
433 | - * @param boolean $return_raw whether to return the formatted float value only with no currency sign or code |
|
434 | - * @param boolean $display_code whether to display the country code (USD). Default = TRUE |
|
435 | - * @param string $CNT_ISO 2 letter ISO code for a country |
|
436 | - * @param string $cur_code_span_class |
|
437 | - * @return string the html output for the formatted money value |
|
438 | - * @throws \EE_Error |
|
439 | - */ |
|
440 | - public static function format_currency( |
|
441 | - $amount = null, |
|
442 | - $return_raw = false, |
|
443 | - $display_code = true, |
|
444 | - $CNT_ISO = '', |
|
445 | - $cur_code_span_class = 'currency-code' |
|
446 | - ) { |
|
447 | - // ensure amount was received |
|
448 | - if ($amount === null) { |
|
449 | - $msg = __('In order to format currency, an amount needs to be passed.', 'event_espresso'); |
|
450 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
451 | - return ''; |
|
452 | - } |
|
453 | - //ensure amount is float |
|
454 | - $amount = apply_filters('FHEE__EEH_Template__format_currency__raw_amount', (float)$amount); |
|
455 | - $CNT_ISO = apply_filters('FHEE__EEH_Template__format_currency__CNT_ISO', $CNT_ISO, $amount); |
|
456 | - // filter raw amount (allows 0.00 to be changed to "free" for example) |
|
457 | - $amount_formatted = apply_filters('FHEE__EEH_Template__format_currency__amount', $amount, $return_raw); |
|
458 | - // still a number or was amount converted to a string like "free" ? |
|
459 | - if (is_float($amount_formatted)) { |
|
460 | - // was a country ISO code passed ? if so generate currency config object for that country |
|
461 | - $mny = $CNT_ISO !== '' ? new EE_Currency_Config($CNT_ISO) : null; |
|
462 | - // verify results |
|
463 | - if ( ! $mny instanceof EE_Currency_Config) { |
|
464 | - // set default config country currency settings |
|
465 | - $mny = EE_Registry::instance()->CFG->currency instanceof EE_Currency_Config |
|
466 | - ? EE_Registry::instance()->CFG->currency |
|
467 | - : new EE_Currency_Config(); |
|
468 | - } |
|
469 | - // format float |
|
470 | - $amount_formatted = number_format($amount, $mny->dec_plc, $mny->dec_mrk, $mny->thsnds); |
|
471 | - // add formatting ? |
|
472 | - if ( ! $return_raw) { |
|
473 | - // add currency sign |
|
474 | - if ($mny->sign_b4) { |
|
475 | - if ($amount >= 0) { |
|
476 | - $amount_formatted = $mny->sign . $amount_formatted; |
|
477 | - } else { |
|
478 | - $amount_formatted = '-' . $mny->sign . str_replace('-', '', $amount_formatted); |
|
479 | - } |
|
480 | - |
|
481 | - } else { |
|
482 | - $amount_formatted = $amount_formatted . $mny->sign; |
|
483 | - } |
|
484 | - |
|
485 | - // filter to allow global setting of display_code |
|
486 | - $display_code = apply_filters('FHEE__EEH_Template__format_currency__display_code', $display_code); |
|
487 | - |
|
488 | - // add currency code ? |
|
489 | - $amount_formatted = $display_code ? $amount_formatted . ' <span class="' . $cur_code_span_class . '">(' . $mny->code . ')</span>' : $amount_formatted; |
|
490 | - } |
|
491 | - // filter results |
|
492 | - $amount_formatted = apply_filters('FHEE__EEH_Template__format_currency__amount_formatted', |
|
493 | - $amount_formatted, $mny, $return_raw); |
|
494 | - } |
|
495 | - // clean up vars |
|
496 | - unset($mny); |
|
497 | - // return formatted currency amount |
|
498 | - return $amount_formatted; |
|
499 | - } |
|
500 | - |
|
501 | - |
|
502 | - /** |
|
503 | - * This function is used for outputting the localized label for a given status id in the schema requested (and |
|
504 | - * possibly plural). The intended use of this function is only for cases where wanting a label outside of a |
|
505 | - * related status model or model object (i.e. in documentation etc.) |
|
506 | - * |
|
507 | - * @param string $status_id Status ID matching a registered status in the esp_status table. If there is no |
|
508 | - * match, then 'Unknown' will be returned. |
|
509 | - * @param boolean $plural Whether to return plural or not |
|
510 | - * @param string $schema 'UPPER', 'lower', or 'Sentence' |
|
511 | - * @return string The localized label for the status id. |
|
512 | - */ |
|
513 | - public static function pretty_status($status_id, $plural = false, $schema = 'upper') |
|
514 | - { |
|
515 | - /** @type EEM_Status $EEM_Status */ |
|
516 | - $EEM_Status = EE_Registry::instance()->load_model('Status'); |
|
517 | - $status = $EEM_Status->localized_status(array($status_id => __('unknown', 'event_espresso')), $plural, |
|
518 | - $schema); |
|
519 | - return $status[$status_id]; |
|
520 | - } |
|
521 | - |
|
522 | - |
|
523 | - /** |
|
524 | - * This helper just returns a button or link for the given parameters |
|
525 | - * |
|
526 | - * @param string $url the url for the link, note that `esc_url` will be called on it |
|
527 | - * @param string $label What is the label you want displayed for the button |
|
528 | - * @param string $class what class is used for the button (defaults to 'button-primary') |
|
529 | - * @param string $icon |
|
530 | - * @param string $title |
|
531 | - * @return string the html output for the button |
|
532 | - */ |
|
533 | - public static function get_button_or_link($url, $label, $class = 'button-primary', $icon = '', $title = '') |
|
534 | - { |
|
535 | - $icon_html = ''; |
|
536 | - if ( ! empty($icon)) { |
|
537 | - $dashicons = preg_split("(ee-icon |dashicons )", $icon); |
|
538 | - $dashicons = array_filter($dashicons); |
|
539 | - $count = count($dashicons); |
|
540 | - $icon_html .= $count > 1 ? '<span class="ee-composite-dashicon">' : ''; |
|
541 | - foreach ($dashicons as $dashicon) { |
|
542 | - $type = strpos($dashicon, 'ee-icon') !== false ? 'ee-icon ' : 'dashicons '; |
|
543 | - $icon_html .= '<span class="' . $type . $dashicon . '"></span>'; |
|
544 | - } |
|
545 | - $icon_html .= $count > 1 ? '</span>' : ''; |
|
546 | - } |
|
547 | - $label = ! empty($icon) ? $icon_html . $label : $label; |
|
548 | - $button = '<a id="' . sanitize_title_with_dashes($label) . '" href="' . esc_url($url) . '" class="' . $class . '" title="' . $title . '">' . $label . '</a>'; |
|
549 | - return $button; |
|
550 | - } |
|
551 | - |
|
552 | - |
|
553 | - /** |
|
554 | - * This returns a generated link that will load the related help tab on admin pages. |
|
555 | - * |
|
556 | - * @param string $help_tab_id the id for the connected help tab |
|
557 | - * @param bool|string $page The page identifier for the page the help tab is on |
|
558 | - * @param bool|string $action The action (route) for the admin page the help tab is on. |
|
559 | - * @param bool|string $icon_style (optional) include css class for the style you want to use for the help icon. |
|
560 | - * @param bool|string $help_text (optional) send help text you want to use for the link if default not to be used |
|
561 | - * @return string generated link |
|
562 | - */ |
|
563 | - public static function get_help_tab_link( |
|
564 | - $help_tab_id, |
|
565 | - $page = false, |
|
566 | - $action = false, |
|
567 | - $icon_style = false, |
|
568 | - $help_text = false |
|
569 | - ) { |
|
570 | - |
|
571 | - if ( ! $page) { |
|
572 | - $page = isset($_REQUEST['page']) && ! empty($_REQUEST['page']) ? sanitize_key($_REQUEST['page']) : $page; |
|
573 | - } |
|
574 | - |
|
575 | - if ( ! $action) { |
|
576 | - $action = isset($_REQUEST['action']) && ! empty($_REQUEST['action']) ? sanitize_key($_REQUEST['action']) : $action; |
|
577 | - } |
|
578 | - |
|
579 | - $action = empty($action) ? 'default' : $action; |
|
580 | - |
|
581 | - |
|
582 | - $help_tab_lnk = $page . '-' . $action . '-' . $help_tab_id; |
|
583 | - $icon = ! $icon_style ? ' dashicons-editor-help' : $icon_style; |
|
584 | - $help_text = ! $help_text ? '' : $help_text; |
|
585 | - return '<a id="' . $help_tab_lnk . '" class="ee-clickable dashicons espresso-help-tab-lnk ee-icon-size-22' . $icon . '" title="' . esc_attr__('Click to open the \'Help\' tab for more information about this feature.', |
|
586 | - 'event_espresso') . '" > ' . $help_text . ' </a>'; |
|
587 | - } |
|
588 | - |
|
589 | - |
|
590 | - /** |
|
591 | - * This helper generates the html structure for the jquery joyride plugin with the given params. |
|
592 | - * |
|
593 | - * @link http://zurb.com/playground/jquery-joyride-feature-tour-plugin |
|
594 | - * @see EE_Admin_Page->_stop_callback() for the construct expected for the $stops param. |
|
595 | - * @param EE_Help_Tour |
|
596 | - * @return string html |
|
597 | - */ |
|
598 | - public static function help_tour_stops_generator(EE_Help_Tour $tour) |
|
599 | - { |
|
600 | - $id = $tour->get_slug(); |
|
601 | - $stops = $tour->get_stops(); |
|
602 | - |
|
603 | - $content = '<ol style="display:none" id="' . $id . '">'; |
|
604 | - |
|
605 | - foreach ($stops as $stop) { |
|
606 | - $data_id = ! empty($stop['id']) ? ' data-id="' . $stop['id'] . '"' : ''; |
|
607 | - $data_class = empty($data_id) && ! empty($stop['class']) ? ' data-class="' . $stop['class'] . '"' : ''; |
|
608 | - |
|
609 | - //if container is set to modal then let's make sure we set the options accordingly |
|
610 | - if (empty($data_id) && empty($data_class)) { |
|
611 | - $stop['options']['modal'] = true; |
|
612 | - $stop['options']['expose'] = true; |
|
613 | - } |
|
614 | - |
|
615 | - $custom_class = ! empty($stop['custom_class']) ? ' class="' . $stop['custom_class'] . '"' : ''; |
|
616 | - $button_text = ! empty($stop['button_text']) ? ' data-button="' . $stop['button_text'] . '"' : ''; |
|
617 | - $inner_content = isset($stop['content']) ? $stop['content'] : ''; |
|
618 | - |
|
619 | - //options |
|
620 | - if (isset($stop['options']) && is_array($stop['options'])) { |
|
621 | - $options = ' data-options="'; |
|
622 | - foreach ($stop['options'] as $option => $value) { |
|
623 | - $options .= $option . ':' . $value . ';'; |
|
624 | - } |
|
625 | - $options .= '"'; |
|
626 | - } else { |
|
627 | - $options = ''; |
|
628 | - } |
|
629 | - |
|
630 | - //let's put all together |
|
631 | - $content .= '<li' . $data_id . $data_class . $custom_class . $button_text . $options . '>' . $inner_content . '</li>'; |
|
632 | - } |
|
633 | - |
|
634 | - $content .= '</ol>'; |
|
635 | - return $content; |
|
636 | - } |
|
637 | - |
|
638 | - |
|
639 | - /** |
|
640 | - * This is a helper method to generate a status legend for a given status array. |
|
641 | - * Note this will only work if the incoming statuses have a key in the EEM_Status->localized_status() methods |
|
642 | - * status_array. |
|
643 | - * |
|
644 | - * @param array $status_array array of statuses that will make up the legend. In format: |
|
645 | - * array( |
|
646 | - * 'status_item' => 'status_name' |
|
647 | - * ) |
|
648 | - * @param string $active_status This is used to indicate what the active status is IF that is to be highlighted in |
|
649 | - * the legend. |
|
650 | - * @throws EE_Error |
|
651 | - * @return string html structure for status. |
|
652 | - */ |
|
653 | - public static function status_legend($status_array, $active_status = '') |
|
654 | - { |
|
655 | - if ( ! is_array($status_array)) { |
|
656 | - throw new EE_Error(esc_html__('The EEH_Template::status_legend helper required the incoming status_array argument to be an array!', |
|
657 | - 'event_espresso')); |
|
658 | - } |
|
659 | - |
|
660 | - $setup_array = array(); |
|
661 | - foreach ($status_array as $item => $status) { |
|
662 | - $setup_array[$item] = array( |
|
663 | - 'class' => 'ee-status-legend ee-status-legend-' . $status, |
|
664 | - 'desc' => EEH_Template::pretty_status($status, false, 'sentence'), |
|
665 | - 'status' => $status, |
|
666 | - ); |
|
667 | - } |
|
668 | - |
|
669 | - $content = '<div class="ee-list-table-legend-container">' . "\n"; |
|
670 | - $content .= '<h4 class="status-legend-title">' . esc_html__('Status Legend', 'event_espresso') . '</h4>' . "\n"; |
|
671 | - $content .= '<dl class="ee-list-table-legend">' . "\n\t"; |
|
672 | - foreach ($setup_array as $item => $details) { |
|
673 | - $active_class = $active_status == $details['status'] ? ' class="ee-is-active-status"' : ''; |
|
674 | - $content .= '<dt id="ee-legend-item-tooltip-' . $item . '"' . $active_class . '>' . "\n\t\t"; |
|
675 | - $content .= '<span class="' . $details['class'] . '"></span>' . "\n\t\t"; |
|
676 | - $content .= '<span class="ee-legend-description">' . $details['desc'] . '</span>' . "\n\t"; |
|
677 | - $content .= '</dt>' . "\n"; |
|
678 | - } |
|
679 | - $content .= '</dl>' . "\n"; |
|
680 | - $content .= '</div>' . "\n"; |
|
681 | - return $content; |
|
682 | - } |
|
683 | - |
|
684 | - |
|
685 | - /** |
|
686 | - * Gets HTML for laying out a deeply-nested array (and objects) in a format |
|
687 | - * that's nice for presenting in the wp admin |
|
688 | - * |
|
689 | - * @param mixed $data |
|
690 | - * @return string |
|
691 | - */ |
|
692 | - public static function layout_array_as_table($data) |
|
693 | - { |
|
694 | - if (is_object($data) || $data instanceof __PHP_Incomplete_Class) { |
|
695 | - $data = (array)$data; |
|
696 | - } |
|
697 | - ob_start(); |
|
698 | - if (is_array($data)) { |
|
699 | - if (EEH_Array::is_associative_array($data)) { |
|
700 | - ?> |
|
343 | + $template_path = false, |
|
344 | + $template_args = array(), |
|
345 | + $return_string = false, |
|
346 | + $throw_exceptions = false |
|
347 | + ) { |
|
348 | + |
|
349 | + /** |
|
350 | + * These two filters are intended for last minute changes to templates being loaded and/or template arg |
|
351 | + * modifications. NOTE... modifying these things can cause breakage as most templates running through |
|
352 | + * the display_template method are templates we DON'T want modified (usually because of js |
|
353 | + * dependencies etc). So unless you know what you are doing, do NOT filter templates or template args |
|
354 | + * using this. |
|
355 | + * |
|
356 | + * @since 4.6.0 |
|
357 | + */ |
|
358 | + $template_path = (string) apply_filters('FHEE__EEH_Template__display_template__template_path', $template_path); |
|
359 | + $template_args = (array) apply_filters('FHEE__EEH_Template__display_template__template_args', $template_args); |
|
360 | + |
|
361 | + // you gimme nuttin - YOU GET NUTTIN !! |
|
362 | + if ( ! $template_path || ! is_readable($template_path)) { |
|
363 | + return ''; |
|
364 | + } |
|
365 | + // if $template_args are not in an array, then make it so |
|
366 | + if ( ! is_array($template_args) && ! is_object($template_args)) { |
|
367 | + $template_args = array($template_args); |
|
368 | + } |
|
369 | + extract( $template_args, EXTR_SKIP ); |
|
370 | + // ignore whether template is accessible ? |
|
371 | + if ( $throw_exceptions && ! is_readable( $template_path ) ) { |
|
372 | + throw new \DomainException( |
|
373 | + esc_html__( |
|
374 | + 'Invalid, unreadable, or missing file.', |
|
375 | + 'event_espresso' |
|
376 | + ) |
|
377 | + ); |
|
378 | + } |
|
379 | + |
|
380 | + |
|
381 | + if ($return_string) { |
|
382 | + // because we want to return a string, we are going to capture the output |
|
383 | + ob_start(); |
|
384 | + include($template_path); |
|
385 | + return ob_get_clean(); |
|
386 | + } else { |
|
387 | + include($template_path); |
|
388 | + } |
|
389 | + return ''; |
|
390 | + } |
|
391 | + |
|
392 | + |
|
393 | + /** |
|
394 | + * get_object_css_class - attempts to generate a css class based on the type of EE object passed |
|
395 | + * |
|
396 | + * @param EE_Base_Class $object the EE object the css class is being generated for |
|
397 | + * @param string $prefix added to the beginning of the generated class |
|
398 | + * @param string $suffix added to the end of the generated class |
|
399 | + * @return string |
|
400 | + */ |
|
401 | + public static function get_object_css_class($object = null, $prefix = '', $suffix = '') |
|
402 | + { |
|
403 | + // in the beginning... |
|
404 | + $prefix = ! empty($prefix) ? rtrim($prefix, '-') . '-' : ''; |
|
405 | + // da muddle |
|
406 | + $class = ''; |
|
407 | + // the end |
|
408 | + $suffix = ! empty($suffix) ? '-' . ltrim($suffix, '-') : ''; |
|
409 | + // is the passed object an EE object ? |
|
410 | + if ($object instanceof EE_Base_Class) { |
|
411 | + // grab the exact type of object |
|
412 | + $obj_class = get_class($object); |
|
413 | + // depending on the type of object... |
|
414 | + switch ($obj_class) { |
|
415 | + // no specifics just yet... |
|
416 | + default : |
|
417 | + $class = strtolower(str_replace('_', '-', $obj_class)); |
|
418 | + $class .= method_exists($obj_class, 'name') ? '-' . sanitize_title($object->name()) : ''; |
|
419 | + |
|
420 | + } |
|
421 | + } |
|
422 | + return $prefix . $class . $suffix; |
|
423 | + } |
|
424 | + |
|
425 | + |
|
426 | + |
|
427 | + /** |
|
428 | + * EEH_Template::format_currency |
|
429 | + * This helper takes a raw float value and formats it according to the default config country currency settings, or |
|
430 | + * the country currency settings from the supplied country ISO code |
|
431 | + * |
|
432 | + * @param float $amount raw money value |
|
433 | + * @param boolean $return_raw whether to return the formatted float value only with no currency sign or code |
|
434 | + * @param boolean $display_code whether to display the country code (USD). Default = TRUE |
|
435 | + * @param string $CNT_ISO 2 letter ISO code for a country |
|
436 | + * @param string $cur_code_span_class |
|
437 | + * @return string the html output for the formatted money value |
|
438 | + * @throws \EE_Error |
|
439 | + */ |
|
440 | + public static function format_currency( |
|
441 | + $amount = null, |
|
442 | + $return_raw = false, |
|
443 | + $display_code = true, |
|
444 | + $CNT_ISO = '', |
|
445 | + $cur_code_span_class = 'currency-code' |
|
446 | + ) { |
|
447 | + // ensure amount was received |
|
448 | + if ($amount === null) { |
|
449 | + $msg = __('In order to format currency, an amount needs to be passed.', 'event_espresso'); |
|
450 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
451 | + return ''; |
|
452 | + } |
|
453 | + //ensure amount is float |
|
454 | + $amount = apply_filters('FHEE__EEH_Template__format_currency__raw_amount', (float)$amount); |
|
455 | + $CNT_ISO = apply_filters('FHEE__EEH_Template__format_currency__CNT_ISO', $CNT_ISO, $amount); |
|
456 | + // filter raw amount (allows 0.00 to be changed to "free" for example) |
|
457 | + $amount_formatted = apply_filters('FHEE__EEH_Template__format_currency__amount', $amount, $return_raw); |
|
458 | + // still a number or was amount converted to a string like "free" ? |
|
459 | + if (is_float($amount_formatted)) { |
|
460 | + // was a country ISO code passed ? if so generate currency config object for that country |
|
461 | + $mny = $CNT_ISO !== '' ? new EE_Currency_Config($CNT_ISO) : null; |
|
462 | + // verify results |
|
463 | + if ( ! $mny instanceof EE_Currency_Config) { |
|
464 | + // set default config country currency settings |
|
465 | + $mny = EE_Registry::instance()->CFG->currency instanceof EE_Currency_Config |
|
466 | + ? EE_Registry::instance()->CFG->currency |
|
467 | + : new EE_Currency_Config(); |
|
468 | + } |
|
469 | + // format float |
|
470 | + $amount_formatted = number_format($amount, $mny->dec_plc, $mny->dec_mrk, $mny->thsnds); |
|
471 | + // add formatting ? |
|
472 | + if ( ! $return_raw) { |
|
473 | + // add currency sign |
|
474 | + if ($mny->sign_b4) { |
|
475 | + if ($amount >= 0) { |
|
476 | + $amount_formatted = $mny->sign . $amount_formatted; |
|
477 | + } else { |
|
478 | + $amount_formatted = '-' . $mny->sign . str_replace('-', '', $amount_formatted); |
|
479 | + } |
|
480 | + |
|
481 | + } else { |
|
482 | + $amount_formatted = $amount_formatted . $mny->sign; |
|
483 | + } |
|
484 | + |
|
485 | + // filter to allow global setting of display_code |
|
486 | + $display_code = apply_filters('FHEE__EEH_Template__format_currency__display_code', $display_code); |
|
487 | + |
|
488 | + // add currency code ? |
|
489 | + $amount_formatted = $display_code ? $amount_formatted . ' <span class="' . $cur_code_span_class . '">(' . $mny->code . ')</span>' : $amount_formatted; |
|
490 | + } |
|
491 | + // filter results |
|
492 | + $amount_formatted = apply_filters('FHEE__EEH_Template__format_currency__amount_formatted', |
|
493 | + $amount_formatted, $mny, $return_raw); |
|
494 | + } |
|
495 | + // clean up vars |
|
496 | + unset($mny); |
|
497 | + // return formatted currency amount |
|
498 | + return $amount_formatted; |
|
499 | + } |
|
500 | + |
|
501 | + |
|
502 | + /** |
|
503 | + * This function is used for outputting the localized label for a given status id in the schema requested (and |
|
504 | + * possibly plural). The intended use of this function is only for cases where wanting a label outside of a |
|
505 | + * related status model or model object (i.e. in documentation etc.) |
|
506 | + * |
|
507 | + * @param string $status_id Status ID matching a registered status in the esp_status table. If there is no |
|
508 | + * match, then 'Unknown' will be returned. |
|
509 | + * @param boolean $plural Whether to return plural or not |
|
510 | + * @param string $schema 'UPPER', 'lower', or 'Sentence' |
|
511 | + * @return string The localized label for the status id. |
|
512 | + */ |
|
513 | + public static function pretty_status($status_id, $plural = false, $schema = 'upper') |
|
514 | + { |
|
515 | + /** @type EEM_Status $EEM_Status */ |
|
516 | + $EEM_Status = EE_Registry::instance()->load_model('Status'); |
|
517 | + $status = $EEM_Status->localized_status(array($status_id => __('unknown', 'event_espresso')), $plural, |
|
518 | + $schema); |
|
519 | + return $status[$status_id]; |
|
520 | + } |
|
521 | + |
|
522 | + |
|
523 | + /** |
|
524 | + * This helper just returns a button or link for the given parameters |
|
525 | + * |
|
526 | + * @param string $url the url for the link, note that `esc_url` will be called on it |
|
527 | + * @param string $label What is the label you want displayed for the button |
|
528 | + * @param string $class what class is used for the button (defaults to 'button-primary') |
|
529 | + * @param string $icon |
|
530 | + * @param string $title |
|
531 | + * @return string the html output for the button |
|
532 | + */ |
|
533 | + public static function get_button_or_link($url, $label, $class = 'button-primary', $icon = '', $title = '') |
|
534 | + { |
|
535 | + $icon_html = ''; |
|
536 | + if ( ! empty($icon)) { |
|
537 | + $dashicons = preg_split("(ee-icon |dashicons )", $icon); |
|
538 | + $dashicons = array_filter($dashicons); |
|
539 | + $count = count($dashicons); |
|
540 | + $icon_html .= $count > 1 ? '<span class="ee-composite-dashicon">' : ''; |
|
541 | + foreach ($dashicons as $dashicon) { |
|
542 | + $type = strpos($dashicon, 'ee-icon') !== false ? 'ee-icon ' : 'dashicons '; |
|
543 | + $icon_html .= '<span class="' . $type . $dashicon . '"></span>'; |
|
544 | + } |
|
545 | + $icon_html .= $count > 1 ? '</span>' : ''; |
|
546 | + } |
|
547 | + $label = ! empty($icon) ? $icon_html . $label : $label; |
|
548 | + $button = '<a id="' . sanitize_title_with_dashes($label) . '" href="' . esc_url($url) . '" class="' . $class . '" title="' . $title . '">' . $label . '</a>'; |
|
549 | + return $button; |
|
550 | + } |
|
551 | + |
|
552 | + |
|
553 | + /** |
|
554 | + * This returns a generated link that will load the related help tab on admin pages. |
|
555 | + * |
|
556 | + * @param string $help_tab_id the id for the connected help tab |
|
557 | + * @param bool|string $page The page identifier for the page the help tab is on |
|
558 | + * @param bool|string $action The action (route) for the admin page the help tab is on. |
|
559 | + * @param bool|string $icon_style (optional) include css class for the style you want to use for the help icon. |
|
560 | + * @param bool|string $help_text (optional) send help text you want to use for the link if default not to be used |
|
561 | + * @return string generated link |
|
562 | + */ |
|
563 | + public static function get_help_tab_link( |
|
564 | + $help_tab_id, |
|
565 | + $page = false, |
|
566 | + $action = false, |
|
567 | + $icon_style = false, |
|
568 | + $help_text = false |
|
569 | + ) { |
|
570 | + |
|
571 | + if ( ! $page) { |
|
572 | + $page = isset($_REQUEST['page']) && ! empty($_REQUEST['page']) ? sanitize_key($_REQUEST['page']) : $page; |
|
573 | + } |
|
574 | + |
|
575 | + if ( ! $action) { |
|
576 | + $action = isset($_REQUEST['action']) && ! empty($_REQUEST['action']) ? sanitize_key($_REQUEST['action']) : $action; |
|
577 | + } |
|
578 | + |
|
579 | + $action = empty($action) ? 'default' : $action; |
|
580 | + |
|
581 | + |
|
582 | + $help_tab_lnk = $page . '-' . $action . '-' . $help_tab_id; |
|
583 | + $icon = ! $icon_style ? ' dashicons-editor-help' : $icon_style; |
|
584 | + $help_text = ! $help_text ? '' : $help_text; |
|
585 | + return '<a id="' . $help_tab_lnk . '" class="ee-clickable dashicons espresso-help-tab-lnk ee-icon-size-22' . $icon . '" title="' . esc_attr__('Click to open the \'Help\' tab for more information about this feature.', |
|
586 | + 'event_espresso') . '" > ' . $help_text . ' </a>'; |
|
587 | + } |
|
588 | + |
|
589 | + |
|
590 | + /** |
|
591 | + * This helper generates the html structure for the jquery joyride plugin with the given params. |
|
592 | + * |
|
593 | + * @link http://zurb.com/playground/jquery-joyride-feature-tour-plugin |
|
594 | + * @see EE_Admin_Page->_stop_callback() for the construct expected for the $stops param. |
|
595 | + * @param EE_Help_Tour |
|
596 | + * @return string html |
|
597 | + */ |
|
598 | + public static function help_tour_stops_generator(EE_Help_Tour $tour) |
|
599 | + { |
|
600 | + $id = $tour->get_slug(); |
|
601 | + $stops = $tour->get_stops(); |
|
602 | + |
|
603 | + $content = '<ol style="display:none" id="' . $id . '">'; |
|
604 | + |
|
605 | + foreach ($stops as $stop) { |
|
606 | + $data_id = ! empty($stop['id']) ? ' data-id="' . $stop['id'] . '"' : ''; |
|
607 | + $data_class = empty($data_id) && ! empty($stop['class']) ? ' data-class="' . $stop['class'] . '"' : ''; |
|
608 | + |
|
609 | + //if container is set to modal then let's make sure we set the options accordingly |
|
610 | + if (empty($data_id) && empty($data_class)) { |
|
611 | + $stop['options']['modal'] = true; |
|
612 | + $stop['options']['expose'] = true; |
|
613 | + } |
|
614 | + |
|
615 | + $custom_class = ! empty($stop['custom_class']) ? ' class="' . $stop['custom_class'] . '"' : ''; |
|
616 | + $button_text = ! empty($stop['button_text']) ? ' data-button="' . $stop['button_text'] . '"' : ''; |
|
617 | + $inner_content = isset($stop['content']) ? $stop['content'] : ''; |
|
618 | + |
|
619 | + //options |
|
620 | + if (isset($stop['options']) && is_array($stop['options'])) { |
|
621 | + $options = ' data-options="'; |
|
622 | + foreach ($stop['options'] as $option => $value) { |
|
623 | + $options .= $option . ':' . $value . ';'; |
|
624 | + } |
|
625 | + $options .= '"'; |
|
626 | + } else { |
|
627 | + $options = ''; |
|
628 | + } |
|
629 | + |
|
630 | + //let's put all together |
|
631 | + $content .= '<li' . $data_id . $data_class . $custom_class . $button_text . $options . '>' . $inner_content . '</li>'; |
|
632 | + } |
|
633 | + |
|
634 | + $content .= '</ol>'; |
|
635 | + return $content; |
|
636 | + } |
|
637 | + |
|
638 | + |
|
639 | + /** |
|
640 | + * This is a helper method to generate a status legend for a given status array. |
|
641 | + * Note this will only work if the incoming statuses have a key in the EEM_Status->localized_status() methods |
|
642 | + * status_array. |
|
643 | + * |
|
644 | + * @param array $status_array array of statuses that will make up the legend. In format: |
|
645 | + * array( |
|
646 | + * 'status_item' => 'status_name' |
|
647 | + * ) |
|
648 | + * @param string $active_status This is used to indicate what the active status is IF that is to be highlighted in |
|
649 | + * the legend. |
|
650 | + * @throws EE_Error |
|
651 | + * @return string html structure for status. |
|
652 | + */ |
|
653 | + public static function status_legend($status_array, $active_status = '') |
|
654 | + { |
|
655 | + if ( ! is_array($status_array)) { |
|
656 | + throw new EE_Error(esc_html__('The EEH_Template::status_legend helper required the incoming status_array argument to be an array!', |
|
657 | + 'event_espresso')); |
|
658 | + } |
|
659 | + |
|
660 | + $setup_array = array(); |
|
661 | + foreach ($status_array as $item => $status) { |
|
662 | + $setup_array[$item] = array( |
|
663 | + 'class' => 'ee-status-legend ee-status-legend-' . $status, |
|
664 | + 'desc' => EEH_Template::pretty_status($status, false, 'sentence'), |
|
665 | + 'status' => $status, |
|
666 | + ); |
|
667 | + } |
|
668 | + |
|
669 | + $content = '<div class="ee-list-table-legend-container">' . "\n"; |
|
670 | + $content .= '<h4 class="status-legend-title">' . esc_html__('Status Legend', 'event_espresso') . '</h4>' . "\n"; |
|
671 | + $content .= '<dl class="ee-list-table-legend">' . "\n\t"; |
|
672 | + foreach ($setup_array as $item => $details) { |
|
673 | + $active_class = $active_status == $details['status'] ? ' class="ee-is-active-status"' : ''; |
|
674 | + $content .= '<dt id="ee-legend-item-tooltip-' . $item . '"' . $active_class . '>' . "\n\t\t"; |
|
675 | + $content .= '<span class="' . $details['class'] . '"></span>' . "\n\t\t"; |
|
676 | + $content .= '<span class="ee-legend-description">' . $details['desc'] . '</span>' . "\n\t"; |
|
677 | + $content .= '</dt>' . "\n"; |
|
678 | + } |
|
679 | + $content .= '</dl>' . "\n"; |
|
680 | + $content .= '</div>' . "\n"; |
|
681 | + return $content; |
|
682 | + } |
|
683 | + |
|
684 | + |
|
685 | + /** |
|
686 | + * Gets HTML for laying out a deeply-nested array (and objects) in a format |
|
687 | + * that's nice for presenting in the wp admin |
|
688 | + * |
|
689 | + * @param mixed $data |
|
690 | + * @return string |
|
691 | + */ |
|
692 | + public static function layout_array_as_table($data) |
|
693 | + { |
|
694 | + if (is_object($data) || $data instanceof __PHP_Incomplete_Class) { |
|
695 | + $data = (array)$data; |
|
696 | + } |
|
697 | + ob_start(); |
|
698 | + if (is_array($data)) { |
|
699 | + if (EEH_Array::is_associative_array($data)) { |
|
700 | + ?> |
|
701 | 701 | <table class="widefat"> |
702 | 702 | <tbody> |
703 | 703 | <?php |
704 | - foreach ($data as $data_key => $data_values) { |
|
705 | - ?> |
|
704 | + foreach ($data as $data_key => $data_values) { |
|
705 | + ?> |
|
706 | 706 | <tr> |
707 | 707 | <td> |
708 | 708 | <?php echo $data_key; ?> |
@@ -712,248 +712,248 @@ discard block |
||
712 | 712 | </td> |
713 | 713 | </tr> |
714 | 714 | <?php |
715 | - } ?> |
|
715 | + } ?> |
|
716 | 716 | </tbody> |
717 | 717 | </table> |
718 | 718 | <?php |
719 | - } else { |
|
720 | - ?> |
|
719 | + } else { |
|
720 | + ?> |
|
721 | 721 | <ul> |
722 | 722 | <?php |
723 | - foreach ($data as $datum) { |
|
724 | - echo "<li>"; |
|
725 | - echo self::layout_array_as_table($datum); |
|
726 | - echo "</li>"; |
|
727 | - } ?> |
|
723 | + foreach ($data as $datum) { |
|
724 | + echo "<li>"; |
|
725 | + echo self::layout_array_as_table($datum); |
|
726 | + echo "</li>"; |
|
727 | + } ?> |
|
728 | 728 | </ul> |
729 | 729 | <?php |
730 | - } |
|
731 | - } else { |
|
732 | - //simple value |
|
733 | - echo esc_html($data); |
|
734 | - } |
|
735 | - return ob_get_clean(); |
|
736 | - } |
|
737 | - |
|
738 | - |
|
739 | - /** |
|
740 | - * wrapper for self::get_paging_html() that simply echos the generated paging html |
|
741 | - * |
|
742 | - * @since 4.4.0 |
|
743 | - * @see self:get_paging_html() for argument docs. |
|
744 | - * @param $total_items |
|
745 | - * @param $current |
|
746 | - * @param $per_page |
|
747 | - * @param $url |
|
748 | - * @param bool $show_num_field |
|
749 | - * @param string $paged_arg_name |
|
750 | - * @param array $items_label |
|
751 | - * @return string |
|
752 | - */ |
|
753 | - public static function paging_html( |
|
754 | - $total_items, |
|
755 | - $current, |
|
756 | - $per_page, |
|
757 | - $url, |
|
758 | - $show_num_field = true, |
|
759 | - $paged_arg_name = 'paged', |
|
760 | - $items_label = array() |
|
761 | - ) { |
|
762 | - echo self::get_paging_html($total_items, $current, $per_page, $url, $show_num_field, $paged_arg_name, |
|
763 | - $items_label); |
|
764 | - } |
|
765 | - |
|
766 | - |
|
767 | - /** |
|
768 | - * A method for generating paging similar to WP_List_Table |
|
769 | - * |
|
770 | - * @since 4.4.0 |
|
771 | - * @see wp-admin/includes/class-wp-list-table.php WP_List_Table::pagination() |
|
772 | - * @param integer $total_items How many total items there are to page. |
|
773 | - * @param integer $current What the current page is. |
|
774 | - * @param integer $per_page How many items per page. |
|
775 | - * @param string $url What the base url for page links is. |
|
776 | - * @param boolean $show_num_field Whether to show the input for changing page number. |
|
777 | - * @param string $paged_arg_name The name of the key for the paged query argument. |
|
778 | - * @param array $items_label An array of singular/plural values for the items label: |
|
779 | - * array( |
|
780 | - * 'single' => 'item', |
|
781 | - * 'plural' => 'items' |
|
782 | - * ) |
|
783 | - * @return string |
|
784 | - */ |
|
785 | - public static function get_paging_html( |
|
786 | - $total_items, |
|
787 | - $current, |
|
788 | - $per_page, |
|
789 | - $url, |
|
790 | - $show_num_field = true, |
|
791 | - $paged_arg_name = 'paged', |
|
792 | - $items_label = array() |
|
793 | - ) { |
|
794 | - $page_links = array(); |
|
795 | - $disable_first = $disable_last = ''; |
|
796 | - $total_items = (int)$total_items; |
|
797 | - $per_page = (int)$per_page; |
|
798 | - $current = (int)$current; |
|
799 | - $paged_arg_name = empty($paged_arg_name) ? 'paged' : sanitize_key($paged_arg_name); |
|
800 | - |
|
801 | - //filter items_label |
|
802 | - $items_label = apply_filters( |
|
803 | - 'FHEE__EEH_Template__get_paging_html__items_label', |
|
804 | - $items_label |
|
805 | - ); |
|
806 | - |
|
807 | - if (empty($items_label) |
|
808 | - || ! is_array($items_label) |
|
809 | - || ! isset($items_label['single']) |
|
810 | - || ! isset($items_label['plural']) |
|
811 | - ) { |
|
812 | - $items_label = array( |
|
813 | - 'single' => __('1 item', 'event_espresso'), |
|
814 | - 'plural' => __('%s items', 'event_espresso'), |
|
815 | - ); |
|
816 | - } else { |
|
817 | - $items_label = array( |
|
818 | - 'single' => '1 ' . esc_html($items_label['single']), |
|
819 | - 'plural' => '%s ' . esc_html($items_label['plural']), |
|
820 | - ); |
|
821 | - } |
|
822 | - |
|
823 | - $total_pages = ceil($total_items / $per_page); |
|
824 | - |
|
825 | - if ($total_pages <= 1) { |
|
826 | - return ''; |
|
827 | - } |
|
828 | - |
|
829 | - $item_label = $total_items > 1 ? sprintf($items_label['plural'], $total_items) : $items_label['single']; |
|
830 | - |
|
831 | - $output = '<span class="displaying-num">' . $item_label . '</span>'; |
|
832 | - |
|
833 | - if ($current === 1) { |
|
834 | - $disable_first = ' disabled'; |
|
835 | - } |
|
836 | - if ($current == $total_pages) { |
|
837 | - $disable_last = ' disabled'; |
|
838 | - } |
|
839 | - |
|
840 | - $page_links[] = sprintf("<a class='%s' title='%s' href='%s'>%s</a>", |
|
841 | - 'first-page' . $disable_first, |
|
842 | - esc_attr__('Go to the first page'), |
|
843 | - esc_url(remove_query_arg($paged_arg_name, $url)), |
|
844 | - '«' |
|
845 | - ); |
|
846 | - |
|
847 | - $page_links[] = sprintf( |
|
848 | - '<a class="%s" title="%s" href="%s">%s</a>', |
|
849 | - 'prev-page' . $disable_first, |
|
850 | - esc_attr__('Go to the previous page'), |
|
851 | - esc_url(add_query_arg($paged_arg_name, max(1, $current - 1), $url)), |
|
852 | - '‹' |
|
853 | - ); |
|
854 | - |
|
855 | - if ( ! $show_num_field) { |
|
856 | - $html_current_page = $current; |
|
857 | - } else { |
|
858 | - $html_current_page = sprintf("<input class='current-page' title='%s' type='text' name=$paged_arg_name value='%s' size='%d' />", |
|
859 | - esc_attr__('Current page'), |
|
860 | - $current, |
|
861 | - strlen($total_pages) |
|
862 | - ); |
|
863 | - } |
|
864 | - |
|
865 | - $html_total_pages = sprintf( |
|
866 | - '<span class="total-pages">%s</span>', |
|
867 | - number_format_i18n($total_pages) |
|
868 | - ); |
|
869 | - $page_links[] = sprintf( |
|
870 | - _x('%3$s%1$s of %2$s%4$s', 'paging'), |
|
871 | - $html_current_page, |
|
872 | - $html_total_pages, |
|
873 | - '<span class="paging-input">', |
|
874 | - '</span>' |
|
875 | - ); |
|
876 | - |
|
877 | - $page_links[] = sprintf( |
|
878 | - '<a class="%s" title="%s" href="%s">%s</a>', |
|
879 | - 'next-page' . $disable_last, |
|
880 | - esc_attr__('Go to the next page'), |
|
881 | - esc_url(add_query_arg($paged_arg_name, min($total_pages, $current + 1), $url)), |
|
882 | - '›' |
|
883 | - ); |
|
884 | - |
|
885 | - $page_links[] = sprintf( |
|
886 | - '<a class="%s" title="%s" href="%s">%s</a>', |
|
887 | - 'last-page' . $disable_last, |
|
888 | - esc_attr__('Go to the last page'), |
|
889 | - esc_url(add_query_arg($paged_arg_name, $total_pages, $url)), |
|
890 | - '»' |
|
891 | - ); |
|
892 | - |
|
893 | - $output .= "\n" . '<span class="pagination-links">' . join("\n", $page_links) . '</span>'; |
|
894 | - // set page class |
|
895 | - if ($total_pages) { |
|
896 | - $page_class = $total_pages < 2 ? ' one-page' : ''; |
|
897 | - } else { |
|
898 | - $page_class = ' no-pages'; |
|
899 | - } |
|
900 | - |
|
901 | - return '<div class="tablenav"><div class="tablenav-pages' . $page_class . '">' . $output . '</div></div>'; |
|
902 | - } |
|
903 | - |
|
904 | - |
|
905 | - /** |
|
906 | - * @param string $wrap_class |
|
907 | - * @param string $wrap_id |
|
908 | - * @return string |
|
909 | - */ |
|
910 | - public static function powered_by_event_espresso($wrap_class = '', $wrap_id = '', array $query_args = array()) |
|
911 | - { |
|
912 | - $admin = is_admin() && ! (defined('DOING_AJAX') && DOING_AJAX); |
|
913 | - if ( |
|
914 | - ! $admin && |
|
915 | - ! apply_filters( |
|
916 | - 'FHEE__EEH_Template__powered_by_event_espresso__show_reg_footer', |
|
917 | - EE_Registry::instance()->CFG->admin->show_reg_footer |
|
918 | - ) |
|
919 | - ) { |
|
920 | - return ''; |
|
921 | - } |
|
922 | - $tag = $admin ? 'span' : 'div'; |
|
923 | - $attributes = ! empty($wrap_id) ? " id=\"{$wrap_id}\"" : ''; |
|
924 | - $wrap_class = $admin ? "{$wrap_class} float-left" : $wrap_class; |
|
925 | - $attributes .= ! empty($wrap_class) |
|
926 | - ? " class=\"{$wrap_class} powered-by-event-espresso-credit\"" |
|
927 | - : ' class="powered-by-event-espresso-credit"'; |
|
928 | - $query_args = array_merge( |
|
929 | - array( |
|
930 | - 'ap_id' => EE_Registry::instance()->CFG->admin->affiliate_id(), |
|
931 | - 'utm_source' => 'powered_by_event_espresso', |
|
932 | - 'utm_medium' => 'link', |
|
933 | - 'utm_campaign' => 'powered_by', |
|
934 | - ), |
|
935 | - $query_args |
|
936 | - ); |
|
937 | - $powered_by = apply_filters('FHEE__EEH_Template__powered_by_event_espresso_text', |
|
938 | - $admin ? 'Event Espresso - ' . EVENT_ESPRESSO_VERSION : 'Event Espresso'); |
|
939 | - $url = add_query_arg($query_args, 'https://eventespresso.com/'); |
|
940 | - $url = apply_filters('FHEE__EEH_Template__powered_by_event_espresso__url', $url); |
|
941 | - return (string)apply_filters( |
|
942 | - 'FHEE__EEH_Template__powered_by_event_espresso__html', |
|
943 | - sprintf( |
|
944 | - esc_html_x( |
|
945 | - '%3$s%1$sOnline event registration and ticketing powered by %2$s%3$s', |
|
946 | - 'Online event registration and ticketing powered by [link to eventespresso.com]', |
|
947 | - 'event_espresso' |
|
948 | - ), |
|
949 | - "<{$tag}{$attributes}>", |
|
950 | - "<a href=\"{$url}\" target=\"_blank\" rel=\"nofollow\">{$powered_by}</a></{$tag}>", |
|
951 | - $admin ? '' : '<br />' |
|
952 | - ), |
|
953 | - $wrap_class, |
|
954 | - $wrap_id |
|
955 | - ); |
|
956 | - } |
|
730 | + } |
|
731 | + } else { |
|
732 | + //simple value |
|
733 | + echo esc_html($data); |
|
734 | + } |
|
735 | + return ob_get_clean(); |
|
736 | + } |
|
737 | + |
|
738 | + |
|
739 | + /** |
|
740 | + * wrapper for self::get_paging_html() that simply echos the generated paging html |
|
741 | + * |
|
742 | + * @since 4.4.0 |
|
743 | + * @see self:get_paging_html() for argument docs. |
|
744 | + * @param $total_items |
|
745 | + * @param $current |
|
746 | + * @param $per_page |
|
747 | + * @param $url |
|
748 | + * @param bool $show_num_field |
|
749 | + * @param string $paged_arg_name |
|
750 | + * @param array $items_label |
|
751 | + * @return string |
|
752 | + */ |
|
753 | + public static function paging_html( |
|
754 | + $total_items, |
|
755 | + $current, |
|
756 | + $per_page, |
|
757 | + $url, |
|
758 | + $show_num_field = true, |
|
759 | + $paged_arg_name = 'paged', |
|
760 | + $items_label = array() |
|
761 | + ) { |
|
762 | + echo self::get_paging_html($total_items, $current, $per_page, $url, $show_num_field, $paged_arg_name, |
|
763 | + $items_label); |
|
764 | + } |
|
765 | + |
|
766 | + |
|
767 | + /** |
|
768 | + * A method for generating paging similar to WP_List_Table |
|
769 | + * |
|
770 | + * @since 4.4.0 |
|
771 | + * @see wp-admin/includes/class-wp-list-table.php WP_List_Table::pagination() |
|
772 | + * @param integer $total_items How many total items there are to page. |
|
773 | + * @param integer $current What the current page is. |
|
774 | + * @param integer $per_page How many items per page. |
|
775 | + * @param string $url What the base url for page links is. |
|
776 | + * @param boolean $show_num_field Whether to show the input for changing page number. |
|
777 | + * @param string $paged_arg_name The name of the key for the paged query argument. |
|
778 | + * @param array $items_label An array of singular/plural values for the items label: |
|
779 | + * array( |
|
780 | + * 'single' => 'item', |
|
781 | + * 'plural' => 'items' |
|
782 | + * ) |
|
783 | + * @return string |
|
784 | + */ |
|
785 | + public static function get_paging_html( |
|
786 | + $total_items, |
|
787 | + $current, |
|
788 | + $per_page, |
|
789 | + $url, |
|
790 | + $show_num_field = true, |
|
791 | + $paged_arg_name = 'paged', |
|
792 | + $items_label = array() |
|
793 | + ) { |
|
794 | + $page_links = array(); |
|
795 | + $disable_first = $disable_last = ''; |
|
796 | + $total_items = (int)$total_items; |
|
797 | + $per_page = (int)$per_page; |
|
798 | + $current = (int)$current; |
|
799 | + $paged_arg_name = empty($paged_arg_name) ? 'paged' : sanitize_key($paged_arg_name); |
|
800 | + |
|
801 | + //filter items_label |
|
802 | + $items_label = apply_filters( |
|
803 | + 'FHEE__EEH_Template__get_paging_html__items_label', |
|
804 | + $items_label |
|
805 | + ); |
|
806 | + |
|
807 | + if (empty($items_label) |
|
808 | + || ! is_array($items_label) |
|
809 | + || ! isset($items_label['single']) |
|
810 | + || ! isset($items_label['plural']) |
|
811 | + ) { |
|
812 | + $items_label = array( |
|
813 | + 'single' => __('1 item', 'event_espresso'), |
|
814 | + 'plural' => __('%s items', 'event_espresso'), |
|
815 | + ); |
|
816 | + } else { |
|
817 | + $items_label = array( |
|
818 | + 'single' => '1 ' . esc_html($items_label['single']), |
|
819 | + 'plural' => '%s ' . esc_html($items_label['plural']), |
|
820 | + ); |
|
821 | + } |
|
822 | + |
|
823 | + $total_pages = ceil($total_items / $per_page); |
|
824 | + |
|
825 | + if ($total_pages <= 1) { |
|
826 | + return ''; |
|
827 | + } |
|
828 | + |
|
829 | + $item_label = $total_items > 1 ? sprintf($items_label['plural'], $total_items) : $items_label['single']; |
|
830 | + |
|
831 | + $output = '<span class="displaying-num">' . $item_label . '</span>'; |
|
832 | + |
|
833 | + if ($current === 1) { |
|
834 | + $disable_first = ' disabled'; |
|
835 | + } |
|
836 | + if ($current == $total_pages) { |
|
837 | + $disable_last = ' disabled'; |
|
838 | + } |
|
839 | + |
|
840 | + $page_links[] = sprintf("<a class='%s' title='%s' href='%s'>%s</a>", |
|
841 | + 'first-page' . $disable_first, |
|
842 | + esc_attr__('Go to the first page'), |
|
843 | + esc_url(remove_query_arg($paged_arg_name, $url)), |
|
844 | + '«' |
|
845 | + ); |
|
846 | + |
|
847 | + $page_links[] = sprintf( |
|
848 | + '<a class="%s" title="%s" href="%s">%s</a>', |
|
849 | + 'prev-page' . $disable_first, |
|
850 | + esc_attr__('Go to the previous page'), |
|
851 | + esc_url(add_query_arg($paged_arg_name, max(1, $current - 1), $url)), |
|
852 | + '‹' |
|
853 | + ); |
|
854 | + |
|
855 | + if ( ! $show_num_field) { |
|
856 | + $html_current_page = $current; |
|
857 | + } else { |
|
858 | + $html_current_page = sprintf("<input class='current-page' title='%s' type='text' name=$paged_arg_name value='%s' size='%d' />", |
|
859 | + esc_attr__('Current page'), |
|
860 | + $current, |
|
861 | + strlen($total_pages) |
|
862 | + ); |
|
863 | + } |
|
864 | + |
|
865 | + $html_total_pages = sprintf( |
|
866 | + '<span class="total-pages">%s</span>', |
|
867 | + number_format_i18n($total_pages) |
|
868 | + ); |
|
869 | + $page_links[] = sprintf( |
|
870 | + _x('%3$s%1$s of %2$s%4$s', 'paging'), |
|
871 | + $html_current_page, |
|
872 | + $html_total_pages, |
|
873 | + '<span class="paging-input">', |
|
874 | + '</span>' |
|
875 | + ); |
|
876 | + |
|
877 | + $page_links[] = sprintf( |
|
878 | + '<a class="%s" title="%s" href="%s">%s</a>', |
|
879 | + 'next-page' . $disable_last, |
|
880 | + esc_attr__('Go to the next page'), |
|
881 | + esc_url(add_query_arg($paged_arg_name, min($total_pages, $current + 1), $url)), |
|
882 | + '›' |
|
883 | + ); |
|
884 | + |
|
885 | + $page_links[] = sprintf( |
|
886 | + '<a class="%s" title="%s" href="%s">%s</a>', |
|
887 | + 'last-page' . $disable_last, |
|
888 | + esc_attr__('Go to the last page'), |
|
889 | + esc_url(add_query_arg($paged_arg_name, $total_pages, $url)), |
|
890 | + '»' |
|
891 | + ); |
|
892 | + |
|
893 | + $output .= "\n" . '<span class="pagination-links">' . join("\n", $page_links) . '</span>'; |
|
894 | + // set page class |
|
895 | + if ($total_pages) { |
|
896 | + $page_class = $total_pages < 2 ? ' one-page' : ''; |
|
897 | + } else { |
|
898 | + $page_class = ' no-pages'; |
|
899 | + } |
|
900 | + |
|
901 | + return '<div class="tablenav"><div class="tablenav-pages' . $page_class . '">' . $output . '</div></div>'; |
|
902 | + } |
|
903 | + |
|
904 | + |
|
905 | + /** |
|
906 | + * @param string $wrap_class |
|
907 | + * @param string $wrap_id |
|
908 | + * @return string |
|
909 | + */ |
|
910 | + public static function powered_by_event_espresso($wrap_class = '', $wrap_id = '', array $query_args = array()) |
|
911 | + { |
|
912 | + $admin = is_admin() && ! (defined('DOING_AJAX') && DOING_AJAX); |
|
913 | + if ( |
|
914 | + ! $admin && |
|
915 | + ! apply_filters( |
|
916 | + 'FHEE__EEH_Template__powered_by_event_espresso__show_reg_footer', |
|
917 | + EE_Registry::instance()->CFG->admin->show_reg_footer |
|
918 | + ) |
|
919 | + ) { |
|
920 | + return ''; |
|
921 | + } |
|
922 | + $tag = $admin ? 'span' : 'div'; |
|
923 | + $attributes = ! empty($wrap_id) ? " id=\"{$wrap_id}\"" : ''; |
|
924 | + $wrap_class = $admin ? "{$wrap_class} float-left" : $wrap_class; |
|
925 | + $attributes .= ! empty($wrap_class) |
|
926 | + ? " class=\"{$wrap_class} powered-by-event-espresso-credit\"" |
|
927 | + : ' class="powered-by-event-espresso-credit"'; |
|
928 | + $query_args = array_merge( |
|
929 | + array( |
|
930 | + 'ap_id' => EE_Registry::instance()->CFG->admin->affiliate_id(), |
|
931 | + 'utm_source' => 'powered_by_event_espresso', |
|
932 | + 'utm_medium' => 'link', |
|
933 | + 'utm_campaign' => 'powered_by', |
|
934 | + ), |
|
935 | + $query_args |
|
936 | + ); |
|
937 | + $powered_by = apply_filters('FHEE__EEH_Template__powered_by_event_espresso_text', |
|
938 | + $admin ? 'Event Espresso - ' . EVENT_ESPRESSO_VERSION : 'Event Espresso'); |
|
939 | + $url = add_query_arg($query_args, 'https://eventespresso.com/'); |
|
940 | + $url = apply_filters('FHEE__EEH_Template__powered_by_event_espresso__url', $url); |
|
941 | + return (string)apply_filters( |
|
942 | + 'FHEE__EEH_Template__powered_by_event_espresso__html', |
|
943 | + sprintf( |
|
944 | + esc_html_x( |
|
945 | + '%3$s%1$sOnline event registration and ticketing powered by %2$s%3$s', |
|
946 | + 'Online event registration and ticketing powered by [link to eventespresso.com]', |
|
947 | + 'event_espresso' |
|
948 | + ), |
|
949 | + "<{$tag}{$attributes}>", |
|
950 | + "<a href=\"{$url}\" target=\"_blank\" rel=\"nofollow\">{$powered_by}</a></{$tag}>", |
|
951 | + $admin ? '' : '<br />' |
|
952 | + ), |
|
953 | + $wrap_class, |
|
954 | + $wrap_id |
|
955 | + ); |
|
956 | + } |
|
957 | 957 | |
958 | 958 | |
959 | 959 | } //end EEH_Template class |
@@ -962,33 +962,33 @@ discard block |
||
962 | 962 | |
963 | 963 | |
964 | 964 | if ( ! function_exists('espresso_pagination')) { |
965 | - /** |
|
966 | - * espresso_pagination |
|
967 | - * |
|
968 | - * @access public |
|
969 | - * @return void |
|
970 | - */ |
|
971 | - function espresso_pagination() |
|
972 | - { |
|
973 | - global $wp_query; |
|
974 | - $big = 999999999; // need an unlikely integer |
|
975 | - $pagination = paginate_links( |
|
976 | - array( |
|
977 | - 'base' => str_replace($big, '%#%', esc_url(get_pagenum_link($big))), |
|
978 | - 'format' => '?paged=%#%', |
|
979 | - 'current' => max(1, get_query_var('paged')), |
|
980 | - 'total' => $wp_query->max_num_pages, |
|
981 | - 'show_all' => true, |
|
982 | - 'end_size' => 10, |
|
983 | - 'mid_size' => 6, |
|
984 | - 'prev_next' => true, |
|
985 | - 'prev_text' => __('‹ PREV', 'event_espresso'), |
|
986 | - 'next_text' => __('NEXT ›', 'event_espresso'), |
|
987 | - 'type' => 'plain', |
|
988 | - 'add_args' => false, |
|
989 | - 'add_fragment' => '', |
|
990 | - ) |
|
991 | - ); |
|
992 | - echo ! empty($pagination) ? '<div class="ee-pagination-dv ee-clear-float">' . $pagination . '</div>' : ''; |
|
993 | - } |
|
965 | + /** |
|
966 | + * espresso_pagination |
|
967 | + * |
|
968 | + * @access public |
|
969 | + * @return void |
|
970 | + */ |
|
971 | + function espresso_pagination() |
|
972 | + { |
|
973 | + global $wp_query; |
|
974 | + $big = 999999999; // need an unlikely integer |
|
975 | + $pagination = paginate_links( |
|
976 | + array( |
|
977 | + 'base' => str_replace($big, '%#%', esc_url(get_pagenum_link($big))), |
|
978 | + 'format' => '?paged=%#%', |
|
979 | + 'current' => max(1, get_query_var('paged')), |
|
980 | + 'total' => $wp_query->max_num_pages, |
|
981 | + 'show_all' => true, |
|
982 | + 'end_size' => 10, |
|
983 | + 'mid_size' => 6, |
|
984 | + 'prev_next' => true, |
|
985 | + 'prev_text' => __('‹ PREV', 'event_espresso'), |
|
986 | + 'next_text' => __('NEXT ›', 'event_espresso'), |
|
987 | + 'type' => 'plain', |
|
988 | + 'add_args' => false, |
|
989 | + 'add_fragment' => '', |
|
990 | + ) |
|
991 | + ); |
|
992 | + echo ! empty($pagination) ? '<div class="ee-pagination-dv ee-clear-float">' . $pagination . '</div>' : ''; |
|
993 | + } |
|
994 | 994 | } |
995 | 995 | \ No newline at end of file |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
2 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
3 | 3 | exit('NO direct script access allowed'); |
4 | 4 | } |
5 | 5 | /** |
@@ -81,8 +81,8 @@ discard block |
||
81 | 81 | public static function load_espresso_theme_functions() |
82 | 82 | { |
83 | 83 | if ( ! defined('EE_THEME_FUNCTIONS_LOADED')) { |
84 | - if (is_readable(EE_PUBLIC . EE_Config::get_current_theme() . DS . 'functions.php')) { |
|
85 | - require_once(EE_PUBLIC . EE_Config::get_current_theme() . DS . 'functions.php'); |
|
84 | + if (is_readable(EE_PUBLIC.EE_Config::get_current_theme().DS.'functions.php')) { |
|
85 | + require_once(EE_PUBLIC.EE_Config::get_current_theme().DS.'functions.php'); |
|
86 | 86 | } |
87 | 87 | } |
88 | 88 | } |
@@ -96,7 +96,7 @@ discard block |
||
96 | 96 | public static function get_espresso_themes() |
97 | 97 | { |
98 | 98 | if (empty(EEH_Template::$_espresso_themes)) { |
99 | - $espresso_themes = glob(EE_PUBLIC . '*', GLOB_ONLYDIR); |
|
99 | + $espresso_themes = glob(EE_PUBLIC.'*', GLOB_ONLYDIR); |
|
100 | 100 | if (empty($espresso_themes)) { |
101 | 101 | return array(); |
102 | 102 | } |
@@ -132,7 +132,7 @@ discard block |
||
132 | 132 | ) { |
133 | 133 | do_action("get_template_part_{$slug}-{$name}", $slug, $name); |
134 | 134 | $templates = array(); |
135 | - $name = (string)$name; |
|
135 | + $name = (string) $name; |
|
136 | 136 | if ($name != '') { |
137 | 137 | $templates[] = "{$slug}-{$name}.php"; |
138 | 138 | } |
@@ -211,7 +211,7 @@ discard block |
||
211 | 211 | if (isset($EE_CPTs[$post_type])) { |
212 | 212 | $archive_or_single = is_archive() ? 'archive' : ''; |
213 | 213 | $archive_or_single = is_single() ? 'single' : $archive_or_single; |
214 | - $templates = $archive_or_single . '-' . $post_type . '.php'; |
|
214 | + $templates = $archive_or_single.'-'.$post_type.'.php'; |
|
215 | 215 | } |
216 | 216 | } |
217 | 217 | // currently active EE template theme |
@@ -220,18 +220,18 @@ discard block |
||
220 | 220 | // array of paths to folders that may contain templates |
221 | 221 | $template_folder_paths = array( |
222 | 222 | // first check the /wp-content/uploads/espresso/templates/(current EE theme)/ folder for an EE theme template file |
223 | - EVENT_ESPRESSO_TEMPLATE_DIR . $current_theme, |
|
223 | + EVENT_ESPRESSO_TEMPLATE_DIR.$current_theme, |
|
224 | 224 | // then in the root of the /wp-content/uploads/espresso/templates/ folder |
225 | 225 | EVENT_ESPRESSO_TEMPLATE_DIR, |
226 | 226 | ); |
227 | 227 | |
228 | 228 | //add core plugin folders for checking only if we're not $check_if_custom |
229 | 229 | if ( ! $check_if_custom) { |
230 | - $core_paths = array( |
|
230 | + $core_paths = array( |
|
231 | 231 | // in the /wp-content/plugins/(EE4 folder)/public/(current EE theme)/ folder within the plugin |
232 | - EE_PUBLIC . $current_theme, |
|
232 | + EE_PUBLIC.$current_theme, |
|
233 | 233 | // in the /wp-content/plugins/(EE4 folder)/core/templates/(current EE theme)/ folder within the plugin |
234 | - EE_TEMPLATES . $current_theme, |
|
234 | + EE_TEMPLATES.$current_theme, |
|
235 | 235 | // or maybe relative from the plugin root: /wp-content/plugins/(EE4 folder)/ |
236 | 236 | EE_PLUGIN_DIR_PATH, |
237 | 237 | ); |
@@ -262,10 +262,10 @@ discard block |
||
262 | 262 | ); |
263 | 263 | if ($common_base_path !== '') { |
264 | 264 | // both paths have a common base, so just tack the filename onto our search path |
265 | - $resolved_path = EEH_File::end_with_directory_separator($template_folder_path) . $file_name; |
|
265 | + $resolved_path = EEH_File::end_with_directory_separator($template_folder_path).$file_name; |
|
266 | 266 | } else { |
267 | 267 | // no common base path, so let's just concatenate |
268 | - $resolved_path = EEH_File::end_with_directory_separator($template_folder_path) . $template; |
|
268 | + $resolved_path = EEH_File::end_with_directory_separator($template_folder_path).$template; |
|
269 | 269 | } |
270 | 270 | // build up our template locations array by adding our resolved paths |
271 | 271 | $full_template_paths[] = $resolved_path; |
@@ -273,13 +273,13 @@ discard block |
||
273 | 273 | // if $template is an absolute path, then we'll tack it onto the start of our array so that it gets searched first |
274 | 274 | array_unshift($full_template_paths, $template); |
275 | 275 | // path to the directory of the current theme: /wp-content/themes/(current WP theme)/ |
276 | - array_unshift($full_template_paths, get_stylesheet_directory() . DS . $file_name); |
|
276 | + array_unshift($full_template_paths, get_stylesheet_directory().DS.$file_name); |
|
277 | 277 | } |
278 | 278 | // filter final array of full template paths |
279 | 279 | $full_template_paths = apply_filters('FHEE__EEH_Template__locate_template__full_template_paths', |
280 | 280 | $full_template_paths, $file_name); |
281 | 281 | // now loop through our final array of template location paths and check each location |
282 | - foreach ((array)$full_template_paths as $full_template_path) { |
|
282 | + foreach ((array) $full_template_paths as $full_template_path) { |
|
283 | 283 | if (is_readable($full_template_path)) { |
284 | 284 | $template_path = str_replace(array('\\', '/'), DIRECTORY_SEPARATOR, $full_template_path); |
285 | 285 | break; |
@@ -366,9 +366,9 @@ discard block |
||
366 | 366 | if ( ! is_array($template_args) && ! is_object($template_args)) { |
367 | 367 | $template_args = array($template_args); |
368 | 368 | } |
369 | - extract( $template_args, EXTR_SKIP ); |
|
369 | + extract($template_args, EXTR_SKIP); |
|
370 | 370 | // ignore whether template is accessible ? |
371 | - if ( $throw_exceptions && ! is_readable( $template_path ) ) { |
|
371 | + if ($throw_exceptions && ! is_readable($template_path)) { |
|
372 | 372 | throw new \DomainException( |
373 | 373 | esc_html__( |
374 | 374 | 'Invalid, unreadable, or missing file.', |
@@ -401,11 +401,11 @@ discard block |
||
401 | 401 | public static function get_object_css_class($object = null, $prefix = '', $suffix = '') |
402 | 402 | { |
403 | 403 | // in the beginning... |
404 | - $prefix = ! empty($prefix) ? rtrim($prefix, '-') . '-' : ''; |
|
404 | + $prefix = ! empty($prefix) ? rtrim($prefix, '-').'-' : ''; |
|
405 | 405 | // da muddle |
406 | 406 | $class = ''; |
407 | 407 | // the end |
408 | - $suffix = ! empty($suffix) ? '-' . ltrim($suffix, '-') : ''; |
|
408 | + $suffix = ! empty($suffix) ? '-'.ltrim($suffix, '-') : ''; |
|
409 | 409 | // is the passed object an EE object ? |
410 | 410 | if ($object instanceof EE_Base_Class) { |
411 | 411 | // grab the exact type of object |
@@ -415,11 +415,11 @@ discard block |
||
415 | 415 | // no specifics just yet... |
416 | 416 | default : |
417 | 417 | $class = strtolower(str_replace('_', '-', $obj_class)); |
418 | - $class .= method_exists($obj_class, 'name') ? '-' . sanitize_title($object->name()) : ''; |
|
418 | + $class .= method_exists($obj_class, 'name') ? '-'.sanitize_title($object->name()) : ''; |
|
419 | 419 | |
420 | 420 | } |
421 | 421 | } |
422 | - return $prefix . $class . $suffix; |
|
422 | + return $prefix.$class.$suffix; |
|
423 | 423 | } |
424 | 424 | |
425 | 425 | |
@@ -451,7 +451,7 @@ discard block |
||
451 | 451 | return ''; |
452 | 452 | } |
453 | 453 | //ensure amount is float |
454 | - $amount = apply_filters('FHEE__EEH_Template__format_currency__raw_amount', (float)$amount); |
|
454 | + $amount = apply_filters('FHEE__EEH_Template__format_currency__raw_amount', (float) $amount); |
|
455 | 455 | $CNT_ISO = apply_filters('FHEE__EEH_Template__format_currency__CNT_ISO', $CNT_ISO, $amount); |
456 | 456 | // filter raw amount (allows 0.00 to be changed to "free" for example) |
457 | 457 | $amount_formatted = apply_filters('FHEE__EEH_Template__format_currency__amount', $amount, $return_raw); |
@@ -473,20 +473,20 @@ discard block |
||
473 | 473 | // add currency sign |
474 | 474 | if ($mny->sign_b4) { |
475 | 475 | if ($amount >= 0) { |
476 | - $amount_formatted = $mny->sign . $amount_formatted; |
|
476 | + $amount_formatted = $mny->sign.$amount_formatted; |
|
477 | 477 | } else { |
478 | - $amount_formatted = '-' . $mny->sign . str_replace('-', '', $amount_formatted); |
|
478 | + $amount_formatted = '-'.$mny->sign.str_replace('-', '', $amount_formatted); |
|
479 | 479 | } |
480 | 480 | |
481 | 481 | } else { |
482 | - $amount_formatted = $amount_formatted . $mny->sign; |
|
482 | + $amount_formatted = $amount_formatted.$mny->sign; |
|
483 | 483 | } |
484 | 484 | |
485 | 485 | // filter to allow global setting of display_code |
486 | 486 | $display_code = apply_filters('FHEE__EEH_Template__format_currency__display_code', $display_code); |
487 | 487 | |
488 | 488 | // add currency code ? |
489 | - $amount_formatted = $display_code ? $amount_formatted . ' <span class="' . $cur_code_span_class . '">(' . $mny->code . ')</span>' : $amount_formatted; |
|
489 | + $amount_formatted = $display_code ? $amount_formatted.' <span class="'.$cur_code_span_class.'">('.$mny->code.')</span>' : $amount_formatted; |
|
490 | 490 | } |
491 | 491 | // filter results |
492 | 492 | $amount_formatted = apply_filters('FHEE__EEH_Template__format_currency__amount_formatted', |
@@ -540,12 +540,12 @@ discard block |
||
540 | 540 | $icon_html .= $count > 1 ? '<span class="ee-composite-dashicon">' : ''; |
541 | 541 | foreach ($dashicons as $dashicon) { |
542 | 542 | $type = strpos($dashicon, 'ee-icon') !== false ? 'ee-icon ' : 'dashicons '; |
543 | - $icon_html .= '<span class="' . $type . $dashicon . '"></span>'; |
|
543 | + $icon_html .= '<span class="'.$type.$dashicon.'"></span>'; |
|
544 | 544 | } |
545 | 545 | $icon_html .= $count > 1 ? '</span>' : ''; |
546 | 546 | } |
547 | - $label = ! empty($icon) ? $icon_html . $label : $label; |
|
548 | - $button = '<a id="' . sanitize_title_with_dashes($label) . '" href="' . esc_url($url) . '" class="' . $class . '" title="' . $title . '">' . $label . '</a>'; |
|
547 | + $label = ! empty($icon) ? $icon_html.$label : $label; |
|
548 | + $button = '<a id="'.sanitize_title_with_dashes($label).'" href="'.esc_url($url).'" class="'.$class.'" title="'.$title.'">'.$label.'</a>'; |
|
549 | 549 | return $button; |
550 | 550 | } |
551 | 551 | |
@@ -579,11 +579,11 @@ discard block |
||
579 | 579 | $action = empty($action) ? 'default' : $action; |
580 | 580 | |
581 | 581 | |
582 | - $help_tab_lnk = $page . '-' . $action . '-' . $help_tab_id; |
|
582 | + $help_tab_lnk = $page.'-'.$action.'-'.$help_tab_id; |
|
583 | 583 | $icon = ! $icon_style ? ' dashicons-editor-help' : $icon_style; |
584 | 584 | $help_text = ! $help_text ? '' : $help_text; |
585 | - return '<a id="' . $help_tab_lnk . '" class="ee-clickable dashicons espresso-help-tab-lnk ee-icon-size-22' . $icon . '" title="' . esc_attr__('Click to open the \'Help\' tab for more information about this feature.', |
|
586 | - 'event_espresso') . '" > ' . $help_text . ' </a>'; |
|
585 | + return '<a id="'.$help_tab_lnk.'" class="ee-clickable dashicons espresso-help-tab-lnk ee-icon-size-22'.$icon.'" title="'.esc_attr__('Click to open the \'Help\' tab for more information about this feature.', |
|
586 | + 'event_espresso').'" > '.$help_text.' </a>'; |
|
587 | 587 | } |
588 | 588 | |
589 | 589 | |
@@ -600,11 +600,11 @@ discard block |
||
600 | 600 | $id = $tour->get_slug(); |
601 | 601 | $stops = $tour->get_stops(); |
602 | 602 | |
603 | - $content = '<ol style="display:none" id="' . $id . '">'; |
|
603 | + $content = '<ol style="display:none" id="'.$id.'">'; |
|
604 | 604 | |
605 | 605 | foreach ($stops as $stop) { |
606 | - $data_id = ! empty($stop['id']) ? ' data-id="' . $stop['id'] . '"' : ''; |
|
607 | - $data_class = empty($data_id) && ! empty($stop['class']) ? ' data-class="' . $stop['class'] . '"' : ''; |
|
606 | + $data_id = ! empty($stop['id']) ? ' data-id="'.$stop['id'].'"' : ''; |
|
607 | + $data_class = empty($data_id) && ! empty($stop['class']) ? ' data-class="'.$stop['class'].'"' : ''; |
|
608 | 608 | |
609 | 609 | //if container is set to modal then let's make sure we set the options accordingly |
610 | 610 | if (empty($data_id) && empty($data_class)) { |
@@ -612,15 +612,15 @@ discard block |
||
612 | 612 | $stop['options']['expose'] = true; |
613 | 613 | } |
614 | 614 | |
615 | - $custom_class = ! empty($stop['custom_class']) ? ' class="' . $stop['custom_class'] . '"' : ''; |
|
616 | - $button_text = ! empty($stop['button_text']) ? ' data-button="' . $stop['button_text'] . '"' : ''; |
|
615 | + $custom_class = ! empty($stop['custom_class']) ? ' class="'.$stop['custom_class'].'"' : ''; |
|
616 | + $button_text = ! empty($stop['button_text']) ? ' data-button="'.$stop['button_text'].'"' : ''; |
|
617 | 617 | $inner_content = isset($stop['content']) ? $stop['content'] : ''; |
618 | 618 | |
619 | 619 | //options |
620 | 620 | if (isset($stop['options']) && is_array($stop['options'])) { |
621 | 621 | $options = ' data-options="'; |
622 | 622 | foreach ($stop['options'] as $option => $value) { |
623 | - $options .= $option . ':' . $value . ';'; |
|
623 | + $options .= $option.':'.$value.';'; |
|
624 | 624 | } |
625 | 625 | $options .= '"'; |
626 | 626 | } else { |
@@ -628,7 +628,7 @@ discard block |
||
628 | 628 | } |
629 | 629 | |
630 | 630 | //let's put all together |
631 | - $content .= '<li' . $data_id . $data_class . $custom_class . $button_text . $options . '>' . $inner_content . '</li>'; |
|
631 | + $content .= '<li'.$data_id.$data_class.$custom_class.$button_text.$options.'>'.$inner_content.'</li>'; |
|
632 | 632 | } |
633 | 633 | |
634 | 634 | $content .= '</ol>'; |
@@ -660,24 +660,24 @@ discard block |
||
660 | 660 | $setup_array = array(); |
661 | 661 | foreach ($status_array as $item => $status) { |
662 | 662 | $setup_array[$item] = array( |
663 | - 'class' => 'ee-status-legend ee-status-legend-' . $status, |
|
663 | + 'class' => 'ee-status-legend ee-status-legend-'.$status, |
|
664 | 664 | 'desc' => EEH_Template::pretty_status($status, false, 'sentence'), |
665 | 665 | 'status' => $status, |
666 | 666 | ); |
667 | 667 | } |
668 | 668 | |
669 | - $content = '<div class="ee-list-table-legend-container">' . "\n"; |
|
670 | - $content .= '<h4 class="status-legend-title">' . esc_html__('Status Legend', 'event_espresso') . '</h4>' . "\n"; |
|
671 | - $content .= '<dl class="ee-list-table-legend">' . "\n\t"; |
|
669 | + $content = '<div class="ee-list-table-legend-container">'."\n"; |
|
670 | + $content .= '<h4 class="status-legend-title">'.esc_html__('Status Legend', 'event_espresso').'</h4>'."\n"; |
|
671 | + $content .= '<dl class="ee-list-table-legend">'."\n\t"; |
|
672 | 672 | foreach ($setup_array as $item => $details) { |
673 | 673 | $active_class = $active_status == $details['status'] ? ' class="ee-is-active-status"' : ''; |
674 | - $content .= '<dt id="ee-legend-item-tooltip-' . $item . '"' . $active_class . '>' . "\n\t\t"; |
|
675 | - $content .= '<span class="' . $details['class'] . '"></span>' . "\n\t\t"; |
|
676 | - $content .= '<span class="ee-legend-description">' . $details['desc'] . '</span>' . "\n\t"; |
|
677 | - $content .= '</dt>' . "\n"; |
|
674 | + $content .= '<dt id="ee-legend-item-tooltip-'.$item.'"'.$active_class.'>'."\n\t\t"; |
|
675 | + $content .= '<span class="'.$details['class'].'"></span>'."\n\t\t"; |
|
676 | + $content .= '<span class="ee-legend-description">'.$details['desc'].'</span>'."\n\t"; |
|
677 | + $content .= '</dt>'."\n"; |
|
678 | 678 | } |
679 | - $content .= '</dl>' . "\n"; |
|
680 | - $content .= '</div>' . "\n"; |
|
679 | + $content .= '</dl>'."\n"; |
|
680 | + $content .= '</div>'."\n"; |
|
681 | 681 | return $content; |
682 | 682 | } |
683 | 683 | |
@@ -692,7 +692,7 @@ discard block |
||
692 | 692 | public static function layout_array_as_table($data) |
693 | 693 | { |
694 | 694 | if (is_object($data) || $data instanceof __PHP_Incomplete_Class) { |
695 | - $data = (array)$data; |
|
695 | + $data = (array) $data; |
|
696 | 696 | } |
697 | 697 | ob_start(); |
698 | 698 | if (is_array($data)) { |
@@ -793,9 +793,9 @@ discard block |
||
793 | 793 | ) { |
794 | 794 | $page_links = array(); |
795 | 795 | $disable_first = $disable_last = ''; |
796 | - $total_items = (int)$total_items; |
|
797 | - $per_page = (int)$per_page; |
|
798 | - $current = (int)$current; |
|
796 | + $total_items = (int) $total_items; |
|
797 | + $per_page = (int) $per_page; |
|
798 | + $current = (int) $current; |
|
799 | 799 | $paged_arg_name = empty($paged_arg_name) ? 'paged' : sanitize_key($paged_arg_name); |
800 | 800 | |
801 | 801 | //filter items_label |
@@ -815,8 +815,8 @@ discard block |
||
815 | 815 | ); |
816 | 816 | } else { |
817 | 817 | $items_label = array( |
818 | - 'single' => '1 ' . esc_html($items_label['single']), |
|
819 | - 'plural' => '%s ' . esc_html($items_label['plural']), |
|
818 | + 'single' => '1 '.esc_html($items_label['single']), |
|
819 | + 'plural' => '%s '.esc_html($items_label['plural']), |
|
820 | 820 | ); |
821 | 821 | } |
822 | 822 | |
@@ -828,7 +828,7 @@ discard block |
||
828 | 828 | |
829 | 829 | $item_label = $total_items > 1 ? sprintf($items_label['plural'], $total_items) : $items_label['single']; |
830 | 830 | |
831 | - $output = '<span class="displaying-num">' . $item_label . '</span>'; |
|
831 | + $output = '<span class="displaying-num">'.$item_label.'</span>'; |
|
832 | 832 | |
833 | 833 | if ($current === 1) { |
834 | 834 | $disable_first = ' disabled'; |
@@ -838,7 +838,7 @@ discard block |
||
838 | 838 | } |
839 | 839 | |
840 | 840 | $page_links[] = sprintf("<a class='%s' title='%s' href='%s'>%s</a>", |
841 | - 'first-page' . $disable_first, |
|
841 | + 'first-page'.$disable_first, |
|
842 | 842 | esc_attr__('Go to the first page'), |
843 | 843 | esc_url(remove_query_arg($paged_arg_name, $url)), |
844 | 844 | '«' |
@@ -846,7 +846,7 @@ discard block |
||
846 | 846 | |
847 | 847 | $page_links[] = sprintf( |
848 | 848 | '<a class="%s" title="%s" href="%s">%s</a>', |
849 | - 'prev-page' . $disable_first, |
|
849 | + 'prev-page'.$disable_first, |
|
850 | 850 | esc_attr__('Go to the previous page'), |
851 | 851 | esc_url(add_query_arg($paged_arg_name, max(1, $current - 1), $url)), |
852 | 852 | '‹' |
@@ -866,7 +866,7 @@ discard block |
||
866 | 866 | '<span class="total-pages">%s</span>', |
867 | 867 | number_format_i18n($total_pages) |
868 | 868 | ); |
869 | - $page_links[] = sprintf( |
|
869 | + $page_links[] = sprintf( |
|
870 | 870 | _x('%3$s%1$s of %2$s%4$s', 'paging'), |
871 | 871 | $html_current_page, |
872 | 872 | $html_total_pages, |
@@ -876,7 +876,7 @@ discard block |
||
876 | 876 | |
877 | 877 | $page_links[] = sprintf( |
878 | 878 | '<a class="%s" title="%s" href="%s">%s</a>', |
879 | - 'next-page' . $disable_last, |
|
879 | + 'next-page'.$disable_last, |
|
880 | 880 | esc_attr__('Go to the next page'), |
881 | 881 | esc_url(add_query_arg($paged_arg_name, min($total_pages, $current + 1), $url)), |
882 | 882 | '›' |
@@ -884,13 +884,13 @@ discard block |
||
884 | 884 | |
885 | 885 | $page_links[] = sprintf( |
886 | 886 | '<a class="%s" title="%s" href="%s">%s</a>', |
887 | - 'last-page' . $disable_last, |
|
887 | + 'last-page'.$disable_last, |
|
888 | 888 | esc_attr__('Go to the last page'), |
889 | 889 | esc_url(add_query_arg($paged_arg_name, $total_pages, $url)), |
890 | 890 | '»' |
891 | 891 | ); |
892 | 892 | |
893 | - $output .= "\n" . '<span class="pagination-links">' . join("\n", $page_links) . '</span>'; |
|
893 | + $output .= "\n".'<span class="pagination-links">'.join("\n", $page_links).'</span>'; |
|
894 | 894 | // set page class |
895 | 895 | if ($total_pages) { |
896 | 896 | $page_class = $total_pages < 2 ? ' one-page' : ''; |
@@ -898,7 +898,7 @@ discard block |
||
898 | 898 | $page_class = ' no-pages'; |
899 | 899 | } |
900 | 900 | |
901 | - return '<div class="tablenav"><div class="tablenav-pages' . $page_class . '">' . $output . '</div></div>'; |
|
901 | + return '<div class="tablenav"><div class="tablenav-pages'.$page_class.'">'.$output.'</div></div>'; |
|
902 | 902 | } |
903 | 903 | |
904 | 904 | |
@@ -935,10 +935,10 @@ discard block |
||
935 | 935 | $query_args |
936 | 936 | ); |
937 | 937 | $powered_by = apply_filters('FHEE__EEH_Template__powered_by_event_espresso_text', |
938 | - $admin ? 'Event Espresso - ' . EVENT_ESPRESSO_VERSION : 'Event Espresso'); |
|
938 | + $admin ? 'Event Espresso - '.EVENT_ESPRESSO_VERSION : 'Event Espresso'); |
|
939 | 939 | $url = add_query_arg($query_args, 'https://eventespresso.com/'); |
940 | 940 | $url = apply_filters('FHEE__EEH_Template__powered_by_event_espresso__url', $url); |
941 | - return (string)apply_filters( |
|
941 | + return (string) apply_filters( |
|
942 | 942 | 'FHEE__EEH_Template__powered_by_event_espresso__html', |
943 | 943 | sprintf( |
944 | 944 | esc_html_x( |
@@ -989,6 +989,6 @@ discard block |
||
989 | 989 | 'add_fragment' => '', |
990 | 990 | ) |
991 | 991 | ); |
992 | - echo ! empty($pagination) ? '<div class="ee-pagination-dv ee-clear-float">' . $pagination . '</div>' : ''; |
|
992 | + echo ! empty($pagination) ? '<div class="ee-pagination-dv ee-clear-float">'.$pagination.'</div>' : ''; |
|
993 | 993 | } |
994 | 994 | } |
995 | 995 | \ No newline at end of file |