@@ -7,7 +7,7 @@ discard block |
||
7 | 7 | use EEH_Template; |
8 | 8 | |
9 | 9 | if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
10 | - exit( 'No direct script access allowed' ); |
|
10 | + exit( 'No direct script access allowed' ); |
|
11 | 11 | } |
12 | 12 | |
13 | 13 | |
@@ -23,387 +23,387 @@ discard block |
||
23 | 23 | class Iframe |
24 | 24 | { |
25 | 25 | |
26 | - /* |
|
26 | + /* |
|
27 | 27 | * HTML for notices and ajax gif |
28 | 28 | * @var string $title |
29 | 29 | */ |
30 | - protected $title = ''; |
|
30 | + protected $title = ''; |
|
31 | 31 | |
32 | - /* |
|
32 | + /* |
|
33 | 33 | * HTML for the content being displayed |
34 | 34 | * @var string $content |
35 | 35 | */ |
36 | - protected $content = ''; |
|
36 | + protected $content = ''; |
|
37 | 37 | |
38 | - /* |
|
38 | + /* |
|
39 | 39 | * whether or not to call wp_head() and wp_footer() |
40 | 40 | * @var boolean $enqueue_wp_assets |
41 | 41 | */ |
42 | - protected $enqueue_wp_assets = false; |
|
42 | + protected $enqueue_wp_assets = false; |
|
43 | 43 | |
44 | - /* |
|
44 | + /* |
|
45 | 45 | * an array of CSS URLs |
46 | 46 | * @var array $css |
47 | 47 | */ |
48 | - protected $css = array(); |
|
48 | + protected $css = array(); |
|
49 | 49 | |
50 | - /* |
|
50 | + /* |
|
51 | 51 | * an array of JS URLs to be set in the HTML header. |
52 | 52 | * @var array $header_js |
53 | 53 | */ |
54 | - protected $header_js = array(); |
|
54 | + protected $header_js = array(); |
|
55 | 55 | |
56 | - /* |
|
56 | + /* |
|
57 | 57 | * an array of additional attributes to be added to <script> tags for header JS |
58 | 58 | * @var array $footer_js |
59 | 59 | */ |
60 | - protected $header_js_attributes = array(); |
|
60 | + protected $header_js_attributes = array(); |
|
61 | 61 | |
62 | - /* |
|
62 | + /* |
|
63 | 63 | * an array of JS URLs to be displayed before the HTML </body> tag |
64 | 64 | * @var array $footer_js |
65 | 65 | */ |
66 | - protected $footer_js = array(); |
|
66 | + protected $footer_js = array(); |
|
67 | 67 | |
68 | - /* |
|
68 | + /* |
|
69 | 69 | * an array of additional attributes to be added to <script> tags for footer JS |
70 | 70 | * @var array $footer_js_attributes |
71 | 71 | */ |
72 | - protected $footer_js_attributes = array(); |
|
72 | + protected $footer_js_attributes = array(); |
|
73 | 73 | |
74 | - /* |
|
74 | + /* |
|
75 | 75 | * an array of JSON vars to be set in the HTML header. |
76 | 76 | * @var array $localized_vars |
77 | 77 | */ |
78 | - protected $localized_vars = array(); |
|
79 | - |
|
80 | - |
|
81 | - |
|
82 | - /** |
|
83 | - * Iframe constructor |
|
84 | - * |
|
85 | - * @param string $title |
|
86 | - * @param string $content |
|
87 | - * @throws DomainException |
|
88 | - */ |
|
89 | - public function __construct( $title, $content ) |
|
90 | - { |
|
91 | - global $wp_version; |
|
92 | - if ( ! defined( 'EE_IFRAME_DIR_URL' ) ) { |
|
93 | - define( 'EE_IFRAME_DIR_URL', plugin_dir_url( __FILE__ ) ); |
|
94 | - } |
|
95 | - $this->setContent( $content ); |
|
96 | - $this->setTitle( $title ); |
|
97 | - $this->addStylesheets( |
|
98 | - apply_filters( |
|
99 | - 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__construct__default_css', |
|
100 | - array( |
|
101 | - 'site_theme' => get_stylesheet_directory_uri() . DS |
|
102 | - . 'style.css?ver=' . EVENT_ESPRESSO_VERSION, |
|
103 | - 'dashicons' => includes_url( 'css/dashicons.min.css?ver=' . $wp_version ), |
|
104 | - 'espresso_default' => EE_GLOBAL_ASSETS_URL |
|
105 | - . 'css/espresso_default.css?ver=' . EVENT_ESPRESSO_VERSION, |
|
106 | - ), |
|
107 | - $this |
|
108 | - ) |
|
109 | - ); |
|
110 | - $this->addScripts( |
|
111 | - apply_filters( |
|
112 | - 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__construct__default_js', |
|
113 | - array( |
|
114 | - 'jquery' => includes_url( 'js/jquery/jquery.js?ver=' . $wp_version ), |
|
115 | - 'espresso_core' => EE_GLOBAL_ASSETS_URL |
|
116 | - . 'scripts/espresso_core.js?ver=' . EVENT_ESPRESSO_VERSION, |
|
117 | - ), |
|
118 | - $this |
|
119 | - ) |
|
120 | - ); |
|
121 | - if ( |
|
122 | - apply_filters( |
|
123 | - 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__construct__load_default_theme_stylesheet', |
|
124 | - false |
|
125 | - ) |
|
126 | - ) { |
|
127 | - $this->addStylesheets( |
|
128 | - apply_filters( |
|
129 | - 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__construct__default_theme_stylesheet', |
|
130 | - array('default_theme_stylesheet' => get_stylesheet_uri()), |
|
131 | - $this |
|
132 | - ) |
|
133 | - ); |
|
134 | - } |
|
135 | - } |
|
136 | - |
|
137 | - |
|
138 | - |
|
139 | - /** |
|
140 | - * @param string $title |
|
141 | - * @throws DomainException |
|
142 | - */ |
|
143 | - public function setTitle( $title ) |
|
144 | - { |
|
145 | - if ( empty( $title ) ) { |
|
146 | - throw new DomainException( |
|
147 | - esc_html__( 'You must provide a page title in order to create an iframe.', 'event_espresso' ) |
|
148 | - ); |
|
149 | - } |
|
150 | - $this->title = $title; |
|
151 | - } |
|
152 | - |
|
153 | - |
|
154 | - |
|
155 | - /** |
|
156 | - * @param string $content |
|
157 | - * @throws DomainException |
|
158 | - */ |
|
159 | - public function setContent( $content ) |
|
160 | - { |
|
161 | - if ( empty( $content ) ) { |
|
162 | - throw new DomainException( |
|
163 | - esc_html__( 'You must provide content in order to create an iframe.', 'event_espresso' ) |
|
164 | - ); |
|
165 | - } |
|
166 | - $this->content = $content; |
|
167 | - } |
|
168 | - |
|
169 | - |
|
170 | - |
|
171 | - /** |
|
172 | - * @param boolean $enqueue_wp_assets |
|
173 | - */ |
|
174 | - public function setEnqueueWpAssets( $enqueue_wp_assets ) |
|
175 | - { |
|
176 | - $this->enqueue_wp_assets = filter_var( $enqueue_wp_assets, FILTER_VALIDATE_BOOLEAN ); |
|
177 | - } |
|
178 | - |
|
179 | - |
|
180 | - |
|
181 | - /** |
|
182 | - * @param array $stylesheets |
|
183 | - * @throws DomainException |
|
184 | - */ |
|
185 | - public function addStylesheets( array $stylesheets ) |
|
186 | - { |
|
187 | - if ( empty( $stylesheets ) ) { |
|
188 | - throw new DomainException( |
|
189 | - esc_html__( |
|
190 | - 'A non-empty array of URLs, is required to add a CSS stylesheet to an iframe.', |
|
191 | - 'event_espresso' |
|
192 | - ) |
|
193 | - ); |
|
194 | - } |
|
195 | - foreach ( $stylesheets as $handle => $stylesheet ) { |
|
196 | - $this->css[ $handle ] = $stylesheet; |
|
197 | - } |
|
198 | - } |
|
199 | - |
|
200 | - |
|
201 | - |
|
202 | - /** |
|
203 | - * @param array $scripts |
|
204 | - * @param bool $add_to_header |
|
205 | - * @throws DomainException |
|
206 | - */ |
|
207 | - public function addScripts( array $scripts, $add_to_header = false ) |
|
208 | - { |
|
209 | - if ( empty( $scripts ) ) { |
|
210 | - throw new DomainException( |
|
211 | - esc_html__( |
|
212 | - 'A non-empty array of URLs, is required to add Javascript to an iframe.', |
|
213 | - 'event_espresso' |
|
214 | - ) |
|
215 | - ); |
|
216 | - } |
|
217 | - foreach ( $scripts as $handle => $script ) { |
|
218 | - if ( $add_to_header ) { |
|
219 | - $this->header_js[ $handle ] = $script; |
|
220 | - } else { |
|
221 | - $this->footer_js[ $handle ] = $script; |
|
222 | - } |
|
223 | - } |
|
224 | - } |
|
225 | - |
|
226 | - |
|
227 | - |
|
228 | - /** |
|
229 | - * @param array $script_attributes |
|
230 | - * @param bool $add_to_header |
|
231 | - * @throws DomainException |
|
232 | - */ |
|
233 | - public function addScriptAttributes( array $script_attributes, $add_to_header = false ) |
|
234 | - { |
|
235 | - if ( empty($script_attributes ) ) { |
|
236 | - throw new DomainException( |
|
237 | - esc_html__( |
|
238 | - 'A non-empty array of strings, is required to add attributes to iframe Javascript.', |
|
239 | - 'event_espresso' |
|
240 | - ) |
|
241 | - ); |
|
242 | - } |
|
243 | - foreach ($script_attributes as $handle => $script_attribute ) { |
|
244 | - if ( $add_to_header ) { |
|
245 | - $this->header_js_attributes[ $handle ] = $script_attribute; |
|
246 | - } else { |
|
247 | - $this->footer_js_attributes[ $handle ] = $script_attribute; |
|
248 | - } |
|
249 | - } |
|
250 | - } |
|
251 | - |
|
252 | - |
|
253 | - |
|
254 | - /** |
|
255 | - * @param array $vars |
|
256 | - * @param string $var_name |
|
257 | - * @throws DomainException |
|
258 | - */ |
|
259 | - public function addLocalizedVars( array $vars, $var_name = 'eei18n' ) |
|
260 | - { |
|
261 | - if ( empty( $vars ) ) { |
|
262 | - throw new DomainException( |
|
263 | - esc_html__( |
|
264 | - 'A non-empty array of vars, is required to add localized Javascript vars to an iframe.', |
|
265 | - 'event_espresso' |
|
266 | - ) |
|
267 | - ); |
|
268 | - } |
|
269 | - foreach ( $vars as $handle => $var ) { |
|
270 | - if ( $var_name === 'eei18n' ) { |
|
271 | - EE_Registry::$i18n_js_strings[ $handle ] = $var; |
|
272 | - } elseif ($var_name === 'eeCAL' && $handle === 'espresso_calendar') { |
|
273 | - $this->localized_vars[ $var_name ] = $var; |
|
274 | - } else { |
|
275 | - if ( ! isset( $this->localized_vars[ $var_name ] ) ) { |
|
276 | - $this->localized_vars[ $var_name ] = array(); |
|
277 | - } |
|
278 | - $this->localized_vars[ $var_name ][ $handle ] = $var; |
|
279 | - } |
|
280 | - } |
|
281 | - } |
|
282 | - |
|
283 | - |
|
284 | - |
|
285 | - /** |
|
286 | - * @param string $utm_content |
|
287 | - * @throws DomainException |
|
288 | - */ |
|
289 | - public function display($utm_content = '') |
|
290 | - { |
|
291 | - $this->content .= EEH_Template::powered_by_event_espresso( |
|
292 | - '', |
|
293 | - '', |
|
294 | - ! empty($utm_content) ? array('utm_content' => $utm_content) : array() |
|
295 | - ); |
|
296 | - EE_System::do_not_cache(); |
|
297 | - echo $this->getTemplate(); |
|
298 | - exit; |
|
299 | - } |
|
300 | - |
|
301 | - |
|
302 | - |
|
303 | - /** |
|
304 | - * @return string |
|
305 | - * @throws DomainException |
|
306 | - */ |
|
307 | - public function getTemplate() |
|
308 | - { |
|
309 | - return EEH_Template::display_template( |
|
310 | - __DIR__ . DIRECTORY_SEPARATOR . 'iframe_wrapper.template.php', |
|
311 | - array( |
|
312 | - 'title' => apply_filters( |
|
313 | - 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__title', |
|
314 | - $this->title, |
|
315 | - $this |
|
316 | - ), |
|
317 | - 'content' => apply_filters( |
|
318 | - 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__content', |
|
319 | - $this->content, |
|
320 | - $this |
|
321 | - ), |
|
322 | - 'enqueue_wp_assets' => apply_filters( |
|
323 | - 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__enqueue_wp_assets', |
|
324 | - $this->enqueue_wp_assets, |
|
325 | - $this |
|
326 | - ), |
|
327 | - 'css' => (array)apply_filters( |
|
328 | - 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__css_urls', |
|
329 | - $this->css, |
|
330 | - $this |
|
331 | - ), |
|
332 | - 'header_js' => (array)apply_filters( |
|
333 | - 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__header_js_urls', |
|
334 | - $this->header_js, |
|
335 | - $this |
|
336 | - ), |
|
337 | - 'header_js_attributes' => (array) apply_filters( |
|
338 | - 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__header_js_attributes', |
|
339 | - $this->header_js_attributes, |
|
340 | - $this |
|
341 | - ), |
|
342 | - 'footer_js' => (array)apply_filters( |
|
343 | - 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__footer_js_urls', |
|
344 | - $this->footer_js, |
|
345 | - $this |
|
346 | - ), |
|
347 | - 'footer_js_attributes' => (array)apply_filters( |
|
348 | - 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__footer_js_attributes', |
|
349 | - $this->footer_js_attributes, |
|
350 | - $this |
|
351 | - ), |
|
352 | - 'eei18n' => apply_filters( |
|
353 | - 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__eei18n_js_strings', |
|
354 | - EE_Registry::localize_i18n_js_strings() . $this->localizeJsonVars(), |
|
355 | - $this |
|
356 | - ), |
|
357 | - 'notices' => EEH_Template::display_template( |
|
358 | - EE_TEMPLATES . 'espresso-ajax-notices.template.php', |
|
359 | - array(), |
|
360 | - true |
|
361 | - ), |
|
362 | - ), |
|
363 | - true, |
|
364 | - true |
|
365 | - ); |
|
366 | - } |
|
367 | - |
|
368 | - |
|
369 | - |
|
370 | - /** |
|
371 | - * localizeJsonVars |
|
372 | - * |
|
373 | - * @return string |
|
374 | - */ |
|
375 | - public function localizeJsonVars() |
|
376 | - { |
|
377 | - $JSON = ''; |
|
378 | - foreach ( (array)$this->localized_vars as $var_name => $vars ) { |
|
379 | - $this->localized_vars[ $var_name ] = $this->encodeJsonVars($vars ); |
|
380 | - $JSON .= "/* <![CDATA[ */ var {$var_name} = "; |
|
381 | - $JSON .= wp_json_encode( $this->localized_vars[ $var_name ] ); |
|
382 | - $JSON .= '; /* ]]> */'; |
|
383 | - } |
|
384 | - return $JSON; |
|
385 | - } |
|
386 | - |
|
387 | - |
|
388 | - |
|
389 | - /** |
|
390 | - * @param bool|int|float|string|array $var |
|
391 | - * @return array |
|
392 | - */ |
|
393 | - public function encodeJsonVars( $var ) |
|
394 | - { |
|
395 | - if ( is_array( $var ) ) { |
|
396 | - $localized_vars = array(); |
|
397 | - foreach ( (array)$var as $key => $value ) { |
|
398 | - $localized_vars[ $key ] = $this->encodeJsonVars( $value ); |
|
399 | - } |
|
400 | - return $localized_vars; |
|
401 | - } |
|
402 | - if ( is_scalar( $var ) ) { |
|
403 | - return html_entity_decode( (string)$var, ENT_QUOTES, 'UTF-8' ); |
|
404 | - } |
|
405 | - return null; |
|
406 | - } |
|
78 | + protected $localized_vars = array(); |
|
79 | + |
|
80 | + |
|
81 | + |
|
82 | + /** |
|
83 | + * Iframe constructor |
|
84 | + * |
|
85 | + * @param string $title |
|
86 | + * @param string $content |
|
87 | + * @throws DomainException |
|
88 | + */ |
|
89 | + public function __construct( $title, $content ) |
|
90 | + { |
|
91 | + global $wp_version; |
|
92 | + if ( ! defined( 'EE_IFRAME_DIR_URL' ) ) { |
|
93 | + define( 'EE_IFRAME_DIR_URL', plugin_dir_url( __FILE__ ) ); |
|
94 | + } |
|
95 | + $this->setContent( $content ); |
|
96 | + $this->setTitle( $title ); |
|
97 | + $this->addStylesheets( |
|
98 | + apply_filters( |
|
99 | + 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__construct__default_css', |
|
100 | + array( |
|
101 | + 'site_theme' => get_stylesheet_directory_uri() . DS |
|
102 | + . 'style.css?ver=' . EVENT_ESPRESSO_VERSION, |
|
103 | + 'dashicons' => includes_url( 'css/dashicons.min.css?ver=' . $wp_version ), |
|
104 | + 'espresso_default' => EE_GLOBAL_ASSETS_URL |
|
105 | + . 'css/espresso_default.css?ver=' . EVENT_ESPRESSO_VERSION, |
|
106 | + ), |
|
107 | + $this |
|
108 | + ) |
|
109 | + ); |
|
110 | + $this->addScripts( |
|
111 | + apply_filters( |
|
112 | + 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__construct__default_js', |
|
113 | + array( |
|
114 | + 'jquery' => includes_url( 'js/jquery/jquery.js?ver=' . $wp_version ), |
|
115 | + 'espresso_core' => EE_GLOBAL_ASSETS_URL |
|
116 | + . 'scripts/espresso_core.js?ver=' . EVENT_ESPRESSO_VERSION, |
|
117 | + ), |
|
118 | + $this |
|
119 | + ) |
|
120 | + ); |
|
121 | + if ( |
|
122 | + apply_filters( |
|
123 | + 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__construct__load_default_theme_stylesheet', |
|
124 | + false |
|
125 | + ) |
|
126 | + ) { |
|
127 | + $this->addStylesheets( |
|
128 | + apply_filters( |
|
129 | + 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__construct__default_theme_stylesheet', |
|
130 | + array('default_theme_stylesheet' => get_stylesheet_uri()), |
|
131 | + $this |
|
132 | + ) |
|
133 | + ); |
|
134 | + } |
|
135 | + } |
|
136 | + |
|
137 | + |
|
138 | + |
|
139 | + /** |
|
140 | + * @param string $title |
|
141 | + * @throws DomainException |
|
142 | + */ |
|
143 | + public function setTitle( $title ) |
|
144 | + { |
|
145 | + if ( empty( $title ) ) { |
|
146 | + throw new DomainException( |
|
147 | + esc_html__( 'You must provide a page title in order to create an iframe.', 'event_espresso' ) |
|
148 | + ); |
|
149 | + } |
|
150 | + $this->title = $title; |
|
151 | + } |
|
152 | + |
|
153 | + |
|
154 | + |
|
155 | + /** |
|
156 | + * @param string $content |
|
157 | + * @throws DomainException |
|
158 | + */ |
|
159 | + public function setContent( $content ) |
|
160 | + { |
|
161 | + if ( empty( $content ) ) { |
|
162 | + throw new DomainException( |
|
163 | + esc_html__( 'You must provide content in order to create an iframe.', 'event_espresso' ) |
|
164 | + ); |
|
165 | + } |
|
166 | + $this->content = $content; |
|
167 | + } |
|
168 | + |
|
169 | + |
|
170 | + |
|
171 | + /** |
|
172 | + * @param boolean $enqueue_wp_assets |
|
173 | + */ |
|
174 | + public function setEnqueueWpAssets( $enqueue_wp_assets ) |
|
175 | + { |
|
176 | + $this->enqueue_wp_assets = filter_var( $enqueue_wp_assets, FILTER_VALIDATE_BOOLEAN ); |
|
177 | + } |
|
178 | + |
|
179 | + |
|
180 | + |
|
181 | + /** |
|
182 | + * @param array $stylesheets |
|
183 | + * @throws DomainException |
|
184 | + */ |
|
185 | + public function addStylesheets( array $stylesheets ) |
|
186 | + { |
|
187 | + if ( empty( $stylesheets ) ) { |
|
188 | + throw new DomainException( |
|
189 | + esc_html__( |
|
190 | + 'A non-empty array of URLs, is required to add a CSS stylesheet to an iframe.', |
|
191 | + 'event_espresso' |
|
192 | + ) |
|
193 | + ); |
|
194 | + } |
|
195 | + foreach ( $stylesheets as $handle => $stylesheet ) { |
|
196 | + $this->css[ $handle ] = $stylesheet; |
|
197 | + } |
|
198 | + } |
|
199 | + |
|
200 | + |
|
201 | + |
|
202 | + /** |
|
203 | + * @param array $scripts |
|
204 | + * @param bool $add_to_header |
|
205 | + * @throws DomainException |
|
206 | + */ |
|
207 | + public function addScripts( array $scripts, $add_to_header = false ) |
|
208 | + { |
|
209 | + if ( empty( $scripts ) ) { |
|
210 | + throw new DomainException( |
|
211 | + esc_html__( |
|
212 | + 'A non-empty array of URLs, is required to add Javascript to an iframe.', |
|
213 | + 'event_espresso' |
|
214 | + ) |
|
215 | + ); |
|
216 | + } |
|
217 | + foreach ( $scripts as $handle => $script ) { |
|
218 | + if ( $add_to_header ) { |
|
219 | + $this->header_js[ $handle ] = $script; |
|
220 | + } else { |
|
221 | + $this->footer_js[ $handle ] = $script; |
|
222 | + } |
|
223 | + } |
|
224 | + } |
|
225 | + |
|
226 | + |
|
227 | + |
|
228 | + /** |
|
229 | + * @param array $script_attributes |
|
230 | + * @param bool $add_to_header |
|
231 | + * @throws DomainException |
|
232 | + */ |
|
233 | + public function addScriptAttributes( array $script_attributes, $add_to_header = false ) |
|
234 | + { |
|
235 | + if ( empty($script_attributes ) ) { |
|
236 | + throw new DomainException( |
|
237 | + esc_html__( |
|
238 | + 'A non-empty array of strings, is required to add attributes to iframe Javascript.', |
|
239 | + 'event_espresso' |
|
240 | + ) |
|
241 | + ); |
|
242 | + } |
|
243 | + foreach ($script_attributes as $handle => $script_attribute ) { |
|
244 | + if ( $add_to_header ) { |
|
245 | + $this->header_js_attributes[ $handle ] = $script_attribute; |
|
246 | + } else { |
|
247 | + $this->footer_js_attributes[ $handle ] = $script_attribute; |
|
248 | + } |
|
249 | + } |
|
250 | + } |
|
251 | + |
|
252 | + |
|
253 | + |
|
254 | + /** |
|
255 | + * @param array $vars |
|
256 | + * @param string $var_name |
|
257 | + * @throws DomainException |
|
258 | + */ |
|
259 | + public function addLocalizedVars( array $vars, $var_name = 'eei18n' ) |
|
260 | + { |
|
261 | + if ( empty( $vars ) ) { |
|
262 | + throw new DomainException( |
|
263 | + esc_html__( |
|
264 | + 'A non-empty array of vars, is required to add localized Javascript vars to an iframe.', |
|
265 | + 'event_espresso' |
|
266 | + ) |
|
267 | + ); |
|
268 | + } |
|
269 | + foreach ( $vars as $handle => $var ) { |
|
270 | + if ( $var_name === 'eei18n' ) { |
|
271 | + EE_Registry::$i18n_js_strings[ $handle ] = $var; |
|
272 | + } elseif ($var_name === 'eeCAL' && $handle === 'espresso_calendar') { |
|
273 | + $this->localized_vars[ $var_name ] = $var; |
|
274 | + } else { |
|
275 | + if ( ! isset( $this->localized_vars[ $var_name ] ) ) { |
|
276 | + $this->localized_vars[ $var_name ] = array(); |
|
277 | + } |
|
278 | + $this->localized_vars[ $var_name ][ $handle ] = $var; |
|
279 | + } |
|
280 | + } |
|
281 | + } |
|
282 | + |
|
283 | + |
|
284 | + |
|
285 | + /** |
|
286 | + * @param string $utm_content |
|
287 | + * @throws DomainException |
|
288 | + */ |
|
289 | + public function display($utm_content = '') |
|
290 | + { |
|
291 | + $this->content .= EEH_Template::powered_by_event_espresso( |
|
292 | + '', |
|
293 | + '', |
|
294 | + ! empty($utm_content) ? array('utm_content' => $utm_content) : array() |
|
295 | + ); |
|
296 | + EE_System::do_not_cache(); |
|
297 | + echo $this->getTemplate(); |
|
298 | + exit; |
|
299 | + } |
|
300 | + |
|
301 | + |
|
302 | + |
|
303 | + /** |
|
304 | + * @return string |
|
305 | + * @throws DomainException |
|
306 | + */ |
|
307 | + public function getTemplate() |
|
308 | + { |
|
309 | + return EEH_Template::display_template( |
|
310 | + __DIR__ . DIRECTORY_SEPARATOR . 'iframe_wrapper.template.php', |
|
311 | + array( |
|
312 | + 'title' => apply_filters( |
|
313 | + 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__title', |
|
314 | + $this->title, |
|
315 | + $this |
|
316 | + ), |
|
317 | + 'content' => apply_filters( |
|
318 | + 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__content', |
|
319 | + $this->content, |
|
320 | + $this |
|
321 | + ), |
|
322 | + 'enqueue_wp_assets' => apply_filters( |
|
323 | + 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__enqueue_wp_assets', |
|
324 | + $this->enqueue_wp_assets, |
|
325 | + $this |
|
326 | + ), |
|
327 | + 'css' => (array)apply_filters( |
|
328 | + 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__css_urls', |
|
329 | + $this->css, |
|
330 | + $this |
|
331 | + ), |
|
332 | + 'header_js' => (array)apply_filters( |
|
333 | + 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__header_js_urls', |
|
334 | + $this->header_js, |
|
335 | + $this |
|
336 | + ), |
|
337 | + 'header_js_attributes' => (array) apply_filters( |
|
338 | + 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__header_js_attributes', |
|
339 | + $this->header_js_attributes, |
|
340 | + $this |
|
341 | + ), |
|
342 | + 'footer_js' => (array)apply_filters( |
|
343 | + 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__footer_js_urls', |
|
344 | + $this->footer_js, |
|
345 | + $this |
|
346 | + ), |
|
347 | + 'footer_js_attributes' => (array)apply_filters( |
|
348 | + 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__footer_js_attributes', |
|
349 | + $this->footer_js_attributes, |
|
350 | + $this |
|
351 | + ), |
|
352 | + 'eei18n' => apply_filters( |
|
353 | + 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__eei18n_js_strings', |
|
354 | + EE_Registry::localize_i18n_js_strings() . $this->localizeJsonVars(), |
|
355 | + $this |
|
356 | + ), |
|
357 | + 'notices' => EEH_Template::display_template( |
|
358 | + EE_TEMPLATES . 'espresso-ajax-notices.template.php', |
|
359 | + array(), |
|
360 | + true |
|
361 | + ), |
|
362 | + ), |
|
363 | + true, |
|
364 | + true |
|
365 | + ); |
|
366 | + } |
|
367 | + |
|
368 | + |
|
369 | + |
|
370 | + /** |
|
371 | + * localizeJsonVars |
|
372 | + * |
|
373 | + * @return string |
|
374 | + */ |
|
375 | + public function localizeJsonVars() |
|
376 | + { |
|
377 | + $JSON = ''; |
|
378 | + foreach ( (array)$this->localized_vars as $var_name => $vars ) { |
|
379 | + $this->localized_vars[ $var_name ] = $this->encodeJsonVars($vars ); |
|
380 | + $JSON .= "/* <![CDATA[ */ var {$var_name} = "; |
|
381 | + $JSON .= wp_json_encode( $this->localized_vars[ $var_name ] ); |
|
382 | + $JSON .= '; /* ]]> */'; |
|
383 | + } |
|
384 | + return $JSON; |
|
385 | + } |
|
386 | + |
|
387 | + |
|
388 | + |
|
389 | + /** |
|
390 | + * @param bool|int|float|string|array $var |
|
391 | + * @return array |
|
392 | + */ |
|
393 | + public function encodeJsonVars( $var ) |
|
394 | + { |
|
395 | + if ( is_array( $var ) ) { |
|
396 | + $localized_vars = array(); |
|
397 | + foreach ( (array)$var as $key => $value ) { |
|
398 | + $localized_vars[ $key ] = $this->encodeJsonVars( $value ); |
|
399 | + } |
|
400 | + return $localized_vars; |
|
401 | + } |
|
402 | + if ( is_scalar( $var ) ) { |
|
403 | + return html_entity_decode( (string)$var, ENT_QUOTES, 'UTF-8' ); |
|
404 | + } |
|
405 | + return null; |
|
406 | + } |
|
407 | 407 | |
408 | 408 | |
409 | 409 |
@@ -6,8 +6,8 @@ discard block |
||
6 | 6 | use EE_System; |
7 | 7 | use EEH_Template; |
8 | 8 | |
9 | -if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
|
10 | - exit( 'No direct script access allowed' ); |
|
9 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
10 | + exit('No direct script access allowed'); |
|
11 | 11 | } |
12 | 12 | |
13 | 13 | |
@@ -86,23 +86,23 @@ discard block |
||
86 | 86 | * @param string $content |
87 | 87 | * @throws DomainException |
88 | 88 | */ |
89 | - public function __construct( $title, $content ) |
|
89 | + public function __construct($title, $content) |
|
90 | 90 | { |
91 | 91 | global $wp_version; |
92 | - if ( ! defined( 'EE_IFRAME_DIR_URL' ) ) { |
|
93 | - define( 'EE_IFRAME_DIR_URL', plugin_dir_url( __FILE__ ) ); |
|
92 | + if ( ! defined('EE_IFRAME_DIR_URL')) { |
|
93 | + define('EE_IFRAME_DIR_URL', plugin_dir_url(__FILE__)); |
|
94 | 94 | } |
95 | - $this->setContent( $content ); |
|
96 | - $this->setTitle( $title ); |
|
95 | + $this->setContent($content); |
|
96 | + $this->setTitle($title); |
|
97 | 97 | $this->addStylesheets( |
98 | 98 | apply_filters( |
99 | 99 | 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__construct__default_css', |
100 | 100 | array( |
101 | - 'site_theme' => get_stylesheet_directory_uri() . DS |
|
102 | - . 'style.css?ver=' . EVENT_ESPRESSO_VERSION, |
|
103 | - 'dashicons' => includes_url( 'css/dashicons.min.css?ver=' . $wp_version ), |
|
101 | + 'site_theme' => get_stylesheet_directory_uri().DS |
|
102 | + . 'style.css?ver='.EVENT_ESPRESSO_VERSION, |
|
103 | + 'dashicons' => includes_url('css/dashicons.min.css?ver='.$wp_version), |
|
104 | 104 | 'espresso_default' => EE_GLOBAL_ASSETS_URL |
105 | - . 'css/espresso_default.css?ver=' . EVENT_ESPRESSO_VERSION, |
|
105 | + . 'css/espresso_default.css?ver='.EVENT_ESPRESSO_VERSION, |
|
106 | 106 | ), |
107 | 107 | $this |
108 | 108 | ) |
@@ -111,9 +111,9 @@ discard block |
||
111 | 111 | apply_filters( |
112 | 112 | 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__construct__default_js', |
113 | 113 | array( |
114 | - 'jquery' => includes_url( 'js/jquery/jquery.js?ver=' . $wp_version ), |
|
114 | + 'jquery' => includes_url('js/jquery/jquery.js?ver='.$wp_version), |
|
115 | 115 | 'espresso_core' => EE_GLOBAL_ASSETS_URL |
116 | - . 'scripts/espresso_core.js?ver=' . EVENT_ESPRESSO_VERSION, |
|
116 | + . 'scripts/espresso_core.js?ver='.EVENT_ESPRESSO_VERSION, |
|
117 | 117 | ), |
118 | 118 | $this |
119 | 119 | ) |
@@ -140,11 +140,11 @@ discard block |
||
140 | 140 | * @param string $title |
141 | 141 | * @throws DomainException |
142 | 142 | */ |
143 | - public function setTitle( $title ) |
|
143 | + public function setTitle($title) |
|
144 | 144 | { |
145 | - if ( empty( $title ) ) { |
|
145 | + if (empty($title)) { |
|
146 | 146 | throw new DomainException( |
147 | - esc_html__( 'You must provide a page title in order to create an iframe.', 'event_espresso' ) |
|
147 | + esc_html__('You must provide a page title in order to create an iframe.', 'event_espresso') |
|
148 | 148 | ); |
149 | 149 | } |
150 | 150 | $this->title = $title; |
@@ -156,11 +156,11 @@ discard block |
||
156 | 156 | * @param string $content |
157 | 157 | * @throws DomainException |
158 | 158 | */ |
159 | - public function setContent( $content ) |
|
159 | + public function setContent($content) |
|
160 | 160 | { |
161 | - if ( empty( $content ) ) { |
|
161 | + if (empty($content)) { |
|
162 | 162 | throw new DomainException( |
163 | - esc_html__( 'You must provide content in order to create an iframe.', 'event_espresso' ) |
|
163 | + esc_html__('You must provide content in order to create an iframe.', 'event_espresso') |
|
164 | 164 | ); |
165 | 165 | } |
166 | 166 | $this->content = $content; |
@@ -171,9 +171,9 @@ discard block |
||
171 | 171 | /** |
172 | 172 | * @param boolean $enqueue_wp_assets |
173 | 173 | */ |
174 | - public function setEnqueueWpAssets( $enqueue_wp_assets ) |
|
174 | + public function setEnqueueWpAssets($enqueue_wp_assets) |
|
175 | 175 | { |
176 | - $this->enqueue_wp_assets = filter_var( $enqueue_wp_assets, FILTER_VALIDATE_BOOLEAN ); |
|
176 | + $this->enqueue_wp_assets = filter_var($enqueue_wp_assets, FILTER_VALIDATE_BOOLEAN); |
|
177 | 177 | } |
178 | 178 | |
179 | 179 | |
@@ -182,9 +182,9 @@ discard block |
||
182 | 182 | * @param array $stylesheets |
183 | 183 | * @throws DomainException |
184 | 184 | */ |
185 | - public function addStylesheets( array $stylesheets ) |
|
185 | + public function addStylesheets(array $stylesheets) |
|
186 | 186 | { |
187 | - if ( empty( $stylesheets ) ) { |
|
187 | + if (empty($stylesheets)) { |
|
188 | 188 | throw new DomainException( |
189 | 189 | esc_html__( |
190 | 190 | 'A non-empty array of URLs, is required to add a CSS stylesheet to an iframe.', |
@@ -192,8 +192,8 @@ discard block |
||
192 | 192 | ) |
193 | 193 | ); |
194 | 194 | } |
195 | - foreach ( $stylesheets as $handle => $stylesheet ) { |
|
196 | - $this->css[ $handle ] = $stylesheet; |
|
195 | + foreach ($stylesheets as $handle => $stylesheet) { |
|
196 | + $this->css[$handle] = $stylesheet; |
|
197 | 197 | } |
198 | 198 | } |
199 | 199 | |
@@ -204,9 +204,9 @@ discard block |
||
204 | 204 | * @param bool $add_to_header |
205 | 205 | * @throws DomainException |
206 | 206 | */ |
207 | - public function addScripts( array $scripts, $add_to_header = false ) |
|
207 | + public function addScripts(array $scripts, $add_to_header = false) |
|
208 | 208 | { |
209 | - if ( empty( $scripts ) ) { |
|
209 | + if (empty($scripts)) { |
|
210 | 210 | throw new DomainException( |
211 | 211 | esc_html__( |
212 | 212 | 'A non-empty array of URLs, is required to add Javascript to an iframe.', |
@@ -214,11 +214,11 @@ discard block |
||
214 | 214 | ) |
215 | 215 | ); |
216 | 216 | } |
217 | - foreach ( $scripts as $handle => $script ) { |
|
218 | - if ( $add_to_header ) { |
|
219 | - $this->header_js[ $handle ] = $script; |
|
217 | + foreach ($scripts as $handle => $script) { |
|
218 | + if ($add_to_header) { |
|
219 | + $this->header_js[$handle] = $script; |
|
220 | 220 | } else { |
221 | - $this->footer_js[ $handle ] = $script; |
|
221 | + $this->footer_js[$handle] = $script; |
|
222 | 222 | } |
223 | 223 | } |
224 | 224 | } |
@@ -230,9 +230,9 @@ discard block |
||
230 | 230 | * @param bool $add_to_header |
231 | 231 | * @throws DomainException |
232 | 232 | */ |
233 | - public function addScriptAttributes( array $script_attributes, $add_to_header = false ) |
|
233 | + public function addScriptAttributes(array $script_attributes, $add_to_header = false) |
|
234 | 234 | { |
235 | - if ( empty($script_attributes ) ) { |
|
235 | + if (empty($script_attributes)) { |
|
236 | 236 | throw new DomainException( |
237 | 237 | esc_html__( |
238 | 238 | 'A non-empty array of strings, is required to add attributes to iframe Javascript.', |
@@ -240,11 +240,11 @@ discard block |
||
240 | 240 | ) |
241 | 241 | ); |
242 | 242 | } |
243 | - foreach ($script_attributes as $handle => $script_attribute ) { |
|
244 | - if ( $add_to_header ) { |
|
245 | - $this->header_js_attributes[ $handle ] = $script_attribute; |
|
243 | + foreach ($script_attributes as $handle => $script_attribute) { |
|
244 | + if ($add_to_header) { |
|
245 | + $this->header_js_attributes[$handle] = $script_attribute; |
|
246 | 246 | } else { |
247 | - $this->footer_js_attributes[ $handle ] = $script_attribute; |
|
247 | + $this->footer_js_attributes[$handle] = $script_attribute; |
|
248 | 248 | } |
249 | 249 | } |
250 | 250 | } |
@@ -256,9 +256,9 @@ discard block |
||
256 | 256 | * @param string $var_name |
257 | 257 | * @throws DomainException |
258 | 258 | */ |
259 | - public function addLocalizedVars( array $vars, $var_name = 'eei18n' ) |
|
259 | + public function addLocalizedVars(array $vars, $var_name = 'eei18n') |
|
260 | 260 | { |
261 | - if ( empty( $vars ) ) { |
|
261 | + if (empty($vars)) { |
|
262 | 262 | throw new DomainException( |
263 | 263 | esc_html__( |
264 | 264 | 'A non-empty array of vars, is required to add localized Javascript vars to an iframe.', |
@@ -266,16 +266,16 @@ discard block |
||
266 | 266 | ) |
267 | 267 | ); |
268 | 268 | } |
269 | - foreach ( $vars as $handle => $var ) { |
|
270 | - if ( $var_name === 'eei18n' ) { |
|
271 | - EE_Registry::$i18n_js_strings[ $handle ] = $var; |
|
269 | + foreach ($vars as $handle => $var) { |
|
270 | + if ($var_name === 'eei18n') { |
|
271 | + EE_Registry::$i18n_js_strings[$handle] = $var; |
|
272 | 272 | } elseif ($var_name === 'eeCAL' && $handle === 'espresso_calendar') { |
273 | - $this->localized_vars[ $var_name ] = $var; |
|
273 | + $this->localized_vars[$var_name] = $var; |
|
274 | 274 | } else { |
275 | - if ( ! isset( $this->localized_vars[ $var_name ] ) ) { |
|
276 | - $this->localized_vars[ $var_name ] = array(); |
|
275 | + if ( ! isset($this->localized_vars[$var_name])) { |
|
276 | + $this->localized_vars[$var_name] = array(); |
|
277 | 277 | } |
278 | - $this->localized_vars[ $var_name ][ $handle ] = $var; |
|
278 | + $this->localized_vars[$var_name][$handle] = $var; |
|
279 | 279 | } |
280 | 280 | } |
281 | 281 | } |
@@ -307,7 +307,7 @@ discard block |
||
307 | 307 | public function getTemplate() |
308 | 308 | { |
309 | 309 | return EEH_Template::display_template( |
310 | - __DIR__ . DIRECTORY_SEPARATOR . 'iframe_wrapper.template.php', |
|
310 | + __DIR__.DIRECTORY_SEPARATOR.'iframe_wrapper.template.php', |
|
311 | 311 | array( |
312 | 312 | 'title' => apply_filters( |
313 | 313 | 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__title', |
@@ -324,12 +324,12 @@ discard block |
||
324 | 324 | $this->enqueue_wp_assets, |
325 | 325 | $this |
326 | 326 | ), |
327 | - 'css' => (array)apply_filters( |
|
327 | + 'css' => (array) apply_filters( |
|
328 | 328 | 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__css_urls', |
329 | 329 | $this->css, |
330 | 330 | $this |
331 | 331 | ), |
332 | - 'header_js' => (array)apply_filters( |
|
332 | + 'header_js' => (array) apply_filters( |
|
333 | 333 | 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__header_js_urls', |
334 | 334 | $this->header_js, |
335 | 335 | $this |
@@ -339,23 +339,23 @@ discard block |
||
339 | 339 | $this->header_js_attributes, |
340 | 340 | $this |
341 | 341 | ), |
342 | - 'footer_js' => (array)apply_filters( |
|
342 | + 'footer_js' => (array) apply_filters( |
|
343 | 343 | 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__footer_js_urls', |
344 | 344 | $this->footer_js, |
345 | 345 | $this |
346 | 346 | ), |
347 | - 'footer_js_attributes' => (array)apply_filters( |
|
347 | + 'footer_js_attributes' => (array) apply_filters( |
|
348 | 348 | 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__footer_js_attributes', |
349 | 349 | $this->footer_js_attributes, |
350 | 350 | $this |
351 | 351 | ), |
352 | 352 | 'eei18n' => apply_filters( |
353 | 353 | 'FHEE___EventEspresso_core_libraries_iframe_display_Iframe__getTemplate__eei18n_js_strings', |
354 | - EE_Registry::localize_i18n_js_strings() . $this->localizeJsonVars(), |
|
354 | + EE_Registry::localize_i18n_js_strings().$this->localizeJsonVars(), |
|
355 | 355 | $this |
356 | 356 | ), |
357 | 357 | 'notices' => EEH_Template::display_template( |
358 | - EE_TEMPLATES . 'espresso-ajax-notices.template.php', |
|
358 | + EE_TEMPLATES.'espresso-ajax-notices.template.php', |
|
359 | 359 | array(), |
360 | 360 | true |
361 | 361 | ), |
@@ -375,10 +375,10 @@ discard block |
||
375 | 375 | public function localizeJsonVars() |
376 | 376 | { |
377 | 377 | $JSON = ''; |
378 | - foreach ( (array)$this->localized_vars as $var_name => $vars ) { |
|
379 | - $this->localized_vars[ $var_name ] = $this->encodeJsonVars($vars ); |
|
378 | + foreach ((array) $this->localized_vars as $var_name => $vars) { |
|
379 | + $this->localized_vars[$var_name] = $this->encodeJsonVars($vars); |
|
380 | 380 | $JSON .= "/* <![CDATA[ */ var {$var_name} = "; |
381 | - $JSON .= wp_json_encode( $this->localized_vars[ $var_name ] ); |
|
381 | + $JSON .= wp_json_encode($this->localized_vars[$var_name]); |
|
382 | 382 | $JSON .= '; /* ]]> */'; |
383 | 383 | } |
384 | 384 | return $JSON; |
@@ -390,17 +390,17 @@ discard block |
||
390 | 390 | * @param bool|int|float|string|array $var |
391 | 391 | * @return array |
392 | 392 | */ |
393 | - public function encodeJsonVars( $var ) |
|
393 | + public function encodeJsonVars($var) |
|
394 | 394 | { |
395 | - if ( is_array( $var ) ) { |
|
395 | + if (is_array($var)) { |
|
396 | 396 | $localized_vars = array(); |
397 | - foreach ( (array)$var as $key => $value ) { |
|
398 | - $localized_vars[ $key ] = $this->encodeJsonVars( $value ); |
|
397 | + foreach ((array) $var as $key => $value) { |
|
398 | + $localized_vars[$key] = $this->encodeJsonVars($value); |
|
399 | 399 | } |
400 | 400 | return $localized_vars; |
401 | 401 | } |
402 | - if ( is_scalar( $var ) ) { |
|
403 | - return html_entity_decode( (string)$var, ENT_QUOTES, 'UTF-8' ); |
|
402 | + if (is_scalar($var)) { |
|
403 | + return html_entity_decode((string) $var, ENT_QUOTES, 'UTF-8'); |
|
404 | 404 | } |
405 | 405 | return null; |
406 | 406 | } |
@@ -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'), |
@@ -11,8 +11,8 @@ discard block |
||
11 | 11 | // if you're a dev and want to receive all errors via email |
12 | 12 | // add this to your wp-config.php: define( 'EE_ERROR_EMAILS', TRUE ); |
13 | 13 | if (defined('WP_DEBUG') && WP_DEBUG === true && defined('EE_ERROR_EMAILS') && EE_ERROR_EMAILS === true) { |
14 | - set_error_handler(array('EE_Error', 'error_handler')); |
|
15 | - register_shutdown_function(array('EE_Error', 'fatal_error_handler')); |
|
14 | + set_error_handler(array('EE_Error', 'error_handler')); |
|
15 | + register_shutdown_function(array('EE_Error', 'fatal_error_handler')); |
|
16 | 16 | } |
17 | 17 | |
18 | 18 | |
@@ -27,258 +27,258 @@ discard block |
||
27 | 27 | class EE_Error extends Exception |
28 | 28 | { |
29 | 29 | |
30 | - const OPTIONS_KEY_NOTICES = 'ee_notices'; |
|
31 | - |
|
32 | - |
|
33 | - /** |
|
34 | - * name of the file to log exceptions to |
|
35 | - * |
|
36 | - * @var string |
|
37 | - */ |
|
38 | - private static $_exception_log_file = 'espresso_error_log.txt'; |
|
39 | - |
|
40 | - /** |
|
41 | - * stores details for all exception |
|
42 | - * |
|
43 | - * @var array |
|
44 | - */ |
|
45 | - private static $_all_exceptions = array(); |
|
46 | - |
|
47 | - /** |
|
48 | - * tracks number of errors |
|
49 | - * |
|
50 | - * @var int |
|
51 | - */ |
|
52 | - private static $_error_count = 0; |
|
53 | - |
|
54 | - /** |
|
55 | - * @var array $_espresso_notices |
|
56 | - */ |
|
57 | - private static $_espresso_notices = array('success' => false, 'errors' => false, 'attention' => false); |
|
58 | - |
|
59 | - |
|
60 | - |
|
61 | - /** |
|
62 | - * @override default exception handling |
|
63 | - * @param string $message |
|
64 | - * @param int $code |
|
65 | - * @param Exception|null $previous |
|
66 | - */ |
|
67 | - public function __construct($message, $code = 0, Exception $previous = null) |
|
68 | - { |
|
69 | - if (version_compare(PHP_VERSION, '5.3.0', '<')) { |
|
70 | - parent::__construct($message, $code); |
|
71 | - } else { |
|
72 | - parent::__construct($message, $code, $previous); |
|
73 | - } |
|
74 | - } |
|
75 | - |
|
76 | - |
|
77 | - /** |
|
78 | - * error_handler |
|
79 | - * |
|
80 | - * @param $code |
|
81 | - * @param $message |
|
82 | - * @param $file |
|
83 | - * @param $line |
|
84 | - * @return void |
|
85 | - */ |
|
86 | - public static function error_handler($code, $message, $file, $line) |
|
87 | - { |
|
88 | - $type = EE_Error::error_type($code); |
|
89 | - $site = site_url(); |
|
90 | - switch ($site) { |
|
91 | - case 'http://ee4.eventespresso.com/' : |
|
92 | - case 'http://ee4decaf.eventespresso.com/' : |
|
93 | - case 'http://ee4hf.eventespresso.com/' : |
|
94 | - case 'http://ee4a.eventespresso.com/' : |
|
95 | - case 'http://ee4ad.eventespresso.com/' : |
|
96 | - case 'http://ee4b.eventespresso.com/' : |
|
97 | - case 'http://ee4bd.eventespresso.com/' : |
|
98 | - case 'http://ee4d.eventespresso.com/' : |
|
99 | - case 'http://ee4dd.eventespresso.com/' : |
|
100 | - $to = '[email protected]'; |
|
101 | - break; |
|
102 | - default : |
|
103 | - $to = get_option('admin_email'); |
|
104 | - } |
|
105 | - $subject = $type . ' ' . $message . ' in ' . EVENT_ESPRESSO_VERSION . ' on ' . site_url(); |
|
106 | - $msg = EE_Error::_format_error($type, $message, $file, $line); |
|
107 | - if (function_exists('wp_mail')) { |
|
108 | - add_filter('wp_mail_content_type', array('EE_Error', 'set_content_type')); |
|
109 | - wp_mail($to, $subject, $msg); |
|
110 | - } |
|
111 | - echo '<div id="message" class="espresso-notices error"><p>'; |
|
112 | - echo $type . ': ' . $message . '<br />' . $file . ' line ' . $line; |
|
113 | - echo '<br /></p></div>'; |
|
114 | - } |
|
115 | - |
|
116 | - |
|
117 | - |
|
118 | - /** |
|
119 | - * error_type |
|
120 | - * http://www.php.net/manual/en/errorfunc.constants.php#109430 |
|
121 | - * |
|
122 | - * @param $code |
|
123 | - * @return string |
|
124 | - */ |
|
125 | - public static function error_type($code) |
|
126 | - { |
|
127 | - switch ($code) { |
|
128 | - case E_ERROR: // 1 // |
|
129 | - return 'E_ERROR'; |
|
130 | - case E_WARNING: // 2 // |
|
131 | - return 'E_WARNING'; |
|
132 | - case E_PARSE: // 4 // |
|
133 | - return 'E_PARSE'; |
|
134 | - case E_NOTICE: // 8 // |
|
135 | - return 'E_NOTICE'; |
|
136 | - case E_CORE_ERROR: // 16 // |
|
137 | - return 'E_CORE_ERROR'; |
|
138 | - case E_CORE_WARNING: // 32 // |
|
139 | - return 'E_CORE_WARNING'; |
|
140 | - case E_COMPILE_ERROR: // 64 // |
|
141 | - return 'E_COMPILE_ERROR'; |
|
142 | - case E_COMPILE_WARNING: // 128 // |
|
143 | - return 'E_COMPILE_WARNING'; |
|
144 | - case E_USER_ERROR: // 256 // |
|
145 | - return 'E_USER_ERROR'; |
|
146 | - case E_USER_WARNING: // 512 // |
|
147 | - return 'E_USER_WARNING'; |
|
148 | - case E_USER_NOTICE: // 1024 // |
|
149 | - return 'E_USER_NOTICE'; |
|
150 | - case E_STRICT: // 2048 // |
|
151 | - return 'E_STRICT'; |
|
152 | - case E_RECOVERABLE_ERROR: // 4096 // |
|
153 | - return 'E_RECOVERABLE_ERROR'; |
|
154 | - case E_DEPRECATED: // 8192 // |
|
155 | - return 'E_DEPRECATED'; |
|
156 | - case E_USER_DEPRECATED: // 16384 // |
|
157 | - return 'E_USER_DEPRECATED'; |
|
158 | - case E_ALL: // 16384 // |
|
159 | - return 'E_ALL'; |
|
160 | - } |
|
161 | - return ''; |
|
162 | - } |
|
163 | - |
|
164 | - |
|
165 | - |
|
166 | - /** |
|
167 | - * fatal_error_handler |
|
168 | - * |
|
169 | - * @return void |
|
170 | - */ |
|
171 | - public static function fatal_error_handler() |
|
172 | - { |
|
173 | - $last_error = error_get_last(); |
|
174 | - if ($last_error['type'] === E_ERROR) { |
|
175 | - EE_Error::error_handler(E_ERROR, $last_error['message'], $last_error['file'], $last_error['line']); |
|
176 | - } |
|
177 | - } |
|
178 | - |
|
179 | - |
|
180 | - |
|
181 | - /** |
|
182 | - * _format_error |
|
183 | - * |
|
184 | - * @param $code |
|
185 | - * @param $message |
|
186 | - * @param $file |
|
187 | - * @param $line |
|
188 | - * @return string |
|
189 | - */ |
|
190 | - private static function _format_error($code, $message, $file, $line) |
|
191 | - { |
|
192 | - $html = "<table cellpadding='5'><thead bgcolor='#f8f8f8'><th>Item</th><th align='left'>Details</th></thead><tbody>"; |
|
193 | - $html .= "<tr valign='top'><td><b>Code</b></td><td>$code</td></tr>"; |
|
194 | - $html .= "<tr valign='top'><td><b>Error</b></td><td>$message</td></tr>"; |
|
195 | - $html .= "<tr valign='top'><td><b>File</b></td><td>$file</td></tr>"; |
|
196 | - $html .= "<tr valign='top'><td><b>Line</b></td><td>$line</td></tr>"; |
|
197 | - $html .= '</tbody></table>'; |
|
198 | - return $html; |
|
199 | - } |
|
200 | - |
|
201 | - |
|
202 | - |
|
203 | - /** |
|
204 | - * set_content_type |
|
205 | - * |
|
206 | - * @param $content_type |
|
207 | - * @return string |
|
208 | - */ |
|
209 | - public static function set_content_type($content_type) |
|
210 | - { |
|
211 | - return 'text/html'; |
|
212 | - } |
|
213 | - |
|
214 | - |
|
215 | - |
|
216 | - /** |
|
217 | - * @return void |
|
218 | - * @throws EE_Error |
|
219 | - * @throws ReflectionException |
|
220 | - */ |
|
221 | - public function get_error() |
|
222 | - { |
|
223 | - if (apply_filters('FHEE__EE_Error__get_error__show_normal_exceptions', false)) { |
|
224 | - throw $this; |
|
225 | - } |
|
226 | - // get separate user and developer messages if they exist |
|
227 | - $msg = explode('||', $this->getMessage()); |
|
228 | - $user_msg = $msg[0]; |
|
229 | - $dev_msg = isset($msg[1]) ? $msg[1] : $msg[0]; |
|
230 | - $msg = WP_DEBUG ? $dev_msg : $user_msg; |
|
231 | - // add details to _all_exceptions array |
|
232 | - $x_time = time(); |
|
233 | - self::$_all_exceptions[$x_time]['name'] = get_class($this); |
|
234 | - self::$_all_exceptions[$x_time]['file'] = $this->getFile(); |
|
235 | - self::$_all_exceptions[$x_time]['line'] = $this->getLine(); |
|
236 | - self::$_all_exceptions[$x_time]['msg'] = $msg; |
|
237 | - self::$_all_exceptions[$x_time]['code'] = $this->getCode(); |
|
238 | - self::$_all_exceptions[$x_time]['trace'] = $this->getTrace(); |
|
239 | - self::$_all_exceptions[$x_time]['string'] = $this->getTraceAsString(); |
|
240 | - self::$_error_count++; |
|
241 | - //add_action( 'shutdown', array( $this, 'display_errors' )); |
|
242 | - $this->display_errors(); |
|
243 | - } |
|
244 | - |
|
245 | - |
|
246 | - /** |
|
247 | - * @param bool $check_stored |
|
248 | - * @param string $type_to_check |
|
249 | - * @return bool |
|
250 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
251 | - * @throws \InvalidArgumentException |
|
252 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
253 | - * @throws InvalidInterfaceException |
|
254 | - */ |
|
255 | - public static function has_error($check_stored = false, $type_to_check = 'errors') |
|
256 | - { |
|
257 | - $has_error = isset(self::$_espresso_notices[$type_to_check]) |
|
258 | - && ! empty(self::$_espresso_notices[$type_to_check]) |
|
259 | - ? true |
|
260 | - : false; |
|
261 | - if ($check_stored && ! $has_error) { |
|
262 | - $notices = EE_Error::getStoredNotices(); |
|
263 | - foreach ($notices as $type => $notice) { |
|
264 | - if ($type === $type_to_check && $notice) { |
|
265 | - return true; |
|
266 | - } |
|
267 | - } |
|
268 | - } |
|
269 | - return $has_error; |
|
270 | - } |
|
271 | - |
|
272 | - |
|
273 | - |
|
274 | - /** |
|
275 | - * @echo string |
|
276 | - * @throws \ReflectionException |
|
277 | - */ |
|
278 | - public function display_errors() |
|
279 | - { |
|
280 | - $trace_details = ''; |
|
281 | - $output = ' |
|
30 | + const OPTIONS_KEY_NOTICES = 'ee_notices'; |
|
31 | + |
|
32 | + |
|
33 | + /** |
|
34 | + * name of the file to log exceptions to |
|
35 | + * |
|
36 | + * @var string |
|
37 | + */ |
|
38 | + private static $_exception_log_file = 'espresso_error_log.txt'; |
|
39 | + |
|
40 | + /** |
|
41 | + * stores details for all exception |
|
42 | + * |
|
43 | + * @var array |
|
44 | + */ |
|
45 | + private static $_all_exceptions = array(); |
|
46 | + |
|
47 | + /** |
|
48 | + * tracks number of errors |
|
49 | + * |
|
50 | + * @var int |
|
51 | + */ |
|
52 | + private static $_error_count = 0; |
|
53 | + |
|
54 | + /** |
|
55 | + * @var array $_espresso_notices |
|
56 | + */ |
|
57 | + private static $_espresso_notices = array('success' => false, 'errors' => false, 'attention' => false); |
|
58 | + |
|
59 | + |
|
60 | + |
|
61 | + /** |
|
62 | + * @override default exception handling |
|
63 | + * @param string $message |
|
64 | + * @param int $code |
|
65 | + * @param Exception|null $previous |
|
66 | + */ |
|
67 | + public function __construct($message, $code = 0, Exception $previous = null) |
|
68 | + { |
|
69 | + if (version_compare(PHP_VERSION, '5.3.0', '<')) { |
|
70 | + parent::__construct($message, $code); |
|
71 | + } else { |
|
72 | + parent::__construct($message, $code, $previous); |
|
73 | + } |
|
74 | + } |
|
75 | + |
|
76 | + |
|
77 | + /** |
|
78 | + * error_handler |
|
79 | + * |
|
80 | + * @param $code |
|
81 | + * @param $message |
|
82 | + * @param $file |
|
83 | + * @param $line |
|
84 | + * @return void |
|
85 | + */ |
|
86 | + public static function error_handler($code, $message, $file, $line) |
|
87 | + { |
|
88 | + $type = EE_Error::error_type($code); |
|
89 | + $site = site_url(); |
|
90 | + switch ($site) { |
|
91 | + case 'http://ee4.eventespresso.com/' : |
|
92 | + case 'http://ee4decaf.eventespresso.com/' : |
|
93 | + case 'http://ee4hf.eventespresso.com/' : |
|
94 | + case 'http://ee4a.eventespresso.com/' : |
|
95 | + case 'http://ee4ad.eventespresso.com/' : |
|
96 | + case 'http://ee4b.eventespresso.com/' : |
|
97 | + case 'http://ee4bd.eventespresso.com/' : |
|
98 | + case 'http://ee4d.eventespresso.com/' : |
|
99 | + case 'http://ee4dd.eventespresso.com/' : |
|
100 | + $to = '[email protected]'; |
|
101 | + break; |
|
102 | + default : |
|
103 | + $to = get_option('admin_email'); |
|
104 | + } |
|
105 | + $subject = $type . ' ' . $message . ' in ' . EVENT_ESPRESSO_VERSION . ' on ' . site_url(); |
|
106 | + $msg = EE_Error::_format_error($type, $message, $file, $line); |
|
107 | + if (function_exists('wp_mail')) { |
|
108 | + add_filter('wp_mail_content_type', array('EE_Error', 'set_content_type')); |
|
109 | + wp_mail($to, $subject, $msg); |
|
110 | + } |
|
111 | + echo '<div id="message" class="espresso-notices error"><p>'; |
|
112 | + echo $type . ': ' . $message . '<br />' . $file . ' line ' . $line; |
|
113 | + echo '<br /></p></div>'; |
|
114 | + } |
|
115 | + |
|
116 | + |
|
117 | + |
|
118 | + /** |
|
119 | + * error_type |
|
120 | + * http://www.php.net/manual/en/errorfunc.constants.php#109430 |
|
121 | + * |
|
122 | + * @param $code |
|
123 | + * @return string |
|
124 | + */ |
|
125 | + public static function error_type($code) |
|
126 | + { |
|
127 | + switch ($code) { |
|
128 | + case E_ERROR: // 1 // |
|
129 | + return 'E_ERROR'; |
|
130 | + case E_WARNING: // 2 // |
|
131 | + return 'E_WARNING'; |
|
132 | + case E_PARSE: // 4 // |
|
133 | + return 'E_PARSE'; |
|
134 | + case E_NOTICE: // 8 // |
|
135 | + return 'E_NOTICE'; |
|
136 | + case E_CORE_ERROR: // 16 // |
|
137 | + return 'E_CORE_ERROR'; |
|
138 | + case E_CORE_WARNING: // 32 // |
|
139 | + return 'E_CORE_WARNING'; |
|
140 | + case E_COMPILE_ERROR: // 64 // |
|
141 | + return 'E_COMPILE_ERROR'; |
|
142 | + case E_COMPILE_WARNING: // 128 // |
|
143 | + return 'E_COMPILE_WARNING'; |
|
144 | + case E_USER_ERROR: // 256 // |
|
145 | + return 'E_USER_ERROR'; |
|
146 | + case E_USER_WARNING: // 512 // |
|
147 | + return 'E_USER_WARNING'; |
|
148 | + case E_USER_NOTICE: // 1024 // |
|
149 | + return 'E_USER_NOTICE'; |
|
150 | + case E_STRICT: // 2048 // |
|
151 | + return 'E_STRICT'; |
|
152 | + case E_RECOVERABLE_ERROR: // 4096 // |
|
153 | + return 'E_RECOVERABLE_ERROR'; |
|
154 | + case E_DEPRECATED: // 8192 // |
|
155 | + return 'E_DEPRECATED'; |
|
156 | + case E_USER_DEPRECATED: // 16384 // |
|
157 | + return 'E_USER_DEPRECATED'; |
|
158 | + case E_ALL: // 16384 // |
|
159 | + return 'E_ALL'; |
|
160 | + } |
|
161 | + return ''; |
|
162 | + } |
|
163 | + |
|
164 | + |
|
165 | + |
|
166 | + /** |
|
167 | + * fatal_error_handler |
|
168 | + * |
|
169 | + * @return void |
|
170 | + */ |
|
171 | + public static function fatal_error_handler() |
|
172 | + { |
|
173 | + $last_error = error_get_last(); |
|
174 | + if ($last_error['type'] === E_ERROR) { |
|
175 | + EE_Error::error_handler(E_ERROR, $last_error['message'], $last_error['file'], $last_error['line']); |
|
176 | + } |
|
177 | + } |
|
178 | + |
|
179 | + |
|
180 | + |
|
181 | + /** |
|
182 | + * _format_error |
|
183 | + * |
|
184 | + * @param $code |
|
185 | + * @param $message |
|
186 | + * @param $file |
|
187 | + * @param $line |
|
188 | + * @return string |
|
189 | + */ |
|
190 | + private static function _format_error($code, $message, $file, $line) |
|
191 | + { |
|
192 | + $html = "<table cellpadding='5'><thead bgcolor='#f8f8f8'><th>Item</th><th align='left'>Details</th></thead><tbody>"; |
|
193 | + $html .= "<tr valign='top'><td><b>Code</b></td><td>$code</td></tr>"; |
|
194 | + $html .= "<tr valign='top'><td><b>Error</b></td><td>$message</td></tr>"; |
|
195 | + $html .= "<tr valign='top'><td><b>File</b></td><td>$file</td></tr>"; |
|
196 | + $html .= "<tr valign='top'><td><b>Line</b></td><td>$line</td></tr>"; |
|
197 | + $html .= '</tbody></table>'; |
|
198 | + return $html; |
|
199 | + } |
|
200 | + |
|
201 | + |
|
202 | + |
|
203 | + /** |
|
204 | + * set_content_type |
|
205 | + * |
|
206 | + * @param $content_type |
|
207 | + * @return string |
|
208 | + */ |
|
209 | + public static function set_content_type($content_type) |
|
210 | + { |
|
211 | + return 'text/html'; |
|
212 | + } |
|
213 | + |
|
214 | + |
|
215 | + |
|
216 | + /** |
|
217 | + * @return void |
|
218 | + * @throws EE_Error |
|
219 | + * @throws ReflectionException |
|
220 | + */ |
|
221 | + public function get_error() |
|
222 | + { |
|
223 | + if (apply_filters('FHEE__EE_Error__get_error__show_normal_exceptions', false)) { |
|
224 | + throw $this; |
|
225 | + } |
|
226 | + // get separate user and developer messages if they exist |
|
227 | + $msg = explode('||', $this->getMessage()); |
|
228 | + $user_msg = $msg[0]; |
|
229 | + $dev_msg = isset($msg[1]) ? $msg[1] : $msg[0]; |
|
230 | + $msg = WP_DEBUG ? $dev_msg : $user_msg; |
|
231 | + // add details to _all_exceptions array |
|
232 | + $x_time = time(); |
|
233 | + self::$_all_exceptions[$x_time]['name'] = get_class($this); |
|
234 | + self::$_all_exceptions[$x_time]['file'] = $this->getFile(); |
|
235 | + self::$_all_exceptions[$x_time]['line'] = $this->getLine(); |
|
236 | + self::$_all_exceptions[$x_time]['msg'] = $msg; |
|
237 | + self::$_all_exceptions[$x_time]['code'] = $this->getCode(); |
|
238 | + self::$_all_exceptions[$x_time]['trace'] = $this->getTrace(); |
|
239 | + self::$_all_exceptions[$x_time]['string'] = $this->getTraceAsString(); |
|
240 | + self::$_error_count++; |
|
241 | + //add_action( 'shutdown', array( $this, 'display_errors' )); |
|
242 | + $this->display_errors(); |
|
243 | + } |
|
244 | + |
|
245 | + |
|
246 | + /** |
|
247 | + * @param bool $check_stored |
|
248 | + * @param string $type_to_check |
|
249 | + * @return bool |
|
250 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
251 | + * @throws \InvalidArgumentException |
|
252 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
253 | + * @throws InvalidInterfaceException |
|
254 | + */ |
|
255 | + public static function has_error($check_stored = false, $type_to_check = 'errors') |
|
256 | + { |
|
257 | + $has_error = isset(self::$_espresso_notices[$type_to_check]) |
|
258 | + && ! empty(self::$_espresso_notices[$type_to_check]) |
|
259 | + ? true |
|
260 | + : false; |
|
261 | + if ($check_stored && ! $has_error) { |
|
262 | + $notices = EE_Error::getStoredNotices(); |
|
263 | + foreach ($notices as $type => $notice) { |
|
264 | + if ($type === $type_to_check && $notice) { |
|
265 | + return true; |
|
266 | + } |
|
267 | + } |
|
268 | + } |
|
269 | + return $has_error; |
|
270 | + } |
|
271 | + |
|
272 | + |
|
273 | + |
|
274 | + /** |
|
275 | + * @echo string |
|
276 | + * @throws \ReflectionException |
|
277 | + */ |
|
278 | + public function display_errors() |
|
279 | + { |
|
280 | + $trace_details = ''; |
|
281 | + $output = ' |
|
282 | 282 | <style type="text/css"> |
283 | 283 | #ee-error-message { |
284 | 284 | max-width:90% !important; |
@@ -334,21 +334,21 @@ discard block |
||
334 | 334 | } |
335 | 335 | </style> |
336 | 336 | <div id="ee-error-message" class="error">'; |
337 | - if (! WP_DEBUG) { |
|
338 | - $output .= ' |
|
337 | + if (! WP_DEBUG) { |
|
338 | + $output .= ' |
|
339 | 339 | <p>'; |
340 | - } |
|
341 | - // cycle thru errors |
|
342 | - foreach (self::$_all_exceptions as $time => $ex) { |
|
343 | - $error_code = ''; |
|
344 | - // process trace info |
|
345 | - if (empty($ex['trace'])) { |
|
346 | - $trace_details .= __( |
|
347 | - 'Sorry, but no trace information was available for this exception.', |
|
348 | - 'event_espresso' |
|
349 | - ); |
|
350 | - } else { |
|
351 | - $trace_details .= ' |
|
340 | + } |
|
341 | + // cycle thru errors |
|
342 | + foreach (self::$_all_exceptions as $time => $ex) { |
|
343 | + $error_code = ''; |
|
344 | + // process trace info |
|
345 | + if (empty($ex['trace'])) { |
|
346 | + $trace_details .= __( |
|
347 | + 'Sorry, but no trace information was available for this exception.', |
|
348 | + 'event_espresso' |
|
349 | + ); |
|
350 | + } else { |
|
351 | + $trace_details .= ' |
|
352 | 352 | <div id="ee-trace-details"> |
353 | 353 | <table width="100%" border="0" cellpadding="5" cellspacing="0"> |
354 | 354 | <tr> |
@@ -358,43 +358,43 @@ discard block |
||
358 | 358 | <th scope="col" align="left">Class</th> |
359 | 359 | <th scope="col" align="left">Method( arguments )</th> |
360 | 360 | </tr>'; |
361 | - $last_on_stack = count($ex['trace']) - 1; |
|
362 | - // reverse array so that stack is in proper chronological order |
|
363 | - $sorted_trace = array_reverse($ex['trace']); |
|
364 | - foreach ($sorted_trace as $nmbr => $trace) { |
|
365 | - $file = isset($trace['file']) ? $trace['file'] : ''; |
|
366 | - $class = isset($trace['class']) ? $trace['class'] : ''; |
|
367 | - $type = isset($trace['type']) ? $trace['type'] : ''; |
|
368 | - $function = isset($trace['function']) ? $trace['function'] : ''; |
|
369 | - $args = isset($trace['args']) ? $this->_convert_args_to_string($trace['args']) : ''; |
|
370 | - $line = isset($trace['line']) ? $trace['line'] : ''; |
|
371 | - $zebra = ($nmbr % 2) ? ' odd' : ''; |
|
372 | - if (empty($file) && ! empty($class)) { |
|
373 | - $a = new ReflectionClass($class); |
|
374 | - $file = $a->getFileName(); |
|
375 | - if (empty($line) && ! empty($function)) { |
|
376 | - try { |
|
377 | - //if $function is a closure, this throws an exception |
|
378 | - $b = new ReflectionMethod($class, $function); |
|
379 | - $line = $b->getStartLine(); |
|
380 | - } catch (Exception $closure_exception) { |
|
381 | - $line = 'unknown'; |
|
382 | - } |
|
383 | - } |
|
384 | - } |
|
385 | - if ($nmbr === $last_on_stack) { |
|
386 | - $file = $ex['file'] !== '' ? $ex['file'] : $file; |
|
387 | - $line = $ex['line'] !== '' ? $ex['line'] : $line; |
|
388 | - $error_code = self::generate_error_code($file, $trace['function'], $line); |
|
389 | - } |
|
390 | - $nmbr_dsply = ! empty($nmbr) ? $nmbr : ' '; |
|
391 | - $line_dsply = ! empty($line) ? $line : ' '; |
|
392 | - $file_dsply = ! empty($file) ? $file : ' '; |
|
393 | - $class_dsply = ! empty($class) ? $class : ' '; |
|
394 | - $type_dsply = ! empty($type) ? $type : ' '; |
|
395 | - $function_dsply = ! empty($function) ? $function : ' '; |
|
396 | - $args_dsply = ! empty($args) ? '( ' . $args . ' )' : ''; |
|
397 | - $trace_details .= ' |
|
361 | + $last_on_stack = count($ex['trace']) - 1; |
|
362 | + // reverse array so that stack is in proper chronological order |
|
363 | + $sorted_trace = array_reverse($ex['trace']); |
|
364 | + foreach ($sorted_trace as $nmbr => $trace) { |
|
365 | + $file = isset($trace['file']) ? $trace['file'] : ''; |
|
366 | + $class = isset($trace['class']) ? $trace['class'] : ''; |
|
367 | + $type = isset($trace['type']) ? $trace['type'] : ''; |
|
368 | + $function = isset($trace['function']) ? $trace['function'] : ''; |
|
369 | + $args = isset($trace['args']) ? $this->_convert_args_to_string($trace['args']) : ''; |
|
370 | + $line = isset($trace['line']) ? $trace['line'] : ''; |
|
371 | + $zebra = ($nmbr % 2) ? ' odd' : ''; |
|
372 | + if (empty($file) && ! empty($class)) { |
|
373 | + $a = new ReflectionClass($class); |
|
374 | + $file = $a->getFileName(); |
|
375 | + if (empty($line) && ! empty($function)) { |
|
376 | + try { |
|
377 | + //if $function is a closure, this throws an exception |
|
378 | + $b = new ReflectionMethod($class, $function); |
|
379 | + $line = $b->getStartLine(); |
|
380 | + } catch (Exception $closure_exception) { |
|
381 | + $line = 'unknown'; |
|
382 | + } |
|
383 | + } |
|
384 | + } |
|
385 | + if ($nmbr === $last_on_stack) { |
|
386 | + $file = $ex['file'] !== '' ? $ex['file'] : $file; |
|
387 | + $line = $ex['line'] !== '' ? $ex['line'] : $line; |
|
388 | + $error_code = self::generate_error_code($file, $trace['function'], $line); |
|
389 | + } |
|
390 | + $nmbr_dsply = ! empty($nmbr) ? $nmbr : ' '; |
|
391 | + $line_dsply = ! empty($line) ? $line : ' '; |
|
392 | + $file_dsply = ! empty($file) ? $file : ' '; |
|
393 | + $class_dsply = ! empty($class) ? $class : ' '; |
|
394 | + $type_dsply = ! empty($type) ? $type : ' '; |
|
395 | + $function_dsply = ! empty($function) ? $function : ' '; |
|
396 | + $args_dsply = ! empty($args) ? '( ' . $args . ' )' : ''; |
|
397 | + $trace_details .= ' |
|
398 | 398 | <tr> |
399 | 399 | <td align="right" class="' . $zebra . '">' . $nmbr_dsply . '</td> |
400 | 400 | <td align="right" class="' . $zebra . '">' . $line_dsply . '</td> |
@@ -402,633 +402,633 @@ discard block |
||
402 | 402 | <td align="left" class="' . $zebra . '">' . $class_dsply . '</td> |
403 | 403 | <td align="left" class="' . $zebra . '">' . $type_dsply . $function_dsply . $args_dsply . '</td> |
404 | 404 | </tr>'; |
405 | - } |
|
406 | - $trace_details .= ' |
|
405 | + } |
|
406 | + $trace_details .= ' |
|
407 | 407 | </table> |
408 | 408 | </div>'; |
409 | - } |
|
410 | - $ex['code'] = $ex['code'] ? $ex['code'] : $error_code; |
|
411 | - // add generic non-identifying messages for non-privileged users |
|
412 | - if (! WP_DEBUG) { |
|
413 | - $output .= '<span class="ee-error-user-msg-spn">' |
|
414 | - . trim($ex['msg']) |
|
415 | - . '</span> <sup>' |
|
416 | - . $ex['code'] |
|
417 | - . '</sup><br />'; |
|
418 | - } else { |
|
419 | - // or helpful developer messages if debugging is on |
|
420 | - $output .= ' |
|
409 | + } |
|
410 | + $ex['code'] = $ex['code'] ? $ex['code'] : $error_code; |
|
411 | + // add generic non-identifying messages for non-privileged users |
|
412 | + if (! WP_DEBUG) { |
|
413 | + $output .= '<span class="ee-error-user-msg-spn">' |
|
414 | + . trim($ex['msg']) |
|
415 | + . '</span> <sup>' |
|
416 | + . $ex['code'] |
|
417 | + . '</sup><br />'; |
|
418 | + } else { |
|
419 | + // or helpful developer messages if debugging is on |
|
420 | + $output .= ' |
|
421 | 421 | <div class="ee-error-dev-msg-dv"> |
422 | 422 | <p class="ee-error-dev-msg-pg"> |
423 | 423 | <strong class="ee-error-dev-msg-str">An ' |
424 | - . $ex['name'] |
|
425 | - . ' exception was thrown!</strong> <span>code: ' |
|
426 | - . $ex['code'] |
|
427 | - . '</span><br /> |
|
424 | + . $ex['name'] |
|
425 | + . ' exception was thrown!</strong> <span>code: ' |
|
426 | + . $ex['code'] |
|
427 | + . '</span><br /> |
|
428 | 428 | <span class="big-text">"' |
429 | - . trim($ex['msg']) |
|
430 | - . '"</span><br/> |
|
429 | + . trim($ex['msg']) |
|
430 | + . '"</span><br/> |
|
431 | 431 | <a id="display-ee-error-trace-' |
432 | - . self::$_error_count |
|
433 | - . $time |
|
434 | - . '" class="display-ee-error-trace-lnk small-text" rel="ee-error-trace-' |
|
435 | - . self::$_error_count |
|
436 | - . $time |
|
437 | - . '"> |
|
432 | + . self::$_error_count |
|
433 | + . $time |
|
434 | + . '" class="display-ee-error-trace-lnk small-text" rel="ee-error-trace-' |
|
435 | + . self::$_error_count |
|
436 | + . $time |
|
437 | + . '"> |
|
438 | 438 | ' |
439 | - . __('click to view backtrace and class/method details', 'event_espresso') |
|
440 | - . ' |
|
439 | + . __('click to view backtrace and class/method details', 'event_espresso') |
|
440 | + . ' |
|
441 | 441 | </a><br /> |
442 | 442 | <span class="small-text lt-grey-text">' |
443 | - . $ex['file'] |
|
444 | - . ' ( line no: ' |
|
445 | - . $ex['line'] |
|
446 | - . ' )</span> |
|
443 | + . $ex['file'] |
|
444 | + . ' ( line no: ' |
|
445 | + . $ex['line'] |
|
446 | + . ' )</span> |
|
447 | 447 | </p> |
448 | 448 | <div id="ee-error-trace-' |
449 | - . self::$_error_count |
|
450 | - . $time |
|
451 | - . '-dv" class="ee-error-trace-dv" style="display: none;"> |
|
449 | + . self::$_error_count |
|
450 | + . $time |
|
451 | + . '-dv" class="ee-error-trace-dv" style="display: none;"> |
|
452 | 452 | ' |
453 | - . $trace_details; |
|
454 | - if (! empty($class)) { |
|
455 | - $output .= ' |
|
453 | + . $trace_details; |
|
454 | + if (! empty($class)) { |
|
455 | + $output .= ' |
|
456 | 456 | <div style="padding:3px; margin:0 0 1em; border:1px solid #666; background:#fff; border-radius:3px;"> |
457 | 457 | <div style="padding:1em 2em; border:1px solid #666; background:#f9f9f9;"> |
458 | 458 | <h3>Class Details</h3>'; |
459 | - $a = new ReflectionClass($class); |
|
460 | - $output .= ' |
|
459 | + $a = new ReflectionClass($class); |
|
460 | + $output .= ' |
|
461 | 461 | <pre>' . $a . '</pre> |
462 | 462 | </div> |
463 | 463 | </div>'; |
464 | - } |
|
465 | - $output .= ' |
|
464 | + } |
|
465 | + $output .= ' |
|
466 | 466 | </div> |
467 | 467 | </div> |
468 | 468 | <br />'; |
469 | - } |
|
470 | - $this->write_to_error_log($time, $ex); |
|
471 | - } |
|
472 | - // remove last linebreak |
|
473 | - $output = substr($output, 0, -6); |
|
474 | - if (! WP_DEBUG) { |
|
475 | - $output .= ' |
|
469 | + } |
|
470 | + $this->write_to_error_log($time, $ex); |
|
471 | + } |
|
472 | + // remove last linebreak |
|
473 | + $output = substr($output, 0, -6); |
|
474 | + if (! WP_DEBUG) { |
|
475 | + $output .= ' |
|
476 | 476 | </p>'; |
477 | - } |
|
478 | - $output .= ' |
|
477 | + } |
|
478 | + $output .= ' |
|
479 | 479 | </div>'; |
480 | - $output .= self::_print_scripts(true); |
|
481 | - if (defined('DOING_AJAX')) { |
|
482 | - echo wp_json_encode(array('error' => $output)); |
|
483 | - exit(); |
|
484 | - } |
|
485 | - echo $output; |
|
486 | - die(); |
|
487 | - } |
|
488 | - |
|
489 | - |
|
490 | - |
|
491 | - /** |
|
492 | - * generate string from exception trace args |
|
493 | - * |
|
494 | - * @param array $arguments |
|
495 | - * @param bool $array |
|
496 | - * @return string |
|
497 | - */ |
|
498 | - private function _convert_args_to_string($arguments = array(), $array = false) |
|
499 | - { |
|
500 | - $arg_string = ''; |
|
501 | - if (! empty($arguments)) { |
|
502 | - $args = array(); |
|
503 | - foreach ($arguments as $arg) { |
|
504 | - if (! empty($arg)) { |
|
505 | - if (is_string($arg)) { |
|
506 | - $args[] = " '" . $arg . "'"; |
|
507 | - } elseif (is_array($arg)) { |
|
508 | - $args[] = 'ARRAY(' . $this->_convert_args_to_string($arg, true); |
|
509 | - } elseif ($arg === null) { |
|
510 | - $args[] = ' NULL'; |
|
511 | - } elseif (is_bool($arg)) { |
|
512 | - $args[] = ($arg) ? ' TRUE' : ' FALSE'; |
|
513 | - } elseif (is_object($arg)) { |
|
514 | - $args[] = ' OBJECT ' . get_class($arg); |
|
515 | - } elseif (is_resource($arg)) { |
|
516 | - $args[] = get_resource_type($arg); |
|
517 | - } else { |
|
518 | - $args[] = $arg; |
|
519 | - } |
|
520 | - } |
|
521 | - } |
|
522 | - $arg_string = implode(', ', $args); |
|
523 | - } |
|
524 | - if ($array) { |
|
525 | - $arg_string .= ' )'; |
|
526 | - } |
|
527 | - return $arg_string; |
|
528 | - } |
|
529 | - |
|
530 | - |
|
531 | - |
|
532 | - /** |
|
533 | - * add error message |
|
534 | - * |
|
535 | - * @param string $msg the message to display to users or developers - adding a double pipe || (OR) creates |
|
536 | - * separate messages for user || dev |
|
537 | - * @param string $file the file that the error occurred in - just use __FILE__ |
|
538 | - * @param string $func the function/method that the error occurred in - just use __FUNCTION__ |
|
539 | - * @param string $line the line number where the error occurred - just use __LINE__ |
|
540 | - * @return void |
|
541 | - */ |
|
542 | - public static function add_error($msg = null, $file = null, $func = null, $line = null) |
|
543 | - { |
|
544 | - self::_add_notice('errors', $msg, $file, $func, $line); |
|
545 | - self::$_error_count++; |
|
546 | - } |
|
547 | - |
|
548 | - |
|
549 | - |
|
550 | - /** |
|
551 | - * If WP_DEBUG is active, throws an exception. If WP_DEBUG is off, just |
|
552 | - * adds an error |
|
553 | - * |
|
554 | - * @param string $msg |
|
555 | - * @param string $file |
|
556 | - * @param string $func |
|
557 | - * @param string $line |
|
558 | - * @throws EE_Error |
|
559 | - */ |
|
560 | - public static function throw_exception_if_debugging($msg = null, $file = null, $func = null, $line = null) |
|
561 | - { |
|
562 | - if (WP_DEBUG) { |
|
563 | - throw new EE_Error($msg); |
|
564 | - } |
|
565 | - EE_Error::add_error($msg, $file, $func, $line); |
|
566 | - } |
|
567 | - |
|
568 | - |
|
569 | - |
|
570 | - /** |
|
571 | - * add success message |
|
572 | - * |
|
573 | - * @param string $msg the message to display to users or developers - adding a double pipe || (OR) creates |
|
574 | - * separate messages for user || dev |
|
575 | - * @param string $file the file that the error occurred in - just use __FILE__ |
|
576 | - * @param string $func the function/method that the error occurred in - just use __FUNCTION__ |
|
577 | - * @param string $line the line number where the error occurred - just use __LINE__ |
|
578 | - * @return void |
|
579 | - */ |
|
580 | - public static function add_success($msg = null, $file = null, $func = null, $line = null) |
|
581 | - { |
|
582 | - self::_add_notice('success', $msg, $file, $func, $line); |
|
583 | - } |
|
584 | - |
|
585 | - |
|
586 | - |
|
587 | - /** |
|
588 | - * add attention message |
|
589 | - * |
|
590 | - * @param string $msg the message to display to users or developers - adding a double pipe || (OR) creates |
|
591 | - * separate messages for user || dev |
|
592 | - * @param string $file the file that the error occurred in - just use __FILE__ |
|
593 | - * @param string $func the function/method that the error occurred in - just use __FUNCTION__ |
|
594 | - * @param string $line the line number where the error occurred - just use __LINE__ |
|
595 | - * @return void |
|
596 | - */ |
|
597 | - public static function add_attention($msg = null, $file = null, $func = null, $line = null) |
|
598 | - { |
|
599 | - self::_add_notice('attention', $msg, $file, $func, $line); |
|
600 | - } |
|
601 | - |
|
602 | - |
|
603 | - |
|
604 | - /** |
|
605 | - * @param string $type whether the message is for a success or error notification |
|
606 | - * @param string $msg the message to display to users or developers |
|
607 | - * - adding a double pipe || (OR) creates separate messages for user || dev |
|
608 | - * @param string $file the file that the error occurred in - just use __FILE__ |
|
609 | - * @param string $func the function/method that the error occurred in - just use __FUNCTION__ |
|
610 | - * @param string $line the line number where the error occurred - just use __LINE__ |
|
611 | - * @return void |
|
612 | - */ |
|
613 | - private static function _add_notice($type = 'success', $msg = '', $file = '', $func = '', $line = '') |
|
614 | - { |
|
615 | - if (empty($msg)) { |
|
616 | - EE_Error::doing_it_wrong( |
|
617 | - 'EE_Error::add_' . $type . '()', |
|
618 | - sprintf( |
|
619 | - __('Notifications are not much use without a message! Please add a message to the EE_Error::add_%s() call made in %s on line %d', |
|
620 | - 'event_espresso'), |
|
621 | - $type, |
|
622 | - $file, |
|
623 | - $line |
|
624 | - ), |
|
625 | - EVENT_ESPRESSO_VERSION |
|
626 | - ); |
|
627 | - } |
|
628 | - if ($type === 'errors' && (empty($file) || empty($func) || empty($line))) { |
|
629 | - EE_Error::doing_it_wrong( |
|
630 | - 'EE_Error::add_error()', |
|
631 | - __('You need to provide the file name, function name, and line number that the error occurred on in order to better assist with debugging.', |
|
632 | - 'event_espresso'), |
|
633 | - EVENT_ESPRESSO_VERSION |
|
634 | - ); |
|
635 | - } |
|
636 | - // get separate user and developer messages if they exist |
|
637 | - $msg = explode('||', $msg); |
|
638 | - $user_msg = $msg[0]; |
|
639 | - $dev_msg = isset($msg[1]) ? $msg[1] : $msg[0]; |
|
640 | - /** |
|
641 | - * Do an action so other code can be triggered when a notice is created |
|
642 | - * |
|
643 | - * @param string $type can be 'errors', 'attention', or 'success' |
|
644 | - * @param string $user_msg message displayed to user when WP_DEBUG is off |
|
645 | - * @param string $user_msg message displayed to user when WP_DEBUG is on |
|
646 | - * @param string $file file where error was generated |
|
647 | - * @param string $func function where error was generated |
|
648 | - * @param string $line line where error was generated |
|
649 | - */ |
|
650 | - do_action('AHEE__EE_Error___add_notice', $type, $user_msg, $dev_msg, $file, $func, $line); |
|
651 | - $msg = WP_DEBUG ? $dev_msg : $user_msg; |
|
652 | - // add notice if message exists |
|
653 | - if (! empty($msg)) { |
|
654 | - // get error code |
|
655 | - $notice_code = EE_Error::generate_error_code($file, $func, $line); |
|
656 | - if (WP_DEBUG && $type === 'errors') { |
|
657 | - $msg .= '<br/><span class="tiny-text">' . $notice_code . '</span>'; |
|
658 | - } |
|
659 | - // add notice. Index by code if it's not blank |
|
660 | - if ($notice_code) { |
|
661 | - self::$_espresso_notices[$type][$notice_code] = $msg; |
|
662 | - } else { |
|
663 | - self::$_espresso_notices[$type][] = $msg; |
|
664 | - } |
|
665 | - add_action('wp_footer', array('EE_Error', 'enqueue_error_scripts'), 1); |
|
666 | - } |
|
667 | - } |
|
668 | - |
|
669 | - |
|
670 | - /** |
|
671 | - * in some case it may be necessary to overwrite the existing success messages |
|
672 | - * |
|
673 | - * @return void |
|
674 | - */ |
|
675 | - public static function overwrite_success() |
|
676 | - { |
|
677 | - self::$_espresso_notices['success'] = false; |
|
678 | - } |
|
679 | - |
|
680 | - |
|
681 | - |
|
682 | - /** |
|
683 | - * in some case it may be necessary to overwrite the existing attention messages |
|
684 | - * |
|
685 | - * @return void |
|
686 | - */ |
|
687 | - public static function overwrite_attention() |
|
688 | - { |
|
689 | - self::$_espresso_notices['attention'] = false; |
|
690 | - } |
|
691 | - |
|
692 | - |
|
693 | - |
|
694 | - /** |
|
695 | - * in some case it may be necessary to overwrite the existing error messages |
|
696 | - * |
|
697 | - * @return void |
|
698 | - */ |
|
699 | - public static function overwrite_errors() |
|
700 | - { |
|
701 | - self::$_espresso_notices['errors'] = false; |
|
702 | - } |
|
703 | - |
|
704 | - |
|
705 | - |
|
706 | - /** |
|
707 | - * @return void |
|
708 | - */ |
|
709 | - public static function reset_notices() |
|
710 | - { |
|
711 | - self::$_espresso_notices['success'] = false; |
|
712 | - self::$_espresso_notices['attention'] = false; |
|
713 | - self::$_espresso_notices['errors'] = false; |
|
714 | - } |
|
715 | - |
|
716 | - |
|
717 | - |
|
718 | - /** |
|
719 | - * @return int |
|
720 | - */ |
|
721 | - public static function has_notices() |
|
722 | - { |
|
723 | - $has_notices = 0; |
|
724 | - // check for success messages |
|
725 | - $has_notices = self::$_espresso_notices['success'] && ! empty(self::$_espresso_notices['success']) |
|
726 | - ? 3 |
|
727 | - : $has_notices; |
|
728 | - // check for attention messages |
|
729 | - $has_notices = self::$_espresso_notices['attention'] && ! empty(self::$_espresso_notices['attention']) |
|
730 | - ? 2 |
|
731 | - : $has_notices; |
|
732 | - // check for error messages |
|
733 | - $has_notices = self::$_espresso_notices['errors'] && ! empty(self::$_espresso_notices['errors']) |
|
734 | - ? 1 |
|
735 | - : $has_notices; |
|
736 | - return $has_notices; |
|
737 | - } |
|
738 | - |
|
739 | - |
|
740 | - /** |
|
741 | - * This simply returns non formatted error notices as they were sent into the EE_Error object. |
|
742 | - * |
|
743 | - * @since 4.9.0 |
|
744 | - * @return array |
|
745 | - */ |
|
746 | - public static function get_vanilla_notices() |
|
747 | - { |
|
748 | - return array( |
|
749 | - 'success' => isset(self::$_espresso_notices['success']) |
|
750 | - ? self::$_espresso_notices['success'] |
|
751 | - : array(), |
|
752 | - 'attention' => isset(self::$_espresso_notices['attention']) |
|
753 | - ? self::$_espresso_notices['attention'] |
|
754 | - : array(), |
|
755 | - 'errors' => isset(self::$_espresso_notices['errors']) |
|
756 | - ? self::$_espresso_notices['errors'] |
|
757 | - : array(), |
|
758 | - ); |
|
759 | - } |
|
760 | - |
|
761 | - |
|
762 | - /** |
|
763 | - * @return array |
|
764 | - * @throws InvalidArgumentException |
|
765 | - * @throws InvalidDataTypeException |
|
766 | - * @throws InvalidInterfaceException |
|
767 | - */ |
|
768 | - public static function getStoredNotices() |
|
769 | - { |
|
770 | - if ($user_id = get_current_user_id()) { |
|
771 | - // get notices for logged in user |
|
772 | - $notices = get_user_option(EE_Error::OPTIONS_KEY_NOTICES, $user_id); |
|
773 | - return is_array($notices) ? $notices : array(); |
|
774 | - } |
|
775 | - if (EE_Session::isLoadedAndActive()) { |
|
776 | - // get notices for user currently engaged in a session |
|
777 | - $session_data = EE_Session::instance()->get_session_data(EE_Error::OPTIONS_KEY_NOTICES); |
|
778 | - return is_array($session_data) ? $session_data : array(); |
|
779 | - } |
|
780 | - // get global notices and hope they apply to the current site visitor |
|
781 | - $notices = get_option(EE_Error::OPTIONS_KEY_NOTICES, array()); |
|
782 | - return is_array($notices) ? $notices : array(); |
|
783 | - } |
|
784 | - |
|
785 | - |
|
786 | - /** |
|
787 | - * @param array $notices |
|
788 | - * @return bool |
|
789 | - * @throws InvalidArgumentException |
|
790 | - * @throws InvalidDataTypeException |
|
791 | - * @throws InvalidInterfaceException |
|
792 | - */ |
|
793 | - public static function storeNotices(array $notices) |
|
794 | - { |
|
795 | - if ($user_id = get_current_user_id()) { |
|
796 | - // store notices for logged in user |
|
797 | - return (bool) update_user_option( |
|
798 | - $user_id, |
|
799 | - EE_Error::OPTIONS_KEY_NOTICES, |
|
800 | - $notices |
|
801 | - ); |
|
802 | - } |
|
803 | - if (EE_Session::isLoadedAndActive()) { |
|
804 | - // store notices for user currently engaged in a session |
|
805 | - return EE_Session::instance()->set_session_data( |
|
806 | - array(EE_Error::OPTIONS_KEY_NOTICES => $notices) |
|
807 | - ); |
|
808 | - } |
|
809 | - // store global notices and hope they apply to the same site visitor on the next request |
|
810 | - return update_option(EE_Error::OPTIONS_KEY_NOTICES, $notices); |
|
811 | - } |
|
812 | - |
|
813 | - |
|
814 | - /** |
|
815 | - * @return bool|TRUE |
|
816 | - * @throws InvalidArgumentException |
|
817 | - * @throws InvalidDataTypeException |
|
818 | - * @throws InvalidInterfaceException |
|
819 | - */ |
|
820 | - public static function clearNotices() |
|
821 | - { |
|
822 | - if ($user_id = get_current_user_id()) { |
|
823 | - // clear notices for logged in user |
|
824 | - return (bool) update_user_option( |
|
825 | - $user_id, |
|
826 | - EE_Error::OPTIONS_KEY_NOTICES, |
|
827 | - array() |
|
828 | - ); |
|
829 | - } |
|
830 | - if (EE_Session::isLoadedAndActive()) { |
|
831 | - // clear notices for user currently engaged in a session |
|
832 | - return EE_Session::instance()->reset_data(EE_Error::OPTIONS_KEY_NOTICES); |
|
833 | - } |
|
834 | - // clear global notices and hope none belonged to some for some other site visitor |
|
835 | - return update_option(EE_Error::OPTIONS_KEY_NOTICES, array()); |
|
836 | - } |
|
837 | - |
|
838 | - |
|
839 | - /** |
|
840 | - * saves notices to the db for retrieval on next request |
|
841 | - * |
|
842 | - * @return void |
|
843 | - * @throws InvalidArgumentException |
|
844 | - * @throws InvalidDataTypeException |
|
845 | - * @throws InvalidInterfaceException |
|
846 | - */ |
|
847 | - public static function stashNoticesBeforeRedirect() |
|
848 | - { |
|
849 | - EE_Error::get_notices(false, true); |
|
850 | - } |
|
851 | - |
|
852 | - |
|
853 | - /** |
|
854 | - * compile all error or success messages into one string |
|
855 | - * |
|
856 | - * @see EE_Error::get_raw_notices if you want the raw notices without any preparations made to them |
|
857 | - * @param boolean $format_output whether or not to format the messages for display in the WP admin |
|
858 | - * @param boolean $save_to_transient whether or not to save notices to the db for retrieval on next request |
|
859 | - * - ONLY do this just before redirecting |
|
860 | - * @param boolean $remove_empty whether or not to unset empty messages |
|
861 | - * @return array |
|
862 | - * @throws InvalidArgumentException |
|
863 | - * @throws InvalidDataTypeException |
|
864 | - * @throws InvalidInterfaceException |
|
865 | - */ |
|
866 | - public static function get_notices($format_output = true, $save_to_transient = false, $remove_empty = true) |
|
867 | - { |
|
868 | - $success_messages = ''; |
|
869 | - $attention_messages = ''; |
|
870 | - $error_messages = ''; |
|
871 | - // either save notices to the db |
|
872 | - if ($save_to_transient || isset($_REQUEST['activate-selected'])) { |
|
873 | - self::$_espresso_notices = array_merge( |
|
874 | - EE_Error::getStoredNotices(), |
|
875 | - self::$_espresso_notices |
|
876 | - ); |
|
877 | - EE_Error::storeNotices(self::$_espresso_notices); |
|
878 | - return array(); |
|
879 | - } |
|
880 | - $print_scripts = EE_Error::combineExistingAndNewNotices(); |
|
881 | - // check for success messages |
|
882 | - if (self::$_espresso_notices['success'] && ! empty(self::$_espresso_notices['success'])) { |
|
883 | - // combine messages |
|
884 | - $success_messages .= implode(self::$_espresso_notices['success'], '<br />'); |
|
885 | - $print_scripts = true; |
|
886 | - } |
|
887 | - // check for attention messages |
|
888 | - if (self::$_espresso_notices['attention'] && ! empty(self::$_espresso_notices['attention'])) { |
|
889 | - // combine messages |
|
890 | - $attention_messages .= implode(self::$_espresso_notices['attention'], '<br />'); |
|
891 | - $print_scripts = true; |
|
892 | - } |
|
893 | - // check for error messages |
|
894 | - if (self::$_espresso_notices['errors'] && ! empty(self::$_espresso_notices['errors'])) { |
|
895 | - $error_messages .= count(self::$_espresso_notices['errors']) > 1 |
|
896 | - ? __('The following errors have occurred:<br />', 'event_espresso') |
|
897 | - : __('An error has occurred:<br />', 'event_espresso'); |
|
898 | - // combine messages |
|
899 | - $error_messages .= implode(self::$_espresso_notices['errors'], '<br />'); |
|
900 | - $print_scripts = true; |
|
901 | - } |
|
902 | - if ($format_output) { |
|
903 | - $notices = EE_Error::formatNoticesOutput( |
|
904 | - $success_messages, |
|
905 | - $attention_messages, |
|
906 | - $error_messages |
|
907 | - ); |
|
908 | - } else { |
|
909 | - $notices = array( |
|
910 | - 'success' => $success_messages, |
|
911 | - 'attention' => $attention_messages, |
|
912 | - 'errors' => $error_messages, |
|
913 | - ); |
|
914 | - if ($remove_empty) { |
|
915 | - // remove empty notices |
|
916 | - foreach ($notices as $type => $notice) { |
|
917 | - if (empty($notice)) { |
|
918 | - unset($notices[$type]); |
|
919 | - } |
|
920 | - } |
|
921 | - } |
|
922 | - } |
|
923 | - if ($print_scripts) { |
|
924 | - self::_print_scripts(); |
|
925 | - } |
|
926 | - return $notices; |
|
927 | - } |
|
928 | - |
|
929 | - |
|
930 | - /** |
|
931 | - * @return bool |
|
932 | - * @throws InvalidArgumentException |
|
933 | - * @throws InvalidDataTypeException |
|
934 | - * @throws InvalidInterfaceException |
|
935 | - */ |
|
936 | - private static function combineExistingAndNewNotices() |
|
937 | - { |
|
938 | - $print_scripts = false; |
|
939 | - // grab any notices that have been previously saved |
|
940 | - $notices = EE_Error::getStoredNotices(); |
|
941 | - if (! empty($notices)) { |
|
942 | - foreach ($notices as $type => $notice) { |
|
943 | - if (is_array($notice) && ! empty($notice)) { |
|
944 | - // make sure that existing notice type is an array |
|
945 | - self::$_espresso_notices[ $type ] = is_array(self::$_espresso_notices[ $type ]) |
|
946 | - && ! empty(self::$_espresso_notices[ $type ]) |
|
947 | - ? self::$_espresso_notices[ $type ] |
|
948 | - : array(); |
|
949 | - // add newly created notices to existing ones |
|
950 | - self::$_espresso_notices[ $type ] += $notice; |
|
951 | - $print_scripts = true; |
|
952 | - } |
|
953 | - } |
|
954 | - // now clear any stored notices |
|
955 | - EE_Error::clearNotices(); |
|
956 | - } |
|
957 | - return $print_scripts; |
|
958 | - } |
|
959 | - |
|
960 | - |
|
961 | - /** |
|
962 | - * @param string $success_messages |
|
963 | - * @param string $attention_messages |
|
964 | - * @param string $error_messages |
|
965 | - * @return string |
|
966 | - */ |
|
967 | - private static function formatNoticesOutput($success_messages, $attention_messages, $error_messages) |
|
968 | - { |
|
969 | - $notices = '<div id="espresso-notices">'; |
|
970 | - $close = is_admin() |
|
971 | - ? '' |
|
972 | - : '<a class="close-espresso-notice hide-if-no-js"><span class="dashicons dashicons-no"/></a>'; |
|
973 | - if ($success_messages !== '') { |
|
974 | - $css_id = is_admin() ? 'ee-success-message' : 'espresso-notices-success'; |
|
975 | - $css_class = is_admin() ? 'updated fade' : 'success fade-away'; |
|
976 | - //showMessage( $success_messages ); |
|
977 | - $notices .= '<div id="' . $css_id . '" ' |
|
978 | - . 'class="espresso-notices ' . $css_class . '" ' |
|
979 | - . 'style="display:none;">' |
|
980 | - . '<p>' . $success_messages . '</p>' |
|
981 | - . $close |
|
982 | - . '</div>'; |
|
983 | - } |
|
984 | - if ($attention_messages !== '') { |
|
985 | - $css_id = is_admin() ? 'ee-attention-message' : 'espresso-notices-attention'; |
|
986 | - $css_class = is_admin() ? 'updated ee-notices-attention' : 'attention fade-away'; |
|
987 | - //showMessage( $error_messages, TRUE ); |
|
988 | - $notices .= '<div id="' . $css_id . '" ' |
|
989 | - . 'class="espresso-notices ' . $css_class . '" ' |
|
990 | - . 'style="display:none;">' |
|
991 | - . '<p>' . $attention_messages . '</p>' |
|
992 | - . $close |
|
993 | - . '</div>'; |
|
994 | - } |
|
995 | - if ($error_messages !== '') { |
|
996 | - $css_id = is_admin() ? 'ee-error-message' : 'espresso-notices-error'; |
|
997 | - $css_class = is_admin() ? 'error' : 'error fade-away'; |
|
998 | - //showMessage( $error_messages, TRUE ); |
|
999 | - $notices .= '<div id="' . $css_id . '" ' |
|
1000 | - . 'class="espresso-notices ' . $css_class . '" ' |
|
1001 | - . 'style="display:none;">' |
|
1002 | - . '<p>' . $error_messages . '</p>' |
|
1003 | - . $close |
|
1004 | - . '</div>'; |
|
1005 | - } |
|
1006 | - $notices .= '</div>'; |
|
1007 | - return $notices; |
|
1008 | - } |
|
1009 | - |
|
1010 | - |
|
1011 | - |
|
1012 | - /** |
|
1013 | - * _print_scripts |
|
1014 | - * |
|
1015 | - * @param bool $force_print |
|
1016 | - * @return string |
|
1017 | - */ |
|
1018 | - private static function _print_scripts($force_print = false) |
|
1019 | - { |
|
1020 | - if (! $force_print && (did_action('admin_enqueue_scripts') || did_action('wp_enqueue_scripts'))) { |
|
1021 | - if (wp_script_is('ee_error_js', 'enqueued')) { |
|
1022 | - return ''; |
|
1023 | - } |
|
1024 | - if (wp_script_is('ee_error_js', 'registered')) { |
|
1025 | - wp_enqueue_style('espresso_default'); |
|
1026 | - wp_enqueue_style('espresso_custom_css'); |
|
1027 | - wp_enqueue_script('ee_error_js'); |
|
1028 | - wp_localize_script('ee_error_js', 'ee_settings', array('wp_debug' => WP_DEBUG)); |
|
1029 | - } |
|
1030 | - } else { |
|
1031 | - return ' |
|
480 | + $output .= self::_print_scripts(true); |
|
481 | + if (defined('DOING_AJAX')) { |
|
482 | + echo wp_json_encode(array('error' => $output)); |
|
483 | + exit(); |
|
484 | + } |
|
485 | + echo $output; |
|
486 | + die(); |
|
487 | + } |
|
488 | + |
|
489 | + |
|
490 | + |
|
491 | + /** |
|
492 | + * generate string from exception trace args |
|
493 | + * |
|
494 | + * @param array $arguments |
|
495 | + * @param bool $array |
|
496 | + * @return string |
|
497 | + */ |
|
498 | + private function _convert_args_to_string($arguments = array(), $array = false) |
|
499 | + { |
|
500 | + $arg_string = ''; |
|
501 | + if (! empty($arguments)) { |
|
502 | + $args = array(); |
|
503 | + foreach ($arguments as $arg) { |
|
504 | + if (! empty($arg)) { |
|
505 | + if (is_string($arg)) { |
|
506 | + $args[] = " '" . $arg . "'"; |
|
507 | + } elseif (is_array($arg)) { |
|
508 | + $args[] = 'ARRAY(' . $this->_convert_args_to_string($arg, true); |
|
509 | + } elseif ($arg === null) { |
|
510 | + $args[] = ' NULL'; |
|
511 | + } elseif (is_bool($arg)) { |
|
512 | + $args[] = ($arg) ? ' TRUE' : ' FALSE'; |
|
513 | + } elseif (is_object($arg)) { |
|
514 | + $args[] = ' OBJECT ' . get_class($arg); |
|
515 | + } elseif (is_resource($arg)) { |
|
516 | + $args[] = get_resource_type($arg); |
|
517 | + } else { |
|
518 | + $args[] = $arg; |
|
519 | + } |
|
520 | + } |
|
521 | + } |
|
522 | + $arg_string = implode(', ', $args); |
|
523 | + } |
|
524 | + if ($array) { |
|
525 | + $arg_string .= ' )'; |
|
526 | + } |
|
527 | + return $arg_string; |
|
528 | + } |
|
529 | + |
|
530 | + |
|
531 | + |
|
532 | + /** |
|
533 | + * add error message |
|
534 | + * |
|
535 | + * @param string $msg the message to display to users or developers - adding a double pipe || (OR) creates |
|
536 | + * separate messages for user || dev |
|
537 | + * @param string $file the file that the error occurred in - just use __FILE__ |
|
538 | + * @param string $func the function/method that the error occurred in - just use __FUNCTION__ |
|
539 | + * @param string $line the line number where the error occurred - just use __LINE__ |
|
540 | + * @return void |
|
541 | + */ |
|
542 | + public static function add_error($msg = null, $file = null, $func = null, $line = null) |
|
543 | + { |
|
544 | + self::_add_notice('errors', $msg, $file, $func, $line); |
|
545 | + self::$_error_count++; |
|
546 | + } |
|
547 | + |
|
548 | + |
|
549 | + |
|
550 | + /** |
|
551 | + * If WP_DEBUG is active, throws an exception. If WP_DEBUG is off, just |
|
552 | + * adds an error |
|
553 | + * |
|
554 | + * @param string $msg |
|
555 | + * @param string $file |
|
556 | + * @param string $func |
|
557 | + * @param string $line |
|
558 | + * @throws EE_Error |
|
559 | + */ |
|
560 | + public static function throw_exception_if_debugging($msg = null, $file = null, $func = null, $line = null) |
|
561 | + { |
|
562 | + if (WP_DEBUG) { |
|
563 | + throw new EE_Error($msg); |
|
564 | + } |
|
565 | + EE_Error::add_error($msg, $file, $func, $line); |
|
566 | + } |
|
567 | + |
|
568 | + |
|
569 | + |
|
570 | + /** |
|
571 | + * add success message |
|
572 | + * |
|
573 | + * @param string $msg the message to display to users or developers - adding a double pipe || (OR) creates |
|
574 | + * separate messages for user || dev |
|
575 | + * @param string $file the file that the error occurred in - just use __FILE__ |
|
576 | + * @param string $func the function/method that the error occurred in - just use __FUNCTION__ |
|
577 | + * @param string $line the line number where the error occurred - just use __LINE__ |
|
578 | + * @return void |
|
579 | + */ |
|
580 | + public static function add_success($msg = null, $file = null, $func = null, $line = null) |
|
581 | + { |
|
582 | + self::_add_notice('success', $msg, $file, $func, $line); |
|
583 | + } |
|
584 | + |
|
585 | + |
|
586 | + |
|
587 | + /** |
|
588 | + * add attention message |
|
589 | + * |
|
590 | + * @param string $msg the message to display to users or developers - adding a double pipe || (OR) creates |
|
591 | + * separate messages for user || dev |
|
592 | + * @param string $file the file that the error occurred in - just use __FILE__ |
|
593 | + * @param string $func the function/method that the error occurred in - just use __FUNCTION__ |
|
594 | + * @param string $line the line number where the error occurred - just use __LINE__ |
|
595 | + * @return void |
|
596 | + */ |
|
597 | + public static function add_attention($msg = null, $file = null, $func = null, $line = null) |
|
598 | + { |
|
599 | + self::_add_notice('attention', $msg, $file, $func, $line); |
|
600 | + } |
|
601 | + |
|
602 | + |
|
603 | + |
|
604 | + /** |
|
605 | + * @param string $type whether the message is for a success or error notification |
|
606 | + * @param string $msg the message to display to users or developers |
|
607 | + * - adding a double pipe || (OR) creates separate messages for user || dev |
|
608 | + * @param string $file the file that the error occurred in - just use __FILE__ |
|
609 | + * @param string $func the function/method that the error occurred in - just use __FUNCTION__ |
|
610 | + * @param string $line the line number where the error occurred - just use __LINE__ |
|
611 | + * @return void |
|
612 | + */ |
|
613 | + private static function _add_notice($type = 'success', $msg = '', $file = '', $func = '', $line = '') |
|
614 | + { |
|
615 | + if (empty($msg)) { |
|
616 | + EE_Error::doing_it_wrong( |
|
617 | + 'EE_Error::add_' . $type . '()', |
|
618 | + sprintf( |
|
619 | + __('Notifications are not much use without a message! Please add a message to the EE_Error::add_%s() call made in %s on line %d', |
|
620 | + 'event_espresso'), |
|
621 | + $type, |
|
622 | + $file, |
|
623 | + $line |
|
624 | + ), |
|
625 | + EVENT_ESPRESSO_VERSION |
|
626 | + ); |
|
627 | + } |
|
628 | + if ($type === 'errors' && (empty($file) || empty($func) || empty($line))) { |
|
629 | + EE_Error::doing_it_wrong( |
|
630 | + 'EE_Error::add_error()', |
|
631 | + __('You need to provide the file name, function name, and line number that the error occurred on in order to better assist with debugging.', |
|
632 | + 'event_espresso'), |
|
633 | + EVENT_ESPRESSO_VERSION |
|
634 | + ); |
|
635 | + } |
|
636 | + // get separate user and developer messages if they exist |
|
637 | + $msg = explode('||', $msg); |
|
638 | + $user_msg = $msg[0]; |
|
639 | + $dev_msg = isset($msg[1]) ? $msg[1] : $msg[0]; |
|
640 | + /** |
|
641 | + * Do an action so other code can be triggered when a notice is created |
|
642 | + * |
|
643 | + * @param string $type can be 'errors', 'attention', or 'success' |
|
644 | + * @param string $user_msg message displayed to user when WP_DEBUG is off |
|
645 | + * @param string $user_msg message displayed to user when WP_DEBUG is on |
|
646 | + * @param string $file file where error was generated |
|
647 | + * @param string $func function where error was generated |
|
648 | + * @param string $line line where error was generated |
|
649 | + */ |
|
650 | + do_action('AHEE__EE_Error___add_notice', $type, $user_msg, $dev_msg, $file, $func, $line); |
|
651 | + $msg = WP_DEBUG ? $dev_msg : $user_msg; |
|
652 | + // add notice if message exists |
|
653 | + if (! empty($msg)) { |
|
654 | + // get error code |
|
655 | + $notice_code = EE_Error::generate_error_code($file, $func, $line); |
|
656 | + if (WP_DEBUG && $type === 'errors') { |
|
657 | + $msg .= '<br/><span class="tiny-text">' . $notice_code . '</span>'; |
|
658 | + } |
|
659 | + // add notice. Index by code if it's not blank |
|
660 | + if ($notice_code) { |
|
661 | + self::$_espresso_notices[$type][$notice_code] = $msg; |
|
662 | + } else { |
|
663 | + self::$_espresso_notices[$type][] = $msg; |
|
664 | + } |
|
665 | + add_action('wp_footer', array('EE_Error', 'enqueue_error_scripts'), 1); |
|
666 | + } |
|
667 | + } |
|
668 | + |
|
669 | + |
|
670 | + /** |
|
671 | + * in some case it may be necessary to overwrite the existing success messages |
|
672 | + * |
|
673 | + * @return void |
|
674 | + */ |
|
675 | + public static function overwrite_success() |
|
676 | + { |
|
677 | + self::$_espresso_notices['success'] = false; |
|
678 | + } |
|
679 | + |
|
680 | + |
|
681 | + |
|
682 | + /** |
|
683 | + * in some case it may be necessary to overwrite the existing attention messages |
|
684 | + * |
|
685 | + * @return void |
|
686 | + */ |
|
687 | + public static function overwrite_attention() |
|
688 | + { |
|
689 | + self::$_espresso_notices['attention'] = false; |
|
690 | + } |
|
691 | + |
|
692 | + |
|
693 | + |
|
694 | + /** |
|
695 | + * in some case it may be necessary to overwrite the existing error messages |
|
696 | + * |
|
697 | + * @return void |
|
698 | + */ |
|
699 | + public static function overwrite_errors() |
|
700 | + { |
|
701 | + self::$_espresso_notices['errors'] = false; |
|
702 | + } |
|
703 | + |
|
704 | + |
|
705 | + |
|
706 | + /** |
|
707 | + * @return void |
|
708 | + */ |
|
709 | + public static function reset_notices() |
|
710 | + { |
|
711 | + self::$_espresso_notices['success'] = false; |
|
712 | + self::$_espresso_notices['attention'] = false; |
|
713 | + self::$_espresso_notices['errors'] = false; |
|
714 | + } |
|
715 | + |
|
716 | + |
|
717 | + |
|
718 | + /** |
|
719 | + * @return int |
|
720 | + */ |
|
721 | + public static function has_notices() |
|
722 | + { |
|
723 | + $has_notices = 0; |
|
724 | + // check for success messages |
|
725 | + $has_notices = self::$_espresso_notices['success'] && ! empty(self::$_espresso_notices['success']) |
|
726 | + ? 3 |
|
727 | + : $has_notices; |
|
728 | + // check for attention messages |
|
729 | + $has_notices = self::$_espresso_notices['attention'] && ! empty(self::$_espresso_notices['attention']) |
|
730 | + ? 2 |
|
731 | + : $has_notices; |
|
732 | + // check for error messages |
|
733 | + $has_notices = self::$_espresso_notices['errors'] && ! empty(self::$_espresso_notices['errors']) |
|
734 | + ? 1 |
|
735 | + : $has_notices; |
|
736 | + return $has_notices; |
|
737 | + } |
|
738 | + |
|
739 | + |
|
740 | + /** |
|
741 | + * This simply returns non formatted error notices as they were sent into the EE_Error object. |
|
742 | + * |
|
743 | + * @since 4.9.0 |
|
744 | + * @return array |
|
745 | + */ |
|
746 | + public static function get_vanilla_notices() |
|
747 | + { |
|
748 | + return array( |
|
749 | + 'success' => isset(self::$_espresso_notices['success']) |
|
750 | + ? self::$_espresso_notices['success'] |
|
751 | + : array(), |
|
752 | + 'attention' => isset(self::$_espresso_notices['attention']) |
|
753 | + ? self::$_espresso_notices['attention'] |
|
754 | + : array(), |
|
755 | + 'errors' => isset(self::$_espresso_notices['errors']) |
|
756 | + ? self::$_espresso_notices['errors'] |
|
757 | + : array(), |
|
758 | + ); |
|
759 | + } |
|
760 | + |
|
761 | + |
|
762 | + /** |
|
763 | + * @return array |
|
764 | + * @throws InvalidArgumentException |
|
765 | + * @throws InvalidDataTypeException |
|
766 | + * @throws InvalidInterfaceException |
|
767 | + */ |
|
768 | + public static function getStoredNotices() |
|
769 | + { |
|
770 | + if ($user_id = get_current_user_id()) { |
|
771 | + // get notices for logged in user |
|
772 | + $notices = get_user_option(EE_Error::OPTIONS_KEY_NOTICES, $user_id); |
|
773 | + return is_array($notices) ? $notices : array(); |
|
774 | + } |
|
775 | + if (EE_Session::isLoadedAndActive()) { |
|
776 | + // get notices for user currently engaged in a session |
|
777 | + $session_data = EE_Session::instance()->get_session_data(EE_Error::OPTIONS_KEY_NOTICES); |
|
778 | + return is_array($session_data) ? $session_data : array(); |
|
779 | + } |
|
780 | + // get global notices and hope they apply to the current site visitor |
|
781 | + $notices = get_option(EE_Error::OPTIONS_KEY_NOTICES, array()); |
|
782 | + return is_array($notices) ? $notices : array(); |
|
783 | + } |
|
784 | + |
|
785 | + |
|
786 | + /** |
|
787 | + * @param array $notices |
|
788 | + * @return bool |
|
789 | + * @throws InvalidArgumentException |
|
790 | + * @throws InvalidDataTypeException |
|
791 | + * @throws InvalidInterfaceException |
|
792 | + */ |
|
793 | + public static function storeNotices(array $notices) |
|
794 | + { |
|
795 | + if ($user_id = get_current_user_id()) { |
|
796 | + // store notices for logged in user |
|
797 | + return (bool) update_user_option( |
|
798 | + $user_id, |
|
799 | + EE_Error::OPTIONS_KEY_NOTICES, |
|
800 | + $notices |
|
801 | + ); |
|
802 | + } |
|
803 | + if (EE_Session::isLoadedAndActive()) { |
|
804 | + // store notices for user currently engaged in a session |
|
805 | + return EE_Session::instance()->set_session_data( |
|
806 | + array(EE_Error::OPTIONS_KEY_NOTICES => $notices) |
|
807 | + ); |
|
808 | + } |
|
809 | + // store global notices and hope they apply to the same site visitor on the next request |
|
810 | + return update_option(EE_Error::OPTIONS_KEY_NOTICES, $notices); |
|
811 | + } |
|
812 | + |
|
813 | + |
|
814 | + /** |
|
815 | + * @return bool|TRUE |
|
816 | + * @throws InvalidArgumentException |
|
817 | + * @throws InvalidDataTypeException |
|
818 | + * @throws InvalidInterfaceException |
|
819 | + */ |
|
820 | + public static function clearNotices() |
|
821 | + { |
|
822 | + if ($user_id = get_current_user_id()) { |
|
823 | + // clear notices for logged in user |
|
824 | + return (bool) update_user_option( |
|
825 | + $user_id, |
|
826 | + EE_Error::OPTIONS_KEY_NOTICES, |
|
827 | + array() |
|
828 | + ); |
|
829 | + } |
|
830 | + if (EE_Session::isLoadedAndActive()) { |
|
831 | + // clear notices for user currently engaged in a session |
|
832 | + return EE_Session::instance()->reset_data(EE_Error::OPTIONS_KEY_NOTICES); |
|
833 | + } |
|
834 | + // clear global notices and hope none belonged to some for some other site visitor |
|
835 | + return update_option(EE_Error::OPTIONS_KEY_NOTICES, array()); |
|
836 | + } |
|
837 | + |
|
838 | + |
|
839 | + /** |
|
840 | + * saves notices to the db for retrieval on next request |
|
841 | + * |
|
842 | + * @return void |
|
843 | + * @throws InvalidArgumentException |
|
844 | + * @throws InvalidDataTypeException |
|
845 | + * @throws InvalidInterfaceException |
|
846 | + */ |
|
847 | + public static function stashNoticesBeforeRedirect() |
|
848 | + { |
|
849 | + EE_Error::get_notices(false, true); |
|
850 | + } |
|
851 | + |
|
852 | + |
|
853 | + /** |
|
854 | + * compile all error or success messages into one string |
|
855 | + * |
|
856 | + * @see EE_Error::get_raw_notices if you want the raw notices without any preparations made to them |
|
857 | + * @param boolean $format_output whether or not to format the messages for display in the WP admin |
|
858 | + * @param boolean $save_to_transient whether or not to save notices to the db for retrieval on next request |
|
859 | + * - ONLY do this just before redirecting |
|
860 | + * @param boolean $remove_empty whether or not to unset empty messages |
|
861 | + * @return array |
|
862 | + * @throws InvalidArgumentException |
|
863 | + * @throws InvalidDataTypeException |
|
864 | + * @throws InvalidInterfaceException |
|
865 | + */ |
|
866 | + public static function get_notices($format_output = true, $save_to_transient = false, $remove_empty = true) |
|
867 | + { |
|
868 | + $success_messages = ''; |
|
869 | + $attention_messages = ''; |
|
870 | + $error_messages = ''; |
|
871 | + // either save notices to the db |
|
872 | + if ($save_to_transient || isset($_REQUEST['activate-selected'])) { |
|
873 | + self::$_espresso_notices = array_merge( |
|
874 | + EE_Error::getStoredNotices(), |
|
875 | + self::$_espresso_notices |
|
876 | + ); |
|
877 | + EE_Error::storeNotices(self::$_espresso_notices); |
|
878 | + return array(); |
|
879 | + } |
|
880 | + $print_scripts = EE_Error::combineExistingAndNewNotices(); |
|
881 | + // check for success messages |
|
882 | + if (self::$_espresso_notices['success'] && ! empty(self::$_espresso_notices['success'])) { |
|
883 | + // combine messages |
|
884 | + $success_messages .= implode(self::$_espresso_notices['success'], '<br />'); |
|
885 | + $print_scripts = true; |
|
886 | + } |
|
887 | + // check for attention messages |
|
888 | + if (self::$_espresso_notices['attention'] && ! empty(self::$_espresso_notices['attention'])) { |
|
889 | + // combine messages |
|
890 | + $attention_messages .= implode(self::$_espresso_notices['attention'], '<br />'); |
|
891 | + $print_scripts = true; |
|
892 | + } |
|
893 | + // check for error messages |
|
894 | + if (self::$_espresso_notices['errors'] && ! empty(self::$_espresso_notices['errors'])) { |
|
895 | + $error_messages .= count(self::$_espresso_notices['errors']) > 1 |
|
896 | + ? __('The following errors have occurred:<br />', 'event_espresso') |
|
897 | + : __('An error has occurred:<br />', 'event_espresso'); |
|
898 | + // combine messages |
|
899 | + $error_messages .= implode(self::$_espresso_notices['errors'], '<br />'); |
|
900 | + $print_scripts = true; |
|
901 | + } |
|
902 | + if ($format_output) { |
|
903 | + $notices = EE_Error::formatNoticesOutput( |
|
904 | + $success_messages, |
|
905 | + $attention_messages, |
|
906 | + $error_messages |
|
907 | + ); |
|
908 | + } else { |
|
909 | + $notices = array( |
|
910 | + 'success' => $success_messages, |
|
911 | + 'attention' => $attention_messages, |
|
912 | + 'errors' => $error_messages, |
|
913 | + ); |
|
914 | + if ($remove_empty) { |
|
915 | + // remove empty notices |
|
916 | + foreach ($notices as $type => $notice) { |
|
917 | + if (empty($notice)) { |
|
918 | + unset($notices[$type]); |
|
919 | + } |
|
920 | + } |
|
921 | + } |
|
922 | + } |
|
923 | + if ($print_scripts) { |
|
924 | + self::_print_scripts(); |
|
925 | + } |
|
926 | + return $notices; |
|
927 | + } |
|
928 | + |
|
929 | + |
|
930 | + /** |
|
931 | + * @return bool |
|
932 | + * @throws InvalidArgumentException |
|
933 | + * @throws InvalidDataTypeException |
|
934 | + * @throws InvalidInterfaceException |
|
935 | + */ |
|
936 | + private static function combineExistingAndNewNotices() |
|
937 | + { |
|
938 | + $print_scripts = false; |
|
939 | + // grab any notices that have been previously saved |
|
940 | + $notices = EE_Error::getStoredNotices(); |
|
941 | + if (! empty($notices)) { |
|
942 | + foreach ($notices as $type => $notice) { |
|
943 | + if (is_array($notice) && ! empty($notice)) { |
|
944 | + // make sure that existing notice type is an array |
|
945 | + self::$_espresso_notices[ $type ] = is_array(self::$_espresso_notices[ $type ]) |
|
946 | + && ! empty(self::$_espresso_notices[ $type ]) |
|
947 | + ? self::$_espresso_notices[ $type ] |
|
948 | + : array(); |
|
949 | + // add newly created notices to existing ones |
|
950 | + self::$_espresso_notices[ $type ] += $notice; |
|
951 | + $print_scripts = true; |
|
952 | + } |
|
953 | + } |
|
954 | + // now clear any stored notices |
|
955 | + EE_Error::clearNotices(); |
|
956 | + } |
|
957 | + return $print_scripts; |
|
958 | + } |
|
959 | + |
|
960 | + |
|
961 | + /** |
|
962 | + * @param string $success_messages |
|
963 | + * @param string $attention_messages |
|
964 | + * @param string $error_messages |
|
965 | + * @return string |
|
966 | + */ |
|
967 | + private static function formatNoticesOutput($success_messages, $attention_messages, $error_messages) |
|
968 | + { |
|
969 | + $notices = '<div id="espresso-notices">'; |
|
970 | + $close = is_admin() |
|
971 | + ? '' |
|
972 | + : '<a class="close-espresso-notice hide-if-no-js"><span class="dashicons dashicons-no"/></a>'; |
|
973 | + if ($success_messages !== '') { |
|
974 | + $css_id = is_admin() ? 'ee-success-message' : 'espresso-notices-success'; |
|
975 | + $css_class = is_admin() ? 'updated fade' : 'success fade-away'; |
|
976 | + //showMessage( $success_messages ); |
|
977 | + $notices .= '<div id="' . $css_id . '" ' |
|
978 | + . 'class="espresso-notices ' . $css_class . '" ' |
|
979 | + . 'style="display:none;">' |
|
980 | + . '<p>' . $success_messages . '</p>' |
|
981 | + . $close |
|
982 | + . '</div>'; |
|
983 | + } |
|
984 | + if ($attention_messages !== '') { |
|
985 | + $css_id = is_admin() ? 'ee-attention-message' : 'espresso-notices-attention'; |
|
986 | + $css_class = is_admin() ? 'updated ee-notices-attention' : 'attention fade-away'; |
|
987 | + //showMessage( $error_messages, TRUE ); |
|
988 | + $notices .= '<div id="' . $css_id . '" ' |
|
989 | + . 'class="espresso-notices ' . $css_class . '" ' |
|
990 | + . 'style="display:none;">' |
|
991 | + . '<p>' . $attention_messages . '</p>' |
|
992 | + . $close |
|
993 | + . '</div>'; |
|
994 | + } |
|
995 | + if ($error_messages !== '') { |
|
996 | + $css_id = is_admin() ? 'ee-error-message' : 'espresso-notices-error'; |
|
997 | + $css_class = is_admin() ? 'error' : 'error fade-away'; |
|
998 | + //showMessage( $error_messages, TRUE ); |
|
999 | + $notices .= '<div id="' . $css_id . '" ' |
|
1000 | + . 'class="espresso-notices ' . $css_class . '" ' |
|
1001 | + . 'style="display:none;">' |
|
1002 | + . '<p>' . $error_messages . '</p>' |
|
1003 | + . $close |
|
1004 | + . '</div>'; |
|
1005 | + } |
|
1006 | + $notices .= '</div>'; |
|
1007 | + return $notices; |
|
1008 | + } |
|
1009 | + |
|
1010 | + |
|
1011 | + |
|
1012 | + /** |
|
1013 | + * _print_scripts |
|
1014 | + * |
|
1015 | + * @param bool $force_print |
|
1016 | + * @return string |
|
1017 | + */ |
|
1018 | + private static function _print_scripts($force_print = false) |
|
1019 | + { |
|
1020 | + if (! $force_print && (did_action('admin_enqueue_scripts') || did_action('wp_enqueue_scripts'))) { |
|
1021 | + if (wp_script_is('ee_error_js', 'enqueued')) { |
|
1022 | + return ''; |
|
1023 | + } |
|
1024 | + if (wp_script_is('ee_error_js', 'registered')) { |
|
1025 | + wp_enqueue_style('espresso_default'); |
|
1026 | + wp_enqueue_style('espresso_custom_css'); |
|
1027 | + wp_enqueue_script('ee_error_js'); |
|
1028 | + wp_localize_script('ee_error_js', 'ee_settings', array('wp_debug' => WP_DEBUG)); |
|
1029 | + } |
|
1030 | + } else { |
|
1031 | + return ' |
|
1032 | 1032 | <script> |
1033 | 1033 | /* <![CDATA[ */ |
1034 | 1034 | var ee_settings = {"wp_debug":"' . WP_DEBUG . '"}; |
@@ -1038,223 +1038,223 @@ discard block |
||
1038 | 1038 | <script src="' . EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js' . '?ver=' . espresso_version() . '" type="text/javascript"></script> |
1039 | 1039 | <script src="' . EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js' . '?ver=' . espresso_version() . '" type="text/javascript"></script> |
1040 | 1040 | '; |
1041 | - } |
|
1042 | - return ''; |
|
1043 | - } |
|
1044 | - |
|
1045 | - |
|
1046 | - |
|
1047 | - /** |
|
1048 | - * @return void |
|
1049 | - */ |
|
1050 | - public static function enqueue_error_scripts() |
|
1051 | - { |
|
1052 | - self::_print_scripts(); |
|
1053 | - } |
|
1054 | - |
|
1055 | - |
|
1056 | - |
|
1057 | - /** |
|
1058 | - * create error code from filepath, function name, |
|
1059 | - * and line number where exception or error was thrown |
|
1060 | - * |
|
1061 | - * @param string $file |
|
1062 | - * @param string $func |
|
1063 | - * @param string $line |
|
1064 | - * @return string |
|
1065 | - */ |
|
1066 | - public static function generate_error_code($file = '', $func = '', $line = '') |
|
1067 | - { |
|
1068 | - $file = explode('.', basename($file)); |
|
1069 | - $error_code = ! empty($file[0]) ? $file[0] : ''; |
|
1070 | - $error_code .= ! empty($func) ? ' - ' . $func : ''; |
|
1071 | - $error_code .= ! empty($line) ? ' - ' . $line : ''; |
|
1072 | - return $error_code; |
|
1073 | - } |
|
1074 | - |
|
1075 | - |
|
1076 | - |
|
1077 | - /** |
|
1078 | - * write exception details to log file |
|
1079 | - * Since 4.9.53.rc.006 this writes to the standard PHP log file, not EE's custom log file |
|
1080 | - * |
|
1081 | - * @param int $time |
|
1082 | - * @param array $ex |
|
1083 | - * @param bool $clear |
|
1084 | - * @return void |
|
1085 | - */ |
|
1086 | - public function write_to_error_log($time = 0, $ex = array(), $clear = false) |
|
1087 | - { |
|
1088 | - if (empty($ex)) { |
|
1089 | - return; |
|
1090 | - } |
|
1091 | - if (! $time) { |
|
1092 | - $time = time(); |
|
1093 | - } |
|
1094 | - $exception_log = '----------------------------------------------------------------------------------------' |
|
1095 | - . PHP_EOL; |
|
1096 | - $exception_log .= '[' . date('Y-m-d H:i:s', $time) . '] Exception Details' . PHP_EOL; |
|
1097 | - $exception_log .= 'Message: ' . $ex['msg'] . PHP_EOL; |
|
1098 | - $exception_log .= 'Code: ' . $ex['code'] . PHP_EOL; |
|
1099 | - $exception_log .= 'File: ' . $ex['file'] . PHP_EOL; |
|
1100 | - $exception_log .= 'Line No: ' . $ex['line'] . PHP_EOL; |
|
1101 | - $exception_log .= 'Stack trace: ' . PHP_EOL; |
|
1102 | - $exception_log .= $ex['string'] . PHP_EOL; |
|
1103 | - $exception_log .= '----------------------------------------------------------------------------------------' |
|
1104 | - . PHP_EOL; |
|
1105 | - try { |
|
1106 | - error_log($exception_log); |
|
1107 | - } catch (EE_Error $e) { |
|
1108 | - EE_Error::add_error(sprintf(__('Event Espresso error logging could not be setup because: %s', |
|
1109 | - 'event_espresso'), $e->getMessage())); |
|
1110 | - } |
|
1111 | - } |
|
1112 | - |
|
1113 | - |
|
1114 | - |
|
1115 | - /** |
|
1116 | - * This is just a wrapper for the EEH_Debug_Tools::instance()->doing_it_wrong() method. |
|
1117 | - * doing_it_wrong() is used in those cases where a normal PHP error won't get thrown, |
|
1118 | - * but the code execution is done in a manner that could lead to unexpected results |
|
1119 | - * (i.e. running to early, or too late in WP or EE loading process). |
|
1120 | - * A good test for knowing whether to use this method is: |
|
1121 | - * 1. Is there going to be a PHP error if something isn't setup/used correctly? |
|
1122 | - * Yes -> use EE_Error::add_error() or throw new EE_Error() |
|
1123 | - * 2. If this is loaded before something else, it won't break anything, |
|
1124 | - * but just wont' do what its supposed to do? Yes -> use EE_Error::doing_it_wrong() |
|
1125 | - * |
|
1126 | - * @uses constant WP_DEBUG test if wp_debug is on or not |
|
1127 | - * @param string $function The function that was called |
|
1128 | - * @param string $message A message explaining what has been done incorrectly |
|
1129 | - * @param string $version The version of Event Espresso where the error was added |
|
1130 | - * @param string $applies_when a version string for when you want the doing_it_wrong notice to begin appearing |
|
1131 | - * for a deprecated function. This allows deprecation to occur during one version, |
|
1132 | - * but not have any notices appear until a later version. This allows developers |
|
1133 | - * extra time to update their code before notices appear. |
|
1134 | - * @param int $error_type |
|
1135 | - */ |
|
1136 | - public static function doing_it_wrong( |
|
1137 | - $function, |
|
1138 | - $message, |
|
1139 | - $version, |
|
1140 | - $applies_when = '', |
|
1141 | - $error_type = null |
|
1142 | - ) { |
|
1143 | - if (defined('WP_DEBUG') && WP_DEBUG) { |
|
1144 | - EEH_Debug_Tools::instance()->doing_it_wrong($function, $message, $version, $applies_when, $error_type); |
|
1145 | - } |
|
1146 | - } |
|
1147 | - |
|
1148 | - |
|
1149 | - |
|
1150 | - /** |
|
1151 | - * Like get_notices, but returns an array of all the notices of the given type. |
|
1152 | - * |
|
1153 | - * @return array { |
|
1154 | - * @type array $success all the success messages |
|
1155 | - * @type array $errors all the error messages |
|
1156 | - * @type array $attention all the attention messages |
|
1157 | - * } |
|
1158 | - */ |
|
1159 | - public static function get_raw_notices() |
|
1160 | - { |
|
1161 | - return self::$_espresso_notices; |
|
1162 | - } |
|
1163 | - |
|
1164 | - |
|
1165 | - |
|
1166 | - /** |
|
1167 | - * @deprecated 4.9.27 |
|
1168 | - * @param string $pan_name the name, or key of the Persistent Admin Notice to be stored |
|
1169 | - * @param string $pan_message the message to be stored persistently until dismissed |
|
1170 | - * @param bool $force_update allows one to enforce the reappearance of a persistent message. |
|
1171 | - * @return void |
|
1172 | - * @throws InvalidDataTypeException |
|
1173 | - */ |
|
1174 | - public static function add_persistent_admin_notice($pan_name = '', $pan_message, $force_update = false) |
|
1175 | - { |
|
1176 | - new PersistentAdminNotice( |
|
1177 | - $pan_name, |
|
1178 | - $pan_message, |
|
1179 | - $force_update |
|
1180 | - ); |
|
1181 | - EE_Error::doing_it_wrong( |
|
1182 | - __METHOD__, |
|
1183 | - sprintf( |
|
1184 | - __('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'), |
|
1185 | - '\EventEspresso\core\domain\entities\notifications\PersistentAdminNotice' |
|
1186 | - ), |
|
1187 | - '4.9.27' |
|
1188 | - ); |
|
1189 | - } |
|
1190 | - |
|
1191 | - |
|
1192 | - |
|
1193 | - /** |
|
1194 | - * @deprecated 4.9.27 |
|
1195 | - * @param string $pan_name the name, or key of the Persistent Admin Notice to be dismissed |
|
1196 | - * @param bool $purge |
|
1197 | - * @param bool $return |
|
1198 | - * @throws DomainException |
|
1199 | - * @throws InvalidInterfaceException |
|
1200 | - * @throws InvalidDataTypeException |
|
1201 | - * @throws ServiceNotFoundException |
|
1202 | - * @throws InvalidArgumentException |
|
1203 | - */ |
|
1204 | - public static function dismiss_persistent_admin_notice($pan_name = '', $purge = false, $return = false) |
|
1205 | - { |
|
1206 | - /** @var PersistentAdminNoticeManager $persistent_admin_notice_manager */ |
|
1207 | - $persistent_admin_notice_manager = LoaderFactory::getLoader()->getShared( |
|
1208 | - 'EventEspresso\core\services\notifications\PersistentAdminNoticeManager' |
|
1209 | - ); |
|
1210 | - $persistent_admin_notice_manager->dismissNotice($pan_name, $purge, $return); |
|
1211 | - EE_Error::doing_it_wrong( |
|
1212 | - __METHOD__, |
|
1213 | - sprintf( |
|
1214 | - __('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'), |
|
1215 | - '\EventEspresso\core\services\notifications\PersistentAdminNoticeManager' |
|
1216 | - ), |
|
1217 | - '4.9.27' |
|
1218 | - ); |
|
1219 | - } |
|
1220 | - |
|
1221 | - |
|
1222 | - |
|
1223 | - /** |
|
1224 | - * @deprecated 4.9.27 |
|
1225 | - * @param string $pan_name the name, or key of the Persistent Admin Notice to be stored |
|
1226 | - * @param string $pan_message the message to be stored persistently until dismissed |
|
1227 | - * @param string $return_url URL to go back to after nag notice is dismissed |
|
1228 | - */ |
|
1229 | - public static function display_persistent_admin_notices($pan_name = '', $pan_message = '', $return_url = '') |
|
1230 | - { |
|
1231 | - EE_Error::doing_it_wrong( |
|
1232 | - __METHOD__, |
|
1233 | - sprintf( |
|
1234 | - __('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'), |
|
1235 | - '\EventEspresso\core\services\notifications\PersistentAdminNoticeManager' |
|
1236 | - ), |
|
1237 | - '4.9.27' |
|
1238 | - ); |
|
1239 | - } |
|
1240 | - |
|
1241 | - |
|
1242 | - |
|
1243 | - /** |
|
1244 | - * @deprecated 4.9.27 |
|
1245 | - * @param string $return_url |
|
1246 | - */ |
|
1247 | - public static function get_persistent_admin_notices($return_url = '') |
|
1248 | - { |
|
1249 | - EE_Error::doing_it_wrong( |
|
1250 | - __METHOD__, |
|
1251 | - sprintf( |
|
1252 | - __('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'), |
|
1253 | - '\EventEspresso\core\services\notifications\PersistentAdminNoticeManager' |
|
1254 | - ), |
|
1255 | - '4.9.27' |
|
1256 | - ); |
|
1257 | - } |
|
1041 | + } |
|
1042 | + return ''; |
|
1043 | + } |
|
1044 | + |
|
1045 | + |
|
1046 | + |
|
1047 | + /** |
|
1048 | + * @return void |
|
1049 | + */ |
|
1050 | + public static function enqueue_error_scripts() |
|
1051 | + { |
|
1052 | + self::_print_scripts(); |
|
1053 | + } |
|
1054 | + |
|
1055 | + |
|
1056 | + |
|
1057 | + /** |
|
1058 | + * create error code from filepath, function name, |
|
1059 | + * and line number where exception or error was thrown |
|
1060 | + * |
|
1061 | + * @param string $file |
|
1062 | + * @param string $func |
|
1063 | + * @param string $line |
|
1064 | + * @return string |
|
1065 | + */ |
|
1066 | + public static function generate_error_code($file = '', $func = '', $line = '') |
|
1067 | + { |
|
1068 | + $file = explode('.', basename($file)); |
|
1069 | + $error_code = ! empty($file[0]) ? $file[0] : ''; |
|
1070 | + $error_code .= ! empty($func) ? ' - ' . $func : ''; |
|
1071 | + $error_code .= ! empty($line) ? ' - ' . $line : ''; |
|
1072 | + return $error_code; |
|
1073 | + } |
|
1074 | + |
|
1075 | + |
|
1076 | + |
|
1077 | + /** |
|
1078 | + * write exception details to log file |
|
1079 | + * Since 4.9.53.rc.006 this writes to the standard PHP log file, not EE's custom log file |
|
1080 | + * |
|
1081 | + * @param int $time |
|
1082 | + * @param array $ex |
|
1083 | + * @param bool $clear |
|
1084 | + * @return void |
|
1085 | + */ |
|
1086 | + public function write_to_error_log($time = 0, $ex = array(), $clear = false) |
|
1087 | + { |
|
1088 | + if (empty($ex)) { |
|
1089 | + return; |
|
1090 | + } |
|
1091 | + if (! $time) { |
|
1092 | + $time = time(); |
|
1093 | + } |
|
1094 | + $exception_log = '----------------------------------------------------------------------------------------' |
|
1095 | + . PHP_EOL; |
|
1096 | + $exception_log .= '[' . date('Y-m-d H:i:s', $time) . '] Exception Details' . PHP_EOL; |
|
1097 | + $exception_log .= 'Message: ' . $ex['msg'] . PHP_EOL; |
|
1098 | + $exception_log .= 'Code: ' . $ex['code'] . PHP_EOL; |
|
1099 | + $exception_log .= 'File: ' . $ex['file'] . PHP_EOL; |
|
1100 | + $exception_log .= 'Line No: ' . $ex['line'] . PHP_EOL; |
|
1101 | + $exception_log .= 'Stack trace: ' . PHP_EOL; |
|
1102 | + $exception_log .= $ex['string'] . PHP_EOL; |
|
1103 | + $exception_log .= '----------------------------------------------------------------------------------------' |
|
1104 | + . PHP_EOL; |
|
1105 | + try { |
|
1106 | + error_log($exception_log); |
|
1107 | + } catch (EE_Error $e) { |
|
1108 | + EE_Error::add_error(sprintf(__('Event Espresso error logging could not be setup because: %s', |
|
1109 | + 'event_espresso'), $e->getMessage())); |
|
1110 | + } |
|
1111 | + } |
|
1112 | + |
|
1113 | + |
|
1114 | + |
|
1115 | + /** |
|
1116 | + * This is just a wrapper for the EEH_Debug_Tools::instance()->doing_it_wrong() method. |
|
1117 | + * doing_it_wrong() is used in those cases where a normal PHP error won't get thrown, |
|
1118 | + * but the code execution is done in a manner that could lead to unexpected results |
|
1119 | + * (i.e. running to early, or too late in WP or EE loading process). |
|
1120 | + * A good test for knowing whether to use this method is: |
|
1121 | + * 1. Is there going to be a PHP error if something isn't setup/used correctly? |
|
1122 | + * Yes -> use EE_Error::add_error() or throw new EE_Error() |
|
1123 | + * 2. If this is loaded before something else, it won't break anything, |
|
1124 | + * but just wont' do what its supposed to do? Yes -> use EE_Error::doing_it_wrong() |
|
1125 | + * |
|
1126 | + * @uses constant WP_DEBUG test if wp_debug is on or not |
|
1127 | + * @param string $function The function that was called |
|
1128 | + * @param string $message A message explaining what has been done incorrectly |
|
1129 | + * @param string $version The version of Event Espresso where the error was added |
|
1130 | + * @param string $applies_when a version string for when you want the doing_it_wrong notice to begin appearing |
|
1131 | + * for a deprecated function. This allows deprecation to occur during one version, |
|
1132 | + * but not have any notices appear until a later version. This allows developers |
|
1133 | + * extra time to update their code before notices appear. |
|
1134 | + * @param int $error_type |
|
1135 | + */ |
|
1136 | + public static function doing_it_wrong( |
|
1137 | + $function, |
|
1138 | + $message, |
|
1139 | + $version, |
|
1140 | + $applies_when = '', |
|
1141 | + $error_type = null |
|
1142 | + ) { |
|
1143 | + if (defined('WP_DEBUG') && WP_DEBUG) { |
|
1144 | + EEH_Debug_Tools::instance()->doing_it_wrong($function, $message, $version, $applies_when, $error_type); |
|
1145 | + } |
|
1146 | + } |
|
1147 | + |
|
1148 | + |
|
1149 | + |
|
1150 | + /** |
|
1151 | + * Like get_notices, but returns an array of all the notices of the given type. |
|
1152 | + * |
|
1153 | + * @return array { |
|
1154 | + * @type array $success all the success messages |
|
1155 | + * @type array $errors all the error messages |
|
1156 | + * @type array $attention all the attention messages |
|
1157 | + * } |
|
1158 | + */ |
|
1159 | + public static function get_raw_notices() |
|
1160 | + { |
|
1161 | + return self::$_espresso_notices; |
|
1162 | + } |
|
1163 | + |
|
1164 | + |
|
1165 | + |
|
1166 | + /** |
|
1167 | + * @deprecated 4.9.27 |
|
1168 | + * @param string $pan_name the name, or key of the Persistent Admin Notice to be stored |
|
1169 | + * @param string $pan_message the message to be stored persistently until dismissed |
|
1170 | + * @param bool $force_update allows one to enforce the reappearance of a persistent message. |
|
1171 | + * @return void |
|
1172 | + * @throws InvalidDataTypeException |
|
1173 | + */ |
|
1174 | + public static function add_persistent_admin_notice($pan_name = '', $pan_message, $force_update = false) |
|
1175 | + { |
|
1176 | + new PersistentAdminNotice( |
|
1177 | + $pan_name, |
|
1178 | + $pan_message, |
|
1179 | + $force_update |
|
1180 | + ); |
|
1181 | + EE_Error::doing_it_wrong( |
|
1182 | + __METHOD__, |
|
1183 | + sprintf( |
|
1184 | + __('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'), |
|
1185 | + '\EventEspresso\core\domain\entities\notifications\PersistentAdminNotice' |
|
1186 | + ), |
|
1187 | + '4.9.27' |
|
1188 | + ); |
|
1189 | + } |
|
1190 | + |
|
1191 | + |
|
1192 | + |
|
1193 | + /** |
|
1194 | + * @deprecated 4.9.27 |
|
1195 | + * @param string $pan_name the name, or key of the Persistent Admin Notice to be dismissed |
|
1196 | + * @param bool $purge |
|
1197 | + * @param bool $return |
|
1198 | + * @throws DomainException |
|
1199 | + * @throws InvalidInterfaceException |
|
1200 | + * @throws InvalidDataTypeException |
|
1201 | + * @throws ServiceNotFoundException |
|
1202 | + * @throws InvalidArgumentException |
|
1203 | + */ |
|
1204 | + public static function dismiss_persistent_admin_notice($pan_name = '', $purge = false, $return = false) |
|
1205 | + { |
|
1206 | + /** @var PersistentAdminNoticeManager $persistent_admin_notice_manager */ |
|
1207 | + $persistent_admin_notice_manager = LoaderFactory::getLoader()->getShared( |
|
1208 | + 'EventEspresso\core\services\notifications\PersistentAdminNoticeManager' |
|
1209 | + ); |
|
1210 | + $persistent_admin_notice_manager->dismissNotice($pan_name, $purge, $return); |
|
1211 | + EE_Error::doing_it_wrong( |
|
1212 | + __METHOD__, |
|
1213 | + sprintf( |
|
1214 | + __('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'), |
|
1215 | + '\EventEspresso\core\services\notifications\PersistentAdminNoticeManager' |
|
1216 | + ), |
|
1217 | + '4.9.27' |
|
1218 | + ); |
|
1219 | + } |
|
1220 | + |
|
1221 | + |
|
1222 | + |
|
1223 | + /** |
|
1224 | + * @deprecated 4.9.27 |
|
1225 | + * @param string $pan_name the name, or key of the Persistent Admin Notice to be stored |
|
1226 | + * @param string $pan_message the message to be stored persistently until dismissed |
|
1227 | + * @param string $return_url URL to go back to after nag notice is dismissed |
|
1228 | + */ |
|
1229 | + public static function display_persistent_admin_notices($pan_name = '', $pan_message = '', $return_url = '') |
|
1230 | + { |
|
1231 | + EE_Error::doing_it_wrong( |
|
1232 | + __METHOD__, |
|
1233 | + sprintf( |
|
1234 | + __('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'), |
|
1235 | + '\EventEspresso\core\services\notifications\PersistentAdminNoticeManager' |
|
1236 | + ), |
|
1237 | + '4.9.27' |
|
1238 | + ); |
|
1239 | + } |
|
1240 | + |
|
1241 | + |
|
1242 | + |
|
1243 | + /** |
|
1244 | + * @deprecated 4.9.27 |
|
1245 | + * @param string $return_url |
|
1246 | + */ |
|
1247 | + public static function get_persistent_admin_notices($return_url = '') |
|
1248 | + { |
|
1249 | + EE_Error::doing_it_wrong( |
|
1250 | + __METHOD__, |
|
1251 | + sprintf( |
|
1252 | + __('Usage is deprecated. Use "%1$s" instead.', 'event_espresso'), |
|
1253 | + '\EventEspresso\core\services\notifications\PersistentAdminNoticeManager' |
|
1254 | + ), |
|
1255 | + '4.9.27' |
|
1256 | + ); |
|
1257 | + } |
|
1258 | 1258 | |
1259 | 1259 | |
1260 | 1260 | |
@@ -1269,27 +1269,27 @@ discard block |
||
1269 | 1269 | */ |
1270 | 1270 | function espresso_error_enqueue_scripts() |
1271 | 1271 | { |
1272 | - // js for error handling |
|
1273 | - wp_register_script( |
|
1274 | - 'espresso_core', |
|
1275 | - EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', |
|
1276 | - array('jquery'), |
|
1277 | - EVENT_ESPRESSO_VERSION, |
|
1278 | - false |
|
1279 | - ); |
|
1280 | - wp_register_script( |
|
1281 | - 'ee_error_js', |
|
1282 | - EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js', |
|
1283 | - array('espresso_core'), |
|
1284 | - EVENT_ESPRESSO_VERSION, |
|
1285 | - false |
|
1286 | - ); |
|
1272 | + // js for error handling |
|
1273 | + wp_register_script( |
|
1274 | + 'espresso_core', |
|
1275 | + EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', |
|
1276 | + array('jquery'), |
|
1277 | + EVENT_ESPRESSO_VERSION, |
|
1278 | + false |
|
1279 | + ); |
|
1280 | + wp_register_script( |
|
1281 | + 'ee_error_js', |
|
1282 | + EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js', |
|
1283 | + array('espresso_core'), |
|
1284 | + EVENT_ESPRESSO_VERSION, |
|
1285 | + false |
|
1286 | + ); |
|
1287 | 1287 | } |
1288 | 1288 | |
1289 | 1289 | if (is_admin()) { |
1290 | - add_action('admin_enqueue_scripts', 'espresso_error_enqueue_scripts', 2); |
|
1290 | + add_action('admin_enqueue_scripts', 'espresso_error_enqueue_scripts', 2); |
|
1291 | 1291 | } else { |
1292 | - add_action('wp_enqueue_scripts', 'espresso_error_enqueue_scripts', 2); |
|
1292 | + add_action('wp_enqueue_scripts', 'espresso_error_enqueue_scripts', 2); |
|
1293 | 1293 | } |
1294 | 1294 | |
1295 | 1295 |
@@ -102,14 +102,14 @@ discard block |
||
102 | 102 | default : |
103 | 103 | $to = get_option('admin_email'); |
104 | 104 | } |
105 | - $subject = $type . ' ' . $message . ' in ' . EVENT_ESPRESSO_VERSION . ' on ' . site_url(); |
|
105 | + $subject = $type.' '.$message.' in '.EVENT_ESPRESSO_VERSION.' on '.site_url(); |
|
106 | 106 | $msg = EE_Error::_format_error($type, $message, $file, $line); |
107 | 107 | if (function_exists('wp_mail')) { |
108 | 108 | add_filter('wp_mail_content_type', array('EE_Error', 'set_content_type')); |
109 | 109 | wp_mail($to, $subject, $msg); |
110 | 110 | } |
111 | 111 | echo '<div id="message" class="espresso-notices error"><p>'; |
112 | - echo $type . ': ' . $message . '<br />' . $file . ' line ' . $line; |
|
112 | + echo $type.': '.$message.'<br />'.$file.' line '.$line; |
|
113 | 113 | echo '<br /></p></div>'; |
114 | 114 | } |
115 | 115 | |
@@ -334,7 +334,7 @@ discard block |
||
334 | 334 | } |
335 | 335 | </style> |
336 | 336 | <div id="ee-error-message" class="error">'; |
337 | - if (! WP_DEBUG) { |
|
337 | + if ( ! WP_DEBUG) { |
|
338 | 338 | $output .= ' |
339 | 339 | <p>'; |
340 | 340 | } |
@@ -393,14 +393,14 @@ discard block |
||
393 | 393 | $class_dsply = ! empty($class) ? $class : ' '; |
394 | 394 | $type_dsply = ! empty($type) ? $type : ' '; |
395 | 395 | $function_dsply = ! empty($function) ? $function : ' '; |
396 | - $args_dsply = ! empty($args) ? '( ' . $args . ' )' : ''; |
|
396 | + $args_dsply = ! empty($args) ? '( '.$args.' )' : ''; |
|
397 | 397 | $trace_details .= ' |
398 | 398 | <tr> |
399 | - <td align="right" class="' . $zebra . '">' . $nmbr_dsply . '</td> |
|
400 | - <td align="right" class="' . $zebra . '">' . $line_dsply . '</td> |
|
401 | - <td align="left" class="' . $zebra . '">' . $file_dsply . '</td> |
|
402 | - <td align="left" class="' . $zebra . '">' . $class_dsply . '</td> |
|
403 | - <td align="left" class="' . $zebra . '">' . $type_dsply . $function_dsply . $args_dsply . '</td> |
|
399 | + <td align="right" class="' . $zebra.'">'.$nmbr_dsply.'</td> |
|
400 | + <td align="right" class="' . $zebra.'">'.$line_dsply.'</td> |
|
401 | + <td align="left" class="' . $zebra.'">'.$file_dsply.'</td> |
|
402 | + <td align="left" class="' . $zebra.'">'.$class_dsply.'</td> |
|
403 | + <td align="left" class="' . $zebra.'">'.$type_dsply.$function_dsply.$args_dsply.'</td> |
|
404 | 404 | </tr>'; |
405 | 405 | } |
406 | 406 | $trace_details .= ' |
@@ -409,7 +409,7 @@ discard block |
||
409 | 409 | } |
410 | 410 | $ex['code'] = $ex['code'] ? $ex['code'] : $error_code; |
411 | 411 | // add generic non-identifying messages for non-privileged users |
412 | - if (! WP_DEBUG) { |
|
412 | + if ( ! WP_DEBUG) { |
|
413 | 413 | $output .= '<span class="ee-error-user-msg-spn">' |
414 | 414 | . trim($ex['msg']) |
415 | 415 | . '</span> <sup>' |
@@ -451,14 +451,14 @@ discard block |
||
451 | 451 | . '-dv" class="ee-error-trace-dv" style="display: none;"> |
452 | 452 | ' |
453 | 453 | . $trace_details; |
454 | - if (! empty($class)) { |
|
454 | + if ( ! empty($class)) { |
|
455 | 455 | $output .= ' |
456 | 456 | <div style="padding:3px; margin:0 0 1em; border:1px solid #666; background:#fff; border-radius:3px;"> |
457 | 457 | <div style="padding:1em 2em; border:1px solid #666; background:#f9f9f9;"> |
458 | 458 | <h3>Class Details</h3>'; |
459 | 459 | $a = new ReflectionClass($class); |
460 | 460 | $output .= ' |
461 | - <pre>' . $a . '</pre> |
|
461 | + <pre>' . $a.'</pre> |
|
462 | 462 | </div> |
463 | 463 | </div>'; |
464 | 464 | } |
@@ -471,7 +471,7 @@ discard block |
||
471 | 471 | } |
472 | 472 | // remove last linebreak |
473 | 473 | $output = substr($output, 0, -6); |
474 | - if (! WP_DEBUG) { |
|
474 | + if ( ! WP_DEBUG) { |
|
475 | 475 | $output .= ' |
476 | 476 | </p>'; |
477 | 477 | } |
@@ -498,20 +498,20 @@ discard block |
||
498 | 498 | private function _convert_args_to_string($arguments = array(), $array = false) |
499 | 499 | { |
500 | 500 | $arg_string = ''; |
501 | - if (! empty($arguments)) { |
|
501 | + if ( ! empty($arguments)) { |
|
502 | 502 | $args = array(); |
503 | 503 | foreach ($arguments as $arg) { |
504 | - if (! empty($arg)) { |
|
504 | + if ( ! empty($arg)) { |
|
505 | 505 | if (is_string($arg)) { |
506 | - $args[] = " '" . $arg . "'"; |
|
506 | + $args[] = " '".$arg."'"; |
|
507 | 507 | } elseif (is_array($arg)) { |
508 | - $args[] = 'ARRAY(' . $this->_convert_args_to_string($arg, true); |
|
508 | + $args[] = 'ARRAY('.$this->_convert_args_to_string($arg, true); |
|
509 | 509 | } elseif ($arg === null) { |
510 | 510 | $args[] = ' NULL'; |
511 | 511 | } elseif (is_bool($arg)) { |
512 | 512 | $args[] = ($arg) ? ' TRUE' : ' FALSE'; |
513 | 513 | } elseif (is_object($arg)) { |
514 | - $args[] = ' OBJECT ' . get_class($arg); |
|
514 | + $args[] = ' OBJECT '.get_class($arg); |
|
515 | 515 | } elseif (is_resource($arg)) { |
516 | 516 | $args[] = get_resource_type($arg); |
517 | 517 | } else { |
@@ -614,7 +614,7 @@ discard block |
||
614 | 614 | { |
615 | 615 | if (empty($msg)) { |
616 | 616 | EE_Error::doing_it_wrong( |
617 | - 'EE_Error::add_' . $type . '()', |
|
617 | + 'EE_Error::add_'.$type.'()', |
|
618 | 618 | sprintf( |
619 | 619 | __('Notifications are not much use without a message! Please add a message to the EE_Error::add_%s() call made in %s on line %d', |
620 | 620 | 'event_espresso'), |
@@ -650,11 +650,11 @@ discard block |
||
650 | 650 | do_action('AHEE__EE_Error___add_notice', $type, $user_msg, $dev_msg, $file, $func, $line); |
651 | 651 | $msg = WP_DEBUG ? $dev_msg : $user_msg; |
652 | 652 | // add notice if message exists |
653 | - if (! empty($msg)) { |
|
653 | + if ( ! empty($msg)) { |
|
654 | 654 | // get error code |
655 | 655 | $notice_code = EE_Error::generate_error_code($file, $func, $line); |
656 | 656 | if (WP_DEBUG && $type === 'errors') { |
657 | - $msg .= '<br/><span class="tiny-text">' . $notice_code . '</span>'; |
|
657 | + $msg .= '<br/><span class="tiny-text">'.$notice_code.'</span>'; |
|
658 | 658 | } |
659 | 659 | // add notice. Index by code if it's not blank |
660 | 660 | if ($notice_code) { |
@@ -882,13 +882,13 @@ discard block |
||
882 | 882 | if (self::$_espresso_notices['success'] && ! empty(self::$_espresso_notices['success'])) { |
883 | 883 | // combine messages |
884 | 884 | $success_messages .= implode(self::$_espresso_notices['success'], '<br />'); |
885 | - $print_scripts = true; |
|
885 | + $print_scripts = true; |
|
886 | 886 | } |
887 | 887 | // check for attention messages |
888 | 888 | if (self::$_espresso_notices['attention'] && ! empty(self::$_espresso_notices['attention'])) { |
889 | 889 | // combine messages |
890 | 890 | $attention_messages .= implode(self::$_espresso_notices['attention'], '<br />'); |
891 | - $print_scripts = true; |
|
891 | + $print_scripts = true; |
|
892 | 892 | } |
893 | 893 | // check for error messages |
894 | 894 | if (self::$_espresso_notices['errors'] && ! empty(self::$_espresso_notices['errors'])) { |
@@ -897,7 +897,7 @@ discard block |
||
897 | 897 | : __('An error has occurred:<br />', 'event_espresso'); |
898 | 898 | // combine messages |
899 | 899 | $error_messages .= implode(self::$_espresso_notices['errors'], '<br />'); |
900 | - $print_scripts = true; |
|
900 | + $print_scripts = true; |
|
901 | 901 | } |
902 | 902 | if ($format_output) { |
903 | 903 | $notices = EE_Error::formatNoticesOutput( |
@@ -938,16 +938,16 @@ discard block |
||
938 | 938 | $print_scripts = false; |
939 | 939 | // grab any notices that have been previously saved |
940 | 940 | $notices = EE_Error::getStoredNotices(); |
941 | - if (! empty($notices)) { |
|
941 | + if ( ! empty($notices)) { |
|
942 | 942 | foreach ($notices as $type => $notice) { |
943 | 943 | if (is_array($notice) && ! empty($notice)) { |
944 | 944 | // make sure that existing notice type is an array |
945 | - self::$_espresso_notices[ $type ] = is_array(self::$_espresso_notices[ $type ]) |
|
946 | - && ! empty(self::$_espresso_notices[ $type ]) |
|
947 | - ? self::$_espresso_notices[ $type ] |
|
945 | + self::$_espresso_notices[$type] = is_array(self::$_espresso_notices[$type]) |
|
946 | + && ! empty(self::$_espresso_notices[$type]) |
|
947 | + ? self::$_espresso_notices[$type] |
|
948 | 948 | : array(); |
949 | 949 | // add newly created notices to existing ones |
950 | - self::$_espresso_notices[ $type ] += $notice; |
|
950 | + self::$_espresso_notices[$type] += $notice; |
|
951 | 951 | $print_scripts = true; |
952 | 952 | } |
953 | 953 | } |
@@ -974,10 +974,10 @@ discard block |
||
974 | 974 | $css_id = is_admin() ? 'ee-success-message' : 'espresso-notices-success'; |
975 | 975 | $css_class = is_admin() ? 'updated fade' : 'success fade-away'; |
976 | 976 | //showMessage( $success_messages ); |
977 | - $notices .= '<div id="' . $css_id . '" ' |
|
978 | - . 'class="espresso-notices ' . $css_class . '" ' |
|
977 | + $notices .= '<div id="'.$css_id.'" ' |
|
978 | + . 'class="espresso-notices '.$css_class.'" ' |
|
979 | 979 | . 'style="display:none;">' |
980 | - . '<p>' . $success_messages . '</p>' |
|
980 | + . '<p>'.$success_messages.'</p>' |
|
981 | 981 | . $close |
982 | 982 | . '</div>'; |
983 | 983 | } |
@@ -985,10 +985,10 @@ discard block |
||
985 | 985 | $css_id = is_admin() ? 'ee-attention-message' : 'espresso-notices-attention'; |
986 | 986 | $css_class = is_admin() ? 'updated ee-notices-attention' : 'attention fade-away'; |
987 | 987 | //showMessage( $error_messages, TRUE ); |
988 | - $notices .= '<div id="' . $css_id . '" ' |
|
989 | - . 'class="espresso-notices ' . $css_class . '" ' |
|
988 | + $notices .= '<div id="'.$css_id.'" ' |
|
989 | + . 'class="espresso-notices '.$css_class.'" ' |
|
990 | 990 | . 'style="display:none;">' |
991 | - . '<p>' . $attention_messages . '</p>' |
|
991 | + . '<p>'.$attention_messages.'</p>' |
|
992 | 992 | . $close |
993 | 993 | . '</div>'; |
994 | 994 | } |
@@ -996,10 +996,10 @@ discard block |
||
996 | 996 | $css_id = is_admin() ? 'ee-error-message' : 'espresso-notices-error'; |
997 | 997 | $css_class = is_admin() ? 'error' : 'error fade-away'; |
998 | 998 | //showMessage( $error_messages, TRUE ); |
999 | - $notices .= '<div id="' . $css_id . '" ' |
|
1000 | - . 'class="espresso-notices ' . $css_class . '" ' |
|
999 | + $notices .= '<div id="'.$css_id.'" ' |
|
1000 | + . 'class="espresso-notices '.$css_class.'" ' |
|
1001 | 1001 | . 'style="display:none;">' |
1002 | - . '<p>' . $error_messages . '</p>' |
|
1002 | + . '<p>'.$error_messages.'</p>' |
|
1003 | 1003 | . $close |
1004 | 1004 | . '</div>'; |
1005 | 1005 | } |
@@ -1017,7 +1017,7 @@ discard block |
||
1017 | 1017 | */ |
1018 | 1018 | private static function _print_scripts($force_print = false) |
1019 | 1019 | { |
1020 | - if (! $force_print && (did_action('admin_enqueue_scripts') || did_action('wp_enqueue_scripts'))) { |
|
1020 | + if ( ! $force_print && (did_action('admin_enqueue_scripts') || did_action('wp_enqueue_scripts'))) { |
|
1021 | 1021 | if (wp_script_is('ee_error_js', 'enqueued')) { |
1022 | 1022 | return ''; |
1023 | 1023 | } |
@@ -1031,12 +1031,12 @@ discard block |
||
1031 | 1031 | return ' |
1032 | 1032 | <script> |
1033 | 1033 | /* <![CDATA[ */ |
1034 | -var ee_settings = {"wp_debug":"' . WP_DEBUG . '"}; |
|
1034 | +var ee_settings = {"wp_debug":"' . WP_DEBUG.'"}; |
|
1035 | 1035 | /* ]]> */ |
1036 | 1036 | </script> |
1037 | -<script src="' . includes_url() . 'js/jquery/jquery.js" type="text/javascript"></script> |
|
1038 | -<script src="' . EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js' . '?ver=' . espresso_version() . '" type="text/javascript"></script> |
|
1039 | -<script src="' . EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js' . '?ver=' . espresso_version() . '" type="text/javascript"></script> |
|
1037 | +<script src="' . includes_url().'js/jquery/jquery.js" type="text/javascript"></script> |
|
1038 | +<script src="' . EE_GLOBAL_ASSETS_URL.'scripts/espresso_core.js'.'?ver='.espresso_version().'" type="text/javascript"></script> |
|
1039 | +<script src="' . EE_GLOBAL_ASSETS_URL.'scripts/EE_Error.js'.'?ver='.espresso_version().'" type="text/javascript"></script> |
|
1040 | 1040 | '; |
1041 | 1041 | } |
1042 | 1042 | return ''; |
@@ -1067,8 +1067,8 @@ discard block |
||
1067 | 1067 | { |
1068 | 1068 | $file = explode('.', basename($file)); |
1069 | 1069 | $error_code = ! empty($file[0]) ? $file[0] : ''; |
1070 | - $error_code .= ! empty($func) ? ' - ' . $func : ''; |
|
1071 | - $error_code .= ! empty($line) ? ' - ' . $line : ''; |
|
1070 | + $error_code .= ! empty($func) ? ' - '.$func : ''; |
|
1071 | + $error_code .= ! empty($line) ? ' - '.$line : ''; |
|
1072 | 1072 | return $error_code; |
1073 | 1073 | } |
1074 | 1074 | |
@@ -1088,18 +1088,18 @@ discard block |
||
1088 | 1088 | if (empty($ex)) { |
1089 | 1089 | return; |
1090 | 1090 | } |
1091 | - if (! $time) { |
|
1091 | + if ( ! $time) { |
|
1092 | 1092 | $time = time(); |
1093 | 1093 | } |
1094 | 1094 | $exception_log = '----------------------------------------------------------------------------------------' |
1095 | 1095 | . PHP_EOL; |
1096 | - $exception_log .= '[' . date('Y-m-d H:i:s', $time) . '] Exception Details' . PHP_EOL; |
|
1097 | - $exception_log .= 'Message: ' . $ex['msg'] . PHP_EOL; |
|
1098 | - $exception_log .= 'Code: ' . $ex['code'] . PHP_EOL; |
|
1099 | - $exception_log .= 'File: ' . $ex['file'] . PHP_EOL; |
|
1100 | - $exception_log .= 'Line No: ' . $ex['line'] . PHP_EOL; |
|
1101 | - $exception_log .= 'Stack trace: ' . PHP_EOL; |
|
1102 | - $exception_log .= $ex['string'] . PHP_EOL; |
|
1096 | + $exception_log .= '['.date('Y-m-d H:i:s', $time).'] Exception Details'.PHP_EOL; |
|
1097 | + $exception_log .= 'Message: '.$ex['msg'].PHP_EOL; |
|
1098 | + $exception_log .= 'Code: '.$ex['code'].PHP_EOL; |
|
1099 | + $exception_log .= 'File: '.$ex['file'].PHP_EOL; |
|
1100 | + $exception_log .= 'Line No: '.$ex['line'].PHP_EOL; |
|
1101 | + $exception_log .= 'Stack trace: '.PHP_EOL; |
|
1102 | + $exception_log .= $ex['string'].PHP_EOL; |
|
1103 | 1103 | $exception_log .= '----------------------------------------------------------------------------------------' |
1104 | 1104 | . PHP_EOL; |
1105 | 1105 | try { |
@@ -1272,14 +1272,14 @@ discard block |
||
1272 | 1272 | // js for error handling |
1273 | 1273 | wp_register_script( |
1274 | 1274 | 'espresso_core', |
1275 | - EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', |
|
1275 | + EE_GLOBAL_ASSETS_URL.'scripts/espresso_core.js', |
|
1276 | 1276 | array('jquery'), |
1277 | 1277 | EVENT_ESPRESSO_VERSION, |
1278 | 1278 | false |
1279 | 1279 | ); |
1280 | 1280 | wp_register_script( |
1281 | 1281 | 'ee_error_js', |
1282 | - EE_GLOBAL_ASSETS_URL . 'scripts/EE_Error.js', |
|
1282 | + EE_GLOBAL_ASSETS_URL.'scripts/EE_Error.js', |
|
1283 | 1283 | array('espresso_core'), |
1284 | 1284 | EVENT_ESPRESSO_VERSION, |
1285 | 1285 | false |
@@ -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.070'); |
|
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.070'); |
|
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 | } |