@@ -17,2443 +17,2443 @@ discard block |
||
17 | 17 | final class EE_Config implements ResettableInterface |
18 | 18 | { |
19 | 19 | |
20 | - const OPTION_NAME = 'ee_config'; |
|
20 | + const OPTION_NAME = 'ee_config'; |
|
21 | + |
|
22 | + const LOG_NAME = 'ee_config_log'; |
|
23 | + |
|
24 | + const LOG_LENGTH = 100; |
|
25 | + |
|
26 | + const ADDON_OPTION_NAMES = 'ee_config_option_names'; |
|
27 | + |
|
28 | + |
|
29 | + /** |
|
30 | + * instance of the EE_Config object |
|
31 | + * |
|
32 | + * @var EE_Config $_instance |
|
33 | + * @access private |
|
34 | + */ |
|
35 | + private static $_instance; |
|
36 | + |
|
37 | + /** |
|
38 | + * @var boolean $_logging_enabled |
|
39 | + */ |
|
40 | + private static $_logging_enabled = false; |
|
41 | + |
|
42 | + /** |
|
43 | + * @var LegacyShortcodesManager $legacy_shortcodes_manager |
|
44 | + */ |
|
45 | + private $legacy_shortcodes_manager; |
|
46 | + |
|
47 | + /** |
|
48 | + * An StdClass whose property names are addon slugs, |
|
49 | + * and values are their config classes |
|
50 | + * |
|
51 | + * @var StdClass |
|
52 | + */ |
|
53 | + public $addons; |
|
54 | + |
|
55 | + /** |
|
56 | + * @var EE_Admin_Config |
|
57 | + */ |
|
58 | + public $admin; |
|
59 | + |
|
60 | + /** |
|
61 | + * @var EE_Core_Config |
|
62 | + */ |
|
63 | + public $core; |
|
64 | + |
|
65 | + /** |
|
66 | + * @var EE_Currency_Config |
|
67 | + */ |
|
68 | + public $currency; |
|
69 | + |
|
70 | + /** |
|
71 | + * @var EE_Organization_Config |
|
72 | + */ |
|
73 | + public $organization; |
|
74 | + |
|
75 | + /** |
|
76 | + * @var EE_Registration_Config |
|
77 | + */ |
|
78 | + public $registration; |
|
79 | + |
|
80 | + /** |
|
81 | + * @var EE_Template_Config |
|
82 | + */ |
|
83 | + public $template_settings; |
|
84 | + |
|
85 | + /** |
|
86 | + * Holds EE environment values. |
|
87 | + * |
|
88 | + * @var EE_Environment_Config |
|
89 | + */ |
|
90 | + public $environment; |
|
91 | + |
|
92 | + /** |
|
93 | + * settings pertaining to Google maps |
|
94 | + * |
|
95 | + * @var EE_Map_Config |
|
96 | + */ |
|
97 | + public $map_settings; |
|
98 | + |
|
99 | + /** |
|
100 | + * settings pertaining to Taxes |
|
101 | + * |
|
102 | + * @var EE_Tax_Config |
|
103 | + */ |
|
104 | + public $tax_settings; |
|
105 | + |
|
106 | + |
|
107 | + /** |
|
108 | + * Settings pertaining to global messages settings. |
|
109 | + * |
|
110 | + * @var EE_Messages_Config |
|
111 | + */ |
|
112 | + public $messages; |
|
113 | + |
|
114 | + /** |
|
115 | + * @deprecated |
|
116 | + * @var EE_Gateway_Config |
|
117 | + */ |
|
118 | + public $gateway; |
|
119 | + |
|
120 | + /** |
|
121 | + * @var array $_addon_option_names |
|
122 | + * @access private |
|
123 | + */ |
|
124 | + private $_addon_option_names = array(); |
|
125 | + |
|
126 | + /** |
|
127 | + * @var array $_module_route_map |
|
128 | + * @access private |
|
129 | + */ |
|
130 | + private static $_module_route_map = array(); |
|
131 | + |
|
132 | + /** |
|
133 | + * @var array $_module_forward_map |
|
134 | + * @access private |
|
135 | + */ |
|
136 | + private static $_module_forward_map = array(); |
|
137 | + |
|
138 | + /** |
|
139 | + * @var array $_module_view_map |
|
140 | + * @access private |
|
141 | + */ |
|
142 | + private static $_module_view_map = array(); |
|
143 | + |
|
144 | + |
|
145 | + |
|
146 | + /** |
|
147 | + * @singleton method used to instantiate class object |
|
148 | + * @access public |
|
149 | + * @return EE_Config instance |
|
150 | + */ |
|
151 | + public static function instance() |
|
152 | + { |
|
153 | + // check if class object is instantiated, and instantiated properly |
|
154 | + if (! self::$_instance instanceof EE_Config) { |
|
155 | + self::$_instance = new self(); |
|
156 | + } |
|
157 | + return self::$_instance; |
|
158 | + } |
|
159 | + |
|
160 | + |
|
161 | + |
|
162 | + /** |
|
163 | + * Resets the config |
|
164 | + * |
|
165 | + * @param bool $hard_reset if TRUE, sets EE_CONFig back to its original settings in the database. If FALSE |
|
166 | + * (default) leaves the database alone, and merely resets the EE_Config object to |
|
167 | + * reflect its state in the database |
|
168 | + * @param boolean $reinstantiate if TRUE (default) call instance() and return it. Otherwise, just leave |
|
169 | + * $_instance as NULL. Useful in case you want to forget about the old instance on |
|
170 | + * EE_Config, but might not be ready to instantiate EE_Config currently (eg if the |
|
171 | + * site was put into maintenance mode) |
|
172 | + * @return EE_Config |
|
173 | + */ |
|
174 | + public static function reset($hard_reset = false, $reinstantiate = true) |
|
175 | + { |
|
176 | + if (self::$_instance instanceof EE_Config) { |
|
177 | + if ($hard_reset) { |
|
178 | + self::$_instance->legacy_shortcodes_manager = null; |
|
179 | + self::$_instance->_addon_option_names = array(); |
|
180 | + self::$_instance->_initialize_config(); |
|
181 | + self::$_instance->update_espresso_config(); |
|
182 | + } |
|
183 | + self::$_instance->update_addon_option_names(); |
|
184 | + } |
|
185 | + self::$_instance = null; |
|
186 | + //we don't need to reset the static properties imo because those should |
|
187 | + //only change when a module is added or removed. Currently we don't |
|
188 | + //support removing a module during a request when it previously existed |
|
189 | + if ($reinstantiate) { |
|
190 | + return self::instance(); |
|
191 | + } else { |
|
192 | + return null; |
|
193 | + } |
|
194 | + } |
|
195 | + |
|
196 | + |
|
197 | + |
|
198 | + /** |
|
199 | + * class constructor |
|
200 | + * |
|
201 | + * @access private |
|
202 | + */ |
|
203 | + private function __construct() |
|
204 | + { |
|
205 | + do_action('AHEE__EE_Config__construct__begin', $this); |
|
206 | + EE_Config::$_logging_enabled = apply_filters('FHEE__EE_Config___construct__logging_enabled', false); |
|
207 | + // setup empty config classes |
|
208 | + $this->_initialize_config(); |
|
209 | + // load existing EE site settings |
|
210 | + $this->_load_core_config(); |
|
211 | + // confirm everything loaded correctly and set filtered defaults if not |
|
212 | + $this->_verify_config(); |
|
213 | + // register shortcodes and modules |
|
214 | + add_action( |
|
215 | + 'AHEE__EE_System__register_shortcodes_modules_and_widgets', |
|
216 | + array($this, 'register_shortcodes_and_modules'), |
|
217 | + 999 |
|
218 | + ); |
|
219 | + // initialize shortcodes and modules |
|
220 | + add_action('AHEE__EE_System__core_loaded_and_ready', array($this, 'initialize_shortcodes_and_modules')); |
|
221 | + // register widgets |
|
222 | + add_action('widgets_init', array($this, 'widgets_init'), 10); |
|
223 | + // shutdown |
|
224 | + add_action('shutdown', array($this, 'shutdown'), 10); |
|
225 | + // construct__end hook |
|
226 | + do_action('AHEE__EE_Config__construct__end', $this); |
|
227 | + // hardcoded hack |
|
228 | + $this->template_settings->current_espresso_theme = 'Espresso_Arabica_2014'; |
|
229 | + } |
|
230 | + |
|
231 | + |
|
232 | + |
|
233 | + /** |
|
234 | + * @return boolean |
|
235 | + */ |
|
236 | + public static function logging_enabled() |
|
237 | + { |
|
238 | + return self::$_logging_enabled; |
|
239 | + } |
|
240 | + |
|
241 | + |
|
242 | + |
|
243 | + /** |
|
244 | + * use to get the current theme if needed from static context |
|
245 | + * |
|
246 | + * @return string current theme set. |
|
247 | + */ |
|
248 | + public static function get_current_theme() |
|
249 | + { |
|
250 | + return isset(self::$_instance->template_settings->current_espresso_theme) |
|
251 | + ? self::$_instance->template_settings->current_espresso_theme : 'Espresso_Arabica_2014'; |
|
252 | + } |
|
253 | + |
|
254 | + |
|
255 | + |
|
256 | + /** |
|
257 | + * _initialize_config |
|
258 | + * |
|
259 | + * @access private |
|
260 | + * @return void |
|
261 | + */ |
|
262 | + private function _initialize_config() |
|
263 | + { |
|
264 | + EE_Config::trim_log(); |
|
265 | + //set defaults |
|
266 | + $this->_addon_option_names = get_option(EE_Config::ADDON_OPTION_NAMES, array()); |
|
267 | + $this->addons = new stdClass(); |
|
268 | + // set _module_route_map |
|
269 | + EE_Config::$_module_route_map = array(); |
|
270 | + // set _module_forward_map |
|
271 | + EE_Config::$_module_forward_map = array(); |
|
272 | + // set _module_view_map |
|
273 | + EE_Config::$_module_view_map = array(); |
|
274 | + } |
|
275 | + |
|
276 | + |
|
277 | + |
|
278 | + /** |
|
279 | + * load core plugin configuration |
|
280 | + * |
|
281 | + * @access private |
|
282 | + * @return void |
|
283 | + */ |
|
284 | + private function _load_core_config() |
|
285 | + { |
|
286 | + // load_core_config__start hook |
|
287 | + do_action('AHEE__EE_Config___load_core_config__start', $this); |
|
288 | + $espresso_config = $this->get_espresso_config(); |
|
289 | + foreach ($espresso_config as $config => $settings) { |
|
290 | + // load_core_config__start hook |
|
291 | + $settings = apply_filters( |
|
292 | + 'FHEE__EE_Config___load_core_config__config_settings', |
|
293 | + $settings, |
|
294 | + $config, |
|
295 | + $this |
|
296 | + ); |
|
297 | + if (is_object($settings) && property_exists($this, $config)) { |
|
298 | + $this->{$config} = apply_filters('FHEE__EE_Config___load_core_config__' . $config, $settings); |
|
299 | + //call configs populate method to ensure any defaults are set for empty values. |
|
300 | + if (method_exists($settings, 'populate')) { |
|
301 | + $this->{$config}->populate(); |
|
302 | + } |
|
303 | + if (method_exists($settings, 'do_hooks')) { |
|
304 | + $this->{$config}->do_hooks(); |
|
305 | + } |
|
306 | + } |
|
307 | + } |
|
308 | + if (apply_filters('FHEE__EE_Config___load_core_config__update_espresso_config', false)) { |
|
309 | + $this->update_espresso_config(); |
|
310 | + } |
|
311 | + // load_core_config__end hook |
|
312 | + do_action('AHEE__EE_Config___load_core_config__end', $this); |
|
313 | + } |
|
314 | + |
|
315 | + |
|
316 | + |
|
317 | + /** |
|
318 | + * _verify_config |
|
319 | + * |
|
320 | + * @access protected |
|
321 | + * @return void |
|
322 | + */ |
|
323 | + protected function _verify_config() |
|
324 | + { |
|
325 | + $this->core = $this->core instanceof EE_Core_Config |
|
326 | + ? $this->core |
|
327 | + : new EE_Core_Config(); |
|
328 | + $this->core = apply_filters('FHEE__EE_Config___initialize_config__core', $this->core); |
|
329 | + $this->organization = $this->organization instanceof EE_Organization_Config |
|
330 | + ? $this->organization |
|
331 | + : new EE_Organization_Config(); |
|
332 | + $this->organization = apply_filters( |
|
333 | + 'FHEE__EE_Config___initialize_config__organization', |
|
334 | + $this->organization |
|
335 | + ); |
|
336 | + $this->currency = $this->currency instanceof EE_Currency_Config |
|
337 | + ? $this->currency |
|
338 | + : new EE_Currency_Config(); |
|
339 | + $this->currency = apply_filters('FHEE__EE_Config___initialize_config__currency', $this->currency); |
|
340 | + $this->registration = $this->registration instanceof EE_Registration_Config |
|
341 | + ? $this->registration |
|
342 | + : new EE_Registration_Config(); |
|
343 | + $this->registration = apply_filters( |
|
344 | + 'FHEE__EE_Config___initialize_config__registration', |
|
345 | + $this->registration |
|
346 | + ); |
|
347 | + $this->admin = $this->admin instanceof EE_Admin_Config |
|
348 | + ? $this->admin |
|
349 | + : new EE_Admin_Config(); |
|
350 | + $this->admin = apply_filters('FHEE__EE_Config___initialize_config__admin', $this->admin); |
|
351 | + $this->template_settings = $this->template_settings instanceof EE_Template_Config |
|
352 | + ? $this->template_settings |
|
353 | + : new EE_Template_Config(); |
|
354 | + $this->template_settings = apply_filters( |
|
355 | + 'FHEE__EE_Config___initialize_config__template_settings', |
|
356 | + $this->template_settings |
|
357 | + ); |
|
358 | + $this->map_settings = $this->map_settings instanceof EE_Map_Config |
|
359 | + ? $this->map_settings |
|
360 | + : new EE_Map_Config(); |
|
361 | + $this->map_settings = apply_filters('FHEE__EE_Config___initialize_config__map_settings', |
|
362 | + $this->map_settings); |
|
363 | + $this->environment = $this->environment instanceof EE_Environment_Config |
|
364 | + ? $this->environment |
|
365 | + : new EE_Environment_Config(); |
|
366 | + $this->environment = apply_filters('FHEE__EE_Config___initialize_config__environment', |
|
367 | + $this->environment); |
|
368 | + $this->tax_settings = $this->tax_settings instanceof EE_Tax_Config |
|
369 | + ? $this->tax_settings |
|
370 | + : new EE_Tax_Config(); |
|
371 | + $this->tax_settings = apply_filters('FHEE__EE_Config___initialize_config__tax_settings', |
|
372 | + $this->tax_settings); |
|
373 | + $this->messages = apply_filters('FHEE__EE_Config__initialize_config__messages', $this->messages); |
|
374 | + $this->messages = $this->messages instanceof EE_Messages_Config |
|
375 | + ? $this->messages |
|
376 | + : new EE_Messages_Config(); |
|
377 | + $this->gateway = $this->gateway instanceof EE_Gateway_Config |
|
378 | + ? $this->gateway |
|
379 | + : new EE_Gateway_Config(); |
|
380 | + $this->gateway = apply_filters('FHEE__EE_Config___initialize_config__gateway', $this->gateway); |
|
381 | + $this->legacy_shortcodes_manager = null; |
|
382 | + } |
|
383 | + |
|
384 | + |
|
385 | + /** |
|
386 | + * get_espresso_config |
|
387 | + * |
|
388 | + * @access public |
|
389 | + * @return array of espresso config stuff |
|
390 | + */ |
|
391 | + public function get_espresso_config() |
|
392 | + { |
|
393 | + // grab espresso configuration |
|
394 | + return apply_filters( |
|
395 | + 'FHEE__EE_Config__get_espresso_config__CFG', |
|
396 | + get_option(EE_Config::OPTION_NAME, array()) |
|
397 | + ); |
|
398 | + } |
|
399 | + |
|
400 | + |
|
401 | + |
|
402 | + /** |
|
403 | + * double_check_config_comparison |
|
404 | + * |
|
405 | + * @access public |
|
406 | + * @param string $option |
|
407 | + * @param $old_value |
|
408 | + * @param $value |
|
409 | + */ |
|
410 | + public function double_check_config_comparison($option = '', $old_value, $value) |
|
411 | + { |
|
412 | + // make sure we're checking the ee config |
|
413 | + if ($option === EE_Config::OPTION_NAME) { |
|
414 | + // run a loose comparison of the old value against the new value for type and properties, |
|
415 | + // but NOT exact instance like WP update_option does (ie: NOT type safe comparison) |
|
416 | + if ($value != $old_value) { |
|
417 | + // if they are NOT the same, then remove the hook, |
|
418 | + // which means the subsequent update results will be based solely on the update query results |
|
419 | + // the reason we do this is because, as stated above, |
|
420 | + // WP update_option performs an exact instance comparison (===) on any update values passed to it |
|
421 | + // this happens PRIOR to serialization and any subsequent update. |
|
422 | + // If values are found to match their previous old value, |
|
423 | + // then WP bails before performing any update. |
|
424 | + // Since we are passing the EE_Config object, it is comparing the EXACT instance of the saved version |
|
425 | + // it just pulled from the db, with the one being passed to it (which will not match). |
|
426 | + // HOWEVER, once the object is serialized and passed off to MySQL to update, |
|
427 | + // MySQL MAY ALSO NOT perform the update because |
|
428 | + // the string it sees in the db looks the same as the new one it has been passed!!! |
|
429 | + // This results in the query returning an "affected rows" value of ZERO, |
|
430 | + // which gets returned immediately by WP update_option and looks like an error. |
|
431 | + remove_action('update_option', array($this, 'check_config_updated')); |
|
432 | + } |
|
433 | + } |
|
434 | + } |
|
435 | + |
|
436 | + |
|
437 | + |
|
438 | + /** |
|
439 | + * update_espresso_config |
|
440 | + * |
|
441 | + * @access public |
|
442 | + */ |
|
443 | + protected function _reset_espresso_addon_config() |
|
444 | + { |
|
445 | + $this->_addon_option_names = array(); |
|
446 | + foreach ($this->addons as $addon_name => $addon_config_obj) { |
|
447 | + $addon_config_obj = maybe_unserialize($addon_config_obj); |
|
448 | + $config_class = get_class($addon_config_obj); |
|
449 | + if ($addon_config_obj instanceof $config_class && ! $addon_config_obj instanceof __PHP_Incomplete_Class) { |
|
450 | + $this->update_config('addons', $addon_name, $addon_config_obj, false); |
|
451 | + } |
|
452 | + $this->addons->{$addon_name} = null; |
|
453 | + } |
|
454 | + } |
|
455 | + |
|
456 | + |
|
457 | + |
|
458 | + /** |
|
459 | + * update_espresso_config |
|
460 | + * |
|
461 | + * @access public |
|
462 | + * @param bool $add_success |
|
463 | + * @param bool $add_error |
|
464 | + * @return bool |
|
465 | + */ |
|
466 | + public function update_espresso_config($add_success = false, $add_error = true) |
|
467 | + { |
|
468 | + // don't allow config updates during WP heartbeats |
|
469 | + if (\EE_Registry::instance()->REQ->get('action', '') === 'heartbeat') { |
|
470 | + return false; |
|
471 | + } |
|
472 | + // commented out the following re: https://events.codebasehq.com/projects/event-espresso/tickets/8197 |
|
473 | + //$clone = clone( self::$_instance ); |
|
474 | + //self::$_instance = NULL; |
|
475 | + do_action('AHEE__EE_Config__update_espresso_config__begin', $this); |
|
476 | + $this->_reset_espresso_addon_config(); |
|
477 | + // hook into update_option because that happens AFTER the ( $value === $old_value ) conditional |
|
478 | + // but BEFORE the actual update occurs |
|
479 | + add_action('update_option', array($this, 'double_check_config_comparison'), 1, 3); |
|
480 | + // don't want to persist legacy_shortcodes_manager, but don't want to lose it either |
|
481 | + $legacy_shortcodes_manager = $this->legacy_shortcodes_manager; |
|
482 | + $this->legacy_shortcodes_manager = null; |
|
483 | + // now update "ee_config" |
|
484 | + $saved = update_option(EE_Config::OPTION_NAME, $this); |
|
485 | + $this->legacy_shortcodes_manager = $legacy_shortcodes_manager; |
|
486 | + EE_Config::log(EE_Config::OPTION_NAME); |
|
487 | + // if not saved... check if the hook we just added still exists; |
|
488 | + // if it does, it means one of two things: |
|
489 | + // that update_option bailed at the ( $value === $old_value ) conditional, |
|
490 | + // or... |
|
491 | + // the db update query returned 0 rows affected |
|
492 | + // (probably because the data value was the same from it's perspective) |
|
493 | + // so the existence of the hook means that a negative result from update_option is NOT an error, |
|
494 | + // but just means no update occurred, so don't display an error to the user. |
|
495 | + // BUT... if update_option returns FALSE, AND the hook is missing, |
|
496 | + // then it means that something truly went wrong |
|
497 | + $saved = ! $saved ? has_action('update_option', array($this, 'double_check_config_comparison')) : $saved; |
|
498 | + // remove our action since we don't want it in the system anymore |
|
499 | + remove_action('update_option', array($this, 'double_check_config_comparison'), 1); |
|
500 | + do_action('AHEE__EE_Config__update_espresso_config__end', $this, $saved); |
|
501 | + //self::$_instance = $clone; |
|
502 | + //unset( $clone ); |
|
503 | + // if config remains the same or was updated successfully |
|
504 | + if ($saved) { |
|
505 | + if ($add_success) { |
|
506 | + EE_Error::add_success( |
|
507 | + __('The Event Espresso Configuration Settings have been successfully updated.', 'event_espresso'), |
|
508 | + __FILE__, |
|
509 | + __FUNCTION__, |
|
510 | + __LINE__ |
|
511 | + ); |
|
512 | + } |
|
513 | + return true; |
|
514 | + } else { |
|
515 | + if ($add_error) { |
|
516 | + EE_Error::add_error( |
|
517 | + __('The Event Espresso Configuration Settings were not updated.', 'event_espresso'), |
|
518 | + __FILE__, |
|
519 | + __FUNCTION__, |
|
520 | + __LINE__ |
|
521 | + ); |
|
522 | + } |
|
523 | + return false; |
|
524 | + } |
|
525 | + } |
|
526 | + |
|
527 | + |
|
528 | + |
|
529 | + /** |
|
530 | + * _verify_config_params |
|
531 | + * |
|
532 | + * @access private |
|
533 | + * @param string $section |
|
534 | + * @param string $name |
|
535 | + * @param string $config_class |
|
536 | + * @param EE_Config_Base $config_obj |
|
537 | + * @param array $tests_to_run |
|
538 | + * @param bool $display_errors |
|
539 | + * @return bool TRUE on success, FALSE on fail |
|
540 | + */ |
|
541 | + private function _verify_config_params( |
|
542 | + $section = '', |
|
543 | + $name = '', |
|
544 | + $config_class = '', |
|
545 | + $config_obj = null, |
|
546 | + $tests_to_run = array(1, 2, 3, 4, 5, 6, 7, 8), |
|
547 | + $display_errors = true |
|
548 | + ) { |
|
549 | + try { |
|
550 | + foreach ($tests_to_run as $test) { |
|
551 | + switch ($test) { |
|
552 | + // TEST #1 : check that section was set |
|
553 | + case 1 : |
|
554 | + if (empty($section)) { |
|
555 | + if ($display_errors) { |
|
556 | + throw new EE_Error( |
|
557 | + sprintf( |
|
558 | + __( |
|
559 | + 'No configuration section has been provided while attempting to save "%s".', |
|
560 | + 'event_espresso' |
|
561 | + ), |
|
562 | + $config_class |
|
563 | + ) |
|
564 | + ); |
|
565 | + } |
|
566 | + return false; |
|
567 | + } |
|
568 | + break; |
|
569 | + // TEST #2 : check that settings section exists |
|
570 | + case 2 : |
|
571 | + if (! isset($this->{$section})) { |
|
572 | + if ($display_errors) { |
|
573 | + throw new EE_Error( |
|
574 | + sprintf( |
|
575 | + __('The "%s" configuration section does not exist.', 'event_espresso'), |
|
576 | + $section |
|
577 | + ) |
|
578 | + ); |
|
579 | + } |
|
580 | + return false; |
|
581 | + } |
|
582 | + break; |
|
583 | + // TEST #3 : check that section is the proper format |
|
584 | + case 3 : |
|
585 | + if ( |
|
586 | + ! ($this->{$section} instanceof EE_Config_Base || $this->{$section} instanceof stdClass) |
|
587 | + ) { |
|
588 | + if ($display_errors) { |
|
589 | + throw new EE_Error( |
|
590 | + sprintf( |
|
591 | + __( |
|
592 | + 'The "%s" configuration settings have not been formatted correctly.', |
|
593 | + 'event_espresso' |
|
594 | + ), |
|
595 | + $section |
|
596 | + ) |
|
597 | + ); |
|
598 | + } |
|
599 | + return false; |
|
600 | + } |
|
601 | + break; |
|
602 | + // TEST #4 : check that config section name has been set |
|
603 | + case 4 : |
|
604 | + if (empty($name)) { |
|
605 | + if ($display_errors) { |
|
606 | + throw new EE_Error( |
|
607 | + __( |
|
608 | + 'No name has been provided for the specific configuration section.', |
|
609 | + 'event_espresso' |
|
610 | + ) |
|
611 | + ); |
|
612 | + } |
|
613 | + return false; |
|
614 | + } |
|
615 | + break; |
|
616 | + // TEST #5 : check that a config class name has been set |
|
617 | + case 5 : |
|
618 | + if (empty($config_class)) { |
|
619 | + if ($display_errors) { |
|
620 | + throw new EE_Error( |
|
621 | + __( |
|
622 | + 'No class name has been provided for the specific configuration section.', |
|
623 | + 'event_espresso' |
|
624 | + ) |
|
625 | + ); |
|
626 | + } |
|
627 | + return false; |
|
628 | + } |
|
629 | + break; |
|
630 | + // TEST #6 : verify config class is accessible |
|
631 | + case 6 : |
|
632 | + if (! class_exists($config_class)) { |
|
633 | + if ($display_errors) { |
|
634 | + throw new EE_Error( |
|
635 | + sprintf( |
|
636 | + __( |
|
637 | + 'The "%s" class does not exist. Please ensure that an autoloader has been set for it.', |
|
638 | + 'event_espresso' |
|
639 | + ), |
|
640 | + $config_class |
|
641 | + ) |
|
642 | + ); |
|
643 | + } |
|
644 | + return false; |
|
645 | + } |
|
646 | + break; |
|
647 | + // TEST #7 : check that config has even been set |
|
648 | + case 7 : |
|
649 | + if (! isset($this->{$section}->{$name})) { |
|
650 | + if ($display_errors) { |
|
651 | + throw new EE_Error( |
|
652 | + sprintf( |
|
653 | + __('No configuration has been set for "%1$s->%2$s".', 'event_espresso'), |
|
654 | + $section, |
|
655 | + $name |
|
656 | + ) |
|
657 | + ); |
|
658 | + } |
|
659 | + return false; |
|
660 | + } else { |
|
661 | + // and make sure it's not serialized |
|
662 | + $this->{$section}->{$name} = maybe_unserialize($this->{$section}->{$name}); |
|
663 | + } |
|
664 | + break; |
|
665 | + // TEST #8 : check that config is the requested type |
|
666 | + case 8 : |
|
667 | + if (! $this->{$section}->{$name} instanceof $config_class) { |
|
668 | + if ($display_errors) { |
|
669 | + throw new EE_Error( |
|
670 | + sprintf( |
|
671 | + __( |
|
672 | + 'The configuration for "%1$s->%2$s" is not of the "%3$s" class.', |
|
673 | + 'event_espresso' |
|
674 | + ), |
|
675 | + $section, |
|
676 | + $name, |
|
677 | + $config_class |
|
678 | + ) |
|
679 | + ); |
|
680 | + } |
|
681 | + return false; |
|
682 | + } |
|
683 | + break; |
|
684 | + // TEST #9 : verify config object |
|
685 | + case 9 : |
|
686 | + if (! $config_obj instanceof EE_Config_Base) { |
|
687 | + if ($display_errors) { |
|
688 | + throw new EE_Error( |
|
689 | + sprintf( |
|
690 | + __('The "%s" class is not an instance of EE_Config_Base.', 'event_espresso'), |
|
691 | + print_r($config_obj, true) |
|
692 | + ) |
|
693 | + ); |
|
694 | + } |
|
695 | + return false; |
|
696 | + } |
|
697 | + break; |
|
698 | + } |
|
699 | + } |
|
700 | + } catch (EE_Error $e) { |
|
701 | + $e->get_error(); |
|
702 | + } |
|
703 | + // you have successfully run the gauntlet |
|
704 | + return true; |
|
705 | + } |
|
706 | + |
|
707 | + |
|
708 | + |
|
709 | + /** |
|
710 | + * _generate_config_option_name |
|
711 | + * |
|
712 | + * @access protected |
|
713 | + * @param string $section |
|
714 | + * @param string $name |
|
715 | + * @return string |
|
716 | + */ |
|
717 | + private function _generate_config_option_name($section = '', $name = '') |
|
718 | + { |
|
719 | + return 'ee_config-' . strtolower($section . '-' . str_replace(array('EE_', 'EED_'), '', $name)); |
|
720 | + } |
|
721 | + |
|
722 | + |
|
723 | + |
|
724 | + /** |
|
725 | + * _set_config_class |
|
726 | + * ensures that a config class is set, either from a passed config class or one generated from the config name |
|
727 | + * |
|
728 | + * @access private |
|
729 | + * @param string $config_class |
|
730 | + * @param string $name |
|
731 | + * @return string |
|
732 | + */ |
|
733 | + private function _set_config_class($config_class = '', $name = '') |
|
734 | + { |
|
735 | + return ! empty($config_class) |
|
736 | + ? $config_class |
|
737 | + : str_replace(' ', '_', ucwords(str_replace('_', ' ', $name))) . '_Config'; |
|
738 | + } |
|
739 | + |
|
740 | + |
|
741 | + |
|
742 | + /** |
|
743 | + * set_config |
|
744 | + * |
|
745 | + * @access protected |
|
746 | + * @param string $section |
|
747 | + * @param string $name |
|
748 | + * @param string $config_class |
|
749 | + * @param EE_Config_Base $config_obj |
|
750 | + * @return EE_Config_Base |
|
751 | + */ |
|
752 | + public function set_config($section = '', $name = '', $config_class = '', EE_Config_Base $config_obj = null) |
|
753 | + { |
|
754 | + // ensure config class is set to something |
|
755 | + $config_class = $this->_set_config_class($config_class, $name); |
|
756 | + // run tests 1-4, 6, and 7 to verify all config params are set and valid |
|
757 | + if (! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) { |
|
758 | + return null; |
|
759 | + } |
|
760 | + $config_option_name = $this->_generate_config_option_name($section, $name); |
|
761 | + // if the config option name hasn't been added yet to the list of option names we're tracking, then do so now |
|
762 | + if (! isset($this->_addon_option_names[$config_option_name])) { |
|
763 | + $this->_addon_option_names[$config_option_name] = $config_class; |
|
764 | + $this->update_addon_option_names(); |
|
765 | + } |
|
766 | + // verify the incoming config object but suppress errors |
|
767 | + if (! $this->_verify_config_params($section, $name, $config_class, $config_obj, array(9), false)) { |
|
768 | + $config_obj = new $config_class(); |
|
769 | + } |
|
770 | + if (get_option($config_option_name)) { |
|
771 | + EE_Config::log($config_option_name); |
|
772 | + update_option($config_option_name, $config_obj); |
|
773 | + $this->{$section}->{$name} = $config_obj; |
|
774 | + return $this->{$section}->{$name}; |
|
775 | + } else { |
|
776 | + // create a wp-option for this config |
|
777 | + if (add_option($config_option_name, $config_obj, '', 'no')) { |
|
778 | + $this->{$section}->{$name} = maybe_unserialize($config_obj); |
|
779 | + return $this->{$section}->{$name}; |
|
780 | + } else { |
|
781 | + EE_Error::add_error( |
|
782 | + sprintf(__('The "%s" could not be saved to the database.', 'event_espresso'), $config_class), |
|
783 | + __FILE__, |
|
784 | + __FUNCTION__, |
|
785 | + __LINE__ |
|
786 | + ); |
|
787 | + return null; |
|
788 | + } |
|
789 | + } |
|
790 | + } |
|
791 | + |
|
792 | + |
|
793 | + |
|
794 | + /** |
|
795 | + * update_config |
|
796 | + * Important: the config object must ALREADY be set, otherwise this will produce an error. |
|
797 | + * |
|
798 | + * @access public |
|
799 | + * @param string $section |
|
800 | + * @param string $name |
|
801 | + * @param EE_Config_Base|string $config_obj |
|
802 | + * @param bool $throw_errors |
|
803 | + * @return bool |
|
804 | + */ |
|
805 | + public function update_config($section = '', $name = '', $config_obj = '', $throw_errors = true) |
|
806 | + { |
|
807 | + // don't allow config updates during WP heartbeats |
|
808 | + if (\EE_Registry::instance()->REQ->get('action', '') === 'heartbeat') { |
|
809 | + return false; |
|
810 | + } |
|
811 | + $config_obj = maybe_unserialize($config_obj); |
|
812 | + // get class name of the incoming object |
|
813 | + $config_class = get_class($config_obj); |
|
814 | + // run tests 1-5 and 9 to verify config |
|
815 | + if (! $this->_verify_config_params( |
|
816 | + $section, |
|
817 | + $name, |
|
818 | + $config_class, |
|
819 | + $config_obj, |
|
820 | + array(1, 2, 3, 4, 7, 9) |
|
821 | + ) |
|
822 | + ) { |
|
823 | + return false; |
|
824 | + } |
|
825 | + $config_option_name = $this->_generate_config_option_name($section, $name); |
|
826 | + // check if config object has been added to db by seeing if config option name is in $this->_addon_option_names array |
|
827 | + if (! isset($this->_addon_option_names[$config_option_name])) { |
|
828 | + // save new config to db |
|
829 | + if ($this->set_config($section, $name, $config_class, $config_obj)) { |
|
830 | + return true; |
|
831 | + } |
|
832 | + } else { |
|
833 | + // first check if the record already exists |
|
834 | + $existing_config = get_option($config_option_name); |
|
835 | + $config_obj = serialize($config_obj); |
|
836 | + // just return if db record is already up to date (NOT type safe comparison) |
|
837 | + if ($existing_config == $config_obj) { |
|
838 | + $this->{$section}->{$name} = $config_obj; |
|
839 | + return true; |
|
840 | + } else if (update_option($config_option_name, $config_obj)) { |
|
841 | + EE_Config::log($config_option_name); |
|
842 | + // update wp-option for this config class |
|
843 | + $this->{$section}->{$name} = $config_obj; |
|
844 | + return true; |
|
845 | + } elseif ($throw_errors) { |
|
846 | + EE_Error::add_error( |
|
847 | + sprintf( |
|
848 | + __( |
|
849 | + 'The "%1$s" object stored at"%2$s" was not successfully updated in the database.', |
|
850 | + 'event_espresso' |
|
851 | + ), |
|
852 | + $config_class, |
|
853 | + 'EE_Config->' . $section . '->' . $name |
|
854 | + ), |
|
855 | + __FILE__, |
|
856 | + __FUNCTION__, |
|
857 | + __LINE__ |
|
858 | + ); |
|
859 | + } |
|
860 | + } |
|
861 | + return false; |
|
862 | + } |
|
863 | + |
|
864 | + |
|
865 | + |
|
866 | + /** |
|
867 | + * get_config |
|
868 | + * |
|
869 | + * @access public |
|
870 | + * @param string $section |
|
871 | + * @param string $name |
|
872 | + * @param string $config_class |
|
873 | + * @return mixed EE_Config_Base | NULL |
|
874 | + */ |
|
875 | + public function get_config($section = '', $name = '', $config_class = '') |
|
876 | + { |
|
877 | + // ensure config class is set to something |
|
878 | + $config_class = $this->_set_config_class($config_class, $name); |
|
879 | + // run tests 1-4, 6 and 7 to verify that all params have been set |
|
880 | + if (! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) { |
|
881 | + return null; |
|
882 | + } |
|
883 | + // now test if the requested config object exists, but suppress errors |
|
884 | + if ($this->_verify_config_params($section, $name, $config_class, null, array(7, 8), false)) { |
|
885 | + // config already exists, so pass it back |
|
886 | + return $this->{$section}->{$name}; |
|
887 | + } |
|
888 | + // load config option from db if it exists |
|
889 | + $config_obj = $this->get_config_option($this->_generate_config_option_name($section, $name)); |
|
890 | + // verify the newly retrieved config object, but suppress errors |
|
891 | + if ($this->_verify_config_params($section, $name, $config_class, $config_obj, array(9), false)) { |
|
892 | + // config is good, so set it and pass it back |
|
893 | + $this->{$section}->{$name} = $config_obj; |
|
894 | + return $this->{$section}->{$name}; |
|
895 | + } |
|
896 | + // oops! $config_obj is not already set and does not exist in the db, so create a new one |
|
897 | + $config_obj = $this->set_config($section, $name, $config_class); |
|
898 | + // verify the newly created config object |
|
899 | + if ($this->_verify_config_params($section, $name, $config_class, $config_obj, array(9))) { |
|
900 | + return $this->{$section}->{$name}; |
|
901 | + } else { |
|
902 | + EE_Error::add_error( |
|
903 | + sprintf(__('The "%s" could not be retrieved from the database.', 'event_espresso'), $config_class), |
|
904 | + __FILE__, |
|
905 | + __FUNCTION__, |
|
906 | + __LINE__ |
|
907 | + ); |
|
908 | + } |
|
909 | + return null; |
|
910 | + } |
|
911 | + |
|
912 | + |
|
913 | + |
|
914 | + /** |
|
915 | + * get_config_option |
|
916 | + * |
|
917 | + * @access public |
|
918 | + * @param string $config_option_name |
|
919 | + * @return mixed EE_Config_Base | FALSE |
|
920 | + */ |
|
921 | + public function get_config_option($config_option_name = '') |
|
922 | + { |
|
923 | + // retrieve the wp-option for this config class. |
|
924 | + $config_option = maybe_unserialize(get_option($config_option_name, array())); |
|
925 | + if (empty($config_option)) { |
|
926 | + EE_Config::log($config_option_name . '-NOT-FOUND'); |
|
927 | + } |
|
928 | + return $config_option; |
|
929 | + } |
|
930 | + |
|
931 | + |
|
932 | + |
|
933 | + /** |
|
934 | + * log |
|
935 | + * |
|
936 | + * @param string $config_option_name |
|
937 | + */ |
|
938 | + public static function log($config_option_name = '') |
|
939 | + { |
|
940 | + if (EE_Config::logging_enabled() && ! empty($config_option_name)) { |
|
941 | + $config_log = get_option(EE_Config::LOG_NAME, array()); |
|
942 | + //copy incoming $_REQUEST and sanitize it so we can save it |
|
943 | + $_request = $_REQUEST; |
|
944 | + array_walk_recursive($_request, 'sanitize_text_field'); |
|
945 | + $config_log[(string)microtime(true)] = array( |
|
946 | + 'config_name' => $config_option_name, |
|
947 | + 'request' => $_request, |
|
948 | + ); |
|
949 | + update_option(EE_Config::LOG_NAME, $config_log); |
|
950 | + } |
|
951 | + } |
|
952 | + |
|
953 | + |
|
954 | + |
|
955 | + /** |
|
956 | + * trim_log |
|
957 | + * reduces the size of the config log to the length specified by EE_Config::LOG_LENGTH |
|
958 | + */ |
|
959 | + public static function trim_log() |
|
960 | + { |
|
961 | + if (! EE_Config::logging_enabled()) { |
|
962 | + return; |
|
963 | + } |
|
964 | + $config_log = maybe_unserialize(get_option(EE_Config::LOG_NAME, array())); |
|
965 | + $log_length = count($config_log); |
|
966 | + if ($log_length > EE_Config::LOG_LENGTH) { |
|
967 | + ksort($config_log); |
|
968 | + $config_log = array_slice($config_log, $log_length - EE_Config::LOG_LENGTH, null, true); |
|
969 | + update_option(EE_Config::LOG_NAME, $config_log); |
|
970 | + } |
|
971 | + } |
|
972 | + |
|
973 | + |
|
974 | + |
|
975 | + /** |
|
976 | + * get_page_for_posts |
|
977 | + * if the wp-option "show_on_front" is set to "page", then this is the post_name for the post set in the |
|
978 | + * wp-option "page_for_posts", or "posts" if no page is selected |
|
979 | + * |
|
980 | + * @access public |
|
981 | + * @return string |
|
982 | + */ |
|
983 | + public static function get_page_for_posts() |
|
984 | + { |
|
985 | + $page_for_posts = get_option('page_for_posts'); |
|
986 | + if (! $page_for_posts) { |
|
987 | + return 'posts'; |
|
988 | + } |
|
989 | + /** @type WPDB $wpdb */ |
|
990 | + global $wpdb; |
|
991 | + $SQL = "SELECT post_name from $wpdb->posts WHERE post_type='posts' OR post_type='page' AND post_status='publish' AND ID=%d"; |
|
992 | + return $wpdb->get_var($wpdb->prepare($SQL, $page_for_posts)); |
|
993 | + } |
|
994 | + |
|
995 | + |
|
996 | + |
|
997 | + /** |
|
998 | + * register_shortcodes_and_modules. |
|
999 | + * At this point, it's too early to tell if we're maintenance mode or not. |
|
1000 | + * In fact, this is where we give modules a chance to let core know they exist |
|
1001 | + * so they can help trigger maintenance mode if it's needed |
|
1002 | + * |
|
1003 | + * @access public |
|
1004 | + * @return void |
|
1005 | + */ |
|
1006 | + public function register_shortcodes_and_modules() |
|
1007 | + { |
|
1008 | + // allow modules to set hooks for the rest of the system |
|
1009 | + EE_Registry::instance()->modules = $this->_register_modules(); |
|
1010 | + } |
|
1011 | + |
|
1012 | + |
|
1013 | + |
|
1014 | + /** |
|
1015 | + * initialize_shortcodes_and_modules |
|
1016 | + * meaning they can start adding their hooks to get stuff done |
|
1017 | + * |
|
1018 | + * @access public |
|
1019 | + * @return void |
|
1020 | + */ |
|
1021 | + public function initialize_shortcodes_and_modules() |
|
1022 | + { |
|
1023 | + // allow modules to set hooks for the rest of the system |
|
1024 | + $this->_initialize_modules(); |
|
1025 | + } |
|
1026 | + |
|
1027 | + |
|
1028 | + |
|
1029 | + /** |
|
1030 | + * widgets_init |
|
1031 | + * |
|
1032 | + * @access private |
|
1033 | + * @return void |
|
1034 | + */ |
|
1035 | + public function widgets_init() |
|
1036 | + { |
|
1037 | + //only init widgets on admin pages when not in complete maintenance, and |
|
1038 | + //on frontend when not in any maintenance mode |
|
1039 | + if ( |
|
1040 | + ! EE_Maintenance_Mode::instance()->level() |
|
1041 | + || ( |
|
1042 | + is_admin() |
|
1043 | + && EE_Maintenance_Mode::instance()->level() !== EE_Maintenance_Mode::level_2_complete_maintenance |
|
1044 | + ) |
|
1045 | + ) { |
|
1046 | + // grab list of installed widgets |
|
1047 | + $widgets_to_register = glob(EE_WIDGETS . '*', GLOB_ONLYDIR); |
|
1048 | + // filter list of modules to register |
|
1049 | + $widgets_to_register = apply_filters( |
|
1050 | + 'FHEE__EE_Config__register_widgets__widgets_to_register', |
|
1051 | + $widgets_to_register |
|
1052 | + ); |
|
1053 | + if (! empty($widgets_to_register)) { |
|
1054 | + // cycle thru widget folders |
|
1055 | + foreach ($widgets_to_register as $widget_path) { |
|
1056 | + // add to list of installed widget modules |
|
1057 | + EE_Config::register_ee_widget($widget_path); |
|
1058 | + } |
|
1059 | + } |
|
1060 | + // filter list of installed modules |
|
1061 | + EE_Registry::instance()->widgets = apply_filters( |
|
1062 | + 'FHEE__EE_Config__register_widgets__installed_widgets', |
|
1063 | + EE_Registry::instance()->widgets |
|
1064 | + ); |
|
1065 | + } |
|
1066 | + } |
|
1067 | + |
|
1068 | + |
|
1069 | + |
|
1070 | + /** |
|
1071 | + * register_ee_widget - makes core aware of this widget |
|
1072 | + * |
|
1073 | + * @access public |
|
1074 | + * @param string $widget_path - full path up to and including widget folder |
|
1075 | + * @return void |
|
1076 | + */ |
|
1077 | + public static function register_ee_widget($widget_path = null) |
|
1078 | + { |
|
1079 | + do_action('AHEE__EE_Config__register_widget__begin', $widget_path); |
|
1080 | + $widget_ext = '.widget.php'; |
|
1081 | + // make all separators match |
|
1082 | + $widget_path = rtrim(str_replace('/\\', DS, $widget_path), DS); |
|
1083 | + // does the file path INCLUDE the actual file name as part of the path ? |
|
1084 | + if (strpos($widget_path, $widget_ext) !== false) { |
|
1085 | + // grab and shortcode file name from directory name and break apart at dots |
|
1086 | + $file_name = explode('.', basename($widget_path)); |
|
1087 | + // take first segment from file name pieces and remove class prefix if it exists |
|
1088 | + $widget = strpos($file_name[0], 'EEW_') === 0 ? substr($file_name[0], 4) : $file_name[0]; |
|
1089 | + // sanitize shortcode directory name |
|
1090 | + $widget = sanitize_key($widget); |
|
1091 | + // now we need to rebuild the shortcode path |
|
1092 | + $widget_path = explode(DS, $widget_path); |
|
1093 | + // remove last segment |
|
1094 | + array_pop($widget_path); |
|
1095 | + // glue it back together |
|
1096 | + $widget_path = implode(DS, $widget_path); |
|
1097 | + } else { |
|
1098 | + // grab and sanitize widget directory name |
|
1099 | + $widget = sanitize_key(basename($widget_path)); |
|
1100 | + } |
|
1101 | + // create classname from widget directory name |
|
1102 | + $widget = str_replace(' ', '_', ucwords(str_replace('_', ' ', $widget))); |
|
1103 | + // add class prefix |
|
1104 | + $widget_class = 'EEW_' . $widget; |
|
1105 | + // does the widget exist ? |
|
1106 | + if (! is_readable($widget_path . DS . $widget_class . $widget_ext)) { |
|
1107 | + $msg = sprintf( |
|
1108 | + __( |
|
1109 | + 'The requested %s widget file could not be found or is not readable due to file permissions. Please ensure the following path is correct: %s', |
|
1110 | + 'event_espresso' |
|
1111 | + ), |
|
1112 | + $widget_class, |
|
1113 | + $widget_path . DS . $widget_class . $widget_ext |
|
1114 | + ); |
|
1115 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
1116 | + return; |
|
1117 | + } |
|
1118 | + // load the widget class file |
|
1119 | + require_once($widget_path . DS . $widget_class . $widget_ext); |
|
1120 | + // verify that class exists |
|
1121 | + if (! class_exists($widget_class)) { |
|
1122 | + $msg = sprintf(__('The requested %s widget class does not exist.', 'event_espresso'), $widget_class); |
|
1123 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
1124 | + return; |
|
1125 | + } |
|
1126 | + register_widget($widget_class); |
|
1127 | + // add to array of registered widgets |
|
1128 | + EE_Registry::instance()->widgets->{$widget_class} = $widget_path . DS . $widget_class . $widget_ext; |
|
1129 | + } |
|
1130 | + |
|
1131 | + |
|
1132 | + |
|
1133 | + /** |
|
1134 | + * _register_modules |
|
1135 | + * |
|
1136 | + * @access private |
|
1137 | + * @return array |
|
1138 | + */ |
|
1139 | + private function _register_modules() |
|
1140 | + { |
|
1141 | + // grab list of installed modules |
|
1142 | + $modules_to_register = glob(EE_MODULES . '*', GLOB_ONLYDIR); |
|
1143 | + // filter list of modules to register |
|
1144 | + $modules_to_register = apply_filters( |
|
1145 | + 'FHEE__EE_Config__register_modules__modules_to_register', |
|
1146 | + $modules_to_register |
|
1147 | + ); |
|
1148 | + if (! empty($modules_to_register)) { |
|
1149 | + // loop through folders |
|
1150 | + foreach ($modules_to_register as $module_path) { |
|
1151 | + /**TEMPORARILY EXCLUDE gateways from modules for time being**/ |
|
1152 | + if ( |
|
1153 | + $module_path !== EE_MODULES . 'zzz-copy-this-module-template' |
|
1154 | + && $module_path !== EE_MODULES . 'gateways' |
|
1155 | + ) { |
|
1156 | + // add to list of installed modules |
|
1157 | + EE_Config::register_module($module_path); |
|
1158 | + } |
|
1159 | + } |
|
1160 | + } |
|
1161 | + // filter list of installed modules |
|
1162 | + return apply_filters( |
|
1163 | + 'FHEE__EE_Config___register_modules__installed_modules', |
|
1164 | + EE_Registry::instance()->modules |
|
1165 | + ); |
|
1166 | + } |
|
1167 | + |
|
1168 | + |
|
1169 | + |
|
1170 | + /** |
|
1171 | + * register_module - makes core aware of this module |
|
1172 | + * |
|
1173 | + * @access public |
|
1174 | + * @param string $module_path - full path up to and including module folder |
|
1175 | + * @return bool |
|
1176 | + */ |
|
1177 | + public static function register_module($module_path = null) |
|
1178 | + { |
|
1179 | + do_action('AHEE__EE_Config__register_module__begin', $module_path); |
|
1180 | + $module_ext = '.module.php'; |
|
1181 | + // make all separators match |
|
1182 | + $module_path = str_replace(array('\\', '/'), DS, $module_path); |
|
1183 | + // does the file path INCLUDE the actual file name as part of the path ? |
|
1184 | + if (strpos($module_path, $module_ext) !== false) { |
|
1185 | + // grab and shortcode file name from directory name and break apart at dots |
|
1186 | + $module_file = explode('.', basename($module_path)); |
|
1187 | + // now we need to rebuild the shortcode path |
|
1188 | + $module_path = explode(DS, $module_path); |
|
1189 | + // remove last segment |
|
1190 | + array_pop($module_path); |
|
1191 | + // glue it back together |
|
1192 | + $module_path = implode(DS, $module_path) . DS; |
|
1193 | + // take first segment from file name pieces and sanitize it |
|
1194 | + $module = preg_replace('/[^a-zA-Z0-9_\-]/', '', $module_file[0]); |
|
1195 | + // ensure class prefix is added |
|
1196 | + $module_class = strpos($module, 'EED_') !== 0 ? 'EED_' . $module : $module; |
|
1197 | + } else { |
|
1198 | + // we need to generate the filename based off of the folder name |
|
1199 | + // grab and sanitize module name |
|
1200 | + $module = strtolower(basename($module_path)); |
|
1201 | + $module = preg_replace('/[^a-z0-9_\-]/', '', $module); |
|
1202 | + // like trailingslashit() |
|
1203 | + $module_path = rtrim($module_path, DS) . DS; |
|
1204 | + // create classname from module directory name |
|
1205 | + $module = str_replace(' ', '_', ucwords(str_replace('_', ' ', $module))); |
|
1206 | + // add class prefix |
|
1207 | + $module_class = 'EED_' . $module; |
|
1208 | + } |
|
1209 | + // does the module exist ? |
|
1210 | + if (! is_readable($module_path . DS . $module_class . $module_ext)) { |
|
1211 | + $msg = sprintf( |
|
1212 | + __( |
|
1213 | + 'The requested %s module file could not be found or is not readable due to file permissions.', |
|
1214 | + 'event_espresso' |
|
1215 | + ), |
|
1216 | + $module |
|
1217 | + ); |
|
1218 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
1219 | + return false; |
|
1220 | + } |
|
1221 | + // load the module class file |
|
1222 | + require_once($module_path . $module_class . $module_ext); |
|
1223 | + // verify that class exists |
|
1224 | + if (! class_exists($module_class)) { |
|
1225 | + $msg = sprintf(__('The requested %s module class does not exist.', 'event_espresso'), $module_class); |
|
1226 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
1227 | + return false; |
|
1228 | + } |
|
1229 | + // add to array of registered modules |
|
1230 | + EE_Registry::instance()->modules->{$module_class} = $module_path . $module_class . $module_ext; |
|
1231 | + do_action( |
|
1232 | + 'AHEE__EE_Config__register_module__complete', |
|
1233 | + $module_class, |
|
1234 | + EE_Registry::instance()->modules->{$module_class} |
|
1235 | + ); |
|
1236 | + return true; |
|
1237 | + } |
|
1238 | + |
|
1239 | + |
|
1240 | + |
|
1241 | + /** |
|
1242 | + * _initialize_modules |
|
1243 | + * allow modules to set hooks for the rest of the system |
|
1244 | + * |
|
1245 | + * @access private |
|
1246 | + * @return void |
|
1247 | + */ |
|
1248 | + private function _initialize_modules() |
|
1249 | + { |
|
1250 | + // cycle thru shortcode folders |
|
1251 | + foreach (EE_Registry::instance()->modules as $module_class => $module_path) { |
|
1252 | + // fire the shortcode class's set_hooks methods in case it needs to hook into other parts of the system |
|
1253 | + // which set hooks ? |
|
1254 | + if (is_admin()) { |
|
1255 | + // fire immediately |
|
1256 | + call_user_func(array($module_class, 'set_hooks_admin')); |
|
1257 | + } else { |
|
1258 | + // delay until other systems are online |
|
1259 | + add_action( |
|
1260 | + 'AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons', |
|
1261 | + array($module_class, 'set_hooks') |
|
1262 | + ); |
|
1263 | + } |
|
1264 | + } |
|
1265 | + } |
|
1266 | + |
|
1267 | + |
|
1268 | + |
|
1269 | + /** |
|
1270 | + * register_route - adds module method routes to route_map |
|
1271 | + * |
|
1272 | + * @access public |
|
1273 | + * @param string $route - "pretty" public alias for module method |
|
1274 | + * @param string $module - module name (classname without EED_ prefix) |
|
1275 | + * @param string $method_name - the actual module method to be routed to |
|
1276 | + * @param string $key - url param key indicating a route is being called |
|
1277 | + * @return bool |
|
1278 | + */ |
|
1279 | + public static function register_route($route = null, $module = null, $method_name = null, $key = 'ee') |
|
1280 | + { |
|
1281 | + do_action('AHEE__EE_Config__register_route__begin', $route, $module, $method_name); |
|
1282 | + $module = str_replace('EED_', '', $module); |
|
1283 | + $module_class = 'EED_' . $module; |
|
1284 | + if (! isset(EE_Registry::instance()->modules->{$module_class})) { |
|
1285 | + $msg = sprintf(__('The module %s has not been registered.', 'event_espresso'), $module); |
|
1286 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
1287 | + return false; |
|
1288 | + } |
|
1289 | + if (empty($route)) { |
|
1290 | + $msg = sprintf(__('No route has been supplied.', 'event_espresso'), $route); |
|
1291 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
1292 | + return false; |
|
1293 | + } |
|
1294 | + if (! method_exists('EED_' . $module, $method_name)) { |
|
1295 | + $msg = sprintf( |
|
1296 | + __('A valid class method for the %s route has not been supplied.', 'event_espresso'), |
|
1297 | + $route |
|
1298 | + ); |
|
1299 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
1300 | + return false; |
|
1301 | + } |
|
1302 | + EE_Config::$_module_route_map[$key][$route] = array('EED_' . $module, $method_name); |
|
1303 | + return true; |
|
1304 | + } |
|
1305 | + |
|
1306 | + |
|
1307 | + |
|
1308 | + /** |
|
1309 | + * get_route - get module method route |
|
1310 | + * |
|
1311 | + * @access public |
|
1312 | + * @param string $route - "pretty" public alias for module method |
|
1313 | + * @param string $key - url param key indicating a route is being called |
|
1314 | + * @return string |
|
1315 | + */ |
|
1316 | + public static function get_route($route = null, $key = 'ee') |
|
1317 | + { |
|
1318 | + do_action('AHEE__EE_Config__get_route__begin', $route); |
|
1319 | + $route = (string)apply_filters('FHEE__EE_Config__get_route', $route); |
|
1320 | + if (isset(EE_Config::$_module_route_map[$key][$route])) { |
|
1321 | + return EE_Config::$_module_route_map[$key][$route]; |
|
1322 | + } |
|
1323 | + return null; |
|
1324 | + } |
|
1325 | + |
|
1326 | + |
|
1327 | + |
|
1328 | + /** |
|
1329 | + * get_routes - get ALL module method routes |
|
1330 | + * |
|
1331 | + * @access public |
|
1332 | + * @return array |
|
1333 | + */ |
|
1334 | + public static function get_routes() |
|
1335 | + { |
|
1336 | + return EE_Config::$_module_route_map; |
|
1337 | + } |
|
1338 | + |
|
1339 | + |
|
1340 | + |
|
1341 | + /** |
|
1342 | + * register_forward - allows modules to forward request to another module for further processing |
|
1343 | + * |
|
1344 | + * @access public |
|
1345 | + * @param string $route - "pretty" public alias for module method |
|
1346 | + * @param integer $status - integer value corresponding to status constant strings set in module parent |
|
1347 | + * class, allows different forwards to be served based on status |
|
1348 | + * @param array|string $forward - function name or array( class, method ) |
|
1349 | + * @param string $key - url param key indicating a route is being called |
|
1350 | + * @return bool |
|
1351 | + */ |
|
1352 | + public static function register_forward($route = null, $status = 0, $forward = null, $key = 'ee') |
|
1353 | + { |
|
1354 | + do_action('AHEE__EE_Config__register_forward', $route, $status, $forward); |
|
1355 | + if (! isset(EE_Config::$_module_route_map[$key][$route]) || empty($route)) { |
|
1356 | + $msg = sprintf( |
|
1357 | + __('The module route %s for this forward has not been registered.', 'event_espresso'), |
|
1358 | + $route |
|
1359 | + ); |
|
1360 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
1361 | + return false; |
|
1362 | + } |
|
1363 | + if (empty($forward)) { |
|
1364 | + $msg = sprintf(__('No forwarding route has been supplied.', 'event_espresso'), $route); |
|
1365 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
1366 | + return false; |
|
1367 | + } |
|
1368 | + if (is_array($forward)) { |
|
1369 | + if (! isset($forward[1])) { |
|
1370 | + $msg = sprintf( |
|
1371 | + __('A class method for the %s forwarding route has not been supplied.', 'event_espresso'), |
|
1372 | + $route |
|
1373 | + ); |
|
1374 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
1375 | + return false; |
|
1376 | + } |
|
1377 | + if (! method_exists($forward[0], $forward[1])) { |
|
1378 | + $msg = sprintf( |
|
1379 | + __('The class method %s for the %s forwarding route is in invalid.', 'event_espresso'), |
|
1380 | + $forward[1], |
|
1381 | + $route |
|
1382 | + ); |
|
1383 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
1384 | + return false; |
|
1385 | + } |
|
1386 | + } else if (! function_exists($forward)) { |
|
1387 | + $msg = sprintf( |
|
1388 | + __('The function %s for the %s forwarding route is in invalid.', 'event_espresso'), |
|
1389 | + $forward, |
|
1390 | + $route |
|
1391 | + ); |
|
1392 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
1393 | + return false; |
|
1394 | + } |
|
1395 | + EE_Config::$_module_forward_map[$key][$route][absint($status)] = $forward; |
|
1396 | + return true; |
|
1397 | + } |
|
1398 | + |
|
1399 | + |
|
1400 | + |
|
1401 | + /** |
|
1402 | + * get_forward - get forwarding route |
|
1403 | + * |
|
1404 | + * @access public |
|
1405 | + * @param string $route - "pretty" public alias for module method |
|
1406 | + * @param integer $status - integer value corresponding to status constant strings set in module parent class, |
|
1407 | + * allows different forwards to be served based on status |
|
1408 | + * @param string $key - url param key indicating a route is being called |
|
1409 | + * @return string |
|
1410 | + */ |
|
1411 | + public static function get_forward($route = null, $status = 0, $key = 'ee') |
|
1412 | + { |
|
1413 | + do_action('AHEE__EE_Config__get_forward__begin', $route, $status); |
|
1414 | + if (isset(EE_Config::$_module_forward_map[$key][$route][$status])) { |
|
1415 | + return apply_filters( |
|
1416 | + 'FHEE__EE_Config__get_forward', |
|
1417 | + EE_Config::$_module_forward_map[$key][$route][$status], |
|
1418 | + $route, |
|
1419 | + $status |
|
1420 | + ); |
|
1421 | + } |
|
1422 | + return null; |
|
1423 | + } |
|
1424 | + |
|
1425 | + |
|
1426 | + |
|
1427 | + /** |
|
1428 | + * register_forward - allows modules to specify different view templates for different method routes and status |
|
1429 | + * results |
|
1430 | + * |
|
1431 | + * @access public |
|
1432 | + * @param string $route - "pretty" public alias for module method |
|
1433 | + * @param integer $status - integer value corresponding to status constant strings set in module parent class, |
|
1434 | + * allows different views to be served based on status |
|
1435 | + * @param string $view |
|
1436 | + * @param string $key - url param key indicating a route is being called |
|
1437 | + * @return bool |
|
1438 | + */ |
|
1439 | + public static function register_view($route = null, $status = 0, $view = null, $key = 'ee') |
|
1440 | + { |
|
1441 | + do_action('AHEE__EE_Config__register_view__begin', $route, $status, $view); |
|
1442 | + if (! isset(EE_Config::$_module_route_map[$key][$route]) || empty($route)) { |
|
1443 | + $msg = sprintf( |
|
1444 | + __('The module route %s for this view has not been registered.', 'event_espresso'), |
|
1445 | + $route |
|
1446 | + ); |
|
1447 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
1448 | + return false; |
|
1449 | + } |
|
1450 | + if (! is_readable($view)) { |
|
1451 | + $msg = sprintf( |
|
1452 | + __( |
|
1453 | + 'The %s view file could not be found or is not readable due to file permissions.', |
|
1454 | + 'event_espresso' |
|
1455 | + ), |
|
1456 | + $view |
|
1457 | + ); |
|
1458 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
1459 | + return false; |
|
1460 | + } |
|
1461 | + EE_Config::$_module_view_map[$key][$route][absint($status)] = $view; |
|
1462 | + return true; |
|
1463 | + } |
|
1464 | + |
|
1465 | + |
|
1466 | + |
|
1467 | + /** |
|
1468 | + * get_view - get view for route and status |
|
1469 | + * |
|
1470 | + * @access public |
|
1471 | + * @param string $route - "pretty" public alias for module method |
|
1472 | + * @param integer $status - integer value corresponding to status constant strings set in module parent class, |
|
1473 | + * allows different views to be served based on status |
|
1474 | + * @param string $key - url param key indicating a route is being called |
|
1475 | + * @return string |
|
1476 | + */ |
|
1477 | + public static function get_view($route = null, $status = 0, $key = 'ee') |
|
1478 | + { |
|
1479 | + do_action('AHEE__EE_Config__get_view__begin', $route, $status); |
|
1480 | + if (isset(EE_Config::$_module_view_map[$key][$route][$status])) { |
|
1481 | + return apply_filters( |
|
1482 | + 'FHEE__EE_Config__get_view', |
|
1483 | + EE_Config::$_module_view_map[$key][$route][$status], |
|
1484 | + $route, |
|
1485 | + $status |
|
1486 | + ); |
|
1487 | + } |
|
1488 | + return null; |
|
1489 | + } |
|
1490 | + |
|
1491 | + |
|
1492 | + |
|
1493 | + public function update_addon_option_names() |
|
1494 | + { |
|
1495 | + update_option(EE_Config::ADDON_OPTION_NAMES, $this->_addon_option_names); |
|
1496 | + } |
|
1497 | + |
|
1498 | + |
|
1499 | + |
|
1500 | + public function shutdown() |
|
1501 | + { |
|
1502 | + $this->update_addon_option_names(); |
|
1503 | + } |
|
1504 | + |
|
1505 | + |
|
1506 | + |
|
1507 | + /** |
|
1508 | + * @return LegacyShortcodesManager |
|
1509 | + */ |
|
1510 | + public static function getLegacyShortcodesManager() |
|
1511 | + { |
|
1512 | + |
|
1513 | + if ( ! EE_Config::instance()->legacy_shortcodes_manager instanceof LegacyShortcodesManager) { |
|
1514 | + EE_Config::instance()->legacy_shortcodes_manager = new LegacyShortcodesManager( |
|
1515 | + EE_Registry::instance() |
|
1516 | + ); |
|
1517 | + } |
|
1518 | + return EE_Config::instance()->legacy_shortcodes_manager; |
|
1519 | + } |
|
1520 | + |
|
1521 | + |
|
1522 | + |
|
1523 | + /** |
|
1524 | + * register_shortcode - makes core aware of this shortcode |
|
1525 | + * |
|
1526 | + * @deprecated 4.9.26 |
|
1527 | + * @param string $shortcode_path - full path up to and including shortcode folder |
|
1528 | + * @return bool |
|
1529 | + */ |
|
1530 | + public static function register_shortcode($shortcode_path = null) |
|
1531 | + { |
|
1532 | + EE_Error::doing_it_wrong( |
|
1533 | + __METHOD__, |
|
1534 | + __( |
|
1535 | + 'Usage is deprecated. Use \EventEspresso\core\services\shortcodes\LegacyShortcodesManager::registerShortcode() as direct replacement, or better yet, please see the new \EventEspresso\core\services\shortcodes\ShortcodesManager class.', |
|
1536 | + 'event_espresso' |
|
1537 | + ), |
|
1538 | + '4.9.26' |
|
1539 | + ); |
|
1540 | + return EE_Config::instance()->getLegacyShortcodesManager()->registerShortcode($shortcode_path); |
|
1541 | + } |
|
21 | 1542 | |
22 | - const LOG_NAME = 'ee_config_log'; |
|
23 | 1543 | |
24 | - const LOG_LENGTH = 100; |
|
25 | 1544 | |
26 | - const ADDON_OPTION_NAMES = 'ee_config_option_names'; |
|
27 | - |
|
28 | - |
|
29 | - /** |
|
30 | - * instance of the EE_Config object |
|
31 | - * |
|
32 | - * @var EE_Config $_instance |
|
33 | - * @access private |
|
34 | - */ |
|
35 | - private static $_instance; |
|
36 | - |
|
37 | - /** |
|
38 | - * @var boolean $_logging_enabled |
|
39 | - */ |
|
40 | - private static $_logging_enabled = false; |
|
41 | - |
|
42 | - /** |
|
43 | - * @var LegacyShortcodesManager $legacy_shortcodes_manager |
|
44 | - */ |
|
45 | - private $legacy_shortcodes_manager; |
|
46 | - |
|
47 | - /** |
|
48 | - * An StdClass whose property names are addon slugs, |
|
49 | - * and values are their config classes |
|
50 | - * |
|
51 | - * @var StdClass |
|
52 | - */ |
|
53 | - public $addons; |
|
54 | - |
|
55 | - /** |
|
56 | - * @var EE_Admin_Config |
|
57 | - */ |
|
58 | - public $admin; |
|
59 | - |
|
60 | - /** |
|
61 | - * @var EE_Core_Config |
|
62 | - */ |
|
63 | - public $core; |
|
64 | - |
|
65 | - /** |
|
66 | - * @var EE_Currency_Config |
|
67 | - */ |
|
68 | - public $currency; |
|
69 | - |
|
70 | - /** |
|
71 | - * @var EE_Organization_Config |
|
72 | - */ |
|
73 | - public $organization; |
|
74 | - |
|
75 | - /** |
|
76 | - * @var EE_Registration_Config |
|
77 | - */ |
|
78 | - public $registration; |
|
79 | - |
|
80 | - /** |
|
81 | - * @var EE_Template_Config |
|
82 | - */ |
|
83 | - public $template_settings; |
|
84 | - |
|
85 | - /** |
|
86 | - * Holds EE environment values. |
|
87 | - * |
|
88 | - * @var EE_Environment_Config |
|
89 | - */ |
|
90 | - public $environment; |
|
91 | - |
|
92 | - /** |
|
93 | - * settings pertaining to Google maps |
|
94 | - * |
|
95 | - * @var EE_Map_Config |
|
96 | - */ |
|
97 | - public $map_settings; |
|
98 | - |
|
99 | - /** |
|
100 | - * settings pertaining to Taxes |
|
101 | - * |
|
102 | - * @var EE_Tax_Config |
|
103 | - */ |
|
104 | - public $tax_settings; |
|
105 | - |
|
106 | - |
|
107 | - /** |
|
108 | - * Settings pertaining to global messages settings. |
|
109 | - * |
|
110 | - * @var EE_Messages_Config |
|
111 | - */ |
|
112 | - public $messages; |
|
113 | - |
|
114 | - /** |
|
115 | - * @deprecated |
|
116 | - * @var EE_Gateway_Config |
|
117 | - */ |
|
118 | - public $gateway; |
|
119 | - |
|
120 | - /** |
|
121 | - * @var array $_addon_option_names |
|
122 | - * @access private |
|
123 | - */ |
|
124 | - private $_addon_option_names = array(); |
|
125 | - |
|
126 | - /** |
|
127 | - * @var array $_module_route_map |
|
128 | - * @access private |
|
129 | - */ |
|
130 | - private static $_module_route_map = array(); |
|
131 | - |
|
132 | - /** |
|
133 | - * @var array $_module_forward_map |
|
134 | - * @access private |
|
135 | - */ |
|
136 | - private static $_module_forward_map = array(); |
|
137 | - |
|
138 | - /** |
|
139 | - * @var array $_module_view_map |
|
140 | - * @access private |
|
141 | - */ |
|
142 | - private static $_module_view_map = array(); |
|
143 | - |
|
144 | - |
|
145 | - |
|
146 | - /** |
|
147 | - * @singleton method used to instantiate class object |
|
148 | - * @access public |
|
149 | - * @return EE_Config instance |
|
150 | - */ |
|
151 | - public static function instance() |
|
152 | - { |
|
153 | - // check if class object is instantiated, and instantiated properly |
|
154 | - if (! self::$_instance instanceof EE_Config) { |
|
155 | - self::$_instance = new self(); |
|
156 | - } |
|
157 | - return self::$_instance; |
|
158 | - } |
|
159 | - |
|
160 | - |
|
161 | - |
|
162 | - /** |
|
163 | - * Resets the config |
|
164 | - * |
|
165 | - * @param bool $hard_reset if TRUE, sets EE_CONFig back to its original settings in the database. If FALSE |
|
166 | - * (default) leaves the database alone, and merely resets the EE_Config object to |
|
167 | - * reflect its state in the database |
|
168 | - * @param boolean $reinstantiate if TRUE (default) call instance() and return it. Otherwise, just leave |
|
169 | - * $_instance as NULL. Useful in case you want to forget about the old instance on |
|
170 | - * EE_Config, but might not be ready to instantiate EE_Config currently (eg if the |
|
171 | - * site was put into maintenance mode) |
|
172 | - * @return EE_Config |
|
173 | - */ |
|
174 | - public static function reset($hard_reset = false, $reinstantiate = true) |
|
175 | - { |
|
176 | - if (self::$_instance instanceof EE_Config) { |
|
177 | - if ($hard_reset) { |
|
178 | - self::$_instance->legacy_shortcodes_manager = null; |
|
179 | - self::$_instance->_addon_option_names = array(); |
|
180 | - self::$_instance->_initialize_config(); |
|
181 | - self::$_instance->update_espresso_config(); |
|
182 | - } |
|
183 | - self::$_instance->update_addon_option_names(); |
|
184 | - } |
|
185 | - self::$_instance = null; |
|
186 | - //we don't need to reset the static properties imo because those should |
|
187 | - //only change when a module is added or removed. Currently we don't |
|
188 | - //support removing a module during a request when it previously existed |
|
189 | - if ($reinstantiate) { |
|
190 | - return self::instance(); |
|
191 | - } else { |
|
192 | - return null; |
|
193 | - } |
|
194 | - } |
|
195 | - |
|
196 | - |
|
197 | - |
|
198 | - /** |
|
199 | - * class constructor |
|
200 | - * |
|
201 | - * @access private |
|
202 | - */ |
|
203 | - private function __construct() |
|
204 | - { |
|
205 | - do_action('AHEE__EE_Config__construct__begin', $this); |
|
206 | - EE_Config::$_logging_enabled = apply_filters('FHEE__EE_Config___construct__logging_enabled', false); |
|
207 | - // setup empty config classes |
|
208 | - $this->_initialize_config(); |
|
209 | - // load existing EE site settings |
|
210 | - $this->_load_core_config(); |
|
211 | - // confirm everything loaded correctly and set filtered defaults if not |
|
212 | - $this->_verify_config(); |
|
213 | - // register shortcodes and modules |
|
214 | - add_action( |
|
215 | - 'AHEE__EE_System__register_shortcodes_modules_and_widgets', |
|
216 | - array($this, 'register_shortcodes_and_modules'), |
|
217 | - 999 |
|
218 | - ); |
|
219 | - // initialize shortcodes and modules |
|
220 | - add_action('AHEE__EE_System__core_loaded_and_ready', array($this, 'initialize_shortcodes_and_modules')); |
|
221 | - // register widgets |
|
222 | - add_action('widgets_init', array($this, 'widgets_init'), 10); |
|
223 | - // shutdown |
|
224 | - add_action('shutdown', array($this, 'shutdown'), 10); |
|
225 | - // construct__end hook |
|
226 | - do_action('AHEE__EE_Config__construct__end', $this); |
|
227 | - // hardcoded hack |
|
228 | - $this->template_settings->current_espresso_theme = 'Espresso_Arabica_2014'; |
|
229 | - } |
|
230 | - |
|
231 | - |
|
232 | - |
|
233 | - /** |
|
234 | - * @return boolean |
|
235 | - */ |
|
236 | - public static function logging_enabled() |
|
237 | - { |
|
238 | - return self::$_logging_enabled; |
|
239 | - } |
|
240 | - |
|
241 | - |
|
242 | - |
|
243 | - /** |
|
244 | - * use to get the current theme if needed from static context |
|
245 | - * |
|
246 | - * @return string current theme set. |
|
247 | - */ |
|
248 | - public static function get_current_theme() |
|
249 | - { |
|
250 | - return isset(self::$_instance->template_settings->current_espresso_theme) |
|
251 | - ? self::$_instance->template_settings->current_espresso_theme : 'Espresso_Arabica_2014'; |
|
252 | - } |
|
253 | - |
|
254 | - |
|
255 | - |
|
256 | - /** |
|
257 | - * _initialize_config |
|
258 | - * |
|
259 | - * @access private |
|
260 | - * @return void |
|
261 | - */ |
|
262 | - private function _initialize_config() |
|
263 | - { |
|
264 | - EE_Config::trim_log(); |
|
265 | - //set defaults |
|
266 | - $this->_addon_option_names = get_option(EE_Config::ADDON_OPTION_NAMES, array()); |
|
267 | - $this->addons = new stdClass(); |
|
268 | - // set _module_route_map |
|
269 | - EE_Config::$_module_route_map = array(); |
|
270 | - // set _module_forward_map |
|
271 | - EE_Config::$_module_forward_map = array(); |
|
272 | - // set _module_view_map |
|
273 | - EE_Config::$_module_view_map = array(); |
|
274 | - } |
|
275 | - |
|
276 | - |
|
277 | - |
|
278 | - /** |
|
279 | - * load core plugin configuration |
|
280 | - * |
|
281 | - * @access private |
|
282 | - * @return void |
|
283 | - */ |
|
284 | - private function _load_core_config() |
|
285 | - { |
|
286 | - // load_core_config__start hook |
|
287 | - do_action('AHEE__EE_Config___load_core_config__start', $this); |
|
288 | - $espresso_config = $this->get_espresso_config(); |
|
289 | - foreach ($espresso_config as $config => $settings) { |
|
290 | - // load_core_config__start hook |
|
291 | - $settings = apply_filters( |
|
292 | - 'FHEE__EE_Config___load_core_config__config_settings', |
|
293 | - $settings, |
|
294 | - $config, |
|
295 | - $this |
|
296 | - ); |
|
297 | - if (is_object($settings) && property_exists($this, $config)) { |
|
298 | - $this->{$config} = apply_filters('FHEE__EE_Config___load_core_config__' . $config, $settings); |
|
299 | - //call configs populate method to ensure any defaults are set for empty values. |
|
300 | - if (method_exists($settings, 'populate')) { |
|
301 | - $this->{$config}->populate(); |
|
302 | - } |
|
303 | - if (method_exists($settings, 'do_hooks')) { |
|
304 | - $this->{$config}->do_hooks(); |
|
305 | - } |
|
306 | - } |
|
307 | - } |
|
308 | - if (apply_filters('FHEE__EE_Config___load_core_config__update_espresso_config', false)) { |
|
309 | - $this->update_espresso_config(); |
|
310 | - } |
|
311 | - // load_core_config__end hook |
|
312 | - do_action('AHEE__EE_Config___load_core_config__end', $this); |
|
313 | - } |
|
314 | - |
|
315 | - |
|
316 | - |
|
317 | - /** |
|
318 | - * _verify_config |
|
319 | - * |
|
320 | - * @access protected |
|
321 | - * @return void |
|
322 | - */ |
|
323 | - protected function _verify_config() |
|
324 | - { |
|
325 | - $this->core = $this->core instanceof EE_Core_Config |
|
326 | - ? $this->core |
|
327 | - : new EE_Core_Config(); |
|
328 | - $this->core = apply_filters('FHEE__EE_Config___initialize_config__core', $this->core); |
|
329 | - $this->organization = $this->organization instanceof EE_Organization_Config |
|
330 | - ? $this->organization |
|
331 | - : new EE_Organization_Config(); |
|
332 | - $this->organization = apply_filters( |
|
333 | - 'FHEE__EE_Config___initialize_config__organization', |
|
334 | - $this->organization |
|
335 | - ); |
|
336 | - $this->currency = $this->currency instanceof EE_Currency_Config |
|
337 | - ? $this->currency |
|
338 | - : new EE_Currency_Config(); |
|
339 | - $this->currency = apply_filters('FHEE__EE_Config___initialize_config__currency', $this->currency); |
|
340 | - $this->registration = $this->registration instanceof EE_Registration_Config |
|
341 | - ? $this->registration |
|
342 | - : new EE_Registration_Config(); |
|
343 | - $this->registration = apply_filters( |
|
344 | - 'FHEE__EE_Config___initialize_config__registration', |
|
345 | - $this->registration |
|
346 | - ); |
|
347 | - $this->admin = $this->admin instanceof EE_Admin_Config |
|
348 | - ? $this->admin |
|
349 | - : new EE_Admin_Config(); |
|
350 | - $this->admin = apply_filters('FHEE__EE_Config___initialize_config__admin', $this->admin); |
|
351 | - $this->template_settings = $this->template_settings instanceof EE_Template_Config |
|
352 | - ? $this->template_settings |
|
353 | - : new EE_Template_Config(); |
|
354 | - $this->template_settings = apply_filters( |
|
355 | - 'FHEE__EE_Config___initialize_config__template_settings', |
|
356 | - $this->template_settings |
|
357 | - ); |
|
358 | - $this->map_settings = $this->map_settings instanceof EE_Map_Config |
|
359 | - ? $this->map_settings |
|
360 | - : new EE_Map_Config(); |
|
361 | - $this->map_settings = apply_filters('FHEE__EE_Config___initialize_config__map_settings', |
|
362 | - $this->map_settings); |
|
363 | - $this->environment = $this->environment instanceof EE_Environment_Config |
|
364 | - ? $this->environment |
|
365 | - : new EE_Environment_Config(); |
|
366 | - $this->environment = apply_filters('FHEE__EE_Config___initialize_config__environment', |
|
367 | - $this->environment); |
|
368 | - $this->tax_settings = $this->tax_settings instanceof EE_Tax_Config |
|
369 | - ? $this->tax_settings |
|
370 | - : new EE_Tax_Config(); |
|
371 | - $this->tax_settings = apply_filters('FHEE__EE_Config___initialize_config__tax_settings', |
|
372 | - $this->tax_settings); |
|
373 | - $this->messages = apply_filters('FHEE__EE_Config__initialize_config__messages', $this->messages); |
|
374 | - $this->messages = $this->messages instanceof EE_Messages_Config |
|
375 | - ? $this->messages |
|
376 | - : new EE_Messages_Config(); |
|
377 | - $this->gateway = $this->gateway instanceof EE_Gateway_Config |
|
378 | - ? $this->gateway |
|
379 | - : new EE_Gateway_Config(); |
|
380 | - $this->gateway = apply_filters('FHEE__EE_Config___initialize_config__gateway', $this->gateway); |
|
381 | - $this->legacy_shortcodes_manager = null; |
|
382 | - } |
|
383 | - |
|
384 | - |
|
385 | - /** |
|
386 | - * get_espresso_config |
|
387 | - * |
|
388 | - * @access public |
|
389 | - * @return array of espresso config stuff |
|
390 | - */ |
|
391 | - public function get_espresso_config() |
|
392 | - { |
|
393 | - // grab espresso configuration |
|
394 | - return apply_filters( |
|
395 | - 'FHEE__EE_Config__get_espresso_config__CFG', |
|
396 | - get_option(EE_Config::OPTION_NAME, array()) |
|
397 | - ); |
|
398 | - } |
|
399 | - |
|
400 | - |
|
401 | - |
|
402 | - /** |
|
403 | - * double_check_config_comparison |
|
404 | - * |
|
405 | - * @access public |
|
406 | - * @param string $option |
|
407 | - * @param $old_value |
|
408 | - * @param $value |
|
409 | - */ |
|
410 | - public function double_check_config_comparison($option = '', $old_value, $value) |
|
411 | - { |
|
412 | - // make sure we're checking the ee config |
|
413 | - if ($option === EE_Config::OPTION_NAME) { |
|
414 | - // run a loose comparison of the old value against the new value for type and properties, |
|
415 | - // but NOT exact instance like WP update_option does (ie: NOT type safe comparison) |
|
416 | - if ($value != $old_value) { |
|
417 | - // if they are NOT the same, then remove the hook, |
|
418 | - // which means the subsequent update results will be based solely on the update query results |
|
419 | - // the reason we do this is because, as stated above, |
|
420 | - // WP update_option performs an exact instance comparison (===) on any update values passed to it |
|
421 | - // this happens PRIOR to serialization and any subsequent update. |
|
422 | - // If values are found to match their previous old value, |
|
423 | - // then WP bails before performing any update. |
|
424 | - // Since we are passing the EE_Config object, it is comparing the EXACT instance of the saved version |
|
425 | - // it just pulled from the db, with the one being passed to it (which will not match). |
|
426 | - // HOWEVER, once the object is serialized and passed off to MySQL to update, |
|
427 | - // MySQL MAY ALSO NOT perform the update because |
|
428 | - // the string it sees in the db looks the same as the new one it has been passed!!! |
|
429 | - // This results in the query returning an "affected rows" value of ZERO, |
|
430 | - // which gets returned immediately by WP update_option and looks like an error. |
|
431 | - remove_action('update_option', array($this, 'check_config_updated')); |
|
432 | - } |
|
433 | - } |
|
434 | - } |
|
435 | - |
|
436 | - |
|
437 | - |
|
438 | - /** |
|
439 | - * update_espresso_config |
|
440 | - * |
|
441 | - * @access public |
|
442 | - */ |
|
443 | - protected function _reset_espresso_addon_config() |
|
444 | - { |
|
445 | - $this->_addon_option_names = array(); |
|
446 | - foreach ($this->addons as $addon_name => $addon_config_obj) { |
|
447 | - $addon_config_obj = maybe_unserialize($addon_config_obj); |
|
448 | - $config_class = get_class($addon_config_obj); |
|
449 | - if ($addon_config_obj instanceof $config_class && ! $addon_config_obj instanceof __PHP_Incomplete_Class) { |
|
450 | - $this->update_config('addons', $addon_name, $addon_config_obj, false); |
|
451 | - } |
|
452 | - $this->addons->{$addon_name} = null; |
|
453 | - } |
|
454 | - } |
|
455 | - |
|
456 | - |
|
457 | - |
|
458 | - /** |
|
459 | - * update_espresso_config |
|
460 | - * |
|
461 | - * @access public |
|
462 | - * @param bool $add_success |
|
463 | - * @param bool $add_error |
|
464 | - * @return bool |
|
465 | - */ |
|
466 | - public function update_espresso_config($add_success = false, $add_error = true) |
|
467 | - { |
|
468 | - // don't allow config updates during WP heartbeats |
|
469 | - if (\EE_Registry::instance()->REQ->get('action', '') === 'heartbeat') { |
|
470 | - return false; |
|
471 | - } |
|
472 | - // commented out the following re: https://events.codebasehq.com/projects/event-espresso/tickets/8197 |
|
473 | - //$clone = clone( self::$_instance ); |
|
474 | - //self::$_instance = NULL; |
|
475 | - do_action('AHEE__EE_Config__update_espresso_config__begin', $this); |
|
476 | - $this->_reset_espresso_addon_config(); |
|
477 | - // hook into update_option because that happens AFTER the ( $value === $old_value ) conditional |
|
478 | - // but BEFORE the actual update occurs |
|
479 | - add_action('update_option', array($this, 'double_check_config_comparison'), 1, 3); |
|
480 | - // don't want to persist legacy_shortcodes_manager, but don't want to lose it either |
|
481 | - $legacy_shortcodes_manager = $this->legacy_shortcodes_manager; |
|
482 | - $this->legacy_shortcodes_manager = null; |
|
483 | - // now update "ee_config" |
|
484 | - $saved = update_option(EE_Config::OPTION_NAME, $this); |
|
485 | - $this->legacy_shortcodes_manager = $legacy_shortcodes_manager; |
|
486 | - EE_Config::log(EE_Config::OPTION_NAME); |
|
487 | - // if not saved... check if the hook we just added still exists; |
|
488 | - // if it does, it means one of two things: |
|
489 | - // that update_option bailed at the ( $value === $old_value ) conditional, |
|
490 | - // or... |
|
491 | - // the db update query returned 0 rows affected |
|
492 | - // (probably because the data value was the same from it's perspective) |
|
493 | - // so the existence of the hook means that a negative result from update_option is NOT an error, |
|
494 | - // but just means no update occurred, so don't display an error to the user. |
|
495 | - // BUT... if update_option returns FALSE, AND the hook is missing, |
|
496 | - // then it means that something truly went wrong |
|
497 | - $saved = ! $saved ? has_action('update_option', array($this, 'double_check_config_comparison')) : $saved; |
|
498 | - // remove our action since we don't want it in the system anymore |
|
499 | - remove_action('update_option', array($this, 'double_check_config_comparison'), 1); |
|
500 | - do_action('AHEE__EE_Config__update_espresso_config__end', $this, $saved); |
|
501 | - //self::$_instance = $clone; |
|
502 | - //unset( $clone ); |
|
503 | - // if config remains the same or was updated successfully |
|
504 | - if ($saved) { |
|
505 | - if ($add_success) { |
|
506 | - EE_Error::add_success( |
|
507 | - __('The Event Espresso Configuration Settings have been successfully updated.', 'event_espresso'), |
|
508 | - __FILE__, |
|
509 | - __FUNCTION__, |
|
510 | - __LINE__ |
|
511 | - ); |
|
512 | - } |
|
513 | - return true; |
|
514 | - } else { |
|
515 | - if ($add_error) { |
|
516 | - EE_Error::add_error( |
|
517 | - __('The Event Espresso Configuration Settings were not updated.', 'event_espresso'), |
|
518 | - __FILE__, |
|
519 | - __FUNCTION__, |
|
520 | - __LINE__ |
|
521 | - ); |
|
522 | - } |
|
523 | - return false; |
|
524 | - } |
|
525 | - } |
|
526 | - |
|
527 | - |
|
528 | - |
|
529 | - /** |
|
530 | - * _verify_config_params |
|
531 | - * |
|
532 | - * @access private |
|
533 | - * @param string $section |
|
534 | - * @param string $name |
|
535 | - * @param string $config_class |
|
536 | - * @param EE_Config_Base $config_obj |
|
537 | - * @param array $tests_to_run |
|
538 | - * @param bool $display_errors |
|
539 | - * @return bool TRUE on success, FALSE on fail |
|
540 | - */ |
|
541 | - private function _verify_config_params( |
|
542 | - $section = '', |
|
543 | - $name = '', |
|
544 | - $config_class = '', |
|
545 | - $config_obj = null, |
|
546 | - $tests_to_run = array(1, 2, 3, 4, 5, 6, 7, 8), |
|
547 | - $display_errors = true |
|
548 | - ) { |
|
549 | - try { |
|
550 | - foreach ($tests_to_run as $test) { |
|
551 | - switch ($test) { |
|
552 | - // TEST #1 : check that section was set |
|
553 | - case 1 : |
|
554 | - if (empty($section)) { |
|
555 | - if ($display_errors) { |
|
556 | - throw new EE_Error( |
|
557 | - sprintf( |
|
558 | - __( |
|
559 | - 'No configuration section has been provided while attempting to save "%s".', |
|
560 | - 'event_espresso' |
|
561 | - ), |
|
562 | - $config_class |
|
563 | - ) |
|
564 | - ); |
|
565 | - } |
|
566 | - return false; |
|
567 | - } |
|
568 | - break; |
|
569 | - // TEST #2 : check that settings section exists |
|
570 | - case 2 : |
|
571 | - if (! isset($this->{$section})) { |
|
572 | - if ($display_errors) { |
|
573 | - throw new EE_Error( |
|
574 | - sprintf( |
|
575 | - __('The "%s" configuration section does not exist.', 'event_espresso'), |
|
576 | - $section |
|
577 | - ) |
|
578 | - ); |
|
579 | - } |
|
580 | - return false; |
|
581 | - } |
|
582 | - break; |
|
583 | - // TEST #3 : check that section is the proper format |
|
584 | - case 3 : |
|
585 | - if ( |
|
586 | - ! ($this->{$section} instanceof EE_Config_Base || $this->{$section} instanceof stdClass) |
|
587 | - ) { |
|
588 | - if ($display_errors) { |
|
589 | - throw new EE_Error( |
|
590 | - sprintf( |
|
591 | - __( |
|
592 | - 'The "%s" configuration settings have not been formatted correctly.', |
|
593 | - 'event_espresso' |
|
594 | - ), |
|
595 | - $section |
|
596 | - ) |
|
597 | - ); |
|
598 | - } |
|
599 | - return false; |
|
600 | - } |
|
601 | - break; |
|
602 | - // TEST #4 : check that config section name has been set |
|
603 | - case 4 : |
|
604 | - if (empty($name)) { |
|
605 | - if ($display_errors) { |
|
606 | - throw new EE_Error( |
|
607 | - __( |
|
608 | - 'No name has been provided for the specific configuration section.', |
|
609 | - 'event_espresso' |
|
610 | - ) |
|
611 | - ); |
|
612 | - } |
|
613 | - return false; |
|
614 | - } |
|
615 | - break; |
|
616 | - // TEST #5 : check that a config class name has been set |
|
617 | - case 5 : |
|
618 | - if (empty($config_class)) { |
|
619 | - if ($display_errors) { |
|
620 | - throw new EE_Error( |
|
621 | - __( |
|
622 | - 'No class name has been provided for the specific configuration section.', |
|
623 | - 'event_espresso' |
|
624 | - ) |
|
625 | - ); |
|
626 | - } |
|
627 | - return false; |
|
628 | - } |
|
629 | - break; |
|
630 | - // TEST #6 : verify config class is accessible |
|
631 | - case 6 : |
|
632 | - if (! class_exists($config_class)) { |
|
633 | - if ($display_errors) { |
|
634 | - throw new EE_Error( |
|
635 | - sprintf( |
|
636 | - __( |
|
637 | - 'The "%s" class does not exist. Please ensure that an autoloader has been set for it.', |
|
638 | - 'event_espresso' |
|
639 | - ), |
|
640 | - $config_class |
|
641 | - ) |
|
642 | - ); |
|
643 | - } |
|
644 | - return false; |
|
645 | - } |
|
646 | - break; |
|
647 | - // TEST #7 : check that config has even been set |
|
648 | - case 7 : |
|
649 | - if (! isset($this->{$section}->{$name})) { |
|
650 | - if ($display_errors) { |
|
651 | - throw new EE_Error( |
|
652 | - sprintf( |
|
653 | - __('No configuration has been set for "%1$s->%2$s".', 'event_espresso'), |
|
654 | - $section, |
|
655 | - $name |
|
656 | - ) |
|
657 | - ); |
|
658 | - } |
|
659 | - return false; |
|
660 | - } else { |
|
661 | - // and make sure it's not serialized |
|
662 | - $this->{$section}->{$name} = maybe_unserialize($this->{$section}->{$name}); |
|
663 | - } |
|
664 | - break; |
|
665 | - // TEST #8 : check that config is the requested type |
|
666 | - case 8 : |
|
667 | - if (! $this->{$section}->{$name} instanceof $config_class) { |
|
668 | - if ($display_errors) { |
|
669 | - throw new EE_Error( |
|
670 | - sprintf( |
|
671 | - __( |
|
672 | - 'The configuration for "%1$s->%2$s" is not of the "%3$s" class.', |
|
673 | - 'event_espresso' |
|
674 | - ), |
|
675 | - $section, |
|
676 | - $name, |
|
677 | - $config_class |
|
678 | - ) |
|
679 | - ); |
|
680 | - } |
|
681 | - return false; |
|
682 | - } |
|
683 | - break; |
|
684 | - // TEST #9 : verify config object |
|
685 | - case 9 : |
|
686 | - if (! $config_obj instanceof EE_Config_Base) { |
|
687 | - if ($display_errors) { |
|
688 | - throw new EE_Error( |
|
689 | - sprintf( |
|
690 | - __('The "%s" class is not an instance of EE_Config_Base.', 'event_espresso'), |
|
691 | - print_r($config_obj, true) |
|
692 | - ) |
|
693 | - ); |
|
694 | - } |
|
695 | - return false; |
|
696 | - } |
|
697 | - break; |
|
698 | - } |
|
699 | - } |
|
700 | - } catch (EE_Error $e) { |
|
701 | - $e->get_error(); |
|
702 | - } |
|
703 | - // you have successfully run the gauntlet |
|
704 | - return true; |
|
705 | - } |
|
706 | - |
|
707 | - |
|
708 | - |
|
709 | - /** |
|
710 | - * _generate_config_option_name |
|
711 | - * |
|
712 | - * @access protected |
|
713 | - * @param string $section |
|
714 | - * @param string $name |
|
715 | - * @return string |
|
716 | - */ |
|
717 | - private function _generate_config_option_name($section = '', $name = '') |
|
718 | - { |
|
719 | - return 'ee_config-' . strtolower($section . '-' . str_replace(array('EE_', 'EED_'), '', $name)); |
|
720 | - } |
|
721 | - |
|
722 | - |
|
723 | - |
|
724 | - /** |
|
725 | - * _set_config_class |
|
726 | - * ensures that a config class is set, either from a passed config class or one generated from the config name |
|
727 | - * |
|
728 | - * @access private |
|
729 | - * @param string $config_class |
|
730 | - * @param string $name |
|
731 | - * @return string |
|
732 | - */ |
|
733 | - private function _set_config_class($config_class = '', $name = '') |
|
734 | - { |
|
735 | - return ! empty($config_class) |
|
736 | - ? $config_class |
|
737 | - : str_replace(' ', '_', ucwords(str_replace('_', ' ', $name))) . '_Config'; |
|
738 | - } |
|
739 | - |
|
740 | - |
|
741 | - |
|
742 | - /** |
|
743 | - * set_config |
|
744 | - * |
|
745 | - * @access protected |
|
746 | - * @param string $section |
|
747 | - * @param string $name |
|
748 | - * @param string $config_class |
|
749 | - * @param EE_Config_Base $config_obj |
|
750 | - * @return EE_Config_Base |
|
751 | - */ |
|
752 | - public function set_config($section = '', $name = '', $config_class = '', EE_Config_Base $config_obj = null) |
|
753 | - { |
|
754 | - // ensure config class is set to something |
|
755 | - $config_class = $this->_set_config_class($config_class, $name); |
|
756 | - // run tests 1-4, 6, and 7 to verify all config params are set and valid |
|
757 | - if (! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) { |
|
758 | - return null; |
|
759 | - } |
|
760 | - $config_option_name = $this->_generate_config_option_name($section, $name); |
|
761 | - // if the config option name hasn't been added yet to the list of option names we're tracking, then do so now |
|
762 | - if (! isset($this->_addon_option_names[$config_option_name])) { |
|
763 | - $this->_addon_option_names[$config_option_name] = $config_class; |
|
764 | - $this->update_addon_option_names(); |
|
765 | - } |
|
766 | - // verify the incoming config object but suppress errors |
|
767 | - if (! $this->_verify_config_params($section, $name, $config_class, $config_obj, array(9), false)) { |
|
768 | - $config_obj = new $config_class(); |
|
769 | - } |
|
770 | - if (get_option($config_option_name)) { |
|
771 | - EE_Config::log($config_option_name); |
|
772 | - update_option($config_option_name, $config_obj); |
|
773 | - $this->{$section}->{$name} = $config_obj; |
|
774 | - return $this->{$section}->{$name}; |
|
775 | - } else { |
|
776 | - // create a wp-option for this config |
|
777 | - if (add_option($config_option_name, $config_obj, '', 'no')) { |
|
778 | - $this->{$section}->{$name} = maybe_unserialize($config_obj); |
|
779 | - return $this->{$section}->{$name}; |
|
780 | - } else { |
|
781 | - EE_Error::add_error( |
|
782 | - sprintf(__('The "%s" could not be saved to the database.', 'event_espresso'), $config_class), |
|
783 | - __FILE__, |
|
784 | - __FUNCTION__, |
|
785 | - __LINE__ |
|
786 | - ); |
|
787 | - return null; |
|
788 | - } |
|
789 | - } |
|
790 | - } |
|
791 | - |
|
792 | - |
|
793 | - |
|
794 | - /** |
|
795 | - * update_config |
|
796 | - * Important: the config object must ALREADY be set, otherwise this will produce an error. |
|
797 | - * |
|
798 | - * @access public |
|
799 | - * @param string $section |
|
800 | - * @param string $name |
|
801 | - * @param EE_Config_Base|string $config_obj |
|
802 | - * @param bool $throw_errors |
|
803 | - * @return bool |
|
804 | - */ |
|
805 | - public function update_config($section = '', $name = '', $config_obj = '', $throw_errors = true) |
|
806 | - { |
|
807 | - // don't allow config updates during WP heartbeats |
|
808 | - if (\EE_Registry::instance()->REQ->get('action', '') === 'heartbeat') { |
|
809 | - return false; |
|
810 | - } |
|
811 | - $config_obj = maybe_unserialize($config_obj); |
|
812 | - // get class name of the incoming object |
|
813 | - $config_class = get_class($config_obj); |
|
814 | - // run tests 1-5 and 9 to verify config |
|
815 | - if (! $this->_verify_config_params( |
|
816 | - $section, |
|
817 | - $name, |
|
818 | - $config_class, |
|
819 | - $config_obj, |
|
820 | - array(1, 2, 3, 4, 7, 9) |
|
821 | - ) |
|
822 | - ) { |
|
823 | - return false; |
|
824 | - } |
|
825 | - $config_option_name = $this->_generate_config_option_name($section, $name); |
|
826 | - // check if config object has been added to db by seeing if config option name is in $this->_addon_option_names array |
|
827 | - if (! isset($this->_addon_option_names[$config_option_name])) { |
|
828 | - // save new config to db |
|
829 | - if ($this->set_config($section, $name, $config_class, $config_obj)) { |
|
830 | - return true; |
|
831 | - } |
|
832 | - } else { |
|
833 | - // first check if the record already exists |
|
834 | - $existing_config = get_option($config_option_name); |
|
835 | - $config_obj = serialize($config_obj); |
|
836 | - // just return if db record is already up to date (NOT type safe comparison) |
|
837 | - if ($existing_config == $config_obj) { |
|
838 | - $this->{$section}->{$name} = $config_obj; |
|
839 | - return true; |
|
840 | - } else if (update_option($config_option_name, $config_obj)) { |
|
841 | - EE_Config::log($config_option_name); |
|
842 | - // update wp-option for this config class |
|
843 | - $this->{$section}->{$name} = $config_obj; |
|
844 | - return true; |
|
845 | - } elseif ($throw_errors) { |
|
846 | - EE_Error::add_error( |
|
847 | - sprintf( |
|
848 | - __( |
|
849 | - 'The "%1$s" object stored at"%2$s" was not successfully updated in the database.', |
|
850 | - 'event_espresso' |
|
851 | - ), |
|
852 | - $config_class, |
|
853 | - 'EE_Config->' . $section . '->' . $name |
|
854 | - ), |
|
855 | - __FILE__, |
|
856 | - __FUNCTION__, |
|
857 | - __LINE__ |
|
858 | - ); |
|
859 | - } |
|
860 | - } |
|
861 | - return false; |
|
862 | - } |
|
863 | - |
|
864 | - |
|
865 | - |
|
866 | - /** |
|
867 | - * get_config |
|
868 | - * |
|
869 | - * @access public |
|
870 | - * @param string $section |
|
871 | - * @param string $name |
|
872 | - * @param string $config_class |
|
873 | - * @return mixed EE_Config_Base | NULL |
|
874 | - */ |
|
875 | - public function get_config($section = '', $name = '', $config_class = '') |
|
876 | - { |
|
877 | - // ensure config class is set to something |
|
878 | - $config_class = $this->_set_config_class($config_class, $name); |
|
879 | - // run tests 1-4, 6 and 7 to verify that all params have been set |
|
880 | - if (! $this->_verify_config_params($section, $name, $config_class, null, array(1, 2, 3, 4, 5, 6))) { |
|
881 | - return null; |
|
882 | - } |
|
883 | - // now test if the requested config object exists, but suppress errors |
|
884 | - if ($this->_verify_config_params($section, $name, $config_class, null, array(7, 8), false)) { |
|
885 | - // config already exists, so pass it back |
|
886 | - return $this->{$section}->{$name}; |
|
887 | - } |
|
888 | - // load config option from db if it exists |
|
889 | - $config_obj = $this->get_config_option($this->_generate_config_option_name($section, $name)); |
|
890 | - // verify the newly retrieved config object, but suppress errors |
|
891 | - if ($this->_verify_config_params($section, $name, $config_class, $config_obj, array(9), false)) { |
|
892 | - // config is good, so set it and pass it back |
|
893 | - $this->{$section}->{$name} = $config_obj; |
|
894 | - return $this->{$section}->{$name}; |
|
895 | - } |
|
896 | - // oops! $config_obj is not already set and does not exist in the db, so create a new one |
|
897 | - $config_obj = $this->set_config($section, $name, $config_class); |
|
898 | - // verify the newly created config object |
|
899 | - if ($this->_verify_config_params($section, $name, $config_class, $config_obj, array(9))) { |
|
900 | - return $this->{$section}->{$name}; |
|
901 | - } else { |
|
902 | - EE_Error::add_error( |
|
903 | - sprintf(__('The "%s" could not be retrieved from the database.', 'event_espresso'), $config_class), |
|
904 | - __FILE__, |
|
905 | - __FUNCTION__, |
|
906 | - __LINE__ |
|
907 | - ); |
|
908 | - } |
|
909 | - return null; |
|
910 | - } |
|
911 | - |
|
912 | - |
|
913 | - |
|
914 | - /** |
|
915 | - * get_config_option |
|
916 | - * |
|
917 | - * @access public |
|
918 | - * @param string $config_option_name |
|
919 | - * @return mixed EE_Config_Base | FALSE |
|
920 | - */ |
|
921 | - public function get_config_option($config_option_name = '') |
|
922 | - { |
|
923 | - // retrieve the wp-option for this config class. |
|
924 | - $config_option = maybe_unserialize(get_option($config_option_name, array())); |
|
925 | - if (empty($config_option)) { |
|
926 | - EE_Config::log($config_option_name . '-NOT-FOUND'); |
|
927 | - } |
|
928 | - return $config_option; |
|
929 | - } |
|
930 | - |
|
931 | - |
|
932 | - |
|
933 | - /** |
|
934 | - * log |
|
935 | - * |
|
936 | - * @param string $config_option_name |
|
937 | - */ |
|
938 | - public static function log($config_option_name = '') |
|
939 | - { |
|
940 | - if (EE_Config::logging_enabled() && ! empty($config_option_name)) { |
|
941 | - $config_log = get_option(EE_Config::LOG_NAME, array()); |
|
942 | - //copy incoming $_REQUEST and sanitize it so we can save it |
|
943 | - $_request = $_REQUEST; |
|
944 | - array_walk_recursive($_request, 'sanitize_text_field'); |
|
945 | - $config_log[(string)microtime(true)] = array( |
|
946 | - 'config_name' => $config_option_name, |
|
947 | - 'request' => $_request, |
|
948 | - ); |
|
949 | - update_option(EE_Config::LOG_NAME, $config_log); |
|
950 | - } |
|
951 | - } |
|
952 | - |
|
953 | - |
|
954 | - |
|
955 | - /** |
|
956 | - * trim_log |
|
957 | - * reduces the size of the config log to the length specified by EE_Config::LOG_LENGTH |
|
958 | - */ |
|
959 | - public static function trim_log() |
|
960 | - { |
|
961 | - if (! EE_Config::logging_enabled()) { |
|
962 | - return; |
|
963 | - } |
|
964 | - $config_log = maybe_unserialize(get_option(EE_Config::LOG_NAME, array())); |
|
965 | - $log_length = count($config_log); |
|
966 | - if ($log_length > EE_Config::LOG_LENGTH) { |
|
967 | - ksort($config_log); |
|
968 | - $config_log = array_slice($config_log, $log_length - EE_Config::LOG_LENGTH, null, true); |
|
969 | - update_option(EE_Config::LOG_NAME, $config_log); |
|
970 | - } |
|
971 | - } |
|
972 | - |
|
973 | - |
|
974 | - |
|
975 | - /** |
|
976 | - * get_page_for_posts |
|
977 | - * if the wp-option "show_on_front" is set to "page", then this is the post_name for the post set in the |
|
978 | - * wp-option "page_for_posts", or "posts" if no page is selected |
|
979 | - * |
|
980 | - * @access public |
|
981 | - * @return string |
|
982 | - */ |
|
983 | - public static function get_page_for_posts() |
|
984 | - { |
|
985 | - $page_for_posts = get_option('page_for_posts'); |
|
986 | - if (! $page_for_posts) { |
|
987 | - return 'posts'; |
|
988 | - } |
|
989 | - /** @type WPDB $wpdb */ |
|
990 | - global $wpdb; |
|
991 | - $SQL = "SELECT post_name from $wpdb->posts WHERE post_type='posts' OR post_type='page' AND post_status='publish' AND ID=%d"; |
|
992 | - return $wpdb->get_var($wpdb->prepare($SQL, $page_for_posts)); |
|
993 | - } |
|
994 | - |
|
995 | - |
|
996 | - |
|
997 | - /** |
|
998 | - * register_shortcodes_and_modules. |
|
999 | - * At this point, it's too early to tell if we're maintenance mode or not. |
|
1000 | - * In fact, this is where we give modules a chance to let core know they exist |
|
1001 | - * so they can help trigger maintenance mode if it's needed |
|
1002 | - * |
|
1003 | - * @access public |
|
1004 | - * @return void |
|
1005 | - */ |
|
1006 | - public function register_shortcodes_and_modules() |
|
1007 | - { |
|
1008 | - // allow modules to set hooks for the rest of the system |
|
1009 | - EE_Registry::instance()->modules = $this->_register_modules(); |
|
1010 | - } |
|
1011 | - |
|
1012 | - |
|
1013 | - |
|
1014 | - /** |
|
1015 | - * initialize_shortcodes_and_modules |
|
1016 | - * meaning they can start adding their hooks to get stuff done |
|
1017 | - * |
|
1018 | - * @access public |
|
1019 | - * @return void |
|
1020 | - */ |
|
1021 | - public function initialize_shortcodes_and_modules() |
|
1022 | - { |
|
1023 | - // allow modules to set hooks for the rest of the system |
|
1024 | - $this->_initialize_modules(); |
|
1025 | - } |
|
1026 | - |
|
1027 | - |
|
1028 | - |
|
1029 | - /** |
|
1030 | - * widgets_init |
|
1031 | - * |
|
1032 | - * @access private |
|
1033 | - * @return void |
|
1034 | - */ |
|
1035 | - public function widgets_init() |
|
1036 | - { |
|
1037 | - //only init widgets on admin pages when not in complete maintenance, and |
|
1038 | - //on frontend when not in any maintenance mode |
|
1039 | - if ( |
|
1040 | - ! EE_Maintenance_Mode::instance()->level() |
|
1041 | - || ( |
|
1042 | - is_admin() |
|
1043 | - && EE_Maintenance_Mode::instance()->level() !== EE_Maintenance_Mode::level_2_complete_maintenance |
|
1044 | - ) |
|
1045 | - ) { |
|
1046 | - // grab list of installed widgets |
|
1047 | - $widgets_to_register = glob(EE_WIDGETS . '*', GLOB_ONLYDIR); |
|
1048 | - // filter list of modules to register |
|
1049 | - $widgets_to_register = apply_filters( |
|
1050 | - 'FHEE__EE_Config__register_widgets__widgets_to_register', |
|
1051 | - $widgets_to_register |
|
1052 | - ); |
|
1053 | - if (! empty($widgets_to_register)) { |
|
1054 | - // cycle thru widget folders |
|
1055 | - foreach ($widgets_to_register as $widget_path) { |
|
1056 | - // add to list of installed widget modules |
|
1057 | - EE_Config::register_ee_widget($widget_path); |
|
1058 | - } |
|
1059 | - } |
|
1060 | - // filter list of installed modules |
|
1061 | - EE_Registry::instance()->widgets = apply_filters( |
|
1062 | - 'FHEE__EE_Config__register_widgets__installed_widgets', |
|
1063 | - EE_Registry::instance()->widgets |
|
1064 | - ); |
|
1065 | - } |
|
1066 | - } |
|
1067 | - |
|
1068 | - |
|
1069 | - |
|
1070 | - /** |
|
1071 | - * register_ee_widget - makes core aware of this widget |
|
1072 | - * |
|
1073 | - * @access public |
|
1074 | - * @param string $widget_path - full path up to and including widget folder |
|
1075 | - * @return void |
|
1076 | - */ |
|
1077 | - public static function register_ee_widget($widget_path = null) |
|
1078 | - { |
|
1079 | - do_action('AHEE__EE_Config__register_widget__begin', $widget_path); |
|
1080 | - $widget_ext = '.widget.php'; |
|
1081 | - // make all separators match |
|
1082 | - $widget_path = rtrim(str_replace('/\\', DS, $widget_path), DS); |
|
1083 | - // does the file path INCLUDE the actual file name as part of the path ? |
|
1084 | - if (strpos($widget_path, $widget_ext) !== false) { |
|
1085 | - // grab and shortcode file name from directory name and break apart at dots |
|
1086 | - $file_name = explode('.', basename($widget_path)); |
|
1087 | - // take first segment from file name pieces and remove class prefix if it exists |
|
1088 | - $widget = strpos($file_name[0], 'EEW_') === 0 ? substr($file_name[0], 4) : $file_name[0]; |
|
1089 | - // sanitize shortcode directory name |
|
1090 | - $widget = sanitize_key($widget); |
|
1091 | - // now we need to rebuild the shortcode path |
|
1092 | - $widget_path = explode(DS, $widget_path); |
|
1093 | - // remove last segment |
|
1094 | - array_pop($widget_path); |
|
1095 | - // glue it back together |
|
1096 | - $widget_path = implode(DS, $widget_path); |
|
1097 | - } else { |
|
1098 | - // grab and sanitize widget directory name |
|
1099 | - $widget = sanitize_key(basename($widget_path)); |
|
1100 | - } |
|
1101 | - // create classname from widget directory name |
|
1102 | - $widget = str_replace(' ', '_', ucwords(str_replace('_', ' ', $widget))); |
|
1103 | - // add class prefix |
|
1104 | - $widget_class = 'EEW_' . $widget; |
|
1105 | - // does the widget exist ? |
|
1106 | - if (! is_readable($widget_path . DS . $widget_class . $widget_ext)) { |
|
1107 | - $msg = sprintf( |
|
1108 | - __( |
|
1109 | - 'The requested %s widget file could not be found or is not readable due to file permissions. Please ensure the following path is correct: %s', |
|
1110 | - 'event_espresso' |
|
1111 | - ), |
|
1112 | - $widget_class, |
|
1113 | - $widget_path . DS . $widget_class . $widget_ext |
|
1114 | - ); |
|
1115 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
1116 | - return; |
|
1117 | - } |
|
1118 | - // load the widget class file |
|
1119 | - require_once($widget_path . DS . $widget_class . $widget_ext); |
|
1120 | - // verify that class exists |
|
1121 | - if (! class_exists($widget_class)) { |
|
1122 | - $msg = sprintf(__('The requested %s widget class does not exist.', 'event_espresso'), $widget_class); |
|
1123 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
1124 | - return; |
|
1125 | - } |
|
1126 | - register_widget($widget_class); |
|
1127 | - // add to array of registered widgets |
|
1128 | - EE_Registry::instance()->widgets->{$widget_class} = $widget_path . DS . $widget_class . $widget_ext; |
|
1129 | - } |
|
1130 | - |
|
1131 | - |
|
1132 | - |
|
1133 | - /** |
|
1134 | - * _register_modules |
|
1135 | - * |
|
1136 | - * @access private |
|
1137 | - * @return array |
|
1138 | - */ |
|
1139 | - private function _register_modules() |
|
1140 | - { |
|
1141 | - // grab list of installed modules |
|
1142 | - $modules_to_register = glob(EE_MODULES . '*', GLOB_ONLYDIR); |
|
1143 | - // filter list of modules to register |
|
1144 | - $modules_to_register = apply_filters( |
|
1145 | - 'FHEE__EE_Config__register_modules__modules_to_register', |
|
1146 | - $modules_to_register |
|
1147 | - ); |
|
1148 | - if (! empty($modules_to_register)) { |
|
1149 | - // loop through folders |
|
1150 | - foreach ($modules_to_register as $module_path) { |
|
1151 | - /**TEMPORARILY EXCLUDE gateways from modules for time being**/ |
|
1152 | - if ( |
|
1153 | - $module_path !== EE_MODULES . 'zzz-copy-this-module-template' |
|
1154 | - && $module_path !== EE_MODULES . 'gateways' |
|
1155 | - ) { |
|
1156 | - // add to list of installed modules |
|
1157 | - EE_Config::register_module($module_path); |
|
1158 | - } |
|
1159 | - } |
|
1160 | - } |
|
1161 | - // filter list of installed modules |
|
1162 | - return apply_filters( |
|
1163 | - 'FHEE__EE_Config___register_modules__installed_modules', |
|
1164 | - EE_Registry::instance()->modules |
|
1165 | - ); |
|
1166 | - } |
|
1167 | - |
|
1168 | - |
|
1169 | - |
|
1170 | - /** |
|
1171 | - * register_module - makes core aware of this module |
|
1172 | - * |
|
1173 | - * @access public |
|
1174 | - * @param string $module_path - full path up to and including module folder |
|
1175 | - * @return bool |
|
1176 | - */ |
|
1177 | - public static function register_module($module_path = null) |
|
1178 | - { |
|
1179 | - do_action('AHEE__EE_Config__register_module__begin', $module_path); |
|
1180 | - $module_ext = '.module.php'; |
|
1181 | - // make all separators match |
|
1182 | - $module_path = str_replace(array('\\', '/'), DS, $module_path); |
|
1183 | - // does the file path INCLUDE the actual file name as part of the path ? |
|
1184 | - if (strpos($module_path, $module_ext) !== false) { |
|
1185 | - // grab and shortcode file name from directory name and break apart at dots |
|
1186 | - $module_file = explode('.', basename($module_path)); |
|
1187 | - // now we need to rebuild the shortcode path |
|
1188 | - $module_path = explode(DS, $module_path); |
|
1189 | - // remove last segment |
|
1190 | - array_pop($module_path); |
|
1191 | - // glue it back together |
|
1192 | - $module_path = implode(DS, $module_path) . DS; |
|
1193 | - // take first segment from file name pieces and sanitize it |
|
1194 | - $module = preg_replace('/[^a-zA-Z0-9_\-]/', '', $module_file[0]); |
|
1195 | - // ensure class prefix is added |
|
1196 | - $module_class = strpos($module, 'EED_') !== 0 ? 'EED_' . $module : $module; |
|
1197 | - } else { |
|
1198 | - // we need to generate the filename based off of the folder name |
|
1199 | - // grab and sanitize module name |
|
1200 | - $module = strtolower(basename($module_path)); |
|
1201 | - $module = preg_replace('/[^a-z0-9_\-]/', '', $module); |
|
1202 | - // like trailingslashit() |
|
1203 | - $module_path = rtrim($module_path, DS) . DS; |
|
1204 | - // create classname from module directory name |
|
1205 | - $module = str_replace(' ', '_', ucwords(str_replace('_', ' ', $module))); |
|
1206 | - // add class prefix |
|
1207 | - $module_class = 'EED_' . $module; |
|
1208 | - } |
|
1209 | - // does the module exist ? |
|
1210 | - if (! is_readable($module_path . DS . $module_class . $module_ext)) { |
|
1211 | - $msg = sprintf( |
|
1212 | - __( |
|
1213 | - 'The requested %s module file could not be found or is not readable due to file permissions.', |
|
1214 | - 'event_espresso' |
|
1215 | - ), |
|
1216 | - $module |
|
1217 | - ); |
|
1218 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
1219 | - return false; |
|
1220 | - } |
|
1221 | - // load the module class file |
|
1222 | - require_once($module_path . $module_class . $module_ext); |
|
1223 | - // verify that class exists |
|
1224 | - if (! class_exists($module_class)) { |
|
1225 | - $msg = sprintf(__('The requested %s module class does not exist.', 'event_espresso'), $module_class); |
|
1226 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
1227 | - return false; |
|
1228 | - } |
|
1229 | - // add to array of registered modules |
|
1230 | - EE_Registry::instance()->modules->{$module_class} = $module_path . $module_class . $module_ext; |
|
1231 | - do_action( |
|
1232 | - 'AHEE__EE_Config__register_module__complete', |
|
1233 | - $module_class, |
|
1234 | - EE_Registry::instance()->modules->{$module_class} |
|
1235 | - ); |
|
1236 | - return true; |
|
1237 | - } |
|
1238 | - |
|
1239 | - |
|
1240 | - |
|
1241 | - /** |
|
1242 | - * _initialize_modules |
|
1243 | - * allow modules to set hooks for the rest of the system |
|
1244 | - * |
|
1245 | - * @access private |
|
1246 | - * @return void |
|
1247 | - */ |
|
1248 | - private function _initialize_modules() |
|
1249 | - { |
|
1250 | - // cycle thru shortcode folders |
|
1251 | - foreach (EE_Registry::instance()->modules as $module_class => $module_path) { |
|
1252 | - // fire the shortcode class's set_hooks methods in case it needs to hook into other parts of the system |
|
1253 | - // which set hooks ? |
|
1254 | - if (is_admin()) { |
|
1255 | - // fire immediately |
|
1256 | - call_user_func(array($module_class, 'set_hooks_admin')); |
|
1257 | - } else { |
|
1258 | - // delay until other systems are online |
|
1259 | - add_action( |
|
1260 | - 'AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons', |
|
1261 | - array($module_class, 'set_hooks') |
|
1262 | - ); |
|
1263 | - } |
|
1264 | - } |
|
1265 | - } |
|
1266 | - |
|
1267 | - |
|
1268 | - |
|
1269 | - /** |
|
1270 | - * register_route - adds module method routes to route_map |
|
1271 | - * |
|
1272 | - * @access public |
|
1273 | - * @param string $route - "pretty" public alias for module method |
|
1274 | - * @param string $module - module name (classname without EED_ prefix) |
|
1275 | - * @param string $method_name - the actual module method to be routed to |
|
1276 | - * @param string $key - url param key indicating a route is being called |
|
1277 | - * @return bool |
|
1278 | - */ |
|
1279 | - public static function register_route($route = null, $module = null, $method_name = null, $key = 'ee') |
|
1280 | - { |
|
1281 | - do_action('AHEE__EE_Config__register_route__begin', $route, $module, $method_name); |
|
1282 | - $module = str_replace('EED_', '', $module); |
|
1283 | - $module_class = 'EED_' . $module; |
|
1284 | - if (! isset(EE_Registry::instance()->modules->{$module_class})) { |
|
1285 | - $msg = sprintf(__('The module %s has not been registered.', 'event_espresso'), $module); |
|
1286 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
1287 | - return false; |
|
1288 | - } |
|
1289 | - if (empty($route)) { |
|
1290 | - $msg = sprintf(__('No route has been supplied.', 'event_espresso'), $route); |
|
1291 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
1292 | - return false; |
|
1293 | - } |
|
1294 | - if (! method_exists('EED_' . $module, $method_name)) { |
|
1295 | - $msg = sprintf( |
|
1296 | - __('A valid class method for the %s route has not been supplied.', 'event_espresso'), |
|
1297 | - $route |
|
1298 | - ); |
|
1299 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
1300 | - return false; |
|
1301 | - } |
|
1302 | - EE_Config::$_module_route_map[$key][$route] = array('EED_' . $module, $method_name); |
|
1303 | - return true; |
|
1304 | - } |
|
1305 | - |
|
1306 | - |
|
1307 | - |
|
1308 | - /** |
|
1309 | - * get_route - get module method route |
|
1310 | - * |
|
1311 | - * @access public |
|
1312 | - * @param string $route - "pretty" public alias for module method |
|
1313 | - * @param string $key - url param key indicating a route is being called |
|
1314 | - * @return string |
|
1315 | - */ |
|
1316 | - public static function get_route($route = null, $key = 'ee') |
|
1317 | - { |
|
1318 | - do_action('AHEE__EE_Config__get_route__begin', $route); |
|
1319 | - $route = (string)apply_filters('FHEE__EE_Config__get_route', $route); |
|
1320 | - if (isset(EE_Config::$_module_route_map[$key][$route])) { |
|
1321 | - return EE_Config::$_module_route_map[$key][$route]; |
|
1322 | - } |
|
1323 | - return null; |
|
1324 | - } |
|
1325 | - |
|
1326 | - |
|
1327 | - |
|
1328 | - /** |
|
1329 | - * get_routes - get ALL module method routes |
|
1330 | - * |
|
1331 | - * @access public |
|
1332 | - * @return array |
|
1333 | - */ |
|
1334 | - public static function get_routes() |
|
1335 | - { |
|
1336 | - return EE_Config::$_module_route_map; |
|
1337 | - } |
|
1338 | - |
|
1339 | - |
|
1340 | - |
|
1341 | - /** |
|
1342 | - * register_forward - allows modules to forward request to another module for further processing |
|
1343 | - * |
|
1344 | - * @access public |
|
1345 | - * @param string $route - "pretty" public alias for module method |
|
1346 | - * @param integer $status - integer value corresponding to status constant strings set in module parent |
|
1347 | - * class, allows different forwards to be served based on status |
|
1348 | - * @param array|string $forward - function name or array( class, method ) |
|
1349 | - * @param string $key - url param key indicating a route is being called |
|
1350 | - * @return bool |
|
1351 | - */ |
|
1352 | - public static function register_forward($route = null, $status = 0, $forward = null, $key = 'ee') |
|
1353 | - { |
|
1354 | - do_action('AHEE__EE_Config__register_forward', $route, $status, $forward); |
|
1355 | - if (! isset(EE_Config::$_module_route_map[$key][$route]) || empty($route)) { |
|
1356 | - $msg = sprintf( |
|
1357 | - __('The module route %s for this forward has not been registered.', 'event_espresso'), |
|
1358 | - $route |
|
1359 | - ); |
|
1360 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
1361 | - return false; |
|
1362 | - } |
|
1363 | - if (empty($forward)) { |
|
1364 | - $msg = sprintf(__('No forwarding route has been supplied.', 'event_espresso'), $route); |
|
1365 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
1366 | - return false; |
|
1367 | - } |
|
1368 | - if (is_array($forward)) { |
|
1369 | - if (! isset($forward[1])) { |
|
1370 | - $msg = sprintf( |
|
1371 | - __('A class method for the %s forwarding route has not been supplied.', 'event_espresso'), |
|
1372 | - $route |
|
1373 | - ); |
|
1374 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
1375 | - return false; |
|
1376 | - } |
|
1377 | - if (! method_exists($forward[0], $forward[1])) { |
|
1378 | - $msg = sprintf( |
|
1379 | - __('The class method %s for the %s forwarding route is in invalid.', 'event_espresso'), |
|
1380 | - $forward[1], |
|
1381 | - $route |
|
1382 | - ); |
|
1383 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
1384 | - return false; |
|
1385 | - } |
|
1386 | - } else if (! function_exists($forward)) { |
|
1387 | - $msg = sprintf( |
|
1388 | - __('The function %s for the %s forwarding route is in invalid.', 'event_espresso'), |
|
1389 | - $forward, |
|
1390 | - $route |
|
1391 | - ); |
|
1392 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
1393 | - return false; |
|
1394 | - } |
|
1395 | - EE_Config::$_module_forward_map[$key][$route][absint($status)] = $forward; |
|
1396 | - return true; |
|
1397 | - } |
|
1398 | - |
|
1399 | - |
|
1400 | - |
|
1401 | - /** |
|
1402 | - * get_forward - get forwarding route |
|
1403 | - * |
|
1404 | - * @access public |
|
1405 | - * @param string $route - "pretty" public alias for module method |
|
1406 | - * @param integer $status - integer value corresponding to status constant strings set in module parent class, |
|
1407 | - * allows different forwards to be served based on status |
|
1408 | - * @param string $key - url param key indicating a route is being called |
|
1409 | - * @return string |
|
1410 | - */ |
|
1411 | - public static function get_forward($route = null, $status = 0, $key = 'ee') |
|
1412 | - { |
|
1413 | - do_action('AHEE__EE_Config__get_forward__begin', $route, $status); |
|
1414 | - if (isset(EE_Config::$_module_forward_map[$key][$route][$status])) { |
|
1415 | - return apply_filters( |
|
1416 | - 'FHEE__EE_Config__get_forward', |
|
1417 | - EE_Config::$_module_forward_map[$key][$route][$status], |
|
1418 | - $route, |
|
1419 | - $status |
|
1420 | - ); |
|
1421 | - } |
|
1422 | - return null; |
|
1423 | - } |
|
1424 | - |
|
1425 | - |
|
1426 | - |
|
1427 | - /** |
|
1428 | - * register_forward - allows modules to specify different view templates for different method routes and status |
|
1429 | - * results |
|
1430 | - * |
|
1431 | - * @access public |
|
1432 | - * @param string $route - "pretty" public alias for module method |
|
1433 | - * @param integer $status - integer value corresponding to status constant strings set in module parent class, |
|
1434 | - * allows different views to be served based on status |
|
1435 | - * @param string $view |
|
1436 | - * @param string $key - url param key indicating a route is being called |
|
1437 | - * @return bool |
|
1438 | - */ |
|
1439 | - public static function register_view($route = null, $status = 0, $view = null, $key = 'ee') |
|
1440 | - { |
|
1441 | - do_action('AHEE__EE_Config__register_view__begin', $route, $status, $view); |
|
1442 | - if (! isset(EE_Config::$_module_route_map[$key][$route]) || empty($route)) { |
|
1443 | - $msg = sprintf( |
|
1444 | - __('The module route %s for this view has not been registered.', 'event_espresso'), |
|
1445 | - $route |
|
1446 | - ); |
|
1447 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
1448 | - return false; |
|
1449 | - } |
|
1450 | - if (! is_readable($view)) { |
|
1451 | - $msg = sprintf( |
|
1452 | - __( |
|
1453 | - 'The %s view file could not be found or is not readable due to file permissions.', |
|
1454 | - 'event_espresso' |
|
1455 | - ), |
|
1456 | - $view |
|
1457 | - ); |
|
1458 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
1459 | - return false; |
|
1460 | - } |
|
1461 | - EE_Config::$_module_view_map[$key][$route][absint($status)] = $view; |
|
1462 | - return true; |
|
1463 | - } |
|
1464 | - |
|
1465 | - |
|
1466 | - |
|
1467 | - /** |
|
1468 | - * get_view - get view for route and status |
|
1469 | - * |
|
1470 | - * @access public |
|
1471 | - * @param string $route - "pretty" public alias for module method |
|
1472 | - * @param integer $status - integer value corresponding to status constant strings set in module parent class, |
|
1473 | - * allows different views to be served based on status |
|
1474 | - * @param string $key - url param key indicating a route is being called |
|
1475 | - * @return string |
|
1476 | - */ |
|
1477 | - public static function get_view($route = null, $status = 0, $key = 'ee') |
|
1478 | - { |
|
1479 | - do_action('AHEE__EE_Config__get_view__begin', $route, $status); |
|
1480 | - if (isset(EE_Config::$_module_view_map[$key][$route][$status])) { |
|
1481 | - return apply_filters( |
|
1482 | - 'FHEE__EE_Config__get_view', |
|
1483 | - EE_Config::$_module_view_map[$key][$route][$status], |
|
1484 | - $route, |
|
1485 | - $status |
|
1486 | - ); |
|
1487 | - } |
|
1488 | - return null; |
|
1489 | - } |
|
1490 | - |
|
1491 | - |
|
1492 | - |
|
1493 | - public function update_addon_option_names() |
|
1494 | - { |
|
1495 | - update_option(EE_Config::ADDON_OPTION_NAMES, $this->_addon_option_names); |
|
1496 | - } |
|
1497 | - |
|
1498 | - |
|
1499 | - |
|
1500 | - public function shutdown() |
|
1501 | - { |
|
1502 | - $this->update_addon_option_names(); |
|
1503 | - } |
|
1504 | - |
|
1505 | - |
|
1506 | - |
|
1507 | - /** |
|
1508 | - * @return LegacyShortcodesManager |
|
1509 | - */ |
|
1510 | - public static function getLegacyShortcodesManager() |
|
1511 | - { |
|
1512 | - |
|
1513 | - if ( ! EE_Config::instance()->legacy_shortcodes_manager instanceof LegacyShortcodesManager) { |
|
1514 | - EE_Config::instance()->legacy_shortcodes_manager = new LegacyShortcodesManager( |
|
1515 | - EE_Registry::instance() |
|
1516 | - ); |
|
1517 | - } |
|
1518 | - return EE_Config::instance()->legacy_shortcodes_manager; |
|
1519 | - } |
|
1520 | - |
|
1521 | - |
|
1522 | - |
|
1523 | - /** |
|
1524 | - * register_shortcode - makes core aware of this shortcode |
|
1525 | - * |
|
1526 | - * @deprecated 4.9.26 |
|
1527 | - * @param string $shortcode_path - full path up to and including shortcode folder |
|
1528 | - * @return bool |
|
1529 | - */ |
|
1530 | - public static function register_shortcode($shortcode_path = null) |
|
1531 | - { |
|
1532 | - EE_Error::doing_it_wrong( |
|
1533 | - __METHOD__, |
|
1534 | - __( |
|
1535 | - 'Usage is deprecated. Use \EventEspresso\core\services\shortcodes\LegacyShortcodesManager::registerShortcode() as direct replacement, or better yet, please see the new \EventEspresso\core\services\shortcodes\ShortcodesManager class.', |
|
1536 | - 'event_espresso' |
|
1537 | - ), |
|
1538 | - '4.9.26' |
|
1539 | - ); |
|
1540 | - return EE_Config::instance()->getLegacyShortcodesManager()->registerShortcode($shortcode_path); |
|
1541 | - } |
|
1542 | - |
|
1543 | - |
|
1544 | - |
|
1545 | -} |
|
1546 | - |
|
1547 | - |
|
1548 | - |
|
1549 | -/** |
|
1550 | - * Base class used for config classes. These classes should generally not have |
|
1551 | - * magic functions in use, except we'll allow them to magically set and get stuff... |
|
1552 | - * basically, they should just be well-defined stdClasses |
|
1553 | - */ |
|
1554 | -class EE_Config_Base |
|
1555 | -{ |
|
1556 | - |
|
1557 | - /** |
|
1558 | - * Utility function for escaping the value of a property and returning. |
|
1559 | - * |
|
1560 | - * @param string $property property name (checks to see if exists). |
|
1561 | - * @return mixed if a detected type found return the escaped value, otherwise just the raw value is returned. |
|
1562 | - * @throws \EE_Error |
|
1563 | - */ |
|
1564 | - public function get_pretty($property) |
|
1565 | - { |
|
1566 | - if (! property_exists($this, $property)) { |
|
1567 | - throw new EE_Error( |
|
1568 | - sprintf( |
|
1569 | - __( |
|
1570 | - '%1$s::get_pretty() has been called with the property %2$s which does not exist on the %1$s config class.', |
|
1571 | - 'event_espresso' |
|
1572 | - ), |
|
1573 | - get_class($this), |
|
1574 | - $property |
|
1575 | - ) |
|
1576 | - ); |
|
1577 | - } |
|
1578 | - //just handling escaping of strings for now. |
|
1579 | - if (is_string($this->{$property})) { |
|
1580 | - return stripslashes($this->{$property}); |
|
1581 | - } |
|
1582 | - return $this->{$property}; |
|
1583 | - } |
|
1584 | - |
|
1585 | - |
|
1586 | - |
|
1587 | - public function populate() |
|
1588 | - { |
|
1589 | - //grab defaults via a new instance of this class. |
|
1590 | - $class_name = get_class($this); |
|
1591 | - $defaults = new $class_name; |
|
1592 | - //loop through the properties for this class and see if they are set. If they are NOT, then grab the |
|
1593 | - //default from our $defaults object. |
|
1594 | - foreach (get_object_vars($defaults) as $property => $value) { |
|
1595 | - if ($this->{$property} === null) { |
|
1596 | - $this->{$property} = $value; |
|
1597 | - } |
|
1598 | - } |
|
1599 | - //cleanup |
|
1600 | - unset($defaults); |
|
1601 | - } |
|
1602 | - |
|
1603 | - |
|
1604 | - |
|
1605 | - /** |
|
1606 | - * __isset |
|
1607 | - * |
|
1608 | - * @param $a |
|
1609 | - * @return bool |
|
1610 | - */ |
|
1611 | - public function __isset($a) |
|
1612 | - { |
|
1613 | - return false; |
|
1614 | - } |
|
1615 | - |
|
1616 | - |
|
1617 | - |
|
1618 | - /** |
|
1619 | - * __unset |
|
1620 | - * |
|
1621 | - * @param $a |
|
1622 | - * @return bool |
|
1623 | - */ |
|
1624 | - public function __unset($a) |
|
1625 | - { |
|
1626 | - return false; |
|
1627 | - } |
|
1628 | - |
|
1629 | - |
|
1630 | - |
|
1631 | - /** |
|
1632 | - * __clone |
|
1633 | - */ |
|
1634 | - public function __clone() |
|
1635 | - { |
|
1636 | - } |
|
1637 | - |
|
1638 | - |
|
1639 | - |
|
1640 | - /** |
|
1641 | - * __wakeup |
|
1642 | - */ |
|
1643 | - public function __wakeup() |
|
1644 | - { |
|
1645 | - } |
|
1646 | - |
|
1647 | - |
|
1648 | - |
|
1649 | - /** |
|
1650 | - * __destruct |
|
1651 | - */ |
|
1652 | - public function __destruct() |
|
1653 | - { |
|
1654 | - } |
|
1655 | -} |
|
1656 | - |
|
1657 | - |
|
1658 | - |
|
1659 | -/** |
|
1660 | - * Class for defining what's in the EE_Config relating to registration settings |
|
1661 | - */ |
|
1662 | -class EE_Core_Config extends EE_Config_Base |
|
1663 | -{ |
|
1664 | - |
|
1665 | - public $current_blog_id; |
|
1666 | - |
|
1667 | - public $ee_ueip_optin; |
|
1668 | - |
|
1669 | - public $ee_ueip_has_notified; |
|
1670 | - |
|
1671 | - /** |
|
1672 | - * Not to be confused with the 4 critical page variables (See |
|
1673 | - * get_critical_pages_array()), this is just an array of wp posts that have EE |
|
1674 | - * shortcodes in them. Keys are slugs, values are arrays with only 1 element: where the key is the shortcode |
|
1675 | - * in the page, and the value is the page's ID. The key 'posts' is basically a duplicate of this same array. |
|
1676 | - * |
|
1677 | - * @var array |
|
1678 | - */ |
|
1679 | - public $post_shortcodes; |
|
1680 | - |
|
1681 | - public $module_route_map; |
|
1682 | - |
|
1683 | - public $module_forward_map; |
|
1684 | - |
|
1685 | - public $module_view_map; |
|
1686 | - |
|
1687 | - /** |
|
1688 | - * The next 4 vars are the IDs of critical EE pages. |
|
1689 | - * |
|
1690 | - * @var int |
|
1691 | - */ |
|
1692 | - public $reg_page_id; |
|
1693 | - |
|
1694 | - public $txn_page_id; |
|
1695 | - |
|
1696 | - public $thank_you_page_id; |
|
1697 | - |
|
1698 | - public $cancel_page_id; |
|
1699 | - |
|
1700 | - /** |
|
1701 | - * The next 4 vars are the URLs of critical EE pages. |
|
1702 | - * |
|
1703 | - * @var int |
|
1704 | - */ |
|
1705 | - public $reg_page_url; |
|
1706 | - |
|
1707 | - public $txn_page_url; |
|
1708 | - |
|
1709 | - public $thank_you_page_url; |
|
1710 | - |
|
1711 | - public $cancel_page_url; |
|
1712 | - |
|
1713 | - /** |
|
1714 | - * The next vars relate to the custom slugs for EE CPT routes |
|
1715 | - */ |
|
1716 | - public $event_cpt_slug; |
|
1717 | - |
|
1718 | - |
|
1719 | - /** |
|
1720 | - * This caches the _ee_ueip_option in case this config is reset in the same |
|
1721 | - * request across blog switches in a multisite context. |
|
1722 | - * Avoids extra queries to the db for this option. |
|
1723 | - * |
|
1724 | - * @var bool |
|
1725 | - */ |
|
1726 | - public static $ee_ueip_option; |
|
1727 | - |
|
1728 | - |
|
1729 | - |
|
1730 | - /** |
|
1731 | - * class constructor |
|
1732 | - * |
|
1733 | - * @access public |
|
1734 | - */ |
|
1735 | - public function __construct() |
|
1736 | - { |
|
1737 | - // set default organization settings |
|
1738 | - $this->current_blog_id = get_current_blog_id(); |
|
1739 | - $this->current_blog_id = $this->current_blog_id === null ? 1 : $this->current_blog_id; |
|
1740 | - $this->ee_ueip_optin = $this->_get_main_ee_ueip_optin(); |
|
1741 | - $this->ee_ueip_has_notified = is_main_site() ? get_option('ee_ueip_has_notified', false) : true; |
|
1742 | - $this->post_shortcodes = array(); |
|
1743 | - $this->module_route_map = array(); |
|
1744 | - $this->module_forward_map = array(); |
|
1745 | - $this->module_view_map = array(); |
|
1746 | - // critical EE page IDs |
|
1747 | - $this->reg_page_id = 0; |
|
1748 | - $this->txn_page_id = 0; |
|
1749 | - $this->thank_you_page_id = 0; |
|
1750 | - $this->cancel_page_id = 0; |
|
1751 | - // critical EE page URLs |
|
1752 | - $this->reg_page_url = ''; |
|
1753 | - $this->txn_page_url = ''; |
|
1754 | - $this->thank_you_page_url = ''; |
|
1755 | - $this->cancel_page_url = ''; |
|
1756 | - //cpt slugs |
|
1757 | - $this->event_cpt_slug = __('events', 'event_espresso'); |
|
1758 | - //ueip constant check |
|
1759 | - if (defined('EE_DISABLE_UXIP') && EE_DISABLE_UXIP) { |
|
1760 | - $this->ee_ueip_optin = false; |
|
1761 | - $this->ee_ueip_has_notified = true; |
|
1762 | - } |
|
1763 | - } |
|
1764 | - |
|
1765 | - |
|
1766 | - |
|
1767 | - /** |
|
1768 | - * @return array |
|
1769 | - */ |
|
1770 | - public function get_critical_pages_array() |
|
1771 | - { |
|
1772 | - return array( |
|
1773 | - $this->reg_page_id, |
|
1774 | - $this->txn_page_id, |
|
1775 | - $this->thank_you_page_id, |
|
1776 | - $this->cancel_page_id, |
|
1777 | - ); |
|
1778 | - } |
|
1779 | - |
|
1780 | - |
|
1781 | - |
|
1782 | - /** |
|
1783 | - * @return array |
|
1784 | - */ |
|
1785 | - public function get_critical_pages_shortcodes_array() |
|
1786 | - { |
|
1787 | - return array( |
|
1788 | - $this->reg_page_id => 'ESPRESSO_CHECKOUT', |
|
1789 | - $this->txn_page_id => 'ESPRESSO_TXN_PAGE', |
|
1790 | - $this->thank_you_page_id => 'ESPRESSO_THANK_YOU', |
|
1791 | - $this->cancel_page_id => 'ESPRESSO_CANCELLED', |
|
1792 | - ); |
|
1793 | - } |
|
1794 | - |
|
1795 | - |
|
1796 | - |
|
1797 | - /** |
|
1798 | - * gets/returns URL for EE reg_page |
|
1799 | - * |
|
1800 | - * @access public |
|
1801 | - * @return string |
|
1802 | - */ |
|
1803 | - public function reg_page_url() |
|
1804 | - { |
|
1805 | - if (! $this->reg_page_url) { |
|
1806 | - $this->reg_page_url = add_query_arg( |
|
1807 | - array('uts' => time()), |
|
1808 | - get_permalink($this->reg_page_id) |
|
1809 | - ) . '#checkout'; |
|
1810 | - } |
|
1811 | - return $this->reg_page_url; |
|
1812 | - } |
|
1813 | - |
|
1814 | - |
|
1815 | - |
|
1816 | - /** |
|
1817 | - * gets/returns URL for EE txn_page |
|
1818 | - * |
|
1819 | - * @param array $query_args like what gets passed to |
|
1820 | - * add_query_arg() as the first argument |
|
1821 | - * @access public |
|
1822 | - * @return string |
|
1823 | - */ |
|
1824 | - public function txn_page_url($query_args = array()) |
|
1825 | - { |
|
1826 | - if (! $this->txn_page_url) { |
|
1827 | - $this->txn_page_url = get_permalink($this->txn_page_id); |
|
1828 | - } |
|
1829 | - if ($query_args) { |
|
1830 | - return add_query_arg($query_args, $this->txn_page_url); |
|
1831 | - } else { |
|
1832 | - return $this->txn_page_url; |
|
1833 | - } |
|
1834 | - } |
|
1835 | - |
|
1836 | - |
|
1837 | - |
|
1838 | - /** |
|
1839 | - * gets/returns URL for EE thank_you_page |
|
1840 | - * |
|
1841 | - * @param array $query_args like what gets passed to |
|
1842 | - * add_query_arg() as the first argument |
|
1843 | - * @access public |
|
1844 | - * @return string |
|
1845 | - */ |
|
1846 | - public function thank_you_page_url($query_args = array()) |
|
1847 | - { |
|
1848 | - if (! $this->thank_you_page_url) { |
|
1849 | - $this->thank_you_page_url = get_permalink($this->thank_you_page_id); |
|
1850 | - } |
|
1851 | - if ($query_args) { |
|
1852 | - return add_query_arg($query_args, $this->thank_you_page_url); |
|
1853 | - } else { |
|
1854 | - return $this->thank_you_page_url; |
|
1855 | - } |
|
1856 | - } |
|
1857 | - |
|
1858 | - |
|
1859 | - |
|
1860 | - /** |
|
1861 | - * gets/returns URL for EE cancel_page |
|
1862 | - * |
|
1863 | - * @access public |
|
1864 | - * @return string |
|
1865 | - */ |
|
1866 | - public function cancel_page_url() |
|
1867 | - { |
|
1868 | - if (! $this->cancel_page_url) { |
|
1869 | - $this->cancel_page_url = get_permalink($this->cancel_page_id); |
|
1870 | - } |
|
1871 | - return $this->cancel_page_url; |
|
1872 | - } |
|
1873 | - |
|
1874 | - |
|
1875 | - |
|
1876 | - /** |
|
1877 | - * Resets all critical page urls to their original state. Used primarily by the __sleep() magic method currently. |
|
1878 | - * |
|
1879 | - * @since 4.7.5 |
|
1880 | - */ |
|
1881 | - protected function _reset_urls() |
|
1882 | - { |
|
1883 | - $this->reg_page_url = ''; |
|
1884 | - $this->txn_page_url = ''; |
|
1885 | - $this->cancel_page_url = ''; |
|
1886 | - $this->thank_you_page_url = ''; |
|
1887 | - } |
|
1888 | - |
|
1889 | - |
|
1890 | - |
|
1891 | - /** |
|
1892 | - * Used to return what the optin value is set for the EE User Experience Program. |
|
1893 | - * This accounts for multisite and this value being requested for a subsite. In multisite, the value is set |
|
1894 | - * on the main site only. |
|
1895 | - * |
|
1896 | - * @return mixed|void |
|
1897 | - */ |
|
1898 | - protected function _get_main_ee_ueip_optin() |
|
1899 | - { |
|
1900 | - //if this is the main site then we can just bypass our direct query. |
|
1901 | - if (is_main_site()) { |
|
1902 | - return get_option('ee_ueip_optin', false); |
|
1903 | - } |
|
1904 | - //is this already cached for this request? If so use it. |
|
1905 | - if ( ! empty(EE_Core_Config::$ee_ueip_option)) { |
|
1906 | - return EE_Core_Config::$ee_ueip_option; |
|
1907 | - } |
|
1908 | - global $wpdb; |
|
1909 | - $current_network_main_site = is_multisite() ? get_current_site() : null; |
|
1910 | - $current_main_site_id = ! empty($current_network_main_site) ? $current_network_main_site->blog_id : 1; |
|
1911 | - $option = 'ee_ueip_optin'; |
|
1912 | - //set correct table for query |
|
1913 | - $table_name = $wpdb->get_blog_prefix($current_main_site_id) . 'options'; |
|
1914 | - //rather than getting blog option for the $current_main_site_id, we do a direct $wpdb query because |
|
1915 | - //get_blog_option() does a switch_to_blog an that could cause infinite recursion because EE_Core_Config might be |
|
1916 | - //re-constructed on the blog switch. Note, we are still executing any core wp filters on this option retrieval. |
|
1917 | - //this bit of code is basically a direct copy of get_option without any caching because we are NOT switched to the blog |
|
1918 | - //for the purpose of caching. |
|
1919 | - $pre = apply_filters('pre_option_' . $option, false, $option); |
|
1920 | - if (false !== $pre) { |
|
1921 | - EE_Core_Config::$ee_ueip_option = $pre; |
|
1922 | - return EE_Core_Config::$ee_ueip_option; |
|
1923 | - } |
|
1924 | - $row = $wpdb->get_row($wpdb->prepare("SELECT option_value FROM $table_name WHERE option_name = %s LIMIT 1", |
|
1925 | - $option)); |
|
1926 | - if (is_object($row)) { |
|
1927 | - $value = $row->option_value; |
|
1928 | - } else { //option does not exist so use default. |
|
1929 | - return apply_filters('default_option_' . $option, false, $option); |
|
1930 | - } |
|
1931 | - EE_Core_Config::$ee_ueip_option = apply_filters('option_' . $option, maybe_unserialize($value), $option); |
|
1932 | - return EE_Core_Config::$ee_ueip_option; |
|
1933 | - } |
|
1934 | - |
|
1935 | - |
|
1936 | - |
|
1937 | - /** |
|
1938 | - * Currently used to ensure critical page urls have initial values saved to the db instead of any current set values |
|
1939 | - * on the object. |
|
1940 | - * |
|
1941 | - * @return array |
|
1942 | - */ |
|
1943 | - public function __sleep() |
|
1944 | - { |
|
1945 | - //reset all url properties |
|
1946 | - $this->_reset_urls(); |
|
1947 | - //return what to save to db |
|
1948 | - return array_keys(get_object_vars($this)); |
|
1949 | - } |
|
1950 | - |
|
1951 | -} |
|
1952 | - |
|
1953 | - |
|
1954 | - |
|
1955 | -/** |
|
1956 | - * Config class for storing info on the Organization |
|
1957 | - */ |
|
1958 | -class EE_Organization_Config extends EE_Config_Base |
|
1959 | -{ |
|
1960 | - |
|
1961 | - /** |
|
1962 | - * @var string $name |
|
1963 | - * eg EE4.1 |
|
1964 | - */ |
|
1965 | - public $name; |
|
1966 | - |
|
1967 | - /** |
|
1968 | - * @var string $address_1 |
|
1969 | - * eg 123 Onna Road |
|
1970 | - */ |
|
1971 | - public $address_1; |
|
1972 | - |
|
1973 | - /** |
|
1974 | - * @var string $address_2 |
|
1975 | - * eg PO Box 123 |
|
1976 | - */ |
|
1977 | - public $address_2; |
|
1978 | - |
|
1979 | - /** |
|
1980 | - * @var string $city |
|
1981 | - * eg Inna City |
|
1982 | - */ |
|
1983 | - public $city; |
|
1984 | - |
|
1985 | - /** |
|
1986 | - * @var int $STA_ID |
|
1987 | - * eg 4 |
|
1988 | - */ |
|
1989 | - public $STA_ID; |
|
1990 | - |
|
1991 | - /** |
|
1992 | - * @var string $CNT_ISO |
|
1993 | - * eg US |
|
1994 | - */ |
|
1995 | - public $CNT_ISO; |
|
1996 | - |
|
1997 | - /** |
|
1998 | - * @var string $zip |
|
1999 | - * eg 12345 or V1A 2B3 |
|
2000 | - */ |
|
2001 | - public $zip; |
|
2002 | - |
|
2003 | - /** |
|
2004 | - * @var string $email |
|
2005 | - * eg [email protected] |
|
2006 | - */ |
|
2007 | - public $email; |
|
2008 | - |
|
2009 | - |
|
2010 | - /** |
|
2011 | - * @var string $phone |
|
2012 | - * eg. 111-111-1111 |
|
2013 | - */ |
|
2014 | - public $phone; |
|
2015 | - |
|
2016 | - |
|
2017 | - /** |
|
2018 | - * @var string $vat |
|
2019 | - * VAT/Tax Number |
|
2020 | - */ |
|
2021 | - public $vat; |
|
2022 | - |
|
2023 | - /** |
|
2024 | - * @var string $logo_url |
|
2025 | - * eg http://www.somedomain.com/wp-content/uploads/kittehs.jpg |
|
2026 | - */ |
|
2027 | - public $logo_url; |
|
2028 | - |
|
2029 | - |
|
2030 | - /** |
|
2031 | - * The below are all various properties for holding links to organization social network profiles |
|
2032 | - * |
|
2033 | - * @var string |
|
2034 | - */ |
|
2035 | - /** |
|
2036 | - * facebook (facebook.com/profile.name) |
|
2037 | - * |
|
2038 | - * @var string |
|
2039 | - */ |
|
2040 | - public $facebook; |
|
2041 | - |
|
2042 | - |
|
2043 | - /** |
|
2044 | - * twitter (twitter.com/twitter_handle) |
|
2045 | - * |
|
2046 | - * @var string |
|
2047 | - */ |
|
2048 | - public $twitter; |
|
2049 | - |
|
2050 | - |
|
2051 | - /** |
|
2052 | - * linkedin (linkedin.com/in/profile_name) |
|
2053 | - * |
|
2054 | - * @var string |
|
2055 | - */ |
|
2056 | - public $linkedin; |
|
2057 | - |
|
2058 | - |
|
2059 | - /** |
|
2060 | - * pinterest (www.pinterest.com/profile_name) |
|
2061 | - * |
|
2062 | - * @var string |
|
2063 | - */ |
|
2064 | - public $pinterest; |
|
2065 | - |
|
2066 | - |
|
2067 | - /** |
|
2068 | - * google+ (google.com/+profileName) |
|
2069 | - * |
|
2070 | - * @var string |
|
2071 | - */ |
|
2072 | - public $google; |
|
2073 | - |
|
2074 | - |
|
2075 | - /** |
|
2076 | - * instagram (instagram.com/handle) |
|
2077 | - * |
|
2078 | - * @var string |
|
2079 | - */ |
|
2080 | - public $instagram; |
|
2081 | - |
|
2082 | - |
|
2083 | - |
|
2084 | - /** |
|
2085 | - * class constructor |
|
2086 | - * |
|
2087 | - * @access public |
|
2088 | - */ |
|
2089 | - public function __construct() |
|
2090 | - { |
|
2091 | - // set default organization settings |
|
2092 | - $this->name = get_bloginfo('name'); |
|
2093 | - $this->address_1 = '123 Onna Road'; |
|
2094 | - $this->address_2 = 'PO Box 123'; |
|
2095 | - $this->city = 'Inna City'; |
|
2096 | - $this->STA_ID = 4; |
|
2097 | - $this->CNT_ISO = 'US'; |
|
2098 | - $this->zip = '12345'; |
|
2099 | - $this->email = get_bloginfo('admin_email'); |
|
2100 | - $this->phone = ''; |
|
2101 | - $this->vat = '123456789'; |
|
2102 | - $this->logo_url = ''; |
|
2103 | - $this->facebook = ''; |
|
2104 | - $this->twitter = ''; |
|
2105 | - $this->linkedin = ''; |
|
2106 | - $this->pinterest = ''; |
|
2107 | - $this->google = ''; |
|
2108 | - $this->instagram = ''; |
|
2109 | - } |
|
2110 | - |
|
2111 | -} |
|
2112 | - |
|
2113 | - |
|
2114 | - |
|
2115 | -/** |
|
2116 | - * Class for defining what's in the EE_Config relating to currency |
|
2117 | - */ |
|
2118 | -class EE_Currency_Config extends EE_Config_Base |
|
2119 | -{ |
|
2120 | - |
|
2121 | - /** |
|
2122 | - * @var string $code |
|
2123 | - * eg 'US' |
|
2124 | - */ |
|
2125 | - public $code; |
|
2126 | - |
|
2127 | - /** |
|
2128 | - * @var string $name |
|
2129 | - * eg 'Dollar' |
|
2130 | - */ |
|
2131 | - public $name; |
|
2132 | - |
|
2133 | - /** |
|
2134 | - * plural name |
|
2135 | - * |
|
2136 | - * @var string $plural |
|
2137 | - * eg 'Dollars' |
|
2138 | - */ |
|
2139 | - public $plural; |
|
2140 | - |
|
2141 | - /** |
|
2142 | - * currency sign |
|
2143 | - * |
|
2144 | - * @var string $sign |
|
2145 | - * eg '$' |
|
2146 | - */ |
|
2147 | - public $sign; |
|
2148 | - |
|
2149 | - /** |
|
2150 | - * Whether the currency sign should come before the number or not |
|
2151 | - * |
|
2152 | - * @var boolean $sign_b4 |
|
2153 | - */ |
|
2154 | - public $sign_b4; |
|
2155 | - |
|
2156 | - /** |
|
2157 | - * How many digits should come after the decimal place |
|
2158 | - * |
|
2159 | - * @var int $dec_plc |
|
2160 | - */ |
|
2161 | - public $dec_plc; |
|
2162 | - |
|
2163 | - /** |
|
2164 | - * Symbol to use for decimal mark |
|
2165 | - * |
|
2166 | - * @var string $dec_mrk |
|
2167 | - * eg '.' |
|
2168 | - */ |
|
2169 | - public $dec_mrk; |
|
2170 | - |
|
2171 | - /** |
|
2172 | - * Symbol to use for thousands |
|
2173 | - * |
|
2174 | - * @var string $thsnds |
|
2175 | - * eg ',' |
|
2176 | - */ |
|
2177 | - public $thsnds; |
|
2178 | - |
|
2179 | - |
|
2180 | - |
|
2181 | - /** |
|
2182 | - * class constructor |
|
2183 | - * |
|
2184 | - * @access public |
|
2185 | - * @param string $CNT_ISO |
|
2186 | - * @throws \EE_Error |
|
2187 | - */ |
|
2188 | - public function __construct($CNT_ISO = '') |
|
2189 | - { |
|
2190 | - /** @var \EventEspresso\core\services\database\TableAnalysis $table_analysis */ |
|
2191 | - $table_analysis = EE_Registry::instance()->create('TableAnalysis', array(), true); |
|
2192 | - // get country code from organization settings or use default |
|
2193 | - $ORG_CNT = isset(EE_Registry::instance()->CFG->organization) |
|
2194 | - && EE_Registry::instance()->CFG->organization instanceof EE_Organization_Config |
|
2195 | - ? EE_Registry::instance()->CFG->organization->CNT_ISO |
|
2196 | - : ''; |
|
2197 | - // but override if requested |
|
2198 | - $CNT_ISO = ! empty($CNT_ISO) ? $CNT_ISO : $ORG_CNT; |
|
2199 | - // so if that all went well, and we are not in M-Mode (cuz you can't query the db in M-Mode) and double-check the countries table exists |
|
2200 | - if ( |
|
2201 | - ! empty($CNT_ISO) |
|
2202 | - && EE_Maintenance_Mode::instance()->models_can_query() |
|
2203 | - && $table_analysis->tableExists(EE_Registry::instance()->load_model('Country')->table()) |
|
2204 | - ) { |
|
2205 | - // retrieve the country settings from the db, just in case they have been customized |
|
2206 | - $country = EE_Registry::instance()->load_model('Country')->get_one_by_ID($CNT_ISO); |
|
2207 | - if ($country instanceof EE_Country) { |
|
2208 | - $this->code = $country->currency_code(); // currency code: USD, CAD, EUR |
|
2209 | - $this->name = $country->currency_name_single(); // Dollar |
|
2210 | - $this->plural = $country->currency_name_plural(); // Dollars |
|
2211 | - $this->sign = $country->currency_sign(); // currency sign: $ |
|
2212 | - $this->sign_b4 = $country->currency_sign_before(); // currency sign before or after: $TRUE or FALSE$ |
|
2213 | - $this->dec_plc = $country->currency_decimal_places(); // decimal places: 2 = 0.00 3 = 0.000 |
|
2214 | - $this->dec_mrk = $country->currency_decimal_mark(); // decimal mark: (comma) ',' = 0,01 or (decimal) '.' = 0.01 |
|
2215 | - $this->thsnds = $country->currency_thousands_separator(); // thousands separator: (comma) ',' = 1,000 or (decimal) '.' = 1.000 |
|
2216 | - } |
|
2217 | - } |
|
2218 | - // fallback to hardcoded defaults, in case the above failed |
|
2219 | - if (empty($this->code)) { |
|
2220 | - // set default currency settings |
|
2221 | - $this->code = 'USD'; // currency code: USD, CAD, EUR |
|
2222 | - $this->name = __('Dollar', 'event_espresso'); // Dollar |
|
2223 | - $this->plural = __('Dollars', 'event_espresso'); // Dollars |
|
2224 | - $this->sign = '$'; // currency sign: $ |
|
2225 | - $this->sign_b4 = true; // currency sign before or after: $TRUE or FALSE$ |
|
2226 | - $this->dec_plc = 2; // decimal places: 2 = 0.00 3 = 0.000 |
|
2227 | - $this->dec_mrk = '.'; // decimal mark: (comma) ',' = 0,01 or (decimal) '.' = 0.01 |
|
2228 | - $this->thsnds = ','; // thousands separator: (comma) ',' = 1,000 or (decimal) '.' = 1.000 |
|
2229 | - } |
|
2230 | - } |
|
2231 | -} |
|
2232 | - |
|
2233 | - |
|
2234 | - |
|
2235 | -/** |
|
2236 | - * Class for defining what's in the EE_Config relating to registration settings |
|
2237 | - */ |
|
2238 | -class EE_Registration_Config extends EE_Config_Base |
|
2239 | -{ |
|
2240 | - |
|
2241 | - /** |
|
2242 | - * Default registration status |
|
2243 | - * |
|
2244 | - * @var string $default_STS_ID |
|
2245 | - * eg 'RPP' |
|
2246 | - */ |
|
2247 | - public $default_STS_ID; |
|
2248 | - |
|
2249 | - |
|
2250 | - /** |
|
2251 | - * For new events, this will be the default value for the maximum number of tickets (equivalent to maximum number of |
|
2252 | - * registrations) |
|
2253 | - * @var int |
|
2254 | - */ |
|
2255 | - public $default_maximum_number_of_tickets; |
|
2256 | - |
|
2257 | - |
|
2258 | - /** |
|
2259 | - * level of validation to apply to email addresses |
|
2260 | - * |
|
2261 | - * @var string $email_validation_level |
|
2262 | - * options: 'basic', 'wp_default', 'i18n', 'i18n_dns' |
|
2263 | - */ |
|
2264 | - public $email_validation_level; |
|
2265 | - |
|
2266 | - /** |
|
2267 | - * whether or not to show alternate payment options during the reg process if payment status is pending |
|
2268 | - * |
|
2269 | - * @var boolean $show_pending_payment_options |
|
2270 | - */ |
|
2271 | - public $show_pending_payment_options; |
|
2272 | - |
|
2273 | - /** |
|
2274 | - * Whether to skip the registration confirmation page |
|
2275 | - * |
|
2276 | - * @var boolean $skip_reg_confirmation |
|
2277 | - */ |
|
2278 | - public $skip_reg_confirmation; |
|
2279 | - |
|
2280 | - /** |
|
2281 | - * an array of SPCO reg steps where: |
|
2282 | - * the keys denotes the reg step order |
|
2283 | - * each element consists of an array with the following elements: |
|
2284 | - * "file_path" => the file path to the EE_SPCO_Reg_Step class |
|
2285 | - * "class_name" => the specific EE_SPCO_Reg_Step child class name |
|
2286 | - * "slug" => the URL param used to trigger the reg step |
|
2287 | - * |
|
2288 | - * @var array $reg_steps |
|
2289 | - */ |
|
2290 | - public $reg_steps; |
|
2291 | - |
|
2292 | - /** |
|
2293 | - * Whether registration confirmation should be the last page of SPCO |
|
2294 | - * |
|
2295 | - * @var boolean $reg_confirmation_last |
|
2296 | - */ |
|
2297 | - public $reg_confirmation_last; |
|
2298 | - |
|
2299 | - /** |
|
2300 | - * Whether or not to enable the EE Bot Trap |
|
2301 | - * |
|
2302 | - * @var boolean $use_bot_trap |
|
2303 | - */ |
|
2304 | - public $use_bot_trap; |
|
2305 | - |
|
2306 | - /** |
|
2307 | - * Whether or not to encrypt some data sent by the EE Bot Trap |
|
2308 | - * |
|
2309 | - * @var boolean $use_encryption |
|
2310 | - */ |
|
2311 | - public $use_encryption; |
|
1545 | +} |
|
2312 | 1546 | |
2313 | - /** |
|
2314 | - * Whether or not to use ReCaptcha |
|
2315 | - * |
|
2316 | - * @var boolean $use_captcha |
|
2317 | - */ |
|
2318 | - public $use_captcha; |
|
2319 | 1547 | |
2320 | - /** |
|
2321 | - * ReCaptcha Theme |
|
2322 | - * |
|
2323 | - * @var string $recaptcha_theme |
|
2324 | - * options: 'dark ', 'light' |
|
2325 | - */ |
|
2326 | - public $recaptcha_theme; |
|
2327 | 1548 | |
2328 | - /** |
|
2329 | - * ReCaptcha Type |
|
2330 | - * |
|
2331 | - * @var string $recaptcha_type |
|
2332 | - * options: 'audio', 'image' |
|
2333 | - */ |
|
2334 | - public $recaptcha_type; |
|
1549 | +/** |
|
1550 | + * Base class used for config classes. These classes should generally not have |
|
1551 | + * magic functions in use, except we'll allow them to magically set and get stuff... |
|
1552 | + * basically, they should just be well-defined stdClasses |
|
1553 | + */ |
|
1554 | +class EE_Config_Base |
|
1555 | +{ |
|
2335 | 1556 | |
2336 | - /** |
|
2337 | - * ReCaptcha language |
|
2338 | - * |
|
2339 | - * @var string $recaptcha_language |
|
2340 | - * eg 'en' |
|
2341 | - */ |
|
2342 | - public $recaptcha_language; |
|
1557 | + /** |
|
1558 | + * Utility function for escaping the value of a property and returning. |
|
1559 | + * |
|
1560 | + * @param string $property property name (checks to see if exists). |
|
1561 | + * @return mixed if a detected type found return the escaped value, otherwise just the raw value is returned. |
|
1562 | + * @throws \EE_Error |
|
1563 | + */ |
|
1564 | + public function get_pretty($property) |
|
1565 | + { |
|
1566 | + if (! property_exists($this, $property)) { |
|
1567 | + throw new EE_Error( |
|
1568 | + sprintf( |
|
1569 | + __( |
|
1570 | + '%1$s::get_pretty() has been called with the property %2$s which does not exist on the %1$s config class.', |
|
1571 | + 'event_espresso' |
|
1572 | + ), |
|
1573 | + get_class($this), |
|
1574 | + $property |
|
1575 | + ) |
|
1576 | + ); |
|
1577 | + } |
|
1578 | + //just handling escaping of strings for now. |
|
1579 | + if (is_string($this->{$property})) { |
|
1580 | + return stripslashes($this->{$property}); |
|
1581 | + } |
|
1582 | + return $this->{$property}; |
|
1583 | + } |
|
1584 | + |
|
1585 | + |
|
1586 | + |
|
1587 | + public function populate() |
|
1588 | + { |
|
1589 | + //grab defaults via a new instance of this class. |
|
1590 | + $class_name = get_class($this); |
|
1591 | + $defaults = new $class_name; |
|
1592 | + //loop through the properties for this class and see if they are set. If they are NOT, then grab the |
|
1593 | + //default from our $defaults object. |
|
1594 | + foreach (get_object_vars($defaults) as $property => $value) { |
|
1595 | + if ($this->{$property} === null) { |
|
1596 | + $this->{$property} = $value; |
|
1597 | + } |
|
1598 | + } |
|
1599 | + //cleanup |
|
1600 | + unset($defaults); |
|
1601 | + } |
|
1602 | + |
|
1603 | + |
|
1604 | + |
|
1605 | + /** |
|
1606 | + * __isset |
|
1607 | + * |
|
1608 | + * @param $a |
|
1609 | + * @return bool |
|
1610 | + */ |
|
1611 | + public function __isset($a) |
|
1612 | + { |
|
1613 | + return false; |
|
1614 | + } |
|
1615 | + |
|
1616 | + |
|
1617 | + |
|
1618 | + /** |
|
1619 | + * __unset |
|
1620 | + * |
|
1621 | + * @param $a |
|
1622 | + * @return bool |
|
1623 | + */ |
|
1624 | + public function __unset($a) |
|
1625 | + { |
|
1626 | + return false; |
|
1627 | + } |
|
1628 | + |
|
1629 | + |
|
1630 | + |
|
1631 | + /** |
|
1632 | + * __clone |
|
1633 | + */ |
|
1634 | + public function __clone() |
|
1635 | + { |
|
1636 | + } |
|
1637 | + |
|
1638 | + |
|
1639 | + |
|
1640 | + /** |
|
1641 | + * __wakeup |
|
1642 | + */ |
|
1643 | + public function __wakeup() |
|
1644 | + { |
|
1645 | + } |
|
1646 | + |
|
1647 | + |
|
1648 | + |
|
1649 | + /** |
|
1650 | + * __destruct |
|
1651 | + */ |
|
1652 | + public function __destruct() |
|
1653 | + { |
|
1654 | + } |
|
1655 | +} |
|
2343 | 1656 | |
2344 | - /** |
|
2345 | - * ReCaptcha public key |
|
2346 | - * |
|
2347 | - * @var string $recaptcha_publickey |
|
2348 | - */ |
|
2349 | - public $recaptcha_publickey; |
|
2350 | 1657 | |
2351 | - /** |
|
2352 | - * ReCaptcha private key |
|
2353 | - * |
|
2354 | - * @var string $recaptcha_privatekey |
|
2355 | - */ |
|
2356 | - public $recaptcha_privatekey; |
|
2357 | 1658 | |
2358 | - /** |
|
2359 | - * ReCaptcha width |
|
2360 | - * |
|
2361 | - * @var int $recaptcha_width |
|
2362 | - * @deprecated |
|
2363 | - */ |
|
2364 | - public $recaptcha_width; |
|
1659 | +/** |
|
1660 | + * Class for defining what's in the EE_Config relating to registration settings |
|
1661 | + */ |
|
1662 | +class EE_Core_Config extends EE_Config_Base |
|
1663 | +{ |
|
2365 | 1664 | |
2366 | - /** |
|
2367 | - * Whether or not invalid attempts to directly access the registration checkout page should be tracked. |
|
2368 | - * |
|
2369 | - * @var boolean $track_invalid_checkout_access |
|
2370 | - */ |
|
2371 | - protected $track_invalid_checkout_access = true; |
|
1665 | + public $current_blog_id; |
|
1666 | + |
|
1667 | + public $ee_ueip_optin; |
|
1668 | + |
|
1669 | + public $ee_ueip_has_notified; |
|
1670 | + |
|
1671 | + /** |
|
1672 | + * Not to be confused with the 4 critical page variables (See |
|
1673 | + * get_critical_pages_array()), this is just an array of wp posts that have EE |
|
1674 | + * shortcodes in them. Keys are slugs, values are arrays with only 1 element: where the key is the shortcode |
|
1675 | + * in the page, and the value is the page's ID. The key 'posts' is basically a duplicate of this same array. |
|
1676 | + * |
|
1677 | + * @var array |
|
1678 | + */ |
|
1679 | + public $post_shortcodes; |
|
1680 | + |
|
1681 | + public $module_route_map; |
|
1682 | + |
|
1683 | + public $module_forward_map; |
|
1684 | + |
|
1685 | + public $module_view_map; |
|
1686 | + |
|
1687 | + /** |
|
1688 | + * The next 4 vars are the IDs of critical EE pages. |
|
1689 | + * |
|
1690 | + * @var int |
|
1691 | + */ |
|
1692 | + public $reg_page_id; |
|
1693 | + |
|
1694 | + public $txn_page_id; |
|
1695 | + |
|
1696 | + public $thank_you_page_id; |
|
1697 | + |
|
1698 | + public $cancel_page_id; |
|
1699 | + |
|
1700 | + /** |
|
1701 | + * The next 4 vars are the URLs of critical EE pages. |
|
1702 | + * |
|
1703 | + * @var int |
|
1704 | + */ |
|
1705 | + public $reg_page_url; |
|
1706 | + |
|
1707 | + public $txn_page_url; |
|
1708 | + |
|
1709 | + public $thank_you_page_url; |
|
1710 | + |
|
1711 | + public $cancel_page_url; |
|
1712 | + |
|
1713 | + /** |
|
1714 | + * The next vars relate to the custom slugs for EE CPT routes |
|
1715 | + */ |
|
1716 | + public $event_cpt_slug; |
|
1717 | + |
|
1718 | + |
|
1719 | + /** |
|
1720 | + * This caches the _ee_ueip_option in case this config is reset in the same |
|
1721 | + * request across blog switches in a multisite context. |
|
1722 | + * Avoids extra queries to the db for this option. |
|
1723 | + * |
|
1724 | + * @var bool |
|
1725 | + */ |
|
1726 | + public static $ee_ueip_option; |
|
1727 | + |
|
1728 | + |
|
1729 | + |
|
1730 | + /** |
|
1731 | + * class constructor |
|
1732 | + * |
|
1733 | + * @access public |
|
1734 | + */ |
|
1735 | + public function __construct() |
|
1736 | + { |
|
1737 | + // set default organization settings |
|
1738 | + $this->current_blog_id = get_current_blog_id(); |
|
1739 | + $this->current_blog_id = $this->current_blog_id === null ? 1 : $this->current_blog_id; |
|
1740 | + $this->ee_ueip_optin = $this->_get_main_ee_ueip_optin(); |
|
1741 | + $this->ee_ueip_has_notified = is_main_site() ? get_option('ee_ueip_has_notified', false) : true; |
|
1742 | + $this->post_shortcodes = array(); |
|
1743 | + $this->module_route_map = array(); |
|
1744 | + $this->module_forward_map = array(); |
|
1745 | + $this->module_view_map = array(); |
|
1746 | + // critical EE page IDs |
|
1747 | + $this->reg_page_id = 0; |
|
1748 | + $this->txn_page_id = 0; |
|
1749 | + $this->thank_you_page_id = 0; |
|
1750 | + $this->cancel_page_id = 0; |
|
1751 | + // critical EE page URLs |
|
1752 | + $this->reg_page_url = ''; |
|
1753 | + $this->txn_page_url = ''; |
|
1754 | + $this->thank_you_page_url = ''; |
|
1755 | + $this->cancel_page_url = ''; |
|
1756 | + //cpt slugs |
|
1757 | + $this->event_cpt_slug = __('events', 'event_espresso'); |
|
1758 | + //ueip constant check |
|
1759 | + if (defined('EE_DISABLE_UXIP') && EE_DISABLE_UXIP) { |
|
1760 | + $this->ee_ueip_optin = false; |
|
1761 | + $this->ee_ueip_has_notified = true; |
|
1762 | + } |
|
1763 | + } |
|
1764 | + |
|
1765 | + |
|
1766 | + |
|
1767 | + /** |
|
1768 | + * @return array |
|
1769 | + */ |
|
1770 | + public function get_critical_pages_array() |
|
1771 | + { |
|
1772 | + return array( |
|
1773 | + $this->reg_page_id, |
|
1774 | + $this->txn_page_id, |
|
1775 | + $this->thank_you_page_id, |
|
1776 | + $this->cancel_page_id, |
|
1777 | + ); |
|
1778 | + } |
|
1779 | + |
|
1780 | + |
|
1781 | + |
|
1782 | + /** |
|
1783 | + * @return array |
|
1784 | + */ |
|
1785 | + public function get_critical_pages_shortcodes_array() |
|
1786 | + { |
|
1787 | + return array( |
|
1788 | + $this->reg_page_id => 'ESPRESSO_CHECKOUT', |
|
1789 | + $this->txn_page_id => 'ESPRESSO_TXN_PAGE', |
|
1790 | + $this->thank_you_page_id => 'ESPRESSO_THANK_YOU', |
|
1791 | + $this->cancel_page_id => 'ESPRESSO_CANCELLED', |
|
1792 | + ); |
|
1793 | + } |
|
1794 | + |
|
1795 | + |
|
1796 | + |
|
1797 | + /** |
|
1798 | + * gets/returns URL for EE reg_page |
|
1799 | + * |
|
1800 | + * @access public |
|
1801 | + * @return string |
|
1802 | + */ |
|
1803 | + public function reg_page_url() |
|
1804 | + { |
|
1805 | + if (! $this->reg_page_url) { |
|
1806 | + $this->reg_page_url = add_query_arg( |
|
1807 | + array('uts' => time()), |
|
1808 | + get_permalink($this->reg_page_id) |
|
1809 | + ) . '#checkout'; |
|
1810 | + } |
|
1811 | + return $this->reg_page_url; |
|
1812 | + } |
|
1813 | + |
|
1814 | + |
|
1815 | + |
|
1816 | + /** |
|
1817 | + * gets/returns URL for EE txn_page |
|
1818 | + * |
|
1819 | + * @param array $query_args like what gets passed to |
|
1820 | + * add_query_arg() as the first argument |
|
1821 | + * @access public |
|
1822 | + * @return string |
|
1823 | + */ |
|
1824 | + public function txn_page_url($query_args = array()) |
|
1825 | + { |
|
1826 | + if (! $this->txn_page_url) { |
|
1827 | + $this->txn_page_url = get_permalink($this->txn_page_id); |
|
1828 | + } |
|
1829 | + if ($query_args) { |
|
1830 | + return add_query_arg($query_args, $this->txn_page_url); |
|
1831 | + } else { |
|
1832 | + return $this->txn_page_url; |
|
1833 | + } |
|
1834 | + } |
|
1835 | + |
|
1836 | + |
|
1837 | + |
|
1838 | + /** |
|
1839 | + * gets/returns URL for EE thank_you_page |
|
1840 | + * |
|
1841 | + * @param array $query_args like what gets passed to |
|
1842 | + * add_query_arg() as the first argument |
|
1843 | + * @access public |
|
1844 | + * @return string |
|
1845 | + */ |
|
1846 | + public function thank_you_page_url($query_args = array()) |
|
1847 | + { |
|
1848 | + if (! $this->thank_you_page_url) { |
|
1849 | + $this->thank_you_page_url = get_permalink($this->thank_you_page_id); |
|
1850 | + } |
|
1851 | + if ($query_args) { |
|
1852 | + return add_query_arg($query_args, $this->thank_you_page_url); |
|
1853 | + } else { |
|
1854 | + return $this->thank_you_page_url; |
|
1855 | + } |
|
1856 | + } |
|
1857 | + |
|
1858 | + |
|
1859 | + |
|
1860 | + /** |
|
1861 | + * gets/returns URL for EE cancel_page |
|
1862 | + * |
|
1863 | + * @access public |
|
1864 | + * @return string |
|
1865 | + */ |
|
1866 | + public function cancel_page_url() |
|
1867 | + { |
|
1868 | + if (! $this->cancel_page_url) { |
|
1869 | + $this->cancel_page_url = get_permalink($this->cancel_page_id); |
|
1870 | + } |
|
1871 | + return $this->cancel_page_url; |
|
1872 | + } |
|
1873 | + |
|
1874 | + |
|
1875 | + |
|
1876 | + /** |
|
1877 | + * Resets all critical page urls to their original state. Used primarily by the __sleep() magic method currently. |
|
1878 | + * |
|
1879 | + * @since 4.7.5 |
|
1880 | + */ |
|
1881 | + protected function _reset_urls() |
|
1882 | + { |
|
1883 | + $this->reg_page_url = ''; |
|
1884 | + $this->txn_page_url = ''; |
|
1885 | + $this->cancel_page_url = ''; |
|
1886 | + $this->thank_you_page_url = ''; |
|
1887 | + } |
|
1888 | + |
|
1889 | + |
|
1890 | + |
|
1891 | + /** |
|
1892 | + * Used to return what the optin value is set for the EE User Experience Program. |
|
1893 | + * This accounts for multisite and this value being requested for a subsite. In multisite, the value is set |
|
1894 | + * on the main site only. |
|
1895 | + * |
|
1896 | + * @return mixed|void |
|
1897 | + */ |
|
1898 | + protected function _get_main_ee_ueip_optin() |
|
1899 | + { |
|
1900 | + //if this is the main site then we can just bypass our direct query. |
|
1901 | + if (is_main_site()) { |
|
1902 | + return get_option('ee_ueip_optin', false); |
|
1903 | + } |
|
1904 | + //is this already cached for this request? If so use it. |
|
1905 | + if ( ! empty(EE_Core_Config::$ee_ueip_option)) { |
|
1906 | + return EE_Core_Config::$ee_ueip_option; |
|
1907 | + } |
|
1908 | + global $wpdb; |
|
1909 | + $current_network_main_site = is_multisite() ? get_current_site() : null; |
|
1910 | + $current_main_site_id = ! empty($current_network_main_site) ? $current_network_main_site->blog_id : 1; |
|
1911 | + $option = 'ee_ueip_optin'; |
|
1912 | + //set correct table for query |
|
1913 | + $table_name = $wpdb->get_blog_prefix($current_main_site_id) . 'options'; |
|
1914 | + //rather than getting blog option for the $current_main_site_id, we do a direct $wpdb query because |
|
1915 | + //get_blog_option() does a switch_to_blog an that could cause infinite recursion because EE_Core_Config might be |
|
1916 | + //re-constructed on the blog switch. Note, we are still executing any core wp filters on this option retrieval. |
|
1917 | + //this bit of code is basically a direct copy of get_option without any caching because we are NOT switched to the blog |
|
1918 | + //for the purpose of caching. |
|
1919 | + $pre = apply_filters('pre_option_' . $option, false, $option); |
|
1920 | + if (false !== $pre) { |
|
1921 | + EE_Core_Config::$ee_ueip_option = $pre; |
|
1922 | + return EE_Core_Config::$ee_ueip_option; |
|
1923 | + } |
|
1924 | + $row = $wpdb->get_row($wpdb->prepare("SELECT option_value FROM $table_name WHERE option_name = %s LIMIT 1", |
|
1925 | + $option)); |
|
1926 | + if (is_object($row)) { |
|
1927 | + $value = $row->option_value; |
|
1928 | + } else { //option does not exist so use default. |
|
1929 | + return apply_filters('default_option_' . $option, false, $option); |
|
1930 | + } |
|
1931 | + EE_Core_Config::$ee_ueip_option = apply_filters('option_' . $option, maybe_unserialize($value), $option); |
|
1932 | + return EE_Core_Config::$ee_ueip_option; |
|
1933 | + } |
|
1934 | + |
|
1935 | + |
|
1936 | + |
|
1937 | + /** |
|
1938 | + * Currently used to ensure critical page urls have initial values saved to the db instead of any current set values |
|
1939 | + * on the object. |
|
1940 | + * |
|
1941 | + * @return array |
|
1942 | + */ |
|
1943 | + public function __sleep() |
|
1944 | + { |
|
1945 | + //reset all url properties |
|
1946 | + $this->_reset_urls(); |
|
1947 | + //return what to save to db |
|
1948 | + return array_keys(get_object_vars($this)); |
|
1949 | + } |
|
2372 | 1950 | |
1951 | +} |
|
2373 | 1952 | |
2374 | 1953 | |
2375 | - /** |
|
2376 | - * class constructor |
|
2377 | - * |
|
2378 | - * @access public |
|
2379 | - */ |
|
2380 | - public function __construct() |
|
2381 | - { |
|
2382 | - // set default registration settings |
|
2383 | - $this->default_STS_ID = EEM_Registration::status_id_pending_payment; |
|
2384 | - $this->email_validation_level = 'wp_default'; |
|
2385 | - $this->show_pending_payment_options = true; |
|
2386 | - $this->skip_reg_confirmation = false; |
|
2387 | - $this->reg_steps = array(); |
|
2388 | - $this->reg_confirmation_last = false; |
|
2389 | - $this->use_bot_trap = true; |
|
2390 | - $this->use_encryption = true; |
|
2391 | - $this->use_captcha = false; |
|
2392 | - $this->recaptcha_theme = 'light'; |
|
2393 | - $this->recaptcha_type = 'image'; |
|
2394 | - $this->recaptcha_language = 'en'; |
|
2395 | - $this->recaptcha_publickey = null; |
|
2396 | - $this->recaptcha_privatekey = null; |
|
2397 | - $this->recaptcha_width = 500; |
|
2398 | - $this->default_maximum_number_of_tickets = 10; |
|
2399 | - } |
|
2400 | - |
|
2401 | - |
|
2402 | - |
|
2403 | - /** |
|
2404 | - * This is called by the config loader and hooks are initialized AFTER the config has been populated. |
|
2405 | - * |
|
2406 | - * @since 4.8.8.rc.019 |
|
2407 | - */ |
|
2408 | - public function do_hooks() |
|
2409 | - { |
|
2410 | - add_action('AHEE__EE_Config___load_core_config__end', array($this, 'set_default_reg_status_on_EEM_Event')); |
|
2411 | - add_action('AHEE__EE_Config___load_core_config__end', array($this, 'set_default_max_ticket_on_EEM_Event')); |
|
2412 | - } |
|
2413 | 1954 | |
1955 | +/** |
|
1956 | + * Config class for storing info on the Organization |
|
1957 | + */ |
|
1958 | +class EE_Organization_Config extends EE_Config_Base |
|
1959 | +{ |
|
2414 | 1960 | |
1961 | + /** |
|
1962 | + * @var string $name |
|
1963 | + * eg EE4.1 |
|
1964 | + */ |
|
1965 | + public $name; |
|
1966 | + |
|
1967 | + /** |
|
1968 | + * @var string $address_1 |
|
1969 | + * eg 123 Onna Road |
|
1970 | + */ |
|
1971 | + public $address_1; |
|
1972 | + |
|
1973 | + /** |
|
1974 | + * @var string $address_2 |
|
1975 | + * eg PO Box 123 |
|
1976 | + */ |
|
1977 | + public $address_2; |
|
1978 | + |
|
1979 | + /** |
|
1980 | + * @var string $city |
|
1981 | + * eg Inna City |
|
1982 | + */ |
|
1983 | + public $city; |
|
1984 | + |
|
1985 | + /** |
|
1986 | + * @var int $STA_ID |
|
1987 | + * eg 4 |
|
1988 | + */ |
|
1989 | + public $STA_ID; |
|
1990 | + |
|
1991 | + /** |
|
1992 | + * @var string $CNT_ISO |
|
1993 | + * eg US |
|
1994 | + */ |
|
1995 | + public $CNT_ISO; |
|
1996 | + |
|
1997 | + /** |
|
1998 | + * @var string $zip |
|
1999 | + * eg 12345 or V1A 2B3 |
|
2000 | + */ |
|
2001 | + public $zip; |
|
2002 | + |
|
2003 | + /** |
|
2004 | + * @var string $email |
|
2005 | + * eg [email protected] |
|
2006 | + */ |
|
2007 | + public $email; |
|
2008 | + |
|
2009 | + |
|
2010 | + /** |
|
2011 | + * @var string $phone |
|
2012 | + * eg. 111-111-1111 |
|
2013 | + */ |
|
2014 | + public $phone; |
|
2015 | + |
|
2016 | + |
|
2017 | + /** |
|
2018 | + * @var string $vat |
|
2019 | + * VAT/Tax Number |
|
2020 | + */ |
|
2021 | + public $vat; |
|
2022 | + |
|
2023 | + /** |
|
2024 | + * @var string $logo_url |
|
2025 | + * eg http://www.somedomain.com/wp-content/uploads/kittehs.jpg |
|
2026 | + */ |
|
2027 | + public $logo_url; |
|
2028 | + |
|
2029 | + |
|
2030 | + /** |
|
2031 | + * The below are all various properties for holding links to organization social network profiles |
|
2032 | + * |
|
2033 | + * @var string |
|
2034 | + */ |
|
2035 | + /** |
|
2036 | + * facebook (facebook.com/profile.name) |
|
2037 | + * |
|
2038 | + * @var string |
|
2039 | + */ |
|
2040 | + public $facebook; |
|
2041 | + |
|
2042 | + |
|
2043 | + /** |
|
2044 | + * twitter (twitter.com/twitter_handle) |
|
2045 | + * |
|
2046 | + * @var string |
|
2047 | + */ |
|
2048 | + public $twitter; |
|
2049 | + |
|
2050 | + |
|
2051 | + /** |
|
2052 | + * linkedin (linkedin.com/in/profile_name) |
|
2053 | + * |
|
2054 | + * @var string |
|
2055 | + */ |
|
2056 | + public $linkedin; |
|
2057 | + |
|
2058 | + |
|
2059 | + /** |
|
2060 | + * pinterest (www.pinterest.com/profile_name) |
|
2061 | + * |
|
2062 | + * @var string |
|
2063 | + */ |
|
2064 | + public $pinterest; |
|
2065 | + |
|
2066 | + |
|
2067 | + /** |
|
2068 | + * google+ (google.com/+profileName) |
|
2069 | + * |
|
2070 | + * @var string |
|
2071 | + */ |
|
2072 | + public $google; |
|
2073 | + |
|
2074 | + |
|
2075 | + /** |
|
2076 | + * instagram (instagram.com/handle) |
|
2077 | + * |
|
2078 | + * @var string |
|
2079 | + */ |
|
2080 | + public $instagram; |
|
2081 | + |
|
2082 | + |
|
2083 | + |
|
2084 | + /** |
|
2085 | + * class constructor |
|
2086 | + * |
|
2087 | + * @access public |
|
2088 | + */ |
|
2089 | + public function __construct() |
|
2090 | + { |
|
2091 | + // set default organization settings |
|
2092 | + $this->name = get_bloginfo('name'); |
|
2093 | + $this->address_1 = '123 Onna Road'; |
|
2094 | + $this->address_2 = 'PO Box 123'; |
|
2095 | + $this->city = 'Inna City'; |
|
2096 | + $this->STA_ID = 4; |
|
2097 | + $this->CNT_ISO = 'US'; |
|
2098 | + $this->zip = '12345'; |
|
2099 | + $this->email = get_bloginfo('admin_email'); |
|
2100 | + $this->phone = ''; |
|
2101 | + $this->vat = '123456789'; |
|
2102 | + $this->logo_url = ''; |
|
2103 | + $this->facebook = ''; |
|
2104 | + $this->twitter = ''; |
|
2105 | + $this->linkedin = ''; |
|
2106 | + $this->pinterest = ''; |
|
2107 | + $this->google = ''; |
|
2108 | + $this->instagram = ''; |
|
2109 | + } |
|
2415 | 2110 | |
2416 | - /** |
|
2417 | - * Hooked into `AHEE__EE_Config___load_core_config__end` to ensure the default for the EVT_default_registration_status |
|
2418 | - * field matches the config setting for default_STS_ID. |
|
2419 | - */ |
|
2420 | - public function set_default_reg_status_on_EEM_Event() |
|
2421 | - { |
|
2422 | - EEM_Event::set_default_reg_status($this->default_STS_ID); |
|
2423 | - } |
|
2111 | +} |
|
2424 | 2112 | |
2425 | 2113 | |
2426 | - /** |
|
2427 | - * Hooked into `AHEE__EE_Config___load_core_config__end` to ensure the default for the EVT_additional_limit field |
|
2428 | - * for Events matches the config setting for default_maximum_number_of_tickets |
|
2429 | - */ |
|
2430 | - public function set_default_max_ticket_on_EEM_Event() |
|
2431 | - { |
|
2432 | - EEM_Event::set_default_additional_limit($this->default_maximum_number_of_tickets); |
|
2433 | - } |
|
2434 | 2114 | |
2115 | +/** |
|
2116 | + * Class for defining what's in the EE_Config relating to currency |
|
2117 | + */ |
|
2118 | +class EE_Currency_Config extends EE_Config_Base |
|
2119 | +{ |
|
2435 | 2120 | |
2121 | + /** |
|
2122 | + * @var string $code |
|
2123 | + * eg 'US' |
|
2124 | + */ |
|
2125 | + public $code; |
|
2126 | + |
|
2127 | + /** |
|
2128 | + * @var string $name |
|
2129 | + * eg 'Dollar' |
|
2130 | + */ |
|
2131 | + public $name; |
|
2132 | + |
|
2133 | + /** |
|
2134 | + * plural name |
|
2135 | + * |
|
2136 | + * @var string $plural |
|
2137 | + * eg 'Dollars' |
|
2138 | + */ |
|
2139 | + public $plural; |
|
2140 | + |
|
2141 | + /** |
|
2142 | + * currency sign |
|
2143 | + * |
|
2144 | + * @var string $sign |
|
2145 | + * eg '$' |
|
2146 | + */ |
|
2147 | + public $sign; |
|
2148 | + |
|
2149 | + /** |
|
2150 | + * Whether the currency sign should come before the number or not |
|
2151 | + * |
|
2152 | + * @var boolean $sign_b4 |
|
2153 | + */ |
|
2154 | + public $sign_b4; |
|
2155 | + |
|
2156 | + /** |
|
2157 | + * How many digits should come after the decimal place |
|
2158 | + * |
|
2159 | + * @var int $dec_plc |
|
2160 | + */ |
|
2161 | + public $dec_plc; |
|
2162 | + |
|
2163 | + /** |
|
2164 | + * Symbol to use for decimal mark |
|
2165 | + * |
|
2166 | + * @var string $dec_mrk |
|
2167 | + * eg '.' |
|
2168 | + */ |
|
2169 | + public $dec_mrk; |
|
2170 | + |
|
2171 | + /** |
|
2172 | + * Symbol to use for thousands |
|
2173 | + * |
|
2174 | + * @var string $thsnds |
|
2175 | + * eg ',' |
|
2176 | + */ |
|
2177 | + public $thsnds; |
|
2178 | + |
|
2179 | + |
|
2180 | + |
|
2181 | + /** |
|
2182 | + * class constructor |
|
2183 | + * |
|
2184 | + * @access public |
|
2185 | + * @param string $CNT_ISO |
|
2186 | + * @throws \EE_Error |
|
2187 | + */ |
|
2188 | + public function __construct($CNT_ISO = '') |
|
2189 | + { |
|
2190 | + /** @var \EventEspresso\core\services\database\TableAnalysis $table_analysis */ |
|
2191 | + $table_analysis = EE_Registry::instance()->create('TableAnalysis', array(), true); |
|
2192 | + // get country code from organization settings or use default |
|
2193 | + $ORG_CNT = isset(EE_Registry::instance()->CFG->organization) |
|
2194 | + && EE_Registry::instance()->CFG->organization instanceof EE_Organization_Config |
|
2195 | + ? EE_Registry::instance()->CFG->organization->CNT_ISO |
|
2196 | + : ''; |
|
2197 | + // but override if requested |
|
2198 | + $CNT_ISO = ! empty($CNT_ISO) ? $CNT_ISO : $ORG_CNT; |
|
2199 | + // so if that all went well, and we are not in M-Mode (cuz you can't query the db in M-Mode) and double-check the countries table exists |
|
2200 | + if ( |
|
2201 | + ! empty($CNT_ISO) |
|
2202 | + && EE_Maintenance_Mode::instance()->models_can_query() |
|
2203 | + && $table_analysis->tableExists(EE_Registry::instance()->load_model('Country')->table()) |
|
2204 | + ) { |
|
2205 | + // retrieve the country settings from the db, just in case they have been customized |
|
2206 | + $country = EE_Registry::instance()->load_model('Country')->get_one_by_ID($CNT_ISO); |
|
2207 | + if ($country instanceof EE_Country) { |
|
2208 | + $this->code = $country->currency_code(); // currency code: USD, CAD, EUR |
|
2209 | + $this->name = $country->currency_name_single(); // Dollar |
|
2210 | + $this->plural = $country->currency_name_plural(); // Dollars |
|
2211 | + $this->sign = $country->currency_sign(); // currency sign: $ |
|
2212 | + $this->sign_b4 = $country->currency_sign_before(); // currency sign before or after: $TRUE or FALSE$ |
|
2213 | + $this->dec_plc = $country->currency_decimal_places(); // decimal places: 2 = 0.00 3 = 0.000 |
|
2214 | + $this->dec_mrk = $country->currency_decimal_mark(); // decimal mark: (comma) ',' = 0,01 or (decimal) '.' = 0.01 |
|
2215 | + $this->thsnds = $country->currency_thousands_separator(); // thousands separator: (comma) ',' = 1,000 or (decimal) '.' = 1.000 |
|
2216 | + } |
|
2217 | + } |
|
2218 | + // fallback to hardcoded defaults, in case the above failed |
|
2219 | + if (empty($this->code)) { |
|
2220 | + // set default currency settings |
|
2221 | + $this->code = 'USD'; // currency code: USD, CAD, EUR |
|
2222 | + $this->name = __('Dollar', 'event_espresso'); // Dollar |
|
2223 | + $this->plural = __('Dollars', 'event_espresso'); // Dollars |
|
2224 | + $this->sign = '$'; // currency sign: $ |
|
2225 | + $this->sign_b4 = true; // currency sign before or after: $TRUE or FALSE$ |
|
2226 | + $this->dec_plc = 2; // decimal places: 2 = 0.00 3 = 0.000 |
|
2227 | + $this->dec_mrk = '.'; // decimal mark: (comma) ',' = 0,01 or (decimal) '.' = 0.01 |
|
2228 | + $this->thsnds = ','; // thousands separator: (comma) ',' = 1,000 or (decimal) '.' = 1.000 |
|
2229 | + } |
|
2230 | + } |
|
2231 | +} |
|
2436 | 2232 | |
2437 | - /** |
|
2438 | - * @return boolean |
|
2439 | - */ |
|
2440 | - public function track_invalid_checkout_access() |
|
2441 | - { |
|
2442 | - return $this->track_invalid_checkout_access; |
|
2443 | - } |
|
2444 | 2233 | |
2445 | 2234 | |
2235 | +/** |
|
2236 | + * Class for defining what's in the EE_Config relating to registration settings |
|
2237 | + */ |
|
2238 | +class EE_Registration_Config extends EE_Config_Base |
|
2239 | +{ |
|
2446 | 2240 | |
2447 | - /** |
|
2448 | - * @param boolean $track_invalid_checkout_access |
|
2449 | - */ |
|
2450 | - public function set_track_invalid_checkout_access($track_invalid_checkout_access) |
|
2451 | - { |
|
2452 | - $this->track_invalid_checkout_access = filter_var( |
|
2453 | - $track_invalid_checkout_access, |
|
2454 | - FILTER_VALIDATE_BOOLEAN |
|
2455 | - ); |
|
2456 | - } |
|
2241 | + /** |
|
2242 | + * Default registration status |
|
2243 | + * |
|
2244 | + * @var string $default_STS_ID |
|
2245 | + * eg 'RPP' |
|
2246 | + */ |
|
2247 | + public $default_STS_ID; |
|
2248 | + |
|
2249 | + |
|
2250 | + /** |
|
2251 | + * For new events, this will be the default value for the maximum number of tickets (equivalent to maximum number of |
|
2252 | + * registrations) |
|
2253 | + * @var int |
|
2254 | + */ |
|
2255 | + public $default_maximum_number_of_tickets; |
|
2256 | + |
|
2257 | + |
|
2258 | + /** |
|
2259 | + * level of validation to apply to email addresses |
|
2260 | + * |
|
2261 | + * @var string $email_validation_level |
|
2262 | + * options: 'basic', 'wp_default', 'i18n', 'i18n_dns' |
|
2263 | + */ |
|
2264 | + public $email_validation_level; |
|
2265 | + |
|
2266 | + /** |
|
2267 | + * whether or not to show alternate payment options during the reg process if payment status is pending |
|
2268 | + * |
|
2269 | + * @var boolean $show_pending_payment_options |
|
2270 | + */ |
|
2271 | + public $show_pending_payment_options; |
|
2272 | + |
|
2273 | + /** |
|
2274 | + * Whether to skip the registration confirmation page |
|
2275 | + * |
|
2276 | + * @var boolean $skip_reg_confirmation |
|
2277 | + */ |
|
2278 | + public $skip_reg_confirmation; |
|
2279 | + |
|
2280 | + /** |
|
2281 | + * an array of SPCO reg steps where: |
|
2282 | + * the keys denotes the reg step order |
|
2283 | + * each element consists of an array with the following elements: |
|
2284 | + * "file_path" => the file path to the EE_SPCO_Reg_Step class |
|
2285 | + * "class_name" => the specific EE_SPCO_Reg_Step child class name |
|
2286 | + * "slug" => the URL param used to trigger the reg step |
|
2287 | + * |
|
2288 | + * @var array $reg_steps |
|
2289 | + */ |
|
2290 | + public $reg_steps; |
|
2291 | + |
|
2292 | + /** |
|
2293 | + * Whether registration confirmation should be the last page of SPCO |
|
2294 | + * |
|
2295 | + * @var boolean $reg_confirmation_last |
|
2296 | + */ |
|
2297 | + public $reg_confirmation_last; |
|
2298 | + |
|
2299 | + /** |
|
2300 | + * Whether or not to enable the EE Bot Trap |
|
2301 | + * |
|
2302 | + * @var boolean $use_bot_trap |
|
2303 | + */ |
|
2304 | + public $use_bot_trap; |
|
2305 | + |
|
2306 | + /** |
|
2307 | + * Whether or not to encrypt some data sent by the EE Bot Trap |
|
2308 | + * |
|
2309 | + * @var boolean $use_encryption |
|
2310 | + */ |
|
2311 | + public $use_encryption; |
|
2312 | + |
|
2313 | + /** |
|
2314 | + * Whether or not to use ReCaptcha |
|
2315 | + * |
|
2316 | + * @var boolean $use_captcha |
|
2317 | + */ |
|
2318 | + public $use_captcha; |
|
2319 | + |
|
2320 | + /** |
|
2321 | + * ReCaptcha Theme |
|
2322 | + * |
|
2323 | + * @var string $recaptcha_theme |
|
2324 | + * options: 'dark ', 'light' |
|
2325 | + */ |
|
2326 | + public $recaptcha_theme; |
|
2327 | + |
|
2328 | + /** |
|
2329 | + * ReCaptcha Type |
|
2330 | + * |
|
2331 | + * @var string $recaptcha_type |
|
2332 | + * options: 'audio', 'image' |
|
2333 | + */ |
|
2334 | + public $recaptcha_type; |
|
2335 | + |
|
2336 | + /** |
|
2337 | + * ReCaptcha language |
|
2338 | + * |
|
2339 | + * @var string $recaptcha_language |
|
2340 | + * eg 'en' |
|
2341 | + */ |
|
2342 | + public $recaptcha_language; |
|
2343 | + |
|
2344 | + /** |
|
2345 | + * ReCaptcha public key |
|
2346 | + * |
|
2347 | + * @var string $recaptcha_publickey |
|
2348 | + */ |
|
2349 | + public $recaptcha_publickey; |
|
2350 | + |
|
2351 | + /** |
|
2352 | + * ReCaptcha private key |
|
2353 | + * |
|
2354 | + * @var string $recaptcha_privatekey |
|
2355 | + */ |
|
2356 | + public $recaptcha_privatekey; |
|
2357 | + |
|
2358 | + /** |
|
2359 | + * ReCaptcha width |
|
2360 | + * |
|
2361 | + * @var int $recaptcha_width |
|
2362 | + * @deprecated |
|
2363 | + */ |
|
2364 | + public $recaptcha_width; |
|
2365 | + |
|
2366 | + /** |
|
2367 | + * Whether or not invalid attempts to directly access the registration checkout page should be tracked. |
|
2368 | + * |
|
2369 | + * @var boolean $track_invalid_checkout_access |
|
2370 | + */ |
|
2371 | + protected $track_invalid_checkout_access = true; |
|
2372 | + |
|
2373 | + |
|
2374 | + |
|
2375 | + /** |
|
2376 | + * class constructor |
|
2377 | + * |
|
2378 | + * @access public |
|
2379 | + */ |
|
2380 | + public function __construct() |
|
2381 | + { |
|
2382 | + // set default registration settings |
|
2383 | + $this->default_STS_ID = EEM_Registration::status_id_pending_payment; |
|
2384 | + $this->email_validation_level = 'wp_default'; |
|
2385 | + $this->show_pending_payment_options = true; |
|
2386 | + $this->skip_reg_confirmation = false; |
|
2387 | + $this->reg_steps = array(); |
|
2388 | + $this->reg_confirmation_last = false; |
|
2389 | + $this->use_bot_trap = true; |
|
2390 | + $this->use_encryption = true; |
|
2391 | + $this->use_captcha = false; |
|
2392 | + $this->recaptcha_theme = 'light'; |
|
2393 | + $this->recaptcha_type = 'image'; |
|
2394 | + $this->recaptcha_language = 'en'; |
|
2395 | + $this->recaptcha_publickey = null; |
|
2396 | + $this->recaptcha_privatekey = null; |
|
2397 | + $this->recaptcha_width = 500; |
|
2398 | + $this->default_maximum_number_of_tickets = 10; |
|
2399 | + } |
|
2400 | + |
|
2401 | + |
|
2402 | + |
|
2403 | + /** |
|
2404 | + * This is called by the config loader and hooks are initialized AFTER the config has been populated. |
|
2405 | + * |
|
2406 | + * @since 4.8.8.rc.019 |
|
2407 | + */ |
|
2408 | + public function do_hooks() |
|
2409 | + { |
|
2410 | + add_action('AHEE__EE_Config___load_core_config__end', array($this, 'set_default_reg_status_on_EEM_Event')); |
|
2411 | + add_action('AHEE__EE_Config___load_core_config__end', array($this, 'set_default_max_ticket_on_EEM_Event')); |
|
2412 | + } |
|
2413 | + |
|
2414 | + |
|
2415 | + |
|
2416 | + /** |
|
2417 | + * Hooked into `AHEE__EE_Config___load_core_config__end` to ensure the default for the EVT_default_registration_status |
|
2418 | + * field matches the config setting for default_STS_ID. |
|
2419 | + */ |
|
2420 | + public function set_default_reg_status_on_EEM_Event() |
|
2421 | + { |
|
2422 | + EEM_Event::set_default_reg_status($this->default_STS_ID); |
|
2423 | + } |
|
2424 | + |
|
2425 | + |
|
2426 | + /** |
|
2427 | + * Hooked into `AHEE__EE_Config___load_core_config__end` to ensure the default for the EVT_additional_limit field |
|
2428 | + * for Events matches the config setting for default_maximum_number_of_tickets |
|
2429 | + */ |
|
2430 | + public function set_default_max_ticket_on_EEM_Event() |
|
2431 | + { |
|
2432 | + EEM_Event::set_default_additional_limit($this->default_maximum_number_of_tickets); |
|
2433 | + } |
|
2434 | + |
|
2435 | + |
|
2436 | + |
|
2437 | + /** |
|
2438 | + * @return boolean |
|
2439 | + */ |
|
2440 | + public function track_invalid_checkout_access() |
|
2441 | + { |
|
2442 | + return $this->track_invalid_checkout_access; |
|
2443 | + } |
|
2444 | + |
|
2445 | + |
|
2446 | + |
|
2447 | + /** |
|
2448 | + * @param boolean $track_invalid_checkout_access |
|
2449 | + */ |
|
2450 | + public function set_track_invalid_checkout_access($track_invalid_checkout_access) |
|
2451 | + { |
|
2452 | + $this->track_invalid_checkout_access = filter_var( |
|
2453 | + $track_invalid_checkout_access, |
|
2454 | + FILTER_VALIDATE_BOOLEAN |
|
2455 | + ); |
|
2456 | + } |
|
2457 | 2457 | |
2458 | 2458 | |
2459 | 2459 | |
@@ -2467,160 +2467,160 @@ discard block |
||
2467 | 2467 | class EE_Admin_Config extends EE_Config_Base |
2468 | 2468 | { |
2469 | 2469 | |
2470 | - /** |
|
2471 | - * @var boolean $use_personnel_manager |
|
2472 | - */ |
|
2473 | - public $use_personnel_manager; |
|
2474 | - |
|
2475 | - /** |
|
2476 | - * @var boolean $use_dashboard_widget |
|
2477 | - */ |
|
2478 | - public $use_dashboard_widget; |
|
2479 | - |
|
2480 | - /** |
|
2481 | - * @var int $events_in_dashboard |
|
2482 | - */ |
|
2483 | - public $events_in_dashboard; |
|
2484 | - |
|
2485 | - /** |
|
2486 | - * @var boolean $use_event_timezones |
|
2487 | - */ |
|
2488 | - public $use_event_timezones; |
|
2489 | - |
|
2490 | - /** |
|
2491 | - * @var boolean $use_full_logging |
|
2492 | - */ |
|
2493 | - public $use_full_logging; |
|
2494 | - |
|
2495 | - /** |
|
2496 | - * @var string $log_file_name |
|
2497 | - */ |
|
2498 | - public $log_file_name; |
|
2499 | - |
|
2500 | - /** |
|
2501 | - * @var string $debug_file_name |
|
2502 | - */ |
|
2503 | - public $debug_file_name; |
|
2504 | - |
|
2505 | - /** |
|
2506 | - * @var boolean $use_remote_logging |
|
2507 | - */ |
|
2508 | - public $use_remote_logging; |
|
2509 | - |
|
2510 | - /** |
|
2511 | - * @var string $remote_logging_url |
|
2512 | - */ |
|
2513 | - public $remote_logging_url; |
|
2514 | - |
|
2515 | - /** |
|
2516 | - * @var boolean $show_reg_footer |
|
2517 | - */ |
|
2518 | - public $show_reg_footer; |
|
2519 | - |
|
2520 | - /** |
|
2521 | - * @var string $affiliate_id |
|
2522 | - */ |
|
2523 | - public $affiliate_id; |
|
2524 | - |
|
2525 | - /** |
|
2526 | - * help tours on or off (global setting) |
|
2527 | - * |
|
2528 | - * @var boolean |
|
2529 | - */ |
|
2530 | - public $help_tour_activation; |
|
2531 | - |
|
2532 | - /** |
|
2533 | - * adds extra layer of encoding to session data to prevent serialization errors |
|
2534 | - * but is incompatible with some server configuration errors |
|
2535 | - * if you get "500 internal server errors" during registration, try turning this on |
|
2536 | - * if you get PHP fatal errors regarding base 64 methods not defined, then turn this off |
|
2537 | - * |
|
2538 | - * @var boolean $encode_session_data |
|
2539 | - */ |
|
2540 | - private $encode_session_data = false; |
|
2541 | - |
|
2542 | - |
|
2543 | - |
|
2544 | - /** |
|
2545 | - * class constructor |
|
2546 | - * |
|
2547 | - * @access public |
|
2548 | - */ |
|
2549 | - public function __construct() |
|
2550 | - { |
|
2551 | - // set default general admin settings |
|
2552 | - $this->use_personnel_manager = true; |
|
2553 | - $this->use_dashboard_widget = true; |
|
2554 | - $this->events_in_dashboard = 30; |
|
2555 | - $this->use_event_timezones = false; |
|
2556 | - $this->use_full_logging = false; |
|
2557 | - $this->use_remote_logging = false; |
|
2558 | - $this->remote_logging_url = null; |
|
2559 | - $this->show_reg_footer = true; |
|
2560 | - $this->affiliate_id = 'default'; |
|
2561 | - $this->help_tour_activation = true; |
|
2562 | - $this->encode_session_data = false; |
|
2563 | - } |
|
2564 | - |
|
2565 | - |
|
2566 | - |
|
2567 | - /** |
|
2568 | - * @param bool $reset |
|
2569 | - * @return string |
|
2570 | - */ |
|
2571 | - public function log_file_name($reset = false) |
|
2572 | - { |
|
2573 | - if (empty($this->log_file_name) || $reset) { |
|
2574 | - $this->log_file_name = sanitize_key('espresso_log_' . md5(uniqid('', true))) . '.txt'; |
|
2575 | - EE_Config::instance()->update_espresso_config(false, false); |
|
2576 | - } |
|
2577 | - return $this->log_file_name; |
|
2578 | - } |
|
2579 | - |
|
2580 | - |
|
2581 | - |
|
2582 | - /** |
|
2583 | - * @param bool $reset |
|
2584 | - * @return string |
|
2585 | - */ |
|
2586 | - public function debug_file_name($reset = false) |
|
2587 | - { |
|
2588 | - if (empty($this->debug_file_name) || $reset) { |
|
2589 | - $this->debug_file_name = sanitize_key('espresso_debug_' . md5(uniqid('', true))) . '.txt'; |
|
2590 | - EE_Config::instance()->update_espresso_config(false, false); |
|
2591 | - } |
|
2592 | - return $this->debug_file_name; |
|
2593 | - } |
|
2594 | - |
|
2595 | - |
|
2596 | - |
|
2597 | - /** |
|
2598 | - * @return string |
|
2599 | - */ |
|
2600 | - public function affiliate_id() |
|
2601 | - { |
|
2602 | - return ! empty($this->affiliate_id) ? $this->affiliate_id : 'default'; |
|
2603 | - } |
|
2604 | - |
|
2605 | - |
|
2606 | - |
|
2607 | - /** |
|
2608 | - * @return boolean |
|
2609 | - */ |
|
2610 | - public function encode_session_data() |
|
2611 | - { |
|
2612 | - return filter_var($this->encode_session_data, FILTER_VALIDATE_BOOLEAN); |
|
2613 | - } |
|
2614 | - |
|
2615 | - |
|
2616 | - |
|
2617 | - /** |
|
2618 | - * @param boolean $encode_session_data |
|
2619 | - */ |
|
2620 | - public function set_encode_session_data($encode_session_data) |
|
2621 | - { |
|
2622 | - $this->encode_session_data = filter_var($encode_session_data, FILTER_VALIDATE_BOOLEAN); |
|
2623 | - } |
|
2470 | + /** |
|
2471 | + * @var boolean $use_personnel_manager |
|
2472 | + */ |
|
2473 | + public $use_personnel_manager; |
|
2474 | + |
|
2475 | + /** |
|
2476 | + * @var boolean $use_dashboard_widget |
|
2477 | + */ |
|
2478 | + public $use_dashboard_widget; |
|
2479 | + |
|
2480 | + /** |
|
2481 | + * @var int $events_in_dashboard |
|
2482 | + */ |
|
2483 | + public $events_in_dashboard; |
|
2484 | + |
|
2485 | + /** |
|
2486 | + * @var boolean $use_event_timezones |
|
2487 | + */ |
|
2488 | + public $use_event_timezones; |
|
2489 | + |
|
2490 | + /** |
|
2491 | + * @var boolean $use_full_logging |
|
2492 | + */ |
|
2493 | + public $use_full_logging; |
|
2494 | + |
|
2495 | + /** |
|
2496 | + * @var string $log_file_name |
|
2497 | + */ |
|
2498 | + public $log_file_name; |
|
2499 | + |
|
2500 | + /** |
|
2501 | + * @var string $debug_file_name |
|
2502 | + */ |
|
2503 | + public $debug_file_name; |
|
2504 | + |
|
2505 | + /** |
|
2506 | + * @var boolean $use_remote_logging |
|
2507 | + */ |
|
2508 | + public $use_remote_logging; |
|
2509 | + |
|
2510 | + /** |
|
2511 | + * @var string $remote_logging_url |
|
2512 | + */ |
|
2513 | + public $remote_logging_url; |
|
2514 | + |
|
2515 | + /** |
|
2516 | + * @var boolean $show_reg_footer |
|
2517 | + */ |
|
2518 | + public $show_reg_footer; |
|
2519 | + |
|
2520 | + /** |
|
2521 | + * @var string $affiliate_id |
|
2522 | + */ |
|
2523 | + public $affiliate_id; |
|
2524 | + |
|
2525 | + /** |
|
2526 | + * help tours on or off (global setting) |
|
2527 | + * |
|
2528 | + * @var boolean |
|
2529 | + */ |
|
2530 | + public $help_tour_activation; |
|
2531 | + |
|
2532 | + /** |
|
2533 | + * adds extra layer of encoding to session data to prevent serialization errors |
|
2534 | + * but is incompatible with some server configuration errors |
|
2535 | + * if you get "500 internal server errors" during registration, try turning this on |
|
2536 | + * if you get PHP fatal errors regarding base 64 methods not defined, then turn this off |
|
2537 | + * |
|
2538 | + * @var boolean $encode_session_data |
|
2539 | + */ |
|
2540 | + private $encode_session_data = false; |
|
2541 | + |
|
2542 | + |
|
2543 | + |
|
2544 | + /** |
|
2545 | + * class constructor |
|
2546 | + * |
|
2547 | + * @access public |
|
2548 | + */ |
|
2549 | + public function __construct() |
|
2550 | + { |
|
2551 | + // set default general admin settings |
|
2552 | + $this->use_personnel_manager = true; |
|
2553 | + $this->use_dashboard_widget = true; |
|
2554 | + $this->events_in_dashboard = 30; |
|
2555 | + $this->use_event_timezones = false; |
|
2556 | + $this->use_full_logging = false; |
|
2557 | + $this->use_remote_logging = false; |
|
2558 | + $this->remote_logging_url = null; |
|
2559 | + $this->show_reg_footer = true; |
|
2560 | + $this->affiliate_id = 'default'; |
|
2561 | + $this->help_tour_activation = true; |
|
2562 | + $this->encode_session_data = false; |
|
2563 | + } |
|
2564 | + |
|
2565 | + |
|
2566 | + |
|
2567 | + /** |
|
2568 | + * @param bool $reset |
|
2569 | + * @return string |
|
2570 | + */ |
|
2571 | + public function log_file_name($reset = false) |
|
2572 | + { |
|
2573 | + if (empty($this->log_file_name) || $reset) { |
|
2574 | + $this->log_file_name = sanitize_key('espresso_log_' . md5(uniqid('', true))) . '.txt'; |
|
2575 | + EE_Config::instance()->update_espresso_config(false, false); |
|
2576 | + } |
|
2577 | + return $this->log_file_name; |
|
2578 | + } |
|
2579 | + |
|
2580 | + |
|
2581 | + |
|
2582 | + /** |
|
2583 | + * @param bool $reset |
|
2584 | + * @return string |
|
2585 | + */ |
|
2586 | + public function debug_file_name($reset = false) |
|
2587 | + { |
|
2588 | + if (empty($this->debug_file_name) || $reset) { |
|
2589 | + $this->debug_file_name = sanitize_key('espresso_debug_' . md5(uniqid('', true))) . '.txt'; |
|
2590 | + EE_Config::instance()->update_espresso_config(false, false); |
|
2591 | + } |
|
2592 | + return $this->debug_file_name; |
|
2593 | + } |
|
2594 | + |
|
2595 | + |
|
2596 | + |
|
2597 | + /** |
|
2598 | + * @return string |
|
2599 | + */ |
|
2600 | + public function affiliate_id() |
|
2601 | + { |
|
2602 | + return ! empty($this->affiliate_id) ? $this->affiliate_id : 'default'; |
|
2603 | + } |
|
2604 | + |
|
2605 | + |
|
2606 | + |
|
2607 | + /** |
|
2608 | + * @return boolean |
|
2609 | + */ |
|
2610 | + public function encode_session_data() |
|
2611 | + { |
|
2612 | + return filter_var($this->encode_session_data, FILTER_VALIDATE_BOOLEAN); |
|
2613 | + } |
|
2614 | + |
|
2615 | + |
|
2616 | + |
|
2617 | + /** |
|
2618 | + * @param boolean $encode_session_data |
|
2619 | + */ |
|
2620 | + public function set_encode_session_data($encode_session_data) |
|
2621 | + { |
|
2622 | + $this->encode_session_data = filter_var($encode_session_data, FILTER_VALIDATE_BOOLEAN); |
|
2623 | + } |
|
2624 | 2624 | |
2625 | 2625 | |
2626 | 2626 | |
@@ -2634,71 +2634,71 @@ discard block |
||
2634 | 2634 | class EE_Template_Config extends EE_Config_Base |
2635 | 2635 | { |
2636 | 2636 | |
2637 | - /** |
|
2638 | - * @var boolean $enable_default_style |
|
2639 | - */ |
|
2640 | - public $enable_default_style; |
|
2641 | - |
|
2642 | - /** |
|
2643 | - * @var string $custom_style_sheet |
|
2644 | - */ |
|
2645 | - public $custom_style_sheet; |
|
2646 | - |
|
2647 | - /** |
|
2648 | - * @var boolean $display_address_in_regform |
|
2649 | - */ |
|
2650 | - public $display_address_in_regform; |
|
2651 | - |
|
2652 | - /** |
|
2653 | - * @var int $display_description_on_multi_reg_page |
|
2654 | - */ |
|
2655 | - public $display_description_on_multi_reg_page; |
|
2656 | - |
|
2657 | - /** |
|
2658 | - * @var boolean $use_custom_templates |
|
2659 | - */ |
|
2660 | - public $use_custom_templates; |
|
2661 | - |
|
2662 | - /** |
|
2663 | - * @var string $current_espresso_theme |
|
2664 | - */ |
|
2665 | - public $current_espresso_theme; |
|
2666 | - |
|
2667 | - /** |
|
2668 | - * @var EE_Ticket_Selector_Config $EED_Ticket_Selector |
|
2669 | - */ |
|
2670 | - public $EED_Ticket_Selector; |
|
2671 | - |
|
2672 | - /** |
|
2673 | - * @var EE_Event_Single_Config $EED_Event_Single |
|
2674 | - */ |
|
2675 | - public $EED_Event_Single; |
|
2676 | - |
|
2677 | - /** |
|
2678 | - * @var EE_Events_Archive_Config $EED_Events_Archive |
|
2679 | - */ |
|
2680 | - public $EED_Events_Archive; |
|
2681 | - |
|
2682 | - |
|
2683 | - |
|
2684 | - /** |
|
2685 | - * class constructor |
|
2686 | - * |
|
2687 | - * @access public |
|
2688 | - */ |
|
2689 | - public function __construct() |
|
2690 | - { |
|
2691 | - // set default template settings |
|
2692 | - $this->enable_default_style = true; |
|
2693 | - $this->custom_style_sheet = null; |
|
2694 | - $this->display_address_in_regform = true; |
|
2695 | - $this->display_description_on_multi_reg_page = false; |
|
2696 | - $this->use_custom_templates = false; |
|
2697 | - $this->current_espresso_theme = 'Espresso_Arabica_2014'; |
|
2698 | - $this->EED_Event_Single = null; |
|
2699 | - $this->EED_Events_Archive = null; |
|
2700 | - $this->EED_Ticket_Selector = null; |
|
2701 | - } |
|
2637 | + /** |
|
2638 | + * @var boolean $enable_default_style |
|
2639 | + */ |
|
2640 | + public $enable_default_style; |
|
2641 | + |
|
2642 | + /** |
|
2643 | + * @var string $custom_style_sheet |
|
2644 | + */ |
|
2645 | + public $custom_style_sheet; |
|
2646 | + |
|
2647 | + /** |
|
2648 | + * @var boolean $display_address_in_regform |
|
2649 | + */ |
|
2650 | + public $display_address_in_regform; |
|
2651 | + |
|
2652 | + /** |
|
2653 | + * @var int $display_description_on_multi_reg_page |
|
2654 | + */ |
|
2655 | + public $display_description_on_multi_reg_page; |
|
2656 | + |
|
2657 | + /** |
|
2658 | + * @var boolean $use_custom_templates |
|
2659 | + */ |
|
2660 | + public $use_custom_templates; |
|
2661 | + |
|
2662 | + /** |
|
2663 | + * @var string $current_espresso_theme |
|
2664 | + */ |
|
2665 | + public $current_espresso_theme; |
|
2666 | + |
|
2667 | + /** |
|
2668 | + * @var EE_Ticket_Selector_Config $EED_Ticket_Selector |
|
2669 | + */ |
|
2670 | + public $EED_Ticket_Selector; |
|
2671 | + |
|
2672 | + /** |
|
2673 | + * @var EE_Event_Single_Config $EED_Event_Single |
|
2674 | + */ |
|
2675 | + public $EED_Event_Single; |
|
2676 | + |
|
2677 | + /** |
|
2678 | + * @var EE_Events_Archive_Config $EED_Events_Archive |
|
2679 | + */ |
|
2680 | + public $EED_Events_Archive; |
|
2681 | + |
|
2682 | + |
|
2683 | + |
|
2684 | + /** |
|
2685 | + * class constructor |
|
2686 | + * |
|
2687 | + * @access public |
|
2688 | + */ |
|
2689 | + public function __construct() |
|
2690 | + { |
|
2691 | + // set default template settings |
|
2692 | + $this->enable_default_style = true; |
|
2693 | + $this->custom_style_sheet = null; |
|
2694 | + $this->display_address_in_regform = true; |
|
2695 | + $this->display_description_on_multi_reg_page = false; |
|
2696 | + $this->use_custom_templates = false; |
|
2697 | + $this->current_espresso_theme = 'Espresso_Arabica_2014'; |
|
2698 | + $this->EED_Event_Single = null; |
|
2699 | + $this->EED_Events_Archive = null; |
|
2700 | + $this->EED_Ticket_Selector = null; |
|
2701 | + } |
|
2702 | 2702 | |
2703 | 2703 | } |
2704 | 2704 | |
@@ -2710,115 +2710,115 @@ discard block |
||
2710 | 2710 | class EE_Map_Config extends EE_Config_Base |
2711 | 2711 | { |
2712 | 2712 | |
2713 | - /** |
|
2714 | - * @var boolean $use_google_maps |
|
2715 | - */ |
|
2716 | - public $use_google_maps; |
|
2717 | - |
|
2718 | - /** |
|
2719 | - * @var string $api_key |
|
2720 | - */ |
|
2721 | - public $google_map_api_key; |
|
2722 | - |
|
2723 | - /** |
|
2724 | - * @var int $event_details_map_width |
|
2725 | - */ |
|
2726 | - public $event_details_map_width; |
|
2727 | - |
|
2728 | - /** |
|
2729 | - * @var int $event_details_map_height |
|
2730 | - */ |
|
2731 | - public $event_details_map_height; |
|
2732 | - |
|
2733 | - /** |
|
2734 | - * @var int $event_details_map_zoom |
|
2735 | - */ |
|
2736 | - public $event_details_map_zoom; |
|
2737 | - |
|
2738 | - /** |
|
2739 | - * @var boolean $event_details_display_nav |
|
2740 | - */ |
|
2741 | - public $event_details_display_nav; |
|
2742 | - |
|
2743 | - /** |
|
2744 | - * @var boolean $event_details_nav_size |
|
2745 | - */ |
|
2746 | - public $event_details_nav_size; |
|
2747 | - |
|
2748 | - /** |
|
2749 | - * @var string $event_details_control_type |
|
2750 | - */ |
|
2751 | - public $event_details_control_type; |
|
2752 | - |
|
2753 | - /** |
|
2754 | - * @var string $event_details_map_align |
|
2755 | - */ |
|
2756 | - public $event_details_map_align; |
|
2757 | - |
|
2758 | - /** |
|
2759 | - * @var int $event_list_map_width |
|
2760 | - */ |
|
2761 | - public $event_list_map_width; |
|
2762 | - |
|
2763 | - /** |
|
2764 | - * @var int $event_list_map_height |
|
2765 | - */ |
|
2766 | - public $event_list_map_height; |
|
2767 | - |
|
2768 | - /** |
|
2769 | - * @var int $event_list_map_zoom |
|
2770 | - */ |
|
2771 | - public $event_list_map_zoom; |
|
2772 | - |
|
2773 | - /** |
|
2774 | - * @var boolean $event_list_display_nav |
|
2775 | - */ |
|
2776 | - public $event_list_display_nav; |
|
2777 | - |
|
2778 | - /** |
|
2779 | - * @var boolean $event_list_nav_size |
|
2780 | - */ |
|
2781 | - public $event_list_nav_size; |
|
2782 | - |
|
2783 | - /** |
|
2784 | - * @var string $event_list_control_type |
|
2785 | - */ |
|
2786 | - public $event_list_control_type; |
|
2787 | - |
|
2788 | - /** |
|
2789 | - * @var string $event_list_map_align |
|
2790 | - */ |
|
2791 | - public $event_list_map_align; |
|
2792 | - |
|
2793 | - |
|
2794 | - |
|
2795 | - /** |
|
2796 | - * class constructor |
|
2797 | - * |
|
2798 | - * @access public |
|
2799 | - */ |
|
2800 | - public function __construct() |
|
2801 | - { |
|
2802 | - // set default map settings |
|
2803 | - $this->use_google_maps = true; |
|
2804 | - $this->google_map_api_key = ''; |
|
2805 | - // for event details pages (reg page) |
|
2806 | - $this->event_details_map_width = 585; // ee_map_width_single |
|
2807 | - $this->event_details_map_height = 362; // ee_map_height_single |
|
2808 | - $this->event_details_map_zoom = 14; // ee_map_zoom_single |
|
2809 | - $this->event_details_display_nav = true; // ee_map_nav_display_single |
|
2810 | - $this->event_details_nav_size = false; // ee_map_nav_size_single |
|
2811 | - $this->event_details_control_type = 'default'; // ee_map_type_control_single |
|
2812 | - $this->event_details_map_align = 'center'; // ee_map_align_single |
|
2813 | - // for event list pages |
|
2814 | - $this->event_list_map_width = 300; // ee_map_width |
|
2815 | - $this->event_list_map_height = 185; // ee_map_height |
|
2816 | - $this->event_list_map_zoom = 12; // ee_map_zoom |
|
2817 | - $this->event_list_display_nav = false; // ee_map_nav_display |
|
2818 | - $this->event_list_nav_size = true; // ee_map_nav_size |
|
2819 | - $this->event_list_control_type = 'dropdown'; // ee_map_type_control |
|
2820 | - $this->event_list_map_align = 'center'; // ee_map_align |
|
2821 | - } |
|
2713 | + /** |
|
2714 | + * @var boolean $use_google_maps |
|
2715 | + */ |
|
2716 | + public $use_google_maps; |
|
2717 | + |
|
2718 | + /** |
|
2719 | + * @var string $api_key |
|
2720 | + */ |
|
2721 | + public $google_map_api_key; |
|
2722 | + |
|
2723 | + /** |
|
2724 | + * @var int $event_details_map_width |
|
2725 | + */ |
|
2726 | + public $event_details_map_width; |
|
2727 | + |
|
2728 | + /** |
|
2729 | + * @var int $event_details_map_height |
|
2730 | + */ |
|
2731 | + public $event_details_map_height; |
|
2732 | + |
|
2733 | + /** |
|
2734 | + * @var int $event_details_map_zoom |
|
2735 | + */ |
|
2736 | + public $event_details_map_zoom; |
|
2737 | + |
|
2738 | + /** |
|
2739 | + * @var boolean $event_details_display_nav |
|
2740 | + */ |
|
2741 | + public $event_details_display_nav; |
|
2742 | + |
|
2743 | + /** |
|
2744 | + * @var boolean $event_details_nav_size |
|
2745 | + */ |
|
2746 | + public $event_details_nav_size; |
|
2747 | + |
|
2748 | + /** |
|
2749 | + * @var string $event_details_control_type |
|
2750 | + */ |
|
2751 | + public $event_details_control_type; |
|
2752 | + |
|
2753 | + /** |
|
2754 | + * @var string $event_details_map_align |
|
2755 | + */ |
|
2756 | + public $event_details_map_align; |
|
2757 | + |
|
2758 | + /** |
|
2759 | + * @var int $event_list_map_width |
|
2760 | + */ |
|
2761 | + public $event_list_map_width; |
|
2762 | + |
|
2763 | + /** |
|
2764 | + * @var int $event_list_map_height |
|
2765 | + */ |
|
2766 | + public $event_list_map_height; |
|
2767 | + |
|
2768 | + /** |
|
2769 | + * @var int $event_list_map_zoom |
|
2770 | + */ |
|
2771 | + public $event_list_map_zoom; |
|
2772 | + |
|
2773 | + /** |
|
2774 | + * @var boolean $event_list_display_nav |
|
2775 | + */ |
|
2776 | + public $event_list_display_nav; |
|
2777 | + |
|
2778 | + /** |
|
2779 | + * @var boolean $event_list_nav_size |
|
2780 | + */ |
|
2781 | + public $event_list_nav_size; |
|
2782 | + |
|
2783 | + /** |
|
2784 | + * @var string $event_list_control_type |
|
2785 | + */ |
|
2786 | + public $event_list_control_type; |
|
2787 | + |
|
2788 | + /** |
|
2789 | + * @var string $event_list_map_align |
|
2790 | + */ |
|
2791 | + public $event_list_map_align; |
|
2792 | + |
|
2793 | + |
|
2794 | + |
|
2795 | + /** |
|
2796 | + * class constructor |
|
2797 | + * |
|
2798 | + * @access public |
|
2799 | + */ |
|
2800 | + public function __construct() |
|
2801 | + { |
|
2802 | + // set default map settings |
|
2803 | + $this->use_google_maps = true; |
|
2804 | + $this->google_map_api_key = ''; |
|
2805 | + // for event details pages (reg page) |
|
2806 | + $this->event_details_map_width = 585; // ee_map_width_single |
|
2807 | + $this->event_details_map_height = 362; // ee_map_height_single |
|
2808 | + $this->event_details_map_zoom = 14; // ee_map_zoom_single |
|
2809 | + $this->event_details_display_nav = true; // ee_map_nav_display_single |
|
2810 | + $this->event_details_nav_size = false; // ee_map_nav_size_single |
|
2811 | + $this->event_details_control_type = 'default'; // ee_map_type_control_single |
|
2812 | + $this->event_details_map_align = 'center'; // ee_map_align_single |
|
2813 | + // for event list pages |
|
2814 | + $this->event_list_map_width = 300; // ee_map_width |
|
2815 | + $this->event_list_map_height = 185; // ee_map_height |
|
2816 | + $this->event_list_map_zoom = 12; // ee_map_zoom |
|
2817 | + $this->event_list_display_nav = false; // ee_map_nav_display |
|
2818 | + $this->event_list_nav_size = true; // ee_map_nav_size |
|
2819 | + $this->event_list_control_type = 'dropdown'; // ee_map_type_control |
|
2820 | + $this->event_list_map_align = 'center'; // ee_map_align |
|
2821 | + } |
|
2822 | 2822 | |
2823 | 2823 | } |
2824 | 2824 | |
@@ -2830,47 +2830,47 @@ discard block |
||
2830 | 2830 | class EE_Events_Archive_Config extends EE_Config_Base |
2831 | 2831 | { |
2832 | 2832 | |
2833 | - public $display_status_banner; |
|
2833 | + public $display_status_banner; |
|
2834 | 2834 | |
2835 | - public $display_description; |
|
2835 | + public $display_description; |
|
2836 | 2836 | |
2837 | - public $display_ticket_selector; |
|
2837 | + public $display_ticket_selector; |
|
2838 | 2838 | |
2839 | - public $display_datetimes; |
|
2839 | + public $display_datetimes; |
|
2840 | 2840 | |
2841 | - public $display_venue; |
|
2841 | + public $display_venue; |
|
2842 | 2842 | |
2843 | - public $display_expired_events; |
|
2843 | + public $display_expired_events; |
|
2844 | 2844 | |
2845 | - public $use_sortable_display_order; |
|
2845 | + public $use_sortable_display_order; |
|
2846 | 2846 | |
2847 | - public $display_order_tickets; |
|
2847 | + public $display_order_tickets; |
|
2848 | 2848 | |
2849 | - public $display_order_datetimes; |
|
2849 | + public $display_order_datetimes; |
|
2850 | 2850 | |
2851 | - public $display_order_event; |
|
2851 | + public $display_order_event; |
|
2852 | 2852 | |
2853 | - public $display_order_venue; |
|
2853 | + public $display_order_venue; |
|
2854 | 2854 | |
2855 | 2855 | |
2856 | 2856 | |
2857 | - /** |
|
2858 | - * class constructor |
|
2859 | - */ |
|
2860 | - public function __construct() |
|
2861 | - { |
|
2862 | - $this->display_status_banner = 0; |
|
2863 | - $this->display_description = 1; |
|
2864 | - $this->display_ticket_selector = 0; |
|
2865 | - $this->display_datetimes = 1; |
|
2866 | - $this->display_venue = 0; |
|
2867 | - $this->display_expired_events = 0; |
|
2868 | - $this->use_sortable_display_order = false; |
|
2869 | - $this->display_order_tickets = 100; |
|
2870 | - $this->display_order_datetimes = 110; |
|
2871 | - $this->display_order_event = 120; |
|
2872 | - $this->display_order_venue = 130; |
|
2873 | - } |
|
2857 | + /** |
|
2858 | + * class constructor |
|
2859 | + */ |
|
2860 | + public function __construct() |
|
2861 | + { |
|
2862 | + $this->display_status_banner = 0; |
|
2863 | + $this->display_description = 1; |
|
2864 | + $this->display_ticket_selector = 0; |
|
2865 | + $this->display_datetimes = 1; |
|
2866 | + $this->display_venue = 0; |
|
2867 | + $this->display_expired_events = 0; |
|
2868 | + $this->use_sortable_display_order = false; |
|
2869 | + $this->display_order_tickets = 100; |
|
2870 | + $this->display_order_datetimes = 110; |
|
2871 | + $this->display_order_event = 120; |
|
2872 | + $this->display_order_venue = 130; |
|
2873 | + } |
|
2874 | 2874 | } |
2875 | 2875 | |
2876 | 2876 | |
@@ -2881,35 +2881,35 @@ discard block |
||
2881 | 2881 | class EE_Event_Single_Config extends EE_Config_Base |
2882 | 2882 | { |
2883 | 2883 | |
2884 | - public $display_status_banner_single; |
|
2884 | + public $display_status_banner_single; |
|
2885 | 2885 | |
2886 | - public $display_venue; |
|
2886 | + public $display_venue; |
|
2887 | 2887 | |
2888 | - public $use_sortable_display_order; |
|
2888 | + public $use_sortable_display_order; |
|
2889 | 2889 | |
2890 | - public $display_order_tickets; |
|
2890 | + public $display_order_tickets; |
|
2891 | 2891 | |
2892 | - public $display_order_datetimes; |
|
2892 | + public $display_order_datetimes; |
|
2893 | 2893 | |
2894 | - public $display_order_event; |
|
2894 | + public $display_order_event; |
|
2895 | 2895 | |
2896 | - public $display_order_venue; |
|
2896 | + public $display_order_venue; |
|
2897 | 2897 | |
2898 | 2898 | |
2899 | 2899 | |
2900 | - /** |
|
2901 | - * class constructor |
|
2902 | - */ |
|
2903 | - public function __construct() |
|
2904 | - { |
|
2905 | - $this->display_status_banner_single = 0; |
|
2906 | - $this->display_venue = 1; |
|
2907 | - $this->use_sortable_display_order = false; |
|
2908 | - $this->display_order_tickets = 100; |
|
2909 | - $this->display_order_datetimes = 110; |
|
2910 | - $this->display_order_event = 120; |
|
2911 | - $this->display_order_venue = 130; |
|
2912 | - } |
|
2900 | + /** |
|
2901 | + * class constructor |
|
2902 | + */ |
|
2903 | + public function __construct() |
|
2904 | + { |
|
2905 | + $this->display_status_banner_single = 0; |
|
2906 | + $this->display_venue = 1; |
|
2907 | + $this->use_sortable_display_order = false; |
|
2908 | + $this->display_order_tickets = 100; |
|
2909 | + $this->display_order_datetimes = 110; |
|
2910 | + $this->display_order_event = 120; |
|
2911 | + $this->display_order_venue = 130; |
|
2912 | + } |
|
2913 | 2913 | } |
2914 | 2914 | |
2915 | 2915 | |
@@ -2920,152 +2920,152 @@ discard block |
||
2920 | 2920 | class EE_Ticket_Selector_Config extends EE_Config_Base |
2921 | 2921 | { |
2922 | 2922 | |
2923 | - /** |
|
2924 | - * constant to indicate that a datetime selector should NEVER be shown for ticket selectors |
|
2925 | - */ |
|
2926 | - const DO_NOT_SHOW_DATETIME_SELECTOR = 'no_datetime_selector'; |
|
2927 | - |
|
2928 | - /** |
|
2929 | - * constant to indicate that a datetime selector should only be shown for ticket selectors |
|
2930 | - * when the number of datetimes for the event matches the value set for $datetime_selector_threshold |
|
2931 | - */ |
|
2932 | - const MAYBE_SHOW_DATETIME_SELECTOR = 'maybe_datetime_selector'; |
|
2933 | - |
|
2934 | - /** |
|
2935 | - * @var boolean $show_ticket_sale_columns |
|
2936 | - */ |
|
2937 | - public $show_ticket_sale_columns; |
|
2938 | - |
|
2939 | - /** |
|
2940 | - * @var boolean $show_ticket_details |
|
2941 | - */ |
|
2942 | - public $show_ticket_details; |
|
2943 | - |
|
2944 | - /** |
|
2945 | - * @var boolean $show_expired_tickets |
|
2946 | - */ |
|
2947 | - public $show_expired_tickets; |
|
2948 | - |
|
2949 | - /** |
|
2950 | - * whether or not to display a dropdown box populated with event datetimes |
|
2951 | - * that toggles which tickets are displayed for a ticket selector. |
|
2952 | - * uses one of the *_DATETIME_SELECTOR constants defined above |
|
2953 | - * |
|
2954 | - * @var string $show_datetime_selector |
|
2955 | - */ |
|
2956 | - private $show_datetime_selector = 'no_datetime_selector'; |
|
2957 | - |
|
2958 | - /** |
|
2959 | - * the number of datetimes an event has to have before conditionally displaying a datetime selector |
|
2960 | - * |
|
2961 | - * @var int $datetime_selector_threshold |
|
2962 | - */ |
|
2963 | - private $datetime_selector_threshold = 3; |
|
2964 | - |
|
2965 | - |
|
2966 | - |
|
2967 | - /** |
|
2968 | - * class constructor |
|
2969 | - */ |
|
2970 | - public function __construct() |
|
2971 | - { |
|
2972 | - $this->show_ticket_sale_columns = true; |
|
2973 | - $this->show_ticket_details = true; |
|
2974 | - $this->show_expired_tickets = true; |
|
2975 | - $this->show_datetime_selector = \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR; |
|
2976 | - $this->datetime_selector_threshold = 3; |
|
2977 | - } |
|
2978 | - |
|
2979 | - |
|
2980 | - |
|
2981 | - /** |
|
2982 | - * returns true if a datetime selector should be displayed |
|
2983 | - * |
|
2984 | - * @param array $datetimes |
|
2985 | - * @return bool |
|
2986 | - */ |
|
2987 | - public function showDatetimeSelector(array $datetimes) |
|
2988 | - { |
|
2989 | - // if the settings are NOT: don't show OR below threshold, THEN active = true |
|
2990 | - return ! ( |
|
2991 | - $this->getShowDatetimeSelector() === \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR |
|
2992 | - || ( |
|
2993 | - $this->getShowDatetimeSelector() === \EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR |
|
2994 | - && count($datetimes) < $this->getDatetimeSelectorThreshold() |
|
2995 | - ) |
|
2996 | - ); |
|
2997 | - } |
|
2998 | - |
|
2999 | - |
|
3000 | - |
|
3001 | - /** |
|
3002 | - * @return string |
|
3003 | - */ |
|
3004 | - public function getShowDatetimeSelector() |
|
3005 | - { |
|
3006 | - return $this->show_datetime_selector; |
|
3007 | - } |
|
3008 | - |
|
3009 | - |
|
3010 | - |
|
3011 | - /** |
|
3012 | - * @param bool $keys_only |
|
3013 | - * @return array |
|
3014 | - */ |
|
3015 | - public function getShowDatetimeSelectorOptions($keys_only = true) |
|
3016 | - { |
|
3017 | - return $keys_only |
|
3018 | - ? array( |
|
3019 | - \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR, |
|
3020 | - \EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR, |
|
3021 | - ) |
|
3022 | - : array( |
|
3023 | - \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR => esc_html__( |
|
3024 | - 'Do not show date & time filter', 'event_espresso' |
|
3025 | - ), |
|
3026 | - \EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR => esc_html__( |
|
3027 | - 'Maybe show date & time filter', 'event_espresso' |
|
3028 | - ), |
|
3029 | - ); |
|
3030 | - } |
|
3031 | - |
|
3032 | - |
|
3033 | - |
|
3034 | - /** |
|
3035 | - * @param string $show_datetime_selector |
|
3036 | - */ |
|
3037 | - public function setShowDatetimeSelector($show_datetime_selector) |
|
3038 | - { |
|
3039 | - $this->show_datetime_selector = in_array( |
|
3040 | - $show_datetime_selector, |
|
3041 | - $this->getShowDatetimeSelectorOptions(), |
|
3042 | - true |
|
3043 | - ) |
|
3044 | - ? $show_datetime_selector |
|
3045 | - : \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR; |
|
3046 | - } |
|
3047 | - |
|
3048 | - |
|
3049 | - |
|
3050 | - /** |
|
3051 | - * @return int |
|
3052 | - */ |
|
3053 | - public function getDatetimeSelectorThreshold() |
|
3054 | - { |
|
3055 | - return $this->datetime_selector_threshold; |
|
3056 | - } |
|
3057 | - |
|
3058 | - |
|
3059 | - |
|
3060 | - |
|
3061 | - /** |
|
3062 | - * @param int $datetime_selector_threshold |
|
3063 | - */ |
|
3064 | - public function setDatetimeSelectorThreshold($datetime_selector_threshold) |
|
3065 | - { |
|
3066 | - $datetime_selector_threshold = absint($datetime_selector_threshold); |
|
3067 | - $this->datetime_selector_threshold = $datetime_selector_threshold ? $datetime_selector_threshold : 3; |
|
3068 | - } |
|
2923 | + /** |
|
2924 | + * constant to indicate that a datetime selector should NEVER be shown for ticket selectors |
|
2925 | + */ |
|
2926 | + const DO_NOT_SHOW_DATETIME_SELECTOR = 'no_datetime_selector'; |
|
2927 | + |
|
2928 | + /** |
|
2929 | + * constant to indicate that a datetime selector should only be shown for ticket selectors |
|
2930 | + * when the number of datetimes for the event matches the value set for $datetime_selector_threshold |
|
2931 | + */ |
|
2932 | + const MAYBE_SHOW_DATETIME_SELECTOR = 'maybe_datetime_selector'; |
|
2933 | + |
|
2934 | + /** |
|
2935 | + * @var boolean $show_ticket_sale_columns |
|
2936 | + */ |
|
2937 | + public $show_ticket_sale_columns; |
|
2938 | + |
|
2939 | + /** |
|
2940 | + * @var boolean $show_ticket_details |
|
2941 | + */ |
|
2942 | + public $show_ticket_details; |
|
2943 | + |
|
2944 | + /** |
|
2945 | + * @var boolean $show_expired_tickets |
|
2946 | + */ |
|
2947 | + public $show_expired_tickets; |
|
2948 | + |
|
2949 | + /** |
|
2950 | + * whether or not to display a dropdown box populated with event datetimes |
|
2951 | + * that toggles which tickets are displayed for a ticket selector. |
|
2952 | + * uses one of the *_DATETIME_SELECTOR constants defined above |
|
2953 | + * |
|
2954 | + * @var string $show_datetime_selector |
|
2955 | + */ |
|
2956 | + private $show_datetime_selector = 'no_datetime_selector'; |
|
2957 | + |
|
2958 | + /** |
|
2959 | + * the number of datetimes an event has to have before conditionally displaying a datetime selector |
|
2960 | + * |
|
2961 | + * @var int $datetime_selector_threshold |
|
2962 | + */ |
|
2963 | + private $datetime_selector_threshold = 3; |
|
2964 | + |
|
2965 | + |
|
2966 | + |
|
2967 | + /** |
|
2968 | + * class constructor |
|
2969 | + */ |
|
2970 | + public function __construct() |
|
2971 | + { |
|
2972 | + $this->show_ticket_sale_columns = true; |
|
2973 | + $this->show_ticket_details = true; |
|
2974 | + $this->show_expired_tickets = true; |
|
2975 | + $this->show_datetime_selector = \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR; |
|
2976 | + $this->datetime_selector_threshold = 3; |
|
2977 | + } |
|
2978 | + |
|
2979 | + |
|
2980 | + |
|
2981 | + /** |
|
2982 | + * returns true if a datetime selector should be displayed |
|
2983 | + * |
|
2984 | + * @param array $datetimes |
|
2985 | + * @return bool |
|
2986 | + */ |
|
2987 | + public function showDatetimeSelector(array $datetimes) |
|
2988 | + { |
|
2989 | + // if the settings are NOT: don't show OR below threshold, THEN active = true |
|
2990 | + return ! ( |
|
2991 | + $this->getShowDatetimeSelector() === \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR |
|
2992 | + || ( |
|
2993 | + $this->getShowDatetimeSelector() === \EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR |
|
2994 | + && count($datetimes) < $this->getDatetimeSelectorThreshold() |
|
2995 | + ) |
|
2996 | + ); |
|
2997 | + } |
|
2998 | + |
|
2999 | + |
|
3000 | + |
|
3001 | + /** |
|
3002 | + * @return string |
|
3003 | + */ |
|
3004 | + public function getShowDatetimeSelector() |
|
3005 | + { |
|
3006 | + return $this->show_datetime_selector; |
|
3007 | + } |
|
3008 | + |
|
3009 | + |
|
3010 | + |
|
3011 | + /** |
|
3012 | + * @param bool $keys_only |
|
3013 | + * @return array |
|
3014 | + */ |
|
3015 | + public function getShowDatetimeSelectorOptions($keys_only = true) |
|
3016 | + { |
|
3017 | + return $keys_only |
|
3018 | + ? array( |
|
3019 | + \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR, |
|
3020 | + \EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR, |
|
3021 | + ) |
|
3022 | + : array( |
|
3023 | + \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR => esc_html__( |
|
3024 | + 'Do not show date & time filter', 'event_espresso' |
|
3025 | + ), |
|
3026 | + \EE_Ticket_Selector_Config::MAYBE_SHOW_DATETIME_SELECTOR => esc_html__( |
|
3027 | + 'Maybe show date & time filter', 'event_espresso' |
|
3028 | + ), |
|
3029 | + ); |
|
3030 | + } |
|
3031 | + |
|
3032 | + |
|
3033 | + |
|
3034 | + /** |
|
3035 | + * @param string $show_datetime_selector |
|
3036 | + */ |
|
3037 | + public function setShowDatetimeSelector($show_datetime_selector) |
|
3038 | + { |
|
3039 | + $this->show_datetime_selector = in_array( |
|
3040 | + $show_datetime_selector, |
|
3041 | + $this->getShowDatetimeSelectorOptions(), |
|
3042 | + true |
|
3043 | + ) |
|
3044 | + ? $show_datetime_selector |
|
3045 | + : \EE_Ticket_Selector_Config::DO_NOT_SHOW_DATETIME_SELECTOR; |
|
3046 | + } |
|
3047 | + |
|
3048 | + |
|
3049 | + |
|
3050 | + /** |
|
3051 | + * @return int |
|
3052 | + */ |
|
3053 | + public function getDatetimeSelectorThreshold() |
|
3054 | + { |
|
3055 | + return $this->datetime_selector_threshold; |
|
3056 | + } |
|
3057 | + |
|
3058 | + |
|
3059 | + |
|
3060 | + |
|
3061 | + /** |
|
3062 | + * @param int $datetime_selector_threshold |
|
3063 | + */ |
|
3064 | + public function setDatetimeSelectorThreshold($datetime_selector_threshold) |
|
3065 | + { |
|
3066 | + $datetime_selector_threshold = absint($datetime_selector_threshold); |
|
3067 | + $this->datetime_selector_threshold = $datetime_selector_threshold ? $datetime_selector_threshold : 3; |
|
3068 | + } |
|
3069 | 3069 | |
3070 | 3070 | |
3071 | 3071 | |
@@ -3083,85 +3083,85 @@ discard block |
||
3083 | 3083 | class EE_Environment_Config extends EE_Config_Base |
3084 | 3084 | { |
3085 | 3085 | |
3086 | - /** |
|
3087 | - * Hold any php environment variables that we want to track. |
|
3088 | - * |
|
3089 | - * @var stdClass; |
|
3090 | - */ |
|
3091 | - public $php; |
|
3092 | - |
|
3093 | - |
|
3094 | - |
|
3095 | - /** |
|
3096 | - * constructor |
|
3097 | - */ |
|
3098 | - public function __construct() |
|
3099 | - { |
|
3100 | - $this->php = new stdClass(); |
|
3101 | - $this->_set_php_values(); |
|
3102 | - } |
|
3103 | - |
|
3104 | - |
|
3105 | - |
|
3106 | - /** |
|
3107 | - * This sets the php environment variables. |
|
3108 | - * |
|
3109 | - * @since 4.4.0 |
|
3110 | - * @return void |
|
3111 | - */ |
|
3112 | - protected function _set_php_values() |
|
3113 | - { |
|
3114 | - $this->php->max_input_vars = ini_get('max_input_vars'); |
|
3115 | - $this->php->version = phpversion(); |
|
3116 | - } |
|
3117 | - |
|
3118 | - |
|
3119 | - |
|
3120 | - /** |
|
3121 | - * helper method for determining whether input_count is |
|
3122 | - * reaching the potential maximum the server can handle |
|
3123 | - * according to max_input_vars |
|
3124 | - * |
|
3125 | - * @param int $input_count the count of input vars. |
|
3126 | - * @return array { |
|
3127 | - * An array that represents whether available space and if no available space the error |
|
3128 | - * message. |
|
3129 | - * @type bool $has_space whether more inputs can be added. |
|
3130 | - * @type string $msg Any message to be displayed. |
|
3131 | - * } |
|
3132 | - */ |
|
3133 | - public function max_input_vars_limit_check($input_count = 0) |
|
3134 | - { |
|
3135 | - if (! empty($this->php->max_input_vars) |
|
3136 | - && ($input_count >= $this->php->max_input_vars) |
|
3137 | - && (PHP_MAJOR_VERSION >= 5 && PHP_MINOR_VERSION >= 3 && PHP_RELEASE_VERSION >= 9) |
|
3138 | - ) { |
|
3139 | - return sprintf( |
|
3140 | - __( |
|
3141 | - 'The maximum number of inputs on this page has been exceeded. You cannot add anymore items (i.e. tickets, datetimes, custom fields) on this page because of your servers PHP "max_input_vars" setting.%1$sThere are %2$d inputs and the maximum amount currently allowed by your server is %3$d.', |
|
3142 | - 'event_espresso' |
|
3143 | - ), |
|
3144 | - '<br>', |
|
3145 | - $input_count, |
|
3146 | - $this->php->max_input_vars |
|
3147 | - ); |
|
3148 | - } else { |
|
3149 | - return ''; |
|
3150 | - } |
|
3151 | - } |
|
3152 | - |
|
3153 | - |
|
3154 | - |
|
3155 | - /** |
|
3156 | - * The purpose of this method is just to force rechecking php values so if they've changed, they get updated. |
|
3157 | - * |
|
3158 | - * @since 4.4.1 |
|
3159 | - * @return void |
|
3160 | - */ |
|
3161 | - public function recheck_values() |
|
3162 | - { |
|
3163 | - $this->_set_php_values(); |
|
3164 | - } |
|
3086 | + /** |
|
3087 | + * Hold any php environment variables that we want to track. |
|
3088 | + * |
|
3089 | + * @var stdClass; |
|
3090 | + */ |
|
3091 | + public $php; |
|
3092 | + |
|
3093 | + |
|
3094 | + |
|
3095 | + /** |
|
3096 | + * constructor |
|
3097 | + */ |
|
3098 | + public function __construct() |
|
3099 | + { |
|
3100 | + $this->php = new stdClass(); |
|
3101 | + $this->_set_php_values(); |
|
3102 | + } |
|
3103 | + |
|
3104 | + |
|
3105 | + |
|
3106 | + /** |
|
3107 | + * This sets the php environment variables. |
|
3108 | + * |
|
3109 | + * @since 4.4.0 |
|
3110 | + * @return void |
|
3111 | + */ |
|
3112 | + protected function _set_php_values() |
|
3113 | + { |
|
3114 | + $this->php->max_input_vars = ini_get('max_input_vars'); |
|
3115 | + $this->php->version = phpversion(); |
|
3116 | + } |
|
3117 | + |
|
3118 | + |
|
3119 | + |
|
3120 | + /** |
|
3121 | + * helper method for determining whether input_count is |
|
3122 | + * reaching the potential maximum the server can handle |
|
3123 | + * according to max_input_vars |
|
3124 | + * |
|
3125 | + * @param int $input_count the count of input vars. |
|
3126 | + * @return array { |
|
3127 | + * An array that represents whether available space and if no available space the error |
|
3128 | + * message. |
|
3129 | + * @type bool $has_space whether more inputs can be added. |
|
3130 | + * @type string $msg Any message to be displayed. |
|
3131 | + * } |
|
3132 | + */ |
|
3133 | + public function max_input_vars_limit_check($input_count = 0) |
|
3134 | + { |
|
3135 | + if (! empty($this->php->max_input_vars) |
|
3136 | + && ($input_count >= $this->php->max_input_vars) |
|
3137 | + && (PHP_MAJOR_VERSION >= 5 && PHP_MINOR_VERSION >= 3 && PHP_RELEASE_VERSION >= 9) |
|
3138 | + ) { |
|
3139 | + return sprintf( |
|
3140 | + __( |
|
3141 | + 'The maximum number of inputs on this page has been exceeded. You cannot add anymore items (i.e. tickets, datetimes, custom fields) on this page because of your servers PHP "max_input_vars" setting.%1$sThere are %2$d inputs and the maximum amount currently allowed by your server is %3$d.', |
|
3142 | + 'event_espresso' |
|
3143 | + ), |
|
3144 | + '<br>', |
|
3145 | + $input_count, |
|
3146 | + $this->php->max_input_vars |
|
3147 | + ); |
|
3148 | + } else { |
|
3149 | + return ''; |
|
3150 | + } |
|
3151 | + } |
|
3152 | + |
|
3153 | + |
|
3154 | + |
|
3155 | + /** |
|
3156 | + * The purpose of this method is just to force rechecking php values so if they've changed, they get updated. |
|
3157 | + * |
|
3158 | + * @since 4.4.1 |
|
3159 | + * @return void |
|
3160 | + */ |
|
3161 | + public function recheck_values() |
|
3162 | + { |
|
3163 | + $this->_set_php_values(); |
|
3164 | + } |
|
3165 | 3165 | |
3166 | 3166 | |
3167 | 3167 | |
@@ -3179,22 +3179,22 @@ discard block |
||
3179 | 3179 | class EE_Tax_Config extends EE_Config_Base |
3180 | 3180 | { |
3181 | 3181 | |
3182 | - /* |
|
3182 | + /* |
|
3183 | 3183 | * flag to indicate whether or not to display ticket prices with the taxes included |
3184 | 3184 | * |
3185 | 3185 | * @var boolean $prices_displayed_including_taxes |
3186 | 3186 | */ |
3187 | - public $prices_displayed_including_taxes; |
|
3187 | + public $prices_displayed_including_taxes; |
|
3188 | 3188 | |
3189 | 3189 | |
3190 | 3190 | |
3191 | - /** |
|
3192 | - * class constructor |
|
3193 | - */ |
|
3194 | - public function __construct() |
|
3195 | - { |
|
3196 | - $this->prices_displayed_including_taxes = true; |
|
3197 | - } |
|
3191 | + /** |
|
3192 | + * class constructor |
|
3193 | + */ |
|
3194 | + public function __construct() |
|
3195 | + { |
|
3196 | + $this->prices_displayed_including_taxes = true; |
|
3197 | + } |
|
3198 | 3198 | } |
3199 | 3199 | |
3200 | 3200 | |
@@ -3209,17 +3209,17 @@ discard block |
||
3209 | 3209 | class EE_Messages_Config extends EE_Config_Base |
3210 | 3210 | { |
3211 | 3211 | |
3212 | - /** |
|
3213 | - * This is an integer representing the deletion threshold in months for when old messages will get deleted. |
|
3214 | - * A value of 0 represents never deleting. Default is 0. |
|
3215 | - * |
|
3216 | - * @var integer |
|
3217 | - */ |
|
3218 | - public $delete_threshold; |
|
3219 | - |
|
3220 | - public function __construct() { |
|
3221 | - $this->delete_threshold = 0; |
|
3222 | - } |
|
3212 | + /** |
|
3213 | + * This is an integer representing the deletion threshold in months for when old messages will get deleted. |
|
3214 | + * A value of 0 represents never deleting. Default is 0. |
|
3215 | + * |
|
3216 | + * @var integer |
|
3217 | + */ |
|
3218 | + public $delete_threshold; |
|
3219 | + |
|
3220 | + public function __construct() { |
|
3221 | + $this->delete_threshold = 0; |
|
3222 | + } |
|
3223 | 3223 | } |
3224 | 3224 | |
3225 | 3225 | |
@@ -3231,34 +3231,34 @@ discard block |
||
3231 | 3231 | class EE_Gateway_Config extends EE_Config_Base |
3232 | 3232 | { |
3233 | 3233 | |
3234 | - /** |
|
3235 | - * Array with keys that are payment gateways slugs, and values are arrays |
|
3236 | - * with any config info the gateway wants to store |
|
3237 | - * |
|
3238 | - * @var array |
|
3239 | - */ |
|
3240 | - public $payment_settings; |
|
3241 | - |
|
3242 | - /** |
|
3243 | - * Where keys are gateway slugs, and values are booleans indicating whether or not |
|
3244 | - * the gateway is stored in the uploads directory |
|
3245 | - * |
|
3246 | - * @var array |
|
3247 | - */ |
|
3248 | - public $active_gateways; |
|
3249 | - |
|
3250 | - |
|
3251 | - |
|
3252 | - /** |
|
3253 | - * class constructor |
|
3254 | - * |
|
3255 | - * @deprecated |
|
3256 | - */ |
|
3257 | - public function __construct() |
|
3258 | - { |
|
3259 | - $this->payment_settings = array(); |
|
3260 | - $this->active_gateways = array('Invoice' => false); |
|
3261 | - } |
|
3234 | + /** |
|
3235 | + * Array with keys that are payment gateways slugs, and values are arrays |
|
3236 | + * with any config info the gateway wants to store |
|
3237 | + * |
|
3238 | + * @var array |
|
3239 | + */ |
|
3240 | + public $payment_settings; |
|
3241 | + |
|
3242 | + /** |
|
3243 | + * Where keys are gateway slugs, and values are booleans indicating whether or not |
|
3244 | + * the gateway is stored in the uploads directory |
|
3245 | + * |
|
3246 | + * @var array |
|
3247 | + */ |
|
3248 | + public $active_gateways; |
|
3249 | + |
|
3250 | + |
|
3251 | + |
|
3252 | + /** |
|
3253 | + * class constructor |
|
3254 | + * |
|
3255 | + * @deprecated |
|
3256 | + */ |
|
3257 | + public function __construct() |
|
3258 | + { |
|
3259 | + $this->payment_settings = array(); |
|
3260 | + $this->active_gateways = array('Invoice' => false); |
|
3261 | + } |
|
3262 | 3262 | } |
3263 | 3263 | |
3264 | 3264 | // End of file EE_Config.core.php |
@@ -2,7 +2,7 @@ discard block |
||
2 | 2 | use EventEspresso\core\interfaces\ResettableInterface; |
3 | 3 | |
4 | 4 | if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
5 | - exit('No direct script access allowed'); |
|
5 | + exit('No direct script access allowed'); |
|
6 | 6 | } |
7 | 7 | do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
8 | 8 | |
@@ -23,418 +23,418 @@ discard block |
||
23 | 23 | class EE_Cart implements ResettableInterface |
24 | 24 | { |
25 | 25 | |
26 | - /** |
|
27 | - * instance of the EE_Cart object |
|
28 | - * |
|
29 | - * @access private |
|
30 | - * @var EE_Cart $_instance |
|
31 | - */ |
|
32 | - private static $_instance; |
|
33 | - |
|
34 | - /** |
|
35 | - * instance of the EE_Session object |
|
36 | - * |
|
37 | - * @access protected |
|
38 | - * @var EE_Session $_session |
|
39 | - */ |
|
40 | - protected $_session; |
|
41 | - |
|
42 | - /** |
|
43 | - * The total Line item which comprises all the children line-item subtotals, |
|
44 | - * which in turn each have their line items. |
|
45 | - * Typically, the line item structure will look like: |
|
46 | - * grand total |
|
47 | - * -tickets-sub-total |
|
48 | - * --ticket1 |
|
49 | - * --ticket2 |
|
50 | - * --... |
|
51 | - * -taxes-sub-total |
|
52 | - * --tax1 |
|
53 | - * --tax2 |
|
54 | - * |
|
55 | - * @var EE_Line_Item |
|
56 | - */ |
|
57 | - private $_grand_total; |
|
58 | - |
|
59 | - |
|
60 | - |
|
61 | - /** |
|
62 | - * @singleton method used to instantiate class object |
|
63 | - * @access public |
|
64 | - * @param EE_Line_Item $grand_total |
|
65 | - * @param EE_Session $session |
|
66 | - * @return \EE_Cart |
|
67 | - * @throws \EE_Error |
|
68 | - */ |
|
69 | - public static function instance(EE_Line_Item $grand_total = null, EE_Session $session = null) |
|
70 | - { |
|
71 | - if ( ! empty($grand_total)) { |
|
72 | - self::$_instance = new self($grand_total, $session); |
|
73 | - } |
|
74 | - // or maybe retrieve an existing one ? |
|
75 | - if ( ! self::$_instance instanceof EE_Cart) { |
|
76 | - // try getting the cart out of the session |
|
77 | - $saved_cart = $session instanceof EE_Session ? $session->cart() : null; |
|
78 | - self::$_instance = $saved_cart instanceof EE_Cart ? $saved_cart : new self($grand_total, $session); |
|
79 | - unset($saved_cart); |
|
80 | - } |
|
81 | - // verify that cart is ok and grand total line item exists |
|
82 | - if ( ! self::$_instance instanceof EE_Cart || ! self::$_instance->_grand_total instanceof EE_Line_Item) { |
|
83 | - self::$_instance = new self($grand_total, $session); |
|
84 | - } |
|
85 | - self::$_instance->get_grand_total(); |
|
86 | - // once everything is all said and done, save the cart to the EE_Session |
|
87 | - add_action('shutdown', array(self::$_instance, 'save_cart'), 90); |
|
88 | - return self::$_instance; |
|
89 | - } |
|
90 | - |
|
91 | - |
|
92 | - |
|
93 | - /** |
|
94 | - * private constructor to prevent direct creation |
|
95 | - * |
|
96 | - * @Constructor |
|
97 | - * @access private |
|
98 | - * @param EE_Line_Item $grand_total |
|
99 | - * @param EE_Session $session |
|
100 | - */ |
|
101 | - private function __construct(EE_Line_Item $grand_total = null, EE_Session $session = null) |
|
102 | - { |
|
103 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
104 | - $this->set_session($session); |
|
105 | - if ($grand_total instanceof EE_Line_Item) { |
|
106 | - $this->set_grand_total_line_item($grand_total); |
|
107 | - } |
|
108 | - } |
|
109 | - |
|
110 | - |
|
111 | - |
|
112 | - /** |
|
113 | - * Resets the cart completely (whereas empty_cart |
|
114 | - * |
|
115 | - * @param EE_Line_Item $grand_total |
|
116 | - * @param EE_Session $session |
|
117 | - * @return EE_Cart |
|
118 | - * @throws \EE_Error |
|
119 | - */ |
|
120 | - public static function reset(EE_Line_Item $grand_total = null, EE_Session $session = null) |
|
121 | - { |
|
122 | - remove_action('shutdown', array(self::$_instance, 'save_cart'), 90); |
|
123 | - if ($session instanceof EE_Session) { |
|
124 | - $session->reset_cart(); |
|
125 | - } |
|
126 | - self::$_instance = null; |
|
127 | - return self::instance($grand_total, $session); |
|
128 | - } |
|
129 | - |
|
130 | - |
|
131 | - |
|
132 | - /** |
|
133 | - * @return \EE_Session |
|
134 | - */ |
|
135 | - public function session() |
|
136 | - { |
|
137 | - if ( ! $this->_session instanceof EE_Session) { |
|
138 | - $this->set_session(); |
|
139 | - } |
|
140 | - return $this->_session; |
|
141 | - } |
|
142 | - |
|
143 | - |
|
144 | - |
|
145 | - /** |
|
146 | - * @param EE_Session $session |
|
147 | - */ |
|
148 | - public function set_session(EE_Session $session = null) |
|
149 | - { |
|
150 | - $this->_session = $session instanceof EE_Session ? $session : EE_Registry::instance()->load_core('Session'); |
|
151 | - } |
|
152 | - |
|
153 | - |
|
154 | - |
|
155 | - /** |
|
156 | - * Sets the cart to match the line item. Especially handy for loading an old cart where you |
|
157 | - * know the grand total line item on it |
|
158 | - * |
|
159 | - * @param EE_Line_Item $line_item |
|
160 | - */ |
|
161 | - public function set_grand_total_line_item(EE_Line_Item $line_item) |
|
162 | - { |
|
163 | - $this->_grand_total = $line_item; |
|
164 | - } |
|
165 | - |
|
166 | - |
|
167 | - |
|
168 | - /** |
|
169 | - * get_cart_from_reg_url_link |
|
170 | - * |
|
171 | - * @access public |
|
172 | - * @param EE_Transaction $transaction |
|
173 | - * @param EE_Session $session |
|
174 | - * @return \EE_Cart |
|
175 | - * @throws \EE_Error |
|
176 | - */ |
|
177 | - public static function get_cart_from_txn(EE_Transaction $transaction, EE_Session $session = null) |
|
178 | - { |
|
179 | - $grand_total = $transaction->total_line_item(); |
|
180 | - $grand_total->get_items(); |
|
181 | - $grand_total->tax_descendants(); |
|
182 | - return EE_Cart::instance($grand_total, $session); |
|
183 | - } |
|
184 | - |
|
185 | - |
|
186 | - |
|
187 | - /** |
|
188 | - * Creates the total line item, and ensures it has its 'tickets' and 'taxes' sub-items |
|
189 | - * |
|
190 | - * @return EE_Line_Item |
|
191 | - * @throws \EE_Error |
|
192 | - */ |
|
193 | - private function _create_grand_total() |
|
194 | - { |
|
195 | - $this->_grand_total = EEH_Line_Item::create_total_line_item(); |
|
196 | - return $this->_grand_total; |
|
197 | - } |
|
198 | - |
|
199 | - |
|
200 | - |
|
201 | - /** |
|
202 | - * Gets all the line items of object type Ticket |
|
203 | - * |
|
204 | - * @access public |
|
205 | - * @return \EE_Line_Item[] |
|
206 | - */ |
|
207 | - public function get_tickets() |
|
208 | - { |
|
209 | - if ($this->_grand_total === null ) { |
|
210 | - return array(); |
|
211 | - } |
|
212 | - return EEH_Line_Item::get_ticket_line_items($this->_grand_total); |
|
213 | - } |
|
214 | - |
|
215 | - |
|
216 | - |
|
217 | - /** |
|
218 | - * returns the total quantity of tickets in the cart |
|
219 | - * |
|
220 | - * @access public |
|
221 | - * @return int |
|
222 | - * @throws \EE_Error |
|
223 | - */ |
|
224 | - public function all_ticket_quantity_count() |
|
225 | - { |
|
226 | - $tickets = $this->get_tickets(); |
|
227 | - if (empty($tickets)) { |
|
228 | - return 0; |
|
229 | - } |
|
230 | - $count = 0; |
|
231 | - foreach ($tickets as $ticket) { |
|
232 | - $count += $ticket->get('LIN_quantity'); |
|
233 | - } |
|
234 | - return $count; |
|
235 | - } |
|
236 | - |
|
237 | - |
|
238 | - |
|
239 | - /** |
|
240 | - * Gets all the tax line items |
|
241 | - * |
|
242 | - * @return \EE_Line_Item[] |
|
243 | - * @throws \EE_Error |
|
244 | - */ |
|
245 | - public function get_taxes() |
|
246 | - { |
|
247 | - return EEH_Line_Item::get_taxes_subtotal($this->_grand_total)->children(); |
|
248 | - } |
|
249 | - |
|
250 | - |
|
251 | - |
|
252 | - /** |
|
253 | - * Gets the total line item (which is a parent of all other line items) on this cart |
|
254 | - * |
|
255 | - * @return EE_Line_Item |
|
256 | - * @throws \EE_Error |
|
257 | - */ |
|
258 | - public function get_grand_total() |
|
259 | - { |
|
260 | - return $this->_grand_total instanceof EE_Line_Item ? $this->_grand_total : $this->_create_grand_total(); |
|
261 | - } |
|
262 | - |
|
263 | - |
|
264 | - |
|
265 | - /** |
|
266 | - * @process items for adding to cart |
|
267 | - * @access public |
|
268 | - * @param EE_Ticket $ticket |
|
269 | - * @param int $qty |
|
270 | - * @return TRUE on success, FALSE on fail |
|
271 | - * @throws \EE_Error |
|
272 | - */ |
|
273 | - public function add_ticket_to_cart(EE_Ticket $ticket, $qty = 1) |
|
274 | - { |
|
275 | - EEH_Line_Item::add_ticket_purchase($this->get_grand_total(), $ticket, $qty); |
|
276 | - return $this->save_cart() ? true : false; |
|
277 | - } |
|
278 | - |
|
279 | - |
|
280 | - |
|
281 | - /** |
|
282 | - * get_cart_total_before_tax |
|
283 | - * |
|
284 | - * @access public |
|
285 | - * @return float |
|
286 | - * @throws \EE_Error |
|
287 | - */ |
|
288 | - public function get_cart_total_before_tax() |
|
289 | - { |
|
290 | - return $this->get_grand_total()->recalculate_pre_tax_total(); |
|
291 | - } |
|
292 | - |
|
293 | - |
|
294 | - |
|
295 | - /** |
|
296 | - * gets the total amount of tax paid for items in this cart |
|
297 | - * |
|
298 | - * @access public |
|
299 | - * @return float |
|
300 | - * @throws \EE_Error |
|
301 | - */ |
|
302 | - public function get_applied_taxes() |
|
303 | - { |
|
304 | - return EEH_Line_Item::ensure_taxes_applied($this->_grand_total); |
|
305 | - } |
|
306 | - |
|
307 | - |
|
308 | - |
|
309 | - /** |
|
310 | - * Gets the total amount to be paid for the items in the cart, including taxes and other modifiers |
|
311 | - * |
|
312 | - * @access public |
|
313 | - * @return float |
|
314 | - * @throws \EE_Error |
|
315 | - */ |
|
316 | - public function get_cart_grand_total() |
|
317 | - { |
|
318 | - EEH_Line_Item::ensure_taxes_applied($this->_grand_total); |
|
319 | - return $this->get_grand_total()->total(); |
|
320 | - } |
|
321 | - |
|
322 | - |
|
323 | - |
|
324 | - /** |
|
325 | - * Gets the total amount to be paid for the items in the cart, including taxes and other modifiers |
|
326 | - * |
|
327 | - * @access public |
|
328 | - * @return float |
|
329 | - * @throws \EE_Error |
|
330 | - */ |
|
331 | - public function recalculate_all_cart_totals() |
|
332 | - { |
|
333 | - $pre_tax_total = $this->get_cart_total_before_tax(); |
|
334 | - $taxes_total = EEH_Line_Item::ensure_taxes_applied($this->_grand_total); |
|
335 | - $this->_grand_total->set_total($pre_tax_total + $taxes_total); |
|
336 | - $this->_grand_total->save_this_and_descendants_to_txn(); |
|
337 | - return $this->get_grand_total()->total(); |
|
338 | - } |
|
339 | - |
|
340 | - |
|
341 | - |
|
342 | - /** |
|
343 | - * deletes an item from the cart |
|
344 | - * |
|
345 | - * @access public |
|
346 | - * @param array|bool|string $line_item_codes |
|
347 | - * @return int on success, FALSE on fail |
|
348 | - * @throws \EE_Error |
|
349 | - */ |
|
350 | - public function delete_items($line_item_codes = false) |
|
351 | - { |
|
352 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
353 | - return EEH_Line_Item::delete_items($this->get_grand_total(), $line_item_codes); |
|
354 | - } |
|
355 | - |
|
356 | - |
|
357 | - |
|
358 | - /** |
|
359 | - * @remove ALL items from cart and zero ALL totals |
|
360 | - * @access public |
|
361 | - * @return bool |
|
362 | - * @throws \EE_Error |
|
363 | - */ |
|
364 | - public function empty_cart() |
|
365 | - { |
|
366 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
367 | - $this->_grand_total = $this->_create_grand_total(); |
|
368 | - return $this->save_cart(true); |
|
369 | - } |
|
370 | - |
|
371 | - |
|
372 | - |
|
373 | - /** |
|
374 | - * @remove ALL items from cart and delete total as well |
|
375 | - * @access public |
|
376 | - * @return bool |
|
377 | - * @throws \EE_Error |
|
378 | - */ |
|
379 | - public function delete_cart() |
|
380 | - { |
|
381 | - $deleted = EEH_Line_Item::delete_all_child_items($this->_grand_total); |
|
382 | - if ($deleted) { |
|
383 | - $deleted += $this->_grand_total->delete(); |
|
384 | - $this->_grand_total = null; |
|
385 | - } |
|
386 | - return $deleted; |
|
387 | - } |
|
388 | - |
|
389 | - |
|
390 | - |
|
391 | - /** |
|
392 | - * @save cart to session |
|
393 | - * @access public |
|
394 | - * @param bool $apply_taxes |
|
395 | - * @return TRUE on success, FALSE on fail |
|
396 | - * @throws \EE_Error |
|
397 | - */ |
|
398 | - public function save_cart($apply_taxes = true) |
|
399 | - { |
|
400 | - if ($apply_taxes && $this->_grand_total instanceof EE_Line_Item) { |
|
401 | - EEH_Line_Item::ensure_taxes_applied($this->_grand_total); |
|
402 | - //make sure we don't cache the transaction because it can get stale |
|
403 | - if ($this->_grand_total->get_one_from_cache('Transaction') instanceof EE_Transaction |
|
404 | - && $this->_grand_total->get_one_from_cache('Transaction')->ID() |
|
405 | - ) { |
|
406 | - $this->_grand_total->clear_cache('Transaction', null, true); |
|
407 | - } |
|
408 | - } |
|
409 | - if ($this->session() instanceof EE_Session) { |
|
410 | - return $this->session()->set_cart($this); |
|
411 | - } else { |
|
412 | - return false; |
|
413 | - } |
|
414 | - } |
|
415 | - |
|
416 | - |
|
417 | - |
|
418 | - public function __wakeup() |
|
419 | - { |
|
420 | - if ( ! $this->_grand_total instanceof EE_Line_Item && absint($this->_grand_total) !== 0) { |
|
421 | - // $this->_grand_total is actually just an ID, so use it to get the object from the db |
|
422 | - $this->_grand_total = EEM_Line_Item::instance()->get_one_by_ID($this->_grand_total); |
|
423 | - } |
|
424 | - } |
|
425 | - |
|
426 | - |
|
427 | - |
|
428 | - /** |
|
429 | - * @return array |
|
430 | - */ |
|
431 | - public function __sleep() |
|
432 | - { |
|
433 | - if ($this->_grand_total instanceof EE_Line_Item && $this->_grand_total->ID()) { |
|
434 | - $this->_grand_total = $this->_grand_total->ID(); |
|
435 | - } |
|
436 | - return array('_grand_total'); |
|
437 | - } |
|
26 | + /** |
|
27 | + * instance of the EE_Cart object |
|
28 | + * |
|
29 | + * @access private |
|
30 | + * @var EE_Cart $_instance |
|
31 | + */ |
|
32 | + private static $_instance; |
|
33 | + |
|
34 | + /** |
|
35 | + * instance of the EE_Session object |
|
36 | + * |
|
37 | + * @access protected |
|
38 | + * @var EE_Session $_session |
|
39 | + */ |
|
40 | + protected $_session; |
|
41 | + |
|
42 | + /** |
|
43 | + * The total Line item which comprises all the children line-item subtotals, |
|
44 | + * which in turn each have their line items. |
|
45 | + * Typically, the line item structure will look like: |
|
46 | + * grand total |
|
47 | + * -tickets-sub-total |
|
48 | + * --ticket1 |
|
49 | + * --ticket2 |
|
50 | + * --... |
|
51 | + * -taxes-sub-total |
|
52 | + * --tax1 |
|
53 | + * --tax2 |
|
54 | + * |
|
55 | + * @var EE_Line_Item |
|
56 | + */ |
|
57 | + private $_grand_total; |
|
58 | + |
|
59 | + |
|
60 | + |
|
61 | + /** |
|
62 | + * @singleton method used to instantiate class object |
|
63 | + * @access public |
|
64 | + * @param EE_Line_Item $grand_total |
|
65 | + * @param EE_Session $session |
|
66 | + * @return \EE_Cart |
|
67 | + * @throws \EE_Error |
|
68 | + */ |
|
69 | + public static function instance(EE_Line_Item $grand_total = null, EE_Session $session = null) |
|
70 | + { |
|
71 | + if ( ! empty($grand_total)) { |
|
72 | + self::$_instance = new self($grand_total, $session); |
|
73 | + } |
|
74 | + // or maybe retrieve an existing one ? |
|
75 | + if ( ! self::$_instance instanceof EE_Cart) { |
|
76 | + // try getting the cart out of the session |
|
77 | + $saved_cart = $session instanceof EE_Session ? $session->cart() : null; |
|
78 | + self::$_instance = $saved_cart instanceof EE_Cart ? $saved_cart : new self($grand_total, $session); |
|
79 | + unset($saved_cart); |
|
80 | + } |
|
81 | + // verify that cart is ok and grand total line item exists |
|
82 | + if ( ! self::$_instance instanceof EE_Cart || ! self::$_instance->_grand_total instanceof EE_Line_Item) { |
|
83 | + self::$_instance = new self($grand_total, $session); |
|
84 | + } |
|
85 | + self::$_instance->get_grand_total(); |
|
86 | + // once everything is all said and done, save the cart to the EE_Session |
|
87 | + add_action('shutdown', array(self::$_instance, 'save_cart'), 90); |
|
88 | + return self::$_instance; |
|
89 | + } |
|
90 | + |
|
91 | + |
|
92 | + |
|
93 | + /** |
|
94 | + * private constructor to prevent direct creation |
|
95 | + * |
|
96 | + * @Constructor |
|
97 | + * @access private |
|
98 | + * @param EE_Line_Item $grand_total |
|
99 | + * @param EE_Session $session |
|
100 | + */ |
|
101 | + private function __construct(EE_Line_Item $grand_total = null, EE_Session $session = null) |
|
102 | + { |
|
103 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
104 | + $this->set_session($session); |
|
105 | + if ($grand_total instanceof EE_Line_Item) { |
|
106 | + $this->set_grand_total_line_item($grand_total); |
|
107 | + } |
|
108 | + } |
|
109 | + |
|
110 | + |
|
111 | + |
|
112 | + /** |
|
113 | + * Resets the cart completely (whereas empty_cart |
|
114 | + * |
|
115 | + * @param EE_Line_Item $grand_total |
|
116 | + * @param EE_Session $session |
|
117 | + * @return EE_Cart |
|
118 | + * @throws \EE_Error |
|
119 | + */ |
|
120 | + public static function reset(EE_Line_Item $grand_total = null, EE_Session $session = null) |
|
121 | + { |
|
122 | + remove_action('shutdown', array(self::$_instance, 'save_cart'), 90); |
|
123 | + if ($session instanceof EE_Session) { |
|
124 | + $session->reset_cart(); |
|
125 | + } |
|
126 | + self::$_instance = null; |
|
127 | + return self::instance($grand_total, $session); |
|
128 | + } |
|
129 | + |
|
130 | + |
|
131 | + |
|
132 | + /** |
|
133 | + * @return \EE_Session |
|
134 | + */ |
|
135 | + public function session() |
|
136 | + { |
|
137 | + if ( ! $this->_session instanceof EE_Session) { |
|
138 | + $this->set_session(); |
|
139 | + } |
|
140 | + return $this->_session; |
|
141 | + } |
|
142 | + |
|
143 | + |
|
144 | + |
|
145 | + /** |
|
146 | + * @param EE_Session $session |
|
147 | + */ |
|
148 | + public function set_session(EE_Session $session = null) |
|
149 | + { |
|
150 | + $this->_session = $session instanceof EE_Session ? $session : EE_Registry::instance()->load_core('Session'); |
|
151 | + } |
|
152 | + |
|
153 | + |
|
154 | + |
|
155 | + /** |
|
156 | + * Sets the cart to match the line item. Especially handy for loading an old cart where you |
|
157 | + * know the grand total line item on it |
|
158 | + * |
|
159 | + * @param EE_Line_Item $line_item |
|
160 | + */ |
|
161 | + public function set_grand_total_line_item(EE_Line_Item $line_item) |
|
162 | + { |
|
163 | + $this->_grand_total = $line_item; |
|
164 | + } |
|
165 | + |
|
166 | + |
|
167 | + |
|
168 | + /** |
|
169 | + * get_cart_from_reg_url_link |
|
170 | + * |
|
171 | + * @access public |
|
172 | + * @param EE_Transaction $transaction |
|
173 | + * @param EE_Session $session |
|
174 | + * @return \EE_Cart |
|
175 | + * @throws \EE_Error |
|
176 | + */ |
|
177 | + public static function get_cart_from_txn(EE_Transaction $transaction, EE_Session $session = null) |
|
178 | + { |
|
179 | + $grand_total = $transaction->total_line_item(); |
|
180 | + $grand_total->get_items(); |
|
181 | + $grand_total->tax_descendants(); |
|
182 | + return EE_Cart::instance($grand_total, $session); |
|
183 | + } |
|
184 | + |
|
185 | + |
|
186 | + |
|
187 | + /** |
|
188 | + * Creates the total line item, and ensures it has its 'tickets' and 'taxes' sub-items |
|
189 | + * |
|
190 | + * @return EE_Line_Item |
|
191 | + * @throws \EE_Error |
|
192 | + */ |
|
193 | + private function _create_grand_total() |
|
194 | + { |
|
195 | + $this->_grand_total = EEH_Line_Item::create_total_line_item(); |
|
196 | + return $this->_grand_total; |
|
197 | + } |
|
198 | + |
|
199 | + |
|
200 | + |
|
201 | + /** |
|
202 | + * Gets all the line items of object type Ticket |
|
203 | + * |
|
204 | + * @access public |
|
205 | + * @return \EE_Line_Item[] |
|
206 | + */ |
|
207 | + public function get_tickets() |
|
208 | + { |
|
209 | + if ($this->_grand_total === null ) { |
|
210 | + return array(); |
|
211 | + } |
|
212 | + return EEH_Line_Item::get_ticket_line_items($this->_grand_total); |
|
213 | + } |
|
214 | + |
|
215 | + |
|
216 | + |
|
217 | + /** |
|
218 | + * returns the total quantity of tickets in the cart |
|
219 | + * |
|
220 | + * @access public |
|
221 | + * @return int |
|
222 | + * @throws \EE_Error |
|
223 | + */ |
|
224 | + public function all_ticket_quantity_count() |
|
225 | + { |
|
226 | + $tickets = $this->get_tickets(); |
|
227 | + if (empty($tickets)) { |
|
228 | + return 0; |
|
229 | + } |
|
230 | + $count = 0; |
|
231 | + foreach ($tickets as $ticket) { |
|
232 | + $count += $ticket->get('LIN_quantity'); |
|
233 | + } |
|
234 | + return $count; |
|
235 | + } |
|
236 | + |
|
237 | + |
|
238 | + |
|
239 | + /** |
|
240 | + * Gets all the tax line items |
|
241 | + * |
|
242 | + * @return \EE_Line_Item[] |
|
243 | + * @throws \EE_Error |
|
244 | + */ |
|
245 | + public function get_taxes() |
|
246 | + { |
|
247 | + return EEH_Line_Item::get_taxes_subtotal($this->_grand_total)->children(); |
|
248 | + } |
|
249 | + |
|
250 | + |
|
251 | + |
|
252 | + /** |
|
253 | + * Gets the total line item (which is a parent of all other line items) on this cart |
|
254 | + * |
|
255 | + * @return EE_Line_Item |
|
256 | + * @throws \EE_Error |
|
257 | + */ |
|
258 | + public function get_grand_total() |
|
259 | + { |
|
260 | + return $this->_grand_total instanceof EE_Line_Item ? $this->_grand_total : $this->_create_grand_total(); |
|
261 | + } |
|
262 | + |
|
263 | + |
|
264 | + |
|
265 | + /** |
|
266 | + * @process items for adding to cart |
|
267 | + * @access public |
|
268 | + * @param EE_Ticket $ticket |
|
269 | + * @param int $qty |
|
270 | + * @return TRUE on success, FALSE on fail |
|
271 | + * @throws \EE_Error |
|
272 | + */ |
|
273 | + public function add_ticket_to_cart(EE_Ticket $ticket, $qty = 1) |
|
274 | + { |
|
275 | + EEH_Line_Item::add_ticket_purchase($this->get_grand_total(), $ticket, $qty); |
|
276 | + return $this->save_cart() ? true : false; |
|
277 | + } |
|
278 | + |
|
279 | + |
|
280 | + |
|
281 | + /** |
|
282 | + * get_cart_total_before_tax |
|
283 | + * |
|
284 | + * @access public |
|
285 | + * @return float |
|
286 | + * @throws \EE_Error |
|
287 | + */ |
|
288 | + public function get_cart_total_before_tax() |
|
289 | + { |
|
290 | + return $this->get_grand_total()->recalculate_pre_tax_total(); |
|
291 | + } |
|
292 | + |
|
293 | + |
|
294 | + |
|
295 | + /** |
|
296 | + * gets the total amount of tax paid for items in this cart |
|
297 | + * |
|
298 | + * @access public |
|
299 | + * @return float |
|
300 | + * @throws \EE_Error |
|
301 | + */ |
|
302 | + public function get_applied_taxes() |
|
303 | + { |
|
304 | + return EEH_Line_Item::ensure_taxes_applied($this->_grand_total); |
|
305 | + } |
|
306 | + |
|
307 | + |
|
308 | + |
|
309 | + /** |
|
310 | + * Gets the total amount to be paid for the items in the cart, including taxes and other modifiers |
|
311 | + * |
|
312 | + * @access public |
|
313 | + * @return float |
|
314 | + * @throws \EE_Error |
|
315 | + */ |
|
316 | + public function get_cart_grand_total() |
|
317 | + { |
|
318 | + EEH_Line_Item::ensure_taxes_applied($this->_grand_total); |
|
319 | + return $this->get_grand_total()->total(); |
|
320 | + } |
|
321 | + |
|
322 | + |
|
323 | + |
|
324 | + /** |
|
325 | + * Gets the total amount to be paid for the items in the cart, including taxes and other modifiers |
|
326 | + * |
|
327 | + * @access public |
|
328 | + * @return float |
|
329 | + * @throws \EE_Error |
|
330 | + */ |
|
331 | + public function recalculate_all_cart_totals() |
|
332 | + { |
|
333 | + $pre_tax_total = $this->get_cart_total_before_tax(); |
|
334 | + $taxes_total = EEH_Line_Item::ensure_taxes_applied($this->_grand_total); |
|
335 | + $this->_grand_total->set_total($pre_tax_total + $taxes_total); |
|
336 | + $this->_grand_total->save_this_and_descendants_to_txn(); |
|
337 | + return $this->get_grand_total()->total(); |
|
338 | + } |
|
339 | + |
|
340 | + |
|
341 | + |
|
342 | + /** |
|
343 | + * deletes an item from the cart |
|
344 | + * |
|
345 | + * @access public |
|
346 | + * @param array|bool|string $line_item_codes |
|
347 | + * @return int on success, FALSE on fail |
|
348 | + * @throws \EE_Error |
|
349 | + */ |
|
350 | + public function delete_items($line_item_codes = false) |
|
351 | + { |
|
352 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
353 | + return EEH_Line_Item::delete_items($this->get_grand_total(), $line_item_codes); |
|
354 | + } |
|
355 | + |
|
356 | + |
|
357 | + |
|
358 | + /** |
|
359 | + * @remove ALL items from cart and zero ALL totals |
|
360 | + * @access public |
|
361 | + * @return bool |
|
362 | + * @throws \EE_Error |
|
363 | + */ |
|
364 | + public function empty_cart() |
|
365 | + { |
|
366 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
367 | + $this->_grand_total = $this->_create_grand_total(); |
|
368 | + return $this->save_cart(true); |
|
369 | + } |
|
370 | + |
|
371 | + |
|
372 | + |
|
373 | + /** |
|
374 | + * @remove ALL items from cart and delete total as well |
|
375 | + * @access public |
|
376 | + * @return bool |
|
377 | + * @throws \EE_Error |
|
378 | + */ |
|
379 | + public function delete_cart() |
|
380 | + { |
|
381 | + $deleted = EEH_Line_Item::delete_all_child_items($this->_grand_total); |
|
382 | + if ($deleted) { |
|
383 | + $deleted += $this->_grand_total->delete(); |
|
384 | + $this->_grand_total = null; |
|
385 | + } |
|
386 | + return $deleted; |
|
387 | + } |
|
388 | + |
|
389 | + |
|
390 | + |
|
391 | + /** |
|
392 | + * @save cart to session |
|
393 | + * @access public |
|
394 | + * @param bool $apply_taxes |
|
395 | + * @return TRUE on success, FALSE on fail |
|
396 | + * @throws \EE_Error |
|
397 | + */ |
|
398 | + public function save_cart($apply_taxes = true) |
|
399 | + { |
|
400 | + if ($apply_taxes && $this->_grand_total instanceof EE_Line_Item) { |
|
401 | + EEH_Line_Item::ensure_taxes_applied($this->_grand_total); |
|
402 | + //make sure we don't cache the transaction because it can get stale |
|
403 | + if ($this->_grand_total->get_one_from_cache('Transaction') instanceof EE_Transaction |
|
404 | + && $this->_grand_total->get_one_from_cache('Transaction')->ID() |
|
405 | + ) { |
|
406 | + $this->_grand_total->clear_cache('Transaction', null, true); |
|
407 | + } |
|
408 | + } |
|
409 | + if ($this->session() instanceof EE_Session) { |
|
410 | + return $this->session()->set_cart($this); |
|
411 | + } else { |
|
412 | + return false; |
|
413 | + } |
|
414 | + } |
|
415 | + |
|
416 | + |
|
417 | + |
|
418 | + public function __wakeup() |
|
419 | + { |
|
420 | + if ( ! $this->_grand_total instanceof EE_Line_Item && absint($this->_grand_total) !== 0) { |
|
421 | + // $this->_grand_total is actually just an ID, so use it to get the object from the db |
|
422 | + $this->_grand_total = EEM_Line_Item::instance()->get_one_by_ID($this->_grand_total); |
|
423 | + } |
|
424 | + } |
|
425 | + |
|
426 | + |
|
427 | + |
|
428 | + /** |
|
429 | + * @return array |
|
430 | + */ |
|
431 | + public function __sleep() |
|
432 | + { |
|
433 | + if ($this->_grand_total instanceof EE_Line_Item && $this->_grand_total->ID()) { |
|
434 | + $this->_grand_total = $this->_grand_total->ID(); |
|
435 | + } |
|
436 | + return array('_grand_total'); |
|
437 | + } |
|
438 | 438 | |
439 | 439 | |
440 | 440 | } |
@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <?php use EventEspresso\core\interfaces\ResettableInterface; |
2 | 2 | |
3 | 3 | if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
4 | - exit('No direct script access allowed'); |
|
4 | + exit('No direct script access allowed'); |
|
5 | 5 | } |
6 | 6 | EE_Registry::instance()->load_class('Processor_Base'); |
7 | 7 | |
@@ -18,748 +18,748 @@ discard block |
||
18 | 18 | class EE_Payment_Processor extends EE_Processor_Base implements ResettableInterface |
19 | 19 | { |
20 | 20 | |
21 | - /** |
|
22 | - * @var EE_Payment_Processor $_instance |
|
23 | - * @access private |
|
24 | - */ |
|
25 | - private static $_instance; |
|
26 | - |
|
27 | - |
|
28 | - |
|
29 | - /** |
|
30 | - * @singleton method used to instantiate class object |
|
31 | - * @access public |
|
32 | - * @return EE_Payment_Processor instance |
|
33 | - */ |
|
34 | - public static function instance() |
|
35 | - { |
|
36 | - // check if class object is instantiated |
|
37 | - if ( ! self::$_instance instanceof EE_Payment_Processor) { |
|
38 | - self::$_instance = new self(); |
|
39 | - } |
|
40 | - return self::$_instance; |
|
41 | - } |
|
42 | - |
|
43 | - |
|
44 | - |
|
45 | - /** |
|
46 | - * @return EE_Payment_Processor |
|
47 | - */ |
|
48 | - public static function reset() |
|
49 | - { |
|
50 | - self::$_instance = null; |
|
51 | - return self::instance(); |
|
52 | - } |
|
53 | - |
|
54 | - |
|
55 | - |
|
56 | - /** |
|
57 | - *private constructor to prevent direct creation |
|
58 | - * |
|
59 | - * @Constructor |
|
60 | - * @access private |
|
61 | - */ |
|
62 | - private function __construct() |
|
63 | - { |
|
64 | - do_action('AHEE__EE_Payment_Processor__construct'); |
|
65 | - add_action('http_api_curl', array($this, '_curl_requests_to_paypal_use_tls'), 10, 3); |
|
66 | - } |
|
67 | - |
|
68 | - |
|
69 | - |
|
70 | - /** |
|
71 | - * Using the selected gateway, processes the payment for that transaction, and updates the transaction |
|
72 | - * appropriately. Saves the payment that is generated |
|
73 | - * |
|
74 | - * @param EE_Payment_Method $payment_method |
|
75 | - * @param EE_Transaction $transaction |
|
76 | - * @param float $amount if only part of the transaction is to be paid for, how much. |
|
77 | - * Leave null if payment is for the full amount owing |
|
78 | - * @param EE_Billing_Info_Form $billing_form (or probably null, if it's an offline or offsite payment method). |
|
79 | - * Receive_form_submission() should have |
|
80 | - * already been called on the billing form |
|
81 | - * (ie, its inputs should have their normalized values set). |
|
82 | - * @param string $return_url string used mostly by offsite gateways to specify |
|
83 | - * where to go AFTER the offsite gateway |
|
84 | - * @param string $method like 'CART', indicates who the client who called this was |
|
85 | - * @param bool $by_admin TRUE if payment is being attempted from the admin |
|
86 | - * @param boolean $update_txn whether or not to call |
|
87 | - * EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment() |
|
88 | - * @param string $cancel_url URL to return to if off-site payments are cancelled |
|
89 | - * @return \EE_Payment |
|
90 | - * @throws \EE_Error |
|
91 | - */ |
|
92 | - public function process_payment( |
|
93 | - EE_Payment_Method $payment_method, |
|
94 | - EE_Transaction $transaction, |
|
95 | - $amount = null, |
|
96 | - $billing_form = null, |
|
97 | - $return_url = null, |
|
98 | - $method = 'CART', |
|
99 | - $by_admin = false, |
|
100 | - $update_txn = true, |
|
101 | - $cancel_url = '' |
|
102 | - ) { |
|
103 | - if ((float)$amount < 0) { |
|
104 | - throw new EE_Error( |
|
105 | - sprintf( |
|
106 | - __( |
|
107 | - 'Attempting to make a payment for a negative amount of %1$d for transaction %2$d. That should be a refund', |
|
108 | - 'event_espresso' |
|
109 | - ), |
|
110 | - $amount, |
|
111 | - $transaction->ID() |
|
112 | - ) |
|
113 | - ); |
|
114 | - } |
|
115 | - // verify payment method |
|
116 | - $payment_method = EEM_Payment_Method::instance()->ensure_is_obj($payment_method, true); |
|
117 | - // verify transaction |
|
118 | - EEM_Transaction::instance()->ensure_is_obj($transaction); |
|
119 | - $transaction->set_payment_method_ID($payment_method->ID()); |
|
120 | - // verify payment method type |
|
121 | - if ($payment_method->type_obj() instanceof EE_PMT_Base) { |
|
122 | - $payment = $payment_method->type_obj()->process_payment( |
|
123 | - $transaction, |
|
124 | - min($amount, $transaction->remaining()),//make sure we don't overcharge |
|
125 | - $billing_form, |
|
126 | - $return_url, |
|
127 | - add_query_arg(array('ee_cancel_payment' => true), $cancel_url), |
|
128 | - $method, |
|
129 | - $by_admin |
|
130 | - ); |
|
131 | - // check if payment method uses an off-site gateway |
|
132 | - if ($payment_method->type_obj()->payment_occurs() !== EE_PMT_Base::offsite) { |
|
133 | - // don't process payments for off-site gateways yet because no payment has occurred yet |
|
134 | - $this->update_txn_based_on_payment($transaction, $payment, $update_txn); |
|
135 | - } |
|
136 | - return $payment; |
|
137 | - } else { |
|
138 | - EE_Error::add_error( |
|
139 | - sprintf( |
|
140 | - __('A valid payment method could not be determined due to a technical issue.%sPlease try again or contact %s for assistance.', 'event_espresso'), |
|
141 | - '<br/>', |
|
142 | - EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
143 | - ), __FILE__, __FUNCTION__, __LINE__ |
|
144 | - ); |
|
145 | - return null; |
|
146 | - } |
|
147 | - } |
|
148 | - |
|
149 | - |
|
150 | - |
|
151 | - /** |
|
152 | - * @param EE_Transaction|int $transaction |
|
153 | - * @param EE_Payment_Method $payment_method |
|
154 | - * @throws EE_Error |
|
155 | - * @return string |
|
156 | - */ |
|
157 | - public function get_ipn_url_for_payment_method($transaction, $payment_method) |
|
158 | - { |
|
159 | - /** @type \EE_Transaction $transaction */ |
|
160 | - $transaction = EEM_Transaction::instance()->ensure_is_obj($transaction); |
|
161 | - $primary_reg = $transaction->primary_registration(); |
|
162 | - if ( ! $primary_reg instanceof EE_Registration) { |
|
163 | - throw new EE_Error( |
|
164 | - sprintf( |
|
165 | - __( |
|
166 | - "Cannot get IPN URL for transaction with ID %d because it has no primary registration", |
|
167 | - "event_espresso" |
|
168 | - ), |
|
169 | - $transaction->ID() |
|
170 | - ) |
|
171 | - ); |
|
172 | - } |
|
173 | - $payment_method = EEM_Payment_Method::instance()->ensure_is_obj($payment_method, true); |
|
174 | - $url = add_query_arg( |
|
175 | - array( |
|
176 | - 'e_reg_url_link' => $primary_reg->reg_url_link(), |
|
177 | - 'ee_payment_method' => $payment_method->slug(), |
|
178 | - ), |
|
179 | - EE_Registry::instance()->CFG->core->txn_page_url() |
|
180 | - ); |
|
181 | - return $url; |
|
182 | - } |
|
183 | - |
|
184 | - |
|
185 | - |
|
186 | - /** |
|
187 | - * Process the IPN. Firstly, we'll hope we put the standard args into the IPN URL so |
|
188 | - * we can easily find what registration the IPN is for and what payment method. |
|
189 | - * However, if not, we'll give all payment methods a chance to claim it and process it. |
|
190 | - * If a payment is found for the IPN info, it is saved. |
|
191 | - * |
|
192 | - * @param array $_req_data eg $_REQUEST |
|
193 | - * @param EE_Transaction|int $transaction optional (or a transactions id) |
|
194 | - * @param EE_Payment_Method $payment_method (or a slug or id of one) |
|
195 | - * @param boolean $update_txn whether or not to call |
|
196 | - * EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment() |
|
197 | - * @param bool $separate_IPN_request whether the IPN uses a separate request ( true like PayPal ) |
|
198 | - * or is processed manually ( false like Mijireh ) |
|
199 | - * @throws EE_Error |
|
200 | - * @throws Exception |
|
201 | - * @return EE_Payment |
|
202 | - */ |
|
203 | - public function process_ipn( |
|
204 | - $_req_data, |
|
205 | - $transaction = null, |
|
206 | - $payment_method = null, |
|
207 | - $update_txn = true, |
|
208 | - $separate_IPN_request = true |
|
209 | - ) { |
|
210 | - EE_Registry::instance()->load_model('Change_Log'); |
|
211 | - $_req_data = $this->_remove_unusable_characters_from_array((array)$_req_data); |
|
212 | - EE_Processor_Base::set_IPN($separate_IPN_request); |
|
213 | - $obj_for_log = null; |
|
214 | - if ($transaction instanceof EE_Transaction) { |
|
215 | - $obj_for_log = $transaction; |
|
216 | - if ($payment_method instanceof EE_Payment_Method) { |
|
217 | - $obj_for_log = EEM_Payment::instance()->get_one( |
|
218 | - array( |
|
219 | - array('TXN_ID' => $transaction->ID(), 'PMD_ID' => $payment_method->ID()), |
|
220 | - 'order_by' => array('PAY_timestamp' => 'desc'), |
|
221 | - ) |
|
222 | - ); |
|
223 | - } |
|
224 | - } else if ($payment_method instanceof EE_Payment) { |
|
225 | - $obj_for_log = $payment_method; |
|
226 | - } |
|
227 | - $log = EEM_Change_Log::instance()->log( |
|
228 | - EEM_Change_Log::type_gateway, |
|
229 | - array('IPN data received' => $_req_data), |
|
230 | - $obj_for_log |
|
231 | - ); |
|
232 | - try { |
|
233 | - /** |
|
234 | - * @var EE_Payment $payment |
|
235 | - */ |
|
236 | - $payment = null; |
|
237 | - if ($transaction && $payment_method) { |
|
238 | - /** @type EE_Transaction $transaction */ |
|
239 | - $transaction = EEM_Transaction::instance()->ensure_is_obj($transaction); |
|
240 | - /** @type EE_Payment_Method $payment_method */ |
|
241 | - $payment_method = EEM_Payment_Method::instance()->ensure_is_obj($payment_method); |
|
242 | - if ($payment_method->type_obj() instanceof EE_PMT_Base) { |
|
243 | - try { |
|
244 | - $payment = $payment_method->type_obj()->handle_ipn($_req_data, $transaction); |
|
245 | - $log->set_object($payment); |
|
246 | - } catch (EventEspresso\core\exceptions\IpnException $e) { |
|
247 | - EEM_Change_Log::instance()->log( |
|
248 | - EEM_Change_Log::type_gateway, |
|
249 | - array( |
|
250 | - 'message' => 'IPN Exception: ' . $e->getMessage(), |
|
251 | - 'current_url' => EEH_URL::current_url(), |
|
252 | - 'payment' => $e->getPaymentProperties(), |
|
253 | - 'IPN_data' => $e->getIpnData(), |
|
254 | - ), |
|
255 | - $obj_for_log |
|
256 | - ); |
|
257 | - return $e->getPayment(); |
|
258 | - } |
|
259 | - } else { |
|
260 | - // not a payment |
|
261 | - EE_Error::add_error( |
|
262 | - sprintf( |
|
263 | - __('A valid payment method could not be determined due to a technical issue.%sPlease refresh your browser and try again or contact %s for assistance.', 'event_espresso'), |
|
264 | - '<br/>', |
|
265 | - EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
266 | - ), |
|
267 | - __FILE__, __FUNCTION__, __LINE__ |
|
268 | - ); |
|
269 | - } |
|
270 | - } else { |
|
271 | - //that's actually pretty ok. The IPN just wasn't able |
|
272 | - //to identify which transaction or payment method this was for |
|
273 | - // give all active payment methods a chance to claim it |
|
274 | - $active_payment_methods = EEM_Payment_Method::instance()->get_all_active(); |
|
275 | - foreach ($active_payment_methods as $active_payment_method) { |
|
276 | - try { |
|
277 | - $payment = $active_payment_method->type_obj()->handle_unclaimed_ipn($_req_data); |
|
278 | - $payment_method = $active_payment_method; |
|
279 | - EEM_Change_Log::instance()->log( |
|
280 | - EEM_Change_Log::type_gateway, array('IPN data' => $_req_data), $payment |
|
281 | - ); |
|
282 | - break; |
|
283 | - } catch (EventEspresso\core\exceptions\IpnException $e) { |
|
284 | - EEM_Change_Log::instance()->log( |
|
285 | - EEM_Change_Log::type_gateway, |
|
286 | - array( |
|
287 | - 'message' => 'IPN Exception: ' . $e->getMessage(), |
|
288 | - 'current_url' => EEH_URL::current_url(), |
|
289 | - 'payment' => $e->getPaymentProperties(), |
|
290 | - 'IPN_data' => $e->getIpnData(), |
|
291 | - ), |
|
292 | - $obj_for_log |
|
293 | - ); |
|
294 | - return $e->getPayment(); |
|
295 | - } catch (EE_Error $e) { |
|
296 | - //that's fine- it apparently couldn't handle the IPN |
|
297 | - } |
|
298 | - } |
|
299 | - } |
|
300 | - // EEM_Payment_Log::instance()->log("got to 7",$transaction,$payment_method); |
|
301 | - if ($payment instanceof EE_Payment) { |
|
302 | - $payment->save(); |
|
303 | - // update the TXN |
|
304 | - $this->update_txn_based_on_payment($transaction, $payment, $update_txn, $separate_IPN_request); |
|
305 | - } else { |
|
306 | - //we couldn't find the payment for this IPN... let's try and log at least SOMETHING |
|
307 | - if ($payment_method) { |
|
308 | - EEM_Change_Log::instance()->log(EEM_Change_Log::type_gateway, array('IPN data' => $_req_data), $payment_method); |
|
309 | - } elseif ($transaction) { |
|
310 | - EEM_Change_Log::instance()->log(EEM_Change_Log::type_gateway, array('IPN data' => $_req_data), $transaction); |
|
311 | - } |
|
312 | - } |
|
313 | - return $payment; |
|
314 | - } catch (EE_Error $e) { |
|
315 | - do_action( |
|
316 | - 'AHEE__log', __FILE__, __FUNCTION__, sprintf( |
|
317 | - __('Error occurred while receiving IPN. Transaction: %1$s, req data: %2$s. The error was "%3$s"', 'event_espresso'), |
|
318 | - print_r($transaction, true), |
|
319 | - print_r($_req_data, true), |
|
320 | - $e->getMessage() |
|
321 | - ) |
|
322 | - ); |
|
323 | - throw $e; |
|
324 | - } |
|
325 | - } |
|
326 | - |
|
327 | - |
|
328 | - |
|
329 | - /** |
|
330 | - * Removes any non-printable illegal characters from the input, |
|
331 | - * which might cause a raucous when trying to insert into the database |
|
332 | - * |
|
333 | - * @param array $request_data |
|
334 | - * @return array |
|
335 | - */ |
|
336 | - protected function _remove_unusable_characters_from_array(array $request_data) |
|
337 | - { |
|
338 | - $return_data = array(); |
|
339 | - foreach ($request_data as $key => $value) { |
|
340 | - $return_data[$this->_remove_unusable_characters($key)] = $this->_remove_unusable_characters($value); |
|
341 | - } |
|
342 | - return $return_data; |
|
343 | - } |
|
344 | - |
|
345 | - |
|
346 | - |
|
347 | - /** |
|
348 | - * Removes any non-printable illegal characters from the input, |
|
349 | - * which might cause a raucous when trying to insert into the database |
|
350 | - * |
|
351 | - * @param string $request_data |
|
352 | - * @return string |
|
353 | - */ |
|
354 | - protected function _remove_unusable_characters($request_data) |
|
355 | - { |
|
356 | - return preg_replace('/[^[:print:]]/', '', $request_data); |
|
357 | - } |
|
358 | - |
|
359 | - |
|
360 | - |
|
361 | - /** |
|
362 | - * Should be called just before displaying the payment attempt results to the user, |
|
363 | - * when the payment attempt has finished. Some payment methods may have special |
|
364 | - * logic to perform here. For example, if process_payment() happens on a special request |
|
365 | - * and then the user is redirected to a page that displays the payment's status, this |
|
366 | - * should be called while loading the page that displays the payment's status. If the user is |
|
367 | - * sent to an offsite payment provider, this should be called upon returning from that offsite payment |
|
368 | - * provider. |
|
369 | - * |
|
370 | - * @param EE_Transaction|int $transaction |
|
371 | - * @param bool $update_txn whether or not to call |
|
372 | - * EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment() |
|
373 | - * @throws \EE_Error |
|
374 | - * @return EE_Payment |
|
375 | - * @deprecated 4.6.24 method is no longer used. Instead it is up to client code, like SPCO, |
|
376 | - * to call handle_ipn() for offsite gateways that don't receive separate IPNs |
|
377 | - */ |
|
378 | - public function finalize_payment_for($transaction, $update_txn = true) |
|
379 | - { |
|
380 | - /** @var $transaction EE_Transaction */ |
|
381 | - $transaction = EEM_Transaction::instance()->ensure_is_obj($transaction); |
|
382 | - $last_payment_method = $transaction->payment_method(); |
|
383 | - if ($last_payment_method instanceof EE_Payment_Method) { |
|
384 | - $payment = $last_payment_method->type_obj()->finalize_payment_for($transaction); |
|
385 | - $this->update_txn_based_on_payment($transaction, $payment, $update_txn); |
|
386 | - return $payment; |
|
387 | - } else { |
|
388 | - return null; |
|
389 | - } |
|
390 | - } |
|
391 | - |
|
392 | - |
|
393 | - |
|
394 | - /** |
|
395 | - * Processes a direct refund request, saves the payment, and updates the transaction appropriately. |
|
396 | - * |
|
397 | - * @param EE_Payment_Method $payment_method |
|
398 | - * @param EE_Payment $payment_to_refund |
|
399 | - * @param array $refund_info |
|
400 | - * @return EE_Payment |
|
401 | - * @throws \EE_Error |
|
402 | - */ |
|
403 | - public function process_refund( |
|
404 | - EE_Payment_Method $payment_method, |
|
405 | - EE_Payment $payment_to_refund, |
|
406 | - $refund_info = array() |
|
407 | - ) { |
|
408 | - if ($payment_method instanceof EE_Payment_Method && $payment_method->type_obj()->supports_sending_refunds()) { |
|
409 | - $payment_method->type_obj()->process_refund($payment_to_refund, $refund_info); |
|
410 | - $this->update_txn_based_on_payment($payment_to_refund->transaction(), $payment_to_refund); |
|
411 | - } |
|
412 | - return $payment_to_refund; |
|
413 | - } |
|
414 | - |
|
415 | - |
|
416 | - |
|
417 | - /** |
|
418 | - * This should be called each time there may have been an update to a |
|
419 | - * payment on a transaction (ie, we asked for a payment to process a |
|
420 | - * payment for a transaction, or we told a payment method about an IPN, or |
|
421 | - * we told a payment method to |
|
422 | - * "finalize_payment_for" (a transaction), or we told a payment method to |
|
423 | - * process a refund. This should handle firing the correct hooks to |
|
424 | - * indicate |
|
425 | - * what exactly happened and updating the transaction appropriately). This |
|
426 | - * could be integrated directly into EE_Transaction upon save, but we want |
|
427 | - * this logic to be separate from 'normal' plain-jane saving and updating |
|
428 | - * of transactions and payments, and to be tied to payment processing. |
|
429 | - * Note: this method DOES NOT save the payment passed into it. It is the responsibility |
|
430 | - * of previous code to decide whether or not to save (because the payment passed into |
|
431 | - * this method might be a temporary, never-to-be-saved payment from an offline gateway, |
|
432 | - * in which case we only want that payment object for some temporary usage during this request, |
|
433 | - * but we don't want it to be saved). |
|
434 | - * |
|
435 | - * @param EE_Transaction|int $transaction |
|
436 | - * @param EE_Payment $payment |
|
437 | - * @param boolean $update_txn |
|
438 | - * whether or not to call |
|
439 | - * EE_Transaction_Processor:: |
|
440 | - * update_transaction_and_registrations_after_checkout_or_payment() |
|
441 | - * (you can save 1 DB query if you know you're going |
|
442 | - * to save it later instead) |
|
443 | - * @param bool $IPN |
|
444 | - * if processing IPNs or other similar payment |
|
445 | - * related activities that occur in alternate |
|
446 | - * requests than the main one that is processing the |
|
447 | - * TXN, then set this to true to check whether the |
|
448 | - * TXN is locked before updating |
|
449 | - * @throws \EE_Error |
|
450 | - */ |
|
451 | - public function update_txn_based_on_payment($transaction, $payment, $update_txn = true, $IPN = false) |
|
452 | - { |
|
453 | - $do_action = 'AHEE__EE_Payment_Processor__update_txn_based_on_payment__not_successful'; |
|
454 | - /** @type EE_Transaction $transaction */ |
|
455 | - $transaction = EEM_Transaction::instance()->ensure_is_obj($transaction); |
|
456 | - // can we freely update the TXN at this moment? |
|
457 | - if ($IPN && $transaction->is_locked()) { |
|
458 | - // don't update the transaction at this exact moment |
|
459 | - // because the TXN is active in another request |
|
460 | - EE_Cron_Tasks::schedule_update_transaction_with_payment( |
|
461 | - time(), |
|
462 | - $transaction->ID(), |
|
463 | - $payment->ID() |
|
464 | - ); |
|
465 | - } else { |
|
466 | - // verify payment and that it has been saved |
|
467 | - if ($payment instanceof EE_Payment && $payment->ID()) { |
|
468 | - if ( |
|
469 | - $payment->payment_method() instanceof EE_Payment_Method |
|
470 | - && $payment->payment_method()->type_obj() instanceof EE_PMT_Base |
|
471 | - ) { |
|
472 | - $payment->payment_method()->type_obj()->update_txn_based_on_payment($payment); |
|
473 | - // update TXN registrations with payment info |
|
474 | - $this->process_registration_payments($transaction, $payment); |
|
475 | - } |
|
476 | - $do_action = $payment->just_approved() |
|
477 | - ? 'AHEE__EE_Payment_Processor__update_txn_based_on_payment__successful' |
|
478 | - : $do_action; |
|
479 | - } else { |
|
480 | - // send out notifications |
|
481 | - add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true'); |
|
482 | - $do_action = 'AHEE__EE_Payment_Processor__update_txn_based_on_payment__no_payment_made'; |
|
483 | - } |
|
484 | - if ($payment instanceof EE_Payment && $payment->status() !== EEM_Payment::status_id_failed) { |
|
485 | - /** @type EE_Transaction_Payments $transaction_payments */ |
|
486 | - $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments'); |
|
487 | - // set new value for total paid |
|
488 | - $transaction_payments->calculate_total_payments_and_update_status($transaction); |
|
489 | - // call EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment() ??? |
|
490 | - if ($update_txn) { |
|
491 | - $this->_post_payment_processing($transaction, $payment, $IPN); |
|
492 | - } |
|
493 | - } |
|
494 | - // granular hook for others to use. |
|
495 | - do_action($do_action, $transaction, $payment); |
|
496 | - do_action('AHEE_log', __CLASS__, __FUNCTION__, $do_action, '$do_action'); |
|
497 | - //global hook for others to use. |
|
498 | - do_action('AHEE__EE_Payment_Processor__update_txn_based_on_payment', $transaction, $payment); |
|
499 | - } |
|
500 | - } |
|
501 | - |
|
502 | - |
|
503 | - |
|
504 | - /** |
|
505 | - * update registrations REG_paid field after successful payment and link registrations with payment |
|
506 | - * |
|
507 | - * @param EE_Transaction $transaction |
|
508 | - * @param EE_Payment $payment |
|
509 | - * @param EE_Registration[] $registrations |
|
510 | - * @throws \EE_Error |
|
511 | - */ |
|
512 | - public function process_registration_payments( |
|
513 | - EE_Transaction $transaction, |
|
514 | - EE_Payment $payment, |
|
515 | - $registrations = array() |
|
516 | - ) { |
|
517 | - // only process if payment was successful |
|
518 | - if ($payment->status() !== EEM_Payment::status_id_approved) { |
|
519 | - return; |
|
520 | - } |
|
521 | - //EEM_Registration::instance()->show_next_x_db_queries(); |
|
522 | - if (empty($registrations)) { |
|
523 | - // find registrations with monies owing that can receive a payment |
|
524 | - $registrations = $transaction->registrations( |
|
525 | - array( |
|
526 | - array( |
|
527 | - // only these reg statuses can receive payments |
|
528 | - 'STS_ID' => array('IN', EEM_Registration::reg_statuses_that_allow_payment()), |
|
529 | - 'REG_final_price' => array('!=', 0), |
|
530 | - 'REG_final_price*' => array('!=', 'REG_paid', true), |
|
531 | - ), |
|
532 | - ) |
|
533 | - ); |
|
534 | - } |
|
535 | - // still nothing ??!?? |
|
536 | - if (empty($registrations)) { |
|
537 | - return; |
|
538 | - } |
|
539 | - // todo: break out the following logic into a separate strategy class |
|
540 | - // todo: named something like "Sequential_Reg_Payment_Strategy" |
|
541 | - // todo: which would apply payments using the capitalist "first come first paid" approach |
|
542 | - // todo: then have another strategy class like "Distributed_Reg_Payment_Strategy" |
|
543 | - // todo: which would be the socialist "everybody gets a piece of pie" approach, |
|
544 | - // todo: which would be better for deposits, where you want a bit of the payment applied to each registration |
|
545 | - $refund = $payment->is_a_refund(); |
|
546 | - // how much is available to apply to registrations? |
|
547 | - $available_payment_amount = abs($payment->amount()); |
|
548 | - foreach ($registrations as $registration) { |
|
549 | - if ($registration instanceof EE_Registration) { |
|
550 | - // nothing left? |
|
551 | - if ($available_payment_amount <= 0) { |
|
552 | - break; |
|
553 | - } |
|
554 | - if ($refund) { |
|
555 | - $available_payment_amount = $this->process_registration_refund($registration, $payment, $available_payment_amount); |
|
556 | - } else { |
|
557 | - $available_payment_amount = $this->process_registration_payment($registration, $payment, $available_payment_amount); |
|
558 | - } |
|
559 | - } |
|
560 | - } |
|
561 | - if ($available_payment_amount > 0 && apply_filters('FHEE__EE_Payment_Processor__process_registration_payments__display_notifications', false)) { |
|
562 | - EE_Error::add_attention( |
|
563 | - sprintf( |
|
564 | - __('A remainder of %1$s exists after applying this payment to Registration(s) %2$s.%3$sPlease verify that the original payment amount of %4$s is correct. If so, you should edit this payment and select at least one additional registration in the "Registrations to Apply Payment to" section, so that the remainder of this payment can be applied to the additional registration(s).', |
|
565 | - 'event_espresso'), |
|
566 | - EEH_Template::format_currency($available_payment_amount), |
|
567 | - implode(', ', array_keys($registrations)), |
|
568 | - '<br/>', |
|
569 | - EEH_Template::format_currency($payment->amount()) |
|
570 | - ), |
|
571 | - __FILE__, __FUNCTION__, __LINE__ |
|
572 | - ); |
|
573 | - } |
|
574 | - } |
|
575 | - |
|
576 | - |
|
577 | - |
|
578 | - /** |
|
579 | - * update registration REG_paid field after successful payment and link registration with payment |
|
580 | - * |
|
581 | - * @param EE_Registration $registration |
|
582 | - * @param EE_Payment $payment |
|
583 | - * @param float $available_payment_amount |
|
584 | - * @return float |
|
585 | - * @throws \EE_Error |
|
586 | - */ |
|
587 | - public function process_registration_payment( |
|
588 | - EE_Registration $registration, |
|
589 | - EE_Payment $payment, |
|
590 | - $available_payment_amount = 0.00 |
|
591 | - ) { |
|
592 | - $owing = $registration->final_price() - $registration->paid(); |
|
593 | - if ($owing > 0) { |
|
594 | - // don't allow payment amount to exceed the available payment amount, OR the amount owing |
|
595 | - $payment_amount = min($available_payment_amount, $owing); |
|
596 | - // update $available_payment_amount |
|
597 | - $available_payment_amount -= $payment_amount; |
|
598 | - //calculate and set new REG_paid |
|
599 | - $registration->set_paid($registration->paid() + $payment_amount); |
|
600 | - // now save it |
|
601 | - $this->_apply_registration_payment($registration, $payment, $payment_amount); |
|
602 | - } |
|
603 | - return $available_payment_amount; |
|
604 | - } |
|
605 | - |
|
606 | - |
|
607 | - |
|
608 | - /** |
|
609 | - * update registration REG_paid field after successful payment and link registration with payment |
|
610 | - * |
|
611 | - * @param EE_Registration $registration |
|
612 | - * @param EE_Payment $payment |
|
613 | - * @param float $payment_amount |
|
614 | - * @return void |
|
615 | - * @throws \EE_Error |
|
616 | - */ |
|
617 | - protected function _apply_registration_payment( |
|
618 | - EE_Registration $registration, |
|
619 | - EE_Payment $payment, |
|
620 | - $payment_amount = 0.00 |
|
621 | - ) { |
|
622 | - // find any existing reg payment records for this registration and payment |
|
623 | - $existing_reg_payment = EEM_Registration_Payment::instance()->get_one( |
|
624 | - array(array('REG_ID' => $registration->ID(), 'PAY_ID' => $payment->ID())) |
|
625 | - ); |
|
626 | - // if existing registration payment exists |
|
627 | - if ($existing_reg_payment instanceof EE_Registration_Payment) { |
|
628 | - // then update that record |
|
629 | - $existing_reg_payment->set_amount($payment_amount); |
|
630 | - $existing_reg_payment->save(); |
|
631 | - } else { |
|
632 | - // or add new relation between registration and payment and set amount |
|
633 | - $registration->_add_relation_to($payment, 'Payment', array('RPY_amount' => $payment_amount)); |
|
634 | - // make it stick |
|
635 | - $registration->save(); |
|
636 | - } |
|
637 | - } |
|
638 | - |
|
639 | - |
|
640 | - |
|
641 | - /** |
|
642 | - * update registration REG_paid field after refund and link registration with payment |
|
643 | - * |
|
644 | - * @param EE_Registration $registration |
|
645 | - * @param EE_Payment $payment |
|
646 | - * @param float $available_refund_amount - IMPORTANT !!! SEND AVAILABLE REFUND AMOUNT AS A POSITIVE NUMBER |
|
647 | - * @return float |
|
648 | - * @throws \EE_Error |
|
649 | - */ |
|
650 | - public function process_registration_refund( |
|
651 | - EE_Registration $registration, |
|
652 | - EE_Payment $payment, |
|
653 | - $available_refund_amount = 0.00 |
|
654 | - ) { |
|
655 | - //EEH_Debug_Tools::printr( $payment->amount(), '$payment->amount()', __FILE__, __LINE__ ); |
|
656 | - if ($registration->paid() > 0) { |
|
657 | - // ensure $available_refund_amount is NOT negative |
|
658 | - $available_refund_amount = (float)abs($available_refund_amount); |
|
659 | - // don't allow refund amount to exceed the available payment amount, OR the amount paid |
|
660 | - $refund_amount = min($available_refund_amount, (float)$registration->paid()); |
|
661 | - // update $available_payment_amount |
|
662 | - $available_refund_amount -= $refund_amount; |
|
663 | - //calculate and set new REG_paid |
|
664 | - $registration->set_paid($registration->paid() - $refund_amount); |
|
665 | - // convert payment amount back to a negative value for storage in the db |
|
666 | - $refund_amount = (float)abs($refund_amount) * -1; |
|
667 | - // now save it |
|
668 | - $this->_apply_registration_payment($registration, $payment, $refund_amount); |
|
669 | - } |
|
670 | - return $available_refund_amount; |
|
671 | - } |
|
672 | - |
|
673 | - |
|
674 | - |
|
675 | - /** |
|
676 | - * Process payments and transaction after payment process completed. |
|
677 | - * ultimately this will send the TXN and payment details off so that notifications can be sent out. |
|
678 | - * if this request happens to be processing an IPN, |
|
679 | - * then we will also set the Payment Options Reg Step to completed, |
|
680 | - * and attempt to completely finalize the TXN if all of the other Reg Steps are completed as well. |
|
681 | - * |
|
682 | - * @param EE_Transaction $transaction |
|
683 | - * @param EE_Payment $payment |
|
684 | - * @param bool $IPN |
|
685 | - * @throws \EE_Error |
|
686 | - */ |
|
687 | - protected function _post_payment_processing(EE_Transaction $transaction, EE_Payment $payment, $IPN = false) |
|
688 | - { |
|
689 | - /** @type EE_Transaction_Processor $transaction_processor */ |
|
690 | - $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor'); |
|
691 | - // is the Payment Options Reg Step completed ? |
|
692 | - $payment_options_step_completed = $transaction->reg_step_completed('payment_options'); |
|
693 | - // if the Payment Options Reg Step is completed... |
|
694 | - $revisit = $payment_options_step_completed === true ? true : false; |
|
695 | - // then this is kinda sorta a revisit with regards to payments at least |
|
696 | - $transaction_processor->set_revisit($revisit); |
|
697 | - // if this is an IPN, let's consider the Payment Options Reg Step completed if not already |
|
698 | - if ( |
|
699 | - $IPN |
|
700 | - && $payment_options_step_completed !== true |
|
701 | - && ($payment->is_approved() || $payment->is_pending()) |
|
702 | - ) { |
|
703 | - $payment_options_step_completed = $transaction->set_reg_step_completed( |
|
704 | - 'payment_options' |
|
705 | - ); |
|
706 | - } |
|
707 | - // maybe update status, but don't save transaction just yet |
|
708 | - $transaction->update_status_based_on_total_paid(false); |
|
709 | - // check if 'finalize_registration' step has been completed... |
|
710 | - $finalized = $transaction->reg_step_completed('finalize_registration'); |
|
711 | - // if this is an IPN and the final step has not been initiated |
|
712 | - if ($IPN && $payment_options_step_completed && $finalized === false) { |
|
713 | - // and if it hasn't already been set as being started... |
|
714 | - $finalized = $transaction->set_reg_step_initiated('finalize_registration'); |
|
715 | - } |
|
716 | - $transaction->save(); |
|
717 | - // because the above will return false if the final step was not fully completed, we need to check again... |
|
718 | - if ($IPN && $finalized !== false) { |
|
719 | - // and if we are all good to go, then send out notifications |
|
720 | - add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true'); |
|
721 | - //ok, now process the transaction according to the payment |
|
722 | - $transaction_processor->update_transaction_and_registrations_after_checkout_or_payment($transaction, $payment); |
|
723 | - } |
|
724 | - // DEBUG LOG |
|
725 | - $payment_method = $payment->payment_method(); |
|
726 | - if ($payment_method instanceof EE_Payment_Method) { |
|
727 | - $payment_method_type_obj = $payment_method->type_obj(); |
|
728 | - if ($payment_method_type_obj instanceof EE_PMT_Base) { |
|
729 | - $gateway = $payment_method_type_obj->get_gateway(); |
|
730 | - if ($gateway instanceof EE_Gateway) { |
|
731 | - $gateway->log( |
|
732 | - array( |
|
733 | - 'message' => __('Post Payment Transaction Details', 'event_espresso'), |
|
734 | - 'transaction' => $transaction->model_field_array(), |
|
735 | - 'finalized' => $finalized, |
|
736 | - 'IPN' => $IPN, |
|
737 | - 'deliver_notifications' => has_filter( |
|
738 | - 'FHEE__EED_Messages___maybe_registration__deliver_notifications' |
|
739 | - ), |
|
740 | - ), |
|
741 | - $payment |
|
742 | - ); |
|
743 | - } |
|
744 | - } |
|
745 | - } |
|
746 | - } |
|
747 | - |
|
748 | - |
|
749 | - |
|
750 | - /** |
|
751 | - * Force posts to PayPal to use TLS v1.2. See: |
|
752 | - * https://core.trac.wordpress.org/ticket/36320 |
|
753 | - * https://core.trac.wordpress.org/ticket/34924#comment:15 |
|
754 | - * https://www.paypal-knowledge.com/infocenter/index?page=content&widgetview=true&id=FAQ1914&viewlocale=en_US |
|
755 | - * This will affect paypal standard, pro, express, and payflow. |
|
756 | - */ |
|
757 | - public static function _curl_requests_to_paypal_use_tls($handle, $r, $url) |
|
758 | - { |
|
759 | - if (strstr($url, 'https://') && strstr($url, '.paypal.com')) { |
|
760 | - //Use the value of the constant CURL_SSLVERSION_TLSv1 = 1 |
|
761 | - //instead of the constant because it might not be defined |
|
762 | - curl_setopt($handle, CURLOPT_SSLVERSION, 1); |
|
763 | - } |
|
764 | - } |
|
21 | + /** |
|
22 | + * @var EE_Payment_Processor $_instance |
|
23 | + * @access private |
|
24 | + */ |
|
25 | + private static $_instance; |
|
26 | + |
|
27 | + |
|
28 | + |
|
29 | + /** |
|
30 | + * @singleton method used to instantiate class object |
|
31 | + * @access public |
|
32 | + * @return EE_Payment_Processor instance |
|
33 | + */ |
|
34 | + public static function instance() |
|
35 | + { |
|
36 | + // check if class object is instantiated |
|
37 | + if ( ! self::$_instance instanceof EE_Payment_Processor) { |
|
38 | + self::$_instance = new self(); |
|
39 | + } |
|
40 | + return self::$_instance; |
|
41 | + } |
|
42 | + |
|
43 | + |
|
44 | + |
|
45 | + /** |
|
46 | + * @return EE_Payment_Processor |
|
47 | + */ |
|
48 | + public static function reset() |
|
49 | + { |
|
50 | + self::$_instance = null; |
|
51 | + return self::instance(); |
|
52 | + } |
|
53 | + |
|
54 | + |
|
55 | + |
|
56 | + /** |
|
57 | + *private constructor to prevent direct creation |
|
58 | + * |
|
59 | + * @Constructor |
|
60 | + * @access private |
|
61 | + */ |
|
62 | + private function __construct() |
|
63 | + { |
|
64 | + do_action('AHEE__EE_Payment_Processor__construct'); |
|
65 | + add_action('http_api_curl', array($this, '_curl_requests_to_paypal_use_tls'), 10, 3); |
|
66 | + } |
|
67 | + |
|
68 | + |
|
69 | + |
|
70 | + /** |
|
71 | + * Using the selected gateway, processes the payment for that transaction, and updates the transaction |
|
72 | + * appropriately. Saves the payment that is generated |
|
73 | + * |
|
74 | + * @param EE_Payment_Method $payment_method |
|
75 | + * @param EE_Transaction $transaction |
|
76 | + * @param float $amount if only part of the transaction is to be paid for, how much. |
|
77 | + * Leave null if payment is for the full amount owing |
|
78 | + * @param EE_Billing_Info_Form $billing_form (or probably null, if it's an offline or offsite payment method). |
|
79 | + * Receive_form_submission() should have |
|
80 | + * already been called on the billing form |
|
81 | + * (ie, its inputs should have their normalized values set). |
|
82 | + * @param string $return_url string used mostly by offsite gateways to specify |
|
83 | + * where to go AFTER the offsite gateway |
|
84 | + * @param string $method like 'CART', indicates who the client who called this was |
|
85 | + * @param bool $by_admin TRUE if payment is being attempted from the admin |
|
86 | + * @param boolean $update_txn whether or not to call |
|
87 | + * EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment() |
|
88 | + * @param string $cancel_url URL to return to if off-site payments are cancelled |
|
89 | + * @return \EE_Payment |
|
90 | + * @throws \EE_Error |
|
91 | + */ |
|
92 | + public function process_payment( |
|
93 | + EE_Payment_Method $payment_method, |
|
94 | + EE_Transaction $transaction, |
|
95 | + $amount = null, |
|
96 | + $billing_form = null, |
|
97 | + $return_url = null, |
|
98 | + $method = 'CART', |
|
99 | + $by_admin = false, |
|
100 | + $update_txn = true, |
|
101 | + $cancel_url = '' |
|
102 | + ) { |
|
103 | + if ((float)$amount < 0) { |
|
104 | + throw new EE_Error( |
|
105 | + sprintf( |
|
106 | + __( |
|
107 | + 'Attempting to make a payment for a negative amount of %1$d for transaction %2$d. That should be a refund', |
|
108 | + 'event_espresso' |
|
109 | + ), |
|
110 | + $amount, |
|
111 | + $transaction->ID() |
|
112 | + ) |
|
113 | + ); |
|
114 | + } |
|
115 | + // verify payment method |
|
116 | + $payment_method = EEM_Payment_Method::instance()->ensure_is_obj($payment_method, true); |
|
117 | + // verify transaction |
|
118 | + EEM_Transaction::instance()->ensure_is_obj($transaction); |
|
119 | + $transaction->set_payment_method_ID($payment_method->ID()); |
|
120 | + // verify payment method type |
|
121 | + if ($payment_method->type_obj() instanceof EE_PMT_Base) { |
|
122 | + $payment = $payment_method->type_obj()->process_payment( |
|
123 | + $transaction, |
|
124 | + min($amount, $transaction->remaining()),//make sure we don't overcharge |
|
125 | + $billing_form, |
|
126 | + $return_url, |
|
127 | + add_query_arg(array('ee_cancel_payment' => true), $cancel_url), |
|
128 | + $method, |
|
129 | + $by_admin |
|
130 | + ); |
|
131 | + // check if payment method uses an off-site gateway |
|
132 | + if ($payment_method->type_obj()->payment_occurs() !== EE_PMT_Base::offsite) { |
|
133 | + // don't process payments for off-site gateways yet because no payment has occurred yet |
|
134 | + $this->update_txn_based_on_payment($transaction, $payment, $update_txn); |
|
135 | + } |
|
136 | + return $payment; |
|
137 | + } else { |
|
138 | + EE_Error::add_error( |
|
139 | + sprintf( |
|
140 | + __('A valid payment method could not be determined due to a technical issue.%sPlease try again or contact %s for assistance.', 'event_espresso'), |
|
141 | + '<br/>', |
|
142 | + EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
143 | + ), __FILE__, __FUNCTION__, __LINE__ |
|
144 | + ); |
|
145 | + return null; |
|
146 | + } |
|
147 | + } |
|
148 | + |
|
149 | + |
|
150 | + |
|
151 | + /** |
|
152 | + * @param EE_Transaction|int $transaction |
|
153 | + * @param EE_Payment_Method $payment_method |
|
154 | + * @throws EE_Error |
|
155 | + * @return string |
|
156 | + */ |
|
157 | + public function get_ipn_url_for_payment_method($transaction, $payment_method) |
|
158 | + { |
|
159 | + /** @type \EE_Transaction $transaction */ |
|
160 | + $transaction = EEM_Transaction::instance()->ensure_is_obj($transaction); |
|
161 | + $primary_reg = $transaction->primary_registration(); |
|
162 | + if ( ! $primary_reg instanceof EE_Registration) { |
|
163 | + throw new EE_Error( |
|
164 | + sprintf( |
|
165 | + __( |
|
166 | + "Cannot get IPN URL for transaction with ID %d because it has no primary registration", |
|
167 | + "event_espresso" |
|
168 | + ), |
|
169 | + $transaction->ID() |
|
170 | + ) |
|
171 | + ); |
|
172 | + } |
|
173 | + $payment_method = EEM_Payment_Method::instance()->ensure_is_obj($payment_method, true); |
|
174 | + $url = add_query_arg( |
|
175 | + array( |
|
176 | + 'e_reg_url_link' => $primary_reg->reg_url_link(), |
|
177 | + 'ee_payment_method' => $payment_method->slug(), |
|
178 | + ), |
|
179 | + EE_Registry::instance()->CFG->core->txn_page_url() |
|
180 | + ); |
|
181 | + return $url; |
|
182 | + } |
|
183 | + |
|
184 | + |
|
185 | + |
|
186 | + /** |
|
187 | + * Process the IPN. Firstly, we'll hope we put the standard args into the IPN URL so |
|
188 | + * we can easily find what registration the IPN is for and what payment method. |
|
189 | + * However, if not, we'll give all payment methods a chance to claim it and process it. |
|
190 | + * If a payment is found for the IPN info, it is saved. |
|
191 | + * |
|
192 | + * @param array $_req_data eg $_REQUEST |
|
193 | + * @param EE_Transaction|int $transaction optional (or a transactions id) |
|
194 | + * @param EE_Payment_Method $payment_method (or a slug or id of one) |
|
195 | + * @param boolean $update_txn whether or not to call |
|
196 | + * EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment() |
|
197 | + * @param bool $separate_IPN_request whether the IPN uses a separate request ( true like PayPal ) |
|
198 | + * or is processed manually ( false like Mijireh ) |
|
199 | + * @throws EE_Error |
|
200 | + * @throws Exception |
|
201 | + * @return EE_Payment |
|
202 | + */ |
|
203 | + public function process_ipn( |
|
204 | + $_req_data, |
|
205 | + $transaction = null, |
|
206 | + $payment_method = null, |
|
207 | + $update_txn = true, |
|
208 | + $separate_IPN_request = true |
|
209 | + ) { |
|
210 | + EE_Registry::instance()->load_model('Change_Log'); |
|
211 | + $_req_data = $this->_remove_unusable_characters_from_array((array)$_req_data); |
|
212 | + EE_Processor_Base::set_IPN($separate_IPN_request); |
|
213 | + $obj_for_log = null; |
|
214 | + if ($transaction instanceof EE_Transaction) { |
|
215 | + $obj_for_log = $transaction; |
|
216 | + if ($payment_method instanceof EE_Payment_Method) { |
|
217 | + $obj_for_log = EEM_Payment::instance()->get_one( |
|
218 | + array( |
|
219 | + array('TXN_ID' => $transaction->ID(), 'PMD_ID' => $payment_method->ID()), |
|
220 | + 'order_by' => array('PAY_timestamp' => 'desc'), |
|
221 | + ) |
|
222 | + ); |
|
223 | + } |
|
224 | + } else if ($payment_method instanceof EE_Payment) { |
|
225 | + $obj_for_log = $payment_method; |
|
226 | + } |
|
227 | + $log = EEM_Change_Log::instance()->log( |
|
228 | + EEM_Change_Log::type_gateway, |
|
229 | + array('IPN data received' => $_req_data), |
|
230 | + $obj_for_log |
|
231 | + ); |
|
232 | + try { |
|
233 | + /** |
|
234 | + * @var EE_Payment $payment |
|
235 | + */ |
|
236 | + $payment = null; |
|
237 | + if ($transaction && $payment_method) { |
|
238 | + /** @type EE_Transaction $transaction */ |
|
239 | + $transaction = EEM_Transaction::instance()->ensure_is_obj($transaction); |
|
240 | + /** @type EE_Payment_Method $payment_method */ |
|
241 | + $payment_method = EEM_Payment_Method::instance()->ensure_is_obj($payment_method); |
|
242 | + if ($payment_method->type_obj() instanceof EE_PMT_Base) { |
|
243 | + try { |
|
244 | + $payment = $payment_method->type_obj()->handle_ipn($_req_data, $transaction); |
|
245 | + $log->set_object($payment); |
|
246 | + } catch (EventEspresso\core\exceptions\IpnException $e) { |
|
247 | + EEM_Change_Log::instance()->log( |
|
248 | + EEM_Change_Log::type_gateway, |
|
249 | + array( |
|
250 | + 'message' => 'IPN Exception: ' . $e->getMessage(), |
|
251 | + 'current_url' => EEH_URL::current_url(), |
|
252 | + 'payment' => $e->getPaymentProperties(), |
|
253 | + 'IPN_data' => $e->getIpnData(), |
|
254 | + ), |
|
255 | + $obj_for_log |
|
256 | + ); |
|
257 | + return $e->getPayment(); |
|
258 | + } |
|
259 | + } else { |
|
260 | + // not a payment |
|
261 | + EE_Error::add_error( |
|
262 | + sprintf( |
|
263 | + __('A valid payment method could not be determined due to a technical issue.%sPlease refresh your browser and try again or contact %s for assistance.', 'event_espresso'), |
|
264 | + '<br/>', |
|
265 | + EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
266 | + ), |
|
267 | + __FILE__, __FUNCTION__, __LINE__ |
|
268 | + ); |
|
269 | + } |
|
270 | + } else { |
|
271 | + //that's actually pretty ok. The IPN just wasn't able |
|
272 | + //to identify which transaction or payment method this was for |
|
273 | + // give all active payment methods a chance to claim it |
|
274 | + $active_payment_methods = EEM_Payment_Method::instance()->get_all_active(); |
|
275 | + foreach ($active_payment_methods as $active_payment_method) { |
|
276 | + try { |
|
277 | + $payment = $active_payment_method->type_obj()->handle_unclaimed_ipn($_req_data); |
|
278 | + $payment_method = $active_payment_method; |
|
279 | + EEM_Change_Log::instance()->log( |
|
280 | + EEM_Change_Log::type_gateway, array('IPN data' => $_req_data), $payment |
|
281 | + ); |
|
282 | + break; |
|
283 | + } catch (EventEspresso\core\exceptions\IpnException $e) { |
|
284 | + EEM_Change_Log::instance()->log( |
|
285 | + EEM_Change_Log::type_gateway, |
|
286 | + array( |
|
287 | + 'message' => 'IPN Exception: ' . $e->getMessage(), |
|
288 | + 'current_url' => EEH_URL::current_url(), |
|
289 | + 'payment' => $e->getPaymentProperties(), |
|
290 | + 'IPN_data' => $e->getIpnData(), |
|
291 | + ), |
|
292 | + $obj_for_log |
|
293 | + ); |
|
294 | + return $e->getPayment(); |
|
295 | + } catch (EE_Error $e) { |
|
296 | + //that's fine- it apparently couldn't handle the IPN |
|
297 | + } |
|
298 | + } |
|
299 | + } |
|
300 | + // EEM_Payment_Log::instance()->log("got to 7",$transaction,$payment_method); |
|
301 | + if ($payment instanceof EE_Payment) { |
|
302 | + $payment->save(); |
|
303 | + // update the TXN |
|
304 | + $this->update_txn_based_on_payment($transaction, $payment, $update_txn, $separate_IPN_request); |
|
305 | + } else { |
|
306 | + //we couldn't find the payment for this IPN... let's try and log at least SOMETHING |
|
307 | + if ($payment_method) { |
|
308 | + EEM_Change_Log::instance()->log(EEM_Change_Log::type_gateway, array('IPN data' => $_req_data), $payment_method); |
|
309 | + } elseif ($transaction) { |
|
310 | + EEM_Change_Log::instance()->log(EEM_Change_Log::type_gateway, array('IPN data' => $_req_data), $transaction); |
|
311 | + } |
|
312 | + } |
|
313 | + return $payment; |
|
314 | + } catch (EE_Error $e) { |
|
315 | + do_action( |
|
316 | + 'AHEE__log', __FILE__, __FUNCTION__, sprintf( |
|
317 | + __('Error occurred while receiving IPN. Transaction: %1$s, req data: %2$s. The error was "%3$s"', 'event_espresso'), |
|
318 | + print_r($transaction, true), |
|
319 | + print_r($_req_data, true), |
|
320 | + $e->getMessage() |
|
321 | + ) |
|
322 | + ); |
|
323 | + throw $e; |
|
324 | + } |
|
325 | + } |
|
326 | + |
|
327 | + |
|
328 | + |
|
329 | + /** |
|
330 | + * Removes any non-printable illegal characters from the input, |
|
331 | + * which might cause a raucous when trying to insert into the database |
|
332 | + * |
|
333 | + * @param array $request_data |
|
334 | + * @return array |
|
335 | + */ |
|
336 | + protected function _remove_unusable_characters_from_array(array $request_data) |
|
337 | + { |
|
338 | + $return_data = array(); |
|
339 | + foreach ($request_data as $key => $value) { |
|
340 | + $return_data[$this->_remove_unusable_characters($key)] = $this->_remove_unusable_characters($value); |
|
341 | + } |
|
342 | + return $return_data; |
|
343 | + } |
|
344 | + |
|
345 | + |
|
346 | + |
|
347 | + /** |
|
348 | + * Removes any non-printable illegal characters from the input, |
|
349 | + * which might cause a raucous when trying to insert into the database |
|
350 | + * |
|
351 | + * @param string $request_data |
|
352 | + * @return string |
|
353 | + */ |
|
354 | + protected function _remove_unusable_characters($request_data) |
|
355 | + { |
|
356 | + return preg_replace('/[^[:print:]]/', '', $request_data); |
|
357 | + } |
|
358 | + |
|
359 | + |
|
360 | + |
|
361 | + /** |
|
362 | + * Should be called just before displaying the payment attempt results to the user, |
|
363 | + * when the payment attempt has finished. Some payment methods may have special |
|
364 | + * logic to perform here. For example, if process_payment() happens on a special request |
|
365 | + * and then the user is redirected to a page that displays the payment's status, this |
|
366 | + * should be called while loading the page that displays the payment's status. If the user is |
|
367 | + * sent to an offsite payment provider, this should be called upon returning from that offsite payment |
|
368 | + * provider. |
|
369 | + * |
|
370 | + * @param EE_Transaction|int $transaction |
|
371 | + * @param bool $update_txn whether or not to call |
|
372 | + * EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment() |
|
373 | + * @throws \EE_Error |
|
374 | + * @return EE_Payment |
|
375 | + * @deprecated 4.6.24 method is no longer used. Instead it is up to client code, like SPCO, |
|
376 | + * to call handle_ipn() for offsite gateways that don't receive separate IPNs |
|
377 | + */ |
|
378 | + public function finalize_payment_for($transaction, $update_txn = true) |
|
379 | + { |
|
380 | + /** @var $transaction EE_Transaction */ |
|
381 | + $transaction = EEM_Transaction::instance()->ensure_is_obj($transaction); |
|
382 | + $last_payment_method = $transaction->payment_method(); |
|
383 | + if ($last_payment_method instanceof EE_Payment_Method) { |
|
384 | + $payment = $last_payment_method->type_obj()->finalize_payment_for($transaction); |
|
385 | + $this->update_txn_based_on_payment($transaction, $payment, $update_txn); |
|
386 | + return $payment; |
|
387 | + } else { |
|
388 | + return null; |
|
389 | + } |
|
390 | + } |
|
391 | + |
|
392 | + |
|
393 | + |
|
394 | + /** |
|
395 | + * Processes a direct refund request, saves the payment, and updates the transaction appropriately. |
|
396 | + * |
|
397 | + * @param EE_Payment_Method $payment_method |
|
398 | + * @param EE_Payment $payment_to_refund |
|
399 | + * @param array $refund_info |
|
400 | + * @return EE_Payment |
|
401 | + * @throws \EE_Error |
|
402 | + */ |
|
403 | + public function process_refund( |
|
404 | + EE_Payment_Method $payment_method, |
|
405 | + EE_Payment $payment_to_refund, |
|
406 | + $refund_info = array() |
|
407 | + ) { |
|
408 | + if ($payment_method instanceof EE_Payment_Method && $payment_method->type_obj()->supports_sending_refunds()) { |
|
409 | + $payment_method->type_obj()->process_refund($payment_to_refund, $refund_info); |
|
410 | + $this->update_txn_based_on_payment($payment_to_refund->transaction(), $payment_to_refund); |
|
411 | + } |
|
412 | + return $payment_to_refund; |
|
413 | + } |
|
414 | + |
|
415 | + |
|
416 | + |
|
417 | + /** |
|
418 | + * This should be called each time there may have been an update to a |
|
419 | + * payment on a transaction (ie, we asked for a payment to process a |
|
420 | + * payment for a transaction, or we told a payment method about an IPN, or |
|
421 | + * we told a payment method to |
|
422 | + * "finalize_payment_for" (a transaction), or we told a payment method to |
|
423 | + * process a refund. This should handle firing the correct hooks to |
|
424 | + * indicate |
|
425 | + * what exactly happened and updating the transaction appropriately). This |
|
426 | + * could be integrated directly into EE_Transaction upon save, but we want |
|
427 | + * this logic to be separate from 'normal' plain-jane saving and updating |
|
428 | + * of transactions and payments, and to be tied to payment processing. |
|
429 | + * Note: this method DOES NOT save the payment passed into it. It is the responsibility |
|
430 | + * of previous code to decide whether or not to save (because the payment passed into |
|
431 | + * this method might be a temporary, never-to-be-saved payment from an offline gateway, |
|
432 | + * in which case we only want that payment object for some temporary usage during this request, |
|
433 | + * but we don't want it to be saved). |
|
434 | + * |
|
435 | + * @param EE_Transaction|int $transaction |
|
436 | + * @param EE_Payment $payment |
|
437 | + * @param boolean $update_txn |
|
438 | + * whether or not to call |
|
439 | + * EE_Transaction_Processor:: |
|
440 | + * update_transaction_and_registrations_after_checkout_or_payment() |
|
441 | + * (you can save 1 DB query if you know you're going |
|
442 | + * to save it later instead) |
|
443 | + * @param bool $IPN |
|
444 | + * if processing IPNs or other similar payment |
|
445 | + * related activities that occur in alternate |
|
446 | + * requests than the main one that is processing the |
|
447 | + * TXN, then set this to true to check whether the |
|
448 | + * TXN is locked before updating |
|
449 | + * @throws \EE_Error |
|
450 | + */ |
|
451 | + public function update_txn_based_on_payment($transaction, $payment, $update_txn = true, $IPN = false) |
|
452 | + { |
|
453 | + $do_action = 'AHEE__EE_Payment_Processor__update_txn_based_on_payment__not_successful'; |
|
454 | + /** @type EE_Transaction $transaction */ |
|
455 | + $transaction = EEM_Transaction::instance()->ensure_is_obj($transaction); |
|
456 | + // can we freely update the TXN at this moment? |
|
457 | + if ($IPN && $transaction->is_locked()) { |
|
458 | + // don't update the transaction at this exact moment |
|
459 | + // because the TXN is active in another request |
|
460 | + EE_Cron_Tasks::schedule_update_transaction_with_payment( |
|
461 | + time(), |
|
462 | + $transaction->ID(), |
|
463 | + $payment->ID() |
|
464 | + ); |
|
465 | + } else { |
|
466 | + // verify payment and that it has been saved |
|
467 | + if ($payment instanceof EE_Payment && $payment->ID()) { |
|
468 | + if ( |
|
469 | + $payment->payment_method() instanceof EE_Payment_Method |
|
470 | + && $payment->payment_method()->type_obj() instanceof EE_PMT_Base |
|
471 | + ) { |
|
472 | + $payment->payment_method()->type_obj()->update_txn_based_on_payment($payment); |
|
473 | + // update TXN registrations with payment info |
|
474 | + $this->process_registration_payments($transaction, $payment); |
|
475 | + } |
|
476 | + $do_action = $payment->just_approved() |
|
477 | + ? 'AHEE__EE_Payment_Processor__update_txn_based_on_payment__successful' |
|
478 | + : $do_action; |
|
479 | + } else { |
|
480 | + // send out notifications |
|
481 | + add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true'); |
|
482 | + $do_action = 'AHEE__EE_Payment_Processor__update_txn_based_on_payment__no_payment_made'; |
|
483 | + } |
|
484 | + if ($payment instanceof EE_Payment && $payment->status() !== EEM_Payment::status_id_failed) { |
|
485 | + /** @type EE_Transaction_Payments $transaction_payments */ |
|
486 | + $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments'); |
|
487 | + // set new value for total paid |
|
488 | + $transaction_payments->calculate_total_payments_and_update_status($transaction); |
|
489 | + // call EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment() ??? |
|
490 | + if ($update_txn) { |
|
491 | + $this->_post_payment_processing($transaction, $payment, $IPN); |
|
492 | + } |
|
493 | + } |
|
494 | + // granular hook for others to use. |
|
495 | + do_action($do_action, $transaction, $payment); |
|
496 | + do_action('AHEE_log', __CLASS__, __FUNCTION__, $do_action, '$do_action'); |
|
497 | + //global hook for others to use. |
|
498 | + do_action('AHEE__EE_Payment_Processor__update_txn_based_on_payment', $transaction, $payment); |
|
499 | + } |
|
500 | + } |
|
501 | + |
|
502 | + |
|
503 | + |
|
504 | + /** |
|
505 | + * update registrations REG_paid field after successful payment and link registrations with payment |
|
506 | + * |
|
507 | + * @param EE_Transaction $transaction |
|
508 | + * @param EE_Payment $payment |
|
509 | + * @param EE_Registration[] $registrations |
|
510 | + * @throws \EE_Error |
|
511 | + */ |
|
512 | + public function process_registration_payments( |
|
513 | + EE_Transaction $transaction, |
|
514 | + EE_Payment $payment, |
|
515 | + $registrations = array() |
|
516 | + ) { |
|
517 | + // only process if payment was successful |
|
518 | + if ($payment->status() !== EEM_Payment::status_id_approved) { |
|
519 | + return; |
|
520 | + } |
|
521 | + //EEM_Registration::instance()->show_next_x_db_queries(); |
|
522 | + if (empty($registrations)) { |
|
523 | + // find registrations with monies owing that can receive a payment |
|
524 | + $registrations = $transaction->registrations( |
|
525 | + array( |
|
526 | + array( |
|
527 | + // only these reg statuses can receive payments |
|
528 | + 'STS_ID' => array('IN', EEM_Registration::reg_statuses_that_allow_payment()), |
|
529 | + 'REG_final_price' => array('!=', 0), |
|
530 | + 'REG_final_price*' => array('!=', 'REG_paid', true), |
|
531 | + ), |
|
532 | + ) |
|
533 | + ); |
|
534 | + } |
|
535 | + // still nothing ??!?? |
|
536 | + if (empty($registrations)) { |
|
537 | + return; |
|
538 | + } |
|
539 | + // todo: break out the following logic into a separate strategy class |
|
540 | + // todo: named something like "Sequential_Reg_Payment_Strategy" |
|
541 | + // todo: which would apply payments using the capitalist "first come first paid" approach |
|
542 | + // todo: then have another strategy class like "Distributed_Reg_Payment_Strategy" |
|
543 | + // todo: which would be the socialist "everybody gets a piece of pie" approach, |
|
544 | + // todo: which would be better for deposits, where you want a bit of the payment applied to each registration |
|
545 | + $refund = $payment->is_a_refund(); |
|
546 | + // how much is available to apply to registrations? |
|
547 | + $available_payment_amount = abs($payment->amount()); |
|
548 | + foreach ($registrations as $registration) { |
|
549 | + if ($registration instanceof EE_Registration) { |
|
550 | + // nothing left? |
|
551 | + if ($available_payment_amount <= 0) { |
|
552 | + break; |
|
553 | + } |
|
554 | + if ($refund) { |
|
555 | + $available_payment_amount = $this->process_registration_refund($registration, $payment, $available_payment_amount); |
|
556 | + } else { |
|
557 | + $available_payment_amount = $this->process_registration_payment($registration, $payment, $available_payment_amount); |
|
558 | + } |
|
559 | + } |
|
560 | + } |
|
561 | + if ($available_payment_amount > 0 && apply_filters('FHEE__EE_Payment_Processor__process_registration_payments__display_notifications', false)) { |
|
562 | + EE_Error::add_attention( |
|
563 | + sprintf( |
|
564 | + __('A remainder of %1$s exists after applying this payment to Registration(s) %2$s.%3$sPlease verify that the original payment amount of %4$s is correct. If so, you should edit this payment and select at least one additional registration in the "Registrations to Apply Payment to" section, so that the remainder of this payment can be applied to the additional registration(s).', |
|
565 | + 'event_espresso'), |
|
566 | + EEH_Template::format_currency($available_payment_amount), |
|
567 | + implode(', ', array_keys($registrations)), |
|
568 | + '<br/>', |
|
569 | + EEH_Template::format_currency($payment->amount()) |
|
570 | + ), |
|
571 | + __FILE__, __FUNCTION__, __LINE__ |
|
572 | + ); |
|
573 | + } |
|
574 | + } |
|
575 | + |
|
576 | + |
|
577 | + |
|
578 | + /** |
|
579 | + * update registration REG_paid field after successful payment and link registration with payment |
|
580 | + * |
|
581 | + * @param EE_Registration $registration |
|
582 | + * @param EE_Payment $payment |
|
583 | + * @param float $available_payment_amount |
|
584 | + * @return float |
|
585 | + * @throws \EE_Error |
|
586 | + */ |
|
587 | + public function process_registration_payment( |
|
588 | + EE_Registration $registration, |
|
589 | + EE_Payment $payment, |
|
590 | + $available_payment_amount = 0.00 |
|
591 | + ) { |
|
592 | + $owing = $registration->final_price() - $registration->paid(); |
|
593 | + if ($owing > 0) { |
|
594 | + // don't allow payment amount to exceed the available payment amount, OR the amount owing |
|
595 | + $payment_amount = min($available_payment_amount, $owing); |
|
596 | + // update $available_payment_amount |
|
597 | + $available_payment_amount -= $payment_amount; |
|
598 | + //calculate and set new REG_paid |
|
599 | + $registration->set_paid($registration->paid() + $payment_amount); |
|
600 | + // now save it |
|
601 | + $this->_apply_registration_payment($registration, $payment, $payment_amount); |
|
602 | + } |
|
603 | + return $available_payment_amount; |
|
604 | + } |
|
605 | + |
|
606 | + |
|
607 | + |
|
608 | + /** |
|
609 | + * update registration REG_paid field after successful payment and link registration with payment |
|
610 | + * |
|
611 | + * @param EE_Registration $registration |
|
612 | + * @param EE_Payment $payment |
|
613 | + * @param float $payment_amount |
|
614 | + * @return void |
|
615 | + * @throws \EE_Error |
|
616 | + */ |
|
617 | + protected function _apply_registration_payment( |
|
618 | + EE_Registration $registration, |
|
619 | + EE_Payment $payment, |
|
620 | + $payment_amount = 0.00 |
|
621 | + ) { |
|
622 | + // find any existing reg payment records for this registration and payment |
|
623 | + $existing_reg_payment = EEM_Registration_Payment::instance()->get_one( |
|
624 | + array(array('REG_ID' => $registration->ID(), 'PAY_ID' => $payment->ID())) |
|
625 | + ); |
|
626 | + // if existing registration payment exists |
|
627 | + if ($existing_reg_payment instanceof EE_Registration_Payment) { |
|
628 | + // then update that record |
|
629 | + $existing_reg_payment->set_amount($payment_amount); |
|
630 | + $existing_reg_payment->save(); |
|
631 | + } else { |
|
632 | + // or add new relation between registration and payment and set amount |
|
633 | + $registration->_add_relation_to($payment, 'Payment', array('RPY_amount' => $payment_amount)); |
|
634 | + // make it stick |
|
635 | + $registration->save(); |
|
636 | + } |
|
637 | + } |
|
638 | + |
|
639 | + |
|
640 | + |
|
641 | + /** |
|
642 | + * update registration REG_paid field after refund and link registration with payment |
|
643 | + * |
|
644 | + * @param EE_Registration $registration |
|
645 | + * @param EE_Payment $payment |
|
646 | + * @param float $available_refund_amount - IMPORTANT !!! SEND AVAILABLE REFUND AMOUNT AS A POSITIVE NUMBER |
|
647 | + * @return float |
|
648 | + * @throws \EE_Error |
|
649 | + */ |
|
650 | + public function process_registration_refund( |
|
651 | + EE_Registration $registration, |
|
652 | + EE_Payment $payment, |
|
653 | + $available_refund_amount = 0.00 |
|
654 | + ) { |
|
655 | + //EEH_Debug_Tools::printr( $payment->amount(), '$payment->amount()', __FILE__, __LINE__ ); |
|
656 | + if ($registration->paid() > 0) { |
|
657 | + // ensure $available_refund_amount is NOT negative |
|
658 | + $available_refund_amount = (float)abs($available_refund_amount); |
|
659 | + // don't allow refund amount to exceed the available payment amount, OR the amount paid |
|
660 | + $refund_amount = min($available_refund_amount, (float)$registration->paid()); |
|
661 | + // update $available_payment_amount |
|
662 | + $available_refund_amount -= $refund_amount; |
|
663 | + //calculate and set new REG_paid |
|
664 | + $registration->set_paid($registration->paid() - $refund_amount); |
|
665 | + // convert payment amount back to a negative value for storage in the db |
|
666 | + $refund_amount = (float)abs($refund_amount) * -1; |
|
667 | + // now save it |
|
668 | + $this->_apply_registration_payment($registration, $payment, $refund_amount); |
|
669 | + } |
|
670 | + return $available_refund_amount; |
|
671 | + } |
|
672 | + |
|
673 | + |
|
674 | + |
|
675 | + /** |
|
676 | + * Process payments and transaction after payment process completed. |
|
677 | + * ultimately this will send the TXN and payment details off so that notifications can be sent out. |
|
678 | + * if this request happens to be processing an IPN, |
|
679 | + * then we will also set the Payment Options Reg Step to completed, |
|
680 | + * and attempt to completely finalize the TXN if all of the other Reg Steps are completed as well. |
|
681 | + * |
|
682 | + * @param EE_Transaction $transaction |
|
683 | + * @param EE_Payment $payment |
|
684 | + * @param bool $IPN |
|
685 | + * @throws \EE_Error |
|
686 | + */ |
|
687 | + protected function _post_payment_processing(EE_Transaction $transaction, EE_Payment $payment, $IPN = false) |
|
688 | + { |
|
689 | + /** @type EE_Transaction_Processor $transaction_processor */ |
|
690 | + $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor'); |
|
691 | + // is the Payment Options Reg Step completed ? |
|
692 | + $payment_options_step_completed = $transaction->reg_step_completed('payment_options'); |
|
693 | + // if the Payment Options Reg Step is completed... |
|
694 | + $revisit = $payment_options_step_completed === true ? true : false; |
|
695 | + // then this is kinda sorta a revisit with regards to payments at least |
|
696 | + $transaction_processor->set_revisit($revisit); |
|
697 | + // if this is an IPN, let's consider the Payment Options Reg Step completed if not already |
|
698 | + if ( |
|
699 | + $IPN |
|
700 | + && $payment_options_step_completed !== true |
|
701 | + && ($payment->is_approved() || $payment->is_pending()) |
|
702 | + ) { |
|
703 | + $payment_options_step_completed = $transaction->set_reg_step_completed( |
|
704 | + 'payment_options' |
|
705 | + ); |
|
706 | + } |
|
707 | + // maybe update status, but don't save transaction just yet |
|
708 | + $transaction->update_status_based_on_total_paid(false); |
|
709 | + // check if 'finalize_registration' step has been completed... |
|
710 | + $finalized = $transaction->reg_step_completed('finalize_registration'); |
|
711 | + // if this is an IPN and the final step has not been initiated |
|
712 | + if ($IPN && $payment_options_step_completed && $finalized === false) { |
|
713 | + // and if it hasn't already been set as being started... |
|
714 | + $finalized = $transaction->set_reg_step_initiated('finalize_registration'); |
|
715 | + } |
|
716 | + $transaction->save(); |
|
717 | + // because the above will return false if the final step was not fully completed, we need to check again... |
|
718 | + if ($IPN && $finalized !== false) { |
|
719 | + // and if we are all good to go, then send out notifications |
|
720 | + add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true'); |
|
721 | + //ok, now process the transaction according to the payment |
|
722 | + $transaction_processor->update_transaction_and_registrations_after_checkout_or_payment($transaction, $payment); |
|
723 | + } |
|
724 | + // DEBUG LOG |
|
725 | + $payment_method = $payment->payment_method(); |
|
726 | + if ($payment_method instanceof EE_Payment_Method) { |
|
727 | + $payment_method_type_obj = $payment_method->type_obj(); |
|
728 | + if ($payment_method_type_obj instanceof EE_PMT_Base) { |
|
729 | + $gateway = $payment_method_type_obj->get_gateway(); |
|
730 | + if ($gateway instanceof EE_Gateway) { |
|
731 | + $gateway->log( |
|
732 | + array( |
|
733 | + 'message' => __('Post Payment Transaction Details', 'event_espresso'), |
|
734 | + 'transaction' => $transaction->model_field_array(), |
|
735 | + 'finalized' => $finalized, |
|
736 | + 'IPN' => $IPN, |
|
737 | + 'deliver_notifications' => has_filter( |
|
738 | + 'FHEE__EED_Messages___maybe_registration__deliver_notifications' |
|
739 | + ), |
|
740 | + ), |
|
741 | + $payment |
|
742 | + ); |
|
743 | + } |
|
744 | + } |
|
745 | + } |
|
746 | + } |
|
747 | + |
|
748 | + |
|
749 | + |
|
750 | + /** |
|
751 | + * Force posts to PayPal to use TLS v1.2. See: |
|
752 | + * https://core.trac.wordpress.org/ticket/36320 |
|
753 | + * https://core.trac.wordpress.org/ticket/34924#comment:15 |
|
754 | + * https://www.paypal-knowledge.com/infocenter/index?page=content&widgetview=true&id=FAQ1914&viewlocale=en_US |
|
755 | + * This will affect paypal standard, pro, express, and payflow. |
|
756 | + */ |
|
757 | + public static function _curl_requests_to_paypal_use_tls($handle, $r, $url) |
|
758 | + { |
|
759 | + if (strstr($url, 'https://') && strstr($url, '.paypal.com')) { |
|
760 | + //Use the value of the constant CURL_SSLVERSION_TLSv1 = 1 |
|
761 | + //instead of the constant because it might not be defined |
|
762 | + curl_setopt($handle, CURLOPT_SSLVERSION, 1); |
|
763 | + } |
|
764 | + } |
|
765 | 765 | } |
@@ -42,13 +42,13 @@ discard block |
||
42 | 42 | |
43 | 43 | public function __construct() { |
44 | 44 | // construct request stack and run middleware apps as soon as all WP plugins are loaded |
45 | - add_action( 'plugins_loaded', array( $this, 'run_request_stack' ), 0 ); |
|
45 | + add_action('plugins_loaded', array($this, 'run_request_stack'), 0); |
|
46 | 46 | // set framework for the rest of EE to hook into when loading |
47 | - add_action( 'plugins_loaded', array( 'EE_Bootstrap', 'load_espresso_addons' ), 1 ); |
|
48 | - add_action( 'plugins_loaded', array( 'EE_Bootstrap', 'detect_activations_or_upgrades' ), 3 ); |
|
49 | - add_action( 'plugins_loaded', array( 'EE_Bootstrap', 'load_core_configuration' ), 5 ); |
|
50 | - add_action( 'plugins_loaded', array( 'EE_Bootstrap', 'register_shortcodes_modules_and_widgets' ), 7 ); |
|
51 | - add_action( 'plugins_loaded', array( 'EE_Bootstrap', 'brew_espresso' ), 9 ); |
|
47 | + add_action('plugins_loaded', array('EE_Bootstrap', 'load_espresso_addons'), 1); |
|
48 | + add_action('plugins_loaded', array('EE_Bootstrap', 'detect_activations_or_upgrades'), 3); |
|
49 | + add_action('plugins_loaded', array('EE_Bootstrap', 'load_core_configuration'), 5); |
|
50 | + add_action('plugins_loaded', array('EE_Bootstrap', 'register_shortcodes_modules_and_widgets'), 7); |
|
51 | + add_action('plugins_loaded', array('EE_Bootstrap', 'brew_espresso'), 9); |
|
52 | 52 | } |
53 | 53 | |
54 | 54 | |
@@ -65,7 +65,7 @@ discard block |
||
65 | 65 | new EE_Load_Espresso_Core() |
66 | 66 | ); |
67 | 67 | $this->_request_stack->handle_request( |
68 | - new EE_Request( $_GET, $_POST, $_COOKIE ), |
|
68 | + new EE_Request($_GET, $_POST, $_COOKIE), |
|
69 | 69 | new EE_Response() |
70 | 70 | ); |
71 | 71 | $this->_request_stack->handle_response(); |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | */ |
79 | 79 | protected function load_autoloader() { |
80 | 80 | // load interfaces |
81 | - espresso_load_required( 'EEH_Autoloader', EE_CORE . 'helpers' . DS . 'EEH_Autoloader.helper.php' ); |
|
81 | + espresso_load_required('EEH_Autoloader', EE_CORE.'helpers'.DS.'EEH_Autoloader.helper.php'); |
|
82 | 82 | EEH_Autoloader::instance(); |
83 | 83 | } |
84 | 84 | |
@@ -89,15 +89,15 @@ discard block |
||
89 | 89 | */ |
90 | 90 | protected function set_autoloaders_for_required_files() { |
91 | 91 | // load interfaces |
92 | - espresso_load_required( 'EEI_Interfaces', EE_CORE . 'interfaces' . DS . 'EEI_Interfaces.php' ); |
|
93 | - espresso_load_required( 'InterminableInterface', EE_CORE . 'interfaces' . DS . 'InterminableInterface.php' ); |
|
94 | - espresso_load_required( 'ResettableInterface', EE_CORE . 'interfaces' . DS . 'ResettableInterface.php' ); |
|
92 | + espresso_load_required('EEI_Interfaces', EE_CORE.'interfaces'.DS.'EEI_Interfaces.php'); |
|
93 | + espresso_load_required('InterminableInterface', EE_CORE.'interfaces'.DS.'InterminableInterface.php'); |
|
94 | + espresso_load_required('ResettableInterface', EE_CORE.'interfaces'.DS.'ResettableInterface.php'); |
|
95 | 95 | // load helpers |
96 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder( EE_HELPERS ); |
|
96 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_HELPERS); |
|
97 | 97 | // load request stack |
98 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder( EE_CORE . 'request_stack' . DS ); |
|
98 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE.'request_stack'.DS); |
|
99 | 99 | // load middleware |
100 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder( EE_CORE . 'middleware' . DS ); |
|
100 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(EE_CORE.'middleware'.DS); |
|
101 | 101 | } |
102 | 102 | |
103 | 103 | |
@@ -118,9 +118,9 @@ discard block |
||
118 | 118 | ) |
119 | 119 | ); |
120 | 120 | // load middleware onto stack : FILO (First In Last Out) |
121 | - foreach ( (array)$stack_apps as $stack_app ) { |
|
121 | + foreach ((array) $stack_apps as $stack_app) { |
|
122 | 122 | //$request_stack_builder->push( $stack_app ); |
123 | - $request_stack_builder->unshift( $stack_app ); |
|
123 | + $request_stack_builder->unshift($stack_app); |
|
124 | 124 | } |
125 | 125 | return apply_filters( |
126 | 126 | 'FHEE__EE_Bootstrap__build_request_stack__request_stack_builder', |
@@ -137,7 +137,7 @@ discard block |
||
137 | 137 | * no other logic should be performed at this point |
138 | 138 | */ |
139 | 139 | public static function load_espresso_addons() { |
140 | - do_action( 'AHEE__EE_Bootstrap__load_espresso_addons' ); |
|
140 | + do_action('AHEE__EE_Bootstrap__load_espresso_addons'); |
|
141 | 141 | } |
142 | 142 | |
143 | 143 | |
@@ -149,7 +149,7 @@ discard block |
||
149 | 149 | * we can determine if anything needs activating or upgrading |
150 | 150 | */ |
151 | 151 | public static function detect_activations_or_upgrades() { |
152 | - do_action( 'AHEE__EE_Bootstrap__detect_activations_or_upgrades' ); |
|
152 | + do_action('AHEE__EE_Bootstrap__detect_activations_or_upgrades'); |
|
153 | 153 | } |
154 | 154 | |
155 | 155 | |
@@ -161,7 +161,7 @@ discard block |
||
161 | 161 | * we can load and set all of the system configurations |
162 | 162 | */ |
163 | 163 | public static function load_core_configuration() { |
164 | - do_action( 'AHEE__EE_Bootstrap__load_core_configuration' ); |
|
164 | + do_action('AHEE__EE_Bootstrap__load_core_configuration'); |
|
165 | 165 | } |
166 | 166 | |
167 | 167 | |
@@ -173,7 +173,7 @@ discard block |
||
173 | 173 | * so that they are ready to be used throughout the system |
174 | 174 | */ |
175 | 175 | public static function register_shortcodes_modules_and_widgets() { |
176 | - do_action( 'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets' ); |
|
176 | + do_action('AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets'); |
|
177 | 177 | } |
178 | 178 | |
179 | 179 | |
@@ -185,7 +185,7 @@ discard block |
||
185 | 185 | * so let the fun begin... |
186 | 186 | */ |
187 | 187 | public static function brew_espresso() { |
188 | - do_action( 'AHEE__EE_Bootstrap__brew_espresso' ); |
|
188 | + do_action('AHEE__EE_Bootstrap__brew_espresso'); |
|
189 | 189 | } |
190 | 190 | |
191 | 191 |
@@ -1,4 +1,4 @@ |
||
1 | -<?php use EventEspresso\core\interfaces\InterminableInterface; |
|
1 | +<?php |
|
2 | 2 | |
3 | 3 | defined('EVENT_ESPRESSO_VERSION') || exit('No direct script access allowed'); |
4 | 4 |
@@ -7,7 +7,7 @@ discard block |
||
7 | 7 | use ReflectionException; |
8 | 8 | |
9 | 9 | if (! defined('EVENT_ESPRESSO_VERSION')) { |
10 | - exit('No direct script access allowed'); |
|
10 | + exit('No direct script access allowed'); |
|
11 | 11 | } |
12 | 12 | |
13 | 13 | |
@@ -25,53 +25,53 @@ discard block |
||
25 | 25 | |
26 | 26 | |
27 | 27 | |
28 | - /** |
|
29 | - * @param Exception $exception |
|
30 | - * @throws Exception |
|
31 | - */ |
|
32 | - public function __construct(Exception $exception) |
|
33 | - { |
|
34 | - if (WP_DEBUG && ! defined('EE_TESTS_DIR')) { |
|
35 | - $this->displayException($exception); |
|
36 | - } else { |
|
37 | - throw $exception; |
|
38 | - } |
|
39 | - } |
|
28 | + /** |
|
29 | + * @param Exception $exception |
|
30 | + * @throws Exception |
|
31 | + */ |
|
32 | + public function __construct(Exception $exception) |
|
33 | + { |
|
34 | + if (WP_DEBUG && ! defined('EE_TESTS_DIR')) { |
|
35 | + $this->displayException($exception); |
|
36 | + } else { |
|
37 | + throw $exception; |
|
38 | + } |
|
39 | + } |
|
40 | 40 | |
41 | 41 | |
42 | 42 | |
43 | - /** |
|
44 | - * @access protected |
|
45 | - * @param Exception $exception |
|
46 | - * @throws ReflectionException |
|
47 | - */ |
|
48 | - protected function displayException(Exception $exception) |
|
49 | - { |
|
50 | - $error_code = ''; |
|
51 | - $trace_details = ''; |
|
52 | - $time = time(); |
|
53 | - $trace = $exception->getTrace(); |
|
54 | - // get separate user and developer messages if they exist |
|
55 | - $msg = explode('||', $exception->getMessage()); |
|
56 | - $user_msg = $msg[0]; |
|
57 | - $dev_msg = isset($msg[1]) ? $msg[1] : $msg[0]; |
|
58 | - $msg = WP_DEBUG ? $dev_msg : $user_msg; |
|
59 | - // start gathering output |
|
60 | - $output = $this->exceptionStyles(); |
|
61 | - $output .= ' |
|
43 | + /** |
|
44 | + * @access protected |
|
45 | + * @param Exception $exception |
|
46 | + * @throws ReflectionException |
|
47 | + */ |
|
48 | + protected function displayException(Exception $exception) |
|
49 | + { |
|
50 | + $error_code = ''; |
|
51 | + $trace_details = ''; |
|
52 | + $time = time(); |
|
53 | + $trace = $exception->getTrace(); |
|
54 | + // get separate user and developer messages if they exist |
|
55 | + $msg = explode('||', $exception->getMessage()); |
|
56 | + $user_msg = $msg[0]; |
|
57 | + $dev_msg = isset($msg[1]) ? $msg[1] : $msg[0]; |
|
58 | + $msg = WP_DEBUG ? $dev_msg : $user_msg; |
|
59 | + // start gathering output |
|
60 | + $output = $this->exceptionStyles(); |
|
61 | + $output .= ' |
|
62 | 62 | <div id="ee-error-message" class="error">'; |
63 | - if (! WP_DEBUG) { |
|
64 | - $output .= ' |
|
63 | + if (! WP_DEBUG) { |
|
64 | + $output .= ' |
|
65 | 65 | <p>'; |
66 | - } |
|
67 | - // process trace info |
|
68 | - if (empty($trace)) { |
|
69 | - $trace_details .= __( |
|
70 | - 'Sorry, but no trace information was available for this exception.', |
|
71 | - 'event_espresso' |
|
72 | - ); |
|
73 | - } else { |
|
74 | - $trace_details .= ' |
|
66 | + } |
|
67 | + // process trace info |
|
68 | + if (empty($trace)) { |
|
69 | + $trace_details .= __( |
|
70 | + 'Sorry, but no trace information was available for this exception.', |
|
71 | + 'event_espresso' |
|
72 | + ); |
|
73 | + } else { |
|
74 | + $trace_details .= ' |
|
75 | 75 | <div id="ee-trace-details"> |
76 | 76 | <table width="100%" border="0" cellpadding="5" cellspacing="0"> |
77 | 77 | <tr> |
@@ -79,255 +79,255 @@ discard block |
||
79 | 79 | <th scope="col" align="right" style="width:3.5%;">Line</th> |
80 | 80 | <th scope="col" align="left" style="width:40%;">File</th> |
81 | 81 | <th scope="col" align="left">' . __('Class', 'event_espresso') . '->' . __('Method( arguments )', |
82 | - 'event_espresso') . '</th> |
|
82 | + 'event_espresso') . '</th> |
|
83 | 83 | </tr>'; |
84 | - $last_on_stack = count($trace) - 1; |
|
85 | - // reverse array so that stack is in proper chronological order |
|
86 | - $sorted_trace = array_reverse($trace); |
|
87 | - foreach ($sorted_trace as $nmbr => $trace) { |
|
88 | - $file = isset($trace['file']) ? $trace['file'] : ''; |
|
89 | - $class = isset($trace['class']) ? $trace['class'] : ''; |
|
90 | - $type = isset($trace['type']) ? $trace['type'] : ''; |
|
91 | - $function = isset($trace['function']) ? $trace['function'] : ''; |
|
92 | - $args = isset($trace['args']) ? $this->_convert_args_to_string($trace['args']) : ''; |
|
93 | - $args = isset($trace['args']) && count($trace['args']) > 4 ? ' <br />' . $args . '<br />' : $args; |
|
94 | - $line = isset($trace['line']) ? $trace['line'] : ''; |
|
95 | - $zebra = $nmbr % 2 !== 0 ? ' odd' : ''; |
|
96 | - if (empty($file) && ! empty($class)) { |
|
97 | - $a = new ReflectionClass($class); |
|
98 | - $file = $a->getFileName(); |
|
99 | - if (empty($line) && ! empty($function)) { |
|
100 | - $b = new \ReflectionMethod($class, $function); |
|
101 | - $line = $b->getStartLine(); |
|
102 | - } |
|
103 | - } |
|
104 | - if ($nmbr === $last_on_stack) { |
|
105 | - $file = $exception->getFile() !== '' ? $exception->getFile() : $file; |
|
106 | - $line = $exception->getLine() !== '' ? $exception->getLine() : $line; |
|
107 | - $error_code = $this->generate_error_code($file, $trace['function'], $line); |
|
108 | - } |
|
109 | - $file = \EEH_File::standardise_directory_separators($file); |
|
110 | - $nmbr = ! empty($nmbr) ? $nmbr : ' '; |
|
111 | - $line = ! empty($line) ? $line : ' '; |
|
112 | - $file = ! empty($file) ? $file : ' '; |
|
113 | - $class_display = ! empty($class) ? $class : ''; |
|
114 | - $type = ! empty($type) ? $type : ''; |
|
115 | - $function = ! empty($function) ? $function : ''; |
|
116 | - $args = ! empty($args) ? '( ' . $args . ' )' : '()'; |
|
117 | - $trace_details .= ' |
|
84 | + $last_on_stack = count($trace) - 1; |
|
85 | + // reverse array so that stack is in proper chronological order |
|
86 | + $sorted_trace = array_reverse($trace); |
|
87 | + foreach ($sorted_trace as $nmbr => $trace) { |
|
88 | + $file = isset($trace['file']) ? $trace['file'] : ''; |
|
89 | + $class = isset($trace['class']) ? $trace['class'] : ''; |
|
90 | + $type = isset($trace['type']) ? $trace['type'] : ''; |
|
91 | + $function = isset($trace['function']) ? $trace['function'] : ''; |
|
92 | + $args = isset($trace['args']) ? $this->_convert_args_to_string($trace['args']) : ''; |
|
93 | + $args = isset($trace['args']) && count($trace['args']) > 4 ? ' <br />' . $args . '<br />' : $args; |
|
94 | + $line = isset($trace['line']) ? $trace['line'] : ''; |
|
95 | + $zebra = $nmbr % 2 !== 0 ? ' odd' : ''; |
|
96 | + if (empty($file) && ! empty($class)) { |
|
97 | + $a = new ReflectionClass($class); |
|
98 | + $file = $a->getFileName(); |
|
99 | + if (empty($line) && ! empty($function)) { |
|
100 | + $b = new \ReflectionMethod($class, $function); |
|
101 | + $line = $b->getStartLine(); |
|
102 | + } |
|
103 | + } |
|
104 | + if ($nmbr === $last_on_stack) { |
|
105 | + $file = $exception->getFile() !== '' ? $exception->getFile() : $file; |
|
106 | + $line = $exception->getLine() !== '' ? $exception->getLine() : $line; |
|
107 | + $error_code = $this->generate_error_code($file, $trace['function'], $line); |
|
108 | + } |
|
109 | + $file = \EEH_File::standardise_directory_separators($file); |
|
110 | + $nmbr = ! empty($nmbr) ? $nmbr : ' '; |
|
111 | + $line = ! empty($line) ? $line : ' '; |
|
112 | + $file = ! empty($file) ? $file : ' '; |
|
113 | + $class_display = ! empty($class) ? $class : ''; |
|
114 | + $type = ! empty($type) ? $type : ''; |
|
115 | + $function = ! empty($function) ? $function : ''; |
|
116 | + $args = ! empty($args) ? '( ' . $args . ' )' : '()'; |
|
117 | + $trace_details .= ' |
|
118 | 118 | <tr> |
119 | 119 | <td align="right" valign="top" class="' |
120 | - . $zebra |
|
121 | - . '">' |
|
122 | - . $nmbr |
|
123 | - . '</td> |
|
120 | + . $zebra |
|
121 | + . '">' |
|
122 | + . $nmbr |
|
123 | + . '</td> |
|
124 | 124 | <td align="right" valign="top" class="' |
125 | - . $zebra |
|
126 | - . '">' |
|
127 | - . $line |
|
128 | - . '</td> |
|
125 | + . $zebra |
|
126 | + . '">' |
|
127 | + . $line |
|
128 | + . '</td> |
|
129 | 129 | <td align="left" valign="top" class="' |
130 | - . $zebra |
|
131 | - . '">' |
|
132 | - . $file |
|
133 | - . '</td> |
|
130 | + . $zebra |
|
131 | + . '">' |
|
132 | + . $file |
|
133 | + . '</td> |
|
134 | 134 | <td align="left" valign="top" class="' |
135 | - . $zebra |
|
136 | - . '">' |
|
137 | - . $class_display |
|
138 | - . $type |
|
139 | - . $function |
|
140 | - . $args |
|
141 | - . '</td> |
|
135 | + . $zebra |
|
136 | + . '">' |
|
137 | + . $class_display |
|
138 | + . $type |
|
139 | + . $function |
|
140 | + . $args |
|
141 | + . '</td> |
|
142 | 142 | </tr>'; |
143 | - } |
|
144 | - $trace_details .= ' |
|
143 | + } |
|
144 | + $trace_details .= ' |
|
145 | 145 | </table> |
146 | 146 | </div>'; |
147 | - } |
|
148 | - $code = $exception->getCode() ? $exception->getCode() : $error_code; |
|
149 | - // add generic non-identifying messages for non-privileged users |
|
150 | - if (! WP_DEBUG) { |
|
151 | - $output .= '<span class="ee-error-user-msg-spn">' |
|
152 | - . trim($msg) |
|
153 | - . '</span> <sup>' |
|
154 | - . $code |
|
155 | - . '</sup><br />'; |
|
156 | - } else { |
|
157 | - // or helpful developer messages if debugging is on |
|
158 | - $output .= ' |
|
147 | + } |
|
148 | + $code = $exception->getCode() ? $exception->getCode() : $error_code; |
|
149 | + // add generic non-identifying messages for non-privileged users |
|
150 | + if (! WP_DEBUG) { |
|
151 | + $output .= '<span class="ee-error-user-msg-spn">' |
|
152 | + . trim($msg) |
|
153 | + . '</span> <sup>' |
|
154 | + . $code |
|
155 | + . '</sup><br />'; |
|
156 | + } else { |
|
157 | + // or helpful developer messages if debugging is on |
|
158 | + $output .= ' |
|
159 | 159 | <div class="ee-error-dev-msg-dv"> |
160 | 160 | <p class="ee-error-dev-msg-pg"> |
161 | 161 | ' |
162 | - . sprintf( |
|
163 | - __('%1$sAn %2$s was thrown!%3$s code: %4$s', 'event_espresso'), |
|
164 | - '<strong class="ee-error-dev-msg-str">', |
|
165 | - get_class($exception), |
|
166 | - '</strong> <span>', |
|
167 | - $code . '</span>' |
|
168 | - ) |
|
169 | - . '<br /> |
|
162 | + . sprintf( |
|
163 | + __('%1$sAn %2$s was thrown!%3$s code: %4$s', 'event_espresso'), |
|
164 | + '<strong class="ee-error-dev-msg-str">', |
|
165 | + get_class($exception), |
|
166 | + '</strong> <span>', |
|
167 | + $code . '</span>' |
|
168 | + ) |
|
169 | + . '<br /> |
|
170 | 170 | <span class="big-text">"' |
171 | - . trim($msg) |
|
172 | - . '"</span><br/> |
|
171 | + . trim($msg) |
|
172 | + . '"</span><br/> |
|
173 | 173 | <a id="display-ee-error-trace-1' |
174 | - . $time |
|
175 | - . '" class="display-ee-error-trace-lnk small-text" rel="ee-error-trace-1' |
|
176 | - . $time |
|
177 | - . '"> |
|
174 | + . $time |
|
175 | + . '" class="display-ee-error-trace-lnk small-text" rel="ee-error-trace-1' |
|
176 | + . $time |
|
177 | + . '"> |
|
178 | 178 | ' |
179 | - . __('click to view backtrace and class/method details', 'event_espresso') |
|
180 | - . ' |
|
179 | + . __('click to view backtrace and class/method details', 'event_espresso') |
|
180 | + . ' |
|
181 | 181 | </a><br /> |
182 | 182 | ' |
183 | - . $exception->getFile() |
|
184 | - . sprintf( |
|
185 | - __('%1$s( line no: %2$s )%3$s', 'event_espresso'), |
|
186 | - ' <span class="small-text lt-grey-text">', |
|
187 | - $exception->getLine(), |
|
188 | - '</span>' |
|
189 | - ) |
|
190 | - . ' |
|
183 | + . $exception->getFile() |
|
184 | + . sprintf( |
|
185 | + __('%1$s( line no: %2$s )%3$s', 'event_espresso'), |
|
186 | + ' <span class="small-text lt-grey-text">', |
|
187 | + $exception->getLine(), |
|
188 | + '</span>' |
|
189 | + ) |
|
190 | + . ' |
|
191 | 191 | </p> |
192 | 192 | <div id="ee-error-trace-1' |
193 | - . $time |
|
194 | - . '-dv" class="ee-error-trace-dv" style="display: none;"> |
|
193 | + . $time |
|
194 | + . '-dv" class="ee-error-trace-dv" style="display: none;"> |
|
195 | 195 | ' |
196 | - . $trace_details; |
|
197 | - if (! empty($class)) { |
|
198 | - $output .= ' |
|
196 | + . $trace_details; |
|
197 | + if (! empty($class)) { |
|
198 | + $output .= ' |
|
199 | 199 | <div style="padding:3px; margin:0 0 1em; border:1px solid #999; background:#fff; border-radius:3px;"> |
200 | 200 | <div style="padding:1em 2em; border:1px solid #999; background:#fcfcfc;"> |
201 | 201 | <h3>' . __('Class Details', 'event_espresso') . '</h3>'; |
202 | - $a = new ReflectionClass($class); |
|
203 | - $output .= ' |
|
202 | + $a = new ReflectionClass($class); |
|
203 | + $output .= ' |
|
204 | 204 | <pre>' . $a . '</pre> |
205 | 205 | </div> |
206 | 206 | </div>'; |
207 | - } |
|
208 | - $output .= ' |
|
207 | + } |
|
208 | + $output .= ' |
|
209 | 209 | </div> |
210 | 210 | </div> |
211 | 211 | <br />'; |
212 | - } |
|
213 | - // remove last linebreak |
|
214 | - $output = substr($output, 0, -6); |
|
215 | - if (! WP_DEBUG) { |
|
216 | - $output .= ' |
|
212 | + } |
|
213 | + // remove last linebreak |
|
214 | + $output = substr($output, 0, -6); |
|
215 | + if (! WP_DEBUG) { |
|
216 | + $output .= ' |
|
217 | 217 | </p>'; |
218 | - } |
|
219 | - $output .= ' |
|
218 | + } |
|
219 | + $output .= ' |
|
220 | 220 | </div>'; |
221 | - $output .= $this->printScripts(true); |
|
222 | - if (defined('DOING_AJAX')) { |
|
223 | - echo wp_json_encode(array('error' => $output)); |
|
224 | - exit(); |
|
225 | - } |
|
226 | - echo $output; |
|
227 | - } |
|
221 | + $output .= $this->printScripts(true); |
|
222 | + if (defined('DOING_AJAX')) { |
|
223 | + echo wp_json_encode(array('error' => $output)); |
|
224 | + exit(); |
|
225 | + } |
|
226 | + echo $output; |
|
227 | + } |
|
228 | 228 | |
229 | 229 | |
230 | 230 | |
231 | - /** |
|
232 | - * generate string from exception trace args |
|
233 | - * |
|
234 | - * @param array $arguments |
|
235 | - * @param int $indent |
|
236 | - * @param bool $array |
|
237 | - * @return string |
|
238 | - */ |
|
239 | - private function _convert_args_to_string($arguments = array(), $indent = 0, $array = false) |
|
240 | - { |
|
241 | - $args = array(); |
|
242 | - $args_count = count($arguments); |
|
243 | - if ($args_count > 2) { |
|
244 | - $indent++; |
|
245 | - $args[] = '<br />'; |
|
246 | - } |
|
247 | - $x = 0; |
|
248 | - foreach ($arguments as $arg) { |
|
249 | - $x++; |
|
250 | - for ($i = 0; $i < $indent; $i++) { |
|
251 | - $args[] = ' '; |
|
252 | - } |
|
253 | - if (is_string($arg)) { |
|
254 | - if (! $array && strlen($arg) > 75) { |
|
255 | - $args[] = '<br />'; |
|
256 | - for ($i = 0; $i <= $indent; $i++) { |
|
257 | - $args[] = ' '; |
|
258 | - } |
|
259 | - $args[] = "'" . $arg . "'<br />"; |
|
260 | - } else { |
|
261 | - $args[] = " '" . $arg . "'"; |
|
262 | - } |
|
263 | - } elseif (is_array($arg)) { |
|
264 | - $arg_count = count($arg); |
|
265 | - if ($arg_count > 2) { |
|
266 | - $indent++; |
|
267 | - $args[] = ' array(' . $this->_convert_args_to_string($arg, $indent, true) . ')'; |
|
268 | - $indent--; |
|
269 | - } else if ($arg_count === 0) { |
|
270 | - $args[] = ' array()'; |
|
271 | - } else { |
|
272 | - $args[] = ' array( ' . $this->_convert_args_to_string($arg) . ' )'; |
|
273 | - } |
|
274 | - } elseif ($arg === null) { |
|
275 | - $args[] = ' null'; |
|
276 | - } elseif (is_bool($arg)) { |
|
277 | - $args[] = $arg ? ' true' : ' false'; |
|
278 | - } elseif (is_object($arg)) { |
|
279 | - $args[] = get_class($arg); |
|
280 | - } elseif (is_resource($arg)) { |
|
281 | - $args[] = get_resource_type($arg); |
|
282 | - } else { |
|
283 | - $args[] = $arg; |
|
284 | - } |
|
285 | - if ($x === $args_count) { |
|
286 | - if ($args_count > 2) { |
|
287 | - $args[] = '<br />'; |
|
288 | - $indent--; |
|
289 | - for ($i = 1; $i < $indent; $i++) { |
|
290 | - $args[] = ' '; |
|
291 | - } |
|
292 | - } |
|
293 | - } else { |
|
294 | - $args[] = $args_count > 2 ? ',<br />' : ', '; |
|
295 | - } |
|
296 | - } |
|
297 | - return implode('', $args); |
|
298 | - } |
|
231 | + /** |
|
232 | + * generate string from exception trace args |
|
233 | + * |
|
234 | + * @param array $arguments |
|
235 | + * @param int $indent |
|
236 | + * @param bool $array |
|
237 | + * @return string |
|
238 | + */ |
|
239 | + private function _convert_args_to_string($arguments = array(), $indent = 0, $array = false) |
|
240 | + { |
|
241 | + $args = array(); |
|
242 | + $args_count = count($arguments); |
|
243 | + if ($args_count > 2) { |
|
244 | + $indent++; |
|
245 | + $args[] = '<br />'; |
|
246 | + } |
|
247 | + $x = 0; |
|
248 | + foreach ($arguments as $arg) { |
|
249 | + $x++; |
|
250 | + for ($i = 0; $i < $indent; $i++) { |
|
251 | + $args[] = ' '; |
|
252 | + } |
|
253 | + if (is_string($arg)) { |
|
254 | + if (! $array && strlen($arg) > 75) { |
|
255 | + $args[] = '<br />'; |
|
256 | + for ($i = 0; $i <= $indent; $i++) { |
|
257 | + $args[] = ' '; |
|
258 | + } |
|
259 | + $args[] = "'" . $arg . "'<br />"; |
|
260 | + } else { |
|
261 | + $args[] = " '" . $arg . "'"; |
|
262 | + } |
|
263 | + } elseif (is_array($arg)) { |
|
264 | + $arg_count = count($arg); |
|
265 | + if ($arg_count > 2) { |
|
266 | + $indent++; |
|
267 | + $args[] = ' array(' . $this->_convert_args_to_string($arg, $indent, true) . ')'; |
|
268 | + $indent--; |
|
269 | + } else if ($arg_count === 0) { |
|
270 | + $args[] = ' array()'; |
|
271 | + } else { |
|
272 | + $args[] = ' array( ' . $this->_convert_args_to_string($arg) . ' )'; |
|
273 | + } |
|
274 | + } elseif ($arg === null) { |
|
275 | + $args[] = ' null'; |
|
276 | + } elseif (is_bool($arg)) { |
|
277 | + $args[] = $arg ? ' true' : ' false'; |
|
278 | + } elseif (is_object($arg)) { |
|
279 | + $args[] = get_class($arg); |
|
280 | + } elseif (is_resource($arg)) { |
|
281 | + $args[] = get_resource_type($arg); |
|
282 | + } else { |
|
283 | + $args[] = $arg; |
|
284 | + } |
|
285 | + if ($x === $args_count) { |
|
286 | + if ($args_count > 2) { |
|
287 | + $args[] = '<br />'; |
|
288 | + $indent--; |
|
289 | + for ($i = 1; $i < $indent; $i++) { |
|
290 | + $args[] = ' '; |
|
291 | + } |
|
292 | + } |
|
293 | + } else { |
|
294 | + $args[] = $args_count > 2 ? ',<br />' : ', '; |
|
295 | + } |
|
296 | + } |
|
297 | + return implode('', $args); |
|
298 | + } |
|
299 | 299 | |
300 | 300 | |
301 | 301 | |
302 | - /** |
|
303 | - * create error code from filepath, function name, |
|
304 | - * and line number where exception or error was thrown |
|
305 | - * |
|
306 | - * @access protected |
|
307 | - * @param string $file |
|
308 | - * @param string $func |
|
309 | - * @param string $line |
|
310 | - * @return string |
|
311 | - */ |
|
312 | - protected function generate_error_code($file = '', $func = '', $line = '') |
|
313 | - { |
|
314 | - $file_bits = explode('.', basename($file)); |
|
315 | - $error_code = ! empty($file_bits[0]) ? $file_bits[0] : ''; |
|
316 | - $error_code .= ! empty($func) ? ' - ' . $func : ''; |
|
317 | - $error_code .= ! empty($line) ? ' - ' . $line : ''; |
|
318 | - return $error_code; |
|
319 | - } |
|
302 | + /** |
|
303 | + * create error code from filepath, function name, |
|
304 | + * and line number where exception or error was thrown |
|
305 | + * |
|
306 | + * @access protected |
|
307 | + * @param string $file |
|
308 | + * @param string $func |
|
309 | + * @param string $line |
|
310 | + * @return string |
|
311 | + */ |
|
312 | + protected function generate_error_code($file = '', $func = '', $line = '') |
|
313 | + { |
|
314 | + $file_bits = explode('.', basename($file)); |
|
315 | + $error_code = ! empty($file_bits[0]) ? $file_bits[0] : ''; |
|
316 | + $error_code .= ! empty($func) ? ' - ' . $func : ''; |
|
317 | + $error_code .= ! empty($line) ? ' - ' . $line : ''; |
|
318 | + return $error_code; |
|
319 | + } |
|
320 | 320 | |
321 | 321 | |
322 | 322 | |
323 | - /** |
|
324 | - * _exception_styles |
|
325 | - * |
|
326 | - * @return string |
|
327 | - */ |
|
328 | - private function exceptionStyles() |
|
329 | - { |
|
330 | - return ' |
|
323 | + /** |
|
324 | + * _exception_styles |
|
325 | + * |
|
326 | + * @return string |
|
327 | + */ |
|
328 | + private function exceptionStyles() |
|
329 | + { |
|
330 | + return ' |
|
331 | 331 | <style type="text/css"> |
332 | 332 | #ee-error-message { |
333 | 333 | max-width:90% !important; |
@@ -384,30 +384,30 @@ discard block |
||
384 | 384 | color: #999; |
385 | 385 | } |
386 | 386 | </style>'; |
387 | - } |
|
387 | + } |
|
388 | 388 | |
389 | 389 | |
390 | 390 | |
391 | - /** |
|
392 | - * _print_scripts |
|
393 | - * |
|
394 | - * @param bool $force_print |
|
395 | - * @return string |
|
396 | - */ |
|
397 | - private function printScripts($force_print = false) |
|
398 | - { |
|
399 | - if (! $force_print && (did_action('admin_enqueue_scripts') || did_action('wp_enqueue_scripts'))) { |
|
400 | - if (wp_script_is('ee_error_js', 'enqueued')) { |
|
401 | - return ''; |
|
402 | - } |
|
403 | - if (wp_script_is('ee_error_js', 'registered')) { |
|
404 | - wp_enqueue_style('espresso_default'); |
|
405 | - wp_enqueue_style('espresso_custom_css'); |
|
406 | - wp_enqueue_script( 'ee_error_js' ); |
|
391 | + /** |
|
392 | + * _print_scripts |
|
393 | + * |
|
394 | + * @param bool $force_print |
|
395 | + * @return string |
|
396 | + */ |
|
397 | + private function printScripts($force_print = false) |
|
398 | + { |
|
399 | + if (! $force_print && (did_action('admin_enqueue_scripts') || did_action('wp_enqueue_scripts'))) { |
|
400 | + if (wp_script_is('ee_error_js', 'enqueued')) { |
|
401 | + return ''; |
|
402 | + } |
|
403 | + if (wp_script_is('ee_error_js', 'registered')) { |
|
404 | + wp_enqueue_style('espresso_default'); |
|
405 | + wp_enqueue_style('espresso_custom_css'); |
|
406 | + wp_enqueue_script( 'ee_error_js' ); |
|
407 | 407 | wp_localize_script( 'ee_error_js', 'ee_settings', array( 'wp_debug' => WP_DEBUG ) ); |
408 | - } |
|
409 | - } else { |
|
410 | - return ' |
|
408 | + } |
|
409 | + } else { |
|
410 | + return ' |
|
411 | 411 | <script> |
412 | 412 | /* <![CDATA[ */ |
413 | 413 | var ee_settings = {"wp_debug":"' . WP_DEBUG . '"}; |
@@ -417,9 +417,9 @@ discard block |
||
417 | 417 | <script src="' . EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js' . '?ver=' . espresso_version() . '" type="text/javascript"></script> |
418 | 418 | <script src="' . EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js' . '?ver=' . espresso_version() . '" type="text/javascript"></script> |
419 | 419 | '; |
420 | - } |
|
421 | - return ''; |
|
422 | - } |
|
420 | + } |
|
421 | + return ''; |
|
422 | + } |
|
423 | 423 | |
424 | 424 | |
425 | 425 |
@@ -6,7 +6,7 @@ discard block |
||
6 | 6 | use ReflectionClass; |
7 | 7 | use ReflectionException; |
8 | 8 | |
9 | -if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
9 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
10 | 10 | exit('No direct script access allowed'); |
11 | 11 | } |
12 | 12 | |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | $output = $this->exceptionStyles(); |
61 | 61 | $output .= ' |
62 | 62 | <div id="ee-error-message" class="error">'; |
63 | - if (! WP_DEBUG) { |
|
63 | + if ( ! WP_DEBUG) { |
|
64 | 64 | $output .= ' |
65 | 65 | <p>'; |
66 | 66 | } |
@@ -78,8 +78,8 @@ discard block |
||
78 | 78 | <th scope="col" align="right" style="width:2.5%;">#</th> |
79 | 79 | <th scope="col" align="right" style="width:3.5%;">Line</th> |
80 | 80 | <th scope="col" align="left" style="width:40%;">File</th> |
81 | - <th scope="col" align="left">' . __('Class', 'event_espresso') . '->' . __('Method( arguments )', |
|
82 | - 'event_espresso') . '</th> |
|
81 | + <th scope="col" align="left">' . __('Class', 'event_espresso').'->'.__('Method( arguments )', |
|
82 | + 'event_espresso').'</th> |
|
83 | 83 | </tr>'; |
84 | 84 | $last_on_stack = count($trace) - 1; |
85 | 85 | // reverse array so that stack is in proper chronological order |
@@ -90,7 +90,7 @@ discard block |
||
90 | 90 | $type = isset($trace['type']) ? $trace['type'] : ''; |
91 | 91 | $function = isset($trace['function']) ? $trace['function'] : ''; |
92 | 92 | $args = isset($trace['args']) ? $this->_convert_args_to_string($trace['args']) : ''; |
93 | - $args = isset($trace['args']) && count($trace['args']) > 4 ? ' <br />' . $args . '<br />' : $args; |
|
93 | + $args = isset($trace['args']) && count($trace['args']) > 4 ? ' <br />'.$args.'<br />' : $args; |
|
94 | 94 | $line = isset($trace['line']) ? $trace['line'] : ''; |
95 | 95 | $zebra = $nmbr % 2 !== 0 ? ' odd' : ''; |
96 | 96 | if (empty($file) && ! empty($class)) { |
@@ -113,7 +113,7 @@ discard block |
||
113 | 113 | $class_display = ! empty($class) ? $class : ''; |
114 | 114 | $type = ! empty($type) ? $type : ''; |
115 | 115 | $function = ! empty($function) ? $function : ''; |
116 | - $args = ! empty($args) ? '( ' . $args . ' )' : '()'; |
|
116 | + $args = ! empty($args) ? '( '.$args.' )' : '()'; |
|
117 | 117 | $trace_details .= ' |
118 | 118 | <tr> |
119 | 119 | <td align="right" valign="top" class="' |
@@ -147,7 +147,7 @@ discard block |
||
147 | 147 | } |
148 | 148 | $code = $exception->getCode() ? $exception->getCode() : $error_code; |
149 | 149 | // add generic non-identifying messages for non-privileged users |
150 | - if (! WP_DEBUG) { |
|
150 | + if ( ! WP_DEBUG) { |
|
151 | 151 | $output .= '<span class="ee-error-user-msg-spn">' |
152 | 152 | . trim($msg) |
153 | 153 | . '</span> <sup>' |
@@ -164,7 +164,7 @@ discard block |
||
164 | 164 | '<strong class="ee-error-dev-msg-str">', |
165 | 165 | get_class($exception), |
166 | 166 | '</strong> <span>', |
167 | - $code . '</span>' |
|
167 | + $code.'</span>' |
|
168 | 168 | ) |
169 | 169 | . '<br /> |
170 | 170 | <span class="big-text">"' |
@@ -194,14 +194,14 @@ discard block |
||
194 | 194 | . '-dv" class="ee-error-trace-dv" style="display: none;"> |
195 | 195 | ' |
196 | 196 | . $trace_details; |
197 | - if (! empty($class)) { |
|
197 | + if ( ! empty($class)) { |
|
198 | 198 | $output .= ' |
199 | 199 | <div style="padding:3px; margin:0 0 1em; border:1px solid #999; background:#fff; border-radius:3px;"> |
200 | 200 | <div style="padding:1em 2em; border:1px solid #999; background:#fcfcfc;"> |
201 | - <h3>' . __('Class Details', 'event_espresso') . '</h3>'; |
|
201 | + <h3>' . __('Class Details', 'event_espresso').'</h3>'; |
|
202 | 202 | $a = new ReflectionClass($class); |
203 | 203 | $output .= ' |
204 | - <pre>' . $a . '</pre> |
|
204 | + <pre>' . $a.'</pre> |
|
205 | 205 | </div> |
206 | 206 | </div>'; |
207 | 207 | } |
@@ -212,7 +212,7 @@ discard block |
||
212 | 212 | } |
213 | 213 | // remove last linebreak |
214 | 214 | $output = substr($output, 0, -6); |
215 | - if (! WP_DEBUG) { |
|
215 | + if ( ! WP_DEBUG) { |
|
216 | 216 | $output .= ' |
217 | 217 | </p>'; |
218 | 218 | } |
@@ -251,25 +251,25 @@ discard block |
||
251 | 251 | $args[] = ' '; |
252 | 252 | } |
253 | 253 | if (is_string($arg)) { |
254 | - if (! $array && strlen($arg) > 75) { |
|
254 | + if ( ! $array && strlen($arg) > 75) { |
|
255 | 255 | $args[] = '<br />'; |
256 | 256 | for ($i = 0; $i <= $indent; $i++) { |
257 | 257 | $args[] = ' '; |
258 | 258 | } |
259 | - $args[] = "'" . $arg . "'<br />"; |
|
259 | + $args[] = "'".$arg."'<br />"; |
|
260 | 260 | } else { |
261 | - $args[] = " '" . $arg . "'"; |
|
261 | + $args[] = " '".$arg."'"; |
|
262 | 262 | } |
263 | 263 | } elseif (is_array($arg)) { |
264 | 264 | $arg_count = count($arg); |
265 | 265 | if ($arg_count > 2) { |
266 | 266 | $indent++; |
267 | - $args[] = ' array(' . $this->_convert_args_to_string($arg, $indent, true) . ')'; |
|
267 | + $args[] = ' array('.$this->_convert_args_to_string($arg, $indent, true).')'; |
|
268 | 268 | $indent--; |
269 | 269 | } else if ($arg_count === 0) { |
270 | 270 | $args[] = ' array()'; |
271 | 271 | } else { |
272 | - $args[] = ' array( ' . $this->_convert_args_to_string($arg) . ' )'; |
|
272 | + $args[] = ' array( '.$this->_convert_args_to_string($arg).' )'; |
|
273 | 273 | } |
274 | 274 | } elseif ($arg === null) { |
275 | 275 | $args[] = ' null'; |
@@ -313,8 +313,8 @@ discard block |
||
313 | 313 | { |
314 | 314 | $file_bits = explode('.', basename($file)); |
315 | 315 | $error_code = ! empty($file_bits[0]) ? $file_bits[0] : ''; |
316 | - $error_code .= ! empty($func) ? ' - ' . $func : ''; |
|
317 | - $error_code .= ! empty($line) ? ' - ' . $line : ''; |
|
316 | + $error_code .= ! empty($func) ? ' - '.$func : ''; |
|
317 | + $error_code .= ! empty($line) ? ' - '.$line : ''; |
|
318 | 318 | return $error_code; |
319 | 319 | } |
320 | 320 | |
@@ -396,26 +396,26 @@ discard block |
||
396 | 396 | */ |
397 | 397 | private function printScripts($force_print = false) |
398 | 398 | { |
399 | - if (! $force_print && (did_action('admin_enqueue_scripts') || did_action('wp_enqueue_scripts'))) { |
|
399 | + if ( ! $force_print && (did_action('admin_enqueue_scripts') || did_action('wp_enqueue_scripts'))) { |
|
400 | 400 | if (wp_script_is('ee_error_js', 'enqueued')) { |
401 | 401 | return ''; |
402 | 402 | } |
403 | 403 | if (wp_script_is('ee_error_js', 'registered')) { |
404 | 404 | wp_enqueue_style('espresso_default'); |
405 | 405 | wp_enqueue_style('espresso_custom_css'); |
406 | - wp_enqueue_script( 'ee_error_js' ); |
|
407 | - wp_localize_script( 'ee_error_js', 'ee_settings', array( 'wp_debug' => WP_DEBUG ) ); |
|
406 | + wp_enqueue_script('ee_error_js'); |
|
407 | + wp_localize_script('ee_error_js', 'ee_settings', array('wp_debug' => WP_DEBUG)); |
|
408 | 408 | } |
409 | 409 | } else { |
410 | 410 | return ' |
411 | 411 | <script> |
412 | 412 | /* <![CDATA[ */ |
413 | -var ee_settings = {"wp_debug":"' . WP_DEBUG . '"}; |
|
413 | +var ee_settings = {"wp_debug":"' . WP_DEBUG.'"}; |
|
414 | 414 | /* ]]> */ |
415 | 415 | </script> |
416 | -<script src="' . includes_url() . 'js/jquery/jquery.js" type="text/javascript"></script> |
|
417 | -<script src="' . EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js' . '?ver=' . espresso_version() . '" type="text/javascript"></script> |
|
418 | -<script src="' . EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js' . '?ver=' . espresso_version() . '" type="text/javascript"></script> |
|
416 | +<script src="' . includes_url().'js/jquery/jquery.js" type="text/javascript"></script> |
|
417 | +<script src="' . EE_GLOBAL_ASSETS_URL.'scripts/espresso_core.js'.'?ver='.espresso_version().'" type="text/javascript"></script> |
|
418 | +<script src="' . EE_GLOBAL_ASSETS_URL.'scripts/EE_Error.js'.'?ver='.espresso_version().'" type="text/javascript"></script> |
|
419 | 419 | '; |
420 | 420 | } |
421 | 421 | return ''; |
@@ -151,7 +151,7 @@ |
||
151 | 151 | * This provides a count of events using this custom template |
152 | 152 | * |
153 | 153 | * @param EE_Message_Template_Group $item message_template group data |
154 | - * @return string column output |
|
154 | + * @return integer column output |
|
155 | 155 | */ |
156 | 156 | public function column_events($item) |
157 | 157 | { |
@@ -12,246 +12,246 @@ |
||
12 | 12 | class Custom_Messages_Template_List_Table extends Messages_Template_List_Table |
13 | 13 | { |
14 | 14 | |
15 | - /** |
|
16 | - * Setup initial data. |
|
17 | - */ |
|
18 | - protected function _setup_data() |
|
19 | - { |
|
20 | - $this->_data = $this->get_admin_page()->get_message_templates( |
|
21 | - $this->_per_page, |
|
22 | - $this->_view, |
|
23 | - false, |
|
24 | - false, |
|
25 | - false |
|
26 | - ); |
|
27 | - $this->_all_data_count = $this->get_admin_page()->get_message_templates( |
|
28 | - $this->_per_page, |
|
29 | - $this->_view, |
|
30 | - true, |
|
31 | - true, |
|
32 | - false |
|
33 | - ); |
|
34 | - } |
|
15 | + /** |
|
16 | + * Setup initial data. |
|
17 | + */ |
|
18 | + protected function _setup_data() |
|
19 | + { |
|
20 | + $this->_data = $this->get_admin_page()->get_message_templates( |
|
21 | + $this->_per_page, |
|
22 | + $this->_view, |
|
23 | + false, |
|
24 | + false, |
|
25 | + false |
|
26 | + ); |
|
27 | + $this->_all_data_count = $this->get_admin_page()->get_message_templates( |
|
28 | + $this->_per_page, |
|
29 | + $this->_view, |
|
30 | + true, |
|
31 | + true, |
|
32 | + false |
|
33 | + ); |
|
34 | + } |
|
35 | 35 | |
36 | 36 | |
37 | - /** |
|
38 | - * Set initial properties |
|
39 | - */ |
|
40 | - protected function _set_properties() |
|
41 | - { |
|
42 | - parent::_set_properties(); |
|
43 | - $this->_wp_list_args = array( |
|
44 | - 'singular' => esc_html__('Message Template Group', 'event_espresso'), |
|
45 | - 'plural' => esc_html__('Message Template', 'event_espresso'), |
|
46 | - 'ajax' => true, //for now, |
|
47 | - 'screen' => $this->get_admin_page()->get_current_screen()->id, |
|
48 | - ); |
|
37 | + /** |
|
38 | + * Set initial properties |
|
39 | + */ |
|
40 | + protected function _set_properties() |
|
41 | + { |
|
42 | + parent::_set_properties(); |
|
43 | + $this->_wp_list_args = array( |
|
44 | + 'singular' => esc_html__('Message Template Group', 'event_espresso'), |
|
45 | + 'plural' => esc_html__('Message Template', 'event_espresso'), |
|
46 | + 'ajax' => true, //for now, |
|
47 | + 'screen' => $this->get_admin_page()->get_current_screen()->id, |
|
48 | + ); |
|
49 | 49 | |
50 | - $this->_columns = array_merge( |
|
51 | - array( |
|
52 | - 'cb' => '<input type="checkbox" />', |
|
53 | - 'name' => esc_html__('Template Name', 'event_espresso'), |
|
54 | - ), |
|
55 | - $this->_columns, |
|
56 | - array( |
|
57 | - 'events' => esc_html__('Events', 'event_espresso'), |
|
58 | - 'actions' => '' |
|
59 | - ) |
|
60 | - ); |
|
61 | - } |
|
50 | + $this->_columns = array_merge( |
|
51 | + array( |
|
52 | + 'cb' => '<input type="checkbox" />', |
|
53 | + 'name' => esc_html__('Template Name', 'event_espresso'), |
|
54 | + ), |
|
55 | + $this->_columns, |
|
56 | + array( |
|
57 | + 'events' => esc_html__('Events', 'event_espresso'), |
|
58 | + 'actions' => '' |
|
59 | + ) |
|
60 | + ); |
|
61 | + } |
|
62 | 62 | |
63 | 63 | |
64 | - /** |
|
65 | - * Custom message for when there are no items found. |
|
66 | - * |
|
67 | - * @since 4.3.0 |
|
68 | - */ |
|
69 | - public function no_items() |
|
70 | - { |
|
71 | - if ($this->_view !== 'trashed') { |
|
72 | - printf( |
|
73 | - esc_html__( |
|
74 | - '%sNo Custom Templates found.%s To create your first custom message template, go to the "Default Message Templates" tab and click the "Create Custom" button next to the template you want to use as a base for the new one.', |
|
75 | - 'event_espresso' |
|
76 | - ), |
|
77 | - '<strong>', |
|
78 | - '</strong>' |
|
79 | - ); |
|
80 | - } else { |
|
81 | - parent::no_items(); |
|
82 | - } |
|
83 | - } |
|
64 | + /** |
|
65 | + * Custom message for when there are no items found. |
|
66 | + * |
|
67 | + * @since 4.3.0 |
|
68 | + */ |
|
69 | + public function no_items() |
|
70 | + { |
|
71 | + if ($this->_view !== 'trashed') { |
|
72 | + printf( |
|
73 | + esc_html__( |
|
74 | + '%sNo Custom Templates found.%s To create your first custom message template, go to the "Default Message Templates" tab and click the "Create Custom" button next to the template you want to use as a base for the new one.', |
|
75 | + 'event_espresso' |
|
76 | + ), |
|
77 | + '<strong>', |
|
78 | + '</strong>' |
|
79 | + ); |
|
80 | + } else { |
|
81 | + parent::no_items(); |
|
82 | + } |
|
83 | + } |
|
84 | 84 | |
85 | 85 | |
86 | - /** |
|
87 | - * @param EE_Message_Template_Group $item |
|
88 | - * @return string |
|
89 | - */ |
|
90 | - public function column_cb($item) |
|
91 | - { |
|
92 | - return sprintf('<input type="checkbox" name="checkbox[%s]" value="1" />', $item->GRP_ID()); |
|
93 | - } |
|
86 | + /** |
|
87 | + * @param EE_Message_Template_Group $item |
|
88 | + * @return string |
|
89 | + */ |
|
90 | + public function column_cb($item) |
|
91 | + { |
|
92 | + return sprintf('<input type="checkbox" name="checkbox[%s]" value="1" />', $item->GRP_ID()); |
|
93 | + } |
|
94 | 94 | |
95 | 95 | |
96 | - /** |
|
97 | - * @param EE_Message_Template_Group $item |
|
98 | - * @return string |
|
99 | - */ |
|
100 | - public function column_name($item) |
|
101 | - { |
|
102 | - return '<p>' . $item->name() . '</p>'; |
|
103 | - } |
|
96 | + /** |
|
97 | + * @param EE_Message_Template_Group $item |
|
98 | + * @return string |
|
99 | + */ |
|
100 | + public function column_name($item) |
|
101 | + { |
|
102 | + return '<p>' . $item->name() . '</p>'; |
|
103 | + } |
|
104 | 104 | |
105 | 105 | |
106 | - /** |
|
107 | - * @param EE_Message_Template_Group $item |
|
108 | - * @return string |
|
109 | - */ |
|
110 | - public function column_actions($item) |
|
111 | - { |
|
112 | - if (EE_Registry::instance()->CAP->current_user_can( |
|
113 | - 'ee_edit_messages', |
|
114 | - 'espresso_messages_add_new_message_template' |
|
115 | - )) { |
|
116 | - $create_args = array( |
|
117 | - 'GRP_ID' => $item->ID(), |
|
118 | - 'messenger' => $item->messenger(), |
|
119 | - 'message_type' => $item->message_type(), |
|
120 | - 'action' => 'add_new_message_template', |
|
121 | - ); |
|
122 | - $create_link = EE_Admin_Page::add_query_args_and_nonce($create_args, EE_MSG_ADMIN_URL); |
|
123 | - return sprintf( |
|
124 | - '<p><a href="%s" class="button button-small">%s</a></p>', |
|
125 | - $create_link, |
|
126 | - esc_html__('Create Custom', 'event_espresso') |
|
127 | - ); |
|
128 | - } |
|
129 | - return ''; |
|
130 | - } |
|
106 | + /** |
|
107 | + * @param EE_Message_Template_Group $item |
|
108 | + * @return string |
|
109 | + */ |
|
110 | + public function column_actions($item) |
|
111 | + { |
|
112 | + if (EE_Registry::instance()->CAP->current_user_can( |
|
113 | + 'ee_edit_messages', |
|
114 | + 'espresso_messages_add_new_message_template' |
|
115 | + )) { |
|
116 | + $create_args = array( |
|
117 | + 'GRP_ID' => $item->ID(), |
|
118 | + 'messenger' => $item->messenger(), |
|
119 | + 'message_type' => $item->message_type(), |
|
120 | + 'action' => 'add_new_message_template', |
|
121 | + ); |
|
122 | + $create_link = EE_Admin_Page::add_query_args_and_nonce($create_args, EE_MSG_ADMIN_URL); |
|
123 | + return sprintf( |
|
124 | + '<p><a href="%s" class="button button-small">%s</a></p>', |
|
125 | + $create_link, |
|
126 | + esc_html__('Create Custom', 'event_espresso') |
|
127 | + ); |
|
128 | + } |
|
129 | + return ''; |
|
130 | + } |
|
131 | 131 | |
132 | - /** |
|
133 | - * Set the view counts on the _views property |
|
134 | - */ |
|
135 | - protected function _add_view_counts() |
|
136 | - { |
|
137 | - foreach ($this->_views as $view => $args) { |
|
138 | - $this->_views[$view]['count'] = $this->get_admin_page()->get_message_templates( |
|
139 | - $this->_per_page, |
|
140 | - $view, |
|
141 | - true, |
|
142 | - true, |
|
143 | - false |
|
144 | - ); |
|
145 | - } |
|
146 | - } |
|
132 | + /** |
|
133 | + * Set the view counts on the _views property |
|
134 | + */ |
|
135 | + protected function _add_view_counts() |
|
136 | + { |
|
137 | + foreach ($this->_views as $view => $args) { |
|
138 | + $this->_views[$view]['count'] = $this->get_admin_page()->get_message_templates( |
|
139 | + $this->_per_page, |
|
140 | + $view, |
|
141 | + true, |
|
142 | + true, |
|
143 | + false |
|
144 | + ); |
|
145 | + } |
|
146 | + } |
|
147 | 147 | |
148 | 148 | |
149 | - /** |
|
150 | - * column_events |
|
151 | - * This provides a count of events using this custom template |
|
152 | - * |
|
153 | - * @param EE_Message_Template_Group $item message_template group data |
|
154 | - * @return string column output |
|
155 | - */ |
|
156 | - public function column_events($item) |
|
157 | - { |
|
158 | - return $item->count_events(); |
|
159 | - } |
|
149 | + /** |
|
150 | + * column_events |
|
151 | + * This provides a count of events using this custom template |
|
152 | + * |
|
153 | + * @param EE_Message_Template_Group $item message_template group data |
|
154 | + * @return string column output |
|
155 | + */ |
|
156 | + public function column_events($item) |
|
157 | + { |
|
158 | + return $item->count_events(); |
|
159 | + } |
|
160 | 160 | |
161 | 161 | |
162 | - /** |
|
163 | - * Add additional actions for custom message template list view. |
|
164 | - * @param EE_Message_Template_Group $item |
|
165 | - * @return array |
|
166 | - * @throws EE_Error |
|
167 | - */ |
|
168 | - protected function _get_actions_for_messenger_column(EE_Message_Template_Group $item) |
|
169 | - { |
|
170 | - $actions = parent::_get_actions_for_messenger_column($item); |
|
162 | + /** |
|
163 | + * Add additional actions for custom message template list view. |
|
164 | + * @param EE_Message_Template_Group $item |
|
165 | + * @return array |
|
166 | + * @throws EE_Error |
|
167 | + */ |
|
168 | + protected function _get_actions_for_messenger_column(EE_Message_Template_Group $item) |
|
169 | + { |
|
170 | + $actions = parent::_get_actions_for_messenger_column($item); |
|
171 | 171 | |
172 | - //add additional actions for trash/restore etc. |
|
173 | - $trash_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'trash_message_template', |
|
174 | - 'id' => $item->GRP_ID(), |
|
175 | - 'noheader' => true, |
|
176 | - ), EE_MSG_ADMIN_URL); |
|
177 | - // restore link |
|
178 | - $restore_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'restore_message_template', |
|
179 | - 'id' => $item->GRP_ID(), |
|
180 | - 'noheader' => true, |
|
181 | - ), EE_MSG_ADMIN_URL); |
|
182 | - // delete price link |
|
183 | - $delete_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'delete_message_template', |
|
184 | - 'id' => $item->GRP_ID(), |
|
185 | - 'noheader' => true, |
|
186 | - ), EE_MSG_ADMIN_URL); |
|
172 | + //add additional actions for trash/restore etc. |
|
173 | + $trash_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'trash_message_template', |
|
174 | + 'id' => $item->GRP_ID(), |
|
175 | + 'noheader' => true, |
|
176 | + ), EE_MSG_ADMIN_URL); |
|
177 | + // restore link |
|
178 | + $restore_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'restore_message_template', |
|
179 | + 'id' => $item->GRP_ID(), |
|
180 | + 'noheader' => true, |
|
181 | + ), EE_MSG_ADMIN_URL); |
|
182 | + // delete price link |
|
183 | + $delete_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'delete_message_template', |
|
184 | + 'id' => $item->GRP_ID(), |
|
185 | + 'noheader' => true, |
|
186 | + ), EE_MSG_ADMIN_URL); |
|
187 | 187 | |
188 | - if (! $item->get('MTP_deleted') |
|
189 | - && EE_Registry::instance()->CAP->current_user_can( |
|
190 | - 'ee_delete_message', |
|
191 | - 'espresso_messages_trash_message_template', |
|
192 | - $item->ID() |
|
193 | - ) |
|
194 | - ) { |
|
195 | - $actions['trash'] = '<a href="' |
|
196 | - . $trash_lnk_url |
|
197 | - . '" title="' |
|
198 | - . esc_attr__('Move Template Group to Trash', 'event_espresso') |
|
199 | - . '">' |
|
200 | - . esc_html__('Move to Trash', 'event_espresso') |
|
201 | - . '</a>'; |
|
202 | - } else { |
|
203 | - if (EE_Registry::instance()->CAP->current_user_can( |
|
204 | - 'ee_delete_message', |
|
205 | - 'espresso_messages_restore_message_template', |
|
206 | - $item->ID() |
|
207 | - )) { |
|
208 | - $actions['restore'] = '<a href="' |
|
209 | - . $restore_lnk_url |
|
210 | - . '" title="' |
|
211 | - . esc_attr__('Restore Message Template', 'event_espresso') |
|
212 | - . '">' |
|
213 | - . esc_html__('Restore', 'event_espresso') . '</a>'; |
|
214 | - } |
|
188 | + if (! $item->get('MTP_deleted') |
|
189 | + && EE_Registry::instance()->CAP->current_user_can( |
|
190 | + 'ee_delete_message', |
|
191 | + 'espresso_messages_trash_message_template', |
|
192 | + $item->ID() |
|
193 | + ) |
|
194 | + ) { |
|
195 | + $actions['trash'] = '<a href="' |
|
196 | + . $trash_lnk_url |
|
197 | + . '" title="' |
|
198 | + . esc_attr__('Move Template Group to Trash', 'event_espresso') |
|
199 | + . '">' |
|
200 | + . esc_html__('Move to Trash', 'event_espresso') |
|
201 | + . '</a>'; |
|
202 | + } else { |
|
203 | + if (EE_Registry::instance()->CAP->current_user_can( |
|
204 | + 'ee_delete_message', |
|
205 | + 'espresso_messages_restore_message_template', |
|
206 | + $item->ID() |
|
207 | + )) { |
|
208 | + $actions['restore'] = '<a href="' |
|
209 | + . $restore_lnk_url |
|
210 | + . '" title="' |
|
211 | + . esc_attr__('Restore Message Template', 'event_espresso') |
|
212 | + . '">' |
|
213 | + . esc_html__('Restore', 'event_espresso') . '</a>'; |
|
214 | + } |
|
215 | 215 | |
216 | - if ($this->_view === 'trashed' |
|
217 | - && EE_Registry::instance()->CAP->current_user_can( |
|
218 | - 'ee_delete_message', |
|
219 | - 'espresso_messages_delete_message_template', |
|
220 | - $item->ID() |
|
221 | - )) { |
|
222 | - $actions['delete'] = '<a href="' |
|
223 | - . $delete_lnk_url |
|
224 | - . '" title="' |
|
225 | - . esc_attr__('Delete Template Group Permanently', 'event_espresso') |
|
226 | - . '">' |
|
227 | - . esc_html__('Delete Permanently', 'event_espresso') |
|
228 | - . '</a>'; |
|
229 | - } |
|
230 | - } |
|
231 | - return $actions; |
|
232 | - } |
|
216 | + if ($this->_view === 'trashed' |
|
217 | + && EE_Registry::instance()->CAP->current_user_can( |
|
218 | + 'ee_delete_message', |
|
219 | + 'espresso_messages_delete_message_template', |
|
220 | + $item->ID() |
|
221 | + )) { |
|
222 | + $actions['delete'] = '<a href="' |
|
223 | + . $delete_lnk_url |
|
224 | + . '" title="' |
|
225 | + . esc_attr__('Delete Template Group Permanently', 'event_espresso') |
|
226 | + . '">' |
|
227 | + . esc_html__('Delete Permanently', 'event_espresso') |
|
228 | + . '</a>'; |
|
229 | + } |
|
230 | + } |
|
231 | + return $actions; |
|
232 | + } |
|
233 | 233 | |
234 | 234 | |
235 | - /** |
|
236 | - * Generate dropdown filter select input for messengers |
|
237 | - * @param bool $global |
|
238 | - * @return string |
|
239 | - * @throws EE_Error |
|
240 | - */ |
|
241 | - protected function _get_messengers_dropdown_filter($global = true) |
|
242 | - { |
|
243 | - return parent::_get_messengers_dropdown_filter(false); |
|
244 | - } |
|
235 | + /** |
|
236 | + * Generate dropdown filter select input for messengers |
|
237 | + * @param bool $global |
|
238 | + * @return string |
|
239 | + * @throws EE_Error |
|
240 | + */ |
|
241 | + protected function _get_messengers_dropdown_filter($global = true) |
|
242 | + { |
|
243 | + return parent::_get_messengers_dropdown_filter(false); |
|
244 | + } |
|
245 | 245 | |
246 | 246 | |
247 | - /** |
|
248 | - * Generate dropdown filter select input for message types |
|
249 | - * @param bool $global |
|
250 | - * @return string |
|
251 | - * @throws EE_Error |
|
252 | - */ |
|
253 | - protected function _get_message_types_dropdown_filter($global = true) |
|
254 | - { |
|
255 | - return parent::_get_message_types_dropdown_filter(false); |
|
256 | - } |
|
247 | + /** |
|
248 | + * Generate dropdown filter select input for message types |
|
249 | + * @param bool $global |
|
250 | + * @return string |
|
251 | + * @throws EE_Error |
|
252 | + */ |
|
253 | + protected function _get_message_types_dropdown_filter($global = true) |
|
254 | + { |
|
255 | + return parent::_get_message_types_dropdown_filter(false); |
|
256 | + } |
|
257 | 257 | } |
@@ -17,7 +17,7 @@ discard block |
||
17 | 17 | */ |
18 | 18 | protected function _setup_data() |
19 | 19 | { |
20 | - $this->_data = $this->get_admin_page()->get_message_templates( |
|
20 | + $this->_data = $this->get_admin_page()->get_message_templates( |
|
21 | 21 | $this->_per_page, |
22 | 22 | $this->_view, |
23 | 23 | false, |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | */ |
100 | 100 | public function column_name($item) |
101 | 101 | { |
102 | - return '<p>' . $item->name() . '</p>'; |
|
102 | + return '<p>'.$item->name().'</p>'; |
|
103 | 103 | } |
104 | 104 | |
105 | 105 | |
@@ -185,7 +185,7 @@ discard block |
||
185 | 185 | 'noheader' => true, |
186 | 186 | ), EE_MSG_ADMIN_URL); |
187 | 187 | |
188 | - if (! $item->get('MTP_deleted') |
|
188 | + if ( ! $item->get('MTP_deleted') |
|
189 | 189 | && EE_Registry::instance()->CAP->current_user_can( |
190 | 190 | 'ee_delete_message', |
191 | 191 | 'espresso_messages_trash_message_template', |
@@ -210,7 +210,7 @@ discard block |
||
210 | 210 | . '" title="' |
211 | 211 | . esc_attr__('Restore Message Template', 'event_espresso') |
212 | 212 | . '">' |
213 | - . esc_html__('Restore', 'event_espresso') . '</a>'; |
|
213 | + . esc_html__('Restore', 'event_espresso').'</a>'; |
|
214 | 214 | } |
215 | 215 | |
216 | 216 | if ($this->_view === 'trashed' |
@@ -27,7 +27,7 @@ discard block |
||
27 | 27 | */ |
28 | 28 | protected function _setup_data() |
29 | 29 | { |
30 | - $this->_data = $this->get_admin_page()->get_message_templates( |
|
30 | + $this->_data = $this->get_admin_page()->get_message_templates( |
|
31 | 31 | $this->_per_page, |
32 | 32 | $this->_view, |
33 | 33 | false |
@@ -52,7 +52,7 @@ discard block |
||
52 | 52 | 'ajax' => true, //for now, |
53 | 53 | 'screen' => $this->get_admin_page()->get_current_screen()->id, |
54 | 54 | ); |
55 | - $this->_columns = array( |
|
55 | + $this->_columns = array( |
|
56 | 56 | //'cb' => '<input type="checkbox" />', //no deleting default (global) templates! |
57 | 57 | 'message_type' => esc_html__('Message Type', 'event_espresso'), |
58 | 58 | 'messenger' => esc_html__('Messenger', 'event_espresso'), |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | $message_type = $item->message_type_obj(); |
81 | 81 | $messenger = $item->messenger_obj(); |
82 | 82 | |
83 | - if (! $message_type instanceof EE_message_type || ! $messenger instanceof EE_messenger) { |
|
83 | + if ( ! $message_type instanceof EE_message_type || ! $messenger instanceof EE_messenger) { |
|
84 | 84 | echo ''; |
85 | 85 | return; |
86 | 86 | } |
@@ -156,7 +156,7 @@ discard block |
||
156 | 156 | */ |
157 | 157 | public function column_description($item) |
158 | 158 | { |
159 | - return '<p>' . $item->message_type_obj()->description . '</p>'; |
|
159 | + return '<p>'.$item->message_type_obj()->description.'</p>'; |
|
160 | 160 | } |
161 | 161 | |
162 | 162 | |
@@ -268,7 +268,7 @@ discard block |
||
268 | 268 | { |
269 | 269 | $edit_url = ''; |
270 | 270 | // edit link but only if item isn't trashed. |
271 | - if (! $item->get('MTP_deleted') |
|
271 | + if ( ! $item->get('MTP_deleted') |
|
272 | 272 | && EE_Registry::instance()->CAP->current_user_can( |
273 | 273 | 'ee_edit_message', |
274 | 274 | 'espresso_messages_edit_message_template', |
@@ -295,7 +295,7 @@ discard block |
||
295 | 295 | protected function _get_context_links(EE_Message_Template_Group $item) |
296 | 296 | { |
297 | 297 | //first check if we even show the context links or not. |
298 | - if (! EE_Registry::instance()->CAP->current_user_can( |
|
298 | + if ( ! EE_Registry::instance()->CAP->current_user_can( |
|
299 | 299 | 'ee_edit_message', |
300 | 300 | 'espresso_messages_edit_message_template', |
301 | 301 | $item->ID() |
@@ -314,7 +314,7 @@ discard block |
||
314 | 314 | && $context_templates[$context]['to'] instanceof EE_Message_Template |
315 | 315 | ? $context_templates[$context]['to']->get('MTP_content') |
316 | 316 | : null; |
317 | - $inactive = empty($mtp_to) |
|
317 | + $inactive = empty($mtp_to) |
|
318 | 318 | && ! empty($context_templates[$context]['to']) |
319 | 319 | ? ' class="mtp-inactive"' |
320 | 320 | : ''; |
@@ -324,15 +324,15 @@ discard block |
||
324 | 324 | 'id' => $item->GRP_ID(), |
325 | 325 | 'context' => $context, |
326 | 326 | ), EE_MSG_ADMIN_URL); |
327 | - $ctxt[] = '<a' . $inactive |
|
328 | - . ' href="' . $edit_link . '"' |
|
329 | - . ' class="' . $item->message_type() . '-' . $context . '-edit-link"' |
|
330 | - . ' title="' . esc_attr__('Edit Context', 'event_espresso') . '">' |
|
327 | + $ctxt[] = '<a'.$inactive |
|
328 | + . ' href="'.$edit_link.'"' |
|
329 | + . ' class="'.$item->message_type().'-'.$context.'-edit-link"' |
|
330 | + . ' title="'.esc_attr__('Edit Context', 'event_espresso').'">' |
|
331 | 331 | . $context_title |
332 | 332 | . '</a>'; |
333 | 333 | } |
334 | 334 | |
335 | - return sprintf('<strong>%s:</strong> ', ucwords($c_label['plural'])) . implode(' | ', $ctxt); |
|
335 | + return sprintf('<strong>%s:</strong> ', ucwords($c_label['plural'])).implode(' | ', $ctxt); |
|
336 | 336 | } |
337 | 337 | |
338 | 338 | |
@@ -346,8 +346,8 @@ discard block |
||
346 | 346 | { |
347 | 347 | $edit_url = $this->_get_edit_url($item); |
348 | 348 | return $edit_url |
349 | - ? '<a href="' . $edit_url . '"' |
|
350 | - . ' title="' . esc_attr__('Edit Template Group', 'event_espresso') . '">' |
|
349 | + ? '<a href="'.$edit_url.'"' |
|
350 | + . ' title="'.esc_attr__('Edit Template Group', 'event_espresso').'">' |
|
351 | 351 | . ucwords($item->messenger_obj()->label['singular']) |
352 | 352 | . '</a>' |
353 | 353 | : ucwords($item->messenger_obj()->label['singular']); |
@@ -365,9 +365,9 @@ discard block |
||
365 | 365 | $actions = array(); |
366 | 366 | if ($edit_url = $this->_get_edit_url($item)) { |
367 | 367 | $actions = array( |
368 | - 'edit' => '<a href="' . $edit_url . '"' |
|
369 | - . ' class="' . $item->message_type() . '-edit-link"' |
|
370 | - . ' title="' . esc_attr__('Edit Template Group', 'event_espresso') . '">' |
|
368 | + 'edit' => '<a href="'.$edit_url.'"' |
|
369 | + . ' class="'.$item->message_type().'-edit-link"' |
|
370 | + . ' title="'.esc_attr__('Edit Template Group', 'event_espresso').'">' |
|
371 | 371 | . esc_html__('Edit', 'event_espresso') |
372 | 372 | . '</a>' |
373 | 373 | ); |
@@ -13,370 +13,370 @@ |
||
13 | 13 | { |
14 | 14 | |
15 | 15 | |
16 | - /** |
|
17 | - * @return Messages_Admin_Page |
|
18 | - */ |
|
19 | - public function get_admin_page() |
|
20 | - { |
|
21 | - return $this->_admin_page; |
|
22 | - } |
|
23 | - |
|
24 | - |
|
25 | - /** |
|
26 | - * Setup data object |
|
27 | - */ |
|
28 | - protected function _setup_data() |
|
29 | - { |
|
30 | - $this->_data = $this->get_admin_page()->get_message_templates( |
|
31 | - $this->_per_page, |
|
32 | - $this->_view, |
|
33 | - false |
|
34 | - ); |
|
35 | - $this->_all_data_count = $this->get_admin_page()->get_message_templates( |
|
36 | - $this->_per_page, |
|
37 | - $this->_view, |
|
38 | - true, |
|
39 | - true |
|
40 | - ); |
|
41 | - } |
|
42 | - |
|
43 | - |
|
44 | - /** |
|
45 | - * Set internal properties |
|
46 | - */ |
|
47 | - protected function _set_properties() |
|
48 | - { |
|
49 | - $this->_wp_list_args = array( |
|
50 | - 'singular' => esc_html__('Message Template Group', 'event_espresso'), |
|
51 | - 'plural' => esc_html__('Message Template', 'event_espresso'), |
|
52 | - 'ajax' => true, //for now, |
|
53 | - 'screen' => $this->get_admin_page()->get_current_screen()->id, |
|
54 | - ); |
|
55 | - $this->_columns = array( |
|
56 | - //'cb' => '<input type="checkbox" />', //no deleting default (global) templates! |
|
57 | - 'message_type' => esc_html__('Message Type', 'event_espresso'), |
|
58 | - 'messenger' => esc_html__('Messenger', 'event_espresso'), |
|
59 | - 'description' => esc_html__('Description', 'event_espresso'), |
|
60 | - ); |
|
61 | - |
|
62 | - $this->_sortable_columns = array( |
|
63 | - 'messenger' => array('MTP_messenger' => true), |
|
64 | - ); |
|
65 | - |
|
66 | - $this->_hidden_columns = array(); |
|
67 | - } |
|
68 | - |
|
69 | - |
|
70 | - /** |
|
71 | - * Overriding the single_row method from parent to verify whether the $item has an accessible |
|
72 | - * message_type or messenger object before generating the row. |
|
73 | - * |
|
74 | - * @param EE_Message_Template_Group $item |
|
75 | - * @return string |
|
76 | - * @throws EE_Error |
|
77 | - */ |
|
78 | - public function single_row($item) |
|
79 | - { |
|
80 | - $message_type = $item->message_type_obj(); |
|
81 | - $messenger = $item->messenger_obj(); |
|
82 | - |
|
83 | - if (! $message_type instanceof EE_message_type || ! $messenger instanceof EE_messenger) { |
|
84 | - echo ''; |
|
85 | - return; |
|
86 | - } |
|
87 | - |
|
88 | - parent::single_row($item); |
|
89 | - } |
|
90 | - |
|
91 | - |
|
92 | - /** |
|
93 | - * @return array |
|
94 | - * @throws EE_Error |
|
95 | - */ |
|
96 | - protected function _get_table_filters() |
|
97 | - { |
|
98 | - $filters = array(); |
|
99 | - |
|
100 | - //get select inputs |
|
101 | - $select_inputs = array( |
|
102 | - $this->_get_messengers_dropdown_filter(), |
|
103 | - $this->_get_message_types_dropdown_filter(), |
|
104 | - ); |
|
105 | - |
|
106 | - //set filters to select inputs if they aren't empty |
|
107 | - foreach ($select_inputs as $select_input) { |
|
108 | - if ($select_input) { |
|
109 | - $filters[] = $select_input; |
|
110 | - } |
|
111 | - } |
|
112 | - return $filters; |
|
113 | - } |
|
114 | - |
|
115 | - /** |
|
116 | - * We're just removing the search box for message templates, not needed. |
|
117 | - * |
|
118 | - * @param string $text |
|
119 | - * @param string $input_id |
|
120 | - * @return string ; |
|
121 | - */ |
|
122 | - public function search_box($text, $input_id) |
|
123 | - { |
|
124 | - return ''; |
|
125 | - } |
|
126 | - |
|
127 | - |
|
128 | - /** |
|
129 | - * Add counts to the _views property |
|
130 | - */ |
|
131 | - protected function _add_view_counts() |
|
132 | - { |
|
133 | - foreach ($this->_views as $view => $args) { |
|
134 | - $this->_views[$view]['count'] = $this->get_admin_page()->get_message_templates( |
|
135 | - $this->_per_page, |
|
136 | - $view, |
|
137 | - true, |
|
138 | - true |
|
139 | - ); |
|
140 | - } |
|
141 | - } |
|
142 | - |
|
143 | - |
|
144 | - /** |
|
145 | - * @param EE_Message_Template_Group $item |
|
146 | - * @return string |
|
147 | - */ |
|
148 | - public function column_cb($item) |
|
149 | - { |
|
150 | - return ''; |
|
151 | - } |
|
152 | - |
|
153 | - |
|
154 | - /** |
|
155 | - * @param EE_Message_Template_Group $item |
|
156 | - * @return string |
|
157 | - * @throws EE_Error |
|
158 | - */ |
|
159 | - public function column_description($item) |
|
160 | - { |
|
161 | - return '<p>' . $item->message_type_obj()->description . '</p>'; |
|
162 | - } |
|
163 | - |
|
164 | - |
|
165 | - /** |
|
166 | - * @param EE_Message_Template_Group $item |
|
167 | - * @return string |
|
168 | - * @throws EE_Error |
|
169 | - */ |
|
170 | - public function column_messenger($item) |
|
171 | - { |
|
172 | - //Return the name contents |
|
173 | - return sprintf( |
|
174 | - '%1$s <span style="color:silver">(id:%2$s)</span><br />%3$s%4$s', |
|
175 | - /* $1%s */ |
|
176 | - $this->_get_name_link_for_messenger($item), |
|
177 | - /* $2%s */ |
|
178 | - $item->GRP_ID(), |
|
179 | - /* %4$s */ |
|
180 | - $this->_get_context_links($item), |
|
181 | - /* $3%s */ |
|
182 | - $this->row_actions($this->_get_actions_for_messenger_column($item)) |
|
183 | - ); |
|
184 | - } |
|
185 | - |
|
186 | - /** |
|
187 | - * column_message_type |
|
188 | - * |
|
189 | - * @param EE_Message_Template_Group $item message info for the row |
|
190 | - * @return string message_type name |
|
191 | - * @throws EE_Error |
|
192 | - */ |
|
193 | - public function column_message_type($item) |
|
194 | - { |
|
195 | - return ucwords($item->message_type_obj()->label['singular']); |
|
196 | - } |
|
197 | - |
|
198 | - |
|
199 | - /** |
|
200 | - * Generate dropdown filter select input for messengers |
|
201 | - * |
|
202 | - * @param bool $global |
|
203 | - * @return string |
|
204 | - * @throws EE_Error |
|
205 | - */ |
|
206 | - protected function _get_messengers_dropdown_filter($global = true) |
|
207 | - { |
|
208 | - $messenger_options = array(); |
|
209 | - $active_message_template_groups_grouped_by_messenger = EEM_Message_Template_Group::instance()->get_all( |
|
210 | - array( |
|
211 | - array( |
|
212 | - 'MTP_is_active' => true, |
|
213 | - 'MTP_is_global' => $global, |
|
214 | - ), |
|
215 | - 'group_by' => 'MTP_messenger', |
|
216 | - ) |
|
217 | - ); |
|
218 | - |
|
219 | - foreach ($active_message_template_groups_grouped_by_messenger as $active_message_template_group) { |
|
220 | - if ($active_message_template_group instanceof EE_Message_Template_Group) { |
|
221 | - $messenger = $active_message_template_group->messenger_obj(); |
|
222 | - $messenger_label = $messenger instanceof EE_messenger |
|
223 | - ? $messenger->label['singular'] |
|
224 | - : $active_message_template_group->messenger(); |
|
225 | - $messenger_options[$active_message_template_group->messenger()] = ucwords($messenger_label); |
|
226 | - } |
|
227 | - } |
|
228 | - return $this->get_admin_page()->get_messengers_select_input($messenger_options); |
|
229 | - } |
|
230 | - |
|
231 | - |
|
232 | - /** |
|
233 | - * Generate dropdown filter select input for message types |
|
234 | - * |
|
235 | - * @param bool $global |
|
236 | - * @return string |
|
237 | - * @throws EE_Error |
|
238 | - */ |
|
239 | - protected function _get_message_types_dropdown_filter($global = true) |
|
240 | - { |
|
241 | - $message_type_options = array(); |
|
242 | - $active_message_template_groups_grouped_by_message_type = EEM_Message_Template_Group::instance()->get_all( |
|
243 | - array( |
|
244 | - array( |
|
245 | - 'MTP_is_active' => true, |
|
246 | - 'MTP_is_global' => true, |
|
247 | - ), |
|
248 | - 'group_by' => 'MTP_message_type', |
|
249 | - ) |
|
250 | - ); |
|
251 | - |
|
252 | - foreach ($active_message_template_groups_grouped_by_message_type as $active_message_template_group) { |
|
253 | - if ($active_message_template_group instanceof EE_Message_Template_Group) { |
|
254 | - $message_type = $active_message_template_group->message_type_obj(); |
|
255 | - $message_type_label = $message_type instanceof EE_message_type |
|
256 | - ? $message_type->label['singular'] |
|
257 | - : $active_message_template_group->message_type(); |
|
258 | - $message_type_options[$active_message_template_group->message_type()] = ucwords($message_type_label); |
|
259 | - } |
|
260 | - } |
|
261 | - return $this->get_admin_page()->get_message_types_select_input($message_type_options); |
|
262 | - } |
|
263 | - |
|
264 | - |
|
265 | - /** |
|
266 | - * Return the edit url for the message template group. |
|
267 | - * @param EE_Message_Template_Group $item |
|
268 | - * @return string |
|
269 | - * @throws EE_Error |
|
270 | - */ |
|
271 | - protected function _get_edit_url(EE_Message_Template_Group $item) |
|
272 | - { |
|
273 | - $edit_url = ''; |
|
274 | - // edit link but only if item isn't trashed. |
|
275 | - if (! $item->get('MTP_deleted') |
|
276 | - && EE_Registry::instance()->CAP->current_user_can( |
|
277 | - 'ee_edit_message', |
|
278 | - 'espresso_messages_edit_message_template', |
|
279 | - $item->ID() |
|
280 | - )) { |
|
281 | - $edit_url = EE_Admin_Page::add_query_args_and_nonce( |
|
282 | - array( |
|
283 | - 'action' => 'edit_message_template', |
|
284 | - 'id' => $item->GRP_ID(), |
|
285 | - ), |
|
286 | - EE_MSG_ADMIN_URL |
|
287 | - ); |
|
288 | - } |
|
289 | - return $edit_url; |
|
290 | - } |
|
291 | - |
|
292 | - |
|
293 | - /** |
|
294 | - * Get the context link string for the messenger column. |
|
295 | - * @param EE_Message_Template_Group $item |
|
296 | - * @return string |
|
297 | - * @throws EE_Error |
|
298 | - */ |
|
299 | - protected function _get_context_links(EE_Message_Template_Group $item) |
|
300 | - { |
|
301 | - //first check if we even show the context links or not. |
|
302 | - if (! EE_Registry::instance()->CAP->current_user_can( |
|
303 | - 'ee_edit_message', |
|
304 | - 'espresso_messages_edit_message_template', |
|
305 | - $item->ID() |
|
306 | - ) |
|
307 | - || $item->get('MTP_deleted') |
|
308 | - ) { |
|
309 | - return ''; |
|
310 | - } |
|
311 | - //we want to display the contexts in here so we need to set them up |
|
312 | - $c_label = $item->context_label(); |
|
313 | - $c_configs = $item->contexts_config(); |
|
314 | - $ctxt = array(); |
|
315 | - $context_templates = $item->context_templates(); |
|
316 | - foreach ($context_templates as $context => $template_fields) { |
|
317 | - $mtp_to = ! empty($context_templates[$context]['to']) |
|
318 | - && $context_templates[$context]['to'] instanceof EE_Message_Template |
|
319 | - ? $context_templates[$context]['to']->get('MTP_content') |
|
320 | - : null; |
|
321 | - $inactive = empty($mtp_to) |
|
322 | - && ! empty($context_templates[$context]['to']) |
|
323 | - ? ' class="mtp-inactive"' |
|
324 | - : ''; |
|
325 | - $context_title = ucwords($c_configs[$context]['label']); |
|
326 | - $edit_link = EE_Admin_Page::add_query_args_and_nonce(array( |
|
327 | - 'action' => 'edit_message_template', |
|
328 | - 'id' => $item->GRP_ID(), |
|
329 | - 'context' => $context, |
|
330 | - ), EE_MSG_ADMIN_URL); |
|
331 | - $ctxt[] = '<a' . $inactive |
|
332 | - . ' href="' . $edit_link . '"' |
|
333 | - . ' class="' . $item->message_type() . '-' . $context . '-edit-link"' |
|
334 | - . ' title="' . esc_attr__('Edit Context', 'event_espresso') . '">' |
|
335 | - . $context_title |
|
336 | - . '</a>'; |
|
337 | - } |
|
338 | - |
|
339 | - return sprintf('<strong>%s:</strong> ', ucwords($c_label['plural'])) . implode(' | ', $ctxt); |
|
340 | - } |
|
341 | - |
|
342 | - |
|
343 | - /** |
|
344 | - * Get the Name string from the messenger column (linked to edit if the context allows for that). |
|
345 | - * @param EE_Message_Template_Group $item |
|
346 | - * @return string |
|
347 | - * @throws EE_Error |
|
348 | - */ |
|
349 | - protected function _get_name_link_for_messenger(EE_Message_Template_Group $item) |
|
350 | - { |
|
351 | - $edit_url = $this->_get_edit_url($item); |
|
352 | - return $edit_url |
|
353 | - ? '<a href="' . $edit_url . '"' |
|
354 | - . ' title="' . esc_attr__('Edit Template Group', 'event_espresso') . '">' |
|
355 | - . ucwords($item->messenger_obj()->label['singular']) |
|
356 | - . '</a>' |
|
357 | - : ucwords($item->messenger_obj()->label['singular']); |
|
358 | - } |
|
359 | - |
|
360 | - |
|
361 | - /** |
|
362 | - * Return the actions array for the messenger column. |
|
363 | - * @param EE_Message_Template_Group $item |
|
364 | - * @return array |
|
365 | - * @throws EE_Error |
|
366 | - */ |
|
367 | - protected function _get_actions_for_messenger_column(EE_Message_Template_Group $item) |
|
368 | - { |
|
369 | - $actions = array(); |
|
370 | - if ($edit_url = $this->_get_edit_url($item)) { |
|
371 | - $actions = array( |
|
372 | - 'edit' => '<a href="' . $edit_url . '"' |
|
373 | - . ' class="' . $item->message_type() . '-edit-link"' |
|
374 | - . ' title="' . esc_attr__('Edit Template Group', 'event_espresso') . '">' |
|
375 | - . esc_html__('Edit', 'event_espresso') |
|
376 | - . '</a>' |
|
377 | - ); |
|
378 | - } |
|
379 | - return $actions; |
|
380 | - } |
|
16 | + /** |
|
17 | + * @return Messages_Admin_Page |
|
18 | + */ |
|
19 | + public function get_admin_page() |
|
20 | + { |
|
21 | + return $this->_admin_page; |
|
22 | + } |
|
23 | + |
|
24 | + |
|
25 | + /** |
|
26 | + * Setup data object |
|
27 | + */ |
|
28 | + protected function _setup_data() |
|
29 | + { |
|
30 | + $this->_data = $this->get_admin_page()->get_message_templates( |
|
31 | + $this->_per_page, |
|
32 | + $this->_view, |
|
33 | + false |
|
34 | + ); |
|
35 | + $this->_all_data_count = $this->get_admin_page()->get_message_templates( |
|
36 | + $this->_per_page, |
|
37 | + $this->_view, |
|
38 | + true, |
|
39 | + true |
|
40 | + ); |
|
41 | + } |
|
42 | + |
|
43 | + |
|
44 | + /** |
|
45 | + * Set internal properties |
|
46 | + */ |
|
47 | + protected function _set_properties() |
|
48 | + { |
|
49 | + $this->_wp_list_args = array( |
|
50 | + 'singular' => esc_html__('Message Template Group', 'event_espresso'), |
|
51 | + 'plural' => esc_html__('Message Template', 'event_espresso'), |
|
52 | + 'ajax' => true, //for now, |
|
53 | + 'screen' => $this->get_admin_page()->get_current_screen()->id, |
|
54 | + ); |
|
55 | + $this->_columns = array( |
|
56 | + //'cb' => '<input type="checkbox" />', //no deleting default (global) templates! |
|
57 | + 'message_type' => esc_html__('Message Type', 'event_espresso'), |
|
58 | + 'messenger' => esc_html__('Messenger', 'event_espresso'), |
|
59 | + 'description' => esc_html__('Description', 'event_espresso'), |
|
60 | + ); |
|
61 | + |
|
62 | + $this->_sortable_columns = array( |
|
63 | + 'messenger' => array('MTP_messenger' => true), |
|
64 | + ); |
|
65 | + |
|
66 | + $this->_hidden_columns = array(); |
|
67 | + } |
|
68 | + |
|
69 | + |
|
70 | + /** |
|
71 | + * Overriding the single_row method from parent to verify whether the $item has an accessible |
|
72 | + * message_type or messenger object before generating the row. |
|
73 | + * |
|
74 | + * @param EE_Message_Template_Group $item |
|
75 | + * @return string |
|
76 | + * @throws EE_Error |
|
77 | + */ |
|
78 | + public function single_row($item) |
|
79 | + { |
|
80 | + $message_type = $item->message_type_obj(); |
|
81 | + $messenger = $item->messenger_obj(); |
|
82 | + |
|
83 | + if (! $message_type instanceof EE_message_type || ! $messenger instanceof EE_messenger) { |
|
84 | + echo ''; |
|
85 | + return; |
|
86 | + } |
|
87 | + |
|
88 | + parent::single_row($item); |
|
89 | + } |
|
90 | + |
|
91 | + |
|
92 | + /** |
|
93 | + * @return array |
|
94 | + * @throws EE_Error |
|
95 | + */ |
|
96 | + protected function _get_table_filters() |
|
97 | + { |
|
98 | + $filters = array(); |
|
99 | + |
|
100 | + //get select inputs |
|
101 | + $select_inputs = array( |
|
102 | + $this->_get_messengers_dropdown_filter(), |
|
103 | + $this->_get_message_types_dropdown_filter(), |
|
104 | + ); |
|
105 | + |
|
106 | + //set filters to select inputs if they aren't empty |
|
107 | + foreach ($select_inputs as $select_input) { |
|
108 | + if ($select_input) { |
|
109 | + $filters[] = $select_input; |
|
110 | + } |
|
111 | + } |
|
112 | + return $filters; |
|
113 | + } |
|
114 | + |
|
115 | + /** |
|
116 | + * We're just removing the search box for message templates, not needed. |
|
117 | + * |
|
118 | + * @param string $text |
|
119 | + * @param string $input_id |
|
120 | + * @return string ; |
|
121 | + */ |
|
122 | + public function search_box($text, $input_id) |
|
123 | + { |
|
124 | + return ''; |
|
125 | + } |
|
126 | + |
|
127 | + |
|
128 | + /** |
|
129 | + * Add counts to the _views property |
|
130 | + */ |
|
131 | + protected function _add_view_counts() |
|
132 | + { |
|
133 | + foreach ($this->_views as $view => $args) { |
|
134 | + $this->_views[$view]['count'] = $this->get_admin_page()->get_message_templates( |
|
135 | + $this->_per_page, |
|
136 | + $view, |
|
137 | + true, |
|
138 | + true |
|
139 | + ); |
|
140 | + } |
|
141 | + } |
|
142 | + |
|
143 | + |
|
144 | + /** |
|
145 | + * @param EE_Message_Template_Group $item |
|
146 | + * @return string |
|
147 | + */ |
|
148 | + public function column_cb($item) |
|
149 | + { |
|
150 | + return ''; |
|
151 | + } |
|
152 | + |
|
153 | + |
|
154 | + /** |
|
155 | + * @param EE_Message_Template_Group $item |
|
156 | + * @return string |
|
157 | + * @throws EE_Error |
|
158 | + */ |
|
159 | + public function column_description($item) |
|
160 | + { |
|
161 | + return '<p>' . $item->message_type_obj()->description . '</p>'; |
|
162 | + } |
|
163 | + |
|
164 | + |
|
165 | + /** |
|
166 | + * @param EE_Message_Template_Group $item |
|
167 | + * @return string |
|
168 | + * @throws EE_Error |
|
169 | + */ |
|
170 | + public function column_messenger($item) |
|
171 | + { |
|
172 | + //Return the name contents |
|
173 | + return sprintf( |
|
174 | + '%1$s <span style="color:silver">(id:%2$s)</span><br />%3$s%4$s', |
|
175 | + /* $1%s */ |
|
176 | + $this->_get_name_link_for_messenger($item), |
|
177 | + /* $2%s */ |
|
178 | + $item->GRP_ID(), |
|
179 | + /* %4$s */ |
|
180 | + $this->_get_context_links($item), |
|
181 | + /* $3%s */ |
|
182 | + $this->row_actions($this->_get_actions_for_messenger_column($item)) |
|
183 | + ); |
|
184 | + } |
|
185 | + |
|
186 | + /** |
|
187 | + * column_message_type |
|
188 | + * |
|
189 | + * @param EE_Message_Template_Group $item message info for the row |
|
190 | + * @return string message_type name |
|
191 | + * @throws EE_Error |
|
192 | + */ |
|
193 | + public function column_message_type($item) |
|
194 | + { |
|
195 | + return ucwords($item->message_type_obj()->label['singular']); |
|
196 | + } |
|
197 | + |
|
198 | + |
|
199 | + /** |
|
200 | + * Generate dropdown filter select input for messengers |
|
201 | + * |
|
202 | + * @param bool $global |
|
203 | + * @return string |
|
204 | + * @throws EE_Error |
|
205 | + */ |
|
206 | + protected function _get_messengers_dropdown_filter($global = true) |
|
207 | + { |
|
208 | + $messenger_options = array(); |
|
209 | + $active_message_template_groups_grouped_by_messenger = EEM_Message_Template_Group::instance()->get_all( |
|
210 | + array( |
|
211 | + array( |
|
212 | + 'MTP_is_active' => true, |
|
213 | + 'MTP_is_global' => $global, |
|
214 | + ), |
|
215 | + 'group_by' => 'MTP_messenger', |
|
216 | + ) |
|
217 | + ); |
|
218 | + |
|
219 | + foreach ($active_message_template_groups_grouped_by_messenger as $active_message_template_group) { |
|
220 | + if ($active_message_template_group instanceof EE_Message_Template_Group) { |
|
221 | + $messenger = $active_message_template_group->messenger_obj(); |
|
222 | + $messenger_label = $messenger instanceof EE_messenger |
|
223 | + ? $messenger->label['singular'] |
|
224 | + : $active_message_template_group->messenger(); |
|
225 | + $messenger_options[$active_message_template_group->messenger()] = ucwords($messenger_label); |
|
226 | + } |
|
227 | + } |
|
228 | + return $this->get_admin_page()->get_messengers_select_input($messenger_options); |
|
229 | + } |
|
230 | + |
|
231 | + |
|
232 | + /** |
|
233 | + * Generate dropdown filter select input for message types |
|
234 | + * |
|
235 | + * @param bool $global |
|
236 | + * @return string |
|
237 | + * @throws EE_Error |
|
238 | + */ |
|
239 | + protected function _get_message_types_dropdown_filter($global = true) |
|
240 | + { |
|
241 | + $message_type_options = array(); |
|
242 | + $active_message_template_groups_grouped_by_message_type = EEM_Message_Template_Group::instance()->get_all( |
|
243 | + array( |
|
244 | + array( |
|
245 | + 'MTP_is_active' => true, |
|
246 | + 'MTP_is_global' => true, |
|
247 | + ), |
|
248 | + 'group_by' => 'MTP_message_type', |
|
249 | + ) |
|
250 | + ); |
|
251 | + |
|
252 | + foreach ($active_message_template_groups_grouped_by_message_type as $active_message_template_group) { |
|
253 | + if ($active_message_template_group instanceof EE_Message_Template_Group) { |
|
254 | + $message_type = $active_message_template_group->message_type_obj(); |
|
255 | + $message_type_label = $message_type instanceof EE_message_type |
|
256 | + ? $message_type->label['singular'] |
|
257 | + : $active_message_template_group->message_type(); |
|
258 | + $message_type_options[$active_message_template_group->message_type()] = ucwords($message_type_label); |
|
259 | + } |
|
260 | + } |
|
261 | + return $this->get_admin_page()->get_message_types_select_input($message_type_options); |
|
262 | + } |
|
263 | + |
|
264 | + |
|
265 | + /** |
|
266 | + * Return the edit url for the message template group. |
|
267 | + * @param EE_Message_Template_Group $item |
|
268 | + * @return string |
|
269 | + * @throws EE_Error |
|
270 | + */ |
|
271 | + protected function _get_edit_url(EE_Message_Template_Group $item) |
|
272 | + { |
|
273 | + $edit_url = ''; |
|
274 | + // edit link but only if item isn't trashed. |
|
275 | + if (! $item->get('MTP_deleted') |
|
276 | + && EE_Registry::instance()->CAP->current_user_can( |
|
277 | + 'ee_edit_message', |
|
278 | + 'espresso_messages_edit_message_template', |
|
279 | + $item->ID() |
|
280 | + )) { |
|
281 | + $edit_url = EE_Admin_Page::add_query_args_and_nonce( |
|
282 | + array( |
|
283 | + 'action' => 'edit_message_template', |
|
284 | + 'id' => $item->GRP_ID(), |
|
285 | + ), |
|
286 | + EE_MSG_ADMIN_URL |
|
287 | + ); |
|
288 | + } |
|
289 | + return $edit_url; |
|
290 | + } |
|
291 | + |
|
292 | + |
|
293 | + /** |
|
294 | + * Get the context link string for the messenger column. |
|
295 | + * @param EE_Message_Template_Group $item |
|
296 | + * @return string |
|
297 | + * @throws EE_Error |
|
298 | + */ |
|
299 | + protected function _get_context_links(EE_Message_Template_Group $item) |
|
300 | + { |
|
301 | + //first check if we even show the context links or not. |
|
302 | + if (! EE_Registry::instance()->CAP->current_user_can( |
|
303 | + 'ee_edit_message', |
|
304 | + 'espresso_messages_edit_message_template', |
|
305 | + $item->ID() |
|
306 | + ) |
|
307 | + || $item->get('MTP_deleted') |
|
308 | + ) { |
|
309 | + return ''; |
|
310 | + } |
|
311 | + //we want to display the contexts in here so we need to set them up |
|
312 | + $c_label = $item->context_label(); |
|
313 | + $c_configs = $item->contexts_config(); |
|
314 | + $ctxt = array(); |
|
315 | + $context_templates = $item->context_templates(); |
|
316 | + foreach ($context_templates as $context => $template_fields) { |
|
317 | + $mtp_to = ! empty($context_templates[$context]['to']) |
|
318 | + && $context_templates[$context]['to'] instanceof EE_Message_Template |
|
319 | + ? $context_templates[$context]['to']->get('MTP_content') |
|
320 | + : null; |
|
321 | + $inactive = empty($mtp_to) |
|
322 | + && ! empty($context_templates[$context]['to']) |
|
323 | + ? ' class="mtp-inactive"' |
|
324 | + : ''; |
|
325 | + $context_title = ucwords($c_configs[$context]['label']); |
|
326 | + $edit_link = EE_Admin_Page::add_query_args_and_nonce(array( |
|
327 | + 'action' => 'edit_message_template', |
|
328 | + 'id' => $item->GRP_ID(), |
|
329 | + 'context' => $context, |
|
330 | + ), EE_MSG_ADMIN_URL); |
|
331 | + $ctxt[] = '<a' . $inactive |
|
332 | + . ' href="' . $edit_link . '"' |
|
333 | + . ' class="' . $item->message_type() . '-' . $context . '-edit-link"' |
|
334 | + . ' title="' . esc_attr__('Edit Context', 'event_espresso') . '">' |
|
335 | + . $context_title |
|
336 | + . '</a>'; |
|
337 | + } |
|
338 | + |
|
339 | + return sprintf('<strong>%s:</strong> ', ucwords($c_label['plural'])) . implode(' | ', $ctxt); |
|
340 | + } |
|
341 | + |
|
342 | + |
|
343 | + /** |
|
344 | + * Get the Name string from the messenger column (linked to edit if the context allows for that). |
|
345 | + * @param EE_Message_Template_Group $item |
|
346 | + * @return string |
|
347 | + * @throws EE_Error |
|
348 | + */ |
|
349 | + protected function _get_name_link_for_messenger(EE_Message_Template_Group $item) |
|
350 | + { |
|
351 | + $edit_url = $this->_get_edit_url($item); |
|
352 | + return $edit_url |
|
353 | + ? '<a href="' . $edit_url . '"' |
|
354 | + . ' title="' . esc_attr__('Edit Template Group', 'event_espresso') . '">' |
|
355 | + . ucwords($item->messenger_obj()->label['singular']) |
|
356 | + . '</a>' |
|
357 | + : ucwords($item->messenger_obj()->label['singular']); |
|
358 | + } |
|
359 | + |
|
360 | + |
|
361 | + /** |
|
362 | + * Return the actions array for the messenger column. |
|
363 | + * @param EE_Message_Template_Group $item |
|
364 | + * @return array |
|
365 | + * @throws EE_Error |
|
366 | + */ |
|
367 | + protected function _get_actions_for_messenger_column(EE_Message_Template_Group $item) |
|
368 | + { |
|
369 | + $actions = array(); |
|
370 | + if ($edit_url = $this->_get_edit_url($item)) { |
|
371 | + $actions = array( |
|
372 | + 'edit' => '<a href="' . $edit_url . '"' |
|
373 | + . ' class="' . $item->message_type() . '-edit-link"' |
|
374 | + . ' title="' . esc_attr__('Edit Template Group', 'event_espresso') . '">' |
|
375 | + . esc_html__('Edit', 'event_espresso') |
|
376 | + . '</a>' |
|
377 | + ); |
|
378 | + } |
|
379 | + return $actions; |
|
380 | + } |
|
381 | 381 | } |
382 | 382 |
@@ -19,206 +19,206 @@ |
||
19 | 19 | class EventListQuery extends WP_Query |
20 | 20 | { |
21 | 21 | |
22 | - /** |
|
23 | - * @var string $title |
|
24 | - */ |
|
25 | - private $title; |
|
26 | - |
|
27 | - /** |
|
28 | - * @var integer $limit |
|
29 | - */ |
|
30 | - private $limit = 10; |
|
31 | - |
|
32 | - /** |
|
33 | - * @var string $css_class |
|
34 | - */ |
|
35 | - private $css_class; |
|
36 | - |
|
37 | - /** |
|
38 | - * @var boolean $show_expired |
|
39 | - */ |
|
40 | - private $show_expired = false; |
|
41 | - |
|
42 | - /** |
|
43 | - * @var string $month |
|
44 | - */ |
|
45 | - private $month; |
|
46 | - |
|
47 | - /** |
|
48 | - * @var string $category_slug |
|
49 | - */ |
|
50 | - private $category_slug; |
|
51 | - |
|
52 | - /** |
|
53 | - * @var string $order_by |
|
54 | - */ |
|
55 | - private $order_by; |
|
56 | - |
|
57 | - /** |
|
58 | - * @var string $sort |
|
59 | - */ |
|
60 | - private $sort; |
|
61 | - |
|
62 | - /** |
|
63 | - * @var boolean $show_title |
|
64 | - */ |
|
65 | - private $show_title = true; |
|
66 | - |
|
67 | - |
|
68 | - |
|
69 | - /** |
|
70 | - * EE_Event_List_Query Constructor * |
|
71 | - * |
|
72 | - * @param array $args |
|
73 | - */ |
|
74 | - public function __construct($args = array()) |
|
75 | - { |
|
76 | - $args = $this->parseArgs((array)$args); |
|
77 | - $this->setupEventQueryHelper(); |
|
78 | - $this->setupFilters(); |
|
79 | - $args = $this->getQueryArgs($args); |
|
80 | - // run the query |
|
81 | - parent::__construct($args); |
|
82 | - } |
|
83 | - |
|
84 | - |
|
85 | - |
|
86 | - /** |
|
87 | - * @param array $args |
|
88 | - * @return array |
|
89 | - */ |
|
90 | - private function parseArgs(array $args) |
|
91 | - { |
|
92 | - // incoming args could be a mix of WP query args + EE shortcode args |
|
93 | - foreach ($args as $property => $value) { |
|
94 | - // if the arg is a property of this class, then it's an EE shortcode arg |
|
95 | - if (property_exists($this, $property) && ! property_exists('WP_Query', $property)) { |
|
96 | - // set the property value |
|
97 | - $this->{$property} = $value; |
|
98 | - // then remove it from the array of args that will later be passed to WP_Query() |
|
99 | - unset($args[$property]); |
|
100 | - } |
|
101 | - } |
|
102 | - return $args; |
|
103 | - } |
|
104 | - |
|
105 | - |
|
106 | - |
|
107 | - private function setupEventQueryHelper() |
|
108 | - { |
|
109 | - //add query filters |
|
110 | - EEH_Event_Query::add_query_filters(); |
|
111 | - // set params that will get used by the filters |
|
112 | - EEH_Event_Query::set_query_params( |
|
113 | - $this->month, |
|
114 | - $this->category_slug, |
|
115 | - $this->show_expired, |
|
116 | - $this->order_by, |
|
117 | - $this->sort |
|
118 | - ); |
|
119 | - } |
|
120 | - |
|
121 | - |
|
122 | - |
|
123 | - private function setupFilters() |
|
124 | - { |
|
125 | - // first off, let's remove any filters from previous queries |
|
126 | - remove_filter( |
|
127 | - 'FHEE__archive_espresso_events_template__show_header', |
|
128 | - array($this, 'show_event_list_title') |
|
129 | - ); |
|
130 | - remove_filter( |
|
131 | - 'FHEE__archive_espresso_events_template__upcoming_events_h1', |
|
132 | - array($this, 'event_list_title') |
|
133 | - ); |
|
134 | - remove_all_filters('FHEE__content_espresso_events__event_class'); |
|
135 | - // Event List Title ? |
|
136 | - add_filter( |
|
137 | - 'FHEE__archive_espresso_events_template__show_header', |
|
138 | - array($this, 'show_event_list_title') |
|
139 | - ); |
|
140 | - add_filter( |
|
141 | - 'FHEE__archive_espresso_events_template__upcoming_events_h1', |
|
142 | - array($this, 'event_list_title'), |
|
143 | - 10, |
|
144 | - 1 |
|
145 | - ); |
|
146 | - // add the css class |
|
147 | - add_filter( |
|
148 | - 'FHEE__content_espresso_events__event_class', |
|
149 | - array($this, 'event_list_css'), |
|
150 | - 10, |
|
151 | - 1 |
|
152 | - ); |
|
153 | - } |
|
154 | - |
|
155 | - |
|
156 | - |
|
157 | - private function getQueryArgs(array $args) |
|
158 | - { |
|
159 | - // the current "page" we are viewing |
|
160 | - $paged = max(1, get_query_var('paged')); |
|
161 | - // Force these args |
|
162 | - return array_merge( |
|
163 | - $args, |
|
164 | - array( |
|
165 | - 'post_type' => 'espresso_events', |
|
166 | - 'posts_per_page' => $this->limit, |
|
167 | - 'update_post_term_cache' => false, |
|
168 | - 'update_post_meta_cache' => false, |
|
169 | - 'paged' => $paged, |
|
170 | - 'offset' => ($paged - 1) * $this->limit, |
|
171 | - ) |
|
172 | - ); |
|
173 | - } |
|
174 | - |
|
175 | - |
|
176 | - |
|
177 | - /** |
|
178 | - * show_event_list_title |
|
179 | - * |
|
180 | - * @return boolean |
|
181 | - */ |
|
182 | - public function show_event_list_title() |
|
183 | - { |
|
184 | - return filter_var( |
|
185 | - $this->show_title, |
|
186 | - FILTER_VALIDATE_BOOLEAN |
|
187 | - ); |
|
188 | - } |
|
189 | - |
|
190 | - |
|
191 | - |
|
192 | - /** |
|
193 | - * callback for FHEE__archive_espresso_events_template__upcoming_events_h1 filter |
|
194 | - * |
|
195 | - * @param string $event_list_title |
|
196 | - * @return string |
|
197 | - */ |
|
198 | - public function event_list_title($event_list_title = '') |
|
199 | - { |
|
200 | - if ( ! empty($this->title)) { |
|
201 | - return $this->title; |
|
202 | - } |
|
203 | - return $event_list_title; |
|
204 | - } |
|
205 | - |
|
206 | - |
|
207 | - |
|
208 | - /** |
|
209 | - * callback for FHEE__content_espresso_events__event_class filter |
|
210 | - * |
|
211 | - * @param string $event_list_css |
|
212 | - * @return string |
|
213 | - */ |
|
214 | - public function event_list_css($event_list_css = '') |
|
215 | - { |
|
216 | - $event_list_css .= ! empty($event_list_css) ? ' ' : ''; |
|
217 | - $event_list_css .= ! empty($this->css_class) ? $this->css_class : ''; |
|
218 | - $event_list_css .= ! empty($event_list_css) ? ' ' : ''; |
|
219 | - $event_list_css .= ! empty($this->category_slug) ? $this->category_slug : ''; |
|
220 | - return $event_list_css; |
|
221 | - } |
|
22 | + /** |
|
23 | + * @var string $title |
|
24 | + */ |
|
25 | + private $title; |
|
26 | + |
|
27 | + /** |
|
28 | + * @var integer $limit |
|
29 | + */ |
|
30 | + private $limit = 10; |
|
31 | + |
|
32 | + /** |
|
33 | + * @var string $css_class |
|
34 | + */ |
|
35 | + private $css_class; |
|
36 | + |
|
37 | + /** |
|
38 | + * @var boolean $show_expired |
|
39 | + */ |
|
40 | + private $show_expired = false; |
|
41 | + |
|
42 | + /** |
|
43 | + * @var string $month |
|
44 | + */ |
|
45 | + private $month; |
|
46 | + |
|
47 | + /** |
|
48 | + * @var string $category_slug |
|
49 | + */ |
|
50 | + private $category_slug; |
|
51 | + |
|
52 | + /** |
|
53 | + * @var string $order_by |
|
54 | + */ |
|
55 | + private $order_by; |
|
56 | + |
|
57 | + /** |
|
58 | + * @var string $sort |
|
59 | + */ |
|
60 | + private $sort; |
|
61 | + |
|
62 | + /** |
|
63 | + * @var boolean $show_title |
|
64 | + */ |
|
65 | + private $show_title = true; |
|
66 | + |
|
67 | + |
|
68 | + |
|
69 | + /** |
|
70 | + * EE_Event_List_Query Constructor * |
|
71 | + * |
|
72 | + * @param array $args |
|
73 | + */ |
|
74 | + public function __construct($args = array()) |
|
75 | + { |
|
76 | + $args = $this->parseArgs((array)$args); |
|
77 | + $this->setupEventQueryHelper(); |
|
78 | + $this->setupFilters(); |
|
79 | + $args = $this->getQueryArgs($args); |
|
80 | + // run the query |
|
81 | + parent::__construct($args); |
|
82 | + } |
|
83 | + |
|
84 | + |
|
85 | + |
|
86 | + /** |
|
87 | + * @param array $args |
|
88 | + * @return array |
|
89 | + */ |
|
90 | + private function parseArgs(array $args) |
|
91 | + { |
|
92 | + // incoming args could be a mix of WP query args + EE shortcode args |
|
93 | + foreach ($args as $property => $value) { |
|
94 | + // if the arg is a property of this class, then it's an EE shortcode arg |
|
95 | + if (property_exists($this, $property) && ! property_exists('WP_Query', $property)) { |
|
96 | + // set the property value |
|
97 | + $this->{$property} = $value; |
|
98 | + // then remove it from the array of args that will later be passed to WP_Query() |
|
99 | + unset($args[$property]); |
|
100 | + } |
|
101 | + } |
|
102 | + return $args; |
|
103 | + } |
|
104 | + |
|
105 | + |
|
106 | + |
|
107 | + private function setupEventQueryHelper() |
|
108 | + { |
|
109 | + //add query filters |
|
110 | + EEH_Event_Query::add_query_filters(); |
|
111 | + // set params that will get used by the filters |
|
112 | + EEH_Event_Query::set_query_params( |
|
113 | + $this->month, |
|
114 | + $this->category_slug, |
|
115 | + $this->show_expired, |
|
116 | + $this->order_by, |
|
117 | + $this->sort |
|
118 | + ); |
|
119 | + } |
|
120 | + |
|
121 | + |
|
122 | + |
|
123 | + private function setupFilters() |
|
124 | + { |
|
125 | + // first off, let's remove any filters from previous queries |
|
126 | + remove_filter( |
|
127 | + 'FHEE__archive_espresso_events_template__show_header', |
|
128 | + array($this, 'show_event_list_title') |
|
129 | + ); |
|
130 | + remove_filter( |
|
131 | + 'FHEE__archive_espresso_events_template__upcoming_events_h1', |
|
132 | + array($this, 'event_list_title') |
|
133 | + ); |
|
134 | + remove_all_filters('FHEE__content_espresso_events__event_class'); |
|
135 | + // Event List Title ? |
|
136 | + add_filter( |
|
137 | + 'FHEE__archive_espresso_events_template__show_header', |
|
138 | + array($this, 'show_event_list_title') |
|
139 | + ); |
|
140 | + add_filter( |
|
141 | + 'FHEE__archive_espresso_events_template__upcoming_events_h1', |
|
142 | + array($this, 'event_list_title'), |
|
143 | + 10, |
|
144 | + 1 |
|
145 | + ); |
|
146 | + // add the css class |
|
147 | + add_filter( |
|
148 | + 'FHEE__content_espresso_events__event_class', |
|
149 | + array($this, 'event_list_css'), |
|
150 | + 10, |
|
151 | + 1 |
|
152 | + ); |
|
153 | + } |
|
154 | + |
|
155 | + |
|
156 | + |
|
157 | + private function getQueryArgs(array $args) |
|
158 | + { |
|
159 | + // the current "page" we are viewing |
|
160 | + $paged = max(1, get_query_var('paged')); |
|
161 | + // Force these args |
|
162 | + return array_merge( |
|
163 | + $args, |
|
164 | + array( |
|
165 | + 'post_type' => 'espresso_events', |
|
166 | + 'posts_per_page' => $this->limit, |
|
167 | + 'update_post_term_cache' => false, |
|
168 | + 'update_post_meta_cache' => false, |
|
169 | + 'paged' => $paged, |
|
170 | + 'offset' => ($paged - 1) * $this->limit, |
|
171 | + ) |
|
172 | + ); |
|
173 | + } |
|
174 | + |
|
175 | + |
|
176 | + |
|
177 | + /** |
|
178 | + * show_event_list_title |
|
179 | + * |
|
180 | + * @return boolean |
|
181 | + */ |
|
182 | + public function show_event_list_title() |
|
183 | + { |
|
184 | + return filter_var( |
|
185 | + $this->show_title, |
|
186 | + FILTER_VALIDATE_BOOLEAN |
|
187 | + ); |
|
188 | + } |
|
189 | + |
|
190 | + |
|
191 | + |
|
192 | + /** |
|
193 | + * callback for FHEE__archive_espresso_events_template__upcoming_events_h1 filter |
|
194 | + * |
|
195 | + * @param string $event_list_title |
|
196 | + * @return string |
|
197 | + */ |
|
198 | + public function event_list_title($event_list_title = '') |
|
199 | + { |
|
200 | + if ( ! empty($this->title)) { |
|
201 | + return $this->title; |
|
202 | + } |
|
203 | + return $event_list_title; |
|
204 | + } |
|
205 | + |
|
206 | + |
|
207 | + |
|
208 | + /** |
|
209 | + * callback for FHEE__content_espresso_events__event_class filter |
|
210 | + * |
|
211 | + * @param string $event_list_css |
|
212 | + * @return string |
|
213 | + */ |
|
214 | + public function event_list_css($event_list_css = '') |
|
215 | + { |
|
216 | + $event_list_css .= ! empty($event_list_css) ? ' ' : ''; |
|
217 | + $event_list_css .= ! empty($this->css_class) ? $this->css_class : ''; |
|
218 | + $event_list_css .= ! empty($event_list_css) ? ' ' : ''; |
|
219 | + $event_list_css .= ! empty($this->category_slug) ? $this->category_slug : ''; |
|
220 | + return $event_list_css; |
|
221 | + } |
|
222 | 222 | |
223 | 223 | } |
224 | 224 | // End of file EventListQuery.php |