@@ -2,47 +2,47 @@ |
||
2 | 2 | |
3 | 3 | class EE_Validation_Error extends Exception |
4 | 4 | { |
5 | - /** |
|
6 | - * Form Section from which this error originated. |
|
7 | - * @var EE_Form_Section |
|
8 | - */ |
|
9 | - protected $_form_section; |
|
10 | - /** |
|
11 | - * a short string for uniquely identifying the error, which isn't internationalized and |
|
12 | - * machines can use to identify the error |
|
13 | - * @var string |
|
14 | - */ |
|
15 | - protected $_string_code; |
|
5 | + /** |
|
6 | + * Form Section from which this error originated. |
|
7 | + * @var EE_Form_Section |
|
8 | + */ |
|
9 | + protected $_form_section; |
|
10 | + /** |
|
11 | + * a short string for uniquely identifying the error, which isn't internationalized and |
|
12 | + * machines can use to identify the error |
|
13 | + * @var string |
|
14 | + */ |
|
15 | + protected $_string_code; |
|
16 | 16 | |
17 | - /** |
|
18 | - * When creating a validation error, we need to know which field the error relates to. |
|
19 | - * @param string $message message you want to display about this error |
|
20 | - * @param string $string_code a code for uniquely identifying the exception |
|
21 | - * @param EE_Form_Section_Validatable $form_section |
|
22 | - * @param Exception $previous if there was an exception that caused this exception |
|
23 | - */ |
|
24 | - public function __construct($message = null, $string_code = null, $form_section = null, $previous = null) |
|
25 | - { |
|
26 | - $this->_form_section = $form_section; |
|
27 | - $this->_string_code = $string_code; |
|
28 | - parent::__construct($message, 500, $previous); |
|
29 | - } |
|
17 | + /** |
|
18 | + * When creating a validation error, we need to know which field the error relates to. |
|
19 | + * @param string $message message you want to display about this error |
|
20 | + * @param string $string_code a code for uniquely identifying the exception |
|
21 | + * @param EE_Form_Section_Validatable $form_section |
|
22 | + * @param Exception $previous if there was an exception that caused this exception |
|
23 | + */ |
|
24 | + public function __construct($message = null, $string_code = null, $form_section = null, $previous = null) |
|
25 | + { |
|
26 | + $this->_form_section = $form_section; |
|
27 | + $this->_string_code = $string_code; |
|
28 | + parent::__construct($message, 500, $previous); |
|
29 | + } |
|
30 | 30 | |
31 | - /** |
|
32 | - * returns teh form section which caused the error. |
|
33 | - * @return EE_Form_Section_Validatable |
|
34 | - */ |
|
35 | - public function get_form_section() |
|
36 | - { |
|
37 | - return $this->_form_section; |
|
38 | - } |
|
39 | - /** |
|
40 | - * Sets teh form seciton of the error, in case it wasnt set previously |
|
41 | - * @param EE_Form_Section_Validatable $form_section |
|
42 | - * @return void |
|
43 | - */ |
|
44 | - public function set_form_section($form_section) |
|
45 | - { |
|
46 | - $this->_form_section = $form_section; |
|
47 | - } |
|
31 | + /** |
|
32 | + * returns teh form section which caused the error. |
|
33 | + * @return EE_Form_Section_Validatable |
|
34 | + */ |
|
35 | + public function get_form_section() |
|
36 | + { |
|
37 | + return $this->_form_section; |
|
38 | + } |
|
39 | + /** |
|
40 | + * Sets teh form seciton of the error, in case it wasnt set previously |
|
41 | + * @param EE_Form_Section_Validatable $form_section |
|
42 | + * @return void |
|
43 | + */ |
|
44 | + public function set_form_section($form_section) |
|
45 | + { |
|
46 | + $this->_form_section = $form_section; |
|
47 | + } |
|
48 | 48 | } |
@@ -187,7 +187,7 @@ discard block |
||
187 | 187 | public function set_settings($settings_array) |
188 | 188 | { |
189 | 189 | foreach ($settings_array as $name => $value) { |
190 | - $property_name = "_" . $name; |
|
190 | + $property_name = "_".$name; |
|
191 | 191 | $this->{$property_name} = $value; |
192 | 192 | } |
193 | 193 | } |
@@ -251,7 +251,7 @@ discard block |
||
251 | 251 | */ |
252 | 252 | public function set_gateway_data_formatter(GatewayDataFormatterInterface $gateway_data_formatter) |
253 | 253 | { |
254 | - if (! $gateway_data_formatter instanceof GatewayDataFormatterInterface) { |
|
254 | + if ( ! $gateway_data_formatter instanceof GatewayDataFormatterInterface) { |
|
255 | 255 | throw new InvalidEntityException( |
256 | 256 | is_object($gateway_data_formatter) |
257 | 257 | ? get_class($gateway_data_formatter) |
@@ -270,7 +270,7 @@ discard block |
||
270 | 270 | */ |
271 | 271 | protected function _get_gateway_formatter() |
272 | 272 | { |
273 | - if (! $this->_gateway_data_formatter instanceof GatewayDataFormatterInterface) { |
|
273 | + if ( ! $this->_gateway_data_formatter instanceof GatewayDataFormatterInterface) { |
|
274 | 274 | throw new InvalidEntityException( |
275 | 275 | is_object($this->_gateway_data_formatter) |
276 | 276 | ? get_class($this->_gateway_data_formatter) |
@@ -291,7 +291,7 @@ discard block |
||
291 | 291 | */ |
292 | 292 | public function set_unsupported_character_remover(FormatterInterface $formatter) |
293 | 293 | { |
294 | - if (! $formatter instanceof FormatterInterface) { |
|
294 | + if ( ! $formatter instanceof FormatterInterface) { |
|
295 | 295 | throw new InvalidEntityException( |
296 | 296 | is_object($formatter) |
297 | 297 | ? get_class($formatter) |
@@ -310,7 +310,7 @@ discard block |
||
310 | 310 | */ |
311 | 311 | protected function _get_unsupported_character_remover() |
312 | 312 | { |
313 | - if (! $this->_unsupported_character_remover instanceof FormatterInterface) { |
|
313 | + if ( ! $this->_unsupported_character_remover instanceof FormatterInterface) { |
|
314 | 314 | throw new InvalidEntityException( |
315 | 315 | is_object($this->_unsupported_character_remover) |
316 | 316 | ? get_class($this->_unsupported_character_remover) |
@@ -23,495 +23,495 @@ |
||
23 | 23 | */ |
24 | 24 | abstract class EE_Gateway |
25 | 25 | { |
26 | - /** |
|
27 | - * a constant used as a possible value for $_currencies_supported to indicate |
|
28 | - * that ALL currencies are supported by this gateway |
|
29 | - */ |
|
30 | - const all_currencies_supported = 'all_currencies_supported'; |
|
31 | - /** |
|
32 | - * Where values are 3-letter currency codes |
|
33 | - * |
|
34 | - * @var array |
|
35 | - */ |
|
36 | - protected $_currencies_supported = array(); |
|
37 | - /** |
|
38 | - * Whether or not this gateway can support SENDING a refund request (ie, initiated by |
|
39 | - * admin in EE's wp-admin page) |
|
40 | - * |
|
41 | - * @var boolean |
|
42 | - */ |
|
43 | - protected $_supports_sending_refunds = false; |
|
44 | - |
|
45 | - /** |
|
46 | - * Whether or not this gateway can support RECEIVING a refund request from the payment |
|
47 | - * provider (ie, initiated by admin on the payment prover's website who sends an IPN to EE) |
|
48 | - * |
|
49 | - * @var boolean |
|
50 | - */ |
|
51 | - protected $_supports_receiving_refunds = false; |
|
52 | - /** |
|
53 | - * Model for querying for existing payments |
|
54 | - * |
|
55 | - * @var EEMI_Payment |
|
56 | - */ |
|
57 | - protected $_pay_model; |
|
58 | - |
|
59 | - /** |
|
60 | - * Model used for adding to the payments log |
|
61 | - * |
|
62 | - * @var EEMI_Payment_Log |
|
63 | - */ |
|
64 | - protected $_pay_log; |
|
65 | - |
|
66 | - /** |
|
67 | - * Used for formatting some input to gateways |
|
68 | - * |
|
69 | - * @var EEHI_Template |
|
70 | - */ |
|
71 | - protected $_template; |
|
72 | - |
|
73 | - /** |
|
74 | - * Concrete class that implements EEHI_Money, used by most gateways |
|
75 | - * |
|
76 | - * @var EEHI_Money |
|
77 | - */ |
|
78 | - protected $_money; |
|
79 | - |
|
80 | - /** |
|
81 | - * Concrete class that implements EEHI_Line_Item, used for manipulating the line item tree |
|
82 | - * |
|
83 | - * @var EEHI_Line_Item |
|
84 | - */ |
|
85 | - protected $_line_item; |
|
86 | - |
|
87 | - /** |
|
88 | - * @var GatewayDataFormatterInterface |
|
89 | - */ |
|
90 | - protected $_gateway_data_formatter; |
|
91 | - |
|
92 | - /** |
|
93 | - * @var FormatterInterface |
|
94 | - */ |
|
95 | - protected $_unsupported_character_remover; |
|
96 | - |
|
97 | - /** |
|
98 | - * The ID of the payment method using this gateway |
|
99 | - * |
|
100 | - * @var int |
|
101 | - */ |
|
102 | - protected $_ID; |
|
103 | - |
|
104 | - /** |
|
105 | - * @var $_debug_mode boolean whether to send requests to teh sandbox site or not |
|
106 | - */ |
|
107 | - protected $_debug_mode; |
|
108 | - /** |
|
109 | - * |
|
110 | - * @var string $_name name to show for this payment method |
|
111 | - */ |
|
112 | - protected $_name; |
|
113 | - /** |
|
114 | - * |
|
115 | - * @var string name to show fir this payment method to admin-type users |
|
116 | - */ |
|
117 | - protected $_admin_name; |
|
118 | - |
|
119 | - /** |
|
120 | - * @return EE_Gateway |
|
121 | - */ |
|
122 | - public function __construct() |
|
123 | - { |
|
124 | - } |
|
125 | - |
|
126 | - /** |
|
127 | - * We don't want to serialize models as they often have circular structures |
|
128 | - * (eg a payment model has a reference to each payment model object; and most |
|
129 | - * payments have a transaction, most transactions have a payment method; |
|
130 | - * most payment methods have a payment method type; most payment method types |
|
131 | - * have a gateway. And if a gateway serializes its models, we start at the |
|
132 | - * beginning again) |
|
133 | - * |
|
134 | - * @return array |
|
135 | - */ |
|
136 | - public function __sleep() |
|
137 | - { |
|
138 | - $properties = get_object_vars($this); |
|
139 | - unset($properties['_pay_model'], $properties['_pay_log']); |
|
140 | - return array_keys($properties); |
|
141 | - } |
|
142 | - |
|
143 | - /** |
|
144 | - * Returns whether or not this gateway should support SENDING refunds |
|
145 | - * see $_supports_sending_refunds |
|
146 | - * |
|
147 | - * @return boolean |
|
148 | - */ |
|
149 | - public function supports_sending_refunds() |
|
150 | - { |
|
151 | - return $this->_supports_sending_refunds; |
|
152 | - } |
|
153 | - |
|
154 | - /** |
|
155 | - * Returns whether or not this gateway should support RECEIVING refunds |
|
156 | - * see $_supports_receiving_refunds |
|
157 | - * |
|
158 | - * @return boolean |
|
159 | - */ |
|
160 | - public function supports_receiving_refunds() |
|
161 | - { |
|
162 | - return $this->_supports_receiving_refunds; |
|
163 | - } |
|
164 | - |
|
165 | - |
|
166 | - /** |
|
167 | - * Tries to refund the payment specified, taking into account the extra |
|
168 | - * refund info. Note that if the gateway's _supports_sending_refunds is false, |
|
169 | - * this should just throw an exception. |
|
170 | - * |
|
171 | - * @param EE_Payment $payment |
|
172 | - * @param array $refund_info |
|
173 | - * @return EE_Payment for the refund |
|
174 | - * @throws EE_Error |
|
175 | - */ |
|
176 | - public function do_direct_refund(EE_Payment $payment, $refund_info = null) |
|
177 | - { |
|
178 | - return null; |
|
179 | - } |
|
180 | - |
|
181 | - |
|
182 | - /** |
|
183 | - * Sets the payment method's settings so the gateway knows where to send the request |
|
184 | - * etc |
|
185 | - * |
|
186 | - * @param array $settings_array |
|
187 | - */ |
|
188 | - public function set_settings($settings_array) |
|
189 | - { |
|
190 | - foreach ($settings_array as $name => $value) { |
|
191 | - $property_name = "_" . $name; |
|
192 | - $this->{$property_name} = $value; |
|
193 | - } |
|
194 | - } |
|
195 | - |
|
196 | - /** |
|
197 | - * See this class description |
|
198 | - * |
|
199 | - * @param EEMI_Payment $payment_model |
|
200 | - */ |
|
201 | - public function set_payment_model($payment_model) |
|
202 | - { |
|
203 | - $this->_pay_model = $payment_model; |
|
204 | - } |
|
205 | - |
|
206 | - /** |
|
207 | - * See this class description |
|
208 | - * |
|
209 | - * @param EEMI_Payment_Log $payment_log_model |
|
210 | - */ |
|
211 | - public function set_payment_log($payment_log_model) |
|
212 | - { |
|
213 | - $this->_pay_log = $payment_log_model; |
|
214 | - } |
|
215 | - |
|
216 | - /** |
|
217 | - * See this class description |
|
218 | - * |
|
219 | - * @param EEHI_Template $template_helper |
|
220 | - */ |
|
221 | - public function set_template_helper($template_helper) |
|
222 | - { |
|
223 | - $this->_template = $template_helper; |
|
224 | - } |
|
225 | - |
|
226 | - /** |
|
227 | - * See this class description |
|
228 | - * |
|
229 | - * @param EEHI_Line_Item $line_item_helper |
|
230 | - */ |
|
231 | - public function set_line_item_helper($line_item_helper) |
|
232 | - { |
|
233 | - $this->_line_item = $line_item_helper; |
|
234 | - } |
|
235 | - |
|
236 | - /** |
|
237 | - * See this class description |
|
238 | - * |
|
239 | - * @param EEHI_Money $money_helper |
|
240 | - */ |
|
241 | - public function set_money_helper($money_helper) |
|
242 | - { |
|
243 | - $this->_money = $money_helper; |
|
244 | - } |
|
245 | - |
|
246 | - |
|
247 | - /** |
|
248 | - * Sets the gateway data formatter helper |
|
249 | - * |
|
250 | - * @param GatewayDataFormatterInterface $gateway_data_formatter |
|
251 | - * @throws InvalidEntityException if it's not set properly |
|
252 | - */ |
|
253 | - public function set_gateway_data_formatter(GatewayDataFormatterInterface $gateway_data_formatter) |
|
254 | - { |
|
255 | - if (! $gateway_data_formatter instanceof GatewayDataFormatterInterface) { |
|
256 | - throw new InvalidEntityException( |
|
257 | - is_object($gateway_data_formatter) |
|
258 | - ? get_class($gateway_data_formatter) |
|
259 | - : esc_html__('Not an object', 'event_espresso'), |
|
260 | - '\\EventEspresso\\core\\services\\payment_methods\\gateways\\GatewayDataFormatterInterface' |
|
261 | - ); |
|
262 | - } |
|
263 | - $this->_gateway_data_formatter = $gateway_data_formatter; |
|
264 | - } |
|
265 | - |
|
266 | - /** |
|
267 | - * Gets the gateway data formatter |
|
268 | - * |
|
269 | - * @return GatewayDataFormatterInterface |
|
270 | - * @throws InvalidEntityException if it's not set properly |
|
271 | - */ |
|
272 | - protected function _get_gateway_formatter() |
|
273 | - { |
|
274 | - if (! $this->_gateway_data_formatter instanceof GatewayDataFormatterInterface) { |
|
275 | - throw new InvalidEntityException( |
|
276 | - is_object($this->_gateway_data_formatter) |
|
277 | - ? get_class($this->_gateway_data_formatter) |
|
278 | - : esc_html__('Not an object', 'event_espresso'), |
|
279 | - '\\EventEspresso\\core\\services\\payment_methods\\gateways\\GatewayDataFormatterInterface' |
|
280 | - ); |
|
281 | - } |
|
282 | - return $this->_gateway_data_formatter; |
|
283 | - } |
|
284 | - |
|
285 | - |
|
286 | - /** |
|
287 | - * Sets the helper which will remove unsupported characters for most gateways |
|
288 | - * |
|
289 | - * @param FormatterInterface $formatter |
|
290 | - * @return FormatterInterface |
|
291 | - * @throws InvalidEntityException |
|
292 | - */ |
|
293 | - public function set_unsupported_character_remover(FormatterInterface $formatter) |
|
294 | - { |
|
295 | - if (! $formatter instanceof FormatterInterface) { |
|
296 | - throw new InvalidEntityException( |
|
297 | - is_object($formatter) |
|
298 | - ? get_class($formatter) |
|
299 | - : esc_html__('Not an object', 'event_espresso'), |
|
300 | - '\\EventEspresso\\core\\services\\formatters\\FormatterInterface' |
|
301 | - ); |
|
302 | - } |
|
303 | - $this->_unsupported_character_remover = $formatter; |
|
304 | - } |
|
305 | - |
|
306 | - /** |
|
307 | - * Gets the helper which removes characters which gateways might not support, like emojis etc. |
|
308 | - * |
|
309 | - * @return FormatterInterface |
|
310 | - * @throws InvalidEntityException |
|
311 | - */ |
|
312 | - protected function _get_unsupported_character_remover() |
|
313 | - { |
|
314 | - if (! $this->_unsupported_character_remover instanceof FormatterInterface) { |
|
315 | - throw new InvalidEntityException( |
|
316 | - is_object($this->_unsupported_character_remover) |
|
317 | - ? get_class($this->_unsupported_character_remover) |
|
318 | - : esc_html__('Not an object', 'event_espresso'), |
|
319 | - '\\EventEspresso\\core\\services\\formatters\\FormatterInterface' |
|
320 | - ); |
|
321 | - } |
|
322 | - return $this->_unsupported_character_remover; |
|
323 | - } |
|
324 | - |
|
325 | - |
|
326 | - /** |
|
327 | - * @param $message |
|
328 | - * @param $payment |
|
329 | - */ |
|
330 | - public function log($message, $object_logged) |
|
331 | - { |
|
332 | - if ($object_logged instanceof EEI_Payment) { |
|
333 | - $type = 'Payment'; |
|
334 | - $id = $object_logged->ID(); |
|
335 | - } elseif ($object_logged instanceof EEI_Transaction) { |
|
336 | - $type = 'Transaction'; |
|
337 | - $id = $object_logged->ID(); |
|
338 | - } else { |
|
339 | - $type = 'Payment_Method'; |
|
340 | - $id = $this->_ID; |
|
341 | - } |
|
342 | - // only log if we're going to store it for longer than the minimum time |
|
343 | - $reg_config = LoaderFactory::getLoader()->load('EE_Registration_Config'); |
|
344 | - if ($reg_config->gateway_log_lifespan !== '1 second') { |
|
345 | - $this->_pay_log->gateway_log($message, $id, $type); |
|
346 | - } |
|
347 | - } |
|
348 | - |
|
349 | - /** |
|
350 | - * Formats the amount so it can generally be sent to gateways |
|
351 | - * |
|
352 | - * @param float $amount |
|
353 | - * @return string |
|
354 | - * @deprecated since 4.9.31 insetad use |
|
355 | - * EventEspresso\core\services\payment_methods\gateways\GatewayDataFormatter::format_currency() |
|
356 | - */ |
|
357 | - public function format_currency($amount) |
|
358 | - { |
|
359 | - return $this->_get_gateway_formatter()->formatCurrency($amount); |
|
360 | - } |
|
361 | - |
|
362 | - /** |
|
363 | - * Returns either an array of all the currency codes supported, |
|
364 | - * or a string indicating they're all supported (EE_gateway::all_currencies_supported) |
|
365 | - * |
|
366 | - * @return mixed array or string |
|
367 | - */ |
|
368 | - public function currencies_supported() |
|
369 | - { |
|
370 | - return $this->_currencies_supported; |
|
371 | - } |
|
372 | - |
|
373 | - /** |
|
374 | - * Returns what a simple summing of items and taxes for this transaction. This |
|
375 | - * can be used to determine if some more complex line items, like promotions, |
|
376 | - * surcharges, or cancellations occurred (in which case we might want to forget |
|
377 | - * about creating an itemized list of purchases and instead only send the total due) |
|
378 | - * |
|
379 | - * @param EE_Transaction $transaction |
|
380 | - * @return float |
|
381 | - */ |
|
382 | - protected function _sum_items_and_taxes(EE_Transaction $transaction) |
|
383 | - { |
|
384 | - $total_line_item = $transaction->total_line_item(); |
|
385 | - $total = 0; |
|
386 | - foreach ($total_line_item->get_items() as $item_line_item) { |
|
387 | - $total += max($item_line_item->total(), 0); |
|
388 | - } |
|
389 | - foreach ($total_line_item->tax_descendants() as $tax_line_item) { |
|
390 | - $total += max($tax_line_item->total(), 0); |
|
391 | - } |
|
392 | - return $total; |
|
393 | - } |
|
394 | - |
|
395 | - /** |
|
396 | - * Determines whether or not we can easily itemize the transaction using only |
|
397 | - * items and taxes (ie, no promotions or surcharges or cancellations needed) |
|
398 | - * |
|
399 | - * @param EEI_Payment $payment |
|
400 | - * @return boolean |
|
401 | - */ |
|
402 | - protected function _can_easily_itemize_transaction_for(EEI_Payment $payment) |
|
403 | - { |
|
404 | - return $this->_money->compare_floats( |
|
405 | - $this->_sum_items_and_taxes($payment->transaction()), |
|
406 | - $payment->transaction()->total() |
|
407 | - ) |
|
408 | - && $this->_money->compare_floats( |
|
409 | - $payment->amount(), |
|
410 | - $payment->transaction()->total() |
|
411 | - ); |
|
412 | - } |
|
413 | - |
|
414 | - /** |
|
415 | - * Handles updating the transaction and any other related data based on the payment. |
|
416 | - * You may be tempted to do this as part of do_direct_payment or handle_payment_update, |
|
417 | - * but doing so on those functions might be too early. It's possible that the changes |
|
418 | - * you make to teh transaction or registration or line items may just get overwritten |
|
419 | - * at that point. Instead, you should store any info you need on the payment during those |
|
420 | - * functions, and use that information at this step, which client code will decide |
|
421 | - * for you when it should be called. |
|
422 | - * |
|
423 | - * @param EE_Payment $payment |
|
424 | - * @return void |
|
425 | - */ |
|
426 | - public function update_txn_based_on_payment($payment) |
|
427 | - { |
|
428 | - // maybe update the transaction or line items or registrations |
|
429 | - // but most gateways don't need to do this, because they only update the payment |
|
430 | - } |
|
431 | - |
|
432 | - /** |
|
433 | - * Gets the first event for this payment (it's possible that it could be for multiple) |
|
434 | - * |
|
435 | - * @param EEI_Payment $payment |
|
436 | - * @return EEI_Event|null |
|
437 | - * @deprecated since 4.9.31 instead use EEI_Payment::get_first_event() |
|
438 | - */ |
|
439 | - protected function _get_first_event_for_payment(EEI_Payment $payment) |
|
440 | - { |
|
441 | - return $payment->get_first_event(); |
|
442 | - } |
|
443 | - |
|
444 | - /** |
|
445 | - * Gets the name of the first event for which is being paid |
|
446 | - * |
|
447 | - * @param EEI_Payment $payment |
|
448 | - * @return string |
|
449 | - * @deprecated since 4.9.31 instead use EEI_Payment::get_first_event_name() |
|
450 | - */ |
|
451 | - protected function _get_first_event_name_for_payment(EEI_Payment $payment) |
|
452 | - { |
|
453 | - return $payment->get_first_event_name(); |
|
454 | - } |
|
455 | - |
|
456 | - /** |
|
457 | - * Gets the text to use for a gateway's line item name when this is a partial payment |
|
458 | - * |
|
459 | - * @deprecated since 4.9.31 instead use $this->_get_gateway_formatter()->formatPartialPaymentLineItemName($payment) |
|
460 | - * @param EE_Payment $payment |
|
461 | - * @return string |
|
462 | - */ |
|
463 | - protected function _format_partial_payment_line_item_name(EEI_Payment $payment) |
|
464 | - { |
|
465 | - return $this->_get_gateway_formatter()->formatPartialPaymentLineItemName($payment); |
|
466 | - } |
|
467 | - |
|
468 | - /** |
|
469 | - * Gets the text to use for a gateway's line item description when this is a partial payment |
|
470 | - * |
|
471 | - * @deprecated since 4.9.31 instead use $this->_get_gateway_formatter()->formatPartialPaymentLineItemDesc() |
|
472 | - * @param EEI_Payment $payment |
|
473 | - * @return string |
|
474 | - */ |
|
475 | - protected function _format_partial_payment_line_item_desc(EEI_Payment $payment) |
|
476 | - { |
|
477 | - return $this->_get_gateway_formatter()->formatPartialPaymentLineItemDesc($payment); |
|
478 | - } |
|
479 | - |
|
480 | - /** |
|
481 | - * Gets the name to use for a line item when sending line items to the gateway |
|
482 | - * |
|
483 | - * @deprecated since 4.9.31 instead use $this->_get_gateway_formatter()->formatLineItemName($line_item,$payment) |
|
484 | - * @param EEI_Line_Item $line_item |
|
485 | - * @param EEI_Payment $payment |
|
486 | - * @return string |
|
487 | - */ |
|
488 | - protected function _format_line_item_name(EEI_Line_Item $line_item, EEI_Payment $payment) |
|
489 | - { |
|
490 | - return $this->_get_gateway_formatter()->formatLineItemName($line_item, $payment); |
|
491 | - } |
|
492 | - |
|
493 | - /** |
|
494 | - * Gets the description to use for a line item when sending line items to the gateway |
|
495 | - * |
|
496 | - * @deprecated since 4.9.31 instead use $this->_get_gateway_formatter()->formatLineItemDesc($line_item, $payment)) |
|
497 | - * @param EEI_Line_Item $line_item |
|
498 | - * @param EEI_Payment $payment |
|
499 | - * @return string |
|
500 | - */ |
|
501 | - protected function _format_line_item_desc(EEI_Line_Item $line_item, EEI_Payment $payment) |
|
502 | - { |
|
503 | - return $this->_get_gateway_formatter()->formatLineItemDesc($line_item, $payment); |
|
504 | - } |
|
505 | - |
|
506 | - /** |
|
507 | - * Gets the order description that should generlly be sent to gateways |
|
508 | - * |
|
509 | - * @deprecated since 4.9.31 instead use $this->_get_gateway_formatter()->formatOrderDescription($payment) |
|
510 | - * @param EEI_Payment $payment |
|
511 | - * @return type |
|
512 | - */ |
|
513 | - protected function _format_order_description(EEI_Payment $payment) |
|
514 | - { |
|
515 | - return $this->_get_gateway_formatter()->formatOrderDescription($payment); |
|
516 | - } |
|
26 | + /** |
|
27 | + * a constant used as a possible value for $_currencies_supported to indicate |
|
28 | + * that ALL currencies are supported by this gateway |
|
29 | + */ |
|
30 | + const all_currencies_supported = 'all_currencies_supported'; |
|
31 | + /** |
|
32 | + * Where values are 3-letter currency codes |
|
33 | + * |
|
34 | + * @var array |
|
35 | + */ |
|
36 | + protected $_currencies_supported = array(); |
|
37 | + /** |
|
38 | + * Whether or not this gateway can support SENDING a refund request (ie, initiated by |
|
39 | + * admin in EE's wp-admin page) |
|
40 | + * |
|
41 | + * @var boolean |
|
42 | + */ |
|
43 | + protected $_supports_sending_refunds = false; |
|
44 | + |
|
45 | + /** |
|
46 | + * Whether or not this gateway can support RECEIVING a refund request from the payment |
|
47 | + * provider (ie, initiated by admin on the payment prover's website who sends an IPN to EE) |
|
48 | + * |
|
49 | + * @var boolean |
|
50 | + */ |
|
51 | + protected $_supports_receiving_refunds = false; |
|
52 | + /** |
|
53 | + * Model for querying for existing payments |
|
54 | + * |
|
55 | + * @var EEMI_Payment |
|
56 | + */ |
|
57 | + protected $_pay_model; |
|
58 | + |
|
59 | + /** |
|
60 | + * Model used for adding to the payments log |
|
61 | + * |
|
62 | + * @var EEMI_Payment_Log |
|
63 | + */ |
|
64 | + protected $_pay_log; |
|
65 | + |
|
66 | + /** |
|
67 | + * Used for formatting some input to gateways |
|
68 | + * |
|
69 | + * @var EEHI_Template |
|
70 | + */ |
|
71 | + protected $_template; |
|
72 | + |
|
73 | + /** |
|
74 | + * Concrete class that implements EEHI_Money, used by most gateways |
|
75 | + * |
|
76 | + * @var EEHI_Money |
|
77 | + */ |
|
78 | + protected $_money; |
|
79 | + |
|
80 | + /** |
|
81 | + * Concrete class that implements EEHI_Line_Item, used for manipulating the line item tree |
|
82 | + * |
|
83 | + * @var EEHI_Line_Item |
|
84 | + */ |
|
85 | + protected $_line_item; |
|
86 | + |
|
87 | + /** |
|
88 | + * @var GatewayDataFormatterInterface |
|
89 | + */ |
|
90 | + protected $_gateway_data_formatter; |
|
91 | + |
|
92 | + /** |
|
93 | + * @var FormatterInterface |
|
94 | + */ |
|
95 | + protected $_unsupported_character_remover; |
|
96 | + |
|
97 | + /** |
|
98 | + * The ID of the payment method using this gateway |
|
99 | + * |
|
100 | + * @var int |
|
101 | + */ |
|
102 | + protected $_ID; |
|
103 | + |
|
104 | + /** |
|
105 | + * @var $_debug_mode boolean whether to send requests to teh sandbox site or not |
|
106 | + */ |
|
107 | + protected $_debug_mode; |
|
108 | + /** |
|
109 | + * |
|
110 | + * @var string $_name name to show for this payment method |
|
111 | + */ |
|
112 | + protected $_name; |
|
113 | + /** |
|
114 | + * |
|
115 | + * @var string name to show fir this payment method to admin-type users |
|
116 | + */ |
|
117 | + protected $_admin_name; |
|
118 | + |
|
119 | + /** |
|
120 | + * @return EE_Gateway |
|
121 | + */ |
|
122 | + public function __construct() |
|
123 | + { |
|
124 | + } |
|
125 | + |
|
126 | + /** |
|
127 | + * We don't want to serialize models as they often have circular structures |
|
128 | + * (eg a payment model has a reference to each payment model object; and most |
|
129 | + * payments have a transaction, most transactions have a payment method; |
|
130 | + * most payment methods have a payment method type; most payment method types |
|
131 | + * have a gateway. And if a gateway serializes its models, we start at the |
|
132 | + * beginning again) |
|
133 | + * |
|
134 | + * @return array |
|
135 | + */ |
|
136 | + public function __sleep() |
|
137 | + { |
|
138 | + $properties = get_object_vars($this); |
|
139 | + unset($properties['_pay_model'], $properties['_pay_log']); |
|
140 | + return array_keys($properties); |
|
141 | + } |
|
142 | + |
|
143 | + /** |
|
144 | + * Returns whether or not this gateway should support SENDING refunds |
|
145 | + * see $_supports_sending_refunds |
|
146 | + * |
|
147 | + * @return boolean |
|
148 | + */ |
|
149 | + public function supports_sending_refunds() |
|
150 | + { |
|
151 | + return $this->_supports_sending_refunds; |
|
152 | + } |
|
153 | + |
|
154 | + /** |
|
155 | + * Returns whether or not this gateway should support RECEIVING refunds |
|
156 | + * see $_supports_receiving_refunds |
|
157 | + * |
|
158 | + * @return boolean |
|
159 | + */ |
|
160 | + public function supports_receiving_refunds() |
|
161 | + { |
|
162 | + return $this->_supports_receiving_refunds; |
|
163 | + } |
|
164 | + |
|
165 | + |
|
166 | + /** |
|
167 | + * Tries to refund the payment specified, taking into account the extra |
|
168 | + * refund info. Note that if the gateway's _supports_sending_refunds is false, |
|
169 | + * this should just throw an exception. |
|
170 | + * |
|
171 | + * @param EE_Payment $payment |
|
172 | + * @param array $refund_info |
|
173 | + * @return EE_Payment for the refund |
|
174 | + * @throws EE_Error |
|
175 | + */ |
|
176 | + public function do_direct_refund(EE_Payment $payment, $refund_info = null) |
|
177 | + { |
|
178 | + return null; |
|
179 | + } |
|
180 | + |
|
181 | + |
|
182 | + /** |
|
183 | + * Sets the payment method's settings so the gateway knows where to send the request |
|
184 | + * etc |
|
185 | + * |
|
186 | + * @param array $settings_array |
|
187 | + */ |
|
188 | + public function set_settings($settings_array) |
|
189 | + { |
|
190 | + foreach ($settings_array as $name => $value) { |
|
191 | + $property_name = "_" . $name; |
|
192 | + $this->{$property_name} = $value; |
|
193 | + } |
|
194 | + } |
|
195 | + |
|
196 | + /** |
|
197 | + * See this class description |
|
198 | + * |
|
199 | + * @param EEMI_Payment $payment_model |
|
200 | + */ |
|
201 | + public function set_payment_model($payment_model) |
|
202 | + { |
|
203 | + $this->_pay_model = $payment_model; |
|
204 | + } |
|
205 | + |
|
206 | + /** |
|
207 | + * See this class description |
|
208 | + * |
|
209 | + * @param EEMI_Payment_Log $payment_log_model |
|
210 | + */ |
|
211 | + public function set_payment_log($payment_log_model) |
|
212 | + { |
|
213 | + $this->_pay_log = $payment_log_model; |
|
214 | + } |
|
215 | + |
|
216 | + /** |
|
217 | + * See this class description |
|
218 | + * |
|
219 | + * @param EEHI_Template $template_helper |
|
220 | + */ |
|
221 | + public function set_template_helper($template_helper) |
|
222 | + { |
|
223 | + $this->_template = $template_helper; |
|
224 | + } |
|
225 | + |
|
226 | + /** |
|
227 | + * See this class description |
|
228 | + * |
|
229 | + * @param EEHI_Line_Item $line_item_helper |
|
230 | + */ |
|
231 | + public function set_line_item_helper($line_item_helper) |
|
232 | + { |
|
233 | + $this->_line_item = $line_item_helper; |
|
234 | + } |
|
235 | + |
|
236 | + /** |
|
237 | + * See this class description |
|
238 | + * |
|
239 | + * @param EEHI_Money $money_helper |
|
240 | + */ |
|
241 | + public function set_money_helper($money_helper) |
|
242 | + { |
|
243 | + $this->_money = $money_helper; |
|
244 | + } |
|
245 | + |
|
246 | + |
|
247 | + /** |
|
248 | + * Sets the gateway data formatter helper |
|
249 | + * |
|
250 | + * @param GatewayDataFormatterInterface $gateway_data_formatter |
|
251 | + * @throws InvalidEntityException if it's not set properly |
|
252 | + */ |
|
253 | + public function set_gateway_data_formatter(GatewayDataFormatterInterface $gateway_data_formatter) |
|
254 | + { |
|
255 | + if (! $gateway_data_formatter instanceof GatewayDataFormatterInterface) { |
|
256 | + throw new InvalidEntityException( |
|
257 | + is_object($gateway_data_formatter) |
|
258 | + ? get_class($gateway_data_formatter) |
|
259 | + : esc_html__('Not an object', 'event_espresso'), |
|
260 | + '\\EventEspresso\\core\\services\\payment_methods\\gateways\\GatewayDataFormatterInterface' |
|
261 | + ); |
|
262 | + } |
|
263 | + $this->_gateway_data_formatter = $gateway_data_formatter; |
|
264 | + } |
|
265 | + |
|
266 | + /** |
|
267 | + * Gets the gateway data formatter |
|
268 | + * |
|
269 | + * @return GatewayDataFormatterInterface |
|
270 | + * @throws InvalidEntityException if it's not set properly |
|
271 | + */ |
|
272 | + protected function _get_gateway_formatter() |
|
273 | + { |
|
274 | + if (! $this->_gateway_data_formatter instanceof GatewayDataFormatterInterface) { |
|
275 | + throw new InvalidEntityException( |
|
276 | + is_object($this->_gateway_data_formatter) |
|
277 | + ? get_class($this->_gateway_data_formatter) |
|
278 | + : esc_html__('Not an object', 'event_espresso'), |
|
279 | + '\\EventEspresso\\core\\services\\payment_methods\\gateways\\GatewayDataFormatterInterface' |
|
280 | + ); |
|
281 | + } |
|
282 | + return $this->_gateway_data_formatter; |
|
283 | + } |
|
284 | + |
|
285 | + |
|
286 | + /** |
|
287 | + * Sets the helper which will remove unsupported characters for most gateways |
|
288 | + * |
|
289 | + * @param FormatterInterface $formatter |
|
290 | + * @return FormatterInterface |
|
291 | + * @throws InvalidEntityException |
|
292 | + */ |
|
293 | + public function set_unsupported_character_remover(FormatterInterface $formatter) |
|
294 | + { |
|
295 | + if (! $formatter instanceof FormatterInterface) { |
|
296 | + throw new InvalidEntityException( |
|
297 | + is_object($formatter) |
|
298 | + ? get_class($formatter) |
|
299 | + : esc_html__('Not an object', 'event_espresso'), |
|
300 | + '\\EventEspresso\\core\\services\\formatters\\FormatterInterface' |
|
301 | + ); |
|
302 | + } |
|
303 | + $this->_unsupported_character_remover = $formatter; |
|
304 | + } |
|
305 | + |
|
306 | + /** |
|
307 | + * Gets the helper which removes characters which gateways might not support, like emojis etc. |
|
308 | + * |
|
309 | + * @return FormatterInterface |
|
310 | + * @throws InvalidEntityException |
|
311 | + */ |
|
312 | + protected function _get_unsupported_character_remover() |
|
313 | + { |
|
314 | + if (! $this->_unsupported_character_remover instanceof FormatterInterface) { |
|
315 | + throw new InvalidEntityException( |
|
316 | + is_object($this->_unsupported_character_remover) |
|
317 | + ? get_class($this->_unsupported_character_remover) |
|
318 | + : esc_html__('Not an object', 'event_espresso'), |
|
319 | + '\\EventEspresso\\core\\services\\formatters\\FormatterInterface' |
|
320 | + ); |
|
321 | + } |
|
322 | + return $this->_unsupported_character_remover; |
|
323 | + } |
|
324 | + |
|
325 | + |
|
326 | + /** |
|
327 | + * @param $message |
|
328 | + * @param $payment |
|
329 | + */ |
|
330 | + public function log($message, $object_logged) |
|
331 | + { |
|
332 | + if ($object_logged instanceof EEI_Payment) { |
|
333 | + $type = 'Payment'; |
|
334 | + $id = $object_logged->ID(); |
|
335 | + } elseif ($object_logged instanceof EEI_Transaction) { |
|
336 | + $type = 'Transaction'; |
|
337 | + $id = $object_logged->ID(); |
|
338 | + } else { |
|
339 | + $type = 'Payment_Method'; |
|
340 | + $id = $this->_ID; |
|
341 | + } |
|
342 | + // only log if we're going to store it for longer than the minimum time |
|
343 | + $reg_config = LoaderFactory::getLoader()->load('EE_Registration_Config'); |
|
344 | + if ($reg_config->gateway_log_lifespan !== '1 second') { |
|
345 | + $this->_pay_log->gateway_log($message, $id, $type); |
|
346 | + } |
|
347 | + } |
|
348 | + |
|
349 | + /** |
|
350 | + * Formats the amount so it can generally be sent to gateways |
|
351 | + * |
|
352 | + * @param float $amount |
|
353 | + * @return string |
|
354 | + * @deprecated since 4.9.31 insetad use |
|
355 | + * EventEspresso\core\services\payment_methods\gateways\GatewayDataFormatter::format_currency() |
|
356 | + */ |
|
357 | + public function format_currency($amount) |
|
358 | + { |
|
359 | + return $this->_get_gateway_formatter()->formatCurrency($amount); |
|
360 | + } |
|
361 | + |
|
362 | + /** |
|
363 | + * Returns either an array of all the currency codes supported, |
|
364 | + * or a string indicating they're all supported (EE_gateway::all_currencies_supported) |
|
365 | + * |
|
366 | + * @return mixed array or string |
|
367 | + */ |
|
368 | + public function currencies_supported() |
|
369 | + { |
|
370 | + return $this->_currencies_supported; |
|
371 | + } |
|
372 | + |
|
373 | + /** |
|
374 | + * Returns what a simple summing of items and taxes for this transaction. This |
|
375 | + * can be used to determine if some more complex line items, like promotions, |
|
376 | + * surcharges, or cancellations occurred (in which case we might want to forget |
|
377 | + * about creating an itemized list of purchases and instead only send the total due) |
|
378 | + * |
|
379 | + * @param EE_Transaction $transaction |
|
380 | + * @return float |
|
381 | + */ |
|
382 | + protected function _sum_items_and_taxes(EE_Transaction $transaction) |
|
383 | + { |
|
384 | + $total_line_item = $transaction->total_line_item(); |
|
385 | + $total = 0; |
|
386 | + foreach ($total_line_item->get_items() as $item_line_item) { |
|
387 | + $total += max($item_line_item->total(), 0); |
|
388 | + } |
|
389 | + foreach ($total_line_item->tax_descendants() as $tax_line_item) { |
|
390 | + $total += max($tax_line_item->total(), 0); |
|
391 | + } |
|
392 | + return $total; |
|
393 | + } |
|
394 | + |
|
395 | + /** |
|
396 | + * Determines whether or not we can easily itemize the transaction using only |
|
397 | + * items and taxes (ie, no promotions or surcharges or cancellations needed) |
|
398 | + * |
|
399 | + * @param EEI_Payment $payment |
|
400 | + * @return boolean |
|
401 | + */ |
|
402 | + protected function _can_easily_itemize_transaction_for(EEI_Payment $payment) |
|
403 | + { |
|
404 | + return $this->_money->compare_floats( |
|
405 | + $this->_sum_items_and_taxes($payment->transaction()), |
|
406 | + $payment->transaction()->total() |
|
407 | + ) |
|
408 | + && $this->_money->compare_floats( |
|
409 | + $payment->amount(), |
|
410 | + $payment->transaction()->total() |
|
411 | + ); |
|
412 | + } |
|
413 | + |
|
414 | + /** |
|
415 | + * Handles updating the transaction and any other related data based on the payment. |
|
416 | + * You may be tempted to do this as part of do_direct_payment or handle_payment_update, |
|
417 | + * but doing so on those functions might be too early. It's possible that the changes |
|
418 | + * you make to teh transaction or registration or line items may just get overwritten |
|
419 | + * at that point. Instead, you should store any info you need on the payment during those |
|
420 | + * functions, and use that information at this step, which client code will decide |
|
421 | + * for you when it should be called. |
|
422 | + * |
|
423 | + * @param EE_Payment $payment |
|
424 | + * @return void |
|
425 | + */ |
|
426 | + public function update_txn_based_on_payment($payment) |
|
427 | + { |
|
428 | + // maybe update the transaction or line items or registrations |
|
429 | + // but most gateways don't need to do this, because they only update the payment |
|
430 | + } |
|
431 | + |
|
432 | + /** |
|
433 | + * Gets the first event for this payment (it's possible that it could be for multiple) |
|
434 | + * |
|
435 | + * @param EEI_Payment $payment |
|
436 | + * @return EEI_Event|null |
|
437 | + * @deprecated since 4.9.31 instead use EEI_Payment::get_first_event() |
|
438 | + */ |
|
439 | + protected function _get_first_event_for_payment(EEI_Payment $payment) |
|
440 | + { |
|
441 | + return $payment->get_first_event(); |
|
442 | + } |
|
443 | + |
|
444 | + /** |
|
445 | + * Gets the name of the first event for which is being paid |
|
446 | + * |
|
447 | + * @param EEI_Payment $payment |
|
448 | + * @return string |
|
449 | + * @deprecated since 4.9.31 instead use EEI_Payment::get_first_event_name() |
|
450 | + */ |
|
451 | + protected function _get_first_event_name_for_payment(EEI_Payment $payment) |
|
452 | + { |
|
453 | + return $payment->get_first_event_name(); |
|
454 | + } |
|
455 | + |
|
456 | + /** |
|
457 | + * Gets the text to use for a gateway's line item name when this is a partial payment |
|
458 | + * |
|
459 | + * @deprecated since 4.9.31 instead use $this->_get_gateway_formatter()->formatPartialPaymentLineItemName($payment) |
|
460 | + * @param EE_Payment $payment |
|
461 | + * @return string |
|
462 | + */ |
|
463 | + protected function _format_partial_payment_line_item_name(EEI_Payment $payment) |
|
464 | + { |
|
465 | + return $this->_get_gateway_formatter()->formatPartialPaymentLineItemName($payment); |
|
466 | + } |
|
467 | + |
|
468 | + /** |
|
469 | + * Gets the text to use for a gateway's line item description when this is a partial payment |
|
470 | + * |
|
471 | + * @deprecated since 4.9.31 instead use $this->_get_gateway_formatter()->formatPartialPaymentLineItemDesc() |
|
472 | + * @param EEI_Payment $payment |
|
473 | + * @return string |
|
474 | + */ |
|
475 | + protected function _format_partial_payment_line_item_desc(EEI_Payment $payment) |
|
476 | + { |
|
477 | + return $this->_get_gateway_formatter()->formatPartialPaymentLineItemDesc($payment); |
|
478 | + } |
|
479 | + |
|
480 | + /** |
|
481 | + * Gets the name to use for a line item when sending line items to the gateway |
|
482 | + * |
|
483 | + * @deprecated since 4.9.31 instead use $this->_get_gateway_formatter()->formatLineItemName($line_item,$payment) |
|
484 | + * @param EEI_Line_Item $line_item |
|
485 | + * @param EEI_Payment $payment |
|
486 | + * @return string |
|
487 | + */ |
|
488 | + protected function _format_line_item_name(EEI_Line_Item $line_item, EEI_Payment $payment) |
|
489 | + { |
|
490 | + return $this->_get_gateway_formatter()->formatLineItemName($line_item, $payment); |
|
491 | + } |
|
492 | + |
|
493 | + /** |
|
494 | + * Gets the description to use for a line item when sending line items to the gateway |
|
495 | + * |
|
496 | + * @deprecated since 4.9.31 instead use $this->_get_gateway_formatter()->formatLineItemDesc($line_item, $payment)) |
|
497 | + * @param EEI_Line_Item $line_item |
|
498 | + * @param EEI_Payment $payment |
|
499 | + * @return string |
|
500 | + */ |
|
501 | + protected function _format_line_item_desc(EEI_Line_Item $line_item, EEI_Payment $payment) |
|
502 | + { |
|
503 | + return $this->_get_gateway_formatter()->formatLineItemDesc($line_item, $payment); |
|
504 | + } |
|
505 | + |
|
506 | + /** |
|
507 | + * Gets the order description that should generlly be sent to gateways |
|
508 | + * |
|
509 | + * @deprecated since 4.9.31 instead use $this->_get_gateway_formatter()->formatOrderDescription($payment) |
|
510 | + * @param EEI_Payment $payment |
|
511 | + * @return type |
|
512 | + */ |
|
513 | + protected function _format_order_description(EEI_Payment $payment) |
|
514 | + { |
|
515 | + return $this->_get_gateway_formatter()->formatOrderDescription($payment); |
|
516 | + } |
|
517 | 517 | } |
@@ -22,30 +22,30 @@ |
||
22 | 22 | |
23 | 23 | interface JobHandlerInterface |
24 | 24 | { |
25 | - /** |
|
26 | - * Performs any necessary setup for starting the job. This is also a good |
|
27 | - * place to setup the $job_arguments which will be used for subsequent HTTP requests |
|
28 | - * when continue_job will be called |
|
29 | - * @param JobParameters $job_parameters |
|
30 | - * @throws BatchRequestException |
|
31 | - * @return JobStepResponse |
|
32 | - */ |
|
33 | - public function create_job(JobParameters $job_parameters); |
|
25 | + /** |
|
26 | + * Performs any necessary setup for starting the job. This is also a good |
|
27 | + * place to setup the $job_arguments which will be used for subsequent HTTP requests |
|
28 | + * when continue_job will be called |
|
29 | + * @param JobParameters $job_parameters |
|
30 | + * @throws BatchRequestException |
|
31 | + * @return JobStepResponse |
|
32 | + */ |
|
33 | + public function create_job(JobParameters $job_parameters); |
|
34 | 34 | |
35 | - /** |
|
36 | - * Performs another step of the job |
|
37 | - * @param JobParameters $job_parameters |
|
38 | - * @param int $batch_size |
|
39 | - * @return JobStepResponse |
|
40 | - * @throws BatchRequestException |
|
41 | - */ |
|
42 | - public function continue_job(JobParameters $job_parameters, $batch_size = 50); |
|
35 | + /** |
|
36 | + * Performs another step of the job |
|
37 | + * @param JobParameters $job_parameters |
|
38 | + * @param int $batch_size |
|
39 | + * @return JobStepResponse |
|
40 | + * @throws BatchRequestException |
|
41 | + */ |
|
42 | + public function continue_job(JobParameters $job_parameters, $batch_size = 50); |
|
43 | 43 | |
44 | - /** |
|
45 | - * Performs any clean-up logic when we know the job is completed |
|
46 | - * @param JobParameters $job_parameters |
|
47 | - * @return JobStepResponse |
|
48 | - * @throws BatchRequestException |
|
49 | - */ |
|
50 | - public function cleanup_job(JobParameters $job_parameters); |
|
44 | + /** |
|
45 | + * Performs any clean-up logic when we know the job is completed |
|
46 | + * @param JobParameters $job_parameters |
|
47 | + * @return JobStepResponse |
|
48 | + * @throws BatchRequestException |
|
49 | + */ |
|
50 | + public function cleanup_job(JobParameters $job_parameters); |
|
51 | 51 | } |
@@ -71,7 +71,7 @@ discard block |
||
71 | 71 | */ |
72 | 72 | public function set_notice($key, $value) |
73 | 73 | { |
74 | - $this->_notice[ $key ] = $value; |
|
74 | + $this->_notice[$key] = $value; |
|
75 | 75 | } |
76 | 76 | |
77 | 77 | |
@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | */ |
83 | 83 | public function get_notice($key) |
84 | 84 | { |
85 | - return isset($this->_notice[ $key ]) ? $this->_notice[ $key ] : null; |
|
85 | + return isset($this->_notice[$key]) ? $this->_notice[$key] : null; |
|
86 | 86 | } |
87 | 87 | |
88 | 88 | |
@@ -103,7 +103,7 @@ discard block |
||
103 | 103 | */ |
104 | 104 | public function add_output($string, $append = true) |
105 | 105 | { |
106 | - $this->_output = $append ? $this->_output . $string : $string . $this->_output; |
|
106 | + $this->_output = $append ? $this->_output.$string : $string.$this->_output; |
|
107 | 107 | } |
108 | 108 | |
109 | 109 |
@@ -12,146 +12,146 @@ |
||
12 | 12 | */ |
13 | 13 | class EE_Response |
14 | 14 | { |
15 | - /** |
|
16 | - * @access protected |
|
17 | - * @type array $_notice |
|
18 | - */ |
|
19 | - protected $_notice = array(); |
|
20 | - |
|
21 | - /** |
|
22 | - * rendered output to be returned to WP |
|
23 | - * |
|
24 | - * @access protected |
|
25 | - * @type string |
|
26 | - */ |
|
27 | - protected $_output = ''; |
|
28 | - |
|
29 | - /** |
|
30 | - * @access protected |
|
31 | - * @type bool |
|
32 | - */ |
|
33 | - protected $request_terminated = false; |
|
34 | - |
|
35 | - /** |
|
36 | - * @access protected |
|
37 | - * @type bool |
|
38 | - */ |
|
39 | - protected $deactivate_plugin = false; |
|
40 | - |
|
41 | - |
|
42 | - /** |
|
43 | - * @deprecated 4.9.53 |
|
44 | - * @return \EE_Response |
|
45 | - */ |
|
46 | - public function __construct() |
|
47 | - { |
|
48 | - $this->terminate_request(false); |
|
49 | - EE_Error::doing_it_wrong( |
|
50 | - __METHOD__, |
|
51 | - sprintf( |
|
52 | - esc_html__( |
|
53 | - 'This class is deprecated. Please use %1$s instead. All Event Espresso request stack classes have been moved to %2$s and are now under the %3$s namespace', |
|
54 | - 'event_espresso' |
|
55 | - ), |
|
56 | - 'EventEspresso\core\services\request\Response', |
|
57 | - '\core\services\request', |
|
58 | - 'EventEspresso\core\services\request' |
|
59 | - ), |
|
60 | - '4.9.53' |
|
61 | - ); |
|
62 | - } |
|
63 | - |
|
64 | - |
|
65 | - /** |
|
66 | - * @deprecated 4.9.53 |
|
67 | - * @param $key |
|
68 | - * @param $value |
|
69 | - * @return void |
|
70 | - */ |
|
71 | - public function set_notice($key, $value) |
|
72 | - { |
|
73 | - $this->_notice[ $key ] = $value; |
|
74 | - } |
|
75 | - |
|
76 | - |
|
77 | - /** |
|
78 | - * @deprecated 4.9.53 |
|
79 | - * @param $key |
|
80 | - * @return mixed |
|
81 | - */ |
|
82 | - public function get_notice($key) |
|
83 | - { |
|
84 | - return isset($this->_notice[ $key ]) ? $this->_notice[ $key ] : null; |
|
85 | - } |
|
86 | - |
|
87 | - |
|
88 | - /** |
|
89 | - * @deprecated 4.9.53 |
|
90 | - * @return array |
|
91 | - */ |
|
92 | - public function get_notices() |
|
93 | - { |
|
94 | - return $this->_notice; |
|
95 | - } |
|
96 | - |
|
97 | - |
|
98 | - /** |
|
99 | - * @deprecated 4.9.53 |
|
100 | - * @param $string |
|
101 | - * @param bool $append |
|
102 | - */ |
|
103 | - public function add_output($string, $append = true) |
|
104 | - { |
|
105 | - $this->_output = $append ? $this->_output . $string : $string . $this->_output; |
|
106 | - } |
|
107 | - |
|
108 | - |
|
109 | - /** |
|
110 | - * @deprecated 4.9.53 |
|
111 | - * @return string |
|
112 | - */ |
|
113 | - public function get_output() |
|
114 | - { |
|
115 | - return $this->_output; |
|
116 | - } |
|
117 | - |
|
118 | - |
|
119 | - /** |
|
120 | - * @deprecated 4.9.53 |
|
121 | - * @return boolean |
|
122 | - */ |
|
123 | - public function request_terminated() |
|
124 | - { |
|
125 | - return $this->request_terminated; |
|
126 | - } |
|
127 | - |
|
128 | - |
|
129 | - /** |
|
130 | - * @deprecated 4.9.53 |
|
131 | - * @param boolean $request_terminated |
|
132 | - */ |
|
133 | - public function terminate_request($request_terminated = true) |
|
134 | - { |
|
135 | - $this->request_terminated = filter_var($request_terminated, FILTER_VALIDATE_BOOLEAN); |
|
136 | - } |
|
137 | - |
|
138 | - |
|
139 | - /** |
|
140 | - * @deprecated 4.9.53 |
|
141 | - * @return boolean |
|
142 | - */ |
|
143 | - public function plugin_deactivated() |
|
144 | - { |
|
145 | - return $this->deactivate_plugin; |
|
146 | - } |
|
147 | - |
|
148 | - |
|
149 | - /** |
|
150 | - * @deprecated 4.9.53 |
|
151 | - * sets $deactivate_plugin to true |
|
152 | - */ |
|
153 | - public function deactivate_plugin() |
|
154 | - { |
|
155 | - $this->deactivate_plugin = true; |
|
156 | - } |
|
15 | + /** |
|
16 | + * @access protected |
|
17 | + * @type array $_notice |
|
18 | + */ |
|
19 | + protected $_notice = array(); |
|
20 | + |
|
21 | + /** |
|
22 | + * rendered output to be returned to WP |
|
23 | + * |
|
24 | + * @access protected |
|
25 | + * @type string |
|
26 | + */ |
|
27 | + protected $_output = ''; |
|
28 | + |
|
29 | + /** |
|
30 | + * @access protected |
|
31 | + * @type bool |
|
32 | + */ |
|
33 | + protected $request_terminated = false; |
|
34 | + |
|
35 | + /** |
|
36 | + * @access protected |
|
37 | + * @type bool |
|
38 | + */ |
|
39 | + protected $deactivate_plugin = false; |
|
40 | + |
|
41 | + |
|
42 | + /** |
|
43 | + * @deprecated 4.9.53 |
|
44 | + * @return \EE_Response |
|
45 | + */ |
|
46 | + public function __construct() |
|
47 | + { |
|
48 | + $this->terminate_request(false); |
|
49 | + EE_Error::doing_it_wrong( |
|
50 | + __METHOD__, |
|
51 | + sprintf( |
|
52 | + esc_html__( |
|
53 | + 'This class is deprecated. Please use %1$s instead. All Event Espresso request stack classes have been moved to %2$s and are now under the %3$s namespace', |
|
54 | + 'event_espresso' |
|
55 | + ), |
|
56 | + 'EventEspresso\core\services\request\Response', |
|
57 | + '\core\services\request', |
|
58 | + 'EventEspresso\core\services\request' |
|
59 | + ), |
|
60 | + '4.9.53' |
|
61 | + ); |
|
62 | + } |
|
63 | + |
|
64 | + |
|
65 | + /** |
|
66 | + * @deprecated 4.9.53 |
|
67 | + * @param $key |
|
68 | + * @param $value |
|
69 | + * @return void |
|
70 | + */ |
|
71 | + public function set_notice($key, $value) |
|
72 | + { |
|
73 | + $this->_notice[ $key ] = $value; |
|
74 | + } |
|
75 | + |
|
76 | + |
|
77 | + /** |
|
78 | + * @deprecated 4.9.53 |
|
79 | + * @param $key |
|
80 | + * @return mixed |
|
81 | + */ |
|
82 | + public function get_notice($key) |
|
83 | + { |
|
84 | + return isset($this->_notice[ $key ]) ? $this->_notice[ $key ] : null; |
|
85 | + } |
|
86 | + |
|
87 | + |
|
88 | + /** |
|
89 | + * @deprecated 4.9.53 |
|
90 | + * @return array |
|
91 | + */ |
|
92 | + public function get_notices() |
|
93 | + { |
|
94 | + return $this->_notice; |
|
95 | + } |
|
96 | + |
|
97 | + |
|
98 | + /** |
|
99 | + * @deprecated 4.9.53 |
|
100 | + * @param $string |
|
101 | + * @param bool $append |
|
102 | + */ |
|
103 | + public function add_output($string, $append = true) |
|
104 | + { |
|
105 | + $this->_output = $append ? $this->_output . $string : $string . $this->_output; |
|
106 | + } |
|
107 | + |
|
108 | + |
|
109 | + /** |
|
110 | + * @deprecated 4.9.53 |
|
111 | + * @return string |
|
112 | + */ |
|
113 | + public function get_output() |
|
114 | + { |
|
115 | + return $this->_output; |
|
116 | + } |
|
117 | + |
|
118 | + |
|
119 | + /** |
|
120 | + * @deprecated 4.9.53 |
|
121 | + * @return boolean |
|
122 | + */ |
|
123 | + public function request_terminated() |
|
124 | + { |
|
125 | + return $this->request_terminated; |
|
126 | + } |
|
127 | + |
|
128 | + |
|
129 | + /** |
|
130 | + * @deprecated 4.9.53 |
|
131 | + * @param boolean $request_terminated |
|
132 | + */ |
|
133 | + public function terminate_request($request_terminated = true) |
|
134 | + { |
|
135 | + $this->request_terminated = filter_var($request_terminated, FILTER_VALIDATE_BOOLEAN); |
|
136 | + } |
|
137 | + |
|
138 | + |
|
139 | + /** |
|
140 | + * @deprecated 4.9.53 |
|
141 | + * @return boolean |
|
142 | + */ |
|
143 | + public function plugin_deactivated() |
|
144 | + { |
|
145 | + return $this->deactivate_plugin; |
|
146 | + } |
|
147 | + |
|
148 | + |
|
149 | + /** |
|
150 | + * @deprecated 4.9.53 |
|
151 | + * sets $deactivate_plugin to true |
|
152 | + */ |
|
153 | + public function deactivate_plugin() |
|
154 | + { |
|
155 | + $this->deactivate_plugin = true; |
|
156 | + } |
|
157 | 157 | } |
@@ -104,7 +104,7 @@ discard block |
||
104 | 104 | // what shortcode was actually parsed ? |
105 | 105 | $shortcode_class = get_called_class(); |
106 | 106 | // notify rest of system that fallback processor was triggered |
107 | - add_filter('FHEE__fallback_shortcode_processor__' . $shortcode_class, '__return_true'); |
|
107 | + add_filter('FHEE__fallback_shortcode_processor__'.$shortcode_class, '__return_true'); |
|
108 | 108 | // get instance of actual shortcode |
109 | 109 | $shortcode_obj = self::instance($shortcode_class); |
110 | 110 | // verify class |
@@ -159,13 +159,13 @@ discard block |
||
159 | 159 | { |
160 | 160 | foreach ($attributes as $key => $value) { |
161 | 161 | // is a custom sanitization callback specified ? |
162 | - if (isset($custom_sanitization[ $key ])) { |
|
163 | - $callback = $custom_sanitization[ $key ]; |
|
162 | + if (isset($custom_sanitization[$key])) { |
|
163 | + $callback = $custom_sanitization[$key]; |
|
164 | 164 | if ($callback === 'skip_sanitization') { |
165 | - $attributes[ $key ] = $value; |
|
165 | + $attributes[$key] = $value; |
|
166 | 166 | continue; |
167 | 167 | } elseif (function_exists($callback)) { |
168 | - $attributes[ $key ] = $callback($value); |
|
168 | + $attributes[$key] = $callback($value); |
|
169 | 169 | continue; |
170 | 170 | } |
171 | 171 | } |
@@ -175,18 +175,18 @@ discard block |
||
175 | 175 | case is_float($value): |
176 | 176 | // typical booleans |
177 | 177 | case in_array($value, array(true, 'true', '1', 'on', 'yes', false, 'false', '0', 'off', 'no'), true): |
178 | - $attributes[ $key ] = $value; |
|
178 | + $attributes[$key] = $value; |
|
179 | 179 | break; |
180 | 180 | case is_string($value): |
181 | - $attributes[ $key ] = sanitize_text_field($value); |
|
181 | + $attributes[$key] = sanitize_text_field($value); |
|
182 | 182 | break; |
183 | 183 | case is_array($value): |
184 | - $attributes[ $key ] = \EES_Shortcode::sanitize_attributes($value); |
|
184 | + $attributes[$key] = \EES_Shortcode::sanitize_attributes($value); |
|
185 | 185 | break; |
186 | 186 | default: |
187 | 187 | // only remaining data types are Object and Resource |
188 | 188 | // which are not allowed as shortcode attributes |
189 | - $attributes[ $key ] = null; |
|
189 | + $attributes[$key] = null; |
|
190 | 190 | break; |
191 | 191 | } |
192 | 192 | } |
@@ -14,186 +14,186 @@ |
||
14 | 14 | */ |
15 | 15 | abstract class EES_Shortcode extends EE_Base |
16 | 16 | { |
17 | - /** |
|
18 | - * @protected public |
|
19 | - * @var array $_attributes |
|
20 | - */ |
|
21 | - protected $_attributes = array(); |
|
22 | - |
|
23 | - |
|
24 | - |
|
25 | - /** |
|
26 | - * class constructor - should ONLY be instantiated by EE_Front_Controller |
|
27 | - */ |
|
28 | - final public function __construct() |
|
29 | - { |
|
30 | - $shortcode = LegacyShortcodesManager::generateShortcodeTagFromClassName(get_class($this)); |
|
31 | - // assign shortcode to the preferred callback, which overwrites the "fallback shortcode processor" assigned earlier |
|
32 | - add_shortcode($shortcode, array($this, 'process_shortcode')); |
|
33 | - // make sure system knows this is an EE page |
|
34 | - /** @var CurrentPage $current_page */ |
|
35 | - $current_page = LoaderFactory::getLoader()->getShared(CurrentPage::class); |
|
36 | - $current_page->setEspressoPage(true); |
|
37 | - } |
|
38 | - |
|
39 | - |
|
40 | - |
|
41 | - /** |
|
42 | - * run - initial shortcode module setup called during "parse_request" hook by |
|
43 | - * \EE_Front_Controller::_initialize_shortcodes() IF this shortcode is going to execute during this request ! |
|
44 | - * It may also get called by \EES_Shortcode::fallback_shortcode_processor() if the shortcode is being implemented |
|
45 | - * by a theme or plugin in a non-standard way. |
|
46 | - * Basically this method is primarily used for loading resources and assets like CSS or JS |
|
47 | - * that will be required by the shortcode when it is actually processed. |
|
48 | - * Please note that assets may not load if the fallback_shortcode_processor() is being used. |
|
49 | - * |
|
50 | - * @access public |
|
51 | - * @param WP $WP |
|
52 | - * @return void |
|
53 | - */ |
|
54 | - abstract public function run(WP $WP); |
|
55 | - |
|
56 | - |
|
57 | - |
|
58 | - /** |
|
59 | - * process_shortcode |
|
60 | - * this method is the callback function for the actual shortcode, and is what runs when WP encounters the shortcode within the_content |
|
61 | - * |
|
62 | - * @access public |
|
63 | - * @param array $attributes |
|
64 | - * @return mixed |
|
65 | - */ |
|
66 | - abstract public function process_shortcode($attributes = array()); |
|
67 | - |
|
68 | - |
|
69 | - |
|
70 | - /** |
|
71 | - * instance - returns instance of child class object |
|
72 | - * |
|
73 | - * @access public |
|
74 | - * @param string $shortcode_class |
|
75 | - * @return \EES_Shortcode |
|
76 | - */ |
|
77 | - final public static function instance($shortcode_class = null) |
|
78 | - { |
|
79 | - $shortcode_class = ! empty($shortcode_class) ? $shortcode_class : get_called_class(); |
|
80 | - if ($shortcode_class === 'EES_Shortcode' || empty($shortcode_class)) { |
|
81 | - return null; |
|
82 | - } |
|
83 | - $shortcode = str_replace('EES_', '', strtoupper($shortcode_class)); |
|
84 | - $shortcode_obj = isset(EE_Registry::instance()->shortcodes->{$shortcode}) |
|
85 | - ? EE_Registry::instance()->shortcodes->{$shortcode} |
|
86 | - : null; |
|
87 | - return $shortcode_obj instanceof $shortcode_class || $shortcode_class === 'self' |
|
88 | - ? $shortcode_obj |
|
89 | - : new $shortcode_class(); |
|
90 | - } |
|
91 | - |
|
92 | - |
|
93 | - |
|
94 | - |
|
95 | - /** |
|
96 | - * fallback_shortcode_processor - create instance and call process_shortcode |
|
97 | - * NOTE: shortcode may not function perfectly dues to missing assets, but it's better than not having things work at all |
|
98 | - * |
|
99 | - * @access public |
|
100 | - * @param $attributes |
|
101 | - * @return mixed |
|
102 | - */ |
|
103 | - final public static function fallback_shortcode_processor($attributes) |
|
104 | - { |
|
105 | - if (EE_Maintenance_Mode::disable_frontend_for_maintenance()) { |
|
106 | - return null; |
|
107 | - } |
|
108 | - // what shortcode was actually parsed ? |
|
109 | - $shortcode_class = get_called_class(); |
|
110 | - // notify rest of system that fallback processor was triggered |
|
111 | - add_filter('FHEE__fallback_shortcode_processor__' . $shortcode_class, '__return_true'); |
|
112 | - // get instance of actual shortcode |
|
113 | - $shortcode_obj = self::instance($shortcode_class); |
|
114 | - // verify class |
|
115 | - if ($shortcode_obj instanceof EES_Shortcode) { |
|
116 | - global $wp; |
|
117 | - $shortcode_obj->run($wp); |
|
118 | - // set attributes and run the shortcode |
|
119 | - $shortcode_obj->_attributes = (array) $attributes; |
|
120 | - return $shortcode_obj->process_shortcode($shortcode_obj->_attributes); |
|
121 | - } else { |
|
122 | - return null; |
|
123 | - } |
|
124 | - } |
|
125 | - |
|
126 | - |
|
127 | - |
|
128 | - |
|
129 | - /** |
|
130 | - * invalid_shortcode_processor - used in cases where we know the shortcode is invalid, most likely due to a deactivated addon, and simply returns an empty string |
|
131 | - * |
|
132 | - * @access public |
|
133 | - * @param $attributes |
|
134 | - * @return string |
|
135 | - */ |
|
136 | - final public static function invalid_shortcode_processor($attributes) |
|
137 | - { |
|
138 | - return ''; |
|
139 | - } |
|
140 | - |
|
141 | - |
|
142 | - |
|
143 | - |
|
144 | - |
|
145 | - /** |
|
146 | - * Performs basic sanitization on shortcode attributes |
|
147 | - * Since incoming attributes from the shortcode usage in the WP editor will all be strings, |
|
148 | - * most attributes will by default be sanitized using the sanitize_text_field() function. |
|
149 | - * This can be overridden by supplying an array for the $custom_sanitization param, |
|
150 | - * where keys match keys in your attributes array, |
|
151 | - * and values represent the sanitization function you wish to be applied to that attribute. |
|
152 | - * So for example, if you had an integer attribute named "event_id" |
|
153 | - * that you wanted to be sanitized using absint(), |
|
154 | - * then you would pass the following for your $custom_sanitization array: |
|
155 | - * array('event_id' => 'absint') |
|
156 | - * all other attributes would be sanitized using the defaults in the switch statement below |
|
157 | - * |
|
158 | - * @param array $attributes |
|
159 | - * @param array $custom_sanitization |
|
160 | - * @return array |
|
161 | - */ |
|
162 | - public static function sanitize_attributes(array $attributes, $custom_sanitization = array()) |
|
163 | - { |
|
164 | - foreach ($attributes as $key => $value) { |
|
165 | - // is a custom sanitization callback specified ? |
|
166 | - if (isset($custom_sanitization[ $key ])) { |
|
167 | - $callback = $custom_sanitization[ $key ]; |
|
168 | - if ($callback === 'skip_sanitization') { |
|
169 | - $attributes[ $key ] = $value; |
|
170 | - continue; |
|
171 | - } elseif (function_exists($callback)) { |
|
172 | - $attributes[ $key ] = $callback($value); |
|
173 | - continue; |
|
174 | - } |
|
175 | - } |
|
176 | - switch (true) { |
|
177 | - case $value === null: |
|
178 | - case is_int($value): |
|
179 | - case is_float($value): |
|
180 | - // typical booleans |
|
181 | - case in_array($value, array(true, 'true', '1', 'on', 'yes', false, 'false', '0', 'off', 'no'), true): |
|
182 | - $attributes[ $key ] = $value; |
|
183 | - break; |
|
184 | - case is_string($value): |
|
185 | - $attributes[ $key ] = sanitize_text_field($value); |
|
186 | - break; |
|
187 | - case is_array($value): |
|
188 | - $attributes[ $key ] = \EES_Shortcode::sanitize_attributes($value); |
|
189 | - break; |
|
190 | - default: |
|
191 | - // only remaining data types are Object and Resource |
|
192 | - // which are not allowed as shortcode attributes |
|
193 | - $attributes[ $key ] = null; |
|
194 | - break; |
|
195 | - } |
|
196 | - } |
|
197 | - return $attributes; |
|
198 | - } |
|
17 | + /** |
|
18 | + * @protected public |
|
19 | + * @var array $_attributes |
|
20 | + */ |
|
21 | + protected $_attributes = array(); |
|
22 | + |
|
23 | + |
|
24 | + |
|
25 | + /** |
|
26 | + * class constructor - should ONLY be instantiated by EE_Front_Controller |
|
27 | + */ |
|
28 | + final public function __construct() |
|
29 | + { |
|
30 | + $shortcode = LegacyShortcodesManager::generateShortcodeTagFromClassName(get_class($this)); |
|
31 | + // assign shortcode to the preferred callback, which overwrites the "fallback shortcode processor" assigned earlier |
|
32 | + add_shortcode($shortcode, array($this, 'process_shortcode')); |
|
33 | + // make sure system knows this is an EE page |
|
34 | + /** @var CurrentPage $current_page */ |
|
35 | + $current_page = LoaderFactory::getLoader()->getShared(CurrentPage::class); |
|
36 | + $current_page->setEspressoPage(true); |
|
37 | + } |
|
38 | + |
|
39 | + |
|
40 | + |
|
41 | + /** |
|
42 | + * run - initial shortcode module setup called during "parse_request" hook by |
|
43 | + * \EE_Front_Controller::_initialize_shortcodes() IF this shortcode is going to execute during this request ! |
|
44 | + * It may also get called by \EES_Shortcode::fallback_shortcode_processor() if the shortcode is being implemented |
|
45 | + * by a theme or plugin in a non-standard way. |
|
46 | + * Basically this method is primarily used for loading resources and assets like CSS or JS |
|
47 | + * that will be required by the shortcode when it is actually processed. |
|
48 | + * Please note that assets may not load if the fallback_shortcode_processor() is being used. |
|
49 | + * |
|
50 | + * @access public |
|
51 | + * @param WP $WP |
|
52 | + * @return void |
|
53 | + */ |
|
54 | + abstract public function run(WP $WP); |
|
55 | + |
|
56 | + |
|
57 | + |
|
58 | + /** |
|
59 | + * process_shortcode |
|
60 | + * this method is the callback function for the actual shortcode, and is what runs when WP encounters the shortcode within the_content |
|
61 | + * |
|
62 | + * @access public |
|
63 | + * @param array $attributes |
|
64 | + * @return mixed |
|
65 | + */ |
|
66 | + abstract public function process_shortcode($attributes = array()); |
|
67 | + |
|
68 | + |
|
69 | + |
|
70 | + /** |
|
71 | + * instance - returns instance of child class object |
|
72 | + * |
|
73 | + * @access public |
|
74 | + * @param string $shortcode_class |
|
75 | + * @return \EES_Shortcode |
|
76 | + */ |
|
77 | + final public static function instance($shortcode_class = null) |
|
78 | + { |
|
79 | + $shortcode_class = ! empty($shortcode_class) ? $shortcode_class : get_called_class(); |
|
80 | + if ($shortcode_class === 'EES_Shortcode' || empty($shortcode_class)) { |
|
81 | + return null; |
|
82 | + } |
|
83 | + $shortcode = str_replace('EES_', '', strtoupper($shortcode_class)); |
|
84 | + $shortcode_obj = isset(EE_Registry::instance()->shortcodes->{$shortcode}) |
|
85 | + ? EE_Registry::instance()->shortcodes->{$shortcode} |
|
86 | + : null; |
|
87 | + return $shortcode_obj instanceof $shortcode_class || $shortcode_class === 'self' |
|
88 | + ? $shortcode_obj |
|
89 | + : new $shortcode_class(); |
|
90 | + } |
|
91 | + |
|
92 | + |
|
93 | + |
|
94 | + |
|
95 | + /** |
|
96 | + * fallback_shortcode_processor - create instance and call process_shortcode |
|
97 | + * NOTE: shortcode may not function perfectly dues to missing assets, but it's better than not having things work at all |
|
98 | + * |
|
99 | + * @access public |
|
100 | + * @param $attributes |
|
101 | + * @return mixed |
|
102 | + */ |
|
103 | + final public static function fallback_shortcode_processor($attributes) |
|
104 | + { |
|
105 | + if (EE_Maintenance_Mode::disable_frontend_for_maintenance()) { |
|
106 | + return null; |
|
107 | + } |
|
108 | + // what shortcode was actually parsed ? |
|
109 | + $shortcode_class = get_called_class(); |
|
110 | + // notify rest of system that fallback processor was triggered |
|
111 | + add_filter('FHEE__fallback_shortcode_processor__' . $shortcode_class, '__return_true'); |
|
112 | + // get instance of actual shortcode |
|
113 | + $shortcode_obj = self::instance($shortcode_class); |
|
114 | + // verify class |
|
115 | + if ($shortcode_obj instanceof EES_Shortcode) { |
|
116 | + global $wp; |
|
117 | + $shortcode_obj->run($wp); |
|
118 | + // set attributes and run the shortcode |
|
119 | + $shortcode_obj->_attributes = (array) $attributes; |
|
120 | + return $shortcode_obj->process_shortcode($shortcode_obj->_attributes); |
|
121 | + } else { |
|
122 | + return null; |
|
123 | + } |
|
124 | + } |
|
125 | + |
|
126 | + |
|
127 | + |
|
128 | + |
|
129 | + /** |
|
130 | + * invalid_shortcode_processor - used in cases where we know the shortcode is invalid, most likely due to a deactivated addon, and simply returns an empty string |
|
131 | + * |
|
132 | + * @access public |
|
133 | + * @param $attributes |
|
134 | + * @return string |
|
135 | + */ |
|
136 | + final public static function invalid_shortcode_processor($attributes) |
|
137 | + { |
|
138 | + return ''; |
|
139 | + } |
|
140 | + |
|
141 | + |
|
142 | + |
|
143 | + |
|
144 | + |
|
145 | + /** |
|
146 | + * Performs basic sanitization on shortcode attributes |
|
147 | + * Since incoming attributes from the shortcode usage in the WP editor will all be strings, |
|
148 | + * most attributes will by default be sanitized using the sanitize_text_field() function. |
|
149 | + * This can be overridden by supplying an array for the $custom_sanitization param, |
|
150 | + * where keys match keys in your attributes array, |
|
151 | + * and values represent the sanitization function you wish to be applied to that attribute. |
|
152 | + * So for example, if you had an integer attribute named "event_id" |
|
153 | + * that you wanted to be sanitized using absint(), |
|
154 | + * then you would pass the following for your $custom_sanitization array: |
|
155 | + * array('event_id' => 'absint') |
|
156 | + * all other attributes would be sanitized using the defaults in the switch statement below |
|
157 | + * |
|
158 | + * @param array $attributes |
|
159 | + * @param array $custom_sanitization |
|
160 | + * @return array |
|
161 | + */ |
|
162 | + public static function sanitize_attributes(array $attributes, $custom_sanitization = array()) |
|
163 | + { |
|
164 | + foreach ($attributes as $key => $value) { |
|
165 | + // is a custom sanitization callback specified ? |
|
166 | + if (isset($custom_sanitization[ $key ])) { |
|
167 | + $callback = $custom_sanitization[ $key ]; |
|
168 | + if ($callback === 'skip_sanitization') { |
|
169 | + $attributes[ $key ] = $value; |
|
170 | + continue; |
|
171 | + } elseif (function_exists($callback)) { |
|
172 | + $attributes[ $key ] = $callback($value); |
|
173 | + continue; |
|
174 | + } |
|
175 | + } |
|
176 | + switch (true) { |
|
177 | + case $value === null: |
|
178 | + case is_int($value): |
|
179 | + case is_float($value): |
|
180 | + // typical booleans |
|
181 | + case in_array($value, array(true, 'true', '1', 'on', 'yes', false, 'false', '0', 'off', 'no'), true): |
|
182 | + $attributes[ $key ] = $value; |
|
183 | + break; |
|
184 | + case is_string($value): |
|
185 | + $attributes[ $key ] = sanitize_text_field($value); |
|
186 | + break; |
|
187 | + case is_array($value): |
|
188 | + $attributes[ $key ] = \EES_Shortcode::sanitize_attributes($value); |
|
189 | + break; |
|
190 | + default: |
|
191 | + // only remaining data types are Object and Resource |
|
192 | + // which are not allowed as shortcode attributes |
|
193 | + $attributes[ $key ] = null; |
|
194 | + break; |
|
195 | + } |
|
196 | + } |
|
197 | + return $attributes; |
|
198 | + } |
|
199 | 199 | } |
@@ -62,49 +62,49 @@ discard block |
||
62 | 62 | ); |
63 | 63 | $cpt_models = array_keys(EE_Registry::instance()->cpt_models()); |
64 | 64 | foreach ($cpt_models as $model_name) { |
65 | - $this->_model_relations[ $model_name ] = new EE_HABTM_Relation('Term_Relationship'); |
|
65 | + $this->_model_relations[$model_name] = new EE_HABTM_Relation('Term_Relationship'); |
|
66 | 66 | } |
67 | 67 | $this->_wp_core_model = true; |
68 | 68 | $this->_indexes = array( |
69 | 69 | 'term_id_taxonomy' => new EE_Unique_Index(array('term_id', 'taxonomy')), |
70 | 70 | ); |
71 | 71 | $path_to_tax_model = ''; |
72 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public(); |
|
73 | - $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Taxonomy_Protected( |
|
72 | + $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Public(); |
|
73 | + $this->_cap_restriction_generators[EEM_Base::caps_read_admin] = new EE_Restriction_Generator_Taxonomy_Protected( |
|
74 | 74 | $path_to_tax_model |
75 | 75 | ); |
76 | - $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = false; |
|
77 | - $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = false; |
|
76 | + $this->_cap_restriction_generators[EEM_Base::caps_edit] = false; |
|
77 | + $this->_cap_restriction_generators[EEM_Base::caps_delete] = false; |
|
78 | 78 | // add cap restrictions for editing relating to the "ee_edit_*" |
79 | - $this->_cap_restrictions[ EEM_Base::caps_edit ]['ee_edit_event_category'] = new EE_Default_Where_Conditions( |
|
79 | + $this->_cap_restrictions[EEM_Base::caps_edit]['ee_edit_event_category'] = new EE_Default_Where_Conditions( |
|
80 | 80 | array( |
81 | - $path_to_tax_model . 'taxonomy*ee_edit_event_category' => array('!=', 'espresso_event_categories'), |
|
81 | + $path_to_tax_model.'taxonomy*ee_edit_event_category' => array('!=', 'espresso_event_categories'), |
|
82 | 82 | ) |
83 | 83 | ); |
84 | - $this->_cap_restrictions[ EEM_Base::caps_edit ]['ee_edit_venue_category'] = new EE_Default_Where_Conditions( |
|
84 | + $this->_cap_restrictions[EEM_Base::caps_edit]['ee_edit_venue_category'] = new EE_Default_Where_Conditions( |
|
85 | 85 | array( |
86 | - $path_to_tax_model . 'taxonomy*ee_edit_venue_category' => array('!=', 'espresso_venue_categories'), |
|
86 | + $path_to_tax_model.'taxonomy*ee_edit_venue_category' => array('!=', 'espresso_venue_categories'), |
|
87 | 87 | ) |
88 | 88 | ); |
89 | - $this->_cap_restrictions[ EEM_Base::caps_edit ]['ee_edit_event_type'] = new EE_Default_Where_Conditions( |
|
89 | + $this->_cap_restrictions[EEM_Base::caps_edit]['ee_edit_event_type'] = new EE_Default_Where_Conditions( |
|
90 | 90 | array( |
91 | - $path_to_tax_model . 'taxonomy*ee_edit_event_type' => array('!=', 'espresso_event_type'), |
|
91 | + $path_to_tax_model.'taxonomy*ee_edit_event_type' => array('!=', 'espresso_event_type'), |
|
92 | 92 | ) |
93 | 93 | ); |
94 | 94 | // add cap restrictions for deleting relating to the "ee_deleting_*" |
95 | - $this->_cap_restrictions[ EEM_Base::caps_delete ]['ee_delete_event_category'] = new EE_Default_Where_Conditions( |
|
95 | + $this->_cap_restrictions[EEM_Base::caps_delete]['ee_delete_event_category'] = new EE_Default_Where_Conditions( |
|
96 | 96 | array( |
97 | - $path_to_tax_model . 'taxonomy*ee_delete_event_category' => array('!=', 'espresso_event_categories'), |
|
97 | + $path_to_tax_model.'taxonomy*ee_delete_event_category' => array('!=', 'espresso_event_categories'), |
|
98 | 98 | ) |
99 | 99 | ); |
100 | - $this->_cap_restrictions[ EEM_Base::caps_delete ]['ee_delete_venue_category'] = new EE_Default_Where_Conditions( |
|
100 | + $this->_cap_restrictions[EEM_Base::caps_delete]['ee_delete_venue_category'] = new EE_Default_Where_Conditions( |
|
101 | 101 | array( |
102 | - $path_to_tax_model . 'taxonomy*ee_delete_venue_category' => array('!=', 'espresso_venue_categories'), |
|
102 | + $path_to_tax_model.'taxonomy*ee_delete_venue_category' => array('!=', 'espresso_venue_categories'), |
|
103 | 103 | ) |
104 | 104 | ); |
105 | - $this->_cap_restrictions[ EEM_Base::caps_delete ]['ee_delete_event_type'] = new EE_Default_Where_Conditions( |
|
105 | + $this->_cap_restrictions[EEM_Base::caps_delete]['ee_delete_event_type'] = new EE_Default_Where_Conditions( |
|
106 | 106 | array( |
107 | - $path_to_tax_model . 'taxonomy*ee_delete_event_type' => array('!=', 'espresso_event_type'), |
|
107 | + $path_to_tax_model.'taxonomy*ee_delete_event_type' => array('!=', 'espresso_event_type'), |
|
108 | 108 | ) |
109 | 109 | ); |
110 | 110 | parent::__construct($timezone); |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | { |
127 | 127 | if ($model === EEM_Term_Taxonomy::instance()) { |
128 | 128 | $taxonomies = get_taxonomies(array('show_in_rest' => true)); |
129 | - if (! empty($taxonomies)) { |
|
129 | + if ( ! empty($taxonomies)) { |
|
130 | 130 | $model_query_params[0]['taxonomy'] = array('IN', $taxonomies); |
131 | 131 | } |
132 | 132 | } |
@@ -10,128 +10,128 @@ |
||
10 | 10 | */ |
11 | 11 | class EEM_Term_Taxonomy extends EEM_Base |
12 | 12 | { |
13 | - // private instance of the Attendee object |
|
14 | - protected static $_instance = null; |
|
13 | + // private instance of the Attendee object |
|
14 | + protected static $_instance = null; |
|
15 | 15 | |
16 | 16 | |
17 | 17 | |
18 | - protected function __construct($timezone = null) |
|
19 | - { |
|
20 | - $this->singular_item = esc_html__('Term Taxonomy', 'event_espresso'); |
|
21 | - $this->plural_item = esc_html__('Term Taxonomy', 'event_espresso'); |
|
22 | - $this->_tables = array( |
|
23 | - 'Term_Taxonomy' => new EE_Primary_Table('term_taxonomy', 'term_taxonomy_id'), |
|
24 | - ); |
|
25 | - $this->_fields = array( |
|
26 | - 'Term_Taxonomy' => array( |
|
27 | - 'term_taxonomy_id' => new EE_Primary_Key_Int_Field( |
|
28 | - 'term_taxonomy_id', |
|
29 | - esc_html__('Term-Taxonomy ID', 'event_espresso') |
|
30 | - ), |
|
31 | - 'term_id' => new EE_Foreign_Key_Int_Field( |
|
32 | - 'term_id', |
|
33 | - esc_html__("Term Id", "event_espresso"), |
|
34 | - false, |
|
35 | - 0, |
|
36 | - 'Term' |
|
37 | - ), |
|
38 | - 'taxonomy' => new EE_Plain_Text_Field( |
|
39 | - 'taxonomy', |
|
40 | - esc_html__('Taxonomy Name', 'event_espresso'), |
|
41 | - false, |
|
42 | - 'category' |
|
43 | - ), |
|
44 | - 'description' => new EE_Post_Content_Field( |
|
45 | - 'description', |
|
46 | - esc_html__("Description of Term", "event_espresso"), |
|
47 | - false, |
|
48 | - '' |
|
49 | - ), |
|
50 | - 'parent' => new EE_Integer_Field('parent', esc_html__("Parent Term ID", "event_espresso"), false, 0), |
|
51 | - 'term_count' => new EE_Integer_Field( |
|
52 | - 'count', |
|
53 | - esc_html__("Count of Objects attached", 'event_espresso'), |
|
54 | - false, |
|
55 | - 0 |
|
56 | - ), |
|
57 | - ), |
|
58 | - ); |
|
59 | - $this->_model_relations = array( |
|
60 | - 'Term_Relationship' => new EE_Has_Many_Relation(), |
|
61 | - 'Term' => new EE_Belongs_To_Relation(), |
|
62 | - ); |
|
63 | - $cpt_models = array_keys(EE_Registry::instance()->cpt_models()); |
|
64 | - foreach ($cpt_models as $model_name) { |
|
65 | - $this->_model_relations[ $model_name ] = new EE_HABTM_Relation('Term_Relationship'); |
|
66 | - } |
|
67 | - $this->_wp_core_model = true; |
|
68 | - $this->_indexes = array( |
|
69 | - 'term_id_taxonomy' => new EE_Unique_Index(array('term_id', 'taxonomy')), |
|
70 | - ); |
|
71 | - $path_to_tax_model = ''; |
|
72 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public(); |
|
73 | - $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Taxonomy_Protected( |
|
74 | - $path_to_tax_model |
|
75 | - ); |
|
76 | - $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = false; |
|
77 | - $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = false; |
|
78 | - // add cap restrictions for editing relating to the "ee_edit_*" |
|
79 | - $this->_cap_restrictions[ EEM_Base::caps_edit ]['ee_edit_event_category'] = new EE_Default_Where_Conditions( |
|
80 | - array( |
|
81 | - $path_to_tax_model . 'taxonomy*ee_edit_event_category' => array('!=', 'espresso_event_categories'), |
|
82 | - ) |
|
83 | - ); |
|
84 | - $this->_cap_restrictions[ EEM_Base::caps_edit ]['ee_edit_venue_category'] = new EE_Default_Where_Conditions( |
|
85 | - array( |
|
86 | - $path_to_tax_model . 'taxonomy*ee_edit_venue_category' => array('!=', 'espresso_venue_categories'), |
|
87 | - ) |
|
88 | - ); |
|
89 | - $this->_cap_restrictions[ EEM_Base::caps_edit ]['ee_edit_event_type'] = new EE_Default_Where_Conditions( |
|
90 | - array( |
|
91 | - $path_to_tax_model . 'taxonomy*ee_edit_event_type' => array('!=', 'espresso_event_type'), |
|
92 | - ) |
|
93 | - ); |
|
94 | - // add cap restrictions for deleting relating to the "ee_deleting_*" |
|
95 | - $this->_cap_restrictions[ EEM_Base::caps_delete ]['ee_delete_event_category'] = new EE_Default_Where_Conditions( |
|
96 | - array( |
|
97 | - $path_to_tax_model . 'taxonomy*ee_delete_event_category' => array('!=', 'espresso_event_categories'), |
|
98 | - ) |
|
99 | - ); |
|
100 | - $this->_cap_restrictions[ EEM_Base::caps_delete ]['ee_delete_venue_category'] = new EE_Default_Where_Conditions( |
|
101 | - array( |
|
102 | - $path_to_tax_model . 'taxonomy*ee_delete_venue_category' => array('!=', 'espresso_venue_categories'), |
|
103 | - ) |
|
104 | - ); |
|
105 | - $this->_cap_restrictions[ EEM_Base::caps_delete ]['ee_delete_event_type'] = new EE_Default_Where_Conditions( |
|
106 | - array( |
|
107 | - $path_to_tax_model . 'taxonomy*ee_delete_event_type' => array('!=', 'espresso_event_type'), |
|
108 | - ) |
|
109 | - ); |
|
110 | - parent::__construct($timezone); |
|
111 | - add_filter('FHEE__Read__create_model_query_params', array('EEM_Term_Taxonomy', 'rest_api_query_params'), 10, 3); |
|
112 | - } |
|
18 | + protected function __construct($timezone = null) |
|
19 | + { |
|
20 | + $this->singular_item = esc_html__('Term Taxonomy', 'event_espresso'); |
|
21 | + $this->plural_item = esc_html__('Term Taxonomy', 'event_espresso'); |
|
22 | + $this->_tables = array( |
|
23 | + 'Term_Taxonomy' => new EE_Primary_Table('term_taxonomy', 'term_taxonomy_id'), |
|
24 | + ); |
|
25 | + $this->_fields = array( |
|
26 | + 'Term_Taxonomy' => array( |
|
27 | + 'term_taxonomy_id' => new EE_Primary_Key_Int_Field( |
|
28 | + 'term_taxonomy_id', |
|
29 | + esc_html__('Term-Taxonomy ID', 'event_espresso') |
|
30 | + ), |
|
31 | + 'term_id' => new EE_Foreign_Key_Int_Field( |
|
32 | + 'term_id', |
|
33 | + esc_html__("Term Id", "event_espresso"), |
|
34 | + false, |
|
35 | + 0, |
|
36 | + 'Term' |
|
37 | + ), |
|
38 | + 'taxonomy' => new EE_Plain_Text_Field( |
|
39 | + 'taxonomy', |
|
40 | + esc_html__('Taxonomy Name', 'event_espresso'), |
|
41 | + false, |
|
42 | + 'category' |
|
43 | + ), |
|
44 | + 'description' => new EE_Post_Content_Field( |
|
45 | + 'description', |
|
46 | + esc_html__("Description of Term", "event_espresso"), |
|
47 | + false, |
|
48 | + '' |
|
49 | + ), |
|
50 | + 'parent' => new EE_Integer_Field('parent', esc_html__("Parent Term ID", "event_espresso"), false, 0), |
|
51 | + 'term_count' => new EE_Integer_Field( |
|
52 | + 'count', |
|
53 | + esc_html__("Count of Objects attached", 'event_espresso'), |
|
54 | + false, |
|
55 | + 0 |
|
56 | + ), |
|
57 | + ), |
|
58 | + ); |
|
59 | + $this->_model_relations = array( |
|
60 | + 'Term_Relationship' => new EE_Has_Many_Relation(), |
|
61 | + 'Term' => new EE_Belongs_To_Relation(), |
|
62 | + ); |
|
63 | + $cpt_models = array_keys(EE_Registry::instance()->cpt_models()); |
|
64 | + foreach ($cpt_models as $model_name) { |
|
65 | + $this->_model_relations[ $model_name ] = new EE_HABTM_Relation('Term_Relationship'); |
|
66 | + } |
|
67 | + $this->_wp_core_model = true; |
|
68 | + $this->_indexes = array( |
|
69 | + 'term_id_taxonomy' => new EE_Unique_Index(array('term_id', 'taxonomy')), |
|
70 | + ); |
|
71 | + $path_to_tax_model = ''; |
|
72 | + $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public(); |
|
73 | + $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Taxonomy_Protected( |
|
74 | + $path_to_tax_model |
|
75 | + ); |
|
76 | + $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = false; |
|
77 | + $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = false; |
|
78 | + // add cap restrictions for editing relating to the "ee_edit_*" |
|
79 | + $this->_cap_restrictions[ EEM_Base::caps_edit ]['ee_edit_event_category'] = new EE_Default_Where_Conditions( |
|
80 | + array( |
|
81 | + $path_to_tax_model . 'taxonomy*ee_edit_event_category' => array('!=', 'espresso_event_categories'), |
|
82 | + ) |
|
83 | + ); |
|
84 | + $this->_cap_restrictions[ EEM_Base::caps_edit ]['ee_edit_venue_category'] = new EE_Default_Where_Conditions( |
|
85 | + array( |
|
86 | + $path_to_tax_model . 'taxonomy*ee_edit_venue_category' => array('!=', 'espresso_venue_categories'), |
|
87 | + ) |
|
88 | + ); |
|
89 | + $this->_cap_restrictions[ EEM_Base::caps_edit ]['ee_edit_event_type'] = new EE_Default_Where_Conditions( |
|
90 | + array( |
|
91 | + $path_to_tax_model . 'taxonomy*ee_edit_event_type' => array('!=', 'espresso_event_type'), |
|
92 | + ) |
|
93 | + ); |
|
94 | + // add cap restrictions for deleting relating to the "ee_deleting_*" |
|
95 | + $this->_cap_restrictions[ EEM_Base::caps_delete ]['ee_delete_event_category'] = new EE_Default_Where_Conditions( |
|
96 | + array( |
|
97 | + $path_to_tax_model . 'taxonomy*ee_delete_event_category' => array('!=', 'espresso_event_categories'), |
|
98 | + ) |
|
99 | + ); |
|
100 | + $this->_cap_restrictions[ EEM_Base::caps_delete ]['ee_delete_venue_category'] = new EE_Default_Where_Conditions( |
|
101 | + array( |
|
102 | + $path_to_tax_model . 'taxonomy*ee_delete_venue_category' => array('!=', 'espresso_venue_categories'), |
|
103 | + ) |
|
104 | + ); |
|
105 | + $this->_cap_restrictions[ EEM_Base::caps_delete ]['ee_delete_event_type'] = new EE_Default_Where_Conditions( |
|
106 | + array( |
|
107 | + $path_to_tax_model . 'taxonomy*ee_delete_event_type' => array('!=', 'espresso_event_type'), |
|
108 | + ) |
|
109 | + ); |
|
110 | + parent::__construct($timezone); |
|
111 | + add_filter('FHEE__Read__create_model_query_params', array('EEM_Term_Taxonomy', 'rest_api_query_params'), 10, 3); |
|
112 | + } |
|
113 | 113 | |
114 | 114 | |
115 | 115 | |
116 | - /** |
|
117 | - * Makes sure that during REST API queries, we only return term-taxonomies |
|
118 | - * for term taxonomies which should be shown in the rest api |
|
119 | - * |
|
120 | - * @param array $model_query_params |
|
121 | - * @param array $querystring_query_params |
|
122 | - * @param EEM_Base $model |
|
123 | - * @return array |
|
124 | - */ |
|
125 | - public static function rest_api_query_params($model_query_params, $querystring_query_params, $model) |
|
126 | - { |
|
127 | - if ($model === EEM_Term_Taxonomy::instance()) { |
|
128 | - $taxonomies = get_taxonomies(array('show_in_rest' => true)); |
|
129 | - if (! empty($taxonomies)) { |
|
130 | - $model_query_params[0]['taxonomy'] = array('IN', $taxonomies); |
|
131 | - } |
|
132 | - } |
|
133 | - return $model_query_params; |
|
134 | - } |
|
116 | + /** |
|
117 | + * Makes sure that during REST API queries, we only return term-taxonomies |
|
118 | + * for term taxonomies which should be shown in the rest api |
|
119 | + * |
|
120 | + * @param array $model_query_params |
|
121 | + * @param array $querystring_query_params |
|
122 | + * @param EEM_Base $model |
|
123 | + * @return array |
|
124 | + */ |
|
125 | + public static function rest_api_query_params($model_query_params, $querystring_query_params, $model) |
|
126 | + { |
|
127 | + if ($model === EEM_Term_Taxonomy::instance()) { |
|
128 | + $taxonomies = get_taxonomies(array('show_in_rest' => true)); |
|
129 | + if (! empty($taxonomies)) { |
|
130 | + $model_query_params[0]['taxonomy'] = array('IN', $taxonomies); |
|
131 | + } |
|
132 | + } |
|
133 | + return $model_query_params; |
|
134 | + } |
|
135 | 135 | } |
136 | 136 | // End of file EEM_Term_Taxonomy.model.php |
137 | 137 | // Location: /includes/models/EEM_Term_Taxonomy.model.php |
@@ -113,17 +113,17 @@ discard block |
||
113 | 113 | ), |
114 | 114 | ), |
115 | 115 | ); |
116 | - $this->_model_relations = array(); |
|
116 | + $this->_model_relations = array(); |
|
117 | 117 | foreach ($models_this_can_attach_to as $model) { |
118 | 118 | if ($model != 'Change_Log') { |
119 | - $this->_model_relations[ $model ] = new EE_Belongs_To_Any_Relation(); |
|
119 | + $this->_model_relations[$model] = new EE_Belongs_To_Any_Relation(); |
|
120 | 120 | } |
121 | 121 | } |
122 | 122 | // use completely custom caps for this |
123 | 123 | $this->_cap_restriction_generators = false; |
124 | 124 | // caps-wise this is all-or-nothing: if you have the default role you can access anything, otherwise nothing |
125 | 125 | foreach ($this->_cap_contexts_to_cap_action_map as $cap_context => $action) { |
126 | - $this->_cap_restrictions[ $cap_context ][ EE_Restriction_Generator_Base::get_default_restrictions_cap() ] |
|
126 | + $this->_cap_restrictions[$cap_context][EE_Restriction_Generator_Base::get_default_restrictions_cap()] |
|
127 | 127 | = new EE_Return_None_Where_Conditions(); |
128 | 128 | } |
129 | 129 | parent::__construct($timezone); |
@@ -168,7 +168,7 @@ discard block |
||
168 | 168 | */ |
169 | 169 | public function gateway_log($message, $related_obj_id, $related_obj_type) |
170 | 170 | { |
171 | - if (! EE_Registry::instance()->is_model_name($related_obj_type)) { |
|
171 | + if ( ! EE_Registry::instance()->is_model_name($related_obj_type)) { |
|
172 | 172 | throw new EE_Error( |
173 | 173 | sprintf( |
174 | 174 | esc_html__( |
@@ -217,7 +217,7 @@ discard block |
||
217 | 217 | global $wpdb; |
218 | 218 | return $wpdb->query( |
219 | 219 | $wpdb->prepare( |
220 | - 'DELETE FROM ' . $this->table() . ' WHERE LOG_type = %s AND LOG_time < %s', |
|
220 | + 'DELETE FROM '.$this->table().' WHERE LOG_type = %s AND LOG_time < %s', |
|
221 | 221 | EEM_Change_Log::type_gateway, |
222 | 222 | $datetime->format(EE_Datetime_Field::mysql_timestamp_format) |
223 | 223 | ) |
@@ -256,8 +256,8 @@ discard block |
||
256 | 256 | { |
257 | 257 | $type_identifier_map = self::get_pretty_label_map_for_registered_types(); |
258 | 258 | // we fallback to the incoming type identifier if there is no localized label for it. |
259 | - return isset($type_identifier_map[ $type_identifier ]) |
|
260 | - ? $type_identifier_map[ $type_identifier ] |
|
259 | + return isset($type_identifier_map[$type_identifier]) |
|
260 | + ? $type_identifier_map[$type_identifier] |
|
261 | 261 | : $type_identifier; |
262 | 262 | } |
263 | 263 | } |
@@ -10,93 +10,93 @@ discard block |
||
10 | 10 | */ |
11 | 11 | class EEM_Change_Log extends EEM_Base |
12 | 12 | { |
13 | - /** |
|
14 | - * the related object was created log type |
|
15 | - */ |
|
16 | - const type_create = 'create'; |
|
17 | - /** |
|
18 | - * the related object was updated (changed, or soft-deleted) |
|
19 | - */ |
|
20 | - const type_update = 'update'; |
|
21 | - /** |
|
22 | - * the related object was deleted permanently |
|
23 | - */ |
|
24 | - const type_delete = 'delete'; |
|
25 | - /** |
|
26 | - * the related item had something worth noting happen on it, but |
|
27 | - * only for the purposes of debugging problems |
|
28 | - */ |
|
29 | - const type_debug = 'debug'; |
|
30 | - /** |
|
31 | - * the related item had an error occur on it |
|
32 | - */ |
|
33 | - const type_error = 'error'; |
|
34 | - /** |
|
35 | - * the related item is regarding some gateway interaction, like an IPN |
|
36 | - * or request to process a payment |
|
37 | - */ |
|
38 | - const type_gateway = 'gateway'; |
|
13 | + /** |
|
14 | + * the related object was created log type |
|
15 | + */ |
|
16 | + const type_create = 'create'; |
|
17 | + /** |
|
18 | + * the related object was updated (changed, or soft-deleted) |
|
19 | + */ |
|
20 | + const type_update = 'update'; |
|
21 | + /** |
|
22 | + * the related object was deleted permanently |
|
23 | + */ |
|
24 | + const type_delete = 'delete'; |
|
25 | + /** |
|
26 | + * the related item had something worth noting happen on it, but |
|
27 | + * only for the purposes of debugging problems |
|
28 | + */ |
|
29 | + const type_debug = 'debug'; |
|
30 | + /** |
|
31 | + * the related item had an error occur on it |
|
32 | + */ |
|
33 | + const type_error = 'error'; |
|
34 | + /** |
|
35 | + * the related item is regarding some gateway interaction, like an IPN |
|
36 | + * or request to process a payment |
|
37 | + */ |
|
38 | + const type_gateway = 'gateway'; |
|
39 | 39 | |
40 | - /** |
|
41 | - * private instance of the EEM_Change_Log object |
|
42 | - * |
|
43 | - * @access private |
|
44 | - * @var EEM_Change_Log $_instance |
|
45 | - */ |
|
46 | - protected static $_instance = null; |
|
40 | + /** |
|
41 | + * private instance of the EEM_Change_Log object |
|
42 | + * |
|
43 | + * @access private |
|
44 | + * @var EEM_Change_Log $_instance |
|
45 | + */ |
|
46 | + protected static $_instance = null; |
|
47 | 47 | |
48 | 48 | |
49 | - /** |
|
50 | - * constructor |
|
51 | - * |
|
52 | - * @access protected |
|
53 | - * @param null $timezone |
|
54 | - * @throws EE_Error |
|
55 | - */ |
|
56 | - protected function __construct($timezone = null) |
|
57 | - { |
|
58 | - global $current_user; |
|
59 | - $this->singular_item = esc_html__('Log', 'event_espresso'); |
|
60 | - $this->plural_item = esc_html__('Logs', 'event_espresso'); |
|
61 | - $this->_tables = array( |
|
62 | - 'Log' => new EE_Primary_Table('esp_log', 'LOG_ID'), |
|
63 | - ); |
|
64 | - $models_this_can_attach_to = array_keys(EE_Registry::instance()->non_abstract_db_models); |
|
65 | - $this->_fields = array( |
|
66 | - 'Log' => array( |
|
67 | - 'LOG_ID' => new EE_Primary_Key_Int_Field('LOG_ID', esc_html__('Log ID', 'event_espresso')), |
|
68 | - 'LOG_time' => new EE_Datetime_Field( |
|
69 | - 'LOG_time', |
|
70 | - esc_html__("Log Time", 'event_espresso'), |
|
71 | - false, |
|
72 | - EE_Datetime_Field::now |
|
73 | - ), |
|
74 | - 'OBJ_ID' => new EE_Foreign_Key_String_Field( |
|
75 | - 'OBJ_ID', |
|
76 | - esc_html__("Object ID (int or string)", 'event_espresso'), |
|
77 | - true, |
|
78 | - null, |
|
79 | - $models_this_can_attach_to |
|
80 | - ), |
|
81 | - 'OBJ_type' => new EE_Any_Foreign_Model_Name_Field( |
|
82 | - 'OBJ_type', |
|
83 | - esc_html__("Object Type", 'event_espresso'), |
|
84 | - true, |
|
85 | - null, |
|
86 | - $models_this_can_attach_to |
|
87 | - ), |
|
88 | - 'LOG_type' => new EE_Plain_Text_Field( |
|
89 | - 'LOG_type', |
|
90 | - esc_html__("Type of log entry", "event_espresso"), |
|
91 | - false, |
|
92 | - self::type_debug |
|
93 | - ), |
|
94 | - 'LOG_message' => new EE_Maybe_Serialized_Text_Field( |
|
95 | - 'LOG_message', |
|
96 | - esc_html__("Log Message (body)", 'event_espresso'), |
|
97 | - true |
|
98 | - ), |
|
99 | - /* |
|
49 | + /** |
|
50 | + * constructor |
|
51 | + * |
|
52 | + * @access protected |
|
53 | + * @param null $timezone |
|
54 | + * @throws EE_Error |
|
55 | + */ |
|
56 | + protected function __construct($timezone = null) |
|
57 | + { |
|
58 | + global $current_user; |
|
59 | + $this->singular_item = esc_html__('Log', 'event_espresso'); |
|
60 | + $this->plural_item = esc_html__('Logs', 'event_espresso'); |
|
61 | + $this->_tables = array( |
|
62 | + 'Log' => new EE_Primary_Table('esp_log', 'LOG_ID'), |
|
63 | + ); |
|
64 | + $models_this_can_attach_to = array_keys(EE_Registry::instance()->non_abstract_db_models); |
|
65 | + $this->_fields = array( |
|
66 | + 'Log' => array( |
|
67 | + 'LOG_ID' => new EE_Primary_Key_Int_Field('LOG_ID', esc_html__('Log ID', 'event_espresso')), |
|
68 | + 'LOG_time' => new EE_Datetime_Field( |
|
69 | + 'LOG_time', |
|
70 | + esc_html__("Log Time", 'event_espresso'), |
|
71 | + false, |
|
72 | + EE_Datetime_Field::now |
|
73 | + ), |
|
74 | + 'OBJ_ID' => new EE_Foreign_Key_String_Field( |
|
75 | + 'OBJ_ID', |
|
76 | + esc_html__("Object ID (int or string)", 'event_espresso'), |
|
77 | + true, |
|
78 | + null, |
|
79 | + $models_this_can_attach_to |
|
80 | + ), |
|
81 | + 'OBJ_type' => new EE_Any_Foreign_Model_Name_Field( |
|
82 | + 'OBJ_type', |
|
83 | + esc_html__("Object Type", 'event_espresso'), |
|
84 | + true, |
|
85 | + null, |
|
86 | + $models_this_can_attach_to |
|
87 | + ), |
|
88 | + 'LOG_type' => new EE_Plain_Text_Field( |
|
89 | + 'LOG_type', |
|
90 | + esc_html__("Type of log entry", "event_espresso"), |
|
91 | + false, |
|
92 | + self::type_debug |
|
93 | + ), |
|
94 | + 'LOG_message' => new EE_Maybe_Serialized_Text_Field( |
|
95 | + 'LOG_message', |
|
96 | + esc_html__("Log Message (body)", 'event_espresso'), |
|
97 | + true |
|
98 | + ), |
|
99 | + /* |
|
100 | 100 | * Note: when querying for a change log's user, the OBJ_ID and OBJ_type fields are used, |
101 | 101 | * not the LOG_wp_user field. E.g., |
102 | 102 | * `EEM_Change_Log::instance()->get_all(array(array('WP_User.ID'=>1)))` will actually return |
@@ -105,158 +105,158 @@ discard block |
||
105 | 105 | * If you want the latter, you can't use the model's magic joining. E.g, you would need to do |
106 | 106 | * `EEM_Change_Log::instance()->get_all(array(array('LOG_wp_user' => 1)))`. |
107 | 107 | */ |
108 | - 'LOG_wp_user' => new EE_WP_User_Field( |
|
109 | - 'LOG_wp_user', |
|
110 | - esc_html__("User who was logged in while this occurred", 'event_espresso'), |
|
111 | - true |
|
112 | - ), |
|
113 | - ), |
|
114 | - ); |
|
115 | - $this->_model_relations = array(); |
|
116 | - foreach ($models_this_can_attach_to as $model) { |
|
117 | - if ($model != 'Change_Log') { |
|
118 | - $this->_model_relations[ $model ] = new EE_Belongs_To_Any_Relation(); |
|
119 | - } |
|
120 | - } |
|
121 | - // use completely custom caps for this |
|
122 | - $this->_cap_restriction_generators = false; |
|
123 | - // caps-wise this is all-or-nothing: if you have the default role you can access anything, otherwise nothing |
|
124 | - foreach ($this->_cap_contexts_to_cap_action_map as $cap_context => $action) { |
|
125 | - $this->_cap_restrictions[ $cap_context ][ EE_Restriction_Generator_Base::get_default_restrictions_cap() ] |
|
126 | - = new EE_Return_None_Where_Conditions(); |
|
127 | - } |
|
128 | - parent::__construct($timezone); |
|
129 | - } |
|
108 | + 'LOG_wp_user' => new EE_WP_User_Field( |
|
109 | + 'LOG_wp_user', |
|
110 | + esc_html__("User who was logged in while this occurred", 'event_espresso'), |
|
111 | + true |
|
112 | + ), |
|
113 | + ), |
|
114 | + ); |
|
115 | + $this->_model_relations = array(); |
|
116 | + foreach ($models_this_can_attach_to as $model) { |
|
117 | + if ($model != 'Change_Log') { |
|
118 | + $this->_model_relations[ $model ] = new EE_Belongs_To_Any_Relation(); |
|
119 | + } |
|
120 | + } |
|
121 | + // use completely custom caps for this |
|
122 | + $this->_cap_restriction_generators = false; |
|
123 | + // caps-wise this is all-or-nothing: if you have the default role you can access anything, otherwise nothing |
|
124 | + foreach ($this->_cap_contexts_to_cap_action_map as $cap_context => $action) { |
|
125 | + $this->_cap_restrictions[ $cap_context ][ EE_Restriction_Generator_Base::get_default_restrictions_cap() ] |
|
126 | + = new EE_Return_None_Where_Conditions(); |
|
127 | + } |
|
128 | + parent::__construct($timezone); |
|
129 | + } |
|
130 | 130 | |
131 | - /** |
|
132 | - * @param string $log_type !see the acceptable values of LOG_type in EEM__Change_Log::__construct |
|
133 | - * @param mixed $message array|string of the message you want to record |
|
134 | - * @param EE_Base_Class $related_model_obj |
|
135 | - * @return EE_Change_Log |
|
136 | - * @throws EE_Error |
|
137 | - */ |
|
138 | - public function log($log_type, $message, $related_model_obj) |
|
139 | - { |
|
140 | - if ($related_model_obj instanceof EE_Base_Class) { |
|
141 | - $obj_id = $related_model_obj->ID(); |
|
142 | - $obj_type = $related_model_obj->get_model()->get_this_model_name(); |
|
143 | - } else { |
|
144 | - $obj_id = null; |
|
145 | - $obj_type = null; |
|
146 | - } |
|
147 | - /** @var EE_Change_Log $log */ |
|
148 | - $log = EE_Change_Log::new_instance(array( |
|
149 | - 'LOG_type' => $log_type, |
|
150 | - 'LOG_message' => $message, |
|
151 | - 'OBJ_ID' => $obj_id, |
|
152 | - 'OBJ_type' => $obj_type, |
|
153 | - )); |
|
154 | - $log->save(); |
|
155 | - return $log; |
|
156 | - } |
|
131 | + /** |
|
132 | + * @param string $log_type !see the acceptable values of LOG_type in EEM__Change_Log::__construct |
|
133 | + * @param mixed $message array|string of the message you want to record |
|
134 | + * @param EE_Base_Class $related_model_obj |
|
135 | + * @return EE_Change_Log |
|
136 | + * @throws EE_Error |
|
137 | + */ |
|
138 | + public function log($log_type, $message, $related_model_obj) |
|
139 | + { |
|
140 | + if ($related_model_obj instanceof EE_Base_Class) { |
|
141 | + $obj_id = $related_model_obj->ID(); |
|
142 | + $obj_type = $related_model_obj->get_model()->get_this_model_name(); |
|
143 | + } else { |
|
144 | + $obj_id = null; |
|
145 | + $obj_type = null; |
|
146 | + } |
|
147 | + /** @var EE_Change_Log $log */ |
|
148 | + $log = EE_Change_Log::new_instance(array( |
|
149 | + 'LOG_type' => $log_type, |
|
150 | + 'LOG_message' => $message, |
|
151 | + 'OBJ_ID' => $obj_id, |
|
152 | + 'OBJ_type' => $obj_type, |
|
153 | + )); |
|
154 | + $log->save(); |
|
155 | + return $log; |
|
156 | + } |
|
157 | 157 | |
158 | 158 | |
159 | - /** |
|
160 | - * Adds a gateway log for the specified object, given its ID and type |
|
161 | - * |
|
162 | - * @param string $message |
|
163 | - * @param mixed $related_obj_id |
|
164 | - * @param string $related_obj_type |
|
165 | - * @throws EE_Error |
|
166 | - * @return EE_Change_Log |
|
167 | - */ |
|
168 | - public function gateway_log($message, $related_obj_id, $related_obj_type) |
|
169 | - { |
|
170 | - if (! EE_Registry::instance()->is_model_name($related_obj_type)) { |
|
171 | - throw new EE_Error( |
|
172 | - sprintf( |
|
173 | - esc_html__( |
|
174 | - "'%s' is not a model name. A model name must be provided when making a gateway log. Eg, 'Payment', 'Payment_Method', etc", |
|
175 | - "event_espresso" |
|
176 | - ), |
|
177 | - $related_obj_type |
|
178 | - ) |
|
179 | - ); |
|
180 | - } |
|
181 | - /** @var EE_Change_Log $log */ |
|
182 | - $log = EE_Change_Log::new_instance(array( |
|
183 | - 'LOG_type' => EEM_Change_Log::type_gateway, |
|
184 | - 'LOG_message' => $message, |
|
185 | - 'OBJ_ID' => $related_obj_id, |
|
186 | - 'OBJ_type' => $related_obj_type, |
|
187 | - )); |
|
188 | - $log->save(); |
|
189 | - return $log; |
|
190 | - } |
|
159 | + /** |
|
160 | + * Adds a gateway log for the specified object, given its ID and type |
|
161 | + * |
|
162 | + * @param string $message |
|
163 | + * @param mixed $related_obj_id |
|
164 | + * @param string $related_obj_type |
|
165 | + * @throws EE_Error |
|
166 | + * @return EE_Change_Log |
|
167 | + */ |
|
168 | + public function gateway_log($message, $related_obj_id, $related_obj_type) |
|
169 | + { |
|
170 | + if (! EE_Registry::instance()->is_model_name($related_obj_type)) { |
|
171 | + throw new EE_Error( |
|
172 | + sprintf( |
|
173 | + esc_html__( |
|
174 | + "'%s' is not a model name. A model name must be provided when making a gateway log. Eg, 'Payment', 'Payment_Method', etc", |
|
175 | + "event_espresso" |
|
176 | + ), |
|
177 | + $related_obj_type |
|
178 | + ) |
|
179 | + ); |
|
180 | + } |
|
181 | + /** @var EE_Change_Log $log */ |
|
182 | + $log = EE_Change_Log::new_instance(array( |
|
183 | + 'LOG_type' => EEM_Change_Log::type_gateway, |
|
184 | + 'LOG_message' => $message, |
|
185 | + 'OBJ_ID' => $related_obj_id, |
|
186 | + 'OBJ_type' => $related_obj_type, |
|
187 | + )); |
|
188 | + $log->save(); |
|
189 | + return $log; |
|
190 | + } |
|
191 | 191 | |
192 | 192 | |
193 | - /** |
|
194 | - * Just gets the bare-bones wpdb results as an array in cases where efficiency is essential |
|
195 | - * |
|
196 | - * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
197 | - * @return array of arrays |
|
198 | - * @throws EE_Error |
|
199 | - */ |
|
200 | - public function get_all_efficiently($query_params) |
|
201 | - { |
|
202 | - return $this->_get_all_wpdb_results($query_params); |
|
203 | - } |
|
193 | + /** |
|
194 | + * Just gets the bare-bones wpdb results as an array in cases where efficiency is essential |
|
195 | + * |
|
196 | + * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
197 | + * @return array of arrays |
|
198 | + * @throws EE_Error |
|
199 | + */ |
|
200 | + public function get_all_efficiently($query_params) |
|
201 | + { |
|
202 | + return $this->_get_all_wpdb_results($query_params); |
|
203 | + } |
|
204 | 204 | |
205 | 205 | |
206 | - /** |
|
207 | - * Executes a database query to delete gateway logs. Does not affect model objects, so if you attempt to use |
|
208 | - * models after this, they may be out-of-sync with the database |
|
209 | - * |
|
210 | - * @param DateTime $datetime |
|
211 | - * @return false|int |
|
212 | - * @throws EE_Error |
|
213 | - */ |
|
214 | - public function delete_gateway_logs_older_than(DateTime $datetime) |
|
215 | - { |
|
216 | - global $wpdb; |
|
217 | - return $wpdb->query( |
|
218 | - $wpdb->prepare( |
|
219 | - 'DELETE FROM ' . $this->table() . ' WHERE LOG_type = %s AND LOG_time < %s', |
|
220 | - EEM_Change_Log::type_gateway, |
|
221 | - $datetime->format(EE_Datetime_Field::mysql_timestamp_format) |
|
222 | - ) |
|
223 | - ); |
|
224 | - } |
|
206 | + /** |
|
207 | + * Executes a database query to delete gateway logs. Does not affect model objects, so if you attempt to use |
|
208 | + * models after this, they may be out-of-sync with the database |
|
209 | + * |
|
210 | + * @param DateTime $datetime |
|
211 | + * @return false|int |
|
212 | + * @throws EE_Error |
|
213 | + */ |
|
214 | + public function delete_gateway_logs_older_than(DateTime $datetime) |
|
215 | + { |
|
216 | + global $wpdb; |
|
217 | + return $wpdb->query( |
|
218 | + $wpdb->prepare( |
|
219 | + 'DELETE FROM ' . $this->table() . ' WHERE LOG_type = %s AND LOG_time < %s', |
|
220 | + EEM_Change_Log::type_gateway, |
|
221 | + $datetime->format(EE_Datetime_Field::mysql_timestamp_format) |
|
222 | + ) |
|
223 | + ); |
|
224 | + } |
|
225 | 225 | |
226 | 226 | |
227 | - /** |
|
228 | - * Returns the map of type to pretty label for identifiers used for `LOG_type`. Client code can register their own |
|
229 | - * map vai the given filter. |
|
230 | - * |
|
231 | - * @return array |
|
232 | - */ |
|
233 | - public static function get_pretty_label_map_for_registered_types() |
|
234 | - { |
|
235 | - return apply_filters( |
|
236 | - 'FHEE__EEM_Change_Log__get_pretty_label_map_for_registered_types', |
|
237 | - array( |
|
238 | - self::type_create => esc_html__("Create", "event_espresso"), |
|
239 | - self::type_update => esc_html__("Update", "event_espresso"), |
|
240 | - self::type_delete => esc_html__("Delete", "event_espresso"), |
|
241 | - self::type_debug => esc_html__("Debug", "event_espresso"), |
|
242 | - self::type_error => esc_html__("Error", "event_espresso"), |
|
243 | - self::type_gateway => esc_html__("Gateway Interaction (IPN or Direct Payment)", 'event_espresso') |
|
244 | - ) |
|
245 | - ); |
|
246 | - } |
|
227 | + /** |
|
228 | + * Returns the map of type to pretty label for identifiers used for `LOG_type`. Client code can register their own |
|
229 | + * map vai the given filter. |
|
230 | + * |
|
231 | + * @return array |
|
232 | + */ |
|
233 | + public static function get_pretty_label_map_for_registered_types() |
|
234 | + { |
|
235 | + return apply_filters( |
|
236 | + 'FHEE__EEM_Change_Log__get_pretty_label_map_for_registered_types', |
|
237 | + array( |
|
238 | + self::type_create => esc_html__("Create", "event_espresso"), |
|
239 | + self::type_update => esc_html__("Update", "event_espresso"), |
|
240 | + self::type_delete => esc_html__("Delete", "event_espresso"), |
|
241 | + self::type_debug => esc_html__("Debug", "event_espresso"), |
|
242 | + self::type_error => esc_html__("Error", "event_espresso"), |
|
243 | + self::type_gateway => esc_html__("Gateway Interaction (IPN or Direct Payment)", 'event_espresso') |
|
244 | + ) |
|
245 | + ); |
|
246 | + } |
|
247 | 247 | |
248 | 248 | |
249 | - /** |
|
250 | - * Return the pretty (localized) label for the given log type identifier. |
|
251 | - * @param string $type_identifier |
|
252 | - * @return string |
|
253 | - */ |
|
254 | - public static function get_pretty_label_for_type($type_identifier) |
|
255 | - { |
|
256 | - $type_identifier_map = self::get_pretty_label_map_for_registered_types(); |
|
257 | - // we fallback to the incoming type identifier if there is no localized label for it. |
|
258 | - return isset($type_identifier_map[ $type_identifier ]) |
|
259 | - ? $type_identifier_map[ $type_identifier ] |
|
260 | - : $type_identifier; |
|
261 | - } |
|
249 | + /** |
|
250 | + * Return the pretty (localized) label for the given log type identifier. |
|
251 | + * @param string $type_identifier |
|
252 | + * @return string |
|
253 | + */ |
|
254 | + public static function get_pretty_label_for_type($type_identifier) |
|
255 | + { |
|
256 | + $type_identifier_map = self::get_pretty_label_map_for_registered_types(); |
|
257 | + // we fallback to the incoming type identifier if there is no localized label for it. |
|
258 | + return isset($type_identifier_map[ $type_identifier ]) |
|
259 | + ? $type_identifier_map[ $type_identifier ] |
|
260 | + : $type_identifier; |
|
261 | + } |
|
262 | 262 | } |
@@ -38,10 +38,10 @@ |
||
38 | 38 | )); |
39 | 39 | $this->_model_relations = array(); |
40 | 40 | foreach ($models_this_can_attach_to as $model) { |
41 | - $this->_model_relations[ $model ] = new EE_Belongs_To_Any_Relation(); |
|
41 | + $this->_model_relations[$model] = new EE_Belongs_To_Any_Relation(); |
|
42 | 42 | } |
43 | 43 | foreach ($this->cap_contexts_to_cap_action_map() as $cap_context => $action) { |
44 | - $this->_cap_restriction_generators[ $cap_context ] = new EE_Restriction_Generator_Meta('EXM_key', 'EXM_value'); |
|
44 | + $this->_cap_restriction_generators[$cap_context] = new EE_Restriction_Generator_Meta('EXM_key', 'EXM_value'); |
|
45 | 45 | } |
46 | 46 | parent::__construct($timezone); |
47 | 47 | } |
@@ -16,33 +16,33 @@ |
||
16 | 16 | */ |
17 | 17 | class EEM_Extra_Meta extends EEM_Base |
18 | 18 | { |
19 | - // private instance of the Attendee object |
|
20 | - protected static $_instance = null; |
|
19 | + // private instance of the Attendee object |
|
20 | + protected static $_instance = null; |
|
21 | 21 | |
22 | - protected function __construct($timezone = null) |
|
23 | - { |
|
24 | - $this->singular_item = esc_html__('Extra Meta', 'event_espresso'); |
|
25 | - $this->plural_item = esc_html__('Extra Metas', 'event_espresso'); |
|
26 | - $this->_tables = array( |
|
27 | - 'Extra_Meta' => new EE_Primary_Table('esp_extra_meta', 'EXM_ID') |
|
28 | - ); |
|
29 | - $models_this_can_attach_to = array_keys(EE_Registry::instance()->non_abstract_db_models); |
|
30 | - $this->_fields = array( |
|
31 | - 'Extra_Meta' => array( |
|
32 | - 'EXM_ID' => new EE_Primary_Key_Int_Field('EXM_ID', esc_html__("Extra Meta ID", "event_espresso")), |
|
33 | - 'OBJ_ID' => new EE_Foreign_Key_Int_Field('OBJ_ID', esc_html__("Primary Key of Attached Thing", "event_espresso"), false, 0, $models_this_can_attach_to), |
|
34 | - 'EXM_type' => new EE_Any_Foreign_Model_Name_Field('EXM_type', esc_html__("Model of Attached Thing", "event_espresso"), false, 'Transaction', $models_this_can_attach_to), |
|
35 | - 'EXM_key' => new EE_Plain_Text_Field('EXM_key', esc_html__("Meta Key", "event_espresso"), false, ''), |
|
36 | - 'EXM_value' => new EE_Maybe_Serialized_Text_Field('EXM_value', esc_html__("Meta Value", "event_espresso"), true) |
|
22 | + protected function __construct($timezone = null) |
|
23 | + { |
|
24 | + $this->singular_item = esc_html__('Extra Meta', 'event_espresso'); |
|
25 | + $this->plural_item = esc_html__('Extra Metas', 'event_espresso'); |
|
26 | + $this->_tables = array( |
|
27 | + 'Extra_Meta' => new EE_Primary_Table('esp_extra_meta', 'EXM_ID') |
|
28 | + ); |
|
29 | + $models_this_can_attach_to = array_keys(EE_Registry::instance()->non_abstract_db_models); |
|
30 | + $this->_fields = array( |
|
31 | + 'Extra_Meta' => array( |
|
32 | + 'EXM_ID' => new EE_Primary_Key_Int_Field('EXM_ID', esc_html__("Extra Meta ID", "event_espresso")), |
|
33 | + 'OBJ_ID' => new EE_Foreign_Key_Int_Field('OBJ_ID', esc_html__("Primary Key of Attached Thing", "event_espresso"), false, 0, $models_this_can_attach_to), |
|
34 | + 'EXM_type' => new EE_Any_Foreign_Model_Name_Field('EXM_type', esc_html__("Model of Attached Thing", "event_espresso"), false, 'Transaction', $models_this_can_attach_to), |
|
35 | + 'EXM_key' => new EE_Plain_Text_Field('EXM_key', esc_html__("Meta Key", "event_espresso"), false, ''), |
|
36 | + 'EXM_value' => new EE_Maybe_Serialized_Text_Field('EXM_value', esc_html__("Meta Value", "event_espresso"), true) |
|
37 | 37 | |
38 | - )); |
|
39 | - $this->_model_relations = array(); |
|
40 | - foreach ($models_this_can_attach_to as $model) { |
|
41 | - $this->_model_relations[ $model ] = new EE_Belongs_To_Any_Relation(); |
|
42 | - } |
|
43 | - foreach ($this->cap_contexts_to_cap_action_map() as $cap_context => $action) { |
|
44 | - $this->_cap_restriction_generators[ $cap_context ] = new EE_Restriction_Generator_Meta('EXM_key', 'EXM_value'); |
|
45 | - } |
|
46 | - parent::__construct($timezone); |
|
47 | - } |
|
38 | + )); |
|
39 | + $this->_model_relations = array(); |
|
40 | + foreach ($models_this_can_attach_to as $model) { |
|
41 | + $this->_model_relations[ $model ] = new EE_Belongs_To_Any_Relation(); |
|
42 | + } |
|
43 | + foreach ($this->cap_contexts_to_cap_action_map() as $cap_context => $action) { |
|
44 | + $this->_cap_restriction_generators[ $cap_context ] = new EE_Restriction_Generator_Meta('EXM_key', 'EXM_value'); |
|
45 | + } |
|
46 | + parent::__construct($timezone); |
|
47 | + } |
|
48 | 48 | } |
@@ -45,10 +45,10 @@ discard block |
||
45 | 45 | 'WP_User' => new EE_Belongs_To_Relation(), |
46 | 46 | ); |
47 | 47 | // this model is generally available for reading |
48 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public(); |
|
49 | - $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Reg_Form('QSG_system'); |
|
50 | - $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Reg_Form('QSG_system'); |
|
51 | - $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Reg_Form('QSG_system'); |
|
48 | + $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Public(); |
|
49 | + $this->_cap_restriction_generators[EEM_Base::caps_read_admin] = new EE_Restriction_Generator_Reg_Form('QSG_system'); |
|
50 | + $this->_cap_restriction_generators[EEM_Base::caps_edit] = new EE_Restriction_Generator_Reg_Form('QSG_system'); |
|
51 | + $this->_cap_restriction_generators[EEM_Base::caps_delete] = new EE_Restriction_Generator_Reg_Form('QSG_system'); |
|
52 | 52 | parent::__construct($timezone); |
53 | 53 | } |
54 | 54 | /** |
@@ -59,7 +59,7 @@ discard block |
||
59 | 59 | public function get_latest_question_group_order() |
60 | 60 | { |
61 | 61 | $columns_to_select = array( |
62 | - 'max_order' => array("MAX(QSG_order)","%d") |
|
62 | + 'max_order' => array("MAX(QSG_order)", "%d") |
|
63 | 63 | ); |
64 | 64 | $max = $this->_get_all_wpdb_results(array(), ARRAY_A, $columns_to_select); |
65 | 65 | return $max[0]['max_order']; |
@@ -11,58 +11,58 @@ |
||
11 | 11 | */ |
12 | 12 | class EEM_Question_Group extends EEM_Soft_Delete_Base |
13 | 13 | { |
14 | - const system_personal = 1; |
|
15 | - const system_address = 2; |
|
16 | - // private instance of the Attendee object |
|
17 | - protected static $_instance = null; |
|
14 | + const system_personal = 1; |
|
15 | + const system_address = 2; |
|
16 | + // private instance of the Attendee object |
|
17 | + protected static $_instance = null; |
|
18 | 18 | |
19 | 19 | |
20 | - protected function __construct($timezone = null) |
|
21 | - { |
|
22 | - $this->singular_item = esc_html__('Question Group', 'event_espresso'); |
|
23 | - $this->plural_item = esc_html__('Question Groups', 'event_espresso'); |
|
20 | + protected function __construct($timezone = null) |
|
21 | + { |
|
22 | + $this->singular_item = esc_html__('Question Group', 'event_espresso'); |
|
23 | + $this->plural_item = esc_html__('Question Groups', 'event_espresso'); |
|
24 | 24 | |
25 | - $this->_tables = array( |
|
26 | - 'Question_Group' => new EE_Primary_Table('esp_question_group', 'QSG_ID') |
|
27 | - ); |
|
28 | - $this->_fields = array( |
|
29 | - 'Question_Group' => array( |
|
30 | - 'QSG_ID' => new EE_Primary_Key_Int_Field('QSG_ID', esc_html__('Question Group ID', 'event_espresso')), |
|
31 | - 'QSG_name' => new EE_Plain_Text_Field('QSG_name', esc_html__('Question Group Name', 'event_espresso'), false, ''), |
|
32 | - 'QSG_identifier' => new EE_Plain_Text_Field('QSG_identifier', esc_html__('Text ID for question Group', 'event_espresso'), false, ''), |
|
33 | - 'QSG_desc' => new EE_Post_Content_Field('QSG_desc', esc_html__('Description of Question Group', 'event_espresso'), true, ''), |
|
34 | - 'QSG_order' => new EE_Integer_Field('QSG_order', esc_html__('Order in which to show the question group', 'event_espresso'), true, 0), |
|
35 | - 'QSG_show_group_name' => new EE_Boolean_Field('QSG_show_group_name', esc_html__('Flag indicating whether to show the group\'s name on the registration page', 'event_espresso'), false, true), |
|
36 | - 'QSG_show_group_desc' => new EE_Boolean_Field('QSG_show_group_desc', esc_html__('Flag indicating whether to show the group\s description on the registration page', 'event_espresso'), false, false), |
|
37 | - 'QSG_wp_user' => new EE_WP_User_Field('QSG_wp_user', esc_html__('Question Group Creator ID', 'event_espresso'), false), |
|
38 | - 'QSG_system' => new EE_Integer_Field('QSG_system', esc_html__('Indicate IF this is a system group and if it is what system group it corresponds to.', 'event_espresso'), false, 0), |
|
39 | - 'QSG_deleted' => new EE_Trashed_Flag_Field('QSG_deleted', esc_html__('Flag indicating this question group was deleted', 'event_espresso'), false, false) |
|
40 | - ) |
|
41 | - ); |
|
42 | - $this->_model_relations = array( |
|
43 | - 'Question' => new EE_HABTM_Relation('Question_Group_Question'), |
|
44 | - 'Event' => new EE_HABTM_Relation('Event_Question_Group'), |
|
45 | - 'Event_Question_Group' => new EE_Has_Many_Relation(), |
|
46 | - 'WP_User' => new EE_Belongs_To_Relation(), |
|
47 | - ); |
|
48 | - // this model is generally available for reading |
|
49 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public(); |
|
50 | - $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Reg_Form('QSG_system'); |
|
51 | - $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Reg_Form('QSG_system'); |
|
52 | - $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Reg_Form('QSG_system'); |
|
53 | - parent::__construct($timezone); |
|
54 | - } |
|
55 | - /** |
|
56 | - * searches the db for the question group with the latest question order and returns that value. |
|
57 | - * @access public |
|
58 | - * @return int |
|
59 | - */ |
|
60 | - public function get_latest_question_group_order() |
|
61 | - { |
|
62 | - $columns_to_select = array( |
|
63 | - 'max_order' => array("MAX(QSG_order)","%d") |
|
64 | - ); |
|
65 | - $max = $this->_get_all_wpdb_results(array(), ARRAY_A, $columns_to_select); |
|
66 | - return $max[0]['max_order']; |
|
67 | - } |
|
25 | + $this->_tables = array( |
|
26 | + 'Question_Group' => new EE_Primary_Table('esp_question_group', 'QSG_ID') |
|
27 | + ); |
|
28 | + $this->_fields = array( |
|
29 | + 'Question_Group' => array( |
|
30 | + 'QSG_ID' => new EE_Primary_Key_Int_Field('QSG_ID', esc_html__('Question Group ID', 'event_espresso')), |
|
31 | + 'QSG_name' => new EE_Plain_Text_Field('QSG_name', esc_html__('Question Group Name', 'event_espresso'), false, ''), |
|
32 | + 'QSG_identifier' => new EE_Plain_Text_Field('QSG_identifier', esc_html__('Text ID for question Group', 'event_espresso'), false, ''), |
|
33 | + 'QSG_desc' => new EE_Post_Content_Field('QSG_desc', esc_html__('Description of Question Group', 'event_espresso'), true, ''), |
|
34 | + 'QSG_order' => new EE_Integer_Field('QSG_order', esc_html__('Order in which to show the question group', 'event_espresso'), true, 0), |
|
35 | + 'QSG_show_group_name' => new EE_Boolean_Field('QSG_show_group_name', esc_html__('Flag indicating whether to show the group\'s name on the registration page', 'event_espresso'), false, true), |
|
36 | + 'QSG_show_group_desc' => new EE_Boolean_Field('QSG_show_group_desc', esc_html__('Flag indicating whether to show the group\s description on the registration page', 'event_espresso'), false, false), |
|
37 | + 'QSG_wp_user' => new EE_WP_User_Field('QSG_wp_user', esc_html__('Question Group Creator ID', 'event_espresso'), false), |
|
38 | + 'QSG_system' => new EE_Integer_Field('QSG_system', esc_html__('Indicate IF this is a system group and if it is what system group it corresponds to.', 'event_espresso'), false, 0), |
|
39 | + 'QSG_deleted' => new EE_Trashed_Flag_Field('QSG_deleted', esc_html__('Flag indicating this question group was deleted', 'event_espresso'), false, false) |
|
40 | + ) |
|
41 | + ); |
|
42 | + $this->_model_relations = array( |
|
43 | + 'Question' => new EE_HABTM_Relation('Question_Group_Question'), |
|
44 | + 'Event' => new EE_HABTM_Relation('Event_Question_Group'), |
|
45 | + 'Event_Question_Group' => new EE_Has_Many_Relation(), |
|
46 | + 'WP_User' => new EE_Belongs_To_Relation(), |
|
47 | + ); |
|
48 | + // this model is generally available for reading |
|
49 | + $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public(); |
|
50 | + $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Reg_Form('QSG_system'); |
|
51 | + $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Reg_Form('QSG_system'); |
|
52 | + $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Reg_Form('QSG_system'); |
|
53 | + parent::__construct($timezone); |
|
54 | + } |
|
55 | + /** |
|
56 | + * searches the db for the question group with the latest question order and returns that value. |
|
57 | + * @access public |
|
58 | + * @return int |
|
59 | + */ |
|
60 | + public function get_latest_question_group_order() |
|
61 | + { |
|
62 | + $columns_to_select = array( |
|
63 | + 'max_order' => array("MAX(QSG_order)","%d") |
|
64 | + ); |
|
65 | + $max = $this->_get_all_wpdb_results(array(), ARRAY_A, $columns_to_select); |
|
66 | + return $max[0]['max_order']; |
|
67 | + } |
|
68 | 68 | } |