@@ -22,1229 +22,1229 @@ discard block |
||
22 | 22 | class EE_Session implements SessionIdentifierInterface |
23 | 23 | { |
24 | 24 | |
25 | - const session_id_prefix = 'ee_ssn_'; |
|
26 | - |
|
27 | - const hash_check_prefix = 'ee_shc_'; |
|
28 | - |
|
29 | - const OPTION_NAME_SETTINGS = 'ee_session_settings'; |
|
30 | - |
|
31 | - const STATUS_CLOSED = 0; |
|
32 | - |
|
33 | - const STATUS_OPEN = 1; |
|
34 | - |
|
35 | - /** |
|
36 | - * instance of the EE_Session object |
|
37 | - * |
|
38 | - * @var EE_Session |
|
39 | - */ |
|
40 | - private static $_instance; |
|
41 | - |
|
42 | - /** |
|
43 | - * @var CacheStorageInterface $cache_storage |
|
44 | - */ |
|
45 | - protected $cache_storage; |
|
46 | - |
|
47 | - /** |
|
48 | - * EE_Encryption object |
|
49 | - * |
|
50 | - * @var EE_Encryption |
|
51 | - */ |
|
52 | - protected $encryption; |
|
53 | - |
|
54 | - /** |
|
55 | - * the session id |
|
56 | - * |
|
57 | - * @var string |
|
58 | - */ |
|
59 | - private $_sid; |
|
60 | - |
|
61 | - /** |
|
62 | - * session id salt |
|
63 | - * |
|
64 | - * @var string |
|
65 | - */ |
|
66 | - private $_sid_salt; |
|
67 | - |
|
68 | - /** |
|
69 | - * session data |
|
70 | - * |
|
71 | - * @var array |
|
72 | - */ |
|
73 | - private $_session_data = array(); |
|
74 | - |
|
75 | - /** |
|
76 | - * how long an EE session lasts |
|
77 | - * default session lifespan of 1 hour (for not so instant IPNs) |
|
78 | - * |
|
79 | - * @var SessionLifespan $session_lifespan |
|
80 | - */ |
|
81 | - private $session_lifespan; |
|
82 | - |
|
83 | - /** |
|
84 | - * session expiration time as Unix timestamp in GMT |
|
85 | - * |
|
86 | - * @var int |
|
87 | - */ |
|
88 | - private $_expiration; |
|
89 | - |
|
90 | - /** |
|
91 | - * whether or not session has expired at some point |
|
92 | - * |
|
93 | - * @var boolean |
|
94 | - */ |
|
95 | - private $_expired = false; |
|
96 | - |
|
97 | - /** |
|
98 | - * current time as Unix timestamp in GMT |
|
99 | - * |
|
100 | - * @var int |
|
101 | - */ |
|
102 | - private $_time; |
|
103 | - |
|
104 | - /** |
|
105 | - * whether to encrypt session data |
|
106 | - * |
|
107 | - * @var bool |
|
108 | - */ |
|
109 | - private $_use_encryption; |
|
110 | - |
|
111 | - /** |
|
112 | - * well... according to the server... |
|
113 | - * |
|
114 | - * @var null |
|
115 | - */ |
|
116 | - private $_user_agent; |
|
117 | - |
|
118 | - /** |
|
119 | - * do you really trust the server ? |
|
120 | - * |
|
121 | - * @var null |
|
122 | - */ |
|
123 | - private $_ip_address; |
|
124 | - |
|
125 | - /** |
|
126 | - * current WP user_id |
|
127 | - * |
|
128 | - * @var null |
|
129 | - */ |
|
130 | - private $_wp_user_id; |
|
131 | - |
|
132 | - /** |
|
133 | - * array for defining default session vars |
|
134 | - * |
|
135 | - * @var array |
|
136 | - */ |
|
137 | - private $_default_session_vars = array( |
|
138 | - 'id' => null, |
|
139 | - 'user_id' => null, |
|
140 | - 'ip_address' => null, |
|
141 | - 'user_agent' => null, |
|
142 | - 'init_access' => null, |
|
143 | - 'last_access' => null, |
|
144 | - 'expiration' => null, |
|
145 | - 'pages_visited' => array(), |
|
146 | - ); |
|
147 | - |
|
148 | - /** |
|
149 | - * timestamp for when last garbage collection cycle was performed |
|
150 | - * |
|
151 | - * @var int $_last_gc |
|
152 | - */ |
|
153 | - private $_last_gc; |
|
154 | - |
|
155 | - /** |
|
156 | - * @var RequestInterface $request |
|
157 | - */ |
|
158 | - protected $request; |
|
159 | - |
|
160 | - /** |
|
161 | - * whether session is active or not |
|
162 | - * |
|
163 | - * @var int $status |
|
164 | - */ |
|
165 | - private $status = EE_Session::STATUS_CLOSED; |
|
166 | - |
|
167 | - |
|
168 | - |
|
169 | - /** |
|
170 | - * @singleton method used to instantiate class object |
|
171 | - * @param CacheStorageInterface $cache_storage |
|
172 | - * @param SessionLifespan|null $lifespan |
|
173 | - * @param RequestInterface $request |
|
174 | - * @param EE_Encryption $encryption |
|
175 | - * @return EE_Session |
|
176 | - * @throws InvalidArgumentException |
|
177 | - * @throws InvalidDataTypeException |
|
178 | - * @throws InvalidInterfaceException |
|
179 | - */ |
|
180 | - public static function instance( |
|
181 | - CacheStorageInterface $cache_storage = null, |
|
182 | - SessionLifespan $lifespan = null, |
|
183 | - RequestInterface $request = null, |
|
184 | - EE_Encryption $encryption = null |
|
185 | - ) { |
|
186 | - // check if class object is instantiated |
|
187 | - // session loading is turned ON by default, but prior to the init hook, can be turned back OFF via: |
|
188 | - // add_filter( 'FHEE_load_EE_Session', '__return_false' ); |
|
189 | - if (! self::$_instance instanceof EE_Session && apply_filters('FHEE_load_EE_Session', true)) { |
|
190 | - self::$_instance = new self( |
|
191 | - $cache_storage, |
|
192 | - $lifespan, |
|
193 | - $request, |
|
194 | - $encryption |
|
195 | - ); |
|
196 | - } |
|
197 | - return self::$_instance; |
|
198 | - } |
|
199 | - |
|
200 | - |
|
201 | - /** |
|
202 | - * protected constructor to prevent direct creation |
|
203 | - * |
|
204 | - * @param CacheStorageInterface $cache_storage |
|
205 | - * @param SessionLifespan $lifespan |
|
206 | - * @param RequestInterface $request |
|
207 | - * @param EE_Encryption $encryption |
|
208 | - * @throws InvalidArgumentException |
|
209 | - * @throws InvalidDataTypeException |
|
210 | - * @throws InvalidInterfaceException |
|
211 | - */ |
|
212 | - protected function __construct( |
|
213 | - CacheStorageInterface $cache_storage, |
|
214 | - SessionLifespan $lifespan, |
|
215 | - RequestInterface $request, |
|
216 | - EE_Encryption $encryption = null |
|
217 | - ) { |
|
218 | - // session loading is turned ON by default, |
|
219 | - // but prior to the 'AHEE__EE_System__core_loaded_and_ready' hook |
|
220 | - // (which currently fires on the init hook at priority 9), |
|
221 | - // can be turned back OFF via: add_filter( 'FHEE_load_EE_Session', '__return_false' ); |
|
222 | - if (! apply_filters('FHEE_load_EE_Session', true)) { |
|
223 | - return; |
|
224 | - } |
|
225 | - $this->session_lifespan = $lifespan; |
|
226 | - $this->request = $request; |
|
227 | - if (! defined('ESPRESSO_SESSION')) { |
|
228 | - define('ESPRESSO_SESSION', true); |
|
229 | - } |
|
230 | - // retrieve session options from db |
|
231 | - $session_settings = (array) get_option(EE_Session::OPTION_NAME_SETTINGS, array()); |
|
232 | - if (! empty($session_settings)) { |
|
233 | - // cycle though existing session options |
|
234 | - foreach ($session_settings as $var_name => $session_setting) { |
|
235 | - // set values for class properties |
|
236 | - $var_name = '_' . $var_name; |
|
237 | - $this->{$var_name} = $session_setting; |
|
238 | - } |
|
239 | - } |
|
240 | - $this->cache_storage = $cache_storage; |
|
241 | - // are we using encryption? |
|
242 | - $this->_use_encryption = $encryption instanceof EE_Encryption |
|
243 | - && EE_Registry::instance()->CFG->admin->encode_session_data(); |
|
244 | - // encrypt data via: $this->encryption->encrypt(); |
|
245 | - $this->encryption = $encryption; |
|
246 | - // filter hook allows outside functions/classes/plugins to change default empty cart |
|
247 | - $extra_default_session_vars = apply_filters('FHEE__EE_Session__construct__extra_default_session_vars', array()); |
|
248 | - array_merge($this->_default_session_vars, $extra_default_session_vars); |
|
249 | - // apply default session vars |
|
250 | - $this->_set_defaults(); |
|
251 | - add_action('AHEE__EE_System__initialize', array($this, 'open_session')); |
|
252 | - // check request for 'clear_session' param |
|
253 | - add_action('AHEE__EE_Request_Handler__construct__complete', array($this, 'wp_loaded')); |
|
254 | - // once everything is all said and done, |
|
255 | - add_action('shutdown', array($this, 'update'), 100); |
|
256 | - add_action('shutdown', array($this, 'garbageCollection'), 1000); |
|
257 | - $this->configure_garbage_collection_filters(); |
|
258 | - } |
|
259 | - |
|
260 | - |
|
261 | - /** |
|
262 | - * @return bool |
|
263 | - * @throws InvalidArgumentException |
|
264 | - * @throws InvalidDataTypeException |
|
265 | - * @throws InvalidInterfaceException |
|
266 | - */ |
|
267 | - public static function isLoadedAndActive() |
|
268 | - { |
|
269 | - return did_action('AHEE__EE_System__core_loaded_and_ready') |
|
270 | - && EE_Session::instance() instanceof EE_Session |
|
271 | - && EE_Session::instance()->isActive(); |
|
272 | - } |
|
273 | - |
|
274 | - |
|
275 | - /** |
|
276 | - * @return bool |
|
277 | - */ |
|
278 | - public function isActive() |
|
279 | - { |
|
280 | - return $this->status === EE_Session::STATUS_OPEN; |
|
281 | - } |
|
282 | - |
|
283 | - |
|
284 | - |
|
285 | - /** |
|
286 | - * @return void |
|
287 | - * @throws EE_Error |
|
288 | - * @throws InvalidArgumentException |
|
289 | - * @throws InvalidDataTypeException |
|
290 | - * @throws InvalidInterfaceException |
|
291 | - * @throws InvalidSessionDataException |
|
292 | - */ |
|
293 | - public function open_session() |
|
294 | - { |
|
295 | - // check for existing session and retrieve it from db |
|
296 | - if (! $this->_espresso_session()) { |
|
297 | - // or just start a new one |
|
298 | - $this->_create_espresso_session(); |
|
299 | - } |
|
300 | - } |
|
301 | - |
|
302 | - |
|
303 | - |
|
304 | - /** |
|
305 | - * @return bool |
|
306 | - */ |
|
307 | - public function expired() |
|
308 | - { |
|
309 | - return $this->_expired; |
|
310 | - } |
|
311 | - |
|
312 | - |
|
313 | - |
|
314 | - /** |
|
315 | - * @return void |
|
316 | - */ |
|
317 | - public function reset_expired() |
|
318 | - { |
|
319 | - $this->_expired = false; |
|
320 | - } |
|
321 | - |
|
322 | - |
|
323 | - /** |
|
324 | - * @return int |
|
325 | - */ |
|
326 | - public function expiration() |
|
327 | - { |
|
328 | - return $this->_expiration; |
|
329 | - } |
|
330 | - |
|
331 | - |
|
332 | - |
|
333 | - /** |
|
334 | - * @return int |
|
335 | - */ |
|
336 | - public function extension() |
|
337 | - { |
|
338 | - return apply_filters('FHEE__EE_Session__extend_expiration__seconds_added', 10 * MINUTE_IN_SECONDS); |
|
339 | - } |
|
340 | - |
|
341 | - |
|
342 | - |
|
343 | - /** |
|
344 | - * @param int $time number of seconds to add to session expiration |
|
345 | - */ |
|
346 | - public function extend_expiration($time = 0) |
|
347 | - { |
|
348 | - $time = $time ? $time : $this->extension(); |
|
349 | - $this->_expiration += absint($time); |
|
350 | - } |
|
351 | - |
|
352 | - |
|
353 | - |
|
354 | - /** |
|
355 | - * @return int |
|
356 | - */ |
|
357 | - public function lifespan() |
|
358 | - { |
|
359 | - return $this->session_lifespan->inSeconds(); |
|
360 | - } |
|
361 | - |
|
362 | - |
|
363 | - |
|
364 | - /** |
|
365 | - * This just sets some defaults for the _session data property |
|
366 | - * |
|
367 | - * @access private |
|
368 | - * @return void |
|
369 | - */ |
|
370 | - private function _set_defaults() |
|
371 | - { |
|
372 | - // set some defaults |
|
373 | - foreach ($this->_default_session_vars as $key => $default_var) { |
|
374 | - if (is_array($default_var)) { |
|
375 | - $this->_session_data[ $key ] = array(); |
|
376 | - } else { |
|
377 | - $this->_session_data[ $key ] = ''; |
|
378 | - } |
|
379 | - } |
|
380 | - } |
|
25 | + const session_id_prefix = 'ee_ssn_'; |
|
26 | + |
|
27 | + const hash_check_prefix = 'ee_shc_'; |
|
28 | + |
|
29 | + const OPTION_NAME_SETTINGS = 'ee_session_settings'; |
|
30 | + |
|
31 | + const STATUS_CLOSED = 0; |
|
32 | + |
|
33 | + const STATUS_OPEN = 1; |
|
34 | + |
|
35 | + /** |
|
36 | + * instance of the EE_Session object |
|
37 | + * |
|
38 | + * @var EE_Session |
|
39 | + */ |
|
40 | + private static $_instance; |
|
41 | + |
|
42 | + /** |
|
43 | + * @var CacheStorageInterface $cache_storage |
|
44 | + */ |
|
45 | + protected $cache_storage; |
|
46 | + |
|
47 | + /** |
|
48 | + * EE_Encryption object |
|
49 | + * |
|
50 | + * @var EE_Encryption |
|
51 | + */ |
|
52 | + protected $encryption; |
|
53 | + |
|
54 | + /** |
|
55 | + * the session id |
|
56 | + * |
|
57 | + * @var string |
|
58 | + */ |
|
59 | + private $_sid; |
|
60 | + |
|
61 | + /** |
|
62 | + * session id salt |
|
63 | + * |
|
64 | + * @var string |
|
65 | + */ |
|
66 | + private $_sid_salt; |
|
67 | + |
|
68 | + /** |
|
69 | + * session data |
|
70 | + * |
|
71 | + * @var array |
|
72 | + */ |
|
73 | + private $_session_data = array(); |
|
74 | + |
|
75 | + /** |
|
76 | + * how long an EE session lasts |
|
77 | + * default session lifespan of 1 hour (for not so instant IPNs) |
|
78 | + * |
|
79 | + * @var SessionLifespan $session_lifespan |
|
80 | + */ |
|
81 | + private $session_lifespan; |
|
82 | + |
|
83 | + /** |
|
84 | + * session expiration time as Unix timestamp in GMT |
|
85 | + * |
|
86 | + * @var int |
|
87 | + */ |
|
88 | + private $_expiration; |
|
89 | + |
|
90 | + /** |
|
91 | + * whether or not session has expired at some point |
|
92 | + * |
|
93 | + * @var boolean |
|
94 | + */ |
|
95 | + private $_expired = false; |
|
96 | + |
|
97 | + /** |
|
98 | + * current time as Unix timestamp in GMT |
|
99 | + * |
|
100 | + * @var int |
|
101 | + */ |
|
102 | + private $_time; |
|
103 | + |
|
104 | + /** |
|
105 | + * whether to encrypt session data |
|
106 | + * |
|
107 | + * @var bool |
|
108 | + */ |
|
109 | + private $_use_encryption; |
|
110 | + |
|
111 | + /** |
|
112 | + * well... according to the server... |
|
113 | + * |
|
114 | + * @var null |
|
115 | + */ |
|
116 | + private $_user_agent; |
|
117 | + |
|
118 | + /** |
|
119 | + * do you really trust the server ? |
|
120 | + * |
|
121 | + * @var null |
|
122 | + */ |
|
123 | + private $_ip_address; |
|
124 | + |
|
125 | + /** |
|
126 | + * current WP user_id |
|
127 | + * |
|
128 | + * @var null |
|
129 | + */ |
|
130 | + private $_wp_user_id; |
|
131 | + |
|
132 | + /** |
|
133 | + * array for defining default session vars |
|
134 | + * |
|
135 | + * @var array |
|
136 | + */ |
|
137 | + private $_default_session_vars = array( |
|
138 | + 'id' => null, |
|
139 | + 'user_id' => null, |
|
140 | + 'ip_address' => null, |
|
141 | + 'user_agent' => null, |
|
142 | + 'init_access' => null, |
|
143 | + 'last_access' => null, |
|
144 | + 'expiration' => null, |
|
145 | + 'pages_visited' => array(), |
|
146 | + ); |
|
147 | + |
|
148 | + /** |
|
149 | + * timestamp for when last garbage collection cycle was performed |
|
150 | + * |
|
151 | + * @var int $_last_gc |
|
152 | + */ |
|
153 | + private $_last_gc; |
|
154 | + |
|
155 | + /** |
|
156 | + * @var RequestInterface $request |
|
157 | + */ |
|
158 | + protected $request; |
|
159 | + |
|
160 | + /** |
|
161 | + * whether session is active or not |
|
162 | + * |
|
163 | + * @var int $status |
|
164 | + */ |
|
165 | + private $status = EE_Session::STATUS_CLOSED; |
|
166 | + |
|
167 | + |
|
168 | + |
|
169 | + /** |
|
170 | + * @singleton method used to instantiate class object |
|
171 | + * @param CacheStorageInterface $cache_storage |
|
172 | + * @param SessionLifespan|null $lifespan |
|
173 | + * @param RequestInterface $request |
|
174 | + * @param EE_Encryption $encryption |
|
175 | + * @return EE_Session |
|
176 | + * @throws InvalidArgumentException |
|
177 | + * @throws InvalidDataTypeException |
|
178 | + * @throws InvalidInterfaceException |
|
179 | + */ |
|
180 | + public static function instance( |
|
181 | + CacheStorageInterface $cache_storage = null, |
|
182 | + SessionLifespan $lifespan = null, |
|
183 | + RequestInterface $request = null, |
|
184 | + EE_Encryption $encryption = null |
|
185 | + ) { |
|
186 | + // check if class object is instantiated |
|
187 | + // session loading is turned ON by default, but prior to the init hook, can be turned back OFF via: |
|
188 | + // add_filter( 'FHEE_load_EE_Session', '__return_false' ); |
|
189 | + if (! self::$_instance instanceof EE_Session && apply_filters('FHEE_load_EE_Session', true)) { |
|
190 | + self::$_instance = new self( |
|
191 | + $cache_storage, |
|
192 | + $lifespan, |
|
193 | + $request, |
|
194 | + $encryption |
|
195 | + ); |
|
196 | + } |
|
197 | + return self::$_instance; |
|
198 | + } |
|
199 | + |
|
200 | + |
|
201 | + /** |
|
202 | + * protected constructor to prevent direct creation |
|
203 | + * |
|
204 | + * @param CacheStorageInterface $cache_storage |
|
205 | + * @param SessionLifespan $lifespan |
|
206 | + * @param RequestInterface $request |
|
207 | + * @param EE_Encryption $encryption |
|
208 | + * @throws InvalidArgumentException |
|
209 | + * @throws InvalidDataTypeException |
|
210 | + * @throws InvalidInterfaceException |
|
211 | + */ |
|
212 | + protected function __construct( |
|
213 | + CacheStorageInterface $cache_storage, |
|
214 | + SessionLifespan $lifespan, |
|
215 | + RequestInterface $request, |
|
216 | + EE_Encryption $encryption = null |
|
217 | + ) { |
|
218 | + // session loading is turned ON by default, |
|
219 | + // but prior to the 'AHEE__EE_System__core_loaded_and_ready' hook |
|
220 | + // (which currently fires on the init hook at priority 9), |
|
221 | + // can be turned back OFF via: add_filter( 'FHEE_load_EE_Session', '__return_false' ); |
|
222 | + if (! apply_filters('FHEE_load_EE_Session', true)) { |
|
223 | + return; |
|
224 | + } |
|
225 | + $this->session_lifespan = $lifespan; |
|
226 | + $this->request = $request; |
|
227 | + if (! defined('ESPRESSO_SESSION')) { |
|
228 | + define('ESPRESSO_SESSION', true); |
|
229 | + } |
|
230 | + // retrieve session options from db |
|
231 | + $session_settings = (array) get_option(EE_Session::OPTION_NAME_SETTINGS, array()); |
|
232 | + if (! empty($session_settings)) { |
|
233 | + // cycle though existing session options |
|
234 | + foreach ($session_settings as $var_name => $session_setting) { |
|
235 | + // set values for class properties |
|
236 | + $var_name = '_' . $var_name; |
|
237 | + $this->{$var_name} = $session_setting; |
|
238 | + } |
|
239 | + } |
|
240 | + $this->cache_storage = $cache_storage; |
|
241 | + // are we using encryption? |
|
242 | + $this->_use_encryption = $encryption instanceof EE_Encryption |
|
243 | + && EE_Registry::instance()->CFG->admin->encode_session_data(); |
|
244 | + // encrypt data via: $this->encryption->encrypt(); |
|
245 | + $this->encryption = $encryption; |
|
246 | + // filter hook allows outside functions/classes/plugins to change default empty cart |
|
247 | + $extra_default_session_vars = apply_filters('FHEE__EE_Session__construct__extra_default_session_vars', array()); |
|
248 | + array_merge($this->_default_session_vars, $extra_default_session_vars); |
|
249 | + // apply default session vars |
|
250 | + $this->_set_defaults(); |
|
251 | + add_action('AHEE__EE_System__initialize', array($this, 'open_session')); |
|
252 | + // check request for 'clear_session' param |
|
253 | + add_action('AHEE__EE_Request_Handler__construct__complete', array($this, 'wp_loaded')); |
|
254 | + // once everything is all said and done, |
|
255 | + add_action('shutdown', array($this, 'update'), 100); |
|
256 | + add_action('shutdown', array($this, 'garbageCollection'), 1000); |
|
257 | + $this->configure_garbage_collection_filters(); |
|
258 | + } |
|
259 | + |
|
260 | + |
|
261 | + /** |
|
262 | + * @return bool |
|
263 | + * @throws InvalidArgumentException |
|
264 | + * @throws InvalidDataTypeException |
|
265 | + * @throws InvalidInterfaceException |
|
266 | + */ |
|
267 | + public static function isLoadedAndActive() |
|
268 | + { |
|
269 | + return did_action('AHEE__EE_System__core_loaded_and_ready') |
|
270 | + && EE_Session::instance() instanceof EE_Session |
|
271 | + && EE_Session::instance()->isActive(); |
|
272 | + } |
|
273 | + |
|
274 | + |
|
275 | + /** |
|
276 | + * @return bool |
|
277 | + */ |
|
278 | + public function isActive() |
|
279 | + { |
|
280 | + return $this->status === EE_Session::STATUS_OPEN; |
|
281 | + } |
|
282 | + |
|
283 | + |
|
284 | + |
|
285 | + /** |
|
286 | + * @return void |
|
287 | + * @throws EE_Error |
|
288 | + * @throws InvalidArgumentException |
|
289 | + * @throws InvalidDataTypeException |
|
290 | + * @throws InvalidInterfaceException |
|
291 | + * @throws InvalidSessionDataException |
|
292 | + */ |
|
293 | + public function open_session() |
|
294 | + { |
|
295 | + // check for existing session and retrieve it from db |
|
296 | + if (! $this->_espresso_session()) { |
|
297 | + // or just start a new one |
|
298 | + $this->_create_espresso_session(); |
|
299 | + } |
|
300 | + } |
|
301 | + |
|
302 | + |
|
303 | + |
|
304 | + /** |
|
305 | + * @return bool |
|
306 | + */ |
|
307 | + public function expired() |
|
308 | + { |
|
309 | + return $this->_expired; |
|
310 | + } |
|
311 | + |
|
312 | + |
|
313 | + |
|
314 | + /** |
|
315 | + * @return void |
|
316 | + */ |
|
317 | + public function reset_expired() |
|
318 | + { |
|
319 | + $this->_expired = false; |
|
320 | + } |
|
321 | + |
|
322 | + |
|
323 | + /** |
|
324 | + * @return int |
|
325 | + */ |
|
326 | + public function expiration() |
|
327 | + { |
|
328 | + return $this->_expiration; |
|
329 | + } |
|
330 | + |
|
331 | + |
|
332 | + |
|
333 | + /** |
|
334 | + * @return int |
|
335 | + */ |
|
336 | + public function extension() |
|
337 | + { |
|
338 | + return apply_filters('FHEE__EE_Session__extend_expiration__seconds_added', 10 * MINUTE_IN_SECONDS); |
|
339 | + } |
|
340 | + |
|
341 | + |
|
342 | + |
|
343 | + /** |
|
344 | + * @param int $time number of seconds to add to session expiration |
|
345 | + */ |
|
346 | + public function extend_expiration($time = 0) |
|
347 | + { |
|
348 | + $time = $time ? $time : $this->extension(); |
|
349 | + $this->_expiration += absint($time); |
|
350 | + } |
|
351 | + |
|
352 | + |
|
353 | + |
|
354 | + /** |
|
355 | + * @return int |
|
356 | + */ |
|
357 | + public function lifespan() |
|
358 | + { |
|
359 | + return $this->session_lifespan->inSeconds(); |
|
360 | + } |
|
361 | + |
|
362 | + |
|
363 | + |
|
364 | + /** |
|
365 | + * This just sets some defaults for the _session data property |
|
366 | + * |
|
367 | + * @access private |
|
368 | + * @return void |
|
369 | + */ |
|
370 | + private function _set_defaults() |
|
371 | + { |
|
372 | + // set some defaults |
|
373 | + foreach ($this->_default_session_vars as $key => $default_var) { |
|
374 | + if (is_array($default_var)) { |
|
375 | + $this->_session_data[ $key ] = array(); |
|
376 | + } else { |
|
377 | + $this->_session_data[ $key ] = ''; |
|
378 | + } |
|
379 | + } |
|
380 | + } |
|
381 | 381 | |
382 | 382 | |
383 | - |
|
384 | - /** |
|
385 | - * @retrieve session data |
|
386 | - * @access public |
|
387 | - * @return string |
|
388 | - */ |
|
389 | - public function id() |
|
390 | - { |
|
391 | - return $this->_sid; |
|
392 | - } |
|
383 | + |
|
384 | + /** |
|
385 | + * @retrieve session data |
|
386 | + * @access public |
|
387 | + * @return string |
|
388 | + */ |
|
389 | + public function id() |
|
390 | + { |
|
391 | + return $this->_sid; |
|
392 | + } |
|
393 | 393 | |
394 | 394 | |
395 | 395 | |
396 | - /** |
|
397 | - * @param \EE_Cart $cart |
|
398 | - * @return bool |
|
399 | - */ |
|
400 | - public function set_cart(EE_Cart $cart) |
|
401 | - { |
|
402 | - $this->_session_data['cart'] = $cart; |
|
403 | - return true; |
|
404 | - } |
|
405 | - |
|
406 | - |
|
407 | - |
|
408 | - /** |
|
409 | - * reset_cart |
|
410 | - */ |
|
411 | - public function reset_cart() |
|
412 | - { |
|
413 | - do_action('AHEE__EE_Session__reset_cart__before_reset', $this); |
|
414 | - $this->_session_data['cart'] = null; |
|
415 | - } |
|
416 | - |
|
417 | - |
|
418 | - |
|
419 | - /** |
|
420 | - * @return \EE_Cart |
|
421 | - */ |
|
422 | - public function cart() |
|
423 | - { |
|
424 | - return isset($this->_session_data['cart']) && $this->_session_data['cart'] instanceof EE_Cart |
|
425 | - ? $this->_session_data['cart'] |
|
426 | - : null; |
|
427 | - } |
|
428 | - |
|
429 | - |
|
430 | - |
|
431 | - /** |
|
432 | - * @param \EE_Checkout $checkout |
|
433 | - * @return bool |
|
434 | - */ |
|
435 | - public function set_checkout(EE_Checkout $checkout) |
|
436 | - { |
|
437 | - $this->_session_data['checkout'] = $checkout; |
|
438 | - return true; |
|
439 | - } |
|
440 | - |
|
441 | - |
|
442 | - |
|
443 | - /** |
|
444 | - * reset_checkout |
|
445 | - */ |
|
446 | - public function reset_checkout() |
|
447 | - { |
|
448 | - do_action('AHEE__EE_Session__reset_checkout__before_reset', $this); |
|
449 | - $this->_session_data['checkout'] = null; |
|
450 | - } |
|
451 | - |
|
452 | - |
|
453 | - |
|
454 | - /** |
|
455 | - * @return \EE_Checkout |
|
456 | - */ |
|
457 | - public function checkout() |
|
458 | - { |
|
459 | - return isset($this->_session_data['checkout']) && $this->_session_data['checkout'] instanceof EE_Checkout |
|
460 | - ? $this->_session_data['checkout'] |
|
461 | - : null; |
|
462 | - } |
|
463 | - |
|
464 | - |
|
465 | - |
|
466 | - /** |
|
467 | - * @param \EE_Transaction $transaction |
|
468 | - * @return bool |
|
469 | - * @throws EE_Error |
|
470 | - */ |
|
471 | - public function set_transaction(EE_Transaction $transaction) |
|
472 | - { |
|
473 | - // first remove the session from the transaction before we save the transaction in the session |
|
474 | - $transaction->set_txn_session_data(null); |
|
475 | - $this->_session_data['transaction'] = $transaction; |
|
476 | - return true; |
|
477 | - } |
|
478 | - |
|
479 | - |
|
480 | - |
|
481 | - /** |
|
482 | - * reset_transaction |
|
483 | - */ |
|
484 | - public function reset_transaction() |
|
485 | - { |
|
486 | - do_action('AHEE__EE_Session__reset_transaction__before_reset', $this); |
|
487 | - $this->_session_data['transaction'] = null; |
|
488 | - } |
|
489 | - |
|
490 | - |
|
491 | - |
|
492 | - /** |
|
493 | - * @return \EE_Transaction |
|
494 | - */ |
|
495 | - public function transaction() |
|
496 | - { |
|
497 | - return isset($this->_session_data['transaction']) |
|
498 | - && $this->_session_data['transaction'] instanceof EE_Transaction |
|
499 | - ? $this->_session_data['transaction'] |
|
500 | - : null; |
|
501 | - } |
|
502 | - |
|
503 | - |
|
504 | - /** |
|
505 | - * retrieve session data |
|
506 | - * |
|
507 | - * @param null $key |
|
508 | - * @param bool $reset_cache |
|
509 | - * @return array |
|
510 | - */ |
|
511 | - public function get_session_data($key = null, $reset_cache = false) |
|
512 | - { |
|
513 | - if ($reset_cache) { |
|
514 | - $this->reset_cart(); |
|
515 | - $this->reset_checkout(); |
|
516 | - $this->reset_transaction(); |
|
517 | - } |
|
518 | - if (! empty($key)) { |
|
519 | - return isset($this->_session_data[ $key ]) ? $this->_session_data[ $key ] : null; |
|
520 | - } |
|
521 | - return $this->_session_data; |
|
522 | - } |
|
523 | - |
|
524 | - |
|
525 | - /** |
|
526 | - * Returns TRUE on success, FALSE on fail |
|
527 | - * |
|
528 | - * @param array $data |
|
529 | - * @return bool |
|
530 | - */ |
|
531 | - public function set_session_data($data) |
|
532 | - { |
|
533 | - // nothing ??? bad data ??? go home! |
|
534 | - if (empty($data) || ! is_array($data)) { |
|
535 | - EE_Error::add_error( |
|
536 | - esc_html__( |
|
537 | - 'No session data or invalid session data was provided.', |
|
538 | - 'event_espresso' |
|
539 | - ), |
|
540 | - __FILE__, __FUNCTION__, __LINE__ |
|
541 | - ); |
|
542 | - return false; |
|
543 | - } |
|
544 | - foreach ($data as $key => $value) { |
|
545 | - if (isset($this->_default_session_vars[ $key ])) { |
|
546 | - EE_Error::add_error( |
|
547 | - sprintf( |
|
548 | - esc_html__( |
|
549 | - 'Sorry! %s is a default session datum and can not be reset.', |
|
550 | - 'event_espresso' |
|
551 | - ), |
|
552 | - $key |
|
553 | - ), |
|
554 | - __FILE__, __FUNCTION__, __LINE__ |
|
555 | - ); |
|
556 | - return false; |
|
557 | - } |
|
558 | - $this->_session_data[ $key ] = $value; |
|
559 | - } |
|
560 | - return true; |
|
561 | - } |
|
562 | - |
|
563 | - |
|
564 | - |
|
565 | - /** |
|
566 | - * @initiate session |
|
567 | - * @access private |
|
568 | - * @return TRUE on success, FALSE on fail |
|
569 | - * @throws EE_Error |
|
570 | - * @throws InvalidArgumentException |
|
571 | - * @throws InvalidDataTypeException |
|
572 | - * @throws InvalidInterfaceException |
|
573 | - * @throws InvalidSessionDataException |
|
574 | - */ |
|
575 | - private function _espresso_session() |
|
576 | - { |
|
577 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
578 | - // check that session has started |
|
579 | - if (session_id() === '') { |
|
580 | - //starts a new session if one doesn't already exist, or re-initiates an existing one |
|
581 | - session_start(); |
|
582 | - } |
|
583 | - $this->status = EE_Session::STATUS_OPEN; |
|
584 | - // get our modified session ID |
|
585 | - $this->_sid = $this->_generate_session_id(); |
|
586 | - // and the visitors IP |
|
587 | - $this->_ip_address = $this->request->ipAddress(); |
|
588 | - // set the "user agent" |
|
589 | - $this->_user_agent = $this->request->userAgent(); |
|
590 | - // now let's retrieve what's in the db |
|
591 | - $session_data = $this->_retrieve_session_data(); |
|
592 | - if (! empty($session_data)) { |
|
593 | - // get the current time in UTC |
|
594 | - $this->_time = $this->_time !== null ? $this->_time : time(); |
|
595 | - // and reset the session expiration |
|
596 | - $this->_expiration = isset($session_data['expiration']) |
|
597 | - ? $session_data['expiration'] |
|
598 | - : $this->_time + $this->session_lifespan->inSeconds(); |
|
599 | - } else { |
|
600 | - // set initial site access time and the session expiration |
|
601 | - $this->_set_init_access_and_expiration(); |
|
602 | - // set referer |
|
603 | - $this->_session_data['pages_visited'][ $this->_session_data['init_access'] ] = isset($_SERVER['HTTP_REFERER']) |
|
604 | - ? esc_attr($_SERVER['HTTP_REFERER']) |
|
605 | - : ''; |
|
606 | - // no previous session = go back and create one (on top of the data above) |
|
607 | - return false; |
|
608 | - } |
|
609 | - // now the user agent |
|
610 | - if ($session_data['user_agent'] !== $this->_user_agent) { |
|
611 | - return false; |
|
612 | - } |
|
613 | - // wait a minute... how old are you? |
|
614 | - if ($this->_time > $this->_expiration) { |
|
615 | - // yer too old fer me! |
|
616 | - $this->_expired = true; |
|
617 | - // wipe out everything that isn't a default session datum |
|
618 | - $this->clear_session(__CLASS__, __FUNCTION__); |
|
619 | - } |
|
620 | - // make event espresso session data available to plugin |
|
621 | - $this->_session_data = array_merge($this->_session_data, $session_data); |
|
622 | - return true; |
|
623 | - } |
|
624 | - |
|
625 | - |
|
626 | - |
|
627 | - /** |
|
628 | - * _get_session_data |
|
629 | - * Retrieves the session data, and attempts to correct any encoding issues that can occur due to improperly setup |
|
630 | - * databases |
|
631 | - * |
|
632 | - * @return array |
|
633 | - * @throws EE_Error |
|
634 | - * @throws InvalidArgumentException |
|
635 | - * @throws InvalidSessionDataException |
|
636 | - * @throws InvalidDataTypeException |
|
637 | - * @throws InvalidInterfaceException |
|
638 | - */ |
|
639 | - protected function _retrieve_session_data() |
|
640 | - { |
|
641 | - $ssn_key = EE_Session::session_id_prefix . $this->_sid; |
|
642 | - try { |
|
643 | - // we're using WP's Transient API to store session data using the PHP session ID as the option name |
|
644 | - $session_data = $this->cache_storage->get($ssn_key, false); |
|
645 | - if (empty($session_data)) { |
|
646 | - return array(); |
|
647 | - } |
|
648 | - if (apply_filters('FHEE__EE_Session___perform_session_id_hash_check', WP_DEBUG)) { |
|
649 | - $hash_check = $this->cache_storage->get( |
|
650 | - EE_Session::hash_check_prefix . $this->_sid, |
|
651 | - false |
|
652 | - ); |
|
653 | - if ($hash_check && $hash_check !== md5($session_data)) { |
|
654 | - EE_Error::add_error( |
|
655 | - sprintf( |
|
656 | - __( |
|
657 | - 'The stored data for session %1$s failed to pass a hash check and therefore appears to be invalid.', |
|
658 | - 'event_espresso' |
|
659 | - ), |
|
660 | - EE_Session::session_id_prefix . $this->_sid |
|
661 | - ), |
|
662 | - __FILE__, __FUNCTION__, __LINE__ |
|
663 | - ); |
|
664 | - } |
|
665 | - } |
|
666 | - } catch (Exception $e) { |
|
667 | - // let's just eat that error for now and attempt to correct any corrupted data |
|
668 | - global $wpdb; |
|
669 | - $row = $wpdb->get_row( |
|
670 | - $wpdb->prepare( |
|
671 | - "SELECT option_value FROM {$wpdb->options} WHERE option_name = %s LIMIT 1", |
|
672 | - '_transient_' . $ssn_key |
|
673 | - ) |
|
674 | - ); |
|
675 | - $session_data = is_object($row) ? $row->option_value : null; |
|
676 | - if ($session_data) { |
|
677 | - $session_data = preg_replace_callback( |
|
678 | - '!s:(d+):"(.*?)";!', |
|
679 | - function ($match) |
|
680 | - { |
|
681 | - return $match[1] === strlen($match[2]) |
|
682 | - ? $match[0] |
|
683 | - : 's:' . strlen($match[2]) . ':"' . $match[2] . '";'; |
|
684 | - }, |
|
685 | - $session_data |
|
686 | - ); |
|
687 | - } |
|
688 | - $session_data = maybe_unserialize($session_data); |
|
689 | - } |
|
690 | - // in case the data is encoded... try to decode it |
|
691 | - $session_data = $this->encryption instanceof EE_Encryption |
|
692 | - ? $this->encryption->base64_string_decode($session_data) |
|
693 | - : $session_data; |
|
694 | - if (! is_array($session_data)) { |
|
695 | - try { |
|
696 | - $session_data = maybe_unserialize($session_data); |
|
697 | - } catch (Exception $e) { |
|
698 | - $msg = esc_html__( |
|
699 | - 'An error occurred while attempting to unserialize the session data.', |
|
700 | - 'event_espresso' |
|
701 | - ); |
|
702 | - $msg .= WP_DEBUG |
|
703 | - ? '<br><pre>' |
|
704 | - . print_r($session_data, true) |
|
705 | - . '</pre><br>' |
|
706 | - . $this->find_serialize_error($session_data) |
|
707 | - : ''; |
|
708 | - $this->cache_storage->delete(EE_Session::session_id_prefix . $this->_sid); |
|
709 | - throw new InvalidSessionDataException($msg, 0, $e); |
|
710 | - } |
|
711 | - } |
|
712 | - // just a check to make sure the session array is indeed an array |
|
713 | - if (! is_array($session_data)) { |
|
714 | - // no?!?! then something is wrong |
|
715 | - $msg = esc_html__( |
|
716 | - 'The session data is missing, invalid, or corrupted.', |
|
717 | - 'event_espresso' |
|
718 | - ); |
|
719 | - $msg .= WP_DEBUG |
|
720 | - ? '<br><pre>' . print_r($session_data, true) . '</pre><br>' . $this->find_serialize_error($session_data) |
|
721 | - : ''; |
|
722 | - $this->cache_storage->delete(EE_Session::session_id_prefix . $this->_sid); |
|
723 | - throw new InvalidSessionDataException($msg); |
|
724 | - } |
|
725 | - if (isset($session_data['transaction']) && absint($session_data['transaction']) !== 0) { |
|
726 | - $session_data['transaction'] = EEM_Transaction::instance()->get_one_by_ID( |
|
727 | - $session_data['transaction'] |
|
728 | - ); |
|
729 | - } |
|
730 | - return $session_data; |
|
731 | - } |
|
732 | - |
|
733 | - |
|
734 | - |
|
735 | - /** |
|
736 | - * _generate_session_id |
|
737 | - * Retrieves the PHP session id either directly from the PHP session, |
|
738 | - * or from the $_REQUEST array if it was passed in from an AJAX request. |
|
739 | - * The session id is then salted and hashed (mmm sounds tasty) |
|
740 | - * so that it can be safely used as a $_REQUEST param |
|
741 | - * |
|
742 | - * @return string |
|
743 | - */ |
|
744 | - protected function _generate_session_id() |
|
745 | - { |
|
746 | - // check if the SID was passed explicitly, otherwise get from session, then add salt and hash it to reduce length |
|
747 | - if (isset($_REQUEST['EESID'])) { |
|
748 | - $session_id = sanitize_text_field($_REQUEST['EESID']); |
|
749 | - } else { |
|
750 | - $session_id = md5(session_id() . get_current_blog_id() . $this->_get_sid_salt()); |
|
751 | - } |
|
752 | - return apply_filters('FHEE__EE_Session___generate_session_id__session_id', $session_id); |
|
753 | - } |
|
754 | - |
|
755 | - |
|
756 | - |
|
757 | - /** |
|
758 | - * _get_sid_salt |
|
759 | - * |
|
760 | - * @return string |
|
761 | - */ |
|
762 | - protected function _get_sid_salt() |
|
763 | - { |
|
764 | - // was session id salt already saved to db ? |
|
765 | - if (empty($this->_sid_salt)) { |
|
766 | - // no? then maybe use WP defined constant |
|
767 | - if (defined('AUTH_SALT')) { |
|
768 | - $this->_sid_salt = AUTH_SALT; |
|
769 | - } |
|
770 | - // if salt doesn't exist or is too short |
|
771 | - if (strlen($this->_sid_salt) < 32) { |
|
772 | - // create a new one |
|
773 | - $this->_sid_salt = wp_generate_password(64); |
|
774 | - } |
|
775 | - // and save it as a permanent session setting |
|
776 | - $this->updateSessionSettings(array('sid_salt' => $this->_sid_salt)); |
|
777 | - } |
|
778 | - return $this->_sid_salt; |
|
779 | - } |
|
780 | - |
|
781 | - |
|
782 | - |
|
783 | - /** |
|
784 | - * _set_init_access_and_expiration |
|
785 | - * |
|
786 | - * @return void |
|
787 | - */ |
|
788 | - protected function _set_init_access_and_expiration() |
|
789 | - { |
|
790 | - $this->_time = time(); |
|
791 | - $this->_expiration = $this->_time + $this->session_lifespan->inSeconds(); |
|
792 | - // set initial site access time |
|
793 | - $this->_session_data['init_access'] = $this->_time; |
|
794 | - // and the session expiration |
|
795 | - $this->_session_data['expiration'] = $this->_expiration; |
|
796 | - } |
|
797 | - |
|
798 | - |
|
799 | - |
|
800 | - /** |
|
801 | - * @update session data prior to saving to the db |
|
802 | - * @access public |
|
803 | - * @param bool $new_session |
|
804 | - * @return TRUE on success, FALSE on fail |
|
805 | - * @throws EE_Error |
|
806 | - * @throws InvalidArgumentException |
|
807 | - * @throws InvalidDataTypeException |
|
808 | - * @throws InvalidInterfaceException |
|
809 | - */ |
|
810 | - public function update($new_session = false) |
|
811 | - { |
|
812 | - $this->_session_data = $this->_session_data !== null |
|
813 | - && is_array($this->_session_data) |
|
814 | - && isset($this->_session_data['id']) |
|
815 | - ? $this->_session_data |
|
816 | - : array(); |
|
817 | - if (empty($this->_session_data)) { |
|
818 | - $this->_set_defaults(); |
|
819 | - } |
|
820 | - $session_data = array(); |
|
821 | - foreach ($this->_session_data as $key => $value) { |
|
822 | - |
|
823 | - switch ($key) { |
|
824 | - |
|
825 | - case 'id' : |
|
826 | - // session ID |
|
827 | - $session_data['id'] = $this->_sid; |
|
828 | - break; |
|
829 | - case 'ip_address' : |
|
830 | - // visitor ip address |
|
831 | - $session_data['ip_address'] = $this->request->ipAddress(); |
|
832 | - break; |
|
833 | - case 'user_agent' : |
|
834 | - // visitor user_agent |
|
835 | - $session_data['user_agent'] = $this->_user_agent; |
|
836 | - break; |
|
837 | - case 'init_access' : |
|
838 | - $session_data['init_access'] = absint($value); |
|
839 | - break; |
|
840 | - case 'last_access' : |
|
841 | - // current access time |
|
842 | - $session_data['last_access'] = $this->_time; |
|
843 | - break; |
|
844 | - case 'expiration' : |
|
845 | - // when the session expires |
|
846 | - $session_data['expiration'] = ! empty($this->_expiration) |
|
847 | - ? $this->_expiration |
|
848 | - : $session_data['init_access'] + $this->session_lifespan->inSeconds(); |
|
849 | - break; |
|
850 | - case 'user_id' : |
|
851 | - // current user if logged in |
|
852 | - $session_data['user_id'] = $this->_wp_user_id(); |
|
853 | - break; |
|
854 | - case 'pages_visited' : |
|
855 | - $page_visit = $this->_get_page_visit(); |
|
856 | - if ($page_visit) { |
|
857 | - // set pages visited where the first will be the http referrer |
|
858 | - $this->_session_data['pages_visited'][ $this->_time ] = $page_visit; |
|
859 | - // we'll only save the last 10 page visits. |
|
860 | - $session_data['pages_visited'] = array_slice($this->_session_data['pages_visited'], -10); |
|
861 | - } |
|
862 | - break; |
|
863 | - default : |
|
864 | - // carry any other data over |
|
865 | - $session_data[ $key ] = $this->_session_data[ $key ]; |
|
866 | - } |
|
867 | - } |
|
868 | - $this->_session_data = $session_data; |
|
869 | - // creating a new session does not require saving to the db just yet |
|
870 | - if (! $new_session) { |
|
871 | - // ready? let's save |
|
872 | - if ($this->_save_session_to_db()) { |
|
873 | - return true; |
|
874 | - } |
|
875 | - return false; |
|
876 | - } |
|
877 | - // meh, why not? |
|
878 | - return true; |
|
879 | - } |
|
880 | - |
|
881 | - |
|
882 | - |
|
883 | - /** |
|
884 | - * @create session data array |
|
885 | - * @access public |
|
886 | - * @return bool |
|
887 | - * @throws EE_Error |
|
888 | - * @throws InvalidArgumentException |
|
889 | - * @throws InvalidDataTypeException |
|
890 | - * @throws InvalidInterfaceException |
|
891 | - */ |
|
892 | - private function _create_espresso_session() |
|
893 | - { |
|
894 | - do_action('AHEE_log', __CLASS__, __FUNCTION__, ''); |
|
895 | - // use the update function for now with $new_session arg set to TRUE |
|
896 | - return $this->update(true) ? true : false; |
|
897 | - } |
|
898 | - |
|
899 | - |
|
900 | - |
|
901 | - /** |
|
902 | - * _save_session_to_db |
|
903 | - * |
|
904 | - * @param bool $clear_session |
|
905 | - * @return string |
|
906 | - * @throws EE_Error |
|
907 | - * @throws InvalidArgumentException |
|
908 | - * @throws InvalidDataTypeException |
|
909 | - * @throws InvalidInterfaceException |
|
910 | - */ |
|
911 | - private function _save_session_to_db($clear_session = false) |
|
912 | - { |
|
913 | - // don't save sessions for crawlers |
|
914 | - // and unless we're deleting the session data, don't save anything if there isn't a cart |
|
915 | - if ($this->request->isBot() || (! $clear_session && ! $this->cart() instanceof EE_Cart)) { |
|
916 | - return false; |
|
917 | - } |
|
918 | - $transaction = $this->transaction(); |
|
919 | - if ($transaction instanceof EE_Transaction) { |
|
920 | - if (! $transaction->ID()) { |
|
921 | - $transaction->save(); |
|
922 | - } |
|
923 | - $this->_session_data['transaction'] = $transaction->ID(); |
|
924 | - } |
|
925 | - // then serialize all of our session data |
|
926 | - $session_data = serialize($this->_session_data); |
|
927 | - // do we need to also encode it to avoid corrupted data when saved to the db? |
|
928 | - $session_data = $this->_use_encryption |
|
929 | - ? $this->encryption->base64_string_encode($session_data) |
|
930 | - : $session_data; |
|
931 | - // maybe save hash check |
|
932 | - if (apply_filters('FHEE__EE_Session___perform_session_id_hash_check', WP_DEBUG)) { |
|
933 | - $this->cache_storage->add( |
|
934 | - EE_Session::hash_check_prefix . $this->_sid, |
|
935 | - md5($session_data), |
|
936 | - $this->session_lifespan->inSeconds() |
|
937 | - ); |
|
938 | - } |
|
939 | - // we're using the Transient API for storing session data, |
|
940 | - return $this->cache_storage->add( |
|
941 | - EE_Session::session_id_prefix . $this->_sid, |
|
942 | - $session_data, |
|
943 | - $this->session_lifespan->inSeconds() |
|
944 | - ); |
|
945 | - } |
|
946 | - |
|
947 | - |
|
948 | - /** |
|
949 | - * @get the full page request the visitor is accessing |
|
950 | - * @access public |
|
951 | - * @return string |
|
952 | - */ |
|
953 | - public function _get_page_visit() |
|
954 | - { |
|
955 | - $page_visit = home_url('/') . 'wp-admin/admin-ajax.php'; |
|
956 | - // check for request url |
|
957 | - if (isset($_SERVER['REQUEST_URI'])) { |
|
958 | - $http_host = ''; |
|
959 | - $page_id = '?'; |
|
960 | - $e_reg = ''; |
|
961 | - $request_uri = esc_url($_SERVER['REQUEST_URI']); |
|
962 | - $ru_bits = explode('?', $request_uri); |
|
963 | - $request_uri = $ru_bits[0]; |
|
964 | - // check for and grab host as well |
|
965 | - if (isset($_SERVER['HTTP_HOST'])) { |
|
966 | - $http_host = esc_url($_SERVER['HTTP_HOST']); |
|
967 | - } |
|
968 | - // check for page_id in SERVER REQUEST |
|
969 | - if (isset($_REQUEST['page_id'])) { |
|
970 | - // rebuild $e_reg without any of the extra parameters |
|
971 | - $page_id = '?page_id=' . esc_attr($_REQUEST['page_id']) . '&'; |
|
972 | - } |
|
973 | - // check for $e_reg in SERVER REQUEST |
|
974 | - if (isset($_REQUEST['ee'])) { |
|
975 | - // rebuild $e_reg without any of the extra parameters |
|
976 | - $e_reg = 'ee=' . esc_attr($_REQUEST['ee']); |
|
977 | - } |
|
978 | - $page_visit = rtrim($http_host . $request_uri . $page_id . $e_reg, '?'); |
|
979 | - } |
|
980 | - return $page_visit !== home_url('/wp-admin/admin-ajax.php') ? $page_visit : ''; |
|
981 | - } |
|
982 | - |
|
983 | - |
|
984 | - |
|
985 | - /** |
|
986 | - * @the current wp user id |
|
987 | - * @access public |
|
988 | - * @return int |
|
989 | - */ |
|
990 | - public function _wp_user_id() |
|
991 | - { |
|
992 | - // if I need to explain the following lines of code, then you shouldn't be looking at this! |
|
993 | - $this->_wp_user_id = get_current_user_id(); |
|
994 | - return $this->_wp_user_id; |
|
995 | - } |
|
996 | - |
|
997 | - |
|
998 | - |
|
999 | - /** |
|
1000 | - * Clear EE_Session data |
|
1001 | - * |
|
1002 | - * @access public |
|
1003 | - * @param string $class |
|
1004 | - * @param string $function |
|
1005 | - * @return void |
|
1006 | - * @throws EE_Error |
|
1007 | - * @throws InvalidArgumentException |
|
1008 | - * @throws InvalidDataTypeException |
|
1009 | - * @throws InvalidInterfaceException |
|
1010 | - */ |
|
1011 | - public function clear_session($class = '', $function = '') |
|
1012 | - { |
|
396 | + /** |
|
397 | + * @param \EE_Cart $cart |
|
398 | + * @return bool |
|
399 | + */ |
|
400 | + public function set_cart(EE_Cart $cart) |
|
401 | + { |
|
402 | + $this->_session_data['cart'] = $cart; |
|
403 | + return true; |
|
404 | + } |
|
405 | + |
|
406 | + |
|
407 | + |
|
408 | + /** |
|
409 | + * reset_cart |
|
410 | + */ |
|
411 | + public function reset_cart() |
|
412 | + { |
|
413 | + do_action('AHEE__EE_Session__reset_cart__before_reset', $this); |
|
414 | + $this->_session_data['cart'] = null; |
|
415 | + } |
|
416 | + |
|
417 | + |
|
418 | + |
|
419 | + /** |
|
420 | + * @return \EE_Cart |
|
421 | + */ |
|
422 | + public function cart() |
|
423 | + { |
|
424 | + return isset($this->_session_data['cart']) && $this->_session_data['cart'] instanceof EE_Cart |
|
425 | + ? $this->_session_data['cart'] |
|
426 | + : null; |
|
427 | + } |
|
428 | + |
|
429 | + |
|
430 | + |
|
431 | + /** |
|
432 | + * @param \EE_Checkout $checkout |
|
433 | + * @return bool |
|
434 | + */ |
|
435 | + public function set_checkout(EE_Checkout $checkout) |
|
436 | + { |
|
437 | + $this->_session_data['checkout'] = $checkout; |
|
438 | + return true; |
|
439 | + } |
|
440 | + |
|
441 | + |
|
442 | + |
|
443 | + /** |
|
444 | + * reset_checkout |
|
445 | + */ |
|
446 | + public function reset_checkout() |
|
447 | + { |
|
448 | + do_action('AHEE__EE_Session__reset_checkout__before_reset', $this); |
|
449 | + $this->_session_data['checkout'] = null; |
|
450 | + } |
|
451 | + |
|
452 | + |
|
453 | + |
|
454 | + /** |
|
455 | + * @return \EE_Checkout |
|
456 | + */ |
|
457 | + public function checkout() |
|
458 | + { |
|
459 | + return isset($this->_session_data['checkout']) && $this->_session_data['checkout'] instanceof EE_Checkout |
|
460 | + ? $this->_session_data['checkout'] |
|
461 | + : null; |
|
462 | + } |
|
463 | + |
|
464 | + |
|
465 | + |
|
466 | + /** |
|
467 | + * @param \EE_Transaction $transaction |
|
468 | + * @return bool |
|
469 | + * @throws EE_Error |
|
470 | + */ |
|
471 | + public function set_transaction(EE_Transaction $transaction) |
|
472 | + { |
|
473 | + // first remove the session from the transaction before we save the transaction in the session |
|
474 | + $transaction->set_txn_session_data(null); |
|
475 | + $this->_session_data['transaction'] = $transaction; |
|
476 | + return true; |
|
477 | + } |
|
478 | + |
|
479 | + |
|
480 | + |
|
481 | + /** |
|
482 | + * reset_transaction |
|
483 | + */ |
|
484 | + public function reset_transaction() |
|
485 | + { |
|
486 | + do_action('AHEE__EE_Session__reset_transaction__before_reset', $this); |
|
487 | + $this->_session_data['transaction'] = null; |
|
488 | + } |
|
489 | + |
|
490 | + |
|
491 | + |
|
492 | + /** |
|
493 | + * @return \EE_Transaction |
|
494 | + */ |
|
495 | + public function transaction() |
|
496 | + { |
|
497 | + return isset($this->_session_data['transaction']) |
|
498 | + && $this->_session_data['transaction'] instanceof EE_Transaction |
|
499 | + ? $this->_session_data['transaction'] |
|
500 | + : null; |
|
501 | + } |
|
502 | + |
|
503 | + |
|
504 | + /** |
|
505 | + * retrieve session data |
|
506 | + * |
|
507 | + * @param null $key |
|
508 | + * @param bool $reset_cache |
|
509 | + * @return array |
|
510 | + */ |
|
511 | + public function get_session_data($key = null, $reset_cache = false) |
|
512 | + { |
|
513 | + if ($reset_cache) { |
|
514 | + $this->reset_cart(); |
|
515 | + $this->reset_checkout(); |
|
516 | + $this->reset_transaction(); |
|
517 | + } |
|
518 | + if (! empty($key)) { |
|
519 | + return isset($this->_session_data[ $key ]) ? $this->_session_data[ $key ] : null; |
|
520 | + } |
|
521 | + return $this->_session_data; |
|
522 | + } |
|
523 | + |
|
524 | + |
|
525 | + /** |
|
526 | + * Returns TRUE on success, FALSE on fail |
|
527 | + * |
|
528 | + * @param array $data |
|
529 | + * @return bool |
|
530 | + */ |
|
531 | + public function set_session_data($data) |
|
532 | + { |
|
533 | + // nothing ??? bad data ??? go home! |
|
534 | + if (empty($data) || ! is_array($data)) { |
|
535 | + EE_Error::add_error( |
|
536 | + esc_html__( |
|
537 | + 'No session data or invalid session data was provided.', |
|
538 | + 'event_espresso' |
|
539 | + ), |
|
540 | + __FILE__, __FUNCTION__, __LINE__ |
|
541 | + ); |
|
542 | + return false; |
|
543 | + } |
|
544 | + foreach ($data as $key => $value) { |
|
545 | + if (isset($this->_default_session_vars[ $key ])) { |
|
546 | + EE_Error::add_error( |
|
547 | + sprintf( |
|
548 | + esc_html__( |
|
549 | + 'Sorry! %s is a default session datum and can not be reset.', |
|
550 | + 'event_espresso' |
|
551 | + ), |
|
552 | + $key |
|
553 | + ), |
|
554 | + __FILE__, __FUNCTION__, __LINE__ |
|
555 | + ); |
|
556 | + return false; |
|
557 | + } |
|
558 | + $this->_session_data[ $key ] = $value; |
|
559 | + } |
|
560 | + return true; |
|
561 | + } |
|
562 | + |
|
563 | + |
|
564 | + |
|
565 | + /** |
|
566 | + * @initiate session |
|
567 | + * @access private |
|
568 | + * @return TRUE on success, FALSE on fail |
|
569 | + * @throws EE_Error |
|
570 | + * @throws InvalidArgumentException |
|
571 | + * @throws InvalidDataTypeException |
|
572 | + * @throws InvalidInterfaceException |
|
573 | + * @throws InvalidSessionDataException |
|
574 | + */ |
|
575 | + private function _espresso_session() |
|
576 | + { |
|
577 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
578 | + // check that session has started |
|
579 | + if (session_id() === '') { |
|
580 | + //starts a new session if one doesn't already exist, or re-initiates an existing one |
|
581 | + session_start(); |
|
582 | + } |
|
583 | + $this->status = EE_Session::STATUS_OPEN; |
|
584 | + // get our modified session ID |
|
585 | + $this->_sid = $this->_generate_session_id(); |
|
586 | + // and the visitors IP |
|
587 | + $this->_ip_address = $this->request->ipAddress(); |
|
588 | + // set the "user agent" |
|
589 | + $this->_user_agent = $this->request->userAgent(); |
|
590 | + // now let's retrieve what's in the db |
|
591 | + $session_data = $this->_retrieve_session_data(); |
|
592 | + if (! empty($session_data)) { |
|
593 | + // get the current time in UTC |
|
594 | + $this->_time = $this->_time !== null ? $this->_time : time(); |
|
595 | + // and reset the session expiration |
|
596 | + $this->_expiration = isset($session_data['expiration']) |
|
597 | + ? $session_data['expiration'] |
|
598 | + : $this->_time + $this->session_lifespan->inSeconds(); |
|
599 | + } else { |
|
600 | + // set initial site access time and the session expiration |
|
601 | + $this->_set_init_access_and_expiration(); |
|
602 | + // set referer |
|
603 | + $this->_session_data['pages_visited'][ $this->_session_data['init_access'] ] = isset($_SERVER['HTTP_REFERER']) |
|
604 | + ? esc_attr($_SERVER['HTTP_REFERER']) |
|
605 | + : ''; |
|
606 | + // no previous session = go back and create one (on top of the data above) |
|
607 | + return false; |
|
608 | + } |
|
609 | + // now the user agent |
|
610 | + if ($session_data['user_agent'] !== $this->_user_agent) { |
|
611 | + return false; |
|
612 | + } |
|
613 | + // wait a minute... how old are you? |
|
614 | + if ($this->_time > $this->_expiration) { |
|
615 | + // yer too old fer me! |
|
616 | + $this->_expired = true; |
|
617 | + // wipe out everything that isn't a default session datum |
|
618 | + $this->clear_session(__CLASS__, __FUNCTION__); |
|
619 | + } |
|
620 | + // make event espresso session data available to plugin |
|
621 | + $this->_session_data = array_merge($this->_session_data, $session_data); |
|
622 | + return true; |
|
623 | + } |
|
624 | + |
|
625 | + |
|
626 | + |
|
627 | + /** |
|
628 | + * _get_session_data |
|
629 | + * Retrieves the session data, and attempts to correct any encoding issues that can occur due to improperly setup |
|
630 | + * databases |
|
631 | + * |
|
632 | + * @return array |
|
633 | + * @throws EE_Error |
|
634 | + * @throws InvalidArgumentException |
|
635 | + * @throws InvalidSessionDataException |
|
636 | + * @throws InvalidDataTypeException |
|
637 | + * @throws InvalidInterfaceException |
|
638 | + */ |
|
639 | + protected function _retrieve_session_data() |
|
640 | + { |
|
641 | + $ssn_key = EE_Session::session_id_prefix . $this->_sid; |
|
642 | + try { |
|
643 | + // we're using WP's Transient API to store session data using the PHP session ID as the option name |
|
644 | + $session_data = $this->cache_storage->get($ssn_key, false); |
|
645 | + if (empty($session_data)) { |
|
646 | + return array(); |
|
647 | + } |
|
648 | + if (apply_filters('FHEE__EE_Session___perform_session_id_hash_check', WP_DEBUG)) { |
|
649 | + $hash_check = $this->cache_storage->get( |
|
650 | + EE_Session::hash_check_prefix . $this->_sid, |
|
651 | + false |
|
652 | + ); |
|
653 | + if ($hash_check && $hash_check !== md5($session_data)) { |
|
654 | + EE_Error::add_error( |
|
655 | + sprintf( |
|
656 | + __( |
|
657 | + 'The stored data for session %1$s failed to pass a hash check and therefore appears to be invalid.', |
|
658 | + 'event_espresso' |
|
659 | + ), |
|
660 | + EE_Session::session_id_prefix . $this->_sid |
|
661 | + ), |
|
662 | + __FILE__, __FUNCTION__, __LINE__ |
|
663 | + ); |
|
664 | + } |
|
665 | + } |
|
666 | + } catch (Exception $e) { |
|
667 | + // let's just eat that error for now and attempt to correct any corrupted data |
|
668 | + global $wpdb; |
|
669 | + $row = $wpdb->get_row( |
|
670 | + $wpdb->prepare( |
|
671 | + "SELECT option_value FROM {$wpdb->options} WHERE option_name = %s LIMIT 1", |
|
672 | + '_transient_' . $ssn_key |
|
673 | + ) |
|
674 | + ); |
|
675 | + $session_data = is_object($row) ? $row->option_value : null; |
|
676 | + if ($session_data) { |
|
677 | + $session_data = preg_replace_callback( |
|
678 | + '!s:(d+):"(.*?)";!', |
|
679 | + function ($match) |
|
680 | + { |
|
681 | + return $match[1] === strlen($match[2]) |
|
682 | + ? $match[0] |
|
683 | + : 's:' . strlen($match[2]) . ':"' . $match[2] . '";'; |
|
684 | + }, |
|
685 | + $session_data |
|
686 | + ); |
|
687 | + } |
|
688 | + $session_data = maybe_unserialize($session_data); |
|
689 | + } |
|
690 | + // in case the data is encoded... try to decode it |
|
691 | + $session_data = $this->encryption instanceof EE_Encryption |
|
692 | + ? $this->encryption->base64_string_decode($session_data) |
|
693 | + : $session_data; |
|
694 | + if (! is_array($session_data)) { |
|
695 | + try { |
|
696 | + $session_data = maybe_unserialize($session_data); |
|
697 | + } catch (Exception $e) { |
|
698 | + $msg = esc_html__( |
|
699 | + 'An error occurred while attempting to unserialize the session data.', |
|
700 | + 'event_espresso' |
|
701 | + ); |
|
702 | + $msg .= WP_DEBUG |
|
703 | + ? '<br><pre>' |
|
704 | + . print_r($session_data, true) |
|
705 | + . '</pre><br>' |
|
706 | + . $this->find_serialize_error($session_data) |
|
707 | + : ''; |
|
708 | + $this->cache_storage->delete(EE_Session::session_id_prefix . $this->_sid); |
|
709 | + throw new InvalidSessionDataException($msg, 0, $e); |
|
710 | + } |
|
711 | + } |
|
712 | + // just a check to make sure the session array is indeed an array |
|
713 | + if (! is_array($session_data)) { |
|
714 | + // no?!?! then something is wrong |
|
715 | + $msg = esc_html__( |
|
716 | + 'The session data is missing, invalid, or corrupted.', |
|
717 | + 'event_espresso' |
|
718 | + ); |
|
719 | + $msg .= WP_DEBUG |
|
720 | + ? '<br><pre>' . print_r($session_data, true) . '</pre><br>' . $this->find_serialize_error($session_data) |
|
721 | + : ''; |
|
722 | + $this->cache_storage->delete(EE_Session::session_id_prefix . $this->_sid); |
|
723 | + throw new InvalidSessionDataException($msg); |
|
724 | + } |
|
725 | + if (isset($session_data['transaction']) && absint($session_data['transaction']) !== 0) { |
|
726 | + $session_data['transaction'] = EEM_Transaction::instance()->get_one_by_ID( |
|
727 | + $session_data['transaction'] |
|
728 | + ); |
|
729 | + } |
|
730 | + return $session_data; |
|
731 | + } |
|
732 | + |
|
733 | + |
|
734 | + |
|
735 | + /** |
|
736 | + * _generate_session_id |
|
737 | + * Retrieves the PHP session id either directly from the PHP session, |
|
738 | + * or from the $_REQUEST array if it was passed in from an AJAX request. |
|
739 | + * The session id is then salted and hashed (mmm sounds tasty) |
|
740 | + * so that it can be safely used as a $_REQUEST param |
|
741 | + * |
|
742 | + * @return string |
|
743 | + */ |
|
744 | + protected function _generate_session_id() |
|
745 | + { |
|
746 | + // check if the SID was passed explicitly, otherwise get from session, then add salt and hash it to reduce length |
|
747 | + if (isset($_REQUEST['EESID'])) { |
|
748 | + $session_id = sanitize_text_field($_REQUEST['EESID']); |
|
749 | + } else { |
|
750 | + $session_id = md5(session_id() . get_current_blog_id() . $this->_get_sid_salt()); |
|
751 | + } |
|
752 | + return apply_filters('FHEE__EE_Session___generate_session_id__session_id', $session_id); |
|
753 | + } |
|
754 | + |
|
755 | + |
|
756 | + |
|
757 | + /** |
|
758 | + * _get_sid_salt |
|
759 | + * |
|
760 | + * @return string |
|
761 | + */ |
|
762 | + protected function _get_sid_salt() |
|
763 | + { |
|
764 | + // was session id salt already saved to db ? |
|
765 | + if (empty($this->_sid_salt)) { |
|
766 | + // no? then maybe use WP defined constant |
|
767 | + if (defined('AUTH_SALT')) { |
|
768 | + $this->_sid_salt = AUTH_SALT; |
|
769 | + } |
|
770 | + // if salt doesn't exist or is too short |
|
771 | + if (strlen($this->_sid_salt) < 32) { |
|
772 | + // create a new one |
|
773 | + $this->_sid_salt = wp_generate_password(64); |
|
774 | + } |
|
775 | + // and save it as a permanent session setting |
|
776 | + $this->updateSessionSettings(array('sid_salt' => $this->_sid_salt)); |
|
777 | + } |
|
778 | + return $this->_sid_salt; |
|
779 | + } |
|
780 | + |
|
781 | + |
|
782 | + |
|
783 | + /** |
|
784 | + * _set_init_access_and_expiration |
|
785 | + * |
|
786 | + * @return void |
|
787 | + */ |
|
788 | + protected function _set_init_access_and_expiration() |
|
789 | + { |
|
790 | + $this->_time = time(); |
|
791 | + $this->_expiration = $this->_time + $this->session_lifespan->inSeconds(); |
|
792 | + // set initial site access time |
|
793 | + $this->_session_data['init_access'] = $this->_time; |
|
794 | + // and the session expiration |
|
795 | + $this->_session_data['expiration'] = $this->_expiration; |
|
796 | + } |
|
797 | + |
|
798 | + |
|
799 | + |
|
800 | + /** |
|
801 | + * @update session data prior to saving to the db |
|
802 | + * @access public |
|
803 | + * @param bool $new_session |
|
804 | + * @return TRUE on success, FALSE on fail |
|
805 | + * @throws EE_Error |
|
806 | + * @throws InvalidArgumentException |
|
807 | + * @throws InvalidDataTypeException |
|
808 | + * @throws InvalidInterfaceException |
|
809 | + */ |
|
810 | + public function update($new_session = false) |
|
811 | + { |
|
812 | + $this->_session_data = $this->_session_data !== null |
|
813 | + && is_array($this->_session_data) |
|
814 | + && isset($this->_session_data['id']) |
|
815 | + ? $this->_session_data |
|
816 | + : array(); |
|
817 | + if (empty($this->_session_data)) { |
|
818 | + $this->_set_defaults(); |
|
819 | + } |
|
820 | + $session_data = array(); |
|
821 | + foreach ($this->_session_data as $key => $value) { |
|
822 | + |
|
823 | + switch ($key) { |
|
824 | + |
|
825 | + case 'id' : |
|
826 | + // session ID |
|
827 | + $session_data['id'] = $this->_sid; |
|
828 | + break; |
|
829 | + case 'ip_address' : |
|
830 | + // visitor ip address |
|
831 | + $session_data['ip_address'] = $this->request->ipAddress(); |
|
832 | + break; |
|
833 | + case 'user_agent' : |
|
834 | + // visitor user_agent |
|
835 | + $session_data['user_agent'] = $this->_user_agent; |
|
836 | + break; |
|
837 | + case 'init_access' : |
|
838 | + $session_data['init_access'] = absint($value); |
|
839 | + break; |
|
840 | + case 'last_access' : |
|
841 | + // current access time |
|
842 | + $session_data['last_access'] = $this->_time; |
|
843 | + break; |
|
844 | + case 'expiration' : |
|
845 | + // when the session expires |
|
846 | + $session_data['expiration'] = ! empty($this->_expiration) |
|
847 | + ? $this->_expiration |
|
848 | + : $session_data['init_access'] + $this->session_lifespan->inSeconds(); |
|
849 | + break; |
|
850 | + case 'user_id' : |
|
851 | + // current user if logged in |
|
852 | + $session_data['user_id'] = $this->_wp_user_id(); |
|
853 | + break; |
|
854 | + case 'pages_visited' : |
|
855 | + $page_visit = $this->_get_page_visit(); |
|
856 | + if ($page_visit) { |
|
857 | + // set pages visited where the first will be the http referrer |
|
858 | + $this->_session_data['pages_visited'][ $this->_time ] = $page_visit; |
|
859 | + // we'll only save the last 10 page visits. |
|
860 | + $session_data['pages_visited'] = array_slice($this->_session_data['pages_visited'], -10); |
|
861 | + } |
|
862 | + break; |
|
863 | + default : |
|
864 | + // carry any other data over |
|
865 | + $session_data[ $key ] = $this->_session_data[ $key ]; |
|
866 | + } |
|
867 | + } |
|
868 | + $this->_session_data = $session_data; |
|
869 | + // creating a new session does not require saving to the db just yet |
|
870 | + if (! $new_session) { |
|
871 | + // ready? let's save |
|
872 | + if ($this->_save_session_to_db()) { |
|
873 | + return true; |
|
874 | + } |
|
875 | + return false; |
|
876 | + } |
|
877 | + // meh, why not? |
|
878 | + return true; |
|
879 | + } |
|
880 | + |
|
881 | + |
|
882 | + |
|
883 | + /** |
|
884 | + * @create session data array |
|
885 | + * @access public |
|
886 | + * @return bool |
|
887 | + * @throws EE_Error |
|
888 | + * @throws InvalidArgumentException |
|
889 | + * @throws InvalidDataTypeException |
|
890 | + * @throws InvalidInterfaceException |
|
891 | + */ |
|
892 | + private function _create_espresso_session() |
|
893 | + { |
|
894 | + do_action('AHEE_log', __CLASS__, __FUNCTION__, ''); |
|
895 | + // use the update function for now with $new_session arg set to TRUE |
|
896 | + return $this->update(true) ? true : false; |
|
897 | + } |
|
898 | + |
|
899 | + |
|
900 | + |
|
901 | + /** |
|
902 | + * _save_session_to_db |
|
903 | + * |
|
904 | + * @param bool $clear_session |
|
905 | + * @return string |
|
906 | + * @throws EE_Error |
|
907 | + * @throws InvalidArgumentException |
|
908 | + * @throws InvalidDataTypeException |
|
909 | + * @throws InvalidInterfaceException |
|
910 | + */ |
|
911 | + private function _save_session_to_db($clear_session = false) |
|
912 | + { |
|
913 | + // don't save sessions for crawlers |
|
914 | + // and unless we're deleting the session data, don't save anything if there isn't a cart |
|
915 | + if ($this->request->isBot() || (! $clear_session && ! $this->cart() instanceof EE_Cart)) { |
|
916 | + return false; |
|
917 | + } |
|
918 | + $transaction = $this->transaction(); |
|
919 | + if ($transaction instanceof EE_Transaction) { |
|
920 | + if (! $transaction->ID()) { |
|
921 | + $transaction->save(); |
|
922 | + } |
|
923 | + $this->_session_data['transaction'] = $transaction->ID(); |
|
924 | + } |
|
925 | + // then serialize all of our session data |
|
926 | + $session_data = serialize($this->_session_data); |
|
927 | + // do we need to also encode it to avoid corrupted data when saved to the db? |
|
928 | + $session_data = $this->_use_encryption |
|
929 | + ? $this->encryption->base64_string_encode($session_data) |
|
930 | + : $session_data; |
|
931 | + // maybe save hash check |
|
932 | + if (apply_filters('FHEE__EE_Session___perform_session_id_hash_check', WP_DEBUG)) { |
|
933 | + $this->cache_storage->add( |
|
934 | + EE_Session::hash_check_prefix . $this->_sid, |
|
935 | + md5($session_data), |
|
936 | + $this->session_lifespan->inSeconds() |
|
937 | + ); |
|
938 | + } |
|
939 | + // we're using the Transient API for storing session data, |
|
940 | + return $this->cache_storage->add( |
|
941 | + EE_Session::session_id_prefix . $this->_sid, |
|
942 | + $session_data, |
|
943 | + $this->session_lifespan->inSeconds() |
|
944 | + ); |
|
945 | + } |
|
946 | + |
|
947 | + |
|
948 | + /** |
|
949 | + * @get the full page request the visitor is accessing |
|
950 | + * @access public |
|
951 | + * @return string |
|
952 | + */ |
|
953 | + public function _get_page_visit() |
|
954 | + { |
|
955 | + $page_visit = home_url('/') . 'wp-admin/admin-ajax.php'; |
|
956 | + // check for request url |
|
957 | + if (isset($_SERVER['REQUEST_URI'])) { |
|
958 | + $http_host = ''; |
|
959 | + $page_id = '?'; |
|
960 | + $e_reg = ''; |
|
961 | + $request_uri = esc_url($_SERVER['REQUEST_URI']); |
|
962 | + $ru_bits = explode('?', $request_uri); |
|
963 | + $request_uri = $ru_bits[0]; |
|
964 | + // check for and grab host as well |
|
965 | + if (isset($_SERVER['HTTP_HOST'])) { |
|
966 | + $http_host = esc_url($_SERVER['HTTP_HOST']); |
|
967 | + } |
|
968 | + // check for page_id in SERVER REQUEST |
|
969 | + if (isset($_REQUEST['page_id'])) { |
|
970 | + // rebuild $e_reg without any of the extra parameters |
|
971 | + $page_id = '?page_id=' . esc_attr($_REQUEST['page_id']) . '&'; |
|
972 | + } |
|
973 | + // check for $e_reg in SERVER REQUEST |
|
974 | + if (isset($_REQUEST['ee'])) { |
|
975 | + // rebuild $e_reg without any of the extra parameters |
|
976 | + $e_reg = 'ee=' . esc_attr($_REQUEST['ee']); |
|
977 | + } |
|
978 | + $page_visit = rtrim($http_host . $request_uri . $page_id . $e_reg, '?'); |
|
979 | + } |
|
980 | + return $page_visit !== home_url('/wp-admin/admin-ajax.php') ? $page_visit : ''; |
|
981 | + } |
|
982 | + |
|
983 | + |
|
984 | + |
|
985 | + /** |
|
986 | + * @the current wp user id |
|
987 | + * @access public |
|
988 | + * @return int |
|
989 | + */ |
|
990 | + public function _wp_user_id() |
|
991 | + { |
|
992 | + // if I need to explain the following lines of code, then you shouldn't be looking at this! |
|
993 | + $this->_wp_user_id = get_current_user_id(); |
|
994 | + return $this->_wp_user_id; |
|
995 | + } |
|
996 | + |
|
997 | + |
|
998 | + |
|
999 | + /** |
|
1000 | + * Clear EE_Session data |
|
1001 | + * |
|
1002 | + * @access public |
|
1003 | + * @param string $class |
|
1004 | + * @param string $function |
|
1005 | + * @return void |
|
1006 | + * @throws EE_Error |
|
1007 | + * @throws InvalidArgumentException |
|
1008 | + * @throws InvalidDataTypeException |
|
1009 | + * @throws InvalidInterfaceException |
|
1010 | + */ |
|
1011 | + public function clear_session($class = '', $function = '') |
|
1012 | + { |
|
1013 | 1013 | // echo ' |
1014 | 1014 | // <h3 style="color:#999;line-height:.9em;"> |
1015 | 1015 | // <span style="color:#2EA2CC">' . __CLASS__ . '</span>::<span style="color:#E76700">' . __FUNCTION__ . '( ' . $class . '::' . $function . '() )</span><br/> |
1016 | 1016 | // <span style="font-size:9px;font-weight:normal;">' . __FILE__ . '</span> <b style="font-size:10px;"> ' . __LINE__ . ' </b> |
1017 | 1017 | // </h3>'; |
1018 | - do_action('AHEE_log', __FILE__, __FUNCTION__, 'session cleared by : ' . $class . '::' . $function . '()'); |
|
1019 | - $this->reset_cart(); |
|
1020 | - $this->reset_checkout(); |
|
1021 | - $this->reset_transaction(); |
|
1022 | - // wipe out everything that isn't a default session datum |
|
1023 | - $this->reset_data(array_keys($this->_session_data)); |
|
1024 | - // reset initial site access time and the session expiration |
|
1025 | - $this->_set_init_access_and_expiration(); |
|
1026 | - $this->_save_session_to_db(true); |
|
1027 | - } |
|
1028 | - |
|
1029 | - |
|
1030 | - /** |
|
1031 | - * resets all non-default session vars. Returns TRUE on success, FALSE on fail |
|
1032 | - * |
|
1033 | - * @param array|mixed $data_to_reset |
|
1034 | - * @param bool $show_all_notices |
|
1035 | - * @return bool |
|
1036 | - */ |
|
1037 | - public function reset_data($data_to_reset = array(), $show_all_notices = false) |
|
1038 | - { |
|
1039 | - // if $data_to_reset is not in an array, then put it in one |
|
1040 | - if (! is_array($data_to_reset)) { |
|
1041 | - $data_to_reset = array($data_to_reset); |
|
1042 | - } |
|
1043 | - // nothing ??? go home! |
|
1044 | - if (empty($data_to_reset)) { |
|
1045 | - EE_Error::add_error(__('No session data could be reset, because no session var name was provided.', |
|
1046 | - 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
1047 | - return false; |
|
1048 | - } |
|
1049 | - $return_value = true; |
|
1050 | - // since $data_to_reset is an array, cycle through the values |
|
1051 | - foreach ($data_to_reset as $reset) { |
|
1052 | - |
|
1053 | - // first check to make sure it is a valid session var |
|
1054 | - if (isset($this->_session_data[ $reset ])) { |
|
1055 | - // then check to make sure it is not a default var |
|
1056 | - if (! array_key_exists($reset, $this->_default_session_vars)) { |
|
1057 | - // remove session var |
|
1058 | - unset($this->_session_data[ $reset ]); |
|
1059 | - if ($show_all_notices) { |
|
1060 | - EE_Error::add_success(sprintf(__('The session variable %s was removed.', 'event_espresso'), |
|
1061 | - $reset), __FILE__, __FUNCTION__, __LINE__); |
|
1062 | - } |
|
1063 | - } else { |
|
1064 | - // yeeeeeeeeerrrrrrrrrrr OUT !!!! |
|
1065 | - if ($show_all_notices) { |
|
1066 | - EE_Error::add_error(sprintf(__('Sorry! %s is a default session datum and can not be reset.', |
|
1067 | - 'event_espresso'), $reset), __FILE__, __FUNCTION__, __LINE__); |
|
1068 | - } |
|
1069 | - $return_value = false; |
|
1070 | - } |
|
1071 | - } elseif ($show_all_notices) { |
|
1072 | - // oops! that session var does not exist! |
|
1073 | - EE_Error::add_error(sprintf(__('The session item provided, %s, is invalid or does not exist.', |
|
1074 | - 'event_espresso'), $reset), __FILE__, __FUNCTION__, __LINE__); |
|
1075 | - $return_value = false; |
|
1076 | - } |
|
1077 | - } // end of foreach |
|
1078 | - return $return_value; |
|
1079 | - } |
|
1080 | - |
|
1081 | - |
|
1082 | - |
|
1083 | - /** |
|
1084 | - * wp_loaded |
|
1085 | - * |
|
1086 | - * @access public |
|
1087 | - * @throws EE_Error |
|
1088 | - * @throws InvalidDataTypeException |
|
1089 | - * @throws InvalidInterfaceException |
|
1090 | - * @throws InvalidArgumentException |
|
1091 | - */ |
|
1092 | - public function wp_loaded() |
|
1093 | - { |
|
1094 | - if ($this->request->requestParamIsSet('clear_session')) { |
|
1095 | - $this->clear_session(__CLASS__, __FUNCTION__); |
|
1096 | - } |
|
1097 | - } |
|
1098 | - |
|
1099 | - |
|
1100 | - |
|
1101 | - /** |
|
1102 | - * Used to reset the entire object (for tests). |
|
1103 | - * |
|
1104 | - * @since 4.3.0 |
|
1105 | - * @throws EE_Error |
|
1106 | - * @throws InvalidDataTypeException |
|
1107 | - * @throws InvalidInterfaceException |
|
1108 | - * @throws InvalidArgumentException |
|
1109 | - */ |
|
1110 | - public function reset_instance() |
|
1111 | - { |
|
1112 | - $this->clear_session(); |
|
1113 | - self::$_instance = null; |
|
1114 | - } |
|
1115 | - |
|
1116 | - |
|
1117 | - |
|
1118 | - public function configure_garbage_collection_filters() |
|
1119 | - { |
|
1120 | - // run old filter we had for controlling session cleanup |
|
1121 | - $expired_session_transient_delete_query_limit = absint( |
|
1122 | - apply_filters( |
|
1123 | - 'FHEE__EE_Session__garbage_collection___expired_session_transient_delete_query_limit', |
|
1124 | - 50 |
|
1125 | - ) |
|
1126 | - ); |
|
1127 | - // is there a value? or one that is different than the default 50 records? |
|
1128 | - if ($expired_session_transient_delete_query_limit === 0) { |
|
1129 | - // hook into TransientCacheStorage in case Session cleanup was turned off |
|
1130 | - add_filter('FHEE__TransientCacheStorage__transient_cleanup_schedule', '__return_zero'); |
|
1131 | - } elseif ($expired_session_transient_delete_query_limit !== 50) { |
|
1132 | - // or use that for the new transient cleanup query limit |
|
1133 | - add_filter( |
|
1134 | - 'FHEE__TransientCacheStorage__clearExpiredTransients__limit', |
|
1135 | - function () use ($expired_session_transient_delete_query_limit) |
|
1136 | - { |
|
1137 | - return $expired_session_transient_delete_query_limit; |
|
1138 | - } |
|
1139 | - ); |
|
1140 | - } |
|
1141 | - } |
|
1142 | - |
|
1143 | - |
|
1144 | - |
|
1145 | - /** |
|
1146 | - * @see http://stackoverflow.com/questions/10152904/unserialize-function-unserialize-error-at-offset/21389439#10152996 |
|
1147 | - * @param $data1 |
|
1148 | - * @return string |
|
1149 | - */ |
|
1150 | - private function find_serialize_error($data1) |
|
1151 | - { |
|
1152 | - $error = '<pre>'; |
|
1153 | - $data2 = preg_replace_callback( |
|
1154 | - '!s:(\d+):"(.*?)";!', |
|
1155 | - function ($match) |
|
1156 | - { |
|
1157 | - return ($match[1] === strlen($match[2])) |
|
1158 | - ? $match[0] |
|
1159 | - : 's:' |
|
1160 | - . strlen($match[2]) |
|
1161 | - . ':"' |
|
1162 | - . $match[2] |
|
1163 | - . '";'; |
|
1164 | - }, |
|
1165 | - $data1 |
|
1166 | - ); |
|
1167 | - $max = (strlen($data1) > strlen($data2)) ? strlen($data1) : strlen($data2); |
|
1168 | - $error .= $data1 . PHP_EOL; |
|
1169 | - $error .= $data2 . PHP_EOL; |
|
1170 | - for ($i = 0; $i < $max; $i++) { |
|
1171 | - if (@$data1[ $i ] !== @$data2[ $i ]) { |
|
1172 | - $error .= 'Difference ' . @$data1[ $i ] . ' != ' . @$data2[ $i ] . PHP_EOL; |
|
1173 | - $error .= "\t-> ORD number " . ord(@$data1[ $i ]) . ' != ' . ord(@$data2[ $i ]) . PHP_EOL; |
|
1174 | - $error .= "\t-> Line Number = $i" . PHP_EOL; |
|
1175 | - $start = ($i - 20); |
|
1176 | - $start = ($start < 0) ? 0 : $start; |
|
1177 | - $length = 40; |
|
1178 | - $point = $max - $i; |
|
1179 | - if ($point < 20) { |
|
1180 | - $rlength = 1; |
|
1181 | - $rpoint = -$point; |
|
1182 | - } else { |
|
1183 | - $rpoint = $length - 20; |
|
1184 | - $rlength = 1; |
|
1185 | - } |
|
1186 | - $error .= "\t-> Section Data1 = "; |
|
1187 | - $error .= substr_replace( |
|
1188 | - substr($data1, $start, $length), |
|
1189 | - "<b style=\"color:green\">{$data1[ $i ]}</b>", |
|
1190 | - $rpoint, |
|
1191 | - $rlength |
|
1192 | - ); |
|
1193 | - $error .= PHP_EOL; |
|
1194 | - $error .= "\t-> Section Data2 = "; |
|
1195 | - $error .= substr_replace( |
|
1196 | - substr($data2, $start, $length), |
|
1197 | - "<b style=\"color:red\">{$data2[ $i ]}</b>", |
|
1198 | - $rpoint, |
|
1199 | - $rlength |
|
1200 | - ); |
|
1201 | - $error .= PHP_EOL; |
|
1202 | - } |
|
1203 | - } |
|
1204 | - $error .= '</pre>'; |
|
1205 | - return $error; |
|
1206 | - } |
|
1207 | - |
|
1208 | - |
|
1209 | - /** |
|
1210 | - * Saves an array of settings used for configuring aspects of session behaviour |
|
1211 | - * |
|
1212 | - * @param array $updated_settings |
|
1213 | - */ |
|
1214 | - private function updateSessionSettings(array $updated_settings = array()) |
|
1215 | - { |
|
1216 | - // add existing settings, but only if not included in incoming $updated_settings array |
|
1217 | - $updated_settings += get_option(EE_Session::OPTION_NAME_SETTINGS, array()); |
|
1218 | - update_option(EE_Session::OPTION_NAME_SETTINGS, $updated_settings); |
|
1219 | - } |
|
1220 | - |
|
1221 | - |
|
1222 | - /** |
|
1223 | - * garbage_collection |
|
1224 | - */ |
|
1225 | - public function garbageCollection() |
|
1226 | - { |
|
1227 | - // only perform during regular requests if last garbage collection was over an hour ago |
|
1228 | - if (! (defined('DOING_AJAX') && DOING_AJAX) && (time() - HOUR_IN_SECONDS) >= $this->_last_gc) { |
|
1229 | - $this->_last_gc = time(); |
|
1230 | - $this->updateSessionSettings(array('last_gc' => $this->_last_gc)); |
|
1231 | - /** @type WPDB $wpdb */ |
|
1232 | - global $wpdb; |
|
1233 | - // filter the query limit. Set to 0 to turn off garbage collection |
|
1234 | - $expired_session_transient_delete_query_limit = absint( |
|
1235 | - apply_filters( |
|
1236 | - 'FHEE__EE_Session__garbage_collection___expired_session_transient_delete_query_limit', |
|
1237 | - 50 |
|
1238 | - ) |
|
1239 | - ); |
|
1240 | - // non-zero LIMIT means take out the trash |
|
1241 | - if ($expired_session_transient_delete_query_limit) { |
|
1242 | - $session_key = str_replace('_', '\_', EE_Session::session_id_prefix); |
|
1243 | - $hash_check_key = str_replace('_', '\_', EE_Session::hash_check_prefix); |
|
1244 | - // since transient expiration timestamps are set in the future, we can compare against NOW |
|
1245 | - // but we only want to pick up any trash that's been around for more than a day |
|
1246 | - $expiration = time() - DAY_IN_SECONDS; |
|
1247 | - $SQL = " |
|
1018 | + do_action('AHEE_log', __FILE__, __FUNCTION__, 'session cleared by : ' . $class . '::' . $function . '()'); |
|
1019 | + $this->reset_cart(); |
|
1020 | + $this->reset_checkout(); |
|
1021 | + $this->reset_transaction(); |
|
1022 | + // wipe out everything that isn't a default session datum |
|
1023 | + $this->reset_data(array_keys($this->_session_data)); |
|
1024 | + // reset initial site access time and the session expiration |
|
1025 | + $this->_set_init_access_and_expiration(); |
|
1026 | + $this->_save_session_to_db(true); |
|
1027 | + } |
|
1028 | + |
|
1029 | + |
|
1030 | + /** |
|
1031 | + * resets all non-default session vars. Returns TRUE on success, FALSE on fail |
|
1032 | + * |
|
1033 | + * @param array|mixed $data_to_reset |
|
1034 | + * @param bool $show_all_notices |
|
1035 | + * @return bool |
|
1036 | + */ |
|
1037 | + public function reset_data($data_to_reset = array(), $show_all_notices = false) |
|
1038 | + { |
|
1039 | + // if $data_to_reset is not in an array, then put it in one |
|
1040 | + if (! is_array($data_to_reset)) { |
|
1041 | + $data_to_reset = array($data_to_reset); |
|
1042 | + } |
|
1043 | + // nothing ??? go home! |
|
1044 | + if (empty($data_to_reset)) { |
|
1045 | + EE_Error::add_error(__('No session data could be reset, because no session var name was provided.', |
|
1046 | + 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
1047 | + return false; |
|
1048 | + } |
|
1049 | + $return_value = true; |
|
1050 | + // since $data_to_reset is an array, cycle through the values |
|
1051 | + foreach ($data_to_reset as $reset) { |
|
1052 | + |
|
1053 | + // first check to make sure it is a valid session var |
|
1054 | + if (isset($this->_session_data[ $reset ])) { |
|
1055 | + // then check to make sure it is not a default var |
|
1056 | + if (! array_key_exists($reset, $this->_default_session_vars)) { |
|
1057 | + // remove session var |
|
1058 | + unset($this->_session_data[ $reset ]); |
|
1059 | + if ($show_all_notices) { |
|
1060 | + EE_Error::add_success(sprintf(__('The session variable %s was removed.', 'event_espresso'), |
|
1061 | + $reset), __FILE__, __FUNCTION__, __LINE__); |
|
1062 | + } |
|
1063 | + } else { |
|
1064 | + // yeeeeeeeeerrrrrrrrrrr OUT !!!! |
|
1065 | + if ($show_all_notices) { |
|
1066 | + EE_Error::add_error(sprintf(__('Sorry! %s is a default session datum and can not be reset.', |
|
1067 | + 'event_espresso'), $reset), __FILE__, __FUNCTION__, __LINE__); |
|
1068 | + } |
|
1069 | + $return_value = false; |
|
1070 | + } |
|
1071 | + } elseif ($show_all_notices) { |
|
1072 | + // oops! that session var does not exist! |
|
1073 | + EE_Error::add_error(sprintf(__('The session item provided, %s, is invalid or does not exist.', |
|
1074 | + 'event_espresso'), $reset), __FILE__, __FUNCTION__, __LINE__); |
|
1075 | + $return_value = false; |
|
1076 | + } |
|
1077 | + } // end of foreach |
|
1078 | + return $return_value; |
|
1079 | + } |
|
1080 | + |
|
1081 | + |
|
1082 | + |
|
1083 | + /** |
|
1084 | + * wp_loaded |
|
1085 | + * |
|
1086 | + * @access public |
|
1087 | + * @throws EE_Error |
|
1088 | + * @throws InvalidDataTypeException |
|
1089 | + * @throws InvalidInterfaceException |
|
1090 | + * @throws InvalidArgumentException |
|
1091 | + */ |
|
1092 | + public function wp_loaded() |
|
1093 | + { |
|
1094 | + if ($this->request->requestParamIsSet('clear_session')) { |
|
1095 | + $this->clear_session(__CLASS__, __FUNCTION__); |
|
1096 | + } |
|
1097 | + } |
|
1098 | + |
|
1099 | + |
|
1100 | + |
|
1101 | + /** |
|
1102 | + * Used to reset the entire object (for tests). |
|
1103 | + * |
|
1104 | + * @since 4.3.0 |
|
1105 | + * @throws EE_Error |
|
1106 | + * @throws InvalidDataTypeException |
|
1107 | + * @throws InvalidInterfaceException |
|
1108 | + * @throws InvalidArgumentException |
|
1109 | + */ |
|
1110 | + public function reset_instance() |
|
1111 | + { |
|
1112 | + $this->clear_session(); |
|
1113 | + self::$_instance = null; |
|
1114 | + } |
|
1115 | + |
|
1116 | + |
|
1117 | + |
|
1118 | + public function configure_garbage_collection_filters() |
|
1119 | + { |
|
1120 | + // run old filter we had for controlling session cleanup |
|
1121 | + $expired_session_transient_delete_query_limit = absint( |
|
1122 | + apply_filters( |
|
1123 | + 'FHEE__EE_Session__garbage_collection___expired_session_transient_delete_query_limit', |
|
1124 | + 50 |
|
1125 | + ) |
|
1126 | + ); |
|
1127 | + // is there a value? or one that is different than the default 50 records? |
|
1128 | + if ($expired_session_transient_delete_query_limit === 0) { |
|
1129 | + // hook into TransientCacheStorage in case Session cleanup was turned off |
|
1130 | + add_filter('FHEE__TransientCacheStorage__transient_cleanup_schedule', '__return_zero'); |
|
1131 | + } elseif ($expired_session_transient_delete_query_limit !== 50) { |
|
1132 | + // or use that for the new transient cleanup query limit |
|
1133 | + add_filter( |
|
1134 | + 'FHEE__TransientCacheStorage__clearExpiredTransients__limit', |
|
1135 | + function () use ($expired_session_transient_delete_query_limit) |
|
1136 | + { |
|
1137 | + return $expired_session_transient_delete_query_limit; |
|
1138 | + } |
|
1139 | + ); |
|
1140 | + } |
|
1141 | + } |
|
1142 | + |
|
1143 | + |
|
1144 | + |
|
1145 | + /** |
|
1146 | + * @see http://stackoverflow.com/questions/10152904/unserialize-function-unserialize-error-at-offset/21389439#10152996 |
|
1147 | + * @param $data1 |
|
1148 | + * @return string |
|
1149 | + */ |
|
1150 | + private function find_serialize_error($data1) |
|
1151 | + { |
|
1152 | + $error = '<pre>'; |
|
1153 | + $data2 = preg_replace_callback( |
|
1154 | + '!s:(\d+):"(.*?)";!', |
|
1155 | + function ($match) |
|
1156 | + { |
|
1157 | + return ($match[1] === strlen($match[2])) |
|
1158 | + ? $match[0] |
|
1159 | + : 's:' |
|
1160 | + . strlen($match[2]) |
|
1161 | + . ':"' |
|
1162 | + . $match[2] |
|
1163 | + . '";'; |
|
1164 | + }, |
|
1165 | + $data1 |
|
1166 | + ); |
|
1167 | + $max = (strlen($data1) > strlen($data2)) ? strlen($data1) : strlen($data2); |
|
1168 | + $error .= $data1 . PHP_EOL; |
|
1169 | + $error .= $data2 . PHP_EOL; |
|
1170 | + for ($i = 0; $i < $max; $i++) { |
|
1171 | + if (@$data1[ $i ] !== @$data2[ $i ]) { |
|
1172 | + $error .= 'Difference ' . @$data1[ $i ] . ' != ' . @$data2[ $i ] . PHP_EOL; |
|
1173 | + $error .= "\t-> ORD number " . ord(@$data1[ $i ]) . ' != ' . ord(@$data2[ $i ]) . PHP_EOL; |
|
1174 | + $error .= "\t-> Line Number = $i" . PHP_EOL; |
|
1175 | + $start = ($i - 20); |
|
1176 | + $start = ($start < 0) ? 0 : $start; |
|
1177 | + $length = 40; |
|
1178 | + $point = $max - $i; |
|
1179 | + if ($point < 20) { |
|
1180 | + $rlength = 1; |
|
1181 | + $rpoint = -$point; |
|
1182 | + } else { |
|
1183 | + $rpoint = $length - 20; |
|
1184 | + $rlength = 1; |
|
1185 | + } |
|
1186 | + $error .= "\t-> Section Data1 = "; |
|
1187 | + $error .= substr_replace( |
|
1188 | + substr($data1, $start, $length), |
|
1189 | + "<b style=\"color:green\">{$data1[ $i ]}</b>", |
|
1190 | + $rpoint, |
|
1191 | + $rlength |
|
1192 | + ); |
|
1193 | + $error .= PHP_EOL; |
|
1194 | + $error .= "\t-> Section Data2 = "; |
|
1195 | + $error .= substr_replace( |
|
1196 | + substr($data2, $start, $length), |
|
1197 | + "<b style=\"color:red\">{$data2[ $i ]}</b>", |
|
1198 | + $rpoint, |
|
1199 | + $rlength |
|
1200 | + ); |
|
1201 | + $error .= PHP_EOL; |
|
1202 | + } |
|
1203 | + } |
|
1204 | + $error .= '</pre>'; |
|
1205 | + return $error; |
|
1206 | + } |
|
1207 | + |
|
1208 | + |
|
1209 | + /** |
|
1210 | + * Saves an array of settings used for configuring aspects of session behaviour |
|
1211 | + * |
|
1212 | + * @param array $updated_settings |
|
1213 | + */ |
|
1214 | + private function updateSessionSettings(array $updated_settings = array()) |
|
1215 | + { |
|
1216 | + // add existing settings, but only if not included in incoming $updated_settings array |
|
1217 | + $updated_settings += get_option(EE_Session::OPTION_NAME_SETTINGS, array()); |
|
1218 | + update_option(EE_Session::OPTION_NAME_SETTINGS, $updated_settings); |
|
1219 | + } |
|
1220 | + |
|
1221 | + |
|
1222 | + /** |
|
1223 | + * garbage_collection |
|
1224 | + */ |
|
1225 | + public function garbageCollection() |
|
1226 | + { |
|
1227 | + // only perform during regular requests if last garbage collection was over an hour ago |
|
1228 | + if (! (defined('DOING_AJAX') && DOING_AJAX) && (time() - HOUR_IN_SECONDS) >= $this->_last_gc) { |
|
1229 | + $this->_last_gc = time(); |
|
1230 | + $this->updateSessionSettings(array('last_gc' => $this->_last_gc)); |
|
1231 | + /** @type WPDB $wpdb */ |
|
1232 | + global $wpdb; |
|
1233 | + // filter the query limit. Set to 0 to turn off garbage collection |
|
1234 | + $expired_session_transient_delete_query_limit = absint( |
|
1235 | + apply_filters( |
|
1236 | + 'FHEE__EE_Session__garbage_collection___expired_session_transient_delete_query_limit', |
|
1237 | + 50 |
|
1238 | + ) |
|
1239 | + ); |
|
1240 | + // non-zero LIMIT means take out the trash |
|
1241 | + if ($expired_session_transient_delete_query_limit) { |
|
1242 | + $session_key = str_replace('_', '\_', EE_Session::session_id_prefix); |
|
1243 | + $hash_check_key = str_replace('_', '\_', EE_Session::hash_check_prefix); |
|
1244 | + // since transient expiration timestamps are set in the future, we can compare against NOW |
|
1245 | + // but we only want to pick up any trash that's been around for more than a day |
|
1246 | + $expiration = time() - DAY_IN_SECONDS; |
|
1247 | + $SQL = " |
|
1248 | 1248 | SELECT option_name |
1249 | 1249 | FROM {$wpdb->options} |
1250 | 1250 | WHERE |
@@ -1253,19 +1253,19 @@ discard block |
||
1253 | 1253 | AND option_value < {$expiration} |
1254 | 1254 | LIMIT {$expired_session_transient_delete_query_limit} |
1255 | 1255 | "; |
1256 | - // produces something like: |
|
1257 | - // SELECT option_name FROM wp_options |
|
1258 | - // WHERE ( option_name LIKE '\_transient\_timeout\_ee\_ssn\_%' |
|
1259 | - // OR option_name LIKE '\_transient\_timeout\_ee\_shc\_%' ) |
|
1260 | - // AND option_value < 1508368198 LIMIT 50 |
|
1261 | - $expired_sessions = $wpdb->get_col($SQL); |
|
1262 | - // valid results? |
|
1263 | - if (! $expired_sessions instanceof WP_Error && ! empty($expired_sessions)) { |
|
1264 | - $this->cache_storage->deleteMany($expired_sessions, true); |
|
1265 | - } |
|
1266 | - } |
|
1267 | - } |
|
1268 | - } |
|
1256 | + // produces something like: |
|
1257 | + // SELECT option_name FROM wp_options |
|
1258 | + // WHERE ( option_name LIKE '\_transient\_timeout\_ee\_ssn\_%' |
|
1259 | + // OR option_name LIKE '\_transient\_timeout\_ee\_shc\_%' ) |
|
1260 | + // AND option_value < 1508368198 LIMIT 50 |
|
1261 | + $expired_sessions = $wpdb->get_col($SQL); |
|
1262 | + // valid results? |
|
1263 | + if (! $expired_sessions instanceof WP_Error && ! empty($expired_sessions)) { |
|
1264 | + $this->cache_storage->deleteMany($expired_sessions, true); |
|
1265 | + } |
|
1266 | + } |
|
1267 | + } |
|
1268 | + } |
|
1269 | 1269 | |
1270 | 1270 | |
1271 | 1271 |
@@ -186,7 +186,7 @@ discard block |
||
186 | 186 | // check if class object is instantiated |
187 | 187 | // session loading is turned ON by default, but prior to the init hook, can be turned back OFF via: |
188 | 188 | // add_filter( 'FHEE_load_EE_Session', '__return_false' ); |
189 | - if (! self::$_instance instanceof EE_Session && apply_filters('FHEE_load_EE_Session', true)) { |
|
189 | + if ( ! self::$_instance instanceof EE_Session && apply_filters('FHEE_load_EE_Session', true)) { |
|
190 | 190 | self::$_instance = new self( |
191 | 191 | $cache_storage, |
192 | 192 | $lifespan, |
@@ -219,21 +219,21 @@ discard block |
||
219 | 219 | // but prior to the 'AHEE__EE_System__core_loaded_and_ready' hook |
220 | 220 | // (which currently fires on the init hook at priority 9), |
221 | 221 | // can be turned back OFF via: add_filter( 'FHEE_load_EE_Session', '__return_false' ); |
222 | - if (! apply_filters('FHEE_load_EE_Session', true)) { |
|
222 | + if ( ! apply_filters('FHEE_load_EE_Session', true)) { |
|
223 | 223 | return; |
224 | 224 | } |
225 | 225 | $this->session_lifespan = $lifespan; |
226 | 226 | $this->request = $request; |
227 | - if (! defined('ESPRESSO_SESSION')) { |
|
227 | + if ( ! defined('ESPRESSO_SESSION')) { |
|
228 | 228 | define('ESPRESSO_SESSION', true); |
229 | 229 | } |
230 | 230 | // retrieve session options from db |
231 | 231 | $session_settings = (array) get_option(EE_Session::OPTION_NAME_SETTINGS, array()); |
232 | - if (! empty($session_settings)) { |
|
232 | + if ( ! empty($session_settings)) { |
|
233 | 233 | // cycle though existing session options |
234 | 234 | foreach ($session_settings as $var_name => $session_setting) { |
235 | 235 | // set values for class properties |
236 | - $var_name = '_' . $var_name; |
|
236 | + $var_name = '_'.$var_name; |
|
237 | 237 | $this->{$var_name} = $session_setting; |
238 | 238 | } |
239 | 239 | } |
@@ -293,7 +293,7 @@ discard block |
||
293 | 293 | public function open_session() |
294 | 294 | { |
295 | 295 | // check for existing session and retrieve it from db |
296 | - if (! $this->_espresso_session()) { |
|
296 | + if ( ! $this->_espresso_session()) { |
|
297 | 297 | // or just start a new one |
298 | 298 | $this->_create_espresso_session(); |
299 | 299 | } |
@@ -345,7 +345,7 @@ discard block |
||
345 | 345 | */ |
346 | 346 | public function extend_expiration($time = 0) |
347 | 347 | { |
348 | - $time = $time ? $time : $this->extension(); |
|
348 | + $time = $time ? $time : $this->extension(); |
|
349 | 349 | $this->_expiration += absint($time); |
350 | 350 | } |
351 | 351 | |
@@ -372,9 +372,9 @@ discard block |
||
372 | 372 | // set some defaults |
373 | 373 | foreach ($this->_default_session_vars as $key => $default_var) { |
374 | 374 | if (is_array($default_var)) { |
375 | - $this->_session_data[ $key ] = array(); |
|
375 | + $this->_session_data[$key] = array(); |
|
376 | 376 | } else { |
377 | - $this->_session_data[ $key ] = ''; |
|
377 | + $this->_session_data[$key] = ''; |
|
378 | 378 | } |
379 | 379 | } |
380 | 380 | } |
@@ -515,8 +515,8 @@ discard block |
||
515 | 515 | $this->reset_checkout(); |
516 | 516 | $this->reset_transaction(); |
517 | 517 | } |
518 | - if (! empty($key)) { |
|
519 | - return isset($this->_session_data[ $key ]) ? $this->_session_data[ $key ] : null; |
|
518 | + if ( ! empty($key)) { |
|
519 | + return isset($this->_session_data[$key]) ? $this->_session_data[$key] : null; |
|
520 | 520 | } |
521 | 521 | return $this->_session_data; |
522 | 522 | } |
@@ -542,7 +542,7 @@ discard block |
||
542 | 542 | return false; |
543 | 543 | } |
544 | 544 | foreach ($data as $key => $value) { |
545 | - if (isset($this->_default_session_vars[ $key ])) { |
|
545 | + if (isset($this->_default_session_vars[$key])) { |
|
546 | 546 | EE_Error::add_error( |
547 | 547 | sprintf( |
548 | 548 | esc_html__( |
@@ -555,7 +555,7 @@ discard block |
||
555 | 555 | ); |
556 | 556 | return false; |
557 | 557 | } |
558 | - $this->_session_data[ $key ] = $value; |
|
558 | + $this->_session_data[$key] = $value; |
|
559 | 559 | } |
560 | 560 | return true; |
561 | 561 | } |
@@ -589,7 +589,7 @@ discard block |
||
589 | 589 | $this->_user_agent = $this->request->userAgent(); |
590 | 590 | // now let's retrieve what's in the db |
591 | 591 | $session_data = $this->_retrieve_session_data(); |
592 | - if (! empty($session_data)) { |
|
592 | + if ( ! empty($session_data)) { |
|
593 | 593 | // get the current time in UTC |
594 | 594 | $this->_time = $this->_time !== null ? $this->_time : time(); |
595 | 595 | // and reset the session expiration |
@@ -600,7 +600,7 @@ discard block |
||
600 | 600 | // set initial site access time and the session expiration |
601 | 601 | $this->_set_init_access_and_expiration(); |
602 | 602 | // set referer |
603 | - $this->_session_data['pages_visited'][ $this->_session_data['init_access'] ] = isset($_SERVER['HTTP_REFERER']) |
|
603 | + $this->_session_data['pages_visited'][$this->_session_data['init_access']] = isset($_SERVER['HTTP_REFERER']) |
|
604 | 604 | ? esc_attr($_SERVER['HTTP_REFERER']) |
605 | 605 | : ''; |
606 | 606 | // no previous session = go back and create one (on top of the data above) |
@@ -638,7 +638,7 @@ discard block |
||
638 | 638 | */ |
639 | 639 | protected function _retrieve_session_data() |
640 | 640 | { |
641 | - $ssn_key = EE_Session::session_id_prefix . $this->_sid; |
|
641 | + $ssn_key = EE_Session::session_id_prefix.$this->_sid; |
|
642 | 642 | try { |
643 | 643 | // we're using WP's Transient API to store session data using the PHP session ID as the option name |
644 | 644 | $session_data = $this->cache_storage->get($ssn_key, false); |
@@ -647,7 +647,7 @@ discard block |
||
647 | 647 | } |
648 | 648 | if (apply_filters('FHEE__EE_Session___perform_session_id_hash_check', WP_DEBUG)) { |
649 | 649 | $hash_check = $this->cache_storage->get( |
650 | - EE_Session::hash_check_prefix . $this->_sid, |
|
650 | + EE_Session::hash_check_prefix.$this->_sid, |
|
651 | 651 | false |
652 | 652 | ); |
653 | 653 | if ($hash_check && $hash_check !== md5($session_data)) { |
@@ -657,7 +657,7 @@ discard block |
||
657 | 657 | 'The stored data for session %1$s failed to pass a hash check and therefore appears to be invalid.', |
658 | 658 | 'event_espresso' |
659 | 659 | ), |
660 | - EE_Session::session_id_prefix . $this->_sid |
|
660 | + EE_Session::session_id_prefix.$this->_sid |
|
661 | 661 | ), |
662 | 662 | __FILE__, __FUNCTION__, __LINE__ |
663 | 663 | ); |
@@ -666,21 +666,21 @@ discard block |
||
666 | 666 | } catch (Exception $e) { |
667 | 667 | // let's just eat that error for now and attempt to correct any corrupted data |
668 | 668 | global $wpdb; |
669 | - $row = $wpdb->get_row( |
|
669 | + $row = $wpdb->get_row( |
|
670 | 670 | $wpdb->prepare( |
671 | 671 | "SELECT option_value FROM {$wpdb->options} WHERE option_name = %s LIMIT 1", |
672 | - '_transient_' . $ssn_key |
|
672 | + '_transient_'.$ssn_key |
|
673 | 673 | ) |
674 | 674 | ); |
675 | 675 | $session_data = is_object($row) ? $row->option_value : null; |
676 | 676 | if ($session_data) { |
677 | 677 | $session_data = preg_replace_callback( |
678 | 678 | '!s:(d+):"(.*?)";!', |
679 | - function ($match) |
|
679 | + function($match) |
|
680 | 680 | { |
681 | 681 | return $match[1] === strlen($match[2]) |
682 | 682 | ? $match[0] |
683 | - : 's:' . strlen($match[2]) . ':"' . $match[2] . '";'; |
|
683 | + : 's:'.strlen($match[2]).':"'.$match[2].'";'; |
|
684 | 684 | }, |
685 | 685 | $session_data |
686 | 686 | ); |
@@ -691,7 +691,7 @@ discard block |
||
691 | 691 | $session_data = $this->encryption instanceof EE_Encryption |
692 | 692 | ? $this->encryption->base64_string_decode($session_data) |
693 | 693 | : $session_data; |
694 | - if (! is_array($session_data)) { |
|
694 | + if ( ! is_array($session_data)) { |
|
695 | 695 | try { |
696 | 696 | $session_data = maybe_unserialize($session_data); |
697 | 697 | } catch (Exception $e) { |
@@ -705,21 +705,21 @@ discard block |
||
705 | 705 | . '</pre><br>' |
706 | 706 | . $this->find_serialize_error($session_data) |
707 | 707 | : ''; |
708 | - $this->cache_storage->delete(EE_Session::session_id_prefix . $this->_sid); |
|
708 | + $this->cache_storage->delete(EE_Session::session_id_prefix.$this->_sid); |
|
709 | 709 | throw new InvalidSessionDataException($msg, 0, $e); |
710 | 710 | } |
711 | 711 | } |
712 | 712 | // just a check to make sure the session array is indeed an array |
713 | - if (! is_array($session_data)) { |
|
713 | + if ( ! is_array($session_data)) { |
|
714 | 714 | // no?!?! then something is wrong |
715 | 715 | $msg = esc_html__( |
716 | 716 | 'The session data is missing, invalid, or corrupted.', |
717 | 717 | 'event_espresso' |
718 | 718 | ); |
719 | 719 | $msg .= WP_DEBUG |
720 | - ? '<br><pre>' . print_r($session_data, true) . '</pre><br>' . $this->find_serialize_error($session_data) |
|
720 | + ? '<br><pre>'.print_r($session_data, true).'</pre><br>'.$this->find_serialize_error($session_data) |
|
721 | 721 | : ''; |
722 | - $this->cache_storage->delete(EE_Session::session_id_prefix . $this->_sid); |
|
722 | + $this->cache_storage->delete(EE_Session::session_id_prefix.$this->_sid); |
|
723 | 723 | throw new InvalidSessionDataException($msg); |
724 | 724 | } |
725 | 725 | if (isset($session_data['transaction']) && absint($session_data['transaction']) !== 0) { |
@@ -747,7 +747,7 @@ discard block |
||
747 | 747 | if (isset($_REQUEST['EESID'])) { |
748 | 748 | $session_id = sanitize_text_field($_REQUEST['EESID']); |
749 | 749 | } else { |
750 | - $session_id = md5(session_id() . get_current_blog_id() . $this->_get_sid_salt()); |
|
750 | + $session_id = md5(session_id().get_current_blog_id().$this->_get_sid_salt()); |
|
751 | 751 | } |
752 | 752 | return apply_filters('FHEE__EE_Session___generate_session_id__session_id', $session_id); |
753 | 753 | } |
@@ -855,19 +855,19 @@ discard block |
||
855 | 855 | $page_visit = $this->_get_page_visit(); |
856 | 856 | if ($page_visit) { |
857 | 857 | // set pages visited where the first will be the http referrer |
858 | - $this->_session_data['pages_visited'][ $this->_time ] = $page_visit; |
|
858 | + $this->_session_data['pages_visited'][$this->_time] = $page_visit; |
|
859 | 859 | // we'll only save the last 10 page visits. |
860 | 860 | $session_data['pages_visited'] = array_slice($this->_session_data['pages_visited'], -10); |
861 | 861 | } |
862 | 862 | break; |
863 | 863 | default : |
864 | 864 | // carry any other data over |
865 | - $session_data[ $key ] = $this->_session_data[ $key ]; |
|
865 | + $session_data[$key] = $this->_session_data[$key]; |
|
866 | 866 | } |
867 | 867 | } |
868 | 868 | $this->_session_data = $session_data; |
869 | 869 | // creating a new session does not require saving to the db just yet |
870 | - if (! $new_session) { |
|
870 | + if ( ! $new_session) { |
|
871 | 871 | // ready? let's save |
872 | 872 | if ($this->_save_session_to_db()) { |
873 | 873 | return true; |
@@ -912,12 +912,12 @@ discard block |
||
912 | 912 | { |
913 | 913 | // don't save sessions for crawlers |
914 | 914 | // and unless we're deleting the session data, don't save anything if there isn't a cart |
915 | - if ($this->request->isBot() || (! $clear_session && ! $this->cart() instanceof EE_Cart)) { |
|
915 | + if ($this->request->isBot() || ( ! $clear_session && ! $this->cart() instanceof EE_Cart)) { |
|
916 | 916 | return false; |
917 | 917 | } |
918 | 918 | $transaction = $this->transaction(); |
919 | 919 | if ($transaction instanceof EE_Transaction) { |
920 | - if (! $transaction->ID()) { |
|
920 | + if ( ! $transaction->ID()) { |
|
921 | 921 | $transaction->save(); |
922 | 922 | } |
923 | 923 | $this->_session_data['transaction'] = $transaction->ID(); |
@@ -931,14 +931,14 @@ discard block |
||
931 | 931 | // maybe save hash check |
932 | 932 | if (apply_filters('FHEE__EE_Session___perform_session_id_hash_check', WP_DEBUG)) { |
933 | 933 | $this->cache_storage->add( |
934 | - EE_Session::hash_check_prefix . $this->_sid, |
|
934 | + EE_Session::hash_check_prefix.$this->_sid, |
|
935 | 935 | md5($session_data), |
936 | 936 | $this->session_lifespan->inSeconds() |
937 | 937 | ); |
938 | 938 | } |
939 | 939 | // we're using the Transient API for storing session data, |
940 | 940 | return $this->cache_storage->add( |
941 | - EE_Session::session_id_prefix . $this->_sid, |
|
941 | + EE_Session::session_id_prefix.$this->_sid, |
|
942 | 942 | $session_data, |
943 | 943 | $this->session_lifespan->inSeconds() |
944 | 944 | ); |
@@ -952,7 +952,7 @@ discard block |
||
952 | 952 | */ |
953 | 953 | public function _get_page_visit() |
954 | 954 | { |
955 | - $page_visit = home_url('/') . 'wp-admin/admin-ajax.php'; |
|
955 | + $page_visit = home_url('/').'wp-admin/admin-ajax.php'; |
|
956 | 956 | // check for request url |
957 | 957 | if (isset($_SERVER['REQUEST_URI'])) { |
958 | 958 | $http_host = ''; |
@@ -968,14 +968,14 @@ discard block |
||
968 | 968 | // check for page_id in SERVER REQUEST |
969 | 969 | if (isset($_REQUEST['page_id'])) { |
970 | 970 | // rebuild $e_reg without any of the extra parameters |
971 | - $page_id = '?page_id=' . esc_attr($_REQUEST['page_id']) . '&'; |
|
971 | + $page_id = '?page_id='.esc_attr($_REQUEST['page_id']).'&'; |
|
972 | 972 | } |
973 | 973 | // check for $e_reg in SERVER REQUEST |
974 | 974 | if (isset($_REQUEST['ee'])) { |
975 | 975 | // rebuild $e_reg without any of the extra parameters |
976 | - $e_reg = 'ee=' . esc_attr($_REQUEST['ee']); |
|
976 | + $e_reg = 'ee='.esc_attr($_REQUEST['ee']); |
|
977 | 977 | } |
978 | - $page_visit = rtrim($http_host . $request_uri . $page_id . $e_reg, '?'); |
|
978 | + $page_visit = rtrim($http_host.$request_uri.$page_id.$e_reg, '?'); |
|
979 | 979 | } |
980 | 980 | return $page_visit !== home_url('/wp-admin/admin-ajax.php') ? $page_visit : ''; |
981 | 981 | } |
@@ -1015,7 +1015,7 @@ discard block |
||
1015 | 1015 | // <span style="color:#2EA2CC">' . __CLASS__ . '</span>::<span style="color:#E76700">' . __FUNCTION__ . '( ' . $class . '::' . $function . '() )</span><br/> |
1016 | 1016 | // <span style="font-size:9px;font-weight:normal;">' . __FILE__ . '</span> <b style="font-size:10px;"> ' . __LINE__ . ' </b> |
1017 | 1017 | // </h3>'; |
1018 | - do_action('AHEE_log', __FILE__, __FUNCTION__, 'session cleared by : ' . $class . '::' . $function . '()'); |
|
1018 | + do_action('AHEE_log', __FILE__, __FUNCTION__, 'session cleared by : '.$class.'::'.$function.'()'); |
|
1019 | 1019 | $this->reset_cart(); |
1020 | 1020 | $this->reset_checkout(); |
1021 | 1021 | $this->reset_transaction(); |
@@ -1037,7 +1037,7 @@ discard block |
||
1037 | 1037 | public function reset_data($data_to_reset = array(), $show_all_notices = false) |
1038 | 1038 | { |
1039 | 1039 | // if $data_to_reset is not in an array, then put it in one |
1040 | - if (! is_array($data_to_reset)) { |
|
1040 | + if ( ! is_array($data_to_reset)) { |
|
1041 | 1041 | $data_to_reset = array($data_to_reset); |
1042 | 1042 | } |
1043 | 1043 | // nothing ??? go home! |
@@ -1051,11 +1051,11 @@ discard block |
||
1051 | 1051 | foreach ($data_to_reset as $reset) { |
1052 | 1052 | |
1053 | 1053 | // first check to make sure it is a valid session var |
1054 | - if (isset($this->_session_data[ $reset ])) { |
|
1054 | + if (isset($this->_session_data[$reset])) { |
|
1055 | 1055 | // then check to make sure it is not a default var |
1056 | - if (! array_key_exists($reset, $this->_default_session_vars)) { |
|
1056 | + if ( ! array_key_exists($reset, $this->_default_session_vars)) { |
|
1057 | 1057 | // remove session var |
1058 | - unset($this->_session_data[ $reset ]); |
|
1058 | + unset($this->_session_data[$reset]); |
|
1059 | 1059 | if ($show_all_notices) { |
1060 | 1060 | EE_Error::add_success(sprintf(__('The session variable %s was removed.', 'event_espresso'), |
1061 | 1061 | $reset), __FILE__, __FUNCTION__, __LINE__); |
@@ -1132,7 +1132,7 @@ discard block |
||
1132 | 1132 | // or use that for the new transient cleanup query limit |
1133 | 1133 | add_filter( |
1134 | 1134 | 'FHEE__TransientCacheStorage__clearExpiredTransients__limit', |
1135 | - function () use ($expired_session_transient_delete_query_limit) |
|
1135 | + function() use ($expired_session_transient_delete_query_limit) |
|
1136 | 1136 | { |
1137 | 1137 | return $expired_session_transient_delete_query_limit; |
1138 | 1138 | } |
@@ -1152,7 +1152,7 @@ discard block |
||
1152 | 1152 | $error = '<pre>'; |
1153 | 1153 | $data2 = preg_replace_callback( |
1154 | 1154 | '!s:(\d+):"(.*?)";!', |
1155 | - function ($match) |
|
1155 | + function($match) |
|
1156 | 1156 | { |
1157 | 1157 | return ($match[1] === strlen($match[2])) |
1158 | 1158 | ? $match[0] |
@@ -1164,14 +1164,14 @@ discard block |
||
1164 | 1164 | }, |
1165 | 1165 | $data1 |
1166 | 1166 | ); |
1167 | - $max = (strlen($data1) > strlen($data2)) ? strlen($data1) : strlen($data2); |
|
1168 | - $error .= $data1 . PHP_EOL; |
|
1169 | - $error .= $data2 . PHP_EOL; |
|
1167 | + $max = (strlen($data1) > strlen($data2)) ? strlen($data1) : strlen($data2); |
|
1168 | + $error .= $data1.PHP_EOL; |
|
1169 | + $error .= $data2.PHP_EOL; |
|
1170 | 1170 | for ($i = 0; $i < $max; $i++) { |
1171 | - if (@$data1[ $i ] !== @$data2[ $i ]) { |
|
1172 | - $error .= 'Difference ' . @$data1[ $i ] . ' != ' . @$data2[ $i ] . PHP_EOL; |
|
1173 | - $error .= "\t-> ORD number " . ord(@$data1[ $i ]) . ' != ' . ord(@$data2[ $i ]) . PHP_EOL; |
|
1174 | - $error .= "\t-> Line Number = $i" . PHP_EOL; |
|
1171 | + if (@$data1[$i] !== @$data2[$i]) { |
|
1172 | + $error .= 'Difference '.@$data1[$i].' != '.@$data2[$i].PHP_EOL; |
|
1173 | + $error .= "\t-> ORD number ".ord(@$data1[$i]).' != '.ord(@$data2[$i]).PHP_EOL; |
|
1174 | + $error .= "\t-> Line Number = $i".PHP_EOL; |
|
1175 | 1175 | $start = ($i - 20); |
1176 | 1176 | $start = ($start < 0) ? 0 : $start; |
1177 | 1177 | $length = 40; |
@@ -1186,7 +1186,7 @@ discard block |
||
1186 | 1186 | $error .= "\t-> Section Data1 = "; |
1187 | 1187 | $error .= substr_replace( |
1188 | 1188 | substr($data1, $start, $length), |
1189 | - "<b style=\"color:green\">{$data1[ $i ]}</b>", |
|
1189 | + "<b style=\"color:green\">{$data1[$i]}</b>", |
|
1190 | 1190 | $rpoint, |
1191 | 1191 | $rlength |
1192 | 1192 | ); |
@@ -1194,7 +1194,7 @@ discard block |
||
1194 | 1194 | $error .= "\t-> Section Data2 = "; |
1195 | 1195 | $error .= substr_replace( |
1196 | 1196 | substr($data2, $start, $length), |
1197 | - "<b style=\"color:red\">{$data2[ $i ]}</b>", |
|
1197 | + "<b style=\"color:red\">{$data2[$i]}</b>", |
|
1198 | 1198 | $rpoint, |
1199 | 1199 | $rlength |
1200 | 1200 | ); |
@@ -1225,7 +1225,7 @@ discard block |
||
1225 | 1225 | public function garbageCollection() |
1226 | 1226 | { |
1227 | 1227 | // only perform during regular requests if last garbage collection was over an hour ago |
1228 | - if (! (defined('DOING_AJAX') && DOING_AJAX) && (time() - HOUR_IN_SECONDS) >= $this->_last_gc) { |
|
1228 | + if ( ! (defined('DOING_AJAX') && DOING_AJAX) && (time() - HOUR_IN_SECONDS) >= $this->_last_gc) { |
|
1229 | 1229 | $this->_last_gc = time(); |
1230 | 1230 | $this->updateSessionSettings(array('last_gc' => $this->_last_gc)); |
1231 | 1231 | /** @type WPDB $wpdb */ |
@@ -1260,7 +1260,7 @@ discard block |
||
1260 | 1260 | // AND option_value < 1508368198 LIMIT 50 |
1261 | 1261 | $expired_sessions = $wpdb->get_col($SQL); |
1262 | 1262 | // valid results? |
1263 | - if (! $expired_sessions instanceof WP_Error && ! empty($expired_sessions)) { |
|
1263 | + if ( ! $expired_sessions instanceof WP_Error && ! empty($expired_sessions)) { |
|
1264 | 1264 | $this->cache_storage->deleteMany($expired_sessions, true); |
1265 | 1265 | } |
1266 | 1266 | } |
@@ -104,7 +104,7 @@ discard block |
||
104 | 104 | $this->registerManifestFile( |
105 | 105 | self::ASSET_NAMESPACE, |
106 | 106 | $this->domain->distributionAssetsUrl(), |
107 | - $this->domain->distributionAssetsPath() . 'build-manifest.json' |
|
107 | + $this->domain->distributionAssetsPath().'build-manifest.json' |
|
108 | 108 | ); |
109 | 109 | add_action('wp_enqueue_scripts', array($this, 'scripts'), 1); |
110 | 110 | add_action('admin_enqueue_scripts', array($this, 'scripts'), 1); |
@@ -149,7 +149,7 @@ discard block |
||
149 | 149 | //js.api |
150 | 150 | wp_register_script( |
151 | 151 | 'eejs-api', |
152 | - EE_LIBRARIES_URL . 'rest_api/assets/js/eejs-api.min.js', |
|
152 | + EE_LIBRARIES_URL.'rest_api/assets/js/eejs-api.min.js', |
|
153 | 153 | array('underscore', 'eejs-core'), |
154 | 154 | EVENT_ESPRESSO_VERSION, |
155 | 155 | true |
@@ -157,7 +157,7 @@ discard block |
||
157 | 157 | $this->jsdata['eejs_api_nonce'] = wp_create_nonce('wp_rest'); |
158 | 158 | $this->jsdata['paths'] = array('rest_route' => rest_url('ee/v4.8.36/')); |
159 | 159 | } |
160 | - if (! is_admin()) { |
|
160 | + if ( ! is_admin()) { |
|
161 | 161 | $this->loadCoreCss(); |
162 | 162 | } |
163 | 163 | $this->loadCoreJs(); |
@@ -254,7 +254,7 @@ discard block |
||
254 | 254 | */ |
255 | 255 | public function addTemplate($template_reference, $template_content) |
256 | 256 | { |
257 | - if (! isset($this->jsdata['templates'])) { |
|
257 | + if ( ! isset($this->jsdata['templates'])) { |
|
258 | 258 | $this->jsdata['templates'] = array(); |
259 | 259 | } |
260 | 260 | //no overrides allowed. |
@@ -368,7 +368,7 @@ discard block |
||
368 | 368 | ); |
369 | 369 | } |
370 | 370 | $this->manifest_data[$namespace] = $this->decodeManifestFile($manifest_file); |
371 | - if (! isset($this->manifest_data[$namespace]['url_base'])) { |
|
371 | + if ( ! isset($this->manifest_data[$namespace]['url_base'])) { |
|
372 | 372 | $this->manifest_data[$namespace]['url_base'] = trailingslashit($url_base); |
373 | 373 | } |
374 | 374 | } |
@@ -385,7 +385,7 @@ discard block |
||
385 | 385 | */ |
386 | 386 | private function decodeManifestFile($manifest_file) |
387 | 387 | { |
388 | - if (! file_exists($manifest_file)) { |
|
388 | + if ( ! file_exists($manifest_file)) { |
|
389 | 389 | throw new InvalidFilePathException($manifest_file); |
390 | 390 | } |
391 | 391 | return json_decode(file_get_contents($manifest_file), true); |
@@ -440,9 +440,9 @@ discard block |
||
440 | 440 | private function loadCoreCss() |
441 | 441 | { |
442 | 442 | if ($this->template_config->enable_default_style) { |
443 | - $default_stylesheet_path = is_readable(EVENT_ESPRESSO_UPLOAD_DIR . 'css/style.css') |
|
443 | + $default_stylesheet_path = is_readable(EVENT_ESPRESSO_UPLOAD_DIR.'css/style.css') |
|
444 | 444 | ? EVENT_ESPRESSO_UPLOAD_DIR . 'css/espresso_default.css' |
445 | - : EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css'; |
|
445 | + : EE_GLOBAL_ASSETS_URL.'css/espresso_default.css'; |
|
446 | 446 | wp_register_style( |
447 | 447 | 'espresso_default', |
448 | 448 | $default_stylesheet_path, |
@@ -453,7 +453,7 @@ discard block |
||
453 | 453 | if ($this->template_config->custom_style_sheet !== null) { |
454 | 454 | wp_register_style( |
455 | 455 | 'espresso_custom_css', |
456 | - EVENT_ESPRESSO_UPLOAD_URL . 'css/' . $this->template_config->custom_style_sheet, |
|
456 | + EVENT_ESPRESSO_UPLOAD_URL.'css/'.$this->template_config->custom_style_sheet, |
|
457 | 457 | array('espresso_default'), |
458 | 458 | EVENT_ESPRESSO_VERSION |
459 | 459 | ); |
@@ -471,7 +471,7 @@ discard block |
||
471 | 471 | // load core js |
472 | 472 | wp_register_script( |
473 | 473 | 'espresso_core', |
474 | - EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', |
|
474 | + EE_GLOBAL_ASSETS_URL.'scripts/espresso_core.js', |
|
475 | 475 | array('jquery'), |
476 | 476 | EVENT_ESPRESSO_VERSION, |
477 | 477 | true |
@@ -488,14 +488,14 @@ discard block |
||
488 | 488 | // register jQuery Validate and additional methods |
489 | 489 | wp_register_script( |
490 | 490 | 'jquery-validate', |
491 | - EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.min.js', |
|
491 | + EE_GLOBAL_ASSETS_URL.'scripts/jquery.validate.min.js', |
|
492 | 492 | array('jquery'), |
493 | 493 | '1.15.0', |
494 | 494 | true |
495 | 495 | ); |
496 | 496 | wp_register_script( |
497 | 497 | 'jquery-validate-extra-methods', |
498 | - EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.additional-methods.min.js', |
|
498 | + EE_GLOBAL_ASSETS_URL.'scripts/jquery.validate.additional-methods.min.js', |
|
499 | 499 | array('jquery', 'jquery-validate'), |
500 | 500 | '1.15.0', |
501 | 501 | true |
@@ -513,14 +513,14 @@ discard block |
||
513 | 513 | // @link http://josscrowcroft.github.io/accounting.js/ |
514 | 514 | wp_register_script( |
515 | 515 | 'ee-accounting-core', |
516 | - EE_THIRD_PARTY_URL . 'accounting/accounting.js', |
|
516 | + EE_THIRD_PARTY_URL.'accounting/accounting.js', |
|
517 | 517 | array('underscore'), |
518 | 518 | '0.3.2', |
519 | 519 | true |
520 | 520 | ); |
521 | 521 | wp_register_script( |
522 | 522 | 'ee-accounting', |
523 | - EE_GLOBAL_ASSETS_URL . 'scripts/ee-accounting-config.js', |
|
523 | + EE_GLOBAL_ASSETS_URL.'scripts/ee-accounting-config.js', |
|
524 | 524 | array('ee-accounting-core'), |
525 | 525 | EVENT_ESPRESSO_VERSION, |
526 | 526 | true |
@@ -25,616 +25,616 @@ |
||
25 | 25 | class Registry |
26 | 26 | { |
27 | 27 | |
28 | - const ASSET_TYPE_CSS = 'css'; |
|
29 | - const ASSET_TYPE_JS = 'js'; |
|
30 | - const ASSET_NAMESPACE = 'core'; |
|
31 | - |
|
32 | - /** |
|
33 | - * @var EE_Template_Config $template_config |
|
34 | - */ |
|
35 | - protected $template_config; |
|
36 | - |
|
37 | - /** |
|
38 | - * @var EE_Currency_Config $currency_config |
|
39 | - */ |
|
40 | - protected $currency_config; |
|
41 | - |
|
42 | - /** |
|
43 | - * This holds the jsdata data object that will be exposed on pages that enqueue the `eejs-core` script. |
|
44 | - * |
|
45 | - * @var array |
|
46 | - */ |
|
47 | - protected $jsdata = array(); |
|
48 | - |
|
49 | - |
|
50 | - /** |
|
51 | - * This keeps track of all scripts with registered data. It is used to prevent duplicate data objects setup in the |
|
52 | - * page source. |
|
53 | - * @var array |
|
54 | - */ |
|
55 | - protected $script_handles_with_data = array(); |
|
56 | - |
|
57 | - |
|
58 | - /** |
|
59 | - * @var DomainInterface |
|
60 | - */ |
|
61 | - protected $domain; |
|
62 | - |
|
63 | - |
|
64 | - |
|
65 | - /** |
|
66 | - * Holds the manifest data obtained from registered manifest files. |
|
67 | - * Manifests are maps of asset chunk name to actual built asset file names. |
|
68 | - * Shape of this array is: |
|
69 | - * |
|
70 | - * array( |
|
71 | - * 'some_namespace_slug' => array( |
|
72 | - * 'some_chunk_name' => array( |
|
73 | - * 'js' => 'filename.js' |
|
74 | - * 'css' => 'filename.js' |
|
75 | - * ), |
|
76 | - * 'url_base' => 'https://baseurl.com/to/assets |
|
77 | - * ) |
|
78 | - * ) |
|
79 | - * |
|
80 | - * @var array |
|
81 | - */ |
|
82 | - private $manifest_data = array(); |
|
83 | - |
|
84 | - |
|
85 | - /** |
|
86 | - * Registry constructor. |
|
87 | - * Hooking into WP actions for script registry. |
|
88 | - * |
|
89 | - * @param EE_Template_Config $template_config |
|
90 | - * @param EE_Currency_Config $currency_config |
|
91 | - * @param DomainInterface $domain |
|
92 | - * @throws InvalidArgumentException |
|
93 | - * @throws InvalidFilePathException |
|
94 | - */ |
|
95 | - public function __construct( |
|
96 | - EE_Template_Config $template_config, |
|
97 | - EE_Currency_Config $currency_config, |
|
98 | - DomainInterface $domain |
|
99 | - ) { |
|
100 | - $this->template_config = $template_config; |
|
101 | - $this->currency_config = $currency_config; |
|
102 | - $this->domain = $domain; |
|
103 | - $this->registerManifestFile( |
|
104 | - self::ASSET_NAMESPACE, |
|
105 | - $this->domain->distributionAssetsUrl(), |
|
106 | - $this->domain->distributionAssetsPath() . 'build-manifest.json' |
|
107 | - ); |
|
108 | - add_action('wp_enqueue_scripts', array($this, 'scripts'), 1); |
|
109 | - add_action('admin_enqueue_scripts', array($this, 'scripts'), 1); |
|
110 | - add_action('wp_enqueue_scripts', array($this, 'enqueueData'), 2); |
|
111 | - add_action('admin_enqueue_scripts', array($this, 'enqueueData'), 2); |
|
112 | - add_action('wp_print_footer_scripts', array($this, 'enqueueData'), 1); |
|
113 | - add_action('admin_print_footer_scripts', array($this, 'enqueueData'), 1); |
|
114 | - } |
|
115 | - |
|
116 | - /** |
|
117 | - * Callback for the WP script actions. |
|
118 | - * Used to register globally accessible core scripts. |
|
119 | - * Also used to add the eejs.data object to the source for any js having eejs-core as a dependency. |
|
120 | - * |
|
121 | - */ |
|
122 | - public function scripts() |
|
123 | - { |
|
124 | - global $wp_version; |
|
125 | - wp_register_script( |
|
126 | - 'ee-manifest', |
|
127 | - $this->getAssetUrl(self::ASSET_NAMESPACE, 'manifest', self::ASSET_TYPE_JS), |
|
128 | - array(), |
|
129 | - null, |
|
130 | - true |
|
131 | - ); |
|
132 | - wp_register_script( |
|
133 | - 'eejs-core', |
|
134 | - $this->getAssetUrl(self::ASSET_NAMESPACE, 'eejs', self::ASSET_TYPE_JS), |
|
135 | - array('ee-manifest'), |
|
136 | - null, |
|
137 | - true |
|
138 | - ); |
|
139 | - wp_register_script( |
|
140 | - 'ee-vendor-react', |
|
141 | - $this->getAssetUrl(self::ASSET_NAMESPACE, 'reactVendor', self::ASSET_TYPE_JS), |
|
142 | - array('eejs-core'), |
|
143 | - null, |
|
144 | - true |
|
145 | - ); |
|
146 | - //only run this if WordPress 4.4.0 > is in use. |
|
147 | - if (version_compare($wp_version, '4.4.0', '>')) { |
|
148 | - //js.api |
|
149 | - wp_register_script( |
|
150 | - 'eejs-api', |
|
151 | - EE_LIBRARIES_URL . 'rest_api/assets/js/eejs-api.min.js', |
|
152 | - array('underscore', 'eejs-core'), |
|
153 | - EVENT_ESPRESSO_VERSION, |
|
154 | - true |
|
155 | - ); |
|
156 | - $this->jsdata['eejs_api_nonce'] = wp_create_nonce('wp_rest'); |
|
157 | - $this->jsdata['paths'] = array('rest_route' => rest_url('ee/v4.8.36/')); |
|
158 | - } |
|
159 | - if (! is_admin()) { |
|
160 | - $this->loadCoreCss(); |
|
161 | - } |
|
162 | - $this->loadCoreJs(); |
|
163 | - $this->loadJqueryValidate(); |
|
164 | - $this->loadAccountingJs(); |
|
165 | - $this->loadQtipJs(); |
|
166 | - $this->registerAdminAssets(); |
|
167 | - } |
|
168 | - |
|
169 | - |
|
170 | - |
|
171 | - /** |
|
172 | - * Call back for the script print in frontend and backend. |
|
173 | - * Used to call wp_localize_scripts so that data can be added throughout the runtime until this later hook point. |
|
174 | - * |
|
175 | - * @since 4.9.31.rc.015 |
|
176 | - */ |
|
177 | - public function enqueueData() |
|
178 | - { |
|
179 | - $this->removeAlreadyRegisteredDataForScriptHandles(); |
|
180 | - wp_localize_script('eejs-core', 'eejsdata', array('data' => $this->jsdata)); |
|
181 | - wp_localize_script('espresso_core', 'eei18n', EE_Registry::$i18n_js_strings); |
|
182 | - $this->localizeAccountingJs(); |
|
183 | - $this->addRegisteredScriptHandlesWithData('eejs-core'); |
|
184 | - $this->addRegisteredScriptHandlesWithData('espresso_core'); |
|
185 | - } |
|
186 | - |
|
187 | - |
|
188 | - |
|
189 | - /** |
|
190 | - * Used to add data to eejs.data object. |
|
191 | - * Note: Overriding existing data is not allowed. |
|
192 | - * Data will be accessible as a javascript object when you list `eejs-core` as a dependency for your javascript. |
|
193 | - * If the data you add is something like this: |
|
194 | - * $this->addData( 'my_plugin_data', array( 'foo' => 'gar' ) ); |
|
195 | - * It will be exposed in the page source as: |
|
196 | - * eejs.data.my_plugin_data.foo == gar |
|
197 | - * |
|
198 | - * @param string $key Key used to access your data |
|
199 | - * @param string|array $value Value to attach to key |
|
200 | - * @throws InvalidArgumentException |
|
201 | - */ |
|
202 | - public function addData($key, $value) |
|
203 | - { |
|
204 | - if ($this->verifyDataNotExisting($key)) { |
|
205 | - $this->jsdata[$key] = $value; |
|
206 | - } |
|
207 | - } |
|
208 | - |
|
209 | - |
|
210 | - |
|
211 | - /** |
|
212 | - * Similar to addData except this allows for users to push values to an existing key where the values on key are |
|
213 | - * elements in an array. |
|
214 | - * When you use this method, the value you include will be appended to the end of an array on $key. |
|
215 | - * So if the $key was 'test' and you added a value of 'my_data' then it would be represented in the javascript |
|
216 | - * object like this, eejs.data.test = [ my_data, |
|
217 | - * ] |
|
218 | - * If there has already been a scalar value attached to the data object given key, then |
|
219 | - * this will throw an exception. |
|
220 | - * |
|
221 | - * @param string $key Key to attach data to. |
|
222 | - * @param string|array $value Value being registered. |
|
223 | - * @throws InvalidArgumentException |
|
224 | - */ |
|
225 | - public function pushData($key, $value) |
|
226 | - { |
|
227 | - if (isset($this->jsdata[$key]) |
|
228 | - && ! is_array($this->jsdata[$key]) |
|
229 | - ) { |
|
230 | - throw new invalidArgumentException( |
|
231 | - sprintf( |
|
232 | - __( |
|
233 | - 'The value for %1$s is already set and it is not an array. The %2$s method can only be used to |
|
28 | + const ASSET_TYPE_CSS = 'css'; |
|
29 | + const ASSET_TYPE_JS = 'js'; |
|
30 | + const ASSET_NAMESPACE = 'core'; |
|
31 | + |
|
32 | + /** |
|
33 | + * @var EE_Template_Config $template_config |
|
34 | + */ |
|
35 | + protected $template_config; |
|
36 | + |
|
37 | + /** |
|
38 | + * @var EE_Currency_Config $currency_config |
|
39 | + */ |
|
40 | + protected $currency_config; |
|
41 | + |
|
42 | + /** |
|
43 | + * This holds the jsdata data object that will be exposed on pages that enqueue the `eejs-core` script. |
|
44 | + * |
|
45 | + * @var array |
|
46 | + */ |
|
47 | + protected $jsdata = array(); |
|
48 | + |
|
49 | + |
|
50 | + /** |
|
51 | + * This keeps track of all scripts with registered data. It is used to prevent duplicate data objects setup in the |
|
52 | + * page source. |
|
53 | + * @var array |
|
54 | + */ |
|
55 | + protected $script_handles_with_data = array(); |
|
56 | + |
|
57 | + |
|
58 | + /** |
|
59 | + * @var DomainInterface |
|
60 | + */ |
|
61 | + protected $domain; |
|
62 | + |
|
63 | + |
|
64 | + |
|
65 | + /** |
|
66 | + * Holds the manifest data obtained from registered manifest files. |
|
67 | + * Manifests are maps of asset chunk name to actual built asset file names. |
|
68 | + * Shape of this array is: |
|
69 | + * |
|
70 | + * array( |
|
71 | + * 'some_namespace_slug' => array( |
|
72 | + * 'some_chunk_name' => array( |
|
73 | + * 'js' => 'filename.js' |
|
74 | + * 'css' => 'filename.js' |
|
75 | + * ), |
|
76 | + * 'url_base' => 'https://baseurl.com/to/assets |
|
77 | + * ) |
|
78 | + * ) |
|
79 | + * |
|
80 | + * @var array |
|
81 | + */ |
|
82 | + private $manifest_data = array(); |
|
83 | + |
|
84 | + |
|
85 | + /** |
|
86 | + * Registry constructor. |
|
87 | + * Hooking into WP actions for script registry. |
|
88 | + * |
|
89 | + * @param EE_Template_Config $template_config |
|
90 | + * @param EE_Currency_Config $currency_config |
|
91 | + * @param DomainInterface $domain |
|
92 | + * @throws InvalidArgumentException |
|
93 | + * @throws InvalidFilePathException |
|
94 | + */ |
|
95 | + public function __construct( |
|
96 | + EE_Template_Config $template_config, |
|
97 | + EE_Currency_Config $currency_config, |
|
98 | + DomainInterface $domain |
|
99 | + ) { |
|
100 | + $this->template_config = $template_config; |
|
101 | + $this->currency_config = $currency_config; |
|
102 | + $this->domain = $domain; |
|
103 | + $this->registerManifestFile( |
|
104 | + self::ASSET_NAMESPACE, |
|
105 | + $this->domain->distributionAssetsUrl(), |
|
106 | + $this->domain->distributionAssetsPath() . 'build-manifest.json' |
|
107 | + ); |
|
108 | + add_action('wp_enqueue_scripts', array($this, 'scripts'), 1); |
|
109 | + add_action('admin_enqueue_scripts', array($this, 'scripts'), 1); |
|
110 | + add_action('wp_enqueue_scripts', array($this, 'enqueueData'), 2); |
|
111 | + add_action('admin_enqueue_scripts', array($this, 'enqueueData'), 2); |
|
112 | + add_action('wp_print_footer_scripts', array($this, 'enqueueData'), 1); |
|
113 | + add_action('admin_print_footer_scripts', array($this, 'enqueueData'), 1); |
|
114 | + } |
|
115 | + |
|
116 | + /** |
|
117 | + * Callback for the WP script actions. |
|
118 | + * Used to register globally accessible core scripts. |
|
119 | + * Also used to add the eejs.data object to the source for any js having eejs-core as a dependency. |
|
120 | + * |
|
121 | + */ |
|
122 | + public function scripts() |
|
123 | + { |
|
124 | + global $wp_version; |
|
125 | + wp_register_script( |
|
126 | + 'ee-manifest', |
|
127 | + $this->getAssetUrl(self::ASSET_NAMESPACE, 'manifest', self::ASSET_TYPE_JS), |
|
128 | + array(), |
|
129 | + null, |
|
130 | + true |
|
131 | + ); |
|
132 | + wp_register_script( |
|
133 | + 'eejs-core', |
|
134 | + $this->getAssetUrl(self::ASSET_NAMESPACE, 'eejs', self::ASSET_TYPE_JS), |
|
135 | + array('ee-manifest'), |
|
136 | + null, |
|
137 | + true |
|
138 | + ); |
|
139 | + wp_register_script( |
|
140 | + 'ee-vendor-react', |
|
141 | + $this->getAssetUrl(self::ASSET_NAMESPACE, 'reactVendor', self::ASSET_TYPE_JS), |
|
142 | + array('eejs-core'), |
|
143 | + null, |
|
144 | + true |
|
145 | + ); |
|
146 | + //only run this if WordPress 4.4.0 > is in use. |
|
147 | + if (version_compare($wp_version, '4.4.0', '>')) { |
|
148 | + //js.api |
|
149 | + wp_register_script( |
|
150 | + 'eejs-api', |
|
151 | + EE_LIBRARIES_URL . 'rest_api/assets/js/eejs-api.min.js', |
|
152 | + array('underscore', 'eejs-core'), |
|
153 | + EVENT_ESPRESSO_VERSION, |
|
154 | + true |
|
155 | + ); |
|
156 | + $this->jsdata['eejs_api_nonce'] = wp_create_nonce('wp_rest'); |
|
157 | + $this->jsdata['paths'] = array('rest_route' => rest_url('ee/v4.8.36/')); |
|
158 | + } |
|
159 | + if (! is_admin()) { |
|
160 | + $this->loadCoreCss(); |
|
161 | + } |
|
162 | + $this->loadCoreJs(); |
|
163 | + $this->loadJqueryValidate(); |
|
164 | + $this->loadAccountingJs(); |
|
165 | + $this->loadQtipJs(); |
|
166 | + $this->registerAdminAssets(); |
|
167 | + } |
|
168 | + |
|
169 | + |
|
170 | + |
|
171 | + /** |
|
172 | + * Call back for the script print in frontend and backend. |
|
173 | + * Used to call wp_localize_scripts so that data can be added throughout the runtime until this later hook point. |
|
174 | + * |
|
175 | + * @since 4.9.31.rc.015 |
|
176 | + */ |
|
177 | + public function enqueueData() |
|
178 | + { |
|
179 | + $this->removeAlreadyRegisteredDataForScriptHandles(); |
|
180 | + wp_localize_script('eejs-core', 'eejsdata', array('data' => $this->jsdata)); |
|
181 | + wp_localize_script('espresso_core', 'eei18n', EE_Registry::$i18n_js_strings); |
|
182 | + $this->localizeAccountingJs(); |
|
183 | + $this->addRegisteredScriptHandlesWithData('eejs-core'); |
|
184 | + $this->addRegisteredScriptHandlesWithData('espresso_core'); |
|
185 | + } |
|
186 | + |
|
187 | + |
|
188 | + |
|
189 | + /** |
|
190 | + * Used to add data to eejs.data object. |
|
191 | + * Note: Overriding existing data is not allowed. |
|
192 | + * Data will be accessible as a javascript object when you list `eejs-core` as a dependency for your javascript. |
|
193 | + * If the data you add is something like this: |
|
194 | + * $this->addData( 'my_plugin_data', array( 'foo' => 'gar' ) ); |
|
195 | + * It will be exposed in the page source as: |
|
196 | + * eejs.data.my_plugin_data.foo == gar |
|
197 | + * |
|
198 | + * @param string $key Key used to access your data |
|
199 | + * @param string|array $value Value to attach to key |
|
200 | + * @throws InvalidArgumentException |
|
201 | + */ |
|
202 | + public function addData($key, $value) |
|
203 | + { |
|
204 | + if ($this->verifyDataNotExisting($key)) { |
|
205 | + $this->jsdata[$key] = $value; |
|
206 | + } |
|
207 | + } |
|
208 | + |
|
209 | + |
|
210 | + |
|
211 | + /** |
|
212 | + * Similar to addData except this allows for users to push values to an existing key where the values on key are |
|
213 | + * elements in an array. |
|
214 | + * When you use this method, the value you include will be appended to the end of an array on $key. |
|
215 | + * So if the $key was 'test' and you added a value of 'my_data' then it would be represented in the javascript |
|
216 | + * object like this, eejs.data.test = [ my_data, |
|
217 | + * ] |
|
218 | + * If there has already been a scalar value attached to the data object given key, then |
|
219 | + * this will throw an exception. |
|
220 | + * |
|
221 | + * @param string $key Key to attach data to. |
|
222 | + * @param string|array $value Value being registered. |
|
223 | + * @throws InvalidArgumentException |
|
224 | + */ |
|
225 | + public function pushData($key, $value) |
|
226 | + { |
|
227 | + if (isset($this->jsdata[$key]) |
|
228 | + && ! is_array($this->jsdata[$key]) |
|
229 | + ) { |
|
230 | + throw new invalidArgumentException( |
|
231 | + sprintf( |
|
232 | + __( |
|
233 | + 'The value for %1$s is already set and it is not an array. The %2$s method can only be used to |
|
234 | 234 | push values to this data element when it is an array.', |
235 | - 'event_espresso' |
|
236 | - ), |
|
237 | - $key, |
|
238 | - __METHOD__ |
|
239 | - ) |
|
240 | - ); |
|
241 | - } |
|
242 | - $this->jsdata[$key][] = $value; |
|
243 | - } |
|
244 | - |
|
245 | - |
|
246 | - |
|
247 | - /** |
|
248 | - * Used to set content used by javascript for a template. |
|
249 | - * Note: Overrides of existing registered templates are not allowed. |
|
250 | - * |
|
251 | - * @param string $template_reference |
|
252 | - * @param string $template_content |
|
253 | - * @throws InvalidArgumentException |
|
254 | - */ |
|
255 | - public function addTemplate($template_reference, $template_content) |
|
256 | - { |
|
257 | - if (! isset($this->jsdata['templates'])) { |
|
258 | - $this->jsdata['templates'] = array(); |
|
259 | - } |
|
260 | - //no overrides allowed. |
|
261 | - if (isset($this->jsdata['templates'][$template_reference])) { |
|
262 | - throw new invalidArgumentException( |
|
263 | - sprintf( |
|
264 | - __( |
|
265 | - 'The %1$s key already exists for the templates array in the js data array. No overrides are allowed.', |
|
266 | - 'event_espresso' |
|
267 | - ), |
|
268 | - $template_reference |
|
269 | - ) |
|
270 | - ); |
|
271 | - } |
|
272 | - $this->jsdata['templates'][$template_reference] = $template_content; |
|
273 | - } |
|
274 | - |
|
275 | - |
|
276 | - |
|
277 | - /** |
|
278 | - * Retrieve the template content already registered for the given reference. |
|
279 | - * |
|
280 | - * @param string $template_reference |
|
281 | - * @return string |
|
282 | - */ |
|
283 | - public function getTemplate($template_reference) |
|
284 | - { |
|
285 | - return isset($this->jsdata['templates'], $this->jsdata['templates'][$template_reference]) |
|
286 | - ? $this->jsdata['templates'][$template_reference] |
|
287 | - : ''; |
|
288 | - } |
|
289 | - |
|
290 | - |
|
291 | - |
|
292 | - /** |
|
293 | - * Retrieve registered data. |
|
294 | - * |
|
295 | - * @param string $key Name of key to attach data to. |
|
296 | - * @return mixed If there is no for the given key, then false is returned. |
|
297 | - */ |
|
298 | - public function getData($key) |
|
299 | - { |
|
300 | - return isset($this->jsdata[$key]) |
|
301 | - ? $this->jsdata[$key] |
|
302 | - : false; |
|
303 | - } |
|
304 | - |
|
305 | - |
|
306 | - /** |
|
307 | - * Get the actual asset path for asset manifests. |
|
308 | - * If there is no asset path found for the given $chunk_name, then the $chunk_name is returned. |
|
309 | - * @param string $namespace The namespace associated with the manifest file hosting the map of chunk_name to actual |
|
310 | - * asset file location. |
|
311 | - * @param string $chunk_name |
|
312 | - * @param string $asset_type |
|
313 | - * @return string |
|
314 | - * @since $VID:$ |
|
315 | - */ |
|
316 | - public function getAssetUrl($namespace, $chunk_name, $asset_type) |
|
317 | - { |
|
318 | - $url = isset( |
|
319 | - $this->manifest_data[$namespace][$chunk_name][$asset_type], |
|
320 | - $this->manifest_data[$namespace]['url_base'] |
|
321 | - ) |
|
322 | - ? $this->manifest_data[$namespace]['url_base'] |
|
323 | - . $this->manifest_data[$namespace][$chunk_name][$asset_type] |
|
324 | - : $chunk_name; |
|
325 | - return apply_filters( |
|
326 | - 'FHEE__EventEspresso_core_services_assets_Registry__getAssetUrl', |
|
327 | - $url, |
|
328 | - $namespace, |
|
329 | - $chunk_name, |
|
330 | - $asset_type |
|
331 | - ); |
|
332 | - } |
|
333 | - |
|
334 | - |
|
335 | - /** |
|
336 | - * Used to register a js/css manifest file with the registered_manifest_files property. |
|
337 | - * |
|
338 | - * @param string $namespace Provided to associate the manifest file with a specific namespace. |
|
339 | - * @param string $url_base The url base for the manifest file location. |
|
340 | - * @param string $manifest_file The absolute path to the manifest file. |
|
341 | - * @throws InvalidArgumentException |
|
342 | - * @throws InvalidFilePathException |
|
343 | - * @since $VID:$ |
|
344 | - */ |
|
345 | - public function registerManifestFile($namespace, $url_base, $manifest_file) |
|
346 | - { |
|
347 | - if (isset($this->manifest_data[$namespace])) { |
|
348 | - throw new InvalidArgumentException( |
|
349 | - sprintf( |
|
350 | - esc_html__( |
|
351 | - 'The namespace for this manifest file has already been registered, choose a namespace other than %s', |
|
352 | - 'event_espresso' |
|
353 | - ), |
|
354 | - $namespace |
|
355 | - ) |
|
356 | - ); |
|
357 | - } |
|
358 | - if (filter_var($url_base, FILTER_VALIDATE_URL) === false) { |
|
359 | - throw new InvalidArgumentException( |
|
360 | - sprintf( |
|
361 | - esc_html__( |
|
362 | - 'The provided value for %1$s is not a valid url. The url provided was: %2$s', |
|
363 | - 'event_espresso' |
|
364 | - ), |
|
365 | - '$url_base', |
|
366 | - $url_base |
|
367 | - ) |
|
368 | - ); |
|
369 | - } |
|
370 | - $this->manifest_data[$namespace] = $this->decodeManifestFile($manifest_file); |
|
371 | - if (! isset($this->manifest_data[$namespace]['url_base'])) { |
|
372 | - $this->manifest_data[$namespace]['url_base'] = trailingslashit($url_base); |
|
373 | - } |
|
374 | - } |
|
375 | - |
|
376 | - |
|
377 | - |
|
378 | - /** |
|
379 | - * Decodes json from the provided manifest file. |
|
380 | - * |
|
381 | - * @since $VID:$ |
|
382 | - * @param string $manifest_file Path to manifest file. |
|
383 | - * @return array |
|
384 | - * @throws InvalidFilePathException |
|
385 | - */ |
|
386 | - private function decodeManifestFile($manifest_file) |
|
387 | - { |
|
388 | - if (! file_exists($manifest_file)) { |
|
389 | - throw new InvalidFilePathException($manifest_file); |
|
390 | - } |
|
391 | - return json_decode(file_get_contents($manifest_file), true); |
|
392 | - } |
|
393 | - |
|
394 | - |
|
395 | - |
|
396 | - /** |
|
397 | - * Verifies whether the given data exists already on the jsdata array. |
|
398 | - * Overriding data is not allowed. |
|
399 | - * |
|
400 | - * @param string $key Index for data. |
|
401 | - * @return bool If valid then return true. |
|
402 | - * @throws InvalidArgumentException if data already exists. |
|
403 | - */ |
|
404 | - protected function verifyDataNotExisting($key) |
|
405 | - { |
|
406 | - if (isset($this->jsdata[$key])) { |
|
407 | - if (is_array($this->jsdata[$key])) { |
|
408 | - throw new InvalidArgumentException( |
|
409 | - sprintf( |
|
410 | - __( |
|
411 | - 'The value for %1$s already exists in the Registry::eejs object. |
|
235 | + 'event_espresso' |
|
236 | + ), |
|
237 | + $key, |
|
238 | + __METHOD__ |
|
239 | + ) |
|
240 | + ); |
|
241 | + } |
|
242 | + $this->jsdata[$key][] = $value; |
|
243 | + } |
|
244 | + |
|
245 | + |
|
246 | + |
|
247 | + /** |
|
248 | + * Used to set content used by javascript for a template. |
|
249 | + * Note: Overrides of existing registered templates are not allowed. |
|
250 | + * |
|
251 | + * @param string $template_reference |
|
252 | + * @param string $template_content |
|
253 | + * @throws InvalidArgumentException |
|
254 | + */ |
|
255 | + public function addTemplate($template_reference, $template_content) |
|
256 | + { |
|
257 | + if (! isset($this->jsdata['templates'])) { |
|
258 | + $this->jsdata['templates'] = array(); |
|
259 | + } |
|
260 | + //no overrides allowed. |
|
261 | + if (isset($this->jsdata['templates'][$template_reference])) { |
|
262 | + throw new invalidArgumentException( |
|
263 | + sprintf( |
|
264 | + __( |
|
265 | + 'The %1$s key already exists for the templates array in the js data array. No overrides are allowed.', |
|
266 | + 'event_espresso' |
|
267 | + ), |
|
268 | + $template_reference |
|
269 | + ) |
|
270 | + ); |
|
271 | + } |
|
272 | + $this->jsdata['templates'][$template_reference] = $template_content; |
|
273 | + } |
|
274 | + |
|
275 | + |
|
276 | + |
|
277 | + /** |
|
278 | + * Retrieve the template content already registered for the given reference. |
|
279 | + * |
|
280 | + * @param string $template_reference |
|
281 | + * @return string |
|
282 | + */ |
|
283 | + public function getTemplate($template_reference) |
|
284 | + { |
|
285 | + return isset($this->jsdata['templates'], $this->jsdata['templates'][$template_reference]) |
|
286 | + ? $this->jsdata['templates'][$template_reference] |
|
287 | + : ''; |
|
288 | + } |
|
289 | + |
|
290 | + |
|
291 | + |
|
292 | + /** |
|
293 | + * Retrieve registered data. |
|
294 | + * |
|
295 | + * @param string $key Name of key to attach data to. |
|
296 | + * @return mixed If there is no for the given key, then false is returned. |
|
297 | + */ |
|
298 | + public function getData($key) |
|
299 | + { |
|
300 | + return isset($this->jsdata[$key]) |
|
301 | + ? $this->jsdata[$key] |
|
302 | + : false; |
|
303 | + } |
|
304 | + |
|
305 | + |
|
306 | + /** |
|
307 | + * Get the actual asset path for asset manifests. |
|
308 | + * If there is no asset path found for the given $chunk_name, then the $chunk_name is returned. |
|
309 | + * @param string $namespace The namespace associated with the manifest file hosting the map of chunk_name to actual |
|
310 | + * asset file location. |
|
311 | + * @param string $chunk_name |
|
312 | + * @param string $asset_type |
|
313 | + * @return string |
|
314 | + * @since $VID:$ |
|
315 | + */ |
|
316 | + public function getAssetUrl($namespace, $chunk_name, $asset_type) |
|
317 | + { |
|
318 | + $url = isset( |
|
319 | + $this->manifest_data[$namespace][$chunk_name][$asset_type], |
|
320 | + $this->manifest_data[$namespace]['url_base'] |
|
321 | + ) |
|
322 | + ? $this->manifest_data[$namespace]['url_base'] |
|
323 | + . $this->manifest_data[$namespace][$chunk_name][$asset_type] |
|
324 | + : $chunk_name; |
|
325 | + return apply_filters( |
|
326 | + 'FHEE__EventEspresso_core_services_assets_Registry__getAssetUrl', |
|
327 | + $url, |
|
328 | + $namespace, |
|
329 | + $chunk_name, |
|
330 | + $asset_type |
|
331 | + ); |
|
332 | + } |
|
333 | + |
|
334 | + |
|
335 | + /** |
|
336 | + * Used to register a js/css manifest file with the registered_manifest_files property. |
|
337 | + * |
|
338 | + * @param string $namespace Provided to associate the manifest file with a specific namespace. |
|
339 | + * @param string $url_base The url base for the manifest file location. |
|
340 | + * @param string $manifest_file The absolute path to the manifest file. |
|
341 | + * @throws InvalidArgumentException |
|
342 | + * @throws InvalidFilePathException |
|
343 | + * @since $VID:$ |
|
344 | + */ |
|
345 | + public function registerManifestFile($namespace, $url_base, $manifest_file) |
|
346 | + { |
|
347 | + if (isset($this->manifest_data[$namespace])) { |
|
348 | + throw new InvalidArgumentException( |
|
349 | + sprintf( |
|
350 | + esc_html__( |
|
351 | + 'The namespace for this manifest file has already been registered, choose a namespace other than %s', |
|
352 | + 'event_espresso' |
|
353 | + ), |
|
354 | + $namespace |
|
355 | + ) |
|
356 | + ); |
|
357 | + } |
|
358 | + if (filter_var($url_base, FILTER_VALIDATE_URL) === false) { |
|
359 | + throw new InvalidArgumentException( |
|
360 | + sprintf( |
|
361 | + esc_html__( |
|
362 | + 'The provided value for %1$s is not a valid url. The url provided was: %2$s', |
|
363 | + 'event_espresso' |
|
364 | + ), |
|
365 | + '$url_base', |
|
366 | + $url_base |
|
367 | + ) |
|
368 | + ); |
|
369 | + } |
|
370 | + $this->manifest_data[$namespace] = $this->decodeManifestFile($manifest_file); |
|
371 | + if (! isset($this->manifest_data[$namespace]['url_base'])) { |
|
372 | + $this->manifest_data[$namespace]['url_base'] = trailingslashit($url_base); |
|
373 | + } |
|
374 | + } |
|
375 | + |
|
376 | + |
|
377 | + |
|
378 | + /** |
|
379 | + * Decodes json from the provided manifest file. |
|
380 | + * |
|
381 | + * @since $VID:$ |
|
382 | + * @param string $manifest_file Path to manifest file. |
|
383 | + * @return array |
|
384 | + * @throws InvalidFilePathException |
|
385 | + */ |
|
386 | + private function decodeManifestFile($manifest_file) |
|
387 | + { |
|
388 | + if (! file_exists($manifest_file)) { |
|
389 | + throw new InvalidFilePathException($manifest_file); |
|
390 | + } |
|
391 | + return json_decode(file_get_contents($manifest_file), true); |
|
392 | + } |
|
393 | + |
|
394 | + |
|
395 | + |
|
396 | + /** |
|
397 | + * Verifies whether the given data exists already on the jsdata array. |
|
398 | + * Overriding data is not allowed. |
|
399 | + * |
|
400 | + * @param string $key Index for data. |
|
401 | + * @return bool If valid then return true. |
|
402 | + * @throws InvalidArgumentException if data already exists. |
|
403 | + */ |
|
404 | + protected function verifyDataNotExisting($key) |
|
405 | + { |
|
406 | + if (isset($this->jsdata[$key])) { |
|
407 | + if (is_array($this->jsdata[$key])) { |
|
408 | + throw new InvalidArgumentException( |
|
409 | + sprintf( |
|
410 | + __( |
|
411 | + 'The value for %1$s already exists in the Registry::eejs object. |
|
412 | 412 | Overrides are not allowed. Since the value of this data is an array, you may want to use the |
413 | 413 | %2$s method to push your value to the array.', |
414 | - 'event_espresso' |
|
415 | - ), |
|
416 | - $key, |
|
417 | - 'pushData()' |
|
418 | - ) |
|
419 | - ); |
|
420 | - } |
|
421 | - throw new InvalidArgumentException( |
|
422 | - sprintf( |
|
423 | - __( |
|
424 | - 'The value for %1$s already exists in the Registry::eejs object. Overrides are not |
|
414 | + 'event_espresso' |
|
415 | + ), |
|
416 | + $key, |
|
417 | + 'pushData()' |
|
418 | + ) |
|
419 | + ); |
|
420 | + } |
|
421 | + throw new InvalidArgumentException( |
|
422 | + sprintf( |
|
423 | + __( |
|
424 | + 'The value for %1$s already exists in the Registry::eejs object. Overrides are not |
|
425 | 425 | allowed. Consider attaching your value to a different key', |
426 | - 'event_espresso' |
|
427 | - ), |
|
428 | - $key |
|
429 | - ) |
|
430 | - ); |
|
431 | - } |
|
432 | - return true; |
|
433 | - } |
|
434 | - |
|
435 | - |
|
436 | - |
|
437 | - /** |
|
438 | - * registers core default stylesheets |
|
439 | - */ |
|
440 | - private function loadCoreCss() |
|
441 | - { |
|
442 | - if ($this->template_config->enable_default_style) { |
|
443 | - $default_stylesheet_path = is_readable(EVENT_ESPRESSO_UPLOAD_DIR . 'css/style.css') |
|
444 | - ? EVENT_ESPRESSO_UPLOAD_DIR . 'css/espresso_default.css' |
|
445 | - : EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css'; |
|
446 | - wp_register_style( |
|
447 | - 'espresso_default', |
|
448 | - $default_stylesheet_path, |
|
449 | - array('dashicons'), |
|
450 | - EVENT_ESPRESSO_VERSION |
|
451 | - ); |
|
452 | - //Load custom style sheet if available |
|
453 | - if ($this->template_config->custom_style_sheet !== null) { |
|
454 | - wp_register_style( |
|
455 | - 'espresso_custom_css', |
|
456 | - EVENT_ESPRESSO_UPLOAD_URL . 'css/' . $this->template_config->custom_style_sheet, |
|
457 | - array('espresso_default'), |
|
458 | - EVENT_ESPRESSO_VERSION |
|
459 | - ); |
|
460 | - } |
|
461 | - } |
|
462 | - } |
|
463 | - |
|
464 | - |
|
465 | - |
|
466 | - /** |
|
467 | - * registers core default javascript |
|
468 | - */ |
|
469 | - private function loadCoreJs() |
|
470 | - { |
|
471 | - // load core js |
|
472 | - wp_register_script( |
|
473 | - 'espresso_core', |
|
474 | - EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', |
|
475 | - array('jquery'), |
|
476 | - EVENT_ESPRESSO_VERSION, |
|
477 | - true |
|
478 | - ); |
|
479 | - } |
|
480 | - |
|
481 | - |
|
482 | - |
|
483 | - /** |
|
484 | - * registers jQuery Validate for form validation |
|
485 | - */ |
|
486 | - private function loadJqueryValidate() |
|
487 | - { |
|
488 | - // register jQuery Validate and additional methods |
|
489 | - wp_register_script( |
|
490 | - 'jquery-validate', |
|
491 | - EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.min.js', |
|
492 | - array('jquery'), |
|
493 | - '1.15.0', |
|
494 | - true |
|
495 | - ); |
|
496 | - wp_register_script( |
|
497 | - 'jquery-validate-extra-methods', |
|
498 | - EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.additional-methods.min.js', |
|
499 | - array('jquery', 'jquery-validate'), |
|
500 | - '1.15.0', |
|
501 | - true |
|
502 | - ); |
|
503 | - } |
|
504 | - |
|
505 | - |
|
506 | - |
|
507 | - /** |
|
508 | - * registers accounting.js for performing client-side calculations |
|
509 | - */ |
|
510 | - private function loadAccountingJs() |
|
511 | - { |
|
512 | - //accounting.js library |
|
513 | - // @link http://josscrowcroft.github.io/accounting.js/ |
|
514 | - wp_register_script( |
|
515 | - 'ee-accounting-core', |
|
516 | - EE_THIRD_PARTY_URL . 'accounting/accounting.js', |
|
517 | - array('underscore'), |
|
518 | - '0.3.2', |
|
519 | - true |
|
520 | - ); |
|
521 | - wp_register_script( |
|
522 | - 'ee-accounting', |
|
523 | - EE_GLOBAL_ASSETS_URL . 'scripts/ee-accounting-config.js', |
|
524 | - array('ee-accounting-core'), |
|
525 | - EVENT_ESPRESSO_VERSION, |
|
526 | - true |
|
527 | - ); |
|
528 | - } |
|
529 | - |
|
530 | - |
|
531 | - |
|
532 | - /** |
|
533 | - * registers accounting.js for performing client-side calculations |
|
534 | - */ |
|
535 | - private function localizeAccountingJs() |
|
536 | - { |
|
537 | - wp_localize_script( |
|
538 | - 'ee-accounting', |
|
539 | - 'EE_ACCOUNTING_CFG', |
|
540 | - array( |
|
541 | - 'currency' => array( |
|
542 | - 'symbol' => $this->currency_config->sign, |
|
543 | - 'format' => array( |
|
544 | - 'pos' => $this->currency_config->sign_b4 ? '%s%v' : '%v%s', |
|
545 | - 'neg' => $this->currency_config->sign_b4 ? '- %s%v' : '- %v%s', |
|
546 | - 'zero' => $this->currency_config->sign_b4 ? '%s--' : '--%s', |
|
547 | - ), |
|
548 | - 'decimal' => $this->currency_config->dec_mrk, |
|
549 | - 'thousand' => $this->currency_config->thsnds, |
|
550 | - 'precision' => $this->currency_config->dec_plc, |
|
551 | - ), |
|
552 | - 'number' => array( |
|
553 | - 'precision' => $this->currency_config->dec_plc, |
|
554 | - 'thousand' => $this->currency_config->thsnds, |
|
555 | - 'decimal' => $this->currency_config->dec_mrk, |
|
556 | - ), |
|
557 | - ) |
|
558 | - ); |
|
559 | - $this->addRegisteredScriptHandlesWithData('ee-accounting'); |
|
560 | - } |
|
561 | - |
|
562 | - |
|
563 | - |
|
564 | - /** |
|
565 | - * registers assets for cleaning your ears |
|
566 | - */ |
|
567 | - private function loadQtipJs() |
|
568 | - { |
|
569 | - // qtip is turned OFF by default, but prior to the wp_enqueue_scripts hook, |
|
570 | - // can be turned back on again via: add_filter('FHEE_load_qtip', '__return_true' ); |
|
571 | - if (apply_filters('FHEE_load_qtip', false)) { |
|
572 | - EEH_Qtip_Loader::instance()->register_and_enqueue(); |
|
573 | - } |
|
574 | - } |
|
575 | - |
|
576 | - |
|
577 | - /** |
|
578 | - * This is used to set registered script handles that have data. |
|
579 | - * @param string $script_handle |
|
580 | - */ |
|
581 | - private function addRegisteredScriptHandlesWithData($script_handle) |
|
582 | - { |
|
583 | - $this->script_handles_with_data[$script_handle] = $script_handle; |
|
584 | - } |
|
585 | - |
|
586 | - |
|
587 | - /** |
|
588 | - * Checks WP_Scripts for all of each script handle registered internally as having data and unsets from the |
|
589 | - * Dependency stored in WP_Scripts if its set. |
|
590 | - */ |
|
591 | - private function removeAlreadyRegisteredDataForScriptHandles() |
|
592 | - { |
|
593 | - if (empty($this->script_handles_with_data)) { |
|
594 | - return; |
|
595 | - } |
|
596 | - foreach ($this->script_handles_with_data as $script_handle) { |
|
597 | - $this->removeAlreadyRegisteredDataForScriptHandle($script_handle); |
|
598 | - } |
|
599 | - } |
|
600 | - |
|
601 | - |
|
602 | - /** |
|
603 | - * Removes any data dependency registered in WP_Scripts if its set. |
|
604 | - * @param string $script_handle |
|
605 | - */ |
|
606 | - private function removeAlreadyRegisteredDataForScriptHandle($script_handle) |
|
607 | - { |
|
608 | - if (isset($this->script_handles_with_data[$script_handle])) { |
|
609 | - global $wp_scripts; |
|
610 | - if ($wp_scripts->get_data($script_handle, 'data')) { |
|
611 | - unset($wp_scripts->registered[$script_handle]->extra['data']); |
|
612 | - unset($this->script_handles_with_data[$script_handle]); |
|
613 | - } |
|
614 | - } |
|
615 | - } |
|
616 | - |
|
617 | - |
|
618 | - /** |
|
619 | - * Registers assets that are used in the WordPress admin. |
|
620 | - */ |
|
621 | - private function registerAdminAssets() |
|
622 | - { |
|
623 | - wp_register_script( |
|
624 | - 'ee-wp-plugins-page', |
|
625 | - $this->getAssetUrl(self::ASSET_NAMESPACE, 'wp-plugins-page', self::ASSET_TYPE_JS), |
|
626 | - array( |
|
627 | - 'jquery', |
|
628 | - 'ee-vendor-react' |
|
629 | - ), |
|
630 | - null, |
|
631 | - true |
|
632 | - ); |
|
633 | - wp_register_style( |
|
634 | - 'ee-wp-plugins-page', |
|
635 | - $this->getAssetUrl(self::ASSET_NAMESPACE, 'wp-plugins-page', self::ASSET_TYPE_CSS), |
|
636 | - array(), |
|
637 | - null |
|
638 | - ); |
|
639 | - } |
|
426 | + 'event_espresso' |
|
427 | + ), |
|
428 | + $key |
|
429 | + ) |
|
430 | + ); |
|
431 | + } |
|
432 | + return true; |
|
433 | + } |
|
434 | + |
|
435 | + |
|
436 | + |
|
437 | + /** |
|
438 | + * registers core default stylesheets |
|
439 | + */ |
|
440 | + private function loadCoreCss() |
|
441 | + { |
|
442 | + if ($this->template_config->enable_default_style) { |
|
443 | + $default_stylesheet_path = is_readable(EVENT_ESPRESSO_UPLOAD_DIR . 'css/style.css') |
|
444 | + ? EVENT_ESPRESSO_UPLOAD_DIR . 'css/espresso_default.css' |
|
445 | + : EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css'; |
|
446 | + wp_register_style( |
|
447 | + 'espresso_default', |
|
448 | + $default_stylesheet_path, |
|
449 | + array('dashicons'), |
|
450 | + EVENT_ESPRESSO_VERSION |
|
451 | + ); |
|
452 | + //Load custom style sheet if available |
|
453 | + if ($this->template_config->custom_style_sheet !== null) { |
|
454 | + wp_register_style( |
|
455 | + 'espresso_custom_css', |
|
456 | + EVENT_ESPRESSO_UPLOAD_URL . 'css/' . $this->template_config->custom_style_sheet, |
|
457 | + array('espresso_default'), |
|
458 | + EVENT_ESPRESSO_VERSION |
|
459 | + ); |
|
460 | + } |
|
461 | + } |
|
462 | + } |
|
463 | + |
|
464 | + |
|
465 | + |
|
466 | + /** |
|
467 | + * registers core default javascript |
|
468 | + */ |
|
469 | + private function loadCoreJs() |
|
470 | + { |
|
471 | + // load core js |
|
472 | + wp_register_script( |
|
473 | + 'espresso_core', |
|
474 | + EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', |
|
475 | + array('jquery'), |
|
476 | + EVENT_ESPRESSO_VERSION, |
|
477 | + true |
|
478 | + ); |
|
479 | + } |
|
480 | + |
|
481 | + |
|
482 | + |
|
483 | + /** |
|
484 | + * registers jQuery Validate for form validation |
|
485 | + */ |
|
486 | + private function loadJqueryValidate() |
|
487 | + { |
|
488 | + // register jQuery Validate and additional methods |
|
489 | + wp_register_script( |
|
490 | + 'jquery-validate', |
|
491 | + EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.min.js', |
|
492 | + array('jquery'), |
|
493 | + '1.15.0', |
|
494 | + true |
|
495 | + ); |
|
496 | + wp_register_script( |
|
497 | + 'jquery-validate-extra-methods', |
|
498 | + EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.additional-methods.min.js', |
|
499 | + array('jquery', 'jquery-validate'), |
|
500 | + '1.15.0', |
|
501 | + true |
|
502 | + ); |
|
503 | + } |
|
504 | + |
|
505 | + |
|
506 | + |
|
507 | + /** |
|
508 | + * registers accounting.js for performing client-side calculations |
|
509 | + */ |
|
510 | + private function loadAccountingJs() |
|
511 | + { |
|
512 | + //accounting.js library |
|
513 | + // @link http://josscrowcroft.github.io/accounting.js/ |
|
514 | + wp_register_script( |
|
515 | + 'ee-accounting-core', |
|
516 | + EE_THIRD_PARTY_URL . 'accounting/accounting.js', |
|
517 | + array('underscore'), |
|
518 | + '0.3.2', |
|
519 | + true |
|
520 | + ); |
|
521 | + wp_register_script( |
|
522 | + 'ee-accounting', |
|
523 | + EE_GLOBAL_ASSETS_URL . 'scripts/ee-accounting-config.js', |
|
524 | + array('ee-accounting-core'), |
|
525 | + EVENT_ESPRESSO_VERSION, |
|
526 | + true |
|
527 | + ); |
|
528 | + } |
|
529 | + |
|
530 | + |
|
531 | + |
|
532 | + /** |
|
533 | + * registers accounting.js for performing client-side calculations |
|
534 | + */ |
|
535 | + private function localizeAccountingJs() |
|
536 | + { |
|
537 | + wp_localize_script( |
|
538 | + 'ee-accounting', |
|
539 | + 'EE_ACCOUNTING_CFG', |
|
540 | + array( |
|
541 | + 'currency' => array( |
|
542 | + 'symbol' => $this->currency_config->sign, |
|
543 | + 'format' => array( |
|
544 | + 'pos' => $this->currency_config->sign_b4 ? '%s%v' : '%v%s', |
|
545 | + 'neg' => $this->currency_config->sign_b4 ? '- %s%v' : '- %v%s', |
|
546 | + 'zero' => $this->currency_config->sign_b4 ? '%s--' : '--%s', |
|
547 | + ), |
|
548 | + 'decimal' => $this->currency_config->dec_mrk, |
|
549 | + 'thousand' => $this->currency_config->thsnds, |
|
550 | + 'precision' => $this->currency_config->dec_plc, |
|
551 | + ), |
|
552 | + 'number' => array( |
|
553 | + 'precision' => $this->currency_config->dec_plc, |
|
554 | + 'thousand' => $this->currency_config->thsnds, |
|
555 | + 'decimal' => $this->currency_config->dec_mrk, |
|
556 | + ), |
|
557 | + ) |
|
558 | + ); |
|
559 | + $this->addRegisteredScriptHandlesWithData('ee-accounting'); |
|
560 | + } |
|
561 | + |
|
562 | + |
|
563 | + |
|
564 | + /** |
|
565 | + * registers assets for cleaning your ears |
|
566 | + */ |
|
567 | + private function loadQtipJs() |
|
568 | + { |
|
569 | + // qtip is turned OFF by default, but prior to the wp_enqueue_scripts hook, |
|
570 | + // can be turned back on again via: add_filter('FHEE_load_qtip', '__return_true' ); |
|
571 | + if (apply_filters('FHEE_load_qtip', false)) { |
|
572 | + EEH_Qtip_Loader::instance()->register_and_enqueue(); |
|
573 | + } |
|
574 | + } |
|
575 | + |
|
576 | + |
|
577 | + /** |
|
578 | + * This is used to set registered script handles that have data. |
|
579 | + * @param string $script_handle |
|
580 | + */ |
|
581 | + private function addRegisteredScriptHandlesWithData($script_handle) |
|
582 | + { |
|
583 | + $this->script_handles_with_data[$script_handle] = $script_handle; |
|
584 | + } |
|
585 | + |
|
586 | + |
|
587 | + /** |
|
588 | + * Checks WP_Scripts for all of each script handle registered internally as having data and unsets from the |
|
589 | + * Dependency stored in WP_Scripts if its set. |
|
590 | + */ |
|
591 | + private function removeAlreadyRegisteredDataForScriptHandles() |
|
592 | + { |
|
593 | + if (empty($this->script_handles_with_data)) { |
|
594 | + return; |
|
595 | + } |
|
596 | + foreach ($this->script_handles_with_data as $script_handle) { |
|
597 | + $this->removeAlreadyRegisteredDataForScriptHandle($script_handle); |
|
598 | + } |
|
599 | + } |
|
600 | + |
|
601 | + |
|
602 | + /** |
|
603 | + * Removes any data dependency registered in WP_Scripts if its set. |
|
604 | + * @param string $script_handle |
|
605 | + */ |
|
606 | + private function removeAlreadyRegisteredDataForScriptHandle($script_handle) |
|
607 | + { |
|
608 | + if (isset($this->script_handles_with_data[$script_handle])) { |
|
609 | + global $wp_scripts; |
|
610 | + if ($wp_scripts->get_data($script_handle, 'data')) { |
|
611 | + unset($wp_scripts->registered[$script_handle]->extra['data']); |
|
612 | + unset($this->script_handles_with_data[$script_handle]); |
|
613 | + } |
|
614 | + } |
|
615 | + } |
|
616 | + |
|
617 | + |
|
618 | + /** |
|
619 | + * Registers assets that are used in the WordPress admin. |
|
620 | + */ |
|
621 | + private function registerAdminAssets() |
|
622 | + { |
|
623 | + wp_register_script( |
|
624 | + 'ee-wp-plugins-page', |
|
625 | + $this->getAssetUrl(self::ASSET_NAMESPACE, 'wp-plugins-page', self::ASSET_TYPE_JS), |
|
626 | + array( |
|
627 | + 'jquery', |
|
628 | + 'ee-vendor-react' |
|
629 | + ), |
|
630 | + null, |
|
631 | + true |
|
632 | + ); |
|
633 | + wp_register_style( |
|
634 | + 'ee-wp-plugins-page', |
|
635 | + $this->getAssetUrl(self::ASSET_NAMESPACE, 'wp-plugins-page', self::ASSET_TYPE_CSS), |
|
636 | + array(), |
|
637 | + null |
|
638 | + ); |
|
639 | + } |
|
640 | 640 | } |
@@ -19,94 +19,94 @@ |
||
19 | 19 | class ExitModal |
20 | 20 | { |
21 | 21 | |
22 | - /** |
|
23 | - * @var Registry |
|
24 | - */ |
|
25 | - private $assets_registry; |
|
22 | + /** |
|
23 | + * @var Registry |
|
24 | + */ |
|
25 | + private $assets_registry; |
|
26 | 26 | |
27 | - /** |
|
28 | - * ExitModal constructor. |
|
29 | - * |
|
30 | - * @param Registry $assets_registry |
|
31 | - */ |
|
32 | - public function __construct(Registry $assets_registry) |
|
33 | - { |
|
34 | - $this->assets_registry = $assets_registry; |
|
35 | - add_action('in_admin_footer', array($this, 'modalContainer')); |
|
36 | - add_action('admin_enqueue_scripts', array($this, 'enqueues')); |
|
37 | - } |
|
27 | + /** |
|
28 | + * ExitModal constructor. |
|
29 | + * |
|
30 | + * @param Registry $assets_registry |
|
31 | + */ |
|
32 | + public function __construct(Registry $assets_registry) |
|
33 | + { |
|
34 | + $this->assets_registry = $assets_registry; |
|
35 | + add_action('in_admin_footer', array($this, 'modalContainer')); |
|
36 | + add_action('admin_enqueue_scripts', array($this, 'enqueues')); |
|
37 | + } |
|
38 | 38 | |
39 | 39 | |
40 | - /** |
|
41 | - * Callback on in_admin_footer that is used to output the exit modal container. |
|
42 | - */ |
|
43 | - public function modalContainer() |
|
44 | - { |
|
45 | - echo '<div id="ee-exit-survey-modal"></div>'; |
|
46 | - } |
|
40 | + /** |
|
41 | + * Callback on in_admin_footer that is used to output the exit modal container. |
|
42 | + */ |
|
43 | + public function modalContainer() |
|
44 | + { |
|
45 | + echo '<div id="ee-exit-survey-modal"></div>'; |
|
46 | + } |
|
47 | 47 | |
48 | 48 | |
49 | - /** |
|
50 | - * Callback for `admin_enqueue_scripts` to take care of enqueueing scripts and styles specific to the modal. |
|
51 | - * |
|
52 | - * @throws InvalidArgumentException |
|
53 | - */ |
|
54 | - public function enqueues() |
|
55 | - { |
|
56 | - $current_user = new WP_User(get_current_user_id()); |
|
57 | - $this->assets_registry->addData( |
|
58 | - 'exitModali18n', |
|
59 | - array( |
|
60 | - 'introText' => htmlspecialchars( |
|
61 | - __( |
|
62 | - 'Do you have a moment to share why you are deactivating Event Espresso?', |
|
63 | - 'event_espresso' |
|
64 | - ), |
|
65 | - ENT_NOQUOTES |
|
66 | - ), |
|
67 | - 'doSurveyButtonText' => htmlspecialchars( |
|
68 | - __( |
|
69 | - 'Sure I\'ll help', |
|
70 | - 'event_espresso' |
|
71 | - ), |
|
72 | - ENT_NOQUOTES |
|
73 | - ), |
|
74 | - 'skipButtonText' => htmlspecialchars( |
|
75 | - __( |
|
76 | - 'Skip', |
|
77 | - 'event_espresso' |
|
78 | - ), |
|
79 | - ENT_NOQUOTES |
|
80 | - ) |
|
81 | - ) |
|
82 | - ); |
|
83 | - $this->assets_registry->addData( |
|
84 | - 'exitModalInfo', |
|
85 | - array( |
|
86 | - 'firstname' => htmlspecialchars($current_user->user_firstname), |
|
87 | - 'emailaddress' => htmlspecialchars($current_user->user_email), |
|
88 | - 'website' => htmlspecialchars(site_url()), |
|
89 | - 'isModalActive' => $this->isModalActive() |
|
90 | - ) |
|
91 | - ); |
|
49 | + /** |
|
50 | + * Callback for `admin_enqueue_scripts` to take care of enqueueing scripts and styles specific to the modal. |
|
51 | + * |
|
52 | + * @throws InvalidArgumentException |
|
53 | + */ |
|
54 | + public function enqueues() |
|
55 | + { |
|
56 | + $current_user = new WP_User(get_current_user_id()); |
|
57 | + $this->assets_registry->addData( |
|
58 | + 'exitModali18n', |
|
59 | + array( |
|
60 | + 'introText' => htmlspecialchars( |
|
61 | + __( |
|
62 | + 'Do you have a moment to share why you are deactivating Event Espresso?', |
|
63 | + 'event_espresso' |
|
64 | + ), |
|
65 | + ENT_NOQUOTES |
|
66 | + ), |
|
67 | + 'doSurveyButtonText' => htmlspecialchars( |
|
68 | + __( |
|
69 | + 'Sure I\'ll help', |
|
70 | + 'event_espresso' |
|
71 | + ), |
|
72 | + ENT_NOQUOTES |
|
73 | + ), |
|
74 | + 'skipButtonText' => htmlspecialchars( |
|
75 | + __( |
|
76 | + 'Skip', |
|
77 | + 'event_espresso' |
|
78 | + ), |
|
79 | + ENT_NOQUOTES |
|
80 | + ) |
|
81 | + ) |
|
82 | + ); |
|
83 | + $this->assets_registry->addData( |
|
84 | + 'exitModalInfo', |
|
85 | + array( |
|
86 | + 'firstname' => htmlspecialchars($current_user->user_firstname), |
|
87 | + 'emailaddress' => htmlspecialchars($current_user->user_email), |
|
88 | + 'website' => htmlspecialchars(site_url()), |
|
89 | + 'isModalActive' => $this->isModalActive() |
|
90 | + ) |
|
91 | + ); |
|
92 | 92 | |
93 | - wp_enqueue_script('ee-wp-plugins-page'); |
|
94 | - wp_enqueue_style('ee-wp-plugins-page'); |
|
95 | - } |
|
93 | + wp_enqueue_script('ee-wp-plugins-page'); |
|
94 | + wp_enqueue_style('ee-wp-plugins-page'); |
|
95 | + } |
|
96 | 96 | |
97 | 97 | |
98 | - /** |
|
99 | - * Exposes a filter switch for turning off the enqueueing of the modal script. |
|
100 | - * @return bool |
|
101 | - */ |
|
102 | - private function isModalActive() |
|
103 | - { |
|
104 | - return filter_var( |
|
105 | - apply_filters( |
|
106 | - 'FHEE__EventEspresso_core_domain_services_admin_ExitModal__isModalActive', |
|
107 | - true |
|
108 | - ), |
|
109 | - FILTER_VALIDATE_BOOLEAN |
|
110 | - ); |
|
111 | - } |
|
98 | + /** |
|
99 | + * Exposes a filter switch for turning off the enqueueing of the modal script. |
|
100 | + * @return bool |
|
101 | + */ |
|
102 | + private function isModalActive() |
|
103 | + { |
|
104 | + return filter_var( |
|
105 | + apply_filters( |
|
106 | + 'FHEE__EventEspresso_core_domain_services_admin_ExitModal__isModalActive', |
|
107 | + true |
|
108 | + ), |
|
109 | + FILTER_VALIDATE_BOOLEAN |
|
110 | + ); |
|
111 | + } |
|
112 | 112 | } |
113 | 113 | \ No newline at end of file |
@@ -473,7 +473,7 @@ |
||
473 | 473 | * |
474 | 474 | * @param EE_Ticket $ticket |
475 | 475 | * @param int $qty |
476 | - * @return TRUE on success, FALSE on fail |
|
476 | + * @return boolean on success, FALSE on fail |
|
477 | 477 | * @throws InvalidArgumentException |
478 | 478 | * @throws InvalidInterfaceException |
479 | 479 | * @throws InvalidDataTypeException |
@@ -34,526 +34,526 @@ |
||
34 | 34 | class ProcessTicketSelector |
35 | 35 | { |
36 | 36 | |
37 | - /** |
|
38 | - * @var EE_Cart $cart |
|
39 | - */ |
|
40 | - private $cart; |
|
41 | - |
|
42 | - /** |
|
43 | - * @var EE_Core_Config $core_config |
|
44 | - */ |
|
45 | - private $core_config; |
|
46 | - |
|
47 | - /** |
|
48 | - * @var Request $request |
|
49 | - */ |
|
50 | - private $request; |
|
51 | - |
|
52 | - /** |
|
53 | - * @var EE_Session $session |
|
54 | - */ |
|
55 | - private $session; |
|
56 | - |
|
57 | - /** |
|
58 | - * @var EEM_Ticket $ticket_model |
|
59 | - */ |
|
60 | - private $ticket_model; |
|
61 | - |
|
62 | - /** |
|
63 | - * @var TicketDatetimeAvailabilityTracker $tracker |
|
64 | - */ |
|
65 | - private $tracker; |
|
66 | - |
|
67 | - |
|
68 | - /** |
|
69 | - * ProcessTicketSelector constructor. |
|
70 | - * NOTE: PLZ use the Loader to instantiate this class if need be |
|
71 | - * so that all dependencies get injected correctly (which will happen automatically) |
|
72 | - * Null values for parameters are only for backwards compatibility but will be removed later on. |
|
73 | - * |
|
74 | - * @param EE_Core_Config $core_config |
|
75 | - * @param Request $request |
|
76 | - * @param EE_Session $session |
|
77 | - * @param EEM_Ticket $ticket_model |
|
78 | - * @param TicketDatetimeAvailabilityTracker $tracker |
|
79 | - * @throws InvalidArgumentException |
|
80 | - * @throws InvalidDataTypeException |
|
81 | - * @throws InvalidInterfaceException |
|
82 | - */ |
|
83 | - public function __construct( |
|
84 | - EE_Core_Config $core_config = null, |
|
85 | - Request $request = null, |
|
86 | - EE_Session $session = null, |
|
87 | - EEM_Ticket $ticket_model = null, |
|
88 | - TicketDatetimeAvailabilityTracker $tracker = null |
|
89 | - ) { |
|
90 | - /** @var LoaderInterface $loader */ |
|
91 | - $loader = LoaderFactory::getLoader(); |
|
92 | - $this->core_config = $core_config instanceof EE_Core_Config |
|
93 | - ? $core_config |
|
94 | - : $loader->getShared('EE_Core_Config'); |
|
95 | - $this->request = $request instanceof Request |
|
96 | - ? $request |
|
97 | - : $loader->getShared('EventEspresso\core\services\request\Request'); |
|
98 | - $this->session = $session instanceof EE_Session |
|
99 | - ? $session |
|
100 | - : $loader->getShared('EE_Session'); |
|
101 | - $this->ticket_model = $ticket_model instanceof EEM_Ticket |
|
102 | - ? $ticket_model |
|
103 | - : $loader->getShared('EEM_Ticket'); |
|
104 | - $this->tracker = $tracker instanceof TicketDatetimeAvailabilityTracker |
|
105 | - ? $tracker |
|
106 | - : $loader->getShared('EventEspresso\modules\ticket_selector\TicketDatetimeAvailabilityTracker'); |
|
107 | - } |
|
108 | - |
|
109 | - |
|
110 | - /** |
|
111 | - * cancelTicketSelections |
|
112 | - * |
|
113 | - * @return bool |
|
114 | - * @throws EE_Error |
|
115 | - * @throws InvalidArgumentException |
|
116 | - * @throws InvalidInterfaceException |
|
117 | - * @throws InvalidDataTypeException |
|
118 | - */ |
|
119 | - public function cancelTicketSelections() |
|
120 | - { |
|
121 | - // check nonce |
|
122 | - if (! $this->processTicketSelectorNonce('cancel_ticket_selections')) { |
|
123 | - return false; |
|
124 | - } |
|
125 | - $this->session->clear_session(__CLASS__, __FUNCTION__); |
|
126 | - if ($this->request->requestParamIsSet('event_id')) { |
|
127 | - EEH_URL::safeRedirectAndExit( |
|
128 | - EEH_Event_View::event_link_url( |
|
129 | - $this->request->getRequestParam('event_id') |
|
130 | - ) |
|
131 | - ); |
|
132 | - } |
|
133 | - EEH_URL::safeRedirectAndExit( |
|
134 | - site_url('/' . $this->core_config->event_cpt_slug . '/') |
|
135 | - ); |
|
136 | - return true; |
|
137 | - } |
|
138 | - |
|
139 | - |
|
140 | - /** |
|
141 | - * processTicketSelectorNonce |
|
142 | - * |
|
143 | - * @param string $nonce_name |
|
144 | - * @param string $id |
|
145 | - * @return bool |
|
146 | - */ |
|
147 | - private function processTicketSelectorNonce($nonce_name, $id = '') |
|
148 | - { |
|
149 | - $nonce_name_with_id = ! empty($id) ? "{$nonce_name}_nonce_{$id}" : "{$nonce_name}_nonce"; |
|
150 | - if ( |
|
151 | - ! $this->request->isAdmin() |
|
152 | - && ( |
|
153 | - ! $this->request->is_set($nonce_name_with_id) |
|
154 | - || ! wp_verify_nonce( |
|
155 | - $this->request->get($nonce_name_with_id), |
|
156 | - $nonce_name |
|
157 | - ) |
|
158 | - ) |
|
159 | - ) { |
|
160 | - EE_Error::add_error( |
|
161 | - sprintf( |
|
162 | - esc_html__( |
|
163 | - 'We\'re sorry but your request failed to pass a security check.%sPlease click the back button on your browser and try again.', |
|
164 | - 'event_espresso' |
|
165 | - ), |
|
166 | - '<br/>' |
|
167 | - ), |
|
168 | - __FILE__, |
|
169 | - __FUNCTION__, |
|
170 | - __LINE__ |
|
171 | - ); |
|
172 | - return false; |
|
173 | - } |
|
174 | - return true; |
|
175 | - } |
|
176 | - |
|
177 | - |
|
178 | - /** |
|
179 | - * process_ticket_selections |
|
180 | - * |
|
181 | - * @return array|bool |
|
182 | - * @throws EE_Error |
|
183 | - * @throws InvalidArgumentException |
|
184 | - * @throws InvalidDataTypeException |
|
185 | - * @throws InvalidInterfaceException |
|
186 | - */ |
|
187 | - public function processTicketSelections() |
|
188 | - { |
|
189 | - do_action('EED_Ticket_Selector__process_ticket_selections__before'); |
|
190 | - if($this->request->isBot()) { |
|
191 | - EEH_URL::safeRedirectAndExit( |
|
192 | - apply_filters( |
|
193 | - 'FHEE__EE_Ticket_Selector__process_ticket_selections__bot_redirect_url', |
|
194 | - site_url() |
|
195 | - ) |
|
196 | - ); |
|
197 | - } |
|
198 | - // do we have an event id? |
|
199 | - $id = $this->getEventId(); |
|
200 | - // we should really only have 1 registration in the works now |
|
201 | - // (ie, no MER) so unless otherwise requested, clear the session |
|
202 | - if (apply_filters('FHEE__EE_Ticket_Selector__process_ticket_selections__clear_session', true)) { |
|
203 | - $this->session->clear_session(__CLASS__, __FUNCTION__); |
|
204 | - } |
|
205 | - // validate/sanitize/filter data |
|
206 | - $valid = apply_filters( |
|
207 | - 'FHEE__EED_Ticket_Selector__process_ticket_selections__valid_post_data', |
|
208 | - $this->validatePostData($id) |
|
209 | - ); |
|
210 | - //check total tickets ordered vs max number of attendees that can register |
|
211 | - if ($valid['total_tickets'] > $valid['max_atndz']) { |
|
212 | - $this->maxAttendeesViolation($valid); |
|
213 | - } else { |
|
214 | - // all data appears to be valid |
|
215 | - if ($this->processSuccessfulCart($this->addTicketsToCart($valid))) { |
|
216 | - return true; |
|
217 | - } |
|
218 | - } |
|
219 | - // die(); // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< KILL BEFORE REDIRECT |
|
220 | - // at this point, just return if registration is being made from admin |
|
221 | - if ($this->request->isAdmin() || $this->request->isFrontAjax()) { |
|
222 | - return false; |
|
223 | - } |
|
224 | - if ($valid['return_url']) { |
|
225 | - EEH_URL::safeRedirectAndExit($valid['return_url']); |
|
226 | - } |
|
227 | - if ($id) { |
|
228 | - EEH_URL::safeRedirectAndExit(get_permalink($id)); |
|
229 | - } |
|
230 | - echo EE_Error::get_notices(); |
|
231 | - return false; |
|
232 | - } |
|
233 | - |
|
234 | - |
|
235 | - /** |
|
236 | - * @return int |
|
237 | - */ |
|
238 | - private function getEventId() |
|
239 | - { |
|
240 | - // do we have an event id? |
|
241 | - if (! $this->request->requestParamIsSet('tkt-slctr-event-id')) { |
|
242 | - // $_POST['tkt-slctr-event-id'] was not set ?!?!?!? |
|
243 | - EE_Error::add_error( |
|
244 | - sprintf( |
|
245 | - esc_html__( |
|
246 | - 'An event id was not provided or was not received.%sPlease click the back button on your browser and try again.', |
|
247 | - 'event_espresso' |
|
248 | - ), |
|
249 | - '<br/>' |
|
250 | - ), |
|
251 | - __FILE__, |
|
252 | - __FUNCTION__, |
|
253 | - __LINE__ |
|
254 | - ); |
|
255 | - } |
|
256 | - //if event id is valid |
|
257 | - return absint($this->request->getRequestParam('tkt-slctr-event-id')); |
|
258 | - } |
|
259 | - |
|
260 | - |
|
261 | - /** |
|
262 | - * validate_post_data |
|
263 | - * |
|
264 | - * @param int $id |
|
265 | - * @return array|FALSE |
|
266 | - */ |
|
267 | - private function validatePostData($id = 0) |
|
268 | - { |
|
269 | - if (! $id) { |
|
270 | - EE_Error::add_error( |
|
271 | - esc_html__('The event id provided was not valid.', 'event_espresso'), |
|
272 | - __FILE__, |
|
273 | - __FUNCTION__, |
|
274 | - __LINE__ |
|
275 | - ); |
|
276 | - return false; |
|
277 | - } |
|
278 | - // start with an empty array() |
|
279 | - $valid_data = array(); |
|
280 | - // grab valid id |
|
281 | - $valid_data['id'] = $id; |
|
282 | - // array of other form names |
|
283 | - $inputs_to_clean = array( |
|
284 | - 'event_id' => 'tkt-slctr-event-id', |
|
285 | - 'max_atndz' => 'tkt-slctr-max-atndz-', |
|
286 | - 'rows' => 'tkt-slctr-rows-', |
|
287 | - 'qty' => 'tkt-slctr-qty-', |
|
288 | - 'ticket_id' => 'tkt-slctr-ticket-id-', |
|
289 | - 'return_url' => 'tkt-slctr-return-url-', |
|
290 | - ); |
|
291 | - // let's track the total number of tickets ordered.' |
|
292 | - $valid_data['total_tickets'] = 0; |
|
293 | - // cycle through $inputs_to_clean array |
|
294 | - foreach ($inputs_to_clean as $what => $input_to_clean) { |
|
295 | - // check for POST data |
|
296 | - if ($this->request->requestParamIsSet($input_to_clean . $id)) { |
|
297 | - // grab value |
|
298 | - $input_value = $this->request->getRequestParam($input_to_clean . $id); |
|
299 | - switch ($what) { |
|
300 | - // integers |
|
301 | - case 'event_id': |
|
302 | - $valid_data[ $what ] = absint($input_value); |
|
303 | - // get event via the event id we put in the form |
|
304 | - break; |
|
305 | - case 'rows': |
|
306 | - case 'max_atndz': |
|
307 | - $valid_data[ $what ] = absint($input_value); |
|
308 | - break; |
|
309 | - // arrays of integers |
|
310 | - case 'qty': |
|
311 | - /** @var array $row_qty */ |
|
312 | - $row_qty = $input_value; |
|
313 | - // if qty is coming from a radio button input, then we need to assemble an array of rows |
|
314 | - if (! is_array($row_qty)) { |
|
315 | - /** @var string $row_qty */ |
|
316 | - // get number of rows |
|
317 | - $rows = $this->request->requestParamIsSet('tkt-slctr-rows-' . $id) |
|
318 | - ? absint($this->request->getRequestParam('tkt-slctr-rows-' . $id)) |
|
319 | - : 1; |
|
320 | - // explode integers by the dash |
|
321 | - $row_qty = explode('-', $row_qty); |
|
322 | - $row = isset($row_qty[0]) ? absint($row_qty[0]) : 1; |
|
323 | - $qty = isset($row_qty[1]) ? absint($row_qty[1]) : 0; |
|
324 | - $row_qty = array($row => $qty); |
|
325 | - for ($x = 1; $x <= $rows; $x++) { |
|
326 | - if (! isset($row_qty[ $x ])) { |
|
327 | - $row_qty[ $x ] = 0; |
|
328 | - } |
|
329 | - } |
|
330 | - } |
|
331 | - ksort($row_qty); |
|
332 | - // cycle thru values |
|
333 | - foreach ($row_qty as $qty) { |
|
334 | - $qty = absint($qty); |
|
335 | - // sanitize as integers |
|
336 | - $valid_data[ $what ][] = $qty; |
|
337 | - $valid_data['total_tickets'] += $qty; |
|
338 | - } |
|
339 | - break; |
|
340 | - // array of integers |
|
341 | - case 'ticket_id': |
|
342 | - // cycle thru values |
|
343 | - foreach ((array) $input_value as $key => $value) { |
|
344 | - // allow only integers |
|
345 | - $valid_data[ $what ][ $key ] = absint($value); |
|
346 | - } |
|
347 | - break; |
|
348 | - case 'return_url' : |
|
349 | - // grab and sanitize return-url |
|
350 | - $input_value = esc_url_raw($input_value); |
|
351 | - // was the request coming from an iframe ? if so, then: |
|
352 | - if (strpos($input_value, 'event_list=iframe')) { |
|
353 | - // get anchor fragment |
|
354 | - $input_value = explode('#', $input_value); |
|
355 | - $input_value = end($input_value); |
|
356 | - // use event list url instead, but append anchor |
|
357 | - $input_value = EEH_Event_View::event_archive_url() . '#' . $input_value; |
|
358 | - } |
|
359 | - $valid_data[ $what ] = $input_value; |
|
360 | - break; |
|
361 | - } // end switch $what |
|
362 | - } |
|
363 | - } // end foreach $inputs_to_clean |
|
364 | - return $valid_data; |
|
365 | - } |
|
366 | - |
|
367 | - |
|
368 | - /** |
|
369 | - * @param array $valid |
|
370 | - */ |
|
371 | - private function maxAttendeesViolation(array $valid) |
|
372 | - { |
|
373 | - // ordering too many tickets !!! |
|
374 | - $total_tickets_string = esc_html( |
|
375 | - _n( |
|
376 | - 'You have attempted to purchase %s ticket.', |
|
377 | - 'You have attempted to purchase %s tickets.', |
|
378 | - $valid['total_tickets'], |
|
379 | - 'event_espresso' |
|
380 | - ) |
|
381 | - ); |
|
382 | - $limit_error_1 = sprintf($total_tickets_string, $valid['total_tickets']); |
|
383 | - // dev only message |
|
384 | - $max_attendees_string = esc_html( |
|
385 | - _n( |
|
386 | - 'The registration limit for this event is %s ticket per registration, therefore the total number of tickets you may purchase at a time can not exceed %s.', |
|
387 | - 'The registration limit for this event is %s tickets per registration, therefore the total number of tickets you may purchase at a time can not exceed %s.', |
|
388 | - $valid['max_atndz'], |
|
389 | - 'event_espresso' |
|
390 | - ) |
|
391 | - ); |
|
392 | - $limit_error_2 = sprintf($max_attendees_string, $valid['max_atndz'], $valid['max_atndz']); |
|
393 | - EE_Error::add_error($limit_error_1 . '<br/>' . $limit_error_2, __FILE__, __FUNCTION__, __LINE__); |
|
394 | - } |
|
395 | - |
|
396 | - |
|
397 | - /** |
|
398 | - * @param array $valid |
|
399 | - * @return int|TRUE |
|
400 | - * @throws EE_Error |
|
401 | - * @throws InvalidArgumentException |
|
402 | - * @throws InvalidDataTypeException |
|
403 | - * @throws InvalidInterfaceException |
|
404 | - */ |
|
405 | - private function addTicketsToCart(array $valid) |
|
406 | - { |
|
407 | - $tickets_added = 0; |
|
408 | - $tickets_selected = false; |
|
409 | - if($valid['total_tickets'] > 0){ |
|
410 | - // load cart using factory because we don't want to do so until actually needed |
|
411 | - $this->cart = CartFactory::getCart(); |
|
412 | - // cycle thru the number of data rows sent from the event listing |
|
413 | - for ($x = 0; $x < $valid['rows']; $x++) { |
|
414 | - // does this row actually contain a ticket quantity? |
|
415 | - if (isset($valid['qty'][ $x ]) && $valid['qty'][ $x ] > 0) { |
|
416 | - // YES we have a ticket quantity |
|
417 | - $tickets_selected = true; |
|
418 | - $valid_ticket = false; |
|
419 | - // \EEH_Debug_Tools::printr( |
|
420 | - // $valid['ticket_id'][ $x ], |
|
421 | - // '$valid[\'ticket_id\'][ $x ]', |
|
422 | - // __FILE__, __LINE__ |
|
423 | - // ); |
|
424 | - if (isset($valid['ticket_id'][ $x ])) { |
|
425 | - // get ticket via the ticket id we put in the form |
|
426 | - $ticket = $this->ticket_model->get_one_by_ID($valid['ticket_id'][ $x ]); |
|
427 | - if ($ticket instanceof EE_Ticket) { |
|
428 | - $valid_ticket = true; |
|
429 | - $tickets_added += $this->addTicketToCart( |
|
430 | - $ticket, |
|
431 | - $valid['qty'][ $x ] |
|
432 | - ); |
|
433 | - } |
|
434 | - } |
|
435 | - if ($valid_ticket !== true) { |
|
436 | - // nothing added to cart retrieved |
|
437 | - EE_Error::add_error( |
|
438 | - sprintf( |
|
439 | - esc_html__( |
|
440 | - 'A valid ticket could not be retrieved for the event.%sPlease click the back button on your browser and try again.', |
|
441 | - 'event_espresso' |
|
442 | - ), |
|
443 | - '<br/>' |
|
444 | - ), |
|
445 | - __FILE__, __FUNCTION__, __LINE__ |
|
446 | - ); |
|
447 | - } |
|
448 | - if (EE_Error::has_error()) { |
|
449 | - break; |
|
450 | - } |
|
451 | - } |
|
452 | - } |
|
453 | - } |
|
454 | - do_action( |
|
455 | - 'AHEE__EE_Ticket_Selector__process_ticket_selections__after_tickets_added_to_cart', |
|
456 | - $this->cart, |
|
457 | - $this |
|
458 | - ); |
|
459 | - if (! apply_filters('FHEE__EED_Ticket_Selector__process_ticket_selections__tckts_slctd', $tickets_selected)) { |
|
460 | - // no ticket quantities were selected |
|
461 | - EE_Error::add_error( |
|
462 | - esc_html__('You need to select a ticket quantity before you can proceed.', 'event_espresso'), |
|
463 | - __FILE__, __FUNCTION__, __LINE__ |
|
464 | - ); |
|
465 | - } |
|
466 | - return $tickets_added; |
|
467 | - } |
|
468 | - |
|
469 | - |
|
470 | - |
|
471 | - /** |
|
472 | - * adds a ticket to the cart |
|
473 | - * |
|
474 | - * @param EE_Ticket $ticket |
|
475 | - * @param int $qty |
|
476 | - * @return TRUE on success, FALSE on fail |
|
477 | - * @throws InvalidArgumentException |
|
478 | - * @throws InvalidInterfaceException |
|
479 | - * @throws InvalidDataTypeException |
|
480 | - * @throws EE_Error |
|
481 | - */ |
|
482 | - private function addTicketToCart(EE_Ticket $ticket, $qty = 1) |
|
483 | - { |
|
484 | - // get the number of spaces left for this datetime ticket |
|
485 | - $available_spaces = $this->tracker->ticketDatetimeAvailability($ticket); |
|
486 | - // compare available spaces against the number of tickets being purchased |
|
487 | - if ($available_spaces >= $qty) { |
|
488 | - // allow addons to prevent a ticket from being added to cart |
|
489 | - if ( |
|
490 | - ! apply_filters( |
|
491 | - 'FHEE__EE_Ticket_Selector___add_ticket_to_cart__allow_add_to_cart', |
|
492 | - true, |
|
493 | - $ticket, |
|
494 | - $qty, |
|
495 | - $available_spaces |
|
496 | - ) |
|
497 | - ) { |
|
498 | - return false; |
|
499 | - } |
|
500 | - $qty = absint(apply_filters('FHEE__EE_Ticket_Selector___add_ticket_to_cart__ticket_qty', $qty, $ticket)); |
|
501 | - // add event to cart |
|
502 | - if ($this->cart->add_ticket_to_cart($ticket, $qty)) { |
|
503 | - $this->tracker->recalculateTicketDatetimeAvailability($ticket, $qty); |
|
504 | - return true; |
|
505 | - } |
|
506 | - return false; |
|
507 | - } |
|
508 | - $this->tracker->processAvailabilityError($ticket, $qty, $this->cart->all_ticket_quantity_count()); |
|
509 | - return false; |
|
510 | - } |
|
511 | - |
|
512 | - |
|
513 | - /** |
|
514 | - * @param $tickets_added |
|
515 | - * @return bool |
|
516 | - * @throws InvalidInterfaceException |
|
517 | - * @throws InvalidDataTypeException |
|
518 | - * @throws EE_Error |
|
519 | - * @throws InvalidArgumentException |
|
520 | - */ |
|
521 | - private function processSuccessfulCart($tickets_added) |
|
522 | - { |
|
523 | - // exit('KILL REDIRECT BEFORE CART UPDATE'); // <<<<<<<<<<<<<<<<< KILL REDIRECT HERE BEFORE CART UPDATE |
|
524 | - if (apply_filters('FHEE__EED_Ticket_Selector__process_ticket_selections__success', $tickets_added)) { |
|
525 | - // make sure cart is loaded |
|
526 | - if(! $this->cart instanceof EE_Cart){ |
|
527 | - $this->cart = CartFactory::getCart(); |
|
528 | - } |
|
529 | - do_action( |
|
530 | - 'FHEE__EE_Ticket_Selector__process_ticket_selections__before_redirecting_to_checkout', |
|
531 | - $this->cart, |
|
532 | - $this |
|
533 | - ); |
|
534 | - $this->cart->recalculate_all_cart_totals(); |
|
535 | - $this->cart->save_cart(false); |
|
536 | - // exit('KILL REDIRECT AFTER CART UPDATE'); // <<<<<<<< OR HERE TO KILL REDIRECT AFTER CART UPDATE |
|
537 | - // just return TRUE for registrations being made from admin |
|
538 | - if ($this->request->isAdmin() || $this->request->isFrontAjax()) { |
|
539 | - return true; |
|
540 | - } |
|
541 | - EEH_URL::safeRedirectAndExit( |
|
542 | - apply_filters( |
|
543 | - 'FHEE__EE_Ticket_Selector__process_ticket_selections__success_redirect_url', |
|
544 | - $this->core_config->reg_page_url() |
|
545 | - ) |
|
546 | - ); |
|
547 | - } |
|
548 | - if (! EE_Error::has_error() && ! EE_Error::has_error(true, 'attention')) { |
|
549 | - // nothing added to cart |
|
550 | - EE_Error::add_attention( |
|
551 | - esc_html__('No tickets were added for the event', 'event_espresso'), |
|
552 | - __FILE__, __FUNCTION__, __LINE__ |
|
553 | - ); |
|
554 | - } |
|
555 | - return false; |
|
556 | - } |
|
37 | + /** |
|
38 | + * @var EE_Cart $cart |
|
39 | + */ |
|
40 | + private $cart; |
|
41 | + |
|
42 | + /** |
|
43 | + * @var EE_Core_Config $core_config |
|
44 | + */ |
|
45 | + private $core_config; |
|
46 | + |
|
47 | + /** |
|
48 | + * @var Request $request |
|
49 | + */ |
|
50 | + private $request; |
|
51 | + |
|
52 | + /** |
|
53 | + * @var EE_Session $session |
|
54 | + */ |
|
55 | + private $session; |
|
56 | + |
|
57 | + /** |
|
58 | + * @var EEM_Ticket $ticket_model |
|
59 | + */ |
|
60 | + private $ticket_model; |
|
61 | + |
|
62 | + /** |
|
63 | + * @var TicketDatetimeAvailabilityTracker $tracker |
|
64 | + */ |
|
65 | + private $tracker; |
|
66 | + |
|
67 | + |
|
68 | + /** |
|
69 | + * ProcessTicketSelector constructor. |
|
70 | + * NOTE: PLZ use the Loader to instantiate this class if need be |
|
71 | + * so that all dependencies get injected correctly (which will happen automatically) |
|
72 | + * Null values for parameters are only for backwards compatibility but will be removed later on. |
|
73 | + * |
|
74 | + * @param EE_Core_Config $core_config |
|
75 | + * @param Request $request |
|
76 | + * @param EE_Session $session |
|
77 | + * @param EEM_Ticket $ticket_model |
|
78 | + * @param TicketDatetimeAvailabilityTracker $tracker |
|
79 | + * @throws InvalidArgumentException |
|
80 | + * @throws InvalidDataTypeException |
|
81 | + * @throws InvalidInterfaceException |
|
82 | + */ |
|
83 | + public function __construct( |
|
84 | + EE_Core_Config $core_config = null, |
|
85 | + Request $request = null, |
|
86 | + EE_Session $session = null, |
|
87 | + EEM_Ticket $ticket_model = null, |
|
88 | + TicketDatetimeAvailabilityTracker $tracker = null |
|
89 | + ) { |
|
90 | + /** @var LoaderInterface $loader */ |
|
91 | + $loader = LoaderFactory::getLoader(); |
|
92 | + $this->core_config = $core_config instanceof EE_Core_Config |
|
93 | + ? $core_config |
|
94 | + : $loader->getShared('EE_Core_Config'); |
|
95 | + $this->request = $request instanceof Request |
|
96 | + ? $request |
|
97 | + : $loader->getShared('EventEspresso\core\services\request\Request'); |
|
98 | + $this->session = $session instanceof EE_Session |
|
99 | + ? $session |
|
100 | + : $loader->getShared('EE_Session'); |
|
101 | + $this->ticket_model = $ticket_model instanceof EEM_Ticket |
|
102 | + ? $ticket_model |
|
103 | + : $loader->getShared('EEM_Ticket'); |
|
104 | + $this->tracker = $tracker instanceof TicketDatetimeAvailabilityTracker |
|
105 | + ? $tracker |
|
106 | + : $loader->getShared('EventEspresso\modules\ticket_selector\TicketDatetimeAvailabilityTracker'); |
|
107 | + } |
|
108 | + |
|
109 | + |
|
110 | + /** |
|
111 | + * cancelTicketSelections |
|
112 | + * |
|
113 | + * @return bool |
|
114 | + * @throws EE_Error |
|
115 | + * @throws InvalidArgumentException |
|
116 | + * @throws InvalidInterfaceException |
|
117 | + * @throws InvalidDataTypeException |
|
118 | + */ |
|
119 | + public function cancelTicketSelections() |
|
120 | + { |
|
121 | + // check nonce |
|
122 | + if (! $this->processTicketSelectorNonce('cancel_ticket_selections')) { |
|
123 | + return false; |
|
124 | + } |
|
125 | + $this->session->clear_session(__CLASS__, __FUNCTION__); |
|
126 | + if ($this->request->requestParamIsSet('event_id')) { |
|
127 | + EEH_URL::safeRedirectAndExit( |
|
128 | + EEH_Event_View::event_link_url( |
|
129 | + $this->request->getRequestParam('event_id') |
|
130 | + ) |
|
131 | + ); |
|
132 | + } |
|
133 | + EEH_URL::safeRedirectAndExit( |
|
134 | + site_url('/' . $this->core_config->event_cpt_slug . '/') |
|
135 | + ); |
|
136 | + return true; |
|
137 | + } |
|
138 | + |
|
139 | + |
|
140 | + /** |
|
141 | + * processTicketSelectorNonce |
|
142 | + * |
|
143 | + * @param string $nonce_name |
|
144 | + * @param string $id |
|
145 | + * @return bool |
|
146 | + */ |
|
147 | + private function processTicketSelectorNonce($nonce_name, $id = '') |
|
148 | + { |
|
149 | + $nonce_name_with_id = ! empty($id) ? "{$nonce_name}_nonce_{$id}" : "{$nonce_name}_nonce"; |
|
150 | + if ( |
|
151 | + ! $this->request->isAdmin() |
|
152 | + && ( |
|
153 | + ! $this->request->is_set($nonce_name_with_id) |
|
154 | + || ! wp_verify_nonce( |
|
155 | + $this->request->get($nonce_name_with_id), |
|
156 | + $nonce_name |
|
157 | + ) |
|
158 | + ) |
|
159 | + ) { |
|
160 | + EE_Error::add_error( |
|
161 | + sprintf( |
|
162 | + esc_html__( |
|
163 | + 'We\'re sorry but your request failed to pass a security check.%sPlease click the back button on your browser and try again.', |
|
164 | + 'event_espresso' |
|
165 | + ), |
|
166 | + '<br/>' |
|
167 | + ), |
|
168 | + __FILE__, |
|
169 | + __FUNCTION__, |
|
170 | + __LINE__ |
|
171 | + ); |
|
172 | + return false; |
|
173 | + } |
|
174 | + return true; |
|
175 | + } |
|
176 | + |
|
177 | + |
|
178 | + /** |
|
179 | + * process_ticket_selections |
|
180 | + * |
|
181 | + * @return array|bool |
|
182 | + * @throws EE_Error |
|
183 | + * @throws InvalidArgumentException |
|
184 | + * @throws InvalidDataTypeException |
|
185 | + * @throws InvalidInterfaceException |
|
186 | + */ |
|
187 | + public function processTicketSelections() |
|
188 | + { |
|
189 | + do_action('EED_Ticket_Selector__process_ticket_selections__before'); |
|
190 | + if($this->request->isBot()) { |
|
191 | + EEH_URL::safeRedirectAndExit( |
|
192 | + apply_filters( |
|
193 | + 'FHEE__EE_Ticket_Selector__process_ticket_selections__bot_redirect_url', |
|
194 | + site_url() |
|
195 | + ) |
|
196 | + ); |
|
197 | + } |
|
198 | + // do we have an event id? |
|
199 | + $id = $this->getEventId(); |
|
200 | + // we should really only have 1 registration in the works now |
|
201 | + // (ie, no MER) so unless otherwise requested, clear the session |
|
202 | + if (apply_filters('FHEE__EE_Ticket_Selector__process_ticket_selections__clear_session', true)) { |
|
203 | + $this->session->clear_session(__CLASS__, __FUNCTION__); |
|
204 | + } |
|
205 | + // validate/sanitize/filter data |
|
206 | + $valid = apply_filters( |
|
207 | + 'FHEE__EED_Ticket_Selector__process_ticket_selections__valid_post_data', |
|
208 | + $this->validatePostData($id) |
|
209 | + ); |
|
210 | + //check total tickets ordered vs max number of attendees that can register |
|
211 | + if ($valid['total_tickets'] > $valid['max_atndz']) { |
|
212 | + $this->maxAttendeesViolation($valid); |
|
213 | + } else { |
|
214 | + // all data appears to be valid |
|
215 | + if ($this->processSuccessfulCart($this->addTicketsToCart($valid))) { |
|
216 | + return true; |
|
217 | + } |
|
218 | + } |
|
219 | + // die(); // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< KILL BEFORE REDIRECT |
|
220 | + // at this point, just return if registration is being made from admin |
|
221 | + if ($this->request->isAdmin() || $this->request->isFrontAjax()) { |
|
222 | + return false; |
|
223 | + } |
|
224 | + if ($valid['return_url']) { |
|
225 | + EEH_URL::safeRedirectAndExit($valid['return_url']); |
|
226 | + } |
|
227 | + if ($id) { |
|
228 | + EEH_URL::safeRedirectAndExit(get_permalink($id)); |
|
229 | + } |
|
230 | + echo EE_Error::get_notices(); |
|
231 | + return false; |
|
232 | + } |
|
233 | + |
|
234 | + |
|
235 | + /** |
|
236 | + * @return int |
|
237 | + */ |
|
238 | + private function getEventId() |
|
239 | + { |
|
240 | + // do we have an event id? |
|
241 | + if (! $this->request->requestParamIsSet('tkt-slctr-event-id')) { |
|
242 | + // $_POST['tkt-slctr-event-id'] was not set ?!?!?!? |
|
243 | + EE_Error::add_error( |
|
244 | + sprintf( |
|
245 | + esc_html__( |
|
246 | + 'An event id was not provided or was not received.%sPlease click the back button on your browser and try again.', |
|
247 | + 'event_espresso' |
|
248 | + ), |
|
249 | + '<br/>' |
|
250 | + ), |
|
251 | + __FILE__, |
|
252 | + __FUNCTION__, |
|
253 | + __LINE__ |
|
254 | + ); |
|
255 | + } |
|
256 | + //if event id is valid |
|
257 | + return absint($this->request->getRequestParam('tkt-slctr-event-id')); |
|
258 | + } |
|
259 | + |
|
260 | + |
|
261 | + /** |
|
262 | + * validate_post_data |
|
263 | + * |
|
264 | + * @param int $id |
|
265 | + * @return array|FALSE |
|
266 | + */ |
|
267 | + private function validatePostData($id = 0) |
|
268 | + { |
|
269 | + if (! $id) { |
|
270 | + EE_Error::add_error( |
|
271 | + esc_html__('The event id provided was not valid.', 'event_espresso'), |
|
272 | + __FILE__, |
|
273 | + __FUNCTION__, |
|
274 | + __LINE__ |
|
275 | + ); |
|
276 | + return false; |
|
277 | + } |
|
278 | + // start with an empty array() |
|
279 | + $valid_data = array(); |
|
280 | + // grab valid id |
|
281 | + $valid_data['id'] = $id; |
|
282 | + // array of other form names |
|
283 | + $inputs_to_clean = array( |
|
284 | + 'event_id' => 'tkt-slctr-event-id', |
|
285 | + 'max_atndz' => 'tkt-slctr-max-atndz-', |
|
286 | + 'rows' => 'tkt-slctr-rows-', |
|
287 | + 'qty' => 'tkt-slctr-qty-', |
|
288 | + 'ticket_id' => 'tkt-slctr-ticket-id-', |
|
289 | + 'return_url' => 'tkt-slctr-return-url-', |
|
290 | + ); |
|
291 | + // let's track the total number of tickets ordered.' |
|
292 | + $valid_data['total_tickets'] = 0; |
|
293 | + // cycle through $inputs_to_clean array |
|
294 | + foreach ($inputs_to_clean as $what => $input_to_clean) { |
|
295 | + // check for POST data |
|
296 | + if ($this->request->requestParamIsSet($input_to_clean . $id)) { |
|
297 | + // grab value |
|
298 | + $input_value = $this->request->getRequestParam($input_to_clean . $id); |
|
299 | + switch ($what) { |
|
300 | + // integers |
|
301 | + case 'event_id': |
|
302 | + $valid_data[ $what ] = absint($input_value); |
|
303 | + // get event via the event id we put in the form |
|
304 | + break; |
|
305 | + case 'rows': |
|
306 | + case 'max_atndz': |
|
307 | + $valid_data[ $what ] = absint($input_value); |
|
308 | + break; |
|
309 | + // arrays of integers |
|
310 | + case 'qty': |
|
311 | + /** @var array $row_qty */ |
|
312 | + $row_qty = $input_value; |
|
313 | + // if qty is coming from a radio button input, then we need to assemble an array of rows |
|
314 | + if (! is_array($row_qty)) { |
|
315 | + /** @var string $row_qty */ |
|
316 | + // get number of rows |
|
317 | + $rows = $this->request->requestParamIsSet('tkt-slctr-rows-' . $id) |
|
318 | + ? absint($this->request->getRequestParam('tkt-slctr-rows-' . $id)) |
|
319 | + : 1; |
|
320 | + // explode integers by the dash |
|
321 | + $row_qty = explode('-', $row_qty); |
|
322 | + $row = isset($row_qty[0]) ? absint($row_qty[0]) : 1; |
|
323 | + $qty = isset($row_qty[1]) ? absint($row_qty[1]) : 0; |
|
324 | + $row_qty = array($row => $qty); |
|
325 | + for ($x = 1; $x <= $rows; $x++) { |
|
326 | + if (! isset($row_qty[ $x ])) { |
|
327 | + $row_qty[ $x ] = 0; |
|
328 | + } |
|
329 | + } |
|
330 | + } |
|
331 | + ksort($row_qty); |
|
332 | + // cycle thru values |
|
333 | + foreach ($row_qty as $qty) { |
|
334 | + $qty = absint($qty); |
|
335 | + // sanitize as integers |
|
336 | + $valid_data[ $what ][] = $qty; |
|
337 | + $valid_data['total_tickets'] += $qty; |
|
338 | + } |
|
339 | + break; |
|
340 | + // array of integers |
|
341 | + case 'ticket_id': |
|
342 | + // cycle thru values |
|
343 | + foreach ((array) $input_value as $key => $value) { |
|
344 | + // allow only integers |
|
345 | + $valid_data[ $what ][ $key ] = absint($value); |
|
346 | + } |
|
347 | + break; |
|
348 | + case 'return_url' : |
|
349 | + // grab and sanitize return-url |
|
350 | + $input_value = esc_url_raw($input_value); |
|
351 | + // was the request coming from an iframe ? if so, then: |
|
352 | + if (strpos($input_value, 'event_list=iframe')) { |
|
353 | + // get anchor fragment |
|
354 | + $input_value = explode('#', $input_value); |
|
355 | + $input_value = end($input_value); |
|
356 | + // use event list url instead, but append anchor |
|
357 | + $input_value = EEH_Event_View::event_archive_url() . '#' . $input_value; |
|
358 | + } |
|
359 | + $valid_data[ $what ] = $input_value; |
|
360 | + break; |
|
361 | + } // end switch $what |
|
362 | + } |
|
363 | + } // end foreach $inputs_to_clean |
|
364 | + return $valid_data; |
|
365 | + } |
|
366 | + |
|
367 | + |
|
368 | + /** |
|
369 | + * @param array $valid |
|
370 | + */ |
|
371 | + private function maxAttendeesViolation(array $valid) |
|
372 | + { |
|
373 | + // ordering too many tickets !!! |
|
374 | + $total_tickets_string = esc_html( |
|
375 | + _n( |
|
376 | + 'You have attempted to purchase %s ticket.', |
|
377 | + 'You have attempted to purchase %s tickets.', |
|
378 | + $valid['total_tickets'], |
|
379 | + 'event_espresso' |
|
380 | + ) |
|
381 | + ); |
|
382 | + $limit_error_1 = sprintf($total_tickets_string, $valid['total_tickets']); |
|
383 | + // dev only message |
|
384 | + $max_attendees_string = esc_html( |
|
385 | + _n( |
|
386 | + 'The registration limit for this event is %s ticket per registration, therefore the total number of tickets you may purchase at a time can not exceed %s.', |
|
387 | + 'The registration limit for this event is %s tickets per registration, therefore the total number of tickets you may purchase at a time can not exceed %s.', |
|
388 | + $valid['max_atndz'], |
|
389 | + 'event_espresso' |
|
390 | + ) |
|
391 | + ); |
|
392 | + $limit_error_2 = sprintf($max_attendees_string, $valid['max_atndz'], $valid['max_atndz']); |
|
393 | + EE_Error::add_error($limit_error_1 . '<br/>' . $limit_error_2, __FILE__, __FUNCTION__, __LINE__); |
|
394 | + } |
|
395 | + |
|
396 | + |
|
397 | + /** |
|
398 | + * @param array $valid |
|
399 | + * @return int|TRUE |
|
400 | + * @throws EE_Error |
|
401 | + * @throws InvalidArgumentException |
|
402 | + * @throws InvalidDataTypeException |
|
403 | + * @throws InvalidInterfaceException |
|
404 | + */ |
|
405 | + private function addTicketsToCart(array $valid) |
|
406 | + { |
|
407 | + $tickets_added = 0; |
|
408 | + $tickets_selected = false; |
|
409 | + if($valid['total_tickets'] > 0){ |
|
410 | + // load cart using factory because we don't want to do so until actually needed |
|
411 | + $this->cart = CartFactory::getCart(); |
|
412 | + // cycle thru the number of data rows sent from the event listing |
|
413 | + for ($x = 0; $x < $valid['rows']; $x++) { |
|
414 | + // does this row actually contain a ticket quantity? |
|
415 | + if (isset($valid['qty'][ $x ]) && $valid['qty'][ $x ] > 0) { |
|
416 | + // YES we have a ticket quantity |
|
417 | + $tickets_selected = true; |
|
418 | + $valid_ticket = false; |
|
419 | + // \EEH_Debug_Tools::printr( |
|
420 | + // $valid['ticket_id'][ $x ], |
|
421 | + // '$valid[\'ticket_id\'][ $x ]', |
|
422 | + // __FILE__, __LINE__ |
|
423 | + // ); |
|
424 | + if (isset($valid['ticket_id'][ $x ])) { |
|
425 | + // get ticket via the ticket id we put in the form |
|
426 | + $ticket = $this->ticket_model->get_one_by_ID($valid['ticket_id'][ $x ]); |
|
427 | + if ($ticket instanceof EE_Ticket) { |
|
428 | + $valid_ticket = true; |
|
429 | + $tickets_added += $this->addTicketToCart( |
|
430 | + $ticket, |
|
431 | + $valid['qty'][ $x ] |
|
432 | + ); |
|
433 | + } |
|
434 | + } |
|
435 | + if ($valid_ticket !== true) { |
|
436 | + // nothing added to cart retrieved |
|
437 | + EE_Error::add_error( |
|
438 | + sprintf( |
|
439 | + esc_html__( |
|
440 | + 'A valid ticket could not be retrieved for the event.%sPlease click the back button on your browser and try again.', |
|
441 | + 'event_espresso' |
|
442 | + ), |
|
443 | + '<br/>' |
|
444 | + ), |
|
445 | + __FILE__, __FUNCTION__, __LINE__ |
|
446 | + ); |
|
447 | + } |
|
448 | + if (EE_Error::has_error()) { |
|
449 | + break; |
|
450 | + } |
|
451 | + } |
|
452 | + } |
|
453 | + } |
|
454 | + do_action( |
|
455 | + 'AHEE__EE_Ticket_Selector__process_ticket_selections__after_tickets_added_to_cart', |
|
456 | + $this->cart, |
|
457 | + $this |
|
458 | + ); |
|
459 | + if (! apply_filters('FHEE__EED_Ticket_Selector__process_ticket_selections__tckts_slctd', $tickets_selected)) { |
|
460 | + // no ticket quantities were selected |
|
461 | + EE_Error::add_error( |
|
462 | + esc_html__('You need to select a ticket quantity before you can proceed.', 'event_espresso'), |
|
463 | + __FILE__, __FUNCTION__, __LINE__ |
|
464 | + ); |
|
465 | + } |
|
466 | + return $tickets_added; |
|
467 | + } |
|
468 | + |
|
469 | + |
|
470 | + |
|
471 | + /** |
|
472 | + * adds a ticket to the cart |
|
473 | + * |
|
474 | + * @param EE_Ticket $ticket |
|
475 | + * @param int $qty |
|
476 | + * @return TRUE on success, FALSE on fail |
|
477 | + * @throws InvalidArgumentException |
|
478 | + * @throws InvalidInterfaceException |
|
479 | + * @throws InvalidDataTypeException |
|
480 | + * @throws EE_Error |
|
481 | + */ |
|
482 | + private function addTicketToCart(EE_Ticket $ticket, $qty = 1) |
|
483 | + { |
|
484 | + // get the number of spaces left for this datetime ticket |
|
485 | + $available_spaces = $this->tracker->ticketDatetimeAvailability($ticket); |
|
486 | + // compare available spaces against the number of tickets being purchased |
|
487 | + if ($available_spaces >= $qty) { |
|
488 | + // allow addons to prevent a ticket from being added to cart |
|
489 | + if ( |
|
490 | + ! apply_filters( |
|
491 | + 'FHEE__EE_Ticket_Selector___add_ticket_to_cart__allow_add_to_cart', |
|
492 | + true, |
|
493 | + $ticket, |
|
494 | + $qty, |
|
495 | + $available_spaces |
|
496 | + ) |
|
497 | + ) { |
|
498 | + return false; |
|
499 | + } |
|
500 | + $qty = absint(apply_filters('FHEE__EE_Ticket_Selector___add_ticket_to_cart__ticket_qty', $qty, $ticket)); |
|
501 | + // add event to cart |
|
502 | + if ($this->cart->add_ticket_to_cart($ticket, $qty)) { |
|
503 | + $this->tracker->recalculateTicketDatetimeAvailability($ticket, $qty); |
|
504 | + return true; |
|
505 | + } |
|
506 | + return false; |
|
507 | + } |
|
508 | + $this->tracker->processAvailabilityError($ticket, $qty, $this->cart->all_ticket_quantity_count()); |
|
509 | + return false; |
|
510 | + } |
|
511 | + |
|
512 | + |
|
513 | + /** |
|
514 | + * @param $tickets_added |
|
515 | + * @return bool |
|
516 | + * @throws InvalidInterfaceException |
|
517 | + * @throws InvalidDataTypeException |
|
518 | + * @throws EE_Error |
|
519 | + * @throws InvalidArgumentException |
|
520 | + */ |
|
521 | + private function processSuccessfulCart($tickets_added) |
|
522 | + { |
|
523 | + // exit('KILL REDIRECT BEFORE CART UPDATE'); // <<<<<<<<<<<<<<<<< KILL REDIRECT HERE BEFORE CART UPDATE |
|
524 | + if (apply_filters('FHEE__EED_Ticket_Selector__process_ticket_selections__success', $tickets_added)) { |
|
525 | + // make sure cart is loaded |
|
526 | + if(! $this->cart instanceof EE_Cart){ |
|
527 | + $this->cart = CartFactory::getCart(); |
|
528 | + } |
|
529 | + do_action( |
|
530 | + 'FHEE__EE_Ticket_Selector__process_ticket_selections__before_redirecting_to_checkout', |
|
531 | + $this->cart, |
|
532 | + $this |
|
533 | + ); |
|
534 | + $this->cart->recalculate_all_cart_totals(); |
|
535 | + $this->cart->save_cart(false); |
|
536 | + // exit('KILL REDIRECT AFTER CART UPDATE'); // <<<<<<<< OR HERE TO KILL REDIRECT AFTER CART UPDATE |
|
537 | + // just return TRUE for registrations being made from admin |
|
538 | + if ($this->request->isAdmin() || $this->request->isFrontAjax()) { |
|
539 | + return true; |
|
540 | + } |
|
541 | + EEH_URL::safeRedirectAndExit( |
|
542 | + apply_filters( |
|
543 | + 'FHEE__EE_Ticket_Selector__process_ticket_selections__success_redirect_url', |
|
544 | + $this->core_config->reg_page_url() |
|
545 | + ) |
|
546 | + ); |
|
547 | + } |
|
548 | + if (! EE_Error::has_error() && ! EE_Error::has_error(true, 'attention')) { |
|
549 | + // nothing added to cart |
|
550 | + EE_Error::add_attention( |
|
551 | + esc_html__('No tickets were added for the event', 'event_espresso'), |
|
552 | + __FILE__, __FUNCTION__, __LINE__ |
|
553 | + ); |
|
554 | + } |
|
555 | + return false; |
|
556 | + } |
|
557 | 557 | } |
558 | 558 | // End of file ProcessTicketSelector.php |
559 | 559 | // Location: /ProcessTicketSelector.php |
@@ -119,7 +119,7 @@ discard block |
||
119 | 119 | public function cancelTicketSelections() |
120 | 120 | { |
121 | 121 | // check nonce |
122 | - if (! $this->processTicketSelectorNonce('cancel_ticket_selections')) { |
|
122 | + if ( ! $this->processTicketSelectorNonce('cancel_ticket_selections')) { |
|
123 | 123 | return false; |
124 | 124 | } |
125 | 125 | $this->session->clear_session(__CLASS__, __FUNCTION__); |
@@ -131,7 +131,7 @@ discard block |
||
131 | 131 | ); |
132 | 132 | } |
133 | 133 | EEH_URL::safeRedirectAndExit( |
134 | - site_url('/' . $this->core_config->event_cpt_slug . '/') |
|
134 | + site_url('/'.$this->core_config->event_cpt_slug.'/') |
|
135 | 135 | ); |
136 | 136 | return true; |
137 | 137 | } |
@@ -187,7 +187,7 @@ discard block |
||
187 | 187 | public function processTicketSelections() |
188 | 188 | { |
189 | 189 | do_action('EED_Ticket_Selector__process_ticket_selections__before'); |
190 | - if($this->request->isBot()) { |
|
190 | + if ($this->request->isBot()) { |
|
191 | 191 | EEH_URL::safeRedirectAndExit( |
192 | 192 | apply_filters( |
193 | 193 | 'FHEE__EE_Ticket_Selector__process_ticket_selections__bot_redirect_url', |
@@ -238,7 +238,7 @@ discard block |
||
238 | 238 | private function getEventId() |
239 | 239 | { |
240 | 240 | // do we have an event id? |
241 | - if (! $this->request->requestParamIsSet('tkt-slctr-event-id')) { |
|
241 | + if ( ! $this->request->requestParamIsSet('tkt-slctr-event-id')) { |
|
242 | 242 | // $_POST['tkt-slctr-event-id'] was not set ?!?!?!? |
243 | 243 | EE_Error::add_error( |
244 | 244 | sprintf( |
@@ -266,7 +266,7 @@ discard block |
||
266 | 266 | */ |
267 | 267 | private function validatePostData($id = 0) |
268 | 268 | { |
269 | - if (! $id) { |
|
269 | + if ( ! $id) { |
|
270 | 270 | EE_Error::add_error( |
271 | 271 | esc_html__('The event id provided was not valid.', 'event_espresso'), |
272 | 272 | __FILE__, |
@@ -293,29 +293,29 @@ discard block |
||
293 | 293 | // cycle through $inputs_to_clean array |
294 | 294 | foreach ($inputs_to_clean as $what => $input_to_clean) { |
295 | 295 | // check for POST data |
296 | - if ($this->request->requestParamIsSet($input_to_clean . $id)) { |
|
296 | + if ($this->request->requestParamIsSet($input_to_clean.$id)) { |
|
297 | 297 | // grab value |
298 | - $input_value = $this->request->getRequestParam($input_to_clean . $id); |
|
298 | + $input_value = $this->request->getRequestParam($input_to_clean.$id); |
|
299 | 299 | switch ($what) { |
300 | 300 | // integers |
301 | 301 | case 'event_id': |
302 | - $valid_data[ $what ] = absint($input_value); |
|
302 | + $valid_data[$what] = absint($input_value); |
|
303 | 303 | // get event via the event id we put in the form |
304 | 304 | break; |
305 | 305 | case 'rows': |
306 | 306 | case 'max_atndz': |
307 | - $valid_data[ $what ] = absint($input_value); |
|
307 | + $valid_data[$what] = absint($input_value); |
|
308 | 308 | break; |
309 | 309 | // arrays of integers |
310 | 310 | case 'qty': |
311 | 311 | /** @var array $row_qty */ |
312 | 312 | $row_qty = $input_value; |
313 | 313 | // if qty is coming from a radio button input, then we need to assemble an array of rows |
314 | - if (! is_array($row_qty)) { |
|
314 | + if ( ! is_array($row_qty)) { |
|
315 | 315 | /** @var string $row_qty */ |
316 | 316 | // get number of rows |
317 | - $rows = $this->request->requestParamIsSet('tkt-slctr-rows-' . $id) |
|
318 | - ? absint($this->request->getRequestParam('tkt-slctr-rows-' . $id)) |
|
317 | + $rows = $this->request->requestParamIsSet('tkt-slctr-rows-'.$id) |
|
318 | + ? absint($this->request->getRequestParam('tkt-slctr-rows-'.$id)) |
|
319 | 319 | : 1; |
320 | 320 | // explode integers by the dash |
321 | 321 | $row_qty = explode('-', $row_qty); |
@@ -323,8 +323,8 @@ discard block |
||
323 | 323 | $qty = isset($row_qty[1]) ? absint($row_qty[1]) : 0; |
324 | 324 | $row_qty = array($row => $qty); |
325 | 325 | for ($x = 1; $x <= $rows; $x++) { |
326 | - if (! isset($row_qty[ $x ])) { |
|
327 | - $row_qty[ $x ] = 0; |
|
326 | + if ( ! isset($row_qty[$x])) { |
|
327 | + $row_qty[$x] = 0; |
|
328 | 328 | } |
329 | 329 | } |
330 | 330 | } |
@@ -333,7 +333,7 @@ discard block |
||
333 | 333 | foreach ($row_qty as $qty) { |
334 | 334 | $qty = absint($qty); |
335 | 335 | // sanitize as integers |
336 | - $valid_data[ $what ][] = $qty; |
|
336 | + $valid_data[$what][] = $qty; |
|
337 | 337 | $valid_data['total_tickets'] += $qty; |
338 | 338 | } |
339 | 339 | break; |
@@ -342,7 +342,7 @@ discard block |
||
342 | 342 | // cycle thru values |
343 | 343 | foreach ((array) $input_value as $key => $value) { |
344 | 344 | // allow only integers |
345 | - $valid_data[ $what ][ $key ] = absint($value); |
|
345 | + $valid_data[$what][$key] = absint($value); |
|
346 | 346 | } |
347 | 347 | break; |
348 | 348 | case 'return_url' : |
@@ -354,9 +354,9 @@ discard block |
||
354 | 354 | $input_value = explode('#', $input_value); |
355 | 355 | $input_value = end($input_value); |
356 | 356 | // use event list url instead, but append anchor |
357 | - $input_value = EEH_Event_View::event_archive_url() . '#' . $input_value; |
|
357 | + $input_value = EEH_Event_View::event_archive_url().'#'.$input_value; |
|
358 | 358 | } |
359 | - $valid_data[ $what ] = $input_value; |
|
359 | + $valid_data[$what] = $input_value; |
|
360 | 360 | break; |
361 | 361 | } // end switch $what |
362 | 362 | } |
@@ -389,8 +389,8 @@ discard block |
||
389 | 389 | 'event_espresso' |
390 | 390 | ) |
391 | 391 | ); |
392 | - $limit_error_2 = sprintf($max_attendees_string, $valid['max_atndz'], $valid['max_atndz']); |
|
393 | - EE_Error::add_error($limit_error_1 . '<br/>' . $limit_error_2, __FILE__, __FUNCTION__, __LINE__); |
|
392 | + $limit_error_2 = sprintf($max_attendees_string, $valid['max_atndz'], $valid['max_atndz']); |
|
393 | + EE_Error::add_error($limit_error_1.'<br/>'.$limit_error_2, __FILE__, __FUNCTION__, __LINE__); |
|
394 | 394 | } |
395 | 395 | |
396 | 396 | |
@@ -406,13 +406,13 @@ discard block |
||
406 | 406 | { |
407 | 407 | $tickets_added = 0; |
408 | 408 | $tickets_selected = false; |
409 | - if($valid['total_tickets'] > 0){ |
|
409 | + if ($valid['total_tickets'] > 0) { |
|
410 | 410 | // load cart using factory because we don't want to do so until actually needed |
411 | 411 | $this->cart = CartFactory::getCart(); |
412 | 412 | // cycle thru the number of data rows sent from the event listing |
413 | 413 | for ($x = 0; $x < $valid['rows']; $x++) { |
414 | 414 | // does this row actually contain a ticket quantity? |
415 | - if (isset($valid['qty'][ $x ]) && $valid['qty'][ $x ] > 0) { |
|
415 | + if (isset($valid['qty'][$x]) && $valid['qty'][$x] > 0) { |
|
416 | 416 | // YES we have a ticket quantity |
417 | 417 | $tickets_selected = true; |
418 | 418 | $valid_ticket = false; |
@@ -421,14 +421,14 @@ discard block |
||
421 | 421 | // '$valid[\'ticket_id\'][ $x ]', |
422 | 422 | // __FILE__, __LINE__ |
423 | 423 | // ); |
424 | - if (isset($valid['ticket_id'][ $x ])) { |
|
424 | + if (isset($valid['ticket_id'][$x])) { |
|
425 | 425 | // get ticket via the ticket id we put in the form |
426 | - $ticket = $this->ticket_model->get_one_by_ID($valid['ticket_id'][ $x ]); |
|
426 | + $ticket = $this->ticket_model->get_one_by_ID($valid['ticket_id'][$x]); |
|
427 | 427 | if ($ticket instanceof EE_Ticket) { |
428 | - $valid_ticket = true; |
|
428 | + $valid_ticket = true; |
|
429 | 429 | $tickets_added += $this->addTicketToCart( |
430 | 430 | $ticket, |
431 | - $valid['qty'][ $x ] |
|
431 | + $valid['qty'][$x] |
|
432 | 432 | ); |
433 | 433 | } |
434 | 434 | } |
@@ -456,7 +456,7 @@ discard block |
||
456 | 456 | $this->cart, |
457 | 457 | $this |
458 | 458 | ); |
459 | - if (! apply_filters('FHEE__EED_Ticket_Selector__process_ticket_selections__tckts_slctd', $tickets_selected)) { |
|
459 | + if ( ! apply_filters('FHEE__EED_Ticket_Selector__process_ticket_selections__tckts_slctd', $tickets_selected)) { |
|
460 | 460 | // no ticket quantities were selected |
461 | 461 | EE_Error::add_error( |
462 | 462 | esc_html__('You need to select a ticket quantity before you can proceed.', 'event_espresso'), |
@@ -523,7 +523,7 @@ discard block |
||
523 | 523 | // exit('KILL REDIRECT BEFORE CART UPDATE'); // <<<<<<<<<<<<<<<<< KILL REDIRECT HERE BEFORE CART UPDATE |
524 | 524 | if (apply_filters('FHEE__EED_Ticket_Selector__process_ticket_selections__success', $tickets_added)) { |
525 | 525 | // make sure cart is loaded |
526 | - if(! $this->cart instanceof EE_Cart){ |
|
526 | + if ( ! $this->cart instanceof EE_Cart) { |
|
527 | 527 | $this->cart = CartFactory::getCart(); |
528 | 528 | } |
529 | 529 | do_action( |
@@ -545,7 +545,7 @@ discard block |
||
545 | 545 | ) |
546 | 546 | ); |
547 | 547 | } |
548 | - if (! EE_Error::has_error() && ! EE_Error::has_error(true, 'attention')) { |
|
548 | + if ( ! EE_Error::has_error() && ! EE_Error::has_error(true, 'attention')) { |
|
549 | 549 | // nothing added to cart |
550 | 550 | EE_Error::add_attention( |
551 | 551 | esc_html__('No tickets were added for the event', 'event_espresso'), |
@@ -38,103 +38,103 @@ |
||
38 | 38 | * @since 4.0 |
39 | 39 | */ |
40 | 40 | if (function_exists('espresso_version')) { |
41 | - if (! function_exists('espresso_duplicate_plugin_error')) { |
|
42 | - /** |
|
43 | - * espresso_duplicate_plugin_error |
|
44 | - * displays if more than one version of EE is activated at the same time |
|
45 | - */ |
|
46 | - function espresso_duplicate_plugin_error() |
|
47 | - { |
|
48 | - ?> |
|
41 | + if (! function_exists('espresso_duplicate_plugin_error')) { |
|
42 | + /** |
|
43 | + * espresso_duplicate_plugin_error |
|
44 | + * displays if more than one version of EE is activated at the same time |
|
45 | + */ |
|
46 | + function espresso_duplicate_plugin_error() |
|
47 | + { |
|
48 | + ?> |
|
49 | 49 | <div class="error"> |
50 | 50 | <p> |
51 | 51 | <?php |
52 | - 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 | - ); ?> |
|
52 | + 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 | + ); ?> |
|
56 | 56 | </p> |
57 | 57 | </div> |
58 | 58 | <?php |
59 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
60 | - } |
|
61 | - } |
|
62 | - add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
59 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
60 | + } |
|
61 | + } |
|
62 | + add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
63 | 63 | |
64 | 64 | } else { |
65 | - define('EE_MIN_PHP_VER_REQUIRED', '5.4.0'); |
|
66 | - if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
67 | - /** |
|
68 | - * espresso_minimum_php_version_error |
|
69 | - * @return void |
|
70 | - */ |
|
71 | - function espresso_minimum_php_version_error() |
|
72 | - { |
|
73 | - ?> |
|
65 | + define('EE_MIN_PHP_VER_REQUIRED', '5.4.0'); |
|
66 | + if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
67 | + /** |
|
68 | + * espresso_minimum_php_version_error |
|
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 | - define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
97 | - /** |
|
98 | - * espresso_version |
|
99 | - * Returns the plugin version |
|
100 | - * |
|
101 | - * @return string |
|
102 | - */ |
|
103 | - function espresso_version() |
|
104 | - { |
|
105 | - return apply_filters('FHEE__espresso__espresso_version', '4.9.59.rc.061'); |
|
106 | - } |
|
94 | + add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
95 | + } else { |
|
96 | + define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
97 | + /** |
|
98 | + * espresso_version |
|
99 | + * Returns the plugin version |
|
100 | + * |
|
101 | + * @return string |
|
102 | + */ |
|
103 | + function espresso_version() |
|
104 | + { |
|
105 | + return apply_filters('FHEE__espresso__espresso_version', '4.9.59.rc.061'); |
|
106 | + } |
|
107 | 107 | |
108 | - /** |
|
109 | - * espresso_plugin_activation |
|
110 | - * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
111 | - */ |
|
112 | - function espresso_plugin_activation() |
|
113 | - { |
|
114 | - update_option('ee_espresso_activation', true); |
|
115 | - } |
|
108 | + /** |
|
109 | + * espresso_plugin_activation |
|
110 | + * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
111 | + */ |
|
112 | + function espresso_plugin_activation() |
|
113 | + { |
|
114 | + update_option('ee_espresso_activation', true); |
|
115 | + } |
|
116 | 116 | |
117 | - register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
117 | + register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
118 | 118 | |
119 | - require_once __DIR__ . '/core/bootstrap_espresso.php'; |
|
120 | - bootstrap_espresso(); |
|
121 | - } |
|
119 | + require_once __DIR__ . '/core/bootstrap_espresso.php'; |
|
120 | + bootstrap_espresso(); |
|
121 | + } |
|
122 | 122 | } |
123 | 123 | if (! function_exists('espresso_deactivate_plugin')) { |
124 | - /** |
|
125 | - * deactivate_plugin |
|
126 | - * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
127 | - * |
|
128 | - * @access public |
|
129 | - * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
130 | - * @return void |
|
131 | - */ |
|
132 | - function espresso_deactivate_plugin($plugin_basename = '') |
|
133 | - { |
|
134 | - if (! function_exists('deactivate_plugins')) { |
|
135 | - require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
136 | - } |
|
137 | - unset($_GET['activate'], $_REQUEST['activate']); |
|
138 | - deactivate_plugins($plugin_basename); |
|
139 | - } |
|
124 | + /** |
|
125 | + * deactivate_plugin |
|
126 | + * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
127 | + * |
|
128 | + * @access public |
|
129 | + * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
130 | + * @return void |
|
131 | + */ |
|
132 | + function espresso_deactivate_plugin($plugin_basename = '') |
|
133 | + { |
|
134 | + if (! function_exists('deactivate_plugins')) { |
|
135 | + require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
136 | + } |
|
137 | + unset($_GET['activate'], $_REQUEST['activate']); |
|
138 | + deactivate_plugins($plugin_basename); |
|
139 | + } |
|
140 | 140 | } |
@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | use EventEspresso\core\services\request\ResponseInterface; |
9 | 9 | |
10 | 10 | if (! defined('EVENT_ESPRESSO_VERSION')) { |
11 | - exit('No direct script access allowed'); |
|
11 | + exit('No direct script access allowed'); |
|
12 | 12 | } |
13 | 13 | |
14 | 14 | |
@@ -25,867 +25,867 @@ discard block |
||
25 | 25 | class EE_Dependency_Map |
26 | 26 | { |
27 | 27 | |
28 | - /** |
|
29 | - * This means that the requested class dependency is not present in the dependency map |
|
30 | - */ |
|
31 | - const not_registered = 0; |
|
32 | - |
|
33 | - /** |
|
34 | - * This instructs class loaders to ALWAYS return a newly instantiated object for the requested class. |
|
35 | - */ |
|
36 | - const load_new_object = 1; |
|
37 | - |
|
38 | - /** |
|
39 | - * This instructs class loaders to return a previously instantiated and cached object for the requested class. |
|
40 | - * IF a previously instantiated object does not exist, a new one will be created and added to the cache. |
|
41 | - */ |
|
42 | - const load_from_cache = 2; |
|
43 | - |
|
44 | - /** |
|
45 | - * When registering a dependency, |
|
46 | - * this indicates to keep any existing dependencies that already exist, |
|
47 | - * and simply discard any new dependencies declared in the incoming data |
|
48 | - */ |
|
49 | - const KEEP_EXISTING_DEPENDENCIES = 0; |
|
50 | - |
|
51 | - /** |
|
52 | - * When registering a dependency, |
|
53 | - * this indicates to overwrite any existing dependencies that already exist using the incoming data |
|
54 | - */ |
|
55 | - const OVERWRITE_DEPENDENCIES = 1; |
|
56 | - |
|
57 | - |
|
58 | - |
|
59 | - /** |
|
60 | - * @type EE_Dependency_Map $_instance |
|
61 | - */ |
|
62 | - protected static $_instance; |
|
63 | - |
|
64 | - /** |
|
65 | - * @type RequestInterface $request |
|
66 | - */ |
|
67 | - protected $request; |
|
68 | - |
|
69 | - /** |
|
70 | - * @type LegacyRequestInterface $legacy_request |
|
71 | - */ |
|
72 | - protected $legacy_request; |
|
73 | - |
|
74 | - /** |
|
75 | - * @type ResponseInterface $response |
|
76 | - */ |
|
77 | - protected $response; |
|
78 | - |
|
79 | - /** |
|
80 | - * @type LoaderInterface $loader |
|
81 | - */ |
|
82 | - protected $loader; |
|
83 | - |
|
84 | - /** |
|
85 | - * @type array $_dependency_map |
|
86 | - */ |
|
87 | - protected $_dependency_map = array(); |
|
88 | - |
|
89 | - /** |
|
90 | - * @type array $_class_loaders |
|
91 | - */ |
|
92 | - protected $_class_loaders = array(); |
|
93 | - |
|
94 | - /** |
|
95 | - * @type array $_aliases |
|
96 | - */ |
|
97 | - protected $_aliases = array(); |
|
98 | - |
|
99 | - |
|
100 | - |
|
101 | - /** |
|
102 | - * EE_Dependency_Map constructor. |
|
103 | - */ |
|
104 | - protected function __construct() |
|
105 | - { |
|
106 | - // add_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading', array($this, 'initialize')); |
|
107 | - do_action('EE_Dependency_Map____construct'); |
|
108 | - } |
|
109 | - |
|
110 | - |
|
111 | - |
|
112 | - /** |
|
113 | - * @throws InvalidDataTypeException |
|
114 | - * @throws InvalidInterfaceException |
|
115 | - * @throws InvalidArgumentException |
|
116 | - */ |
|
117 | - public function initialize() |
|
118 | - { |
|
119 | - $this->_register_core_dependencies(); |
|
120 | - $this->_register_core_class_loaders(); |
|
121 | - $this->_register_core_aliases(); |
|
122 | - } |
|
123 | - |
|
124 | - |
|
125 | - |
|
126 | - /** |
|
127 | - * @singleton method used to instantiate class object |
|
128 | - * @return EE_Dependency_Map |
|
129 | - */ |
|
130 | - public static function instance() { |
|
131 | - // check if class object is instantiated, and instantiated properly |
|
132 | - if (! self::$_instance instanceof EE_Dependency_Map) { |
|
133 | - self::$_instance = new EE_Dependency_Map(/*$request, $response, $legacy_request*/); |
|
134 | - } |
|
135 | - return self::$_instance; |
|
136 | - } |
|
137 | - |
|
138 | - |
|
139 | - /** |
|
140 | - * @param RequestInterface $request |
|
141 | - */ |
|
142 | - public function setRequest(RequestInterface $request) |
|
143 | - { |
|
144 | - $this->request = $request; |
|
145 | - } |
|
146 | - |
|
147 | - |
|
148 | - /** |
|
149 | - * @param LegacyRequestInterface $legacy_request |
|
150 | - */ |
|
151 | - public function setLegacyRequest(LegacyRequestInterface $legacy_request) |
|
152 | - { |
|
153 | - $this->legacy_request = $legacy_request; |
|
154 | - } |
|
155 | - |
|
156 | - |
|
157 | - /** |
|
158 | - * @param ResponseInterface $response |
|
159 | - */ |
|
160 | - public function setResponse(ResponseInterface $response) |
|
161 | - { |
|
162 | - $this->response = $response; |
|
163 | - } |
|
164 | - |
|
165 | - |
|
166 | - |
|
167 | - /** |
|
168 | - * @param LoaderInterface $loader |
|
169 | - */ |
|
170 | - public function setLoader(LoaderInterface $loader) |
|
171 | - { |
|
172 | - $this->loader = $loader; |
|
173 | - } |
|
174 | - |
|
175 | - |
|
176 | - |
|
177 | - /** |
|
178 | - * @param string $class |
|
179 | - * @param array $dependencies |
|
180 | - * @param int $overwrite |
|
181 | - * @return bool |
|
182 | - */ |
|
183 | - public static function register_dependencies( |
|
184 | - $class, |
|
185 | - array $dependencies, |
|
186 | - $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES |
|
187 | - ) { |
|
188 | - return self::$_instance->registerDependencies($class, $dependencies, $overwrite); |
|
189 | - } |
|
190 | - |
|
191 | - |
|
192 | - |
|
193 | - /** |
|
194 | - * Assigns an array of class names and corresponding load sources (new or cached) |
|
195 | - * to the class specified by the first parameter. |
|
196 | - * IMPORTANT !!! |
|
197 | - * The order of elements in the incoming $dependencies array MUST match |
|
198 | - * the order of the constructor parameters for the class in question. |
|
199 | - * This is especially important when overriding any existing dependencies that are registered. |
|
200 | - * the third parameter controls whether any duplicate dependencies are overwritten or not. |
|
201 | - * |
|
202 | - * @param string $class |
|
203 | - * @param array $dependencies |
|
204 | - * @param int $overwrite |
|
205 | - * @return bool |
|
206 | - */ |
|
207 | - public function registerDependencies( |
|
208 | - $class, |
|
209 | - array $dependencies, |
|
210 | - $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES |
|
211 | - ) { |
|
212 | - $class = trim($class, '\\'); |
|
213 | - $registered = false; |
|
214 | - if (empty(self::$_instance->_dependency_map[ $class ])) { |
|
215 | - self::$_instance->_dependency_map[ $class ] = array(); |
|
216 | - } |
|
217 | - // we need to make sure that any aliases used when registering a dependency |
|
218 | - // get resolved to the correct class name |
|
219 | - foreach ($dependencies as $dependency => $load_source) { |
|
220 | - $alias = self::$_instance->get_alias($dependency); |
|
221 | - if ( |
|
222 | - $overwrite === EE_Dependency_Map::OVERWRITE_DEPENDENCIES |
|
223 | - || ! isset(self::$_instance->_dependency_map[ $class ][ $alias ]) |
|
224 | - ) { |
|
225 | - unset($dependencies[$dependency]); |
|
226 | - $dependencies[$alias] = $load_source; |
|
227 | - $registered = true; |
|
228 | - } |
|
229 | - } |
|
230 | - // now add our two lists of dependencies together. |
|
231 | - // using Union (+=) favours the arrays in precedence from left to right, |
|
232 | - // so $dependencies is NOT overwritten because it is listed first |
|
233 | - // ie: with A = B + C, entries in B take precedence over duplicate entries in C |
|
234 | - // Union is way faster than array_merge() but should be used with caution... |
|
235 | - // especially with numerically indexed arrays |
|
236 | - $dependencies += self::$_instance->_dependency_map[ $class ]; |
|
237 | - // now we need to ensure that the resulting dependencies |
|
238 | - // array only has the entries that are required for the class |
|
239 | - // so first count how many dependencies were originally registered for the class |
|
240 | - $dependency_count = count(self::$_instance->_dependency_map[ $class ]); |
|
241 | - // if that count is non-zero (meaning dependencies were already registered) |
|
242 | - self::$_instance->_dependency_map[ $class ] = $dependency_count |
|
243 | - // then truncate the final array to match that count |
|
244 | - ? array_slice($dependencies, 0, $dependency_count) |
|
245 | - // otherwise just take the incoming array because nothing previously existed |
|
246 | - : $dependencies; |
|
247 | - return $registered; |
|
248 | - } |
|
249 | - |
|
250 | - |
|
251 | - |
|
252 | - /** |
|
253 | - * @param string $class_name |
|
254 | - * @param string $loader |
|
255 | - * @return bool |
|
256 | - * @throws DomainException |
|
257 | - */ |
|
258 | - public static function register_class_loader($class_name, $loader = 'load_core') |
|
259 | - { |
|
260 | - if (! $loader instanceof Closure && strpos($class_name, '\\') !== false) { |
|
261 | - throw new DomainException( |
|
262 | - esc_html__('Don\'t use class loaders for FQCNs.', 'event_espresso') |
|
263 | - ); |
|
264 | - } |
|
265 | - // check that loader is callable or method starts with "load_" and exists in EE_Registry |
|
266 | - if ( |
|
267 | - ! is_callable($loader) |
|
268 | - && ( |
|
269 | - strpos($loader, 'load_') !== 0 |
|
270 | - || ! method_exists('EE_Registry', $loader) |
|
271 | - ) |
|
272 | - ) { |
|
273 | - throw new DomainException( |
|
274 | - sprintf( |
|
275 | - esc_html__( |
|
276 | - '"%1$s" is not a valid loader method on EE_Registry.', |
|
277 | - 'event_espresso' |
|
278 | - ), |
|
279 | - $loader |
|
280 | - ) |
|
281 | - ); |
|
282 | - } |
|
283 | - $class_name = self::$_instance->get_alias($class_name); |
|
284 | - if (! isset(self::$_instance->_class_loaders[$class_name])) { |
|
285 | - self::$_instance->_class_loaders[$class_name] = $loader; |
|
286 | - return true; |
|
287 | - } |
|
288 | - return false; |
|
289 | - } |
|
290 | - |
|
291 | - |
|
292 | - |
|
293 | - /** |
|
294 | - * @return array |
|
295 | - */ |
|
296 | - public function dependency_map() |
|
297 | - { |
|
298 | - return $this->_dependency_map; |
|
299 | - } |
|
300 | - |
|
301 | - |
|
302 | - |
|
303 | - /** |
|
304 | - * returns TRUE if dependency map contains a listing for the provided class name |
|
305 | - * |
|
306 | - * @param string $class_name |
|
307 | - * @return boolean |
|
308 | - */ |
|
309 | - public function has($class_name = '') |
|
310 | - { |
|
311 | - // all legacy models have the same dependencies |
|
312 | - if (strpos($class_name, 'EEM_') === 0) { |
|
313 | - $class_name = 'LEGACY_MODELS'; |
|
314 | - } |
|
315 | - return isset($this->_dependency_map[$class_name]) ? true : false; |
|
316 | - } |
|
317 | - |
|
318 | - |
|
319 | - |
|
320 | - /** |
|
321 | - * returns TRUE if dependency map contains a listing for the provided class name AND dependency |
|
322 | - * |
|
323 | - * @param string $class_name |
|
324 | - * @param string $dependency |
|
325 | - * @return bool |
|
326 | - */ |
|
327 | - public function has_dependency_for_class($class_name = '', $dependency = '') |
|
328 | - { |
|
329 | - // all legacy models have the same dependencies |
|
330 | - if (strpos($class_name, 'EEM_') === 0) { |
|
331 | - $class_name = 'LEGACY_MODELS'; |
|
332 | - } |
|
333 | - $dependency = $this->get_alias($dependency); |
|
334 | - return isset($this->_dependency_map[$class_name][$dependency]) |
|
335 | - ? true |
|
336 | - : false; |
|
337 | - } |
|
338 | - |
|
339 | - |
|
340 | - |
|
341 | - /** |
|
342 | - * returns loading strategy for whether a previously cached dependency should be loaded or a new instance returned |
|
343 | - * |
|
344 | - * @param string $class_name |
|
345 | - * @param string $dependency |
|
346 | - * @return int |
|
347 | - */ |
|
348 | - public function loading_strategy_for_class_dependency($class_name = '', $dependency = '') |
|
349 | - { |
|
350 | - // all legacy models have the same dependencies |
|
351 | - if (strpos($class_name, 'EEM_') === 0) { |
|
352 | - $class_name = 'LEGACY_MODELS'; |
|
353 | - } |
|
354 | - $dependency = $this->get_alias($dependency); |
|
355 | - return $this->has_dependency_for_class($class_name, $dependency) |
|
356 | - ? $this->_dependency_map[$class_name][$dependency] |
|
357 | - : EE_Dependency_Map::not_registered; |
|
358 | - } |
|
359 | - |
|
360 | - |
|
361 | - |
|
362 | - /** |
|
363 | - * @param string $class_name |
|
364 | - * @return string | Closure |
|
365 | - */ |
|
366 | - public function class_loader($class_name) |
|
367 | - { |
|
368 | - // all legacy models use load_model() |
|
369 | - if(strpos($class_name, 'EEM_') === 0){ |
|
370 | - return 'load_model'; |
|
371 | - } |
|
372 | - $class_name = $this->get_alias($class_name); |
|
373 | - return isset($this->_class_loaders[$class_name]) ? $this->_class_loaders[$class_name] : ''; |
|
374 | - } |
|
375 | - |
|
376 | - |
|
377 | - |
|
378 | - /** |
|
379 | - * @return array |
|
380 | - */ |
|
381 | - public function class_loaders() |
|
382 | - { |
|
383 | - return $this->_class_loaders; |
|
384 | - } |
|
385 | - |
|
386 | - |
|
387 | - |
|
388 | - /** |
|
389 | - * adds an alias for a classname |
|
390 | - * |
|
391 | - * @param string $class_name the class name that should be used (concrete class to replace interface) |
|
392 | - * @param string $alias the class name that would be type hinted for (abstract parent or interface) |
|
393 | - * @param string $for_class the class that has the dependency (is type hinting for the interface) |
|
394 | - */ |
|
395 | - public function add_alias($class_name, $alias, $for_class = '') |
|
396 | - { |
|
397 | - if ($for_class !== '') { |
|
398 | - if (! isset($this->_aliases[$for_class])) { |
|
399 | - $this->_aliases[$for_class] = array(); |
|
400 | - } |
|
401 | - $this->_aliases[$for_class][$class_name] = $alias; |
|
402 | - } |
|
403 | - $this->_aliases[$class_name] = $alias; |
|
404 | - } |
|
405 | - |
|
406 | - |
|
407 | - |
|
408 | - /** |
|
409 | - * returns TRUE if the provided class name has an alias |
|
410 | - * |
|
411 | - * @param string $class_name |
|
412 | - * @param string $for_class |
|
413 | - * @return bool |
|
414 | - */ |
|
415 | - public function has_alias($class_name = '', $for_class = '') |
|
416 | - { |
|
417 | - return isset($this->_aliases[$for_class][$class_name]) |
|
418 | - || ( |
|
419 | - isset($this->_aliases[$class_name]) |
|
420 | - && ! is_array($this->_aliases[$class_name]) |
|
421 | - ); |
|
422 | - } |
|
423 | - |
|
424 | - |
|
425 | - |
|
426 | - /** |
|
427 | - * returns alias for class name if one exists, otherwise returns the original classname |
|
428 | - * functions recursively, so that multiple aliases can be used to drill down to a classname |
|
429 | - * for example: |
|
430 | - * if the following two entries were added to the _aliases array: |
|
431 | - * array( |
|
432 | - * 'interface_alias' => 'some\namespace\interface' |
|
433 | - * 'some\namespace\interface' => 'some\namespace\classname' |
|
434 | - * ) |
|
435 | - * then one could use EE_Registry::instance()->create( 'interface_alias' ) |
|
436 | - * to load an instance of 'some\namespace\classname' |
|
437 | - * |
|
438 | - * @param string $class_name |
|
439 | - * @param string $for_class |
|
440 | - * @return string |
|
441 | - */ |
|
442 | - public function get_alias($class_name = '', $for_class = '') |
|
443 | - { |
|
444 | - if (! $this->has_alias($class_name, $for_class)) { |
|
445 | - return $class_name; |
|
446 | - } |
|
447 | - if ($for_class !== '' && isset($this->_aliases[ $for_class ][ $class_name ])) { |
|
448 | - return $this->get_alias($this->_aliases[$for_class][$class_name], $for_class); |
|
449 | - } |
|
450 | - return $this->get_alias($this->_aliases[$class_name]); |
|
451 | - } |
|
452 | - |
|
453 | - |
|
454 | - |
|
455 | - /** |
|
456 | - * Registers the core dependencies and whether a previously instantiated object should be loaded from the cache, |
|
457 | - * if one exists, or whether a new object should be generated every time the requested class is loaded. |
|
458 | - * This is done by using the following class constants: |
|
459 | - * EE_Dependency_Map::load_from_cache - loads previously instantiated object |
|
460 | - * EE_Dependency_Map::load_new_object - generates a new object every time |
|
461 | - */ |
|
462 | - protected function _register_core_dependencies() |
|
463 | - { |
|
464 | - $this->_dependency_map = array( |
|
465 | - 'EE_Request_Handler' => array( |
|
466 | - 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
467 | - ), |
|
468 | - 'EE_System' => array( |
|
469 | - 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
470 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
471 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
472 | - 'EE_Maintenance_Mode' => EE_Dependency_Map::load_from_cache, |
|
473 | - ), |
|
474 | - 'EE_Session' => array( |
|
475 | - 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
476 | - 'EventEspresso\core\domain\values\session\SessionLifespan' => EE_Dependency_Map::load_from_cache, |
|
477 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
478 | - 'EE_Encryption' => EE_Dependency_Map::load_from_cache, |
|
479 | - ), |
|
480 | - 'EE_Cart' => array( |
|
481 | - 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
482 | - ), |
|
483 | - 'EE_Front_Controller' => array( |
|
484 | - 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
485 | - 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
486 | - 'EE_Module_Request_Router' => EE_Dependency_Map::load_from_cache, |
|
487 | - ), |
|
488 | - 'EE_Messenger_Collection_Loader' => array( |
|
489 | - 'EE_Messenger_Collection' => EE_Dependency_Map::load_new_object, |
|
490 | - ), |
|
491 | - 'EE_Message_Type_Collection_Loader' => array( |
|
492 | - 'EE_Message_Type_Collection' => EE_Dependency_Map::load_new_object, |
|
493 | - ), |
|
494 | - 'EE_Message_Resource_Manager' => array( |
|
495 | - 'EE_Messenger_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
496 | - 'EE_Message_Type_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
497 | - 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
498 | - ), |
|
499 | - 'EE_Message_Factory' => array( |
|
500 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
501 | - ), |
|
502 | - 'EE_messages' => array( |
|
503 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
504 | - ), |
|
505 | - 'EE_Messages_Generator' => array( |
|
506 | - 'EE_Messages_Queue' => EE_Dependency_Map::load_new_object, |
|
507 | - 'EE_Messages_Data_Handler_Collection' => EE_Dependency_Map::load_new_object, |
|
508 | - 'EE_Message_Template_Group_Collection' => EE_Dependency_Map::load_new_object, |
|
509 | - 'EEH_Parse_Shortcodes' => EE_Dependency_Map::load_from_cache, |
|
510 | - ), |
|
511 | - 'EE_Messages_Processor' => array( |
|
512 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
513 | - ), |
|
514 | - 'EE_Messages_Queue' => array( |
|
515 | - 'EE_Message_Repository' => EE_Dependency_Map::load_new_object, |
|
516 | - ), |
|
517 | - 'EE_Messages_Template_Defaults' => array( |
|
518 | - 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
519 | - 'EEM_Message_Template' => EE_Dependency_Map::load_from_cache, |
|
520 | - ), |
|
521 | - 'EE_Message_To_Generate_From_Request' => array( |
|
522 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
523 | - 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
524 | - ), |
|
525 | - 'EventEspresso\core\services\commands\CommandBus' => array( |
|
526 | - 'EventEspresso\core\services\commands\CommandHandlerManager' => EE_Dependency_Map::load_from_cache, |
|
527 | - ), |
|
528 | - 'EventEspresso\services\commands\CommandHandler' => array( |
|
529 | - 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
530 | - 'CommandBusInterface' => EE_Dependency_Map::load_from_cache, |
|
531 | - ), |
|
532 | - 'EventEspresso\core\services\commands\CommandHandlerManager' => array( |
|
533 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
534 | - ), |
|
535 | - 'EventEspresso\core\services\commands\CompositeCommandHandler' => array( |
|
536 | - 'EventEspresso\core\services\commands\CommandBus' => EE_Dependency_Map::load_from_cache, |
|
537 | - 'EventEspresso\core\services\commands\CommandFactory' => EE_Dependency_Map::load_from_cache, |
|
538 | - ), |
|
539 | - 'EventEspresso\core\services\commands\CommandFactory' => array( |
|
540 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
541 | - ), |
|
542 | - 'EventEspresso\core\services\commands\middleware\CapChecker' => array( |
|
543 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, |
|
544 | - ), |
|
545 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => array( |
|
546 | - 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
547 | - ), |
|
548 | - 'EventEspresso\core\domain\services\capabilities\RegistrationsCapChecker' => array( |
|
549 | - 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
550 | - ), |
|
551 | - 'EventEspresso\core\services\commands\registration\CreateRegistrationCommandHandler' => array( |
|
552 | - 'EventEspresso\core\domain\services\registration\CreateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
553 | - ), |
|
554 | - 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommandHandler' => array( |
|
555 | - 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
556 | - ), |
|
557 | - 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommandHandler' => array( |
|
558 | - 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
559 | - ), |
|
560 | - 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler' => array( |
|
561 | - 'EventEspresso\core\domain\services\registration\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
562 | - ), |
|
563 | - 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler' => array( |
|
564 | - 'EventEspresso\core\domain\services\registration\UpdateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
565 | - ), |
|
566 | - 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommandHandler' => array( |
|
567 | - 'EventEspresso\core\domain\services\ticket\CreateTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
568 | - ), |
|
569 | - 'EventEspresso\core\services\commands\ticket\CancelTicketLineItemCommandHandler' => array( |
|
570 | - 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
571 | - ), |
|
572 | - 'EventEspresso\core\domain\services\registration\CancelRegistrationService' => array( |
|
573 | - 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
574 | - ), |
|
575 | - 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler' => array( |
|
576 | - 'EEM_Attendee' => EE_Dependency_Map::load_from_cache, |
|
577 | - ), |
|
578 | - 'EventEspresso\core\services\database\TableManager' => array( |
|
579 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
580 | - ), |
|
581 | - 'EE_Data_Migration_Class_Base' => array( |
|
582 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
583 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
584 | - ), |
|
585 | - 'EE_DMS_Core_4_1_0' => array( |
|
586 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
587 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
588 | - ), |
|
589 | - 'EE_DMS_Core_4_2_0' => array( |
|
590 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
591 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
592 | - ), |
|
593 | - 'EE_DMS_Core_4_3_0' => array( |
|
594 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
595 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
596 | - ), |
|
597 | - 'EE_DMS_Core_4_4_0' => array( |
|
598 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
599 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
600 | - ), |
|
601 | - 'EE_DMS_Core_4_5_0' => array( |
|
602 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
603 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
604 | - ), |
|
605 | - 'EE_DMS_Core_4_6_0' => array( |
|
606 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
607 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
608 | - ), |
|
609 | - 'EE_DMS_Core_4_7_0' => array( |
|
610 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
611 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
612 | - ), |
|
613 | - 'EE_DMS_Core_4_8_0' => array( |
|
614 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
615 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
616 | - ), |
|
617 | - 'EE_DMS_Core_4_9_0' => array( |
|
618 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
619 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
620 | - ), |
|
621 | - 'EventEspresso\core\services\assets\Registry' => array( |
|
622 | - 'EE_Template_Config' => EE_Dependency_Map::load_from_cache, |
|
623 | - 'EE_Currency_Config' => EE_Dependency_Map::load_from_cache, |
|
624 | - 'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache |
|
625 | - ), |
|
626 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoCancelled' => array( |
|
627 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
628 | - ), |
|
629 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoCheckout' => array( |
|
630 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
631 | - ), |
|
632 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoEventAttendees' => array( |
|
633 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
634 | - ), |
|
635 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoEvents' => array( |
|
636 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
637 | - ), |
|
638 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoThankYou' => array( |
|
639 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
640 | - ), |
|
641 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoTicketSelector' => array( |
|
642 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
643 | - ), |
|
644 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoTxnPage' => array( |
|
645 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
646 | - ), |
|
647 | - 'EventEspresso\core\services\cache\BasicCacheManager' => array( |
|
648 | - 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
649 | - ), |
|
650 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => array( |
|
651 | - 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
652 | - ), |
|
653 | - 'EventEspresso\core\domain\services\validation\email\EmailValidationService' => array( |
|
654 | - 'EE_Registration_Config' => EE_Dependency_Map::load_from_cache, |
|
655 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
656 | - ), |
|
657 | - 'EventEspresso\core\domain\values\EmailAddress' => array( |
|
658 | - null, |
|
659 | - 'EventEspresso\core\domain\services\validation\email\EmailValidationService' => EE_Dependency_Map::load_from_cache, |
|
660 | - ), |
|
661 | - 'EventEspresso\core\services\orm\ModelFieldFactory' => array( |
|
662 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
663 | - ), |
|
664 | - 'LEGACY_MODELS' => array( |
|
665 | - null, |
|
666 | - 'EventEspresso\core\services\database\ModelFieldFactory' => EE_Dependency_Map::load_from_cache, |
|
667 | - ), |
|
668 | - 'EE_Module_Request_Router' => array( |
|
669 | - 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
670 | - ), |
|
671 | - 'EE_Registration_Processor' => array( |
|
672 | - 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
673 | - ), |
|
674 | - 'EventEspresso\core\services\notifications\PersistentAdminNoticeManager' => array( |
|
675 | - null, |
|
676 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, |
|
677 | - 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
678 | - ), |
|
679 | - 'EE_Admin_Transactions_List_Table' => array( |
|
680 | - null, |
|
681 | - 'EventEspresso\core\domain\values\session\SessionLifespan' => EE_Dependency_Map::load_from_cache, |
|
682 | - ), |
|
683 | - 'EventEspresso\core\domain\services\admin\ExitModal' => array( |
|
684 | - 'EventEspresso\core\services\assets\Registry' => EE_Dependency_Map::load_from_cache |
|
685 | - ), |
|
686 | - 'EventEspresso\core\domain\services\admin\PluginUpsells' => array( |
|
687 | - 'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache |
|
688 | - ), |
|
689 | - 'EventEspresso\caffeinated\modules\recaptcha_invisible\InvisibleRecaptcha' => array( |
|
690 | - 'EE_Registration_Config' => EE_Dependency_Map::load_from_cache, |
|
691 | - 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
692 | - ), |
|
693 | - 'EventEspresso\caffeinated\modules\recaptcha_invisible\RecaptchaAdminSettings' => array( |
|
694 | - 'EE_Registration_Config' => EE_Dependency_Map::load_from_cache, |
|
695 | - ), |
|
696 | - 'EventEspresso\modules\ticket_selector\ProcessTicketSelector' => array( |
|
697 | - 'EE_Core_Config' => EE_Dependency_Map::load_from_cache, |
|
698 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
699 | - 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
700 | - 'EEM_Ticket' => EE_Dependency_Map::load_from_cache, |
|
701 | - 'EventEspresso\modules\ticket_selector\TicketDatetimeAvailabilityTracker' => EE_Dependency_Map::load_from_cache, |
|
702 | - ), |
|
703 | - 'EventEspresso\modules\ticket_selector\TicketDatetimeAvailabilityTracker' => array( |
|
704 | - 'EEM_Datetime' => EE_Dependency_Map::load_from_cache, |
|
705 | - ), |
|
706 | - ); |
|
707 | - } |
|
708 | - |
|
709 | - |
|
710 | - |
|
711 | - /** |
|
712 | - * Registers how core classes are loaded. |
|
713 | - * This can either be done by simply providing the name of one of the EE_Registry loader methods such as: |
|
714 | - * 'EE_Request_Handler' => 'load_core' |
|
715 | - * 'EE_Messages_Queue' => 'load_lib' |
|
716 | - * 'EEH_Debug_Tools' => 'load_helper' |
|
717 | - * or, if greater control is required, by providing a custom closure. For example: |
|
718 | - * 'Some_Class' => function () { |
|
719 | - * return new Some_Class(); |
|
720 | - * }, |
|
721 | - * This is required for instantiating dependencies |
|
722 | - * where an interface has been type hinted in a class constructor. For example: |
|
723 | - * 'Required_Interface' => function () { |
|
724 | - * return new A_Class_That_Implements_Required_Interface(); |
|
725 | - * }, |
|
726 | - * |
|
727 | - * @throws InvalidInterfaceException |
|
728 | - * @throws InvalidDataTypeException |
|
729 | - * @throws InvalidArgumentException |
|
730 | - */ |
|
731 | - protected function _register_core_class_loaders() |
|
732 | - { |
|
733 | - //for PHP5.3 compat, we need to register any properties called here in a variable because `$this` cannot |
|
734 | - //be used in a closure. |
|
735 | - $request = &$this->request; |
|
736 | - $response = &$this->response; |
|
737 | - $legacy_request = &$this->legacy_request; |
|
738 | - // $loader = &$this->loader; |
|
739 | - $this->_class_loaders = array( |
|
740 | - //load_core |
|
741 | - 'EE_Capabilities' => 'load_core', |
|
742 | - 'EE_Encryption' => 'load_core', |
|
743 | - 'EE_Front_Controller' => 'load_core', |
|
744 | - 'EE_Module_Request_Router' => 'load_core', |
|
745 | - 'EE_Registry' => 'load_core', |
|
746 | - 'EE_Request' => function () use (&$legacy_request) { |
|
747 | - return $legacy_request; |
|
748 | - }, |
|
749 | - 'EventEspresso\core\services\request\Request' => function () use (&$request) { |
|
750 | - return $request; |
|
751 | - }, |
|
752 | - 'EventEspresso\core\services\request\Response' => function () use (&$response) { |
|
753 | - return $response; |
|
754 | - }, |
|
755 | - 'EE_Request_Handler' => 'load_core', |
|
756 | - 'EE_Session' => 'load_core', |
|
757 | - 'EE_Cron_Tasks' => 'load_core', |
|
758 | - 'EE_System' => 'load_core', |
|
759 | - 'EE_Maintenance_Mode' => 'load_core', |
|
760 | - 'EE_Register_CPTs' => 'load_core', |
|
761 | - 'EE_Admin' => 'load_core', |
|
762 | - //load_lib |
|
763 | - 'EE_Message_Resource_Manager' => 'load_lib', |
|
764 | - 'EE_Message_Type_Collection' => 'load_lib', |
|
765 | - 'EE_Message_Type_Collection_Loader' => 'load_lib', |
|
766 | - 'EE_Messenger_Collection' => 'load_lib', |
|
767 | - 'EE_Messenger_Collection_Loader' => 'load_lib', |
|
768 | - 'EE_Messages_Processor' => 'load_lib', |
|
769 | - 'EE_Message_Repository' => 'load_lib', |
|
770 | - 'EE_Messages_Queue' => 'load_lib', |
|
771 | - 'EE_Messages_Data_Handler_Collection' => 'load_lib', |
|
772 | - 'EE_Message_Template_Group_Collection' => 'load_lib', |
|
773 | - 'EE_Payment_Method_Manager' => 'load_lib', |
|
774 | - 'EE_Messages_Generator' => function () { |
|
775 | - return EE_Registry::instance()->load_lib( |
|
776 | - 'Messages_Generator', |
|
777 | - array(), |
|
778 | - false, |
|
779 | - false |
|
780 | - ); |
|
781 | - }, |
|
782 | - 'EE_Messages_Template_Defaults' => function ($arguments = array()) { |
|
783 | - return EE_Registry::instance()->load_lib( |
|
784 | - 'Messages_Template_Defaults', |
|
785 | - $arguments, |
|
786 | - false, |
|
787 | - false |
|
788 | - ); |
|
789 | - }, |
|
790 | - //load_model |
|
791 | - // 'EEM_Attendee' => 'load_model', |
|
792 | - // 'EEM_Message_Template_Group' => 'load_model', |
|
793 | - // 'EEM_Message_Template' => 'load_model', |
|
794 | - //load_helper |
|
795 | - 'EEH_Parse_Shortcodes' => function () { |
|
796 | - if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) { |
|
797 | - return new EEH_Parse_Shortcodes(); |
|
798 | - } |
|
799 | - return null; |
|
800 | - }, |
|
801 | - 'EE_Template_Config' => function () { |
|
802 | - return EE_Config::instance()->template_settings; |
|
803 | - }, |
|
804 | - 'EE_Currency_Config' => function () { |
|
805 | - return EE_Config::instance()->currency; |
|
806 | - }, |
|
807 | - 'EE_Registration_Config' => function () { |
|
808 | - return EE_Config::instance()->registration; |
|
809 | - }, |
|
810 | - 'EE_Core_Config' => function () { |
|
811 | - return EE_Config::instance()->core; |
|
812 | - }, |
|
813 | - 'EventEspresso\core\services\loaders\Loader' => function () { |
|
814 | - return LoaderFactory::getLoader(); |
|
815 | - }, |
|
816 | - ); |
|
817 | - } |
|
818 | - |
|
819 | - |
|
820 | - |
|
821 | - /** |
|
822 | - * can be used for supplying alternate names for classes, |
|
823 | - * or for connecting interface names to instantiable classes |
|
824 | - */ |
|
825 | - protected function _register_core_aliases() |
|
826 | - { |
|
827 | - $this->_aliases = array( |
|
828 | - 'CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBusInterface', |
|
829 | - 'EventEspresso\core\services\commands\CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBus', |
|
830 | - 'CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManagerInterface', |
|
831 | - 'EventEspresso\core\services\commands\CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManager', |
|
832 | - 'CapChecker' => 'EventEspresso\core\services\commands\middleware\CapChecker', |
|
833 | - 'AddActionHook' => 'EventEspresso\core\services\commands\middleware\AddActionHook', |
|
834 | - 'CapabilitiesChecker' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
835 | - 'CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface', |
|
836 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
837 | - 'CreateRegistrationService' => 'EventEspresso\core\domain\services\registration\CreateRegistrationService', |
|
838 | - 'CreateRegCodeCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegCodeCommand', |
|
839 | - 'CreateRegUrlLinkCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegUrlLinkCommand', |
|
840 | - 'CreateRegistrationCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand', |
|
841 | - 'CopyRegistrationDetailsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommand', |
|
842 | - 'CopyRegistrationPaymentsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommand', |
|
843 | - 'CancelRegistrationAndTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler', |
|
844 | - 'UpdateRegistrationAndTransactionAfterChangeCommandHandler' => 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler', |
|
845 | - 'CreateTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommand', |
|
846 | - 'CreateTransactionCommandHandler' => 'EventEspresso\core\services\commands\transaction\CreateTransactionCommandHandler', |
|
847 | - 'CreateAttendeeCommandHandler' => 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler', |
|
848 | - 'TableManager' => 'EventEspresso\core\services\database\TableManager', |
|
849 | - 'TableAnalysis' => 'EventEspresso\core\services\database\TableAnalysis', |
|
850 | - 'EspressoShortcode' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
851 | - 'ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\ShortcodeInterface', |
|
852 | - 'EventEspresso\core\services\shortcodes\ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
853 | - 'EventEspresso\core\services\cache\CacheStorageInterface' => 'EventEspresso\core\services\cache\TransientCacheStorage', |
|
854 | - 'LoaderInterface' => 'EventEspresso\core\services\loaders\LoaderInterface', |
|
855 | - 'EventEspresso\core\services\loaders\LoaderInterface' => 'EventEspresso\core\services\loaders\Loader', |
|
856 | - 'CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactoryInterface', |
|
857 | - 'EventEspresso\core\services\commands\CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactory', |
|
858 | - 'EventEspresso\core\domain\services\session\SessionIdentifierInterface' => 'EE_Session', |
|
859 | - 'EmailValidatorInterface' => 'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface', |
|
860 | - 'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface' => 'EventEspresso\core\domain\services\validation\email\EmailValidationService', |
|
861 | - 'NoticeConverterInterface' => 'EventEspresso\core\services\notices\NoticeConverterInterface', |
|
862 | - 'EventEspresso\core\services\notices\NoticeConverterInterface' => 'EventEspresso\core\services\notices\ConvertNoticesToEeErrors', |
|
863 | - 'NoticesContainerInterface' => 'EventEspresso\core\services\notices\NoticesContainerInterface', |
|
864 | - 'EventEspresso\core\services\notices\NoticesContainerInterface' => 'EventEspresso\core\services\notices\NoticesContainer', |
|
865 | - 'EventEspresso\core\services\request\RequestInterface' => 'EventEspresso\core\services\request\Request', |
|
866 | - 'EventEspresso\core\services\request\ResponseInterface' => 'EventEspresso\core\services\request\Response', |
|
867 | - 'EventEspresso\core\domain\DomainInterface' => 'EventEspresso\core\domain\Domain', |
|
868 | - ); |
|
869 | - if (! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) { |
|
870 | - $this->_aliases['EventEspresso\core\services\notices\NoticeConverterInterface'] = 'EventEspresso\core\services\notices\ConvertNoticesToAdminNotices'; |
|
871 | - } |
|
872 | - } |
|
873 | - |
|
874 | - |
|
875 | - |
|
876 | - /** |
|
877 | - * This is used to reset the internal map and class_loaders to their original default state at the beginning of the |
|
878 | - * request Primarily used by unit tests. |
|
879 | - * |
|
880 | - * @throws InvalidDataTypeException |
|
881 | - * @throws InvalidInterfaceException |
|
882 | - * @throws InvalidArgumentException |
|
883 | - */ |
|
884 | - public function reset() |
|
885 | - { |
|
886 | - $this->_register_core_class_loaders(); |
|
887 | - $this->_register_core_dependencies(); |
|
888 | - } |
|
28 | + /** |
|
29 | + * This means that the requested class dependency is not present in the dependency map |
|
30 | + */ |
|
31 | + const not_registered = 0; |
|
32 | + |
|
33 | + /** |
|
34 | + * This instructs class loaders to ALWAYS return a newly instantiated object for the requested class. |
|
35 | + */ |
|
36 | + const load_new_object = 1; |
|
37 | + |
|
38 | + /** |
|
39 | + * This instructs class loaders to return a previously instantiated and cached object for the requested class. |
|
40 | + * IF a previously instantiated object does not exist, a new one will be created and added to the cache. |
|
41 | + */ |
|
42 | + const load_from_cache = 2; |
|
43 | + |
|
44 | + /** |
|
45 | + * When registering a dependency, |
|
46 | + * this indicates to keep any existing dependencies that already exist, |
|
47 | + * and simply discard any new dependencies declared in the incoming data |
|
48 | + */ |
|
49 | + const KEEP_EXISTING_DEPENDENCIES = 0; |
|
50 | + |
|
51 | + /** |
|
52 | + * When registering a dependency, |
|
53 | + * this indicates to overwrite any existing dependencies that already exist using the incoming data |
|
54 | + */ |
|
55 | + const OVERWRITE_DEPENDENCIES = 1; |
|
56 | + |
|
57 | + |
|
58 | + |
|
59 | + /** |
|
60 | + * @type EE_Dependency_Map $_instance |
|
61 | + */ |
|
62 | + protected static $_instance; |
|
63 | + |
|
64 | + /** |
|
65 | + * @type RequestInterface $request |
|
66 | + */ |
|
67 | + protected $request; |
|
68 | + |
|
69 | + /** |
|
70 | + * @type LegacyRequestInterface $legacy_request |
|
71 | + */ |
|
72 | + protected $legacy_request; |
|
73 | + |
|
74 | + /** |
|
75 | + * @type ResponseInterface $response |
|
76 | + */ |
|
77 | + protected $response; |
|
78 | + |
|
79 | + /** |
|
80 | + * @type LoaderInterface $loader |
|
81 | + */ |
|
82 | + protected $loader; |
|
83 | + |
|
84 | + /** |
|
85 | + * @type array $_dependency_map |
|
86 | + */ |
|
87 | + protected $_dependency_map = array(); |
|
88 | + |
|
89 | + /** |
|
90 | + * @type array $_class_loaders |
|
91 | + */ |
|
92 | + protected $_class_loaders = array(); |
|
93 | + |
|
94 | + /** |
|
95 | + * @type array $_aliases |
|
96 | + */ |
|
97 | + protected $_aliases = array(); |
|
98 | + |
|
99 | + |
|
100 | + |
|
101 | + /** |
|
102 | + * EE_Dependency_Map constructor. |
|
103 | + */ |
|
104 | + protected function __construct() |
|
105 | + { |
|
106 | + // add_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading', array($this, 'initialize')); |
|
107 | + do_action('EE_Dependency_Map____construct'); |
|
108 | + } |
|
109 | + |
|
110 | + |
|
111 | + |
|
112 | + /** |
|
113 | + * @throws InvalidDataTypeException |
|
114 | + * @throws InvalidInterfaceException |
|
115 | + * @throws InvalidArgumentException |
|
116 | + */ |
|
117 | + public function initialize() |
|
118 | + { |
|
119 | + $this->_register_core_dependencies(); |
|
120 | + $this->_register_core_class_loaders(); |
|
121 | + $this->_register_core_aliases(); |
|
122 | + } |
|
123 | + |
|
124 | + |
|
125 | + |
|
126 | + /** |
|
127 | + * @singleton method used to instantiate class object |
|
128 | + * @return EE_Dependency_Map |
|
129 | + */ |
|
130 | + public static function instance() { |
|
131 | + // check if class object is instantiated, and instantiated properly |
|
132 | + if (! self::$_instance instanceof EE_Dependency_Map) { |
|
133 | + self::$_instance = new EE_Dependency_Map(/*$request, $response, $legacy_request*/); |
|
134 | + } |
|
135 | + return self::$_instance; |
|
136 | + } |
|
137 | + |
|
138 | + |
|
139 | + /** |
|
140 | + * @param RequestInterface $request |
|
141 | + */ |
|
142 | + public function setRequest(RequestInterface $request) |
|
143 | + { |
|
144 | + $this->request = $request; |
|
145 | + } |
|
146 | + |
|
147 | + |
|
148 | + /** |
|
149 | + * @param LegacyRequestInterface $legacy_request |
|
150 | + */ |
|
151 | + public function setLegacyRequest(LegacyRequestInterface $legacy_request) |
|
152 | + { |
|
153 | + $this->legacy_request = $legacy_request; |
|
154 | + } |
|
155 | + |
|
156 | + |
|
157 | + /** |
|
158 | + * @param ResponseInterface $response |
|
159 | + */ |
|
160 | + public function setResponse(ResponseInterface $response) |
|
161 | + { |
|
162 | + $this->response = $response; |
|
163 | + } |
|
164 | + |
|
165 | + |
|
166 | + |
|
167 | + /** |
|
168 | + * @param LoaderInterface $loader |
|
169 | + */ |
|
170 | + public function setLoader(LoaderInterface $loader) |
|
171 | + { |
|
172 | + $this->loader = $loader; |
|
173 | + } |
|
174 | + |
|
175 | + |
|
176 | + |
|
177 | + /** |
|
178 | + * @param string $class |
|
179 | + * @param array $dependencies |
|
180 | + * @param int $overwrite |
|
181 | + * @return bool |
|
182 | + */ |
|
183 | + public static function register_dependencies( |
|
184 | + $class, |
|
185 | + array $dependencies, |
|
186 | + $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES |
|
187 | + ) { |
|
188 | + return self::$_instance->registerDependencies($class, $dependencies, $overwrite); |
|
189 | + } |
|
190 | + |
|
191 | + |
|
192 | + |
|
193 | + /** |
|
194 | + * Assigns an array of class names and corresponding load sources (new or cached) |
|
195 | + * to the class specified by the first parameter. |
|
196 | + * IMPORTANT !!! |
|
197 | + * The order of elements in the incoming $dependencies array MUST match |
|
198 | + * the order of the constructor parameters for the class in question. |
|
199 | + * This is especially important when overriding any existing dependencies that are registered. |
|
200 | + * the third parameter controls whether any duplicate dependencies are overwritten or not. |
|
201 | + * |
|
202 | + * @param string $class |
|
203 | + * @param array $dependencies |
|
204 | + * @param int $overwrite |
|
205 | + * @return bool |
|
206 | + */ |
|
207 | + public function registerDependencies( |
|
208 | + $class, |
|
209 | + array $dependencies, |
|
210 | + $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES |
|
211 | + ) { |
|
212 | + $class = trim($class, '\\'); |
|
213 | + $registered = false; |
|
214 | + if (empty(self::$_instance->_dependency_map[ $class ])) { |
|
215 | + self::$_instance->_dependency_map[ $class ] = array(); |
|
216 | + } |
|
217 | + // we need to make sure that any aliases used when registering a dependency |
|
218 | + // get resolved to the correct class name |
|
219 | + foreach ($dependencies as $dependency => $load_source) { |
|
220 | + $alias = self::$_instance->get_alias($dependency); |
|
221 | + if ( |
|
222 | + $overwrite === EE_Dependency_Map::OVERWRITE_DEPENDENCIES |
|
223 | + || ! isset(self::$_instance->_dependency_map[ $class ][ $alias ]) |
|
224 | + ) { |
|
225 | + unset($dependencies[$dependency]); |
|
226 | + $dependencies[$alias] = $load_source; |
|
227 | + $registered = true; |
|
228 | + } |
|
229 | + } |
|
230 | + // now add our two lists of dependencies together. |
|
231 | + // using Union (+=) favours the arrays in precedence from left to right, |
|
232 | + // so $dependencies is NOT overwritten because it is listed first |
|
233 | + // ie: with A = B + C, entries in B take precedence over duplicate entries in C |
|
234 | + // Union is way faster than array_merge() but should be used with caution... |
|
235 | + // especially with numerically indexed arrays |
|
236 | + $dependencies += self::$_instance->_dependency_map[ $class ]; |
|
237 | + // now we need to ensure that the resulting dependencies |
|
238 | + // array only has the entries that are required for the class |
|
239 | + // so first count how many dependencies were originally registered for the class |
|
240 | + $dependency_count = count(self::$_instance->_dependency_map[ $class ]); |
|
241 | + // if that count is non-zero (meaning dependencies were already registered) |
|
242 | + self::$_instance->_dependency_map[ $class ] = $dependency_count |
|
243 | + // then truncate the final array to match that count |
|
244 | + ? array_slice($dependencies, 0, $dependency_count) |
|
245 | + // otherwise just take the incoming array because nothing previously existed |
|
246 | + : $dependencies; |
|
247 | + return $registered; |
|
248 | + } |
|
249 | + |
|
250 | + |
|
251 | + |
|
252 | + /** |
|
253 | + * @param string $class_name |
|
254 | + * @param string $loader |
|
255 | + * @return bool |
|
256 | + * @throws DomainException |
|
257 | + */ |
|
258 | + public static function register_class_loader($class_name, $loader = 'load_core') |
|
259 | + { |
|
260 | + if (! $loader instanceof Closure && strpos($class_name, '\\') !== false) { |
|
261 | + throw new DomainException( |
|
262 | + esc_html__('Don\'t use class loaders for FQCNs.', 'event_espresso') |
|
263 | + ); |
|
264 | + } |
|
265 | + // check that loader is callable or method starts with "load_" and exists in EE_Registry |
|
266 | + if ( |
|
267 | + ! is_callable($loader) |
|
268 | + && ( |
|
269 | + strpos($loader, 'load_') !== 0 |
|
270 | + || ! method_exists('EE_Registry', $loader) |
|
271 | + ) |
|
272 | + ) { |
|
273 | + throw new DomainException( |
|
274 | + sprintf( |
|
275 | + esc_html__( |
|
276 | + '"%1$s" is not a valid loader method on EE_Registry.', |
|
277 | + 'event_espresso' |
|
278 | + ), |
|
279 | + $loader |
|
280 | + ) |
|
281 | + ); |
|
282 | + } |
|
283 | + $class_name = self::$_instance->get_alias($class_name); |
|
284 | + if (! isset(self::$_instance->_class_loaders[$class_name])) { |
|
285 | + self::$_instance->_class_loaders[$class_name] = $loader; |
|
286 | + return true; |
|
287 | + } |
|
288 | + return false; |
|
289 | + } |
|
290 | + |
|
291 | + |
|
292 | + |
|
293 | + /** |
|
294 | + * @return array |
|
295 | + */ |
|
296 | + public function dependency_map() |
|
297 | + { |
|
298 | + return $this->_dependency_map; |
|
299 | + } |
|
300 | + |
|
301 | + |
|
302 | + |
|
303 | + /** |
|
304 | + * returns TRUE if dependency map contains a listing for the provided class name |
|
305 | + * |
|
306 | + * @param string $class_name |
|
307 | + * @return boolean |
|
308 | + */ |
|
309 | + public function has($class_name = '') |
|
310 | + { |
|
311 | + // all legacy models have the same dependencies |
|
312 | + if (strpos($class_name, 'EEM_') === 0) { |
|
313 | + $class_name = 'LEGACY_MODELS'; |
|
314 | + } |
|
315 | + return isset($this->_dependency_map[$class_name]) ? true : false; |
|
316 | + } |
|
317 | + |
|
318 | + |
|
319 | + |
|
320 | + /** |
|
321 | + * returns TRUE if dependency map contains a listing for the provided class name AND dependency |
|
322 | + * |
|
323 | + * @param string $class_name |
|
324 | + * @param string $dependency |
|
325 | + * @return bool |
|
326 | + */ |
|
327 | + public function has_dependency_for_class($class_name = '', $dependency = '') |
|
328 | + { |
|
329 | + // all legacy models have the same dependencies |
|
330 | + if (strpos($class_name, 'EEM_') === 0) { |
|
331 | + $class_name = 'LEGACY_MODELS'; |
|
332 | + } |
|
333 | + $dependency = $this->get_alias($dependency); |
|
334 | + return isset($this->_dependency_map[$class_name][$dependency]) |
|
335 | + ? true |
|
336 | + : false; |
|
337 | + } |
|
338 | + |
|
339 | + |
|
340 | + |
|
341 | + /** |
|
342 | + * returns loading strategy for whether a previously cached dependency should be loaded or a new instance returned |
|
343 | + * |
|
344 | + * @param string $class_name |
|
345 | + * @param string $dependency |
|
346 | + * @return int |
|
347 | + */ |
|
348 | + public function loading_strategy_for_class_dependency($class_name = '', $dependency = '') |
|
349 | + { |
|
350 | + // all legacy models have the same dependencies |
|
351 | + if (strpos($class_name, 'EEM_') === 0) { |
|
352 | + $class_name = 'LEGACY_MODELS'; |
|
353 | + } |
|
354 | + $dependency = $this->get_alias($dependency); |
|
355 | + return $this->has_dependency_for_class($class_name, $dependency) |
|
356 | + ? $this->_dependency_map[$class_name][$dependency] |
|
357 | + : EE_Dependency_Map::not_registered; |
|
358 | + } |
|
359 | + |
|
360 | + |
|
361 | + |
|
362 | + /** |
|
363 | + * @param string $class_name |
|
364 | + * @return string | Closure |
|
365 | + */ |
|
366 | + public function class_loader($class_name) |
|
367 | + { |
|
368 | + // all legacy models use load_model() |
|
369 | + if(strpos($class_name, 'EEM_') === 0){ |
|
370 | + return 'load_model'; |
|
371 | + } |
|
372 | + $class_name = $this->get_alias($class_name); |
|
373 | + return isset($this->_class_loaders[$class_name]) ? $this->_class_loaders[$class_name] : ''; |
|
374 | + } |
|
375 | + |
|
376 | + |
|
377 | + |
|
378 | + /** |
|
379 | + * @return array |
|
380 | + */ |
|
381 | + public function class_loaders() |
|
382 | + { |
|
383 | + return $this->_class_loaders; |
|
384 | + } |
|
385 | + |
|
386 | + |
|
387 | + |
|
388 | + /** |
|
389 | + * adds an alias for a classname |
|
390 | + * |
|
391 | + * @param string $class_name the class name that should be used (concrete class to replace interface) |
|
392 | + * @param string $alias the class name that would be type hinted for (abstract parent or interface) |
|
393 | + * @param string $for_class the class that has the dependency (is type hinting for the interface) |
|
394 | + */ |
|
395 | + public function add_alias($class_name, $alias, $for_class = '') |
|
396 | + { |
|
397 | + if ($for_class !== '') { |
|
398 | + if (! isset($this->_aliases[$for_class])) { |
|
399 | + $this->_aliases[$for_class] = array(); |
|
400 | + } |
|
401 | + $this->_aliases[$for_class][$class_name] = $alias; |
|
402 | + } |
|
403 | + $this->_aliases[$class_name] = $alias; |
|
404 | + } |
|
405 | + |
|
406 | + |
|
407 | + |
|
408 | + /** |
|
409 | + * returns TRUE if the provided class name has an alias |
|
410 | + * |
|
411 | + * @param string $class_name |
|
412 | + * @param string $for_class |
|
413 | + * @return bool |
|
414 | + */ |
|
415 | + public function has_alias($class_name = '', $for_class = '') |
|
416 | + { |
|
417 | + return isset($this->_aliases[$for_class][$class_name]) |
|
418 | + || ( |
|
419 | + isset($this->_aliases[$class_name]) |
|
420 | + && ! is_array($this->_aliases[$class_name]) |
|
421 | + ); |
|
422 | + } |
|
423 | + |
|
424 | + |
|
425 | + |
|
426 | + /** |
|
427 | + * returns alias for class name if one exists, otherwise returns the original classname |
|
428 | + * functions recursively, so that multiple aliases can be used to drill down to a classname |
|
429 | + * for example: |
|
430 | + * if the following two entries were added to the _aliases array: |
|
431 | + * array( |
|
432 | + * 'interface_alias' => 'some\namespace\interface' |
|
433 | + * 'some\namespace\interface' => 'some\namespace\classname' |
|
434 | + * ) |
|
435 | + * then one could use EE_Registry::instance()->create( 'interface_alias' ) |
|
436 | + * to load an instance of 'some\namespace\classname' |
|
437 | + * |
|
438 | + * @param string $class_name |
|
439 | + * @param string $for_class |
|
440 | + * @return string |
|
441 | + */ |
|
442 | + public function get_alias($class_name = '', $for_class = '') |
|
443 | + { |
|
444 | + if (! $this->has_alias($class_name, $for_class)) { |
|
445 | + return $class_name; |
|
446 | + } |
|
447 | + if ($for_class !== '' && isset($this->_aliases[ $for_class ][ $class_name ])) { |
|
448 | + return $this->get_alias($this->_aliases[$for_class][$class_name], $for_class); |
|
449 | + } |
|
450 | + return $this->get_alias($this->_aliases[$class_name]); |
|
451 | + } |
|
452 | + |
|
453 | + |
|
454 | + |
|
455 | + /** |
|
456 | + * Registers the core dependencies and whether a previously instantiated object should be loaded from the cache, |
|
457 | + * if one exists, or whether a new object should be generated every time the requested class is loaded. |
|
458 | + * This is done by using the following class constants: |
|
459 | + * EE_Dependency_Map::load_from_cache - loads previously instantiated object |
|
460 | + * EE_Dependency_Map::load_new_object - generates a new object every time |
|
461 | + */ |
|
462 | + protected function _register_core_dependencies() |
|
463 | + { |
|
464 | + $this->_dependency_map = array( |
|
465 | + 'EE_Request_Handler' => array( |
|
466 | + 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
467 | + ), |
|
468 | + 'EE_System' => array( |
|
469 | + 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
470 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
471 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
472 | + 'EE_Maintenance_Mode' => EE_Dependency_Map::load_from_cache, |
|
473 | + ), |
|
474 | + 'EE_Session' => array( |
|
475 | + 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
476 | + 'EventEspresso\core\domain\values\session\SessionLifespan' => EE_Dependency_Map::load_from_cache, |
|
477 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
478 | + 'EE_Encryption' => EE_Dependency_Map::load_from_cache, |
|
479 | + ), |
|
480 | + 'EE_Cart' => array( |
|
481 | + 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
482 | + ), |
|
483 | + 'EE_Front_Controller' => array( |
|
484 | + 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
485 | + 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
486 | + 'EE_Module_Request_Router' => EE_Dependency_Map::load_from_cache, |
|
487 | + ), |
|
488 | + 'EE_Messenger_Collection_Loader' => array( |
|
489 | + 'EE_Messenger_Collection' => EE_Dependency_Map::load_new_object, |
|
490 | + ), |
|
491 | + 'EE_Message_Type_Collection_Loader' => array( |
|
492 | + 'EE_Message_Type_Collection' => EE_Dependency_Map::load_new_object, |
|
493 | + ), |
|
494 | + 'EE_Message_Resource_Manager' => array( |
|
495 | + 'EE_Messenger_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
496 | + 'EE_Message_Type_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
497 | + 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
498 | + ), |
|
499 | + 'EE_Message_Factory' => array( |
|
500 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
501 | + ), |
|
502 | + 'EE_messages' => array( |
|
503 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
504 | + ), |
|
505 | + 'EE_Messages_Generator' => array( |
|
506 | + 'EE_Messages_Queue' => EE_Dependency_Map::load_new_object, |
|
507 | + 'EE_Messages_Data_Handler_Collection' => EE_Dependency_Map::load_new_object, |
|
508 | + 'EE_Message_Template_Group_Collection' => EE_Dependency_Map::load_new_object, |
|
509 | + 'EEH_Parse_Shortcodes' => EE_Dependency_Map::load_from_cache, |
|
510 | + ), |
|
511 | + 'EE_Messages_Processor' => array( |
|
512 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
513 | + ), |
|
514 | + 'EE_Messages_Queue' => array( |
|
515 | + 'EE_Message_Repository' => EE_Dependency_Map::load_new_object, |
|
516 | + ), |
|
517 | + 'EE_Messages_Template_Defaults' => array( |
|
518 | + 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
519 | + 'EEM_Message_Template' => EE_Dependency_Map::load_from_cache, |
|
520 | + ), |
|
521 | + 'EE_Message_To_Generate_From_Request' => array( |
|
522 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
523 | + 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
524 | + ), |
|
525 | + 'EventEspresso\core\services\commands\CommandBus' => array( |
|
526 | + 'EventEspresso\core\services\commands\CommandHandlerManager' => EE_Dependency_Map::load_from_cache, |
|
527 | + ), |
|
528 | + 'EventEspresso\services\commands\CommandHandler' => array( |
|
529 | + 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
530 | + 'CommandBusInterface' => EE_Dependency_Map::load_from_cache, |
|
531 | + ), |
|
532 | + 'EventEspresso\core\services\commands\CommandHandlerManager' => array( |
|
533 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
534 | + ), |
|
535 | + 'EventEspresso\core\services\commands\CompositeCommandHandler' => array( |
|
536 | + 'EventEspresso\core\services\commands\CommandBus' => EE_Dependency_Map::load_from_cache, |
|
537 | + 'EventEspresso\core\services\commands\CommandFactory' => EE_Dependency_Map::load_from_cache, |
|
538 | + ), |
|
539 | + 'EventEspresso\core\services\commands\CommandFactory' => array( |
|
540 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
541 | + ), |
|
542 | + 'EventEspresso\core\services\commands\middleware\CapChecker' => array( |
|
543 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, |
|
544 | + ), |
|
545 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => array( |
|
546 | + 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
547 | + ), |
|
548 | + 'EventEspresso\core\domain\services\capabilities\RegistrationsCapChecker' => array( |
|
549 | + 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
550 | + ), |
|
551 | + 'EventEspresso\core\services\commands\registration\CreateRegistrationCommandHandler' => array( |
|
552 | + 'EventEspresso\core\domain\services\registration\CreateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
553 | + ), |
|
554 | + 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommandHandler' => array( |
|
555 | + 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
556 | + ), |
|
557 | + 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommandHandler' => array( |
|
558 | + 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
559 | + ), |
|
560 | + 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler' => array( |
|
561 | + 'EventEspresso\core\domain\services\registration\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
562 | + ), |
|
563 | + 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler' => array( |
|
564 | + 'EventEspresso\core\domain\services\registration\UpdateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
565 | + ), |
|
566 | + 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommandHandler' => array( |
|
567 | + 'EventEspresso\core\domain\services\ticket\CreateTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
568 | + ), |
|
569 | + 'EventEspresso\core\services\commands\ticket\CancelTicketLineItemCommandHandler' => array( |
|
570 | + 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
571 | + ), |
|
572 | + 'EventEspresso\core\domain\services\registration\CancelRegistrationService' => array( |
|
573 | + 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
574 | + ), |
|
575 | + 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler' => array( |
|
576 | + 'EEM_Attendee' => EE_Dependency_Map::load_from_cache, |
|
577 | + ), |
|
578 | + 'EventEspresso\core\services\database\TableManager' => array( |
|
579 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
580 | + ), |
|
581 | + 'EE_Data_Migration_Class_Base' => array( |
|
582 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
583 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
584 | + ), |
|
585 | + 'EE_DMS_Core_4_1_0' => array( |
|
586 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
587 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
588 | + ), |
|
589 | + 'EE_DMS_Core_4_2_0' => array( |
|
590 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
591 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
592 | + ), |
|
593 | + 'EE_DMS_Core_4_3_0' => array( |
|
594 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
595 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
596 | + ), |
|
597 | + 'EE_DMS_Core_4_4_0' => array( |
|
598 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
599 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
600 | + ), |
|
601 | + 'EE_DMS_Core_4_5_0' => array( |
|
602 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
603 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
604 | + ), |
|
605 | + 'EE_DMS_Core_4_6_0' => array( |
|
606 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
607 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
608 | + ), |
|
609 | + 'EE_DMS_Core_4_7_0' => array( |
|
610 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
611 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
612 | + ), |
|
613 | + 'EE_DMS_Core_4_8_0' => array( |
|
614 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
615 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
616 | + ), |
|
617 | + 'EE_DMS_Core_4_9_0' => array( |
|
618 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
619 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
620 | + ), |
|
621 | + 'EventEspresso\core\services\assets\Registry' => array( |
|
622 | + 'EE_Template_Config' => EE_Dependency_Map::load_from_cache, |
|
623 | + 'EE_Currency_Config' => EE_Dependency_Map::load_from_cache, |
|
624 | + 'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache |
|
625 | + ), |
|
626 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoCancelled' => array( |
|
627 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
628 | + ), |
|
629 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoCheckout' => array( |
|
630 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
631 | + ), |
|
632 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoEventAttendees' => array( |
|
633 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
634 | + ), |
|
635 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoEvents' => array( |
|
636 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
637 | + ), |
|
638 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoThankYou' => array( |
|
639 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
640 | + ), |
|
641 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoTicketSelector' => array( |
|
642 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
643 | + ), |
|
644 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoTxnPage' => array( |
|
645 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
646 | + ), |
|
647 | + 'EventEspresso\core\services\cache\BasicCacheManager' => array( |
|
648 | + 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
649 | + ), |
|
650 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => array( |
|
651 | + 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
652 | + ), |
|
653 | + 'EventEspresso\core\domain\services\validation\email\EmailValidationService' => array( |
|
654 | + 'EE_Registration_Config' => EE_Dependency_Map::load_from_cache, |
|
655 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
656 | + ), |
|
657 | + 'EventEspresso\core\domain\values\EmailAddress' => array( |
|
658 | + null, |
|
659 | + 'EventEspresso\core\domain\services\validation\email\EmailValidationService' => EE_Dependency_Map::load_from_cache, |
|
660 | + ), |
|
661 | + 'EventEspresso\core\services\orm\ModelFieldFactory' => array( |
|
662 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
663 | + ), |
|
664 | + 'LEGACY_MODELS' => array( |
|
665 | + null, |
|
666 | + 'EventEspresso\core\services\database\ModelFieldFactory' => EE_Dependency_Map::load_from_cache, |
|
667 | + ), |
|
668 | + 'EE_Module_Request_Router' => array( |
|
669 | + 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
670 | + ), |
|
671 | + 'EE_Registration_Processor' => array( |
|
672 | + 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
673 | + ), |
|
674 | + 'EventEspresso\core\services\notifications\PersistentAdminNoticeManager' => array( |
|
675 | + null, |
|
676 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, |
|
677 | + 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
678 | + ), |
|
679 | + 'EE_Admin_Transactions_List_Table' => array( |
|
680 | + null, |
|
681 | + 'EventEspresso\core\domain\values\session\SessionLifespan' => EE_Dependency_Map::load_from_cache, |
|
682 | + ), |
|
683 | + 'EventEspresso\core\domain\services\admin\ExitModal' => array( |
|
684 | + 'EventEspresso\core\services\assets\Registry' => EE_Dependency_Map::load_from_cache |
|
685 | + ), |
|
686 | + 'EventEspresso\core\domain\services\admin\PluginUpsells' => array( |
|
687 | + 'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache |
|
688 | + ), |
|
689 | + 'EventEspresso\caffeinated\modules\recaptcha_invisible\InvisibleRecaptcha' => array( |
|
690 | + 'EE_Registration_Config' => EE_Dependency_Map::load_from_cache, |
|
691 | + 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
692 | + ), |
|
693 | + 'EventEspresso\caffeinated\modules\recaptcha_invisible\RecaptchaAdminSettings' => array( |
|
694 | + 'EE_Registration_Config' => EE_Dependency_Map::load_from_cache, |
|
695 | + ), |
|
696 | + 'EventEspresso\modules\ticket_selector\ProcessTicketSelector' => array( |
|
697 | + 'EE_Core_Config' => EE_Dependency_Map::load_from_cache, |
|
698 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
699 | + 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
700 | + 'EEM_Ticket' => EE_Dependency_Map::load_from_cache, |
|
701 | + 'EventEspresso\modules\ticket_selector\TicketDatetimeAvailabilityTracker' => EE_Dependency_Map::load_from_cache, |
|
702 | + ), |
|
703 | + 'EventEspresso\modules\ticket_selector\TicketDatetimeAvailabilityTracker' => array( |
|
704 | + 'EEM_Datetime' => EE_Dependency_Map::load_from_cache, |
|
705 | + ), |
|
706 | + ); |
|
707 | + } |
|
708 | + |
|
709 | + |
|
710 | + |
|
711 | + /** |
|
712 | + * Registers how core classes are loaded. |
|
713 | + * This can either be done by simply providing the name of one of the EE_Registry loader methods such as: |
|
714 | + * 'EE_Request_Handler' => 'load_core' |
|
715 | + * 'EE_Messages_Queue' => 'load_lib' |
|
716 | + * 'EEH_Debug_Tools' => 'load_helper' |
|
717 | + * or, if greater control is required, by providing a custom closure. For example: |
|
718 | + * 'Some_Class' => function () { |
|
719 | + * return new Some_Class(); |
|
720 | + * }, |
|
721 | + * This is required for instantiating dependencies |
|
722 | + * where an interface has been type hinted in a class constructor. For example: |
|
723 | + * 'Required_Interface' => function () { |
|
724 | + * return new A_Class_That_Implements_Required_Interface(); |
|
725 | + * }, |
|
726 | + * |
|
727 | + * @throws InvalidInterfaceException |
|
728 | + * @throws InvalidDataTypeException |
|
729 | + * @throws InvalidArgumentException |
|
730 | + */ |
|
731 | + protected function _register_core_class_loaders() |
|
732 | + { |
|
733 | + //for PHP5.3 compat, we need to register any properties called here in a variable because `$this` cannot |
|
734 | + //be used in a closure. |
|
735 | + $request = &$this->request; |
|
736 | + $response = &$this->response; |
|
737 | + $legacy_request = &$this->legacy_request; |
|
738 | + // $loader = &$this->loader; |
|
739 | + $this->_class_loaders = array( |
|
740 | + //load_core |
|
741 | + 'EE_Capabilities' => 'load_core', |
|
742 | + 'EE_Encryption' => 'load_core', |
|
743 | + 'EE_Front_Controller' => 'load_core', |
|
744 | + 'EE_Module_Request_Router' => 'load_core', |
|
745 | + 'EE_Registry' => 'load_core', |
|
746 | + 'EE_Request' => function () use (&$legacy_request) { |
|
747 | + return $legacy_request; |
|
748 | + }, |
|
749 | + 'EventEspresso\core\services\request\Request' => function () use (&$request) { |
|
750 | + return $request; |
|
751 | + }, |
|
752 | + 'EventEspresso\core\services\request\Response' => function () use (&$response) { |
|
753 | + return $response; |
|
754 | + }, |
|
755 | + 'EE_Request_Handler' => 'load_core', |
|
756 | + 'EE_Session' => 'load_core', |
|
757 | + 'EE_Cron_Tasks' => 'load_core', |
|
758 | + 'EE_System' => 'load_core', |
|
759 | + 'EE_Maintenance_Mode' => 'load_core', |
|
760 | + 'EE_Register_CPTs' => 'load_core', |
|
761 | + 'EE_Admin' => 'load_core', |
|
762 | + //load_lib |
|
763 | + 'EE_Message_Resource_Manager' => 'load_lib', |
|
764 | + 'EE_Message_Type_Collection' => 'load_lib', |
|
765 | + 'EE_Message_Type_Collection_Loader' => 'load_lib', |
|
766 | + 'EE_Messenger_Collection' => 'load_lib', |
|
767 | + 'EE_Messenger_Collection_Loader' => 'load_lib', |
|
768 | + 'EE_Messages_Processor' => 'load_lib', |
|
769 | + 'EE_Message_Repository' => 'load_lib', |
|
770 | + 'EE_Messages_Queue' => 'load_lib', |
|
771 | + 'EE_Messages_Data_Handler_Collection' => 'load_lib', |
|
772 | + 'EE_Message_Template_Group_Collection' => 'load_lib', |
|
773 | + 'EE_Payment_Method_Manager' => 'load_lib', |
|
774 | + 'EE_Messages_Generator' => function () { |
|
775 | + return EE_Registry::instance()->load_lib( |
|
776 | + 'Messages_Generator', |
|
777 | + array(), |
|
778 | + false, |
|
779 | + false |
|
780 | + ); |
|
781 | + }, |
|
782 | + 'EE_Messages_Template_Defaults' => function ($arguments = array()) { |
|
783 | + return EE_Registry::instance()->load_lib( |
|
784 | + 'Messages_Template_Defaults', |
|
785 | + $arguments, |
|
786 | + false, |
|
787 | + false |
|
788 | + ); |
|
789 | + }, |
|
790 | + //load_model |
|
791 | + // 'EEM_Attendee' => 'load_model', |
|
792 | + // 'EEM_Message_Template_Group' => 'load_model', |
|
793 | + // 'EEM_Message_Template' => 'load_model', |
|
794 | + //load_helper |
|
795 | + 'EEH_Parse_Shortcodes' => function () { |
|
796 | + if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) { |
|
797 | + return new EEH_Parse_Shortcodes(); |
|
798 | + } |
|
799 | + return null; |
|
800 | + }, |
|
801 | + 'EE_Template_Config' => function () { |
|
802 | + return EE_Config::instance()->template_settings; |
|
803 | + }, |
|
804 | + 'EE_Currency_Config' => function () { |
|
805 | + return EE_Config::instance()->currency; |
|
806 | + }, |
|
807 | + 'EE_Registration_Config' => function () { |
|
808 | + return EE_Config::instance()->registration; |
|
809 | + }, |
|
810 | + 'EE_Core_Config' => function () { |
|
811 | + return EE_Config::instance()->core; |
|
812 | + }, |
|
813 | + 'EventEspresso\core\services\loaders\Loader' => function () { |
|
814 | + return LoaderFactory::getLoader(); |
|
815 | + }, |
|
816 | + ); |
|
817 | + } |
|
818 | + |
|
819 | + |
|
820 | + |
|
821 | + /** |
|
822 | + * can be used for supplying alternate names for classes, |
|
823 | + * or for connecting interface names to instantiable classes |
|
824 | + */ |
|
825 | + protected function _register_core_aliases() |
|
826 | + { |
|
827 | + $this->_aliases = array( |
|
828 | + 'CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBusInterface', |
|
829 | + 'EventEspresso\core\services\commands\CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBus', |
|
830 | + 'CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManagerInterface', |
|
831 | + 'EventEspresso\core\services\commands\CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManager', |
|
832 | + 'CapChecker' => 'EventEspresso\core\services\commands\middleware\CapChecker', |
|
833 | + 'AddActionHook' => 'EventEspresso\core\services\commands\middleware\AddActionHook', |
|
834 | + 'CapabilitiesChecker' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
835 | + 'CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface', |
|
836 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
837 | + 'CreateRegistrationService' => 'EventEspresso\core\domain\services\registration\CreateRegistrationService', |
|
838 | + 'CreateRegCodeCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegCodeCommand', |
|
839 | + 'CreateRegUrlLinkCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegUrlLinkCommand', |
|
840 | + 'CreateRegistrationCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand', |
|
841 | + 'CopyRegistrationDetailsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommand', |
|
842 | + 'CopyRegistrationPaymentsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommand', |
|
843 | + 'CancelRegistrationAndTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler', |
|
844 | + 'UpdateRegistrationAndTransactionAfterChangeCommandHandler' => 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler', |
|
845 | + 'CreateTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommand', |
|
846 | + 'CreateTransactionCommandHandler' => 'EventEspresso\core\services\commands\transaction\CreateTransactionCommandHandler', |
|
847 | + 'CreateAttendeeCommandHandler' => 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler', |
|
848 | + 'TableManager' => 'EventEspresso\core\services\database\TableManager', |
|
849 | + 'TableAnalysis' => 'EventEspresso\core\services\database\TableAnalysis', |
|
850 | + 'EspressoShortcode' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
851 | + 'ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\ShortcodeInterface', |
|
852 | + 'EventEspresso\core\services\shortcodes\ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
853 | + 'EventEspresso\core\services\cache\CacheStorageInterface' => 'EventEspresso\core\services\cache\TransientCacheStorage', |
|
854 | + 'LoaderInterface' => 'EventEspresso\core\services\loaders\LoaderInterface', |
|
855 | + 'EventEspresso\core\services\loaders\LoaderInterface' => 'EventEspresso\core\services\loaders\Loader', |
|
856 | + 'CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactoryInterface', |
|
857 | + 'EventEspresso\core\services\commands\CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactory', |
|
858 | + 'EventEspresso\core\domain\services\session\SessionIdentifierInterface' => 'EE_Session', |
|
859 | + 'EmailValidatorInterface' => 'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface', |
|
860 | + 'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface' => 'EventEspresso\core\domain\services\validation\email\EmailValidationService', |
|
861 | + 'NoticeConverterInterface' => 'EventEspresso\core\services\notices\NoticeConverterInterface', |
|
862 | + 'EventEspresso\core\services\notices\NoticeConverterInterface' => 'EventEspresso\core\services\notices\ConvertNoticesToEeErrors', |
|
863 | + 'NoticesContainerInterface' => 'EventEspresso\core\services\notices\NoticesContainerInterface', |
|
864 | + 'EventEspresso\core\services\notices\NoticesContainerInterface' => 'EventEspresso\core\services\notices\NoticesContainer', |
|
865 | + 'EventEspresso\core\services\request\RequestInterface' => 'EventEspresso\core\services\request\Request', |
|
866 | + 'EventEspresso\core\services\request\ResponseInterface' => 'EventEspresso\core\services\request\Response', |
|
867 | + 'EventEspresso\core\domain\DomainInterface' => 'EventEspresso\core\domain\Domain', |
|
868 | + ); |
|
869 | + if (! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) { |
|
870 | + $this->_aliases['EventEspresso\core\services\notices\NoticeConverterInterface'] = 'EventEspresso\core\services\notices\ConvertNoticesToAdminNotices'; |
|
871 | + } |
|
872 | + } |
|
873 | + |
|
874 | + |
|
875 | + |
|
876 | + /** |
|
877 | + * This is used to reset the internal map and class_loaders to their original default state at the beginning of the |
|
878 | + * request Primarily used by unit tests. |
|
879 | + * |
|
880 | + * @throws InvalidDataTypeException |
|
881 | + * @throws InvalidInterfaceException |
|
882 | + * @throws InvalidArgumentException |
|
883 | + */ |
|
884 | + public function reset() |
|
885 | + { |
|
886 | + $this->_register_core_class_loaders(); |
|
887 | + $this->_register_core_dependencies(); |
|
888 | + } |
|
889 | 889 | |
890 | 890 | |
891 | 891 | } |
@@ -47,444 +47,444 @@ |
||
47 | 47 | class EEM_Line_Item extends EEM_Base |
48 | 48 | { |
49 | 49 | |
50 | - /** |
|
51 | - * Tax sub-total is just the total of all the taxes, which should be children |
|
52 | - * of this line item. There should only ever be one tax sub-total, and it should |
|
53 | - * be a direct child of. Its quantity and LIN_unit_price = 1. |
|
54 | - */ |
|
55 | - const type_tax_sub_total = 'tax-sub-total'; |
|
56 | - |
|
57 | - /** |
|
58 | - * Tax line items indicate a tax applied to all the taxable line items. |
|
59 | - * Should not have any children line items. Its LIN_unit_price = 0. Its LIN_percent is a percent, not a decimal |
|
60 | - * (eg 10% tax = 10, not 0.1). Its LIN_total = LIN_unit_price * pre-tax-total. Quantity = 1. |
|
61 | - */ |
|
62 | - const type_tax = 'tax'; |
|
63 | - |
|
64 | - /** |
|
65 | - * Indicating individual items purchased, or discounts or surcharges. |
|
66 | - * The sum of all the regular line items plus the tax items should equal |
|
67 | - * the grand total. |
|
68 | - * Possible children are sub-line-items and cancellations. |
|
69 | - * For flat items, LIN_unit_price * LIN_quantity = LIN_total. Its LIN_total is the sum of all the children |
|
70 | - * LIN_totals. Its LIN_percent = 0. |
|
71 | - * For percent items, its LIN_unit_price = 0. Its LIN_percent is a percent, not a decimal (eg 10% = 10, not 0.1). |
|
72 | - * Its LIN_total is LIN_percent / 100 * sum of lower-priority sibling line items. Quantity = 1. |
|
73 | - */ |
|
74 | - const type_line_item = 'line-item'; |
|
75 | - |
|
76 | - /** |
|
77 | - * Line item indicating all the factors that make a single line item. |
|
78 | - * Sub-line items should have NO children line items. |
|
79 | - * For flat sub-items, their quantity should match their parent item, their LIN_unit_price should be this sub-item's |
|
80 | - * contribution towards the price of ONE of their parent items, and its LIN_total should be |
|
81 | - * = LIN_quantity * LIN_unit_price. Its LIN_percent = 0. |
|
82 | - * For percent sub-items, the quantity should be 1, LIN_unit_price should be 0, and its LIN_total should |
|
83 | - * = LIN_percent / 100 * sum of lower-priority sibling line items.. |
|
84 | - */ |
|
85 | - const type_sub_line_item = 'sub-item'; |
|
86 | - |
|
87 | - /** |
|
88 | - * Line item indicating a sub-total (eg total for an event, or pre-tax subtotal). |
|
89 | - * Direct children should be event subtotals. |
|
90 | - * Should have quantity of 1, and a LIN_total and LIN_unit_price of the sum of all its sub-items' LIN_totals. |
|
91 | - * |
|
92 | - */ |
|
93 | - const type_sub_total = 'sub-total'; |
|
94 | - |
|
95 | - /** |
|
96 | - * Line item for the grand total of an order. Its direct children |
|
97 | - * should be tax subtotals and (pre-tax) subtotals, and possibly a regular line item |
|
98 | - * indicating a transaction-wide discount/surcharge. Should have a quantity of 1, a LIN_total and LIN_unit_price of |
|
99 | - * the entire order's mount. |
|
100 | - */ |
|
101 | - const type_total = 'total'; |
|
102 | - |
|
103 | - /** |
|
104 | - * When a line item is cancelled, a sub-line-item of type 'cancellation' |
|
105 | - * should be created, indicating the quantity that were cancelled |
|
106 | - * (because a line item could have a quantity of 1, and its cancellation item |
|
107 | - * could be for 3, indicating that originally 4 were purchased, but 3 have been |
|
108 | - * cancelled, and only one remains). |
|
109 | - * When items are refunded, a cancellation line item should be made, which points |
|
110 | - * to teh payment model object which actually refunded the payment. |
|
111 | - * Cancellations should NOT have any children line items; the should NOT affect |
|
112 | - * any calculations, and are only meant as a record that cancellations have occurred. |
|
113 | - * Their LIN_percent should be 0. |
|
114 | - */ |
|
115 | - const type_cancellation = 'cancellation'; |
|
116 | - |
|
117 | - // private instance of the EEM_Line_Item object |
|
118 | - protected static $_instance = NULL; |
|
119 | - |
|
120 | - |
|
121 | - /** |
|
122 | - * private constructor to prevent direct creation |
|
123 | - * @Constructor |
|
124 | - * @access protected |
|
125 | - * @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and any incoming timezone data that gets saved). Note this just sends the timezone info to the date time model field objects. Default is NULL (and will be assumed using the set timezone in the 'timezone_string' wp option) |
|
126 | - * @return \EEM_Line_Item |
|
127 | - */ |
|
128 | - protected function __construct($timezone) |
|
129 | - { |
|
130 | - $this->singular_item = __('Line Item', 'event_espresso'); |
|
131 | - $this->plural_item = __('Line Items', 'event_espresso'); |
|
132 | - |
|
133 | - $this->_tables = array( |
|
134 | - 'Line_Item' => new EE_Primary_Table('esp_line_item', 'LIN_ID') |
|
135 | - ); |
|
136 | - $line_items_can_be_for = apply_filters('FHEE__EEM_Line_Item__line_items_can_be_for', array('Ticket', 'Price', 'Event')); |
|
137 | - $this->_fields = array( |
|
138 | - 'Line_Item' => array( |
|
139 | - 'LIN_ID' => new EE_Primary_Key_Int_Field('LIN_ID', __("ID", "event_espresso")), |
|
140 | - 'LIN_code' => new EE_Slug_Field('LIN_code', __("Code for index into Cart", "event_espresso"), TRUE), |
|
141 | - 'TXN_ID' => new EE_Foreign_Key_Int_Field('TXN_ID', __("Transaction ID", "event_espresso"), TRUE, NULL, 'Transaction'), |
|
142 | - 'LIN_name' => new EE_Full_HTML_Field('LIN_name', __("Line Item Name", "event_espresso"), FALSE, ''), |
|
143 | - 'LIN_desc' => new EE_Full_HTML_Field('LIN_desc', __("Line Item Description", "event_espresso"), TRUE), |
|
144 | - 'LIN_unit_price' => new EE_Money_Field('LIN_unit_price', __("Unit Price", "event_espresso"), FALSE, 0), |
|
145 | - 'LIN_percent' => new EE_Float_Field('LIN_percent', __("Percent", "event_espresso"), FALSE, 0), |
|
146 | - 'LIN_is_taxable' => new EE_Boolean_Field('LIN_is_taxable', __("Taxable", "event_espresso"), FALSE, FALSE), |
|
147 | - 'LIN_order' => new EE_Integer_Field('LIN_order', __("Order of Application towards total of parent", "event_espresso"), FALSE, 1), |
|
148 | - 'LIN_total' => new EE_Money_Field('LIN_total', __("Total (unit price x quantity)", "event_espresso"), FALSE, 0), |
|
149 | - 'LIN_quantity' => new EE_Integer_Field('LIN_quantity', __("Quantity", "event_espresso"), TRUE, 1), |
|
150 | - 'LIN_parent' => new EE_Integer_Field('LIN_parent', __("Parent ID (this item goes towards that Line Item's total)", "event_espresso"), TRUE, NULL), |
|
151 | - 'LIN_type' => new EE_Enum_Text_Field('LIN_type', __("Type", "event_espresso"), FALSE, 'line-item', array( |
|
152 | - self::type_line_item => __("Line Item", "event_espresso"), |
|
153 | - self::type_sub_line_item => __("Sub-Item", "event_espresso"), |
|
154 | - self::type_sub_total => __("Subtotal", "event_espresso"), |
|
155 | - self::type_tax_sub_total => __("Tax Subtotal", "event_espresso"), |
|
156 | - self::type_tax => __("Tax", "event_espresso"), |
|
157 | - self::type_total => __("Total", "event_espresso"), |
|
158 | - self::type_cancellation => __('Cancellation', 'event_espresso') |
|
159 | - ) |
|
160 | - ), |
|
161 | - 'OBJ_ID' => new EE_Foreign_Key_Int_Field('OBJ_ID', __('ID of Item purchased.', 'event_espresso'), TRUE, NULL, $line_items_can_be_for), |
|
162 | - 'OBJ_type' => new EE_Any_Foreign_Model_Name_Field('OBJ_type', __("Model Name this Line Item is for", "event_espresso"), TRUE, NULL, $line_items_can_be_for), |
|
163 | - 'LIN_timestamp' => new EE_Datetime_Field('LIN_timestamp', __('When the line item was created', 'event_espresso'), false, EE_Datetime_Field::now, $timezone), |
|
164 | - ) |
|
165 | - ); |
|
166 | - $this->_model_relations = array( |
|
167 | - 'Transaction' => new EE_Belongs_To_Relation(), |
|
168 | - 'Ticket' => new EE_Belongs_To_Any_Relation(), |
|
169 | - 'Price' => new EE_Belongs_To_Any_Relation(), |
|
170 | - 'Event' => new EE_Belongs_To_Any_Relation() |
|
171 | - ); |
|
172 | - $this->_model_chain_to_wp_user = 'Transaction.Registration.Event'; |
|
173 | - $this->_caps_slug = 'transactions'; |
|
174 | - parent::__construct($timezone); |
|
175 | - } |
|
176 | - |
|
177 | - |
|
178 | - /** |
|
179 | - * Gets all the line items for this transaction of the given type |
|
180 | - * @param string $line_item_type like one of EEM_Line_Item::type_* |
|
181 | - * @param EE_Transaction|int $transaction |
|
182 | - * @return EE_Line_Item[] |
|
183 | - */ |
|
184 | - public function get_all_of_type_for_transaction($line_item_type, $transaction) |
|
185 | - { |
|
186 | - $transaction = EEM_Transaction::instance()->ensure_is_ID($transaction); |
|
187 | - return $this->get_all(array(array( |
|
188 | - 'LIN_type' => $line_item_type, |
|
189 | - 'TXN_ID' => $transaction |
|
190 | - ))); |
|
191 | - } |
|
192 | - |
|
193 | - |
|
194 | - /** |
|
195 | - * Gets all line items unrelated to tickets that are normal line items |
|
196 | - * (eg shipping, promotions, and miscellaneous other stuff should probably fit in this category) |
|
197 | - * @param EE_Transaction|int $transaction |
|
198 | - * @return EE_Line_Item[] |
|
199 | - */ |
|
200 | - public function get_all_non_ticket_line_items_for_transaction($transaction) |
|
201 | - { |
|
202 | - $transaction = EEM_Transaction::instance()->ensure_is_ID($transaction); |
|
203 | - return $this->get_all(array(array( |
|
204 | - 'LIN_type' => self::type_line_item, |
|
205 | - 'TXN_ID' => $transaction, |
|
206 | - 'OR' => array( |
|
207 | - 'OBJ_type*notticket' => array('!=', 'Ticket'), |
|
208 | - 'OBJ_type*null' => array('IS_NULL')) |
|
209 | - ))); |
|
210 | - } |
|
211 | - |
|
212 | - /** |
|
213 | - * Deletes line items with no transaction who have passed the transaction cutoff time. |
|
214 | - * This needs to be very efficient |
|
215 | - * because if there are spam bots afoot there will be LOTS of line items |
|
216 | - * @return int count of how many deleted |
|
217 | - */ |
|
218 | - public function delete_line_items_with_no_transaction() |
|
219 | - { |
|
220 | - /** @type WPDB $wpdb */ |
|
221 | - global $wpdb; |
|
222 | - $time_to_leave_alone = apply_filters( |
|
223 | - 'FHEE__EEM_Line_Item__delete_line_items_with_no_transaction__time_to_leave_alone', WEEK_IN_SECONDS |
|
224 | - ); |
|
225 | - $query = $wpdb->prepare( |
|
226 | - 'DELETE li |
|
50 | + /** |
|
51 | + * Tax sub-total is just the total of all the taxes, which should be children |
|
52 | + * of this line item. There should only ever be one tax sub-total, and it should |
|
53 | + * be a direct child of. Its quantity and LIN_unit_price = 1. |
|
54 | + */ |
|
55 | + const type_tax_sub_total = 'tax-sub-total'; |
|
56 | + |
|
57 | + /** |
|
58 | + * Tax line items indicate a tax applied to all the taxable line items. |
|
59 | + * Should not have any children line items. Its LIN_unit_price = 0. Its LIN_percent is a percent, not a decimal |
|
60 | + * (eg 10% tax = 10, not 0.1). Its LIN_total = LIN_unit_price * pre-tax-total. Quantity = 1. |
|
61 | + */ |
|
62 | + const type_tax = 'tax'; |
|
63 | + |
|
64 | + /** |
|
65 | + * Indicating individual items purchased, or discounts or surcharges. |
|
66 | + * The sum of all the regular line items plus the tax items should equal |
|
67 | + * the grand total. |
|
68 | + * Possible children are sub-line-items and cancellations. |
|
69 | + * For flat items, LIN_unit_price * LIN_quantity = LIN_total. Its LIN_total is the sum of all the children |
|
70 | + * LIN_totals. Its LIN_percent = 0. |
|
71 | + * For percent items, its LIN_unit_price = 0. Its LIN_percent is a percent, not a decimal (eg 10% = 10, not 0.1). |
|
72 | + * Its LIN_total is LIN_percent / 100 * sum of lower-priority sibling line items. Quantity = 1. |
|
73 | + */ |
|
74 | + const type_line_item = 'line-item'; |
|
75 | + |
|
76 | + /** |
|
77 | + * Line item indicating all the factors that make a single line item. |
|
78 | + * Sub-line items should have NO children line items. |
|
79 | + * For flat sub-items, their quantity should match their parent item, their LIN_unit_price should be this sub-item's |
|
80 | + * contribution towards the price of ONE of their parent items, and its LIN_total should be |
|
81 | + * = LIN_quantity * LIN_unit_price. Its LIN_percent = 0. |
|
82 | + * For percent sub-items, the quantity should be 1, LIN_unit_price should be 0, and its LIN_total should |
|
83 | + * = LIN_percent / 100 * sum of lower-priority sibling line items.. |
|
84 | + */ |
|
85 | + const type_sub_line_item = 'sub-item'; |
|
86 | + |
|
87 | + /** |
|
88 | + * Line item indicating a sub-total (eg total for an event, or pre-tax subtotal). |
|
89 | + * Direct children should be event subtotals. |
|
90 | + * Should have quantity of 1, and a LIN_total and LIN_unit_price of the sum of all its sub-items' LIN_totals. |
|
91 | + * |
|
92 | + */ |
|
93 | + const type_sub_total = 'sub-total'; |
|
94 | + |
|
95 | + /** |
|
96 | + * Line item for the grand total of an order. Its direct children |
|
97 | + * should be tax subtotals and (pre-tax) subtotals, and possibly a regular line item |
|
98 | + * indicating a transaction-wide discount/surcharge. Should have a quantity of 1, a LIN_total and LIN_unit_price of |
|
99 | + * the entire order's mount. |
|
100 | + */ |
|
101 | + const type_total = 'total'; |
|
102 | + |
|
103 | + /** |
|
104 | + * When a line item is cancelled, a sub-line-item of type 'cancellation' |
|
105 | + * should be created, indicating the quantity that were cancelled |
|
106 | + * (because a line item could have a quantity of 1, and its cancellation item |
|
107 | + * could be for 3, indicating that originally 4 were purchased, but 3 have been |
|
108 | + * cancelled, and only one remains). |
|
109 | + * When items are refunded, a cancellation line item should be made, which points |
|
110 | + * to teh payment model object which actually refunded the payment. |
|
111 | + * Cancellations should NOT have any children line items; the should NOT affect |
|
112 | + * any calculations, and are only meant as a record that cancellations have occurred. |
|
113 | + * Their LIN_percent should be 0. |
|
114 | + */ |
|
115 | + const type_cancellation = 'cancellation'; |
|
116 | + |
|
117 | + // private instance of the EEM_Line_Item object |
|
118 | + protected static $_instance = NULL; |
|
119 | + |
|
120 | + |
|
121 | + /** |
|
122 | + * private constructor to prevent direct creation |
|
123 | + * @Constructor |
|
124 | + * @access protected |
|
125 | + * @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and any incoming timezone data that gets saved). Note this just sends the timezone info to the date time model field objects. Default is NULL (and will be assumed using the set timezone in the 'timezone_string' wp option) |
|
126 | + * @return \EEM_Line_Item |
|
127 | + */ |
|
128 | + protected function __construct($timezone) |
|
129 | + { |
|
130 | + $this->singular_item = __('Line Item', 'event_espresso'); |
|
131 | + $this->plural_item = __('Line Items', 'event_espresso'); |
|
132 | + |
|
133 | + $this->_tables = array( |
|
134 | + 'Line_Item' => new EE_Primary_Table('esp_line_item', 'LIN_ID') |
|
135 | + ); |
|
136 | + $line_items_can_be_for = apply_filters('FHEE__EEM_Line_Item__line_items_can_be_for', array('Ticket', 'Price', 'Event')); |
|
137 | + $this->_fields = array( |
|
138 | + 'Line_Item' => array( |
|
139 | + 'LIN_ID' => new EE_Primary_Key_Int_Field('LIN_ID', __("ID", "event_espresso")), |
|
140 | + 'LIN_code' => new EE_Slug_Field('LIN_code', __("Code for index into Cart", "event_espresso"), TRUE), |
|
141 | + 'TXN_ID' => new EE_Foreign_Key_Int_Field('TXN_ID', __("Transaction ID", "event_espresso"), TRUE, NULL, 'Transaction'), |
|
142 | + 'LIN_name' => new EE_Full_HTML_Field('LIN_name', __("Line Item Name", "event_espresso"), FALSE, ''), |
|
143 | + 'LIN_desc' => new EE_Full_HTML_Field('LIN_desc', __("Line Item Description", "event_espresso"), TRUE), |
|
144 | + 'LIN_unit_price' => new EE_Money_Field('LIN_unit_price', __("Unit Price", "event_espresso"), FALSE, 0), |
|
145 | + 'LIN_percent' => new EE_Float_Field('LIN_percent', __("Percent", "event_espresso"), FALSE, 0), |
|
146 | + 'LIN_is_taxable' => new EE_Boolean_Field('LIN_is_taxable', __("Taxable", "event_espresso"), FALSE, FALSE), |
|
147 | + 'LIN_order' => new EE_Integer_Field('LIN_order', __("Order of Application towards total of parent", "event_espresso"), FALSE, 1), |
|
148 | + 'LIN_total' => new EE_Money_Field('LIN_total', __("Total (unit price x quantity)", "event_espresso"), FALSE, 0), |
|
149 | + 'LIN_quantity' => new EE_Integer_Field('LIN_quantity', __("Quantity", "event_espresso"), TRUE, 1), |
|
150 | + 'LIN_parent' => new EE_Integer_Field('LIN_parent', __("Parent ID (this item goes towards that Line Item's total)", "event_espresso"), TRUE, NULL), |
|
151 | + 'LIN_type' => new EE_Enum_Text_Field('LIN_type', __("Type", "event_espresso"), FALSE, 'line-item', array( |
|
152 | + self::type_line_item => __("Line Item", "event_espresso"), |
|
153 | + self::type_sub_line_item => __("Sub-Item", "event_espresso"), |
|
154 | + self::type_sub_total => __("Subtotal", "event_espresso"), |
|
155 | + self::type_tax_sub_total => __("Tax Subtotal", "event_espresso"), |
|
156 | + self::type_tax => __("Tax", "event_espresso"), |
|
157 | + self::type_total => __("Total", "event_espresso"), |
|
158 | + self::type_cancellation => __('Cancellation', 'event_espresso') |
|
159 | + ) |
|
160 | + ), |
|
161 | + 'OBJ_ID' => new EE_Foreign_Key_Int_Field('OBJ_ID', __('ID of Item purchased.', 'event_espresso'), TRUE, NULL, $line_items_can_be_for), |
|
162 | + 'OBJ_type' => new EE_Any_Foreign_Model_Name_Field('OBJ_type', __("Model Name this Line Item is for", "event_espresso"), TRUE, NULL, $line_items_can_be_for), |
|
163 | + 'LIN_timestamp' => new EE_Datetime_Field('LIN_timestamp', __('When the line item was created', 'event_espresso'), false, EE_Datetime_Field::now, $timezone), |
|
164 | + ) |
|
165 | + ); |
|
166 | + $this->_model_relations = array( |
|
167 | + 'Transaction' => new EE_Belongs_To_Relation(), |
|
168 | + 'Ticket' => new EE_Belongs_To_Any_Relation(), |
|
169 | + 'Price' => new EE_Belongs_To_Any_Relation(), |
|
170 | + 'Event' => new EE_Belongs_To_Any_Relation() |
|
171 | + ); |
|
172 | + $this->_model_chain_to_wp_user = 'Transaction.Registration.Event'; |
|
173 | + $this->_caps_slug = 'transactions'; |
|
174 | + parent::__construct($timezone); |
|
175 | + } |
|
176 | + |
|
177 | + |
|
178 | + /** |
|
179 | + * Gets all the line items for this transaction of the given type |
|
180 | + * @param string $line_item_type like one of EEM_Line_Item::type_* |
|
181 | + * @param EE_Transaction|int $transaction |
|
182 | + * @return EE_Line_Item[] |
|
183 | + */ |
|
184 | + public function get_all_of_type_for_transaction($line_item_type, $transaction) |
|
185 | + { |
|
186 | + $transaction = EEM_Transaction::instance()->ensure_is_ID($transaction); |
|
187 | + return $this->get_all(array(array( |
|
188 | + 'LIN_type' => $line_item_type, |
|
189 | + 'TXN_ID' => $transaction |
|
190 | + ))); |
|
191 | + } |
|
192 | + |
|
193 | + |
|
194 | + /** |
|
195 | + * Gets all line items unrelated to tickets that are normal line items |
|
196 | + * (eg shipping, promotions, and miscellaneous other stuff should probably fit in this category) |
|
197 | + * @param EE_Transaction|int $transaction |
|
198 | + * @return EE_Line_Item[] |
|
199 | + */ |
|
200 | + public function get_all_non_ticket_line_items_for_transaction($transaction) |
|
201 | + { |
|
202 | + $transaction = EEM_Transaction::instance()->ensure_is_ID($transaction); |
|
203 | + return $this->get_all(array(array( |
|
204 | + 'LIN_type' => self::type_line_item, |
|
205 | + 'TXN_ID' => $transaction, |
|
206 | + 'OR' => array( |
|
207 | + 'OBJ_type*notticket' => array('!=', 'Ticket'), |
|
208 | + 'OBJ_type*null' => array('IS_NULL')) |
|
209 | + ))); |
|
210 | + } |
|
211 | + |
|
212 | + /** |
|
213 | + * Deletes line items with no transaction who have passed the transaction cutoff time. |
|
214 | + * This needs to be very efficient |
|
215 | + * because if there are spam bots afoot there will be LOTS of line items |
|
216 | + * @return int count of how many deleted |
|
217 | + */ |
|
218 | + public function delete_line_items_with_no_transaction() |
|
219 | + { |
|
220 | + /** @type WPDB $wpdb */ |
|
221 | + global $wpdb; |
|
222 | + $time_to_leave_alone = apply_filters( |
|
223 | + 'FHEE__EEM_Line_Item__delete_line_items_with_no_transaction__time_to_leave_alone', WEEK_IN_SECONDS |
|
224 | + ); |
|
225 | + $query = $wpdb->prepare( |
|
226 | + 'DELETE li |
|
227 | 227 | FROM ' . $this->table() . ' li |
228 | 228 | LEFT JOIN ' . EEM_Transaction::instance()->table() . ' t ON li.TXN_ID = t.TXN_ID |
229 | 229 | WHERE t.TXN_ID IS NULL AND li.LIN_timestamp < %s', |
230 | - // use GMT time because that's what TXN_timestamps are in |
|
231 | - date('Y-m-d H:i:s', time() - $time_to_leave_alone) |
|
232 | - ); |
|
233 | - return $wpdb->query($query); |
|
234 | - } |
|
235 | - |
|
236 | - |
|
237 | - /** |
|
238 | - * get_line_item_for_transaction_object |
|
239 | - * Gets a transaction's line item record for a specific object such as a EE_Event or EE_Ticket |
|
240 | - * |
|
241 | - * @param int $TXN_ID |
|
242 | - * @param \EE_Base_Class $object |
|
243 | - * @return EE_Line_Item[] |
|
244 | - */ |
|
245 | - public function get_line_item_for_transaction_object($TXN_ID, EE_Base_Class $object) |
|
246 | - { |
|
247 | - return $this->get_all(array(array( |
|
248 | - 'TXN_ID' => $TXN_ID, |
|
249 | - 'OBJ_type' => str_replace('EE_', '', get_class($object)), |
|
250 | - 'OBJ_ID' => $object->ID() |
|
251 | - ))); |
|
252 | - } |
|
253 | - |
|
254 | - |
|
255 | - /** |
|
256 | - * get_object_line_items_for_transaction |
|
257 | - * Gets all of the the object line items for a transaction, based on an object type plus an array of object IDs |
|
258 | - * |
|
259 | - * @param int $TXN_ID |
|
260 | - * @param string $OBJ_type |
|
261 | - * @param array $OBJ_IDs |
|
262 | - * @return EE_Line_Item[] |
|
263 | - */ |
|
264 | - public function get_object_line_items_for_transaction($TXN_ID, $OBJ_type = 'Event', $OBJ_IDs = array()) |
|
265 | - { |
|
266 | - $query_params = array( |
|
267 | - 'OBJ_type' => $OBJ_type, |
|
268 | - // if incoming $OBJ_IDs is an array, then make sure it is formatted correctly for the query |
|
269 | - 'OBJ_ID' => is_array($OBJ_IDs) && !isset($OBJ_IDs['IN']) ? array('IN', $OBJ_IDs) : $OBJ_IDs |
|
270 | - ); |
|
271 | - if ($TXN_ID) { |
|
272 | - $query_params['TXN_ID'] = $TXN_ID; |
|
273 | - } |
|
274 | - return $this->get_all(array($query_params)); |
|
275 | - } |
|
276 | - |
|
277 | - |
|
278 | - /** |
|
279 | - * get_all_ticket_line_items_for_transaction |
|
280 | - * |
|
281 | - * @param EE_Transaction $transaction |
|
282 | - * @return EE_Line_Item[] |
|
283 | - */ |
|
284 | - public function get_all_ticket_line_items_for_transaction(EE_Transaction $transaction) |
|
285 | - { |
|
286 | - return $this->get_all(array( |
|
287 | - array( |
|
288 | - 'TXN_ID' => $transaction->ID(), |
|
289 | - 'OBJ_type' => 'Ticket', |
|
290 | - ) |
|
291 | - )); |
|
292 | - } |
|
293 | - |
|
294 | - |
|
295 | - /** |
|
296 | - * get_ticket_line_item_for_transaction |
|
297 | - * |
|
298 | - * @param int $TXN_ID |
|
299 | - * @param int $TKT_ID |
|
300 | - * @return \EE_Line_Item |
|
301 | - */ |
|
302 | - public function get_ticket_line_item_for_transaction($TXN_ID, $TKT_ID) |
|
303 | - { |
|
304 | - return $this->get_one(array( |
|
305 | - array( |
|
306 | - 'TXN_ID' => EEM_Transaction::instance()->ensure_is_ID($TXN_ID), |
|
307 | - 'OBJ_ID' => $TKT_ID, |
|
308 | - 'OBJ_type' => 'Ticket', |
|
309 | - ) |
|
310 | - )); |
|
311 | - } |
|
312 | - |
|
313 | - |
|
314 | - /** |
|
315 | - * get_existing_promotion_line_item |
|
316 | - * searches the cart for existing line items for the specified promotion |
|
317 | - * |
|
318 | - * @since 1.0.0 |
|
319 | - * |
|
320 | - * @param EE_Line_Item $parent_line_item |
|
321 | - * @param EE_Promotion $promotion |
|
322 | - * @return EE_Line_Item |
|
323 | - */ |
|
324 | - public function get_existing_promotion_line_item(EE_Line_Item $parent_line_item, EE_Promotion $promotion) |
|
325 | - { |
|
326 | - return $this->get_one(array( |
|
327 | - array( |
|
328 | - 'TXN_ID' => $parent_line_item->TXN_ID(), |
|
329 | - 'LIN_parent' => $parent_line_item->ID(), |
|
330 | - 'OBJ_type' => 'Promotion', |
|
331 | - 'OBJ_ID' => $promotion->ID() |
|
332 | - ) |
|
333 | - )); |
|
334 | - } |
|
335 | - |
|
336 | - |
|
337 | - /** |
|
338 | - * get_all_promotion_line_items |
|
339 | - * searches the cart for any and all existing promotion line items |
|
340 | - * |
|
341 | - * @since 1.0.0 |
|
342 | - * |
|
343 | - * @param EE_Line_Item $parent_line_item |
|
344 | - * @return EE_Line_Item[] |
|
345 | - */ |
|
346 | - public function get_all_promotion_line_items(EE_Line_Item $parent_line_item) |
|
347 | - { |
|
348 | - return $this->get_all(array( |
|
349 | - array( |
|
350 | - 'TXN_ID' => $parent_line_item->TXN_ID(), |
|
351 | - 'LIN_parent' => $parent_line_item->ID(), |
|
352 | - 'OBJ_type' => 'Promotion' |
|
353 | - ) |
|
354 | - )); |
|
355 | - } |
|
356 | - |
|
357 | - /** |
|
358 | - * Gets the registration's corresponding line item. |
|
359 | - * Note: basically does NOT support having multiple line items for a single ticket, |
|
360 | - * which would happen if some of the registrations had a price modifier while others didn't. |
|
361 | - * In order to support that, we'd probably need a LIN_ID on registrations or something. |
|
362 | - * @param EE_Registration $registration |
|
363 | - * @return EE_Line_ITem |
|
364 | - */ |
|
365 | - public function get_line_item_for_registration(EE_Registration $registration) |
|
366 | - { |
|
367 | - return $this->get_one($this->line_item_for_registration_query_params($registration)); |
|
368 | - } |
|
369 | - |
|
370 | - /** |
|
371 | - * Gets the query params used to retrieve a specific line item for the given registration |
|
372 | - * @param EE_Registration $registration |
|
373 | - * @param array $original_query_params any extra query params you'd like to be merged with |
|
374 | - * @return array like EEM_Base::get_all()'s $query_params |
|
375 | - */ |
|
376 | - public function line_item_for_registration_query_params(EE_Registration $registration, $original_query_params = array()) |
|
377 | - { |
|
378 | - return array_replace_recursive($original_query_params, array( |
|
379 | - array( |
|
380 | - 'OBJ_ID' => $registration->ticket_ID(), |
|
381 | - 'OBJ_type' => 'Ticket', |
|
382 | - 'TXN_ID' => $registration->transaction_ID() |
|
383 | - ) |
|
384 | - )); |
|
385 | - } |
|
386 | - |
|
387 | - |
|
388 | - /** |
|
389 | - * @return EE_Base_Class[]|EE_Line_Item[] |
|
390 | - * @throws InvalidInterfaceException |
|
391 | - * @throws InvalidDataTypeException |
|
392 | - * @throws EE_Error |
|
393 | - * @throws InvalidArgumentException |
|
394 | - */ |
|
395 | - public function get_total_line_items_with_no_transaction() |
|
396 | - { |
|
397 | - return $this->get_total_line_items_for_carts(); |
|
398 | - } |
|
399 | - |
|
400 | - |
|
401 | - /** |
|
402 | - * @return EE_Base_Class[]|EE_Line_Item[] |
|
403 | - * @throws InvalidInterfaceException |
|
404 | - * @throws InvalidDataTypeException |
|
405 | - * @throws EE_Error |
|
406 | - * @throws InvalidArgumentException |
|
407 | - */ |
|
408 | - public function get_total_line_items_for_active_carts() |
|
409 | - { |
|
410 | - return $this->get_total_line_items_for_carts(false); |
|
411 | - } |
|
412 | - |
|
413 | - |
|
414 | - /** |
|
415 | - * @return EE_Base_Class[]|EE_Line_Item[] |
|
416 | - * @throws InvalidInterfaceException |
|
417 | - * @throws InvalidDataTypeException |
|
418 | - * @throws EE_Error |
|
419 | - * @throws InvalidArgumentException |
|
420 | - */ |
|
421 | - public function get_total_line_items_for_expired_carts() |
|
422 | - { |
|
423 | - return $this->get_total_line_items_for_carts(true); |
|
424 | - } |
|
425 | - |
|
426 | - |
|
427 | - /** |
|
428 | - * Returns an array of grand total line items where the TXN_ID is 0. |
|
429 | - * If $expired is set to true, then only line items for expired sessions will be returned. |
|
430 | - * If $expired is set to false, then only line items for active sessions will be returned. |
|
431 | - * |
|
432 | - * @param null $expired |
|
433 | - * @return EE_Base_Class[]|EE_Line_Item[] |
|
434 | - * @throws EE_Error |
|
435 | - * @throws InvalidArgumentException |
|
436 | - * @throws InvalidDataTypeException |
|
437 | - * @throws InvalidInterfaceException |
|
438 | - */ |
|
439 | - private function get_total_line_items_for_carts($expired = null) |
|
440 | - { |
|
441 | - $where_params = array( |
|
442 | - 'TXN_ID' => 0, |
|
443 | - 'LIN_type' => 'total', |
|
444 | - ); |
|
445 | - if ($expired !== null) { |
|
446 | - /** @var EventEspresso\core\domain\values\session\SessionLifespan $session_lifespan */ |
|
447 | - $session_lifespan = LoaderFactory::getLoader()->getShared( |
|
448 | - 'EventEspresso\core\domain\values\session\SessionLifespan' |
|
449 | - ); |
|
450 | - $where_params['LIN_timestamp'] = array( |
|
451 | - $expired ? '<=' : '>', |
|
452 | - $session_lifespan->expiration(), |
|
453 | - ); |
|
454 | - } |
|
455 | - return $this->get_all(array($where_params)); |
|
456 | - } |
|
457 | - |
|
458 | - |
|
459 | - /** |
|
460 | - * Returns an array of ticket total line items where the TXN_ID is 0 |
|
461 | - * AND the timestamp is older than the session lifespan. |
|
462 | - * |
|
463 | - * @param int $timestamp |
|
464 | - * @return EE_Base_Class[]|EE_Line_Item[] |
|
465 | - * @throws EE_Error |
|
466 | - * @throws InvalidArgumentException |
|
467 | - * @throws InvalidDataTypeException |
|
468 | - * @throws InvalidInterfaceException |
|
469 | - */ |
|
470 | - public function getTicketLineItemsForExpiredCarts($timestamp = 0) |
|
471 | - { |
|
472 | - if(! absint($timestamp)) { |
|
473 | - /** @var EventEspresso\core\domain\values\session\SessionLifespan $session_lifespan */ |
|
474 | - $session_lifespan = LoaderFactory::getLoader()->getShared( |
|
475 | - 'EventEspresso\core\domain\values\session\SessionLifespan' |
|
476 | - ); |
|
477 | - $timestamp = $session_lifespan->expiration(); |
|
478 | - } |
|
479 | - return $this->get_all( |
|
480 | - array( |
|
481 | - array( |
|
482 | - 'TXN_ID' => 0, |
|
483 | - 'OBJ_type' => 'Ticket', |
|
484 | - 'LIN_timestamp' => array('<=', $timestamp), |
|
485 | - ) |
|
486 | - ) |
|
487 | - ); |
|
488 | - } |
|
230 | + // use GMT time because that's what TXN_timestamps are in |
|
231 | + date('Y-m-d H:i:s', time() - $time_to_leave_alone) |
|
232 | + ); |
|
233 | + return $wpdb->query($query); |
|
234 | + } |
|
235 | + |
|
236 | + |
|
237 | + /** |
|
238 | + * get_line_item_for_transaction_object |
|
239 | + * Gets a transaction's line item record for a specific object such as a EE_Event or EE_Ticket |
|
240 | + * |
|
241 | + * @param int $TXN_ID |
|
242 | + * @param \EE_Base_Class $object |
|
243 | + * @return EE_Line_Item[] |
|
244 | + */ |
|
245 | + public function get_line_item_for_transaction_object($TXN_ID, EE_Base_Class $object) |
|
246 | + { |
|
247 | + return $this->get_all(array(array( |
|
248 | + 'TXN_ID' => $TXN_ID, |
|
249 | + 'OBJ_type' => str_replace('EE_', '', get_class($object)), |
|
250 | + 'OBJ_ID' => $object->ID() |
|
251 | + ))); |
|
252 | + } |
|
253 | + |
|
254 | + |
|
255 | + /** |
|
256 | + * get_object_line_items_for_transaction |
|
257 | + * Gets all of the the object line items for a transaction, based on an object type plus an array of object IDs |
|
258 | + * |
|
259 | + * @param int $TXN_ID |
|
260 | + * @param string $OBJ_type |
|
261 | + * @param array $OBJ_IDs |
|
262 | + * @return EE_Line_Item[] |
|
263 | + */ |
|
264 | + public function get_object_line_items_for_transaction($TXN_ID, $OBJ_type = 'Event', $OBJ_IDs = array()) |
|
265 | + { |
|
266 | + $query_params = array( |
|
267 | + 'OBJ_type' => $OBJ_type, |
|
268 | + // if incoming $OBJ_IDs is an array, then make sure it is formatted correctly for the query |
|
269 | + 'OBJ_ID' => is_array($OBJ_IDs) && !isset($OBJ_IDs['IN']) ? array('IN', $OBJ_IDs) : $OBJ_IDs |
|
270 | + ); |
|
271 | + if ($TXN_ID) { |
|
272 | + $query_params['TXN_ID'] = $TXN_ID; |
|
273 | + } |
|
274 | + return $this->get_all(array($query_params)); |
|
275 | + } |
|
276 | + |
|
277 | + |
|
278 | + /** |
|
279 | + * get_all_ticket_line_items_for_transaction |
|
280 | + * |
|
281 | + * @param EE_Transaction $transaction |
|
282 | + * @return EE_Line_Item[] |
|
283 | + */ |
|
284 | + public function get_all_ticket_line_items_for_transaction(EE_Transaction $transaction) |
|
285 | + { |
|
286 | + return $this->get_all(array( |
|
287 | + array( |
|
288 | + 'TXN_ID' => $transaction->ID(), |
|
289 | + 'OBJ_type' => 'Ticket', |
|
290 | + ) |
|
291 | + )); |
|
292 | + } |
|
293 | + |
|
294 | + |
|
295 | + /** |
|
296 | + * get_ticket_line_item_for_transaction |
|
297 | + * |
|
298 | + * @param int $TXN_ID |
|
299 | + * @param int $TKT_ID |
|
300 | + * @return \EE_Line_Item |
|
301 | + */ |
|
302 | + public function get_ticket_line_item_for_transaction($TXN_ID, $TKT_ID) |
|
303 | + { |
|
304 | + return $this->get_one(array( |
|
305 | + array( |
|
306 | + 'TXN_ID' => EEM_Transaction::instance()->ensure_is_ID($TXN_ID), |
|
307 | + 'OBJ_ID' => $TKT_ID, |
|
308 | + 'OBJ_type' => 'Ticket', |
|
309 | + ) |
|
310 | + )); |
|
311 | + } |
|
312 | + |
|
313 | + |
|
314 | + /** |
|
315 | + * get_existing_promotion_line_item |
|
316 | + * searches the cart for existing line items for the specified promotion |
|
317 | + * |
|
318 | + * @since 1.0.0 |
|
319 | + * |
|
320 | + * @param EE_Line_Item $parent_line_item |
|
321 | + * @param EE_Promotion $promotion |
|
322 | + * @return EE_Line_Item |
|
323 | + */ |
|
324 | + public function get_existing_promotion_line_item(EE_Line_Item $parent_line_item, EE_Promotion $promotion) |
|
325 | + { |
|
326 | + return $this->get_one(array( |
|
327 | + array( |
|
328 | + 'TXN_ID' => $parent_line_item->TXN_ID(), |
|
329 | + 'LIN_parent' => $parent_line_item->ID(), |
|
330 | + 'OBJ_type' => 'Promotion', |
|
331 | + 'OBJ_ID' => $promotion->ID() |
|
332 | + ) |
|
333 | + )); |
|
334 | + } |
|
335 | + |
|
336 | + |
|
337 | + /** |
|
338 | + * get_all_promotion_line_items |
|
339 | + * searches the cart for any and all existing promotion line items |
|
340 | + * |
|
341 | + * @since 1.0.0 |
|
342 | + * |
|
343 | + * @param EE_Line_Item $parent_line_item |
|
344 | + * @return EE_Line_Item[] |
|
345 | + */ |
|
346 | + public function get_all_promotion_line_items(EE_Line_Item $parent_line_item) |
|
347 | + { |
|
348 | + return $this->get_all(array( |
|
349 | + array( |
|
350 | + 'TXN_ID' => $parent_line_item->TXN_ID(), |
|
351 | + 'LIN_parent' => $parent_line_item->ID(), |
|
352 | + 'OBJ_type' => 'Promotion' |
|
353 | + ) |
|
354 | + )); |
|
355 | + } |
|
356 | + |
|
357 | + /** |
|
358 | + * Gets the registration's corresponding line item. |
|
359 | + * Note: basically does NOT support having multiple line items for a single ticket, |
|
360 | + * which would happen if some of the registrations had a price modifier while others didn't. |
|
361 | + * In order to support that, we'd probably need a LIN_ID on registrations or something. |
|
362 | + * @param EE_Registration $registration |
|
363 | + * @return EE_Line_ITem |
|
364 | + */ |
|
365 | + public function get_line_item_for_registration(EE_Registration $registration) |
|
366 | + { |
|
367 | + return $this->get_one($this->line_item_for_registration_query_params($registration)); |
|
368 | + } |
|
369 | + |
|
370 | + /** |
|
371 | + * Gets the query params used to retrieve a specific line item for the given registration |
|
372 | + * @param EE_Registration $registration |
|
373 | + * @param array $original_query_params any extra query params you'd like to be merged with |
|
374 | + * @return array like EEM_Base::get_all()'s $query_params |
|
375 | + */ |
|
376 | + public function line_item_for_registration_query_params(EE_Registration $registration, $original_query_params = array()) |
|
377 | + { |
|
378 | + return array_replace_recursive($original_query_params, array( |
|
379 | + array( |
|
380 | + 'OBJ_ID' => $registration->ticket_ID(), |
|
381 | + 'OBJ_type' => 'Ticket', |
|
382 | + 'TXN_ID' => $registration->transaction_ID() |
|
383 | + ) |
|
384 | + )); |
|
385 | + } |
|
386 | + |
|
387 | + |
|
388 | + /** |
|
389 | + * @return EE_Base_Class[]|EE_Line_Item[] |
|
390 | + * @throws InvalidInterfaceException |
|
391 | + * @throws InvalidDataTypeException |
|
392 | + * @throws EE_Error |
|
393 | + * @throws InvalidArgumentException |
|
394 | + */ |
|
395 | + public function get_total_line_items_with_no_transaction() |
|
396 | + { |
|
397 | + return $this->get_total_line_items_for_carts(); |
|
398 | + } |
|
399 | + |
|
400 | + |
|
401 | + /** |
|
402 | + * @return EE_Base_Class[]|EE_Line_Item[] |
|
403 | + * @throws InvalidInterfaceException |
|
404 | + * @throws InvalidDataTypeException |
|
405 | + * @throws EE_Error |
|
406 | + * @throws InvalidArgumentException |
|
407 | + */ |
|
408 | + public function get_total_line_items_for_active_carts() |
|
409 | + { |
|
410 | + return $this->get_total_line_items_for_carts(false); |
|
411 | + } |
|
412 | + |
|
413 | + |
|
414 | + /** |
|
415 | + * @return EE_Base_Class[]|EE_Line_Item[] |
|
416 | + * @throws InvalidInterfaceException |
|
417 | + * @throws InvalidDataTypeException |
|
418 | + * @throws EE_Error |
|
419 | + * @throws InvalidArgumentException |
|
420 | + */ |
|
421 | + public function get_total_line_items_for_expired_carts() |
|
422 | + { |
|
423 | + return $this->get_total_line_items_for_carts(true); |
|
424 | + } |
|
425 | + |
|
426 | + |
|
427 | + /** |
|
428 | + * Returns an array of grand total line items where the TXN_ID is 0. |
|
429 | + * If $expired is set to true, then only line items for expired sessions will be returned. |
|
430 | + * If $expired is set to false, then only line items for active sessions will be returned. |
|
431 | + * |
|
432 | + * @param null $expired |
|
433 | + * @return EE_Base_Class[]|EE_Line_Item[] |
|
434 | + * @throws EE_Error |
|
435 | + * @throws InvalidArgumentException |
|
436 | + * @throws InvalidDataTypeException |
|
437 | + * @throws InvalidInterfaceException |
|
438 | + */ |
|
439 | + private function get_total_line_items_for_carts($expired = null) |
|
440 | + { |
|
441 | + $where_params = array( |
|
442 | + 'TXN_ID' => 0, |
|
443 | + 'LIN_type' => 'total', |
|
444 | + ); |
|
445 | + if ($expired !== null) { |
|
446 | + /** @var EventEspresso\core\domain\values\session\SessionLifespan $session_lifespan */ |
|
447 | + $session_lifespan = LoaderFactory::getLoader()->getShared( |
|
448 | + 'EventEspresso\core\domain\values\session\SessionLifespan' |
|
449 | + ); |
|
450 | + $where_params['LIN_timestamp'] = array( |
|
451 | + $expired ? '<=' : '>', |
|
452 | + $session_lifespan->expiration(), |
|
453 | + ); |
|
454 | + } |
|
455 | + return $this->get_all(array($where_params)); |
|
456 | + } |
|
457 | + |
|
458 | + |
|
459 | + /** |
|
460 | + * Returns an array of ticket total line items where the TXN_ID is 0 |
|
461 | + * AND the timestamp is older than the session lifespan. |
|
462 | + * |
|
463 | + * @param int $timestamp |
|
464 | + * @return EE_Base_Class[]|EE_Line_Item[] |
|
465 | + * @throws EE_Error |
|
466 | + * @throws InvalidArgumentException |
|
467 | + * @throws InvalidDataTypeException |
|
468 | + * @throws InvalidInterfaceException |
|
469 | + */ |
|
470 | + public function getTicketLineItemsForExpiredCarts($timestamp = 0) |
|
471 | + { |
|
472 | + if(! absint($timestamp)) { |
|
473 | + /** @var EventEspresso\core\domain\values\session\SessionLifespan $session_lifespan */ |
|
474 | + $session_lifespan = LoaderFactory::getLoader()->getShared( |
|
475 | + 'EventEspresso\core\domain\values\session\SessionLifespan' |
|
476 | + ); |
|
477 | + $timestamp = $session_lifespan->expiration(); |
|
478 | + } |
|
479 | + return $this->get_all( |
|
480 | + array( |
|
481 | + array( |
|
482 | + 'TXN_ID' => 0, |
|
483 | + 'OBJ_type' => 'Ticket', |
|
484 | + 'LIN_timestamp' => array('<=', $timestamp), |
|
485 | + ) |
|
486 | + ) |
|
487 | + ); |
|
488 | + } |
|
489 | 489 | |
490 | 490 | } |