@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php if ( ! defined('ABSPATH')) { |
2 | - exit('No direct script access allowed'); |
|
2 | + exit('No direct script access allowed'); |
|
3 | 3 | } |
4 | 4 | /* |
5 | 5 | Plugin Name: Event Espresso |
@@ -40,243 +40,243 @@ discard block |
||
40 | 40 | * @since 4.0 |
41 | 41 | */ |
42 | 42 | if (function_exists('espresso_version')) { |
43 | - /** |
|
44 | - * espresso_duplicate_plugin_error |
|
45 | - * displays if more than one version of EE is activated at the same time |
|
46 | - */ |
|
47 | - function espresso_duplicate_plugin_error() |
|
48 | - { |
|
49 | - ?> |
|
43 | + /** |
|
44 | + * espresso_duplicate_plugin_error |
|
45 | + * displays if more than one version of EE is activated at the same time |
|
46 | + */ |
|
47 | + function espresso_duplicate_plugin_error() |
|
48 | + { |
|
49 | + ?> |
|
50 | 50 | <div class="error"> |
51 | 51 | <p> |
52 | 52 | <?php echo esc_html__( |
53 | - 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
54 | - 'event_espresso' |
|
55 | - ); ?> |
|
53 | + 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
54 | + 'event_espresso' |
|
55 | + ); ?> |
|
56 | 56 | </p> |
57 | 57 | </div> |
58 | 58 | <?php |
59 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
60 | - } |
|
59 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
60 | + } |
|
61 | 61 | |
62 | - add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
62 | + add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
63 | 63 | } else { |
64 | - define('EE_MIN_PHP_VER_REQUIRED', '5.3.9'); |
|
65 | - if ( ! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
66 | - /** |
|
67 | - * espresso_minimum_php_version_error |
|
68 | - * |
|
69 | - * @return void |
|
70 | - */ |
|
71 | - function espresso_minimum_php_version_error() |
|
72 | - { |
|
73 | - ?> |
|
64 | + define('EE_MIN_PHP_VER_REQUIRED', '5.3.9'); |
|
65 | + if ( ! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
66 | + /** |
|
67 | + * espresso_minimum_php_version_error |
|
68 | + * |
|
69 | + * @return void |
|
70 | + */ |
|
71 | + function espresso_minimum_php_version_error() |
|
72 | + { |
|
73 | + ?> |
|
74 | 74 | <div class="error"> |
75 | 75 | <p> |
76 | 76 | <?php |
77 | - printf( |
|
78 | - esc_html__( |
|
79 | - 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
80 | - 'event_espresso' |
|
81 | - ), |
|
82 | - EE_MIN_PHP_VER_REQUIRED, |
|
83 | - PHP_VERSION, |
|
84 | - '<br/>', |
|
85 | - '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
86 | - ); |
|
87 | - ?> |
|
77 | + printf( |
|
78 | + esc_html__( |
|
79 | + 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
80 | + 'event_espresso' |
|
81 | + ), |
|
82 | + EE_MIN_PHP_VER_REQUIRED, |
|
83 | + PHP_VERSION, |
|
84 | + '<br/>', |
|
85 | + '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
86 | + ); |
|
87 | + ?> |
|
88 | 88 | </p> |
89 | 89 | </div> |
90 | 90 | <?php |
91 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
92 | - } |
|
91 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
92 | + } |
|
93 | 93 | |
94 | - add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
95 | - } else { |
|
96 | - /** |
|
97 | - * espresso_version |
|
98 | - * Returns the plugin version |
|
99 | - * |
|
100 | - * @return string |
|
101 | - */ |
|
102 | - function espresso_version() |
|
103 | - { |
|
104 | - return apply_filters('FHEE__espresso__espresso_version', '4.9.37.rc.004'); |
|
105 | - } |
|
94 | + add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
95 | + } else { |
|
96 | + /** |
|
97 | + * espresso_version |
|
98 | + * Returns the plugin version |
|
99 | + * |
|
100 | + * @return string |
|
101 | + */ |
|
102 | + function espresso_version() |
|
103 | + { |
|
104 | + return apply_filters('FHEE__espresso__espresso_version', '4.9.37.rc.004'); |
|
105 | + } |
|
106 | 106 | |
107 | - // define versions |
|
108 | - define('EVENT_ESPRESSO_VERSION', espresso_version()); |
|
109 | - define('EE_MIN_WP_VER_REQUIRED', '4.1'); |
|
110 | - define('EE_MIN_WP_VER_RECOMMENDED', '4.4.2'); |
|
111 | - define('EE_MIN_PHP_VER_RECOMMENDED', '5.4.44'); |
|
112 | - define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
113 | - //used to be DIRECTORY_SEPARATOR, but that caused issues on windows |
|
114 | - if ( ! defined('DS')) { |
|
115 | - define('DS', '/'); |
|
116 | - } |
|
117 | - if ( ! defined('PS')) { |
|
118 | - define('PS', PATH_SEPARATOR); |
|
119 | - } |
|
120 | - if ( ! defined('SP')) { |
|
121 | - define('SP', ' '); |
|
122 | - } |
|
123 | - if ( ! defined('EENL')) { |
|
124 | - define('EENL', "\n"); |
|
125 | - } |
|
126 | - define('EE_SUPPORT_EMAIL', '[email protected]'); |
|
127 | - // define the plugin directory and URL |
|
128 | - define('EE_PLUGIN_BASENAME', plugin_basename(EVENT_ESPRESSO_MAIN_FILE)); |
|
129 | - define('EE_PLUGIN_DIR_PATH', plugin_dir_path(EVENT_ESPRESSO_MAIN_FILE)); |
|
130 | - define('EE_PLUGIN_DIR_URL', plugin_dir_url(EVENT_ESPRESSO_MAIN_FILE)); |
|
131 | - // main root folder paths |
|
132 | - define('EE_ADMIN_PAGES', EE_PLUGIN_DIR_PATH . 'admin_pages' . DS); |
|
133 | - define('EE_CORE', EE_PLUGIN_DIR_PATH . 'core' . DS); |
|
134 | - define('EE_MODULES', EE_PLUGIN_DIR_PATH . 'modules' . DS); |
|
135 | - define('EE_PUBLIC', EE_PLUGIN_DIR_PATH . 'public' . DS); |
|
136 | - define('EE_SHORTCODES', EE_PLUGIN_DIR_PATH . 'shortcodes' . DS); |
|
137 | - define('EE_WIDGETS', EE_PLUGIN_DIR_PATH . 'widgets' . DS); |
|
138 | - define('EE_PAYMENT_METHODS', EE_PLUGIN_DIR_PATH . 'payment_methods' . DS); |
|
139 | - define('EE_CAFF_PATH', EE_PLUGIN_DIR_PATH . 'caffeinated' . DS); |
|
140 | - // core system paths |
|
141 | - define('EE_ADMIN', EE_CORE . 'admin' . DS); |
|
142 | - define('EE_CPTS', EE_CORE . 'CPTs' . DS); |
|
143 | - define('EE_CLASSES', EE_CORE . 'db_classes' . DS); |
|
144 | - define('EE_INTERFACES', EE_CORE . 'interfaces' . DS); |
|
145 | - define('EE_BUSINESS', EE_CORE . 'business' . DS); |
|
146 | - define('EE_MODELS', EE_CORE . 'db_models' . DS); |
|
147 | - define('EE_HELPERS', EE_CORE . 'helpers' . DS); |
|
148 | - define('EE_LIBRARIES', EE_CORE . 'libraries' . DS); |
|
149 | - define('EE_TEMPLATES', EE_CORE . 'templates' . DS); |
|
150 | - define('EE_THIRD_PARTY', EE_CORE . 'third_party_libs' . DS); |
|
151 | - define('EE_GLOBAL_ASSETS', EE_TEMPLATES . 'global_assets' . DS); |
|
152 | - define('EE_FORM_SECTIONS', EE_LIBRARIES . 'form_sections' . DS); |
|
153 | - // gateways |
|
154 | - define('EE_GATEWAYS', EE_MODULES . 'gateways' . DS); |
|
155 | - define('EE_GATEWAYS_URL', EE_PLUGIN_DIR_URL . 'modules' . DS . 'gateways' . DS); |
|
156 | - // asset URL paths |
|
157 | - define('EE_TEMPLATES_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'templates' . DS); |
|
158 | - define('EE_GLOBAL_ASSETS_URL', EE_TEMPLATES_URL . 'global_assets' . DS); |
|
159 | - define('EE_IMAGES_URL', EE_GLOBAL_ASSETS_URL . 'images' . DS); |
|
160 | - define('EE_THIRD_PARTY_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'third_party_libs' . DS); |
|
161 | - define('EE_HELPERS_ASSETS', EE_PLUGIN_DIR_URL . 'core/helpers/assets/'); |
|
162 | - define('EE_LIBRARIES_URL', EE_PLUGIN_DIR_URL . 'core/libraries/'); |
|
163 | - // define upload paths |
|
164 | - $uploads = wp_upload_dir(); |
|
165 | - // define the uploads directory and URL |
|
166 | - define('EVENT_ESPRESSO_UPLOAD_DIR', $uploads['basedir'] . DS . 'espresso' . DS); |
|
167 | - define('EVENT_ESPRESSO_UPLOAD_URL', $uploads['baseurl'] . DS . 'espresso' . DS); |
|
168 | - // define the templates directory and URL |
|
169 | - define('EVENT_ESPRESSO_TEMPLATE_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'templates' . DS); |
|
170 | - define('EVENT_ESPRESSO_TEMPLATE_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'templates' . DS); |
|
171 | - // define the gateway directory and URL |
|
172 | - define('EVENT_ESPRESSO_GATEWAY_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'gateways' . DS); |
|
173 | - define('EVENT_ESPRESSO_GATEWAY_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'gateways' . DS); |
|
174 | - // languages folder/path |
|
175 | - define('EE_LANGUAGES_SAFE_LOC', '..' . DS . 'uploads' . DS . 'espresso' . DS . 'languages' . DS); |
|
176 | - define('EE_LANGUAGES_SAFE_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'languages' . DS); |
|
177 | - //check for dompdf fonts in uploads |
|
178 | - if (file_exists(EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS)) { |
|
179 | - define('DOMPDF_FONT_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS); |
|
180 | - } |
|
181 | - //ajax constants |
|
182 | - define( |
|
183 | - 'EE_FRONT_AJAX', |
|
184 | - isset($_REQUEST['ee_front_ajax']) || isset($_REQUEST['data']['ee_front_ajax']) ? true : false |
|
185 | - ); |
|
186 | - define( |
|
187 | - 'EE_ADMIN_AJAX', |
|
188 | - isset($_REQUEST['ee_admin_ajax']) || isset($_REQUEST['data']['ee_admin_ajax']) ? true : false |
|
189 | - ); |
|
190 | - //just a handy constant occasionally needed for finding values representing infinity in the DB |
|
191 | - //you're better to use this than its straight value (currently -1) in case you ever |
|
192 | - //want to change its default value! or find when -1 means infinity |
|
193 | - define('EE_INF_IN_DB', -1); |
|
194 | - define('EE_INF', INF > (float)PHP_INT_MAX ? INF : PHP_INT_MAX); |
|
195 | - define('EE_DEBUG', false); |
|
196 | - // for older WP versions |
|
197 | - if ( ! defined('MONTH_IN_SECONDS')) { |
|
198 | - define('MONTH_IN_SECONDS', DAY_IN_SECONDS * 30); |
|
199 | - } |
|
200 | - /** |
|
201 | - * espresso_plugin_activation |
|
202 | - * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
203 | - */ |
|
204 | - function espresso_plugin_activation() |
|
205 | - { |
|
206 | - update_option('ee_espresso_activation', true); |
|
207 | - } |
|
107 | + // define versions |
|
108 | + define('EVENT_ESPRESSO_VERSION', espresso_version()); |
|
109 | + define('EE_MIN_WP_VER_REQUIRED', '4.1'); |
|
110 | + define('EE_MIN_WP_VER_RECOMMENDED', '4.4.2'); |
|
111 | + define('EE_MIN_PHP_VER_RECOMMENDED', '5.4.44'); |
|
112 | + define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
113 | + //used to be DIRECTORY_SEPARATOR, but that caused issues on windows |
|
114 | + if ( ! defined('DS')) { |
|
115 | + define('DS', '/'); |
|
116 | + } |
|
117 | + if ( ! defined('PS')) { |
|
118 | + define('PS', PATH_SEPARATOR); |
|
119 | + } |
|
120 | + if ( ! defined('SP')) { |
|
121 | + define('SP', ' '); |
|
122 | + } |
|
123 | + if ( ! defined('EENL')) { |
|
124 | + define('EENL', "\n"); |
|
125 | + } |
|
126 | + define('EE_SUPPORT_EMAIL', '[email protected]'); |
|
127 | + // define the plugin directory and URL |
|
128 | + define('EE_PLUGIN_BASENAME', plugin_basename(EVENT_ESPRESSO_MAIN_FILE)); |
|
129 | + define('EE_PLUGIN_DIR_PATH', plugin_dir_path(EVENT_ESPRESSO_MAIN_FILE)); |
|
130 | + define('EE_PLUGIN_DIR_URL', plugin_dir_url(EVENT_ESPRESSO_MAIN_FILE)); |
|
131 | + // main root folder paths |
|
132 | + define('EE_ADMIN_PAGES', EE_PLUGIN_DIR_PATH . 'admin_pages' . DS); |
|
133 | + define('EE_CORE', EE_PLUGIN_DIR_PATH . 'core' . DS); |
|
134 | + define('EE_MODULES', EE_PLUGIN_DIR_PATH . 'modules' . DS); |
|
135 | + define('EE_PUBLIC', EE_PLUGIN_DIR_PATH . 'public' . DS); |
|
136 | + define('EE_SHORTCODES', EE_PLUGIN_DIR_PATH . 'shortcodes' . DS); |
|
137 | + define('EE_WIDGETS', EE_PLUGIN_DIR_PATH . 'widgets' . DS); |
|
138 | + define('EE_PAYMENT_METHODS', EE_PLUGIN_DIR_PATH . 'payment_methods' . DS); |
|
139 | + define('EE_CAFF_PATH', EE_PLUGIN_DIR_PATH . 'caffeinated' . DS); |
|
140 | + // core system paths |
|
141 | + define('EE_ADMIN', EE_CORE . 'admin' . DS); |
|
142 | + define('EE_CPTS', EE_CORE . 'CPTs' . DS); |
|
143 | + define('EE_CLASSES', EE_CORE . 'db_classes' . DS); |
|
144 | + define('EE_INTERFACES', EE_CORE . 'interfaces' . DS); |
|
145 | + define('EE_BUSINESS', EE_CORE . 'business' . DS); |
|
146 | + define('EE_MODELS', EE_CORE . 'db_models' . DS); |
|
147 | + define('EE_HELPERS', EE_CORE . 'helpers' . DS); |
|
148 | + define('EE_LIBRARIES', EE_CORE . 'libraries' . DS); |
|
149 | + define('EE_TEMPLATES', EE_CORE . 'templates' . DS); |
|
150 | + define('EE_THIRD_PARTY', EE_CORE . 'third_party_libs' . DS); |
|
151 | + define('EE_GLOBAL_ASSETS', EE_TEMPLATES . 'global_assets' . DS); |
|
152 | + define('EE_FORM_SECTIONS', EE_LIBRARIES . 'form_sections' . DS); |
|
153 | + // gateways |
|
154 | + define('EE_GATEWAYS', EE_MODULES . 'gateways' . DS); |
|
155 | + define('EE_GATEWAYS_URL', EE_PLUGIN_DIR_URL . 'modules' . DS . 'gateways' . DS); |
|
156 | + // asset URL paths |
|
157 | + define('EE_TEMPLATES_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'templates' . DS); |
|
158 | + define('EE_GLOBAL_ASSETS_URL', EE_TEMPLATES_URL . 'global_assets' . DS); |
|
159 | + define('EE_IMAGES_URL', EE_GLOBAL_ASSETS_URL . 'images' . DS); |
|
160 | + define('EE_THIRD_PARTY_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'third_party_libs' . DS); |
|
161 | + define('EE_HELPERS_ASSETS', EE_PLUGIN_DIR_URL . 'core/helpers/assets/'); |
|
162 | + define('EE_LIBRARIES_URL', EE_PLUGIN_DIR_URL . 'core/libraries/'); |
|
163 | + // define upload paths |
|
164 | + $uploads = wp_upload_dir(); |
|
165 | + // define the uploads directory and URL |
|
166 | + define('EVENT_ESPRESSO_UPLOAD_DIR', $uploads['basedir'] . DS . 'espresso' . DS); |
|
167 | + define('EVENT_ESPRESSO_UPLOAD_URL', $uploads['baseurl'] . DS . 'espresso' . DS); |
|
168 | + // define the templates directory and URL |
|
169 | + define('EVENT_ESPRESSO_TEMPLATE_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'templates' . DS); |
|
170 | + define('EVENT_ESPRESSO_TEMPLATE_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'templates' . DS); |
|
171 | + // define the gateway directory and URL |
|
172 | + define('EVENT_ESPRESSO_GATEWAY_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'gateways' . DS); |
|
173 | + define('EVENT_ESPRESSO_GATEWAY_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'gateways' . DS); |
|
174 | + // languages folder/path |
|
175 | + define('EE_LANGUAGES_SAFE_LOC', '..' . DS . 'uploads' . DS . 'espresso' . DS . 'languages' . DS); |
|
176 | + define('EE_LANGUAGES_SAFE_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'languages' . DS); |
|
177 | + //check for dompdf fonts in uploads |
|
178 | + if (file_exists(EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS)) { |
|
179 | + define('DOMPDF_FONT_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS); |
|
180 | + } |
|
181 | + //ajax constants |
|
182 | + define( |
|
183 | + 'EE_FRONT_AJAX', |
|
184 | + isset($_REQUEST['ee_front_ajax']) || isset($_REQUEST['data']['ee_front_ajax']) ? true : false |
|
185 | + ); |
|
186 | + define( |
|
187 | + 'EE_ADMIN_AJAX', |
|
188 | + isset($_REQUEST['ee_admin_ajax']) || isset($_REQUEST['data']['ee_admin_ajax']) ? true : false |
|
189 | + ); |
|
190 | + //just a handy constant occasionally needed for finding values representing infinity in the DB |
|
191 | + //you're better to use this than its straight value (currently -1) in case you ever |
|
192 | + //want to change its default value! or find when -1 means infinity |
|
193 | + define('EE_INF_IN_DB', -1); |
|
194 | + define('EE_INF', INF > (float)PHP_INT_MAX ? INF : PHP_INT_MAX); |
|
195 | + define('EE_DEBUG', false); |
|
196 | + // for older WP versions |
|
197 | + if ( ! defined('MONTH_IN_SECONDS')) { |
|
198 | + define('MONTH_IN_SECONDS', DAY_IN_SECONDS * 30); |
|
199 | + } |
|
200 | + /** |
|
201 | + * espresso_plugin_activation |
|
202 | + * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
203 | + */ |
|
204 | + function espresso_plugin_activation() |
|
205 | + { |
|
206 | + update_option('ee_espresso_activation', true); |
|
207 | + } |
|
208 | 208 | |
209 | - register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
210 | - /** |
|
211 | - * espresso_load_error_handling |
|
212 | - * this function loads EE's class for handling exceptions and errors |
|
213 | - */ |
|
214 | - function espresso_load_error_handling() |
|
215 | - { |
|
216 | - // load debugging tools |
|
217 | - if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) { |
|
218 | - require_once(EE_HELPERS . 'EEH_Debug_Tools.helper.php'); |
|
219 | - EEH_Debug_Tools::instance(); |
|
220 | - } |
|
221 | - // load error handling |
|
222 | - if (is_readable(EE_CORE . 'EE_Error.core.php')) { |
|
223 | - require_once(EE_CORE . 'EE_Error.core.php'); |
|
224 | - } else { |
|
225 | - wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso')); |
|
226 | - } |
|
227 | - } |
|
209 | + register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
210 | + /** |
|
211 | + * espresso_load_error_handling |
|
212 | + * this function loads EE's class for handling exceptions and errors |
|
213 | + */ |
|
214 | + function espresso_load_error_handling() |
|
215 | + { |
|
216 | + // load debugging tools |
|
217 | + if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) { |
|
218 | + require_once(EE_HELPERS . 'EEH_Debug_Tools.helper.php'); |
|
219 | + EEH_Debug_Tools::instance(); |
|
220 | + } |
|
221 | + // load error handling |
|
222 | + if (is_readable(EE_CORE . 'EE_Error.core.php')) { |
|
223 | + require_once(EE_CORE . 'EE_Error.core.php'); |
|
224 | + } else { |
|
225 | + wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso')); |
|
226 | + } |
|
227 | + } |
|
228 | 228 | |
229 | - /** |
|
230 | - * espresso_load_required |
|
231 | - * given a class name and path, this function will load that file or throw an exception |
|
232 | - * |
|
233 | - * @param string $classname |
|
234 | - * @param string $full_path_to_file |
|
235 | - * @throws EE_Error |
|
236 | - */ |
|
237 | - function espresso_load_required($classname, $full_path_to_file) |
|
238 | - { |
|
239 | - static $error_handling_loaded = false; |
|
240 | - if ( ! $error_handling_loaded) { |
|
241 | - espresso_load_error_handling(); |
|
242 | - $error_handling_loaded = true; |
|
243 | - } |
|
244 | - if (is_readable($full_path_to_file)) { |
|
245 | - require_once($full_path_to_file); |
|
246 | - } else { |
|
247 | - throw new EE_Error ( |
|
248 | - sprintf( |
|
249 | - esc_html__( |
|
250 | - 'The %s class file could not be located or is not readable due to file permissions.', |
|
251 | - 'event_espresso' |
|
252 | - ), |
|
253 | - $classname |
|
254 | - ) |
|
255 | - ); |
|
256 | - } |
|
257 | - } |
|
229 | + /** |
|
230 | + * espresso_load_required |
|
231 | + * given a class name and path, this function will load that file or throw an exception |
|
232 | + * |
|
233 | + * @param string $classname |
|
234 | + * @param string $full_path_to_file |
|
235 | + * @throws EE_Error |
|
236 | + */ |
|
237 | + function espresso_load_required($classname, $full_path_to_file) |
|
238 | + { |
|
239 | + static $error_handling_loaded = false; |
|
240 | + if ( ! $error_handling_loaded) { |
|
241 | + espresso_load_error_handling(); |
|
242 | + $error_handling_loaded = true; |
|
243 | + } |
|
244 | + if (is_readable($full_path_to_file)) { |
|
245 | + require_once($full_path_to_file); |
|
246 | + } else { |
|
247 | + throw new EE_Error ( |
|
248 | + sprintf( |
|
249 | + esc_html__( |
|
250 | + 'The %s class file could not be located or is not readable due to file permissions.', |
|
251 | + 'event_espresso' |
|
252 | + ), |
|
253 | + $classname |
|
254 | + ) |
|
255 | + ); |
|
256 | + } |
|
257 | + } |
|
258 | 258 | |
259 | - espresso_load_required('EEH_Base', EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php'); |
|
260 | - espresso_load_required('EEH_File', EE_CORE . 'helpers' . DS . 'EEH_File.helper.php'); |
|
261 | - espresso_load_required('EE_Bootstrap', EE_CORE . 'EE_Bootstrap.core.php'); |
|
262 | - new EE_Bootstrap(); |
|
263 | - } |
|
259 | + espresso_load_required('EEH_Base', EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php'); |
|
260 | + espresso_load_required('EEH_File', EE_CORE . 'helpers' . DS . 'EEH_File.helper.php'); |
|
261 | + espresso_load_required('EE_Bootstrap', EE_CORE . 'EE_Bootstrap.core.php'); |
|
262 | + new EE_Bootstrap(); |
|
263 | + } |
|
264 | 264 | } |
265 | 265 | if ( ! function_exists('espresso_deactivate_plugin')) { |
266 | - /** |
|
267 | - * deactivate_plugin |
|
268 | - * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
269 | - * |
|
270 | - * @access public |
|
271 | - * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
272 | - * @return void |
|
273 | - */ |
|
274 | - function espresso_deactivate_plugin($plugin_basename = '') |
|
275 | - { |
|
276 | - if ( ! function_exists('deactivate_plugins')) { |
|
277 | - require_once(ABSPATH . 'wp-admin/includes/plugin.php'); |
|
278 | - } |
|
279 | - unset($_GET['activate'], $_REQUEST['activate']); |
|
280 | - deactivate_plugins($plugin_basename); |
|
281 | - } |
|
266 | + /** |
|
267 | + * deactivate_plugin |
|
268 | + * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
269 | + * |
|
270 | + * @access public |
|
271 | + * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
272 | + * @return void |
|
273 | + */ |
|
274 | + function espresso_deactivate_plugin($plugin_basename = '') |
|
275 | + { |
|
276 | + if ( ! function_exists('deactivate_plugins')) { |
|
277 | + require_once(ABSPATH . 'wp-admin/includes/plugin.php'); |
|
278 | + } |
|
279 | + unset($_GET['activate'], $_REQUEST['activate']); |
|
280 | + deactivate_plugins($plugin_basename); |
|
281 | + } |
|
282 | 282 | } |
283 | 283 | \ No newline at end of file |
@@ -2,7 +2,7 @@ discard block |
||
2 | 2 | use EventEspresso\core\exceptions\InvalidEntityException; |
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 | |
8 | 8 | |
@@ -17,1723 +17,1723 @@ discard block |
||
17 | 17 | class EED_Single_Page_Checkout extends EED_Module |
18 | 18 | { |
19 | 19 | |
20 | - /** |
|
21 | - * $_initialized - has the SPCO controller already been initialized ? |
|
22 | - * |
|
23 | - * @access private |
|
24 | - * @var bool $_initialized |
|
25 | - */ |
|
26 | - private static $_initialized = false; |
|
27 | - |
|
28 | - |
|
29 | - /** |
|
30 | - * $_checkout_verified - is the EE_Checkout verified as correct for this request ? |
|
31 | - * |
|
32 | - * @access private |
|
33 | - * @var bool $_valid_checkout |
|
34 | - */ |
|
35 | - private static $_checkout_verified = true; |
|
36 | - |
|
37 | - /** |
|
38 | - * $_reg_steps_array - holds initial array of reg steps |
|
39 | - * |
|
40 | - * @access private |
|
41 | - * @var array $_reg_steps_array |
|
42 | - */ |
|
43 | - private static $_reg_steps_array = array(); |
|
44 | - |
|
45 | - /** |
|
46 | - * $checkout - EE_Checkout object for handling the properties of the current checkout process |
|
47 | - * |
|
48 | - * @access public |
|
49 | - * @var EE_Checkout $checkout |
|
50 | - */ |
|
51 | - public $checkout; |
|
52 | - |
|
53 | - |
|
54 | - |
|
55 | - /** |
|
56 | - * @return EED_Single_Page_Checkout |
|
57 | - */ |
|
58 | - public static function instance() |
|
59 | - { |
|
60 | - add_filter('EED_Single_Page_Checkout__SPCO_active', '__return_true'); |
|
61 | - return parent::get_instance(__CLASS__); |
|
62 | - } |
|
63 | - |
|
64 | - |
|
65 | - |
|
66 | - /** |
|
67 | - * @return EE_CART |
|
68 | - */ |
|
69 | - public function cart() |
|
70 | - { |
|
71 | - return $this->checkout->cart; |
|
72 | - } |
|
73 | - |
|
74 | - |
|
75 | - |
|
76 | - /** |
|
77 | - * @return EE_Transaction |
|
78 | - */ |
|
79 | - public function transaction() |
|
80 | - { |
|
81 | - return $this->checkout->transaction; |
|
82 | - } |
|
83 | - |
|
84 | - |
|
85 | - |
|
86 | - /** |
|
87 | - * set_hooks - for hooking into EE Core, other modules, etc |
|
88 | - * |
|
89 | - * @access public |
|
90 | - * @return void |
|
91 | - * @throws \EE_Error |
|
92 | - */ |
|
93 | - public static function set_hooks() |
|
94 | - { |
|
95 | - EED_Single_Page_Checkout::set_definitions(); |
|
96 | - } |
|
97 | - |
|
98 | - |
|
99 | - |
|
100 | - /** |
|
101 | - * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
102 | - * |
|
103 | - * @access public |
|
104 | - * @return void |
|
105 | - * @throws \EE_Error |
|
106 | - */ |
|
107 | - public static function set_hooks_admin() |
|
108 | - { |
|
109 | - EED_Single_Page_Checkout::set_definitions(); |
|
110 | - if ( ! (defined('DOING_AJAX') && DOING_AJAX)) { |
|
111 | - return; |
|
112 | - } |
|
113 | - // going to start an output buffer in case anything gets accidentally output that might disrupt our JSON response |
|
114 | - ob_start(); |
|
115 | - EED_Single_Page_Checkout::load_request_handler(); |
|
116 | - EED_Single_Page_Checkout::load_reg_steps(); |
|
117 | - // set ajax hooks |
|
118 | - add_action('wp_ajax_process_reg_step', array('EED_Single_Page_Checkout', 'process_reg_step')); |
|
119 | - add_action('wp_ajax_nopriv_process_reg_step', array('EED_Single_Page_Checkout', 'process_reg_step')); |
|
120 | - add_action('wp_ajax_display_spco_reg_step', array('EED_Single_Page_Checkout', 'display_reg_step')); |
|
121 | - add_action('wp_ajax_nopriv_display_spco_reg_step', array('EED_Single_Page_Checkout', 'display_reg_step')); |
|
122 | - add_action('wp_ajax_update_reg_step', array('EED_Single_Page_Checkout', 'update_reg_step')); |
|
123 | - add_action('wp_ajax_nopriv_update_reg_step', array('EED_Single_Page_Checkout', 'update_reg_step')); |
|
124 | - } |
|
125 | - |
|
126 | - |
|
127 | - |
|
128 | - /** |
|
129 | - * process ajax request |
|
130 | - * |
|
131 | - * @param string $ajax_action |
|
132 | - * @throws \EE_Error |
|
133 | - */ |
|
134 | - public static function process_ajax_request($ajax_action) |
|
135 | - { |
|
136 | - EE_Registry::instance()->REQ->set('action', $ajax_action); |
|
137 | - EED_Single_Page_Checkout::instance()->_initialize(); |
|
138 | - } |
|
139 | - |
|
140 | - |
|
141 | - |
|
142 | - /** |
|
143 | - * ajax display registration step |
|
144 | - * |
|
145 | - * @throws \EE_Error |
|
146 | - */ |
|
147 | - public static function display_reg_step() |
|
148 | - { |
|
149 | - EED_Single_Page_Checkout::process_ajax_request('display_spco_reg_step'); |
|
150 | - } |
|
151 | - |
|
152 | - |
|
153 | - |
|
154 | - /** |
|
155 | - * ajax process registration step |
|
156 | - * |
|
157 | - * @throws \EE_Error |
|
158 | - */ |
|
159 | - public static function process_reg_step() |
|
160 | - { |
|
161 | - EED_Single_Page_Checkout::process_ajax_request('process_reg_step'); |
|
162 | - } |
|
163 | - |
|
164 | - |
|
165 | - |
|
166 | - /** |
|
167 | - * ajax process registration step |
|
168 | - * |
|
169 | - * @throws \EE_Error |
|
170 | - */ |
|
171 | - public static function update_reg_step() |
|
172 | - { |
|
173 | - EED_Single_Page_Checkout::process_ajax_request('update_reg_step'); |
|
174 | - } |
|
175 | - |
|
176 | - |
|
177 | - |
|
178 | - /** |
|
179 | - * update_checkout |
|
180 | - * |
|
181 | - * @access public |
|
182 | - * @return void |
|
183 | - * @throws \EE_Error |
|
184 | - */ |
|
185 | - public static function update_checkout() |
|
186 | - { |
|
187 | - EED_Single_Page_Checkout::process_ajax_request('update_checkout'); |
|
188 | - } |
|
189 | - |
|
190 | - |
|
191 | - |
|
192 | - /** |
|
193 | - * load_request_handler |
|
194 | - * |
|
195 | - * @access public |
|
196 | - * @return void |
|
197 | - */ |
|
198 | - public static function load_request_handler() |
|
199 | - { |
|
200 | - // load core Request_Handler class |
|
201 | - if ( ! isset(EE_Registry::instance()->REQ)) { |
|
202 | - EE_Registry::instance()->load_core('Request_Handler'); |
|
203 | - } |
|
204 | - } |
|
205 | - |
|
206 | - |
|
207 | - |
|
208 | - /** |
|
209 | - * set_definitions |
|
210 | - * |
|
211 | - * @access public |
|
212 | - * @return void |
|
213 | - * @throws \EE_Error |
|
214 | - */ |
|
215 | - public static function set_definitions() |
|
216 | - { |
|
217 | - if(defined('SPCO_BASE_PATH')) { |
|
218 | - return; |
|
219 | - } |
|
220 | - define('SPCO_BASE_PATH', rtrim(str_replace(array('\\', '/'), DS, plugin_dir_path(__FILE__)), DS) . DS); |
|
221 | - define('SPCO_CSS_URL', plugin_dir_url(__FILE__) . 'css' . DS); |
|
222 | - define('SPCO_IMG_URL', plugin_dir_url(__FILE__) . 'img' . DS); |
|
223 | - define('SPCO_JS_URL', plugin_dir_url(__FILE__) . 'js' . DS); |
|
224 | - define('SPCO_INC_PATH', SPCO_BASE_PATH . 'inc' . DS); |
|
225 | - define('SPCO_REG_STEPS_PATH', SPCO_BASE_PATH . 'reg_steps' . DS); |
|
226 | - define('SPCO_TEMPLATES_PATH', SPCO_BASE_PATH . 'templates' . DS); |
|
227 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(SPCO_BASE_PATH, true); |
|
228 | - EE_Registry::$i18n_js_strings['registration_expiration_notice'] = sprintf( |
|
229 | - __('%1$sWe\'re sorry, but you\'re registration time has expired.%2$s%4$sIf you still wish to complete your registration, please return to the %5$sEvent List%6$sEvent List%7$s and reselect your tickets if available. Please except our apologies for any inconvenience this may have caused.%8$s', |
|
230 | - 'event_espresso'), |
|
231 | - '<h4 class="important-notice">', |
|
232 | - '</h4>', |
|
233 | - '<br />', |
|
234 | - '<p>', |
|
235 | - '<a href="' . get_post_type_archive_link('espresso_events') . '" title="', |
|
236 | - '">', |
|
237 | - '</a>', |
|
238 | - '</p>' |
|
239 | - ); |
|
240 | - } |
|
241 | - |
|
242 | - |
|
243 | - |
|
244 | - /** |
|
245 | - * load_reg_steps |
|
246 | - * loads and instantiates each reg step based on the EE_Registry::instance()->CFG->registration->reg_steps array |
|
247 | - * |
|
248 | - * @access private |
|
249 | - * @throws \EE_Error |
|
250 | - */ |
|
251 | - public static function load_reg_steps() |
|
252 | - { |
|
253 | - static $reg_steps_loaded = false; |
|
254 | - if ($reg_steps_loaded) { |
|
255 | - return; |
|
256 | - } |
|
257 | - // filter list of reg_steps |
|
258 | - $reg_steps_to_load = (array)apply_filters( |
|
259 | - 'AHEE__SPCO__load_reg_steps__reg_steps_to_load', |
|
260 | - EED_Single_Page_Checkout::get_reg_steps() |
|
261 | - ); |
|
262 | - // sort by key (order) |
|
263 | - ksort($reg_steps_to_load); |
|
264 | - // loop through folders |
|
265 | - foreach ($reg_steps_to_load as $order => $reg_step) { |
|
266 | - // we need a |
|
267 | - if (isset($reg_step['file_path'], $reg_step['class_name'], $reg_step['slug'])) { |
|
268 | - // copy over to the reg_steps_array |
|
269 | - EED_Single_Page_Checkout::$_reg_steps_array[$order] = $reg_step; |
|
270 | - // register custom key route for each reg step |
|
271 | - // ie: step=>"slug" - this is the entire reason we load the reg steps array now |
|
272 | - EE_Config::register_route($reg_step['slug'], 'EED_Single_Page_Checkout', 'run', 'step'); |
|
273 | - // add AJAX or other hooks |
|
274 | - if (isset($reg_step['has_hooks']) && $reg_step['has_hooks']) { |
|
275 | - // setup autoloaders if necessary |
|
276 | - if ( ! class_exists($reg_step['class_name'])) { |
|
277 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder($reg_step['file_path'], true); |
|
278 | - } |
|
279 | - if (is_callable($reg_step['class_name'], 'set_hooks')) { |
|
280 | - call_user_func(array($reg_step['class_name'], 'set_hooks')); |
|
281 | - } |
|
282 | - } |
|
283 | - } |
|
284 | - } |
|
285 | - $reg_steps_loaded = true; |
|
286 | - } |
|
287 | - |
|
288 | - |
|
289 | - |
|
290 | - /** |
|
291 | - * get_reg_steps |
|
292 | - * |
|
293 | - * @access public |
|
294 | - * @return array |
|
295 | - */ |
|
296 | - public static function get_reg_steps() |
|
297 | - { |
|
298 | - $reg_steps = EE_Registry::instance()->CFG->registration->reg_steps; |
|
299 | - if (empty($reg_steps)) { |
|
300 | - $reg_steps = array( |
|
301 | - 10 => array( |
|
302 | - 'file_path' => SPCO_REG_STEPS_PATH . 'attendee_information', |
|
303 | - 'class_name' => 'EE_SPCO_Reg_Step_Attendee_Information', |
|
304 | - 'slug' => 'attendee_information', |
|
305 | - 'has_hooks' => false, |
|
306 | - ), |
|
307 | - 20 => array( |
|
308 | - 'file_path' => SPCO_REG_STEPS_PATH . 'registration_confirmation', |
|
309 | - 'class_name' => 'EE_SPCO_Reg_Step_Registration_Confirmation', |
|
310 | - 'slug' => 'registration_confirmation', |
|
311 | - 'has_hooks' => false, |
|
312 | - ), |
|
313 | - 30 => array( |
|
314 | - 'file_path' => SPCO_REG_STEPS_PATH . 'payment_options', |
|
315 | - 'class_name' => 'EE_SPCO_Reg_Step_Payment_Options', |
|
316 | - 'slug' => 'payment_options', |
|
317 | - 'has_hooks' => true, |
|
318 | - ), |
|
319 | - 999 => array( |
|
320 | - 'file_path' => SPCO_REG_STEPS_PATH . 'finalize_registration', |
|
321 | - 'class_name' => 'EE_SPCO_Reg_Step_Finalize_Registration', |
|
322 | - 'slug' => 'finalize_registration', |
|
323 | - 'has_hooks' => false, |
|
324 | - ), |
|
325 | - ); |
|
326 | - } |
|
327 | - return $reg_steps; |
|
328 | - } |
|
329 | - |
|
330 | - |
|
331 | - |
|
332 | - /** |
|
333 | - * registration_checkout_for_admin |
|
334 | - * |
|
335 | - * @access public |
|
336 | - * @return string |
|
337 | - * @throws \EE_Error |
|
338 | - */ |
|
339 | - public static function registration_checkout_for_admin() |
|
340 | - { |
|
341 | - EED_Single_Page_Checkout::load_request_handler(); |
|
342 | - EE_Registry::instance()->REQ->set('step', 'attendee_information'); |
|
343 | - EE_Registry::instance()->REQ->set('action', 'display_spco_reg_step'); |
|
344 | - EE_Registry::instance()->REQ->set('process_form_submission', false); |
|
345 | - EED_Single_Page_Checkout::instance()->_initialize(); |
|
346 | - EED_Single_Page_Checkout::instance()->_display_spco_reg_form(); |
|
347 | - return EE_Registry::instance()->REQ->get_output(); |
|
348 | - } |
|
349 | - |
|
350 | - |
|
351 | - |
|
352 | - /** |
|
353 | - * process_registration_from_admin |
|
354 | - * |
|
355 | - * @access public |
|
356 | - * @return \EE_Transaction |
|
357 | - * @throws \EE_Error |
|
358 | - */ |
|
359 | - public static function process_registration_from_admin() |
|
360 | - { |
|
361 | - EED_Single_Page_Checkout::load_request_handler(); |
|
362 | - EE_Registry::instance()->REQ->set('step', 'attendee_information'); |
|
363 | - EE_Registry::instance()->REQ->set('action', 'process_reg_step'); |
|
364 | - EE_Registry::instance()->REQ->set('process_form_submission', true); |
|
365 | - EED_Single_Page_Checkout::instance()->_initialize(); |
|
366 | - if (EED_Single_Page_Checkout::instance()->checkout->current_step->completed()) { |
|
367 | - $final_reg_step = end(EED_Single_Page_Checkout::instance()->checkout->reg_steps); |
|
368 | - if ($final_reg_step instanceof EE_SPCO_Reg_Step_Finalize_Registration) { |
|
369 | - EED_Single_Page_Checkout::instance()->checkout->set_reg_step_initiated($final_reg_step); |
|
370 | - if ($final_reg_step->process_reg_step()) { |
|
371 | - $final_reg_step->set_completed(); |
|
372 | - EED_Single_Page_Checkout::instance()->checkout->update_txn_reg_steps_array(); |
|
373 | - return EED_Single_Page_Checkout::instance()->checkout->transaction; |
|
374 | - } |
|
375 | - } |
|
376 | - } |
|
377 | - return null; |
|
378 | - } |
|
379 | - |
|
380 | - |
|
381 | - |
|
382 | - /** |
|
383 | - * run |
|
384 | - * |
|
385 | - * @access public |
|
386 | - * @param WP_Query $WP_Query |
|
387 | - * @return void |
|
388 | - * @throws \EE_Error |
|
389 | - */ |
|
390 | - public function run($WP_Query) |
|
391 | - { |
|
392 | - if ( |
|
393 | - $WP_Query instanceof WP_Query |
|
394 | - && $WP_Query->is_main_query() |
|
395 | - && apply_filters('FHEE__EED_Single_Page_Checkout__run', true) |
|
396 | - && $this->_is_reg_checkout() |
|
397 | - ) { |
|
398 | - $this->_initialize(); |
|
399 | - } |
|
400 | - } |
|
401 | - |
|
402 | - |
|
403 | - |
|
404 | - /** |
|
405 | - * determines whether current url matches reg page url |
|
406 | - * |
|
407 | - * @return bool |
|
408 | - */ |
|
409 | - protected function _is_reg_checkout() |
|
410 | - { |
|
411 | - // get current permalink for reg page without any extra query args |
|
412 | - $reg_page_url = \get_permalink(EE_Config::instance()->core->reg_page_id); |
|
413 | - // get request URI for current request, but without the scheme or host |
|
414 | - $current_request_uri = \EEH_URL::filter_input_server_url('REQUEST_URI'); |
|
415 | - $current_request_uri = html_entity_decode($current_request_uri); |
|
416 | - // get array of query args from the current request URI |
|
417 | - $query_args = \EEH_URL::get_query_string($current_request_uri); |
|
418 | - // grab page id if it is set |
|
419 | - $page_id = isset($query_args['page_id']) ? absint($query_args['page_id']) : 0; |
|
420 | - // and remove the page id from the query args (we will re-add it later) |
|
421 | - unset($query_args['page_id']); |
|
422 | - // now strip all query args from current request URI |
|
423 | - $current_request_uri = remove_query_arg(array_keys($query_args), $current_request_uri); |
|
424 | - // and re-add the page id if it was set |
|
425 | - if ($page_id) { |
|
426 | - $current_request_uri = add_query_arg('page_id', $page_id, $current_request_uri); |
|
427 | - } |
|
428 | - // remove slashes and ? |
|
429 | - $current_request_uri = trim($current_request_uri, '?/'); |
|
430 | - // is current request URI part of the known full reg page URL ? |
|
431 | - return ! empty($current_request_uri) && strpos($reg_page_url, $current_request_uri) !== false; |
|
432 | - } |
|
433 | - |
|
434 | - |
|
435 | - |
|
436 | - /** |
|
437 | - * @param WP_Query $wp_query |
|
438 | - * @return void |
|
439 | - * @throws \EE_Error |
|
440 | - */ |
|
441 | - public static function init($wp_query) |
|
442 | - { |
|
443 | - EED_Single_Page_Checkout::instance()->run($wp_query); |
|
444 | - } |
|
445 | - |
|
446 | - |
|
447 | - |
|
448 | - /** |
|
449 | - * _initialize - initial module setup |
|
450 | - * |
|
451 | - * @access private |
|
452 | - * @throws EE_Error |
|
453 | - * @return void |
|
454 | - */ |
|
455 | - private function _initialize() |
|
456 | - { |
|
457 | - // ensure SPCO doesn't run twice |
|
458 | - if (EED_Single_Page_Checkout::$_initialized) { |
|
459 | - return; |
|
460 | - } |
|
461 | - try { |
|
462 | - EED_Single_Page_Checkout::load_reg_steps(); |
|
463 | - $this->_verify_session(); |
|
464 | - // setup the EE_Checkout object |
|
465 | - $this->checkout = $this->_initialize_checkout(); |
|
466 | - // filter checkout |
|
467 | - $this->checkout = apply_filters('FHEE__EED_Single_Page_Checkout___initialize__checkout', $this->checkout); |
|
468 | - // get the $_GET |
|
469 | - $this->_get_request_vars(); |
|
470 | - if ($this->_block_bots()) { |
|
471 | - return; |
|
472 | - } |
|
473 | - // filter continue_reg |
|
474 | - $this->checkout->continue_reg = apply_filters('FHEE__EED_Single_Page_Checkout__init___continue_reg', true, $this->checkout); |
|
475 | - // load the reg steps array |
|
476 | - if ( ! $this->_load_and_instantiate_reg_steps()) { |
|
477 | - EED_Single_Page_Checkout::$_initialized = true; |
|
478 | - return; |
|
479 | - } |
|
480 | - // set the current step |
|
481 | - $this->checkout->set_current_step($this->checkout->step); |
|
482 | - // and the next step |
|
483 | - $this->checkout->set_next_step(); |
|
484 | - // verify that everything has been setup correctly |
|
485 | - if ( ! ($this->_verify_transaction_and_get_registrations() && $this->_final_verifications())) { |
|
486 | - EED_Single_Page_Checkout::$_initialized = true; |
|
487 | - return; |
|
488 | - } |
|
489 | - // lock the transaction |
|
490 | - $this->checkout->transaction->lock(); |
|
491 | - // make sure all of our cached objects are added to their respective model entity mappers |
|
492 | - $this->checkout->refresh_all_entities(); |
|
493 | - // set amount owing |
|
494 | - $this->checkout->amount_owing = $this->checkout->transaction->remaining(); |
|
495 | - // initialize each reg step, which gives them the chance to potentially alter the process |
|
496 | - $this->_initialize_reg_steps(); |
|
497 | - // DEBUG LOG |
|
498 | - //$this->checkout->log( __CLASS__, __FUNCTION__, __LINE__ ); |
|
499 | - // get reg form |
|
500 | - if( ! $this->_check_form_submission()) { |
|
501 | - EED_Single_Page_Checkout::$_initialized = true; |
|
502 | - return; |
|
503 | - } |
|
504 | - // checkout the action!!! |
|
505 | - $this->_process_form_action(); |
|
506 | - // add some style and make it dance |
|
507 | - $this->add_styles_and_scripts(); |
|
508 | - // kk... SPCO has successfully run |
|
509 | - EED_Single_Page_Checkout::$_initialized = true; |
|
510 | - // set no cache headers and constants |
|
511 | - EE_System::do_not_cache(); |
|
512 | - // add anchor |
|
513 | - add_action('loop_start', array($this, 'set_checkout_anchor'), 1); |
|
514 | - // remove transaction lock |
|
515 | - add_action('shutdown', array($this, 'unlock_transaction'), 1); |
|
516 | - } catch (Exception $e) { |
|
517 | - EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
518 | - } |
|
519 | - } |
|
520 | - |
|
521 | - |
|
522 | - |
|
523 | - /** |
|
524 | - * _verify_session |
|
525 | - * checks that the session is valid and not expired |
|
526 | - * |
|
527 | - * @access private |
|
528 | - * @throws EE_Error |
|
529 | - */ |
|
530 | - private function _verify_session() |
|
531 | - { |
|
532 | - if ( ! EE_Registry::instance()->SSN instanceof EE_Session) { |
|
533 | - throw new EE_Error(__('The EE_Session class could not be loaded.', 'event_espresso')); |
|
534 | - } |
|
535 | - // is session still valid ? |
|
536 | - if (EE_Registry::instance()->SSN->expired() && EE_Registry::instance()->REQ->get('e_reg_url_link', '') === '') { |
|
537 | - $this->checkout = new EE_Checkout(); |
|
538 | - EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__); |
|
539 | - // EE_Registry::instance()->SSN->reset_cart(); |
|
540 | - // EE_Registry::instance()->SSN->reset_checkout(); |
|
541 | - // EE_Registry::instance()->SSN->reset_transaction(); |
|
542 | - EE_Error::add_attention(EE_Registry::$i18n_js_strings['registration_expiration_notice'], __FILE__, |
|
543 | - __FUNCTION__, __LINE__); |
|
544 | - // EE_Registry::instance()->SSN->reset_expired(); |
|
545 | - } |
|
546 | - } |
|
547 | - |
|
548 | - |
|
549 | - |
|
550 | - /** |
|
551 | - * _initialize_checkout |
|
552 | - * loads and instantiates EE_Checkout |
|
553 | - * |
|
554 | - * @access private |
|
555 | - * @throws EE_Error |
|
556 | - * @return EE_Checkout |
|
557 | - */ |
|
558 | - private function _initialize_checkout() |
|
559 | - { |
|
560 | - // look in session for existing checkout |
|
561 | - /** @type EE_Checkout $checkout */ |
|
562 | - $checkout = EE_Registry::instance()->SSN->checkout(); |
|
563 | - // verify |
|
564 | - if ( ! $checkout instanceof EE_Checkout) { |
|
565 | - // instantiate EE_Checkout object for handling the properties of the current checkout process |
|
566 | - $checkout = EE_Registry::instance()->load_file(SPCO_INC_PATH, 'EE_Checkout', 'class', array(), false); |
|
567 | - } else { |
|
568 | - if ($checkout->current_step->is_final_step() && $checkout->exit_spco() === true) { |
|
569 | - $this->unlock_transaction(); |
|
570 | - wp_safe_redirect($checkout->redirect_url); |
|
571 | - exit(); |
|
572 | - } |
|
573 | - } |
|
574 | - $checkout = apply_filters('FHEE__EED_Single_Page_Checkout___initialize_checkout__checkout', $checkout); |
|
575 | - // verify again |
|
576 | - if ( ! $checkout instanceof EE_Checkout) { |
|
577 | - throw new EE_Error(__('The EE_Checkout class could not be loaded.', 'event_espresso')); |
|
578 | - } |
|
579 | - // reset anything that needs a clean slate for each request |
|
580 | - $checkout->reset_for_current_request(); |
|
581 | - return $checkout; |
|
582 | - } |
|
583 | - |
|
584 | - |
|
585 | - |
|
586 | - /** |
|
587 | - * _get_request_vars |
|
588 | - * |
|
589 | - * @access private |
|
590 | - * @return void |
|
591 | - * @throws \EE_Error |
|
592 | - */ |
|
593 | - private function _get_request_vars() |
|
594 | - { |
|
595 | - // load classes |
|
596 | - EED_Single_Page_Checkout::load_request_handler(); |
|
597 | - //make sure this request is marked as belonging to EE |
|
598 | - EE_Registry::instance()->REQ->set_espresso_page(true); |
|
599 | - // which step is being requested ? |
|
600 | - $this->checkout->step = EE_Registry::instance()->REQ->get('step', $this->_get_first_step()); |
|
601 | - // which step is being edited ? |
|
602 | - $this->checkout->edit_step = EE_Registry::instance()->REQ->get('edit_step', ''); |
|
603 | - // and what we're doing on the current step |
|
604 | - $this->checkout->action = EE_Registry::instance()->REQ->get('action', 'display_spco_reg_step'); |
|
605 | - // timestamp |
|
606 | - $this->checkout->uts = EE_Registry::instance()->REQ->get('uts', 0); |
|
607 | - // returning to edit ? |
|
608 | - $this->checkout->reg_url_link = EE_Registry::instance()->REQ->get('e_reg_url_link', ''); |
|
609 | - // or some other kind of revisit ? |
|
610 | - $this->checkout->revisit = filter_var( |
|
611 | - EE_Registry::instance()->REQ->get('revisit', false), |
|
612 | - FILTER_VALIDATE_BOOLEAN |
|
613 | - ); |
|
614 | - // and whether or not to generate a reg form for this request |
|
615 | - $this->checkout->generate_reg_form = filter_var( |
|
616 | - EE_Registry::instance()->REQ->get('generate_reg_form', true), |
|
617 | - FILTER_VALIDATE_BOOLEAN |
|
618 | - ); |
|
619 | - // and whether or not to process a reg form submission for this request |
|
620 | - $this->checkout->process_form_submission = filter_var( |
|
621 | - EE_Registry::instance()->REQ->get( |
|
622 | - 'process_form_submission', |
|
623 | - $this->checkout->action === 'process_reg_step' |
|
624 | - ), |
|
625 | - FILTER_VALIDATE_BOOLEAN |
|
626 | - ); |
|
627 | - $this->checkout->process_form_submission = filter_var( |
|
628 | - $this->checkout->action !== 'display_spco_reg_step' |
|
629 | - ? $this->checkout->process_form_submission |
|
630 | - : false, |
|
631 | - FILTER_VALIDATE_BOOLEAN |
|
632 | - ); |
|
633 | - // $this->_display_request_vars(); |
|
634 | - } |
|
635 | - |
|
636 | - |
|
637 | - |
|
638 | - /** |
|
639 | - * _display_request_vars |
|
640 | - * |
|
641 | - * @access protected |
|
642 | - * @return void |
|
643 | - */ |
|
644 | - protected function _display_request_vars() |
|
645 | - { |
|
646 | - if ( ! WP_DEBUG) { |
|
647 | - return; |
|
648 | - } |
|
649 | - EEH_Debug_Tools::printr($_REQUEST, '$_REQUEST', __FILE__, __LINE__); |
|
650 | - EEH_Debug_Tools::printr($this->checkout->step, '$this->checkout->step', __FILE__, __LINE__); |
|
651 | - EEH_Debug_Tools::printr($this->checkout->edit_step, '$this->checkout->edit_step', __FILE__, __LINE__); |
|
652 | - EEH_Debug_Tools::printr($this->checkout->action, '$this->checkout->action', __FILE__, __LINE__); |
|
653 | - EEH_Debug_Tools::printr($this->checkout->reg_url_link, '$this->checkout->reg_url_link', __FILE__, __LINE__); |
|
654 | - EEH_Debug_Tools::printr($this->checkout->revisit, '$this->checkout->revisit', __FILE__, __LINE__); |
|
655 | - EEH_Debug_Tools::printr($this->checkout->generate_reg_form, '$this->checkout->generate_reg_form', __FILE__, __LINE__); |
|
656 | - EEH_Debug_Tools::printr($this->checkout->process_form_submission, '$this->checkout->process_form_submission', __FILE__, __LINE__); |
|
657 | - } |
|
658 | - |
|
659 | - |
|
660 | - |
|
661 | - /** |
|
662 | - * _block_bots |
|
663 | - * checks that the incoming request has either of the following set: |
|
664 | - * a uts (unix timestamp) which indicates that the request was redirected from the Ticket Selector |
|
665 | - * a REG URL Link, which indicates that the request is a return visit to SPCO for a valid TXN |
|
666 | - * so if you're not coming from the Ticket Selector nor returning for a valid IP... |
|
667 | - * then where you coming from man? |
|
668 | - * |
|
669 | - * @return boolean |
|
670 | - */ |
|
671 | - private function _block_bots() |
|
672 | - { |
|
673 | - $invalid_checkout_access = \EED_Invalid_Checkout_Access::getInvalidCheckoutAccess(); |
|
674 | - if ($invalid_checkout_access->checkoutAccessIsInvalid($this->checkout)) { |
|
675 | - return true; |
|
676 | - } |
|
677 | - return false; |
|
678 | - } |
|
679 | - |
|
680 | - |
|
681 | - |
|
682 | - /** |
|
683 | - * _get_first_step |
|
684 | - * gets slug for first step in $_reg_steps_array |
|
685 | - * |
|
686 | - * @access private |
|
687 | - * @throws EE_Error |
|
688 | - * @return string |
|
689 | - */ |
|
690 | - private function _get_first_step() |
|
691 | - { |
|
692 | - $first_step = reset(EED_Single_Page_Checkout::$_reg_steps_array); |
|
693 | - return isset($first_step['slug']) ? $first_step['slug'] : 'attendee_information'; |
|
694 | - } |
|
695 | - |
|
696 | - |
|
697 | - |
|
698 | - /** |
|
699 | - * _load_and_instantiate_reg_steps |
|
700 | - * instantiates each reg step based on the loaded reg_steps array |
|
701 | - * |
|
702 | - * @access private |
|
703 | - * @throws EE_Error |
|
704 | - * @return bool |
|
705 | - */ |
|
706 | - private function _load_and_instantiate_reg_steps() |
|
707 | - { |
|
708 | - do_action('AHEE__Single_Page_Checkout___load_and_instantiate_reg_steps__start', $this->checkout); |
|
709 | - // have reg_steps already been instantiated ? |
|
710 | - if ( |
|
711 | - empty($this->checkout->reg_steps) |
|
712 | - || apply_filters('FHEE__Single_Page_Checkout__load_reg_steps__reload_reg_steps', false, $this->checkout) |
|
713 | - ) { |
|
714 | - // if not, then loop through raw reg steps array |
|
715 | - foreach (EED_Single_Page_Checkout::$_reg_steps_array as $order => $reg_step) { |
|
716 | - if ( ! $this->_load_and_instantiate_reg_step($reg_step, $order)) { |
|
717 | - return false; |
|
718 | - } |
|
719 | - } |
|
720 | - EE_Registry::instance()->CFG->registration->skip_reg_confirmation = true; |
|
721 | - EE_Registry::instance()->CFG->registration->reg_confirmation_last = true; |
|
722 | - // skip the registration_confirmation page ? |
|
723 | - if (EE_Registry::instance()->CFG->registration->skip_reg_confirmation) { |
|
724 | - // just remove it from the reg steps array |
|
725 | - $this->checkout->remove_reg_step('registration_confirmation', false); |
|
726 | - } else if ( |
|
727 | - isset($this->checkout->reg_steps['registration_confirmation']) |
|
728 | - && EE_Registry::instance()->CFG->registration->reg_confirmation_last |
|
729 | - ) { |
|
730 | - // set the order to something big like 100 |
|
731 | - $this->checkout->set_reg_step_order('registration_confirmation', 100); |
|
732 | - } |
|
733 | - // filter the array for good luck |
|
734 | - $this->checkout->reg_steps = apply_filters( |
|
735 | - 'FHEE__Single_Page_Checkout__load_reg_steps__reg_steps', |
|
736 | - $this->checkout->reg_steps |
|
737 | - ); |
|
738 | - // finally re-sort based on the reg step class order properties |
|
739 | - $this->checkout->sort_reg_steps(); |
|
740 | - } else { |
|
741 | - foreach ($this->checkout->reg_steps as $reg_step) { |
|
742 | - // set all current step stati to FALSE |
|
743 | - $reg_step->set_is_current_step(false); |
|
744 | - } |
|
745 | - } |
|
746 | - if (empty($this->checkout->reg_steps)) { |
|
747 | - EE_Error::add_error(__('No Reg Steps were loaded..', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
748 | - return false; |
|
749 | - } |
|
750 | - // make reg step details available to JS |
|
751 | - $this->checkout->set_reg_step_JSON_info(); |
|
752 | - return true; |
|
753 | - } |
|
754 | - |
|
755 | - |
|
756 | - |
|
757 | - /** |
|
758 | - * _load_and_instantiate_reg_step |
|
759 | - * |
|
760 | - * @access private |
|
761 | - * @param array $reg_step |
|
762 | - * @param int $order |
|
763 | - * @return bool |
|
764 | - */ |
|
765 | - private function _load_and_instantiate_reg_step($reg_step = array(), $order = 0) |
|
766 | - { |
|
767 | - // we need a file_path, class_name, and slug to add a reg step |
|
768 | - if (isset($reg_step['file_path'], $reg_step['class_name'], $reg_step['slug'])) { |
|
769 | - // if editing a specific step, but this is NOT that step... (and it's not the 'finalize_registration' step) |
|
770 | - if ( |
|
771 | - $this->checkout->reg_url_link |
|
772 | - && $this->checkout->step !== $reg_step['slug'] |
|
773 | - && $reg_step['slug'] !== 'finalize_registration' |
|
774 | - // normally at this point we would NOT load the reg step, but this filter can change that |
|
775 | - && apply_filters( |
|
776 | - 'FHEE__Single_Page_Checkout___load_and_instantiate_reg_step__bypass_reg_step', |
|
777 | - true, |
|
778 | - $reg_step, |
|
779 | - $this->checkout |
|
780 | - ) |
|
781 | - ) { |
|
782 | - return true; |
|
783 | - } |
|
784 | - // instantiate step class using file path and class name |
|
785 | - $reg_step_obj = EE_Registry::instance()->load_file( |
|
786 | - $reg_step['file_path'], |
|
787 | - $reg_step['class_name'], |
|
788 | - 'class', |
|
789 | - $this->checkout, |
|
790 | - false |
|
791 | - ); |
|
792 | - // did we gets the goods ? |
|
793 | - if ($reg_step_obj instanceof EE_SPCO_Reg_Step) { |
|
794 | - // set reg step order based on config |
|
795 | - $reg_step_obj->set_order($order); |
|
796 | - // add instantiated reg step object to the master reg steps array |
|
797 | - $this->checkout->add_reg_step($reg_step_obj); |
|
798 | - } else { |
|
799 | - EE_Error::add_error( |
|
800 | - __('The current step could not be set.', 'event_espresso'), |
|
801 | - __FILE__, __FUNCTION__, __LINE__ |
|
802 | - ); |
|
803 | - return false; |
|
804 | - } |
|
805 | - } else { |
|
806 | - if (WP_DEBUG) { |
|
807 | - EE_Error::add_error( |
|
808 | - sprintf( |
|
809 | - __('A registration step could not be loaded. One or more of the following data points is invalid:%4$s%5$sFile Path: %1$s%6$s%5$sClass Name: %2$s%6$s%5$sSlug: %3$s%6$s%7$s', 'event_espresso'), |
|
810 | - isset($reg_step['file_path']) ? $reg_step['file_path'] : '', |
|
811 | - isset($reg_step['class_name']) ? $reg_step['class_name'] : '', |
|
812 | - isset($reg_step['slug']) ? $reg_step['slug'] : '', |
|
813 | - '<ul>', |
|
814 | - '<li>', |
|
815 | - '</li>', |
|
816 | - '</ul>' |
|
817 | - ), |
|
818 | - __FILE__, __FUNCTION__, __LINE__ |
|
819 | - ); |
|
820 | - } |
|
821 | - return false; |
|
822 | - } |
|
823 | - return true; |
|
824 | - } |
|
825 | - |
|
826 | - |
|
827 | - |
|
828 | - /** |
|
829 | - * _verify_transaction_and_get_registrations |
|
830 | - * |
|
831 | - * @access private |
|
832 | - * @return bool |
|
833 | - */ |
|
834 | - private function _verify_transaction_and_get_registrations() |
|
835 | - { |
|
836 | - // was there already a valid transaction in the checkout from the session ? |
|
837 | - if ( ! $this->checkout->transaction instanceof EE_Transaction) { |
|
838 | - // get transaction from db or session |
|
839 | - $this->checkout->transaction = $this->checkout->reg_url_link && ! is_admin() |
|
840 | - ? $this->_get_transaction_and_cart_for_previous_visit() |
|
841 | - : $this->_get_cart_for_current_session_and_setup_new_transaction(); |
|
842 | - if ( ! $this->checkout->transaction instanceof EE_Transaction) { |
|
843 | - EE_Error::add_error( |
|
844 | - __('Your Registration and Transaction information could not be retrieved from the db.', |
|
845 | - 'event_espresso'), |
|
846 | - __FILE__, __FUNCTION__, __LINE__ |
|
847 | - ); |
|
848 | - $this->checkout->transaction = EE_Transaction::new_instance(); |
|
849 | - // add some style and make it dance |
|
850 | - $this->add_styles_and_scripts(); |
|
851 | - EED_Single_Page_Checkout::$_initialized = true; |
|
852 | - return false; |
|
853 | - } |
|
854 | - // and the registrations for the transaction |
|
855 | - $this->_get_registrations($this->checkout->transaction); |
|
856 | - } |
|
857 | - return true; |
|
858 | - } |
|
859 | - |
|
860 | - |
|
861 | - |
|
862 | - /** |
|
863 | - * _get_transaction_and_cart_for_previous_visit |
|
864 | - * |
|
865 | - * @access private |
|
866 | - * @return mixed EE_Transaction|NULL |
|
867 | - */ |
|
868 | - private function _get_transaction_and_cart_for_previous_visit() |
|
869 | - { |
|
870 | - /** @var $TXN_model EEM_Transaction */ |
|
871 | - $TXN_model = EE_Registry::instance()->load_model('Transaction'); |
|
872 | - // because the reg_url_link is present in the request, this is a return visit to SPCO, so we'll get the transaction data from the db |
|
873 | - $transaction = $TXN_model->get_transaction_from_reg_url_link($this->checkout->reg_url_link); |
|
874 | - // verify transaction |
|
875 | - if ($transaction instanceof EE_Transaction) { |
|
876 | - // and get the cart that was used for that transaction |
|
877 | - $this->checkout->cart = $this->_get_cart_for_transaction($transaction); |
|
878 | - return $transaction; |
|
879 | - } else { |
|
880 | - EE_Error::add_error(__('Your Registration and Transaction information could not be retrieved from the db.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
881 | - return null; |
|
882 | - } |
|
883 | - } |
|
884 | - |
|
885 | - |
|
886 | - |
|
887 | - /** |
|
888 | - * _get_cart_for_transaction |
|
889 | - * |
|
890 | - * @access private |
|
891 | - * @param EE_Transaction $transaction |
|
892 | - * @return EE_Cart |
|
893 | - */ |
|
894 | - private function _get_cart_for_transaction($transaction) |
|
895 | - { |
|
896 | - return $this->checkout->get_cart_for_transaction($transaction); |
|
897 | - } |
|
898 | - |
|
899 | - |
|
900 | - |
|
901 | - /** |
|
902 | - * get_cart_for_transaction |
|
903 | - * |
|
904 | - * @access public |
|
905 | - * @param EE_Transaction $transaction |
|
906 | - * @return EE_Cart |
|
907 | - */ |
|
908 | - public function get_cart_for_transaction(EE_Transaction $transaction) |
|
909 | - { |
|
910 | - return $this->checkout->get_cart_for_transaction($transaction); |
|
911 | - } |
|
912 | - |
|
913 | - |
|
914 | - |
|
915 | - /** |
|
916 | - * _get_transaction_and_cart_for_current_session |
|
917 | - * generates a new EE_Transaction object and adds it to the $_transaction property. |
|
918 | - * |
|
919 | - * @access private |
|
920 | - * @return EE_Transaction |
|
921 | - * @throws \EE_Error |
|
922 | - */ |
|
923 | - private function _get_cart_for_current_session_and_setup_new_transaction() |
|
924 | - { |
|
925 | - // if there's no transaction, then this is the FIRST visit to SPCO |
|
926 | - // so load up the cart ( passing nothing for the TXN because it doesn't exist yet ) |
|
927 | - $this->checkout->cart = $this->_get_cart_for_transaction(null); |
|
928 | - // and then create a new transaction |
|
929 | - $transaction = $this->_initialize_transaction(); |
|
930 | - // verify transaction |
|
931 | - if ($transaction instanceof EE_Transaction) { |
|
932 | - // save it so that we have an ID for other objects to use |
|
933 | - $transaction->save(); |
|
934 | - // and save TXN data to the cart |
|
935 | - $this->checkout->cart->get_grand_total()->save_this_and_descendants_to_txn($transaction->ID()); |
|
936 | - } else { |
|
937 | - EE_Error::add_error(__('A Valid Transaction could not be initialized.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
938 | - } |
|
939 | - return $transaction; |
|
940 | - } |
|
941 | - |
|
942 | - |
|
943 | - |
|
944 | - /** |
|
945 | - * generates a new EE_Transaction object and adds it to the $_transaction property. |
|
946 | - * |
|
947 | - * @access private |
|
948 | - * @return mixed EE_Transaction|NULL |
|
949 | - */ |
|
950 | - private function _initialize_transaction() |
|
951 | - { |
|
952 | - try { |
|
953 | - // ensure cart totals have been calculated |
|
954 | - $this->checkout->cart->get_grand_total()->recalculate_total_including_taxes(); |
|
955 | - // grab the cart grand total |
|
956 | - $cart_total = $this->checkout->cart->get_cart_grand_total(); |
|
957 | - // create new TXN |
|
958 | - $transaction = EE_Transaction::new_instance( |
|
959 | - array( |
|
960 | - 'TXN_reg_steps' => $this->checkout->initialize_txn_reg_steps_array(), |
|
961 | - 'TXN_total' => $cart_total > 0 ? $cart_total : 0, |
|
962 | - 'TXN_paid' => 0, |
|
963 | - 'STS_ID' => EEM_Transaction::failed_status_code, |
|
964 | - ) |
|
965 | - ); |
|
966 | - // save it so that we have an ID for other objects to use |
|
967 | - $transaction->save(); |
|
968 | - // set cron job for following up on TXNs after their session has expired |
|
969 | - EE_Cron_Tasks::schedule_expired_transaction_check( |
|
970 | - EE_Registry::instance()->SSN->expiration() + 1, |
|
971 | - $transaction->ID() |
|
972 | - ); |
|
973 | - return $transaction; |
|
974 | - } catch (Exception $e) { |
|
975 | - EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
976 | - } |
|
977 | - return null; |
|
978 | - } |
|
979 | - |
|
980 | - |
|
981 | - |
|
982 | - /** |
|
983 | - * _get_registrations |
|
984 | - * |
|
985 | - * @access private |
|
986 | - * @param EE_Transaction $transaction |
|
987 | - * @return void |
|
988 | - * @throws \EventEspresso\core\exceptions\InvalidEntityException |
|
989 | - * @throws \EE_Error |
|
990 | - */ |
|
991 | - private function _get_registrations(EE_Transaction $transaction) |
|
992 | - { |
|
993 | - // first step: grab the registrants { : o |
|
994 | - $registrations = $transaction->registrations($this->checkout->reg_cache_where_params, true); |
|
995 | - // verify registrations have been set |
|
996 | - if (empty($registrations)) { |
|
997 | - // if no cached registrations, then check the db |
|
998 | - $registrations = $transaction->registrations($this->checkout->reg_cache_where_params, false); |
|
999 | - // still nothing ? well as long as this isn't a revisit |
|
1000 | - if (empty($registrations) && ! $this->checkout->revisit) { |
|
1001 | - // generate new registrations from scratch |
|
1002 | - $registrations = $this->_initialize_registrations($transaction); |
|
1003 | - } |
|
1004 | - } |
|
1005 | - // sort by their original registration order |
|
1006 | - usort($registrations, array('EED_Single_Page_Checkout', 'sort_registrations_by_REG_count')); |
|
1007 | - // then loop thru the array |
|
1008 | - foreach ($registrations as $registration) { |
|
1009 | - // verify each registration |
|
1010 | - if ($registration instanceof EE_Registration) { |
|
1011 | - // we display all attendee info for the primary registrant |
|
1012 | - if ($this->checkout->reg_url_link === $registration->reg_url_link() |
|
1013 | - && $registration->is_primary_registrant() |
|
1014 | - ) { |
|
1015 | - $this->checkout->primary_revisit = true; |
|
1016 | - break; |
|
1017 | - } else if ($this->checkout->revisit |
|
1018 | - && $this->checkout->reg_url_link !== $registration->reg_url_link() |
|
1019 | - ) { |
|
1020 | - // but hide info if it doesn't belong to you |
|
1021 | - $transaction->clear_cache('Registration', $registration->ID()); |
|
1022 | - } |
|
1023 | - $this->checkout->set_reg_status_updated($registration->ID(), false); |
|
1024 | - } |
|
1025 | - } |
|
1026 | - } |
|
1027 | - |
|
1028 | - |
|
1029 | - |
|
1030 | - /** |
|
1031 | - * adds related EE_Registration objects for each ticket in the cart to the current EE_Transaction object |
|
1032 | - * |
|
1033 | - * @access private |
|
1034 | - * @param EE_Transaction $transaction |
|
1035 | - * @return array |
|
1036 | - * @throws \EventEspresso\core\exceptions\InvalidEntityException |
|
1037 | - * @throws \EE_Error |
|
1038 | - */ |
|
1039 | - private function _initialize_registrations(EE_Transaction $transaction) |
|
1040 | - { |
|
1041 | - $att_nmbr = 0; |
|
1042 | - $registrations = array(); |
|
1043 | - if ($transaction instanceof EE_Transaction) { |
|
1044 | - /** @type EE_Registration_Processor $registration_processor */ |
|
1045 | - $registration_processor = EE_Registry::instance()->load_class('Registration_Processor'); |
|
1046 | - $this->checkout->total_ticket_count = $this->checkout->cart->all_ticket_quantity_count(); |
|
1047 | - // now let's add the cart items to the $transaction |
|
1048 | - foreach ($this->checkout->cart->get_tickets() as $line_item) { |
|
1049 | - //do the following for each ticket of this type they selected |
|
1050 | - for ($x = 1; $x <= $line_item->quantity(); $x++) { |
|
1051 | - $att_nmbr++; |
|
1052 | - /** @var EventEspresso\core\services\commands\registration\CreateRegistrationCommand $CreateRegistrationCommand */ |
|
1053 | - $CreateRegistrationCommand = EE_Registry::instance() |
|
1054 | - ->create( |
|
1055 | - 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand', |
|
1056 | - array( |
|
1057 | - $transaction, |
|
1058 | - $line_item, |
|
1059 | - $att_nmbr, |
|
1060 | - $this->checkout->total_ticket_count, |
|
1061 | - ) |
|
1062 | - ); |
|
1063 | - // override capabilities for frontend registrations |
|
1064 | - if ( ! is_admin()) { |
|
1065 | - $CreateRegistrationCommand->setCapCheck( |
|
1066 | - new PublicCapabilities('', 'create_new_registration') |
|
1067 | - ); |
|
1068 | - } |
|
1069 | - $registration = EE_Registry::instance()->BUS->execute($CreateRegistrationCommand); |
|
1070 | - if ( ! $registration instanceof EE_Registration) { |
|
1071 | - throw new InvalidEntityException($registration, 'EE_Registration'); |
|
1072 | - } |
|
1073 | - $registrations[ $registration->ID() ] = $registration; |
|
1074 | - } |
|
1075 | - } |
|
1076 | - $registration_processor->fix_reg_final_price_rounding_issue($transaction); |
|
1077 | - } |
|
1078 | - return $registrations; |
|
1079 | - } |
|
1080 | - |
|
1081 | - |
|
1082 | - |
|
1083 | - /** |
|
1084 | - * sorts registrations by REG_count |
|
1085 | - * |
|
1086 | - * @access public |
|
1087 | - * @param EE_Registration $reg_A |
|
1088 | - * @param EE_Registration $reg_B |
|
1089 | - * @return int |
|
1090 | - */ |
|
1091 | - public static function sort_registrations_by_REG_count(EE_Registration $reg_A, EE_Registration $reg_B) |
|
1092 | - { |
|
1093 | - // this shouldn't ever happen within the same TXN, but oh well |
|
1094 | - if ($reg_A->count() === $reg_B->count()) { |
|
1095 | - return 0; |
|
1096 | - } |
|
1097 | - return ($reg_A->count() > $reg_B->count()) ? 1 : -1; |
|
1098 | - } |
|
1099 | - |
|
1100 | - |
|
1101 | - |
|
1102 | - /** |
|
1103 | - * _final_verifications |
|
1104 | - * just makes sure that everything is set up correctly before proceeding |
|
1105 | - * |
|
1106 | - * @access private |
|
1107 | - * @return bool |
|
1108 | - * @throws \EE_Error |
|
1109 | - */ |
|
1110 | - private function _final_verifications() |
|
1111 | - { |
|
1112 | - // filter checkout |
|
1113 | - $this->checkout = apply_filters('FHEE__EED_Single_Page_Checkout___final_verifications__checkout', $this->checkout); |
|
1114 | - //verify that current step is still set correctly |
|
1115 | - if ( ! $this->checkout->current_step instanceof EE_SPCO_Reg_Step) { |
|
1116 | - EE_Error::add_error( |
|
1117 | - __('We\'re sorry but the registration process can not proceed because one or more registration steps were not setup correctly. Please refresh the page and try again or contact support.', 'event_espresso'), |
|
1118 | - __FILE__, |
|
1119 | - __FUNCTION__, |
|
1120 | - __LINE__ |
|
1121 | - ); |
|
1122 | - return false; |
|
1123 | - } |
|
1124 | - // if returning to SPCO, then verify that primary registrant is set |
|
1125 | - if ( ! empty($this->checkout->reg_url_link)) { |
|
1126 | - $valid_registrant = $this->checkout->transaction->primary_registration(); |
|
1127 | - if ( ! $valid_registrant instanceof EE_Registration) { |
|
1128 | - EE_Error::add_error( |
|
1129 | - __('We\'re sorry but there appears to be an error with the "reg_url_link" or the primary registrant for this transaction. Please refresh the page and try again or contact support.', 'event_espresso'), |
|
1130 | - __FILE__, |
|
1131 | - __FUNCTION__, |
|
1132 | - __LINE__ |
|
1133 | - ); |
|
1134 | - return false; |
|
1135 | - } |
|
1136 | - $valid_registrant = null; |
|
1137 | - foreach ($this->checkout->transaction->registrations($this->checkout->reg_cache_where_params) as $registration) { |
|
1138 | - if ( |
|
1139 | - $registration instanceof EE_Registration |
|
1140 | - && $registration->reg_url_link() === $this->checkout->reg_url_link |
|
1141 | - ) { |
|
1142 | - $valid_registrant = $registration; |
|
1143 | - } |
|
1144 | - } |
|
1145 | - if ( ! $valid_registrant instanceof EE_Registration) { |
|
1146 | - // hmmm... maybe we have the wrong session because the user is opening multiple tabs ? |
|
1147 | - if (EED_Single_Page_Checkout::$_checkout_verified) { |
|
1148 | - // clear the session, mark the checkout as unverified, and try again |
|
1149 | - EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__); |
|
1150 | - EED_Single_Page_Checkout::$_initialized = false; |
|
1151 | - EED_Single_Page_Checkout::$_checkout_verified = false; |
|
1152 | - $this->_initialize(); |
|
1153 | - EE_Error::reset_notices(); |
|
1154 | - return false; |
|
1155 | - } |
|
1156 | - EE_Error::add_error( |
|
1157 | - __('We\'re sorry but there appears to be an error with the "reg_url_link" or the transaction itself. Please refresh the page and try again or contact support.', 'event_espresso'), |
|
1158 | - __FILE__, |
|
1159 | - __FUNCTION__, |
|
1160 | - __LINE__ |
|
1161 | - ); |
|
1162 | - return false; |
|
1163 | - } |
|
1164 | - } |
|
1165 | - // now that things have been kinda sufficiently verified, |
|
1166 | - // let's add the checkout to the session so that it's available to other systems |
|
1167 | - EE_Registry::instance()->SSN->set_checkout($this->checkout); |
|
1168 | - return true; |
|
1169 | - } |
|
1170 | - |
|
1171 | - |
|
1172 | - |
|
1173 | - /** |
|
1174 | - * _initialize_reg_steps |
|
1175 | - * first makes sure that EE_Transaction_Processor::set_reg_step_initiated() is called as required |
|
1176 | - * then loops thru all of the active reg steps and calls the initialize_reg_step() method |
|
1177 | - * |
|
1178 | - * @access private |
|
1179 | - * @param bool $reinitializing |
|
1180 | - * @throws \EE_Error |
|
1181 | - */ |
|
1182 | - private function _initialize_reg_steps($reinitializing = false) |
|
1183 | - { |
|
1184 | - $this->checkout->set_reg_step_initiated($this->checkout->current_step); |
|
1185 | - // loop thru all steps to call their individual "initialize" methods and set i18n strings for JS |
|
1186 | - foreach ($this->checkout->reg_steps as $reg_step) { |
|
1187 | - if ( ! $reg_step->initialize_reg_step()) { |
|
1188 | - // if not initialized then maybe this step is being removed... |
|
1189 | - if ( ! $reinitializing && $reg_step->is_current_step()) { |
|
1190 | - // if it was the current step, then we need to start over here |
|
1191 | - $this->_initialize_reg_steps(true); |
|
1192 | - return; |
|
1193 | - } |
|
1194 | - continue; |
|
1195 | - } |
|
1196 | - // add css and JS for current step |
|
1197 | - $reg_step->enqueue_styles_and_scripts(); |
|
1198 | - // i18n |
|
1199 | - $reg_step->translate_js_strings(); |
|
1200 | - if ($reg_step->is_current_step()) { |
|
1201 | - // the text that appears on the reg step form submit button |
|
1202 | - $reg_step->set_submit_button_text(); |
|
1203 | - } |
|
1204 | - } |
|
1205 | - // dynamically creates hook point like: AHEE__Single_Page_Checkout___initialize_reg_step__attendee_information |
|
1206 | - do_action("AHEE__Single_Page_Checkout___initialize_reg_step__{$this->checkout->current_step->slug()}", $this->checkout->current_step); |
|
1207 | - } |
|
1208 | - |
|
1209 | - |
|
1210 | - |
|
1211 | - /** |
|
1212 | - * _check_form_submission |
|
1213 | - * |
|
1214 | - * @access private |
|
1215 | - * @return boolean |
|
1216 | - */ |
|
1217 | - private function _check_form_submission() |
|
1218 | - { |
|
1219 | - //does this request require the reg form to be generated ? |
|
1220 | - if ($this->checkout->generate_reg_form) { |
|
1221 | - // ever heard that song by Blue Rodeo ? |
|
1222 | - try { |
|
1223 | - $this->checkout->current_step->reg_form = $this->checkout->current_step->generate_reg_form(); |
|
1224 | - // if not displaying a form, then check for form submission |
|
1225 | - if ( |
|
1226 | - $this->checkout->process_form_submission |
|
1227 | - && $this->checkout->current_step->reg_form->was_submitted() |
|
1228 | - ) { |
|
1229 | - // clear out any old data in case this step is being run again |
|
1230 | - $this->checkout->current_step->set_valid_data(array()); |
|
1231 | - // capture submitted form data |
|
1232 | - $this->checkout->current_step->reg_form->receive_form_submission( |
|
1233 | - apply_filters( |
|
1234 | - 'FHEE__Single_Page_Checkout___check_form_submission__request_params', |
|
1235 | - EE_Registry::instance()->REQ->params(), |
|
1236 | - $this->checkout |
|
1237 | - ) |
|
1238 | - ); |
|
1239 | - // validate submitted form data |
|
1240 | - if ( ! $this->checkout->continue_reg || ! $this->checkout->current_step->reg_form->is_valid()) { |
|
1241 | - // thou shall not pass !!! |
|
1242 | - $this->checkout->continue_reg = false; |
|
1243 | - // any form validation errors? |
|
1244 | - if ($this->checkout->current_step->reg_form->submission_error_message() !== '') { |
|
1245 | - $submission_error_messages = array(); |
|
1246 | - // bad, bad, bad registrant |
|
1247 | - foreach ($this->checkout->current_step->reg_form->get_validation_errors_accumulated() as $validation_error) { |
|
1248 | - if ($validation_error instanceof EE_Validation_Error) { |
|
1249 | - $submission_error_messages[] = sprintf( |
|
1250 | - __('%s : %s', 'event_espresso'), |
|
1251 | - $validation_error->get_form_section()->html_label_text(), |
|
1252 | - $validation_error->getMessage() |
|
1253 | - ); |
|
1254 | - } |
|
1255 | - } |
|
1256 | - EE_Error::add_error(implode('<br />', $submission_error_messages), __FILE__, __FUNCTION__, __LINE__); |
|
1257 | - } |
|
1258 | - // well not really... what will happen is we'll just get redirected back to redo the current step |
|
1259 | - $this->go_to_next_step(); |
|
1260 | - return false; |
|
1261 | - } |
|
1262 | - } |
|
1263 | - } catch (EE_Error $e) { |
|
1264 | - $e->get_error(); |
|
1265 | - } |
|
1266 | - } |
|
1267 | - return true; |
|
1268 | - } |
|
1269 | - |
|
1270 | - |
|
1271 | - |
|
1272 | - /** |
|
1273 | - * _process_action |
|
1274 | - * |
|
1275 | - * @access private |
|
1276 | - * @return void |
|
1277 | - * @throws \EE_Error |
|
1278 | - */ |
|
1279 | - private function _process_form_action() |
|
1280 | - { |
|
1281 | - // what cha wanna do? |
|
1282 | - switch ($this->checkout->action) { |
|
1283 | - // AJAX next step reg form |
|
1284 | - case 'display_spco_reg_step' : |
|
1285 | - $this->checkout->redirect = false; |
|
1286 | - if (EE_Registry::instance()->REQ->ajax) { |
|
1287 | - $this->checkout->json_response->set_reg_step_html($this->checkout->current_step->display_reg_form()); |
|
1288 | - } |
|
1289 | - break; |
|
1290 | - default : |
|
1291 | - // meh... do one of those other steps first |
|
1292 | - if ( ! empty($this->checkout->action) && is_callable(array($this->checkout->current_step, $this->checkout->action))) { |
|
1293 | - // dynamically creates hook point like: AHEE__Single_Page_Checkout__before_attendee_information__process_reg_step |
|
1294 | - do_action("AHEE__Single_Page_Checkout__before_{$this->checkout->current_step->slug()}__{$this->checkout->action}", $this->checkout->current_step); |
|
1295 | - // call action on current step |
|
1296 | - if (call_user_func(array($this->checkout->current_step, $this->checkout->action))) { |
|
1297 | - // good registrant, you get to proceed |
|
1298 | - if ( |
|
1299 | - $this->checkout->current_step->success_message() !== '' |
|
1300 | - && apply_filters( |
|
1301 | - 'FHEE__Single_Page_Checkout___process_form_action__display_success', |
|
1302 | - false |
|
1303 | - ) |
|
1304 | - ) { |
|
1305 | - EE_Error::add_success( |
|
1306 | - $this->checkout->current_step->success_message() |
|
1307 | - . '<br />' . $this->checkout->next_step->_instructions() |
|
1308 | - ); |
|
1309 | - } |
|
1310 | - // pack it up, pack it in... |
|
1311 | - $this->_setup_redirect(); |
|
1312 | - } |
|
1313 | - // dynamically creates hook point like: AHEE__Single_Page_Checkout__after_payment_options__process_reg_step |
|
1314 | - do_action("AHEE__Single_Page_Checkout__after_{$this->checkout->current_step->slug()}__{$this->checkout->action}", $this->checkout->current_step); |
|
1315 | - } else { |
|
1316 | - EE_Error::add_error( |
|
1317 | - sprintf( |
|
1318 | - __('The requested form action "%s" does not exist for the current "%s" registration step.', 'event_espresso'), |
|
1319 | - $this->checkout->action, |
|
1320 | - $this->checkout->current_step->name() |
|
1321 | - ), |
|
1322 | - __FILE__, |
|
1323 | - __FUNCTION__, |
|
1324 | - __LINE__ |
|
1325 | - ); |
|
1326 | - } |
|
1327 | - // end default |
|
1328 | - } |
|
1329 | - // store our progress so far |
|
1330 | - $this->checkout->stash_transaction_and_checkout(); |
|
1331 | - // advance to the next step! If you pass GO, collect $200 |
|
1332 | - $this->go_to_next_step(); |
|
1333 | - } |
|
1334 | - |
|
1335 | - |
|
1336 | - |
|
1337 | - /** |
|
1338 | - * add_styles_and_scripts |
|
1339 | - * |
|
1340 | - * @access public |
|
1341 | - * @return void |
|
1342 | - */ |
|
1343 | - public function add_styles_and_scripts() |
|
1344 | - { |
|
1345 | - // i18n |
|
1346 | - $this->translate_js_strings(); |
|
1347 | - if ($this->checkout->admin_request) { |
|
1348 | - add_action('admin_enqueue_scripts', array($this, 'enqueue_styles_and_scripts'), 10); |
|
1349 | - } else { |
|
1350 | - add_action('wp_enqueue_scripts', array($this, 'enqueue_styles_and_scripts'), 10); |
|
1351 | - } |
|
1352 | - } |
|
1353 | - |
|
1354 | - |
|
1355 | - |
|
1356 | - /** |
|
1357 | - * translate_js_strings |
|
1358 | - * |
|
1359 | - * @access public |
|
1360 | - * @return void |
|
1361 | - */ |
|
1362 | - public function translate_js_strings() |
|
1363 | - { |
|
1364 | - EE_Registry::$i18n_js_strings['revisit'] = $this->checkout->revisit; |
|
1365 | - EE_Registry::$i18n_js_strings['e_reg_url_link'] = $this->checkout->reg_url_link; |
|
1366 | - EE_Registry::$i18n_js_strings['server_error'] = __('An unknown error occurred on the server while attempting to process your request. Please refresh the page and try again or contact support.', 'event_espresso'); |
|
1367 | - EE_Registry::$i18n_js_strings['invalid_json_response'] = __('An invalid response was returned from the server while attempting to process your request. Please refresh the page and try again or contact support.', 'event_espresso'); |
|
1368 | - EE_Registry::$i18n_js_strings['validation_error'] = __('There appears to be a problem with the form validation configuration! Please check the admin settings or contact support.', 'event_espresso'); |
|
1369 | - EE_Registry::$i18n_js_strings['invalid_payment_method'] = __('There appears to be a problem with the payment method configuration! Please refresh the page and try again or contact support.', 'event_espresso'); |
|
1370 | - EE_Registry::$i18n_js_strings['reg_step_error'] = __('This registration step could not be completed. Please refresh the page and try again.', 'event_espresso'); |
|
1371 | - EE_Registry::$i18n_js_strings['invalid_coupon'] = __('We\'re sorry but that coupon code does not appear to be valid. If this is incorrect, please contact the site administrator.', 'event_espresso'); |
|
1372 | - EE_Registry::$i18n_js_strings['process_registration'] = sprintf( |
|
1373 | - __('Please wait while we process your registration.%sDo not refresh the page or navigate away while this is happening.%sThank you for your patience.', 'event_espresso'), |
|
1374 | - '<br/>', |
|
1375 | - '<br/>' |
|
1376 | - ); |
|
1377 | - EE_Registry::$i18n_js_strings['language'] = get_bloginfo('language'); |
|
1378 | - EE_Registry::$i18n_js_strings['EESID'] = EE_Registry::instance()->SSN->id(); |
|
1379 | - EE_Registry::$i18n_js_strings['currency'] = EE_Registry::instance()->CFG->currency; |
|
1380 | - EE_Registry::$i18n_js_strings['datepicker_yearRange'] = '-150:+20'; |
|
1381 | - EE_Registry::$i18n_js_strings['timer_years'] = __('years', 'event_espresso'); |
|
1382 | - EE_Registry::$i18n_js_strings['timer_months'] = __('months', 'event_espresso'); |
|
1383 | - EE_Registry::$i18n_js_strings['timer_weeks'] = __('weeks', 'event_espresso'); |
|
1384 | - EE_Registry::$i18n_js_strings['timer_days'] = __('days', 'event_espresso'); |
|
1385 | - EE_Registry::$i18n_js_strings['timer_hours'] = __('hours', 'event_espresso'); |
|
1386 | - EE_Registry::$i18n_js_strings['timer_minutes'] = __('minutes', 'event_espresso'); |
|
1387 | - EE_Registry::$i18n_js_strings['timer_seconds'] = __('seconds', 'event_espresso'); |
|
1388 | - EE_Registry::$i18n_js_strings['timer_year'] = __('year', 'event_espresso'); |
|
1389 | - EE_Registry::$i18n_js_strings['timer_month'] = __('month', 'event_espresso'); |
|
1390 | - EE_Registry::$i18n_js_strings['timer_week'] = __('week', 'event_espresso'); |
|
1391 | - EE_Registry::$i18n_js_strings['timer_day'] = __('day', 'event_espresso'); |
|
1392 | - EE_Registry::$i18n_js_strings['timer_hour'] = __('hour', 'event_espresso'); |
|
1393 | - EE_Registry::$i18n_js_strings['timer_minute'] = __('minute', 'event_espresso'); |
|
1394 | - EE_Registry::$i18n_js_strings['timer_second'] = __('second', 'event_espresso'); |
|
1395 | - EE_Registry::$i18n_js_strings['registration_expiration_notice'] = sprintf( |
|
1396 | - __( |
|
1397 | - '%1$sWe\'re sorry, but your registration time has expired.%2$s%3$s%4$sIf you still wish to complete your registration, please return to the %5$sEvent List%6$sEvent List%7$s and reselect your tickets if available. Please except our apologies for any inconvenience this may have caused.%8$s', |
|
1398 | - 'event_espresso' |
|
1399 | - ), |
|
1400 | - '<h4 class="important-notice">', |
|
1401 | - '</h4>', |
|
1402 | - '<br />', |
|
1403 | - '<p>', |
|
1404 | - '<a href="' . get_post_type_archive_link('espresso_events') . '" title="', |
|
1405 | - '">', |
|
1406 | - '</a>', |
|
1407 | - '</p>' |
|
1408 | - ); |
|
1409 | - EE_Registry::$i18n_js_strings['ajax_submit'] = apply_filters('FHEE__Single_Page_Checkout__translate_js_strings__ajax_submit', true); |
|
1410 | - EE_Registry::$i18n_js_strings['session_extension'] = absint( |
|
1411 | - apply_filters('FHEE__EE_Session__extend_expiration__seconds_added', 10 * MINUTE_IN_SECONDS) |
|
1412 | - ); |
|
1413 | - EE_Registry::$i18n_js_strings['session_expiration'] = gmdate( |
|
1414 | - 'M d, Y H:i:s', EE_Registry::instance()->SSN->expiration() + (get_option('gmt_offset') * HOUR_IN_SECONDS) |
|
1415 | - ); |
|
1416 | - } |
|
1417 | - |
|
1418 | - |
|
1419 | - |
|
1420 | - /** |
|
1421 | - * enqueue_styles_and_scripts |
|
1422 | - * |
|
1423 | - * @access public |
|
1424 | - * @return void |
|
1425 | - * @throws \EE_Error |
|
1426 | - */ |
|
1427 | - public function enqueue_styles_and_scripts() |
|
1428 | - { |
|
1429 | - // load css |
|
1430 | - wp_register_style('single_page_checkout', SPCO_CSS_URL . 'single_page_checkout.css', array(), EVENT_ESPRESSO_VERSION); |
|
1431 | - wp_enqueue_style('single_page_checkout'); |
|
1432 | - // load JS |
|
1433 | - wp_register_script('jquery_plugin', EE_THIRD_PARTY_URL . 'jquery .plugin.min.js', array('jquery'), '1.0.1', true); |
|
1434 | - wp_register_script('jquery_countdown', EE_THIRD_PARTY_URL . 'jquery .countdown.min.js', array('jquery_plugin'), '2.0.2', true); |
|
1435 | - wp_register_script('single_page_checkout', SPCO_JS_URL . 'single_page_checkout.js', array('espresso_core', 'underscore', 'ee_form_section_validation', 'jquery_countdown'), EVENT_ESPRESSO_VERSION, true); |
|
1436 | - if ($this->checkout->registration_form instanceof EE_Form_Section_Proper) { |
|
1437 | - $this->checkout->registration_form->enqueue_js(); |
|
1438 | - } |
|
1439 | - if ($this->checkout->current_step->reg_form instanceof EE_Form_Section_Proper) { |
|
1440 | - $this->checkout->current_step->reg_form->enqueue_js(); |
|
1441 | - } |
|
1442 | - wp_enqueue_script('single_page_checkout'); |
|
1443 | - /** |
|
1444 | - * global action hook for enqueueing styles and scripts with |
|
1445 | - * spco calls. |
|
1446 | - */ |
|
1447 | - do_action('AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts', $this); |
|
1448 | - /** |
|
1449 | - * dynamic action hook for enqueueing styles and scripts with spco calls. |
|
1450 | - * The hook will end up being something like AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__attendee_information |
|
1451 | - */ |
|
1452 | - do_action('AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__' . $this->checkout->current_step->slug(), $this); |
|
1453 | - } |
|
1454 | - |
|
1455 | - |
|
1456 | - |
|
1457 | - /** |
|
1458 | - * display the Registration Single Page Checkout Form |
|
1459 | - * |
|
1460 | - * @access private |
|
1461 | - * @return void |
|
1462 | - * @throws \EE_Error |
|
1463 | - */ |
|
1464 | - private function _display_spco_reg_form() |
|
1465 | - { |
|
1466 | - // if registering via the admin, just display the reg form for the current step |
|
1467 | - if ($this->checkout->admin_request) { |
|
1468 | - EE_Registry::instance()->REQ->add_output($this->checkout->current_step->display_reg_form()); |
|
1469 | - } else { |
|
1470 | - // add powered by EE msg |
|
1471 | - add_action('AHEE__SPCO__reg_form_footer', array('EED_Single_Page_Checkout', 'display_registration_footer')); |
|
1472 | - $empty_cart = count($this->checkout->transaction->registrations($this->checkout->reg_cache_where_params)) < 1 |
|
1473 | - ? true |
|
1474 | - : false; |
|
1475 | - EE_Registry::$i18n_js_strings['empty_cart'] = $empty_cart; |
|
1476 | - $cookies_not_set_msg = ''; |
|
1477 | - if ($empty_cart && ! isset($_COOKIE['ee_cookie_test'])) { |
|
1478 | - $cookies_not_set_msg = apply_filters( |
|
1479 | - 'FHEE__Single_Page_Checkout__display_spco_reg_form__cookies_not_set_msg', |
|
1480 | - sprintf( |
|
1481 | - __( |
|
1482 | - '%1$s%3$sIt appears your browser is not currently set to accept Cookies%4$s%5$sIn order to register for events, you need to enable cookies.%7$sIf you require assistance, then click the following link to learn how to %8$senable cookies%9$s%6$s%2$s', |
|
1483 | - 'event_espresso' |
|
1484 | - ), |
|
1485 | - '<div class="ee-attention">', |
|
1486 | - '</div>', |
|
1487 | - '<h6 class="important-notice">', |
|
1488 | - '</h6>', |
|
1489 | - '<p>', |
|
1490 | - '</p>', |
|
1491 | - '<br />', |
|
1492 | - '<a href="http://www.whatarecookies.com/enable.asp" target="_blank">', |
|
1493 | - '</a>' |
|
1494 | - ) |
|
1495 | - ); |
|
1496 | - } |
|
1497 | - $this->checkout->registration_form = new EE_Form_Section_Proper( |
|
1498 | - array( |
|
1499 | - 'name' => 'single-page-checkout', |
|
1500 | - 'html_id' => 'ee-single-page-checkout-dv', |
|
1501 | - 'layout_strategy' => |
|
1502 | - new EE_Template_Layout( |
|
1503 | - array( |
|
1504 | - 'layout_template_file' => SPCO_TEMPLATES_PATH . 'registration_page_wrapper.template.php', |
|
1505 | - 'template_args' => array( |
|
1506 | - 'empty_cart' => $empty_cart, |
|
1507 | - 'revisit' => $this->checkout->revisit, |
|
1508 | - 'reg_steps' => $this->checkout->reg_steps, |
|
1509 | - 'next_step' => $this->checkout->next_step instanceof EE_SPCO_Reg_Step |
|
1510 | - ? $this->checkout->next_step->slug() |
|
1511 | - : '', |
|
1512 | - 'cancel_page_url' => $this->checkout->cancel_page_url, |
|
1513 | - 'empty_msg' => apply_filters( |
|
1514 | - 'FHEE__Single_Page_Checkout__display_spco_reg_form__empty_msg', |
|
1515 | - sprintf( |
|
1516 | - __('You need to %1$sReturn to Events list%2$sselect at least one event%3$s before you can proceed with the registration process.', |
|
1517 | - 'event_espresso'), |
|
1518 | - '<a href="' . get_post_type_archive_link('espresso_events') . '" title="', |
|
1519 | - '">', |
|
1520 | - '</a>' |
|
1521 | - ) |
|
1522 | - ), |
|
1523 | - 'cookies_not_set_msg' => $cookies_not_set_msg, |
|
1524 | - 'registration_time_limit' => $this->checkout->get_registration_time_limit(), |
|
1525 | - 'session_expiration' => gmdate( |
|
1526 | - 'M d, Y H:i:s', |
|
1527 | - EE_Registry::instance()->SSN->expiration() |
|
1528 | - + (get_option('gmt_offset') * HOUR_IN_SECONDS) |
|
1529 | - ), |
|
1530 | - ), |
|
1531 | - ) |
|
1532 | - ), |
|
1533 | - ) |
|
1534 | - ); |
|
1535 | - // load template and add to output sent that gets filtered into the_content() |
|
1536 | - EE_Registry::instance()->REQ->add_output($this->checkout->registration_form->get_html()); |
|
1537 | - } |
|
1538 | - } |
|
1539 | - |
|
1540 | - |
|
1541 | - |
|
1542 | - /** |
|
1543 | - * add_extra_finalize_registration_inputs |
|
1544 | - * |
|
1545 | - * @access public |
|
1546 | - * @param $next_step |
|
1547 | - * @internal param string $label |
|
1548 | - * @return void |
|
1549 | - */ |
|
1550 | - public function add_extra_finalize_registration_inputs($next_step) |
|
1551 | - { |
|
1552 | - if ($next_step === 'finalize_registration') { |
|
1553 | - echo '<div id="spco-extra-finalize_registration-inputs-dv"></div>'; |
|
1554 | - } |
|
1555 | - } |
|
1556 | - |
|
1557 | - |
|
1558 | - |
|
1559 | - /** |
|
1560 | - * display_registration_footer |
|
1561 | - * |
|
1562 | - * @access public |
|
1563 | - * @return string |
|
1564 | - */ |
|
1565 | - public static function display_registration_footer() |
|
1566 | - { |
|
1567 | - if ( |
|
1568 | - apply_filters( |
|
1569 | - 'FHEE__EE_Front__Controller__show_reg_footer', |
|
1570 | - EE_Registry::instance()->CFG->admin->show_reg_footer |
|
1571 | - ) |
|
1572 | - ) { |
|
1573 | - add_filter( |
|
1574 | - 'FHEE__EEH_Template__powered_by_event_espresso__url', |
|
1575 | - function ($url) { |
|
1576 | - return apply_filters('FHEE__EE_Front_Controller__registration_footer__url', $url); |
|
1577 | - } |
|
1578 | - ); |
|
1579 | - echo apply_filters( |
|
1580 | - 'FHEE__EE_Front_Controller__display_registration_footer', |
|
1581 | - \EEH_Template::powered_by_event_espresso( |
|
1582 | - '', |
|
1583 | - 'espresso-registration-footer-dv', |
|
1584 | - array('utm_content' => 'registration_checkout') |
|
1585 | - ) |
|
1586 | - ); |
|
1587 | - } |
|
1588 | - return ''; |
|
1589 | - } |
|
1590 | - |
|
1591 | - |
|
1592 | - |
|
1593 | - /** |
|
1594 | - * unlock_transaction |
|
1595 | - * |
|
1596 | - * @access public |
|
1597 | - * @return void |
|
1598 | - * @throws \EE_Error |
|
1599 | - */ |
|
1600 | - public function unlock_transaction() |
|
1601 | - { |
|
1602 | - if ($this->checkout->transaction instanceof EE_Transaction) { |
|
1603 | - $this->checkout->transaction->unlock(); |
|
1604 | - } |
|
1605 | - } |
|
1606 | - |
|
1607 | - |
|
1608 | - |
|
1609 | - /** |
|
1610 | - * _setup_redirect |
|
1611 | - * |
|
1612 | - * @access private |
|
1613 | - * @return void |
|
1614 | - */ |
|
1615 | - private function _setup_redirect() |
|
1616 | - { |
|
1617 | - if ($this->checkout->continue_reg && $this->checkout->next_step instanceof EE_SPCO_Reg_Step) { |
|
1618 | - $this->checkout->redirect = true; |
|
1619 | - if (empty($this->checkout->redirect_url)) { |
|
1620 | - $this->checkout->redirect_url = $this->checkout->next_step->reg_step_url(); |
|
1621 | - } |
|
1622 | - $this->checkout->redirect_url = apply_filters( |
|
1623 | - 'FHEE__EED_Single_Page_Checkout___setup_redirect__checkout_redirect_url', |
|
1624 | - $this->checkout->redirect_url, |
|
1625 | - $this->checkout |
|
1626 | - ); |
|
1627 | - } |
|
1628 | - } |
|
1629 | - |
|
1630 | - |
|
1631 | - |
|
1632 | - /** |
|
1633 | - * handle ajax message responses and redirects |
|
1634 | - * |
|
1635 | - * @access public |
|
1636 | - * @return void |
|
1637 | - * @throws \EE_Error |
|
1638 | - */ |
|
1639 | - public function go_to_next_step() |
|
1640 | - { |
|
1641 | - if (EE_Registry::instance()->REQ->ajax) { |
|
1642 | - // capture contents of output buffer we started earlier in the request, and insert into JSON response |
|
1643 | - $this->checkout->json_response->set_unexpected_errors(ob_get_clean()); |
|
1644 | - } |
|
1645 | - $this->unlock_transaction(); |
|
1646 | - // just return for these conditions |
|
1647 | - if ( |
|
1648 | - $this->checkout->admin_request |
|
1649 | - || $this->checkout->action === 'redirect_form' |
|
1650 | - || $this->checkout->action === 'update_checkout' |
|
1651 | - ) { |
|
1652 | - return; |
|
1653 | - } |
|
1654 | - // AJAX response |
|
1655 | - $this->_handle_json_response(); |
|
1656 | - // redirect to next step or the Thank You page |
|
1657 | - $this->_handle_html_redirects(); |
|
1658 | - // hmmm... must be something wrong, so let's just display the form again ! |
|
1659 | - $this->_display_spco_reg_form(); |
|
1660 | - } |
|
1661 | - |
|
1662 | - |
|
1663 | - |
|
1664 | - /** |
|
1665 | - * _handle_json_response |
|
1666 | - * |
|
1667 | - * @access protected |
|
1668 | - * @return void |
|
1669 | - */ |
|
1670 | - protected function _handle_json_response() |
|
1671 | - { |
|
1672 | - // if this is an ajax request |
|
1673 | - if (EE_Registry::instance()->REQ->ajax) { |
|
1674 | - // DEBUG LOG |
|
1675 | - //$this->checkout->log( |
|
1676 | - // __CLASS__, __FUNCTION__, __LINE__, |
|
1677 | - // array( |
|
1678 | - // 'json_response_redirect_url' => $this->checkout->json_response->redirect_url(), |
|
1679 | - // 'redirect' => $this->checkout->redirect, |
|
1680 | - // 'continue_reg' => $this->checkout->continue_reg, |
|
1681 | - // ) |
|
1682 | - //); |
|
1683 | - $this->checkout->json_response->set_registration_time_limit( |
|
1684 | - $this->checkout->get_registration_time_limit() |
|
1685 | - ); |
|
1686 | - $this->checkout->json_response->set_payment_amount($this->checkout->amount_owing); |
|
1687 | - // just send the ajax ( |
|
1688 | - $json_response = apply_filters( |
|
1689 | - 'FHEE__EE_Single_Page_Checkout__JSON_response', |
|
1690 | - $this->checkout->json_response |
|
1691 | - ); |
|
1692 | - echo $json_response; |
|
1693 | - exit(); |
|
1694 | - } |
|
1695 | - } |
|
1696 | - |
|
1697 | - |
|
1698 | - |
|
1699 | - /** |
|
1700 | - * _handle_redirects |
|
1701 | - * |
|
1702 | - * @access protected |
|
1703 | - * @return void |
|
1704 | - */ |
|
1705 | - protected function _handle_html_redirects() |
|
1706 | - { |
|
1707 | - // going somewhere ? |
|
1708 | - if ($this->checkout->redirect && ! empty($this->checkout->redirect_url)) { |
|
1709 | - // store notices in a transient |
|
1710 | - EE_Error::get_notices(false, true, true); |
|
1711 | - // DEBUG LOG |
|
1712 | - //$this->checkout->log( |
|
1713 | - // __CLASS__, __FUNCTION__, __LINE__, |
|
1714 | - // array( |
|
1715 | - // 'headers_sent' => headers_sent(), |
|
1716 | - // 'redirect_url' => $this->checkout->redirect_url, |
|
1717 | - // 'headers_list' => headers_list(), |
|
1718 | - // ) |
|
1719 | - //); |
|
1720 | - wp_safe_redirect($this->checkout->redirect_url); |
|
1721 | - exit(); |
|
1722 | - } |
|
1723 | - } |
|
1724 | - |
|
1725 | - |
|
1726 | - |
|
1727 | - /** |
|
1728 | - * set_checkout_anchor |
|
1729 | - * |
|
1730 | - * @access public |
|
1731 | - * @return void |
|
1732 | - */ |
|
1733 | - public function set_checkout_anchor() |
|
1734 | - { |
|
1735 | - echo '<a id="checkout" style="float: left; margin-left: -999em;"></a>'; |
|
1736 | - } |
|
20 | + /** |
|
21 | + * $_initialized - has the SPCO controller already been initialized ? |
|
22 | + * |
|
23 | + * @access private |
|
24 | + * @var bool $_initialized |
|
25 | + */ |
|
26 | + private static $_initialized = false; |
|
27 | + |
|
28 | + |
|
29 | + /** |
|
30 | + * $_checkout_verified - is the EE_Checkout verified as correct for this request ? |
|
31 | + * |
|
32 | + * @access private |
|
33 | + * @var bool $_valid_checkout |
|
34 | + */ |
|
35 | + private static $_checkout_verified = true; |
|
36 | + |
|
37 | + /** |
|
38 | + * $_reg_steps_array - holds initial array of reg steps |
|
39 | + * |
|
40 | + * @access private |
|
41 | + * @var array $_reg_steps_array |
|
42 | + */ |
|
43 | + private static $_reg_steps_array = array(); |
|
44 | + |
|
45 | + /** |
|
46 | + * $checkout - EE_Checkout object for handling the properties of the current checkout process |
|
47 | + * |
|
48 | + * @access public |
|
49 | + * @var EE_Checkout $checkout |
|
50 | + */ |
|
51 | + public $checkout; |
|
52 | + |
|
53 | + |
|
54 | + |
|
55 | + /** |
|
56 | + * @return EED_Single_Page_Checkout |
|
57 | + */ |
|
58 | + public static function instance() |
|
59 | + { |
|
60 | + add_filter('EED_Single_Page_Checkout__SPCO_active', '__return_true'); |
|
61 | + return parent::get_instance(__CLASS__); |
|
62 | + } |
|
63 | + |
|
64 | + |
|
65 | + |
|
66 | + /** |
|
67 | + * @return EE_CART |
|
68 | + */ |
|
69 | + public function cart() |
|
70 | + { |
|
71 | + return $this->checkout->cart; |
|
72 | + } |
|
73 | + |
|
74 | + |
|
75 | + |
|
76 | + /** |
|
77 | + * @return EE_Transaction |
|
78 | + */ |
|
79 | + public function transaction() |
|
80 | + { |
|
81 | + return $this->checkout->transaction; |
|
82 | + } |
|
83 | + |
|
84 | + |
|
85 | + |
|
86 | + /** |
|
87 | + * set_hooks - for hooking into EE Core, other modules, etc |
|
88 | + * |
|
89 | + * @access public |
|
90 | + * @return void |
|
91 | + * @throws \EE_Error |
|
92 | + */ |
|
93 | + public static function set_hooks() |
|
94 | + { |
|
95 | + EED_Single_Page_Checkout::set_definitions(); |
|
96 | + } |
|
97 | + |
|
98 | + |
|
99 | + |
|
100 | + /** |
|
101 | + * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
102 | + * |
|
103 | + * @access public |
|
104 | + * @return void |
|
105 | + * @throws \EE_Error |
|
106 | + */ |
|
107 | + public static function set_hooks_admin() |
|
108 | + { |
|
109 | + EED_Single_Page_Checkout::set_definitions(); |
|
110 | + if ( ! (defined('DOING_AJAX') && DOING_AJAX)) { |
|
111 | + return; |
|
112 | + } |
|
113 | + // going to start an output buffer in case anything gets accidentally output that might disrupt our JSON response |
|
114 | + ob_start(); |
|
115 | + EED_Single_Page_Checkout::load_request_handler(); |
|
116 | + EED_Single_Page_Checkout::load_reg_steps(); |
|
117 | + // set ajax hooks |
|
118 | + add_action('wp_ajax_process_reg_step', array('EED_Single_Page_Checkout', 'process_reg_step')); |
|
119 | + add_action('wp_ajax_nopriv_process_reg_step', array('EED_Single_Page_Checkout', 'process_reg_step')); |
|
120 | + add_action('wp_ajax_display_spco_reg_step', array('EED_Single_Page_Checkout', 'display_reg_step')); |
|
121 | + add_action('wp_ajax_nopriv_display_spco_reg_step', array('EED_Single_Page_Checkout', 'display_reg_step')); |
|
122 | + add_action('wp_ajax_update_reg_step', array('EED_Single_Page_Checkout', 'update_reg_step')); |
|
123 | + add_action('wp_ajax_nopriv_update_reg_step', array('EED_Single_Page_Checkout', 'update_reg_step')); |
|
124 | + } |
|
125 | + |
|
126 | + |
|
127 | + |
|
128 | + /** |
|
129 | + * process ajax request |
|
130 | + * |
|
131 | + * @param string $ajax_action |
|
132 | + * @throws \EE_Error |
|
133 | + */ |
|
134 | + public static function process_ajax_request($ajax_action) |
|
135 | + { |
|
136 | + EE_Registry::instance()->REQ->set('action', $ajax_action); |
|
137 | + EED_Single_Page_Checkout::instance()->_initialize(); |
|
138 | + } |
|
139 | + |
|
140 | + |
|
141 | + |
|
142 | + /** |
|
143 | + * ajax display registration step |
|
144 | + * |
|
145 | + * @throws \EE_Error |
|
146 | + */ |
|
147 | + public static function display_reg_step() |
|
148 | + { |
|
149 | + EED_Single_Page_Checkout::process_ajax_request('display_spco_reg_step'); |
|
150 | + } |
|
151 | + |
|
152 | + |
|
153 | + |
|
154 | + /** |
|
155 | + * ajax process registration step |
|
156 | + * |
|
157 | + * @throws \EE_Error |
|
158 | + */ |
|
159 | + public static function process_reg_step() |
|
160 | + { |
|
161 | + EED_Single_Page_Checkout::process_ajax_request('process_reg_step'); |
|
162 | + } |
|
163 | + |
|
164 | + |
|
165 | + |
|
166 | + /** |
|
167 | + * ajax process registration step |
|
168 | + * |
|
169 | + * @throws \EE_Error |
|
170 | + */ |
|
171 | + public static function update_reg_step() |
|
172 | + { |
|
173 | + EED_Single_Page_Checkout::process_ajax_request('update_reg_step'); |
|
174 | + } |
|
175 | + |
|
176 | + |
|
177 | + |
|
178 | + /** |
|
179 | + * update_checkout |
|
180 | + * |
|
181 | + * @access public |
|
182 | + * @return void |
|
183 | + * @throws \EE_Error |
|
184 | + */ |
|
185 | + public static function update_checkout() |
|
186 | + { |
|
187 | + EED_Single_Page_Checkout::process_ajax_request('update_checkout'); |
|
188 | + } |
|
189 | + |
|
190 | + |
|
191 | + |
|
192 | + /** |
|
193 | + * load_request_handler |
|
194 | + * |
|
195 | + * @access public |
|
196 | + * @return void |
|
197 | + */ |
|
198 | + public static function load_request_handler() |
|
199 | + { |
|
200 | + // load core Request_Handler class |
|
201 | + if ( ! isset(EE_Registry::instance()->REQ)) { |
|
202 | + EE_Registry::instance()->load_core('Request_Handler'); |
|
203 | + } |
|
204 | + } |
|
205 | + |
|
206 | + |
|
207 | + |
|
208 | + /** |
|
209 | + * set_definitions |
|
210 | + * |
|
211 | + * @access public |
|
212 | + * @return void |
|
213 | + * @throws \EE_Error |
|
214 | + */ |
|
215 | + public static function set_definitions() |
|
216 | + { |
|
217 | + if(defined('SPCO_BASE_PATH')) { |
|
218 | + return; |
|
219 | + } |
|
220 | + define('SPCO_BASE_PATH', rtrim(str_replace(array('\\', '/'), DS, plugin_dir_path(__FILE__)), DS) . DS); |
|
221 | + define('SPCO_CSS_URL', plugin_dir_url(__FILE__) . 'css' . DS); |
|
222 | + define('SPCO_IMG_URL', plugin_dir_url(__FILE__) . 'img' . DS); |
|
223 | + define('SPCO_JS_URL', plugin_dir_url(__FILE__) . 'js' . DS); |
|
224 | + define('SPCO_INC_PATH', SPCO_BASE_PATH . 'inc' . DS); |
|
225 | + define('SPCO_REG_STEPS_PATH', SPCO_BASE_PATH . 'reg_steps' . DS); |
|
226 | + define('SPCO_TEMPLATES_PATH', SPCO_BASE_PATH . 'templates' . DS); |
|
227 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(SPCO_BASE_PATH, true); |
|
228 | + EE_Registry::$i18n_js_strings['registration_expiration_notice'] = sprintf( |
|
229 | + __('%1$sWe\'re sorry, but you\'re registration time has expired.%2$s%4$sIf you still wish to complete your registration, please return to the %5$sEvent List%6$sEvent List%7$s and reselect your tickets if available. Please except our apologies for any inconvenience this may have caused.%8$s', |
|
230 | + 'event_espresso'), |
|
231 | + '<h4 class="important-notice">', |
|
232 | + '</h4>', |
|
233 | + '<br />', |
|
234 | + '<p>', |
|
235 | + '<a href="' . get_post_type_archive_link('espresso_events') . '" title="', |
|
236 | + '">', |
|
237 | + '</a>', |
|
238 | + '</p>' |
|
239 | + ); |
|
240 | + } |
|
241 | + |
|
242 | + |
|
243 | + |
|
244 | + /** |
|
245 | + * load_reg_steps |
|
246 | + * loads and instantiates each reg step based on the EE_Registry::instance()->CFG->registration->reg_steps array |
|
247 | + * |
|
248 | + * @access private |
|
249 | + * @throws \EE_Error |
|
250 | + */ |
|
251 | + public static function load_reg_steps() |
|
252 | + { |
|
253 | + static $reg_steps_loaded = false; |
|
254 | + if ($reg_steps_loaded) { |
|
255 | + return; |
|
256 | + } |
|
257 | + // filter list of reg_steps |
|
258 | + $reg_steps_to_load = (array)apply_filters( |
|
259 | + 'AHEE__SPCO__load_reg_steps__reg_steps_to_load', |
|
260 | + EED_Single_Page_Checkout::get_reg_steps() |
|
261 | + ); |
|
262 | + // sort by key (order) |
|
263 | + ksort($reg_steps_to_load); |
|
264 | + // loop through folders |
|
265 | + foreach ($reg_steps_to_load as $order => $reg_step) { |
|
266 | + // we need a |
|
267 | + if (isset($reg_step['file_path'], $reg_step['class_name'], $reg_step['slug'])) { |
|
268 | + // copy over to the reg_steps_array |
|
269 | + EED_Single_Page_Checkout::$_reg_steps_array[$order] = $reg_step; |
|
270 | + // register custom key route for each reg step |
|
271 | + // ie: step=>"slug" - this is the entire reason we load the reg steps array now |
|
272 | + EE_Config::register_route($reg_step['slug'], 'EED_Single_Page_Checkout', 'run', 'step'); |
|
273 | + // add AJAX or other hooks |
|
274 | + if (isset($reg_step['has_hooks']) && $reg_step['has_hooks']) { |
|
275 | + // setup autoloaders if necessary |
|
276 | + if ( ! class_exists($reg_step['class_name'])) { |
|
277 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder($reg_step['file_path'], true); |
|
278 | + } |
|
279 | + if (is_callable($reg_step['class_name'], 'set_hooks')) { |
|
280 | + call_user_func(array($reg_step['class_name'], 'set_hooks')); |
|
281 | + } |
|
282 | + } |
|
283 | + } |
|
284 | + } |
|
285 | + $reg_steps_loaded = true; |
|
286 | + } |
|
287 | + |
|
288 | + |
|
289 | + |
|
290 | + /** |
|
291 | + * get_reg_steps |
|
292 | + * |
|
293 | + * @access public |
|
294 | + * @return array |
|
295 | + */ |
|
296 | + public static function get_reg_steps() |
|
297 | + { |
|
298 | + $reg_steps = EE_Registry::instance()->CFG->registration->reg_steps; |
|
299 | + if (empty($reg_steps)) { |
|
300 | + $reg_steps = array( |
|
301 | + 10 => array( |
|
302 | + 'file_path' => SPCO_REG_STEPS_PATH . 'attendee_information', |
|
303 | + 'class_name' => 'EE_SPCO_Reg_Step_Attendee_Information', |
|
304 | + 'slug' => 'attendee_information', |
|
305 | + 'has_hooks' => false, |
|
306 | + ), |
|
307 | + 20 => array( |
|
308 | + 'file_path' => SPCO_REG_STEPS_PATH . 'registration_confirmation', |
|
309 | + 'class_name' => 'EE_SPCO_Reg_Step_Registration_Confirmation', |
|
310 | + 'slug' => 'registration_confirmation', |
|
311 | + 'has_hooks' => false, |
|
312 | + ), |
|
313 | + 30 => array( |
|
314 | + 'file_path' => SPCO_REG_STEPS_PATH . 'payment_options', |
|
315 | + 'class_name' => 'EE_SPCO_Reg_Step_Payment_Options', |
|
316 | + 'slug' => 'payment_options', |
|
317 | + 'has_hooks' => true, |
|
318 | + ), |
|
319 | + 999 => array( |
|
320 | + 'file_path' => SPCO_REG_STEPS_PATH . 'finalize_registration', |
|
321 | + 'class_name' => 'EE_SPCO_Reg_Step_Finalize_Registration', |
|
322 | + 'slug' => 'finalize_registration', |
|
323 | + 'has_hooks' => false, |
|
324 | + ), |
|
325 | + ); |
|
326 | + } |
|
327 | + return $reg_steps; |
|
328 | + } |
|
329 | + |
|
330 | + |
|
331 | + |
|
332 | + /** |
|
333 | + * registration_checkout_for_admin |
|
334 | + * |
|
335 | + * @access public |
|
336 | + * @return string |
|
337 | + * @throws \EE_Error |
|
338 | + */ |
|
339 | + public static function registration_checkout_for_admin() |
|
340 | + { |
|
341 | + EED_Single_Page_Checkout::load_request_handler(); |
|
342 | + EE_Registry::instance()->REQ->set('step', 'attendee_information'); |
|
343 | + EE_Registry::instance()->REQ->set('action', 'display_spco_reg_step'); |
|
344 | + EE_Registry::instance()->REQ->set('process_form_submission', false); |
|
345 | + EED_Single_Page_Checkout::instance()->_initialize(); |
|
346 | + EED_Single_Page_Checkout::instance()->_display_spco_reg_form(); |
|
347 | + return EE_Registry::instance()->REQ->get_output(); |
|
348 | + } |
|
349 | + |
|
350 | + |
|
351 | + |
|
352 | + /** |
|
353 | + * process_registration_from_admin |
|
354 | + * |
|
355 | + * @access public |
|
356 | + * @return \EE_Transaction |
|
357 | + * @throws \EE_Error |
|
358 | + */ |
|
359 | + public static function process_registration_from_admin() |
|
360 | + { |
|
361 | + EED_Single_Page_Checkout::load_request_handler(); |
|
362 | + EE_Registry::instance()->REQ->set('step', 'attendee_information'); |
|
363 | + EE_Registry::instance()->REQ->set('action', 'process_reg_step'); |
|
364 | + EE_Registry::instance()->REQ->set('process_form_submission', true); |
|
365 | + EED_Single_Page_Checkout::instance()->_initialize(); |
|
366 | + if (EED_Single_Page_Checkout::instance()->checkout->current_step->completed()) { |
|
367 | + $final_reg_step = end(EED_Single_Page_Checkout::instance()->checkout->reg_steps); |
|
368 | + if ($final_reg_step instanceof EE_SPCO_Reg_Step_Finalize_Registration) { |
|
369 | + EED_Single_Page_Checkout::instance()->checkout->set_reg_step_initiated($final_reg_step); |
|
370 | + if ($final_reg_step->process_reg_step()) { |
|
371 | + $final_reg_step->set_completed(); |
|
372 | + EED_Single_Page_Checkout::instance()->checkout->update_txn_reg_steps_array(); |
|
373 | + return EED_Single_Page_Checkout::instance()->checkout->transaction; |
|
374 | + } |
|
375 | + } |
|
376 | + } |
|
377 | + return null; |
|
378 | + } |
|
379 | + |
|
380 | + |
|
381 | + |
|
382 | + /** |
|
383 | + * run |
|
384 | + * |
|
385 | + * @access public |
|
386 | + * @param WP_Query $WP_Query |
|
387 | + * @return void |
|
388 | + * @throws \EE_Error |
|
389 | + */ |
|
390 | + public function run($WP_Query) |
|
391 | + { |
|
392 | + if ( |
|
393 | + $WP_Query instanceof WP_Query |
|
394 | + && $WP_Query->is_main_query() |
|
395 | + && apply_filters('FHEE__EED_Single_Page_Checkout__run', true) |
|
396 | + && $this->_is_reg_checkout() |
|
397 | + ) { |
|
398 | + $this->_initialize(); |
|
399 | + } |
|
400 | + } |
|
401 | + |
|
402 | + |
|
403 | + |
|
404 | + /** |
|
405 | + * determines whether current url matches reg page url |
|
406 | + * |
|
407 | + * @return bool |
|
408 | + */ |
|
409 | + protected function _is_reg_checkout() |
|
410 | + { |
|
411 | + // get current permalink for reg page without any extra query args |
|
412 | + $reg_page_url = \get_permalink(EE_Config::instance()->core->reg_page_id); |
|
413 | + // get request URI for current request, but without the scheme or host |
|
414 | + $current_request_uri = \EEH_URL::filter_input_server_url('REQUEST_URI'); |
|
415 | + $current_request_uri = html_entity_decode($current_request_uri); |
|
416 | + // get array of query args from the current request URI |
|
417 | + $query_args = \EEH_URL::get_query_string($current_request_uri); |
|
418 | + // grab page id if it is set |
|
419 | + $page_id = isset($query_args['page_id']) ? absint($query_args['page_id']) : 0; |
|
420 | + // and remove the page id from the query args (we will re-add it later) |
|
421 | + unset($query_args['page_id']); |
|
422 | + // now strip all query args from current request URI |
|
423 | + $current_request_uri = remove_query_arg(array_keys($query_args), $current_request_uri); |
|
424 | + // and re-add the page id if it was set |
|
425 | + if ($page_id) { |
|
426 | + $current_request_uri = add_query_arg('page_id', $page_id, $current_request_uri); |
|
427 | + } |
|
428 | + // remove slashes and ? |
|
429 | + $current_request_uri = trim($current_request_uri, '?/'); |
|
430 | + // is current request URI part of the known full reg page URL ? |
|
431 | + return ! empty($current_request_uri) && strpos($reg_page_url, $current_request_uri) !== false; |
|
432 | + } |
|
433 | + |
|
434 | + |
|
435 | + |
|
436 | + /** |
|
437 | + * @param WP_Query $wp_query |
|
438 | + * @return void |
|
439 | + * @throws \EE_Error |
|
440 | + */ |
|
441 | + public static function init($wp_query) |
|
442 | + { |
|
443 | + EED_Single_Page_Checkout::instance()->run($wp_query); |
|
444 | + } |
|
445 | + |
|
446 | + |
|
447 | + |
|
448 | + /** |
|
449 | + * _initialize - initial module setup |
|
450 | + * |
|
451 | + * @access private |
|
452 | + * @throws EE_Error |
|
453 | + * @return void |
|
454 | + */ |
|
455 | + private function _initialize() |
|
456 | + { |
|
457 | + // ensure SPCO doesn't run twice |
|
458 | + if (EED_Single_Page_Checkout::$_initialized) { |
|
459 | + return; |
|
460 | + } |
|
461 | + try { |
|
462 | + EED_Single_Page_Checkout::load_reg_steps(); |
|
463 | + $this->_verify_session(); |
|
464 | + // setup the EE_Checkout object |
|
465 | + $this->checkout = $this->_initialize_checkout(); |
|
466 | + // filter checkout |
|
467 | + $this->checkout = apply_filters('FHEE__EED_Single_Page_Checkout___initialize__checkout', $this->checkout); |
|
468 | + // get the $_GET |
|
469 | + $this->_get_request_vars(); |
|
470 | + if ($this->_block_bots()) { |
|
471 | + return; |
|
472 | + } |
|
473 | + // filter continue_reg |
|
474 | + $this->checkout->continue_reg = apply_filters('FHEE__EED_Single_Page_Checkout__init___continue_reg', true, $this->checkout); |
|
475 | + // load the reg steps array |
|
476 | + if ( ! $this->_load_and_instantiate_reg_steps()) { |
|
477 | + EED_Single_Page_Checkout::$_initialized = true; |
|
478 | + return; |
|
479 | + } |
|
480 | + // set the current step |
|
481 | + $this->checkout->set_current_step($this->checkout->step); |
|
482 | + // and the next step |
|
483 | + $this->checkout->set_next_step(); |
|
484 | + // verify that everything has been setup correctly |
|
485 | + if ( ! ($this->_verify_transaction_and_get_registrations() && $this->_final_verifications())) { |
|
486 | + EED_Single_Page_Checkout::$_initialized = true; |
|
487 | + return; |
|
488 | + } |
|
489 | + // lock the transaction |
|
490 | + $this->checkout->transaction->lock(); |
|
491 | + // make sure all of our cached objects are added to their respective model entity mappers |
|
492 | + $this->checkout->refresh_all_entities(); |
|
493 | + // set amount owing |
|
494 | + $this->checkout->amount_owing = $this->checkout->transaction->remaining(); |
|
495 | + // initialize each reg step, which gives them the chance to potentially alter the process |
|
496 | + $this->_initialize_reg_steps(); |
|
497 | + // DEBUG LOG |
|
498 | + //$this->checkout->log( __CLASS__, __FUNCTION__, __LINE__ ); |
|
499 | + // get reg form |
|
500 | + if( ! $this->_check_form_submission()) { |
|
501 | + EED_Single_Page_Checkout::$_initialized = true; |
|
502 | + return; |
|
503 | + } |
|
504 | + // checkout the action!!! |
|
505 | + $this->_process_form_action(); |
|
506 | + // add some style and make it dance |
|
507 | + $this->add_styles_and_scripts(); |
|
508 | + // kk... SPCO has successfully run |
|
509 | + EED_Single_Page_Checkout::$_initialized = true; |
|
510 | + // set no cache headers and constants |
|
511 | + EE_System::do_not_cache(); |
|
512 | + // add anchor |
|
513 | + add_action('loop_start', array($this, 'set_checkout_anchor'), 1); |
|
514 | + // remove transaction lock |
|
515 | + add_action('shutdown', array($this, 'unlock_transaction'), 1); |
|
516 | + } catch (Exception $e) { |
|
517 | + EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
518 | + } |
|
519 | + } |
|
520 | + |
|
521 | + |
|
522 | + |
|
523 | + /** |
|
524 | + * _verify_session |
|
525 | + * checks that the session is valid and not expired |
|
526 | + * |
|
527 | + * @access private |
|
528 | + * @throws EE_Error |
|
529 | + */ |
|
530 | + private function _verify_session() |
|
531 | + { |
|
532 | + if ( ! EE_Registry::instance()->SSN instanceof EE_Session) { |
|
533 | + throw new EE_Error(__('The EE_Session class could not be loaded.', 'event_espresso')); |
|
534 | + } |
|
535 | + // is session still valid ? |
|
536 | + if (EE_Registry::instance()->SSN->expired() && EE_Registry::instance()->REQ->get('e_reg_url_link', '') === '') { |
|
537 | + $this->checkout = new EE_Checkout(); |
|
538 | + EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__); |
|
539 | + // EE_Registry::instance()->SSN->reset_cart(); |
|
540 | + // EE_Registry::instance()->SSN->reset_checkout(); |
|
541 | + // EE_Registry::instance()->SSN->reset_transaction(); |
|
542 | + EE_Error::add_attention(EE_Registry::$i18n_js_strings['registration_expiration_notice'], __FILE__, |
|
543 | + __FUNCTION__, __LINE__); |
|
544 | + // EE_Registry::instance()->SSN->reset_expired(); |
|
545 | + } |
|
546 | + } |
|
547 | + |
|
548 | + |
|
549 | + |
|
550 | + /** |
|
551 | + * _initialize_checkout |
|
552 | + * loads and instantiates EE_Checkout |
|
553 | + * |
|
554 | + * @access private |
|
555 | + * @throws EE_Error |
|
556 | + * @return EE_Checkout |
|
557 | + */ |
|
558 | + private function _initialize_checkout() |
|
559 | + { |
|
560 | + // look in session for existing checkout |
|
561 | + /** @type EE_Checkout $checkout */ |
|
562 | + $checkout = EE_Registry::instance()->SSN->checkout(); |
|
563 | + // verify |
|
564 | + if ( ! $checkout instanceof EE_Checkout) { |
|
565 | + // instantiate EE_Checkout object for handling the properties of the current checkout process |
|
566 | + $checkout = EE_Registry::instance()->load_file(SPCO_INC_PATH, 'EE_Checkout', 'class', array(), false); |
|
567 | + } else { |
|
568 | + if ($checkout->current_step->is_final_step() && $checkout->exit_spco() === true) { |
|
569 | + $this->unlock_transaction(); |
|
570 | + wp_safe_redirect($checkout->redirect_url); |
|
571 | + exit(); |
|
572 | + } |
|
573 | + } |
|
574 | + $checkout = apply_filters('FHEE__EED_Single_Page_Checkout___initialize_checkout__checkout', $checkout); |
|
575 | + // verify again |
|
576 | + if ( ! $checkout instanceof EE_Checkout) { |
|
577 | + throw new EE_Error(__('The EE_Checkout class could not be loaded.', 'event_espresso')); |
|
578 | + } |
|
579 | + // reset anything that needs a clean slate for each request |
|
580 | + $checkout->reset_for_current_request(); |
|
581 | + return $checkout; |
|
582 | + } |
|
583 | + |
|
584 | + |
|
585 | + |
|
586 | + /** |
|
587 | + * _get_request_vars |
|
588 | + * |
|
589 | + * @access private |
|
590 | + * @return void |
|
591 | + * @throws \EE_Error |
|
592 | + */ |
|
593 | + private function _get_request_vars() |
|
594 | + { |
|
595 | + // load classes |
|
596 | + EED_Single_Page_Checkout::load_request_handler(); |
|
597 | + //make sure this request is marked as belonging to EE |
|
598 | + EE_Registry::instance()->REQ->set_espresso_page(true); |
|
599 | + // which step is being requested ? |
|
600 | + $this->checkout->step = EE_Registry::instance()->REQ->get('step', $this->_get_first_step()); |
|
601 | + // which step is being edited ? |
|
602 | + $this->checkout->edit_step = EE_Registry::instance()->REQ->get('edit_step', ''); |
|
603 | + // and what we're doing on the current step |
|
604 | + $this->checkout->action = EE_Registry::instance()->REQ->get('action', 'display_spco_reg_step'); |
|
605 | + // timestamp |
|
606 | + $this->checkout->uts = EE_Registry::instance()->REQ->get('uts', 0); |
|
607 | + // returning to edit ? |
|
608 | + $this->checkout->reg_url_link = EE_Registry::instance()->REQ->get('e_reg_url_link', ''); |
|
609 | + // or some other kind of revisit ? |
|
610 | + $this->checkout->revisit = filter_var( |
|
611 | + EE_Registry::instance()->REQ->get('revisit', false), |
|
612 | + FILTER_VALIDATE_BOOLEAN |
|
613 | + ); |
|
614 | + // and whether or not to generate a reg form for this request |
|
615 | + $this->checkout->generate_reg_form = filter_var( |
|
616 | + EE_Registry::instance()->REQ->get('generate_reg_form', true), |
|
617 | + FILTER_VALIDATE_BOOLEAN |
|
618 | + ); |
|
619 | + // and whether or not to process a reg form submission for this request |
|
620 | + $this->checkout->process_form_submission = filter_var( |
|
621 | + EE_Registry::instance()->REQ->get( |
|
622 | + 'process_form_submission', |
|
623 | + $this->checkout->action === 'process_reg_step' |
|
624 | + ), |
|
625 | + FILTER_VALIDATE_BOOLEAN |
|
626 | + ); |
|
627 | + $this->checkout->process_form_submission = filter_var( |
|
628 | + $this->checkout->action !== 'display_spco_reg_step' |
|
629 | + ? $this->checkout->process_form_submission |
|
630 | + : false, |
|
631 | + FILTER_VALIDATE_BOOLEAN |
|
632 | + ); |
|
633 | + // $this->_display_request_vars(); |
|
634 | + } |
|
635 | + |
|
636 | + |
|
637 | + |
|
638 | + /** |
|
639 | + * _display_request_vars |
|
640 | + * |
|
641 | + * @access protected |
|
642 | + * @return void |
|
643 | + */ |
|
644 | + protected function _display_request_vars() |
|
645 | + { |
|
646 | + if ( ! WP_DEBUG) { |
|
647 | + return; |
|
648 | + } |
|
649 | + EEH_Debug_Tools::printr($_REQUEST, '$_REQUEST', __FILE__, __LINE__); |
|
650 | + EEH_Debug_Tools::printr($this->checkout->step, '$this->checkout->step', __FILE__, __LINE__); |
|
651 | + EEH_Debug_Tools::printr($this->checkout->edit_step, '$this->checkout->edit_step', __FILE__, __LINE__); |
|
652 | + EEH_Debug_Tools::printr($this->checkout->action, '$this->checkout->action', __FILE__, __LINE__); |
|
653 | + EEH_Debug_Tools::printr($this->checkout->reg_url_link, '$this->checkout->reg_url_link', __FILE__, __LINE__); |
|
654 | + EEH_Debug_Tools::printr($this->checkout->revisit, '$this->checkout->revisit', __FILE__, __LINE__); |
|
655 | + EEH_Debug_Tools::printr($this->checkout->generate_reg_form, '$this->checkout->generate_reg_form', __FILE__, __LINE__); |
|
656 | + EEH_Debug_Tools::printr($this->checkout->process_form_submission, '$this->checkout->process_form_submission', __FILE__, __LINE__); |
|
657 | + } |
|
658 | + |
|
659 | + |
|
660 | + |
|
661 | + /** |
|
662 | + * _block_bots |
|
663 | + * checks that the incoming request has either of the following set: |
|
664 | + * a uts (unix timestamp) which indicates that the request was redirected from the Ticket Selector |
|
665 | + * a REG URL Link, which indicates that the request is a return visit to SPCO for a valid TXN |
|
666 | + * so if you're not coming from the Ticket Selector nor returning for a valid IP... |
|
667 | + * then where you coming from man? |
|
668 | + * |
|
669 | + * @return boolean |
|
670 | + */ |
|
671 | + private function _block_bots() |
|
672 | + { |
|
673 | + $invalid_checkout_access = \EED_Invalid_Checkout_Access::getInvalidCheckoutAccess(); |
|
674 | + if ($invalid_checkout_access->checkoutAccessIsInvalid($this->checkout)) { |
|
675 | + return true; |
|
676 | + } |
|
677 | + return false; |
|
678 | + } |
|
679 | + |
|
680 | + |
|
681 | + |
|
682 | + /** |
|
683 | + * _get_first_step |
|
684 | + * gets slug for first step in $_reg_steps_array |
|
685 | + * |
|
686 | + * @access private |
|
687 | + * @throws EE_Error |
|
688 | + * @return string |
|
689 | + */ |
|
690 | + private function _get_first_step() |
|
691 | + { |
|
692 | + $first_step = reset(EED_Single_Page_Checkout::$_reg_steps_array); |
|
693 | + return isset($first_step['slug']) ? $first_step['slug'] : 'attendee_information'; |
|
694 | + } |
|
695 | + |
|
696 | + |
|
697 | + |
|
698 | + /** |
|
699 | + * _load_and_instantiate_reg_steps |
|
700 | + * instantiates each reg step based on the loaded reg_steps array |
|
701 | + * |
|
702 | + * @access private |
|
703 | + * @throws EE_Error |
|
704 | + * @return bool |
|
705 | + */ |
|
706 | + private function _load_and_instantiate_reg_steps() |
|
707 | + { |
|
708 | + do_action('AHEE__Single_Page_Checkout___load_and_instantiate_reg_steps__start', $this->checkout); |
|
709 | + // have reg_steps already been instantiated ? |
|
710 | + if ( |
|
711 | + empty($this->checkout->reg_steps) |
|
712 | + || apply_filters('FHEE__Single_Page_Checkout__load_reg_steps__reload_reg_steps', false, $this->checkout) |
|
713 | + ) { |
|
714 | + // if not, then loop through raw reg steps array |
|
715 | + foreach (EED_Single_Page_Checkout::$_reg_steps_array as $order => $reg_step) { |
|
716 | + if ( ! $this->_load_and_instantiate_reg_step($reg_step, $order)) { |
|
717 | + return false; |
|
718 | + } |
|
719 | + } |
|
720 | + EE_Registry::instance()->CFG->registration->skip_reg_confirmation = true; |
|
721 | + EE_Registry::instance()->CFG->registration->reg_confirmation_last = true; |
|
722 | + // skip the registration_confirmation page ? |
|
723 | + if (EE_Registry::instance()->CFG->registration->skip_reg_confirmation) { |
|
724 | + // just remove it from the reg steps array |
|
725 | + $this->checkout->remove_reg_step('registration_confirmation', false); |
|
726 | + } else if ( |
|
727 | + isset($this->checkout->reg_steps['registration_confirmation']) |
|
728 | + && EE_Registry::instance()->CFG->registration->reg_confirmation_last |
|
729 | + ) { |
|
730 | + // set the order to something big like 100 |
|
731 | + $this->checkout->set_reg_step_order('registration_confirmation', 100); |
|
732 | + } |
|
733 | + // filter the array for good luck |
|
734 | + $this->checkout->reg_steps = apply_filters( |
|
735 | + 'FHEE__Single_Page_Checkout__load_reg_steps__reg_steps', |
|
736 | + $this->checkout->reg_steps |
|
737 | + ); |
|
738 | + // finally re-sort based on the reg step class order properties |
|
739 | + $this->checkout->sort_reg_steps(); |
|
740 | + } else { |
|
741 | + foreach ($this->checkout->reg_steps as $reg_step) { |
|
742 | + // set all current step stati to FALSE |
|
743 | + $reg_step->set_is_current_step(false); |
|
744 | + } |
|
745 | + } |
|
746 | + if (empty($this->checkout->reg_steps)) { |
|
747 | + EE_Error::add_error(__('No Reg Steps were loaded..', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
748 | + return false; |
|
749 | + } |
|
750 | + // make reg step details available to JS |
|
751 | + $this->checkout->set_reg_step_JSON_info(); |
|
752 | + return true; |
|
753 | + } |
|
754 | + |
|
755 | + |
|
756 | + |
|
757 | + /** |
|
758 | + * _load_and_instantiate_reg_step |
|
759 | + * |
|
760 | + * @access private |
|
761 | + * @param array $reg_step |
|
762 | + * @param int $order |
|
763 | + * @return bool |
|
764 | + */ |
|
765 | + private function _load_and_instantiate_reg_step($reg_step = array(), $order = 0) |
|
766 | + { |
|
767 | + // we need a file_path, class_name, and slug to add a reg step |
|
768 | + if (isset($reg_step['file_path'], $reg_step['class_name'], $reg_step['slug'])) { |
|
769 | + // if editing a specific step, but this is NOT that step... (and it's not the 'finalize_registration' step) |
|
770 | + if ( |
|
771 | + $this->checkout->reg_url_link |
|
772 | + && $this->checkout->step !== $reg_step['slug'] |
|
773 | + && $reg_step['slug'] !== 'finalize_registration' |
|
774 | + // normally at this point we would NOT load the reg step, but this filter can change that |
|
775 | + && apply_filters( |
|
776 | + 'FHEE__Single_Page_Checkout___load_and_instantiate_reg_step__bypass_reg_step', |
|
777 | + true, |
|
778 | + $reg_step, |
|
779 | + $this->checkout |
|
780 | + ) |
|
781 | + ) { |
|
782 | + return true; |
|
783 | + } |
|
784 | + // instantiate step class using file path and class name |
|
785 | + $reg_step_obj = EE_Registry::instance()->load_file( |
|
786 | + $reg_step['file_path'], |
|
787 | + $reg_step['class_name'], |
|
788 | + 'class', |
|
789 | + $this->checkout, |
|
790 | + false |
|
791 | + ); |
|
792 | + // did we gets the goods ? |
|
793 | + if ($reg_step_obj instanceof EE_SPCO_Reg_Step) { |
|
794 | + // set reg step order based on config |
|
795 | + $reg_step_obj->set_order($order); |
|
796 | + // add instantiated reg step object to the master reg steps array |
|
797 | + $this->checkout->add_reg_step($reg_step_obj); |
|
798 | + } else { |
|
799 | + EE_Error::add_error( |
|
800 | + __('The current step could not be set.', 'event_espresso'), |
|
801 | + __FILE__, __FUNCTION__, __LINE__ |
|
802 | + ); |
|
803 | + return false; |
|
804 | + } |
|
805 | + } else { |
|
806 | + if (WP_DEBUG) { |
|
807 | + EE_Error::add_error( |
|
808 | + sprintf( |
|
809 | + __('A registration step could not be loaded. One or more of the following data points is invalid:%4$s%5$sFile Path: %1$s%6$s%5$sClass Name: %2$s%6$s%5$sSlug: %3$s%6$s%7$s', 'event_espresso'), |
|
810 | + isset($reg_step['file_path']) ? $reg_step['file_path'] : '', |
|
811 | + isset($reg_step['class_name']) ? $reg_step['class_name'] : '', |
|
812 | + isset($reg_step['slug']) ? $reg_step['slug'] : '', |
|
813 | + '<ul>', |
|
814 | + '<li>', |
|
815 | + '</li>', |
|
816 | + '</ul>' |
|
817 | + ), |
|
818 | + __FILE__, __FUNCTION__, __LINE__ |
|
819 | + ); |
|
820 | + } |
|
821 | + return false; |
|
822 | + } |
|
823 | + return true; |
|
824 | + } |
|
825 | + |
|
826 | + |
|
827 | + |
|
828 | + /** |
|
829 | + * _verify_transaction_and_get_registrations |
|
830 | + * |
|
831 | + * @access private |
|
832 | + * @return bool |
|
833 | + */ |
|
834 | + private function _verify_transaction_and_get_registrations() |
|
835 | + { |
|
836 | + // was there already a valid transaction in the checkout from the session ? |
|
837 | + if ( ! $this->checkout->transaction instanceof EE_Transaction) { |
|
838 | + // get transaction from db or session |
|
839 | + $this->checkout->transaction = $this->checkout->reg_url_link && ! is_admin() |
|
840 | + ? $this->_get_transaction_and_cart_for_previous_visit() |
|
841 | + : $this->_get_cart_for_current_session_and_setup_new_transaction(); |
|
842 | + if ( ! $this->checkout->transaction instanceof EE_Transaction) { |
|
843 | + EE_Error::add_error( |
|
844 | + __('Your Registration and Transaction information could not be retrieved from the db.', |
|
845 | + 'event_espresso'), |
|
846 | + __FILE__, __FUNCTION__, __LINE__ |
|
847 | + ); |
|
848 | + $this->checkout->transaction = EE_Transaction::new_instance(); |
|
849 | + // add some style and make it dance |
|
850 | + $this->add_styles_and_scripts(); |
|
851 | + EED_Single_Page_Checkout::$_initialized = true; |
|
852 | + return false; |
|
853 | + } |
|
854 | + // and the registrations for the transaction |
|
855 | + $this->_get_registrations($this->checkout->transaction); |
|
856 | + } |
|
857 | + return true; |
|
858 | + } |
|
859 | + |
|
860 | + |
|
861 | + |
|
862 | + /** |
|
863 | + * _get_transaction_and_cart_for_previous_visit |
|
864 | + * |
|
865 | + * @access private |
|
866 | + * @return mixed EE_Transaction|NULL |
|
867 | + */ |
|
868 | + private function _get_transaction_and_cart_for_previous_visit() |
|
869 | + { |
|
870 | + /** @var $TXN_model EEM_Transaction */ |
|
871 | + $TXN_model = EE_Registry::instance()->load_model('Transaction'); |
|
872 | + // because the reg_url_link is present in the request, this is a return visit to SPCO, so we'll get the transaction data from the db |
|
873 | + $transaction = $TXN_model->get_transaction_from_reg_url_link($this->checkout->reg_url_link); |
|
874 | + // verify transaction |
|
875 | + if ($transaction instanceof EE_Transaction) { |
|
876 | + // and get the cart that was used for that transaction |
|
877 | + $this->checkout->cart = $this->_get_cart_for_transaction($transaction); |
|
878 | + return $transaction; |
|
879 | + } else { |
|
880 | + EE_Error::add_error(__('Your Registration and Transaction information could not be retrieved from the db.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
881 | + return null; |
|
882 | + } |
|
883 | + } |
|
884 | + |
|
885 | + |
|
886 | + |
|
887 | + /** |
|
888 | + * _get_cart_for_transaction |
|
889 | + * |
|
890 | + * @access private |
|
891 | + * @param EE_Transaction $transaction |
|
892 | + * @return EE_Cart |
|
893 | + */ |
|
894 | + private function _get_cart_for_transaction($transaction) |
|
895 | + { |
|
896 | + return $this->checkout->get_cart_for_transaction($transaction); |
|
897 | + } |
|
898 | + |
|
899 | + |
|
900 | + |
|
901 | + /** |
|
902 | + * get_cart_for_transaction |
|
903 | + * |
|
904 | + * @access public |
|
905 | + * @param EE_Transaction $transaction |
|
906 | + * @return EE_Cart |
|
907 | + */ |
|
908 | + public function get_cart_for_transaction(EE_Transaction $transaction) |
|
909 | + { |
|
910 | + return $this->checkout->get_cart_for_transaction($transaction); |
|
911 | + } |
|
912 | + |
|
913 | + |
|
914 | + |
|
915 | + /** |
|
916 | + * _get_transaction_and_cart_for_current_session |
|
917 | + * generates a new EE_Transaction object and adds it to the $_transaction property. |
|
918 | + * |
|
919 | + * @access private |
|
920 | + * @return EE_Transaction |
|
921 | + * @throws \EE_Error |
|
922 | + */ |
|
923 | + private function _get_cart_for_current_session_and_setup_new_transaction() |
|
924 | + { |
|
925 | + // if there's no transaction, then this is the FIRST visit to SPCO |
|
926 | + // so load up the cart ( passing nothing for the TXN because it doesn't exist yet ) |
|
927 | + $this->checkout->cart = $this->_get_cart_for_transaction(null); |
|
928 | + // and then create a new transaction |
|
929 | + $transaction = $this->_initialize_transaction(); |
|
930 | + // verify transaction |
|
931 | + if ($transaction instanceof EE_Transaction) { |
|
932 | + // save it so that we have an ID for other objects to use |
|
933 | + $transaction->save(); |
|
934 | + // and save TXN data to the cart |
|
935 | + $this->checkout->cart->get_grand_total()->save_this_and_descendants_to_txn($transaction->ID()); |
|
936 | + } else { |
|
937 | + EE_Error::add_error(__('A Valid Transaction could not be initialized.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
938 | + } |
|
939 | + return $transaction; |
|
940 | + } |
|
941 | + |
|
942 | + |
|
943 | + |
|
944 | + /** |
|
945 | + * generates a new EE_Transaction object and adds it to the $_transaction property. |
|
946 | + * |
|
947 | + * @access private |
|
948 | + * @return mixed EE_Transaction|NULL |
|
949 | + */ |
|
950 | + private function _initialize_transaction() |
|
951 | + { |
|
952 | + try { |
|
953 | + // ensure cart totals have been calculated |
|
954 | + $this->checkout->cart->get_grand_total()->recalculate_total_including_taxes(); |
|
955 | + // grab the cart grand total |
|
956 | + $cart_total = $this->checkout->cart->get_cart_grand_total(); |
|
957 | + // create new TXN |
|
958 | + $transaction = EE_Transaction::new_instance( |
|
959 | + array( |
|
960 | + 'TXN_reg_steps' => $this->checkout->initialize_txn_reg_steps_array(), |
|
961 | + 'TXN_total' => $cart_total > 0 ? $cart_total : 0, |
|
962 | + 'TXN_paid' => 0, |
|
963 | + 'STS_ID' => EEM_Transaction::failed_status_code, |
|
964 | + ) |
|
965 | + ); |
|
966 | + // save it so that we have an ID for other objects to use |
|
967 | + $transaction->save(); |
|
968 | + // set cron job for following up on TXNs after their session has expired |
|
969 | + EE_Cron_Tasks::schedule_expired_transaction_check( |
|
970 | + EE_Registry::instance()->SSN->expiration() + 1, |
|
971 | + $transaction->ID() |
|
972 | + ); |
|
973 | + return $transaction; |
|
974 | + } catch (Exception $e) { |
|
975 | + EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
976 | + } |
|
977 | + return null; |
|
978 | + } |
|
979 | + |
|
980 | + |
|
981 | + |
|
982 | + /** |
|
983 | + * _get_registrations |
|
984 | + * |
|
985 | + * @access private |
|
986 | + * @param EE_Transaction $transaction |
|
987 | + * @return void |
|
988 | + * @throws \EventEspresso\core\exceptions\InvalidEntityException |
|
989 | + * @throws \EE_Error |
|
990 | + */ |
|
991 | + private function _get_registrations(EE_Transaction $transaction) |
|
992 | + { |
|
993 | + // first step: grab the registrants { : o |
|
994 | + $registrations = $transaction->registrations($this->checkout->reg_cache_where_params, true); |
|
995 | + // verify registrations have been set |
|
996 | + if (empty($registrations)) { |
|
997 | + // if no cached registrations, then check the db |
|
998 | + $registrations = $transaction->registrations($this->checkout->reg_cache_where_params, false); |
|
999 | + // still nothing ? well as long as this isn't a revisit |
|
1000 | + if (empty($registrations) && ! $this->checkout->revisit) { |
|
1001 | + // generate new registrations from scratch |
|
1002 | + $registrations = $this->_initialize_registrations($transaction); |
|
1003 | + } |
|
1004 | + } |
|
1005 | + // sort by their original registration order |
|
1006 | + usort($registrations, array('EED_Single_Page_Checkout', 'sort_registrations_by_REG_count')); |
|
1007 | + // then loop thru the array |
|
1008 | + foreach ($registrations as $registration) { |
|
1009 | + // verify each registration |
|
1010 | + if ($registration instanceof EE_Registration) { |
|
1011 | + // we display all attendee info for the primary registrant |
|
1012 | + if ($this->checkout->reg_url_link === $registration->reg_url_link() |
|
1013 | + && $registration->is_primary_registrant() |
|
1014 | + ) { |
|
1015 | + $this->checkout->primary_revisit = true; |
|
1016 | + break; |
|
1017 | + } else if ($this->checkout->revisit |
|
1018 | + && $this->checkout->reg_url_link !== $registration->reg_url_link() |
|
1019 | + ) { |
|
1020 | + // but hide info if it doesn't belong to you |
|
1021 | + $transaction->clear_cache('Registration', $registration->ID()); |
|
1022 | + } |
|
1023 | + $this->checkout->set_reg_status_updated($registration->ID(), false); |
|
1024 | + } |
|
1025 | + } |
|
1026 | + } |
|
1027 | + |
|
1028 | + |
|
1029 | + |
|
1030 | + /** |
|
1031 | + * adds related EE_Registration objects for each ticket in the cart to the current EE_Transaction object |
|
1032 | + * |
|
1033 | + * @access private |
|
1034 | + * @param EE_Transaction $transaction |
|
1035 | + * @return array |
|
1036 | + * @throws \EventEspresso\core\exceptions\InvalidEntityException |
|
1037 | + * @throws \EE_Error |
|
1038 | + */ |
|
1039 | + private function _initialize_registrations(EE_Transaction $transaction) |
|
1040 | + { |
|
1041 | + $att_nmbr = 0; |
|
1042 | + $registrations = array(); |
|
1043 | + if ($transaction instanceof EE_Transaction) { |
|
1044 | + /** @type EE_Registration_Processor $registration_processor */ |
|
1045 | + $registration_processor = EE_Registry::instance()->load_class('Registration_Processor'); |
|
1046 | + $this->checkout->total_ticket_count = $this->checkout->cart->all_ticket_quantity_count(); |
|
1047 | + // now let's add the cart items to the $transaction |
|
1048 | + foreach ($this->checkout->cart->get_tickets() as $line_item) { |
|
1049 | + //do the following for each ticket of this type they selected |
|
1050 | + for ($x = 1; $x <= $line_item->quantity(); $x++) { |
|
1051 | + $att_nmbr++; |
|
1052 | + /** @var EventEspresso\core\services\commands\registration\CreateRegistrationCommand $CreateRegistrationCommand */ |
|
1053 | + $CreateRegistrationCommand = EE_Registry::instance() |
|
1054 | + ->create( |
|
1055 | + 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand', |
|
1056 | + array( |
|
1057 | + $transaction, |
|
1058 | + $line_item, |
|
1059 | + $att_nmbr, |
|
1060 | + $this->checkout->total_ticket_count, |
|
1061 | + ) |
|
1062 | + ); |
|
1063 | + // override capabilities for frontend registrations |
|
1064 | + if ( ! is_admin()) { |
|
1065 | + $CreateRegistrationCommand->setCapCheck( |
|
1066 | + new PublicCapabilities('', 'create_new_registration') |
|
1067 | + ); |
|
1068 | + } |
|
1069 | + $registration = EE_Registry::instance()->BUS->execute($CreateRegistrationCommand); |
|
1070 | + if ( ! $registration instanceof EE_Registration) { |
|
1071 | + throw new InvalidEntityException($registration, 'EE_Registration'); |
|
1072 | + } |
|
1073 | + $registrations[ $registration->ID() ] = $registration; |
|
1074 | + } |
|
1075 | + } |
|
1076 | + $registration_processor->fix_reg_final_price_rounding_issue($transaction); |
|
1077 | + } |
|
1078 | + return $registrations; |
|
1079 | + } |
|
1080 | + |
|
1081 | + |
|
1082 | + |
|
1083 | + /** |
|
1084 | + * sorts registrations by REG_count |
|
1085 | + * |
|
1086 | + * @access public |
|
1087 | + * @param EE_Registration $reg_A |
|
1088 | + * @param EE_Registration $reg_B |
|
1089 | + * @return int |
|
1090 | + */ |
|
1091 | + public static function sort_registrations_by_REG_count(EE_Registration $reg_A, EE_Registration $reg_B) |
|
1092 | + { |
|
1093 | + // this shouldn't ever happen within the same TXN, but oh well |
|
1094 | + if ($reg_A->count() === $reg_B->count()) { |
|
1095 | + return 0; |
|
1096 | + } |
|
1097 | + return ($reg_A->count() > $reg_B->count()) ? 1 : -1; |
|
1098 | + } |
|
1099 | + |
|
1100 | + |
|
1101 | + |
|
1102 | + /** |
|
1103 | + * _final_verifications |
|
1104 | + * just makes sure that everything is set up correctly before proceeding |
|
1105 | + * |
|
1106 | + * @access private |
|
1107 | + * @return bool |
|
1108 | + * @throws \EE_Error |
|
1109 | + */ |
|
1110 | + private function _final_verifications() |
|
1111 | + { |
|
1112 | + // filter checkout |
|
1113 | + $this->checkout = apply_filters('FHEE__EED_Single_Page_Checkout___final_verifications__checkout', $this->checkout); |
|
1114 | + //verify that current step is still set correctly |
|
1115 | + if ( ! $this->checkout->current_step instanceof EE_SPCO_Reg_Step) { |
|
1116 | + EE_Error::add_error( |
|
1117 | + __('We\'re sorry but the registration process can not proceed because one or more registration steps were not setup correctly. Please refresh the page and try again or contact support.', 'event_espresso'), |
|
1118 | + __FILE__, |
|
1119 | + __FUNCTION__, |
|
1120 | + __LINE__ |
|
1121 | + ); |
|
1122 | + return false; |
|
1123 | + } |
|
1124 | + // if returning to SPCO, then verify that primary registrant is set |
|
1125 | + if ( ! empty($this->checkout->reg_url_link)) { |
|
1126 | + $valid_registrant = $this->checkout->transaction->primary_registration(); |
|
1127 | + if ( ! $valid_registrant instanceof EE_Registration) { |
|
1128 | + EE_Error::add_error( |
|
1129 | + __('We\'re sorry but there appears to be an error with the "reg_url_link" or the primary registrant for this transaction. Please refresh the page and try again or contact support.', 'event_espresso'), |
|
1130 | + __FILE__, |
|
1131 | + __FUNCTION__, |
|
1132 | + __LINE__ |
|
1133 | + ); |
|
1134 | + return false; |
|
1135 | + } |
|
1136 | + $valid_registrant = null; |
|
1137 | + foreach ($this->checkout->transaction->registrations($this->checkout->reg_cache_where_params) as $registration) { |
|
1138 | + if ( |
|
1139 | + $registration instanceof EE_Registration |
|
1140 | + && $registration->reg_url_link() === $this->checkout->reg_url_link |
|
1141 | + ) { |
|
1142 | + $valid_registrant = $registration; |
|
1143 | + } |
|
1144 | + } |
|
1145 | + if ( ! $valid_registrant instanceof EE_Registration) { |
|
1146 | + // hmmm... maybe we have the wrong session because the user is opening multiple tabs ? |
|
1147 | + if (EED_Single_Page_Checkout::$_checkout_verified) { |
|
1148 | + // clear the session, mark the checkout as unverified, and try again |
|
1149 | + EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__); |
|
1150 | + EED_Single_Page_Checkout::$_initialized = false; |
|
1151 | + EED_Single_Page_Checkout::$_checkout_verified = false; |
|
1152 | + $this->_initialize(); |
|
1153 | + EE_Error::reset_notices(); |
|
1154 | + return false; |
|
1155 | + } |
|
1156 | + EE_Error::add_error( |
|
1157 | + __('We\'re sorry but there appears to be an error with the "reg_url_link" or the transaction itself. Please refresh the page and try again or contact support.', 'event_espresso'), |
|
1158 | + __FILE__, |
|
1159 | + __FUNCTION__, |
|
1160 | + __LINE__ |
|
1161 | + ); |
|
1162 | + return false; |
|
1163 | + } |
|
1164 | + } |
|
1165 | + // now that things have been kinda sufficiently verified, |
|
1166 | + // let's add the checkout to the session so that it's available to other systems |
|
1167 | + EE_Registry::instance()->SSN->set_checkout($this->checkout); |
|
1168 | + return true; |
|
1169 | + } |
|
1170 | + |
|
1171 | + |
|
1172 | + |
|
1173 | + /** |
|
1174 | + * _initialize_reg_steps |
|
1175 | + * first makes sure that EE_Transaction_Processor::set_reg_step_initiated() is called as required |
|
1176 | + * then loops thru all of the active reg steps and calls the initialize_reg_step() method |
|
1177 | + * |
|
1178 | + * @access private |
|
1179 | + * @param bool $reinitializing |
|
1180 | + * @throws \EE_Error |
|
1181 | + */ |
|
1182 | + private function _initialize_reg_steps($reinitializing = false) |
|
1183 | + { |
|
1184 | + $this->checkout->set_reg_step_initiated($this->checkout->current_step); |
|
1185 | + // loop thru all steps to call their individual "initialize" methods and set i18n strings for JS |
|
1186 | + foreach ($this->checkout->reg_steps as $reg_step) { |
|
1187 | + if ( ! $reg_step->initialize_reg_step()) { |
|
1188 | + // if not initialized then maybe this step is being removed... |
|
1189 | + if ( ! $reinitializing && $reg_step->is_current_step()) { |
|
1190 | + // if it was the current step, then we need to start over here |
|
1191 | + $this->_initialize_reg_steps(true); |
|
1192 | + return; |
|
1193 | + } |
|
1194 | + continue; |
|
1195 | + } |
|
1196 | + // add css and JS for current step |
|
1197 | + $reg_step->enqueue_styles_and_scripts(); |
|
1198 | + // i18n |
|
1199 | + $reg_step->translate_js_strings(); |
|
1200 | + if ($reg_step->is_current_step()) { |
|
1201 | + // the text that appears on the reg step form submit button |
|
1202 | + $reg_step->set_submit_button_text(); |
|
1203 | + } |
|
1204 | + } |
|
1205 | + // dynamically creates hook point like: AHEE__Single_Page_Checkout___initialize_reg_step__attendee_information |
|
1206 | + do_action("AHEE__Single_Page_Checkout___initialize_reg_step__{$this->checkout->current_step->slug()}", $this->checkout->current_step); |
|
1207 | + } |
|
1208 | + |
|
1209 | + |
|
1210 | + |
|
1211 | + /** |
|
1212 | + * _check_form_submission |
|
1213 | + * |
|
1214 | + * @access private |
|
1215 | + * @return boolean |
|
1216 | + */ |
|
1217 | + private function _check_form_submission() |
|
1218 | + { |
|
1219 | + //does this request require the reg form to be generated ? |
|
1220 | + if ($this->checkout->generate_reg_form) { |
|
1221 | + // ever heard that song by Blue Rodeo ? |
|
1222 | + try { |
|
1223 | + $this->checkout->current_step->reg_form = $this->checkout->current_step->generate_reg_form(); |
|
1224 | + // if not displaying a form, then check for form submission |
|
1225 | + if ( |
|
1226 | + $this->checkout->process_form_submission |
|
1227 | + && $this->checkout->current_step->reg_form->was_submitted() |
|
1228 | + ) { |
|
1229 | + // clear out any old data in case this step is being run again |
|
1230 | + $this->checkout->current_step->set_valid_data(array()); |
|
1231 | + // capture submitted form data |
|
1232 | + $this->checkout->current_step->reg_form->receive_form_submission( |
|
1233 | + apply_filters( |
|
1234 | + 'FHEE__Single_Page_Checkout___check_form_submission__request_params', |
|
1235 | + EE_Registry::instance()->REQ->params(), |
|
1236 | + $this->checkout |
|
1237 | + ) |
|
1238 | + ); |
|
1239 | + // validate submitted form data |
|
1240 | + if ( ! $this->checkout->continue_reg || ! $this->checkout->current_step->reg_form->is_valid()) { |
|
1241 | + // thou shall not pass !!! |
|
1242 | + $this->checkout->continue_reg = false; |
|
1243 | + // any form validation errors? |
|
1244 | + if ($this->checkout->current_step->reg_form->submission_error_message() !== '') { |
|
1245 | + $submission_error_messages = array(); |
|
1246 | + // bad, bad, bad registrant |
|
1247 | + foreach ($this->checkout->current_step->reg_form->get_validation_errors_accumulated() as $validation_error) { |
|
1248 | + if ($validation_error instanceof EE_Validation_Error) { |
|
1249 | + $submission_error_messages[] = sprintf( |
|
1250 | + __('%s : %s', 'event_espresso'), |
|
1251 | + $validation_error->get_form_section()->html_label_text(), |
|
1252 | + $validation_error->getMessage() |
|
1253 | + ); |
|
1254 | + } |
|
1255 | + } |
|
1256 | + EE_Error::add_error(implode('<br />', $submission_error_messages), __FILE__, __FUNCTION__, __LINE__); |
|
1257 | + } |
|
1258 | + // well not really... what will happen is we'll just get redirected back to redo the current step |
|
1259 | + $this->go_to_next_step(); |
|
1260 | + return false; |
|
1261 | + } |
|
1262 | + } |
|
1263 | + } catch (EE_Error $e) { |
|
1264 | + $e->get_error(); |
|
1265 | + } |
|
1266 | + } |
|
1267 | + return true; |
|
1268 | + } |
|
1269 | + |
|
1270 | + |
|
1271 | + |
|
1272 | + /** |
|
1273 | + * _process_action |
|
1274 | + * |
|
1275 | + * @access private |
|
1276 | + * @return void |
|
1277 | + * @throws \EE_Error |
|
1278 | + */ |
|
1279 | + private function _process_form_action() |
|
1280 | + { |
|
1281 | + // what cha wanna do? |
|
1282 | + switch ($this->checkout->action) { |
|
1283 | + // AJAX next step reg form |
|
1284 | + case 'display_spco_reg_step' : |
|
1285 | + $this->checkout->redirect = false; |
|
1286 | + if (EE_Registry::instance()->REQ->ajax) { |
|
1287 | + $this->checkout->json_response->set_reg_step_html($this->checkout->current_step->display_reg_form()); |
|
1288 | + } |
|
1289 | + break; |
|
1290 | + default : |
|
1291 | + // meh... do one of those other steps first |
|
1292 | + if ( ! empty($this->checkout->action) && is_callable(array($this->checkout->current_step, $this->checkout->action))) { |
|
1293 | + // dynamically creates hook point like: AHEE__Single_Page_Checkout__before_attendee_information__process_reg_step |
|
1294 | + do_action("AHEE__Single_Page_Checkout__before_{$this->checkout->current_step->slug()}__{$this->checkout->action}", $this->checkout->current_step); |
|
1295 | + // call action on current step |
|
1296 | + if (call_user_func(array($this->checkout->current_step, $this->checkout->action))) { |
|
1297 | + // good registrant, you get to proceed |
|
1298 | + if ( |
|
1299 | + $this->checkout->current_step->success_message() !== '' |
|
1300 | + && apply_filters( |
|
1301 | + 'FHEE__Single_Page_Checkout___process_form_action__display_success', |
|
1302 | + false |
|
1303 | + ) |
|
1304 | + ) { |
|
1305 | + EE_Error::add_success( |
|
1306 | + $this->checkout->current_step->success_message() |
|
1307 | + . '<br />' . $this->checkout->next_step->_instructions() |
|
1308 | + ); |
|
1309 | + } |
|
1310 | + // pack it up, pack it in... |
|
1311 | + $this->_setup_redirect(); |
|
1312 | + } |
|
1313 | + // dynamically creates hook point like: AHEE__Single_Page_Checkout__after_payment_options__process_reg_step |
|
1314 | + do_action("AHEE__Single_Page_Checkout__after_{$this->checkout->current_step->slug()}__{$this->checkout->action}", $this->checkout->current_step); |
|
1315 | + } else { |
|
1316 | + EE_Error::add_error( |
|
1317 | + sprintf( |
|
1318 | + __('The requested form action "%s" does not exist for the current "%s" registration step.', 'event_espresso'), |
|
1319 | + $this->checkout->action, |
|
1320 | + $this->checkout->current_step->name() |
|
1321 | + ), |
|
1322 | + __FILE__, |
|
1323 | + __FUNCTION__, |
|
1324 | + __LINE__ |
|
1325 | + ); |
|
1326 | + } |
|
1327 | + // end default |
|
1328 | + } |
|
1329 | + // store our progress so far |
|
1330 | + $this->checkout->stash_transaction_and_checkout(); |
|
1331 | + // advance to the next step! If you pass GO, collect $200 |
|
1332 | + $this->go_to_next_step(); |
|
1333 | + } |
|
1334 | + |
|
1335 | + |
|
1336 | + |
|
1337 | + /** |
|
1338 | + * add_styles_and_scripts |
|
1339 | + * |
|
1340 | + * @access public |
|
1341 | + * @return void |
|
1342 | + */ |
|
1343 | + public function add_styles_and_scripts() |
|
1344 | + { |
|
1345 | + // i18n |
|
1346 | + $this->translate_js_strings(); |
|
1347 | + if ($this->checkout->admin_request) { |
|
1348 | + add_action('admin_enqueue_scripts', array($this, 'enqueue_styles_and_scripts'), 10); |
|
1349 | + } else { |
|
1350 | + add_action('wp_enqueue_scripts', array($this, 'enqueue_styles_and_scripts'), 10); |
|
1351 | + } |
|
1352 | + } |
|
1353 | + |
|
1354 | + |
|
1355 | + |
|
1356 | + /** |
|
1357 | + * translate_js_strings |
|
1358 | + * |
|
1359 | + * @access public |
|
1360 | + * @return void |
|
1361 | + */ |
|
1362 | + public function translate_js_strings() |
|
1363 | + { |
|
1364 | + EE_Registry::$i18n_js_strings['revisit'] = $this->checkout->revisit; |
|
1365 | + EE_Registry::$i18n_js_strings['e_reg_url_link'] = $this->checkout->reg_url_link; |
|
1366 | + EE_Registry::$i18n_js_strings['server_error'] = __('An unknown error occurred on the server while attempting to process your request. Please refresh the page and try again or contact support.', 'event_espresso'); |
|
1367 | + EE_Registry::$i18n_js_strings['invalid_json_response'] = __('An invalid response was returned from the server while attempting to process your request. Please refresh the page and try again or contact support.', 'event_espresso'); |
|
1368 | + EE_Registry::$i18n_js_strings['validation_error'] = __('There appears to be a problem with the form validation configuration! Please check the admin settings or contact support.', 'event_espresso'); |
|
1369 | + EE_Registry::$i18n_js_strings['invalid_payment_method'] = __('There appears to be a problem with the payment method configuration! Please refresh the page and try again or contact support.', 'event_espresso'); |
|
1370 | + EE_Registry::$i18n_js_strings['reg_step_error'] = __('This registration step could not be completed. Please refresh the page and try again.', 'event_espresso'); |
|
1371 | + EE_Registry::$i18n_js_strings['invalid_coupon'] = __('We\'re sorry but that coupon code does not appear to be valid. If this is incorrect, please contact the site administrator.', 'event_espresso'); |
|
1372 | + EE_Registry::$i18n_js_strings['process_registration'] = sprintf( |
|
1373 | + __('Please wait while we process your registration.%sDo not refresh the page or navigate away while this is happening.%sThank you for your patience.', 'event_espresso'), |
|
1374 | + '<br/>', |
|
1375 | + '<br/>' |
|
1376 | + ); |
|
1377 | + EE_Registry::$i18n_js_strings['language'] = get_bloginfo('language'); |
|
1378 | + EE_Registry::$i18n_js_strings['EESID'] = EE_Registry::instance()->SSN->id(); |
|
1379 | + EE_Registry::$i18n_js_strings['currency'] = EE_Registry::instance()->CFG->currency; |
|
1380 | + EE_Registry::$i18n_js_strings['datepicker_yearRange'] = '-150:+20'; |
|
1381 | + EE_Registry::$i18n_js_strings['timer_years'] = __('years', 'event_espresso'); |
|
1382 | + EE_Registry::$i18n_js_strings['timer_months'] = __('months', 'event_espresso'); |
|
1383 | + EE_Registry::$i18n_js_strings['timer_weeks'] = __('weeks', 'event_espresso'); |
|
1384 | + EE_Registry::$i18n_js_strings['timer_days'] = __('days', 'event_espresso'); |
|
1385 | + EE_Registry::$i18n_js_strings['timer_hours'] = __('hours', 'event_espresso'); |
|
1386 | + EE_Registry::$i18n_js_strings['timer_minutes'] = __('minutes', 'event_espresso'); |
|
1387 | + EE_Registry::$i18n_js_strings['timer_seconds'] = __('seconds', 'event_espresso'); |
|
1388 | + EE_Registry::$i18n_js_strings['timer_year'] = __('year', 'event_espresso'); |
|
1389 | + EE_Registry::$i18n_js_strings['timer_month'] = __('month', 'event_espresso'); |
|
1390 | + EE_Registry::$i18n_js_strings['timer_week'] = __('week', 'event_espresso'); |
|
1391 | + EE_Registry::$i18n_js_strings['timer_day'] = __('day', 'event_espresso'); |
|
1392 | + EE_Registry::$i18n_js_strings['timer_hour'] = __('hour', 'event_espresso'); |
|
1393 | + EE_Registry::$i18n_js_strings['timer_minute'] = __('minute', 'event_espresso'); |
|
1394 | + EE_Registry::$i18n_js_strings['timer_second'] = __('second', 'event_espresso'); |
|
1395 | + EE_Registry::$i18n_js_strings['registration_expiration_notice'] = sprintf( |
|
1396 | + __( |
|
1397 | + '%1$sWe\'re sorry, but your registration time has expired.%2$s%3$s%4$sIf you still wish to complete your registration, please return to the %5$sEvent List%6$sEvent List%7$s and reselect your tickets if available. Please except our apologies for any inconvenience this may have caused.%8$s', |
|
1398 | + 'event_espresso' |
|
1399 | + ), |
|
1400 | + '<h4 class="important-notice">', |
|
1401 | + '</h4>', |
|
1402 | + '<br />', |
|
1403 | + '<p>', |
|
1404 | + '<a href="' . get_post_type_archive_link('espresso_events') . '" title="', |
|
1405 | + '">', |
|
1406 | + '</a>', |
|
1407 | + '</p>' |
|
1408 | + ); |
|
1409 | + EE_Registry::$i18n_js_strings['ajax_submit'] = apply_filters('FHEE__Single_Page_Checkout__translate_js_strings__ajax_submit', true); |
|
1410 | + EE_Registry::$i18n_js_strings['session_extension'] = absint( |
|
1411 | + apply_filters('FHEE__EE_Session__extend_expiration__seconds_added', 10 * MINUTE_IN_SECONDS) |
|
1412 | + ); |
|
1413 | + EE_Registry::$i18n_js_strings['session_expiration'] = gmdate( |
|
1414 | + 'M d, Y H:i:s', EE_Registry::instance()->SSN->expiration() + (get_option('gmt_offset') * HOUR_IN_SECONDS) |
|
1415 | + ); |
|
1416 | + } |
|
1417 | + |
|
1418 | + |
|
1419 | + |
|
1420 | + /** |
|
1421 | + * enqueue_styles_and_scripts |
|
1422 | + * |
|
1423 | + * @access public |
|
1424 | + * @return void |
|
1425 | + * @throws \EE_Error |
|
1426 | + */ |
|
1427 | + public function enqueue_styles_and_scripts() |
|
1428 | + { |
|
1429 | + // load css |
|
1430 | + wp_register_style('single_page_checkout', SPCO_CSS_URL . 'single_page_checkout.css', array(), EVENT_ESPRESSO_VERSION); |
|
1431 | + wp_enqueue_style('single_page_checkout'); |
|
1432 | + // load JS |
|
1433 | + wp_register_script('jquery_plugin', EE_THIRD_PARTY_URL . 'jquery .plugin.min.js', array('jquery'), '1.0.1', true); |
|
1434 | + wp_register_script('jquery_countdown', EE_THIRD_PARTY_URL . 'jquery .countdown.min.js', array('jquery_plugin'), '2.0.2', true); |
|
1435 | + wp_register_script('single_page_checkout', SPCO_JS_URL . 'single_page_checkout.js', array('espresso_core', 'underscore', 'ee_form_section_validation', 'jquery_countdown'), EVENT_ESPRESSO_VERSION, true); |
|
1436 | + if ($this->checkout->registration_form instanceof EE_Form_Section_Proper) { |
|
1437 | + $this->checkout->registration_form->enqueue_js(); |
|
1438 | + } |
|
1439 | + if ($this->checkout->current_step->reg_form instanceof EE_Form_Section_Proper) { |
|
1440 | + $this->checkout->current_step->reg_form->enqueue_js(); |
|
1441 | + } |
|
1442 | + wp_enqueue_script('single_page_checkout'); |
|
1443 | + /** |
|
1444 | + * global action hook for enqueueing styles and scripts with |
|
1445 | + * spco calls. |
|
1446 | + */ |
|
1447 | + do_action('AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts', $this); |
|
1448 | + /** |
|
1449 | + * dynamic action hook for enqueueing styles and scripts with spco calls. |
|
1450 | + * The hook will end up being something like AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__attendee_information |
|
1451 | + */ |
|
1452 | + do_action('AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__' . $this->checkout->current_step->slug(), $this); |
|
1453 | + } |
|
1454 | + |
|
1455 | + |
|
1456 | + |
|
1457 | + /** |
|
1458 | + * display the Registration Single Page Checkout Form |
|
1459 | + * |
|
1460 | + * @access private |
|
1461 | + * @return void |
|
1462 | + * @throws \EE_Error |
|
1463 | + */ |
|
1464 | + private function _display_spco_reg_form() |
|
1465 | + { |
|
1466 | + // if registering via the admin, just display the reg form for the current step |
|
1467 | + if ($this->checkout->admin_request) { |
|
1468 | + EE_Registry::instance()->REQ->add_output($this->checkout->current_step->display_reg_form()); |
|
1469 | + } else { |
|
1470 | + // add powered by EE msg |
|
1471 | + add_action('AHEE__SPCO__reg_form_footer', array('EED_Single_Page_Checkout', 'display_registration_footer')); |
|
1472 | + $empty_cart = count($this->checkout->transaction->registrations($this->checkout->reg_cache_where_params)) < 1 |
|
1473 | + ? true |
|
1474 | + : false; |
|
1475 | + EE_Registry::$i18n_js_strings['empty_cart'] = $empty_cart; |
|
1476 | + $cookies_not_set_msg = ''; |
|
1477 | + if ($empty_cart && ! isset($_COOKIE['ee_cookie_test'])) { |
|
1478 | + $cookies_not_set_msg = apply_filters( |
|
1479 | + 'FHEE__Single_Page_Checkout__display_spco_reg_form__cookies_not_set_msg', |
|
1480 | + sprintf( |
|
1481 | + __( |
|
1482 | + '%1$s%3$sIt appears your browser is not currently set to accept Cookies%4$s%5$sIn order to register for events, you need to enable cookies.%7$sIf you require assistance, then click the following link to learn how to %8$senable cookies%9$s%6$s%2$s', |
|
1483 | + 'event_espresso' |
|
1484 | + ), |
|
1485 | + '<div class="ee-attention">', |
|
1486 | + '</div>', |
|
1487 | + '<h6 class="important-notice">', |
|
1488 | + '</h6>', |
|
1489 | + '<p>', |
|
1490 | + '</p>', |
|
1491 | + '<br />', |
|
1492 | + '<a href="http://www.whatarecookies.com/enable.asp" target="_blank">', |
|
1493 | + '</a>' |
|
1494 | + ) |
|
1495 | + ); |
|
1496 | + } |
|
1497 | + $this->checkout->registration_form = new EE_Form_Section_Proper( |
|
1498 | + array( |
|
1499 | + 'name' => 'single-page-checkout', |
|
1500 | + 'html_id' => 'ee-single-page-checkout-dv', |
|
1501 | + 'layout_strategy' => |
|
1502 | + new EE_Template_Layout( |
|
1503 | + array( |
|
1504 | + 'layout_template_file' => SPCO_TEMPLATES_PATH . 'registration_page_wrapper.template.php', |
|
1505 | + 'template_args' => array( |
|
1506 | + 'empty_cart' => $empty_cart, |
|
1507 | + 'revisit' => $this->checkout->revisit, |
|
1508 | + 'reg_steps' => $this->checkout->reg_steps, |
|
1509 | + 'next_step' => $this->checkout->next_step instanceof EE_SPCO_Reg_Step |
|
1510 | + ? $this->checkout->next_step->slug() |
|
1511 | + : '', |
|
1512 | + 'cancel_page_url' => $this->checkout->cancel_page_url, |
|
1513 | + 'empty_msg' => apply_filters( |
|
1514 | + 'FHEE__Single_Page_Checkout__display_spco_reg_form__empty_msg', |
|
1515 | + sprintf( |
|
1516 | + __('You need to %1$sReturn to Events list%2$sselect at least one event%3$s before you can proceed with the registration process.', |
|
1517 | + 'event_espresso'), |
|
1518 | + '<a href="' . get_post_type_archive_link('espresso_events') . '" title="', |
|
1519 | + '">', |
|
1520 | + '</a>' |
|
1521 | + ) |
|
1522 | + ), |
|
1523 | + 'cookies_not_set_msg' => $cookies_not_set_msg, |
|
1524 | + 'registration_time_limit' => $this->checkout->get_registration_time_limit(), |
|
1525 | + 'session_expiration' => gmdate( |
|
1526 | + 'M d, Y H:i:s', |
|
1527 | + EE_Registry::instance()->SSN->expiration() |
|
1528 | + + (get_option('gmt_offset') * HOUR_IN_SECONDS) |
|
1529 | + ), |
|
1530 | + ), |
|
1531 | + ) |
|
1532 | + ), |
|
1533 | + ) |
|
1534 | + ); |
|
1535 | + // load template and add to output sent that gets filtered into the_content() |
|
1536 | + EE_Registry::instance()->REQ->add_output($this->checkout->registration_form->get_html()); |
|
1537 | + } |
|
1538 | + } |
|
1539 | + |
|
1540 | + |
|
1541 | + |
|
1542 | + /** |
|
1543 | + * add_extra_finalize_registration_inputs |
|
1544 | + * |
|
1545 | + * @access public |
|
1546 | + * @param $next_step |
|
1547 | + * @internal param string $label |
|
1548 | + * @return void |
|
1549 | + */ |
|
1550 | + public function add_extra_finalize_registration_inputs($next_step) |
|
1551 | + { |
|
1552 | + if ($next_step === 'finalize_registration') { |
|
1553 | + echo '<div id="spco-extra-finalize_registration-inputs-dv"></div>'; |
|
1554 | + } |
|
1555 | + } |
|
1556 | + |
|
1557 | + |
|
1558 | + |
|
1559 | + /** |
|
1560 | + * display_registration_footer |
|
1561 | + * |
|
1562 | + * @access public |
|
1563 | + * @return string |
|
1564 | + */ |
|
1565 | + public static function display_registration_footer() |
|
1566 | + { |
|
1567 | + if ( |
|
1568 | + apply_filters( |
|
1569 | + 'FHEE__EE_Front__Controller__show_reg_footer', |
|
1570 | + EE_Registry::instance()->CFG->admin->show_reg_footer |
|
1571 | + ) |
|
1572 | + ) { |
|
1573 | + add_filter( |
|
1574 | + 'FHEE__EEH_Template__powered_by_event_espresso__url', |
|
1575 | + function ($url) { |
|
1576 | + return apply_filters('FHEE__EE_Front_Controller__registration_footer__url', $url); |
|
1577 | + } |
|
1578 | + ); |
|
1579 | + echo apply_filters( |
|
1580 | + 'FHEE__EE_Front_Controller__display_registration_footer', |
|
1581 | + \EEH_Template::powered_by_event_espresso( |
|
1582 | + '', |
|
1583 | + 'espresso-registration-footer-dv', |
|
1584 | + array('utm_content' => 'registration_checkout') |
|
1585 | + ) |
|
1586 | + ); |
|
1587 | + } |
|
1588 | + return ''; |
|
1589 | + } |
|
1590 | + |
|
1591 | + |
|
1592 | + |
|
1593 | + /** |
|
1594 | + * unlock_transaction |
|
1595 | + * |
|
1596 | + * @access public |
|
1597 | + * @return void |
|
1598 | + * @throws \EE_Error |
|
1599 | + */ |
|
1600 | + public function unlock_transaction() |
|
1601 | + { |
|
1602 | + if ($this->checkout->transaction instanceof EE_Transaction) { |
|
1603 | + $this->checkout->transaction->unlock(); |
|
1604 | + } |
|
1605 | + } |
|
1606 | + |
|
1607 | + |
|
1608 | + |
|
1609 | + /** |
|
1610 | + * _setup_redirect |
|
1611 | + * |
|
1612 | + * @access private |
|
1613 | + * @return void |
|
1614 | + */ |
|
1615 | + private function _setup_redirect() |
|
1616 | + { |
|
1617 | + if ($this->checkout->continue_reg && $this->checkout->next_step instanceof EE_SPCO_Reg_Step) { |
|
1618 | + $this->checkout->redirect = true; |
|
1619 | + if (empty($this->checkout->redirect_url)) { |
|
1620 | + $this->checkout->redirect_url = $this->checkout->next_step->reg_step_url(); |
|
1621 | + } |
|
1622 | + $this->checkout->redirect_url = apply_filters( |
|
1623 | + 'FHEE__EED_Single_Page_Checkout___setup_redirect__checkout_redirect_url', |
|
1624 | + $this->checkout->redirect_url, |
|
1625 | + $this->checkout |
|
1626 | + ); |
|
1627 | + } |
|
1628 | + } |
|
1629 | + |
|
1630 | + |
|
1631 | + |
|
1632 | + /** |
|
1633 | + * handle ajax message responses and redirects |
|
1634 | + * |
|
1635 | + * @access public |
|
1636 | + * @return void |
|
1637 | + * @throws \EE_Error |
|
1638 | + */ |
|
1639 | + public function go_to_next_step() |
|
1640 | + { |
|
1641 | + if (EE_Registry::instance()->REQ->ajax) { |
|
1642 | + // capture contents of output buffer we started earlier in the request, and insert into JSON response |
|
1643 | + $this->checkout->json_response->set_unexpected_errors(ob_get_clean()); |
|
1644 | + } |
|
1645 | + $this->unlock_transaction(); |
|
1646 | + // just return for these conditions |
|
1647 | + if ( |
|
1648 | + $this->checkout->admin_request |
|
1649 | + || $this->checkout->action === 'redirect_form' |
|
1650 | + || $this->checkout->action === 'update_checkout' |
|
1651 | + ) { |
|
1652 | + return; |
|
1653 | + } |
|
1654 | + // AJAX response |
|
1655 | + $this->_handle_json_response(); |
|
1656 | + // redirect to next step or the Thank You page |
|
1657 | + $this->_handle_html_redirects(); |
|
1658 | + // hmmm... must be something wrong, so let's just display the form again ! |
|
1659 | + $this->_display_spco_reg_form(); |
|
1660 | + } |
|
1661 | + |
|
1662 | + |
|
1663 | + |
|
1664 | + /** |
|
1665 | + * _handle_json_response |
|
1666 | + * |
|
1667 | + * @access protected |
|
1668 | + * @return void |
|
1669 | + */ |
|
1670 | + protected function _handle_json_response() |
|
1671 | + { |
|
1672 | + // if this is an ajax request |
|
1673 | + if (EE_Registry::instance()->REQ->ajax) { |
|
1674 | + // DEBUG LOG |
|
1675 | + //$this->checkout->log( |
|
1676 | + // __CLASS__, __FUNCTION__, __LINE__, |
|
1677 | + // array( |
|
1678 | + // 'json_response_redirect_url' => $this->checkout->json_response->redirect_url(), |
|
1679 | + // 'redirect' => $this->checkout->redirect, |
|
1680 | + // 'continue_reg' => $this->checkout->continue_reg, |
|
1681 | + // ) |
|
1682 | + //); |
|
1683 | + $this->checkout->json_response->set_registration_time_limit( |
|
1684 | + $this->checkout->get_registration_time_limit() |
|
1685 | + ); |
|
1686 | + $this->checkout->json_response->set_payment_amount($this->checkout->amount_owing); |
|
1687 | + // just send the ajax ( |
|
1688 | + $json_response = apply_filters( |
|
1689 | + 'FHEE__EE_Single_Page_Checkout__JSON_response', |
|
1690 | + $this->checkout->json_response |
|
1691 | + ); |
|
1692 | + echo $json_response; |
|
1693 | + exit(); |
|
1694 | + } |
|
1695 | + } |
|
1696 | + |
|
1697 | + |
|
1698 | + |
|
1699 | + /** |
|
1700 | + * _handle_redirects |
|
1701 | + * |
|
1702 | + * @access protected |
|
1703 | + * @return void |
|
1704 | + */ |
|
1705 | + protected function _handle_html_redirects() |
|
1706 | + { |
|
1707 | + // going somewhere ? |
|
1708 | + if ($this->checkout->redirect && ! empty($this->checkout->redirect_url)) { |
|
1709 | + // store notices in a transient |
|
1710 | + EE_Error::get_notices(false, true, true); |
|
1711 | + // DEBUG LOG |
|
1712 | + //$this->checkout->log( |
|
1713 | + // __CLASS__, __FUNCTION__, __LINE__, |
|
1714 | + // array( |
|
1715 | + // 'headers_sent' => headers_sent(), |
|
1716 | + // 'redirect_url' => $this->checkout->redirect_url, |
|
1717 | + // 'headers_list' => headers_list(), |
|
1718 | + // ) |
|
1719 | + //); |
|
1720 | + wp_safe_redirect($this->checkout->redirect_url); |
|
1721 | + exit(); |
|
1722 | + } |
|
1723 | + } |
|
1724 | + |
|
1725 | + |
|
1726 | + |
|
1727 | + /** |
|
1728 | + * set_checkout_anchor |
|
1729 | + * |
|
1730 | + * @access public |
|
1731 | + * @return void |
|
1732 | + */ |
|
1733 | + public function set_checkout_anchor() |
|
1734 | + { |
|
1735 | + echo '<a id="checkout" style="float: left; margin-left: -999em;"></a>'; |
|
1736 | + } |
|
1737 | 1737 | |
1738 | 1738 | |
1739 | 1739 |
@@ -22,19 +22,19 @@ discard block |
||
22 | 22 | */ |
23 | 23 | private static $_instance; |
24 | 24 | |
25 | - /** |
|
26 | - * @var CacheStorageInterface $cache_storage |
|
27 | - */ |
|
28 | - protected $cache_storage; |
|
29 | - |
|
30 | - /** |
|
31 | - * EE_Encryption object |
|
32 | - * |
|
33 | - * @var EE_Encryption |
|
34 | - */ |
|
35 | - protected $encryption; |
|
36 | - |
|
37 | - /** |
|
25 | + /** |
|
26 | + * @var CacheStorageInterface $cache_storage |
|
27 | + */ |
|
28 | + protected $cache_storage; |
|
29 | + |
|
30 | + /** |
|
31 | + * EE_Encryption object |
|
32 | + * |
|
33 | + * @var EE_Encryption |
|
34 | + */ |
|
35 | + protected $encryption; |
|
36 | + |
|
37 | + /** |
|
38 | 38 | * the session id |
39 | 39 | * @var string |
40 | 40 | */ |
@@ -65,12 +65,12 @@ discard block |
||
65 | 65 | */ |
66 | 66 | private $_expiration; |
67 | 67 | |
68 | - /** |
|
69 | - * whether or not session has expired at some point |
|
70 | - * |
|
71 | - * @var boolean |
|
72 | - */ |
|
73 | - private $_expired = false; |
|
68 | + /** |
|
69 | + * whether or not session has expired at some point |
|
70 | + * |
|
71 | + * @var boolean |
|
72 | + */ |
|
73 | + private $_expired = false; |
|
74 | 74 | |
75 | 75 | /** |
76 | 76 | * current time as Unix timestamp in GMT |
@@ -107,30 +107,30 @@ discard block |
||
107 | 107 | * @var array |
108 | 108 | */ |
109 | 109 | private $_default_session_vars = array ( |
110 | - 'id' => null, |
|
111 | - 'user_id' => null, |
|
112 | - 'ip_address' => null, |
|
113 | - 'user_agent' => null, |
|
114 | - 'init_access' => null, |
|
115 | - 'last_access' => null, |
|
116 | - 'expiration' => null, |
|
117 | - 'pages_visited' => array(), |
|
110 | + 'id' => null, |
|
111 | + 'user_id' => null, |
|
112 | + 'ip_address' => null, |
|
113 | + 'user_agent' => null, |
|
114 | + 'init_access' => null, |
|
115 | + 'last_access' => null, |
|
116 | + 'expiration' => null, |
|
117 | + 'pages_visited' => array(), |
|
118 | 118 | ); |
119 | 119 | |
120 | 120 | |
121 | 121 | |
122 | 122 | /** |
123 | 123 | * @singleton method used to instantiate class object |
124 | - * @param CacheStorageInterface $cache_storage |
|
125 | - * @param \EE_Encryption $encryption |
|
124 | + * @param CacheStorageInterface $cache_storage |
|
125 | + * @param \EE_Encryption $encryption |
|
126 | 126 | * @return EE_Session |
127 | 127 | * @throws InvalidSessionDataException |
128 | 128 | * @throws \EE_Error |
129 | 129 | */ |
130 | 130 | public static function instance( |
131 | - CacheStorageInterface $cache_storage = null, |
|
132 | - EE_Encryption $encryption = null |
|
133 | - ) { |
|
131 | + CacheStorageInterface $cache_storage = null, |
|
132 | + EE_Encryption $encryption = null |
|
133 | + ) { |
|
134 | 134 | // check if class object is instantiated |
135 | 135 | // session loading is turned ON by default, but prior to the init hook, can be turned back OFF via: |
136 | 136 | // add_filter( 'FHEE_load_EE_Session', '__return_false' ); |
@@ -143,10 +143,10 @@ discard block |
||
143 | 143 | |
144 | 144 | |
145 | 145 | /** |
146 | - * protected constructor to prevent direct creation |
|
147 | - * |
|
148 | - * @param CacheStorageInterface $cache_storage |
|
149 | - * @param \EE_Encryption $encryption |
|
146 | + * protected constructor to prevent direct creation |
|
147 | + * |
|
148 | + * @param CacheStorageInterface $cache_storage |
|
149 | + * @param \EE_Encryption $encryption |
|
150 | 150 | * @throws \EE_Error |
151 | 151 | * @throws \EventEspresso\core\exceptions\InvalidSessionDataException |
152 | 152 | */ |
@@ -181,59 +181,59 @@ discard block |
||
181 | 181 | $this->{$var_name} = $session_setting; |
182 | 182 | } |
183 | 183 | } |
184 | - $this->cache_storage = $cache_storage; |
|
185 | - // are we using encryption? |
|
186 | - $this->_use_encryption = $encryption instanceof EE_Encryption && EE_Registry::instance()->CFG->admin->encode_session_data(); |
|
187 | - // \EEH_Debug_Tools::printr($this->_use_encryption, '$this->_use_encryption', __FILE__, __LINE__); |
|
188 | - // encrypt data via: $this->encryption->encrypt(); |
|
189 | - $this->encryption = $encryption; |
|
184 | + $this->cache_storage = $cache_storage; |
|
185 | + // are we using encryption? |
|
186 | + $this->_use_encryption = $encryption instanceof EE_Encryption && EE_Registry::instance()->CFG->admin->encode_session_data(); |
|
187 | + // \EEH_Debug_Tools::printr($this->_use_encryption, '$this->_use_encryption', __FILE__, __LINE__); |
|
188 | + // encrypt data via: $this->encryption->encrypt(); |
|
189 | + $this->encryption = $encryption; |
|
190 | 190 | // filter hook allows outside functions/classes/plugins to change default empty cart |
191 | 191 | $extra_default_session_vars = apply_filters( 'FHEE__EE_Session__construct__extra_default_session_vars', array() ); |
192 | 192 | array_merge( $this->_default_session_vars, $extra_default_session_vars ); |
193 | 193 | // apply default session vars |
194 | 194 | $this->_set_defaults(); |
195 | - add_action('AHEE__EE_System__initialize', array($this, 'open_session')); |
|
196 | - // check request for 'clear_session' param |
|
195 | + add_action('AHEE__EE_System__initialize', array($this, 'open_session')); |
|
196 | + // check request for 'clear_session' param |
|
197 | 197 | add_action( 'AHEE__EE_Request_Handler__construct__complete', array( $this, 'wp_loaded' )); |
198 | 198 | // once everything is all said and done, |
199 | 199 | add_action( 'shutdown', array( $this, 'update' ), 100 ); |
200 | - $this->configure_garbage_collection_filters(); |
|
200 | + $this->configure_garbage_collection_filters(); |
|
201 | 201 | } |
202 | 202 | |
203 | 203 | |
204 | 204 | |
205 | - /** |
|
206 | - * @return void |
|
207 | - * @throws \EventEspresso\core\exceptions\InvalidSessionDataException |
|
208 | - * @throws \EE_Error |
|
209 | - */ |
|
205 | + /** |
|
206 | + * @return void |
|
207 | + * @throws \EventEspresso\core\exceptions\InvalidSessionDataException |
|
208 | + * @throws \EE_Error |
|
209 | + */ |
|
210 | 210 | public function open_session() { |
211 | - // check for existing session and retrieve it from db |
|
212 | - if ( ! $this->_espresso_session()) { |
|
213 | - // or just start a new one |
|
214 | - $this->_create_espresso_session(); |
|
215 | - } |
|
216 | - } |
|
211 | + // check for existing session and retrieve it from db |
|
212 | + if ( ! $this->_espresso_session()) { |
|
213 | + // or just start a new one |
|
214 | + $this->_create_espresso_session(); |
|
215 | + } |
|
216 | + } |
|
217 | 217 | |
218 | 218 | |
219 | 219 | |
220 | - /** |
|
221 | - * @return bool |
|
222 | - */ |
|
223 | - public function expired() |
|
224 | - { |
|
225 | - return $this->_expired; |
|
226 | - } |
|
220 | + /** |
|
221 | + * @return bool |
|
222 | + */ |
|
223 | + public function expired() |
|
224 | + { |
|
225 | + return $this->_expired; |
|
226 | + } |
|
227 | 227 | |
228 | 228 | |
229 | 229 | |
230 | - /** |
|
231 | - * @return void |
|
232 | - */ |
|
233 | - public function reset_expired() |
|
234 | - { |
|
235 | - $this->_expired = false; |
|
236 | - } |
|
230 | + /** |
|
231 | + * @return void |
|
232 | + */ |
|
233 | + public function reset_expired() |
|
234 | + { |
|
235 | + $this->_expired = false; |
|
236 | + } |
|
237 | 237 | |
238 | 238 | |
239 | 239 | /** |
@@ -245,24 +245,24 @@ discard block |
||
245 | 245 | |
246 | 246 | |
247 | 247 | |
248 | - /** |
|
249 | - * @return int |
|
250 | - */ |
|
251 | - public function extension() |
|
252 | - { |
|
253 | - return apply_filters('FHEE__EE_Session__extend_expiration__seconds_added', (10 * MINUTE_IN_SECONDS)); |
|
254 | - } |
|
248 | + /** |
|
249 | + * @return int |
|
250 | + */ |
|
251 | + public function extension() |
|
252 | + { |
|
253 | + return apply_filters('FHEE__EE_Session__extend_expiration__seconds_added', (10 * MINUTE_IN_SECONDS)); |
|
254 | + } |
|
255 | 255 | |
256 | 256 | |
257 | 257 | |
258 | - /** |
|
259 | - * @param int $time number of seconds to add to session expiration |
|
260 | - */ |
|
261 | - public function extend_expiration($time = 0) |
|
262 | - { |
|
263 | - $time = $time ? $time : $this->extension(); |
|
264 | - $this->_expiration += absint($time); |
|
265 | - } |
|
258 | + /** |
|
259 | + * @param int $time number of seconds to add to session expiration |
|
260 | + */ |
|
261 | + public function extend_expiration($time = 0) |
|
262 | + { |
|
263 | + $time = $time ? $time : $this->extension(); |
|
264 | + $this->_expiration += absint($time); |
|
265 | + } |
|
266 | 266 | |
267 | 267 | |
268 | 268 | |
@@ -306,15 +306,15 @@ discard block |
||
306 | 306 | |
307 | 307 | |
308 | 308 | |
309 | - /** |
|
310 | - * @param \EE_Cart $cart |
|
311 | - * @return bool |
|
312 | - */ |
|
313 | - public function set_cart(EE_Cart $cart) |
|
314 | - { |
|
315 | - $this->_session_data['cart'] = $cart; |
|
316 | - return true; |
|
317 | - } |
|
309 | + /** |
|
310 | + * @param \EE_Cart $cart |
|
311 | + * @return bool |
|
312 | + */ |
|
313 | + public function set_cart(EE_Cart $cart) |
|
314 | + { |
|
315 | + $this->_session_data['cart'] = $cart; |
|
316 | + return true; |
|
317 | + } |
|
318 | 318 | |
319 | 319 | |
320 | 320 | |
@@ -322,7 +322,7 @@ discard block |
||
322 | 322 | * reset_cart |
323 | 323 | */ |
324 | 324 | public function reset_cart() { |
325 | - do_action('AHEE__EE_Session__reset_cart__before_reset', $this); |
|
325 | + do_action('AHEE__EE_Session__reset_cart__before_reset', $this); |
|
326 | 326 | $this->_session_data['cart'] = NULL; |
327 | 327 | } |
328 | 328 | |
@@ -332,9 +332,9 @@ discard block |
||
332 | 332 | * @return \EE_Cart |
333 | 333 | */ |
334 | 334 | public function cart() { |
335 | - return isset($this->_session_data['cart']) && $this->_session_data['cart'] instanceof EE_Cart |
|
336 | - ? $this->_session_data['cart'] |
|
337 | - : null; |
|
335 | + return isset($this->_session_data['cart']) && $this->_session_data['cart'] instanceof EE_Cart |
|
336 | + ? $this->_session_data['cart'] |
|
337 | + : null; |
|
338 | 338 | } |
339 | 339 | |
340 | 340 | |
@@ -354,7 +354,7 @@ discard block |
||
354 | 354 | * reset_checkout |
355 | 355 | */ |
356 | 356 | public function reset_checkout() { |
357 | - do_action('AHEE__EE_Session__reset_checkout__before_reset', $this); |
|
357 | + do_action('AHEE__EE_Session__reset_checkout__before_reset', $this); |
|
358 | 358 | $this->_session_data['checkout'] = NULL; |
359 | 359 | } |
360 | 360 | |
@@ -364,9 +364,9 @@ discard block |
||
364 | 364 | * @return \EE_Checkout |
365 | 365 | */ |
366 | 366 | public function checkout() { |
367 | - return isset($this->_session_data['checkout']) && $this->_session_data['checkout'] instanceof EE_Checkout |
|
368 | - ? $this->_session_data['checkout'] |
|
369 | - : null; |
|
367 | + return isset($this->_session_data['checkout']) && $this->_session_data['checkout'] instanceof EE_Checkout |
|
368 | + ? $this->_session_data['checkout'] |
|
369 | + : null; |
|
370 | 370 | } |
371 | 371 | |
372 | 372 | |
@@ -389,7 +389,7 @@ discard block |
||
389 | 389 | * reset_transaction |
390 | 390 | */ |
391 | 391 | public function reset_transaction() { |
392 | - do_action('AHEE__EE_Session__reset_transaction__before_reset', $this); |
|
392 | + do_action('AHEE__EE_Session__reset_transaction__before_reset', $this); |
|
393 | 393 | $this->_session_data['transaction'] = NULL; |
394 | 394 | } |
395 | 395 | |
@@ -399,10 +399,10 @@ discard block |
||
399 | 399 | * @return \EE_Transaction |
400 | 400 | */ |
401 | 401 | public function transaction() { |
402 | - return isset($this->_session_data['transaction']) |
|
403 | - && $this->_session_data['transaction'] instanceof EE_Transaction |
|
404 | - ? $this->_session_data['transaction'] |
|
405 | - : null; |
|
402 | + return isset($this->_session_data['transaction']) |
|
403 | + && $this->_session_data['transaction'] instanceof EE_Transaction |
|
404 | + ? $this->_session_data['transaction'] |
|
405 | + : null; |
|
406 | 406 | } |
407 | 407 | |
408 | 408 | |
@@ -479,16 +479,16 @@ discard block |
||
479 | 479 | // set the "user agent" |
480 | 480 | $this->_user_agent = isset($_SERVER['HTTP_USER_AGENT']) ? esc_attr( $_SERVER['HTTP_USER_AGENT'] ) : FALSE; |
481 | 481 | // now let's retrieve what's in the db |
482 | - $session_data = $this->_retrieve_session_data(); |
|
483 | - if (! empty($session_data)) { |
|
484 | - // get the current time in UTC |
|
482 | + $session_data = $this->_retrieve_session_data(); |
|
483 | + if (! empty($session_data)) { |
|
484 | + // get the current time in UTC |
|
485 | 485 | $this->_time = isset( $this->_time ) ? $this->_time : time(); |
486 | 486 | // and reset the session expiration |
487 | 487 | $this->_expiration = isset( $session_data['expiration'] ) |
488 | 488 | ? $session_data['expiration'] |
489 | 489 | : $this->_time + $this->_lifespan; |
490 | 490 | } else { |
491 | - // set initial site access time and the session expiration |
|
491 | + // set initial site access time and the session expiration |
|
492 | 492 | $this->_set_init_access_and_expiration(); |
493 | 493 | // set referer |
494 | 494 | $this->_session_data[ 'pages_visited' ][ $this->_session_data['init_access'] ] = isset( $_SERVER['HTTP_REFERER'] ) |
@@ -497,14 +497,14 @@ discard block |
||
497 | 497 | // no previous session = go back and create one (on top of the data above) |
498 | 498 | return FALSE; |
499 | 499 | } |
500 | - // now the user agent |
|
500 | + // now the user agent |
|
501 | 501 | if ( $session_data['user_agent'] !== $this->_user_agent ) { |
502 | 502 | return FALSE; |
503 | 503 | } |
504 | 504 | // wait a minute... how old are you? |
505 | 505 | if ( $this->_time > $this->_expiration ) { |
506 | 506 | // yer too old fer me! |
507 | - $this->_expired = true; |
|
507 | + $this->_expired = true; |
|
508 | 508 | // wipe out everything that isn't a default session datum |
509 | 509 | $this->clear_session( __CLASS__, __FUNCTION__ ); |
510 | 510 | } |
@@ -516,101 +516,101 @@ discard block |
||
516 | 516 | |
517 | 517 | |
518 | 518 | |
519 | - /** |
|
520 | - * _get_session_data |
|
521 | - * Retrieves the session data, and attempts to correct any encoding issues that can occur due to improperly setup databases |
|
522 | - * |
|
523 | - * @return array |
|
524 | - * @throws \EventEspresso\core\exceptions\InvalidSessionDataException |
|
525 | - */ |
|
526 | - protected function _retrieve_session_data() |
|
527 | - { |
|
528 | - $ssn_key = EE_Session::session_id_prefix . $this->_sid; |
|
529 | - try { |
|
530 | - // we're using WP's Transient API to store session data using the PHP session ID as the option name |
|
531 | - $session_data = $this->cache_storage->get($ssn_key, false); |
|
532 | - if (empty($session_data)) { |
|
533 | - return array(); |
|
534 | - } |
|
535 | - if (apply_filters('FHEE__EE_Session___perform_session_id_hash_check', WP_DEBUG)) { |
|
536 | - $hash_check = $this->cache_storage->get( |
|
537 | - EE_Session::hash_check_prefix . $this->_sid, |
|
538 | - false |
|
539 | - ); |
|
540 | - if ($hash_check && $hash_check !== md5($session_data)) { |
|
541 | - EE_Error::add_error( |
|
542 | - sprintf( |
|
543 | - __( |
|
544 | - 'The stored data for session %1$s failed to pass a hash check and therefore appears to be invalid.', |
|
545 | - 'event_espresso' |
|
546 | - ), |
|
547 | - EE_Session::session_id_prefix . $this->_sid |
|
548 | - ), |
|
549 | - __FILE__, __FUNCTION__, __LINE__ |
|
550 | - ); |
|
551 | - } |
|
552 | - } |
|
553 | - } catch (Exception $e) { |
|
554 | - // let's just eat that error for now and attempt to correct any corrupted data |
|
555 | - global $wpdb; |
|
556 | - $row = $wpdb->get_row( |
|
557 | - $wpdb->prepare( |
|
558 | - "SELECT option_value FROM {$wpdb->options} WHERE option_name = %s LIMIT 1", |
|
559 | - '_transient_' . $ssn_key |
|
560 | - ) |
|
561 | - ); |
|
562 | - $session_data = is_object($row) ? $row->option_value : null; |
|
563 | - if ($session_data) { |
|
564 | - $session_data = preg_replace_callback( |
|
565 | - '!s:(d+):"(.*?)";!', |
|
566 | - function ($match) { |
|
567 | - return $match[1] === strlen($match[2]) |
|
568 | - ? $match[0] |
|
569 | - : 's:' . strlen($match[2]) . ':"' . $match[2] . '";'; |
|
570 | - }, |
|
571 | - $session_data |
|
572 | - ); |
|
573 | - } |
|
574 | - $session_data = maybe_unserialize($session_data); |
|
575 | - } |
|
576 | - // in case the data is encoded... try to decode it |
|
577 | - $session_data = $this->encryption instanceof EE_Encryption |
|
578 | - ? $this->encryption->base64_string_decode($session_data) |
|
579 | - : $session_data; |
|
580 | - |
|
581 | - if ( ! is_array($session_data)) { |
|
582 | - try { |
|
583 | - $session_data = maybe_unserialize($session_data); |
|
584 | - } catch (Exception $e) { |
|
585 | - $msg = esc_html__( |
|
586 | - 'An error occurred while attempting to unserialize the session data.', |
|
587 | - 'event_espresso' |
|
588 | - ); |
|
589 | - $msg .= WP_DEBUG |
|
590 | - ? '<br><pre>' . print_r($session_data, true) . '</pre><br>' . $this->find_serialize_error($session_data) |
|
591 | - : ''; |
|
592 | - throw new InvalidSessionDataException($msg, 0, $e); |
|
593 | - } |
|
594 | - } |
|
595 | - // just a check to make sure the session array is indeed an array |
|
596 | - if ( ! is_array($session_data)) { |
|
597 | - // no?!?! then something is wrong |
|
598 | - $msg = esc_html__( |
|
599 | - 'The session data is missing, invalid, or corrupted.', |
|
600 | - 'event_espresso' |
|
601 | - ); |
|
602 | - $msg .= WP_DEBUG |
|
603 | - ? '<br><pre>' . print_r($session_data, true) . '</pre><br>' . $this->find_serialize_error($session_data) |
|
604 | - : ''; |
|
605 | - throw new InvalidSessionDataException($msg); |
|
606 | - } |
|
607 | - if ( isset($session_data['transaction'] ) && absint($session_data['transaction'] ) !== 0 ) { |
|
608 | - $session_data['transaction'] = EEM_Transaction::instance()->get_one_by_ID( |
|
609 | - $session_data['transaction'] |
|
610 | - ); |
|
611 | - } |
|
612 | - return $session_data; |
|
613 | - } |
|
519 | + /** |
|
520 | + * _get_session_data |
|
521 | + * Retrieves the session data, and attempts to correct any encoding issues that can occur due to improperly setup databases |
|
522 | + * |
|
523 | + * @return array |
|
524 | + * @throws \EventEspresso\core\exceptions\InvalidSessionDataException |
|
525 | + */ |
|
526 | + protected function _retrieve_session_data() |
|
527 | + { |
|
528 | + $ssn_key = EE_Session::session_id_prefix . $this->_sid; |
|
529 | + try { |
|
530 | + // we're using WP's Transient API to store session data using the PHP session ID as the option name |
|
531 | + $session_data = $this->cache_storage->get($ssn_key, false); |
|
532 | + if (empty($session_data)) { |
|
533 | + return array(); |
|
534 | + } |
|
535 | + if (apply_filters('FHEE__EE_Session___perform_session_id_hash_check', WP_DEBUG)) { |
|
536 | + $hash_check = $this->cache_storage->get( |
|
537 | + EE_Session::hash_check_prefix . $this->_sid, |
|
538 | + false |
|
539 | + ); |
|
540 | + if ($hash_check && $hash_check !== md5($session_data)) { |
|
541 | + EE_Error::add_error( |
|
542 | + sprintf( |
|
543 | + __( |
|
544 | + 'The stored data for session %1$s failed to pass a hash check and therefore appears to be invalid.', |
|
545 | + 'event_espresso' |
|
546 | + ), |
|
547 | + EE_Session::session_id_prefix . $this->_sid |
|
548 | + ), |
|
549 | + __FILE__, __FUNCTION__, __LINE__ |
|
550 | + ); |
|
551 | + } |
|
552 | + } |
|
553 | + } catch (Exception $e) { |
|
554 | + // let's just eat that error for now and attempt to correct any corrupted data |
|
555 | + global $wpdb; |
|
556 | + $row = $wpdb->get_row( |
|
557 | + $wpdb->prepare( |
|
558 | + "SELECT option_value FROM {$wpdb->options} WHERE option_name = %s LIMIT 1", |
|
559 | + '_transient_' . $ssn_key |
|
560 | + ) |
|
561 | + ); |
|
562 | + $session_data = is_object($row) ? $row->option_value : null; |
|
563 | + if ($session_data) { |
|
564 | + $session_data = preg_replace_callback( |
|
565 | + '!s:(d+):"(.*?)";!', |
|
566 | + function ($match) { |
|
567 | + return $match[1] === strlen($match[2]) |
|
568 | + ? $match[0] |
|
569 | + : 's:' . strlen($match[2]) . ':"' . $match[2] . '";'; |
|
570 | + }, |
|
571 | + $session_data |
|
572 | + ); |
|
573 | + } |
|
574 | + $session_data = maybe_unserialize($session_data); |
|
575 | + } |
|
576 | + // in case the data is encoded... try to decode it |
|
577 | + $session_data = $this->encryption instanceof EE_Encryption |
|
578 | + ? $this->encryption->base64_string_decode($session_data) |
|
579 | + : $session_data; |
|
580 | + |
|
581 | + if ( ! is_array($session_data)) { |
|
582 | + try { |
|
583 | + $session_data = maybe_unserialize($session_data); |
|
584 | + } catch (Exception $e) { |
|
585 | + $msg = esc_html__( |
|
586 | + 'An error occurred while attempting to unserialize the session data.', |
|
587 | + 'event_espresso' |
|
588 | + ); |
|
589 | + $msg .= WP_DEBUG |
|
590 | + ? '<br><pre>' . print_r($session_data, true) . '</pre><br>' . $this->find_serialize_error($session_data) |
|
591 | + : ''; |
|
592 | + throw new InvalidSessionDataException($msg, 0, $e); |
|
593 | + } |
|
594 | + } |
|
595 | + // just a check to make sure the session array is indeed an array |
|
596 | + if ( ! is_array($session_data)) { |
|
597 | + // no?!?! then something is wrong |
|
598 | + $msg = esc_html__( |
|
599 | + 'The session data is missing, invalid, or corrupted.', |
|
600 | + 'event_espresso' |
|
601 | + ); |
|
602 | + $msg .= WP_DEBUG |
|
603 | + ? '<br><pre>' . print_r($session_data, true) . '</pre><br>' . $this->find_serialize_error($session_data) |
|
604 | + : ''; |
|
605 | + throw new InvalidSessionDataException($msg); |
|
606 | + } |
|
607 | + if ( isset($session_data['transaction'] ) && absint($session_data['transaction'] ) !== 0 ) { |
|
608 | + $session_data['transaction'] = EEM_Transaction::instance()->get_one_by_ID( |
|
609 | + $session_data['transaction'] |
|
610 | + ); |
|
611 | + } |
|
612 | + return $session_data; |
|
613 | + } |
|
614 | 614 | |
615 | 615 | |
616 | 616 | |
@@ -677,13 +677,13 @@ discard block |
||
677 | 677 | |
678 | 678 | |
679 | 679 | |
680 | - /** |
|
681 | - * @update session data prior to saving to the db |
|
682 | - * @access public |
|
683 | - * @param bool $new_session |
|
684 | - * @return TRUE on success, FALSE on fail |
|
685 | - * @throws \EE_Error |
|
686 | - */ |
|
680 | + /** |
|
681 | + * @update session data prior to saving to the db |
|
682 | + * @access public |
|
683 | + * @param bool $new_session |
|
684 | + * @return TRUE on success, FALSE on fail |
|
685 | + * @throws \EE_Error |
|
686 | + */ |
|
687 | 687 | public function update( $new_session = FALSE ) { |
688 | 688 | $this->_session_data = isset( $this->_session_data ) |
689 | 689 | && is_array( $this->_session_data ) |
@@ -769,12 +769,12 @@ discard block |
||
769 | 769 | |
770 | 770 | |
771 | 771 | |
772 | - /** |
|
773 | - * @create session data array |
|
774 | - * @access public |
|
775 | - * @return bool |
|
776 | - * @throws \EE_Error |
|
777 | - */ |
|
772 | + /** |
|
773 | + * @create session data array |
|
774 | + * @access public |
|
775 | + * @return bool |
|
776 | + * @throws \EE_Error |
|
777 | + */ |
|
778 | 778 | private function _create_espresso_session( ) { |
779 | 779 | do_action( 'AHEE_log', __CLASS__, __FUNCTION__, '' ); |
780 | 780 | // use the update function for now with $new_session arg set to TRUE |
@@ -794,19 +794,19 @@ discard block |
||
794 | 794 | if ( |
795 | 795 | // if the current request is NOT one of the following |
796 | 796 | ! ( |
797 | - // an an AJAX request from the frontend |
|
798 | - EE_Registry::instance()->REQ->front_ajax |
|
799 | - || ( |
|
800 | - // OR an admin request that is NOT AJAX |
|
797 | + // an an AJAX request from the frontend |
|
798 | + EE_Registry::instance()->REQ->front_ajax |
|
799 | + || ( |
|
800 | + // OR an admin request that is NOT AJAX |
|
801 | 801 | ! ( defined( 'DOING_AJAX' ) && DOING_AJAX ) |
802 | - && is_admin() |
|
802 | + && is_admin() |
|
803 | 803 | ) |
804 | - || ( |
|
805 | - // OR an espresso page |
|
806 | - EE_Registry::instance()->REQ instanceof EE_Request_Handler |
|
807 | - && EE_Registry::instance()->REQ->is_espresso_page() |
|
808 | - ) |
|
809 | - ) |
|
804 | + || ( |
|
805 | + // OR an espresso page |
|
806 | + EE_Registry::instance()->REQ instanceof EE_Request_Handler |
|
807 | + && EE_Registry::instance()->REQ->is_espresso_page() |
|
808 | + ) |
|
809 | + ) |
|
810 | 810 | ) { |
811 | 811 | return false; |
812 | 812 | } |
@@ -817,27 +817,27 @@ discard block |
||
817 | 817 | } |
818 | 818 | $this->_session_data['transaction'] = $transaction->ID(); |
819 | 819 | } |
820 | - // then serialize all of our session data |
|
820 | + // then serialize all of our session data |
|
821 | 821 | $session_data = serialize($this->_session_data); |
822 | 822 | // do we need to also encode it to avoid corrupted data when saved to the db? |
823 | 823 | $session_data = $this->_use_encryption |
824 | - ? $this->encryption->base64_string_encode( $session_data ) |
|
825 | - : $session_data; |
|
824 | + ? $this->encryption->base64_string_encode( $session_data ) |
|
825 | + : $session_data; |
|
826 | 826 | // maybe save hash check |
827 | 827 | if ( apply_filters( 'FHEE__EE_Session___perform_session_id_hash_check', WP_DEBUG ) ) { |
828 | - $this->cache_storage->add( |
|
829 | - EE_Session::hash_check_prefix . $this->_sid, |
|
830 | - md5($session_data), |
|
831 | - $this->_lifespan |
|
832 | - ); |
|
833 | - } |
|
834 | - // we're using the Transient API for storing session data, |
|
835 | - return $this->cache_storage->add( |
|
836 | - EE_Session::session_id_prefix . $this->_sid, |
|
837 | - $session_data, |
|
838 | - $this->_lifespan |
|
839 | - ); |
|
840 | - } |
|
828 | + $this->cache_storage->add( |
|
829 | + EE_Session::hash_check_prefix . $this->_sid, |
|
830 | + md5($session_data), |
|
831 | + $this->_lifespan |
|
832 | + ); |
|
833 | + } |
|
834 | + // we're using the Transient API for storing session data, |
|
835 | + return $this->cache_storage->add( |
|
836 | + EE_Session::session_id_prefix . $this->_sid, |
|
837 | + $session_data, |
|
838 | + $this->_lifespan |
|
839 | + ); |
|
840 | + } |
|
841 | 841 | |
842 | 842 | |
843 | 843 | |
@@ -930,18 +930,18 @@ discard block |
||
930 | 930 | |
931 | 931 | |
932 | 932 | |
933 | - /** |
|
934 | - * Clear EE_Session data |
|
935 | - * |
|
936 | - * @access public |
|
937 | - * @param string $class |
|
938 | - * @param string $function |
|
939 | - * @return void |
|
940 | - * @throws \EE_Error |
|
941 | - */ |
|
933 | + /** |
|
934 | + * Clear EE_Session data |
|
935 | + * |
|
936 | + * @access public |
|
937 | + * @param string $class |
|
938 | + * @param string $function |
|
939 | + * @return void |
|
940 | + * @throws \EE_Error |
|
941 | + */ |
|
942 | 942 | public function clear_session( $class = '', $function = '' ) { |
943 | 943 | //echo '<h3 style="color:#999;line-height:.9em;"><span style="color:#2EA2CC">' . __CLASS__ . '</span>::<span style="color:#E76700">' . __FUNCTION__ . '( ' . $class . '::' . $function . '() )</span><br/><span style="font-size:9px;font-weight:normal;">' . __FILE__ . '</span> <b style="font-size:10px;"> ' . __LINE__ . ' </b></h3>'; |
944 | - do_action( 'AHEE_log', __FILE__, __FUNCTION__, 'session cleared by : ' . $class . '::' . $function . '()' ); |
|
944 | + do_action( 'AHEE_log', __FILE__, __FUNCTION__, 'session cleared by : ' . $class . '::' . $function . '()' ); |
|
945 | 945 | $this->reset_cart(); |
946 | 946 | $this->reset_checkout(); |
947 | 947 | $this->reset_transaction(); |
@@ -1008,12 +1008,12 @@ discard block |
||
1008 | 1008 | |
1009 | 1009 | |
1010 | 1010 | |
1011 | - /** |
|
1012 | - * wp_loaded |
|
1013 | - * |
|
1014 | - * @access public |
|
1015 | - * @throws \EE_Error |
|
1016 | - */ |
|
1011 | + /** |
|
1012 | + * wp_loaded |
|
1013 | + * |
|
1014 | + * @access public |
|
1015 | + * @throws \EE_Error |
|
1016 | + */ |
|
1017 | 1017 | public function wp_loaded() { |
1018 | 1018 | if ( isset( EE_Registry::instance()->REQ ) && EE_Registry::instance()->REQ->is_set( 'clear_session' )) { |
1019 | 1019 | $this->clear_session( __CLASS__, __FUNCTION__ ); |
@@ -1022,12 +1022,12 @@ discard block |
||
1022 | 1022 | |
1023 | 1023 | |
1024 | 1024 | |
1025 | - /** |
|
1026 | - * Used to reset the entire object (for tests). |
|
1027 | - * |
|
1028 | - * @since 4.3.0 |
|
1029 | - * @throws \EE_Error |
|
1030 | - */ |
|
1025 | + /** |
|
1026 | + * Used to reset the entire object (for tests). |
|
1027 | + * |
|
1028 | + * @since 4.3.0 |
|
1029 | + * @throws \EE_Error |
|
1030 | + */ |
|
1031 | 1031 | public function reset_instance() { |
1032 | 1032 | $this->clear_session(); |
1033 | 1033 | self::$_instance = NULL; |
@@ -1035,29 +1035,29 @@ discard block |
||
1035 | 1035 | |
1036 | 1036 | |
1037 | 1037 | |
1038 | - public function configure_garbage_collection_filters() |
|
1039 | - { |
|
1040 | - // run old filter we had for controlling session cleanup |
|
1041 | - $expired_session_transient_delete_query_limit = absint( |
|
1042 | - apply_filters( |
|
1043 | - 'FHEE__EE_Session__garbage_collection___expired_session_transient_delete_query_limit', |
|
1044 | - 50 |
|
1045 | - ) |
|
1046 | - ); |
|
1047 | - // is there a value? or one that is different than the default 50 records? |
|
1048 | - if ($expired_session_transient_delete_query_limit === 0) { |
|
1049 | - // hook into TransientCacheStorage in case Session cleanup was turned off |
|
1050 | - add_filter('FHEE__TransientCacheStorage__transient_cleanup_schedule', '__return_zero'); |
|
1051 | - } else if ($expired_session_transient_delete_query_limit !== 50) { |
|
1052 | - // or use that for the new transient cleanup query limit |
|
1053 | - add_filter( |
|
1054 | - 'FHEE__TransientCacheStorage__clearExpiredTransients__limit', |
|
1055 | - function () use ($expired_session_transient_delete_query_limit) { |
|
1056 | - return $expired_session_transient_delete_query_limit; |
|
1057 | - } |
|
1058 | - ); |
|
1059 | - } |
|
1060 | - } |
|
1038 | + public function configure_garbage_collection_filters() |
|
1039 | + { |
|
1040 | + // run old filter we had for controlling session cleanup |
|
1041 | + $expired_session_transient_delete_query_limit = absint( |
|
1042 | + apply_filters( |
|
1043 | + 'FHEE__EE_Session__garbage_collection___expired_session_transient_delete_query_limit', |
|
1044 | + 50 |
|
1045 | + ) |
|
1046 | + ); |
|
1047 | + // is there a value? or one that is different than the default 50 records? |
|
1048 | + if ($expired_session_transient_delete_query_limit === 0) { |
|
1049 | + // hook into TransientCacheStorage in case Session cleanup was turned off |
|
1050 | + add_filter('FHEE__TransientCacheStorage__transient_cleanup_schedule', '__return_zero'); |
|
1051 | + } else if ($expired_session_transient_delete_query_limit !== 50) { |
|
1052 | + // or use that for the new transient cleanup query limit |
|
1053 | + add_filter( |
|
1054 | + 'FHEE__TransientCacheStorage__clearExpiredTransients__limit', |
|
1055 | + function () use ($expired_session_transient_delete_query_limit) { |
|
1056 | + return $expired_session_transient_delete_query_limit; |
|
1057 | + } |
|
1058 | + ); |
|
1059 | + } |
|
1060 | + } |
|
1061 | 1061 | |
1062 | 1062 | |
1063 | 1063 |