@@ -17,559 +17,559 @@ |
||
17 | 17 | class EE_Payment_Method_Manager implements ResettableInterface |
18 | 18 | { |
19 | 19 | |
20 | - /** |
|
21 | - * prefix added to all payment method capabilities names |
|
22 | - */ |
|
23 | - const CAPABILITIES_PREFIX = 'ee_payment_method_'; |
|
24 | - |
|
25 | - /** |
|
26 | - * @var EE_Payment_Method_Manager $_instance |
|
27 | - */ |
|
28 | - private static $_instance; |
|
29 | - |
|
30 | - /** |
|
31 | - * @var boolean |
|
32 | - */ |
|
33 | - protected $payment_method_caps_initialized = false; |
|
34 | - |
|
35 | - /** |
|
36 | - * @var array keys are class names without 'EE_PMT_', values are their filepaths |
|
37 | - */ |
|
38 | - protected $_payment_method_types = array(); |
|
39 | - |
|
40 | - /** |
|
41 | - * @var EE_PMT_Base[] |
|
42 | - */ |
|
43 | - protected $payment_method_objects = array(); |
|
44 | - |
|
45 | - |
|
46 | - /** |
|
47 | - * EE_Payment_Method_Manager constructor. |
|
48 | - * |
|
49 | - * @throws EE_Error |
|
50 | - * @throws DomainException |
|
51 | - */ |
|
52 | - public function __construct() |
|
53 | - { |
|
54 | - // if in admin lets ensure caps are set. |
|
55 | - if (is_admin()) { |
|
56 | - $this->_register_payment_methods(); |
|
57 | - // set them immediately |
|
58 | - $this->initializePaymentMethodCaps(); |
|
59 | - // plus any time they get reset |
|
60 | - add_filter( |
|
61 | - 'FHEE__EE_Capabilities__addCaps__capabilities_to_add', |
|
62 | - array($this, 'addPaymentMethodCapsDuringReset') |
|
63 | - ); |
|
64 | - } |
|
65 | - } |
|
66 | - |
|
67 | - |
|
68 | - /** |
|
69 | - * @singleton method used to instantiate class object |
|
70 | - * @return EE_Payment_Method_Manager instance |
|
71 | - * @throws DomainException |
|
72 | - * @throws EE_Error |
|
73 | - */ |
|
74 | - public static function instance() |
|
75 | - { |
|
76 | - // check if class object is instantiated, and instantiated properly |
|
77 | - if (! self::$_instance instanceof EE_Payment_Method_Manager) { |
|
78 | - EE_Registry::instance()->load_lib('PMT_Base'); |
|
79 | - self::$_instance = new self(); |
|
80 | - } |
|
81 | - return self::$_instance; |
|
82 | - } |
|
83 | - |
|
84 | - |
|
85 | - /** |
|
86 | - * Resets the instance and returns a new one |
|
87 | - * |
|
88 | - * @return EE_Payment_Method_Manager |
|
89 | - * @throws DomainException |
|
90 | - * @throws EE_Error |
|
91 | - */ |
|
92 | - public static function reset() |
|
93 | - { |
|
94 | - self::$_instance = null; |
|
95 | - return self::instance(); |
|
96 | - } |
|
97 | - |
|
98 | - |
|
99 | - /** |
|
100 | - * If necessary, re-register payment methods |
|
101 | - * |
|
102 | - * @param boolean $force_recheck whether to recheck for payment method types, |
|
103 | - * or just re-use the PMTs we found last time we checked during this request (if |
|
104 | - * we have not yet checked during this request, then we need to check anyways) |
|
105 | - */ |
|
106 | - public function maybe_register_payment_methods($force_recheck = false) |
|
107 | - { |
|
108 | - if (! $this->_payment_method_types || $force_recheck) { |
|
109 | - $this->_register_payment_methods(); |
|
110 | - } |
|
111 | - } |
|
112 | - |
|
113 | - |
|
114 | - /** |
|
115 | - * register_payment_methods |
|
116 | - * |
|
117 | - * @return array |
|
118 | - */ |
|
119 | - protected function _register_payment_methods() |
|
120 | - { |
|
121 | - // grab list of installed modules |
|
122 | - $pm_to_register = glob(EE_PAYMENT_METHODS . '*', GLOB_ONLYDIR); |
|
123 | - // filter list of modules to register |
|
124 | - $pm_to_register = apply_filters( |
|
125 | - 'FHEE__EE_Payment_Method_Manager__register_payment_methods__payment_methods_to_register', |
|
126 | - $pm_to_register |
|
127 | - ); |
|
128 | - // remove any duplicates if that should happen for some reason |
|
129 | - $pm_to_register = array_unique($pm_to_register); |
|
130 | - // loop through folders |
|
131 | - foreach ($pm_to_register as $pm_path) { |
|
132 | - $this->register_payment_method($pm_path); |
|
133 | - } |
|
134 | - do_action('FHEE__EE_Payment_Method_Manager__register_payment_methods__registered_payment_methods'); |
|
135 | - // filter list of installed modules |
|
136 | - // keep them organized alphabetically by the payment method type's name |
|
137 | - ksort($this->_payment_method_types); |
|
138 | - return apply_filters( |
|
139 | - 'FHEE__EE_Payment_Method_Manager__register_payment_methods__installed_payment_methods', |
|
140 | - $this->_payment_method_types |
|
141 | - ); |
|
142 | - } |
|
143 | - |
|
144 | - |
|
145 | - /** |
|
146 | - * register_payment_method- makes core aware of this payment method |
|
147 | - * |
|
148 | - * @param string $payment_method_path - full path up to and including payment method folder |
|
149 | - * @return boolean |
|
150 | - */ |
|
151 | - public function register_payment_method($payment_method_path = '') |
|
152 | - { |
|
153 | - do_action('AHEE__EE_Payment_Method_Manager__register_payment_method__begin', $payment_method_path); |
|
154 | - $module_ext = '.pm.php'; |
|
155 | - // make all separators match |
|
156 | - $payment_method_path = rtrim(str_replace('/\\', '/', $payment_method_path), '/'); |
|
157 | - // grab and sanitize module name |
|
158 | - $module_dir = basename($payment_method_path); |
|
159 | - // create class name from module directory name |
|
160 | - $module = str_replace(array('_', ' '), array(' ', '_'), $module_dir); |
|
161 | - // add class prefix |
|
162 | - $module_class = 'EE_PMT_' . $module; |
|
163 | - // does the module exist ? |
|
164 | - if (! is_readable($payment_method_path . '/' . $module_class . $module_ext)) { |
|
165 | - $msg = sprintf( |
|
166 | - esc_html__( |
|
167 | - 'The requested %s payment method file could not be found or is not readable due to file permissions.', |
|
168 | - 'event_espresso' |
|
169 | - ), |
|
170 | - $module |
|
171 | - ); |
|
172 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
173 | - return false; |
|
174 | - } |
|
175 | - // load the module class file |
|
176 | - require_once($payment_method_path . '/' . $module_class . $module_ext); |
|
177 | - // verify that class exists |
|
178 | - if (! class_exists($module_class)) { |
|
179 | - $msg = sprintf( |
|
180 | - esc_html__('The requested %s module class does not exist.', 'event_espresso'), |
|
181 | - $module_class |
|
182 | - ); |
|
183 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
184 | - return false; |
|
185 | - } |
|
186 | - // add to array of registered modules |
|
187 | - $this->_payment_method_types[ $module ] = $payment_method_path . '/' . $module_class . $module_ext; |
|
188 | - ksort($this->_payment_method_types); |
|
189 | - return true; |
|
190 | - } |
|
191 | - |
|
192 | - |
|
193 | - /** |
|
194 | - * Checks if a payment method has been registered, and if so includes it |
|
195 | - * |
|
196 | - * @param string $payment_method_name like 'PayPal_Pro', (ie class name without the prefix 'EEPM_') |
|
197 | - * @param boolean $force_recheck whether to force re-checking for new payment method types |
|
198 | - * @return boolean |
|
199 | - */ |
|
200 | - public function payment_method_type_exists($payment_method_name, $force_recheck = false) |
|
201 | - { |
|
202 | - if ($force_recheck |
|
203 | - || ! is_array($this->_payment_method_types) |
|
204 | - || ! isset($this->_payment_method_types[ $payment_method_name ]) |
|
205 | - ) { |
|
206 | - $this->maybe_register_payment_methods($force_recheck); |
|
207 | - } |
|
208 | - if (isset($this->_payment_method_types[ $payment_method_name ])) { |
|
209 | - require_once($this->_payment_method_types[ $payment_method_name ]); |
|
210 | - return true; |
|
211 | - } |
|
212 | - return false; |
|
213 | - } |
|
214 | - |
|
215 | - |
|
216 | - /** |
|
217 | - * Returns all the class names of the various payment method types |
|
218 | - * |
|
219 | - * @param boolean $with_prefixes TRUE: get payment method type class names; false just their 'names' |
|
220 | - * (what you'd find in wp_esp_payment_method.PMD_type) |
|
221 | - * @param boolean $force_recheck whether to force re-checking for new payment method types |
|
222 | - * @return array |
|
223 | - */ |
|
224 | - public function payment_method_type_names($with_prefixes = false, $force_recheck = false) |
|
225 | - { |
|
226 | - $this->maybe_register_payment_methods($force_recheck); |
|
227 | - if ($with_prefixes) { |
|
228 | - $classnames = array_keys($this->_payment_method_types); |
|
229 | - $payment_methods = array(); |
|
230 | - foreach ($classnames as $classname) { |
|
231 | - $payment_methods[] = $this->payment_method_class_from_type($classname); |
|
232 | - } |
|
233 | - return $payment_methods; |
|
234 | - } |
|
235 | - return array_keys($this->_payment_method_types); |
|
236 | - } |
|
237 | - |
|
238 | - |
|
239 | - /** |
|
240 | - * Gets an object of each payment method type, none of which are bound to a |
|
241 | - * payment method instance |
|
242 | - * |
|
243 | - * @param boolean $force_recheck whether to force re-checking for new payment method types |
|
244 | - * @return EE_PMT_Base[] |
|
245 | - */ |
|
246 | - public function payment_method_types($force_recheck = false) |
|
247 | - { |
|
248 | - if ($force_recheck || empty($this->payment_method_objects)) { |
|
249 | - $this->maybe_register_payment_methods($force_recheck); |
|
250 | - foreach ($this->payment_method_type_names(true) as $classname) { |
|
251 | - if (! isset($this->payment_method_objects[ $classname ])) { |
|
252 | - $this->payment_method_objects[ $classname ] = new $classname; |
|
253 | - } |
|
254 | - } |
|
255 | - } |
|
256 | - return $this->payment_method_objects; |
|
257 | - } |
|
258 | - |
|
259 | - |
|
260 | - /** |
|
261 | - * Changes the payment method's class name into the payment method type's name |
|
262 | - * (as used on the payment method's table's PMD_type field) |
|
263 | - * |
|
264 | - * @param string $classname |
|
265 | - * @return string |
|
266 | - */ |
|
267 | - public function payment_method_type_sans_class_prefix($classname) |
|
268 | - { |
|
269 | - return str_replace('EE_PMT_', '', $classname); |
|
270 | - } |
|
271 | - |
|
272 | - |
|
273 | - /** |
|
274 | - * Does the opposite of payment-method_type_sans_prefix |
|
275 | - * |
|
276 | - * @param string $type |
|
277 | - * @return string |
|
278 | - */ |
|
279 | - public function payment_method_class_from_type($type) |
|
280 | - { |
|
281 | - return 'EE_PMT_' . $type; |
|
282 | - } |
|
283 | - |
|
284 | - |
|
285 | - /** |
|
286 | - * Activates a payment method of the given type. |
|
287 | - * |
|
288 | - * @param string $payment_method_type the PMT_type; for EE_PMT_Invoice this would be 'Invoice' |
|
289 | - * @return EE_Payment_Method |
|
290 | - * @throws InvalidDataTypeException |
|
291 | - * @throws EE_Error |
|
292 | - */ |
|
293 | - public function activate_a_payment_method_of_type($payment_method_type) |
|
294 | - { |
|
295 | - $this->maybe_register_payment_methods(); |
|
296 | - $payment_method = EEM_Payment_Method::instance()->get_one_of_type($payment_method_type); |
|
297 | - if (! $payment_method instanceof EE_Payment_Method) { |
|
298 | - $pm_type_class = $this->payment_method_class_from_type($payment_method_type); |
|
299 | - if (class_exists($pm_type_class)) { |
|
300 | - /** @var $pm_type_obj EE_PMT_Base */ |
|
301 | - $pm_type_obj = new $pm_type_class; |
|
302 | - $payment_method = EEM_Payment_Method::instance()->get_one_by_slug($pm_type_obj->system_name()); |
|
303 | - if (! $payment_method) { |
|
304 | - $payment_method = $this->create_payment_method_of_type($pm_type_obj); |
|
305 | - } |
|
306 | - $payment_method->set_type($payment_method_type); |
|
307 | - $this->initialize_payment_method($payment_method); |
|
308 | - } else { |
|
309 | - throw new EE_Error( |
|
310 | - sprintf( |
|
311 | - esc_html__( |
|
312 | - 'There is no payment method of type %1$s, so it could not be activated', |
|
313 | - 'event_espresso' |
|
314 | - ), |
|
315 | - $pm_type_class |
|
316 | - ) |
|
317 | - ); |
|
318 | - } |
|
319 | - } |
|
320 | - $payment_method->set_active(); |
|
321 | - $payment_method->save(); |
|
322 | - /** @type EE_Message_Resource_Manager $message_resource_manager */ |
|
323 | - // if this was the invoice message type, make sure users can view their invoices |
|
324 | - if ($payment_method->type() === 'Invoice' |
|
325 | - && ( |
|
326 | - ! EEH_MSG_Template::is_mt_active('invoice') |
|
327 | - ) |
|
328 | - ) { |
|
329 | - $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
330 | - /** @type EE_Message_Resource_Manager $message_resource_manager */ |
|
331 | - $message_resource_manager->ensure_message_type_is_active('invoice', 'html'); |
|
332 | - new PersistentAdminNotice( |
|
333 | - 'invoice_pm_requirements_notice', |
|
334 | - sprintf( |
|
335 | - esc_html__( |
|
336 | - 'The Invoice payment method has been activated. It requires the %1$sinvoice message%2$s type to be active, so it was automatically activated for you.', |
|
337 | - 'event_espresso' |
|
338 | - ), |
|
339 | - '<a href="' . admin_url('admin.php?page=espresso_messages&action=settings') . '">', |
|
340 | - '</a>' |
|
341 | - ), |
|
342 | - true |
|
343 | - ); |
|
344 | - } |
|
345 | - return $payment_method; |
|
346 | - } |
|
347 | - |
|
348 | - |
|
349 | - /** |
|
350 | - * Creates a payment method of the specified type. Does not save it. |
|
351 | - * |
|
352 | - * @global WP_User $current_user |
|
353 | - * @param EE_PMT_Base $pm_type_obj |
|
354 | - * @return EE_Payment_Method |
|
355 | - * @throws EE_Error |
|
356 | - */ |
|
357 | - public function create_payment_method_of_type($pm_type_obj) |
|
358 | - { |
|
359 | - global $current_user; |
|
360 | - $payment_method = EE_Payment_Method::new_instance( |
|
361 | - array( |
|
362 | - 'PMD_type' => $pm_type_obj->system_name(), |
|
363 | - 'PMD_name' => $pm_type_obj->defaultFrontendName(), |
|
364 | - 'PMD_admin_name' => $pm_type_obj->pretty_name(), |
|
365 | - 'PMD_slug' => $pm_type_obj->system_name(),// automatically converted to slug |
|
366 | - 'PMD_wp_user' => $current_user->ID, |
|
367 | - 'PMD_order' => EEM_Payment_Method::instance()->count( |
|
368 | - array(array('PMD_type' => array('!=', 'Admin_Only'))) |
|
369 | - ) * 10, |
|
370 | - ) |
|
371 | - ); |
|
372 | - return $payment_method; |
|
373 | - } |
|
374 | - |
|
375 | - |
|
376 | - /** |
|
377 | - * Sets the initial payment method properties (including extra meta) |
|
378 | - * |
|
379 | - * @param EE_Payment_Method $payment_method |
|
380 | - * @return EE_Payment_Method |
|
381 | - * @throws EE_Error |
|
382 | - */ |
|
383 | - public function initialize_payment_method($payment_method) |
|
384 | - { |
|
385 | - $pm_type_obj = $payment_method->type_obj(); |
|
386 | - $payment_method->set_description($pm_type_obj->default_description()); |
|
387 | - if (! $payment_method->button_url()) { |
|
388 | - $payment_method->set_button_url($pm_type_obj->default_button_url()); |
|
389 | - } |
|
390 | - // now add setup its default extra meta properties |
|
391 | - $extra_metas = $pm_type_obj->settings_form()->extra_meta_inputs(); |
|
392 | - if (! empty($extra_metas)) { |
|
393 | - // verify the payment method has an ID before adding extra meta |
|
394 | - if (! $payment_method->ID()) { |
|
395 | - $payment_method->save(); |
|
396 | - } |
|
397 | - foreach ($extra_metas as $meta_name => $input) { |
|
398 | - $payment_method->update_extra_meta($meta_name, $input->raw_value()); |
|
399 | - } |
|
400 | - } |
|
401 | - return $payment_method; |
|
402 | - } |
|
403 | - |
|
404 | - |
|
405 | - /** |
|
406 | - * Makes sure the payment method is related to the specified payment method |
|
407 | - * |
|
408 | - * @deprecated in 4.9.40 because the currency payment method table is being deprecated |
|
409 | - * @param EE_Payment_Method $payment_method |
|
410 | - * @return EE_Payment_Method |
|
411 | - * @throws EE_Error |
|
412 | - */ |
|
413 | - public function set_usable_currencies_on_payment_method($payment_method) |
|
414 | - { |
|
415 | - EE_Error::doing_it_wrong( |
|
416 | - 'EE_Payment_Method_Manager::set_usable_currencies_on_payment_method', |
|
417 | - esc_html__( |
|
418 | - 'We no longer define what currencies are usable by payment methods. Its not used nor efficient.', |
|
419 | - 'event_espresso' |
|
420 | - ), |
|
421 | - '4.9.40' |
|
422 | - ); |
|
423 | - return $payment_method; |
|
424 | - } |
|
425 | - |
|
426 | - |
|
427 | - /** |
|
428 | - * Deactivates a payment method of the given payment method slug. |
|
429 | - * |
|
430 | - * @param string $payment_method_slug The slug for the payment method to deactivate. |
|
431 | - * @return int count of rows updated. |
|
432 | - * @throws EE_Error |
|
433 | - */ |
|
434 | - public function deactivate_payment_method($payment_method_slug) |
|
435 | - { |
|
436 | - EE_Log::instance()->log( |
|
437 | - __FILE__, |
|
438 | - __FUNCTION__, |
|
439 | - sprintf( |
|
440 | - esc_html__( |
|
441 | - 'Payment method with slug %1$s is being deactivated by site admin', |
|
442 | - 'event_espresso' |
|
443 | - ), |
|
444 | - $payment_method_slug |
|
445 | - ), |
|
446 | - 'payment_method_change' |
|
447 | - ); |
|
448 | - $count_updated = EEM_Payment_Method::instance()->update( |
|
449 | - array('PMD_scope' => array()), |
|
450 | - array(array('PMD_slug' => $payment_method_slug)) |
|
451 | - ); |
|
452 | - do_action( |
|
453 | - 'AHEE__EE_Payment_Method_Manager__deactivate_payment_method__after_deactivating_payment_method', |
|
454 | - $payment_method_slug, |
|
455 | - $count_updated |
|
456 | - ); |
|
457 | - return $count_updated; |
|
458 | - } |
|
459 | - |
|
460 | - |
|
461 | - /** |
|
462 | - * initializes payment method access caps via EE_Capabilities::init_role_caps() |
|
463 | - * upon EE_Payment_Method_Manager construction |
|
464 | - * |
|
465 | - * @throws EE_Error |
|
466 | - * @throws DomainException |
|
467 | - */ |
|
468 | - protected function initializePaymentMethodCaps() |
|
469 | - { |
|
470 | - // don't do this twice |
|
471 | - if ($this->payment_method_caps_initialized) { |
|
472 | - return; |
|
473 | - } |
|
474 | - EE_Capabilities::instance()->addCaps( |
|
475 | - $this->getPaymentMethodCaps() |
|
476 | - ); |
|
477 | - $this->payment_method_caps_initialized = true; |
|
478 | - } |
|
479 | - |
|
480 | - |
|
481 | - /** |
|
482 | - * array of dynamic payment method access caps. |
|
483 | - * at the time of writing, october 20 2014, these are the caps added: |
|
484 | - * ee_payment_method_admin_only |
|
485 | - * ee_payment_method_aim |
|
486 | - * ee_payment_method_bank |
|
487 | - * ee_payment_method_check |
|
488 | - * ee_payment_method_invoice |
|
489 | - * ee_payment_method_mijireh |
|
490 | - * ee_payment_method_paypal_pro |
|
491 | - * ee_payment_method_paypal_standard |
|
492 | - * Any other payment methods added to core or via addons will also get |
|
493 | - * their related capability automatically added too, so long as they are |
|
494 | - * registered properly using EE_Register_Payment_Method::register() |
|
495 | - * |
|
496 | - * @return array |
|
497 | - * @throws DomainException |
|
498 | - */ |
|
499 | - protected function getPaymentMethodCaps() |
|
500 | - { |
|
501 | - $caps = array(); |
|
502 | - foreach ($this->payment_method_type_names() as $payment_method_name) { |
|
503 | - $caps = $this->addPaymentMethodCap($payment_method_name, $caps); |
|
504 | - } |
|
505 | - return $caps; |
|
506 | - } |
|
507 | - |
|
508 | - |
|
509 | - /** |
|
510 | - * @param string $payment_method_name |
|
511 | - * @param array $payment_method_caps |
|
512 | - * @param string $role |
|
513 | - * @return array |
|
514 | - * @throws DomainException |
|
515 | - */ |
|
516 | - public function addPaymentMethodCap($payment_method_name, array $payment_method_caps, $role = 'administrator') |
|
517 | - { |
|
518 | - if (empty($payment_method_name)) { |
|
519 | - throw new DomainException( |
|
520 | - esc_html__( |
|
521 | - 'The name of a payment method must be specified to add capabilities.', |
|
522 | - 'event_espresso' |
|
523 | - ) |
|
524 | - ); |
|
525 | - } |
|
526 | - if (empty($role)) { |
|
527 | - throw new DomainException( |
|
528 | - sprintf( |
|
529 | - esc_html__( |
|
530 | - 'No role was supplied while trying to add capabilities for the %1$s payment method.', |
|
531 | - 'event_espresso' |
|
532 | - ), |
|
533 | - $payment_method_name |
|
534 | - ) |
|
535 | - ); |
|
536 | - } |
|
537 | - if (! isset($payment_method_caps[ $role ])) { |
|
538 | - $payment_method_caps[ $role ] = array(); |
|
539 | - } |
|
540 | - $payment_method_caps[ $role ][] = EE_Payment_Method_Manager::CAPABILITIES_PREFIX |
|
541 | - . strtolower($payment_method_name); |
|
542 | - return $payment_method_caps; |
|
543 | - } |
|
544 | - |
|
545 | - |
|
546 | - /** |
|
547 | - * callback for FHEE__EE_Capabilities__init_role_caps__caps_map filter |
|
548 | - * to add dynamic payment method access caps when capabilities are reset |
|
549 | - * (or if that filter is called and PM caps are not already set) |
|
550 | - * |
|
551 | - * @param array $caps capabilities being filtered |
|
552 | - * @param bool $reset |
|
553 | - * @return array |
|
554 | - * @throws DomainException |
|
555 | - */ |
|
556 | - public function addPaymentMethodCapsDuringReset(array $caps, $reset = false) |
|
557 | - { |
|
558 | - if ($reset || ! $this->payment_method_caps_initialized) { |
|
559 | - $this->payment_method_caps_initialized = true; |
|
560 | - $caps = array_merge_recursive($caps, $this->getPaymentMethodCaps()); |
|
561 | - } |
|
562 | - return $caps; |
|
563 | - } |
|
564 | - |
|
565 | - |
|
566 | - /** |
|
567 | - * @deprecated 4.9.42 |
|
568 | - * @param $caps |
|
569 | - * @return mixed |
|
570 | - */ |
|
571 | - public function add_payment_method_caps($caps) |
|
572 | - { |
|
573 | - return $caps; |
|
574 | - } |
|
20 | + /** |
|
21 | + * prefix added to all payment method capabilities names |
|
22 | + */ |
|
23 | + const CAPABILITIES_PREFIX = 'ee_payment_method_'; |
|
24 | + |
|
25 | + /** |
|
26 | + * @var EE_Payment_Method_Manager $_instance |
|
27 | + */ |
|
28 | + private static $_instance; |
|
29 | + |
|
30 | + /** |
|
31 | + * @var boolean |
|
32 | + */ |
|
33 | + protected $payment_method_caps_initialized = false; |
|
34 | + |
|
35 | + /** |
|
36 | + * @var array keys are class names without 'EE_PMT_', values are their filepaths |
|
37 | + */ |
|
38 | + protected $_payment_method_types = array(); |
|
39 | + |
|
40 | + /** |
|
41 | + * @var EE_PMT_Base[] |
|
42 | + */ |
|
43 | + protected $payment_method_objects = array(); |
|
44 | + |
|
45 | + |
|
46 | + /** |
|
47 | + * EE_Payment_Method_Manager constructor. |
|
48 | + * |
|
49 | + * @throws EE_Error |
|
50 | + * @throws DomainException |
|
51 | + */ |
|
52 | + public function __construct() |
|
53 | + { |
|
54 | + // if in admin lets ensure caps are set. |
|
55 | + if (is_admin()) { |
|
56 | + $this->_register_payment_methods(); |
|
57 | + // set them immediately |
|
58 | + $this->initializePaymentMethodCaps(); |
|
59 | + // plus any time they get reset |
|
60 | + add_filter( |
|
61 | + 'FHEE__EE_Capabilities__addCaps__capabilities_to_add', |
|
62 | + array($this, 'addPaymentMethodCapsDuringReset') |
|
63 | + ); |
|
64 | + } |
|
65 | + } |
|
66 | + |
|
67 | + |
|
68 | + /** |
|
69 | + * @singleton method used to instantiate class object |
|
70 | + * @return EE_Payment_Method_Manager instance |
|
71 | + * @throws DomainException |
|
72 | + * @throws EE_Error |
|
73 | + */ |
|
74 | + public static function instance() |
|
75 | + { |
|
76 | + // check if class object is instantiated, and instantiated properly |
|
77 | + if (! self::$_instance instanceof EE_Payment_Method_Manager) { |
|
78 | + EE_Registry::instance()->load_lib('PMT_Base'); |
|
79 | + self::$_instance = new self(); |
|
80 | + } |
|
81 | + return self::$_instance; |
|
82 | + } |
|
83 | + |
|
84 | + |
|
85 | + /** |
|
86 | + * Resets the instance and returns a new one |
|
87 | + * |
|
88 | + * @return EE_Payment_Method_Manager |
|
89 | + * @throws DomainException |
|
90 | + * @throws EE_Error |
|
91 | + */ |
|
92 | + public static function reset() |
|
93 | + { |
|
94 | + self::$_instance = null; |
|
95 | + return self::instance(); |
|
96 | + } |
|
97 | + |
|
98 | + |
|
99 | + /** |
|
100 | + * If necessary, re-register payment methods |
|
101 | + * |
|
102 | + * @param boolean $force_recheck whether to recheck for payment method types, |
|
103 | + * or just re-use the PMTs we found last time we checked during this request (if |
|
104 | + * we have not yet checked during this request, then we need to check anyways) |
|
105 | + */ |
|
106 | + public function maybe_register_payment_methods($force_recheck = false) |
|
107 | + { |
|
108 | + if (! $this->_payment_method_types || $force_recheck) { |
|
109 | + $this->_register_payment_methods(); |
|
110 | + } |
|
111 | + } |
|
112 | + |
|
113 | + |
|
114 | + /** |
|
115 | + * register_payment_methods |
|
116 | + * |
|
117 | + * @return array |
|
118 | + */ |
|
119 | + protected function _register_payment_methods() |
|
120 | + { |
|
121 | + // grab list of installed modules |
|
122 | + $pm_to_register = glob(EE_PAYMENT_METHODS . '*', GLOB_ONLYDIR); |
|
123 | + // filter list of modules to register |
|
124 | + $pm_to_register = apply_filters( |
|
125 | + 'FHEE__EE_Payment_Method_Manager__register_payment_methods__payment_methods_to_register', |
|
126 | + $pm_to_register |
|
127 | + ); |
|
128 | + // remove any duplicates if that should happen for some reason |
|
129 | + $pm_to_register = array_unique($pm_to_register); |
|
130 | + // loop through folders |
|
131 | + foreach ($pm_to_register as $pm_path) { |
|
132 | + $this->register_payment_method($pm_path); |
|
133 | + } |
|
134 | + do_action('FHEE__EE_Payment_Method_Manager__register_payment_methods__registered_payment_methods'); |
|
135 | + // filter list of installed modules |
|
136 | + // keep them organized alphabetically by the payment method type's name |
|
137 | + ksort($this->_payment_method_types); |
|
138 | + return apply_filters( |
|
139 | + 'FHEE__EE_Payment_Method_Manager__register_payment_methods__installed_payment_methods', |
|
140 | + $this->_payment_method_types |
|
141 | + ); |
|
142 | + } |
|
143 | + |
|
144 | + |
|
145 | + /** |
|
146 | + * register_payment_method- makes core aware of this payment method |
|
147 | + * |
|
148 | + * @param string $payment_method_path - full path up to and including payment method folder |
|
149 | + * @return boolean |
|
150 | + */ |
|
151 | + public function register_payment_method($payment_method_path = '') |
|
152 | + { |
|
153 | + do_action('AHEE__EE_Payment_Method_Manager__register_payment_method__begin', $payment_method_path); |
|
154 | + $module_ext = '.pm.php'; |
|
155 | + // make all separators match |
|
156 | + $payment_method_path = rtrim(str_replace('/\\', '/', $payment_method_path), '/'); |
|
157 | + // grab and sanitize module name |
|
158 | + $module_dir = basename($payment_method_path); |
|
159 | + // create class name from module directory name |
|
160 | + $module = str_replace(array('_', ' '), array(' ', '_'), $module_dir); |
|
161 | + // add class prefix |
|
162 | + $module_class = 'EE_PMT_' . $module; |
|
163 | + // does the module exist ? |
|
164 | + if (! is_readable($payment_method_path . '/' . $module_class . $module_ext)) { |
|
165 | + $msg = sprintf( |
|
166 | + esc_html__( |
|
167 | + 'The requested %s payment method file could not be found or is not readable due to file permissions.', |
|
168 | + 'event_espresso' |
|
169 | + ), |
|
170 | + $module |
|
171 | + ); |
|
172 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
173 | + return false; |
|
174 | + } |
|
175 | + // load the module class file |
|
176 | + require_once($payment_method_path . '/' . $module_class . $module_ext); |
|
177 | + // verify that class exists |
|
178 | + if (! class_exists($module_class)) { |
|
179 | + $msg = sprintf( |
|
180 | + esc_html__('The requested %s module class does not exist.', 'event_espresso'), |
|
181 | + $module_class |
|
182 | + ); |
|
183 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
184 | + return false; |
|
185 | + } |
|
186 | + // add to array of registered modules |
|
187 | + $this->_payment_method_types[ $module ] = $payment_method_path . '/' . $module_class . $module_ext; |
|
188 | + ksort($this->_payment_method_types); |
|
189 | + return true; |
|
190 | + } |
|
191 | + |
|
192 | + |
|
193 | + /** |
|
194 | + * Checks if a payment method has been registered, and if so includes it |
|
195 | + * |
|
196 | + * @param string $payment_method_name like 'PayPal_Pro', (ie class name without the prefix 'EEPM_') |
|
197 | + * @param boolean $force_recheck whether to force re-checking for new payment method types |
|
198 | + * @return boolean |
|
199 | + */ |
|
200 | + public function payment_method_type_exists($payment_method_name, $force_recheck = false) |
|
201 | + { |
|
202 | + if ($force_recheck |
|
203 | + || ! is_array($this->_payment_method_types) |
|
204 | + || ! isset($this->_payment_method_types[ $payment_method_name ]) |
|
205 | + ) { |
|
206 | + $this->maybe_register_payment_methods($force_recheck); |
|
207 | + } |
|
208 | + if (isset($this->_payment_method_types[ $payment_method_name ])) { |
|
209 | + require_once($this->_payment_method_types[ $payment_method_name ]); |
|
210 | + return true; |
|
211 | + } |
|
212 | + return false; |
|
213 | + } |
|
214 | + |
|
215 | + |
|
216 | + /** |
|
217 | + * Returns all the class names of the various payment method types |
|
218 | + * |
|
219 | + * @param boolean $with_prefixes TRUE: get payment method type class names; false just their 'names' |
|
220 | + * (what you'd find in wp_esp_payment_method.PMD_type) |
|
221 | + * @param boolean $force_recheck whether to force re-checking for new payment method types |
|
222 | + * @return array |
|
223 | + */ |
|
224 | + public function payment_method_type_names($with_prefixes = false, $force_recheck = false) |
|
225 | + { |
|
226 | + $this->maybe_register_payment_methods($force_recheck); |
|
227 | + if ($with_prefixes) { |
|
228 | + $classnames = array_keys($this->_payment_method_types); |
|
229 | + $payment_methods = array(); |
|
230 | + foreach ($classnames as $classname) { |
|
231 | + $payment_methods[] = $this->payment_method_class_from_type($classname); |
|
232 | + } |
|
233 | + return $payment_methods; |
|
234 | + } |
|
235 | + return array_keys($this->_payment_method_types); |
|
236 | + } |
|
237 | + |
|
238 | + |
|
239 | + /** |
|
240 | + * Gets an object of each payment method type, none of which are bound to a |
|
241 | + * payment method instance |
|
242 | + * |
|
243 | + * @param boolean $force_recheck whether to force re-checking for new payment method types |
|
244 | + * @return EE_PMT_Base[] |
|
245 | + */ |
|
246 | + public function payment_method_types($force_recheck = false) |
|
247 | + { |
|
248 | + if ($force_recheck || empty($this->payment_method_objects)) { |
|
249 | + $this->maybe_register_payment_methods($force_recheck); |
|
250 | + foreach ($this->payment_method_type_names(true) as $classname) { |
|
251 | + if (! isset($this->payment_method_objects[ $classname ])) { |
|
252 | + $this->payment_method_objects[ $classname ] = new $classname; |
|
253 | + } |
|
254 | + } |
|
255 | + } |
|
256 | + return $this->payment_method_objects; |
|
257 | + } |
|
258 | + |
|
259 | + |
|
260 | + /** |
|
261 | + * Changes the payment method's class name into the payment method type's name |
|
262 | + * (as used on the payment method's table's PMD_type field) |
|
263 | + * |
|
264 | + * @param string $classname |
|
265 | + * @return string |
|
266 | + */ |
|
267 | + public function payment_method_type_sans_class_prefix($classname) |
|
268 | + { |
|
269 | + return str_replace('EE_PMT_', '', $classname); |
|
270 | + } |
|
271 | + |
|
272 | + |
|
273 | + /** |
|
274 | + * Does the opposite of payment-method_type_sans_prefix |
|
275 | + * |
|
276 | + * @param string $type |
|
277 | + * @return string |
|
278 | + */ |
|
279 | + public function payment_method_class_from_type($type) |
|
280 | + { |
|
281 | + return 'EE_PMT_' . $type; |
|
282 | + } |
|
283 | + |
|
284 | + |
|
285 | + /** |
|
286 | + * Activates a payment method of the given type. |
|
287 | + * |
|
288 | + * @param string $payment_method_type the PMT_type; for EE_PMT_Invoice this would be 'Invoice' |
|
289 | + * @return EE_Payment_Method |
|
290 | + * @throws InvalidDataTypeException |
|
291 | + * @throws EE_Error |
|
292 | + */ |
|
293 | + public function activate_a_payment_method_of_type($payment_method_type) |
|
294 | + { |
|
295 | + $this->maybe_register_payment_methods(); |
|
296 | + $payment_method = EEM_Payment_Method::instance()->get_one_of_type($payment_method_type); |
|
297 | + if (! $payment_method instanceof EE_Payment_Method) { |
|
298 | + $pm_type_class = $this->payment_method_class_from_type($payment_method_type); |
|
299 | + if (class_exists($pm_type_class)) { |
|
300 | + /** @var $pm_type_obj EE_PMT_Base */ |
|
301 | + $pm_type_obj = new $pm_type_class; |
|
302 | + $payment_method = EEM_Payment_Method::instance()->get_one_by_slug($pm_type_obj->system_name()); |
|
303 | + if (! $payment_method) { |
|
304 | + $payment_method = $this->create_payment_method_of_type($pm_type_obj); |
|
305 | + } |
|
306 | + $payment_method->set_type($payment_method_type); |
|
307 | + $this->initialize_payment_method($payment_method); |
|
308 | + } else { |
|
309 | + throw new EE_Error( |
|
310 | + sprintf( |
|
311 | + esc_html__( |
|
312 | + 'There is no payment method of type %1$s, so it could not be activated', |
|
313 | + 'event_espresso' |
|
314 | + ), |
|
315 | + $pm_type_class |
|
316 | + ) |
|
317 | + ); |
|
318 | + } |
|
319 | + } |
|
320 | + $payment_method->set_active(); |
|
321 | + $payment_method->save(); |
|
322 | + /** @type EE_Message_Resource_Manager $message_resource_manager */ |
|
323 | + // if this was the invoice message type, make sure users can view their invoices |
|
324 | + if ($payment_method->type() === 'Invoice' |
|
325 | + && ( |
|
326 | + ! EEH_MSG_Template::is_mt_active('invoice') |
|
327 | + ) |
|
328 | + ) { |
|
329 | + $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
330 | + /** @type EE_Message_Resource_Manager $message_resource_manager */ |
|
331 | + $message_resource_manager->ensure_message_type_is_active('invoice', 'html'); |
|
332 | + new PersistentAdminNotice( |
|
333 | + 'invoice_pm_requirements_notice', |
|
334 | + sprintf( |
|
335 | + esc_html__( |
|
336 | + 'The Invoice payment method has been activated. It requires the %1$sinvoice message%2$s type to be active, so it was automatically activated for you.', |
|
337 | + 'event_espresso' |
|
338 | + ), |
|
339 | + '<a href="' . admin_url('admin.php?page=espresso_messages&action=settings') . '">', |
|
340 | + '</a>' |
|
341 | + ), |
|
342 | + true |
|
343 | + ); |
|
344 | + } |
|
345 | + return $payment_method; |
|
346 | + } |
|
347 | + |
|
348 | + |
|
349 | + /** |
|
350 | + * Creates a payment method of the specified type. Does not save it. |
|
351 | + * |
|
352 | + * @global WP_User $current_user |
|
353 | + * @param EE_PMT_Base $pm_type_obj |
|
354 | + * @return EE_Payment_Method |
|
355 | + * @throws EE_Error |
|
356 | + */ |
|
357 | + public function create_payment_method_of_type($pm_type_obj) |
|
358 | + { |
|
359 | + global $current_user; |
|
360 | + $payment_method = EE_Payment_Method::new_instance( |
|
361 | + array( |
|
362 | + 'PMD_type' => $pm_type_obj->system_name(), |
|
363 | + 'PMD_name' => $pm_type_obj->defaultFrontendName(), |
|
364 | + 'PMD_admin_name' => $pm_type_obj->pretty_name(), |
|
365 | + 'PMD_slug' => $pm_type_obj->system_name(),// automatically converted to slug |
|
366 | + 'PMD_wp_user' => $current_user->ID, |
|
367 | + 'PMD_order' => EEM_Payment_Method::instance()->count( |
|
368 | + array(array('PMD_type' => array('!=', 'Admin_Only'))) |
|
369 | + ) * 10, |
|
370 | + ) |
|
371 | + ); |
|
372 | + return $payment_method; |
|
373 | + } |
|
374 | + |
|
375 | + |
|
376 | + /** |
|
377 | + * Sets the initial payment method properties (including extra meta) |
|
378 | + * |
|
379 | + * @param EE_Payment_Method $payment_method |
|
380 | + * @return EE_Payment_Method |
|
381 | + * @throws EE_Error |
|
382 | + */ |
|
383 | + public function initialize_payment_method($payment_method) |
|
384 | + { |
|
385 | + $pm_type_obj = $payment_method->type_obj(); |
|
386 | + $payment_method->set_description($pm_type_obj->default_description()); |
|
387 | + if (! $payment_method->button_url()) { |
|
388 | + $payment_method->set_button_url($pm_type_obj->default_button_url()); |
|
389 | + } |
|
390 | + // now add setup its default extra meta properties |
|
391 | + $extra_metas = $pm_type_obj->settings_form()->extra_meta_inputs(); |
|
392 | + if (! empty($extra_metas)) { |
|
393 | + // verify the payment method has an ID before adding extra meta |
|
394 | + if (! $payment_method->ID()) { |
|
395 | + $payment_method->save(); |
|
396 | + } |
|
397 | + foreach ($extra_metas as $meta_name => $input) { |
|
398 | + $payment_method->update_extra_meta($meta_name, $input->raw_value()); |
|
399 | + } |
|
400 | + } |
|
401 | + return $payment_method; |
|
402 | + } |
|
403 | + |
|
404 | + |
|
405 | + /** |
|
406 | + * Makes sure the payment method is related to the specified payment method |
|
407 | + * |
|
408 | + * @deprecated in 4.9.40 because the currency payment method table is being deprecated |
|
409 | + * @param EE_Payment_Method $payment_method |
|
410 | + * @return EE_Payment_Method |
|
411 | + * @throws EE_Error |
|
412 | + */ |
|
413 | + public function set_usable_currencies_on_payment_method($payment_method) |
|
414 | + { |
|
415 | + EE_Error::doing_it_wrong( |
|
416 | + 'EE_Payment_Method_Manager::set_usable_currencies_on_payment_method', |
|
417 | + esc_html__( |
|
418 | + 'We no longer define what currencies are usable by payment methods. Its not used nor efficient.', |
|
419 | + 'event_espresso' |
|
420 | + ), |
|
421 | + '4.9.40' |
|
422 | + ); |
|
423 | + return $payment_method; |
|
424 | + } |
|
425 | + |
|
426 | + |
|
427 | + /** |
|
428 | + * Deactivates a payment method of the given payment method slug. |
|
429 | + * |
|
430 | + * @param string $payment_method_slug The slug for the payment method to deactivate. |
|
431 | + * @return int count of rows updated. |
|
432 | + * @throws EE_Error |
|
433 | + */ |
|
434 | + public function deactivate_payment_method($payment_method_slug) |
|
435 | + { |
|
436 | + EE_Log::instance()->log( |
|
437 | + __FILE__, |
|
438 | + __FUNCTION__, |
|
439 | + sprintf( |
|
440 | + esc_html__( |
|
441 | + 'Payment method with slug %1$s is being deactivated by site admin', |
|
442 | + 'event_espresso' |
|
443 | + ), |
|
444 | + $payment_method_slug |
|
445 | + ), |
|
446 | + 'payment_method_change' |
|
447 | + ); |
|
448 | + $count_updated = EEM_Payment_Method::instance()->update( |
|
449 | + array('PMD_scope' => array()), |
|
450 | + array(array('PMD_slug' => $payment_method_slug)) |
|
451 | + ); |
|
452 | + do_action( |
|
453 | + 'AHEE__EE_Payment_Method_Manager__deactivate_payment_method__after_deactivating_payment_method', |
|
454 | + $payment_method_slug, |
|
455 | + $count_updated |
|
456 | + ); |
|
457 | + return $count_updated; |
|
458 | + } |
|
459 | + |
|
460 | + |
|
461 | + /** |
|
462 | + * initializes payment method access caps via EE_Capabilities::init_role_caps() |
|
463 | + * upon EE_Payment_Method_Manager construction |
|
464 | + * |
|
465 | + * @throws EE_Error |
|
466 | + * @throws DomainException |
|
467 | + */ |
|
468 | + protected function initializePaymentMethodCaps() |
|
469 | + { |
|
470 | + // don't do this twice |
|
471 | + if ($this->payment_method_caps_initialized) { |
|
472 | + return; |
|
473 | + } |
|
474 | + EE_Capabilities::instance()->addCaps( |
|
475 | + $this->getPaymentMethodCaps() |
|
476 | + ); |
|
477 | + $this->payment_method_caps_initialized = true; |
|
478 | + } |
|
479 | + |
|
480 | + |
|
481 | + /** |
|
482 | + * array of dynamic payment method access caps. |
|
483 | + * at the time of writing, october 20 2014, these are the caps added: |
|
484 | + * ee_payment_method_admin_only |
|
485 | + * ee_payment_method_aim |
|
486 | + * ee_payment_method_bank |
|
487 | + * ee_payment_method_check |
|
488 | + * ee_payment_method_invoice |
|
489 | + * ee_payment_method_mijireh |
|
490 | + * ee_payment_method_paypal_pro |
|
491 | + * ee_payment_method_paypal_standard |
|
492 | + * Any other payment methods added to core or via addons will also get |
|
493 | + * their related capability automatically added too, so long as they are |
|
494 | + * registered properly using EE_Register_Payment_Method::register() |
|
495 | + * |
|
496 | + * @return array |
|
497 | + * @throws DomainException |
|
498 | + */ |
|
499 | + protected function getPaymentMethodCaps() |
|
500 | + { |
|
501 | + $caps = array(); |
|
502 | + foreach ($this->payment_method_type_names() as $payment_method_name) { |
|
503 | + $caps = $this->addPaymentMethodCap($payment_method_name, $caps); |
|
504 | + } |
|
505 | + return $caps; |
|
506 | + } |
|
507 | + |
|
508 | + |
|
509 | + /** |
|
510 | + * @param string $payment_method_name |
|
511 | + * @param array $payment_method_caps |
|
512 | + * @param string $role |
|
513 | + * @return array |
|
514 | + * @throws DomainException |
|
515 | + */ |
|
516 | + public function addPaymentMethodCap($payment_method_name, array $payment_method_caps, $role = 'administrator') |
|
517 | + { |
|
518 | + if (empty($payment_method_name)) { |
|
519 | + throw new DomainException( |
|
520 | + esc_html__( |
|
521 | + 'The name of a payment method must be specified to add capabilities.', |
|
522 | + 'event_espresso' |
|
523 | + ) |
|
524 | + ); |
|
525 | + } |
|
526 | + if (empty($role)) { |
|
527 | + throw new DomainException( |
|
528 | + sprintf( |
|
529 | + esc_html__( |
|
530 | + 'No role was supplied while trying to add capabilities for the %1$s payment method.', |
|
531 | + 'event_espresso' |
|
532 | + ), |
|
533 | + $payment_method_name |
|
534 | + ) |
|
535 | + ); |
|
536 | + } |
|
537 | + if (! isset($payment_method_caps[ $role ])) { |
|
538 | + $payment_method_caps[ $role ] = array(); |
|
539 | + } |
|
540 | + $payment_method_caps[ $role ][] = EE_Payment_Method_Manager::CAPABILITIES_PREFIX |
|
541 | + . strtolower($payment_method_name); |
|
542 | + return $payment_method_caps; |
|
543 | + } |
|
544 | + |
|
545 | + |
|
546 | + /** |
|
547 | + * callback for FHEE__EE_Capabilities__init_role_caps__caps_map filter |
|
548 | + * to add dynamic payment method access caps when capabilities are reset |
|
549 | + * (or if that filter is called and PM caps are not already set) |
|
550 | + * |
|
551 | + * @param array $caps capabilities being filtered |
|
552 | + * @param bool $reset |
|
553 | + * @return array |
|
554 | + * @throws DomainException |
|
555 | + */ |
|
556 | + public function addPaymentMethodCapsDuringReset(array $caps, $reset = false) |
|
557 | + { |
|
558 | + if ($reset || ! $this->payment_method_caps_initialized) { |
|
559 | + $this->payment_method_caps_initialized = true; |
|
560 | + $caps = array_merge_recursive($caps, $this->getPaymentMethodCaps()); |
|
561 | + } |
|
562 | + return $caps; |
|
563 | + } |
|
564 | + |
|
565 | + |
|
566 | + /** |
|
567 | + * @deprecated 4.9.42 |
|
568 | + * @param $caps |
|
569 | + * @return mixed |
|
570 | + */ |
|
571 | + public function add_payment_method_caps($caps) |
|
572 | + { |
|
573 | + return $caps; |
|
574 | + } |
|
575 | 575 | } |
@@ -74,7 +74,7 @@ discard block |
||
74 | 74 | public static function instance() |
75 | 75 | { |
76 | 76 | // check if class object is instantiated, and instantiated properly |
77 | - if (! self::$_instance instanceof EE_Payment_Method_Manager) { |
|
77 | + if ( ! self::$_instance instanceof EE_Payment_Method_Manager) { |
|
78 | 78 | EE_Registry::instance()->load_lib('PMT_Base'); |
79 | 79 | self::$_instance = new self(); |
80 | 80 | } |
@@ -105,7 +105,7 @@ discard block |
||
105 | 105 | */ |
106 | 106 | public function maybe_register_payment_methods($force_recheck = false) |
107 | 107 | { |
108 | - if (! $this->_payment_method_types || $force_recheck) { |
|
108 | + if ( ! $this->_payment_method_types || $force_recheck) { |
|
109 | 109 | $this->_register_payment_methods(); |
110 | 110 | } |
111 | 111 | } |
@@ -119,7 +119,7 @@ discard block |
||
119 | 119 | protected function _register_payment_methods() |
120 | 120 | { |
121 | 121 | // grab list of installed modules |
122 | - $pm_to_register = glob(EE_PAYMENT_METHODS . '*', GLOB_ONLYDIR); |
|
122 | + $pm_to_register = glob(EE_PAYMENT_METHODS.'*', GLOB_ONLYDIR); |
|
123 | 123 | // filter list of modules to register |
124 | 124 | $pm_to_register = apply_filters( |
125 | 125 | 'FHEE__EE_Payment_Method_Manager__register_payment_methods__payment_methods_to_register', |
@@ -159,9 +159,9 @@ discard block |
||
159 | 159 | // create class name from module directory name |
160 | 160 | $module = str_replace(array('_', ' '), array(' ', '_'), $module_dir); |
161 | 161 | // add class prefix |
162 | - $module_class = 'EE_PMT_' . $module; |
|
162 | + $module_class = 'EE_PMT_'.$module; |
|
163 | 163 | // does the module exist ? |
164 | - if (! is_readable($payment_method_path . '/' . $module_class . $module_ext)) { |
|
164 | + if ( ! is_readable($payment_method_path.'/'.$module_class.$module_ext)) { |
|
165 | 165 | $msg = sprintf( |
166 | 166 | esc_html__( |
167 | 167 | 'The requested %s payment method file could not be found or is not readable due to file permissions.', |
@@ -169,22 +169,22 @@ discard block |
||
169 | 169 | ), |
170 | 170 | $module |
171 | 171 | ); |
172 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
172 | + EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__); |
|
173 | 173 | return false; |
174 | 174 | } |
175 | 175 | // load the module class file |
176 | - require_once($payment_method_path . '/' . $module_class . $module_ext); |
|
176 | + require_once($payment_method_path.'/'.$module_class.$module_ext); |
|
177 | 177 | // verify that class exists |
178 | - if (! class_exists($module_class)) { |
|
178 | + if ( ! class_exists($module_class)) { |
|
179 | 179 | $msg = sprintf( |
180 | 180 | esc_html__('The requested %s module class does not exist.', 'event_espresso'), |
181 | 181 | $module_class |
182 | 182 | ); |
183 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
183 | + EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__); |
|
184 | 184 | return false; |
185 | 185 | } |
186 | 186 | // add to array of registered modules |
187 | - $this->_payment_method_types[ $module ] = $payment_method_path . '/' . $module_class . $module_ext; |
|
187 | + $this->_payment_method_types[$module] = $payment_method_path.'/'.$module_class.$module_ext; |
|
188 | 188 | ksort($this->_payment_method_types); |
189 | 189 | return true; |
190 | 190 | } |
@@ -201,12 +201,12 @@ discard block |
||
201 | 201 | { |
202 | 202 | if ($force_recheck |
203 | 203 | || ! is_array($this->_payment_method_types) |
204 | - || ! isset($this->_payment_method_types[ $payment_method_name ]) |
|
204 | + || ! isset($this->_payment_method_types[$payment_method_name]) |
|
205 | 205 | ) { |
206 | 206 | $this->maybe_register_payment_methods($force_recheck); |
207 | 207 | } |
208 | - if (isset($this->_payment_method_types[ $payment_method_name ])) { |
|
209 | - require_once($this->_payment_method_types[ $payment_method_name ]); |
|
208 | + if (isset($this->_payment_method_types[$payment_method_name])) { |
|
209 | + require_once($this->_payment_method_types[$payment_method_name]); |
|
210 | 210 | return true; |
211 | 211 | } |
212 | 212 | return false; |
@@ -248,8 +248,8 @@ discard block |
||
248 | 248 | if ($force_recheck || empty($this->payment_method_objects)) { |
249 | 249 | $this->maybe_register_payment_methods($force_recheck); |
250 | 250 | foreach ($this->payment_method_type_names(true) as $classname) { |
251 | - if (! isset($this->payment_method_objects[ $classname ])) { |
|
252 | - $this->payment_method_objects[ $classname ] = new $classname; |
|
251 | + if ( ! isset($this->payment_method_objects[$classname])) { |
|
252 | + $this->payment_method_objects[$classname] = new $classname; |
|
253 | 253 | } |
254 | 254 | } |
255 | 255 | } |
@@ -278,7 +278,7 @@ discard block |
||
278 | 278 | */ |
279 | 279 | public function payment_method_class_from_type($type) |
280 | 280 | { |
281 | - return 'EE_PMT_' . $type; |
|
281 | + return 'EE_PMT_'.$type; |
|
282 | 282 | } |
283 | 283 | |
284 | 284 | |
@@ -294,13 +294,13 @@ discard block |
||
294 | 294 | { |
295 | 295 | $this->maybe_register_payment_methods(); |
296 | 296 | $payment_method = EEM_Payment_Method::instance()->get_one_of_type($payment_method_type); |
297 | - if (! $payment_method instanceof EE_Payment_Method) { |
|
297 | + if ( ! $payment_method instanceof EE_Payment_Method) { |
|
298 | 298 | $pm_type_class = $this->payment_method_class_from_type($payment_method_type); |
299 | 299 | if (class_exists($pm_type_class)) { |
300 | 300 | /** @var $pm_type_obj EE_PMT_Base */ |
301 | 301 | $pm_type_obj = new $pm_type_class; |
302 | 302 | $payment_method = EEM_Payment_Method::instance()->get_one_by_slug($pm_type_obj->system_name()); |
303 | - if (! $payment_method) { |
|
303 | + if ( ! $payment_method) { |
|
304 | 304 | $payment_method = $this->create_payment_method_of_type($pm_type_obj); |
305 | 305 | } |
306 | 306 | $payment_method->set_type($payment_method_type); |
@@ -336,7 +336,7 @@ discard block |
||
336 | 336 | 'The Invoice payment method has been activated. It requires the %1$sinvoice message%2$s type to be active, so it was automatically activated for you.', |
337 | 337 | 'event_espresso' |
338 | 338 | ), |
339 | - '<a href="' . admin_url('admin.php?page=espresso_messages&action=settings') . '">', |
|
339 | + '<a href="'.admin_url('admin.php?page=espresso_messages&action=settings').'">', |
|
340 | 340 | '</a>' |
341 | 341 | ), |
342 | 342 | true |
@@ -362,7 +362,7 @@ discard block |
||
362 | 362 | 'PMD_type' => $pm_type_obj->system_name(), |
363 | 363 | 'PMD_name' => $pm_type_obj->defaultFrontendName(), |
364 | 364 | 'PMD_admin_name' => $pm_type_obj->pretty_name(), |
365 | - 'PMD_slug' => $pm_type_obj->system_name(),// automatically converted to slug |
|
365 | + 'PMD_slug' => $pm_type_obj->system_name(), // automatically converted to slug |
|
366 | 366 | 'PMD_wp_user' => $current_user->ID, |
367 | 367 | 'PMD_order' => EEM_Payment_Method::instance()->count( |
368 | 368 | array(array('PMD_type' => array('!=', 'Admin_Only'))) |
@@ -384,14 +384,14 @@ discard block |
||
384 | 384 | { |
385 | 385 | $pm_type_obj = $payment_method->type_obj(); |
386 | 386 | $payment_method->set_description($pm_type_obj->default_description()); |
387 | - if (! $payment_method->button_url()) { |
|
387 | + if ( ! $payment_method->button_url()) { |
|
388 | 388 | $payment_method->set_button_url($pm_type_obj->default_button_url()); |
389 | 389 | } |
390 | 390 | // now add setup its default extra meta properties |
391 | 391 | $extra_metas = $pm_type_obj->settings_form()->extra_meta_inputs(); |
392 | - if (! empty($extra_metas)) { |
|
392 | + if ( ! empty($extra_metas)) { |
|
393 | 393 | // verify the payment method has an ID before adding extra meta |
394 | - if (! $payment_method->ID()) { |
|
394 | + if ( ! $payment_method->ID()) { |
|
395 | 395 | $payment_method->save(); |
396 | 396 | } |
397 | 397 | foreach ($extra_metas as $meta_name => $input) { |
@@ -534,10 +534,10 @@ discard block |
||
534 | 534 | ) |
535 | 535 | ); |
536 | 536 | } |
537 | - if (! isset($payment_method_caps[ $role ])) { |
|
538 | - $payment_method_caps[ $role ] = array(); |
|
537 | + if ( ! isset($payment_method_caps[$role])) { |
|
538 | + $payment_method_caps[$role] = array(); |
|
539 | 539 | } |
540 | - $payment_method_caps[ $role ][] = EE_Payment_Method_Manager::CAPABILITIES_PREFIX |
|
540 | + $payment_method_caps[$role][] = EE_Payment_Method_Manager::CAPABILITIES_PREFIX |
|
541 | 541 | . strtolower($payment_method_name); |
542 | 542 | return $payment_method_caps; |
543 | 543 | } |
@@ -16,127 +16,127 @@ |
||
16 | 16 | |
17 | 17 | |
18 | 18 | |
19 | - /** |
|
20 | - * @type EE_Messenger_Collection $_messenger_collection |
|
21 | - */ |
|
22 | - protected $_messenger_collection = null; |
|
23 | - |
|
24 | - |
|
25 | - |
|
26 | - /** |
|
27 | - * EE_Messenger_Collection_Loader constructor. |
|
28 | - * |
|
29 | - * @param EE_Messenger_Collection $messengers |
|
30 | - */ |
|
31 | - public function __construct(EE_Messenger_Collection $messengers) |
|
32 | - { |
|
33 | - $this->set_messenger_collection($messengers); |
|
34 | - } |
|
35 | - |
|
36 | - |
|
37 | - |
|
38 | - /** |
|
39 | - * @return EE_Messenger_Collection |
|
40 | - */ |
|
41 | - public function messenger_collection() |
|
42 | - { |
|
43 | - return $this->_messenger_collection; |
|
44 | - } |
|
45 | - |
|
46 | - |
|
47 | - |
|
48 | - /** |
|
49 | - * @param mixed $messengers |
|
50 | - */ |
|
51 | - public function set_messenger_collection(EE_Messenger_Collection $messengers) |
|
52 | - { |
|
53 | - $this->_messenger_collection = $messengers; |
|
54 | - } |
|
55 | - |
|
56 | - |
|
57 | - |
|
58 | - /** |
|
59 | - * load_messengers |
|
60 | - * globs the supplied filepath and adds any found |
|
61 | - * |
|
62 | - * @param string $folder |
|
63 | - * @throws \EE_Error |
|
64 | - */ |
|
65 | - public function load_messengers_from_folder($folder = '') |
|
66 | - { |
|
67 | - // make sure autoloaders are set (fail-safe) |
|
68 | - EED_Messages::set_autoloaders(); |
|
69 | - $folder = ! empty($folder) ? $folder : EE_LIBRARIES . 'messages/messenger'; |
|
70 | - $folder .= $folder[ strlen($folder) - 1 ] != '/' ? '/' : ''; |
|
71 | - // get all the files in that folder that end in ".class.php |
|
72 | - $filepaths = apply_filters( |
|
73 | - 'FHEE__EE_messages__get_installed__messenger_files', |
|
74 | - glob($folder . '*.class.php') |
|
75 | - ); |
|
76 | - if (empty($filepaths)) { |
|
77 | - return; |
|
78 | - } |
|
79 | - foreach ((array) $filepaths as $file_path) { |
|
80 | - // extract filename from path |
|
81 | - $file_path = basename($file_path); |
|
82 | - // now remove any file extensions |
|
83 | - $messenger_class_name = substr($file_path, 0, strpos($file_path, '.')); |
|
84 | - |
|
85 | - // first check to see if the class name represents an actual messenger class. |
|
86 | - if (strpos(strtolower($messenger_class_name), 'messenger') === false) { |
|
87 | - continue; |
|
88 | - } |
|
89 | - |
|
90 | - if (! class_exists($messenger_class_name)) { |
|
91 | - throw new EE_Error( |
|
92 | - sprintf( |
|
93 | - __('The "%1$s" messenger class can\'t be loaded from %2$s. Likely there is a typo in the class name or the file name.', 'event_espresso'), |
|
94 | - $messenger_class_name, |
|
95 | - $file_path |
|
96 | - ) |
|
97 | - ); |
|
98 | - } |
|
99 | - |
|
100 | - $this->_load_messenger(new $messenger_class_name()); |
|
101 | - } |
|
102 | - } |
|
103 | - |
|
104 | - |
|
105 | - /** |
|
106 | - * load_messengers |
|
107 | - * globs the supplied filepath and adds any found |
|
108 | - * |
|
109 | - * @return array |
|
110 | - */ |
|
111 | - public function load_active_messengers_from_db() |
|
112 | - { |
|
113 | - // make sure autoloaders are set (fail-safe) |
|
114 | - EED_Messages::set_autoloaders(); |
|
115 | - $active_messengers = apply_filters( |
|
116 | - 'FHEE__EEH_MSG_Template__get_active_messengers_in_db', |
|
117 | - get_option('ee_active_messengers', array()) |
|
118 | - ); |
|
119 | - foreach ((array) $active_messengers as $active_messenger_classname => $active_messenger) { |
|
120 | - $this->_load_messenger($active_messenger); |
|
121 | - } |
|
122 | - } |
|
123 | - |
|
124 | - |
|
125 | - |
|
126 | - /** |
|
127 | - * load_messenger |
|
128 | - * |
|
129 | - * @param \EE_messenger $messenger |
|
130 | - * @return bool |
|
131 | - */ |
|
132 | - protected function _load_messenger(EE_messenger $messenger) |
|
133 | - { |
|
134 | - if ($this->messenger_collection()->has_by_name($messenger->name)) { |
|
135 | - return true; |
|
136 | - } |
|
137 | - return $this->messenger_collection()->add( |
|
138 | - $messenger, |
|
139 | - $messenger->name |
|
140 | - ); |
|
141 | - } |
|
19 | + /** |
|
20 | + * @type EE_Messenger_Collection $_messenger_collection |
|
21 | + */ |
|
22 | + protected $_messenger_collection = null; |
|
23 | + |
|
24 | + |
|
25 | + |
|
26 | + /** |
|
27 | + * EE_Messenger_Collection_Loader constructor. |
|
28 | + * |
|
29 | + * @param EE_Messenger_Collection $messengers |
|
30 | + */ |
|
31 | + public function __construct(EE_Messenger_Collection $messengers) |
|
32 | + { |
|
33 | + $this->set_messenger_collection($messengers); |
|
34 | + } |
|
35 | + |
|
36 | + |
|
37 | + |
|
38 | + /** |
|
39 | + * @return EE_Messenger_Collection |
|
40 | + */ |
|
41 | + public function messenger_collection() |
|
42 | + { |
|
43 | + return $this->_messenger_collection; |
|
44 | + } |
|
45 | + |
|
46 | + |
|
47 | + |
|
48 | + /** |
|
49 | + * @param mixed $messengers |
|
50 | + */ |
|
51 | + public function set_messenger_collection(EE_Messenger_Collection $messengers) |
|
52 | + { |
|
53 | + $this->_messenger_collection = $messengers; |
|
54 | + } |
|
55 | + |
|
56 | + |
|
57 | + |
|
58 | + /** |
|
59 | + * load_messengers |
|
60 | + * globs the supplied filepath and adds any found |
|
61 | + * |
|
62 | + * @param string $folder |
|
63 | + * @throws \EE_Error |
|
64 | + */ |
|
65 | + public function load_messengers_from_folder($folder = '') |
|
66 | + { |
|
67 | + // make sure autoloaders are set (fail-safe) |
|
68 | + EED_Messages::set_autoloaders(); |
|
69 | + $folder = ! empty($folder) ? $folder : EE_LIBRARIES . 'messages/messenger'; |
|
70 | + $folder .= $folder[ strlen($folder) - 1 ] != '/' ? '/' : ''; |
|
71 | + // get all the files in that folder that end in ".class.php |
|
72 | + $filepaths = apply_filters( |
|
73 | + 'FHEE__EE_messages__get_installed__messenger_files', |
|
74 | + glob($folder . '*.class.php') |
|
75 | + ); |
|
76 | + if (empty($filepaths)) { |
|
77 | + return; |
|
78 | + } |
|
79 | + foreach ((array) $filepaths as $file_path) { |
|
80 | + // extract filename from path |
|
81 | + $file_path = basename($file_path); |
|
82 | + // now remove any file extensions |
|
83 | + $messenger_class_name = substr($file_path, 0, strpos($file_path, '.')); |
|
84 | + |
|
85 | + // first check to see if the class name represents an actual messenger class. |
|
86 | + if (strpos(strtolower($messenger_class_name), 'messenger') === false) { |
|
87 | + continue; |
|
88 | + } |
|
89 | + |
|
90 | + if (! class_exists($messenger_class_name)) { |
|
91 | + throw new EE_Error( |
|
92 | + sprintf( |
|
93 | + __('The "%1$s" messenger class can\'t be loaded from %2$s. Likely there is a typo in the class name or the file name.', 'event_espresso'), |
|
94 | + $messenger_class_name, |
|
95 | + $file_path |
|
96 | + ) |
|
97 | + ); |
|
98 | + } |
|
99 | + |
|
100 | + $this->_load_messenger(new $messenger_class_name()); |
|
101 | + } |
|
102 | + } |
|
103 | + |
|
104 | + |
|
105 | + /** |
|
106 | + * load_messengers |
|
107 | + * globs the supplied filepath and adds any found |
|
108 | + * |
|
109 | + * @return array |
|
110 | + */ |
|
111 | + public function load_active_messengers_from_db() |
|
112 | + { |
|
113 | + // make sure autoloaders are set (fail-safe) |
|
114 | + EED_Messages::set_autoloaders(); |
|
115 | + $active_messengers = apply_filters( |
|
116 | + 'FHEE__EEH_MSG_Template__get_active_messengers_in_db', |
|
117 | + get_option('ee_active_messengers', array()) |
|
118 | + ); |
|
119 | + foreach ((array) $active_messengers as $active_messenger_classname => $active_messenger) { |
|
120 | + $this->_load_messenger($active_messenger); |
|
121 | + } |
|
122 | + } |
|
123 | + |
|
124 | + |
|
125 | + |
|
126 | + /** |
|
127 | + * load_messenger |
|
128 | + * |
|
129 | + * @param \EE_messenger $messenger |
|
130 | + * @return bool |
|
131 | + */ |
|
132 | + protected function _load_messenger(EE_messenger $messenger) |
|
133 | + { |
|
134 | + if ($this->messenger_collection()->has_by_name($messenger->name)) { |
|
135 | + return true; |
|
136 | + } |
|
137 | + return $this->messenger_collection()->add( |
|
138 | + $messenger, |
|
139 | + $messenger->name |
|
140 | + ); |
|
141 | + } |
|
142 | 142 | } |
@@ -66,12 +66,12 @@ discard block |
||
66 | 66 | { |
67 | 67 | // make sure autoloaders are set (fail-safe) |
68 | 68 | EED_Messages::set_autoloaders(); |
69 | - $folder = ! empty($folder) ? $folder : EE_LIBRARIES . 'messages/messenger'; |
|
70 | - $folder .= $folder[ strlen($folder) - 1 ] != '/' ? '/' : ''; |
|
69 | + $folder = ! empty($folder) ? $folder : EE_LIBRARIES.'messages/messenger'; |
|
70 | + $folder .= $folder[strlen($folder) - 1] != '/' ? '/' : ''; |
|
71 | 71 | // get all the files in that folder that end in ".class.php |
72 | 72 | $filepaths = apply_filters( |
73 | 73 | 'FHEE__EE_messages__get_installed__messenger_files', |
74 | - glob($folder . '*.class.php') |
|
74 | + glob($folder.'*.class.php') |
|
75 | 75 | ); |
76 | 76 | if (empty($filepaths)) { |
77 | 77 | return; |
@@ -87,7 +87,7 @@ discard block |
||
87 | 87 | continue; |
88 | 88 | } |
89 | 89 | |
90 | - if (! class_exists($messenger_class_name)) { |
|
90 | + if ( ! class_exists($messenger_class_name)) { |
|
91 | 91 | throw new EE_Error( |
92 | 92 | sprintf( |
93 | 93 | __('The "%1$s" messenger class can\'t be loaded from %2$s. Likely there is a typo in the class name or the file name.', 'event_espresso'), |
@@ -15,105 +15,105 @@ |
||
15 | 15 | { |
16 | 16 | |
17 | 17 | |
18 | - /** |
|
19 | - * @type EE_Message_Type_Collection $_message_type_collection |
|
20 | - */ |
|
21 | - protected $_message_type_collection = null; |
|
22 | - |
|
23 | - |
|
24 | - |
|
25 | - /** |
|
26 | - * EE_Message_Type_Collection_Loader constructor. |
|
27 | - * |
|
28 | - * @param EE_Message_Type_Collection $message_types |
|
29 | - */ |
|
30 | - public function __construct(EE_Message_Type_Collection $message_types) |
|
31 | - { |
|
32 | - $this->set_message_type_collection($message_types); |
|
33 | - } |
|
34 | - |
|
35 | - |
|
36 | - |
|
37 | - /** |
|
38 | - * @return EE_Message_Type_Collection |
|
39 | - */ |
|
40 | - public function message_type_collection() |
|
41 | - { |
|
42 | - return $this->_message_type_collection; |
|
43 | - } |
|
44 | - |
|
45 | - |
|
46 | - |
|
47 | - /** |
|
48 | - * @param mixed $message_types |
|
49 | - */ |
|
50 | - public function set_message_type_collection(EE_Message_Type_Collection $message_types) |
|
51 | - { |
|
52 | - $this->_message_type_collection = $message_types; |
|
53 | - } |
|
54 | - |
|
55 | - |
|
56 | - |
|
57 | - /** |
|
58 | - * load_message_types |
|
59 | - * globs the supplied filepath and adds any found |
|
60 | - * |
|
61 | - * @param string $folder |
|
62 | - * @throws \EE_Error |
|
63 | - */ |
|
64 | - public function load_message_types_from_folder($folder = '') |
|
65 | - { |
|
66 | - // make sure autoloaders are set (fail-safe) |
|
67 | - EED_Messages::set_autoloaders(); |
|
68 | - $folder = ! empty($folder) ? $folder : EE_LIBRARIES . 'messages/message_type'; |
|
69 | - $folder .= $folder[ strlen($folder) - 1 ] != '/' ? '/' : ''; |
|
70 | - // get all the files in that folder that end in ".class.php |
|
71 | - $filepaths = apply_filters( |
|
72 | - 'FHEE__EE_messages__get_installed__messagetype_files', |
|
73 | - glob($folder . '*.class.php') |
|
74 | - ); |
|
75 | - if (empty($filepaths)) { |
|
76 | - return; |
|
77 | - } |
|
78 | - foreach ((array) $filepaths as $file_path) { |
|
79 | - // extract filename from path |
|
80 | - $file_path = basename($file_path); |
|
81 | - // now remove any file extensions |
|
82 | - $message_type_class_name = substr($file_path, 0, strpos($file_path, '.')); |
|
83 | - |
|
84 | - // if this class name doesn't represent a message type class, then we just skip. |
|
85 | - if (strpos(strtolower($message_type_class_name), 'message_type') === false) { |
|
86 | - continue; |
|
87 | - } |
|
88 | - |
|
89 | - if (! class_exists($message_type_class_name)) { |
|
90 | - throw new EE_Error( |
|
91 | - sprintf( |
|
92 | - __('The "%1$s" message type class can\'t be loaded from %2$s. Likely there is a typo in the class name or the file name.', 'event_espresso'), |
|
93 | - $message_type_class_name, |
|
94 | - $file_path |
|
95 | - ) |
|
96 | - ); |
|
97 | - } |
|
98 | - |
|
99 | - $this->_load_message_type(new $message_type_class_name); |
|
100 | - } |
|
101 | - } |
|
102 | - |
|
103 | - |
|
104 | - /** |
|
105 | - * Loads the given message type into the message type collection if it doesn't already exist. |
|
106 | - * @param EE_message_type $message_type |
|
107 | - * @return bool |
|
108 | - */ |
|
109 | - protected function _load_message_type(EE_message_type $message_type) |
|
110 | - { |
|
111 | - if ($this->message_type_collection()->has_by_name($message_type->name)) { |
|
112 | - return true; |
|
113 | - } |
|
114 | - return $this->message_type_collection()->add( |
|
115 | - $message_type, |
|
116 | - $message_type->name |
|
117 | - ); |
|
118 | - } |
|
18 | + /** |
|
19 | + * @type EE_Message_Type_Collection $_message_type_collection |
|
20 | + */ |
|
21 | + protected $_message_type_collection = null; |
|
22 | + |
|
23 | + |
|
24 | + |
|
25 | + /** |
|
26 | + * EE_Message_Type_Collection_Loader constructor. |
|
27 | + * |
|
28 | + * @param EE_Message_Type_Collection $message_types |
|
29 | + */ |
|
30 | + public function __construct(EE_Message_Type_Collection $message_types) |
|
31 | + { |
|
32 | + $this->set_message_type_collection($message_types); |
|
33 | + } |
|
34 | + |
|
35 | + |
|
36 | + |
|
37 | + /** |
|
38 | + * @return EE_Message_Type_Collection |
|
39 | + */ |
|
40 | + public function message_type_collection() |
|
41 | + { |
|
42 | + return $this->_message_type_collection; |
|
43 | + } |
|
44 | + |
|
45 | + |
|
46 | + |
|
47 | + /** |
|
48 | + * @param mixed $message_types |
|
49 | + */ |
|
50 | + public function set_message_type_collection(EE_Message_Type_Collection $message_types) |
|
51 | + { |
|
52 | + $this->_message_type_collection = $message_types; |
|
53 | + } |
|
54 | + |
|
55 | + |
|
56 | + |
|
57 | + /** |
|
58 | + * load_message_types |
|
59 | + * globs the supplied filepath and adds any found |
|
60 | + * |
|
61 | + * @param string $folder |
|
62 | + * @throws \EE_Error |
|
63 | + */ |
|
64 | + public function load_message_types_from_folder($folder = '') |
|
65 | + { |
|
66 | + // make sure autoloaders are set (fail-safe) |
|
67 | + EED_Messages::set_autoloaders(); |
|
68 | + $folder = ! empty($folder) ? $folder : EE_LIBRARIES . 'messages/message_type'; |
|
69 | + $folder .= $folder[ strlen($folder) - 1 ] != '/' ? '/' : ''; |
|
70 | + // get all the files in that folder that end in ".class.php |
|
71 | + $filepaths = apply_filters( |
|
72 | + 'FHEE__EE_messages__get_installed__messagetype_files', |
|
73 | + glob($folder . '*.class.php') |
|
74 | + ); |
|
75 | + if (empty($filepaths)) { |
|
76 | + return; |
|
77 | + } |
|
78 | + foreach ((array) $filepaths as $file_path) { |
|
79 | + // extract filename from path |
|
80 | + $file_path = basename($file_path); |
|
81 | + // now remove any file extensions |
|
82 | + $message_type_class_name = substr($file_path, 0, strpos($file_path, '.')); |
|
83 | + |
|
84 | + // if this class name doesn't represent a message type class, then we just skip. |
|
85 | + if (strpos(strtolower($message_type_class_name), 'message_type') === false) { |
|
86 | + continue; |
|
87 | + } |
|
88 | + |
|
89 | + if (! class_exists($message_type_class_name)) { |
|
90 | + throw new EE_Error( |
|
91 | + sprintf( |
|
92 | + __('The "%1$s" message type class can\'t be loaded from %2$s. Likely there is a typo in the class name or the file name.', 'event_espresso'), |
|
93 | + $message_type_class_name, |
|
94 | + $file_path |
|
95 | + ) |
|
96 | + ); |
|
97 | + } |
|
98 | + |
|
99 | + $this->_load_message_type(new $message_type_class_name); |
|
100 | + } |
|
101 | + } |
|
102 | + |
|
103 | + |
|
104 | + /** |
|
105 | + * Loads the given message type into the message type collection if it doesn't already exist. |
|
106 | + * @param EE_message_type $message_type |
|
107 | + * @return bool |
|
108 | + */ |
|
109 | + protected function _load_message_type(EE_message_type $message_type) |
|
110 | + { |
|
111 | + if ($this->message_type_collection()->has_by_name($message_type->name)) { |
|
112 | + return true; |
|
113 | + } |
|
114 | + return $this->message_type_collection()->add( |
|
115 | + $message_type, |
|
116 | + $message_type->name |
|
117 | + ); |
|
118 | + } |
|
119 | 119 | } |
@@ -65,12 +65,12 @@ discard block |
||
65 | 65 | { |
66 | 66 | // make sure autoloaders are set (fail-safe) |
67 | 67 | EED_Messages::set_autoloaders(); |
68 | - $folder = ! empty($folder) ? $folder : EE_LIBRARIES . 'messages/message_type'; |
|
69 | - $folder .= $folder[ strlen($folder) - 1 ] != '/' ? '/' : ''; |
|
68 | + $folder = ! empty($folder) ? $folder : EE_LIBRARIES.'messages/message_type'; |
|
69 | + $folder .= $folder[strlen($folder) - 1] != '/' ? '/' : ''; |
|
70 | 70 | // get all the files in that folder that end in ".class.php |
71 | 71 | $filepaths = apply_filters( |
72 | 72 | 'FHEE__EE_messages__get_installed__messagetype_files', |
73 | - glob($folder . '*.class.php') |
|
73 | + glob($folder.'*.class.php') |
|
74 | 74 | ); |
75 | 75 | if (empty($filepaths)) { |
76 | 76 | return; |
@@ -86,7 +86,7 @@ discard block |
||
86 | 86 | continue; |
87 | 87 | } |
88 | 88 | |
89 | - if (! class_exists($message_type_class_name)) { |
|
89 | + if ( ! class_exists($message_type_class_name)) { |
|
90 | 90 | throw new EE_Error( |
91 | 91 | sprintf( |
92 | 92 | __('The "%1$s" message type class can\'t be loaded from %2$s. Likely there is a typo in the class name or the file name.', 'event_espresso'), |
@@ -18,371 +18,371 @@ |
||
18 | 18 | class Iframe |
19 | 19 | { |
20 | 20 | |
21 | - /* |
|
21 | + /* |
|
22 | 22 | * HTML for notices and ajax gif |
23 | 23 | * @var string $title |
24 | 24 | */ |
25 | - protected $title = ''; |
|
25 | + protected $title = ''; |
|
26 | 26 | |
27 | - /* |
|
27 | + /* |
|
28 | 28 | * HTML for the content being displayed |
29 | 29 | * @var string $content |
30 | 30 | */ |
31 | - protected $content = ''; |
|
31 | + protected $content = ''; |
|
32 | 32 | |
33 | - /* |
|
33 | + /* |
|
34 | 34 | * whether or not to call wp_head() and wp_footer() |
35 | 35 | * @var boolean $enqueue_wp_assets |
36 | 36 | */ |
37 | - protected $enqueue_wp_assets = false; |
|
37 | + protected $enqueue_wp_assets = false; |
|
38 | 38 | |
39 | - /* |
|
39 | + /* |
|
40 | 40 | * an array of CSS URLs |
41 | 41 | * @var array $css |
42 | 42 | */ |
43 | - protected $css = array(); |
|
43 | + protected $css = array(); |
|
44 | 44 | |
45 | - /* |
|
45 | + /* |
|
46 | 46 | * an array of JS URLs to be set in the HTML header. |
47 | 47 | * @var array $header_js |
48 | 48 | */ |
49 | - protected $header_js = array(); |
|
49 | + protected $header_js = array(); |
|
50 | 50 | |
51 | - /* |
|
51 | + /* |
|
52 | 52 | * an array of additional attributes to be added to <script> tags for header JS |
53 | 53 | * @var array $footer_js |
54 | 54 | */ |
55 | - protected $header_js_attributes = array(); |
|
55 | + protected $header_js_attributes = array(); |
|
56 | 56 | |
57 | - /* |
|
57 | + /* |
|
58 | 58 | * an array of JS URLs to be displayed before the HTML </body> tag |
59 | 59 | * @var array $footer_js |
60 | 60 | */ |
61 | - protected $footer_js = array(); |
|
61 | + protected $footer_js = array(); |
|
62 | 62 | |
63 | - /* |
|
63 | + /* |
|
64 | 64 | * an array of additional attributes to be added to <script> tags for footer JS |
65 | 65 | * @var array $footer_js_attributes |
66 | 66 | */ |
67 | - protected $footer_js_attributes = array(); |
|
67 | + protected $footer_js_attributes = array(); |
|
68 | 68 | |
69 | - /* |
|
69 | + /* |
|
70 | 70 | * an array of JSON vars to be set in the HTML header. |
71 | 71 | * @var array $localized_vars |
72 | 72 | */ |
73 | - protected $localized_vars = array(); |
|
74 | - |
|
75 | - |
|
76 | - /** |
|
77 | - * Iframe constructor |
|
78 | - * |
|
79 | - * @param string $title |
|
80 | - * @param string $content |
|
81 | - * @throws DomainException |
|
82 | - */ |
|
83 | - public function __construct($title, $content) |
|
84 | - { |
|
85 | - global $wp_version; |
|
86 | - if (! defined('EE_IFRAME_DIR_URL')) { |
|
87 | - define('EE_IFRAME_DIR_URL', plugin_dir_url(__FILE__)); |
|
88 | - } |
|
89 | - $this->setContent($content); |
|
90 | - $this->setTitle($title); |
|
91 | - $this->addStylesheets( |
|
92 | - apply_filters( |
|
93 | - 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__construct__default_css', |
|
94 | - array( |
|
95 | - 'site_theme' => get_stylesheet_directory_uri() |
|
96 | - . '/style.css?ver=' . EVENT_ESPRESSO_VERSION, |
|
97 | - 'dashicons' => includes_url('css/dashicons.min.css?ver=' . $wp_version), |
|
98 | - 'espresso_default' => EE_GLOBAL_ASSETS_URL |
|
99 | - . 'css/espresso_default.css?ver=' . EVENT_ESPRESSO_VERSION, |
|
100 | - ), |
|
101 | - $this |
|
102 | - ) |
|
103 | - ); |
|
104 | - $this->addScripts( |
|
105 | - apply_filters( |
|
106 | - 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__construct__default_js', |
|
107 | - array( |
|
108 | - 'jquery' => includes_url('js/jquery/jquery.js?ver=' . $wp_version), |
|
109 | - 'espresso_core' => EE_GLOBAL_ASSETS_URL |
|
110 | - . 'scripts/espresso_core.js?ver=' . EVENT_ESPRESSO_VERSION, |
|
111 | - ), |
|
112 | - $this |
|
113 | - ) |
|
114 | - ); |
|
115 | - if (apply_filters( |
|
116 | - 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__construct__load_default_theme_stylesheet', |
|
117 | - false |
|
118 | - )) { |
|
119 | - $this->addStylesheets( |
|
120 | - apply_filters( |
|
121 | - 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__construct__default_theme_stylesheet', |
|
122 | - array('default_theme_stylesheet' => get_stylesheet_uri()), |
|
123 | - $this |
|
124 | - ) |
|
125 | - ); |
|
126 | - } |
|
127 | - } |
|
128 | - |
|
129 | - |
|
130 | - /** |
|
131 | - * @param string $title |
|
132 | - * @throws DomainException |
|
133 | - */ |
|
134 | - public function setTitle($title) |
|
135 | - { |
|
136 | - if (empty($title)) { |
|
137 | - throw new DomainException( |
|
138 | - esc_html__('You must provide a page title in order to create an iframe.', 'event_espresso') |
|
139 | - ); |
|
140 | - } |
|
141 | - $this->title = $title; |
|
142 | - } |
|
143 | - |
|
144 | - |
|
145 | - /** |
|
146 | - * @param string $content |
|
147 | - * @throws DomainException |
|
148 | - */ |
|
149 | - public function setContent($content) |
|
150 | - { |
|
151 | - if (empty($content)) { |
|
152 | - throw new DomainException( |
|
153 | - esc_html__('You must provide content in order to create an iframe.', 'event_espresso') |
|
154 | - ); |
|
155 | - } |
|
156 | - $this->content = $content; |
|
157 | - } |
|
158 | - |
|
159 | - |
|
160 | - /** |
|
161 | - * @param boolean $enqueue_wp_assets |
|
162 | - */ |
|
163 | - public function setEnqueueWpAssets($enqueue_wp_assets) |
|
164 | - { |
|
165 | - $this->enqueue_wp_assets = filter_var($enqueue_wp_assets, FILTER_VALIDATE_BOOLEAN); |
|
166 | - } |
|
167 | - |
|
168 | - |
|
169 | - /** |
|
170 | - * @param array $stylesheets |
|
171 | - * @throws DomainException |
|
172 | - */ |
|
173 | - public function addStylesheets(array $stylesheets) |
|
174 | - { |
|
175 | - if (empty($stylesheets)) { |
|
176 | - throw new DomainException( |
|
177 | - esc_html__( |
|
178 | - 'A non-empty array of URLs, is required to add a CSS stylesheet to an iframe.', |
|
179 | - 'event_espresso' |
|
180 | - ) |
|
181 | - ); |
|
182 | - } |
|
183 | - foreach ($stylesheets as $handle => $stylesheet) { |
|
184 | - $this->css[ $handle ] = $stylesheet; |
|
185 | - } |
|
186 | - } |
|
187 | - |
|
188 | - |
|
189 | - /** |
|
190 | - * @param array $scripts |
|
191 | - * @param bool $add_to_header |
|
192 | - * @throws DomainException |
|
193 | - */ |
|
194 | - public function addScripts(array $scripts, $add_to_header = false) |
|
195 | - { |
|
196 | - if (empty($scripts)) { |
|
197 | - throw new DomainException( |
|
198 | - esc_html__( |
|
199 | - 'A non-empty array of URLs, is required to add Javascript to an iframe.', |
|
200 | - 'event_espresso' |
|
201 | - ) |
|
202 | - ); |
|
203 | - } |
|
204 | - foreach ($scripts as $handle => $script) { |
|
205 | - if ($add_to_header) { |
|
206 | - $this->header_js[ $handle ] = $script; |
|
207 | - } else { |
|
208 | - $this->footer_js[ $handle ] = $script; |
|
209 | - } |
|
210 | - } |
|
211 | - } |
|
212 | - |
|
213 | - |
|
214 | - /** |
|
215 | - * @param array $script_attributes |
|
216 | - * @param bool $add_to_header |
|
217 | - * @throws DomainException |
|
218 | - */ |
|
219 | - public function addScriptAttributes(array $script_attributes, $add_to_header = false) |
|
220 | - { |
|
221 | - if (empty($script_attributes)) { |
|
222 | - throw new DomainException( |
|
223 | - esc_html__( |
|
224 | - 'A non-empty array of strings, is required to add attributes to iframe Javascript.', |
|
225 | - 'event_espresso' |
|
226 | - ) |
|
227 | - ); |
|
228 | - } |
|
229 | - foreach ($script_attributes as $handle => $script_attribute) { |
|
230 | - if ($add_to_header) { |
|
231 | - $this->header_js_attributes[ $handle ] = $script_attribute; |
|
232 | - } else { |
|
233 | - $this->footer_js_attributes[ $handle ] = $script_attribute; |
|
234 | - } |
|
235 | - } |
|
236 | - } |
|
237 | - |
|
238 | - |
|
239 | - /** |
|
240 | - * @param array $vars |
|
241 | - * @param string $var_name |
|
242 | - * @throws DomainException |
|
243 | - */ |
|
244 | - public function addLocalizedVars(array $vars, $var_name = 'eei18n') |
|
245 | - { |
|
246 | - if (empty($vars)) { |
|
247 | - throw new DomainException( |
|
248 | - esc_html__( |
|
249 | - 'A non-empty array of vars, is required to add localized Javascript vars to an iframe.', |
|
250 | - 'event_espresso' |
|
251 | - ) |
|
252 | - ); |
|
253 | - } |
|
254 | - foreach ($vars as $handle => $var) { |
|
255 | - if ($var_name === 'eei18n') { |
|
256 | - EE_Registry::$i18n_js_strings[ $handle ] = $var; |
|
257 | - } elseif ($var_name === 'eeCAL' && $handle === 'espresso_calendar') { |
|
258 | - $this->localized_vars[ $var_name ] = $var; |
|
259 | - } else { |
|
260 | - if (! isset($this->localized_vars[ $var_name ])) { |
|
261 | - $this->localized_vars[ $var_name ] = array(); |
|
262 | - } |
|
263 | - $this->localized_vars[ $var_name ][ $handle ] = $var; |
|
264 | - } |
|
265 | - } |
|
266 | - } |
|
267 | - |
|
268 | - |
|
269 | - /** |
|
270 | - * @param string $utm_content |
|
271 | - * @throws DomainException |
|
272 | - */ |
|
273 | - public function display($utm_content = '') |
|
274 | - { |
|
275 | - $this->content .= EEH_Template::powered_by_event_espresso( |
|
276 | - '', |
|
277 | - '', |
|
278 | - ! empty($utm_content) ? array('utm_content' => $utm_content) : array() |
|
279 | - ); |
|
280 | - EE_System::do_not_cache(); |
|
281 | - echo $this->getTemplate(); |
|
282 | - exit; |
|
283 | - } |
|
284 | - |
|
285 | - |
|
286 | - /** |
|
287 | - * @return string |
|
288 | - * @throws DomainException |
|
289 | - */ |
|
290 | - public function getTemplate() |
|
291 | - { |
|
292 | - return EEH_Template::display_template( |
|
293 | - __DIR__ . DIRECTORY_SEPARATOR . 'iframe_wrapper.template.php', |
|
294 | - array( |
|
295 | - 'title' => apply_filters( |
|
296 | - 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__title', |
|
297 | - $this->title, |
|
298 | - $this |
|
299 | - ), |
|
300 | - 'content' => apply_filters( |
|
301 | - 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__content', |
|
302 | - $this->content, |
|
303 | - $this |
|
304 | - ), |
|
305 | - 'enqueue_wp_assets' => apply_filters( |
|
306 | - 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__enqueue_wp_assets', |
|
307 | - $this->enqueue_wp_assets, |
|
308 | - $this |
|
309 | - ), |
|
310 | - 'css' => (array) apply_filters( |
|
311 | - 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__css_urls', |
|
312 | - $this->css, |
|
313 | - $this |
|
314 | - ), |
|
315 | - 'header_js' => (array) apply_filters( |
|
316 | - 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__header_js_urls', |
|
317 | - $this->header_js, |
|
318 | - $this |
|
319 | - ), |
|
320 | - 'header_js_attributes' => (array) apply_filters( |
|
321 | - 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__header_js_attributes', |
|
322 | - $this->header_js_attributes, |
|
323 | - $this |
|
324 | - ), |
|
325 | - 'footer_js' => (array) apply_filters( |
|
326 | - 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__footer_js_urls', |
|
327 | - $this->footer_js, |
|
328 | - $this |
|
329 | - ), |
|
330 | - 'footer_js_attributes' => (array) apply_filters( |
|
331 | - 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__footer_js_attributes', |
|
332 | - $this->footer_js_attributes, |
|
333 | - $this |
|
334 | - ), |
|
335 | - 'eei18n' => apply_filters( |
|
336 | - 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__eei18n_js_strings', |
|
337 | - EE_Registry::localize_i18n_js_strings() . $this->localizeJsonVars(), |
|
338 | - $this |
|
339 | - ), |
|
340 | - 'notices' => EEH_Template::display_template( |
|
341 | - EE_TEMPLATES . 'espresso-ajax-notices.template.php', |
|
342 | - array(), |
|
343 | - true |
|
344 | - ), |
|
345 | - ), |
|
346 | - true, |
|
347 | - true |
|
348 | - ); |
|
349 | - } |
|
350 | - |
|
351 | - |
|
352 | - /** |
|
353 | - * localizeJsonVars |
|
354 | - * |
|
355 | - * @return string |
|
356 | - */ |
|
357 | - public function localizeJsonVars() |
|
358 | - { |
|
359 | - $JSON = ''; |
|
360 | - foreach ((array) $this->localized_vars as $var_name => $vars) { |
|
361 | - $this->localized_vars[ $var_name ] = $this->encodeJsonVars($vars); |
|
362 | - $JSON .= "/* <![CDATA[ */ var {$var_name} = "; |
|
363 | - $JSON .= wp_json_encode($this->localized_vars[ $var_name ]); |
|
364 | - $JSON .= '; /* ]]> */'; |
|
365 | - } |
|
366 | - return $JSON; |
|
367 | - } |
|
368 | - |
|
369 | - |
|
370 | - /** |
|
371 | - * @param bool|int|float|string|array $var |
|
372 | - * @return array |
|
373 | - */ |
|
374 | - public function encodeJsonVars($var) |
|
375 | - { |
|
376 | - if (is_array($var)) { |
|
377 | - $localized_vars = array(); |
|
378 | - foreach ((array) $var as $key => $value) { |
|
379 | - $localized_vars[ $key ] = $this->encodeJsonVars($value); |
|
380 | - } |
|
381 | - return $localized_vars; |
|
382 | - } |
|
383 | - if (is_scalar($var)) { |
|
384 | - return html_entity_decode((string) $var, ENT_QUOTES, 'UTF-8'); |
|
385 | - } |
|
386 | - return null; |
|
387 | - } |
|
73 | + protected $localized_vars = array(); |
|
74 | + |
|
75 | + |
|
76 | + /** |
|
77 | + * Iframe constructor |
|
78 | + * |
|
79 | + * @param string $title |
|
80 | + * @param string $content |
|
81 | + * @throws DomainException |
|
82 | + */ |
|
83 | + public function __construct($title, $content) |
|
84 | + { |
|
85 | + global $wp_version; |
|
86 | + if (! defined('EE_IFRAME_DIR_URL')) { |
|
87 | + define('EE_IFRAME_DIR_URL', plugin_dir_url(__FILE__)); |
|
88 | + } |
|
89 | + $this->setContent($content); |
|
90 | + $this->setTitle($title); |
|
91 | + $this->addStylesheets( |
|
92 | + apply_filters( |
|
93 | + 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__construct__default_css', |
|
94 | + array( |
|
95 | + 'site_theme' => get_stylesheet_directory_uri() |
|
96 | + . '/style.css?ver=' . EVENT_ESPRESSO_VERSION, |
|
97 | + 'dashicons' => includes_url('css/dashicons.min.css?ver=' . $wp_version), |
|
98 | + 'espresso_default' => EE_GLOBAL_ASSETS_URL |
|
99 | + . 'css/espresso_default.css?ver=' . EVENT_ESPRESSO_VERSION, |
|
100 | + ), |
|
101 | + $this |
|
102 | + ) |
|
103 | + ); |
|
104 | + $this->addScripts( |
|
105 | + apply_filters( |
|
106 | + 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__construct__default_js', |
|
107 | + array( |
|
108 | + 'jquery' => includes_url('js/jquery/jquery.js?ver=' . $wp_version), |
|
109 | + 'espresso_core' => EE_GLOBAL_ASSETS_URL |
|
110 | + . 'scripts/espresso_core.js?ver=' . EVENT_ESPRESSO_VERSION, |
|
111 | + ), |
|
112 | + $this |
|
113 | + ) |
|
114 | + ); |
|
115 | + if (apply_filters( |
|
116 | + 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__construct__load_default_theme_stylesheet', |
|
117 | + false |
|
118 | + )) { |
|
119 | + $this->addStylesheets( |
|
120 | + apply_filters( |
|
121 | + 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__construct__default_theme_stylesheet', |
|
122 | + array('default_theme_stylesheet' => get_stylesheet_uri()), |
|
123 | + $this |
|
124 | + ) |
|
125 | + ); |
|
126 | + } |
|
127 | + } |
|
128 | + |
|
129 | + |
|
130 | + /** |
|
131 | + * @param string $title |
|
132 | + * @throws DomainException |
|
133 | + */ |
|
134 | + public function setTitle($title) |
|
135 | + { |
|
136 | + if (empty($title)) { |
|
137 | + throw new DomainException( |
|
138 | + esc_html__('You must provide a page title in order to create an iframe.', 'event_espresso') |
|
139 | + ); |
|
140 | + } |
|
141 | + $this->title = $title; |
|
142 | + } |
|
143 | + |
|
144 | + |
|
145 | + /** |
|
146 | + * @param string $content |
|
147 | + * @throws DomainException |
|
148 | + */ |
|
149 | + public function setContent($content) |
|
150 | + { |
|
151 | + if (empty($content)) { |
|
152 | + throw new DomainException( |
|
153 | + esc_html__('You must provide content in order to create an iframe.', 'event_espresso') |
|
154 | + ); |
|
155 | + } |
|
156 | + $this->content = $content; |
|
157 | + } |
|
158 | + |
|
159 | + |
|
160 | + /** |
|
161 | + * @param boolean $enqueue_wp_assets |
|
162 | + */ |
|
163 | + public function setEnqueueWpAssets($enqueue_wp_assets) |
|
164 | + { |
|
165 | + $this->enqueue_wp_assets = filter_var($enqueue_wp_assets, FILTER_VALIDATE_BOOLEAN); |
|
166 | + } |
|
167 | + |
|
168 | + |
|
169 | + /** |
|
170 | + * @param array $stylesheets |
|
171 | + * @throws DomainException |
|
172 | + */ |
|
173 | + public function addStylesheets(array $stylesheets) |
|
174 | + { |
|
175 | + if (empty($stylesheets)) { |
|
176 | + throw new DomainException( |
|
177 | + esc_html__( |
|
178 | + 'A non-empty array of URLs, is required to add a CSS stylesheet to an iframe.', |
|
179 | + 'event_espresso' |
|
180 | + ) |
|
181 | + ); |
|
182 | + } |
|
183 | + foreach ($stylesheets as $handle => $stylesheet) { |
|
184 | + $this->css[ $handle ] = $stylesheet; |
|
185 | + } |
|
186 | + } |
|
187 | + |
|
188 | + |
|
189 | + /** |
|
190 | + * @param array $scripts |
|
191 | + * @param bool $add_to_header |
|
192 | + * @throws DomainException |
|
193 | + */ |
|
194 | + public function addScripts(array $scripts, $add_to_header = false) |
|
195 | + { |
|
196 | + if (empty($scripts)) { |
|
197 | + throw new DomainException( |
|
198 | + esc_html__( |
|
199 | + 'A non-empty array of URLs, is required to add Javascript to an iframe.', |
|
200 | + 'event_espresso' |
|
201 | + ) |
|
202 | + ); |
|
203 | + } |
|
204 | + foreach ($scripts as $handle => $script) { |
|
205 | + if ($add_to_header) { |
|
206 | + $this->header_js[ $handle ] = $script; |
|
207 | + } else { |
|
208 | + $this->footer_js[ $handle ] = $script; |
|
209 | + } |
|
210 | + } |
|
211 | + } |
|
212 | + |
|
213 | + |
|
214 | + /** |
|
215 | + * @param array $script_attributes |
|
216 | + * @param bool $add_to_header |
|
217 | + * @throws DomainException |
|
218 | + */ |
|
219 | + public function addScriptAttributes(array $script_attributes, $add_to_header = false) |
|
220 | + { |
|
221 | + if (empty($script_attributes)) { |
|
222 | + throw new DomainException( |
|
223 | + esc_html__( |
|
224 | + 'A non-empty array of strings, is required to add attributes to iframe Javascript.', |
|
225 | + 'event_espresso' |
|
226 | + ) |
|
227 | + ); |
|
228 | + } |
|
229 | + foreach ($script_attributes as $handle => $script_attribute) { |
|
230 | + if ($add_to_header) { |
|
231 | + $this->header_js_attributes[ $handle ] = $script_attribute; |
|
232 | + } else { |
|
233 | + $this->footer_js_attributes[ $handle ] = $script_attribute; |
|
234 | + } |
|
235 | + } |
|
236 | + } |
|
237 | + |
|
238 | + |
|
239 | + /** |
|
240 | + * @param array $vars |
|
241 | + * @param string $var_name |
|
242 | + * @throws DomainException |
|
243 | + */ |
|
244 | + public function addLocalizedVars(array $vars, $var_name = 'eei18n') |
|
245 | + { |
|
246 | + if (empty($vars)) { |
|
247 | + throw new DomainException( |
|
248 | + esc_html__( |
|
249 | + 'A non-empty array of vars, is required to add localized Javascript vars to an iframe.', |
|
250 | + 'event_espresso' |
|
251 | + ) |
|
252 | + ); |
|
253 | + } |
|
254 | + foreach ($vars as $handle => $var) { |
|
255 | + if ($var_name === 'eei18n') { |
|
256 | + EE_Registry::$i18n_js_strings[ $handle ] = $var; |
|
257 | + } elseif ($var_name === 'eeCAL' && $handle === 'espresso_calendar') { |
|
258 | + $this->localized_vars[ $var_name ] = $var; |
|
259 | + } else { |
|
260 | + if (! isset($this->localized_vars[ $var_name ])) { |
|
261 | + $this->localized_vars[ $var_name ] = array(); |
|
262 | + } |
|
263 | + $this->localized_vars[ $var_name ][ $handle ] = $var; |
|
264 | + } |
|
265 | + } |
|
266 | + } |
|
267 | + |
|
268 | + |
|
269 | + /** |
|
270 | + * @param string $utm_content |
|
271 | + * @throws DomainException |
|
272 | + */ |
|
273 | + public function display($utm_content = '') |
|
274 | + { |
|
275 | + $this->content .= EEH_Template::powered_by_event_espresso( |
|
276 | + '', |
|
277 | + '', |
|
278 | + ! empty($utm_content) ? array('utm_content' => $utm_content) : array() |
|
279 | + ); |
|
280 | + EE_System::do_not_cache(); |
|
281 | + echo $this->getTemplate(); |
|
282 | + exit; |
|
283 | + } |
|
284 | + |
|
285 | + |
|
286 | + /** |
|
287 | + * @return string |
|
288 | + * @throws DomainException |
|
289 | + */ |
|
290 | + public function getTemplate() |
|
291 | + { |
|
292 | + return EEH_Template::display_template( |
|
293 | + __DIR__ . DIRECTORY_SEPARATOR . 'iframe_wrapper.template.php', |
|
294 | + array( |
|
295 | + 'title' => apply_filters( |
|
296 | + 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__title', |
|
297 | + $this->title, |
|
298 | + $this |
|
299 | + ), |
|
300 | + 'content' => apply_filters( |
|
301 | + 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__content', |
|
302 | + $this->content, |
|
303 | + $this |
|
304 | + ), |
|
305 | + 'enqueue_wp_assets' => apply_filters( |
|
306 | + 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__enqueue_wp_assets', |
|
307 | + $this->enqueue_wp_assets, |
|
308 | + $this |
|
309 | + ), |
|
310 | + 'css' => (array) apply_filters( |
|
311 | + 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__css_urls', |
|
312 | + $this->css, |
|
313 | + $this |
|
314 | + ), |
|
315 | + 'header_js' => (array) apply_filters( |
|
316 | + 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__header_js_urls', |
|
317 | + $this->header_js, |
|
318 | + $this |
|
319 | + ), |
|
320 | + 'header_js_attributes' => (array) apply_filters( |
|
321 | + 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__header_js_attributes', |
|
322 | + $this->header_js_attributes, |
|
323 | + $this |
|
324 | + ), |
|
325 | + 'footer_js' => (array) apply_filters( |
|
326 | + 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__footer_js_urls', |
|
327 | + $this->footer_js, |
|
328 | + $this |
|
329 | + ), |
|
330 | + 'footer_js_attributes' => (array) apply_filters( |
|
331 | + 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__footer_js_attributes', |
|
332 | + $this->footer_js_attributes, |
|
333 | + $this |
|
334 | + ), |
|
335 | + 'eei18n' => apply_filters( |
|
336 | + 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__eei18n_js_strings', |
|
337 | + EE_Registry::localize_i18n_js_strings() . $this->localizeJsonVars(), |
|
338 | + $this |
|
339 | + ), |
|
340 | + 'notices' => EEH_Template::display_template( |
|
341 | + EE_TEMPLATES . 'espresso-ajax-notices.template.php', |
|
342 | + array(), |
|
343 | + true |
|
344 | + ), |
|
345 | + ), |
|
346 | + true, |
|
347 | + true |
|
348 | + ); |
|
349 | + } |
|
350 | + |
|
351 | + |
|
352 | + /** |
|
353 | + * localizeJsonVars |
|
354 | + * |
|
355 | + * @return string |
|
356 | + */ |
|
357 | + public function localizeJsonVars() |
|
358 | + { |
|
359 | + $JSON = ''; |
|
360 | + foreach ((array) $this->localized_vars as $var_name => $vars) { |
|
361 | + $this->localized_vars[ $var_name ] = $this->encodeJsonVars($vars); |
|
362 | + $JSON .= "/* <![CDATA[ */ var {$var_name} = "; |
|
363 | + $JSON .= wp_json_encode($this->localized_vars[ $var_name ]); |
|
364 | + $JSON .= '; /* ]]> */'; |
|
365 | + } |
|
366 | + return $JSON; |
|
367 | + } |
|
368 | + |
|
369 | + |
|
370 | + /** |
|
371 | + * @param bool|int|float|string|array $var |
|
372 | + * @return array |
|
373 | + */ |
|
374 | + public function encodeJsonVars($var) |
|
375 | + { |
|
376 | + if (is_array($var)) { |
|
377 | + $localized_vars = array(); |
|
378 | + foreach ((array) $var as $key => $value) { |
|
379 | + $localized_vars[ $key ] = $this->encodeJsonVars($value); |
|
380 | + } |
|
381 | + return $localized_vars; |
|
382 | + } |
|
383 | + if (is_scalar($var)) { |
|
384 | + return html_entity_decode((string) $var, ENT_QUOTES, 'UTF-8'); |
|
385 | + } |
|
386 | + return null; |
|
387 | + } |
|
388 | 388 | } |
@@ -83,7 +83,7 @@ discard block |
||
83 | 83 | public function __construct($title, $content) |
84 | 84 | { |
85 | 85 | global $wp_version; |
86 | - if (! defined('EE_IFRAME_DIR_URL')) { |
|
86 | + if ( ! defined('EE_IFRAME_DIR_URL')) { |
|
87 | 87 | define('EE_IFRAME_DIR_URL', plugin_dir_url(__FILE__)); |
88 | 88 | } |
89 | 89 | $this->setContent($content); |
@@ -93,10 +93,10 @@ discard block |
||
93 | 93 | 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__construct__default_css', |
94 | 94 | array( |
95 | 95 | 'site_theme' => get_stylesheet_directory_uri() |
96 | - . '/style.css?ver=' . EVENT_ESPRESSO_VERSION, |
|
97 | - 'dashicons' => includes_url('css/dashicons.min.css?ver=' . $wp_version), |
|
96 | + . '/style.css?ver='.EVENT_ESPRESSO_VERSION, |
|
97 | + 'dashicons' => includes_url('css/dashicons.min.css?ver='.$wp_version), |
|
98 | 98 | 'espresso_default' => EE_GLOBAL_ASSETS_URL |
99 | - . 'css/espresso_default.css?ver=' . EVENT_ESPRESSO_VERSION, |
|
99 | + . 'css/espresso_default.css?ver='.EVENT_ESPRESSO_VERSION, |
|
100 | 100 | ), |
101 | 101 | $this |
102 | 102 | ) |
@@ -105,9 +105,9 @@ discard block |
||
105 | 105 | apply_filters( |
106 | 106 | 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__construct__default_js', |
107 | 107 | array( |
108 | - 'jquery' => includes_url('js/jquery/jquery.js?ver=' . $wp_version), |
|
108 | + 'jquery' => includes_url('js/jquery/jquery.js?ver='.$wp_version), |
|
109 | 109 | 'espresso_core' => EE_GLOBAL_ASSETS_URL |
110 | - . 'scripts/espresso_core.js?ver=' . EVENT_ESPRESSO_VERSION, |
|
110 | + . 'scripts/espresso_core.js?ver='.EVENT_ESPRESSO_VERSION, |
|
111 | 111 | ), |
112 | 112 | $this |
113 | 113 | ) |
@@ -181,7 +181,7 @@ discard block |
||
181 | 181 | ); |
182 | 182 | } |
183 | 183 | foreach ($stylesheets as $handle => $stylesheet) { |
184 | - $this->css[ $handle ] = $stylesheet; |
|
184 | + $this->css[$handle] = $stylesheet; |
|
185 | 185 | } |
186 | 186 | } |
187 | 187 | |
@@ -203,9 +203,9 @@ discard block |
||
203 | 203 | } |
204 | 204 | foreach ($scripts as $handle => $script) { |
205 | 205 | if ($add_to_header) { |
206 | - $this->header_js[ $handle ] = $script; |
|
206 | + $this->header_js[$handle] = $script; |
|
207 | 207 | } else { |
208 | - $this->footer_js[ $handle ] = $script; |
|
208 | + $this->footer_js[$handle] = $script; |
|
209 | 209 | } |
210 | 210 | } |
211 | 211 | } |
@@ -228,9 +228,9 @@ discard block |
||
228 | 228 | } |
229 | 229 | foreach ($script_attributes as $handle => $script_attribute) { |
230 | 230 | if ($add_to_header) { |
231 | - $this->header_js_attributes[ $handle ] = $script_attribute; |
|
231 | + $this->header_js_attributes[$handle] = $script_attribute; |
|
232 | 232 | } else { |
233 | - $this->footer_js_attributes[ $handle ] = $script_attribute; |
|
233 | + $this->footer_js_attributes[$handle] = $script_attribute; |
|
234 | 234 | } |
235 | 235 | } |
236 | 236 | } |
@@ -253,14 +253,14 @@ discard block |
||
253 | 253 | } |
254 | 254 | foreach ($vars as $handle => $var) { |
255 | 255 | if ($var_name === 'eei18n') { |
256 | - EE_Registry::$i18n_js_strings[ $handle ] = $var; |
|
256 | + EE_Registry::$i18n_js_strings[$handle] = $var; |
|
257 | 257 | } elseif ($var_name === 'eeCAL' && $handle === 'espresso_calendar') { |
258 | - $this->localized_vars[ $var_name ] = $var; |
|
258 | + $this->localized_vars[$var_name] = $var; |
|
259 | 259 | } else { |
260 | - if (! isset($this->localized_vars[ $var_name ])) { |
|
261 | - $this->localized_vars[ $var_name ] = array(); |
|
260 | + if ( ! isset($this->localized_vars[$var_name])) { |
|
261 | + $this->localized_vars[$var_name] = array(); |
|
262 | 262 | } |
263 | - $this->localized_vars[ $var_name ][ $handle ] = $var; |
|
263 | + $this->localized_vars[$var_name][$handle] = $var; |
|
264 | 264 | } |
265 | 265 | } |
266 | 266 | } |
@@ -290,7 +290,7 @@ discard block |
||
290 | 290 | public function getTemplate() |
291 | 291 | { |
292 | 292 | return EEH_Template::display_template( |
293 | - __DIR__ . DIRECTORY_SEPARATOR . 'iframe_wrapper.template.php', |
|
293 | + __DIR__.DIRECTORY_SEPARATOR.'iframe_wrapper.template.php', |
|
294 | 294 | array( |
295 | 295 | 'title' => apply_filters( |
296 | 296 | 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__title', |
@@ -334,11 +334,11 @@ discard block |
||
334 | 334 | ), |
335 | 335 | 'eei18n' => apply_filters( |
336 | 336 | 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__eei18n_js_strings', |
337 | - EE_Registry::localize_i18n_js_strings() . $this->localizeJsonVars(), |
|
337 | + EE_Registry::localize_i18n_js_strings().$this->localizeJsonVars(), |
|
338 | 338 | $this |
339 | 339 | ), |
340 | 340 | 'notices' => EEH_Template::display_template( |
341 | - EE_TEMPLATES . 'espresso-ajax-notices.template.php', |
|
341 | + EE_TEMPLATES.'espresso-ajax-notices.template.php', |
|
342 | 342 | array(), |
343 | 343 | true |
344 | 344 | ), |
@@ -358,9 +358,9 @@ discard block |
||
358 | 358 | { |
359 | 359 | $JSON = ''; |
360 | 360 | foreach ((array) $this->localized_vars as $var_name => $vars) { |
361 | - $this->localized_vars[ $var_name ] = $this->encodeJsonVars($vars); |
|
361 | + $this->localized_vars[$var_name] = $this->encodeJsonVars($vars); |
|
362 | 362 | $JSON .= "/* <![CDATA[ */ var {$var_name} = "; |
363 | - $JSON .= wp_json_encode($this->localized_vars[ $var_name ]); |
|
363 | + $JSON .= wp_json_encode($this->localized_vars[$var_name]); |
|
364 | 364 | $JSON .= '; /* ]]> */'; |
365 | 365 | } |
366 | 366 | return $JSON; |
@@ -376,7 +376,7 @@ discard block |
||
376 | 376 | if (is_array($var)) { |
377 | 377 | $localized_vars = array(); |
378 | 378 | foreach ((array) $var as $key => $value) { |
379 | - $localized_vars[ $key ] = $this->encodeJsonVars($value); |
|
379 | + $localized_vars[$key] = $this->encodeJsonVars($value); |
|
380 | 380 | } |
381 | 381 | return $localized_vars; |
382 | 382 | } |
@@ -17,135 +17,135 @@ |
||
17 | 17 | */ |
18 | 18 | abstract class JobHandlerFile extends JobHandler |
19 | 19 | { |
20 | - // phpcs:disable Generic.NamingConventions.UpperCaseConstantName.ClassConstantNotUpperCase |
|
21 | - const temp_folder_name = 'batch_temp_folder'; |
|
20 | + // phpcs:disable Generic.NamingConventions.UpperCaseConstantName.ClassConstantNotUpperCase |
|
21 | + const temp_folder_name = 'batch_temp_folder'; |
|
22 | 22 | |
23 | - // phpcs:disable PSR2.Classes.PropertyDeclaration.Underscore |
|
24 | - /** |
|
25 | - * @var \EEHI_File |
|
26 | - */ |
|
27 | - protected $_file_helper = null; |
|
23 | + // phpcs:disable PSR2.Classes.PropertyDeclaration.Underscore |
|
24 | + /** |
|
25 | + * @var \EEHI_File |
|
26 | + */ |
|
27 | + protected $_file_helper = null; |
|
28 | 28 | |
29 | 29 | |
30 | - /** |
|
31 | - * JobHandlerFile constructor. |
|
32 | - * |
|
33 | - * @param \EEHI_File|null $file_helper |
|
34 | - */ |
|
35 | - public function __construct(\EEHI_File $file_helper = null) |
|
36 | - { |
|
37 | - if (! $file_helper) { |
|
38 | - $this->_file_helper = new EEH_File(); |
|
39 | - } |
|
40 | - } |
|
30 | + /** |
|
31 | + * JobHandlerFile constructor. |
|
32 | + * |
|
33 | + * @param \EEHI_File|null $file_helper |
|
34 | + */ |
|
35 | + public function __construct(\EEHI_File $file_helper = null) |
|
36 | + { |
|
37 | + if (! $file_helper) { |
|
38 | + $this->_file_helper = new EEH_File(); |
|
39 | + } |
|
40 | + } |
|
41 | 41 | |
42 | - // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
43 | - /** |
|
44 | - * Creates a file |
|
45 | - * |
|
46 | - * @param string $job_id |
|
47 | - * @param string $filename |
|
48 | - * @param string $filetype |
|
49 | - * @param string $bom initial content to place in the file. |
|
50 | - * @return string |
|
51 | - * @throws \EventEspressoBatchRequest\Helpers\BatchRequestException |
|
52 | - */ |
|
53 | - public function create_file_from_job_with_name( |
|
54 | - $job_id, |
|
55 | - $filename, |
|
56 | - $filetype = 'application/ms-excel', |
|
57 | - $bom = "\xEF\xBB\xBF" |
|
58 | - ) { |
|
59 | - $filepath = ''; |
|
60 | - try { |
|
61 | - $base_folder = $this->get_base_folder(); |
|
62 | - $success = $this->_file_helper->ensure_folder_exists_and_is_writable( |
|
63 | - $base_folder . JobHandlerFile::temp_folder_name |
|
64 | - ); |
|
65 | - if ($success) { |
|
66 | - $success = $this->_file_helper->ensure_folder_exists_and_is_writable( |
|
67 | - $base_folder . JobHandlerFile::temp_folder_name . '/' . $job_id |
|
68 | - ); |
|
69 | - } |
|
70 | - if ($success) { |
|
71 | - $filepath = $base_folder . JobHandlerFile::temp_folder_name . '/' . $job_id . '/' . $filename; |
|
72 | - $success = $this->_file_helper->ensure_file_exists_and_is_writable($filepath); |
|
73 | - } |
|
74 | - // let's add the .htaccess file so safari will open the file properly |
|
75 | - if ($success) { |
|
76 | - $extension = EEH_File::get_file_extension($filepath); |
|
77 | - EEH_File::write_to_file( |
|
78 | - $base_folder . JobHandlerFile::temp_folder_name . '/' . $job_id . '/.htaccess', |
|
79 | - 'AddType ' . $filetype . ' ' . $extension, |
|
80 | - '.htaccess' |
|
81 | - ); |
|
82 | - } |
|
83 | - /** |
|
84 | - * Filters what initial content will be added to the file. |
|
85 | - * @param string $return_value. By default it's whatever was pased into |
|
86 | - * JobHandlerFile::create_file_from_job_with_name() |
|
87 | - * @param string $filename |
|
88 | - * @param string $filetype default 'application/ms-excel' |
|
89 | - * @param string $filepath |
|
90 | - */ |
|
91 | - EEH_File::write_to_file( |
|
92 | - $filepath, |
|
93 | - apply_filters( |
|
94 | - 'FHEE__EE_CSV__begin_sending_csv__start_writing', |
|
95 | - $bom, |
|
96 | - $filename, |
|
97 | - $filetype, |
|
98 | - $filepath |
|
99 | - ) |
|
100 | - ); |
|
101 | - // those methods normally fail with an exception, but if not, let's do it |
|
102 | - if (! $success) { |
|
103 | - throw new \EE_Error(__('Could not create temporary file, an unknown error occurred', 'event_espresso')); |
|
104 | - } |
|
105 | - } catch (\EE_Error $e) { |
|
106 | - throw new BatchRequestException( |
|
107 | - sprintf( |
|
108 | - // phpcs:disable WordPress.WP.I18n.MissingTranslatorsComment |
|
109 | - __('Could not create temporary file for job %1$s, because: %2$s ', 'event_espresso'), |
|
110 | - $job_id, |
|
111 | - $e->getMessage() |
|
112 | - ), |
|
113 | - 500, |
|
114 | - $e |
|
115 | - ); |
|
116 | - } |
|
117 | - return $filepath; |
|
118 | - } |
|
42 | + // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
43 | + /** |
|
44 | + * Creates a file |
|
45 | + * |
|
46 | + * @param string $job_id |
|
47 | + * @param string $filename |
|
48 | + * @param string $filetype |
|
49 | + * @param string $bom initial content to place in the file. |
|
50 | + * @return string |
|
51 | + * @throws \EventEspressoBatchRequest\Helpers\BatchRequestException |
|
52 | + */ |
|
53 | + public function create_file_from_job_with_name( |
|
54 | + $job_id, |
|
55 | + $filename, |
|
56 | + $filetype = 'application/ms-excel', |
|
57 | + $bom = "\xEF\xBB\xBF" |
|
58 | + ) { |
|
59 | + $filepath = ''; |
|
60 | + try { |
|
61 | + $base_folder = $this->get_base_folder(); |
|
62 | + $success = $this->_file_helper->ensure_folder_exists_and_is_writable( |
|
63 | + $base_folder . JobHandlerFile::temp_folder_name |
|
64 | + ); |
|
65 | + if ($success) { |
|
66 | + $success = $this->_file_helper->ensure_folder_exists_and_is_writable( |
|
67 | + $base_folder . JobHandlerFile::temp_folder_name . '/' . $job_id |
|
68 | + ); |
|
69 | + } |
|
70 | + if ($success) { |
|
71 | + $filepath = $base_folder . JobHandlerFile::temp_folder_name . '/' . $job_id . '/' . $filename; |
|
72 | + $success = $this->_file_helper->ensure_file_exists_and_is_writable($filepath); |
|
73 | + } |
|
74 | + // let's add the .htaccess file so safari will open the file properly |
|
75 | + if ($success) { |
|
76 | + $extension = EEH_File::get_file_extension($filepath); |
|
77 | + EEH_File::write_to_file( |
|
78 | + $base_folder . JobHandlerFile::temp_folder_name . '/' . $job_id . '/.htaccess', |
|
79 | + 'AddType ' . $filetype . ' ' . $extension, |
|
80 | + '.htaccess' |
|
81 | + ); |
|
82 | + } |
|
83 | + /** |
|
84 | + * Filters what initial content will be added to the file. |
|
85 | + * @param string $return_value. By default it's whatever was pased into |
|
86 | + * JobHandlerFile::create_file_from_job_with_name() |
|
87 | + * @param string $filename |
|
88 | + * @param string $filetype default 'application/ms-excel' |
|
89 | + * @param string $filepath |
|
90 | + */ |
|
91 | + EEH_File::write_to_file( |
|
92 | + $filepath, |
|
93 | + apply_filters( |
|
94 | + 'FHEE__EE_CSV__begin_sending_csv__start_writing', |
|
95 | + $bom, |
|
96 | + $filename, |
|
97 | + $filetype, |
|
98 | + $filepath |
|
99 | + ) |
|
100 | + ); |
|
101 | + // those methods normally fail with an exception, but if not, let's do it |
|
102 | + if (! $success) { |
|
103 | + throw new \EE_Error(__('Could not create temporary file, an unknown error occurred', 'event_espresso')); |
|
104 | + } |
|
105 | + } catch (\EE_Error $e) { |
|
106 | + throw new BatchRequestException( |
|
107 | + sprintf( |
|
108 | + // phpcs:disable WordPress.WP.I18n.MissingTranslatorsComment |
|
109 | + __('Could not create temporary file for job %1$s, because: %2$s ', 'event_espresso'), |
|
110 | + $job_id, |
|
111 | + $e->getMessage() |
|
112 | + ), |
|
113 | + 500, |
|
114 | + $e |
|
115 | + ); |
|
116 | + } |
|
117 | + return $filepath; |
|
118 | + } |
|
119 | 119 | |
120 | - /** |
|
121 | - * Gets the URL to download the file |
|
122 | - * |
|
123 | - * @param string $filepath |
|
124 | - * @return string url to file |
|
125 | - */ |
|
126 | - public function get_url_to_file($filepath) |
|
127 | - { |
|
128 | - return str_replace($this->get_base_folder(), $this->get_base_url(), $filepath); |
|
129 | - } |
|
120 | + /** |
|
121 | + * Gets the URL to download the file |
|
122 | + * |
|
123 | + * @param string $filepath |
|
124 | + * @return string url to file |
|
125 | + */ |
|
126 | + public function get_url_to_file($filepath) |
|
127 | + { |
|
128 | + return str_replace($this->get_base_folder(), $this->get_base_url(), $filepath); |
|
129 | + } |
|
130 | 130 | |
131 | - /** |
|
132 | - * Gets the folder which will contain the "batch_temp_folder" |
|
133 | - * |
|
134 | - * @return string |
|
135 | - */ |
|
136 | - public function get_base_folder() |
|
137 | - { |
|
138 | - return apply_filters( |
|
139 | - 'FHEE__EventEspressoBatchRequest\JobHandlerBaseClasses\JobHandlerFile__get_base_folder', |
|
140 | - EVENT_ESPRESSO_UPLOAD_DIR |
|
141 | - ); |
|
142 | - } |
|
131 | + /** |
|
132 | + * Gets the folder which will contain the "batch_temp_folder" |
|
133 | + * |
|
134 | + * @return string |
|
135 | + */ |
|
136 | + public function get_base_folder() |
|
137 | + { |
|
138 | + return apply_filters( |
|
139 | + 'FHEE__EventEspressoBatchRequest\JobHandlerBaseClasses\JobHandlerFile__get_base_folder', |
|
140 | + EVENT_ESPRESSO_UPLOAD_DIR |
|
141 | + ); |
|
142 | + } |
|
143 | 143 | |
144 | - public function get_base_url() |
|
145 | - { |
|
146 | - return apply_filters( |
|
147 | - 'FHEE__EventEspressoBatchRequest\JobHandlerBaseClasses\JobHandlerFile__get_base_url', |
|
148 | - EVENT_ESPRESSO_UPLOAD_URL |
|
149 | - ); |
|
150 | - } |
|
144 | + public function get_base_url() |
|
145 | + { |
|
146 | + return apply_filters( |
|
147 | + 'FHEE__EventEspressoBatchRequest\JobHandlerBaseClasses\JobHandlerFile__get_base_url', |
|
148 | + EVENT_ESPRESSO_UPLOAD_URL |
|
149 | + ); |
|
150 | + } |
|
151 | 151 | } |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | */ |
35 | 35 | public function __construct(\EEHI_File $file_helper = null) |
36 | 36 | { |
37 | - if (! $file_helper) { |
|
37 | + if ( ! $file_helper) { |
|
38 | 38 | $this->_file_helper = new EEH_File(); |
39 | 39 | } |
40 | 40 | } |
@@ -60,23 +60,23 @@ discard block |
||
60 | 60 | try { |
61 | 61 | $base_folder = $this->get_base_folder(); |
62 | 62 | $success = $this->_file_helper->ensure_folder_exists_and_is_writable( |
63 | - $base_folder . JobHandlerFile::temp_folder_name |
|
63 | + $base_folder.JobHandlerFile::temp_folder_name |
|
64 | 64 | ); |
65 | 65 | if ($success) { |
66 | 66 | $success = $this->_file_helper->ensure_folder_exists_and_is_writable( |
67 | - $base_folder . JobHandlerFile::temp_folder_name . '/' . $job_id |
|
67 | + $base_folder.JobHandlerFile::temp_folder_name.'/'.$job_id |
|
68 | 68 | ); |
69 | 69 | } |
70 | 70 | if ($success) { |
71 | - $filepath = $base_folder . JobHandlerFile::temp_folder_name . '/' . $job_id . '/' . $filename; |
|
71 | + $filepath = $base_folder.JobHandlerFile::temp_folder_name.'/'.$job_id.'/'.$filename; |
|
72 | 72 | $success = $this->_file_helper->ensure_file_exists_and_is_writable($filepath); |
73 | 73 | } |
74 | 74 | // let's add the .htaccess file so safari will open the file properly |
75 | 75 | if ($success) { |
76 | 76 | $extension = EEH_File::get_file_extension($filepath); |
77 | 77 | EEH_File::write_to_file( |
78 | - $base_folder . JobHandlerFile::temp_folder_name . '/' . $job_id . '/.htaccess', |
|
79 | - 'AddType ' . $filetype . ' ' . $extension, |
|
78 | + $base_folder.JobHandlerFile::temp_folder_name.'/'.$job_id.'/.htaccess', |
|
79 | + 'AddType '.$filetype.' '.$extension, |
|
80 | 80 | '.htaccess' |
81 | 81 | ); |
82 | 82 | } |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | ) |
100 | 100 | ); |
101 | 101 | // those methods normally fail with an exception, but if not, let's do it |
102 | - if (! $success) { |
|
102 | + if ( ! $success) { |
|
103 | 103 | throw new \EE_Error(__('Could not create temporary file, an unknown error occurred', 'event_espresso')); |
104 | 104 | } |
105 | 105 | } catch (\EE_Error $e) { |
@@ -23,1679 +23,1679 @@ |
||
23 | 23 | class EE_Registry implements ResettableInterface |
24 | 24 | { |
25 | 25 | |
26 | - /** |
|
27 | - * @var EE_Registry $_instance |
|
28 | - */ |
|
29 | - private static $_instance; |
|
30 | - |
|
31 | - /** |
|
32 | - * @var EE_Dependency_Map $_dependency_map |
|
33 | - */ |
|
34 | - protected $_dependency_map; |
|
35 | - |
|
36 | - /** |
|
37 | - * @var Mirror |
|
38 | - */ |
|
39 | - private $mirror; |
|
40 | - |
|
41 | - /** |
|
42 | - * @var ClassInterfaceCache $class_cache |
|
43 | - */ |
|
44 | - private $class_cache; |
|
45 | - |
|
46 | - /** |
|
47 | - * @var array $_class_abbreviations |
|
48 | - */ |
|
49 | - protected $_class_abbreviations = array(); |
|
50 | - |
|
51 | - /** |
|
52 | - * @var CommandBusInterface $BUS |
|
53 | - */ |
|
54 | - public $BUS; |
|
55 | - |
|
56 | - /** |
|
57 | - * @var EE_Cart $CART |
|
58 | - */ |
|
59 | - public $CART; |
|
60 | - |
|
61 | - /** |
|
62 | - * @var EE_Config $CFG |
|
63 | - */ |
|
64 | - public $CFG; |
|
65 | - |
|
66 | - /** |
|
67 | - * @var EE_Network_Config $NET_CFG |
|
68 | - */ |
|
69 | - public $NET_CFG; |
|
70 | - |
|
71 | - /** |
|
72 | - * StdClass object for storing library classes in |
|
73 | - * |
|
74 | - * @var RegistryContainer $LIB |
|
75 | - */ |
|
76 | - public $LIB; |
|
77 | - |
|
78 | - /** |
|
79 | - * @var EE_Request_Handler $REQ |
|
80 | - */ |
|
81 | - public $REQ; |
|
82 | - |
|
83 | - /** |
|
84 | - * @var EE_Session $SSN |
|
85 | - */ |
|
86 | - public $SSN; |
|
87 | - |
|
88 | - /** |
|
89 | - * @since 4.5.0 |
|
90 | - * @var EE_Capabilities $CAP |
|
91 | - */ |
|
92 | - public $CAP; |
|
93 | - |
|
94 | - /** |
|
95 | - * @since 4.9.0 |
|
96 | - * @var EE_Message_Resource_Manager $MRM |
|
97 | - */ |
|
98 | - public $MRM; |
|
99 | - |
|
100 | - /** |
|
101 | - * @var Registry $AssetsRegistry |
|
102 | - */ |
|
103 | - public $AssetsRegistry; |
|
104 | - |
|
105 | - /** |
|
106 | - * StdClass object for holding addons which have registered themselves to work with EE core |
|
107 | - * |
|
108 | - * @var EE_Addon[] $addons |
|
109 | - */ |
|
110 | - public $addons; |
|
111 | - |
|
112 | - /** |
|
113 | - * keys are 'short names' (eg Event), values are class names (eg 'EEM_Event') |
|
114 | - * |
|
115 | - * @var EEM_Base[] $models |
|
116 | - */ |
|
117 | - public $models = array(); |
|
118 | - |
|
119 | - /** |
|
120 | - * @var EED_Module[] $modules |
|
121 | - */ |
|
122 | - public $modules; |
|
123 | - |
|
124 | - /** |
|
125 | - * @var EES_Shortcode[] $shortcodes |
|
126 | - */ |
|
127 | - public $shortcodes; |
|
128 | - |
|
129 | - /** |
|
130 | - * @var WP_Widget[] $widgets |
|
131 | - */ |
|
132 | - public $widgets; |
|
133 | - |
|
134 | - /** |
|
135 | - * this is an array of all implemented model names (i.e. not the parent abstract models, or models |
|
136 | - * which don't actually fetch items from the DB in the normal way (ie, are not children of EEM_Base)). |
|
137 | - * Keys are model "short names" (eg "Event") as used in model relations, and values are |
|
138 | - * classnames (eg "EEM_Event") |
|
139 | - * |
|
140 | - * @var array $non_abstract_db_models |
|
141 | - */ |
|
142 | - public $non_abstract_db_models = array(); |
|
143 | - |
|
144 | - /** |
|
145 | - * internationalization for JS strings |
|
146 | - * usage: EE_Registry::i18n_js_strings['string_key'] = esc_html__( 'string to translate.', 'event_espresso' ); |
|
147 | - * in js file: var translatedString = eei18n.string_key; |
|
148 | - * |
|
149 | - * @var array $i18n_js_strings |
|
150 | - */ |
|
151 | - public static $i18n_js_strings = array(); |
|
152 | - |
|
153 | - /** |
|
154 | - * $main_file - path to espresso.php |
|
155 | - * |
|
156 | - * @var array $main_file |
|
157 | - */ |
|
158 | - public $main_file; |
|
159 | - |
|
160 | - /** |
|
161 | - * array of ReflectionClass objects where the key is the class name |
|
162 | - * |
|
163 | - * @deprecated 4.9.62.p |
|
164 | - * @var ReflectionClass[] $_reflectors |
|
165 | - */ |
|
166 | - public $_reflectors; |
|
167 | - |
|
168 | - /** |
|
169 | - * boolean flag to indicate whether or not to load/save dependencies from/to the cache |
|
170 | - * |
|
171 | - * @var boolean $_cache_on |
|
172 | - */ |
|
173 | - protected $_cache_on = true; |
|
174 | - |
|
175 | - /** |
|
176 | - * @var ObjectIdentifier |
|
177 | - */ |
|
178 | - private $object_identifier; |
|
179 | - |
|
180 | - |
|
181 | - /** |
|
182 | - * @singleton method used to instantiate class object |
|
183 | - * @param EE_Dependency_Map|null $dependency_map |
|
184 | - * @param Mirror|null $mirror |
|
185 | - * @param ClassInterfaceCache|null $class_cache |
|
186 | - * @param ObjectIdentifier|null $object_identifier |
|
187 | - * @return EE_Registry instance |
|
188 | - */ |
|
189 | - public static function instance( |
|
190 | - EE_Dependency_Map $dependency_map = null, |
|
191 | - Mirror $mirror = null, |
|
192 | - ClassInterfaceCache $class_cache = null, |
|
193 | - ObjectIdentifier $object_identifier = null |
|
194 | - ) { |
|
195 | - // check if class object is instantiated |
|
196 | - if (! self::$_instance instanceof EE_Registry |
|
197 | - && $dependency_map instanceof EE_Dependency_Map |
|
198 | - && $mirror instanceof Mirror |
|
199 | - && $class_cache instanceof ClassInterfaceCache |
|
200 | - && $object_identifier instanceof ObjectIdentifier |
|
201 | - ) { |
|
202 | - self::$_instance = new self( |
|
203 | - $dependency_map, |
|
204 | - $mirror, |
|
205 | - $class_cache, |
|
206 | - $object_identifier |
|
207 | - ); |
|
208 | - } |
|
209 | - return self::$_instance; |
|
210 | - } |
|
211 | - |
|
212 | - |
|
213 | - /** |
|
214 | - * protected constructor to prevent direct creation |
|
215 | - * |
|
216 | - * @Constructor |
|
217 | - * @param EE_Dependency_Map $dependency_map |
|
218 | - * @param Mirror $mirror |
|
219 | - * @param ClassInterfaceCache $class_cache |
|
220 | - * @param ObjectIdentifier $object_identifier |
|
221 | - */ |
|
222 | - protected function __construct( |
|
223 | - EE_Dependency_Map $dependency_map, |
|
224 | - Mirror $mirror, |
|
225 | - ClassInterfaceCache $class_cache, |
|
226 | - ObjectIdentifier $object_identifier |
|
227 | - ) { |
|
228 | - $this->_dependency_map = $dependency_map; |
|
229 | - $this->mirror = $mirror; |
|
230 | - $this->class_cache = $class_cache; |
|
231 | - $this->object_identifier = $object_identifier; |
|
232 | - // $registry_container = new RegistryContainer(); |
|
233 | - $this->LIB = new RegistryContainer(); |
|
234 | - $this->addons = new RegistryContainer(); |
|
235 | - $this->modules = new RegistryContainer(); |
|
236 | - $this->shortcodes = new RegistryContainer(); |
|
237 | - $this->widgets = new RegistryContainer(); |
|
238 | - add_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading', array($this, 'initialize')); |
|
239 | - } |
|
240 | - |
|
241 | - |
|
242 | - /** |
|
243 | - * initialize |
|
244 | - * |
|
245 | - * @throws OutOfBoundsException |
|
246 | - * @throws InvalidArgumentException |
|
247 | - * @throws InvalidInterfaceException |
|
248 | - * @throws InvalidDataTypeException |
|
249 | - * @throws EE_Error |
|
250 | - * @throws ReflectionException |
|
251 | - */ |
|
252 | - public function initialize() |
|
253 | - { |
|
254 | - $this->_class_abbreviations = apply_filters( |
|
255 | - 'FHEE__EE_Registry____construct___class_abbreviations', |
|
256 | - array( |
|
257 | - 'EE_Config' => 'CFG', |
|
258 | - 'EE_Session' => 'SSN', |
|
259 | - 'EE_Capabilities' => 'CAP', |
|
260 | - 'EE_Cart' => 'CART', |
|
261 | - 'EE_Network_Config' => 'NET_CFG', |
|
262 | - 'EE_Request_Handler' => 'REQ', |
|
263 | - 'EE_Message_Resource_Manager' => 'MRM', |
|
264 | - 'EventEspresso\core\services\commands\CommandBus' => 'BUS', |
|
265 | - 'EventEspresso\core\services\assets\Registry' => 'AssetsRegistry', |
|
266 | - ) |
|
267 | - ); |
|
268 | - $this->load_core('Base', array(), true); |
|
269 | - // add our request and response objects to the cache |
|
270 | - $request_loader = $this->_dependency_map->class_loader( |
|
271 | - 'EventEspresso\core\services\request\Request' |
|
272 | - ); |
|
273 | - $this->_set_cached_class( |
|
274 | - $request_loader(), |
|
275 | - 'EventEspresso\core\services\request\Request' |
|
276 | - ); |
|
277 | - $response_loader = $this->_dependency_map->class_loader( |
|
278 | - 'EventEspresso\core\services\request\Response' |
|
279 | - ); |
|
280 | - $this->_set_cached_class( |
|
281 | - $response_loader(), |
|
282 | - 'EventEspresso\core\services\request\Response' |
|
283 | - ); |
|
284 | - add_action('AHEE__EE_System__set_hooks_for_core', array($this, 'init')); |
|
285 | - } |
|
286 | - |
|
287 | - |
|
288 | - /** |
|
289 | - * @return void |
|
290 | - */ |
|
291 | - public function init() |
|
292 | - { |
|
293 | - // Get current page protocol |
|
294 | - $protocol = isset($_SERVER['HTTPS']) ? 'https://' : 'http://'; |
|
295 | - // Output admin-ajax.php URL with same protocol as current page |
|
296 | - self::$i18n_js_strings['ajax_url'] = admin_url('admin-ajax.php', $protocol); |
|
297 | - self::$i18n_js_strings['wp_debug'] = defined('WP_DEBUG') ? WP_DEBUG : false; |
|
298 | - } |
|
299 | - |
|
300 | - |
|
301 | - /** |
|
302 | - * localize_i18n_js_strings |
|
303 | - * |
|
304 | - * @return string |
|
305 | - */ |
|
306 | - public static function localize_i18n_js_strings() |
|
307 | - { |
|
308 | - $i18n_js_strings = (array) self::$i18n_js_strings; |
|
309 | - foreach ($i18n_js_strings as $key => $value) { |
|
310 | - if (is_scalar($value)) { |
|
311 | - $i18n_js_strings[ $key ] = html_entity_decode((string) $value, ENT_QUOTES, 'UTF-8'); |
|
312 | - } |
|
313 | - } |
|
314 | - return '/* <![CDATA[ */ var eei18n = ' . wp_json_encode($i18n_js_strings) . '; /* ]]> */'; |
|
315 | - } |
|
316 | - |
|
317 | - |
|
318 | - /** |
|
319 | - * @param mixed string | EED_Module $module |
|
320 | - * @throws OutOfBoundsException |
|
321 | - * @throws InvalidArgumentException |
|
322 | - * @throws InvalidInterfaceException |
|
323 | - * @throws InvalidDataTypeException |
|
324 | - * @throws EE_Error |
|
325 | - * @throws ReflectionException |
|
326 | - */ |
|
327 | - public function add_module($module) |
|
328 | - { |
|
329 | - if ($module instanceof EED_Module) { |
|
330 | - $module_class = get_class($module); |
|
331 | - $this->modules->{$module_class} = $module; |
|
332 | - } else { |
|
333 | - if (! class_exists('EE_Module_Request_Router', false)) { |
|
334 | - $this->load_core('Module_Request_Router'); |
|
335 | - } |
|
336 | - EE_Module_Request_Router::module_factory($module); |
|
337 | - } |
|
338 | - } |
|
339 | - |
|
340 | - |
|
341 | - /** |
|
342 | - * @param string $module_name |
|
343 | - * @return mixed EED_Module | NULL |
|
344 | - */ |
|
345 | - public function get_module($module_name = '') |
|
346 | - { |
|
347 | - return isset($this->modules->{$module_name}) |
|
348 | - ? $this->modules->{$module_name} |
|
349 | - : null; |
|
350 | - } |
|
351 | - |
|
352 | - |
|
353 | - /** |
|
354 | - * loads core classes - must be singletons |
|
355 | - * |
|
356 | - * @param string $class_name - simple class name ie: session |
|
357 | - * @param mixed $arguments |
|
358 | - * @param bool $load_only |
|
359 | - * @return mixed |
|
360 | - * @throws InvalidInterfaceException |
|
361 | - * @throws InvalidDataTypeException |
|
362 | - * @throws EE_Error |
|
363 | - * @throws ReflectionException |
|
364 | - * @throws InvalidArgumentException |
|
365 | - */ |
|
366 | - public function load_core($class_name, $arguments = array(), $load_only = false) |
|
367 | - { |
|
368 | - $core_paths = apply_filters( |
|
369 | - 'FHEE__EE_Registry__load_core__core_paths', |
|
370 | - array( |
|
371 | - EE_CORE, |
|
372 | - EE_ADMIN, |
|
373 | - EE_CPTS, |
|
374 | - EE_CORE . 'data_migration_scripts/', |
|
375 | - EE_CORE . 'capabilities/', |
|
376 | - EE_CORE . 'request_stack/', |
|
377 | - EE_CORE . 'middleware/', |
|
378 | - ) |
|
379 | - ); |
|
380 | - // retrieve instantiated class |
|
381 | - return $this->_load( |
|
382 | - $core_paths, |
|
383 | - 'EE_', |
|
384 | - $class_name, |
|
385 | - 'core', |
|
386 | - $arguments, |
|
387 | - false, |
|
388 | - true, |
|
389 | - $load_only |
|
390 | - ); |
|
391 | - } |
|
392 | - |
|
393 | - |
|
394 | - /** |
|
395 | - * loads service classes |
|
396 | - * |
|
397 | - * @param string $class_name - simple class name ie: session |
|
398 | - * @param mixed $arguments |
|
399 | - * @param bool $load_only |
|
400 | - * @return mixed |
|
401 | - * @throws InvalidInterfaceException |
|
402 | - * @throws InvalidDataTypeException |
|
403 | - * @throws EE_Error |
|
404 | - * @throws ReflectionException |
|
405 | - * @throws InvalidArgumentException |
|
406 | - */ |
|
407 | - public function load_service($class_name, $arguments = array(), $load_only = false) |
|
408 | - { |
|
409 | - $service_paths = apply_filters( |
|
410 | - 'FHEE__EE_Registry__load_service__service_paths', |
|
411 | - array( |
|
412 | - EE_CORE . 'services/', |
|
413 | - ) |
|
414 | - ); |
|
415 | - // retrieve instantiated class |
|
416 | - return $this->_load( |
|
417 | - $service_paths, |
|
418 | - 'EE_', |
|
419 | - $class_name, |
|
420 | - 'class', |
|
421 | - $arguments, |
|
422 | - false, |
|
423 | - true, |
|
424 | - $load_only |
|
425 | - ); |
|
426 | - } |
|
427 | - |
|
428 | - |
|
429 | - /** |
|
430 | - * loads data_migration_scripts |
|
431 | - * |
|
432 | - * @param string $class_name - class name for the DMS ie: EE_DMS_Core_4_2_0 |
|
433 | - * @param mixed $arguments |
|
434 | - * @return EE_Data_Migration_Script_Base|mixed |
|
435 | - * @throws InvalidInterfaceException |
|
436 | - * @throws InvalidDataTypeException |
|
437 | - * @throws EE_Error |
|
438 | - * @throws ReflectionException |
|
439 | - * @throws InvalidArgumentException |
|
440 | - */ |
|
441 | - public function load_dms($class_name, $arguments = array()) |
|
442 | - { |
|
443 | - // retrieve instantiated class |
|
444 | - return $this->_load( |
|
445 | - EE_Data_Migration_Manager::instance()->get_data_migration_script_folders(), |
|
446 | - 'EE_DMS_', |
|
447 | - $class_name, |
|
448 | - 'dms', |
|
449 | - $arguments, |
|
450 | - false, |
|
451 | - false |
|
452 | - ); |
|
453 | - } |
|
454 | - |
|
455 | - |
|
456 | - /** |
|
457 | - * loads object creating classes - must be singletons |
|
458 | - * |
|
459 | - * @param string $class_name - simple class name ie: attendee |
|
460 | - * @param mixed $arguments - an array of arguments to pass to the class |
|
461 | - * @param bool $from_db - some classes are instantiated from the db and thus call a different method to |
|
462 | - * instantiate |
|
463 | - * @param bool $cache if you don't want the class to be stored in the internal cache (non-persistent) then |
|
464 | - * set this to FALSE (ie. when instantiating model objects from client in a loop) |
|
465 | - * @param bool $load_only whether or not to just load the file and NOT instantiate, or load AND instantiate |
|
466 | - * (default) |
|
467 | - * @return EE_Base_Class | bool |
|
468 | - * @throws InvalidInterfaceException |
|
469 | - * @throws InvalidDataTypeException |
|
470 | - * @throws EE_Error |
|
471 | - * @throws ReflectionException |
|
472 | - * @throws InvalidArgumentException |
|
473 | - */ |
|
474 | - public function load_class($class_name, $arguments = array(), $from_db = false, $cache = true, $load_only = false) |
|
475 | - { |
|
476 | - $paths = apply_filters( |
|
477 | - 'FHEE__EE_Registry__load_class__paths', |
|
478 | - array( |
|
479 | - EE_CORE, |
|
480 | - EE_CLASSES, |
|
481 | - EE_BUSINESS, |
|
482 | - ) |
|
483 | - ); |
|
484 | - // retrieve instantiated class |
|
485 | - return $this->_load( |
|
486 | - $paths, |
|
487 | - 'EE_', |
|
488 | - $class_name, |
|
489 | - 'class', |
|
490 | - $arguments, |
|
491 | - $from_db, |
|
492 | - $cache, |
|
493 | - $load_only |
|
494 | - ); |
|
495 | - } |
|
496 | - |
|
497 | - |
|
498 | - /** |
|
499 | - * loads helper classes - must be singletons |
|
500 | - * |
|
501 | - * @param string $class_name - simple class name ie: price |
|
502 | - * @param mixed $arguments |
|
503 | - * @param bool $load_only |
|
504 | - * @return EEH_Base | bool |
|
505 | - * @throws InvalidInterfaceException |
|
506 | - * @throws InvalidDataTypeException |
|
507 | - * @throws EE_Error |
|
508 | - * @throws ReflectionException |
|
509 | - * @throws InvalidArgumentException |
|
510 | - */ |
|
511 | - public function load_helper($class_name, $arguments = array(), $load_only = true) |
|
512 | - { |
|
513 | - // todo: add doing_it_wrong() in a few versions after all addons have had calls to this method removed |
|
514 | - $helper_paths = apply_filters('FHEE__EE_Registry__load_helper__helper_paths', array(EE_HELPERS)); |
|
515 | - // retrieve instantiated class |
|
516 | - return $this->_load( |
|
517 | - $helper_paths, |
|
518 | - 'EEH_', |
|
519 | - $class_name, |
|
520 | - 'helper', |
|
521 | - $arguments, |
|
522 | - false, |
|
523 | - true, |
|
524 | - $load_only |
|
525 | - ); |
|
526 | - } |
|
527 | - |
|
528 | - |
|
529 | - /** |
|
530 | - * loads core classes - must be singletons |
|
531 | - * |
|
532 | - * @param string $class_name - simple class name ie: session |
|
533 | - * @param mixed $arguments |
|
534 | - * @param bool $load_only |
|
535 | - * @param bool $cache whether to cache the object or not. |
|
536 | - * @return mixed |
|
537 | - * @throws InvalidInterfaceException |
|
538 | - * @throws InvalidDataTypeException |
|
539 | - * @throws EE_Error |
|
540 | - * @throws ReflectionException |
|
541 | - * @throws InvalidArgumentException |
|
542 | - */ |
|
543 | - public function load_lib($class_name, $arguments = array(), $load_only = false, $cache = true) |
|
544 | - { |
|
545 | - $paths = array( |
|
546 | - EE_LIBRARIES, |
|
547 | - EE_LIBRARIES . 'messages/', |
|
548 | - EE_LIBRARIES . 'shortcodes/', |
|
549 | - EE_LIBRARIES . 'qtips/', |
|
550 | - EE_LIBRARIES . 'payment_methods/', |
|
551 | - ); |
|
552 | - // retrieve instantiated class |
|
553 | - return $this->_load( |
|
554 | - $paths, |
|
555 | - 'EE_', |
|
556 | - $class_name, |
|
557 | - 'lib', |
|
558 | - $arguments, |
|
559 | - false, |
|
560 | - $cache, |
|
561 | - $load_only |
|
562 | - ); |
|
563 | - } |
|
564 | - |
|
565 | - |
|
566 | - /** |
|
567 | - * loads model classes - must be singletons |
|
568 | - * |
|
569 | - * @param string $class_name - simple class name ie: price |
|
570 | - * @param mixed $arguments |
|
571 | - * @param bool $load_only |
|
572 | - * @return EEM_Base | bool |
|
573 | - * @throws InvalidInterfaceException |
|
574 | - * @throws InvalidDataTypeException |
|
575 | - * @throws EE_Error |
|
576 | - * @throws ReflectionException |
|
577 | - * @throws InvalidArgumentException |
|
578 | - */ |
|
579 | - public function load_model($class_name, $arguments = array(), $load_only = false) |
|
580 | - { |
|
581 | - $paths = apply_filters( |
|
582 | - 'FHEE__EE_Registry__load_model__paths', |
|
583 | - array( |
|
584 | - EE_MODELS, |
|
585 | - EE_CORE, |
|
586 | - ) |
|
587 | - ); |
|
588 | - // retrieve instantiated class |
|
589 | - return $this->_load( |
|
590 | - $paths, |
|
591 | - 'EEM_', |
|
592 | - $class_name, |
|
593 | - 'model', |
|
594 | - $arguments, |
|
595 | - false, |
|
596 | - true, |
|
597 | - $load_only |
|
598 | - ); |
|
599 | - } |
|
600 | - |
|
601 | - |
|
602 | - /** |
|
603 | - * loads model classes - must be singletons |
|
604 | - * |
|
605 | - * @param string $class_name - simple class name ie: price |
|
606 | - * @param mixed $arguments |
|
607 | - * @param bool $load_only |
|
608 | - * @return mixed | bool |
|
609 | - * @throws InvalidInterfaceException |
|
610 | - * @throws InvalidDataTypeException |
|
611 | - * @throws EE_Error |
|
612 | - * @throws ReflectionException |
|
613 | - * @throws InvalidArgumentException |
|
614 | - */ |
|
615 | - public function load_model_class($class_name, $arguments = array(), $load_only = true) |
|
616 | - { |
|
617 | - $paths = array( |
|
618 | - EE_MODELS . 'fields/', |
|
619 | - EE_MODELS . 'helpers/', |
|
620 | - EE_MODELS . 'relations/', |
|
621 | - EE_MODELS . 'strategies/', |
|
622 | - ); |
|
623 | - // retrieve instantiated class |
|
624 | - return $this->_load( |
|
625 | - $paths, |
|
626 | - 'EE_', |
|
627 | - $class_name, |
|
628 | - '', |
|
629 | - $arguments, |
|
630 | - false, |
|
631 | - true, |
|
632 | - $load_only |
|
633 | - ); |
|
634 | - } |
|
635 | - |
|
636 | - |
|
637 | - /** |
|
638 | - * Determines if $model_name is the name of an actual EE model. |
|
639 | - * |
|
640 | - * @param string $model_name like Event, Attendee, Question_Group_Question, etc. |
|
641 | - * @return boolean |
|
642 | - */ |
|
643 | - public function is_model_name($model_name) |
|
644 | - { |
|
645 | - return isset($this->models[ $model_name ]); |
|
646 | - } |
|
647 | - |
|
648 | - |
|
649 | - /** |
|
650 | - * generic class loader |
|
651 | - * |
|
652 | - * @param string $path_to_file - directory path to file location, not including filename |
|
653 | - * @param string $file_name - file name ie: my_file.php, including extension |
|
654 | - * @param string $type - file type - core? class? helper? model? |
|
655 | - * @param mixed $arguments |
|
656 | - * @param bool $load_only |
|
657 | - * @return mixed |
|
658 | - * @throws InvalidInterfaceException |
|
659 | - * @throws InvalidDataTypeException |
|
660 | - * @throws EE_Error |
|
661 | - * @throws ReflectionException |
|
662 | - * @throws InvalidArgumentException |
|
663 | - */ |
|
664 | - public function load_file($path_to_file, $file_name, $type = '', $arguments = array(), $load_only = true) |
|
665 | - { |
|
666 | - // retrieve instantiated class |
|
667 | - return $this->_load( |
|
668 | - $path_to_file, |
|
669 | - '', |
|
670 | - $file_name, |
|
671 | - $type, |
|
672 | - $arguments, |
|
673 | - false, |
|
674 | - true, |
|
675 | - $load_only |
|
676 | - ); |
|
677 | - } |
|
678 | - |
|
679 | - |
|
680 | - /** |
|
681 | - * @param string $path_to_file - directory path to file location, not including filename |
|
682 | - * @param string $class_name - full class name ie: My_Class |
|
683 | - * @param string $type - file type - core? class? helper? model? |
|
684 | - * @param mixed $arguments |
|
685 | - * @param bool $load_only |
|
686 | - * @return bool|EE_Addon|object |
|
687 | - * @throws InvalidInterfaceException |
|
688 | - * @throws InvalidDataTypeException |
|
689 | - * @throws EE_Error |
|
690 | - * @throws ReflectionException |
|
691 | - * @throws InvalidArgumentException |
|
692 | - */ |
|
693 | - public function load_addon($path_to_file, $class_name, $type = 'class', $arguments = array(), $load_only = false) |
|
694 | - { |
|
695 | - // retrieve instantiated class |
|
696 | - return $this->_load( |
|
697 | - $path_to_file, |
|
698 | - 'addon', |
|
699 | - $class_name, |
|
700 | - $type, |
|
701 | - $arguments, |
|
702 | - false, |
|
703 | - true, |
|
704 | - $load_only |
|
705 | - ); |
|
706 | - } |
|
707 | - |
|
708 | - |
|
709 | - /** |
|
710 | - * instantiates, caches, and automatically resolves dependencies |
|
711 | - * for classes that use a Fully Qualified Class Name. |
|
712 | - * if the class is not capable of being loaded using PSR-4 autoloading, |
|
713 | - * then you need to use one of the existing load_*() methods |
|
714 | - * which can resolve the classname and filepath from the passed arguments |
|
715 | - * |
|
716 | - * @param bool|string $class_name Fully Qualified Class Name |
|
717 | - * @param array $arguments an argument, or array of arguments to pass to the class upon instantiation |
|
718 | - * @param bool $cache whether to cache the instantiated object for reuse |
|
719 | - * @param bool $from_db some classes are instantiated from the db |
|
720 | - * and thus call a different method to instantiate |
|
721 | - * @param bool $load_only if true, will only load the file, but will NOT instantiate an object |
|
722 | - * @param bool|string $addon if true, will cache the object in the EE_Registry->$addons array |
|
723 | - * @return bool|null|mixed null = failure to load or instantiate class object. |
|
724 | - * object = class loaded and instantiated successfully. |
|
725 | - * bool = fail or success when $load_only is true |
|
726 | - * @throws InvalidInterfaceException |
|
727 | - * @throws InvalidDataTypeException |
|
728 | - * @throws EE_Error |
|
729 | - * @throws ReflectionException |
|
730 | - * @throws InvalidArgumentException |
|
731 | - */ |
|
732 | - public function create( |
|
733 | - $class_name = false, |
|
734 | - $arguments = array(), |
|
735 | - $cache = false, |
|
736 | - $from_db = false, |
|
737 | - $load_only = false, |
|
738 | - $addon = false |
|
739 | - ) { |
|
740 | - $class_name = ltrim($class_name, '\\'); |
|
741 | - $class_name = $this->class_cache->getFqnForAlias($class_name); |
|
742 | - $class_exists = $this->loadOrVerifyClassExists($class_name, $arguments); |
|
743 | - // if a non-FQCN was passed, then |
|
744 | - // verifyClassExists() might return an object |
|
745 | - // or it could return null if the class just could not be found anywhere |
|
746 | - if ($class_exists instanceof $class_name || $class_exists === null) { |
|
747 | - // either way, return the results |
|
748 | - return $class_exists; |
|
749 | - } |
|
750 | - $class_name = $class_exists; |
|
751 | - // if we're only loading the class and it already exists, then let's just return true immediately |
|
752 | - if ($load_only) { |
|
753 | - return true; |
|
754 | - } |
|
755 | - $addon = $addon ? 'addon' : ''; |
|
756 | - // $this->_cache_on is toggled during the recursive loading that can occur with dependency injection |
|
757 | - // $cache is controlled by individual calls to separate Registry loader methods like load_class() |
|
758 | - // $load_only is also controlled by individual calls to separate Registry loader methods like load_file() |
|
759 | - if ($this->_cache_on && $cache && ! $load_only) { |
|
760 | - // return object if it's already cached |
|
761 | - $cached_class = $this->_get_cached_class($class_name, $addon, $arguments); |
|
762 | - if ($cached_class !== null) { |
|
763 | - return $cached_class; |
|
764 | - } |
|
765 | - }// obtain the loader method from the dependency map |
|
766 | - $loader = $this->_dependency_map->class_loader($class_name);// instantiate the requested object |
|
767 | - if ($loader instanceof Closure) { |
|
768 | - $class_obj = $loader($arguments); |
|
769 | - } else { |
|
770 | - if ($loader && method_exists($this, $loader)) { |
|
771 | - $class_obj = $this->{$loader}($class_name, $arguments); |
|
772 | - } else { |
|
773 | - $class_obj = $this->_create_object($class_name, $arguments, $addon, $from_db); |
|
774 | - } |
|
775 | - } |
|
776 | - if (($this->_cache_on && $cache) || $this->get_class_abbreviation($class_name, '')) { |
|
777 | - // save it for later... kinda like gum { : $ |
|
778 | - $this->_set_cached_class( |
|
779 | - $class_obj, |
|
780 | - $class_name, |
|
781 | - $addon, |
|
782 | - $from_db, |
|
783 | - $arguments |
|
784 | - ); |
|
785 | - } |
|
786 | - $this->_cache_on = true; |
|
787 | - return $class_obj; |
|
788 | - } |
|
789 | - |
|
790 | - |
|
791 | - /** |
|
792 | - * Recursively checks that a class exists and potentially attempts to load classes with non-FQCNs |
|
793 | - * |
|
794 | - * @param string|object $class_name |
|
795 | - * @param array $arguments |
|
796 | - * @param int $attempt |
|
797 | - * @return mixed |
|
798 | - */ |
|
799 | - private function loadOrVerifyClassExists($class_name, array $arguments, $attempt = 1) |
|
800 | - { |
|
801 | - if (is_object($class_name) || class_exists($class_name)) { |
|
802 | - return $class_name; |
|
803 | - } |
|
804 | - switch ($attempt) { |
|
805 | - case 1: |
|
806 | - // if it's a FQCN then maybe the class is registered with a preceding \ |
|
807 | - $class_name = strpos($class_name, '\\') !== false |
|
808 | - ? '\\' . ltrim($class_name, '\\') |
|
809 | - : $class_name; |
|
810 | - break; |
|
811 | - case 2: |
|
812 | - // |
|
813 | - $loader = $this->_dependency_map->class_loader($class_name); |
|
814 | - if ($loader && method_exists($this, $loader)) { |
|
815 | - return $this->{$loader}($class_name, $arguments); |
|
816 | - } |
|
817 | - break; |
|
818 | - case 3: |
|
819 | - default: |
|
820 | - return null; |
|
821 | - } |
|
822 | - $attempt++; |
|
823 | - return $this->loadOrVerifyClassExists($class_name, $arguments, $attempt); |
|
824 | - } |
|
825 | - |
|
826 | - |
|
827 | - /** |
|
828 | - * instantiates, caches, and injects dependencies for classes |
|
829 | - * |
|
830 | - * @param array $file_paths an array of paths to folders to look in |
|
831 | - * @param string $class_prefix EE or EEM or... ??? |
|
832 | - * @param bool|string $class_name $class name |
|
833 | - * @param string $type file type - core? class? helper? model? |
|
834 | - * @param mixed $arguments an argument or array of arguments to pass to the class upon instantiation |
|
835 | - * @param bool $from_db some classes are instantiated from the db |
|
836 | - * and thus call a different method to instantiate |
|
837 | - * @param bool $cache whether to cache the instantiated object for reuse |
|
838 | - * @param bool $load_only if true, will only load the file, but will NOT instantiate an object |
|
839 | - * @return bool|null|object null = failure to load or instantiate class object. |
|
840 | - * object = class loaded and instantiated successfully. |
|
841 | - * bool = fail or success when $load_only is true |
|
842 | - * @throws EE_Error |
|
843 | - * @throws ReflectionException |
|
844 | - * @throws InvalidInterfaceException |
|
845 | - * @throws InvalidDataTypeException |
|
846 | - * @throws InvalidArgumentException |
|
847 | - */ |
|
848 | - protected function _load( |
|
849 | - $file_paths = array(), |
|
850 | - $class_prefix = 'EE_', |
|
851 | - $class_name = false, |
|
852 | - $type = 'class', |
|
853 | - $arguments = array(), |
|
854 | - $from_db = false, |
|
855 | - $cache = true, |
|
856 | - $load_only = false |
|
857 | - ) { |
|
858 | - $class_name = ltrim($class_name, '\\'); |
|
859 | - // strip php file extension |
|
860 | - $class_name = str_replace('.php', '', trim($class_name)); |
|
861 | - // does the class have a prefix ? |
|
862 | - if (! empty($class_prefix) && $class_prefix !== 'addon') { |
|
863 | - // make sure $class_prefix is uppercase |
|
864 | - $class_prefix = strtoupper(trim($class_prefix)); |
|
865 | - // add class prefix ONCE!!! |
|
866 | - $class_name = $class_prefix . str_replace($class_prefix, '', $class_name); |
|
867 | - } |
|
868 | - $class_name = $this->class_cache->getFqnForAlias($class_name); |
|
869 | - $class_exists = class_exists($class_name, false); |
|
870 | - // if we're only loading the class and it already exists, then let's just return true immediately |
|
871 | - if ($load_only && $class_exists) { |
|
872 | - return true; |
|
873 | - } |
|
874 | - $arguments = is_array($arguments) ? $arguments : array($arguments); |
|
875 | - // $this->_cache_on is toggled during the recursive loading that can occur with dependency injection |
|
876 | - // $cache is controlled by individual calls to separate Registry loader methods like load_class() |
|
877 | - // $load_only is also controlled by individual calls to separate Registry loader methods like load_file() |
|
878 | - if ($this->_cache_on && $cache && ! $load_only) { |
|
879 | - // return object if it's already cached |
|
880 | - $cached_class = $this->_get_cached_class($class_name, $class_prefix, $arguments); |
|
881 | - if ($cached_class !== null) { |
|
882 | - return $cached_class; |
|
883 | - } |
|
884 | - } |
|
885 | - // if the class doesn't already exist.. then we need to try and find the file and load it |
|
886 | - if (! $class_exists) { |
|
887 | - // get full path to file |
|
888 | - $path = $this->_resolve_path($class_name, $type, $file_paths); |
|
889 | - // load the file |
|
890 | - $loaded = $this->_require_file($path, $class_name, $type, $file_paths); |
|
891 | - // if we are only loading a file but NOT instantiating an object |
|
892 | - // then return boolean for whether class was loaded or not |
|
893 | - if ($load_only) { |
|
894 | - return $loaded; |
|
895 | - } |
|
896 | - // if an object was expected but loading failed, then return nothing |
|
897 | - if (! $loaded) { |
|
898 | - return null; |
|
899 | - } |
|
900 | - } |
|
901 | - // instantiate the requested object |
|
902 | - $class_obj = $this->_create_object($class_name, $arguments, $type, $from_db); |
|
903 | - if ($this->_cache_on && $cache) { |
|
904 | - // save it for later... kinda like gum { : $ |
|
905 | - $this->_set_cached_class( |
|
906 | - $class_obj, |
|
907 | - $class_name, |
|
908 | - $class_prefix, |
|
909 | - $from_db, |
|
910 | - $arguments |
|
911 | - ); |
|
912 | - } |
|
913 | - $this->_cache_on = true; |
|
914 | - return $class_obj; |
|
915 | - } |
|
916 | - |
|
917 | - |
|
918 | - /** |
|
919 | - * @param string $class_name |
|
920 | - * @param string $default have to specify something, but not anything that will conflict |
|
921 | - * @return mixed|string |
|
922 | - */ |
|
923 | - protected function get_class_abbreviation($class_name, $default = 'FANCY_BATMAN_PANTS') |
|
924 | - { |
|
925 | - return isset($this->_class_abbreviations[ $class_name ]) |
|
926 | - ? $this->_class_abbreviations[ $class_name ] |
|
927 | - : $default; |
|
928 | - } |
|
929 | - |
|
930 | - |
|
931 | - /** |
|
932 | - * attempts to find a cached version of the requested class |
|
933 | - * by looking in the following places: |
|
934 | - * $this->{$class_abbreviation} ie: $this->CART |
|
935 | - * $this->{$class_name} ie: $this->Some_Class |
|
936 | - * $this->LIB->{$class_name} ie: $this->LIB->Some_Class |
|
937 | - * $this->addon->{$class_name} ie: $this->addon->Some_Addon_Class |
|
938 | - * |
|
939 | - * @param string $class_name |
|
940 | - * @param string $class_prefix |
|
941 | - * @param array $arguments |
|
942 | - * @return mixed |
|
943 | - */ |
|
944 | - protected function _get_cached_class( |
|
945 | - $class_name, |
|
946 | - $class_prefix = '', |
|
947 | - $arguments = array() |
|
948 | - ) { |
|
949 | - if ($class_name === 'EE_Registry') { |
|
950 | - return $this; |
|
951 | - } |
|
952 | - $class_abbreviation = $this->get_class_abbreviation($class_name); |
|
953 | - // check if class has already been loaded, and return it if it has been |
|
954 | - if (isset($this->{$class_abbreviation})) { |
|
955 | - return $this->{$class_abbreviation}; |
|
956 | - } |
|
957 | - $class_name = str_replace('\\', '_', $class_name); |
|
958 | - if (isset($this->{$class_name})) { |
|
959 | - return $this->{$class_name}; |
|
960 | - } |
|
961 | - if ($class_prefix === 'addon' && isset($this->addons->{$class_name})) { |
|
962 | - return $this->addons->{$class_name}; |
|
963 | - } |
|
964 | - $object_identifier = $this->object_identifier->getIdentifier($class_name, $arguments); |
|
965 | - if (isset($this->LIB->{$object_identifier})) { |
|
966 | - return $this->LIB->{$object_identifier}; |
|
967 | - } |
|
968 | - foreach ($this->LIB as $key => $object) { |
|
969 | - if (// request does not contain new arguments and therefore no args identifier |
|
970 | - ! $this->object_identifier->hasArguments($object_identifier) |
|
971 | - // but previously cached class with args was found |
|
972 | - && $this->object_identifier->fqcnMatchesObjectIdentifier($class_name, $key) |
|
973 | - ) { |
|
974 | - return $object; |
|
975 | - } |
|
976 | - } |
|
977 | - return null; |
|
978 | - } |
|
979 | - |
|
980 | - |
|
981 | - /** |
|
982 | - * removes a cached version of the requested class |
|
983 | - * |
|
984 | - * @param string $class_name |
|
985 | - * @param boolean $addon |
|
986 | - * @param array $arguments |
|
987 | - * @return boolean |
|
988 | - */ |
|
989 | - public function clear_cached_class( |
|
990 | - $class_name, |
|
991 | - $addon = false, |
|
992 | - $arguments = array() |
|
993 | - ) { |
|
994 | - $class_abbreviation = $this->get_class_abbreviation($class_name); |
|
995 | - // check if class has already been loaded, and return it if it has been |
|
996 | - if (isset($this->{$class_abbreviation})) { |
|
997 | - $this->{$class_abbreviation} = null; |
|
998 | - return true; |
|
999 | - } |
|
1000 | - $class_name = str_replace('\\', '_', $class_name); |
|
1001 | - if (isset($this->{$class_name})) { |
|
1002 | - $this->{$class_name} = null; |
|
1003 | - return true; |
|
1004 | - } |
|
1005 | - if ($addon && isset($this->addons->{$class_name})) { |
|
1006 | - unset($this->addons->{$class_name}); |
|
1007 | - return true; |
|
1008 | - } |
|
1009 | - $class_name = $this->object_identifier->getIdentifier($class_name, $arguments); |
|
1010 | - if (isset($this->LIB->{$class_name})) { |
|
1011 | - unset($this->LIB->{$class_name}); |
|
1012 | - return true; |
|
1013 | - } |
|
1014 | - return false; |
|
1015 | - } |
|
1016 | - |
|
1017 | - |
|
1018 | - /** |
|
1019 | - * _set_cached_class |
|
1020 | - * attempts to cache the instantiated class locally |
|
1021 | - * in one of the following places, in the following order: |
|
1022 | - * $this->{class_abbreviation} ie: $this->CART |
|
1023 | - * $this->{$class_name} ie: $this->Some_Class |
|
1024 | - * $this->addon->{$$class_name} ie: $this->addon->Some_Addon_Class |
|
1025 | - * $this->LIB->{$class_name} ie: $this->LIB->Some_Class |
|
1026 | - * |
|
1027 | - * @param object $class_obj |
|
1028 | - * @param string $class_name |
|
1029 | - * @param string $class_prefix |
|
1030 | - * @param bool $from_db |
|
1031 | - * @param array $arguments |
|
1032 | - * @return void |
|
1033 | - */ |
|
1034 | - protected function _set_cached_class( |
|
1035 | - $class_obj, |
|
1036 | - $class_name, |
|
1037 | - $class_prefix = '', |
|
1038 | - $from_db = false, |
|
1039 | - $arguments = array() |
|
1040 | - ) { |
|
1041 | - if ($class_name === 'EE_Registry' || empty($class_obj)) { |
|
1042 | - return; |
|
1043 | - } |
|
1044 | - // return newly instantiated class |
|
1045 | - $class_abbreviation = $this->get_class_abbreviation($class_name, ''); |
|
1046 | - if ($class_abbreviation) { |
|
1047 | - $this->{$class_abbreviation} = $class_obj; |
|
1048 | - return; |
|
1049 | - } |
|
1050 | - $class_name = str_replace('\\', '_', $class_name); |
|
1051 | - if (property_exists($this, $class_name)) { |
|
1052 | - $this->{$class_name} = $class_obj; |
|
1053 | - return; |
|
1054 | - } |
|
1055 | - if ($class_prefix === 'addon') { |
|
1056 | - $this->addons->{$class_name} = $class_obj; |
|
1057 | - return; |
|
1058 | - } |
|
1059 | - if (! $from_db) { |
|
1060 | - $class_name = $this->object_identifier->getIdentifier($class_name, $arguments); |
|
1061 | - $this->LIB->{$class_name} = $class_obj; |
|
1062 | - } |
|
1063 | - } |
|
1064 | - |
|
1065 | - |
|
1066 | - /** |
|
1067 | - * attempts to find a full valid filepath for the requested class. |
|
1068 | - * loops thru each of the base paths in the $file_paths array and appends : "{classname} . {file type} . php" |
|
1069 | - * then returns that path if the target file has been found and is readable |
|
1070 | - * |
|
1071 | - * @param string $class_name |
|
1072 | - * @param string $type |
|
1073 | - * @param array $file_paths |
|
1074 | - * @return string | bool |
|
1075 | - */ |
|
1076 | - protected function _resolve_path($class_name, $type = '', $file_paths = array()) |
|
1077 | - { |
|
1078 | - // make sure $file_paths is an array |
|
1079 | - $file_paths = is_array($file_paths) |
|
1080 | - ? $file_paths |
|
1081 | - : array($file_paths); |
|
1082 | - // cycle thru paths |
|
1083 | - foreach ($file_paths as $key => $file_path) { |
|
1084 | - // convert all separators to proper /, if no filepath, then use EE_CLASSES |
|
1085 | - $file_path = $file_path |
|
1086 | - ? str_replace(array('/', '\\'), '/', $file_path) |
|
1087 | - : EE_CLASSES; |
|
1088 | - // prep file type |
|
1089 | - $type = ! empty($type) |
|
1090 | - ? trim($type, '.') . '.' |
|
1091 | - : ''; |
|
1092 | - // build full file path |
|
1093 | - $file_paths[ $key ] = rtrim($file_path, '/') . '/' . $class_name . '.' . $type . 'php'; |
|
1094 | - // does the file exist and can be read ? |
|
1095 | - if (is_readable($file_paths[ $key ])) { |
|
1096 | - return $file_paths[ $key ]; |
|
1097 | - } |
|
1098 | - } |
|
1099 | - return false; |
|
1100 | - } |
|
1101 | - |
|
1102 | - |
|
1103 | - /** |
|
1104 | - * basically just performs a require_once() |
|
1105 | - * but with some error handling |
|
1106 | - * |
|
1107 | - * @param string $path |
|
1108 | - * @param string $class_name |
|
1109 | - * @param string $type |
|
1110 | - * @param array $file_paths |
|
1111 | - * @return bool |
|
1112 | - * @throws EE_Error |
|
1113 | - * @throws ReflectionException |
|
1114 | - */ |
|
1115 | - protected function _require_file($path, $class_name, $type = '', $file_paths = array()) |
|
1116 | - { |
|
1117 | - $this->resolve_legacy_class_parent($class_name); |
|
1118 | - // don't give up! you gotta... |
|
1119 | - try { |
|
1120 | - // does the file exist and can it be read ? |
|
1121 | - if (! $path) { |
|
1122 | - // just in case the file has already been autoloaded, |
|
1123 | - // but discrepancies in the naming schema are preventing it from |
|
1124 | - // being loaded via one of the EE_Registry::load_*() methods, |
|
1125 | - // then let's try one last hail mary before throwing an exception |
|
1126 | - // and call class_exists() again, but with autoloading turned ON |
|
1127 | - if (class_exists($class_name)) { |
|
1128 | - return true; |
|
1129 | - } |
|
1130 | - // so sorry, can't find the file |
|
1131 | - throw new EE_Error( |
|
1132 | - sprintf( |
|
1133 | - esc_html__( |
|
1134 | - 'The %1$s file %2$s could not be located or is not readable due to file permissions. Please ensure that the following filepath(s) are correct: %3$s', |
|
1135 | - 'event_espresso' |
|
1136 | - ), |
|
1137 | - trim($type, '.'), |
|
1138 | - $class_name, |
|
1139 | - '<br />' . implode(',<br />', $file_paths) |
|
1140 | - ) |
|
1141 | - ); |
|
1142 | - } |
|
1143 | - // get the file |
|
1144 | - require_once($path); |
|
1145 | - // if the class isn't already declared somewhere |
|
1146 | - if (class_exists($class_name, false) === false) { |
|
1147 | - // so sorry, not a class |
|
1148 | - throw new EE_Error( |
|
1149 | - sprintf( |
|
1150 | - esc_html__( |
|
1151 | - 'The %s file %s does not appear to contain the %s Class.', |
|
1152 | - 'event_espresso' |
|
1153 | - ), |
|
1154 | - $type, |
|
1155 | - $path, |
|
1156 | - $class_name |
|
1157 | - ) |
|
1158 | - ); |
|
1159 | - } |
|
1160 | - } catch (EE_Error $e) { |
|
1161 | - $e->get_error(); |
|
1162 | - return false; |
|
1163 | - } |
|
1164 | - return true; |
|
1165 | - } |
|
1166 | - |
|
1167 | - |
|
1168 | - /** |
|
1169 | - * Some of our legacy classes that extended a parent class would simply use a require() statement |
|
1170 | - * before their class declaration in order to ensure that the parent class was loaded. |
|
1171 | - * This is not ideal, but it's nearly impossible to determine the parent class of a non-namespaced class, |
|
1172 | - * without triggering a fatal error because the parent class has yet to be loaded and therefore doesn't exist. |
|
1173 | - * |
|
1174 | - * @param string $class_name |
|
1175 | - */ |
|
1176 | - protected function resolve_legacy_class_parent($class_name = '') |
|
1177 | - { |
|
1178 | - try { |
|
1179 | - $legacy_parent_class_map = array( |
|
1180 | - 'EE_Payment_Processor' => 'core/business/EE_Processor_Base.class.php', |
|
1181 | - ); |
|
1182 | - if (isset($legacy_parent_class_map[ $class_name ])) { |
|
1183 | - require_once EE_PLUGIN_DIR_PATH . $legacy_parent_class_map[ $class_name ]; |
|
1184 | - } |
|
1185 | - } catch (Exception $exception) { |
|
1186 | - } |
|
1187 | - } |
|
1188 | - |
|
1189 | - |
|
1190 | - /** |
|
1191 | - * _create_object |
|
1192 | - * Attempts to instantiate the requested class via any of the |
|
1193 | - * commonly used instantiation methods employed throughout EE. |
|
1194 | - * The priority for instantiation is as follows: |
|
1195 | - * - abstract classes or any class flagged as "load only" (no instantiation occurs) |
|
1196 | - * - model objects via their 'new_instance_from_db' method |
|
1197 | - * - model objects via their 'new_instance' method |
|
1198 | - * - "singleton" classes" via their 'instance' method |
|
1199 | - * - standard instantiable classes via their __constructor |
|
1200 | - * Prior to instantiation, if the classname exists in the dependency_map, |
|
1201 | - * then the constructor for the requested class will be examined to determine |
|
1202 | - * if any dependencies exist, and if they can be injected. |
|
1203 | - * If so, then those classes will be added to the array of arguments passed to the constructor |
|
1204 | - * |
|
1205 | - * @param string $class_name |
|
1206 | - * @param array $arguments |
|
1207 | - * @param string $type |
|
1208 | - * @param bool $from_db |
|
1209 | - * @return null|object|bool |
|
1210 | - * @throws InvalidArgumentException |
|
1211 | - * @throws InvalidInterfaceException |
|
1212 | - * @throws EE_Error |
|
1213 | - * @throws ReflectionException |
|
1214 | - * @throws InvalidDataTypeException |
|
1215 | - */ |
|
1216 | - protected function _create_object($class_name, $arguments = array(), $type = '', $from_db = false) |
|
1217 | - { |
|
1218 | - // create reflection |
|
1219 | - $reflector = $this->mirror->getReflectionClass($class_name); |
|
1220 | - // make sure arguments are an array |
|
1221 | - $arguments = is_array($arguments) |
|
1222 | - ? $arguments |
|
1223 | - : array($arguments); |
|
1224 | - // and if arguments array is numerically and sequentially indexed, then we want it to remain as is, |
|
1225 | - // else wrap it in an additional array so that it doesn't get split into multiple parameters |
|
1226 | - $arguments = $this->_array_is_numerically_and_sequentially_indexed($arguments) |
|
1227 | - ? $arguments |
|
1228 | - : array($arguments); |
|
1229 | - // attempt to inject dependencies ? |
|
1230 | - if ($this->_dependency_map->has($class_name)) { |
|
1231 | - $arguments = $this->_resolve_dependencies($reflector, $class_name, $arguments); |
|
1232 | - } |
|
1233 | - // instantiate the class if possible |
|
1234 | - if ($reflector->isAbstract()) { |
|
1235 | - // nothing to instantiate, loading file was enough |
|
1236 | - // does not throw an exception so $instantiation_mode is unused |
|
1237 | - // $instantiation_mode = "1) no constructor abstract class"; |
|
1238 | - return true; |
|
1239 | - } |
|
1240 | - if (empty($arguments) |
|
1241 | - && $this->mirror->getConstructorFromReflection($reflector) === null |
|
1242 | - && $reflector->isInstantiable() |
|
1243 | - ) { |
|
1244 | - // no constructor = static methods only... nothing to instantiate, loading file was enough |
|
1245 | - // $instantiation_mode = "2) no constructor but instantiable"; |
|
1246 | - return $reflector->newInstance(); |
|
1247 | - } |
|
1248 | - if ($from_db && method_exists($class_name, 'new_instance_from_db')) { |
|
1249 | - // $instantiation_mode = "3) new_instance_from_db()"; |
|
1250 | - return call_user_func_array(array($class_name, 'new_instance_from_db'), $arguments); |
|
1251 | - } |
|
1252 | - if (method_exists($class_name, 'new_instance')) { |
|
1253 | - // $instantiation_mode = "4) new_instance()"; |
|
1254 | - return call_user_func_array(array($class_name, 'new_instance'), $arguments); |
|
1255 | - } |
|
1256 | - if (method_exists($class_name, 'instance')) { |
|
1257 | - // $instantiation_mode = "5) instance()"; |
|
1258 | - return call_user_func_array(array($class_name, 'instance'), $arguments); |
|
1259 | - } |
|
1260 | - if ($reflector->isInstantiable()) { |
|
1261 | - // $instantiation_mode = "6) constructor"; |
|
1262 | - return $reflector->newInstanceArgs($arguments); |
|
1263 | - } |
|
1264 | - // heh ? something's not right ! |
|
1265 | - throw new EE_Error( |
|
1266 | - sprintf( |
|
1267 | - __('The %s file %s could not be instantiated.', 'event_espresso'), |
|
1268 | - $type, |
|
1269 | - $class_name |
|
1270 | - ) |
|
1271 | - ); |
|
1272 | - } |
|
1273 | - |
|
1274 | - |
|
1275 | - /** |
|
1276 | - * @see http://stackoverflow.com/questions/173400/how-to-check-if-php-array-is-associative-or-sequential |
|
1277 | - * @param array $array |
|
1278 | - * @return bool |
|
1279 | - */ |
|
1280 | - protected function _array_is_numerically_and_sequentially_indexed(array $array) |
|
1281 | - { |
|
1282 | - return ! empty($array) |
|
1283 | - ? array_keys($array) === range(0, count($array) - 1) |
|
1284 | - : true; |
|
1285 | - } |
|
1286 | - |
|
1287 | - |
|
1288 | - /** |
|
1289 | - * _resolve_dependencies |
|
1290 | - * examines the constructor for the requested class to determine |
|
1291 | - * if any dependencies exist, and if they can be injected. |
|
1292 | - * If so, then those classes will be added to the array of arguments passed to the constructor |
|
1293 | - * PLZ NOTE: this is achieved by type hinting the constructor params |
|
1294 | - * For example: |
|
1295 | - * if attempting to load a class "Foo" with the following constructor: |
|
1296 | - * __construct( Bar $bar_class, Fighter $grohl_class ) |
|
1297 | - * then $bar_class and $grohl_class will be added to the $arguments array, |
|
1298 | - * but only IF they are NOT already present in the incoming arguments array, |
|
1299 | - * and the correct classes can be loaded |
|
1300 | - * |
|
1301 | - * @param ReflectionClass $reflector |
|
1302 | - * @param string $class_name |
|
1303 | - * @param array $arguments |
|
1304 | - * @return array |
|
1305 | - * @throws InvalidArgumentException |
|
1306 | - * @throws InvalidDataTypeException |
|
1307 | - * @throws InvalidInterfaceException |
|
1308 | - * @throws ReflectionException |
|
1309 | - */ |
|
1310 | - protected function _resolve_dependencies(ReflectionClass $reflector, $class_name, array $arguments = array()) |
|
1311 | - { |
|
1312 | - // let's examine the constructor |
|
1313 | - $constructor = $this->mirror->getConstructorFromReflection($reflector); |
|
1314 | - // whu? huh? nothing? |
|
1315 | - if (! $constructor) { |
|
1316 | - return $arguments; |
|
1317 | - } |
|
1318 | - // get constructor parameters |
|
1319 | - $params = $this->mirror->getParametersFromReflection($reflector); |
|
1320 | - // and the keys for the incoming arguments array so that we can compare existing arguments with what is expected |
|
1321 | - $argument_keys = array_keys($arguments); |
|
1322 | - // now loop thru all of the constructors expected parameters |
|
1323 | - foreach ($params as $index => $param) { |
|
1324 | - try { |
|
1325 | - // is this a dependency for a specific class ? |
|
1326 | - $param_class = $this->mirror->getParameterClassName($param, $class_name, $index); |
|
1327 | - } catch (ReflectionException $exception) { |
|
1328 | - // uh-oh... most likely a legacy class that has not been autoloaded |
|
1329 | - // let's try to derive the classname from what we have now |
|
1330 | - // and hope that the property var name is close to the class name |
|
1331 | - $param_class = $param->getName(); |
|
1332 | - $param_class = str_replace('_', ' ', $param_class); |
|
1333 | - $param_class = ucwords($param_class); |
|
1334 | - $param_class = str_replace(' ', '_', $param_class); |
|
1335 | - } |
|
1336 | - // BUT WAIT !!! This class may be an alias for something else (or getting replaced at runtime) |
|
1337 | - $param_class = $this->class_cache->isAlias($param_class, $class_name) |
|
1338 | - ? $this->class_cache->getFqnForAlias($param_class, $class_name) |
|
1339 | - : $param_class; |
|
1340 | - if (// param is not even a class |
|
1341 | - $param_class === null |
|
1342 | - // and something already exists in the incoming arguments for this param |
|
1343 | - && array_key_exists($index, $argument_keys) |
|
1344 | - && array_key_exists($argument_keys[ $index ], $arguments) |
|
1345 | - ) { |
|
1346 | - // so let's skip this argument and move on to the next |
|
1347 | - continue; |
|
1348 | - } |
|
1349 | - if (// parameter is type hinted as a class, exists as an incoming argument, AND it's the correct class |
|
1350 | - $param_class !== null |
|
1351 | - && isset($argument_keys[ $index ], $arguments[ $argument_keys[ $index ] ]) |
|
1352 | - && $arguments[ $argument_keys[ $index ] ] instanceof $param_class |
|
1353 | - ) { |
|
1354 | - // skip this argument and move on to the next |
|
1355 | - continue; |
|
1356 | - } |
|
1357 | - if (// parameter is type hinted as a class, and should be injected |
|
1358 | - $param_class !== null |
|
1359 | - && $this->_dependency_map->has_dependency_for_class($class_name, $param_class) |
|
1360 | - ) { |
|
1361 | - $arguments = $this->_resolve_dependency( |
|
1362 | - $class_name, |
|
1363 | - $param_class, |
|
1364 | - $arguments, |
|
1365 | - $index |
|
1366 | - ); |
|
1367 | - } |
|
1368 | - if (empty($arguments[ $index ])) { |
|
1369 | - $arguments[ $index ] = $this->mirror->getParameterDefaultValue( |
|
1370 | - $param, |
|
1371 | - $class_name, |
|
1372 | - $index |
|
1373 | - ); |
|
1374 | - } |
|
1375 | - } |
|
1376 | - return $arguments; |
|
1377 | - } |
|
1378 | - |
|
1379 | - |
|
1380 | - /** |
|
1381 | - * @param string $class_name |
|
1382 | - * @param string $param_class |
|
1383 | - * @param array $arguments |
|
1384 | - * @param mixed $index |
|
1385 | - * @return array |
|
1386 | - * @throws InvalidArgumentException |
|
1387 | - * @throws InvalidInterfaceException |
|
1388 | - * @throws InvalidDataTypeException |
|
1389 | - */ |
|
1390 | - protected function _resolve_dependency($class_name, $param_class, $arguments, $index) |
|
1391 | - { |
|
1392 | - $dependency = null; |
|
1393 | - // should dependency be loaded from cache ? |
|
1394 | - $cache_on = $this->_dependency_map->loading_strategy_for_class_dependency( |
|
1395 | - $class_name, |
|
1396 | - $param_class |
|
1397 | - ); |
|
1398 | - $cache_on = $cache_on !== EE_Dependency_Map::load_new_object; |
|
1399 | - // we might have a dependency... |
|
1400 | - // let's MAYBE try and find it in our cache if that's what's been requested |
|
1401 | - $cached_class = $cache_on |
|
1402 | - ? $this->_get_cached_class($param_class) |
|
1403 | - : null; |
|
1404 | - // and grab it if it exists |
|
1405 | - if ($cached_class instanceof $param_class) { |
|
1406 | - $dependency = $cached_class; |
|
1407 | - } elseif ($param_class !== $class_name) { |
|
1408 | - // obtain the loader method from the dependency map |
|
1409 | - $loader = $this->_dependency_map->class_loader($param_class); |
|
1410 | - // is loader a custom closure ? |
|
1411 | - if ($loader instanceof Closure) { |
|
1412 | - $dependency = $loader($arguments); |
|
1413 | - } else { |
|
1414 | - // set the cache on property for the recursive loading call |
|
1415 | - $this->_cache_on = $cache_on; |
|
1416 | - // if not, then let's try and load it via the registry |
|
1417 | - if ($loader && method_exists($this, $loader)) { |
|
1418 | - $dependency = $this->{$loader}($param_class); |
|
1419 | - } else { |
|
1420 | - $dependency = LoaderFactory::getLoader()->load( |
|
1421 | - $param_class, |
|
1422 | - array(), |
|
1423 | - $cache_on |
|
1424 | - ); |
|
1425 | - } |
|
1426 | - } |
|
1427 | - } |
|
1428 | - // did we successfully find the correct dependency ? |
|
1429 | - if ($dependency instanceof $param_class) { |
|
1430 | - // then let's inject it into the incoming array of arguments at the correct location |
|
1431 | - $arguments[ $index ] = $dependency; |
|
1432 | - } |
|
1433 | - return $arguments; |
|
1434 | - } |
|
1435 | - |
|
1436 | - |
|
1437 | - /** |
|
1438 | - * call any loader that's been registered in the EE_Dependency_Map::$_class_loaders array |
|
1439 | - * |
|
1440 | - * @param string $classname PLEASE NOTE: the class name needs to match what's registered |
|
1441 | - * in the EE_Dependency_Map::$_class_loaders array, |
|
1442 | - * including the class prefix, ie: "EE_", "EEM_", "EEH_", etc |
|
1443 | - * @param array $arguments |
|
1444 | - * @return object |
|
1445 | - */ |
|
1446 | - public static function factory($classname, $arguments = array()) |
|
1447 | - { |
|
1448 | - $loader = self::instance()->_dependency_map->class_loader($classname); |
|
1449 | - if ($loader instanceof Closure) { |
|
1450 | - return $loader($arguments); |
|
1451 | - } |
|
1452 | - if (method_exists(self::instance(), $loader)) { |
|
1453 | - return self::instance()->{$loader}($classname, $arguments); |
|
1454 | - } |
|
1455 | - return null; |
|
1456 | - } |
|
1457 | - |
|
1458 | - |
|
1459 | - /** |
|
1460 | - * Gets the addon by its class name |
|
1461 | - * |
|
1462 | - * @param string $class_name |
|
1463 | - * @return EE_Addon |
|
1464 | - */ |
|
1465 | - public function getAddon($class_name) |
|
1466 | - { |
|
1467 | - $class_name = str_replace('\\', '_', $class_name); |
|
1468 | - if (isset($this->addons->{$class_name})) { |
|
1469 | - return $this->addons->{$class_name}; |
|
1470 | - } else { |
|
1471 | - return null; |
|
1472 | - } |
|
1473 | - } |
|
1474 | - |
|
1475 | - |
|
1476 | - /** |
|
1477 | - * removes the addon from the internal cache |
|
1478 | - * |
|
1479 | - * @param string $class_name |
|
1480 | - * @return void |
|
1481 | - */ |
|
1482 | - public function removeAddon($class_name) |
|
1483 | - { |
|
1484 | - $class_name = str_replace('\\', '_', $class_name); |
|
1485 | - unset($this->addons->{$class_name}); |
|
1486 | - } |
|
1487 | - |
|
1488 | - |
|
1489 | - /** |
|
1490 | - * Gets the addon by its name/slug (not classname. For that, just |
|
1491 | - * use the get_addon() method above |
|
1492 | - * |
|
1493 | - * @param string $name |
|
1494 | - * @return EE_Addon |
|
1495 | - */ |
|
1496 | - public function get_addon_by_name($name) |
|
1497 | - { |
|
1498 | - foreach ($this->addons as $addon) { |
|
1499 | - if ($addon->name() === $name) { |
|
1500 | - return $addon; |
|
1501 | - } |
|
1502 | - } |
|
1503 | - return null; |
|
1504 | - } |
|
1505 | - |
|
1506 | - |
|
1507 | - /** |
|
1508 | - * Gets an array of all the registered addons, where the keys are their names. |
|
1509 | - * (ie, what each returns for their name() function) |
|
1510 | - * They're already available on EE_Registry::instance()->addons as properties, |
|
1511 | - * where each property's name is the addon's classname, |
|
1512 | - * So if you just want to get the addon by classname, |
|
1513 | - * OR use the get_addon() method above. |
|
1514 | - * PLEASE NOTE: |
|
1515 | - * addons with Fully Qualified Class Names |
|
1516 | - * have had the namespace separators converted to underscores, |
|
1517 | - * so a classname like Fully\Qualified\ClassName |
|
1518 | - * would have been converted to Fully_Qualified_ClassName |
|
1519 | - * |
|
1520 | - * @return EE_Addon[] where the KEYS are the addon's name() |
|
1521 | - */ |
|
1522 | - public function get_addons_by_name() |
|
1523 | - { |
|
1524 | - $addons = array(); |
|
1525 | - foreach ($this->addons as $addon) { |
|
1526 | - $addons[ $addon->name() ] = $addon; |
|
1527 | - } |
|
1528 | - return $addons; |
|
1529 | - } |
|
1530 | - |
|
1531 | - |
|
1532 | - /** |
|
1533 | - * Resets the specified model's instance AND makes sure EE_Registry doesn't keep |
|
1534 | - * a stale copy of it around |
|
1535 | - * |
|
1536 | - * @param string $model_name |
|
1537 | - * @return \EEM_Base |
|
1538 | - * @throws \EE_Error |
|
1539 | - */ |
|
1540 | - public function reset_model($model_name) |
|
1541 | - { |
|
1542 | - $model_class_name = strpos($model_name, 'EEM_') !== 0 |
|
1543 | - ? "EEM_{$model_name}" |
|
1544 | - : $model_name; |
|
1545 | - if (! isset($this->LIB->{$model_class_name}) || ! $this->LIB->{$model_class_name} instanceof EEM_Base) { |
|
1546 | - return null; |
|
1547 | - } |
|
1548 | - // get that model reset it and make sure we nuke the old reference to it |
|
1549 | - if ($this->LIB->{$model_class_name} instanceof $model_class_name |
|
1550 | - && is_callable( |
|
1551 | - array($model_class_name, 'reset') |
|
1552 | - )) { |
|
1553 | - $this->LIB->{$model_class_name} = $this->LIB->{$model_class_name}->reset(); |
|
1554 | - } else { |
|
1555 | - throw new EE_Error( |
|
1556 | - sprintf( |
|
1557 | - esc_html__('Model %s does not have a method "reset"', 'event_espresso'), |
|
1558 | - $model_name |
|
1559 | - ) |
|
1560 | - ); |
|
1561 | - } |
|
1562 | - return $this->LIB->{$model_class_name}; |
|
1563 | - } |
|
1564 | - |
|
1565 | - |
|
1566 | - /** |
|
1567 | - * Resets the registry. |
|
1568 | - * The criteria for what gets reset is based on what can be shared between sites on the same request when |
|
1569 | - * switch_to_blog is used in a multisite install. Here is a list of things that are NOT reset. |
|
1570 | - * - $_dependency_map |
|
1571 | - * - $_class_abbreviations |
|
1572 | - * - $NET_CFG (EE_Network_Config): The config is shared network wide so no need to reset. |
|
1573 | - * - $REQ: Still on the same request so no need to change. |
|
1574 | - * - $CAP: There is no site specific state in the EE_Capability class. |
|
1575 | - * - $SSN: Although ideally, the session should not be shared between site switches, we can't reset it because only |
|
1576 | - * one Session can be active in a single request. Resetting could resolve in "headers already sent" errors. |
|
1577 | - * - $addons: In multisite, the state of the addons is something controlled via hooks etc in a normal request. So |
|
1578 | - * for now, we won't reset the addons because it could break calls to an add-ons class/methods in the |
|
1579 | - * switch or on the restore. |
|
1580 | - * - $modules |
|
1581 | - * - $shortcodes |
|
1582 | - * - $widgets |
|
1583 | - * |
|
1584 | - * @param boolean $hard [deprecated] |
|
1585 | - * @param boolean $reinstantiate whether to create new instances of EE_Registry's singletons too, |
|
1586 | - * or just reset without re-instantiating (handy to set to FALSE if you're not |
|
1587 | - * sure if you CAN currently reinstantiate the singletons at the moment) |
|
1588 | - * @param bool $reset_models Defaults to true. When false, then the models are not reset. This is so |
|
1589 | - * client |
|
1590 | - * code instead can just change the model context to a different blog id if |
|
1591 | - * necessary |
|
1592 | - * @return EE_Registry |
|
1593 | - * @throws InvalidInterfaceException |
|
1594 | - * @throws InvalidDataTypeException |
|
1595 | - * @throws EE_Error |
|
1596 | - * @throws ReflectionException |
|
1597 | - * @throws InvalidArgumentException |
|
1598 | - */ |
|
1599 | - public static function reset($hard = false, $reinstantiate = true, $reset_models = true) |
|
1600 | - { |
|
1601 | - $instance = self::instance(); |
|
1602 | - $instance->_cache_on = true; |
|
1603 | - // reset some "special" classes |
|
1604 | - EEH_Activation::reset(); |
|
1605 | - $hard = apply_filters('FHEE__EE_Registry__reset__hard', $hard); |
|
1606 | - $instance->CFG = EE_Config::reset($hard, $reinstantiate); |
|
1607 | - $instance->CART = null; |
|
1608 | - $instance->MRM = null; |
|
1609 | - $instance->AssetsRegistry = LoaderFactory::getLoader()->getShared( |
|
1610 | - 'EventEspresso\core\services\assets\Registry' |
|
1611 | - ); |
|
1612 | - // messages reset |
|
1613 | - EED_Messages::reset(); |
|
1614 | - // handle of objects cached on LIB |
|
1615 | - foreach (array('LIB', 'modules') as $cache) { |
|
1616 | - foreach ($instance->{$cache} as $class_name => $class) { |
|
1617 | - if (self::_reset_and_unset_object($class, $reset_models)) { |
|
1618 | - unset($instance->{$cache}->{$class_name}); |
|
1619 | - } |
|
1620 | - } |
|
1621 | - } |
|
1622 | - return $instance; |
|
1623 | - } |
|
1624 | - |
|
1625 | - |
|
1626 | - /** |
|
1627 | - * if passed object implements ResettableInterface, then call it's reset() method |
|
1628 | - * if passed object implements InterminableInterface, then return false, |
|
1629 | - * to indicate that it should NOT be cleared from the Registry cache |
|
1630 | - * |
|
1631 | - * @param $object |
|
1632 | - * @param bool $reset_models |
|
1633 | - * @return bool returns true if cached object should be unset |
|
1634 | - */ |
|
1635 | - private static function _reset_and_unset_object($object, $reset_models) |
|
1636 | - { |
|
1637 | - if (! is_object($object)) { |
|
1638 | - // don't unset anything that's not an object |
|
1639 | - return false; |
|
1640 | - } |
|
1641 | - if ($object instanceof EED_Module) { |
|
1642 | - $object::reset(); |
|
1643 | - // don't unset modules |
|
1644 | - return false; |
|
1645 | - } |
|
1646 | - if ($object instanceof ResettableInterface) { |
|
1647 | - if ($object instanceof EEM_Base) { |
|
1648 | - if ($reset_models) { |
|
1649 | - $object->reset(); |
|
1650 | - return true; |
|
1651 | - } |
|
1652 | - return false; |
|
1653 | - } |
|
1654 | - $object->reset(); |
|
1655 | - return true; |
|
1656 | - } |
|
1657 | - if (! $object instanceof InterminableInterface) { |
|
1658 | - return true; |
|
1659 | - } |
|
1660 | - return false; |
|
1661 | - } |
|
1662 | - |
|
1663 | - |
|
1664 | - /** |
|
1665 | - * Gets all the custom post type models defined |
|
1666 | - * |
|
1667 | - * @return array keys are model "short names" (Eg "Event") and keys are classnames (eg "EEM_Event") |
|
1668 | - */ |
|
1669 | - public function cpt_models() |
|
1670 | - { |
|
1671 | - $cpt_models = array(); |
|
1672 | - foreach ($this->non_abstract_db_models as $short_name => $classname) { |
|
1673 | - if (is_subclass_of($classname, 'EEM_CPT_Base')) { |
|
1674 | - $cpt_models[ $short_name ] = $classname; |
|
1675 | - } |
|
1676 | - } |
|
1677 | - return $cpt_models; |
|
1678 | - } |
|
1679 | - |
|
1680 | - |
|
1681 | - /** |
|
1682 | - * @return \EE_Config |
|
1683 | - */ |
|
1684 | - public static function CFG() |
|
1685 | - { |
|
1686 | - return self::instance()->CFG; |
|
1687 | - } |
|
1688 | - |
|
1689 | - |
|
1690 | - /** |
|
1691 | - * @deprecated 4.9.62.p |
|
1692 | - * @param string $class_name |
|
1693 | - * @return ReflectionClass |
|
1694 | - * @throws ReflectionException |
|
1695 | - * @throws InvalidDataTypeException |
|
1696 | - */ |
|
1697 | - public function get_ReflectionClass($class_name) |
|
1698 | - { |
|
1699 | - return $this->mirror->getReflectionClass($class_name); |
|
1700 | - } |
|
26 | + /** |
|
27 | + * @var EE_Registry $_instance |
|
28 | + */ |
|
29 | + private static $_instance; |
|
30 | + |
|
31 | + /** |
|
32 | + * @var EE_Dependency_Map $_dependency_map |
|
33 | + */ |
|
34 | + protected $_dependency_map; |
|
35 | + |
|
36 | + /** |
|
37 | + * @var Mirror |
|
38 | + */ |
|
39 | + private $mirror; |
|
40 | + |
|
41 | + /** |
|
42 | + * @var ClassInterfaceCache $class_cache |
|
43 | + */ |
|
44 | + private $class_cache; |
|
45 | + |
|
46 | + /** |
|
47 | + * @var array $_class_abbreviations |
|
48 | + */ |
|
49 | + protected $_class_abbreviations = array(); |
|
50 | + |
|
51 | + /** |
|
52 | + * @var CommandBusInterface $BUS |
|
53 | + */ |
|
54 | + public $BUS; |
|
55 | + |
|
56 | + /** |
|
57 | + * @var EE_Cart $CART |
|
58 | + */ |
|
59 | + public $CART; |
|
60 | + |
|
61 | + /** |
|
62 | + * @var EE_Config $CFG |
|
63 | + */ |
|
64 | + public $CFG; |
|
65 | + |
|
66 | + /** |
|
67 | + * @var EE_Network_Config $NET_CFG |
|
68 | + */ |
|
69 | + public $NET_CFG; |
|
70 | + |
|
71 | + /** |
|
72 | + * StdClass object for storing library classes in |
|
73 | + * |
|
74 | + * @var RegistryContainer $LIB |
|
75 | + */ |
|
76 | + public $LIB; |
|
77 | + |
|
78 | + /** |
|
79 | + * @var EE_Request_Handler $REQ |
|
80 | + */ |
|
81 | + public $REQ; |
|
82 | + |
|
83 | + /** |
|
84 | + * @var EE_Session $SSN |
|
85 | + */ |
|
86 | + public $SSN; |
|
87 | + |
|
88 | + /** |
|
89 | + * @since 4.5.0 |
|
90 | + * @var EE_Capabilities $CAP |
|
91 | + */ |
|
92 | + public $CAP; |
|
93 | + |
|
94 | + /** |
|
95 | + * @since 4.9.0 |
|
96 | + * @var EE_Message_Resource_Manager $MRM |
|
97 | + */ |
|
98 | + public $MRM; |
|
99 | + |
|
100 | + /** |
|
101 | + * @var Registry $AssetsRegistry |
|
102 | + */ |
|
103 | + public $AssetsRegistry; |
|
104 | + |
|
105 | + /** |
|
106 | + * StdClass object for holding addons which have registered themselves to work with EE core |
|
107 | + * |
|
108 | + * @var EE_Addon[] $addons |
|
109 | + */ |
|
110 | + public $addons; |
|
111 | + |
|
112 | + /** |
|
113 | + * keys are 'short names' (eg Event), values are class names (eg 'EEM_Event') |
|
114 | + * |
|
115 | + * @var EEM_Base[] $models |
|
116 | + */ |
|
117 | + public $models = array(); |
|
118 | + |
|
119 | + /** |
|
120 | + * @var EED_Module[] $modules |
|
121 | + */ |
|
122 | + public $modules; |
|
123 | + |
|
124 | + /** |
|
125 | + * @var EES_Shortcode[] $shortcodes |
|
126 | + */ |
|
127 | + public $shortcodes; |
|
128 | + |
|
129 | + /** |
|
130 | + * @var WP_Widget[] $widgets |
|
131 | + */ |
|
132 | + public $widgets; |
|
133 | + |
|
134 | + /** |
|
135 | + * this is an array of all implemented model names (i.e. not the parent abstract models, or models |
|
136 | + * which don't actually fetch items from the DB in the normal way (ie, are not children of EEM_Base)). |
|
137 | + * Keys are model "short names" (eg "Event") as used in model relations, and values are |
|
138 | + * classnames (eg "EEM_Event") |
|
139 | + * |
|
140 | + * @var array $non_abstract_db_models |
|
141 | + */ |
|
142 | + public $non_abstract_db_models = array(); |
|
143 | + |
|
144 | + /** |
|
145 | + * internationalization for JS strings |
|
146 | + * usage: EE_Registry::i18n_js_strings['string_key'] = esc_html__( 'string to translate.', 'event_espresso' ); |
|
147 | + * in js file: var translatedString = eei18n.string_key; |
|
148 | + * |
|
149 | + * @var array $i18n_js_strings |
|
150 | + */ |
|
151 | + public static $i18n_js_strings = array(); |
|
152 | + |
|
153 | + /** |
|
154 | + * $main_file - path to espresso.php |
|
155 | + * |
|
156 | + * @var array $main_file |
|
157 | + */ |
|
158 | + public $main_file; |
|
159 | + |
|
160 | + /** |
|
161 | + * array of ReflectionClass objects where the key is the class name |
|
162 | + * |
|
163 | + * @deprecated 4.9.62.p |
|
164 | + * @var ReflectionClass[] $_reflectors |
|
165 | + */ |
|
166 | + public $_reflectors; |
|
167 | + |
|
168 | + /** |
|
169 | + * boolean flag to indicate whether or not to load/save dependencies from/to the cache |
|
170 | + * |
|
171 | + * @var boolean $_cache_on |
|
172 | + */ |
|
173 | + protected $_cache_on = true; |
|
174 | + |
|
175 | + /** |
|
176 | + * @var ObjectIdentifier |
|
177 | + */ |
|
178 | + private $object_identifier; |
|
179 | + |
|
180 | + |
|
181 | + /** |
|
182 | + * @singleton method used to instantiate class object |
|
183 | + * @param EE_Dependency_Map|null $dependency_map |
|
184 | + * @param Mirror|null $mirror |
|
185 | + * @param ClassInterfaceCache|null $class_cache |
|
186 | + * @param ObjectIdentifier|null $object_identifier |
|
187 | + * @return EE_Registry instance |
|
188 | + */ |
|
189 | + public static function instance( |
|
190 | + EE_Dependency_Map $dependency_map = null, |
|
191 | + Mirror $mirror = null, |
|
192 | + ClassInterfaceCache $class_cache = null, |
|
193 | + ObjectIdentifier $object_identifier = null |
|
194 | + ) { |
|
195 | + // check if class object is instantiated |
|
196 | + if (! self::$_instance instanceof EE_Registry |
|
197 | + && $dependency_map instanceof EE_Dependency_Map |
|
198 | + && $mirror instanceof Mirror |
|
199 | + && $class_cache instanceof ClassInterfaceCache |
|
200 | + && $object_identifier instanceof ObjectIdentifier |
|
201 | + ) { |
|
202 | + self::$_instance = new self( |
|
203 | + $dependency_map, |
|
204 | + $mirror, |
|
205 | + $class_cache, |
|
206 | + $object_identifier |
|
207 | + ); |
|
208 | + } |
|
209 | + return self::$_instance; |
|
210 | + } |
|
211 | + |
|
212 | + |
|
213 | + /** |
|
214 | + * protected constructor to prevent direct creation |
|
215 | + * |
|
216 | + * @Constructor |
|
217 | + * @param EE_Dependency_Map $dependency_map |
|
218 | + * @param Mirror $mirror |
|
219 | + * @param ClassInterfaceCache $class_cache |
|
220 | + * @param ObjectIdentifier $object_identifier |
|
221 | + */ |
|
222 | + protected function __construct( |
|
223 | + EE_Dependency_Map $dependency_map, |
|
224 | + Mirror $mirror, |
|
225 | + ClassInterfaceCache $class_cache, |
|
226 | + ObjectIdentifier $object_identifier |
|
227 | + ) { |
|
228 | + $this->_dependency_map = $dependency_map; |
|
229 | + $this->mirror = $mirror; |
|
230 | + $this->class_cache = $class_cache; |
|
231 | + $this->object_identifier = $object_identifier; |
|
232 | + // $registry_container = new RegistryContainer(); |
|
233 | + $this->LIB = new RegistryContainer(); |
|
234 | + $this->addons = new RegistryContainer(); |
|
235 | + $this->modules = new RegistryContainer(); |
|
236 | + $this->shortcodes = new RegistryContainer(); |
|
237 | + $this->widgets = new RegistryContainer(); |
|
238 | + add_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading', array($this, 'initialize')); |
|
239 | + } |
|
240 | + |
|
241 | + |
|
242 | + /** |
|
243 | + * initialize |
|
244 | + * |
|
245 | + * @throws OutOfBoundsException |
|
246 | + * @throws InvalidArgumentException |
|
247 | + * @throws InvalidInterfaceException |
|
248 | + * @throws InvalidDataTypeException |
|
249 | + * @throws EE_Error |
|
250 | + * @throws ReflectionException |
|
251 | + */ |
|
252 | + public function initialize() |
|
253 | + { |
|
254 | + $this->_class_abbreviations = apply_filters( |
|
255 | + 'FHEE__EE_Registry____construct___class_abbreviations', |
|
256 | + array( |
|
257 | + 'EE_Config' => 'CFG', |
|
258 | + 'EE_Session' => 'SSN', |
|
259 | + 'EE_Capabilities' => 'CAP', |
|
260 | + 'EE_Cart' => 'CART', |
|
261 | + 'EE_Network_Config' => 'NET_CFG', |
|
262 | + 'EE_Request_Handler' => 'REQ', |
|
263 | + 'EE_Message_Resource_Manager' => 'MRM', |
|
264 | + 'EventEspresso\core\services\commands\CommandBus' => 'BUS', |
|
265 | + 'EventEspresso\core\services\assets\Registry' => 'AssetsRegistry', |
|
266 | + ) |
|
267 | + ); |
|
268 | + $this->load_core('Base', array(), true); |
|
269 | + // add our request and response objects to the cache |
|
270 | + $request_loader = $this->_dependency_map->class_loader( |
|
271 | + 'EventEspresso\core\services\request\Request' |
|
272 | + ); |
|
273 | + $this->_set_cached_class( |
|
274 | + $request_loader(), |
|
275 | + 'EventEspresso\core\services\request\Request' |
|
276 | + ); |
|
277 | + $response_loader = $this->_dependency_map->class_loader( |
|
278 | + 'EventEspresso\core\services\request\Response' |
|
279 | + ); |
|
280 | + $this->_set_cached_class( |
|
281 | + $response_loader(), |
|
282 | + 'EventEspresso\core\services\request\Response' |
|
283 | + ); |
|
284 | + add_action('AHEE__EE_System__set_hooks_for_core', array($this, 'init')); |
|
285 | + } |
|
286 | + |
|
287 | + |
|
288 | + /** |
|
289 | + * @return void |
|
290 | + */ |
|
291 | + public function init() |
|
292 | + { |
|
293 | + // Get current page protocol |
|
294 | + $protocol = isset($_SERVER['HTTPS']) ? 'https://' : 'http://'; |
|
295 | + // Output admin-ajax.php URL with same protocol as current page |
|
296 | + self::$i18n_js_strings['ajax_url'] = admin_url('admin-ajax.php', $protocol); |
|
297 | + self::$i18n_js_strings['wp_debug'] = defined('WP_DEBUG') ? WP_DEBUG : false; |
|
298 | + } |
|
299 | + |
|
300 | + |
|
301 | + /** |
|
302 | + * localize_i18n_js_strings |
|
303 | + * |
|
304 | + * @return string |
|
305 | + */ |
|
306 | + public static function localize_i18n_js_strings() |
|
307 | + { |
|
308 | + $i18n_js_strings = (array) self::$i18n_js_strings; |
|
309 | + foreach ($i18n_js_strings as $key => $value) { |
|
310 | + if (is_scalar($value)) { |
|
311 | + $i18n_js_strings[ $key ] = html_entity_decode((string) $value, ENT_QUOTES, 'UTF-8'); |
|
312 | + } |
|
313 | + } |
|
314 | + return '/* <![CDATA[ */ var eei18n = ' . wp_json_encode($i18n_js_strings) . '; /* ]]> */'; |
|
315 | + } |
|
316 | + |
|
317 | + |
|
318 | + /** |
|
319 | + * @param mixed string | EED_Module $module |
|
320 | + * @throws OutOfBoundsException |
|
321 | + * @throws InvalidArgumentException |
|
322 | + * @throws InvalidInterfaceException |
|
323 | + * @throws InvalidDataTypeException |
|
324 | + * @throws EE_Error |
|
325 | + * @throws ReflectionException |
|
326 | + */ |
|
327 | + public function add_module($module) |
|
328 | + { |
|
329 | + if ($module instanceof EED_Module) { |
|
330 | + $module_class = get_class($module); |
|
331 | + $this->modules->{$module_class} = $module; |
|
332 | + } else { |
|
333 | + if (! class_exists('EE_Module_Request_Router', false)) { |
|
334 | + $this->load_core('Module_Request_Router'); |
|
335 | + } |
|
336 | + EE_Module_Request_Router::module_factory($module); |
|
337 | + } |
|
338 | + } |
|
339 | + |
|
340 | + |
|
341 | + /** |
|
342 | + * @param string $module_name |
|
343 | + * @return mixed EED_Module | NULL |
|
344 | + */ |
|
345 | + public function get_module($module_name = '') |
|
346 | + { |
|
347 | + return isset($this->modules->{$module_name}) |
|
348 | + ? $this->modules->{$module_name} |
|
349 | + : null; |
|
350 | + } |
|
351 | + |
|
352 | + |
|
353 | + /** |
|
354 | + * loads core classes - must be singletons |
|
355 | + * |
|
356 | + * @param string $class_name - simple class name ie: session |
|
357 | + * @param mixed $arguments |
|
358 | + * @param bool $load_only |
|
359 | + * @return mixed |
|
360 | + * @throws InvalidInterfaceException |
|
361 | + * @throws InvalidDataTypeException |
|
362 | + * @throws EE_Error |
|
363 | + * @throws ReflectionException |
|
364 | + * @throws InvalidArgumentException |
|
365 | + */ |
|
366 | + public function load_core($class_name, $arguments = array(), $load_only = false) |
|
367 | + { |
|
368 | + $core_paths = apply_filters( |
|
369 | + 'FHEE__EE_Registry__load_core__core_paths', |
|
370 | + array( |
|
371 | + EE_CORE, |
|
372 | + EE_ADMIN, |
|
373 | + EE_CPTS, |
|
374 | + EE_CORE . 'data_migration_scripts/', |
|
375 | + EE_CORE . 'capabilities/', |
|
376 | + EE_CORE . 'request_stack/', |
|
377 | + EE_CORE . 'middleware/', |
|
378 | + ) |
|
379 | + ); |
|
380 | + // retrieve instantiated class |
|
381 | + return $this->_load( |
|
382 | + $core_paths, |
|
383 | + 'EE_', |
|
384 | + $class_name, |
|
385 | + 'core', |
|
386 | + $arguments, |
|
387 | + false, |
|
388 | + true, |
|
389 | + $load_only |
|
390 | + ); |
|
391 | + } |
|
392 | + |
|
393 | + |
|
394 | + /** |
|
395 | + * loads service classes |
|
396 | + * |
|
397 | + * @param string $class_name - simple class name ie: session |
|
398 | + * @param mixed $arguments |
|
399 | + * @param bool $load_only |
|
400 | + * @return mixed |
|
401 | + * @throws InvalidInterfaceException |
|
402 | + * @throws InvalidDataTypeException |
|
403 | + * @throws EE_Error |
|
404 | + * @throws ReflectionException |
|
405 | + * @throws InvalidArgumentException |
|
406 | + */ |
|
407 | + public function load_service($class_name, $arguments = array(), $load_only = false) |
|
408 | + { |
|
409 | + $service_paths = apply_filters( |
|
410 | + 'FHEE__EE_Registry__load_service__service_paths', |
|
411 | + array( |
|
412 | + EE_CORE . 'services/', |
|
413 | + ) |
|
414 | + ); |
|
415 | + // retrieve instantiated class |
|
416 | + return $this->_load( |
|
417 | + $service_paths, |
|
418 | + 'EE_', |
|
419 | + $class_name, |
|
420 | + 'class', |
|
421 | + $arguments, |
|
422 | + false, |
|
423 | + true, |
|
424 | + $load_only |
|
425 | + ); |
|
426 | + } |
|
427 | + |
|
428 | + |
|
429 | + /** |
|
430 | + * loads data_migration_scripts |
|
431 | + * |
|
432 | + * @param string $class_name - class name for the DMS ie: EE_DMS_Core_4_2_0 |
|
433 | + * @param mixed $arguments |
|
434 | + * @return EE_Data_Migration_Script_Base|mixed |
|
435 | + * @throws InvalidInterfaceException |
|
436 | + * @throws InvalidDataTypeException |
|
437 | + * @throws EE_Error |
|
438 | + * @throws ReflectionException |
|
439 | + * @throws InvalidArgumentException |
|
440 | + */ |
|
441 | + public function load_dms($class_name, $arguments = array()) |
|
442 | + { |
|
443 | + // retrieve instantiated class |
|
444 | + return $this->_load( |
|
445 | + EE_Data_Migration_Manager::instance()->get_data_migration_script_folders(), |
|
446 | + 'EE_DMS_', |
|
447 | + $class_name, |
|
448 | + 'dms', |
|
449 | + $arguments, |
|
450 | + false, |
|
451 | + false |
|
452 | + ); |
|
453 | + } |
|
454 | + |
|
455 | + |
|
456 | + /** |
|
457 | + * loads object creating classes - must be singletons |
|
458 | + * |
|
459 | + * @param string $class_name - simple class name ie: attendee |
|
460 | + * @param mixed $arguments - an array of arguments to pass to the class |
|
461 | + * @param bool $from_db - some classes are instantiated from the db and thus call a different method to |
|
462 | + * instantiate |
|
463 | + * @param bool $cache if you don't want the class to be stored in the internal cache (non-persistent) then |
|
464 | + * set this to FALSE (ie. when instantiating model objects from client in a loop) |
|
465 | + * @param bool $load_only whether or not to just load the file and NOT instantiate, or load AND instantiate |
|
466 | + * (default) |
|
467 | + * @return EE_Base_Class | bool |
|
468 | + * @throws InvalidInterfaceException |
|
469 | + * @throws InvalidDataTypeException |
|
470 | + * @throws EE_Error |
|
471 | + * @throws ReflectionException |
|
472 | + * @throws InvalidArgumentException |
|
473 | + */ |
|
474 | + public function load_class($class_name, $arguments = array(), $from_db = false, $cache = true, $load_only = false) |
|
475 | + { |
|
476 | + $paths = apply_filters( |
|
477 | + 'FHEE__EE_Registry__load_class__paths', |
|
478 | + array( |
|
479 | + EE_CORE, |
|
480 | + EE_CLASSES, |
|
481 | + EE_BUSINESS, |
|
482 | + ) |
|
483 | + ); |
|
484 | + // retrieve instantiated class |
|
485 | + return $this->_load( |
|
486 | + $paths, |
|
487 | + 'EE_', |
|
488 | + $class_name, |
|
489 | + 'class', |
|
490 | + $arguments, |
|
491 | + $from_db, |
|
492 | + $cache, |
|
493 | + $load_only |
|
494 | + ); |
|
495 | + } |
|
496 | + |
|
497 | + |
|
498 | + /** |
|
499 | + * loads helper classes - must be singletons |
|
500 | + * |
|
501 | + * @param string $class_name - simple class name ie: price |
|
502 | + * @param mixed $arguments |
|
503 | + * @param bool $load_only |
|
504 | + * @return EEH_Base | bool |
|
505 | + * @throws InvalidInterfaceException |
|
506 | + * @throws InvalidDataTypeException |
|
507 | + * @throws EE_Error |
|
508 | + * @throws ReflectionException |
|
509 | + * @throws InvalidArgumentException |
|
510 | + */ |
|
511 | + public function load_helper($class_name, $arguments = array(), $load_only = true) |
|
512 | + { |
|
513 | + // todo: add doing_it_wrong() in a few versions after all addons have had calls to this method removed |
|
514 | + $helper_paths = apply_filters('FHEE__EE_Registry__load_helper__helper_paths', array(EE_HELPERS)); |
|
515 | + // retrieve instantiated class |
|
516 | + return $this->_load( |
|
517 | + $helper_paths, |
|
518 | + 'EEH_', |
|
519 | + $class_name, |
|
520 | + 'helper', |
|
521 | + $arguments, |
|
522 | + false, |
|
523 | + true, |
|
524 | + $load_only |
|
525 | + ); |
|
526 | + } |
|
527 | + |
|
528 | + |
|
529 | + /** |
|
530 | + * loads core classes - must be singletons |
|
531 | + * |
|
532 | + * @param string $class_name - simple class name ie: session |
|
533 | + * @param mixed $arguments |
|
534 | + * @param bool $load_only |
|
535 | + * @param bool $cache whether to cache the object or not. |
|
536 | + * @return mixed |
|
537 | + * @throws InvalidInterfaceException |
|
538 | + * @throws InvalidDataTypeException |
|
539 | + * @throws EE_Error |
|
540 | + * @throws ReflectionException |
|
541 | + * @throws InvalidArgumentException |
|
542 | + */ |
|
543 | + public function load_lib($class_name, $arguments = array(), $load_only = false, $cache = true) |
|
544 | + { |
|
545 | + $paths = array( |
|
546 | + EE_LIBRARIES, |
|
547 | + EE_LIBRARIES . 'messages/', |
|
548 | + EE_LIBRARIES . 'shortcodes/', |
|
549 | + EE_LIBRARIES . 'qtips/', |
|
550 | + EE_LIBRARIES . 'payment_methods/', |
|
551 | + ); |
|
552 | + // retrieve instantiated class |
|
553 | + return $this->_load( |
|
554 | + $paths, |
|
555 | + 'EE_', |
|
556 | + $class_name, |
|
557 | + 'lib', |
|
558 | + $arguments, |
|
559 | + false, |
|
560 | + $cache, |
|
561 | + $load_only |
|
562 | + ); |
|
563 | + } |
|
564 | + |
|
565 | + |
|
566 | + /** |
|
567 | + * loads model classes - must be singletons |
|
568 | + * |
|
569 | + * @param string $class_name - simple class name ie: price |
|
570 | + * @param mixed $arguments |
|
571 | + * @param bool $load_only |
|
572 | + * @return EEM_Base | bool |
|
573 | + * @throws InvalidInterfaceException |
|
574 | + * @throws InvalidDataTypeException |
|
575 | + * @throws EE_Error |
|
576 | + * @throws ReflectionException |
|
577 | + * @throws InvalidArgumentException |
|
578 | + */ |
|
579 | + public function load_model($class_name, $arguments = array(), $load_only = false) |
|
580 | + { |
|
581 | + $paths = apply_filters( |
|
582 | + 'FHEE__EE_Registry__load_model__paths', |
|
583 | + array( |
|
584 | + EE_MODELS, |
|
585 | + EE_CORE, |
|
586 | + ) |
|
587 | + ); |
|
588 | + // retrieve instantiated class |
|
589 | + return $this->_load( |
|
590 | + $paths, |
|
591 | + 'EEM_', |
|
592 | + $class_name, |
|
593 | + 'model', |
|
594 | + $arguments, |
|
595 | + false, |
|
596 | + true, |
|
597 | + $load_only |
|
598 | + ); |
|
599 | + } |
|
600 | + |
|
601 | + |
|
602 | + /** |
|
603 | + * loads model classes - must be singletons |
|
604 | + * |
|
605 | + * @param string $class_name - simple class name ie: price |
|
606 | + * @param mixed $arguments |
|
607 | + * @param bool $load_only |
|
608 | + * @return mixed | bool |
|
609 | + * @throws InvalidInterfaceException |
|
610 | + * @throws InvalidDataTypeException |
|
611 | + * @throws EE_Error |
|
612 | + * @throws ReflectionException |
|
613 | + * @throws InvalidArgumentException |
|
614 | + */ |
|
615 | + public function load_model_class($class_name, $arguments = array(), $load_only = true) |
|
616 | + { |
|
617 | + $paths = array( |
|
618 | + EE_MODELS . 'fields/', |
|
619 | + EE_MODELS . 'helpers/', |
|
620 | + EE_MODELS . 'relations/', |
|
621 | + EE_MODELS . 'strategies/', |
|
622 | + ); |
|
623 | + // retrieve instantiated class |
|
624 | + return $this->_load( |
|
625 | + $paths, |
|
626 | + 'EE_', |
|
627 | + $class_name, |
|
628 | + '', |
|
629 | + $arguments, |
|
630 | + false, |
|
631 | + true, |
|
632 | + $load_only |
|
633 | + ); |
|
634 | + } |
|
635 | + |
|
636 | + |
|
637 | + /** |
|
638 | + * Determines if $model_name is the name of an actual EE model. |
|
639 | + * |
|
640 | + * @param string $model_name like Event, Attendee, Question_Group_Question, etc. |
|
641 | + * @return boolean |
|
642 | + */ |
|
643 | + public function is_model_name($model_name) |
|
644 | + { |
|
645 | + return isset($this->models[ $model_name ]); |
|
646 | + } |
|
647 | + |
|
648 | + |
|
649 | + /** |
|
650 | + * generic class loader |
|
651 | + * |
|
652 | + * @param string $path_to_file - directory path to file location, not including filename |
|
653 | + * @param string $file_name - file name ie: my_file.php, including extension |
|
654 | + * @param string $type - file type - core? class? helper? model? |
|
655 | + * @param mixed $arguments |
|
656 | + * @param bool $load_only |
|
657 | + * @return mixed |
|
658 | + * @throws InvalidInterfaceException |
|
659 | + * @throws InvalidDataTypeException |
|
660 | + * @throws EE_Error |
|
661 | + * @throws ReflectionException |
|
662 | + * @throws InvalidArgumentException |
|
663 | + */ |
|
664 | + public function load_file($path_to_file, $file_name, $type = '', $arguments = array(), $load_only = true) |
|
665 | + { |
|
666 | + // retrieve instantiated class |
|
667 | + return $this->_load( |
|
668 | + $path_to_file, |
|
669 | + '', |
|
670 | + $file_name, |
|
671 | + $type, |
|
672 | + $arguments, |
|
673 | + false, |
|
674 | + true, |
|
675 | + $load_only |
|
676 | + ); |
|
677 | + } |
|
678 | + |
|
679 | + |
|
680 | + /** |
|
681 | + * @param string $path_to_file - directory path to file location, not including filename |
|
682 | + * @param string $class_name - full class name ie: My_Class |
|
683 | + * @param string $type - file type - core? class? helper? model? |
|
684 | + * @param mixed $arguments |
|
685 | + * @param bool $load_only |
|
686 | + * @return bool|EE_Addon|object |
|
687 | + * @throws InvalidInterfaceException |
|
688 | + * @throws InvalidDataTypeException |
|
689 | + * @throws EE_Error |
|
690 | + * @throws ReflectionException |
|
691 | + * @throws InvalidArgumentException |
|
692 | + */ |
|
693 | + public function load_addon($path_to_file, $class_name, $type = 'class', $arguments = array(), $load_only = false) |
|
694 | + { |
|
695 | + // retrieve instantiated class |
|
696 | + return $this->_load( |
|
697 | + $path_to_file, |
|
698 | + 'addon', |
|
699 | + $class_name, |
|
700 | + $type, |
|
701 | + $arguments, |
|
702 | + false, |
|
703 | + true, |
|
704 | + $load_only |
|
705 | + ); |
|
706 | + } |
|
707 | + |
|
708 | + |
|
709 | + /** |
|
710 | + * instantiates, caches, and automatically resolves dependencies |
|
711 | + * for classes that use a Fully Qualified Class Name. |
|
712 | + * if the class is not capable of being loaded using PSR-4 autoloading, |
|
713 | + * then you need to use one of the existing load_*() methods |
|
714 | + * which can resolve the classname and filepath from the passed arguments |
|
715 | + * |
|
716 | + * @param bool|string $class_name Fully Qualified Class Name |
|
717 | + * @param array $arguments an argument, or array of arguments to pass to the class upon instantiation |
|
718 | + * @param bool $cache whether to cache the instantiated object for reuse |
|
719 | + * @param bool $from_db some classes are instantiated from the db |
|
720 | + * and thus call a different method to instantiate |
|
721 | + * @param bool $load_only if true, will only load the file, but will NOT instantiate an object |
|
722 | + * @param bool|string $addon if true, will cache the object in the EE_Registry->$addons array |
|
723 | + * @return bool|null|mixed null = failure to load or instantiate class object. |
|
724 | + * object = class loaded and instantiated successfully. |
|
725 | + * bool = fail or success when $load_only is true |
|
726 | + * @throws InvalidInterfaceException |
|
727 | + * @throws InvalidDataTypeException |
|
728 | + * @throws EE_Error |
|
729 | + * @throws ReflectionException |
|
730 | + * @throws InvalidArgumentException |
|
731 | + */ |
|
732 | + public function create( |
|
733 | + $class_name = false, |
|
734 | + $arguments = array(), |
|
735 | + $cache = false, |
|
736 | + $from_db = false, |
|
737 | + $load_only = false, |
|
738 | + $addon = false |
|
739 | + ) { |
|
740 | + $class_name = ltrim($class_name, '\\'); |
|
741 | + $class_name = $this->class_cache->getFqnForAlias($class_name); |
|
742 | + $class_exists = $this->loadOrVerifyClassExists($class_name, $arguments); |
|
743 | + // if a non-FQCN was passed, then |
|
744 | + // verifyClassExists() might return an object |
|
745 | + // or it could return null if the class just could not be found anywhere |
|
746 | + if ($class_exists instanceof $class_name || $class_exists === null) { |
|
747 | + // either way, return the results |
|
748 | + return $class_exists; |
|
749 | + } |
|
750 | + $class_name = $class_exists; |
|
751 | + // if we're only loading the class and it already exists, then let's just return true immediately |
|
752 | + if ($load_only) { |
|
753 | + return true; |
|
754 | + } |
|
755 | + $addon = $addon ? 'addon' : ''; |
|
756 | + // $this->_cache_on is toggled during the recursive loading that can occur with dependency injection |
|
757 | + // $cache is controlled by individual calls to separate Registry loader methods like load_class() |
|
758 | + // $load_only is also controlled by individual calls to separate Registry loader methods like load_file() |
|
759 | + if ($this->_cache_on && $cache && ! $load_only) { |
|
760 | + // return object if it's already cached |
|
761 | + $cached_class = $this->_get_cached_class($class_name, $addon, $arguments); |
|
762 | + if ($cached_class !== null) { |
|
763 | + return $cached_class; |
|
764 | + } |
|
765 | + }// obtain the loader method from the dependency map |
|
766 | + $loader = $this->_dependency_map->class_loader($class_name);// instantiate the requested object |
|
767 | + if ($loader instanceof Closure) { |
|
768 | + $class_obj = $loader($arguments); |
|
769 | + } else { |
|
770 | + if ($loader && method_exists($this, $loader)) { |
|
771 | + $class_obj = $this->{$loader}($class_name, $arguments); |
|
772 | + } else { |
|
773 | + $class_obj = $this->_create_object($class_name, $arguments, $addon, $from_db); |
|
774 | + } |
|
775 | + } |
|
776 | + if (($this->_cache_on && $cache) || $this->get_class_abbreviation($class_name, '')) { |
|
777 | + // save it for later... kinda like gum { : $ |
|
778 | + $this->_set_cached_class( |
|
779 | + $class_obj, |
|
780 | + $class_name, |
|
781 | + $addon, |
|
782 | + $from_db, |
|
783 | + $arguments |
|
784 | + ); |
|
785 | + } |
|
786 | + $this->_cache_on = true; |
|
787 | + return $class_obj; |
|
788 | + } |
|
789 | + |
|
790 | + |
|
791 | + /** |
|
792 | + * Recursively checks that a class exists and potentially attempts to load classes with non-FQCNs |
|
793 | + * |
|
794 | + * @param string|object $class_name |
|
795 | + * @param array $arguments |
|
796 | + * @param int $attempt |
|
797 | + * @return mixed |
|
798 | + */ |
|
799 | + private function loadOrVerifyClassExists($class_name, array $arguments, $attempt = 1) |
|
800 | + { |
|
801 | + if (is_object($class_name) || class_exists($class_name)) { |
|
802 | + return $class_name; |
|
803 | + } |
|
804 | + switch ($attempt) { |
|
805 | + case 1: |
|
806 | + // if it's a FQCN then maybe the class is registered with a preceding \ |
|
807 | + $class_name = strpos($class_name, '\\') !== false |
|
808 | + ? '\\' . ltrim($class_name, '\\') |
|
809 | + : $class_name; |
|
810 | + break; |
|
811 | + case 2: |
|
812 | + // |
|
813 | + $loader = $this->_dependency_map->class_loader($class_name); |
|
814 | + if ($loader && method_exists($this, $loader)) { |
|
815 | + return $this->{$loader}($class_name, $arguments); |
|
816 | + } |
|
817 | + break; |
|
818 | + case 3: |
|
819 | + default: |
|
820 | + return null; |
|
821 | + } |
|
822 | + $attempt++; |
|
823 | + return $this->loadOrVerifyClassExists($class_name, $arguments, $attempt); |
|
824 | + } |
|
825 | + |
|
826 | + |
|
827 | + /** |
|
828 | + * instantiates, caches, and injects dependencies for classes |
|
829 | + * |
|
830 | + * @param array $file_paths an array of paths to folders to look in |
|
831 | + * @param string $class_prefix EE or EEM or... ??? |
|
832 | + * @param bool|string $class_name $class name |
|
833 | + * @param string $type file type - core? class? helper? model? |
|
834 | + * @param mixed $arguments an argument or array of arguments to pass to the class upon instantiation |
|
835 | + * @param bool $from_db some classes are instantiated from the db |
|
836 | + * and thus call a different method to instantiate |
|
837 | + * @param bool $cache whether to cache the instantiated object for reuse |
|
838 | + * @param bool $load_only if true, will only load the file, but will NOT instantiate an object |
|
839 | + * @return bool|null|object null = failure to load or instantiate class object. |
|
840 | + * object = class loaded and instantiated successfully. |
|
841 | + * bool = fail or success when $load_only is true |
|
842 | + * @throws EE_Error |
|
843 | + * @throws ReflectionException |
|
844 | + * @throws InvalidInterfaceException |
|
845 | + * @throws InvalidDataTypeException |
|
846 | + * @throws InvalidArgumentException |
|
847 | + */ |
|
848 | + protected function _load( |
|
849 | + $file_paths = array(), |
|
850 | + $class_prefix = 'EE_', |
|
851 | + $class_name = false, |
|
852 | + $type = 'class', |
|
853 | + $arguments = array(), |
|
854 | + $from_db = false, |
|
855 | + $cache = true, |
|
856 | + $load_only = false |
|
857 | + ) { |
|
858 | + $class_name = ltrim($class_name, '\\'); |
|
859 | + // strip php file extension |
|
860 | + $class_name = str_replace('.php', '', trim($class_name)); |
|
861 | + // does the class have a prefix ? |
|
862 | + if (! empty($class_prefix) && $class_prefix !== 'addon') { |
|
863 | + // make sure $class_prefix is uppercase |
|
864 | + $class_prefix = strtoupper(trim($class_prefix)); |
|
865 | + // add class prefix ONCE!!! |
|
866 | + $class_name = $class_prefix . str_replace($class_prefix, '', $class_name); |
|
867 | + } |
|
868 | + $class_name = $this->class_cache->getFqnForAlias($class_name); |
|
869 | + $class_exists = class_exists($class_name, false); |
|
870 | + // if we're only loading the class and it already exists, then let's just return true immediately |
|
871 | + if ($load_only && $class_exists) { |
|
872 | + return true; |
|
873 | + } |
|
874 | + $arguments = is_array($arguments) ? $arguments : array($arguments); |
|
875 | + // $this->_cache_on is toggled during the recursive loading that can occur with dependency injection |
|
876 | + // $cache is controlled by individual calls to separate Registry loader methods like load_class() |
|
877 | + // $load_only is also controlled by individual calls to separate Registry loader methods like load_file() |
|
878 | + if ($this->_cache_on && $cache && ! $load_only) { |
|
879 | + // return object if it's already cached |
|
880 | + $cached_class = $this->_get_cached_class($class_name, $class_prefix, $arguments); |
|
881 | + if ($cached_class !== null) { |
|
882 | + return $cached_class; |
|
883 | + } |
|
884 | + } |
|
885 | + // if the class doesn't already exist.. then we need to try and find the file and load it |
|
886 | + if (! $class_exists) { |
|
887 | + // get full path to file |
|
888 | + $path = $this->_resolve_path($class_name, $type, $file_paths); |
|
889 | + // load the file |
|
890 | + $loaded = $this->_require_file($path, $class_name, $type, $file_paths); |
|
891 | + // if we are only loading a file but NOT instantiating an object |
|
892 | + // then return boolean for whether class was loaded or not |
|
893 | + if ($load_only) { |
|
894 | + return $loaded; |
|
895 | + } |
|
896 | + // if an object was expected but loading failed, then return nothing |
|
897 | + if (! $loaded) { |
|
898 | + return null; |
|
899 | + } |
|
900 | + } |
|
901 | + // instantiate the requested object |
|
902 | + $class_obj = $this->_create_object($class_name, $arguments, $type, $from_db); |
|
903 | + if ($this->_cache_on && $cache) { |
|
904 | + // save it for later... kinda like gum { : $ |
|
905 | + $this->_set_cached_class( |
|
906 | + $class_obj, |
|
907 | + $class_name, |
|
908 | + $class_prefix, |
|
909 | + $from_db, |
|
910 | + $arguments |
|
911 | + ); |
|
912 | + } |
|
913 | + $this->_cache_on = true; |
|
914 | + return $class_obj; |
|
915 | + } |
|
916 | + |
|
917 | + |
|
918 | + /** |
|
919 | + * @param string $class_name |
|
920 | + * @param string $default have to specify something, but not anything that will conflict |
|
921 | + * @return mixed|string |
|
922 | + */ |
|
923 | + protected function get_class_abbreviation($class_name, $default = 'FANCY_BATMAN_PANTS') |
|
924 | + { |
|
925 | + return isset($this->_class_abbreviations[ $class_name ]) |
|
926 | + ? $this->_class_abbreviations[ $class_name ] |
|
927 | + : $default; |
|
928 | + } |
|
929 | + |
|
930 | + |
|
931 | + /** |
|
932 | + * attempts to find a cached version of the requested class |
|
933 | + * by looking in the following places: |
|
934 | + * $this->{$class_abbreviation} ie: $this->CART |
|
935 | + * $this->{$class_name} ie: $this->Some_Class |
|
936 | + * $this->LIB->{$class_name} ie: $this->LIB->Some_Class |
|
937 | + * $this->addon->{$class_name} ie: $this->addon->Some_Addon_Class |
|
938 | + * |
|
939 | + * @param string $class_name |
|
940 | + * @param string $class_prefix |
|
941 | + * @param array $arguments |
|
942 | + * @return mixed |
|
943 | + */ |
|
944 | + protected function _get_cached_class( |
|
945 | + $class_name, |
|
946 | + $class_prefix = '', |
|
947 | + $arguments = array() |
|
948 | + ) { |
|
949 | + if ($class_name === 'EE_Registry') { |
|
950 | + return $this; |
|
951 | + } |
|
952 | + $class_abbreviation = $this->get_class_abbreviation($class_name); |
|
953 | + // check if class has already been loaded, and return it if it has been |
|
954 | + if (isset($this->{$class_abbreviation})) { |
|
955 | + return $this->{$class_abbreviation}; |
|
956 | + } |
|
957 | + $class_name = str_replace('\\', '_', $class_name); |
|
958 | + if (isset($this->{$class_name})) { |
|
959 | + return $this->{$class_name}; |
|
960 | + } |
|
961 | + if ($class_prefix === 'addon' && isset($this->addons->{$class_name})) { |
|
962 | + return $this->addons->{$class_name}; |
|
963 | + } |
|
964 | + $object_identifier = $this->object_identifier->getIdentifier($class_name, $arguments); |
|
965 | + if (isset($this->LIB->{$object_identifier})) { |
|
966 | + return $this->LIB->{$object_identifier}; |
|
967 | + } |
|
968 | + foreach ($this->LIB as $key => $object) { |
|
969 | + if (// request does not contain new arguments and therefore no args identifier |
|
970 | + ! $this->object_identifier->hasArguments($object_identifier) |
|
971 | + // but previously cached class with args was found |
|
972 | + && $this->object_identifier->fqcnMatchesObjectIdentifier($class_name, $key) |
|
973 | + ) { |
|
974 | + return $object; |
|
975 | + } |
|
976 | + } |
|
977 | + return null; |
|
978 | + } |
|
979 | + |
|
980 | + |
|
981 | + /** |
|
982 | + * removes a cached version of the requested class |
|
983 | + * |
|
984 | + * @param string $class_name |
|
985 | + * @param boolean $addon |
|
986 | + * @param array $arguments |
|
987 | + * @return boolean |
|
988 | + */ |
|
989 | + public function clear_cached_class( |
|
990 | + $class_name, |
|
991 | + $addon = false, |
|
992 | + $arguments = array() |
|
993 | + ) { |
|
994 | + $class_abbreviation = $this->get_class_abbreviation($class_name); |
|
995 | + // check if class has already been loaded, and return it if it has been |
|
996 | + if (isset($this->{$class_abbreviation})) { |
|
997 | + $this->{$class_abbreviation} = null; |
|
998 | + return true; |
|
999 | + } |
|
1000 | + $class_name = str_replace('\\', '_', $class_name); |
|
1001 | + if (isset($this->{$class_name})) { |
|
1002 | + $this->{$class_name} = null; |
|
1003 | + return true; |
|
1004 | + } |
|
1005 | + if ($addon && isset($this->addons->{$class_name})) { |
|
1006 | + unset($this->addons->{$class_name}); |
|
1007 | + return true; |
|
1008 | + } |
|
1009 | + $class_name = $this->object_identifier->getIdentifier($class_name, $arguments); |
|
1010 | + if (isset($this->LIB->{$class_name})) { |
|
1011 | + unset($this->LIB->{$class_name}); |
|
1012 | + return true; |
|
1013 | + } |
|
1014 | + return false; |
|
1015 | + } |
|
1016 | + |
|
1017 | + |
|
1018 | + /** |
|
1019 | + * _set_cached_class |
|
1020 | + * attempts to cache the instantiated class locally |
|
1021 | + * in one of the following places, in the following order: |
|
1022 | + * $this->{class_abbreviation} ie: $this->CART |
|
1023 | + * $this->{$class_name} ie: $this->Some_Class |
|
1024 | + * $this->addon->{$$class_name} ie: $this->addon->Some_Addon_Class |
|
1025 | + * $this->LIB->{$class_name} ie: $this->LIB->Some_Class |
|
1026 | + * |
|
1027 | + * @param object $class_obj |
|
1028 | + * @param string $class_name |
|
1029 | + * @param string $class_prefix |
|
1030 | + * @param bool $from_db |
|
1031 | + * @param array $arguments |
|
1032 | + * @return void |
|
1033 | + */ |
|
1034 | + protected function _set_cached_class( |
|
1035 | + $class_obj, |
|
1036 | + $class_name, |
|
1037 | + $class_prefix = '', |
|
1038 | + $from_db = false, |
|
1039 | + $arguments = array() |
|
1040 | + ) { |
|
1041 | + if ($class_name === 'EE_Registry' || empty($class_obj)) { |
|
1042 | + return; |
|
1043 | + } |
|
1044 | + // return newly instantiated class |
|
1045 | + $class_abbreviation = $this->get_class_abbreviation($class_name, ''); |
|
1046 | + if ($class_abbreviation) { |
|
1047 | + $this->{$class_abbreviation} = $class_obj; |
|
1048 | + return; |
|
1049 | + } |
|
1050 | + $class_name = str_replace('\\', '_', $class_name); |
|
1051 | + if (property_exists($this, $class_name)) { |
|
1052 | + $this->{$class_name} = $class_obj; |
|
1053 | + return; |
|
1054 | + } |
|
1055 | + if ($class_prefix === 'addon') { |
|
1056 | + $this->addons->{$class_name} = $class_obj; |
|
1057 | + return; |
|
1058 | + } |
|
1059 | + if (! $from_db) { |
|
1060 | + $class_name = $this->object_identifier->getIdentifier($class_name, $arguments); |
|
1061 | + $this->LIB->{$class_name} = $class_obj; |
|
1062 | + } |
|
1063 | + } |
|
1064 | + |
|
1065 | + |
|
1066 | + /** |
|
1067 | + * attempts to find a full valid filepath for the requested class. |
|
1068 | + * loops thru each of the base paths in the $file_paths array and appends : "{classname} . {file type} . php" |
|
1069 | + * then returns that path if the target file has been found and is readable |
|
1070 | + * |
|
1071 | + * @param string $class_name |
|
1072 | + * @param string $type |
|
1073 | + * @param array $file_paths |
|
1074 | + * @return string | bool |
|
1075 | + */ |
|
1076 | + protected function _resolve_path($class_name, $type = '', $file_paths = array()) |
|
1077 | + { |
|
1078 | + // make sure $file_paths is an array |
|
1079 | + $file_paths = is_array($file_paths) |
|
1080 | + ? $file_paths |
|
1081 | + : array($file_paths); |
|
1082 | + // cycle thru paths |
|
1083 | + foreach ($file_paths as $key => $file_path) { |
|
1084 | + // convert all separators to proper /, if no filepath, then use EE_CLASSES |
|
1085 | + $file_path = $file_path |
|
1086 | + ? str_replace(array('/', '\\'), '/', $file_path) |
|
1087 | + : EE_CLASSES; |
|
1088 | + // prep file type |
|
1089 | + $type = ! empty($type) |
|
1090 | + ? trim($type, '.') . '.' |
|
1091 | + : ''; |
|
1092 | + // build full file path |
|
1093 | + $file_paths[ $key ] = rtrim($file_path, '/') . '/' . $class_name . '.' . $type . 'php'; |
|
1094 | + // does the file exist and can be read ? |
|
1095 | + if (is_readable($file_paths[ $key ])) { |
|
1096 | + return $file_paths[ $key ]; |
|
1097 | + } |
|
1098 | + } |
|
1099 | + return false; |
|
1100 | + } |
|
1101 | + |
|
1102 | + |
|
1103 | + /** |
|
1104 | + * basically just performs a require_once() |
|
1105 | + * but with some error handling |
|
1106 | + * |
|
1107 | + * @param string $path |
|
1108 | + * @param string $class_name |
|
1109 | + * @param string $type |
|
1110 | + * @param array $file_paths |
|
1111 | + * @return bool |
|
1112 | + * @throws EE_Error |
|
1113 | + * @throws ReflectionException |
|
1114 | + */ |
|
1115 | + protected function _require_file($path, $class_name, $type = '', $file_paths = array()) |
|
1116 | + { |
|
1117 | + $this->resolve_legacy_class_parent($class_name); |
|
1118 | + // don't give up! you gotta... |
|
1119 | + try { |
|
1120 | + // does the file exist and can it be read ? |
|
1121 | + if (! $path) { |
|
1122 | + // just in case the file has already been autoloaded, |
|
1123 | + // but discrepancies in the naming schema are preventing it from |
|
1124 | + // being loaded via one of the EE_Registry::load_*() methods, |
|
1125 | + // then let's try one last hail mary before throwing an exception |
|
1126 | + // and call class_exists() again, but with autoloading turned ON |
|
1127 | + if (class_exists($class_name)) { |
|
1128 | + return true; |
|
1129 | + } |
|
1130 | + // so sorry, can't find the file |
|
1131 | + throw new EE_Error( |
|
1132 | + sprintf( |
|
1133 | + esc_html__( |
|
1134 | + 'The %1$s file %2$s could not be located or is not readable due to file permissions. Please ensure that the following filepath(s) are correct: %3$s', |
|
1135 | + 'event_espresso' |
|
1136 | + ), |
|
1137 | + trim($type, '.'), |
|
1138 | + $class_name, |
|
1139 | + '<br />' . implode(',<br />', $file_paths) |
|
1140 | + ) |
|
1141 | + ); |
|
1142 | + } |
|
1143 | + // get the file |
|
1144 | + require_once($path); |
|
1145 | + // if the class isn't already declared somewhere |
|
1146 | + if (class_exists($class_name, false) === false) { |
|
1147 | + // so sorry, not a class |
|
1148 | + throw new EE_Error( |
|
1149 | + sprintf( |
|
1150 | + esc_html__( |
|
1151 | + 'The %s file %s does not appear to contain the %s Class.', |
|
1152 | + 'event_espresso' |
|
1153 | + ), |
|
1154 | + $type, |
|
1155 | + $path, |
|
1156 | + $class_name |
|
1157 | + ) |
|
1158 | + ); |
|
1159 | + } |
|
1160 | + } catch (EE_Error $e) { |
|
1161 | + $e->get_error(); |
|
1162 | + return false; |
|
1163 | + } |
|
1164 | + return true; |
|
1165 | + } |
|
1166 | + |
|
1167 | + |
|
1168 | + /** |
|
1169 | + * Some of our legacy classes that extended a parent class would simply use a require() statement |
|
1170 | + * before their class declaration in order to ensure that the parent class was loaded. |
|
1171 | + * This is not ideal, but it's nearly impossible to determine the parent class of a non-namespaced class, |
|
1172 | + * without triggering a fatal error because the parent class has yet to be loaded and therefore doesn't exist. |
|
1173 | + * |
|
1174 | + * @param string $class_name |
|
1175 | + */ |
|
1176 | + protected function resolve_legacy_class_parent($class_name = '') |
|
1177 | + { |
|
1178 | + try { |
|
1179 | + $legacy_parent_class_map = array( |
|
1180 | + 'EE_Payment_Processor' => 'core/business/EE_Processor_Base.class.php', |
|
1181 | + ); |
|
1182 | + if (isset($legacy_parent_class_map[ $class_name ])) { |
|
1183 | + require_once EE_PLUGIN_DIR_PATH . $legacy_parent_class_map[ $class_name ]; |
|
1184 | + } |
|
1185 | + } catch (Exception $exception) { |
|
1186 | + } |
|
1187 | + } |
|
1188 | + |
|
1189 | + |
|
1190 | + /** |
|
1191 | + * _create_object |
|
1192 | + * Attempts to instantiate the requested class via any of the |
|
1193 | + * commonly used instantiation methods employed throughout EE. |
|
1194 | + * The priority for instantiation is as follows: |
|
1195 | + * - abstract classes or any class flagged as "load only" (no instantiation occurs) |
|
1196 | + * - model objects via their 'new_instance_from_db' method |
|
1197 | + * - model objects via their 'new_instance' method |
|
1198 | + * - "singleton" classes" via their 'instance' method |
|
1199 | + * - standard instantiable classes via their __constructor |
|
1200 | + * Prior to instantiation, if the classname exists in the dependency_map, |
|
1201 | + * then the constructor for the requested class will be examined to determine |
|
1202 | + * if any dependencies exist, and if they can be injected. |
|
1203 | + * If so, then those classes will be added to the array of arguments passed to the constructor |
|
1204 | + * |
|
1205 | + * @param string $class_name |
|
1206 | + * @param array $arguments |
|
1207 | + * @param string $type |
|
1208 | + * @param bool $from_db |
|
1209 | + * @return null|object|bool |
|
1210 | + * @throws InvalidArgumentException |
|
1211 | + * @throws InvalidInterfaceException |
|
1212 | + * @throws EE_Error |
|
1213 | + * @throws ReflectionException |
|
1214 | + * @throws InvalidDataTypeException |
|
1215 | + */ |
|
1216 | + protected function _create_object($class_name, $arguments = array(), $type = '', $from_db = false) |
|
1217 | + { |
|
1218 | + // create reflection |
|
1219 | + $reflector = $this->mirror->getReflectionClass($class_name); |
|
1220 | + // make sure arguments are an array |
|
1221 | + $arguments = is_array($arguments) |
|
1222 | + ? $arguments |
|
1223 | + : array($arguments); |
|
1224 | + // and if arguments array is numerically and sequentially indexed, then we want it to remain as is, |
|
1225 | + // else wrap it in an additional array so that it doesn't get split into multiple parameters |
|
1226 | + $arguments = $this->_array_is_numerically_and_sequentially_indexed($arguments) |
|
1227 | + ? $arguments |
|
1228 | + : array($arguments); |
|
1229 | + // attempt to inject dependencies ? |
|
1230 | + if ($this->_dependency_map->has($class_name)) { |
|
1231 | + $arguments = $this->_resolve_dependencies($reflector, $class_name, $arguments); |
|
1232 | + } |
|
1233 | + // instantiate the class if possible |
|
1234 | + if ($reflector->isAbstract()) { |
|
1235 | + // nothing to instantiate, loading file was enough |
|
1236 | + // does not throw an exception so $instantiation_mode is unused |
|
1237 | + // $instantiation_mode = "1) no constructor abstract class"; |
|
1238 | + return true; |
|
1239 | + } |
|
1240 | + if (empty($arguments) |
|
1241 | + && $this->mirror->getConstructorFromReflection($reflector) === null |
|
1242 | + && $reflector->isInstantiable() |
|
1243 | + ) { |
|
1244 | + // no constructor = static methods only... nothing to instantiate, loading file was enough |
|
1245 | + // $instantiation_mode = "2) no constructor but instantiable"; |
|
1246 | + return $reflector->newInstance(); |
|
1247 | + } |
|
1248 | + if ($from_db && method_exists($class_name, 'new_instance_from_db')) { |
|
1249 | + // $instantiation_mode = "3) new_instance_from_db()"; |
|
1250 | + return call_user_func_array(array($class_name, 'new_instance_from_db'), $arguments); |
|
1251 | + } |
|
1252 | + if (method_exists($class_name, 'new_instance')) { |
|
1253 | + // $instantiation_mode = "4) new_instance()"; |
|
1254 | + return call_user_func_array(array($class_name, 'new_instance'), $arguments); |
|
1255 | + } |
|
1256 | + if (method_exists($class_name, 'instance')) { |
|
1257 | + // $instantiation_mode = "5) instance()"; |
|
1258 | + return call_user_func_array(array($class_name, 'instance'), $arguments); |
|
1259 | + } |
|
1260 | + if ($reflector->isInstantiable()) { |
|
1261 | + // $instantiation_mode = "6) constructor"; |
|
1262 | + return $reflector->newInstanceArgs($arguments); |
|
1263 | + } |
|
1264 | + // heh ? something's not right ! |
|
1265 | + throw new EE_Error( |
|
1266 | + sprintf( |
|
1267 | + __('The %s file %s could not be instantiated.', 'event_espresso'), |
|
1268 | + $type, |
|
1269 | + $class_name |
|
1270 | + ) |
|
1271 | + ); |
|
1272 | + } |
|
1273 | + |
|
1274 | + |
|
1275 | + /** |
|
1276 | + * @see http://stackoverflow.com/questions/173400/how-to-check-if-php-array-is-associative-or-sequential |
|
1277 | + * @param array $array |
|
1278 | + * @return bool |
|
1279 | + */ |
|
1280 | + protected function _array_is_numerically_and_sequentially_indexed(array $array) |
|
1281 | + { |
|
1282 | + return ! empty($array) |
|
1283 | + ? array_keys($array) === range(0, count($array) - 1) |
|
1284 | + : true; |
|
1285 | + } |
|
1286 | + |
|
1287 | + |
|
1288 | + /** |
|
1289 | + * _resolve_dependencies |
|
1290 | + * examines the constructor for the requested class to determine |
|
1291 | + * if any dependencies exist, and if they can be injected. |
|
1292 | + * If so, then those classes will be added to the array of arguments passed to the constructor |
|
1293 | + * PLZ NOTE: this is achieved by type hinting the constructor params |
|
1294 | + * For example: |
|
1295 | + * if attempting to load a class "Foo" with the following constructor: |
|
1296 | + * __construct( Bar $bar_class, Fighter $grohl_class ) |
|
1297 | + * then $bar_class and $grohl_class will be added to the $arguments array, |
|
1298 | + * but only IF they are NOT already present in the incoming arguments array, |
|
1299 | + * and the correct classes can be loaded |
|
1300 | + * |
|
1301 | + * @param ReflectionClass $reflector |
|
1302 | + * @param string $class_name |
|
1303 | + * @param array $arguments |
|
1304 | + * @return array |
|
1305 | + * @throws InvalidArgumentException |
|
1306 | + * @throws InvalidDataTypeException |
|
1307 | + * @throws InvalidInterfaceException |
|
1308 | + * @throws ReflectionException |
|
1309 | + */ |
|
1310 | + protected function _resolve_dependencies(ReflectionClass $reflector, $class_name, array $arguments = array()) |
|
1311 | + { |
|
1312 | + // let's examine the constructor |
|
1313 | + $constructor = $this->mirror->getConstructorFromReflection($reflector); |
|
1314 | + // whu? huh? nothing? |
|
1315 | + if (! $constructor) { |
|
1316 | + return $arguments; |
|
1317 | + } |
|
1318 | + // get constructor parameters |
|
1319 | + $params = $this->mirror->getParametersFromReflection($reflector); |
|
1320 | + // and the keys for the incoming arguments array so that we can compare existing arguments with what is expected |
|
1321 | + $argument_keys = array_keys($arguments); |
|
1322 | + // now loop thru all of the constructors expected parameters |
|
1323 | + foreach ($params as $index => $param) { |
|
1324 | + try { |
|
1325 | + // is this a dependency for a specific class ? |
|
1326 | + $param_class = $this->mirror->getParameterClassName($param, $class_name, $index); |
|
1327 | + } catch (ReflectionException $exception) { |
|
1328 | + // uh-oh... most likely a legacy class that has not been autoloaded |
|
1329 | + // let's try to derive the classname from what we have now |
|
1330 | + // and hope that the property var name is close to the class name |
|
1331 | + $param_class = $param->getName(); |
|
1332 | + $param_class = str_replace('_', ' ', $param_class); |
|
1333 | + $param_class = ucwords($param_class); |
|
1334 | + $param_class = str_replace(' ', '_', $param_class); |
|
1335 | + } |
|
1336 | + // BUT WAIT !!! This class may be an alias for something else (or getting replaced at runtime) |
|
1337 | + $param_class = $this->class_cache->isAlias($param_class, $class_name) |
|
1338 | + ? $this->class_cache->getFqnForAlias($param_class, $class_name) |
|
1339 | + : $param_class; |
|
1340 | + if (// param is not even a class |
|
1341 | + $param_class === null |
|
1342 | + // and something already exists in the incoming arguments for this param |
|
1343 | + && array_key_exists($index, $argument_keys) |
|
1344 | + && array_key_exists($argument_keys[ $index ], $arguments) |
|
1345 | + ) { |
|
1346 | + // so let's skip this argument and move on to the next |
|
1347 | + continue; |
|
1348 | + } |
|
1349 | + if (// parameter is type hinted as a class, exists as an incoming argument, AND it's the correct class |
|
1350 | + $param_class !== null |
|
1351 | + && isset($argument_keys[ $index ], $arguments[ $argument_keys[ $index ] ]) |
|
1352 | + && $arguments[ $argument_keys[ $index ] ] instanceof $param_class |
|
1353 | + ) { |
|
1354 | + // skip this argument and move on to the next |
|
1355 | + continue; |
|
1356 | + } |
|
1357 | + if (// parameter is type hinted as a class, and should be injected |
|
1358 | + $param_class !== null |
|
1359 | + && $this->_dependency_map->has_dependency_for_class($class_name, $param_class) |
|
1360 | + ) { |
|
1361 | + $arguments = $this->_resolve_dependency( |
|
1362 | + $class_name, |
|
1363 | + $param_class, |
|
1364 | + $arguments, |
|
1365 | + $index |
|
1366 | + ); |
|
1367 | + } |
|
1368 | + if (empty($arguments[ $index ])) { |
|
1369 | + $arguments[ $index ] = $this->mirror->getParameterDefaultValue( |
|
1370 | + $param, |
|
1371 | + $class_name, |
|
1372 | + $index |
|
1373 | + ); |
|
1374 | + } |
|
1375 | + } |
|
1376 | + return $arguments; |
|
1377 | + } |
|
1378 | + |
|
1379 | + |
|
1380 | + /** |
|
1381 | + * @param string $class_name |
|
1382 | + * @param string $param_class |
|
1383 | + * @param array $arguments |
|
1384 | + * @param mixed $index |
|
1385 | + * @return array |
|
1386 | + * @throws InvalidArgumentException |
|
1387 | + * @throws InvalidInterfaceException |
|
1388 | + * @throws InvalidDataTypeException |
|
1389 | + */ |
|
1390 | + protected function _resolve_dependency($class_name, $param_class, $arguments, $index) |
|
1391 | + { |
|
1392 | + $dependency = null; |
|
1393 | + // should dependency be loaded from cache ? |
|
1394 | + $cache_on = $this->_dependency_map->loading_strategy_for_class_dependency( |
|
1395 | + $class_name, |
|
1396 | + $param_class |
|
1397 | + ); |
|
1398 | + $cache_on = $cache_on !== EE_Dependency_Map::load_new_object; |
|
1399 | + // we might have a dependency... |
|
1400 | + // let's MAYBE try and find it in our cache if that's what's been requested |
|
1401 | + $cached_class = $cache_on |
|
1402 | + ? $this->_get_cached_class($param_class) |
|
1403 | + : null; |
|
1404 | + // and grab it if it exists |
|
1405 | + if ($cached_class instanceof $param_class) { |
|
1406 | + $dependency = $cached_class; |
|
1407 | + } elseif ($param_class !== $class_name) { |
|
1408 | + // obtain the loader method from the dependency map |
|
1409 | + $loader = $this->_dependency_map->class_loader($param_class); |
|
1410 | + // is loader a custom closure ? |
|
1411 | + if ($loader instanceof Closure) { |
|
1412 | + $dependency = $loader($arguments); |
|
1413 | + } else { |
|
1414 | + // set the cache on property for the recursive loading call |
|
1415 | + $this->_cache_on = $cache_on; |
|
1416 | + // if not, then let's try and load it via the registry |
|
1417 | + if ($loader && method_exists($this, $loader)) { |
|
1418 | + $dependency = $this->{$loader}($param_class); |
|
1419 | + } else { |
|
1420 | + $dependency = LoaderFactory::getLoader()->load( |
|
1421 | + $param_class, |
|
1422 | + array(), |
|
1423 | + $cache_on |
|
1424 | + ); |
|
1425 | + } |
|
1426 | + } |
|
1427 | + } |
|
1428 | + // did we successfully find the correct dependency ? |
|
1429 | + if ($dependency instanceof $param_class) { |
|
1430 | + // then let's inject it into the incoming array of arguments at the correct location |
|
1431 | + $arguments[ $index ] = $dependency; |
|
1432 | + } |
|
1433 | + return $arguments; |
|
1434 | + } |
|
1435 | + |
|
1436 | + |
|
1437 | + /** |
|
1438 | + * call any loader that's been registered in the EE_Dependency_Map::$_class_loaders array |
|
1439 | + * |
|
1440 | + * @param string $classname PLEASE NOTE: the class name needs to match what's registered |
|
1441 | + * in the EE_Dependency_Map::$_class_loaders array, |
|
1442 | + * including the class prefix, ie: "EE_", "EEM_", "EEH_", etc |
|
1443 | + * @param array $arguments |
|
1444 | + * @return object |
|
1445 | + */ |
|
1446 | + public static function factory($classname, $arguments = array()) |
|
1447 | + { |
|
1448 | + $loader = self::instance()->_dependency_map->class_loader($classname); |
|
1449 | + if ($loader instanceof Closure) { |
|
1450 | + return $loader($arguments); |
|
1451 | + } |
|
1452 | + if (method_exists(self::instance(), $loader)) { |
|
1453 | + return self::instance()->{$loader}($classname, $arguments); |
|
1454 | + } |
|
1455 | + return null; |
|
1456 | + } |
|
1457 | + |
|
1458 | + |
|
1459 | + /** |
|
1460 | + * Gets the addon by its class name |
|
1461 | + * |
|
1462 | + * @param string $class_name |
|
1463 | + * @return EE_Addon |
|
1464 | + */ |
|
1465 | + public function getAddon($class_name) |
|
1466 | + { |
|
1467 | + $class_name = str_replace('\\', '_', $class_name); |
|
1468 | + if (isset($this->addons->{$class_name})) { |
|
1469 | + return $this->addons->{$class_name}; |
|
1470 | + } else { |
|
1471 | + return null; |
|
1472 | + } |
|
1473 | + } |
|
1474 | + |
|
1475 | + |
|
1476 | + /** |
|
1477 | + * removes the addon from the internal cache |
|
1478 | + * |
|
1479 | + * @param string $class_name |
|
1480 | + * @return void |
|
1481 | + */ |
|
1482 | + public function removeAddon($class_name) |
|
1483 | + { |
|
1484 | + $class_name = str_replace('\\', '_', $class_name); |
|
1485 | + unset($this->addons->{$class_name}); |
|
1486 | + } |
|
1487 | + |
|
1488 | + |
|
1489 | + /** |
|
1490 | + * Gets the addon by its name/slug (not classname. For that, just |
|
1491 | + * use the get_addon() method above |
|
1492 | + * |
|
1493 | + * @param string $name |
|
1494 | + * @return EE_Addon |
|
1495 | + */ |
|
1496 | + public function get_addon_by_name($name) |
|
1497 | + { |
|
1498 | + foreach ($this->addons as $addon) { |
|
1499 | + if ($addon->name() === $name) { |
|
1500 | + return $addon; |
|
1501 | + } |
|
1502 | + } |
|
1503 | + return null; |
|
1504 | + } |
|
1505 | + |
|
1506 | + |
|
1507 | + /** |
|
1508 | + * Gets an array of all the registered addons, where the keys are their names. |
|
1509 | + * (ie, what each returns for their name() function) |
|
1510 | + * They're already available on EE_Registry::instance()->addons as properties, |
|
1511 | + * where each property's name is the addon's classname, |
|
1512 | + * So if you just want to get the addon by classname, |
|
1513 | + * OR use the get_addon() method above. |
|
1514 | + * PLEASE NOTE: |
|
1515 | + * addons with Fully Qualified Class Names |
|
1516 | + * have had the namespace separators converted to underscores, |
|
1517 | + * so a classname like Fully\Qualified\ClassName |
|
1518 | + * would have been converted to Fully_Qualified_ClassName |
|
1519 | + * |
|
1520 | + * @return EE_Addon[] where the KEYS are the addon's name() |
|
1521 | + */ |
|
1522 | + public function get_addons_by_name() |
|
1523 | + { |
|
1524 | + $addons = array(); |
|
1525 | + foreach ($this->addons as $addon) { |
|
1526 | + $addons[ $addon->name() ] = $addon; |
|
1527 | + } |
|
1528 | + return $addons; |
|
1529 | + } |
|
1530 | + |
|
1531 | + |
|
1532 | + /** |
|
1533 | + * Resets the specified model's instance AND makes sure EE_Registry doesn't keep |
|
1534 | + * a stale copy of it around |
|
1535 | + * |
|
1536 | + * @param string $model_name |
|
1537 | + * @return \EEM_Base |
|
1538 | + * @throws \EE_Error |
|
1539 | + */ |
|
1540 | + public function reset_model($model_name) |
|
1541 | + { |
|
1542 | + $model_class_name = strpos($model_name, 'EEM_') !== 0 |
|
1543 | + ? "EEM_{$model_name}" |
|
1544 | + : $model_name; |
|
1545 | + if (! isset($this->LIB->{$model_class_name}) || ! $this->LIB->{$model_class_name} instanceof EEM_Base) { |
|
1546 | + return null; |
|
1547 | + } |
|
1548 | + // get that model reset it and make sure we nuke the old reference to it |
|
1549 | + if ($this->LIB->{$model_class_name} instanceof $model_class_name |
|
1550 | + && is_callable( |
|
1551 | + array($model_class_name, 'reset') |
|
1552 | + )) { |
|
1553 | + $this->LIB->{$model_class_name} = $this->LIB->{$model_class_name}->reset(); |
|
1554 | + } else { |
|
1555 | + throw new EE_Error( |
|
1556 | + sprintf( |
|
1557 | + esc_html__('Model %s does not have a method "reset"', 'event_espresso'), |
|
1558 | + $model_name |
|
1559 | + ) |
|
1560 | + ); |
|
1561 | + } |
|
1562 | + return $this->LIB->{$model_class_name}; |
|
1563 | + } |
|
1564 | + |
|
1565 | + |
|
1566 | + /** |
|
1567 | + * Resets the registry. |
|
1568 | + * The criteria for what gets reset is based on what can be shared between sites on the same request when |
|
1569 | + * switch_to_blog is used in a multisite install. Here is a list of things that are NOT reset. |
|
1570 | + * - $_dependency_map |
|
1571 | + * - $_class_abbreviations |
|
1572 | + * - $NET_CFG (EE_Network_Config): The config is shared network wide so no need to reset. |
|
1573 | + * - $REQ: Still on the same request so no need to change. |
|
1574 | + * - $CAP: There is no site specific state in the EE_Capability class. |
|
1575 | + * - $SSN: Although ideally, the session should not be shared between site switches, we can't reset it because only |
|
1576 | + * one Session can be active in a single request. Resetting could resolve in "headers already sent" errors. |
|
1577 | + * - $addons: In multisite, the state of the addons is something controlled via hooks etc in a normal request. So |
|
1578 | + * for now, we won't reset the addons because it could break calls to an add-ons class/methods in the |
|
1579 | + * switch or on the restore. |
|
1580 | + * - $modules |
|
1581 | + * - $shortcodes |
|
1582 | + * - $widgets |
|
1583 | + * |
|
1584 | + * @param boolean $hard [deprecated] |
|
1585 | + * @param boolean $reinstantiate whether to create new instances of EE_Registry's singletons too, |
|
1586 | + * or just reset without re-instantiating (handy to set to FALSE if you're not |
|
1587 | + * sure if you CAN currently reinstantiate the singletons at the moment) |
|
1588 | + * @param bool $reset_models Defaults to true. When false, then the models are not reset. This is so |
|
1589 | + * client |
|
1590 | + * code instead can just change the model context to a different blog id if |
|
1591 | + * necessary |
|
1592 | + * @return EE_Registry |
|
1593 | + * @throws InvalidInterfaceException |
|
1594 | + * @throws InvalidDataTypeException |
|
1595 | + * @throws EE_Error |
|
1596 | + * @throws ReflectionException |
|
1597 | + * @throws InvalidArgumentException |
|
1598 | + */ |
|
1599 | + public static function reset($hard = false, $reinstantiate = true, $reset_models = true) |
|
1600 | + { |
|
1601 | + $instance = self::instance(); |
|
1602 | + $instance->_cache_on = true; |
|
1603 | + // reset some "special" classes |
|
1604 | + EEH_Activation::reset(); |
|
1605 | + $hard = apply_filters('FHEE__EE_Registry__reset__hard', $hard); |
|
1606 | + $instance->CFG = EE_Config::reset($hard, $reinstantiate); |
|
1607 | + $instance->CART = null; |
|
1608 | + $instance->MRM = null; |
|
1609 | + $instance->AssetsRegistry = LoaderFactory::getLoader()->getShared( |
|
1610 | + 'EventEspresso\core\services\assets\Registry' |
|
1611 | + ); |
|
1612 | + // messages reset |
|
1613 | + EED_Messages::reset(); |
|
1614 | + // handle of objects cached on LIB |
|
1615 | + foreach (array('LIB', 'modules') as $cache) { |
|
1616 | + foreach ($instance->{$cache} as $class_name => $class) { |
|
1617 | + if (self::_reset_and_unset_object($class, $reset_models)) { |
|
1618 | + unset($instance->{$cache}->{$class_name}); |
|
1619 | + } |
|
1620 | + } |
|
1621 | + } |
|
1622 | + return $instance; |
|
1623 | + } |
|
1624 | + |
|
1625 | + |
|
1626 | + /** |
|
1627 | + * if passed object implements ResettableInterface, then call it's reset() method |
|
1628 | + * if passed object implements InterminableInterface, then return false, |
|
1629 | + * to indicate that it should NOT be cleared from the Registry cache |
|
1630 | + * |
|
1631 | + * @param $object |
|
1632 | + * @param bool $reset_models |
|
1633 | + * @return bool returns true if cached object should be unset |
|
1634 | + */ |
|
1635 | + private static function _reset_and_unset_object($object, $reset_models) |
|
1636 | + { |
|
1637 | + if (! is_object($object)) { |
|
1638 | + // don't unset anything that's not an object |
|
1639 | + return false; |
|
1640 | + } |
|
1641 | + if ($object instanceof EED_Module) { |
|
1642 | + $object::reset(); |
|
1643 | + // don't unset modules |
|
1644 | + return false; |
|
1645 | + } |
|
1646 | + if ($object instanceof ResettableInterface) { |
|
1647 | + if ($object instanceof EEM_Base) { |
|
1648 | + if ($reset_models) { |
|
1649 | + $object->reset(); |
|
1650 | + return true; |
|
1651 | + } |
|
1652 | + return false; |
|
1653 | + } |
|
1654 | + $object->reset(); |
|
1655 | + return true; |
|
1656 | + } |
|
1657 | + if (! $object instanceof InterminableInterface) { |
|
1658 | + return true; |
|
1659 | + } |
|
1660 | + return false; |
|
1661 | + } |
|
1662 | + |
|
1663 | + |
|
1664 | + /** |
|
1665 | + * Gets all the custom post type models defined |
|
1666 | + * |
|
1667 | + * @return array keys are model "short names" (Eg "Event") and keys are classnames (eg "EEM_Event") |
|
1668 | + */ |
|
1669 | + public function cpt_models() |
|
1670 | + { |
|
1671 | + $cpt_models = array(); |
|
1672 | + foreach ($this->non_abstract_db_models as $short_name => $classname) { |
|
1673 | + if (is_subclass_of($classname, 'EEM_CPT_Base')) { |
|
1674 | + $cpt_models[ $short_name ] = $classname; |
|
1675 | + } |
|
1676 | + } |
|
1677 | + return $cpt_models; |
|
1678 | + } |
|
1679 | + |
|
1680 | + |
|
1681 | + /** |
|
1682 | + * @return \EE_Config |
|
1683 | + */ |
|
1684 | + public static function CFG() |
|
1685 | + { |
|
1686 | + return self::instance()->CFG; |
|
1687 | + } |
|
1688 | + |
|
1689 | + |
|
1690 | + /** |
|
1691 | + * @deprecated 4.9.62.p |
|
1692 | + * @param string $class_name |
|
1693 | + * @return ReflectionClass |
|
1694 | + * @throws ReflectionException |
|
1695 | + * @throws InvalidDataTypeException |
|
1696 | + */ |
|
1697 | + public function get_ReflectionClass($class_name) |
|
1698 | + { |
|
1699 | + return $this->mirror->getReflectionClass($class_name); |
|
1700 | + } |
|
1701 | 1701 | } |
@@ -193,7 +193,7 @@ discard block |
||
193 | 193 | ObjectIdentifier $object_identifier = null |
194 | 194 | ) { |
195 | 195 | // check if class object is instantiated |
196 | - if (! self::$_instance instanceof EE_Registry |
|
196 | + if ( ! self::$_instance instanceof EE_Registry |
|
197 | 197 | && $dependency_map instanceof EE_Dependency_Map |
198 | 198 | && $mirror instanceof Mirror |
199 | 199 | && $class_cache instanceof ClassInterfaceCache |
@@ -308,10 +308,10 @@ discard block |
||
308 | 308 | $i18n_js_strings = (array) self::$i18n_js_strings; |
309 | 309 | foreach ($i18n_js_strings as $key => $value) { |
310 | 310 | if (is_scalar($value)) { |
311 | - $i18n_js_strings[ $key ] = html_entity_decode((string) $value, ENT_QUOTES, 'UTF-8'); |
|
311 | + $i18n_js_strings[$key] = html_entity_decode((string) $value, ENT_QUOTES, 'UTF-8'); |
|
312 | 312 | } |
313 | 313 | } |
314 | - return '/* <![CDATA[ */ var eei18n = ' . wp_json_encode($i18n_js_strings) . '; /* ]]> */'; |
|
314 | + return '/* <![CDATA[ */ var eei18n = '.wp_json_encode($i18n_js_strings).'; /* ]]> */'; |
|
315 | 315 | } |
316 | 316 | |
317 | 317 | |
@@ -330,7 +330,7 @@ discard block |
||
330 | 330 | $module_class = get_class($module); |
331 | 331 | $this->modules->{$module_class} = $module; |
332 | 332 | } else { |
333 | - if (! class_exists('EE_Module_Request_Router', false)) { |
|
333 | + if ( ! class_exists('EE_Module_Request_Router', false)) { |
|
334 | 334 | $this->load_core('Module_Request_Router'); |
335 | 335 | } |
336 | 336 | EE_Module_Request_Router::module_factory($module); |
@@ -371,10 +371,10 @@ discard block |
||
371 | 371 | EE_CORE, |
372 | 372 | EE_ADMIN, |
373 | 373 | EE_CPTS, |
374 | - EE_CORE . 'data_migration_scripts/', |
|
375 | - EE_CORE . 'capabilities/', |
|
376 | - EE_CORE . 'request_stack/', |
|
377 | - EE_CORE . 'middleware/', |
|
374 | + EE_CORE.'data_migration_scripts/', |
|
375 | + EE_CORE.'capabilities/', |
|
376 | + EE_CORE.'request_stack/', |
|
377 | + EE_CORE.'middleware/', |
|
378 | 378 | ) |
379 | 379 | ); |
380 | 380 | // retrieve instantiated class |
@@ -409,7 +409,7 @@ discard block |
||
409 | 409 | $service_paths = apply_filters( |
410 | 410 | 'FHEE__EE_Registry__load_service__service_paths', |
411 | 411 | array( |
412 | - EE_CORE . 'services/', |
|
412 | + EE_CORE.'services/', |
|
413 | 413 | ) |
414 | 414 | ); |
415 | 415 | // retrieve instantiated class |
@@ -544,10 +544,10 @@ discard block |
||
544 | 544 | { |
545 | 545 | $paths = array( |
546 | 546 | EE_LIBRARIES, |
547 | - EE_LIBRARIES . 'messages/', |
|
548 | - EE_LIBRARIES . 'shortcodes/', |
|
549 | - EE_LIBRARIES . 'qtips/', |
|
550 | - EE_LIBRARIES . 'payment_methods/', |
|
547 | + EE_LIBRARIES.'messages/', |
|
548 | + EE_LIBRARIES.'shortcodes/', |
|
549 | + EE_LIBRARIES.'qtips/', |
|
550 | + EE_LIBRARIES.'payment_methods/', |
|
551 | 551 | ); |
552 | 552 | // retrieve instantiated class |
553 | 553 | return $this->_load( |
@@ -615,10 +615,10 @@ discard block |
||
615 | 615 | public function load_model_class($class_name, $arguments = array(), $load_only = true) |
616 | 616 | { |
617 | 617 | $paths = array( |
618 | - EE_MODELS . 'fields/', |
|
619 | - EE_MODELS . 'helpers/', |
|
620 | - EE_MODELS . 'relations/', |
|
621 | - EE_MODELS . 'strategies/', |
|
618 | + EE_MODELS.'fields/', |
|
619 | + EE_MODELS.'helpers/', |
|
620 | + EE_MODELS.'relations/', |
|
621 | + EE_MODELS.'strategies/', |
|
622 | 622 | ); |
623 | 623 | // retrieve instantiated class |
624 | 624 | return $this->_load( |
@@ -642,7 +642,7 @@ discard block |
||
642 | 642 | */ |
643 | 643 | public function is_model_name($model_name) |
644 | 644 | { |
645 | - return isset($this->models[ $model_name ]); |
|
645 | + return isset($this->models[$model_name]); |
|
646 | 646 | } |
647 | 647 | |
648 | 648 | |
@@ -763,7 +763,7 @@ discard block |
||
763 | 763 | return $cached_class; |
764 | 764 | } |
765 | 765 | }// obtain the loader method from the dependency map |
766 | - $loader = $this->_dependency_map->class_loader($class_name);// instantiate the requested object |
|
766 | + $loader = $this->_dependency_map->class_loader($class_name); // instantiate the requested object |
|
767 | 767 | if ($loader instanceof Closure) { |
768 | 768 | $class_obj = $loader($arguments); |
769 | 769 | } else { |
@@ -805,7 +805,7 @@ discard block |
||
805 | 805 | case 1: |
806 | 806 | // if it's a FQCN then maybe the class is registered with a preceding \ |
807 | 807 | $class_name = strpos($class_name, '\\') !== false |
808 | - ? '\\' . ltrim($class_name, '\\') |
|
808 | + ? '\\'.ltrim($class_name, '\\') |
|
809 | 809 | : $class_name; |
810 | 810 | break; |
811 | 811 | case 2: |
@@ -859,11 +859,11 @@ discard block |
||
859 | 859 | // strip php file extension |
860 | 860 | $class_name = str_replace('.php', '', trim($class_name)); |
861 | 861 | // does the class have a prefix ? |
862 | - if (! empty($class_prefix) && $class_prefix !== 'addon') { |
|
862 | + if ( ! empty($class_prefix) && $class_prefix !== 'addon') { |
|
863 | 863 | // make sure $class_prefix is uppercase |
864 | 864 | $class_prefix = strtoupper(trim($class_prefix)); |
865 | 865 | // add class prefix ONCE!!! |
866 | - $class_name = $class_prefix . str_replace($class_prefix, '', $class_name); |
|
866 | + $class_name = $class_prefix.str_replace($class_prefix, '', $class_name); |
|
867 | 867 | } |
868 | 868 | $class_name = $this->class_cache->getFqnForAlias($class_name); |
869 | 869 | $class_exists = class_exists($class_name, false); |
@@ -883,7 +883,7 @@ discard block |
||
883 | 883 | } |
884 | 884 | } |
885 | 885 | // if the class doesn't already exist.. then we need to try and find the file and load it |
886 | - if (! $class_exists) { |
|
886 | + if ( ! $class_exists) { |
|
887 | 887 | // get full path to file |
888 | 888 | $path = $this->_resolve_path($class_name, $type, $file_paths); |
889 | 889 | // load the file |
@@ -894,7 +894,7 @@ discard block |
||
894 | 894 | return $loaded; |
895 | 895 | } |
896 | 896 | // if an object was expected but loading failed, then return nothing |
897 | - if (! $loaded) { |
|
897 | + if ( ! $loaded) { |
|
898 | 898 | return null; |
899 | 899 | } |
900 | 900 | } |
@@ -922,8 +922,8 @@ discard block |
||
922 | 922 | */ |
923 | 923 | protected function get_class_abbreviation($class_name, $default = 'FANCY_BATMAN_PANTS') |
924 | 924 | { |
925 | - return isset($this->_class_abbreviations[ $class_name ]) |
|
926 | - ? $this->_class_abbreviations[ $class_name ] |
|
925 | + return isset($this->_class_abbreviations[$class_name]) |
|
926 | + ? $this->_class_abbreviations[$class_name] |
|
927 | 927 | : $default; |
928 | 928 | } |
929 | 929 | |
@@ -1056,7 +1056,7 @@ discard block |
||
1056 | 1056 | $this->addons->{$class_name} = $class_obj; |
1057 | 1057 | return; |
1058 | 1058 | } |
1059 | - if (! $from_db) { |
|
1059 | + if ( ! $from_db) { |
|
1060 | 1060 | $class_name = $this->object_identifier->getIdentifier($class_name, $arguments); |
1061 | 1061 | $this->LIB->{$class_name} = $class_obj; |
1062 | 1062 | } |
@@ -1087,13 +1087,13 @@ discard block |
||
1087 | 1087 | : EE_CLASSES; |
1088 | 1088 | // prep file type |
1089 | 1089 | $type = ! empty($type) |
1090 | - ? trim($type, '.') . '.' |
|
1090 | + ? trim($type, '.').'.' |
|
1091 | 1091 | : ''; |
1092 | 1092 | // build full file path |
1093 | - $file_paths[ $key ] = rtrim($file_path, '/') . '/' . $class_name . '.' . $type . 'php'; |
|
1093 | + $file_paths[$key] = rtrim($file_path, '/').'/'.$class_name.'.'.$type.'php'; |
|
1094 | 1094 | // does the file exist and can be read ? |
1095 | - if (is_readable($file_paths[ $key ])) { |
|
1096 | - return $file_paths[ $key ]; |
|
1095 | + if (is_readable($file_paths[$key])) { |
|
1096 | + return $file_paths[$key]; |
|
1097 | 1097 | } |
1098 | 1098 | } |
1099 | 1099 | return false; |
@@ -1118,7 +1118,7 @@ discard block |
||
1118 | 1118 | // don't give up! you gotta... |
1119 | 1119 | try { |
1120 | 1120 | // does the file exist and can it be read ? |
1121 | - if (! $path) { |
|
1121 | + if ( ! $path) { |
|
1122 | 1122 | // just in case the file has already been autoloaded, |
1123 | 1123 | // but discrepancies in the naming schema are preventing it from |
1124 | 1124 | // being loaded via one of the EE_Registry::load_*() methods, |
@@ -1136,7 +1136,7 @@ discard block |
||
1136 | 1136 | ), |
1137 | 1137 | trim($type, '.'), |
1138 | 1138 | $class_name, |
1139 | - '<br />' . implode(',<br />', $file_paths) |
|
1139 | + '<br />'.implode(',<br />', $file_paths) |
|
1140 | 1140 | ) |
1141 | 1141 | ); |
1142 | 1142 | } |
@@ -1179,8 +1179,8 @@ discard block |
||
1179 | 1179 | $legacy_parent_class_map = array( |
1180 | 1180 | 'EE_Payment_Processor' => 'core/business/EE_Processor_Base.class.php', |
1181 | 1181 | ); |
1182 | - if (isset($legacy_parent_class_map[ $class_name ])) { |
|
1183 | - require_once EE_PLUGIN_DIR_PATH . $legacy_parent_class_map[ $class_name ]; |
|
1182 | + if (isset($legacy_parent_class_map[$class_name])) { |
|
1183 | + require_once EE_PLUGIN_DIR_PATH.$legacy_parent_class_map[$class_name]; |
|
1184 | 1184 | } |
1185 | 1185 | } catch (Exception $exception) { |
1186 | 1186 | } |
@@ -1312,7 +1312,7 @@ discard block |
||
1312 | 1312 | // let's examine the constructor |
1313 | 1313 | $constructor = $this->mirror->getConstructorFromReflection($reflector); |
1314 | 1314 | // whu? huh? nothing? |
1315 | - if (! $constructor) { |
|
1315 | + if ( ! $constructor) { |
|
1316 | 1316 | return $arguments; |
1317 | 1317 | } |
1318 | 1318 | // get constructor parameters |
@@ -1341,15 +1341,15 @@ discard block |
||
1341 | 1341 | $param_class === null |
1342 | 1342 | // and something already exists in the incoming arguments for this param |
1343 | 1343 | && array_key_exists($index, $argument_keys) |
1344 | - && array_key_exists($argument_keys[ $index ], $arguments) |
|
1344 | + && array_key_exists($argument_keys[$index], $arguments) |
|
1345 | 1345 | ) { |
1346 | 1346 | // so let's skip this argument and move on to the next |
1347 | 1347 | continue; |
1348 | 1348 | } |
1349 | 1349 | if (// parameter is type hinted as a class, exists as an incoming argument, AND it's the correct class |
1350 | 1350 | $param_class !== null |
1351 | - && isset($argument_keys[ $index ], $arguments[ $argument_keys[ $index ] ]) |
|
1352 | - && $arguments[ $argument_keys[ $index ] ] instanceof $param_class |
|
1351 | + && isset($argument_keys[$index], $arguments[$argument_keys[$index]]) |
|
1352 | + && $arguments[$argument_keys[$index]] instanceof $param_class |
|
1353 | 1353 | ) { |
1354 | 1354 | // skip this argument and move on to the next |
1355 | 1355 | continue; |
@@ -1365,8 +1365,8 @@ discard block |
||
1365 | 1365 | $index |
1366 | 1366 | ); |
1367 | 1367 | } |
1368 | - if (empty($arguments[ $index ])) { |
|
1369 | - $arguments[ $index ] = $this->mirror->getParameterDefaultValue( |
|
1368 | + if (empty($arguments[$index])) { |
|
1369 | + $arguments[$index] = $this->mirror->getParameterDefaultValue( |
|
1370 | 1370 | $param, |
1371 | 1371 | $class_name, |
1372 | 1372 | $index |
@@ -1428,7 +1428,7 @@ discard block |
||
1428 | 1428 | // did we successfully find the correct dependency ? |
1429 | 1429 | if ($dependency instanceof $param_class) { |
1430 | 1430 | // then let's inject it into the incoming array of arguments at the correct location |
1431 | - $arguments[ $index ] = $dependency; |
|
1431 | + $arguments[$index] = $dependency; |
|
1432 | 1432 | } |
1433 | 1433 | return $arguments; |
1434 | 1434 | } |
@@ -1523,7 +1523,7 @@ discard block |
||
1523 | 1523 | { |
1524 | 1524 | $addons = array(); |
1525 | 1525 | foreach ($this->addons as $addon) { |
1526 | - $addons[ $addon->name() ] = $addon; |
|
1526 | + $addons[$addon->name()] = $addon; |
|
1527 | 1527 | } |
1528 | 1528 | return $addons; |
1529 | 1529 | } |
@@ -1542,7 +1542,7 @@ discard block |
||
1542 | 1542 | $model_class_name = strpos($model_name, 'EEM_') !== 0 |
1543 | 1543 | ? "EEM_{$model_name}" |
1544 | 1544 | : $model_name; |
1545 | - if (! isset($this->LIB->{$model_class_name}) || ! $this->LIB->{$model_class_name} instanceof EEM_Base) { |
|
1545 | + if ( ! isset($this->LIB->{$model_class_name}) || ! $this->LIB->{$model_class_name} instanceof EEM_Base) { |
|
1546 | 1546 | return null; |
1547 | 1547 | } |
1548 | 1548 | // get that model reset it and make sure we nuke the old reference to it |
@@ -1634,7 +1634,7 @@ discard block |
||
1634 | 1634 | */ |
1635 | 1635 | private static function _reset_and_unset_object($object, $reset_models) |
1636 | 1636 | { |
1637 | - if (! is_object($object)) { |
|
1637 | + if ( ! is_object($object)) { |
|
1638 | 1638 | // don't unset anything that's not an object |
1639 | 1639 | return false; |
1640 | 1640 | } |
@@ -1654,7 +1654,7 @@ discard block |
||
1654 | 1654 | $object->reset(); |
1655 | 1655 | return true; |
1656 | 1656 | } |
1657 | - if (! $object instanceof InterminableInterface) { |
|
1657 | + if ( ! $object instanceof InterminableInterface) { |
|
1658 | 1658 | return true; |
1659 | 1659 | } |
1660 | 1660 | return false; |
@@ -1671,7 +1671,7 @@ discard block |
||
1671 | 1671 | $cpt_models = array(); |
1672 | 1672 | foreach ($this->non_abstract_db_models as $short_name => $classname) { |
1673 | 1673 | if (is_subclass_of($classname, 'EEM_CPT_Base')) { |
1674 | - $cpt_models[ $short_name ] = $classname; |
|
1674 | + $cpt_models[$short_name] = $classname; |
|
1675 | 1675 | } |
1676 | 1676 | } |
1677 | 1677 | return $cpt_models; |
@@ -45,150 +45,150 @@ |
||
45 | 45 | class Psr4Autoloader |
46 | 46 | { |
47 | 47 | |
48 | - /** |
|
49 | - * namespace separator |
|
50 | - */ |
|
51 | - const NS = '\\'; |
|
52 | - |
|
53 | - /** |
|
54 | - * An associative array where the key is a namespace prefix and the value |
|
55 | - * is an array of base directories for classes in that namespace. |
|
56 | - * |
|
57 | - * @var array |
|
58 | - */ |
|
59 | - protected $prefixes = array(); |
|
60 | - |
|
61 | - |
|
62 | - /** |
|
63 | - * returns an array of registered namespace prefixes |
|
64 | - * |
|
65 | - * @param string $prefix |
|
66 | - * @return array |
|
67 | - */ |
|
68 | - public function prefixes($prefix = '') |
|
69 | - { |
|
70 | - if (! empty($prefix)) { |
|
71 | - // are there any base directories for this namespace prefix? |
|
72 | - return isset($this->prefixes[ $prefix ]) ? $this->prefixes[ $prefix ] : array(); |
|
73 | - } |
|
74 | - return $this->prefixes; |
|
75 | - } |
|
76 | - |
|
77 | - |
|
78 | - /** |
|
79 | - * Register loader with SPL autoloader stack. |
|
80 | - * |
|
81 | - * @return void |
|
82 | - */ |
|
83 | - public function register() |
|
84 | - { |
|
85 | - spl_autoload_register(array($this, 'loadClass')); |
|
86 | - } |
|
87 | - |
|
88 | - |
|
89 | - /** |
|
90 | - * Adds a base directory for a namespace prefix. |
|
91 | - * |
|
92 | - * @param string $prefix The namespace prefix. |
|
93 | - * @param string $base_dir A base directory for class files in the |
|
94 | - * namespace. |
|
95 | - * @param bool $prepend If true, prepend the base directory to the stack |
|
96 | - * instead of appending it; this causes it to be searched first rather |
|
97 | - * than last. |
|
98 | - * @return void |
|
99 | - */ |
|
100 | - public function addNamespace($prefix, $base_dir, $prepend = false) |
|
101 | - { |
|
102 | - // normalize namespace prefix |
|
103 | - $prefix = trim($prefix, Psr4Autoloader::NS) . Psr4Autoloader::NS; |
|
104 | - // normalize the base directory with a trailing separator |
|
105 | - $base_dir = \EEH_File::standardise_and_end_with_directory_separator($base_dir); |
|
106 | - // initialize the namespace prefix array |
|
107 | - if (isset($this->prefixes[ $prefix ]) === false) { |
|
108 | - $this->prefixes[ $prefix ] = array(); |
|
109 | - } |
|
110 | - // retain the base directory for the namespace prefix |
|
111 | - if ($prepend) { |
|
112 | - array_unshift($this->prefixes[ $prefix ], $base_dir); |
|
113 | - } else { |
|
114 | - $this->prefixes[ $prefix ][] = $base_dir; |
|
115 | - } |
|
116 | - } |
|
117 | - |
|
118 | - |
|
119 | - /** |
|
120 | - * Loads the class file for a given class name. |
|
121 | - * |
|
122 | - * @param string $class The fully-qualified class name. |
|
123 | - * @return mixed The mapped file name on success, or boolean false on |
|
124 | - * failure. |
|
125 | - */ |
|
126 | - public function loadClass($class) |
|
127 | - { |
|
128 | - // the current namespace prefix |
|
129 | - $prefix = $class; |
|
130 | - // work backwards through the namespace names of the fully-qualified |
|
131 | - // class name to find a mapped file name |
|
132 | - while (false !== $pos = strrpos($prefix, Psr4Autoloader::NS)) { |
|
133 | - // retain the trailing namespace separator in the prefix |
|
134 | - $prefix = substr($class, 0, $pos + 1); |
|
135 | - // the rest is the relative class name |
|
136 | - $relative_class = substr($class, $pos + 1); |
|
137 | - // try to load a mapped file for the prefix and relative class |
|
138 | - $mapped_file = $this->loadMappedFile($prefix, $relative_class); |
|
139 | - if ($mapped_file) { |
|
140 | - return $mapped_file; |
|
141 | - } |
|
142 | - // remove the trailing namespace separator for the next iteration |
|
143 | - // of strrpos() |
|
144 | - $prefix = rtrim($prefix, Psr4Autoloader::NS); |
|
145 | - } |
|
146 | - // never found a mapped file |
|
147 | - return false; |
|
148 | - } |
|
149 | - |
|
150 | - |
|
151 | - /** |
|
152 | - * Load the mapped file for a namespace prefix and relative class. |
|
153 | - * |
|
154 | - * @param string $prefix The namespace prefix. |
|
155 | - * @param string $relative_class The relative class name. |
|
156 | - * @return mixed Boolean false if no mapped file can be loaded, or the |
|
157 | - * name of the mapped file that was loaded. |
|
158 | - */ |
|
159 | - protected function loadMappedFile($prefix, $relative_class) |
|
160 | - { |
|
161 | - // look through base directories for this namespace prefix |
|
162 | - foreach ($this->prefixes($prefix) as $base_dir) { |
|
163 | - // replace the namespace prefix with the base directory, |
|
164 | - // replace namespace separators with directory separators |
|
165 | - // in the relative class name, append with .php |
|
166 | - $file = $base_dir |
|
167 | - . str_replace(Psr4Autoloader::NS, '/', $relative_class) |
|
168 | - . '.php'; |
|
169 | - // if the mapped file exists, require it |
|
170 | - if ($this->requireFile($file)) { |
|
171 | - // yes, we're done |
|
172 | - return $file; |
|
173 | - } |
|
174 | - } |
|
175 | - // never found it |
|
176 | - return false; |
|
177 | - } |
|
178 | - |
|
179 | - |
|
180 | - /** |
|
181 | - * If a file exists, require it from the file system. |
|
182 | - * |
|
183 | - * @param string $file The file to require. |
|
184 | - * @return bool True if the file exists, false if not. |
|
185 | - */ |
|
186 | - protected function requireFile($file) |
|
187 | - { |
|
188 | - if (file_exists($file)) { |
|
189 | - require $file; |
|
190 | - return true; |
|
191 | - } |
|
192 | - return false; |
|
193 | - } |
|
48 | + /** |
|
49 | + * namespace separator |
|
50 | + */ |
|
51 | + const NS = '\\'; |
|
52 | + |
|
53 | + /** |
|
54 | + * An associative array where the key is a namespace prefix and the value |
|
55 | + * is an array of base directories for classes in that namespace. |
|
56 | + * |
|
57 | + * @var array |
|
58 | + */ |
|
59 | + protected $prefixes = array(); |
|
60 | + |
|
61 | + |
|
62 | + /** |
|
63 | + * returns an array of registered namespace prefixes |
|
64 | + * |
|
65 | + * @param string $prefix |
|
66 | + * @return array |
|
67 | + */ |
|
68 | + public function prefixes($prefix = '') |
|
69 | + { |
|
70 | + if (! empty($prefix)) { |
|
71 | + // are there any base directories for this namespace prefix? |
|
72 | + return isset($this->prefixes[ $prefix ]) ? $this->prefixes[ $prefix ] : array(); |
|
73 | + } |
|
74 | + return $this->prefixes; |
|
75 | + } |
|
76 | + |
|
77 | + |
|
78 | + /** |
|
79 | + * Register loader with SPL autoloader stack. |
|
80 | + * |
|
81 | + * @return void |
|
82 | + */ |
|
83 | + public function register() |
|
84 | + { |
|
85 | + spl_autoload_register(array($this, 'loadClass')); |
|
86 | + } |
|
87 | + |
|
88 | + |
|
89 | + /** |
|
90 | + * Adds a base directory for a namespace prefix. |
|
91 | + * |
|
92 | + * @param string $prefix The namespace prefix. |
|
93 | + * @param string $base_dir A base directory for class files in the |
|
94 | + * namespace. |
|
95 | + * @param bool $prepend If true, prepend the base directory to the stack |
|
96 | + * instead of appending it; this causes it to be searched first rather |
|
97 | + * than last. |
|
98 | + * @return void |
|
99 | + */ |
|
100 | + public function addNamespace($prefix, $base_dir, $prepend = false) |
|
101 | + { |
|
102 | + // normalize namespace prefix |
|
103 | + $prefix = trim($prefix, Psr4Autoloader::NS) . Psr4Autoloader::NS; |
|
104 | + // normalize the base directory with a trailing separator |
|
105 | + $base_dir = \EEH_File::standardise_and_end_with_directory_separator($base_dir); |
|
106 | + // initialize the namespace prefix array |
|
107 | + if (isset($this->prefixes[ $prefix ]) === false) { |
|
108 | + $this->prefixes[ $prefix ] = array(); |
|
109 | + } |
|
110 | + // retain the base directory for the namespace prefix |
|
111 | + if ($prepend) { |
|
112 | + array_unshift($this->prefixes[ $prefix ], $base_dir); |
|
113 | + } else { |
|
114 | + $this->prefixes[ $prefix ][] = $base_dir; |
|
115 | + } |
|
116 | + } |
|
117 | + |
|
118 | + |
|
119 | + /** |
|
120 | + * Loads the class file for a given class name. |
|
121 | + * |
|
122 | + * @param string $class The fully-qualified class name. |
|
123 | + * @return mixed The mapped file name on success, or boolean false on |
|
124 | + * failure. |
|
125 | + */ |
|
126 | + public function loadClass($class) |
|
127 | + { |
|
128 | + // the current namespace prefix |
|
129 | + $prefix = $class; |
|
130 | + // work backwards through the namespace names of the fully-qualified |
|
131 | + // class name to find a mapped file name |
|
132 | + while (false !== $pos = strrpos($prefix, Psr4Autoloader::NS)) { |
|
133 | + // retain the trailing namespace separator in the prefix |
|
134 | + $prefix = substr($class, 0, $pos + 1); |
|
135 | + // the rest is the relative class name |
|
136 | + $relative_class = substr($class, $pos + 1); |
|
137 | + // try to load a mapped file for the prefix and relative class |
|
138 | + $mapped_file = $this->loadMappedFile($prefix, $relative_class); |
|
139 | + if ($mapped_file) { |
|
140 | + return $mapped_file; |
|
141 | + } |
|
142 | + // remove the trailing namespace separator for the next iteration |
|
143 | + // of strrpos() |
|
144 | + $prefix = rtrim($prefix, Psr4Autoloader::NS); |
|
145 | + } |
|
146 | + // never found a mapped file |
|
147 | + return false; |
|
148 | + } |
|
149 | + |
|
150 | + |
|
151 | + /** |
|
152 | + * Load the mapped file for a namespace prefix and relative class. |
|
153 | + * |
|
154 | + * @param string $prefix The namespace prefix. |
|
155 | + * @param string $relative_class The relative class name. |
|
156 | + * @return mixed Boolean false if no mapped file can be loaded, or the |
|
157 | + * name of the mapped file that was loaded. |
|
158 | + */ |
|
159 | + protected function loadMappedFile($prefix, $relative_class) |
|
160 | + { |
|
161 | + // look through base directories for this namespace prefix |
|
162 | + foreach ($this->prefixes($prefix) as $base_dir) { |
|
163 | + // replace the namespace prefix with the base directory, |
|
164 | + // replace namespace separators with directory separators |
|
165 | + // in the relative class name, append with .php |
|
166 | + $file = $base_dir |
|
167 | + . str_replace(Psr4Autoloader::NS, '/', $relative_class) |
|
168 | + . '.php'; |
|
169 | + // if the mapped file exists, require it |
|
170 | + if ($this->requireFile($file)) { |
|
171 | + // yes, we're done |
|
172 | + return $file; |
|
173 | + } |
|
174 | + } |
|
175 | + // never found it |
|
176 | + return false; |
|
177 | + } |
|
178 | + |
|
179 | + |
|
180 | + /** |
|
181 | + * If a file exists, require it from the file system. |
|
182 | + * |
|
183 | + * @param string $file The file to require. |
|
184 | + * @return bool True if the file exists, false if not. |
|
185 | + */ |
|
186 | + protected function requireFile($file) |
|
187 | + { |
|
188 | + if (file_exists($file)) { |
|
189 | + require $file; |
|
190 | + return true; |
|
191 | + } |
|
192 | + return false; |
|
193 | + } |
|
194 | 194 | } |
@@ -27,1313 +27,1313 @@ |
||
27 | 27 | final class EE_System implements ResettableInterface |
28 | 28 | { |
29 | 29 | |
30 | - /** |
|
31 | - * indicates this is a 'normal' request. Ie, not activation, nor upgrade, nor activation. |
|
32 | - * So examples of this would be a normal GET request on the frontend or backend, or a POST, etc |
|
33 | - */ |
|
34 | - const req_type_normal = 0; |
|
35 | - |
|
36 | - /** |
|
37 | - * Indicates this is a brand new installation of EE so we should install |
|
38 | - * tables and default data etc |
|
39 | - */ |
|
40 | - const req_type_new_activation = 1; |
|
41 | - |
|
42 | - /** |
|
43 | - * we've detected that EE has been reactivated (or EE was activated during maintenance mode, |
|
44 | - * and we just exited maintenance mode). We MUST check the database is setup properly |
|
45 | - * and that default data is setup too |
|
46 | - */ |
|
47 | - const req_type_reactivation = 2; |
|
48 | - |
|
49 | - /** |
|
50 | - * indicates that EE has been upgraded since its previous request. |
|
51 | - * We may have data migration scripts to call and will want to trigger maintenance mode |
|
52 | - */ |
|
53 | - const req_type_upgrade = 3; |
|
54 | - |
|
55 | - /** |
|
56 | - * TODO will detect that EE has been DOWNGRADED. We probably don't want to run in this case... |
|
57 | - */ |
|
58 | - const req_type_downgrade = 4; |
|
59 | - |
|
60 | - /** |
|
61 | - * @deprecated since version 4.6.0.dev.006 |
|
62 | - * Now whenever a new_activation is detected the request type is still just |
|
63 | - * new_activation (same for reactivation, upgrade, downgrade etc), but if we'r ein maintenance mode |
|
64 | - * EE_System::initialize_db_if_no_migrations_required and EE_Addon::initialize_db_if_no_migrations_required |
|
65 | - * will instead enqueue that EE plugin's db initialization for when we're taken out of maintenance mode. |
|
66 | - * (Specifically, when the migration manager indicates migrations are finished |
|
67 | - * EE_Data_Migration_Manager::initialize_db_for_enqueued_ee_plugins() will be called) |
|
68 | - */ |
|
69 | - const req_type_activation_but_not_installed = 5; |
|
70 | - |
|
71 | - /** |
|
72 | - * option prefix for recording the activation history (like core's "espresso_db_update") of addons |
|
73 | - */ |
|
74 | - const addon_activation_history_option_prefix = 'ee_addon_activation_history_'; |
|
75 | - |
|
76 | - /** |
|
77 | - * @var EE_System $_instance |
|
78 | - */ |
|
79 | - private static $_instance; |
|
80 | - |
|
81 | - /** |
|
82 | - * @var EE_Registry $registry |
|
83 | - */ |
|
84 | - private $registry; |
|
85 | - |
|
86 | - /** |
|
87 | - * @var LoaderInterface $loader |
|
88 | - */ |
|
89 | - private $loader; |
|
90 | - |
|
91 | - /** |
|
92 | - * @var EE_Capabilities $capabilities |
|
93 | - */ |
|
94 | - private $capabilities; |
|
95 | - |
|
96 | - /** |
|
97 | - * @var RequestInterface $request |
|
98 | - */ |
|
99 | - private $request; |
|
100 | - |
|
101 | - /** |
|
102 | - * @var EE_Maintenance_Mode $maintenance_mode |
|
103 | - */ |
|
104 | - private $maintenance_mode; |
|
105 | - |
|
106 | - /** |
|
107 | - * Stores which type of request this is, options being one of the constants on EE_System starting with req_type_*. |
|
108 | - * It can be a brand-new activation, a reactivation, an upgrade, a downgrade, or a normal request. |
|
109 | - * |
|
110 | - * @var int $_req_type |
|
111 | - */ |
|
112 | - private $_req_type; |
|
113 | - |
|
114 | - /** |
|
115 | - * Whether or not there was a non-micro version change in EE core version during this request |
|
116 | - * |
|
117 | - * @var boolean $_major_version_change |
|
118 | - */ |
|
119 | - private $_major_version_change = false; |
|
120 | - |
|
121 | - /** |
|
122 | - * A Context DTO dedicated solely to identifying the current request type. |
|
123 | - * |
|
124 | - * @var RequestTypeContextCheckerInterface $request_type |
|
125 | - */ |
|
126 | - private $request_type; |
|
127 | - |
|
128 | - |
|
129 | - /** |
|
130 | - * @singleton method used to instantiate class object |
|
131 | - * @param EE_Registry|null $registry |
|
132 | - * @param LoaderInterface|null $loader |
|
133 | - * @param RequestInterface|null $request |
|
134 | - * @param EE_Maintenance_Mode|null $maintenance_mode |
|
135 | - * @return EE_System |
|
136 | - */ |
|
137 | - public static function instance( |
|
138 | - EE_Registry $registry = null, |
|
139 | - LoaderInterface $loader = null, |
|
140 | - RequestInterface $request = null, |
|
141 | - EE_Maintenance_Mode $maintenance_mode = null |
|
142 | - ) { |
|
143 | - // check if class object is instantiated |
|
144 | - if (! self::$_instance instanceof EE_System) { |
|
145 | - self::$_instance = new self($registry, $loader, $request, $maintenance_mode); |
|
146 | - } |
|
147 | - return self::$_instance; |
|
148 | - } |
|
149 | - |
|
150 | - |
|
151 | - /** |
|
152 | - * resets the instance and returns it |
|
153 | - * |
|
154 | - * @return EE_System |
|
155 | - */ |
|
156 | - public static function reset() |
|
157 | - { |
|
158 | - self::$_instance->_req_type = null; |
|
159 | - // make sure none of the old hooks are left hanging around |
|
160 | - remove_all_actions('AHEE__EE_System__perform_activations_upgrades_and_migrations'); |
|
161 | - // we need to reset the migration manager in order for it to detect DMSs properly |
|
162 | - EE_Data_Migration_Manager::reset(); |
|
163 | - self::instance()->detect_activations_or_upgrades(); |
|
164 | - self::instance()->perform_activations_upgrades_and_migrations(); |
|
165 | - return self::instance(); |
|
166 | - } |
|
167 | - |
|
168 | - |
|
169 | - /** |
|
170 | - * sets hooks for running rest of system |
|
171 | - * provides "AHEE__EE_System__construct__complete" hook for EE Addons to use as their starting point |
|
172 | - * starting EE Addons from any other point may lead to problems |
|
173 | - * |
|
174 | - * @param EE_Registry $registry |
|
175 | - * @param LoaderInterface $loader |
|
176 | - * @param RequestInterface $request |
|
177 | - * @param EE_Maintenance_Mode $maintenance_mode |
|
178 | - */ |
|
179 | - private function __construct( |
|
180 | - EE_Registry $registry, |
|
181 | - LoaderInterface $loader, |
|
182 | - RequestInterface $request, |
|
183 | - EE_Maintenance_Mode $maintenance_mode |
|
184 | - ) { |
|
185 | - $this->registry = $registry; |
|
186 | - $this->loader = $loader; |
|
187 | - $this->request = $request; |
|
188 | - $this->maintenance_mode = $maintenance_mode; |
|
189 | - do_action('AHEE__EE_System__construct__begin', $this); |
|
190 | - add_action( |
|
191 | - 'AHEE__EE_Bootstrap__load_espresso_addons', |
|
192 | - array($this, 'loadCapabilities'), |
|
193 | - 5 |
|
194 | - ); |
|
195 | - add_action( |
|
196 | - 'AHEE__EE_Bootstrap__load_espresso_addons', |
|
197 | - array($this, 'loadCommandBus'), |
|
198 | - 7 |
|
199 | - ); |
|
200 | - add_action( |
|
201 | - 'AHEE__EE_Bootstrap__load_espresso_addons', |
|
202 | - array($this, 'loadPluginApi'), |
|
203 | - 9 |
|
204 | - ); |
|
205 | - // allow addons to load first so that they can register autoloaders, set hooks for running DMS's, etc |
|
206 | - add_action( |
|
207 | - 'AHEE__EE_Bootstrap__load_espresso_addons', |
|
208 | - array($this, 'load_espresso_addons') |
|
209 | - ); |
|
210 | - // when an ee addon is activated, we want to call the core hook(s) again |
|
211 | - // because the newly-activated addon didn't get a chance to run at all |
|
212 | - add_action('activate_plugin', array($this, 'load_espresso_addons'), 1); |
|
213 | - // detect whether install or upgrade |
|
214 | - add_action( |
|
215 | - 'AHEE__EE_Bootstrap__detect_activations_or_upgrades', |
|
216 | - array($this, 'detect_activations_or_upgrades'), |
|
217 | - 3 |
|
218 | - ); |
|
219 | - // load EE_Config, EE_Textdomain, etc |
|
220 | - add_action( |
|
221 | - 'AHEE__EE_Bootstrap__load_core_configuration', |
|
222 | - array($this, 'load_core_configuration'), |
|
223 | - 5 |
|
224 | - ); |
|
225 | - // load specifications for matching routes to current request |
|
226 | - add_action( |
|
227 | - 'AHEE__EE_Bootstrap__load_core_configuration', |
|
228 | - array($this, 'loadRouteMatchSpecifications') |
|
229 | - ); |
|
230 | - // load EE_Config, EE_Textdomain, etc |
|
231 | - add_action( |
|
232 | - 'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets', |
|
233 | - array($this, 'register_shortcodes_modules_and_widgets'), |
|
234 | - 7 |
|
235 | - ); |
|
236 | - // you wanna get going? I wanna get going... let's get going! |
|
237 | - add_action( |
|
238 | - 'AHEE__EE_Bootstrap__brew_espresso', |
|
239 | - array($this, 'brew_espresso'), |
|
240 | - 9 |
|
241 | - ); |
|
242 | - // other housekeeping |
|
243 | - // exclude EE critical pages from wp_list_pages |
|
244 | - add_filter( |
|
245 | - 'wp_list_pages_excludes', |
|
246 | - array($this, 'remove_pages_from_wp_list_pages'), |
|
247 | - 10 |
|
248 | - ); |
|
249 | - // ALL EE Addons should use the following hook point to attach their initial setup too |
|
250 | - // it's extremely important for EE Addons to register any class autoloaders so that they can be available when the EE_Config loads |
|
251 | - do_action('AHEE__EE_System__construct__complete', $this); |
|
252 | - } |
|
253 | - |
|
254 | - |
|
255 | - /** |
|
256 | - * load and setup EE_Capabilities |
|
257 | - * |
|
258 | - * @return void |
|
259 | - * @throws EE_Error |
|
260 | - */ |
|
261 | - public function loadCapabilities() |
|
262 | - { |
|
263 | - $this->capabilities = $this->loader->getShared('EE_Capabilities'); |
|
264 | - add_action( |
|
265 | - 'AHEE__EE_Capabilities__init_caps__before_initialization', |
|
266 | - function () { |
|
267 | - LoaderFactory::getLoader()->getShared('EE_Payment_Method_Manager'); |
|
268 | - } |
|
269 | - ); |
|
270 | - } |
|
271 | - |
|
272 | - |
|
273 | - /** |
|
274 | - * create and cache the CommandBus, and also add middleware |
|
275 | - * The CapChecker middleware requires the use of EE_Capabilities |
|
276 | - * which is why we need to load the CommandBus after Caps are set up |
|
277 | - * |
|
278 | - * @return void |
|
279 | - * @throws EE_Error |
|
280 | - */ |
|
281 | - public function loadCommandBus() |
|
282 | - { |
|
283 | - $this->loader->getShared( |
|
284 | - 'CommandBusInterface', |
|
285 | - array( |
|
286 | - null, |
|
287 | - apply_filters( |
|
288 | - 'FHEE__EE_Load_Espresso_Core__handle_request__CommandBus_middleware', |
|
289 | - array( |
|
290 | - $this->loader->getShared('EventEspresso\core\services\commands\middleware\CapChecker'), |
|
291 | - $this->loader->getShared('EventEspresso\core\services\commands\middleware\AddActionHook'), |
|
292 | - ) |
|
293 | - ), |
|
294 | - ) |
|
295 | - ); |
|
296 | - } |
|
297 | - |
|
298 | - |
|
299 | - /** |
|
300 | - * @return void |
|
301 | - * @throws EE_Error |
|
302 | - */ |
|
303 | - public function loadPluginApi() |
|
304 | - { |
|
305 | - // set autoloaders for all of the classes implementing EEI_Plugin_API |
|
306 | - // which provide helpers for EE plugin authors to more easily register certain components with EE. |
|
307 | - EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'plugin_api'); |
|
308 | - $this->loader->getShared('EE_Request_Handler'); |
|
309 | - } |
|
310 | - |
|
311 | - |
|
312 | - /** |
|
313 | - * @param string $addon_name |
|
314 | - * @param string $version_constant |
|
315 | - * @param string $min_version_required |
|
316 | - * @param string $load_callback |
|
317 | - * @param string $plugin_file_constant |
|
318 | - * @return void |
|
319 | - */ |
|
320 | - private function deactivateIncompatibleAddon( |
|
321 | - $addon_name, |
|
322 | - $version_constant, |
|
323 | - $min_version_required, |
|
324 | - $load_callback, |
|
325 | - $plugin_file_constant |
|
326 | - ) { |
|
327 | - if (! defined($version_constant)) { |
|
328 | - return; |
|
329 | - } |
|
330 | - $addon_version = constant($version_constant); |
|
331 | - if ($addon_version && version_compare($addon_version, $min_version_required, '<')) { |
|
332 | - remove_action('AHEE__EE_System__load_espresso_addons', $load_callback); |
|
333 | - if (! function_exists('deactivate_plugins')) { |
|
334 | - require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
335 | - } |
|
336 | - deactivate_plugins(plugin_basename(constant($plugin_file_constant))); |
|
337 | - unset($_GET['activate'], $_REQUEST['activate'], $_GET['activate-multi'], $_REQUEST['activate-multi']); |
|
338 | - EE_Error::add_error( |
|
339 | - sprintf( |
|
340 | - esc_html__( |
|
341 | - 'We\'re sorry, but the Event Espresso %1$s addon was deactivated because version %2$s or higher is required with this version of Event Espresso core.', |
|
342 | - 'event_espresso' |
|
343 | - ), |
|
344 | - $addon_name, |
|
345 | - $min_version_required |
|
346 | - ), |
|
347 | - __FILE__, |
|
348 | - __FUNCTION__ . "({$addon_name})", |
|
349 | - __LINE__ |
|
350 | - ); |
|
351 | - EE_Error::get_notices(false, true); |
|
352 | - } |
|
353 | - } |
|
354 | - |
|
355 | - |
|
356 | - /** |
|
357 | - * load_espresso_addons |
|
358 | - * allow addons to load first so that they can set hooks for running DMS's, etc |
|
359 | - * this is hooked into both: |
|
360 | - * 'AHEE__EE_Bootstrap__load_core_configuration' |
|
361 | - * which runs during the WP 'plugins_loaded' action at priority 5 |
|
362 | - * and the WP 'activate_plugin' hook point |
|
363 | - * |
|
364 | - * @access public |
|
365 | - * @return void |
|
366 | - */ |
|
367 | - public function load_espresso_addons() |
|
368 | - { |
|
369 | - $this->deactivateIncompatibleAddon( |
|
370 | - 'Wait Lists', |
|
371 | - 'EE_WAIT_LISTS_VERSION', |
|
372 | - '1.0.0.beta.074', |
|
373 | - 'load_espresso_wait_lists', |
|
374 | - 'EE_WAIT_LISTS_PLUGIN_FILE' |
|
375 | - ); |
|
376 | - $this->deactivateIncompatibleAddon( |
|
377 | - 'Automated Upcoming Event Notifications', |
|
378 | - 'EE_AUTOMATED_UPCOMING_EVENT_NOTIFICATION_VERSION', |
|
379 | - '1.0.0.beta.091', |
|
380 | - 'load_espresso_automated_upcoming_event_notification', |
|
381 | - 'EE_AUTOMATED_UPCOMING_EVENT_NOTIFICATION_PLUGIN_FILE' |
|
382 | - ); |
|
383 | - do_action('AHEE__EE_System__load_espresso_addons'); |
|
384 | - // if the WP API basic auth plugin isn't already loaded, load it now. |
|
385 | - // We want it for mobile apps. Just include the entire plugin |
|
386 | - // also, don't load the basic auth when a plugin is getting activated, because |
|
387 | - // it could be the basic auth plugin, and it doesn't check if its methods are already defined |
|
388 | - // and causes a fatal error |
|
389 | - if (($this->request->isWordPressApi() || $this->request->isApi()) |
|
390 | - && $this->request->getRequestParam('activate') !== 'true' |
|
391 | - && ! function_exists('json_basic_auth_handler') |
|
392 | - && ! function_exists('json_basic_auth_error') |
|
393 | - && ! in_array( |
|
394 | - $this->request->getRequestParam('action'), |
|
395 | - array('activate', 'activate-selected'), |
|
396 | - true |
|
397 | - ) |
|
398 | - ) { |
|
399 | - include_once EE_THIRD_PARTY . 'wp-api-basic-auth/basic-auth.php'; |
|
400 | - } |
|
401 | - do_action('AHEE__EE_System__load_espresso_addons__complete'); |
|
402 | - } |
|
403 | - |
|
404 | - |
|
405 | - /** |
|
406 | - * detect_activations_or_upgrades |
|
407 | - * Checks for activation or upgrade of core first; |
|
408 | - * then also checks if any registered addons have been activated or upgraded |
|
409 | - * This is hooked into 'AHEE__EE_Bootstrap__detect_activations_or_upgrades' |
|
410 | - * which runs during the WP 'plugins_loaded' action at priority 3 |
|
411 | - * |
|
412 | - * @access public |
|
413 | - * @return void |
|
414 | - */ |
|
415 | - public function detect_activations_or_upgrades() |
|
416 | - { |
|
417 | - // first off: let's make sure to handle core |
|
418 | - $this->detect_if_activation_or_upgrade(); |
|
419 | - foreach ($this->registry->addons as $addon) { |
|
420 | - if ($addon instanceof EE_Addon) { |
|
421 | - // detect teh request type for that addon |
|
422 | - $addon->detect_activation_or_upgrade(); |
|
423 | - } |
|
424 | - } |
|
425 | - } |
|
426 | - |
|
427 | - |
|
428 | - /** |
|
429 | - * detect_if_activation_or_upgrade |
|
430 | - * Takes care of detecting whether this is a brand new install or code upgrade, |
|
431 | - * and either setting up the DB or setting up maintenance mode etc. |
|
432 | - * |
|
433 | - * @access public |
|
434 | - * @return void |
|
435 | - */ |
|
436 | - public function detect_if_activation_or_upgrade() |
|
437 | - { |
|
438 | - do_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin'); |
|
439 | - // check if db has been updated, or if its a brand-new installation |
|
440 | - $espresso_db_update = $this->fix_espresso_db_upgrade_option(); |
|
441 | - $request_type = $this->detect_req_type($espresso_db_update); |
|
442 | - // EEH_Debug_Tools::printr( $request_type, '$request_type', __FILE__, __LINE__ ); |
|
443 | - switch ($request_type) { |
|
444 | - case EE_System::req_type_new_activation: |
|
445 | - do_action('AHEE__EE_System__detect_if_activation_or_upgrade__new_activation'); |
|
446 | - $this->_handle_core_version_change($espresso_db_update); |
|
447 | - break; |
|
448 | - case EE_System::req_type_reactivation: |
|
449 | - do_action('AHEE__EE_System__detect_if_activation_or_upgrade__reactivation'); |
|
450 | - $this->_handle_core_version_change($espresso_db_update); |
|
451 | - break; |
|
452 | - case EE_System::req_type_upgrade: |
|
453 | - do_action('AHEE__EE_System__detect_if_activation_or_upgrade__upgrade'); |
|
454 | - // migrations may be required now that we've upgraded |
|
455 | - $this->maintenance_mode->set_maintenance_mode_if_db_old(); |
|
456 | - $this->_handle_core_version_change($espresso_db_update); |
|
457 | - break; |
|
458 | - case EE_System::req_type_downgrade: |
|
459 | - do_action('AHEE__EE_System__detect_if_activation_or_upgrade__downgrade'); |
|
460 | - // its possible migrations are no longer required |
|
461 | - $this->maintenance_mode->set_maintenance_mode_if_db_old(); |
|
462 | - $this->_handle_core_version_change($espresso_db_update); |
|
463 | - break; |
|
464 | - case EE_System::req_type_normal: |
|
465 | - default: |
|
466 | - break; |
|
467 | - } |
|
468 | - do_action('AHEE__EE_System__detect_if_activation_or_upgrade__complete'); |
|
469 | - } |
|
470 | - |
|
471 | - |
|
472 | - /** |
|
473 | - * Updates the list of installed versions and sets hooks for |
|
474 | - * initializing the database later during the request |
|
475 | - * |
|
476 | - * @param array $espresso_db_update |
|
477 | - */ |
|
478 | - private function _handle_core_version_change($espresso_db_update) |
|
479 | - { |
|
480 | - $this->update_list_of_installed_versions($espresso_db_update); |
|
481 | - // get ready to verify the DB is ok (provided we aren't in maintenance mode, of course) |
|
482 | - add_action( |
|
483 | - 'AHEE__EE_System__perform_activations_upgrades_and_migrations', |
|
484 | - array($this, 'initialize_db_if_no_migrations_required') |
|
485 | - ); |
|
486 | - } |
|
487 | - |
|
488 | - |
|
489 | - /** |
|
490 | - * standardizes the wp option 'espresso_db_upgrade' which actually stores |
|
491 | - * information about what versions of EE have been installed and activated, |
|
492 | - * NOT necessarily the state of the database |
|
493 | - * |
|
494 | - * @param mixed $espresso_db_update the value of the WordPress option. |
|
495 | - * If not supplied, fetches it from the options table |
|
496 | - * @return array the correct value of 'espresso_db_upgrade', after saving it, if it needed correction |
|
497 | - */ |
|
498 | - private function fix_espresso_db_upgrade_option($espresso_db_update = null) |
|
499 | - { |
|
500 | - do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__begin', $espresso_db_update); |
|
501 | - if (! $espresso_db_update) { |
|
502 | - $espresso_db_update = get_option('espresso_db_update'); |
|
503 | - } |
|
504 | - // check that option is an array |
|
505 | - if (! is_array($espresso_db_update)) { |
|
506 | - // if option is FALSE, then it never existed |
|
507 | - if ($espresso_db_update === false) { |
|
508 | - // make $espresso_db_update an array and save option with autoload OFF |
|
509 | - $espresso_db_update = array(); |
|
510 | - add_option('espresso_db_update', $espresso_db_update, '', 'no'); |
|
511 | - } else { |
|
512 | - // option is NOT FALSE but also is NOT an array, so make it an array and save it |
|
513 | - $espresso_db_update = array($espresso_db_update => array()); |
|
514 | - update_option('espresso_db_update', $espresso_db_update); |
|
515 | - } |
|
516 | - } else { |
|
517 | - $corrected_db_update = array(); |
|
518 | - // if IS an array, but is it an array where KEYS are version numbers, and values are arrays? |
|
519 | - foreach ($espresso_db_update as $should_be_version_string => $should_be_array) { |
|
520 | - if (is_int($should_be_version_string) && ! is_array($should_be_array)) { |
|
521 | - // the key is an int, and the value IS NOT an array |
|
522 | - // so it must be numerically-indexed, where values are versions installed... |
|
523 | - // fix it! |
|
524 | - $version_string = $should_be_array; |
|
525 | - $corrected_db_update[ $version_string ] = array('unknown-date'); |
|
526 | - } else { |
|
527 | - // ok it checks out |
|
528 | - $corrected_db_update[ $should_be_version_string ] = $should_be_array; |
|
529 | - } |
|
530 | - } |
|
531 | - $espresso_db_update = $corrected_db_update; |
|
532 | - update_option('espresso_db_update', $espresso_db_update); |
|
533 | - } |
|
534 | - do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__complete', $espresso_db_update); |
|
535 | - return $espresso_db_update; |
|
536 | - } |
|
537 | - |
|
538 | - |
|
539 | - /** |
|
540 | - * Does the traditional work of setting up the plugin's database and adding default data. |
|
541 | - * If migration script/process did not exist, this is what would happen on every activation/reactivation/upgrade. |
|
542 | - * NOTE: if we're in maintenance mode (which would be the case if we detect there are data |
|
543 | - * migration scripts that need to be run and a version change happens), enqueues core for database initialization, |
|
544 | - * so that it will be done when migrations are finished |
|
545 | - * |
|
546 | - * @param boolean $initialize_addons_too if true, we double-check addons' database tables etc too; |
|
547 | - * @param boolean $verify_schema if true will re-check the database tables have the correct schema. |
|
548 | - * This is a resource-intensive job |
|
549 | - * so we prefer to only do it when necessary |
|
550 | - * @return void |
|
551 | - * @throws EE_Error |
|
552 | - */ |
|
553 | - public function initialize_db_if_no_migrations_required($initialize_addons_too = false, $verify_schema = true) |
|
554 | - { |
|
555 | - $request_type = $this->detect_req_type(); |
|
556 | - // only initialize system if we're not in maintenance mode. |
|
557 | - if ($this->maintenance_mode->level() !== EE_Maintenance_Mode::level_2_complete_maintenance) { |
|
558 | - /** @var EventEspresso\core\domain\services\custom_post_types\RewriteRules $rewrite_rules */ |
|
559 | - $rewrite_rules = $this->loader->getShared( |
|
560 | - 'EventEspresso\core\domain\services\custom_post_types\RewriteRules' |
|
561 | - ); |
|
562 | - $rewrite_rules->flush(); |
|
563 | - if ($verify_schema) { |
|
564 | - EEH_Activation::initialize_db_and_folders(); |
|
565 | - } |
|
566 | - EEH_Activation::initialize_db_content(); |
|
567 | - EEH_Activation::system_initialization(); |
|
568 | - if ($initialize_addons_too) { |
|
569 | - $this->initialize_addons(); |
|
570 | - } |
|
571 | - } else { |
|
572 | - EE_Data_Migration_Manager::instance()->enqueue_db_initialization_for('Core'); |
|
573 | - } |
|
574 | - if ($request_type === EE_System::req_type_new_activation |
|
575 | - || $request_type === EE_System::req_type_reactivation |
|
576 | - || ( |
|
577 | - $request_type === EE_System::req_type_upgrade |
|
578 | - && $this->is_major_version_change() |
|
579 | - ) |
|
580 | - ) { |
|
581 | - add_action('AHEE__EE_System__initialize_last', array($this, 'redirect_to_about_ee'), 9); |
|
582 | - } |
|
583 | - } |
|
584 | - |
|
585 | - |
|
586 | - /** |
|
587 | - * Initializes the db for all registered addons |
|
588 | - * |
|
589 | - * @throws EE_Error |
|
590 | - */ |
|
591 | - public function initialize_addons() |
|
592 | - { |
|
593 | - // foreach registered addon, make sure its db is up-to-date too |
|
594 | - foreach ($this->registry->addons as $addon) { |
|
595 | - if ($addon instanceof EE_Addon) { |
|
596 | - $addon->initialize_db_if_no_migrations_required(); |
|
597 | - } |
|
598 | - } |
|
599 | - } |
|
600 | - |
|
601 | - |
|
602 | - /** |
|
603 | - * Adds the current code version to the saved wp option which stores a list of all ee versions ever installed. |
|
604 | - * |
|
605 | - * @param array $version_history |
|
606 | - * @param string $current_version_to_add version to be added to the version history |
|
607 | - * @return boolean success as to whether or not this option was changed |
|
608 | - */ |
|
609 | - public function update_list_of_installed_versions($version_history = null, $current_version_to_add = null) |
|
610 | - { |
|
611 | - if (! $version_history) { |
|
612 | - $version_history = $this->fix_espresso_db_upgrade_option($version_history); |
|
613 | - } |
|
614 | - if ($current_version_to_add === null) { |
|
615 | - $current_version_to_add = espresso_version(); |
|
616 | - } |
|
617 | - $version_history[ $current_version_to_add ][] = date('Y-m-d H:i:s', time()); |
|
618 | - // re-save |
|
619 | - return update_option('espresso_db_update', $version_history); |
|
620 | - } |
|
621 | - |
|
622 | - |
|
623 | - /** |
|
624 | - * Detects if the current version indicated in the has existed in the list of |
|
625 | - * previously-installed versions of EE (espresso_db_update). Does NOT modify it (ie, no side-effect) |
|
626 | - * |
|
627 | - * @param array $espresso_db_update array from the wp option stored under the name 'espresso_db_update'. |
|
628 | - * If not supplied, fetches it from the options table. |
|
629 | - * Also, caches its result so later parts of the code can also know whether |
|
630 | - * there's been an update or not. This way we can add the current version to |
|
631 | - * espresso_db_update, but still know if this is a new install or not |
|
632 | - * @return int one of the constants on EE_System::req_type_ |
|
633 | - */ |
|
634 | - public function detect_req_type($espresso_db_update = null) |
|
635 | - { |
|
636 | - if ($this->_req_type === null) { |
|
637 | - $espresso_db_update = ! empty($espresso_db_update) |
|
638 | - ? $espresso_db_update |
|
639 | - : $this->fix_espresso_db_upgrade_option(); |
|
640 | - $this->_req_type = EE_System::detect_req_type_given_activation_history( |
|
641 | - $espresso_db_update, |
|
642 | - 'ee_espresso_activation', |
|
643 | - espresso_version() |
|
644 | - ); |
|
645 | - $this->_major_version_change = $this->_detect_major_version_change($espresso_db_update); |
|
646 | - $this->request->setIsActivation($this->_req_type !== EE_System::req_type_normal); |
|
647 | - } |
|
648 | - return $this->_req_type; |
|
649 | - } |
|
650 | - |
|
651 | - |
|
652 | - /** |
|
653 | - * Returns whether or not there was a non-micro version change (ie, change in either |
|
654 | - * the first or second number in the version. Eg 4.9.0.rc.001 to 4.10.0.rc.000, |
|
655 | - * but not 4.9.0.rc.0001 to 4.9.1.rc.0001 |
|
656 | - * |
|
657 | - * @param $activation_history |
|
658 | - * @return bool |
|
659 | - */ |
|
660 | - private function _detect_major_version_change($activation_history) |
|
661 | - { |
|
662 | - $previous_version = EE_System::_get_most_recently_active_version_from_activation_history($activation_history); |
|
663 | - $previous_version_parts = explode('.', $previous_version); |
|
664 | - $current_version_parts = explode('.', espresso_version()); |
|
665 | - return isset($previous_version_parts[0], $previous_version_parts[1], $current_version_parts[0], $current_version_parts[1]) |
|
666 | - && ($previous_version_parts[0] !== $current_version_parts[0] |
|
667 | - || $previous_version_parts[1] !== $current_version_parts[1] |
|
668 | - ); |
|
669 | - } |
|
670 | - |
|
671 | - |
|
672 | - /** |
|
673 | - * Returns true if either the major or minor version of EE changed during this request. |
|
674 | - * Eg 4.9.0.rc.001 to 4.10.0.rc.000, but not 4.9.0.rc.0001 to 4.9.1.rc.0001 |
|
675 | - * |
|
676 | - * @return bool |
|
677 | - */ |
|
678 | - public function is_major_version_change() |
|
679 | - { |
|
680 | - return $this->_major_version_change; |
|
681 | - } |
|
682 | - |
|
683 | - |
|
684 | - /** |
|
685 | - * Determines the request type for any ee addon, given three piece of info: the current array of activation |
|
686 | - * histories (for core that' 'espresso_db_update' wp option); the name of the WordPress option which is temporarily |
|
687 | - * set upon activation of the plugin (for core it's 'ee_espresso_activation'); and the version that this plugin was |
|
688 | - * just activated to (for core that will always be espresso_version()) |
|
689 | - * |
|
690 | - * @param array $activation_history_for_addon the option's value which stores the activation history for this |
|
691 | - * ee plugin. for core that's 'espresso_db_update' |
|
692 | - * @param string $activation_indicator_option_name the name of the WordPress option that is temporarily set to |
|
693 | - * indicate that this plugin was just activated |
|
694 | - * @param string $version_to_upgrade_to the version that was just upgraded to (for core that will be |
|
695 | - * espresso_version()) |
|
696 | - * @return int one of the constants on EE_System::req_type_* |
|
697 | - */ |
|
698 | - public static function detect_req_type_given_activation_history( |
|
699 | - $activation_history_for_addon, |
|
700 | - $activation_indicator_option_name, |
|
701 | - $version_to_upgrade_to |
|
702 | - ) { |
|
703 | - $version_is_higher = self::_new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to); |
|
704 | - if ($activation_history_for_addon) { |
|
705 | - // it exists, so this isn't a completely new install |
|
706 | - // check if this version already in that list of previously installed versions |
|
707 | - if (! isset($activation_history_for_addon[ $version_to_upgrade_to ])) { |
|
708 | - // it a version we haven't seen before |
|
709 | - if ($version_is_higher === 1) { |
|
710 | - $req_type = EE_System::req_type_upgrade; |
|
711 | - } else { |
|
712 | - $req_type = EE_System::req_type_downgrade; |
|
713 | - } |
|
714 | - delete_option($activation_indicator_option_name); |
|
715 | - } else { |
|
716 | - // its not an update. maybe a reactivation? |
|
717 | - if (get_option($activation_indicator_option_name, false)) { |
|
718 | - if ($version_is_higher === -1) { |
|
719 | - $req_type = EE_System::req_type_downgrade; |
|
720 | - } elseif ($version_is_higher === 0) { |
|
721 | - // we've seen this version before, but it's an activation. must be a reactivation |
|
722 | - $req_type = EE_System::req_type_reactivation; |
|
723 | - } else {// $version_is_higher === 1 |
|
724 | - $req_type = EE_System::req_type_upgrade; |
|
725 | - } |
|
726 | - delete_option($activation_indicator_option_name); |
|
727 | - } else { |
|
728 | - // we've seen this version before and the activation indicate doesn't show it was just activated |
|
729 | - if ($version_is_higher === -1) { |
|
730 | - $req_type = EE_System::req_type_downgrade; |
|
731 | - } elseif ($version_is_higher === 0) { |
|
732 | - // we've seen this version before and it's not an activation. its normal request |
|
733 | - $req_type = EE_System::req_type_normal; |
|
734 | - } else {// $version_is_higher === 1 |
|
735 | - $req_type = EE_System::req_type_upgrade; |
|
736 | - } |
|
737 | - } |
|
738 | - } |
|
739 | - } else { |
|
740 | - // brand new install |
|
741 | - $req_type = EE_System::req_type_new_activation; |
|
742 | - delete_option($activation_indicator_option_name); |
|
743 | - } |
|
744 | - return $req_type; |
|
745 | - } |
|
746 | - |
|
747 | - |
|
748 | - /** |
|
749 | - * Detects if the $version_to_upgrade_to is higher than the most recent version in |
|
750 | - * the $activation_history_for_addon |
|
751 | - * |
|
752 | - * @param array $activation_history_for_addon (keys are versions, values are arrays of times activated, |
|
753 | - * sometimes containing 'unknown-date' |
|
754 | - * @param string $version_to_upgrade_to (current version) |
|
755 | - * @return int results of version_compare( $version_to_upgrade_to, $most_recently_active_version ). |
|
756 | - * ie, -1 if $version_to_upgrade_to is LOWER (downgrade); |
|
757 | - * 0 if $version_to_upgrade_to MATCHES (reactivation or normal request); |
|
758 | - * 1 if $version_to_upgrade_to is HIGHER (upgrade) ; |
|
759 | - */ |
|
760 | - private static function _new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to) |
|
761 | - { |
|
762 | - // find the most recently-activated version |
|
763 | - $most_recently_active_version = |
|
764 | - EE_System::_get_most_recently_active_version_from_activation_history($activation_history_for_addon); |
|
765 | - return version_compare($version_to_upgrade_to, $most_recently_active_version); |
|
766 | - } |
|
767 | - |
|
768 | - |
|
769 | - /** |
|
770 | - * Gets the most recently active version listed in the activation history, |
|
771 | - * and if none are found (ie, it's a brand new install) returns '0.0.0.dev.000'. |
|
772 | - * |
|
773 | - * @param array $activation_history (keys are versions, values are arrays of times activated, |
|
774 | - * sometimes containing 'unknown-date' |
|
775 | - * @return string |
|
776 | - */ |
|
777 | - private static function _get_most_recently_active_version_from_activation_history($activation_history) |
|
778 | - { |
|
779 | - $most_recently_active_version_activation = '1970-01-01 00:00:00'; |
|
780 | - $most_recently_active_version = '0.0.0.dev.000'; |
|
781 | - if (is_array($activation_history)) { |
|
782 | - foreach ($activation_history as $version => $times_activated) { |
|
783 | - // check there is a record of when this version was activated. Otherwise, |
|
784 | - // mark it as unknown |
|
785 | - if (! $times_activated) { |
|
786 | - $times_activated = array('unknown-date'); |
|
787 | - } |
|
788 | - if (is_string($times_activated)) { |
|
789 | - $times_activated = array($times_activated); |
|
790 | - } |
|
791 | - foreach ($times_activated as $an_activation) { |
|
792 | - if ($an_activation !== 'unknown-date' |
|
793 | - && $an_activation |
|
794 | - > $most_recently_active_version_activation) { |
|
795 | - $most_recently_active_version = $version; |
|
796 | - $most_recently_active_version_activation = $an_activation === 'unknown-date' |
|
797 | - ? '1970-01-01 00:00:00' |
|
798 | - : $an_activation; |
|
799 | - } |
|
800 | - } |
|
801 | - } |
|
802 | - } |
|
803 | - return $most_recently_active_version; |
|
804 | - } |
|
805 | - |
|
806 | - |
|
807 | - /** |
|
808 | - * This redirects to the about EE page after activation |
|
809 | - * |
|
810 | - * @return void |
|
811 | - */ |
|
812 | - public function redirect_to_about_ee() |
|
813 | - { |
|
814 | - $notices = EE_Error::get_notices(false); |
|
815 | - // if current user is an admin and it's not an ajax or rest request |
|
816 | - if (! isset($notices['errors']) |
|
817 | - && $this->request->isAdmin() |
|
818 | - && apply_filters( |
|
819 | - 'FHEE__EE_System__redirect_to_about_ee__do_redirect', |
|
820 | - $this->capabilities->current_user_can('manage_options', 'espresso_about_default') |
|
821 | - ) |
|
822 | - ) { |
|
823 | - $query_params = array('page' => 'espresso_about'); |
|
824 | - if (EE_System::instance()->detect_req_type() === EE_System::req_type_new_activation) { |
|
825 | - $query_params['new_activation'] = true; |
|
826 | - } |
|
827 | - if (EE_System::instance()->detect_req_type() === EE_System::req_type_reactivation) { |
|
828 | - $query_params['reactivation'] = true; |
|
829 | - } |
|
830 | - $url = add_query_arg($query_params, admin_url('admin.php')); |
|
831 | - wp_safe_redirect($url); |
|
832 | - exit(); |
|
833 | - } |
|
834 | - } |
|
835 | - |
|
836 | - |
|
837 | - /** |
|
838 | - * load_core_configuration |
|
839 | - * this is hooked into 'AHEE__EE_Bootstrap__load_core_configuration' |
|
840 | - * which runs during the WP 'plugins_loaded' action at priority 5 |
|
841 | - * |
|
842 | - * @return void |
|
843 | - * @throws ReflectionException |
|
844 | - * @throws Exception |
|
845 | - */ |
|
846 | - public function load_core_configuration() |
|
847 | - { |
|
848 | - do_action('AHEE__EE_System__load_core_configuration__begin', $this); |
|
849 | - $this->loader->getShared('EE_Load_Textdomain'); |
|
850 | - // load textdomain |
|
851 | - EE_Load_Textdomain::load_textdomain(); |
|
852 | - // load caf stuff a chance to play during the activation process too. |
|
853 | - $this->_maybe_brew_regular(); |
|
854 | - // load and setup EE_Config and EE_Network_Config |
|
855 | - $config = $this->loader->getShared('EE_Config'); |
|
856 | - $this->loader->getShared('EE_Network_Config'); |
|
857 | - // setup autoloaders |
|
858 | - // enable logging? |
|
859 | - if ($config->admin->use_full_logging) { |
|
860 | - $this->loader->getShared('EE_Log'); |
|
861 | - } |
|
862 | - // check for activation errors |
|
863 | - $activation_errors = get_option('ee_plugin_activation_errors', false); |
|
864 | - if ($activation_errors) { |
|
865 | - EE_Error::add_error($activation_errors, __FILE__, __FUNCTION__, __LINE__); |
|
866 | - update_option('ee_plugin_activation_errors', false); |
|
867 | - } |
|
868 | - // get model names |
|
869 | - $this->_parse_model_names(); |
|
870 | - // configure custom post type definitions |
|
871 | - $this->loader->getShared('EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions'); |
|
872 | - $this->loader->getShared('EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions'); |
|
873 | - do_action('AHEE__EE_System__load_core_configuration__complete', $this); |
|
874 | - } |
|
875 | - |
|
876 | - |
|
877 | - /** |
|
878 | - * cycles through all of the models/*.model.php files, and assembles an array of model names |
|
879 | - * |
|
880 | - * @return void |
|
881 | - * @throws ReflectionException |
|
882 | - */ |
|
883 | - private function _parse_model_names() |
|
884 | - { |
|
885 | - // get all the files in the EE_MODELS folder that end in .model.php |
|
886 | - $models = glob(EE_MODELS . '*.model.php'); |
|
887 | - $model_names = array(); |
|
888 | - $non_abstract_db_models = array(); |
|
889 | - foreach ($models as $model) { |
|
890 | - // get model classname |
|
891 | - $classname = EEH_File::get_classname_from_filepath_with_standard_filename($model); |
|
892 | - $short_name = str_replace('EEM_', '', $classname); |
|
893 | - $reflectionClass = new ReflectionClass($classname); |
|
894 | - if ($reflectionClass->isSubclassOf('EEM_Base') && ! $reflectionClass->isAbstract()) { |
|
895 | - $non_abstract_db_models[ $short_name ] = $classname; |
|
896 | - } |
|
897 | - $model_names[ $short_name ] = $classname; |
|
898 | - } |
|
899 | - $this->registry->models = apply_filters('FHEE__EE_System__parse_model_names', $model_names); |
|
900 | - $this->registry->non_abstract_db_models = apply_filters( |
|
901 | - 'FHEE__EE_System__parse_implemented_model_names', |
|
902 | - $non_abstract_db_models |
|
903 | - ); |
|
904 | - } |
|
905 | - |
|
906 | - |
|
907 | - /** |
|
908 | - * The purpose of this method is to simply check for a file named "caffeinated/brewing_regular.php" for any hooks |
|
909 | - * that need to be setup before our EE_System launches. |
|
910 | - * |
|
911 | - * @return void |
|
912 | - * @throws DomainException |
|
913 | - * @throws InvalidArgumentException |
|
914 | - * @throws InvalidDataTypeException |
|
915 | - * @throws InvalidInterfaceException |
|
916 | - * @throws InvalidClassException |
|
917 | - * @throws InvalidFilePathException |
|
918 | - */ |
|
919 | - private function _maybe_brew_regular() |
|
920 | - { |
|
921 | - /** @var Domain $domain */ |
|
922 | - $domain = DomainFactory::getShared( |
|
923 | - new FullyQualifiedName( |
|
924 | - 'EventEspresso\core\domain\Domain' |
|
925 | - ), |
|
926 | - array( |
|
927 | - new FilePath(EVENT_ESPRESSO_MAIN_FILE), |
|
928 | - Version::fromString(espresso_version()), |
|
929 | - ) |
|
930 | - ); |
|
931 | - if ($domain->isCaffeinated()) { |
|
932 | - require_once EE_CAFF_PATH . 'brewing_regular.php'; |
|
933 | - } |
|
934 | - } |
|
935 | - |
|
936 | - |
|
937 | - /** |
|
938 | - * @since 4.9.71.p |
|
939 | - * @throws Exception |
|
940 | - */ |
|
941 | - public function loadRouteMatchSpecifications() |
|
942 | - { |
|
943 | - try { |
|
944 | - $this->loader->getShared( |
|
945 | - 'EventEspresso\core\services\route_match\RouteMatchSpecificationManager' |
|
946 | - ); |
|
947 | - } catch (Exception $exception) { |
|
948 | - new ExceptionStackTraceDisplay($exception); |
|
949 | - } |
|
950 | - do_action('AHEE__EE_System__loadRouteMatchSpecifications'); |
|
951 | - } |
|
952 | - |
|
953 | - |
|
954 | - /** |
|
955 | - * register_shortcodes_modules_and_widgets |
|
956 | - * generate lists of shortcodes and modules, then verify paths and classes |
|
957 | - * This is hooked into 'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets' |
|
958 | - * which runs during the WP 'plugins_loaded' action at priority 7 |
|
959 | - * |
|
960 | - * @access public |
|
961 | - * @return void |
|
962 | - * @throws Exception |
|
963 | - */ |
|
964 | - public function register_shortcodes_modules_and_widgets() |
|
965 | - { |
|
966 | - if ($this->request->isFrontend() || $this->request->isIframe() || $this->request->isAjax()) { |
|
967 | - try { |
|
968 | - // load, register, and add shortcodes the new way |
|
969 | - $this->loader->getShared( |
|
970 | - 'EventEspresso\core\services\shortcodes\ShortcodesManager', |
|
971 | - array( |
|
972 | - // and the old way, but we'll put it under control of the new system |
|
973 | - EE_Config::getLegacyShortcodesManager(), |
|
974 | - ) |
|
975 | - ); |
|
976 | - } catch (Exception $exception) { |
|
977 | - new ExceptionStackTraceDisplay($exception); |
|
978 | - } |
|
979 | - } |
|
980 | - do_action('AHEE__EE_System__register_shortcodes_modules_and_widgets'); |
|
981 | - // check for addons using old hook point |
|
982 | - if (has_action('AHEE__EE_System__register_shortcodes_modules_and_addons')) { |
|
983 | - $this->_incompatible_addon_error(); |
|
984 | - } |
|
985 | - } |
|
986 | - |
|
987 | - |
|
988 | - /** |
|
989 | - * _incompatible_addon_error |
|
990 | - * |
|
991 | - * @access public |
|
992 | - * @return void |
|
993 | - */ |
|
994 | - private function _incompatible_addon_error() |
|
995 | - { |
|
996 | - // get array of classes hooking into here |
|
997 | - $class_names = EEH_Class_Tools::get_class_names_for_all_callbacks_on_hook( |
|
998 | - 'AHEE__EE_System__register_shortcodes_modules_and_addons' |
|
999 | - ); |
|
1000 | - if (! empty($class_names)) { |
|
1001 | - $msg = __( |
|
1002 | - 'The following plugins, addons, or modules appear to be incompatible with this version of Event Espresso and were automatically deactivated to avoid fatal errors:', |
|
1003 | - 'event_espresso' |
|
1004 | - ); |
|
1005 | - $msg .= '<ul>'; |
|
1006 | - foreach ($class_names as $class_name) { |
|
1007 | - $msg .= '<li><b>Event Espresso - ' |
|
1008 | - . str_replace( |
|
1009 | - array('EE_', 'EEM_', 'EED_', 'EES_', 'EEW_'), |
|
1010 | - '', |
|
1011 | - $class_name |
|
1012 | - ) . '</b></li>'; |
|
1013 | - } |
|
1014 | - $msg .= '</ul>'; |
|
1015 | - $msg .= __( |
|
1016 | - 'Compatibility issues can be avoided and/or resolved by keeping addons and plugins updated to the latest version.', |
|
1017 | - 'event_espresso' |
|
1018 | - ); |
|
1019 | - // save list of incompatible addons to wp-options for later use |
|
1020 | - add_option('ee_incompatible_addons', $class_names, '', 'no'); |
|
1021 | - if (is_admin()) { |
|
1022 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
1023 | - } |
|
1024 | - } |
|
1025 | - } |
|
1026 | - |
|
1027 | - |
|
1028 | - /** |
|
1029 | - * brew_espresso |
|
1030 | - * begins the process of setting hooks for initializing EE in the correct order |
|
1031 | - * This is happening on the 'AHEE__EE_Bootstrap__brew_espresso' hook point |
|
1032 | - * which runs during the WP 'plugins_loaded' action at priority 9 |
|
1033 | - * |
|
1034 | - * @return void |
|
1035 | - */ |
|
1036 | - public function brew_espresso() |
|
1037 | - { |
|
1038 | - do_action('AHEE__EE_System__brew_espresso__begin', $this); |
|
1039 | - // load some final core systems |
|
1040 | - add_action('init', array($this, 'set_hooks_for_core'), 1); |
|
1041 | - add_action('init', array($this, 'perform_activations_upgrades_and_migrations'), 3); |
|
1042 | - add_action('init', array($this, 'load_CPTs_and_session'), 5); |
|
1043 | - add_action('init', array($this, 'load_controllers'), 7); |
|
1044 | - add_action('init', array($this, 'core_loaded_and_ready'), 9); |
|
1045 | - add_action('init', array($this, 'initialize'), 10); |
|
1046 | - add_action('init', array($this, 'initialize_last'), 100); |
|
1047 | - if (is_admin() && apply_filters('FHEE__EE_System__brew_espresso__load_pue', true)) { |
|
1048 | - // pew pew pew |
|
1049 | - $this->loader->getShared('EventEspresso\core\services\licensing\LicenseService'); |
|
1050 | - do_action('AHEE__EE_System__brew_espresso__after_pue_init'); |
|
1051 | - } |
|
1052 | - do_action('AHEE__EE_System__brew_espresso__complete', $this); |
|
1053 | - } |
|
1054 | - |
|
1055 | - |
|
1056 | - /** |
|
1057 | - * set_hooks_for_core |
|
1058 | - * |
|
1059 | - * @access public |
|
1060 | - * @return void |
|
1061 | - * @throws EE_Error |
|
1062 | - */ |
|
1063 | - public function set_hooks_for_core() |
|
1064 | - { |
|
1065 | - $this->_deactivate_incompatible_addons(); |
|
1066 | - do_action('AHEE__EE_System__set_hooks_for_core'); |
|
1067 | - $this->loader->getShared('EventEspresso\core\domain\values\session\SessionLifespan'); |
|
1068 | - // caps need to be initialized on every request so that capability maps are set. |
|
1069 | - // @see https://events.codebasehq.com/projects/event-espresso/tickets/8674 |
|
1070 | - $this->registry->CAP->init_caps(); |
|
1071 | - } |
|
1072 | - |
|
1073 | - |
|
1074 | - /** |
|
1075 | - * Using the information gathered in EE_System::_incompatible_addon_error, |
|
1076 | - * deactivates any addons considered incompatible with the current version of EE |
|
1077 | - */ |
|
1078 | - private function _deactivate_incompatible_addons() |
|
1079 | - { |
|
1080 | - $incompatible_addons = get_option('ee_incompatible_addons', array()); |
|
1081 | - if (! empty($incompatible_addons)) { |
|
1082 | - $active_plugins = get_option('active_plugins', array()); |
|
1083 | - foreach ($active_plugins as $active_plugin) { |
|
1084 | - foreach ($incompatible_addons as $incompatible_addon) { |
|
1085 | - if (strpos($active_plugin, $incompatible_addon) !== false) { |
|
1086 | - unset($_GET['activate']); |
|
1087 | - espresso_deactivate_plugin($active_plugin); |
|
1088 | - } |
|
1089 | - } |
|
1090 | - } |
|
1091 | - } |
|
1092 | - } |
|
1093 | - |
|
1094 | - |
|
1095 | - /** |
|
1096 | - * perform_activations_upgrades_and_migrations |
|
1097 | - * |
|
1098 | - * @access public |
|
1099 | - * @return void |
|
1100 | - */ |
|
1101 | - public function perform_activations_upgrades_and_migrations() |
|
1102 | - { |
|
1103 | - do_action('AHEE__EE_System__perform_activations_upgrades_and_migrations'); |
|
1104 | - } |
|
1105 | - |
|
1106 | - |
|
1107 | - /** |
|
1108 | - * @return void |
|
1109 | - * @throws DomainException |
|
1110 | - */ |
|
1111 | - public function load_CPTs_and_session() |
|
1112 | - { |
|
1113 | - do_action('AHEE__EE_System__load_CPTs_and_session__start'); |
|
1114 | - /** @var EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomies $register_custom_taxonomies */ |
|
1115 | - $register_custom_taxonomies = $this->loader->getShared( |
|
1116 | - 'EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomies' |
|
1117 | - ); |
|
1118 | - $register_custom_taxonomies->registerCustomTaxonomies(); |
|
1119 | - /** @var EventEspresso\core\domain\services\custom_post_types\RegisterCustomPostTypes $register_custom_post_types */ |
|
1120 | - $register_custom_post_types = $this->loader->getShared( |
|
1121 | - 'EventEspresso\core\domain\services\custom_post_types\RegisterCustomPostTypes' |
|
1122 | - ); |
|
1123 | - $register_custom_post_types->registerCustomPostTypes(); |
|
1124 | - /** @var EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomyTerms $register_custom_taxonomy_terms */ |
|
1125 | - $register_custom_taxonomy_terms = $this->loader->getShared( |
|
1126 | - 'EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomyTerms' |
|
1127 | - ); |
|
1128 | - $register_custom_taxonomy_terms->registerCustomTaxonomyTerms(); |
|
1129 | - // load legacy Custom Post Types and Taxonomies |
|
1130 | - $this->loader->getShared('EE_Register_CPTs'); |
|
1131 | - do_action('AHEE__EE_System__load_CPTs_and_session__complete'); |
|
1132 | - } |
|
1133 | - |
|
1134 | - |
|
1135 | - /** |
|
1136 | - * load_controllers |
|
1137 | - * this is the best place to load any additional controllers that needs access to EE core. |
|
1138 | - * it is expected that all basic core EE systems, that are not dependant on the current request are loaded at this |
|
1139 | - * time |
|
1140 | - * |
|
1141 | - * @access public |
|
1142 | - * @return void |
|
1143 | - */ |
|
1144 | - public function load_controllers() |
|
1145 | - { |
|
1146 | - do_action('AHEE__EE_System__load_controllers__start'); |
|
1147 | - // let's get it started |
|
1148 | - if (! $this->maintenance_mode->level() |
|
1149 | - && ($this->request->isFrontend() || $this->request->isFrontAjax()) |
|
1150 | - ) { |
|
1151 | - do_action('AHEE__EE_System__load_controllers__load_front_controllers'); |
|
1152 | - $this->loader->getShared('EE_Front_Controller'); |
|
1153 | - } elseif ($this->request->isAdmin() || $this->request->isAdminAjax()) { |
|
1154 | - do_action('AHEE__EE_System__load_controllers__load_admin_controllers'); |
|
1155 | - $this->loader->getShared('EE_Admin'); |
|
1156 | - } elseif ($this->request->isWordPressHeartbeat()) { |
|
1157 | - $this->loader->getShared('EventEspresso\core\domain\services\admin\ajax\WordpressHeartbeat'); |
|
1158 | - } |
|
1159 | - do_action('AHEE__EE_System__load_controllers__complete'); |
|
1160 | - } |
|
1161 | - |
|
1162 | - |
|
1163 | - /** |
|
1164 | - * core_loaded_and_ready |
|
1165 | - * all of the basic EE core should be loaded at this point and available regardless of M-Mode |
|
1166 | - * |
|
1167 | - * @access public |
|
1168 | - * @return void |
|
1169 | - * @throws Exception |
|
1170 | - */ |
|
1171 | - public function core_loaded_and_ready() |
|
1172 | - { |
|
1173 | - if ($this->request->isAdmin() |
|
1174 | - || $this->request->isFrontend() |
|
1175 | - || $this->request->isIframe() |
|
1176 | - || $this->request->isWordPressApi() |
|
1177 | - ) { |
|
1178 | - try { |
|
1179 | - $this->loader->getShared('EventEspresso\core\services\assets\Registry'); |
|
1180 | - $this->loader->getShared('EventEspresso\core\domain\services\assets\CoreAssetManager'); |
|
1181 | - if ($this->canLoadBlocks()) { |
|
1182 | - $this->loader->getShared( |
|
1183 | - 'EventEspresso\core\services\editor\BlockRegistrationManager' |
|
1184 | - ); |
|
1185 | - } |
|
1186 | - } catch (Exception $exception) { |
|
1187 | - new ExceptionStackTraceDisplay($exception); |
|
1188 | - } |
|
1189 | - } |
|
1190 | - if ($this->request->isAdmin() |
|
1191 | - || $this->request->isEeAjax() |
|
1192 | - || $this->request->isFrontend() |
|
1193 | - ) { |
|
1194 | - $this->loader->getShared('EE_Session'); |
|
1195 | - } |
|
1196 | - // integrate WP_Query with the EE models |
|
1197 | - $this->loader->getShared('EE_CPT_Strategy'); |
|
1198 | - do_action('AHEE__EE_System__core_loaded_and_ready'); |
|
1199 | - // always load template tags, because it's faster than checking if it's a front-end request, and many page |
|
1200 | - // builders require these even on the front-end |
|
1201 | - require_once EE_PUBLIC . 'template_tags.php'; |
|
1202 | - do_action('AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons'); |
|
1203 | - } |
|
1204 | - |
|
1205 | - |
|
1206 | - /** |
|
1207 | - * initialize |
|
1208 | - * this is the best place to begin initializing client code |
|
1209 | - * |
|
1210 | - * @access public |
|
1211 | - * @return void |
|
1212 | - */ |
|
1213 | - public function initialize() |
|
1214 | - { |
|
1215 | - do_action('AHEE__EE_System__initialize'); |
|
1216 | - } |
|
1217 | - |
|
1218 | - |
|
1219 | - /** |
|
1220 | - * initialize_last |
|
1221 | - * this is run really late during the WP init hook point, and ensures that mostly everything else that needs to |
|
1222 | - * initialize has done so |
|
1223 | - * |
|
1224 | - * @access public |
|
1225 | - * @return void |
|
1226 | - */ |
|
1227 | - public function initialize_last() |
|
1228 | - { |
|
1229 | - do_action('AHEE__EE_System__initialize_last'); |
|
1230 | - /** @var EventEspresso\core\domain\services\custom_post_types\RewriteRules $rewrite_rules */ |
|
1231 | - $rewrite_rules = $this->loader->getShared( |
|
1232 | - 'EventEspresso\core\domain\services\custom_post_types\RewriteRules' |
|
1233 | - ); |
|
1234 | - $rewrite_rules->flushRewriteRules(); |
|
1235 | - add_action('admin_bar_init', array($this, 'addEspressoToolbar')); |
|
1236 | - if (($this->request->isAjax() || $this->request->isAdmin()) |
|
1237 | - && $this->maintenance_mode->models_can_query()) { |
|
1238 | - $this->loader->getShared('EventEspresso\core\services\privacy\export\PersonalDataExporterManager'); |
|
1239 | - $this->loader->getShared('EventEspresso\core\services\privacy\erasure\PersonalDataEraserManager'); |
|
1240 | - } |
|
1241 | - } |
|
1242 | - |
|
1243 | - |
|
1244 | - /** |
|
1245 | - * @return void |
|
1246 | - * @throws EE_Error |
|
1247 | - */ |
|
1248 | - public function addEspressoToolbar() |
|
1249 | - { |
|
1250 | - $this->loader->getShared( |
|
1251 | - 'EventEspresso\core\domain\services\admin\AdminToolBar', |
|
1252 | - array($this->registry->CAP) |
|
1253 | - ); |
|
1254 | - } |
|
1255 | - |
|
1256 | - |
|
1257 | - /** |
|
1258 | - * do_not_cache |
|
1259 | - * sets no cache headers and defines no cache constants for WP plugins |
|
1260 | - * |
|
1261 | - * @access public |
|
1262 | - * @return void |
|
1263 | - */ |
|
1264 | - public static function do_not_cache() |
|
1265 | - { |
|
1266 | - // set no cache constants |
|
1267 | - if (! defined('DONOTCACHEPAGE')) { |
|
1268 | - define('DONOTCACHEPAGE', true); |
|
1269 | - } |
|
1270 | - if (! defined('DONOTCACHCEOBJECT')) { |
|
1271 | - define('DONOTCACHCEOBJECT', true); |
|
1272 | - } |
|
1273 | - if (! defined('DONOTCACHEDB')) { |
|
1274 | - define('DONOTCACHEDB', true); |
|
1275 | - } |
|
1276 | - // add no cache headers |
|
1277 | - add_action('send_headers', array('EE_System', 'nocache_headers'), 10); |
|
1278 | - // plus a little extra for nginx and Google Chrome |
|
1279 | - add_filter('nocache_headers', array('EE_System', 'extra_nocache_headers'), 10, 1); |
|
1280 | - // prevent browsers from prefetching of the rel='next' link, because it may contain content that interferes with the registration process |
|
1281 | - remove_action('wp_head', 'adjacent_posts_rel_link_wp_head'); |
|
1282 | - } |
|
1283 | - |
|
1284 | - |
|
1285 | - /** |
|
1286 | - * extra_nocache_headers |
|
1287 | - * |
|
1288 | - * @access public |
|
1289 | - * @param $headers |
|
1290 | - * @return array |
|
1291 | - */ |
|
1292 | - public static function extra_nocache_headers($headers) |
|
1293 | - { |
|
1294 | - // for NGINX |
|
1295 | - $headers['X-Accel-Expires'] = 0; |
|
1296 | - // plus extra for Google Chrome since it doesn't seem to respect "no-cache", but WILL respect "no-store" |
|
1297 | - $headers['Cache-Control'] = 'no-store, no-cache, must-revalidate, max-age=0'; |
|
1298 | - return $headers; |
|
1299 | - } |
|
1300 | - |
|
1301 | - |
|
1302 | - /** |
|
1303 | - * nocache_headers |
|
1304 | - * |
|
1305 | - * @access public |
|
1306 | - * @return void |
|
1307 | - */ |
|
1308 | - public static function nocache_headers() |
|
1309 | - { |
|
1310 | - nocache_headers(); |
|
1311 | - } |
|
1312 | - |
|
1313 | - |
|
1314 | - /** |
|
1315 | - * simply hooks into "wp_list_pages_exclude" filter (for wp_list_pages method) and makes sure EE critical pages are |
|
1316 | - * never returned with the function. |
|
1317 | - * |
|
1318 | - * @param array $exclude_array any existing pages being excluded are in this array. |
|
1319 | - * @return array |
|
1320 | - */ |
|
1321 | - public function remove_pages_from_wp_list_pages($exclude_array) |
|
1322 | - { |
|
1323 | - return array_merge($exclude_array, $this->registry->CFG->core->get_critical_pages_array()); |
|
1324 | - } |
|
1325 | - |
|
1326 | - |
|
1327 | - /** |
|
1328 | - * Return whether blocks can be registered/loaded or not. |
|
1329 | - * @return bool |
|
1330 | - */ |
|
1331 | - private function canLoadBlocks() |
|
1332 | - { |
|
1333 | - return apply_filters('FHEE__EE_System__canLoadBlocks', true) |
|
1334 | - && function_exists('register_block_type') |
|
1335 | - // don't load blocks if in the Divi page builder editor context |
|
1336 | - // @see https://github.com/eventespresso/event-espresso-core/issues/814 |
|
1337 | - && ! $this->request->getRequestParam('et_fb', false); |
|
1338 | - } |
|
30 | + /** |
|
31 | + * indicates this is a 'normal' request. Ie, not activation, nor upgrade, nor activation. |
|
32 | + * So examples of this would be a normal GET request on the frontend or backend, or a POST, etc |
|
33 | + */ |
|
34 | + const req_type_normal = 0; |
|
35 | + |
|
36 | + /** |
|
37 | + * Indicates this is a brand new installation of EE so we should install |
|
38 | + * tables and default data etc |
|
39 | + */ |
|
40 | + const req_type_new_activation = 1; |
|
41 | + |
|
42 | + /** |
|
43 | + * we've detected that EE has been reactivated (or EE was activated during maintenance mode, |
|
44 | + * and we just exited maintenance mode). We MUST check the database is setup properly |
|
45 | + * and that default data is setup too |
|
46 | + */ |
|
47 | + const req_type_reactivation = 2; |
|
48 | + |
|
49 | + /** |
|
50 | + * indicates that EE has been upgraded since its previous request. |
|
51 | + * We may have data migration scripts to call and will want to trigger maintenance mode |
|
52 | + */ |
|
53 | + const req_type_upgrade = 3; |
|
54 | + |
|
55 | + /** |
|
56 | + * TODO will detect that EE has been DOWNGRADED. We probably don't want to run in this case... |
|
57 | + */ |
|
58 | + const req_type_downgrade = 4; |
|
59 | + |
|
60 | + /** |
|
61 | + * @deprecated since version 4.6.0.dev.006 |
|
62 | + * Now whenever a new_activation is detected the request type is still just |
|
63 | + * new_activation (same for reactivation, upgrade, downgrade etc), but if we'r ein maintenance mode |
|
64 | + * EE_System::initialize_db_if_no_migrations_required and EE_Addon::initialize_db_if_no_migrations_required |
|
65 | + * will instead enqueue that EE plugin's db initialization for when we're taken out of maintenance mode. |
|
66 | + * (Specifically, when the migration manager indicates migrations are finished |
|
67 | + * EE_Data_Migration_Manager::initialize_db_for_enqueued_ee_plugins() will be called) |
|
68 | + */ |
|
69 | + const req_type_activation_but_not_installed = 5; |
|
70 | + |
|
71 | + /** |
|
72 | + * option prefix for recording the activation history (like core's "espresso_db_update") of addons |
|
73 | + */ |
|
74 | + const addon_activation_history_option_prefix = 'ee_addon_activation_history_'; |
|
75 | + |
|
76 | + /** |
|
77 | + * @var EE_System $_instance |
|
78 | + */ |
|
79 | + private static $_instance; |
|
80 | + |
|
81 | + /** |
|
82 | + * @var EE_Registry $registry |
|
83 | + */ |
|
84 | + private $registry; |
|
85 | + |
|
86 | + /** |
|
87 | + * @var LoaderInterface $loader |
|
88 | + */ |
|
89 | + private $loader; |
|
90 | + |
|
91 | + /** |
|
92 | + * @var EE_Capabilities $capabilities |
|
93 | + */ |
|
94 | + private $capabilities; |
|
95 | + |
|
96 | + /** |
|
97 | + * @var RequestInterface $request |
|
98 | + */ |
|
99 | + private $request; |
|
100 | + |
|
101 | + /** |
|
102 | + * @var EE_Maintenance_Mode $maintenance_mode |
|
103 | + */ |
|
104 | + private $maintenance_mode; |
|
105 | + |
|
106 | + /** |
|
107 | + * Stores which type of request this is, options being one of the constants on EE_System starting with req_type_*. |
|
108 | + * It can be a brand-new activation, a reactivation, an upgrade, a downgrade, or a normal request. |
|
109 | + * |
|
110 | + * @var int $_req_type |
|
111 | + */ |
|
112 | + private $_req_type; |
|
113 | + |
|
114 | + /** |
|
115 | + * Whether or not there was a non-micro version change in EE core version during this request |
|
116 | + * |
|
117 | + * @var boolean $_major_version_change |
|
118 | + */ |
|
119 | + private $_major_version_change = false; |
|
120 | + |
|
121 | + /** |
|
122 | + * A Context DTO dedicated solely to identifying the current request type. |
|
123 | + * |
|
124 | + * @var RequestTypeContextCheckerInterface $request_type |
|
125 | + */ |
|
126 | + private $request_type; |
|
127 | + |
|
128 | + |
|
129 | + /** |
|
130 | + * @singleton method used to instantiate class object |
|
131 | + * @param EE_Registry|null $registry |
|
132 | + * @param LoaderInterface|null $loader |
|
133 | + * @param RequestInterface|null $request |
|
134 | + * @param EE_Maintenance_Mode|null $maintenance_mode |
|
135 | + * @return EE_System |
|
136 | + */ |
|
137 | + public static function instance( |
|
138 | + EE_Registry $registry = null, |
|
139 | + LoaderInterface $loader = null, |
|
140 | + RequestInterface $request = null, |
|
141 | + EE_Maintenance_Mode $maintenance_mode = null |
|
142 | + ) { |
|
143 | + // check if class object is instantiated |
|
144 | + if (! self::$_instance instanceof EE_System) { |
|
145 | + self::$_instance = new self($registry, $loader, $request, $maintenance_mode); |
|
146 | + } |
|
147 | + return self::$_instance; |
|
148 | + } |
|
149 | + |
|
150 | + |
|
151 | + /** |
|
152 | + * resets the instance and returns it |
|
153 | + * |
|
154 | + * @return EE_System |
|
155 | + */ |
|
156 | + public static function reset() |
|
157 | + { |
|
158 | + self::$_instance->_req_type = null; |
|
159 | + // make sure none of the old hooks are left hanging around |
|
160 | + remove_all_actions('AHEE__EE_System__perform_activations_upgrades_and_migrations'); |
|
161 | + // we need to reset the migration manager in order for it to detect DMSs properly |
|
162 | + EE_Data_Migration_Manager::reset(); |
|
163 | + self::instance()->detect_activations_or_upgrades(); |
|
164 | + self::instance()->perform_activations_upgrades_and_migrations(); |
|
165 | + return self::instance(); |
|
166 | + } |
|
167 | + |
|
168 | + |
|
169 | + /** |
|
170 | + * sets hooks for running rest of system |
|
171 | + * provides "AHEE__EE_System__construct__complete" hook for EE Addons to use as their starting point |
|
172 | + * starting EE Addons from any other point may lead to problems |
|
173 | + * |
|
174 | + * @param EE_Registry $registry |
|
175 | + * @param LoaderInterface $loader |
|
176 | + * @param RequestInterface $request |
|
177 | + * @param EE_Maintenance_Mode $maintenance_mode |
|
178 | + */ |
|
179 | + private function __construct( |
|
180 | + EE_Registry $registry, |
|
181 | + LoaderInterface $loader, |
|
182 | + RequestInterface $request, |
|
183 | + EE_Maintenance_Mode $maintenance_mode |
|
184 | + ) { |
|
185 | + $this->registry = $registry; |
|
186 | + $this->loader = $loader; |
|
187 | + $this->request = $request; |
|
188 | + $this->maintenance_mode = $maintenance_mode; |
|
189 | + do_action('AHEE__EE_System__construct__begin', $this); |
|
190 | + add_action( |
|
191 | + 'AHEE__EE_Bootstrap__load_espresso_addons', |
|
192 | + array($this, 'loadCapabilities'), |
|
193 | + 5 |
|
194 | + ); |
|
195 | + add_action( |
|
196 | + 'AHEE__EE_Bootstrap__load_espresso_addons', |
|
197 | + array($this, 'loadCommandBus'), |
|
198 | + 7 |
|
199 | + ); |
|
200 | + add_action( |
|
201 | + 'AHEE__EE_Bootstrap__load_espresso_addons', |
|
202 | + array($this, 'loadPluginApi'), |
|
203 | + 9 |
|
204 | + ); |
|
205 | + // allow addons to load first so that they can register autoloaders, set hooks for running DMS's, etc |
|
206 | + add_action( |
|
207 | + 'AHEE__EE_Bootstrap__load_espresso_addons', |
|
208 | + array($this, 'load_espresso_addons') |
|
209 | + ); |
|
210 | + // when an ee addon is activated, we want to call the core hook(s) again |
|
211 | + // because the newly-activated addon didn't get a chance to run at all |
|
212 | + add_action('activate_plugin', array($this, 'load_espresso_addons'), 1); |
|
213 | + // detect whether install or upgrade |
|
214 | + add_action( |
|
215 | + 'AHEE__EE_Bootstrap__detect_activations_or_upgrades', |
|
216 | + array($this, 'detect_activations_or_upgrades'), |
|
217 | + 3 |
|
218 | + ); |
|
219 | + // load EE_Config, EE_Textdomain, etc |
|
220 | + add_action( |
|
221 | + 'AHEE__EE_Bootstrap__load_core_configuration', |
|
222 | + array($this, 'load_core_configuration'), |
|
223 | + 5 |
|
224 | + ); |
|
225 | + // load specifications for matching routes to current request |
|
226 | + add_action( |
|
227 | + 'AHEE__EE_Bootstrap__load_core_configuration', |
|
228 | + array($this, 'loadRouteMatchSpecifications') |
|
229 | + ); |
|
230 | + // load EE_Config, EE_Textdomain, etc |
|
231 | + add_action( |
|
232 | + 'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets', |
|
233 | + array($this, 'register_shortcodes_modules_and_widgets'), |
|
234 | + 7 |
|
235 | + ); |
|
236 | + // you wanna get going? I wanna get going... let's get going! |
|
237 | + add_action( |
|
238 | + 'AHEE__EE_Bootstrap__brew_espresso', |
|
239 | + array($this, 'brew_espresso'), |
|
240 | + 9 |
|
241 | + ); |
|
242 | + // other housekeeping |
|
243 | + // exclude EE critical pages from wp_list_pages |
|
244 | + add_filter( |
|
245 | + 'wp_list_pages_excludes', |
|
246 | + array($this, 'remove_pages_from_wp_list_pages'), |
|
247 | + 10 |
|
248 | + ); |
|
249 | + // ALL EE Addons should use the following hook point to attach their initial setup too |
|
250 | + // it's extremely important for EE Addons to register any class autoloaders so that they can be available when the EE_Config loads |
|
251 | + do_action('AHEE__EE_System__construct__complete', $this); |
|
252 | + } |
|
253 | + |
|
254 | + |
|
255 | + /** |
|
256 | + * load and setup EE_Capabilities |
|
257 | + * |
|
258 | + * @return void |
|
259 | + * @throws EE_Error |
|
260 | + */ |
|
261 | + public function loadCapabilities() |
|
262 | + { |
|
263 | + $this->capabilities = $this->loader->getShared('EE_Capabilities'); |
|
264 | + add_action( |
|
265 | + 'AHEE__EE_Capabilities__init_caps__before_initialization', |
|
266 | + function () { |
|
267 | + LoaderFactory::getLoader()->getShared('EE_Payment_Method_Manager'); |
|
268 | + } |
|
269 | + ); |
|
270 | + } |
|
271 | + |
|
272 | + |
|
273 | + /** |
|
274 | + * create and cache the CommandBus, and also add middleware |
|
275 | + * The CapChecker middleware requires the use of EE_Capabilities |
|
276 | + * which is why we need to load the CommandBus after Caps are set up |
|
277 | + * |
|
278 | + * @return void |
|
279 | + * @throws EE_Error |
|
280 | + */ |
|
281 | + public function loadCommandBus() |
|
282 | + { |
|
283 | + $this->loader->getShared( |
|
284 | + 'CommandBusInterface', |
|
285 | + array( |
|
286 | + null, |
|
287 | + apply_filters( |
|
288 | + 'FHEE__EE_Load_Espresso_Core__handle_request__CommandBus_middleware', |
|
289 | + array( |
|
290 | + $this->loader->getShared('EventEspresso\core\services\commands\middleware\CapChecker'), |
|
291 | + $this->loader->getShared('EventEspresso\core\services\commands\middleware\AddActionHook'), |
|
292 | + ) |
|
293 | + ), |
|
294 | + ) |
|
295 | + ); |
|
296 | + } |
|
297 | + |
|
298 | + |
|
299 | + /** |
|
300 | + * @return void |
|
301 | + * @throws EE_Error |
|
302 | + */ |
|
303 | + public function loadPluginApi() |
|
304 | + { |
|
305 | + // set autoloaders for all of the classes implementing EEI_Plugin_API |
|
306 | + // which provide helpers for EE plugin authors to more easily register certain components with EE. |
|
307 | + EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'plugin_api'); |
|
308 | + $this->loader->getShared('EE_Request_Handler'); |
|
309 | + } |
|
310 | + |
|
311 | + |
|
312 | + /** |
|
313 | + * @param string $addon_name |
|
314 | + * @param string $version_constant |
|
315 | + * @param string $min_version_required |
|
316 | + * @param string $load_callback |
|
317 | + * @param string $plugin_file_constant |
|
318 | + * @return void |
|
319 | + */ |
|
320 | + private function deactivateIncompatibleAddon( |
|
321 | + $addon_name, |
|
322 | + $version_constant, |
|
323 | + $min_version_required, |
|
324 | + $load_callback, |
|
325 | + $plugin_file_constant |
|
326 | + ) { |
|
327 | + if (! defined($version_constant)) { |
|
328 | + return; |
|
329 | + } |
|
330 | + $addon_version = constant($version_constant); |
|
331 | + if ($addon_version && version_compare($addon_version, $min_version_required, '<')) { |
|
332 | + remove_action('AHEE__EE_System__load_espresso_addons', $load_callback); |
|
333 | + if (! function_exists('deactivate_plugins')) { |
|
334 | + require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
335 | + } |
|
336 | + deactivate_plugins(plugin_basename(constant($plugin_file_constant))); |
|
337 | + unset($_GET['activate'], $_REQUEST['activate'], $_GET['activate-multi'], $_REQUEST['activate-multi']); |
|
338 | + EE_Error::add_error( |
|
339 | + sprintf( |
|
340 | + esc_html__( |
|
341 | + 'We\'re sorry, but the Event Espresso %1$s addon was deactivated because version %2$s or higher is required with this version of Event Espresso core.', |
|
342 | + 'event_espresso' |
|
343 | + ), |
|
344 | + $addon_name, |
|
345 | + $min_version_required |
|
346 | + ), |
|
347 | + __FILE__, |
|
348 | + __FUNCTION__ . "({$addon_name})", |
|
349 | + __LINE__ |
|
350 | + ); |
|
351 | + EE_Error::get_notices(false, true); |
|
352 | + } |
|
353 | + } |
|
354 | + |
|
355 | + |
|
356 | + /** |
|
357 | + * load_espresso_addons |
|
358 | + * allow addons to load first so that they can set hooks for running DMS's, etc |
|
359 | + * this is hooked into both: |
|
360 | + * 'AHEE__EE_Bootstrap__load_core_configuration' |
|
361 | + * which runs during the WP 'plugins_loaded' action at priority 5 |
|
362 | + * and the WP 'activate_plugin' hook point |
|
363 | + * |
|
364 | + * @access public |
|
365 | + * @return void |
|
366 | + */ |
|
367 | + public function load_espresso_addons() |
|
368 | + { |
|
369 | + $this->deactivateIncompatibleAddon( |
|
370 | + 'Wait Lists', |
|
371 | + 'EE_WAIT_LISTS_VERSION', |
|
372 | + '1.0.0.beta.074', |
|
373 | + 'load_espresso_wait_lists', |
|
374 | + 'EE_WAIT_LISTS_PLUGIN_FILE' |
|
375 | + ); |
|
376 | + $this->deactivateIncompatibleAddon( |
|
377 | + 'Automated Upcoming Event Notifications', |
|
378 | + 'EE_AUTOMATED_UPCOMING_EVENT_NOTIFICATION_VERSION', |
|
379 | + '1.0.0.beta.091', |
|
380 | + 'load_espresso_automated_upcoming_event_notification', |
|
381 | + 'EE_AUTOMATED_UPCOMING_EVENT_NOTIFICATION_PLUGIN_FILE' |
|
382 | + ); |
|
383 | + do_action('AHEE__EE_System__load_espresso_addons'); |
|
384 | + // if the WP API basic auth plugin isn't already loaded, load it now. |
|
385 | + // We want it for mobile apps. Just include the entire plugin |
|
386 | + // also, don't load the basic auth when a plugin is getting activated, because |
|
387 | + // it could be the basic auth plugin, and it doesn't check if its methods are already defined |
|
388 | + // and causes a fatal error |
|
389 | + if (($this->request->isWordPressApi() || $this->request->isApi()) |
|
390 | + && $this->request->getRequestParam('activate') !== 'true' |
|
391 | + && ! function_exists('json_basic_auth_handler') |
|
392 | + && ! function_exists('json_basic_auth_error') |
|
393 | + && ! in_array( |
|
394 | + $this->request->getRequestParam('action'), |
|
395 | + array('activate', 'activate-selected'), |
|
396 | + true |
|
397 | + ) |
|
398 | + ) { |
|
399 | + include_once EE_THIRD_PARTY . 'wp-api-basic-auth/basic-auth.php'; |
|
400 | + } |
|
401 | + do_action('AHEE__EE_System__load_espresso_addons__complete'); |
|
402 | + } |
|
403 | + |
|
404 | + |
|
405 | + /** |
|
406 | + * detect_activations_or_upgrades |
|
407 | + * Checks for activation or upgrade of core first; |
|
408 | + * then also checks if any registered addons have been activated or upgraded |
|
409 | + * This is hooked into 'AHEE__EE_Bootstrap__detect_activations_or_upgrades' |
|
410 | + * which runs during the WP 'plugins_loaded' action at priority 3 |
|
411 | + * |
|
412 | + * @access public |
|
413 | + * @return void |
|
414 | + */ |
|
415 | + public function detect_activations_or_upgrades() |
|
416 | + { |
|
417 | + // first off: let's make sure to handle core |
|
418 | + $this->detect_if_activation_or_upgrade(); |
|
419 | + foreach ($this->registry->addons as $addon) { |
|
420 | + if ($addon instanceof EE_Addon) { |
|
421 | + // detect teh request type for that addon |
|
422 | + $addon->detect_activation_or_upgrade(); |
|
423 | + } |
|
424 | + } |
|
425 | + } |
|
426 | + |
|
427 | + |
|
428 | + /** |
|
429 | + * detect_if_activation_or_upgrade |
|
430 | + * Takes care of detecting whether this is a brand new install or code upgrade, |
|
431 | + * and either setting up the DB or setting up maintenance mode etc. |
|
432 | + * |
|
433 | + * @access public |
|
434 | + * @return void |
|
435 | + */ |
|
436 | + public function detect_if_activation_or_upgrade() |
|
437 | + { |
|
438 | + do_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin'); |
|
439 | + // check if db has been updated, or if its a brand-new installation |
|
440 | + $espresso_db_update = $this->fix_espresso_db_upgrade_option(); |
|
441 | + $request_type = $this->detect_req_type($espresso_db_update); |
|
442 | + // EEH_Debug_Tools::printr( $request_type, '$request_type', __FILE__, __LINE__ ); |
|
443 | + switch ($request_type) { |
|
444 | + case EE_System::req_type_new_activation: |
|
445 | + do_action('AHEE__EE_System__detect_if_activation_or_upgrade__new_activation'); |
|
446 | + $this->_handle_core_version_change($espresso_db_update); |
|
447 | + break; |
|
448 | + case EE_System::req_type_reactivation: |
|
449 | + do_action('AHEE__EE_System__detect_if_activation_or_upgrade__reactivation'); |
|
450 | + $this->_handle_core_version_change($espresso_db_update); |
|
451 | + break; |
|
452 | + case EE_System::req_type_upgrade: |
|
453 | + do_action('AHEE__EE_System__detect_if_activation_or_upgrade__upgrade'); |
|
454 | + // migrations may be required now that we've upgraded |
|
455 | + $this->maintenance_mode->set_maintenance_mode_if_db_old(); |
|
456 | + $this->_handle_core_version_change($espresso_db_update); |
|
457 | + break; |
|
458 | + case EE_System::req_type_downgrade: |
|
459 | + do_action('AHEE__EE_System__detect_if_activation_or_upgrade__downgrade'); |
|
460 | + // its possible migrations are no longer required |
|
461 | + $this->maintenance_mode->set_maintenance_mode_if_db_old(); |
|
462 | + $this->_handle_core_version_change($espresso_db_update); |
|
463 | + break; |
|
464 | + case EE_System::req_type_normal: |
|
465 | + default: |
|
466 | + break; |
|
467 | + } |
|
468 | + do_action('AHEE__EE_System__detect_if_activation_or_upgrade__complete'); |
|
469 | + } |
|
470 | + |
|
471 | + |
|
472 | + /** |
|
473 | + * Updates the list of installed versions and sets hooks for |
|
474 | + * initializing the database later during the request |
|
475 | + * |
|
476 | + * @param array $espresso_db_update |
|
477 | + */ |
|
478 | + private function _handle_core_version_change($espresso_db_update) |
|
479 | + { |
|
480 | + $this->update_list_of_installed_versions($espresso_db_update); |
|
481 | + // get ready to verify the DB is ok (provided we aren't in maintenance mode, of course) |
|
482 | + add_action( |
|
483 | + 'AHEE__EE_System__perform_activations_upgrades_and_migrations', |
|
484 | + array($this, 'initialize_db_if_no_migrations_required') |
|
485 | + ); |
|
486 | + } |
|
487 | + |
|
488 | + |
|
489 | + /** |
|
490 | + * standardizes the wp option 'espresso_db_upgrade' which actually stores |
|
491 | + * information about what versions of EE have been installed and activated, |
|
492 | + * NOT necessarily the state of the database |
|
493 | + * |
|
494 | + * @param mixed $espresso_db_update the value of the WordPress option. |
|
495 | + * If not supplied, fetches it from the options table |
|
496 | + * @return array the correct value of 'espresso_db_upgrade', after saving it, if it needed correction |
|
497 | + */ |
|
498 | + private function fix_espresso_db_upgrade_option($espresso_db_update = null) |
|
499 | + { |
|
500 | + do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__begin', $espresso_db_update); |
|
501 | + if (! $espresso_db_update) { |
|
502 | + $espresso_db_update = get_option('espresso_db_update'); |
|
503 | + } |
|
504 | + // check that option is an array |
|
505 | + if (! is_array($espresso_db_update)) { |
|
506 | + // if option is FALSE, then it never existed |
|
507 | + if ($espresso_db_update === false) { |
|
508 | + // make $espresso_db_update an array and save option with autoload OFF |
|
509 | + $espresso_db_update = array(); |
|
510 | + add_option('espresso_db_update', $espresso_db_update, '', 'no'); |
|
511 | + } else { |
|
512 | + // option is NOT FALSE but also is NOT an array, so make it an array and save it |
|
513 | + $espresso_db_update = array($espresso_db_update => array()); |
|
514 | + update_option('espresso_db_update', $espresso_db_update); |
|
515 | + } |
|
516 | + } else { |
|
517 | + $corrected_db_update = array(); |
|
518 | + // if IS an array, but is it an array where KEYS are version numbers, and values are arrays? |
|
519 | + foreach ($espresso_db_update as $should_be_version_string => $should_be_array) { |
|
520 | + if (is_int($should_be_version_string) && ! is_array($should_be_array)) { |
|
521 | + // the key is an int, and the value IS NOT an array |
|
522 | + // so it must be numerically-indexed, where values are versions installed... |
|
523 | + // fix it! |
|
524 | + $version_string = $should_be_array; |
|
525 | + $corrected_db_update[ $version_string ] = array('unknown-date'); |
|
526 | + } else { |
|
527 | + // ok it checks out |
|
528 | + $corrected_db_update[ $should_be_version_string ] = $should_be_array; |
|
529 | + } |
|
530 | + } |
|
531 | + $espresso_db_update = $corrected_db_update; |
|
532 | + update_option('espresso_db_update', $espresso_db_update); |
|
533 | + } |
|
534 | + do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__complete', $espresso_db_update); |
|
535 | + return $espresso_db_update; |
|
536 | + } |
|
537 | + |
|
538 | + |
|
539 | + /** |
|
540 | + * Does the traditional work of setting up the plugin's database and adding default data. |
|
541 | + * If migration script/process did not exist, this is what would happen on every activation/reactivation/upgrade. |
|
542 | + * NOTE: if we're in maintenance mode (which would be the case if we detect there are data |
|
543 | + * migration scripts that need to be run and a version change happens), enqueues core for database initialization, |
|
544 | + * so that it will be done when migrations are finished |
|
545 | + * |
|
546 | + * @param boolean $initialize_addons_too if true, we double-check addons' database tables etc too; |
|
547 | + * @param boolean $verify_schema if true will re-check the database tables have the correct schema. |
|
548 | + * This is a resource-intensive job |
|
549 | + * so we prefer to only do it when necessary |
|
550 | + * @return void |
|
551 | + * @throws EE_Error |
|
552 | + */ |
|
553 | + public function initialize_db_if_no_migrations_required($initialize_addons_too = false, $verify_schema = true) |
|
554 | + { |
|
555 | + $request_type = $this->detect_req_type(); |
|
556 | + // only initialize system if we're not in maintenance mode. |
|
557 | + if ($this->maintenance_mode->level() !== EE_Maintenance_Mode::level_2_complete_maintenance) { |
|
558 | + /** @var EventEspresso\core\domain\services\custom_post_types\RewriteRules $rewrite_rules */ |
|
559 | + $rewrite_rules = $this->loader->getShared( |
|
560 | + 'EventEspresso\core\domain\services\custom_post_types\RewriteRules' |
|
561 | + ); |
|
562 | + $rewrite_rules->flush(); |
|
563 | + if ($verify_schema) { |
|
564 | + EEH_Activation::initialize_db_and_folders(); |
|
565 | + } |
|
566 | + EEH_Activation::initialize_db_content(); |
|
567 | + EEH_Activation::system_initialization(); |
|
568 | + if ($initialize_addons_too) { |
|
569 | + $this->initialize_addons(); |
|
570 | + } |
|
571 | + } else { |
|
572 | + EE_Data_Migration_Manager::instance()->enqueue_db_initialization_for('Core'); |
|
573 | + } |
|
574 | + if ($request_type === EE_System::req_type_new_activation |
|
575 | + || $request_type === EE_System::req_type_reactivation |
|
576 | + || ( |
|
577 | + $request_type === EE_System::req_type_upgrade |
|
578 | + && $this->is_major_version_change() |
|
579 | + ) |
|
580 | + ) { |
|
581 | + add_action('AHEE__EE_System__initialize_last', array($this, 'redirect_to_about_ee'), 9); |
|
582 | + } |
|
583 | + } |
|
584 | + |
|
585 | + |
|
586 | + /** |
|
587 | + * Initializes the db for all registered addons |
|
588 | + * |
|
589 | + * @throws EE_Error |
|
590 | + */ |
|
591 | + public function initialize_addons() |
|
592 | + { |
|
593 | + // foreach registered addon, make sure its db is up-to-date too |
|
594 | + foreach ($this->registry->addons as $addon) { |
|
595 | + if ($addon instanceof EE_Addon) { |
|
596 | + $addon->initialize_db_if_no_migrations_required(); |
|
597 | + } |
|
598 | + } |
|
599 | + } |
|
600 | + |
|
601 | + |
|
602 | + /** |
|
603 | + * Adds the current code version to the saved wp option which stores a list of all ee versions ever installed. |
|
604 | + * |
|
605 | + * @param array $version_history |
|
606 | + * @param string $current_version_to_add version to be added to the version history |
|
607 | + * @return boolean success as to whether or not this option was changed |
|
608 | + */ |
|
609 | + public function update_list_of_installed_versions($version_history = null, $current_version_to_add = null) |
|
610 | + { |
|
611 | + if (! $version_history) { |
|
612 | + $version_history = $this->fix_espresso_db_upgrade_option($version_history); |
|
613 | + } |
|
614 | + if ($current_version_to_add === null) { |
|
615 | + $current_version_to_add = espresso_version(); |
|
616 | + } |
|
617 | + $version_history[ $current_version_to_add ][] = date('Y-m-d H:i:s', time()); |
|
618 | + // re-save |
|
619 | + return update_option('espresso_db_update', $version_history); |
|
620 | + } |
|
621 | + |
|
622 | + |
|
623 | + /** |
|
624 | + * Detects if the current version indicated in the has existed in the list of |
|
625 | + * previously-installed versions of EE (espresso_db_update). Does NOT modify it (ie, no side-effect) |
|
626 | + * |
|
627 | + * @param array $espresso_db_update array from the wp option stored under the name 'espresso_db_update'. |
|
628 | + * If not supplied, fetches it from the options table. |
|
629 | + * Also, caches its result so later parts of the code can also know whether |
|
630 | + * there's been an update or not. This way we can add the current version to |
|
631 | + * espresso_db_update, but still know if this is a new install or not |
|
632 | + * @return int one of the constants on EE_System::req_type_ |
|
633 | + */ |
|
634 | + public function detect_req_type($espresso_db_update = null) |
|
635 | + { |
|
636 | + if ($this->_req_type === null) { |
|
637 | + $espresso_db_update = ! empty($espresso_db_update) |
|
638 | + ? $espresso_db_update |
|
639 | + : $this->fix_espresso_db_upgrade_option(); |
|
640 | + $this->_req_type = EE_System::detect_req_type_given_activation_history( |
|
641 | + $espresso_db_update, |
|
642 | + 'ee_espresso_activation', |
|
643 | + espresso_version() |
|
644 | + ); |
|
645 | + $this->_major_version_change = $this->_detect_major_version_change($espresso_db_update); |
|
646 | + $this->request->setIsActivation($this->_req_type !== EE_System::req_type_normal); |
|
647 | + } |
|
648 | + return $this->_req_type; |
|
649 | + } |
|
650 | + |
|
651 | + |
|
652 | + /** |
|
653 | + * Returns whether or not there was a non-micro version change (ie, change in either |
|
654 | + * the first or second number in the version. Eg 4.9.0.rc.001 to 4.10.0.rc.000, |
|
655 | + * but not 4.9.0.rc.0001 to 4.9.1.rc.0001 |
|
656 | + * |
|
657 | + * @param $activation_history |
|
658 | + * @return bool |
|
659 | + */ |
|
660 | + private function _detect_major_version_change($activation_history) |
|
661 | + { |
|
662 | + $previous_version = EE_System::_get_most_recently_active_version_from_activation_history($activation_history); |
|
663 | + $previous_version_parts = explode('.', $previous_version); |
|
664 | + $current_version_parts = explode('.', espresso_version()); |
|
665 | + return isset($previous_version_parts[0], $previous_version_parts[1], $current_version_parts[0], $current_version_parts[1]) |
|
666 | + && ($previous_version_parts[0] !== $current_version_parts[0] |
|
667 | + || $previous_version_parts[1] !== $current_version_parts[1] |
|
668 | + ); |
|
669 | + } |
|
670 | + |
|
671 | + |
|
672 | + /** |
|
673 | + * Returns true if either the major or minor version of EE changed during this request. |
|
674 | + * Eg 4.9.0.rc.001 to 4.10.0.rc.000, but not 4.9.0.rc.0001 to 4.9.1.rc.0001 |
|
675 | + * |
|
676 | + * @return bool |
|
677 | + */ |
|
678 | + public function is_major_version_change() |
|
679 | + { |
|
680 | + return $this->_major_version_change; |
|
681 | + } |
|
682 | + |
|
683 | + |
|
684 | + /** |
|
685 | + * Determines the request type for any ee addon, given three piece of info: the current array of activation |
|
686 | + * histories (for core that' 'espresso_db_update' wp option); the name of the WordPress option which is temporarily |
|
687 | + * set upon activation of the plugin (for core it's 'ee_espresso_activation'); and the version that this plugin was |
|
688 | + * just activated to (for core that will always be espresso_version()) |
|
689 | + * |
|
690 | + * @param array $activation_history_for_addon the option's value which stores the activation history for this |
|
691 | + * ee plugin. for core that's 'espresso_db_update' |
|
692 | + * @param string $activation_indicator_option_name the name of the WordPress option that is temporarily set to |
|
693 | + * indicate that this plugin was just activated |
|
694 | + * @param string $version_to_upgrade_to the version that was just upgraded to (for core that will be |
|
695 | + * espresso_version()) |
|
696 | + * @return int one of the constants on EE_System::req_type_* |
|
697 | + */ |
|
698 | + public static function detect_req_type_given_activation_history( |
|
699 | + $activation_history_for_addon, |
|
700 | + $activation_indicator_option_name, |
|
701 | + $version_to_upgrade_to |
|
702 | + ) { |
|
703 | + $version_is_higher = self::_new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to); |
|
704 | + if ($activation_history_for_addon) { |
|
705 | + // it exists, so this isn't a completely new install |
|
706 | + // check if this version already in that list of previously installed versions |
|
707 | + if (! isset($activation_history_for_addon[ $version_to_upgrade_to ])) { |
|
708 | + // it a version we haven't seen before |
|
709 | + if ($version_is_higher === 1) { |
|
710 | + $req_type = EE_System::req_type_upgrade; |
|
711 | + } else { |
|
712 | + $req_type = EE_System::req_type_downgrade; |
|
713 | + } |
|
714 | + delete_option($activation_indicator_option_name); |
|
715 | + } else { |
|
716 | + // its not an update. maybe a reactivation? |
|
717 | + if (get_option($activation_indicator_option_name, false)) { |
|
718 | + if ($version_is_higher === -1) { |
|
719 | + $req_type = EE_System::req_type_downgrade; |
|
720 | + } elseif ($version_is_higher === 0) { |
|
721 | + // we've seen this version before, but it's an activation. must be a reactivation |
|
722 | + $req_type = EE_System::req_type_reactivation; |
|
723 | + } else {// $version_is_higher === 1 |
|
724 | + $req_type = EE_System::req_type_upgrade; |
|
725 | + } |
|
726 | + delete_option($activation_indicator_option_name); |
|
727 | + } else { |
|
728 | + // we've seen this version before and the activation indicate doesn't show it was just activated |
|
729 | + if ($version_is_higher === -1) { |
|
730 | + $req_type = EE_System::req_type_downgrade; |
|
731 | + } elseif ($version_is_higher === 0) { |
|
732 | + // we've seen this version before and it's not an activation. its normal request |
|
733 | + $req_type = EE_System::req_type_normal; |
|
734 | + } else {// $version_is_higher === 1 |
|
735 | + $req_type = EE_System::req_type_upgrade; |
|
736 | + } |
|
737 | + } |
|
738 | + } |
|
739 | + } else { |
|
740 | + // brand new install |
|
741 | + $req_type = EE_System::req_type_new_activation; |
|
742 | + delete_option($activation_indicator_option_name); |
|
743 | + } |
|
744 | + return $req_type; |
|
745 | + } |
|
746 | + |
|
747 | + |
|
748 | + /** |
|
749 | + * Detects if the $version_to_upgrade_to is higher than the most recent version in |
|
750 | + * the $activation_history_for_addon |
|
751 | + * |
|
752 | + * @param array $activation_history_for_addon (keys are versions, values are arrays of times activated, |
|
753 | + * sometimes containing 'unknown-date' |
|
754 | + * @param string $version_to_upgrade_to (current version) |
|
755 | + * @return int results of version_compare( $version_to_upgrade_to, $most_recently_active_version ). |
|
756 | + * ie, -1 if $version_to_upgrade_to is LOWER (downgrade); |
|
757 | + * 0 if $version_to_upgrade_to MATCHES (reactivation or normal request); |
|
758 | + * 1 if $version_to_upgrade_to is HIGHER (upgrade) ; |
|
759 | + */ |
|
760 | + private static function _new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to) |
|
761 | + { |
|
762 | + // find the most recently-activated version |
|
763 | + $most_recently_active_version = |
|
764 | + EE_System::_get_most_recently_active_version_from_activation_history($activation_history_for_addon); |
|
765 | + return version_compare($version_to_upgrade_to, $most_recently_active_version); |
|
766 | + } |
|
767 | + |
|
768 | + |
|
769 | + /** |
|
770 | + * Gets the most recently active version listed in the activation history, |
|
771 | + * and if none are found (ie, it's a brand new install) returns '0.0.0.dev.000'. |
|
772 | + * |
|
773 | + * @param array $activation_history (keys are versions, values are arrays of times activated, |
|
774 | + * sometimes containing 'unknown-date' |
|
775 | + * @return string |
|
776 | + */ |
|
777 | + private static function _get_most_recently_active_version_from_activation_history($activation_history) |
|
778 | + { |
|
779 | + $most_recently_active_version_activation = '1970-01-01 00:00:00'; |
|
780 | + $most_recently_active_version = '0.0.0.dev.000'; |
|
781 | + if (is_array($activation_history)) { |
|
782 | + foreach ($activation_history as $version => $times_activated) { |
|
783 | + // check there is a record of when this version was activated. Otherwise, |
|
784 | + // mark it as unknown |
|
785 | + if (! $times_activated) { |
|
786 | + $times_activated = array('unknown-date'); |
|
787 | + } |
|
788 | + if (is_string($times_activated)) { |
|
789 | + $times_activated = array($times_activated); |
|
790 | + } |
|
791 | + foreach ($times_activated as $an_activation) { |
|
792 | + if ($an_activation !== 'unknown-date' |
|
793 | + && $an_activation |
|
794 | + > $most_recently_active_version_activation) { |
|
795 | + $most_recently_active_version = $version; |
|
796 | + $most_recently_active_version_activation = $an_activation === 'unknown-date' |
|
797 | + ? '1970-01-01 00:00:00' |
|
798 | + : $an_activation; |
|
799 | + } |
|
800 | + } |
|
801 | + } |
|
802 | + } |
|
803 | + return $most_recently_active_version; |
|
804 | + } |
|
805 | + |
|
806 | + |
|
807 | + /** |
|
808 | + * This redirects to the about EE page after activation |
|
809 | + * |
|
810 | + * @return void |
|
811 | + */ |
|
812 | + public function redirect_to_about_ee() |
|
813 | + { |
|
814 | + $notices = EE_Error::get_notices(false); |
|
815 | + // if current user is an admin and it's not an ajax or rest request |
|
816 | + if (! isset($notices['errors']) |
|
817 | + && $this->request->isAdmin() |
|
818 | + && apply_filters( |
|
819 | + 'FHEE__EE_System__redirect_to_about_ee__do_redirect', |
|
820 | + $this->capabilities->current_user_can('manage_options', 'espresso_about_default') |
|
821 | + ) |
|
822 | + ) { |
|
823 | + $query_params = array('page' => 'espresso_about'); |
|
824 | + if (EE_System::instance()->detect_req_type() === EE_System::req_type_new_activation) { |
|
825 | + $query_params['new_activation'] = true; |
|
826 | + } |
|
827 | + if (EE_System::instance()->detect_req_type() === EE_System::req_type_reactivation) { |
|
828 | + $query_params['reactivation'] = true; |
|
829 | + } |
|
830 | + $url = add_query_arg($query_params, admin_url('admin.php')); |
|
831 | + wp_safe_redirect($url); |
|
832 | + exit(); |
|
833 | + } |
|
834 | + } |
|
835 | + |
|
836 | + |
|
837 | + /** |
|
838 | + * load_core_configuration |
|
839 | + * this is hooked into 'AHEE__EE_Bootstrap__load_core_configuration' |
|
840 | + * which runs during the WP 'plugins_loaded' action at priority 5 |
|
841 | + * |
|
842 | + * @return void |
|
843 | + * @throws ReflectionException |
|
844 | + * @throws Exception |
|
845 | + */ |
|
846 | + public function load_core_configuration() |
|
847 | + { |
|
848 | + do_action('AHEE__EE_System__load_core_configuration__begin', $this); |
|
849 | + $this->loader->getShared('EE_Load_Textdomain'); |
|
850 | + // load textdomain |
|
851 | + EE_Load_Textdomain::load_textdomain(); |
|
852 | + // load caf stuff a chance to play during the activation process too. |
|
853 | + $this->_maybe_brew_regular(); |
|
854 | + // load and setup EE_Config and EE_Network_Config |
|
855 | + $config = $this->loader->getShared('EE_Config'); |
|
856 | + $this->loader->getShared('EE_Network_Config'); |
|
857 | + // setup autoloaders |
|
858 | + // enable logging? |
|
859 | + if ($config->admin->use_full_logging) { |
|
860 | + $this->loader->getShared('EE_Log'); |
|
861 | + } |
|
862 | + // check for activation errors |
|
863 | + $activation_errors = get_option('ee_plugin_activation_errors', false); |
|
864 | + if ($activation_errors) { |
|
865 | + EE_Error::add_error($activation_errors, __FILE__, __FUNCTION__, __LINE__); |
|
866 | + update_option('ee_plugin_activation_errors', false); |
|
867 | + } |
|
868 | + // get model names |
|
869 | + $this->_parse_model_names(); |
|
870 | + // configure custom post type definitions |
|
871 | + $this->loader->getShared('EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions'); |
|
872 | + $this->loader->getShared('EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions'); |
|
873 | + do_action('AHEE__EE_System__load_core_configuration__complete', $this); |
|
874 | + } |
|
875 | + |
|
876 | + |
|
877 | + /** |
|
878 | + * cycles through all of the models/*.model.php files, and assembles an array of model names |
|
879 | + * |
|
880 | + * @return void |
|
881 | + * @throws ReflectionException |
|
882 | + */ |
|
883 | + private function _parse_model_names() |
|
884 | + { |
|
885 | + // get all the files in the EE_MODELS folder that end in .model.php |
|
886 | + $models = glob(EE_MODELS . '*.model.php'); |
|
887 | + $model_names = array(); |
|
888 | + $non_abstract_db_models = array(); |
|
889 | + foreach ($models as $model) { |
|
890 | + // get model classname |
|
891 | + $classname = EEH_File::get_classname_from_filepath_with_standard_filename($model); |
|
892 | + $short_name = str_replace('EEM_', '', $classname); |
|
893 | + $reflectionClass = new ReflectionClass($classname); |
|
894 | + if ($reflectionClass->isSubclassOf('EEM_Base') && ! $reflectionClass->isAbstract()) { |
|
895 | + $non_abstract_db_models[ $short_name ] = $classname; |
|
896 | + } |
|
897 | + $model_names[ $short_name ] = $classname; |
|
898 | + } |
|
899 | + $this->registry->models = apply_filters('FHEE__EE_System__parse_model_names', $model_names); |
|
900 | + $this->registry->non_abstract_db_models = apply_filters( |
|
901 | + 'FHEE__EE_System__parse_implemented_model_names', |
|
902 | + $non_abstract_db_models |
|
903 | + ); |
|
904 | + } |
|
905 | + |
|
906 | + |
|
907 | + /** |
|
908 | + * The purpose of this method is to simply check for a file named "caffeinated/brewing_regular.php" for any hooks |
|
909 | + * that need to be setup before our EE_System launches. |
|
910 | + * |
|
911 | + * @return void |
|
912 | + * @throws DomainException |
|
913 | + * @throws InvalidArgumentException |
|
914 | + * @throws InvalidDataTypeException |
|
915 | + * @throws InvalidInterfaceException |
|
916 | + * @throws InvalidClassException |
|
917 | + * @throws InvalidFilePathException |
|
918 | + */ |
|
919 | + private function _maybe_brew_regular() |
|
920 | + { |
|
921 | + /** @var Domain $domain */ |
|
922 | + $domain = DomainFactory::getShared( |
|
923 | + new FullyQualifiedName( |
|
924 | + 'EventEspresso\core\domain\Domain' |
|
925 | + ), |
|
926 | + array( |
|
927 | + new FilePath(EVENT_ESPRESSO_MAIN_FILE), |
|
928 | + Version::fromString(espresso_version()), |
|
929 | + ) |
|
930 | + ); |
|
931 | + if ($domain->isCaffeinated()) { |
|
932 | + require_once EE_CAFF_PATH . 'brewing_regular.php'; |
|
933 | + } |
|
934 | + } |
|
935 | + |
|
936 | + |
|
937 | + /** |
|
938 | + * @since 4.9.71.p |
|
939 | + * @throws Exception |
|
940 | + */ |
|
941 | + public function loadRouteMatchSpecifications() |
|
942 | + { |
|
943 | + try { |
|
944 | + $this->loader->getShared( |
|
945 | + 'EventEspresso\core\services\route_match\RouteMatchSpecificationManager' |
|
946 | + ); |
|
947 | + } catch (Exception $exception) { |
|
948 | + new ExceptionStackTraceDisplay($exception); |
|
949 | + } |
|
950 | + do_action('AHEE__EE_System__loadRouteMatchSpecifications'); |
|
951 | + } |
|
952 | + |
|
953 | + |
|
954 | + /** |
|
955 | + * register_shortcodes_modules_and_widgets |
|
956 | + * generate lists of shortcodes and modules, then verify paths and classes |
|
957 | + * This is hooked into 'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets' |
|
958 | + * which runs during the WP 'plugins_loaded' action at priority 7 |
|
959 | + * |
|
960 | + * @access public |
|
961 | + * @return void |
|
962 | + * @throws Exception |
|
963 | + */ |
|
964 | + public function register_shortcodes_modules_and_widgets() |
|
965 | + { |
|
966 | + if ($this->request->isFrontend() || $this->request->isIframe() || $this->request->isAjax()) { |
|
967 | + try { |
|
968 | + // load, register, and add shortcodes the new way |
|
969 | + $this->loader->getShared( |
|
970 | + 'EventEspresso\core\services\shortcodes\ShortcodesManager', |
|
971 | + array( |
|
972 | + // and the old way, but we'll put it under control of the new system |
|
973 | + EE_Config::getLegacyShortcodesManager(), |
|
974 | + ) |
|
975 | + ); |
|
976 | + } catch (Exception $exception) { |
|
977 | + new ExceptionStackTraceDisplay($exception); |
|
978 | + } |
|
979 | + } |
|
980 | + do_action('AHEE__EE_System__register_shortcodes_modules_and_widgets'); |
|
981 | + // check for addons using old hook point |
|
982 | + if (has_action('AHEE__EE_System__register_shortcodes_modules_and_addons')) { |
|
983 | + $this->_incompatible_addon_error(); |
|
984 | + } |
|
985 | + } |
|
986 | + |
|
987 | + |
|
988 | + /** |
|
989 | + * _incompatible_addon_error |
|
990 | + * |
|
991 | + * @access public |
|
992 | + * @return void |
|
993 | + */ |
|
994 | + private function _incompatible_addon_error() |
|
995 | + { |
|
996 | + // get array of classes hooking into here |
|
997 | + $class_names = EEH_Class_Tools::get_class_names_for_all_callbacks_on_hook( |
|
998 | + 'AHEE__EE_System__register_shortcodes_modules_and_addons' |
|
999 | + ); |
|
1000 | + if (! empty($class_names)) { |
|
1001 | + $msg = __( |
|
1002 | + 'The following plugins, addons, or modules appear to be incompatible with this version of Event Espresso and were automatically deactivated to avoid fatal errors:', |
|
1003 | + 'event_espresso' |
|
1004 | + ); |
|
1005 | + $msg .= '<ul>'; |
|
1006 | + foreach ($class_names as $class_name) { |
|
1007 | + $msg .= '<li><b>Event Espresso - ' |
|
1008 | + . str_replace( |
|
1009 | + array('EE_', 'EEM_', 'EED_', 'EES_', 'EEW_'), |
|
1010 | + '', |
|
1011 | + $class_name |
|
1012 | + ) . '</b></li>'; |
|
1013 | + } |
|
1014 | + $msg .= '</ul>'; |
|
1015 | + $msg .= __( |
|
1016 | + 'Compatibility issues can be avoided and/or resolved by keeping addons and plugins updated to the latest version.', |
|
1017 | + 'event_espresso' |
|
1018 | + ); |
|
1019 | + // save list of incompatible addons to wp-options for later use |
|
1020 | + add_option('ee_incompatible_addons', $class_names, '', 'no'); |
|
1021 | + if (is_admin()) { |
|
1022 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
1023 | + } |
|
1024 | + } |
|
1025 | + } |
|
1026 | + |
|
1027 | + |
|
1028 | + /** |
|
1029 | + * brew_espresso |
|
1030 | + * begins the process of setting hooks for initializing EE in the correct order |
|
1031 | + * This is happening on the 'AHEE__EE_Bootstrap__brew_espresso' hook point |
|
1032 | + * which runs during the WP 'plugins_loaded' action at priority 9 |
|
1033 | + * |
|
1034 | + * @return void |
|
1035 | + */ |
|
1036 | + public function brew_espresso() |
|
1037 | + { |
|
1038 | + do_action('AHEE__EE_System__brew_espresso__begin', $this); |
|
1039 | + // load some final core systems |
|
1040 | + add_action('init', array($this, 'set_hooks_for_core'), 1); |
|
1041 | + add_action('init', array($this, 'perform_activations_upgrades_and_migrations'), 3); |
|
1042 | + add_action('init', array($this, 'load_CPTs_and_session'), 5); |
|
1043 | + add_action('init', array($this, 'load_controllers'), 7); |
|
1044 | + add_action('init', array($this, 'core_loaded_and_ready'), 9); |
|
1045 | + add_action('init', array($this, 'initialize'), 10); |
|
1046 | + add_action('init', array($this, 'initialize_last'), 100); |
|
1047 | + if (is_admin() && apply_filters('FHEE__EE_System__brew_espresso__load_pue', true)) { |
|
1048 | + // pew pew pew |
|
1049 | + $this->loader->getShared('EventEspresso\core\services\licensing\LicenseService'); |
|
1050 | + do_action('AHEE__EE_System__brew_espresso__after_pue_init'); |
|
1051 | + } |
|
1052 | + do_action('AHEE__EE_System__brew_espresso__complete', $this); |
|
1053 | + } |
|
1054 | + |
|
1055 | + |
|
1056 | + /** |
|
1057 | + * set_hooks_for_core |
|
1058 | + * |
|
1059 | + * @access public |
|
1060 | + * @return void |
|
1061 | + * @throws EE_Error |
|
1062 | + */ |
|
1063 | + public function set_hooks_for_core() |
|
1064 | + { |
|
1065 | + $this->_deactivate_incompatible_addons(); |
|
1066 | + do_action('AHEE__EE_System__set_hooks_for_core'); |
|
1067 | + $this->loader->getShared('EventEspresso\core\domain\values\session\SessionLifespan'); |
|
1068 | + // caps need to be initialized on every request so that capability maps are set. |
|
1069 | + // @see https://events.codebasehq.com/projects/event-espresso/tickets/8674 |
|
1070 | + $this->registry->CAP->init_caps(); |
|
1071 | + } |
|
1072 | + |
|
1073 | + |
|
1074 | + /** |
|
1075 | + * Using the information gathered in EE_System::_incompatible_addon_error, |
|
1076 | + * deactivates any addons considered incompatible with the current version of EE |
|
1077 | + */ |
|
1078 | + private function _deactivate_incompatible_addons() |
|
1079 | + { |
|
1080 | + $incompatible_addons = get_option('ee_incompatible_addons', array()); |
|
1081 | + if (! empty($incompatible_addons)) { |
|
1082 | + $active_plugins = get_option('active_plugins', array()); |
|
1083 | + foreach ($active_plugins as $active_plugin) { |
|
1084 | + foreach ($incompatible_addons as $incompatible_addon) { |
|
1085 | + if (strpos($active_plugin, $incompatible_addon) !== false) { |
|
1086 | + unset($_GET['activate']); |
|
1087 | + espresso_deactivate_plugin($active_plugin); |
|
1088 | + } |
|
1089 | + } |
|
1090 | + } |
|
1091 | + } |
|
1092 | + } |
|
1093 | + |
|
1094 | + |
|
1095 | + /** |
|
1096 | + * perform_activations_upgrades_and_migrations |
|
1097 | + * |
|
1098 | + * @access public |
|
1099 | + * @return void |
|
1100 | + */ |
|
1101 | + public function perform_activations_upgrades_and_migrations() |
|
1102 | + { |
|
1103 | + do_action('AHEE__EE_System__perform_activations_upgrades_and_migrations'); |
|
1104 | + } |
|
1105 | + |
|
1106 | + |
|
1107 | + /** |
|
1108 | + * @return void |
|
1109 | + * @throws DomainException |
|
1110 | + */ |
|
1111 | + public function load_CPTs_and_session() |
|
1112 | + { |
|
1113 | + do_action('AHEE__EE_System__load_CPTs_and_session__start'); |
|
1114 | + /** @var EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomies $register_custom_taxonomies */ |
|
1115 | + $register_custom_taxonomies = $this->loader->getShared( |
|
1116 | + 'EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomies' |
|
1117 | + ); |
|
1118 | + $register_custom_taxonomies->registerCustomTaxonomies(); |
|
1119 | + /** @var EventEspresso\core\domain\services\custom_post_types\RegisterCustomPostTypes $register_custom_post_types */ |
|
1120 | + $register_custom_post_types = $this->loader->getShared( |
|
1121 | + 'EventEspresso\core\domain\services\custom_post_types\RegisterCustomPostTypes' |
|
1122 | + ); |
|
1123 | + $register_custom_post_types->registerCustomPostTypes(); |
|
1124 | + /** @var EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomyTerms $register_custom_taxonomy_terms */ |
|
1125 | + $register_custom_taxonomy_terms = $this->loader->getShared( |
|
1126 | + 'EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomyTerms' |
|
1127 | + ); |
|
1128 | + $register_custom_taxonomy_terms->registerCustomTaxonomyTerms(); |
|
1129 | + // load legacy Custom Post Types and Taxonomies |
|
1130 | + $this->loader->getShared('EE_Register_CPTs'); |
|
1131 | + do_action('AHEE__EE_System__load_CPTs_and_session__complete'); |
|
1132 | + } |
|
1133 | + |
|
1134 | + |
|
1135 | + /** |
|
1136 | + * load_controllers |
|
1137 | + * this is the best place to load any additional controllers that needs access to EE core. |
|
1138 | + * it is expected that all basic core EE systems, that are not dependant on the current request are loaded at this |
|
1139 | + * time |
|
1140 | + * |
|
1141 | + * @access public |
|
1142 | + * @return void |
|
1143 | + */ |
|
1144 | + public function load_controllers() |
|
1145 | + { |
|
1146 | + do_action('AHEE__EE_System__load_controllers__start'); |
|
1147 | + // let's get it started |
|
1148 | + if (! $this->maintenance_mode->level() |
|
1149 | + && ($this->request->isFrontend() || $this->request->isFrontAjax()) |
|
1150 | + ) { |
|
1151 | + do_action('AHEE__EE_System__load_controllers__load_front_controllers'); |
|
1152 | + $this->loader->getShared('EE_Front_Controller'); |
|
1153 | + } elseif ($this->request->isAdmin() || $this->request->isAdminAjax()) { |
|
1154 | + do_action('AHEE__EE_System__load_controllers__load_admin_controllers'); |
|
1155 | + $this->loader->getShared('EE_Admin'); |
|
1156 | + } elseif ($this->request->isWordPressHeartbeat()) { |
|
1157 | + $this->loader->getShared('EventEspresso\core\domain\services\admin\ajax\WordpressHeartbeat'); |
|
1158 | + } |
|
1159 | + do_action('AHEE__EE_System__load_controllers__complete'); |
|
1160 | + } |
|
1161 | + |
|
1162 | + |
|
1163 | + /** |
|
1164 | + * core_loaded_and_ready |
|
1165 | + * all of the basic EE core should be loaded at this point and available regardless of M-Mode |
|
1166 | + * |
|
1167 | + * @access public |
|
1168 | + * @return void |
|
1169 | + * @throws Exception |
|
1170 | + */ |
|
1171 | + public function core_loaded_and_ready() |
|
1172 | + { |
|
1173 | + if ($this->request->isAdmin() |
|
1174 | + || $this->request->isFrontend() |
|
1175 | + || $this->request->isIframe() |
|
1176 | + || $this->request->isWordPressApi() |
|
1177 | + ) { |
|
1178 | + try { |
|
1179 | + $this->loader->getShared('EventEspresso\core\services\assets\Registry'); |
|
1180 | + $this->loader->getShared('EventEspresso\core\domain\services\assets\CoreAssetManager'); |
|
1181 | + if ($this->canLoadBlocks()) { |
|
1182 | + $this->loader->getShared( |
|
1183 | + 'EventEspresso\core\services\editor\BlockRegistrationManager' |
|
1184 | + ); |
|
1185 | + } |
|
1186 | + } catch (Exception $exception) { |
|
1187 | + new ExceptionStackTraceDisplay($exception); |
|
1188 | + } |
|
1189 | + } |
|
1190 | + if ($this->request->isAdmin() |
|
1191 | + || $this->request->isEeAjax() |
|
1192 | + || $this->request->isFrontend() |
|
1193 | + ) { |
|
1194 | + $this->loader->getShared('EE_Session'); |
|
1195 | + } |
|
1196 | + // integrate WP_Query with the EE models |
|
1197 | + $this->loader->getShared('EE_CPT_Strategy'); |
|
1198 | + do_action('AHEE__EE_System__core_loaded_and_ready'); |
|
1199 | + // always load template tags, because it's faster than checking if it's a front-end request, and many page |
|
1200 | + // builders require these even on the front-end |
|
1201 | + require_once EE_PUBLIC . 'template_tags.php'; |
|
1202 | + do_action('AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons'); |
|
1203 | + } |
|
1204 | + |
|
1205 | + |
|
1206 | + /** |
|
1207 | + * initialize |
|
1208 | + * this is the best place to begin initializing client code |
|
1209 | + * |
|
1210 | + * @access public |
|
1211 | + * @return void |
|
1212 | + */ |
|
1213 | + public function initialize() |
|
1214 | + { |
|
1215 | + do_action('AHEE__EE_System__initialize'); |
|
1216 | + } |
|
1217 | + |
|
1218 | + |
|
1219 | + /** |
|
1220 | + * initialize_last |
|
1221 | + * this is run really late during the WP init hook point, and ensures that mostly everything else that needs to |
|
1222 | + * initialize has done so |
|
1223 | + * |
|
1224 | + * @access public |
|
1225 | + * @return void |
|
1226 | + */ |
|
1227 | + public function initialize_last() |
|
1228 | + { |
|
1229 | + do_action('AHEE__EE_System__initialize_last'); |
|
1230 | + /** @var EventEspresso\core\domain\services\custom_post_types\RewriteRules $rewrite_rules */ |
|
1231 | + $rewrite_rules = $this->loader->getShared( |
|
1232 | + 'EventEspresso\core\domain\services\custom_post_types\RewriteRules' |
|
1233 | + ); |
|
1234 | + $rewrite_rules->flushRewriteRules(); |
|
1235 | + add_action('admin_bar_init', array($this, 'addEspressoToolbar')); |
|
1236 | + if (($this->request->isAjax() || $this->request->isAdmin()) |
|
1237 | + && $this->maintenance_mode->models_can_query()) { |
|
1238 | + $this->loader->getShared('EventEspresso\core\services\privacy\export\PersonalDataExporterManager'); |
|
1239 | + $this->loader->getShared('EventEspresso\core\services\privacy\erasure\PersonalDataEraserManager'); |
|
1240 | + } |
|
1241 | + } |
|
1242 | + |
|
1243 | + |
|
1244 | + /** |
|
1245 | + * @return void |
|
1246 | + * @throws EE_Error |
|
1247 | + */ |
|
1248 | + public function addEspressoToolbar() |
|
1249 | + { |
|
1250 | + $this->loader->getShared( |
|
1251 | + 'EventEspresso\core\domain\services\admin\AdminToolBar', |
|
1252 | + array($this->registry->CAP) |
|
1253 | + ); |
|
1254 | + } |
|
1255 | + |
|
1256 | + |
|
1257 | + /** |
|
1258 | + * do_not_cache |
|
1259 | + * sets no cache headers and defines no cache constants for WP plugins |
|
1260 | + * |
|
1261 | + * @access public |
|
1262 | + * @return void |
|
1263 | + */ |
|
1264 | + public static function do_not_cache() |
|
1265 | + { |
|
1266 | + // set no cache constants |
|
1267 | + if (! defined('DONOTCACHEPAGE')) { |
|
1268 | + define('DONOTCACHEPAGE', true); |
|
1269 | + } |
|
1270 | + if (! defined('DONOTCACHCEOBJECT')) { |
|
1271 | + define('DONOTCACHCEOBJECT', true); |
|
1272 | + } |
|
1273 | + if (! defined('DONOTCACHEDB')) { |
|
1274 | + define('DONOTCACHEDB', true); |
|
1275 | + } |
|
1276 | + // add no cache headers |
|
1277 | + add_action('send_headers', array('EE_System', 'nocache_headers'), 10); |
|
1278 | + // plus a little extra for nginx and Google Chrome |
|
1279 | + add_filter('nocache_headers', array('EE_System', 'extra_nocache_headers'), 10, 1); |
|
1280 | + // prevent browsers from prefetching of the rel='next' link, because it may contain content that interferes with the registration process |
|
1281 | + remove_action('wp_head', 'adjacent_posts_rel_link_wp_head'); |
|
1282 | + } |
|
1283 | + |
|
1284 | + |
|
1285 | + /** |
|
1286 | + * extra_nocache_headers |
|
1287 | + * |
|
1288 | + * @access public |
|
1289 | + * @param $headers |
|
1290 | + * @return array |
|
1291 | + */ |
|
1292 | + public static function extra_nocache_headers($headers) |
|
1293 | + { |
|
1294 | + // for NGINX |
|
1295 | + $headers['X-Accel-Expires'] = 0; |
|
1296 | + // plus extra for Google Chrome since it doesn't seem to respect "no-cache", but WILL respect "no-store" |
|
1297 | + $headers['Cache-Control'] = 'no-store, no-cache, must-revalidate, max-age=0'; |
|
1298 | + return $headers; |
|
1299 | + } |
|
1300 | + |
|
1301 | + |
|
1302 | + /** |
|
1303 | + * nocache_headers |
|
1304 | + * |
|
1305 | + * @access public |
|
1306 | + * @return void |
|
1307 | + */ |
|
1308 | + public static function nocache_headers() |
|
1309 | + { |
|
1310 | + nocache_headers(); |
|
1311 | + } |
|
1312 | + |
|
1313 | + |
|
1314 | + /** |
|
1315 | + * simply hooks into "wp_list_pages_exclude" filter (for wp_list_pages method) and makes sure EE critical pages are |
|
1316 | + * never returned with the function. |
|
1317 | + * |
|
1318 | + * @param array $exclude_array any existing pages being excluded are in this array. |
|
1319 | + * @return array |
|
1320 | + */ |
|
1321 | + public function remove_pages_from_wp_list_pages($exclude_array) |
|
1322 | + { |
|
1323 | + return array_merge($exclude_array, $this->registry->CFG->core->get_critical_pages_array()); |
|
1324 | + } |
|
1325 | + |
|
1326 | + |
|
1327 | + /** |
|
1328 | + * Return whether blocks can be registered/loaded or not. |
|
1329 | + * @return bool |
|
1330 | + */ |
|
1331 | + private function canLoadBlocks() |
|
1332 | + { |
|
1333 | + return apply_filters('FHEE__EE_System__canLoadBlocks', true) |
|
1334 | + && function_exists('register_block_type') |
|
1335 | + // don't load blocks if in the Divi page builder editor context |
|
1336 | + // @see https://github.com/eventespresso/event-espresso-core/issues/814 |
|
1337 | + && ! $this->request->getRequestParam('et_fb', false); |
|
1338 | + } |
|
1339 | 1339 | } |
@@ -141,7 +141,7 @@ discard block |
||
141 | 141 | EE_Maintenance_Mode $maintenance_mode = null |
142 | 142 | ) { |
143 | 143 | // check if class object is instantiated |
144 | - if (! self::$_instance instanceof EE_System) { |
|
144 | + if ( ! self::$_instance instanceof EE_System) { |
|
145 | 145 | self::$_instance = new self($registry, $loader, $request, $maintenance_mode); |
146 | 146 | } |
147 | 147 | return self::$_instance; |
@@ -263,7 +263,7 @@ discard block |
||
263 | 263 | $this->capabilities = $this->loader->getShared('EE_Capabilities'); |
264 | 264 | add_action( |
265 | 265 | 'AHEE__EE_Capabilities__init_caps__before_initialization', |
266 | - function () { |
|
266 | + function() { |
|
267 | 267 | LoaderFactory::getLoader()->getShared('EE_Payment_Method_Manager'); |
268 | 268 | } |
269 | 269 | ); |
@@ -304,7 +304,7 @@ discard block |
||
304 | 304 | { |
305 | 305 | // set autoloaders for all of the classes implementing EEI_Plugin_API |
306 | 306 | // which provide helpers for EE plugin authors to more easily register certain components with EE. |
307 | - EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'plugin_api'); |
|
307 | + EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_LIBRARIES.'plugin_api'); |
|
308 | 308 | $this->loader->getShared('EE_Request_Handler'); |
309 | 309 | } |
310 | 310 | |
@@ -324,14 +324,14 @@ discard block |
||
324 | 324 | $load_callback, |
325 | 325 | $plugin_file_constant |
326 | 326 | ) { |
327 | - if (! defined($version_constant)) { |
|
327 | + if ( ! defined($version_constant)) { |
|
328 | 328 | return; |
329 | 329 | } |
330 | 330 | $addon_version = constant($version_constant); |
331 | 331 | if ($addon_version && version_compare($addon_version, $min_version_required, '<')) { |
332 | 332 | remove_action('AHEE__EE_System__load_espresso_addons', $load_callback); |
333 | - if (! function_exists('deactivate_plugins')) { |
|
334 | - require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
333 | + if ( ! function_exists('deactivate_plugins')) { |
|
334 | + require_once ABSPATH.'wp-admin/includes/plugin.php'; |
|
335 | 335 | } |
336 | 336 | deactivate_plugins(plugin_basename(constant($plugin_file_constant))); |
337 | 337 | unset($_GET['activate'], $_REQUEST['activate'], $_GET['activate-multi'], $_REQUEST['activate-multi']); |
@@ -345,7 +345,7 @@ discard block |
||
345 | 345 | $min_version_required |
346 | 346 | ), |
347 | 347 | __FILE__, |
348 | - __FUNCTION__ . "({$addon_name})", |
|
348 | + __FUNCTION__."({$addon_name})", |
|
349 | 349 | __LINE__ |
350 | 350 | ); |
351 | 351 | EE_Error::get_notices(false, true); |
@@ -396,7 +396,7 @@ discard block |
||
396 | 396 | true |
397 | 397 | ) |
398 | 398 | ) { |
399 | - include_once EE_THIRD_PARTY . 'wp-api-basic-auth/basic-auth.php'; |
|
399 | + include_once EE_THIRD_PARTY.'wp-api-basic-auth/basic-auth.php'; |
|
400 | 400 | } |
401 | 401 | do_action('AHEE__EE_System__load_espresso_addons__complete'); |
402 | 402 | } |
@@ -498,11 +498,11 @@ discard block |
||
498 | 498 | private function fix_espresso_db_upgrade_option($espresso_db_update = null) |
499 | 499 | { |
500 | 500 | do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__begin', $espresso_db_update); |
501 | - if (! $espresso_db_update) { |
|
501 | + if ( ! $espresso_db_update) { |
|
502 | 502 | $espresso_db_update = get_option('espresso_db_update'); |
503 | 503 | } |
504 | 504 | // check that option is an array |
505 | - if (! is_array($espresso_db_update)) { |
|
505 | + if ( ! is_array($espresso_db_update)) { |
|
506 | 506 | // if option is FALSE, then it never existed |
507 | 507 | if ($espresso_db_update === false) { |
508 | 508 | // make $espresso_db_update an array and save option with autoload OFF |
@@ -522,10 +522,10 @@ discard block |
||
522 | 522 | // so it must be numerically-indexed, where values are versions installed... |
523 | 523 | // fix it! |
524 | 524 | $version_string = $should_be_array; |
525 | - $corrected_db_update[ $version_string ] = array('unknown-date'); |
|
525 | + $corrected_db_update[$version_string] = array('unknown-date'); |
|
526 | 526 | } else { |
527 | 527 | // ok it checks out |
528 | - $corrected_db_update[ $should_be_version_string ] = $should_be_array; |
|
528 | + $corrected_db_update[$should_be_version_string] = $should_be_array; |
|
529 | 529 | } |
530 | 530 | } |
531 | 531 | $espresso_db_update = $corrected_db_update; |
@@ -608,13 +608,13 @@ discard block |
||
608 | 608 | */ |
609 | 609 | public function update_list_of_installed_versions($version_history = null, $current_version_to_add = null) |
610 | 610 | { |
611 | - if (! $version_history) { |
|
611 | + if ( ! $version_history) { |
|
612 | 612 | $version_history = $this->fix_espresso_db_upgrade_option($version_history); |
613 | 613 | } |
614 | 614 | if ($current_version_to_add === null) { |
615 | 615 | $current_version_to_add = espresso_version(); |
616 | 616 | } |
617 | - $version_history[ $current_version_to_add ][] = date('Y-m-d H:i:s', time()); |
|
617 | + $version_history[$current_version_to_add][] = date('Y-m-d H:i:s', time()); |
|
618 | 618 | // re-save |
619 | 619 | return update_option('espresso_db_update', $version_history); |
620 | 620 | } |
@@ -704,7 +704,7 @@ discard block |
||
704 | 704 | if ($activation_history_for_addon) { |
705 | 705 | // it exists, so this isn't a completely new install |
706 | 706 | // check if this version already in that list of previously installed versions |
707 | - if (! isset($activation_history_for_addon[ $version_to_upgrade_to ])) { |
|
707 | + if ( ! isset($activation_history_for_addon[$version_to_upgrade_to])) { |
|
708 | 708 | // it a version we haven't seen before |
709 | 709 | if ($version_is_higher === 1) { |
710 | 710 | $req_type = EE_System::req_type_upgrade; |
@@ -782,7 +782,7 @@ discard block |
||
782 | 782 | foreach ($activation_history as $version => $times_activated) { |
783 | 783 | // check there is a record of when this version was activated. Otherwise, |
784 | 784 | // mark it as unknown |
785 | - if (! $times_activated) { |
|
785 | + if ( ! $times_activated) { |
|
786 | 786 | $times_activated = array('unknown-date'); |
787 | 787 | } |
788 | 788 | if (is_string($times_activated)) { |
@@ -813,7 +813,7 @@ discard block |
||
813 | 813 | { |
814 | 814 | $notices = EE_Error::get_notices(false); |
815 | 815 | // if current user is an admin and it's not an ajax or rest request |
816 | - if (! isset($notices['errors']) |
|
816 | + if ( ! isset($notices['errors']) |
|
817 | 817 | && $this->request->isAdmin() |
818 | 818 | && apply_filters( |
819 | 819 | 'FHEE__EE_System__redirect_to_about_ee__do_redirect', |
@@ -883,7 +883,7 @@ discard block |
||
883 | 883 | private function _parse_model_names() |
884 | 884 | { |
885 | 885 | // get all the files in the EE_MODELS folder that end in .model.php |
886 | - $models = glob(EE_MODELS . '*.model.php'); |
|
886 | + $models = glob(EE_MODELS.'*.model.php'); |
|
887 | 887 | $model_names = array(); |
888 | 888 | $non_abstract_db_models = array(); |
889 | 889 | foreach ($models as $model) { |
@@ -892,9 +892,9 @@ discard block |
||
892 | 892 | $short_name = str_replace('EEM_', '', $classname); |
893 | 893 | $reflectionClass = new ReflectionClass($classname); |
894 | 894 | if ($reflectionClass->isSubclassOf('EEM_Base') && ! $reflectionClass->isAbstract()) { |
895 | - $non_abstract_db_models[ $short_name ] = $classname; |
|
895 | + $non_abstract_db_models[$short_name] = $classname; |
|
896 | 896 | } |
897 | - $model_names[ $short_name ] = $classname; |
|
897 | + $model_names[$short_name] = $classname; |
|
898 | 898 | } |
899 | 899 | $this->registry->models = apply_filters('FHEE__EE_System__parse_model_names', $model_names); |
900 | 900 | $this->registry->non_abstract_db_models = apply_filters( |
@@ -929,7 +929,7 @@ discard block |
||
929 | 929 | ) |
930 | 930 | ); |
931 | 931 | if ($domain->isCaffeinated()) { |
932 | - require_once EE_CAFF_PATH . 'brewing_regular.php'; |
|
932 | + require_once EE_CAFF_PATH.'brewing_regular.php'; |
|
933 | 933 | } |
934 | 934 | } |
935 | 935 | |
@@ -997,7 +997,7 @@ discard block |
||
997 | 997 | $class_names = EEH_Class_Tools::get_class_names_for_all_callbacks_on_hook( |
998 | 998 | 'AHEE__EE_System__register_shortcodes_modules_and_addons' |
999 | 999 | ); |
1000 | - if (! empty($class_names)) { |
|
1000 | + if ( ! empty($class_names)) { |
|
1001 | 1001 | $msg = __( |
1002 | 1002 | 'The following plugins, addons, or modules appear to be incompatible with this version of Event Espresso and were automatically deactivated to avoid fatal errors:', |
1003 | 1003 | 'event_espresso' |
@@ -1009,7 +1009,7 @@ discard block |
||
1009 | 1009 | array('EE_', 'EEM_', 'EED_', 'EES_', 'EEW_'), |
1010 | 1010 | '', |
1011 | 1011 | $class_name |
1012 | - ) . '</b></li>'; |
|
1012 | + ).'</b></li>'; |
|
1013 | 1013 | } |
1014 | 1014 | $msg .= '</ul>'; |
1015 | 1015 | $msg .= __( |
@@ -1078,7 +1078,7 @@ discard block |
||
1078 | 1078 | private function _deactivate_incompatible_addons() |
1079 | 1079 | { |
1080 | 1080 | $incompatible_addons = get_option('ee_incompatible_addons', array()); |
1081 | - if (! empty($incompatible_addons)) { |
|
1081 | + if ( ! empty($incompatible_addons)) { |
|
1082 | 1082 | $active_plugins = get_option('active_plugins', array()); |
1083 | 1083 | foreach ($active_plugins as $active_plugin) { |
1084 | 1084 | foreach ($incompatible_addons as $incompatible_addon) { |
@@ -1145,7 +1145,7 @@ discard block |
||
1145 | 1145 | { |
1146 | 1146 | do_action('AHEE__EE_System__load_controllers__start'); |
1147 | 1147 | // let's get it started |
1148 | - if (! $this->maintenance_mode->level() |
|
1148 | + if ( ! $this->maintenance_mode->level() |
|
1149 | 1149 | && ($this->request->isFrontend() || $this->request->isFrontAjax()) |
1150 | 1150 | ) { |
1151 | 1151 | do_action('AHEE__EE_System__load_controllers__load_front_controllers'); |
@@ -1198,7 +1198,7 @@ discard block |
||
1198 | 1198 | do_action('AHEE__EE_System__core_loaded_and_ready'); |
1199 | 1199 | // always load template tags, because it's faster than checking if it's a front-end request, and many page |
1200 | 1200 | // builders require these even on the front-end |
1201 | - require_once EE_PUBLIC . 'template_tags.php'; |
|
1201 | + require_once EE_PUBLIC.'template_tags.php'; |
|
1202 | 1202 | do_action('AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons'); |
1203 | 1203 | } |
1204 | 1204 | |
@@ -1264,13 +1264,13 @@ discard block |
||
1264 | 1264 | public static function do_not_cache() |
1265 | 1265 | { |
1266 | 1266 | // set no cache constants |
1267 | - if (! defined('DONOTCACHEPAGE')) { |
|
1267 | + if ( ! defined('DONOTCACHEPAGE')) { |
|
1268 | 1268 | define('DONOTCACHEPAGE', true); |
1269 | 1269 | } |
1270 | - if (! defined('DONOTCACHCEOBJECT')) { |
|
1270 | + if ( ! defined('DONOTCACHCEOBJECT')) { |
|
1271 | 1271 | define('DONOTCACHCEOBJECT', true); |
1272 | 1272 | } |
1273 | - if (! defined('DONOTCACHEDB')) { |
|
1273 | + if ( ! defined('DONOTCACHEDB')) { |
|
1274 | 1274 | define('DONOTCACHEDB', true); |
1275 | 1275 | } |
1276 | 1276 | // add no cache headers |
@@ -10,609 +10,609 @@ discard block |
||
10 | 10 | class EED_Thank_You_Page extends EED_Module |
11 | 11 | { |
12 | 12 | |
13 | - /** |
|
14 | - * time in seconds to wait for the IPN to arrive before telling the registrant to bugger off ( 1200s = 20 minutes ) |
|
15 | - */ |
|
16 | - const IPN_wait_time = 1200; |
|
17 | - |
|
18 | - /** |
|
19 | - * The transaction specified by the reg_url_link passed from the Request, or from the Session |
|
20 | - * |
|
21 | - * @var EE_Transaction $_current_txn |
|
22 | - */ |
|
23 | - private $_current_txn; |
|
24 | - |
|
25 | - /** |
|
26 | - * @var EE_Registration $_primary_registrant |
|
27 | - */ |
|
28 | - private $_primary_registrant; |
|
29 | - |
|
30 | - /** |
|
31 | - * The reg_url_link passed from the Request, or from the Session |
|
32 | - * |
|
33 | - * @var string $_reg_url_link |
|
34 | - */ |
|
35 | - private $_reg_url_link; |
|
36 | - |
|
37 | - /** |
|
38 | - * whether the incoming reg_url_link is for the primary registrant or not |
|
39 | - * |
|
40 | - * @var boolean $_is_primary |
|
41 | - */ |
|
42 | - private $_is_primary; |
|
43 | - |
|
44 | - /** |
|
45 | - * The URL for revisiting the SPCO attendee information step |
|
46 | - * |
|
47 | - * @var string $_SPCO_attendee_information_url |
|
48 | - */ |
|
49 | - private $_SPCO_attendee_information_url; |
|
50 | - |
|
51 | - /** |
|
52 | - * The URL for revisiting the SPCO payment options step |
|
53 | - * |
|
54 | - * @var string $_SPCO_payment_options_url |
|
55 | - */ |
|
56 | - private $_SPCO_payment_options_url; |
|
57 | - |
|
58 | - /** |
|
59 | - * whether to display the Payment Options link |
|
60 | - * |
|
61 | - * @var boolean $_show_try_pay_again_link |
|
62 | - */ |
|
63 | - private $_show_try_pay_again_link = false; |
|
64 | - |
|
65 | - /** |
|
66 | - * whether payments are allowed at this time |
|
67 | - * |
|
68 | - * @var boolean $_payments_closed |
|
69 | - */ |
|
70 | - private $_payments_closed = false; |
|
71 | - |
|
72 | - /** |
|
73 | - * whether the selected payment method is Bank, Check , Invoice, etc |
|
74 | - * |
|
75 | - * @var boolean $_is_offline_payment_method |
|
76 | - */ |
|
77 | - private $_is_offline_payment_method = true; |
|
78 | - |
|
79 | - |
|
80 | - /** |
|
81 | - * @return EED_Module|EED_Thank_You_Page |
|
82 | - */ |
|
83 | - public static function instance() |
|
84 | - { |
|
85 | - return parent::get_instance(__CLASS__); |
|
86 | - } |
|
87 | - |
|
88 | - |
|
89 | - /** |
|
90 | - * set_hooks - for hooking into EE Core, modules, etc |
|
91 | - * |
|
92 | - * @return void |
|
93 | - */ |
|
94 | - public static function set_hooks() |
|
95 | - { |
|
96 | - add_action('wp_loaded', array('EED_Thank_You_Page', 'set_definitions'), 2); |
|
97 | - } |
|
98 | - |
|
99 | - |
|
100 | - /** |
|
101 | - * set_hooks_admin - for hooking into EE Admin Core, modules, etc |
|
102 | - * |
|
103 | - * @return void |
|
104 | - */ |
|
105 | - public static function set_hooks_admin() |
|
106 | - { |
|
107 | - add_action( |
|
108 | - 'wp_ajax_espresso_resend_reg_confirmation_email', |
|
109 | - array('EED_Thank_You_Page', 'resend_reg_confirmation_email'), |
|
110 | - 10, |
|
111 | - 2 |
|
112 | - ); |
|
113 | - add_action( |
|
114 | - 'wp_ajax_nopriv_espresso_resend_reg_confirmation_email', |
|
115 | - array('EED_Thank_You_Page', 'resend_reg_confirmation_email'), |
|
116 | - 10, |
|
117 | - 2 |
|
118 | - ); |
|
119 | - } |
|
120 | - |
|
121 | - |
|
122 | - /** |
|
123 | - * set_definitions |
|
124 | - * |
|
125 | - * @return void |
|
126 | - */ |
|
127 | - public static function set_definitions() |
|
128 | - { |
|
129 | - define('THANK_YOU_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets/'); |
|
130 | - define('THANK_YOU_TEMPLATES_PATH', str_replace('\\', '/', plugin_dir_path(__FILE__)) . 'templates/'); |
|
131 | - } |
|
132 | - |
|
133 | - |
|
134 | - /** |
|
135 | - * get_txn |
|
136 | - * |
|
137 | - * @return EE_Transaction |
|
138 | - */ |
|
139 | - public function get_txn() |
|
140 | - { |
|
141 | - if ($this->_current_txn instanceof EE_Transaction) { |
|
142 | - return $this->_current_txn; |
|
143 | - } |
|
144 | - $TXN_model = EE_Registry::instance()->load_model('Transaction'); |
|
145 | - if (! $TXN_model instanceof EEM_Transaction) { |
|
146 | - EE_Error::add_error( |
|
147 | - __('The transaction model could not be established.', 'event_espresso'), |
|
148 | - __FILE__, |
|
149 | - __FUNCTION__, |
|
150 | - __LINE__ |
|
151 | - ); |
|
152 | - return null; |
|
153 | - } |
|
154 | - // get the transaction. yes, we may have just loaded it, but it may have been updated, or this may be via an ajax request |
|
155 | - $this->_current_txn = $TXN_model->get_transaction_from_reg_url_link($this->_reg_url_link); |
|
156 | - // verify TXN |
|
157 | - if (WP_DEBUG && ! $this->_current_txn instanceof EE_Transaction) { |
|
158 | - EE_Error::add_error( |
|
159 | - __( |
|
160 | - 'No transaction information could be retrieved or the transaction data is not of the correct type.', |
|
161 | - 'event_espresso' |
|
162 | - ), |
|
163 | - __FILE__, |
|
164 | - __FUNCTION__, |
|
165 | - __LINE__ |
|
166 | - ); |
|
167 | - return null; |
|
168 | - } |
|
169 | - return $this->_current_txn; |
|
170 | - } |
|
171 | - |
|
172 | - |
|
173 | - /** |
|
174 | - * get_txn_payments |
|
175 | - * |
|
176 | - * @param int $since |
|
177 | - * @return mixed array of EE_Payment || FALSE |
|
178 | - * @throws \EE_Error |
|
179 | - */ |
|
180 | - public function get_txn_payments($since = 0) |
|
181 | - { |
|
182 | - if (! $this->get_txn()) { |
|
183 | - return false; |
|
184 | - } |
|
185 | - $args = array('order_by' => array('PAY_timestamp' => 'ASC')); |
|
186 | - if ($since > 0) { |
|
187 | - $args[0] = array('PAY_timestamp' => array('>', $since)); |
|
188 | - } |
|
189 | - // get array of payments with most recent first |
|
190 | - return $this->_current_txn->payments($args); |
|
191 | - } |
|
192 | - |
|
193 | - |
|
194 | - /** |
|
195 | - * @return bool |
|
196 | - */ |
|
197 | - public function isOfflinePaymentMethod() |
|
198 | - { |
|
199 | - return $this->_is_offline_payment_method; |
|
200 | - } |
|
201 | - |
|
202 | - |
|
203 | - |
|
204 | - |
|
205 | - /** |
|
206 | - * get_reg_url_link |
|
207 | - * |
|
208 | - * @return void |
|
209 | - */ |
|
210 | - private function _get_reg_url_link() |
|
211 | - { |
|
212 | - if (! empty($this->_reg_url_link)) { |
|
213 | - return; |
|
214 | - } |
|
215 | - // only do thank you page stuff if we have a REG_url_link in the url |
|
216 | - if (WP_DEBUG && ! EE_Registry::instance()->REQ->is_set('e_reg_url_link')) { |
|
217 | - EE_Error::add_error( |
|
218 | - __( |
|
219 | - 'No transaction information could be retrieved because the registration URL link is missing or invalid.', |
|
220 | - 'event_espresso' |
|
221 | - ), |
|
222 | - __FILE__, |
|
223 | - __FUNCTION__, |
|
224 | - __LINE__ |
|
225 | - ); |
|
226 | - return; |
|
227 | - } |
|
228 | - // check for reg_url_link |
|
229 | - $this->_reg_url_link = EE_Registry::instance()->REQ->get('e_reg_url_link'); |
|
230 | - } |
|
231 | - |
|
232 | - |
|
233 | - /** |
|
234 | - * set_reg_url_link |
|
235 | - * |
|
236 | - * @param string $reg_url_link |
|
237 | - */ |
|
238 | - public function set_reg_url_link($reg_url_link = null) |
|
239 | - { |
|
240 | - $this->_reg_url_link = ! empty($reg_url_link) ? $reg_url_link : $this->_reg_url_link; |
|
241 | - } |
|
242 | - |
|
243 | - |
|
244 | - /** |
|
245 | - * run - initial module setup |
|
246 | - * this method is primarily used for activating resources in the EE_Front_Controller thru the use of filters |
|
247 | - * |
|
248 | - * @param WP $WP |
|
249 | - * @return void |
|
250 | - * @throws \EE_Error |
|
251 | - */ |
|
252 | - public function run($WP) |
|
253 | - { |
|
254 | - } |
|
255 | - |
|
256 | - |
|
257 | - /** |
|
258 | - * load_resources |
|
259 | - * |
|
260 | - * @return void |
|
261 | - * @throws \EE_Error |
|
262 | - */ |
|
263 | - public function load_resources() |
|
264 | - { |
|
265 | - $this->_get_reg_url_link(); |
|
266 | - // resend_reg_confirmation_email ? |
|
267 | - if (EE_Registry::instance()->REQ->is_set('resend')) { |
|
268 | - EED_Thank_You_Page::resend_reg_confirmation_email(); |
|
269 | - } |
|
270 | - EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__); |
|
271 | - $this->_translate_strings(); |
|
272 | - // load assets |
|
273 | - add_action('wp_enqueue_scripts', array($this, 'load_js'), 10); |
|
274 | - } |
|
275 | - |
|
276 | - |
|
277 | - /** |
|
278 | - * load_js |
|
279 | - * |
|
280 | - * @return void |
|
281 | - */ |
|
282 | - protected function _translate_strings() |
|
283 | - { |
|
284 | - EE_Registry::$i18n_js_strings['e_reg_url_link'] = $this->_reg_url_link; |
|
285 | - EE_Registry::$i18n_js_strings['initial_access'] = time(); |
|
286 | - EE_Registry::$i18n_js_strings['IPN_wait_time'] = EED_Thank_You_Page::IPN_wait_time; |
|
287 | - EE_Registry::$i18n_js_strings['TXN_complete'] = EEM_Transaction::complete_status_code; |
|
288 | - EE_Registry::$i18n_js_strings['TXN_incomplete'] = EEM_Transaction::incomplete_status_code; |
|
289 | - EE_Registry::$i18n_js_strings['checking_for_new_payments'] = __( |
|
290 | - 'checking for new payments...', |
|
291 | - 'event_espresso' |
|
292 | - ); |
|
293 | - EE_Registry::$i18n_js_strings['loading_payment_info'] = __( |
|
294 | - 'loading payment information...', |
|
295 | - 'event_espresso' |
|
296 | - ); |
|
297 | - EE_Registry::$i18n_js_strings['server_error'] = __( |
|
298 | - 'An unknown error occurred on the server while attempting to process your request. Please refresh the page and try again.', |
|
299 | - 'event_espresso' |
|
300 | - ); |
|
301 | - EE_Registry::$i18n_js_strings['slow_IPN'] = apply_filters( |
|
302 | - 'EED_Thank_You_Page__load_js__slow_IPN', |
|
303 | - sprintf( |
|
304 | - __( |
|
305 | - '%sThe Payment Notification appears to be taking longer than usual to arrive. Maybe check back later or just wait for your payment and registration confirmation results to be sent to you via email. We apologize for any inconvenience this may have caused.%s', |
|
306 | - 'event_espresso' |
|
307 | - ), |
|
308 | - '<div id="espresso-thank-you-page-slow-IPN-dv" class="ee-attention jst-left">', |
|
309 | - '</div>' |
|
310 | - ) |
|
311 | - ); |
|
312 | - } |
|
313 | - |
|
314 | - |
|
315 | - /** |
|
316 | - * load_js |
|
317 | - * |
|
318 | - * @return void |
|
319 | - */ |
|
320 | - public function load_js() |
|
321 | - { |
|
322 | - wp_register_script( |
|
323 | - 'thank_you_page', |
|
324 | - THANK_YOU_ASSETS_URL . 'thank_you_page.js', |
|
325 | - array('espresso_core', 'heartbeat'), |
|
326 | - EVENT_ESPRESSO_VERSION, |
|
327 | - true |
|
328 | - ); |
|
329 | - wp_enqueue_script('thank_you_page'); |
|
330 | - wp_enqueue_style('espresso_default'); |
|
331 | - } |
|
332 | - |
|
333 | - |
|
334 | - /** |
|
335 | - * init |
|
336 | - * |
|
337 | - * @return void |
|
338 | - * @throws \EE_Error |
|
339 | - */ |
|
340 | - public function init() |
|
341 | - { |
|
342 | - $this->_get_reg_url_link(); |
|
343 | - if (! $this->get_txn()) { |
|
344 | - echo EEH_HTML::div( |
|
345 | - EEH_HTML::h4(__('We\'re sorry...', 'event_espresso'), '', '') . |
|
346 | - sprintf( |
|
347 | - __( |
|
348 | - 'This is a system page for displaying transaction information after a purchase.%1$sYou are most likely seeing this notice because you have navigated to this page%1$sthrough some means other than completing a transaction.%1$sSorry for the disappointment, but you will most likely find nothing of interest here.%1$s%1$s', |
|
349 | - 'event_espresso' |
|
350 | - ), |
|
351 | - '<br/>' |
|
352 | - ), |
|
353 | - '', |
|
354 | - 'ee-attention' |
|
355 | - ); |
|
356 | - return null; |
|
357 | - } |
|
358 | - // if we've made it to the Thank You page, then let's toggle any "Failed" transactions to "Incomplete" |
|
359 | - if ($this->_current_txn->status_ID() === EEM_Transaction::failed_status_code) { |
|
360 | - $this->_current_txn->set_status(EEM_Transaction::incomplete_status_code); |
|
361 | - $this->_current_txn->save(); |
|
362 | - } |
|
363 | - $this->_primary_registrant = $this->_current_txn->primary_registration() instanceof EE_Registration |
|
364 | - ? $this->_current_txn->primary_registration() |
|
365 | - : null; |
|
366 | - $this->_is_primary = $this->_primary_registrant->reg_url_link() === $this->_reg_url_link ? true : false; |
|
367 | - $show_try_pay_again_link_default = apply_filters( |
|
368 | - 'AFEE__EED_Thank_You_Page__init__show_try_pay_again_link_default', |
|
369 | - true |
|
370 | - ); |
|
371 | - $this->_show_try_pay_again_link = $show_try_pay_again_link_default; |
|
372 | - // txn status ? |
|
373 | - if ($this->_current_txn->is_completed()) { |
|
374 | - $this->_show_try_pay_again_link = $show_try_pay_again_link_default; |
|
375 | - } elseif ($this->_current_txn->is_incomplete() |
|
376 | - && ($this->_primary_registrant->is_approved() |
|
377 | - || $this->_primary_registrant->is_pending_payment()) |
|
378 | - ) { |
|
379 | - $this->_show_try_pay_again_link = true; |
|
380 | - } elseif ($this->_primary_registrant->is_approved() || $this->_primary_registrant->is_pending_payment()) { |
|
381 | - // its pending |
|
382 | - $this->_show_try_pay_again_link = isset( |
|
383 | - EE_Registry::instance()->CFG->registration->show_pending_payment_options |
|
384 | - ) |
|
385 | - && EE_Registry::instance()->CFG |
|
386 | - ->registration->show_pending_payment_options |
|
387 | - ? true |
|
388 | - : $show_try_pay_again_link_default; |
|
389 | - } |
|
390 | - $this->_payments_closed = ! $this->_current_txn->payment_method() instanceof EE_Payment_Method |
|
391 | - ? true |
|
392 | - : false; |
|
393 | - $this->_is_offline_payment_method = false; |
|
394 | - if (// if payment method is unknown |
|
395 | - ! $this->_current_txn->payment_method() instanceof EE_Payment_Method |
|
396 | - || ( |
|
397 | - // or is an offline payment method |
|
398 | - $this->_current_txn->payment_method() instanceof EE_Payment_Method |
|
399 | - && $this->_current_txn->payment_method()->is_off_line() |
|
400 | - ) |
|
401 | - ) { |
|
402 | - $this->_is_offline_payment_method = true; |
|
403 | - } |
|
404 | - // link to SPCO |
|
405 | - $revisit_spco_url = add_query_arg( |
|
406 | - array('ee' => '_register', 'revisit' => true, 'e_reg_url_link' => $this->_reg_url_link), |
|
407 | - EE_Registry::instance()->CFG->core->reg_page_url() |
|
408 | - ); |
|
409 | - // link to SPCO payment_options |
|
410 | - $this->_SPCO_payment_options_url = $this->_primary_registrant instanceof EE_Registration |
|
411 | - ? $this->_primary_registrant->payment_overview_url() |
|
412 | - : add_query_arg( |
|
413 | - array('step' => 'payment_options'), |
|
414 | - $revisit_spco_url |
|
415 | - ); |
|
416 | - // link to SPCO attendee_information |
|
417 | - $this->_SPCO_attendee_information_url = $this->_primary_registrant instanceof EE_Registration |
|
418 | - ? $this->_primary_registrant->edit_attendee_information_url() |
|
419 | - : false; |
|
420 | - do_action('AHEE__EED_Thank_You_Page__init_end', $this->_current_txn); |
|
421 | - // set no cache headers and constants |
|
422 | - EE_System::do_not_cache(); |
|
423 | - } |
|
424 | - |
|
425 | - |
|
426 | - /** |
|
427 | - * display_thank_you_page_results |
|
428 | - * |
|
429 | - * @return string |
|
430 | - * @throws \EE_Error |
|
431 | - */ |
|
432 | - public function thank_you_page_results() |
|
433 | - { |
|
434 | - $this->init(); |
|
435 | - if (! $this->_current_txn instanceof EE_Transaction) { |
|
436 | - return EE_Error::get_notices(); |
|
437 | - } |
|
438 | - // link to receipt |
|
439 | - $template_args['TXN_receipt_url'] = $this->_current_txn->receipt_url('html'); |
|
440 | - if (! empty($template_args['TXN_receipt_url'])) { |
|
441 | - $template_args['order_conf_desc'] = __( |
|
442 | - '%1$sCongratulations%2$sYour registration has been successfully processed.%3$sCheck your email for your registration confirmation or click the button below to view / download / print a full description of your purchases and registration information.', |
|
443 | - 'event_espresso' |
|
444 | - ); |
|
445 | - } else { |
|
446 | - $template_args['order_conf_desc'] = __( |
|
447 | - '%1$sCongratulations%2$sYour registration has been successfully processed.%3$sCheck your email for your registration confirmation.', |
|
448 | - 'event_espresso' |
|
449 | - ); |
|
450 | - } |
|
451 | - $template_args['transaction'] = $this->_current_txn; |
|
452 | - $template_args['revisit'] = EE_Registry::instance()->REQ->get('revisit', false); |
|
453 | - add_action('AHEE__thank_you_page_overview_template__content', array($this, 'get_registration_details')); |
|
454 | - if ($this->_is_primary && ! $this->_current_txn->is_free()) { |
|
455 | - add_action('AHEE__thank_you_page_overview_template__content', array($this, 'get_ajax_content')); |
|
456 | - } |
|
457 | - return EEH_Template::locate_template( |
|
458 | - THANK_YOU_TEMPLATES_PATH . 'thank-you-page-overview.template.php', |
|
459 | - $template_args, |
|
460 | - true, |
|
461 | - true |
|
462 | - ); |
|
463 | - } |
|
464 | - |
|
465 | - |
|
466 | - |
|
467 | - /** |
|
468 | - * _update_server_wait_time |
|
469 | - * |
|
470 | - * @param array $thank_you_page_data thank you page portion of the incoming JSON array from the WP heartbeat data |
|
471 | - * @return array |
|
472 | - * @throws \EE_Error |
|
473 | - */ |
|
474 | - private function _update_server_wait_time($thank_you_page_data = array()) |
|
475 | - { |
|
476 | - $response['espresso_thank_you_page'] = array( |
|
477 | - 'still_waiting' => isset($thank_you_page_data['initial_access']) |
|
478 | - ? time() - $thank_you_page_data['initial_access'] |
|
479 | - : 0, |
|
480 | - 'txn_status' => $this->_current_txn->status_ID(), |
|
481 | - ); |
|
482 | - return $response; |
|
483 | - } |
|
484 | - |
|
485 | - |
|
486 | - /** |
|
487 | - * get_registration_details |
|
488 | - * |
|
489 | - * @throws \EE_Error |
|
490 | - */ |
|
491 | - public function get_registration_details() |
|
492 | - { |
|
493 | - // prepare variables for displaying |
|
494 | - $template_args = array(); |
|
495 | - $template_args['transaction'] = $this->_current_txn; |
|
496 | - $template_args['reg_url_link'] = $this->_reg_url_link; |
|
497 | - $template_args['is_primary'] = $this->_is_primary; |
|
498 | - $template_args['SPCO_attendee_information_url'] = $this->_SPCO_attendee_information_url; |
|
499 | - $template_args['resend_reg_confirmation_url'] = add_query_arg( |
|
500 | - array('token' => $this->_reg_url_link, 'resend_reg_confirmation' => 'true'), |
|
501 | - EE_Registry::instance()->CFG->core->thank_you_page_url() |
|
502 | - ); |
|
503 | - // verify template arguments |
|
504 | - EEH_Template_Validator::verify_instanceof($template_args['transaction'], '$transaction', 'EE_Transaction'); |
|
505 | - EEH_Template_Validator::verify_isnt_null( |
|
506 | - $template_args['SPCO_attendee_information_url'], |
|
507 | - '$SPCO_attendee_information_url' |
|
508 | - ); |
|
509 | - echo EEH_Template::locate_template( |
|
510 | - THANK_YOU_TEMPLATES_PATH . 'thank-you-page-registration-details.template.php', |
|
511 | - $template_args, |
|
512 | - true, |
|
513 | - true |
|
514 | - ); |
|
515 | - } |
|
516 | - |
|
517 | - |
|
518 | - /** |
|
519 | - * resend_reg_confirmation_email |
|
520 | - * |
|
521 | - * @throws \EE_Error |
|
522 | - */ |
|
523 | - public static function resend_reg_confirmation_email() |
|
524 | - { |
|
525 | - EE_Registry::instance()->load_core('Request_Handler'); |
|
526 | - $reg_url_link = EE_Registry::instance()->REQ->get('token'); |
|
527 | - // was a REG_ID passed ? |
|
528 | - if ($reg_url_link) { |
|
529 | - $registration = EE_Registry::instance()->load_model('Registration')->get_one( |
|
530 | - array(array('REG_url_link' => $reg_url_link)) |
|
531 | - ); |
|
532 | - if ($registration instanceof EE_Registration) { |
|
533 | - // resend email |
|
534 | - EED_Messages::process_resend(array('_REG_ID' => $registration->ID())); |
|
535 | - } else { |
|
536 | - EE_Error::add_error( |
|
537 | - __( |
|
538 | - 'The Registration Confirmation email could not be sent because a valid Registration could not be retrieved from the database.', |
|
539 | - 'event_espresso' |
|
540 | - ), |
|
541 | - __FILE__, |
|
542 | - __FUNCTION__, |
|
543 | - __LINE__ |
|
544 | - ); |
|
545 | - } |
|
546 | - } else { |
|
547 | - EE_Error::add_error( |
|
548 | - __( |
|
549 | - 'The Registration Confirmation email could not be sent because a registration token is missing or invalid.', |
|
550 | - 'event_espresso' |
|
551 | - ), |
|
552 | - __FILE__, |
|
553 | - __FUNCTION__, |
|
554 | - __LINE__ |
|
555 | - ); |
|
556 | - } |
|
557 | - // request sent via AJAX ? |
|
558 | - if (EE_FRONT_AJAX) { |
|
559 | - echo wp_json_encode(EE_Error::get_notices(false)); |
|
560 | - die(); |
|
561 | - // or was JS disabled ? |
|
562 | - } else { |
|
563 | - // save errors so that they get picked up on the next request |
|
564 | - EE_Error::get_notices(true, true); |
|
565 | - wp_safe_redirect( |
|
566 | - add_query_arg( |
|
567 | - array('e_reg_url_link' => $reg_url_link), |
|
568 | - EE_Registry::instance()->CFG->core->thank_you_page_url() |
|
569 | - ) |
|
570 | - ); |
|
571 | - } |
|
572 | - } |
|
573 | - |
|
574 | - |
|
575 | - /** |
|
576 | - * get_ajax_content |
|
577 | - * |
|
578 | - * @return void |
|
579 | - * @throws \EE_Error |
|
580 | - */ |
|
581 | - public function get_ajax_content() |
|
582 | - { |
|
583 | - if (! $this->get_txn()) { |
|
584 | - return; |
|
585 | - } |
|
586 | - // first determine which event(s) require pre-approval or not |
|
587 | - $events = array(); |
|
588 | - $events_requiring_pre_approval = array(); |
|
589 | - foreach ($this->_current_txn->registrations() as $registration) { |
|
590 | - if ($registration instanceof EE_Registration) { |
|
591 | - $event = $registration->event(); |
|
592 | - if ($event instanceof EE_Event) { |
|
593 | - if ($registration->is_not_approved() && $registration->event() instanceof EE_Event) { |
|
594 | - $events_requiring_pre_approval[ $event->ID() ] = $event; |
|
595 | - } else { |
|
596 | - $events[ $event->ID() ] = $event; |
|
597 | - } |
|
598 | - } |
|
599 | - } |
|
600 | - } |
|
601 | - $this->display_details_for_events_requiring_pre_approval($events_requiring_pre_approval); |
|
602 | - $this->display_details_for_events($events); |
|
603 | - } |
|
604 | - |
|
605 | - |
|
606 | - /** |
|
607 | - * display_details_for_events |
|
608 | - * |
|
609 | - * @param EE_Event[] $events |
|
610 | - * @return void |
|
611 | - */ |
|
612 | - public function display_details_for_events($events = array()) |
|
613 | - { |
|
614 | - if (! empty($events)) { |
|
615 | - ?> |
|
13 | + /** |
|
14 | + * time in seconds to wait for the IPN to arrive before telling the registrant to bugger off ( 1200s = 20 minutes ) |
|
15 | + */ |
|
16 | + const IPN_wait_time = 1200; |
|
17 | + |
|
18 | + /** |
|
19 | + * The transaction specified by the reg_url_link passed from the Request, or from the Session |
|
20 | + * |
|
21 | + * @var EE_Transaction $_current_txn |
|
22 | + */ |
|
23 | + private $_current_txn; |
|
24 | + |
|
25 | + /** |
|
26 | + * @var EE_Registration $_primary_registrant |
|
27 | + */ |
|
28 | + private $_primary_registrant; |
|
29 | + |
|
30 | + /** |
|
31 | + * The reg_url_link passed from the Request, or from the Session |
|
32 | + * |
|
33 | + * @var string $_reg_url_link |
|
34 | + */ |
|
35 | + private $_reg_url_link; |
|
36 | + |
|
37 | + /** |
|
38 | + * whether the incoming reg_url_link is for the primary registrant or not |
|
39 | + * |
|
40 | + * @var boolean $_is_primary |
|
41 | + */ |
|
42 | + private $_is_primary; |
|
43 | + |
|
44 | + /** |
|
45 | + * The URL for revisiting the SPCO attendee information step |
|
46 | + * |
|
47 | + * @var string $_SPCO_attendee_information_url |
|
48 | + */ |
|
49 | + private $_SPCO_attendee_information_url; |
|
50 | + |
|
51 | + /** |
|
52 | + * The URL for revisiting the SPCO payment options step |
|
53 | + * |
|
54 | + * @var string $_SPCO_payment_options_url |
|
55 | + */ |
|
56 | + private $_SPCO_payment_options_url; |
|
57 | + |
|
58 | + /** |
|
59 | + * whether to display the Payment Options link |
|
60 | + * |
|
61 | + * @var boolean $_show_try_pay_again_link |
|
62 | + */ |
|
63 | + private $_show_try_pay_again_link = false; |
|
64 | + |
|
65 | + /** |
|
66 | + * whether payments are allowed at this time |
|
67 | + * |
|
68 | + * @var boolean $_payments_closed |
|
69 | + */ |
|
70 | + private $_payments_closed = false; |
|
71 | + |
|
72 | + /** |
|
73 | + * whether the selected payment method is Bank, Check , Invoice, etc |
|
74 | + * |
|
75 | + * @var boolean $_is_offline_payment_method |
|
76 | + */ |
|
77 | + private $_is_offline_payment_method = true; |
|
78 | + |
|
79 | + |
|
80 | + /** |
|
81 | + * @return EED_Module|EED_Thank_You_Page |
|
82 | + */ |
|
83 | + public static function instance() |
|
84 | + { |
|
85 | + return parent::get_instance(__CLASS__); |
|
86 | + } |
|
87 | + |
|
88 | + |
|
89 | + /** |
|
90 | + * set_hooks - for hooking into EE Core, modules, etc |
|
91 | + * |
|
92 | + * @return void |
|
93 | + */ |
|
94 | + public static function set_hooks() |
|
95 | + { |
|
96 | + add_action('wp_loaded', array('EED_Thank_You_Page', 'set_definitions'), 2); |
|
97 | + } |
|
98 | + |
|
99 | + |
|
100 | + /** |
|
101 | + * set_hooks_admin - for hooking into EE Admin Core, modules, etc |
|
102 | + * |
|
103 | + * @return void |
|
104 | + */ |
|
105 | + public static function set_hooks_admin() |
|
106 | + { |
|
107 | + add_action( |
|
108 | + 'wp_ajax_espresso_resend_reg_confirmation_email', |
|
109 | + array('EED_Thank_You_Page', 'resend_reg_confirmation_email'), |
|
110 | + 10, |
|
111 | + 2 |
|
112 | + ); |
|
113 | + add_action( |
|
114 | + 'wp_ajax_nopriv_espresso_resend_reg_confirmation_email', |
|
115 | + array('EED_Thank_You_Page', 'resend_reg_confirmation_email'), |
|
116 | + 10, |
|
117 | + 2 |
|
118 | + ); |
|
119 | + } |
|
120 | + |
|
121 | + |
|
122 | + /** |
|
123 | + * set_definitions |
|
124 | + * |
|
125 | + * @return void |
|
126 | + */ |
|
127 | + public static function set_definitions() |
|
128 | + { |
|
129 | + define('THANK_YOU_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets/'); |
|
130 | + define('THANK_YOU_TEMPLATES_PATH', str_replace('\\', '/', plugin_dir_path(__FILE__)) . 'templates/'); |
|
131 | + } |
|
132 | + |
|
133 | + |
|
134 | + /** |
|
135 | + * get_txn |
|
136 | + * |
|
137 | + * @return EE_Transaction |
|
138 | + */ |
|
139 | + public function get_txn() |
|
140 | + { |
|
141 | + if ($this->_current_txn instanceof EE_Transaction) { |
|
142 | + return $this->_current_txn; |
|
143 | + } |
|
144 | + $TXN_model = EE_Registry::instance()->load_model('Transaction'); |
|
145 | + if (! $TXN_model instanceof EEM_Transaction) { |
|
146 | + EE_Error::add_error( |
|
147 | + __('The transaction model could not be established.', 'event_espresso'), |
|
148 | + __FILE__, |
|
149 | + __FUNCTION__, |
|
150 | + __LINE__ |
|
151 | + ); |
|
152 | + return null; |
|
153 | + } |
|
154 | + // get the transaction. yes, we may have just loaded it, but it may have been updated, or this may be via an ajax request |
|
155 | + $this->_current_txn = $TXN_model->get_transaction_from_reg_url_link($this->_reg_url_link); |
|
156 | + // verify TXN |
|
157 | + if (WP_DEBUG && ! $this->_current_txn instanceof EE_Transaction) { |
|
158 | + EE_Error::add_error( |
|
159 | + __( |
|
160 | + 'No transaction information could be retrieved or the transaction data is not of the correct type.', |
|
161 | + 'event_espresso' |
|
162 | + ), |
|
163 | + __FILE__, |
|
164 | + __FUNCTION__, |
|
165 | + __LINE__ |
|
166 | + ); |
|
167 | + return null; |
|
168 | + } |
|
169 | + return $this->_current_txn; |
|
170 | + } |
|
171 | + |
|
172 | + |
|
173 | + /** |
|
174 | + * get_txn_payments |
|
175 | + * |
|
176 | + * @param int $since |
|
177 | + * @return mixed array of EE_Payment || FALSE |
|
178 | + * @throws \EE_Error |
|
179 | + */ |
|
180 | + public function get_txn_payments($since = 0) |
|
181 | + { |
|
182 | + if (! $this->get_txn()) { |
|
183 | + return false; |
|
184 | + } |
|
185 | + $args = array('order_by' => array('PAY_timestamp' => 'ASC')); |
|
186 | + if ($since > 0) { |
|
187 | + $args[0] = array('PAY_timestamp' => array('>', $since)); |
|
188 | + } |
|
189 | + // get array of payments with most recent first |
|
190 | + return $this->_current_txn->payments($args); |
|
191 | + } |
|
192 | + |
|
193 | + |
|
194 | + /** |
|
195 | + * @return bool |
|
196 | + */ |
|
197 | + public function isOfflinePaymentMethod() |
|
198 | + { |
|
199 | + return $this->_is_offline_payment_method; |
|
200 | + } |
|
201 | + |
|
202 | + |
|
203 | + |
|
204 | + |
|
205 | + /** |
|
206 | + * get_reg_url_link |
|
207 | + * |
|
208 | + * @return void |
|
209 | + */ |
|
210 | + private function _get_reg_url_link() |
|
211 | + { |
|
212 | + if (! empty($this->_reg_url_link)) { |
|
213 | + return; |
|
214 | + } |
|
215 | + // only do thank you page stuff if we have a REG_url_link in the url |
|
216 | + if (WP_DEBUG && ! EE_Registry::instance()->REQ->is_set('e_reg_url_link')) { |
|
217 | + EE_Error::add_error( |
|
218 | + __( |
|
219 | + 'No transaction information could be retrieved because the registration URL link is missing or invalid.', |
|
220 | + 'event_espresso' |
|
221 | + ), |
|
222 | + __FILE__, |
|
223 | + __FUNCTION__, |
|
224 | + __LINE__ |
|
225 | + ); |
|
226 | + return; |
|
227 | + } |
|
228 | + // check for reg_url_link |
|
229 | + $this->_reg_url_link = EE_Registry::instance()->REQ->get('e_reg_url_link'); |
|
230 | + } |
|
231 | + |
|
232 | + |
|
233 | + /** |
|
234 | + * set_reg_url_link |
|
235 | + * |
|
236 | + * @param string $reg_url_link |
|
237 | + */ |
|
238 | + public function set_reg_url_link($reg_url_link = null) |
|
239 | + { |
|
240 | + $this->_reg_url_link = ! empty($reg_url_link) ? $reg_url_link : $this->_reg_url_link; |
|
241 | + } |
|
242 | + |
|
243 | + |
|
244 | + /** |
|
245 | + * run - initial module setup |
|
246 | + * this method is primarily used for activating resources in the EE_Front_Controller thru the use of filters |
|
247 | + * |
|
248 | + * @param WP $WP |
|
249 | + * @return void |
|
250 | + * @throws \EE_Error |
|
251 | + */ |
|
252 | + public function run($WP) |
|
253 | + { |
|
254 | + } |
|
255 | + |
|
256 | + |
|
257 | + /** |
|
258 | + * load_resources |
|
259 | + * |
|
260 | + * @return void |
|
261 | + * @throws \EE_Error |
|
262 | + */ |
|
263 | + public function load_resources() |
|
264 | + { |
|
265 | + $this->_get_reg_url_link(); |
|
266 | + // resend_reg_confirmation_email ? |
|
267 | + if (EE_Registry::instance()->REQ->is_set('resend')) { |
|
268 | + EED_Thank_You_Page::resend_reg_confirmation_email(); |
|
269 | + } |
|
270 | + EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__); |
|
271 | + $this->_translate_strings(); |
|
272 | + // load assets |
|
273 | + add_action('wp_enqueue_scripts', array($this, 'load_js'), 10); |
|
274 | + } |
|
275 | + |
|
276 | + |
|
277 | + /** |
|
278 | + * load_js |
|
279 | + * |
|
280 | + * @return void |
|
281 | + */ |
|
282 | + protected function _translate_strings() |
|
283 | + { |
|
284 | + EE_Registry::$i18n_js_strings['e_reg_url_link'] = $this->_reg_url_link; |
|
285 | + EE_Registry::$i18n_js_strings['initial_access'] = time(); |
|
286 | + EE_Registry::$i18n_js_strings['IPN_wait_time'] = EED_Thank_You_Page::IPN_wait_time; |
|
287 | + EE_Registry::$i18n_js_strings['TXN_complete'] = EEM_Transaction::complete_status_code; |
|
288 | + EE_Registry::$i18n_js_strings['TXN_incomplete'] = EEM_Transaction::incomplete_status_code; |
|
289 | + EE_Registry::$i18n_js_strings['checking_for_new_payments'] = __( |
|
290 | + 'checking for new payments...', |
|
291 | + 'event_espresso' |
|
292 | + ); |
|
293 | + EE_Registry::$i18n_js_strings['loading_payment_info'] = __( |
|
294 | + 'loading payment information...', |
|
295 | + 'event_espresso' |
|
296 | + ); |
|
297 | + EE_Registry::$i18n_js_strings['server_error'] = __( |
|
298 | + 'An unknown error occurred on the server while attempting to process your request. Please refresh the page and try again.', |
|
299 | + 'event_espresso' |
|
300 | + ); |
|
301 | + EE_Registry::$i18n_js_strings['slow_IPN'] = apply_filters( |
|
302 | + 'EED_Thank_You_Page__load_js__slow_IPN', |
|
303 | + sprintf( |
|
304 | + __( |
|
305 | + '%sThe Payment Notification appears to be taking longer than usual to arrive. Maybe check back later or just wait for your payment and registration confirmation results to be sent to you via email. We apologize for any inconvenience this may have caused.%s', |
|
306 | + 'event_espresso' |
|
307 | + ), |
|
308 | + '<div id="espresso-thank-you-page-slow-IPN-dv" class="ee-attention jst-left">', |
|
309 | + '</div>' |
|
310 | + ) |
|
311 | + ); |
|
312 | + } |
|
313 | + |
|
314 | + |
|
315 | + /** |
|
316 | + * load_js |
|
317 | + * |
|
318 | + * @return void |
|
319 | + */ |
|
320 | + public function load_js() |
|
321 | + { |
|
322 | + wp_register_script( |
|
323 | + 'thank_you_page', |
|
324 | + THANK_YOU_ASSETS_URL . 'thank_you_page.js', |
|
325 | + array('espresso_core', 'heartbeat'), |
|
326 | + EVENT_ESPRESSO_VERSION, |
|
327 | + true |
|
328 | + ); |
|
329 | + wp_enqueue_script('thank_you_page'); |
|
330 | + wp_enqueue_style('espresso_default'); |
|
331 | + } |
|
332 | + |
|
333 | + |
|
334 | + /** |
|
335 | + * init |
|
336 | + * |
|
337 | + * @return void |
|
338 | + * @throws \EE_Error |
|
339 | + */ |
|
340 | + public function init() |
|
341 | + { |
|
342 | + $this->_get_reg_url_link(); |
|
343 | + if (! $this->get_txn()) { |
|
344 | + echo EEH_HTML::div( |
|
345 | + EEH_HTML::h4(__('We\'re sorry...', 'event_espresso'), '', '') . |
|
346 | + sprintf( |
|
347 | + __( |
|
348 | + 'This is a system page for displaying transaction information after a purchase.%1$sYou are most likely seeing this notice because you have navigated to this page%1$sthrough some means other than completing a transaction.%1$sSorry for the disappointment, but you will most likely find nothing of interest here.%1$s%1$s', |
|
349 | + 'event_espresso' |
|
350 | + ), |
|
351 | + '<br/>' |
|
352 | + ), |
|
353 | + '', |
|
354 | + 'ee-attention' |
|
355 | + ); |
|
356 | + return null; |
|
357 | + } |
|
358 | + // if we've made it to the Thank You page, then let's toggle any "Failed" transactions to "Incomplete" |
|
359 | + if ($this->_current_txn->status_ID() === EEM_Transaction::failed_status_code) { |
|
360 | + $this->_current_txn->set_status(EEM_Transaction::incomplete_status_code); |
|
361 | + $this->_current_txn->save(); |
|
362 | + } |
|
363 | + $this->_primary_registrant = $this->_current_txn->primary_registration() instanceof EE_Registration |
|
364 | + ? $this->_current_txn->primary_registration() |
|
365 | + : null; |
|
366 | + $this->_is_primary = $this->_primary_registrant->reg_url_link() === $this->_reg_url_link ? true : false; |
|
367 | + $show_try_pay_again_link_default = apply_filters( |
|
368 | + 'AFEE__EED_Thank_You_Page__init__show_try_pay_again_link_default', |
|
369 | + true |
|
370 | + ); |
|
371 | + $this->_show_try_pay_again_link = $show_try_pay_again_link_default; |
|
372 | + // txn status ? |
|
373 | + if ($this->_current_txn->is_completed()) { |
|
374 | + $this->_show_try_pay_again_link = $show_try_pay_again_link_default; |
|
375 | + } elseif ($this->_current_txn->is_incomplete() |
|
376 | + && ($this->_primary_registrant->is_approved() |
|
377 | + || $this->_primary_registrant->is_pending_payment()) |
|
378 | + ) { |
|
379 | + $this->_show_try_pay_again_link = true; |
|
380 | + } elseif ($this->_primary_registrant->is_approved() || $this->_primary_registrant->is_pending_payment()) { |
|
381 | + // its pending |
|
382 | + $this->_show_try_pay_again_link = isset( |
|
383 | + EE_Registry::instance()->CFG->registration->show_pending_payment_options |
|
384 | + ) |
|
385 | + && EE_Registry::instance()->CFG |
|
386 | + ->registration->show_pending_payment_options |
|
387 | + ? true |
|
388 | + : $show_try_pay_again_link_default; |
|
389 | + } |
|
390 | + $this->_payments_closed = ! $this->_current_txn->payment_method() instanceof EE_Payment_Method |
|
391 | + ? true |
|
392 | + : false; |
|
393 | + $this->_is_offline_payment_method = false; |
|
394 | + if (// if payment method is unknown |
|
395 | + ! $this->_current_txn->payment_method() instanceof EE_Payment_Method |
|
396 | + || ( |
|
397 | + // or is an offline payment method |
|
398 | + $this->_current_txn->payment_method() instanceof EE_Payment_Method |
|
399 | + && $this->_current_txn->payment_method()->is_off_line() |
|
400 | + ) |
|
401 | + ) { |
|
402 | + $this->_is_offline_payment_method = true; |
|
403 | + } |
|
404 | + // link to SPCO |
|
405 | + $revisit_spco_url = add_query_arg( |
|
406 | + array('ee' => '_register', 'revisit' => true, 'e_reg_url_link' => $this->_reg_url_link), |
|
407 | + EE_Registry::instance()->CFG->core->reg_page_url() |
|
408 | + ); |
|
409 | + // link to SPCO payment_options |
|
410 | + $this->_SPCO_payment_options_url = $this->_primary_registrant instanceof EE_Registration |
|
411 | + ? $this->_primary_registrant->payment_overview_url() |
|
412 | + : add_query_arg( |
|
413 | + array('step' => 'payment_options'), |
|
414 | + $revisit_spco_url |
|
415 | + ); |
|
416 | + // link to SPCO attendee_information |
|
417 | + $this->_SPCO_attendee_information_url = $this->_primary_registrant instanceof EE_Registration |
|
418 | + ? $this->_primary_registrant->edit_attendee_information_url() |
|
419 | + : false; |
|
420 | + do_action('AHEE__EED_Thank_You_Page__init_end', $this->_current_txn); |
|
421 | + // set no cache headers and constants |
|
422 | + EE_System::do_not_cache(); |
|
423 | + } |
|
424 | + |
|
425 | + |
|
426 | + /** |
|
427 | + * display_thank_you_page_results |
|
428 | + * |
|
429 | + * @return string |
|
430 | + * @throws \EE_Error |
|
431 | + */ |
|
432 | + public function thank_you_page_results() |
|
433 | + { |
|
434 | + $this->init(); |
|
435 | + if (! $this->_current_txn instanceof EE_Transaction) { |
|
436 | + return EE_Error::get_notices(); |
|
437 | + } |
|
438 | + // link to receipt |
|
439 | + $template_args['TXN_receipt_url'] = $this->_current_txn->receipt_url('html'); |
|
440 | + if (! empty($template_args['TXN_receipt_url'])) { |
|
441 | + $template_args['order_conf_desc'] = __( |
|
442 | + '%1$sCongratulations%2$sYour registration has been successfully processed.%3$sCheck your email for your registration confirmation or click the button below to view / download / print a full description of your purchases and registration information.', |
|
443 | + 'event_espresso' |
|
444 | + ); |
|
445 | + } else { |
|
446 | + $template_args['order_conf_desc'] = __( |
|
447 | + '%1$sCongratulations%2$sYour registration has been successfully processed.%3$sCheck your email for your registration confirmation.', |
|
448 | + 'event_espresso' |
|
449 | + ); |
|
450 | + } |
|
451 | + $template_args['transaction'] = $this->_current_txn; |
|
452 | + $template_args['revisit'] = EE_Registry::instance()->REQ->get('revisit', false); |
|
453 | + add_action('AHEE__thank_you_page_overview_template__content', array($this, 'get_registration_details')); |
|
454 | + if ($this->_is_primary && ! $this->_current_txn->is_free()) { |
|
455 | + add_action('AHEE__thank_you_page_overview_template__content', array($this, 'get_ajax_content')); |
|
456 | + } |
|
457 | + return EEH_Template::locate_template( |
|
458 | + THANK_YOU_TEMPLATES_PATH . 'thank-you-page-overview.template.php', |
|
459 | + $template_args, |
|
460 | + true, |
|
461 | + true |
|
462 | + ); |
|
463 | + } |
|
464 | + |
|
465 | + |
|
466 | + |
|
467 | + /** |
|
468 | + * _update_server_wait_time |
|
469 | + * |
|
470 | + * @param array $thank_you_page_data thank you page portion of the incoming JSON array from the WP heartbeat data |
|
471 | + * @return array |
|
472 | + * @throws \EE_Error |
|
473 | + */ |
|
474 | + private function _update_server_wait_time($thank_you_page_data = array()) |
|
475 | + { |
|
476 | + $response['espresso_thank_you_page'] = array( |
|
477 | + 'still_waiting' => isset($thank_you_page_data['initial_access']) |
|
478 | + ? time() - $thank_you_page_data['initial_access'] |
|
479 | + : 0, |
|
480 | + 'txn_status' => $this->_current_txn->status_ID(), |
|
481 | + ); |
|
482 | + return $response; |
|
483 | + } |
|
484 | + |
|
485 | + |
|
486 | + /** |
|
487 | + * get_registration_details |
|
488 | + * |
|
489 | + * @throws \EE_Error |
|
490 | + */ |
|
491 | + public function get_registration_details() |
|
492 | + { |
|
493 | + // prepare variables for displaying |
|
494 | + $template_args = array(); |
|
495 | + $template_args['transaction'] = $this->_current_txn; |
|
496 | + $template_args['reg_url_link'] = $this->_reg_url_link; |
|
497 | + $template_args['is_primary'] = $this->_is_primary; |
|
498 | + $template_args['SPCO_attendee_information_url'] = $this->_SPCO_attendee_information_url; |
|
499 | + $template_args['resend_reg_confirmation_url'] = add_query_arg( |
|
500 | + array('token' => $this->_reg_url_link, 'resend_reg_confirmation' => 'true'), |
|
501 | + EE_Registry::instance()->CFG->core->thank_you_page_url() |
|
502 | + ); |
|
503 | + // verify template arguments |
|
504 | + EEH_Template_Validator::verify_instanceof($template_args['transaction'], '$transaction', 'EE_Transaction'); |
|
505 | + EEH_Template_Validator::verify_isnt_null( |
|
506 | + $template_args['SPCO_attendee_information_url'], |
|
507 | + '$SPCO_attendee_information_url' |
|
508 | + ); |
|
509 | + echo EEH_Template::locate_template( |
|
510 | + THANK_YOU_TEMPLATES_PATH . 'thank-you-page-registration-details.template.php', |
|
511 | + $template_args, |
|
512 | + true, |
|
513 | + true |
|
514 | + ); |
|
515 | + } |
|
516 | + |
|
517 | + |
|
518 | + /** |
|
519 | + * resend_reg_confirmation_email |
|
520 | + * |
|
521 | + * @throws \EE_Error |
|
522 | + */ |
|
523 | + public static function resend_reg_confirmation_email() |
|
524 | + { |
|
525 | + EE_Registry::instance()->load_core('Request_Handler'); |
|
526 | + $reg_url_link = EE_Registry::instance()->REQ->get('token'); |
|
527 | + // was a REG_ID passed ? |
|
528 | + if ($reg_url_link) { |
|
529 | + $registration = EE_Registry::instance()->load_model('Registration')->get_one( |
|
530 | + array(array('REG_url_link' => $reg_url_link)) |
|
531 | + ); |
|
532 | + if ($registration instanceof EE_Registration) { |
|
533 | + // resend email |
|
534 | + EED_Messages::process_resend(array('_REG_ID' => $registration->ID())); |
|
535 | + } else { |
|
536 | + EE_Error::add_error( |
|
537 | + __( |
|
538 | + 'The Registration Confirmation email could not be sent because a valid Registration could not be retrieved from the database.', |
|
539 | + 'event_espresso' |
|
540 | + ), |
|
541 | + __FILE__, |
|
542 | + __FUNCTION__, |
|
543 | + __LINE__ |
|
544 | + ); |
|
545 | + } |
|
546 | + } else { |
|
547 | + EE_Error::add_error( |
|
548 | + __( |
|
549 | + 'The Registration Confirmation email could not be sent because a registration token is missing or invalid.', |
|
550 | + 'event_espresso' |
|
551 | + ), |
|
552 | + __FILE__, |
|
553 | + __FUNCTION__, |
|
554 | + __LINE__ |
|
555 | + ); |
|
556 | + } |
|
557 | + // request sent via AJAX ? |
|
558 | + if (EE_FRONT_AJAX) { |
|
559 | + echo wp_json_encode(EE_Error::get_notices(false)); |
|
560 | + die(); |
|
561 | + // or was JS disabled ? |
|
562 | + } else { |
|
563 | + // save errors so that they get picked up on the next request |
|
564 | + EE_Error::get_notices(true, true); |
|
565 | + wp_safe_redirect( |
|
566 | + add_query_arg( |
|
567 | + array('e_reg_url_link' => $reg_url_link), |
|
568 | + EE_Registry::instance()->CFG->core->thank_you_page_url() |
|
569 | + ) |
|
570 | + ); |
|
571 | + } |
|
572 | + } |
|
573 | + |
|
574 | + |
|
575 | + /** |
|
576 | + * get_ajax_content |
|
577 | + * |
|
578 | + * @return void |
|
579 | + * @throws \EE_Error |
|
580 | + */ |
|
581 | + public function get_ajax_content() |
|
582 | + { |
|
583 | + if (! $this->get_txn()) { |
|
584 | + return; |
|
585 | + } |
|
586 | + // first determine which event(s) require pre-approval or not |
|
587 | + $events = array(); |
|
588 | + $events_requiring_pre_approval = array(); |
|
589 | + foreach ($this->_current_txn->registrations() as $registration) { |
|
590 | + if ($registration instanceof EE_Registration) { |
|
591 | + $event = $registration->event(); |
|
592 | + if ($event instanceof EE_Event) { |
|
593 | + if ($registration->is_not_approved() && $registration->event() instanceof EE_Event) { |
|
594 | + $events_requiring_pre_approval[ $event->ID() ] = $event; |
|
595 | + } else { |
|
596 | + $events[ $event->ID() ] = $event; |
|
597 | + } |
|
598 | + } |
|
599 | + } |
|
600 | + } |
|
601 | + $this->display_details_for_events_requiring_pre_approval($events_requiring_pre_approval); |
|
602 | + $this->display_details_for_events($events); |
|
603 | + } |
|
604 | + |
|
605 | + |
|
606 | + /** |
|
607 | + * display_details_for_events |
|
608 | + * |
|
609 | + * @param EE_Event[] $events |
|
610 | + * @return void |
|
611 | + */ |
|
612 | + public function display_details_for_events($events = array()) |
|
613 | + { |
|
614 | + if (! empty($events)) { |
|
615 | + ?> |
|
616 | 616 | <div id="espresso-thank-you-page-ajax-content-dv"> |
617 | 617 | <div id="espresso-thank-you-page-ajax-transaction-dv"></div> |
618 | 618 | <div id="espresso-thank-you-page-ajax-payment-dv"></div> |
@@ -620,19 +620,19 @@ discard block |
||
620 | 620 | <div id="ee-ajax-loading-dv" class="float-left lt-blue-text"> |
621 | 621 | <span class="dashicons dashicons-upload"></span><span id="ee-ajax-loading-msg-spn"> |
622 | 622 | <?php _e( |
623 | - 'loading transaction and payment information...', |
|
624 | - 'event_espresso' |
|
625 | - ); ?></span> |
|
623 | + 'loading transaction and payment information...', |
|
624 | + 'event_espresso' |
|
625 | + ); ?></span> |
|
626 | 626 | </div> |
627 | 627 | <?php if (! $this->_is_offline_payment_method && ! $this->_payments_closed) : ?> |
628 | 628 | <p id="ee-ajax-loading-pg" class="highlight-bg small-text clear"> |
629 | 629 | <?php echo apply_filters( |
630 | - 'EED_Thank_You_Page__get_ajax_content__waiting_for_IPN_msg', |
|
631 | - __( |
|
632 | - 'Some payment gateways can take 15 minutes or more to return their payment notification, so please be patient if you require payment confirmation as soon as possible. Please note that as soon as everything is finalized, we will send your full payment and registration confirmation results to you via email.', |
|
633 | - 'event_espresso' |
|
634 | - ) |
|
635 | - ); ?> |
|
630 | + 'EED_Thank_You_Page__get_ajax_content__waiting_for_IPN_msg', |
|
631 | + __( |
|
632 | + 'Some payment gateways can take 15 minutes or more to return their payment notification, so please be patient if you require payment confirmation as soon as possible. Please note that as soon as everything is finalized, we will send your full payment and registration confirmation results to you via email.', |
|
633 | + 'event_espresso' |
|
634 | + ) |
|
635 | + ); ?> |
|
636 | 636 | <br/> |
637 | 637 | <span class="jst-rght ee-block small-text lt-grey-text"> |
638 | 638 | <?php _e('current wait time ', 'event_espresso'); ?> |
@@ -643,117 +643,117 @@ discard block |
||
643 | 643 | <div class="clear"></div> |
644 | 644 | </div> |
645 | 645 | <?php |
646 | - } |
|
647 | - } |
|
648 | - |
|
649 | - |
|
650 | - /** |
|
651 | - * display_details_for_events_requiring_pre_approval |
|
652 | - * |
|
653 | - * @param EE_Event[] $events |
|
654 | - * @return void |
|
655 | - */ |
|
656 | - public function display_details_for_events_requiring_pre_approval($events = array()) |
|
657 | - { |
|
658 | - if (! empty($events)) { |
|
659 | - ?> |
|
646 | + } |
|
647 | + } |
|
648 | + |
|
649 | + |
|
650 | + /** |
|
651 | + * display_details_for_events_requiring_pre_approval |
|
652 | + * |
|
653 | + * @param EE_Event[] $events |
|
654 | + * @return void |
|
655 | + */ |
|
656 | + public function display_details_for_events_requiring_pre_approval($events = array()) |
|
657 | + { |
|
658 | + if (! empty($events)) { |
|
659 | + ?> |
|
660 | 660 | <div id="espresso-thank-you-page-not-approved-message-dv"> |
661 | 661 | <h4 class="orange-text"><?php _e('Important Notice:', 'event_espresso'); ?></h4> |
662 | 662 | <p id="events-requiring-pre-approval-pg" class="small-text"> |
663 | 663 | <?php echo apply_filters( |
664 | - 'AHEE__EED_Thank_You_Page__get_ajax_content__not_approved_message', |
|
665 | - __( |
|
666 | - 'The following Event(s) you have registered for do not require payment at this time and will not be billed for during this transaction. Billing will only occur after all attendees have been approved by the event organizer. You will be notified when your registration has been processed. If this is a free event, then no billing will occur.', |
|
667 | - 'event_espresso' |
|
668 | - ) |
|
669 | - ); ?> |
|
664 | + 'AHEE__EED_Thank_You_Page__get_ajax_content__not_approved_message', |
|
665 | + __( |
|
666 | + 'The following Event(s) you have registered for do not require payment at this time and will not be billed for during this transaction. Billing will only occur after all attendees have been approved by the event organizer. You will be notified when your registration has been processed. If this is a free event, then no billing will occur.', |
|
667 | + 'event_espresso' |
|
668 | + ) |
|
669 | + ); ?> |
|
670 | 670 | </p> |
671 | 671 | <ul class="events-requiring-pre-approval-ul"> |
672 | 672 | <?php |
673 | - foreach ($events as $event) { |
|
674 | - if ($event instanceof EE_Event) { |
|
675 | - echo '<li><span class="dashicons dashicons-marker ee-icon-size-16 orange-text"></span>', |
|
676 | - $event->name(), |
|
677 | - '</li>'; |
|
678 | - } |
|
679 | - } ?> |
|
673 | + foreach ($events as $event) { |
|
674 | + if ($event instanceof EE_Event) { |
|
675 | + echo '<li><span class="dashicons dashicons-marker ee-icon-size-16 orange-text"></span>', |
|
676 | + $event->name(), |
|
677 | + '</li>'; |
|
678 | + } |
|
679 | + } ?> |
|
680 | 680 | </ul> |
681 | 681 | <div class="clear"></div> |
682 | 682 | </div> |
683 | 683 | <?php |
684 | - } |
|
685 | - } |
|
686 | - |
|
687 | - |
|
688 | - /** |
|
689 | - * get_transaction_details |
|
690 | - * |
|
691 | - * @return string |
|
692 | - * @throws \EE_Error |
|
693 | - */ |
|
694 | - public function get_transaction_details() |
|
695 | - { |
|
696 | - // prepare variables for displaying |
|
697 | - $template_args = array(); |
|
698 | - $template_args['transaction'] = $this->_current_txn; |
|
699 | - $template_args['reg_url_link'] = $this->_reg_url_link; |
|
700 | - $template_args['primary_registrant_name'] = $this->_primary_registrant->attendee()->full_name(true); |
|
701 | - // link to SPCO payment_options |
|
702 | - $template_args['show_try_pay_again_link'] = $this->_show_try_pay_again_link; |
|
703 | - $template_args['SPCO_payment_options_url'] = $this->_SPCO_payment_options_url; |
|
704 | - // verify template arguments |
|
705 | - EEH_Template_Validator::verify_instanceof($template_args['transaction'], '$transaction', 'EE_Transaction'); |
|
706 | - EEH_Template_Validator::verify_isnt_null( |
|
707 | - $template_args['show_try_pay_again_link'], |
|
708 | - '$show_try_pay_again_link' |
|
709 | - ); |
|
710 | - EEH_Template_Validator::verify_isnt_null( |
|
711 | - $template_args['SPCO_payment_options_url'], |
|
712 | - '$SPCO_payment_options_url' |
|
713 | - ); |
|
714 | - return EEH_Template::locate_template( |
|
715 | - THANK_YOU_TEMPLATES_PATH . 'thank-you-page-transaction-details.template.php', |
|
716 | - $template_args, |
|
717 | - true, |
|
718 | - true |
|
719 | - ); |
|
720 | - } |
|
721 | - |
|
722 | - |
|
723 | - /** |
|
724 | - * get_payment_row_html |
|
725 | - * |
|
726 | - * @param EE_Payment $payment |
|
727 | - * @return string |
|
728 | - * @throws \EE_Error |
|
729 | - */ |
|
730 | - public function get_payment_row_html($payment = null) |
|
731 | - { |
|
732 | - $html = ''; |
|
733 | - if ($payment instanceof EE_Payment) { |
|
734 | - if ($payment->payment_method() instanceof EE_Payment_Method |
|
735 | - && $payment->status() === EEM_Payment::status_id_failed |
|
736 | - && $payment->payment_method()->is_off_site() |
|
737 | - ) { |
|
738 | - // considering the registrant has made it to the Thank You page, |
|
739 | - // any failed payments may actually be pending and the IPN is just slow |
|
740 | - // so let's |
|
741 | - $payment->set_status(EEM_Payment::status_id_pending); |
|
742 | - } |
|
743 | - $payment_declined_msg = $payment->STS_ID() === EEM_Payment::status_id_declined |
|
744 | - ? '<br /><span class="small-text">' . $payment->gateway_response() . '</span>' |
|
745 | - : ''; |
|
746 | - $html .= ' |
|
684 | + } |
|
685 | + } |
|
686 | + |
|
687 | + |
|
688 | + /** |
|
689 | + * get_transaction_details |
|
690 | + * |
|
691 | + * @return string |
|
692 | + * @throws \EE_Error |
|
693 | + */ |
|
694 | + public function get_transaction_details() |
|
695 | + { |
|
696 | + // prepare variables for displaying |
|
697 | + $template_args = array(); |
|
698 | + $template_args['transaction'] = $this->_current_txn; |
|
699 | + $template_args['reg_url_link'] = $this->_reg_url_link; |
|
700 | + $template_args['primary_registrant_name'] = $this->_primary_registrant->attendee()->full_name(true); |
|
701 | + // link to SPCO payment_options |
|
702 | + $template_args['show_try_pay_again_link'] = $this->_show_try_pay_again_link; |
|
703 | + $template_args['SPCO_payment_options_url'] = $this->_SPCO_payment_options_url; |
|
704 | + // verify template arguments |
|
705 | + EEH_Template_Validator::verify_instanceof($template_args['transaction'], '$transaction', 'EE_Transaction'); |
|
706 | + EEH_Template_Validator::verify_isnt_null( |
|
707 | + $template_args['show_try_pay_again_link'], |
|
708 | + '$show_try_pay_again_link' |
|
709 | + ); |
|
710 | + EEH_Template_Validator::verify_isnt_null( |
|
711 | + $template_args['SPCO_payment_options_url'], |
|
712 | + '$SPCO_payment_options_url' |
|
713 | + ); |
|
714 | + return EEH_Template::locate_template( |
|
715 | + THANK_YOU_TEMPLATES_PATH . 'thank-you-page-transaction-details.template.php', |
|
716 | + $template_args, |
|
717 | + true, |
|
718 | + true |
|
719 | + ); |
|
720 | + } |
|
721 | + |
|
722 | + |
|
723 | + /** |
|
724 | + * get_payment_row_html |
|
725 | + * |
|
726 | + * @param EE_Payment $payment |
|
727 | + * @return string |
|
728 | + * @throws \EE_Error |
|
729 | + */ |
|
730 | + public function get_payment_row_html($payment = null) |
|
731 | + { |
|
732 | + $html = ''; |
|
733 | + if ($payment instanceof EE_Payment) { |
|
734 | + if ($payment->payment_method() instanceof EE_Payment_Method |
|
735 | + && $payment->status() === EEM_Payment::status_id_failed |
|
736 | + && $payment->payment_method()->is_off_site() |
|
737 | + ) { |
|
738 | + // considering the registrant has made it to the Thank You page, |
|
739 | + // any failed payments may actually be pending and the IPN is just slow |
|
740 | + // so let's |
|
741 | + $payment->set_status(EEM_Payment::status_id_pending); |
|
742 | + } |
|
743 | + $payment_declined_msg = $payment->STS_ID() === EEM_Payment::status_id_declined |
|
744 | + ? '<br /><span class="small-text">' . $payment->gateway_response() . '</span>' |
|
745 | + : ''; |
|
746 | + $html .= ' |
|
747 | 747 | <tr> |
748 | 748 | <td> |
749 | 749 | ' . $payment->timestamp() . ' |
750 | 750 | </td> |
751 | 751 | <td> |
752 | 752 | ' . ( |
753 | - $payment->payment_method() instanceof EE_Payment_Method |
|
754 | - ? $payment->payment_method()->name() |
|
755 | - : __('Unknown', 'event_espresso') |
|
756 | - ) . ' |
|
753 | + $payment->payment_method() instanceof EE_Payment_Method |
|
754 | + ? $payment->payment_method()->name() |
|
755 | + : __('Unknown', 'event_espresso') |
|
756 | + ) . ' |
|
757 | 757 | </td> |
758 | 758 | <td class="jst-rght"> |
759 | 759 | ' . EEH_Template::format_currency($payment->amount()) . ' |
@@ -762,83 +762,83 @@ discard block |
||
762 | 762 | ' . $payment->pretty_status(true) . $payment_declined_msg . ' |
763 | 763 | </td> |
764 | 764 | </tr>'; |
765 | - do_action('AHEE__thank_you_page_payment_details_template__after_each_payment', $payment); |
|
766 | - } |
|
767 | - return $html; |
|
768 | - } |
|
769 | - |
|
770 | - |
|
771 | - /** |
|
772 | - * get_payment_details |
|
773 | - * |
|
774 | - * @param array $payments |
|
775 | - * @return string |
|
776 | - * @throws \EE_Error |
|
777 | - */ |
|
778 | - public function get_payment_details($payments = array()) |
|
779 | - { |
|
780 | - // prepare variables for displaying |
|
781 | - $template_args = array(); |
|
782 | - $template_args['transaction'] = $this->_current_txn; |
|
783 | - $template_args['reg_url_link'] = $this->_reg_url_link; |
|
784 | - $template_args['payments'] = array(); |
|
785 | - foreach ($payments as $payment) { |
|
786 | - $template_args['payments'][] = $this->get_payment_row_html($payment); |
|
787 | - } |
|
788 | - // create a hacky payment object, but dont save it |
|
789 | - $payment = EE_Payment::new_instance( |
|
790 | - array( |
|
791 | - 'TXN_ID' => $this->_current_txn->ID(), |
|
792 | - 'STS_ID' => EEM_Payment::status_id_pending, |
|
793 | - 'PAY_timestamp' => time(), |
|
794 | - 'PAY_amount' => $this->_current_txn->total(), |
|
795 | - 'PMD_ID' => $this->_current_txn->payment_method_ID(), |
|
796 | - ) |
|
797 | - ); |
|
798 | - $payment_method = $this->_current_txn->payment_method(); |
|
799 | - if ($payment_method instanceof EE_Payment_Method && $payment_method->type_obj() instanceof EE_PMT_Base) { |
|
800 | - $template_args['gateway_content'] = $payment_method->type_obj()->payment_overview_content($payment); |
|
801 | - } else { |
|
802 | - $template_args['gateway_content'] = ''; |
|
803 | - } |
|
804 | - // link to SPCO payment_options |
|
805 | - $template_args['show_try_pay_again_link'] = $this->_show_try_pay_again_link; |
|
806 | - $template_args['SPCO_payment_options_url'] = $this->_SPCO_payment_options_url; |
|
807 | - // verify template arguments |
|
808 | - EEH_Template_Validator::verify_instanceof($template_args['transaction'], '$transaction', 'EE_Transaction'); |
|
809 | - EEH_Template_Validator::verify_isnt_null($template_args['payments'], '$payments'); |
|
810 | - EEH_Template_Validator::verify_isnt_null( |
|
811 | - $template_args['show_try_pay_again_link'], |
|
812 | - '$show_try_pay_again_link' |
|
813 | - ); |
|
814 | - EEH_Template_Validator::verify_isnt_null($template_args['gateway_content'], '$gateway_content'); |
|
815 | - EEH_Template_Validator::verify_isnt_null( |
|
816 | - $template_args['SPCO_payment_options_url'], |
|
817 | - '$SPCO_payment_options_url' |
|
818 | - ); |
|
819 | - return EEH_Template::locate_template( |
|
820 | - THANK_YOU_TEMPLATES_PATH . 'thank-you-page-payment-details.template.php', |
|
821 | - $template_args, |
|
822 | - true, |
|
823 | - true |
|
824 | - ); |
|
825 | - } |
|
826 | - |
|
827 | - |
|
828 | - /** |
|
829 | - * get_payment_details |
|
830 | - * |
|
831 | - * @param array $payments |
|
832 | - * @return string |
|
833 | - * @throws \EE_Error |
|
834 | - */ |
|
835 | - public function get_new_payments($payments = array()) |
|
836 | - { |
|
837 | - $payments_html = ''; |
|
838 | - // prepare variables for displaying |
|
839 | - foreach ($payments as $payment) { |
|
840 | - $payments_html .= $this->get_payment_row_html($payment); |
|
841 | - } |
|
842 | - return $payments_html; |
|
843 | - } |
|
765 | + do_action('AHEE__thank_you_page_payment_details_template__after_each_payment', $payment); |
|
766 | + } |
|
767 | + return $html; |
|
768 | + } |
|
769 | + |
|
770 | + |
|
771 | + /** |
|
772 | + * get_payment_details |
|
773 | + * |
|
774 | + * @param array $payments |
|
775 | + * @return string |
|
776 | + * @throws \EE_Error |
|
777 | + */ |
|
778 | + public function get_payment_details($payments = array()) |
|
779 | + { |
|
780 | + // prepare variables for displaying |
|
781 | + $template_args = array(); |
|
782 | + $template_args['transaction'] = $this->_current_txn; |
|
783 | + $template_args['reg_url_link'] = $this->_reg_url_link; |
|
784 | + $template_args['payments'] = array(); |
|
785 | + foreach ($payments as $payment) { |
|
786 | + $template_args['payments'][] = $this->get_payment_row_html($payment); |
|
787 | + } |
|
788 | + // create a hacky payment object, but dont save it |
|
789 | + $payment = EE_Payment::new_instance( |
|
790 | + array( |
|
791 | + 'TXN_ID' => $this->_current_txn->ID(), |
|
792 | + 'STS_ID' => EEM_Payment::status_id_pending, |
|
793 | + 'PAY_timestamp' => time(), |
|
794 | + 'PAY_amount' => $this->_current_txn->total(), |
|
795 | + 'PMD_ID' => $this->_current_txn->payment_method_ID(), |
|
796 | + ) |
|
797 | + ); |
|
798 | + $payment_method = $this->_current_txn->payment_method(); |
|
799 | + if ($payment_method instanceof EE_Payment_Method && $payment_method->type_obj() instanceof EE_PMT_Base) { |
|
800 | + $template_args['gateway_content'] = $payment_method->type_obj()->payment_overview_content($payment); |
|
801 | + } else { |
|
802 | + $template_args['gateway_content'] = ''; |
|
803 | + } |
|
804 | + // link to SPCO payment_options |
|
805 | + $template_args['show_try_pay_again_link'] = $this->_show_try_pay_again_link; |
|
806 | + $template_args['SPCO_payment_options_url'] = $this->_SPCO_payment_options_url; |
|
807 | + // verify template arguments |
|
808 | + EEH_Template_Validator::verify_instanceof($template_args['transaction'], '$transaction', 'EE_Transaction'); |
|
809 | + EEH_Template_Validator::verify_isnt_null($template_args['payments'], '$payments'); |
|
810 | + EEH_Template_Validator::verify_isnt_null( |
|
811 | + $template_args['show_try_pay_again_link'], |
|
812 | + '$show_try_pay_again_link' |
|
813 | + ); |
|
814 | + EEH_Template_Validator::verify_isnt_null($template_args['gateway_content'], '$gateway_content'); |
|
815 | + EEH_Template_Validator::verify_isnt_null( |
|
816 | + $template_args['SPCO_payment_options_url'], |
|
817 | + '$SPCO_payment_options_url' |
|
818 | + ); |
|
819 | + return EEH_Template::locate_template( |
|
820 | + THANK_YOU_TEMPLATES_PATH . 'thank-you-page-payment-details.template.php', |
|
821 | + $template_args, |
|
822 | + true, |
|
823 | + true |
|
824 | + ); |
|
825 | + } |
|
826 | + |
|
827 | + |
|
828 | + /** |
|
829 | + * get_payment_details |
|
830 | + * |
|
831 | + * @param array $payments |
|
832 | + * @return string |
|
833 | + * @throws \EE_Error |
|
834 | + */ |
|
835 | + public function get_new_payments($payments = array()) |
|
836 | + { |
|
837 | + $payments_html = ''; |
|
838 | + // prepare variables for displaying |
|
839 | + foreach ($payments as $payment) { |
|
840 | + $payments_html .= $this->get_payment_row_html($payment); |
|
841 | + } |
|
842 | + return $payments_html; |
|
843 | + } |
|
844 | 844 | } |
@@ -126,8 +126,8 @@ discard block |
||
126 | 126 | */ |
127 | 127 | public static function set_definitions() |
128 | 128 | { |
129 | - define('THANK_YOU_ASSETS_URL', plugin_dir_url(__FILE__) . 'assets/'); |
|
130 | - define('THANK_YOU_TEMPLATES_PATH', str_replace('\\', '/', plugin_dir_path(__FILE__)) . 'templates/'); |
|
129 | + define('THANK_YOU_ASSETS_URL', plugin_dir_url(__FILE__).'assets/'); |
|
130 | + define('THANK_YOU_TEMPLATES_PATH', str_replace('\\', '/', plugin_dir_path(__FILE__)).'templates/'); |
|
131 | 131 | } |
132 | 132 | |
133 | 133 | |
@@ -142,7 +142,7 @@ discard block |
||
142 | 142 | return $this->_current_txn; |
143 | 143 | } |
144 | 144 | $TXN_model = EE_Registry::instance()->load_model('Transaction'); |
145 | - if (! $TXN_model instanceof EEM_Transaction) { |
|
145 | + if ( ! $TXN_model instanceof EEM_Transaction) { |
|
146 | 146 | EE_Error::add_error( |
147 | 147 | __('The transaction model could not be established.', 'event_espresso'), |
148 | 148 | __FILE__, |
@@ -179,7 +179,7 @@ discard block |
||
179 | 179 | */ |
180 | 180 | public function get_txn_payments($since = 0) |
181 | 181 | { |
182 | - if (! $this->get_txn()) { |
|
182 | + if ( ! $this->get_txn()) { |
|
183 | 183 | return false; |
184 | 184 | } |
185 | 185 | $args = array('order_by' => array('PAY_timestamp' => 'ASC')); |
@@ -209,7 +209,7 @@ discard block |
||
209 | 209 | */ |
210 | 210 | private function _get_reg_url_link() |
211 | 211 | { |
212 | - if (! empty($this->_reg_url_link)) { |
|
212 | + if ( ! empty($this->_reg_url_link)) { |
|
213 | 213 | return; |
214 | 214 | } |
215 | 215 | // only do thank you page stuff if we have a REG_url_link in the url |
@@ -321,7 +321,7 @@ discard block |
||
321 | 321 | { |
322 | 322 | wp_register_script( |
323 | 323 | 'thank_you_page', |
324 | - THANK_YOU_ASSETS_URL . 'thank_you_page.js', |
|
324 | + THANK_YOU_ASSETS_URL.'thank_you_page.js', |
|
325 | 325 | array('espresso_core', 'heartbeat'), |
326 | 326 | EVENT_ESPRESSO_VERSION, |
327 | 327 | true |
@@ -340,9 +340,9 @@ discard block |
||
340 | 340 | public function init() |
341 | 341 | { |
342 | 342 | $this->_get_reg_url_link(); |
343 | - if (! $this->get_txn()) { |
|
343 | + if ( ! $this->get_txn()) { |
|
344 | 344 | echo EEH_HTML::div( |
345 | - EEH_HTML::h4(__('We\'re sorry...', 'event_espresso'), '', '') . |
|
345 | + EEH_HTML::h4(__('We\'re sorry...', 'event_espresso'), '', ''). |
|
346 | 346 | sprintf( |
347 | 347 | __( |
348 | 348 | 'This is a system page for displaying transaction information after a purchase.%1$sYou are most likely seeing this notice because you have navigated to this page%1$sthrough some means other than completing a transaction.%1$sSorry for the disappointment, but you will most likely find nothing of interest here.%1$s%1$s', |
@@ -432,12 +432,12 @@ discard block |
||
432 | 432 | public function thank_you_page_results() |
433 | 433 | { |
434 | 434 | $this->init(); |
435 | - if (! $this->_current_txn instanceof EE_Transaction) { |
|
435 | + if ( ! $this->_current_txn instanceof EE_Transaction) { |
|
436 | 436 | return EE_Error::get_notices(); |
437 | 437 | } |
438 | 438 | // link to receipt |
439 | 439 | $template_args['TXN_receipt_url'] = $this->_current_txn->receipt_url('html'); |
440 | - if (! empty($template_args['TXN_receipt_url'])) { |
|
440 | + if ( ! empty($template_args['TXN_receipt_url'])) { |
|
441 | 441 | $template_args['order_conf_desc'] = __( |
442 | 442 | '%1$sCongratulations%2$sYour registration has been successfully processed.%3$sCheck your email for your registration confirmation or click the button below to view / download / print a full description of your purchases and registration information.', |
443 | 443 | 'event_espresso' |
@@ -455,7 +455,7 @@ discard block |
||
455 | 455 | add_action('AHEE__thank_you_page_overview_template__content', array($this, 'get_ajax_content')); |
456 | 456 | } |
457 | 457 | return EEH_Template::locate_template( |
458 | - THANK_YOU_TEMPLATES_PATH . 'thank-you-page-overview.template.php', |
|
458 | + THANK_YOU_TEMPLATES_PATH.'thank-you-page-overview.template.php', |
|
459 | 459 | $template_args, |
460 | 460 | true, |
461 | 461 | true |
@@ -507,7 +507,7 @@ discard block |
||
507 | 507 | '$SPCO_attendee_information_url' |
508 | 508 | ); |
509 | 509 | echo EEH_Template::locate_template( |
510 | - THANK_YOU_TEMPLATES_PATH . 'thank-you-page-registration-details.template.php', |
|
510 | + THANK_YOU_TEMPLATES_PATH.'thank-you-page-registration-details.template.php', |
|
511 | 511 | $template_args, |
512 | 512 | true, |
513 | 513 | true |
@@ -580,7 +580,7 @@ discard block |
||
580 | 580 | */ |
581 | 581 | public function get_ajax_content() |
582 | 582 | { |
583 | - if (! $this->get_txn()) { |
|
583 | + if ( ! $this->get_txn()) { |
|
584 | 584 | return; |
585 | 585 | } |
586 | 586 | // first determine which event(s) require pre-approval or not |
@@ -591,9 +591,9 @@ discard block |
||
591 | 591 | $event = $registration->event(); |
592 | 592 | if ($event instanceof EE_Event) { |
593 | 593 | if ($registration->is_not_approved() && $registration->event() instanceof EE_Event) { |
594 | - $events_requiring_pre_approval[ $event->ID() ] = $event; |
|
594 | + $events_requiring_pre_approval[$event->ID()] = $event; |
|
595 | 595 | } else { |
596 | - $events[ $event->ID() ] = $event; |
|
596 | + $events[$event->ID()] = $event; |
|
597 | 597 | } |
598 | 598 | } |
599 | 599 | } |
@@ -611,7 +611,7 @@ discard block |
||
611 | 611 | */ |
612 | 612 | public function display_details_for_events($events = array()) |
613 | 613 | { |
614 | - if (! empty($events)) { |
|
614 | + if ( ! empty($events)) { |
|
615 | 615 | ?> |
616 | 616 | <div id="espresso-thank-you-page-ajax-content-dv"> |
617 | 617 | <div id="espresso-thank-you-page-ajax-transaction-dv"></div> |
@@ -624,7 +624,7 @@ discard block |
||
624 | 624 | 'event_espresso' |
625 | 625 | ); ?></span> |
626 | 626 | </div> |
627 | - <?php if (! $this->_is_offline_payment_method && ! $this->_payments_closed) : ?> |
|
627 | + <?php if ( ! $this->_is_offline_payment_method && ! $this->_payments_closed) : ?> |
|
628 | 628 | <p id="ee-ajax-loading-pg" class="highlight-bg small-text clear"> |
629 | 629 | <?php echo apply_filters( |
630 | 630 | 'EED_Thank_You_Page__get_ajax_content__waiting_for_IPN_msg', |
@@ -655,7 +655,7 @@ discard block |
||
655 | 655 | */ |
656 | 656 | public function display_details_for_events_requiring_pre_approval($events = array()) |
657 | 657 | { |
658 | - if (! empty($events)) { |
|
658 | + if ( ! empty($events)) { |
|
659 | 659 | ?> |
660 | 660 | <div id="espresso-thank-you-page-not-approved-message-dv"> |
661 | 661 | <h4 class="orange-text"><?php _e('Important Notice:', 'event_espresso'); ?></h4> |
@@ -712,7 +712,7 @@ discard block |
||
712 | 712 | '$SPCO_payment_options_url' |
713 | 713 | ); |
714 | 714 | return EEH_Template::locate_template( |
715 | - THANK_YOU_TEMPLATES_PATH . 'thank-you-page-transaction-details.template.php', |
|
715 | + THANK_YOU_TEMPLATES_PATH.'thank-you-page-transaction-details.template.php', |
|
716 | 716 | $template_args, |
717 | 717 | true, |
718 | 718 | true |
@@ -741,25 +741,25 @@ discard block |
||
741 | 741 | $payment->set_status(EEM_Payment::status_id_pending); |
742 | 742 | } |
743 | 743 | $payment_declined_msg = $payment->STS_ID() === EEM_Payment::status_id_declined |
744 | - ? '<br /><span class="small-text">' . $payment->gateway_response() . '</span>' |
|
744 | + ? '<br /><span class="small-text">'.$payment->gateway_response().'</span>' |
|
745 | 745 | : ''; |
746 | 746 | $html .= ' |
747 | 747 | <tr> |
748 | 748 | <td> |
749 | - ' . $payment->timestamp() . ' |
|
749 | + ' . $payment->timestamp().' |
|
750 | 750 | </td> |
751 | 751 | <td> |
752 | 752 | ' . ( |
753 | 753 | $payment->payment_method() instanceof EE_Payment_Method |
754 | 754 | ? $payment->payment_method()->name() |
755 | 755 | : __('Unknown', 'event_espresso') |
756 | - ) . ' |
|
756 | + ).' |
|
757 | 757 | </td> |
758 | 758 | <td class="jst-rght"> |
759 | - ' . EEH_Template::format_currency($payment->amount()) . ' |
|
759 | + ' . EEH_Template::format_currency($payment->amount()).' |
|
760 | 760 | </td> |
761 | 761 | <td class="jst-rght" style="line-height:1;"> |
762 | - ' . $payment->pretty_status(true) . $payment_declined_msg . ' |
|
762 | + ' . $payment->pretty_status(true).$payment_declined_msg.' |
|
763 | 763 | </td> |
764 | 764 | </tr>'; |
765 | 765 | do_action('AHEE__thank_you_page_payment_details_template__after_each_payment', $payment); |
@@ -817,7 +817,7 @@ discard block |
||
817 | 817 | '$SPCO_payment_options_url' |
818 | 818 | ); |
819 | 819 | return EEH_Template::locate_template( |
820 | - THANK_YOU_TEMPLATES_PATH . 'thank-you-page-payment-details.template.php', |
|
820 | + THANK_YOU_TEMPLATES_PATH.'thank-you-page-payment-details.template.php', |
|
821 | 821 | $template_args, |
822 | 822 | true, |
823 | 823 | true |