@@ -375,7 +375,7 @@ discard block |
||
375 | 375 | |
376 | 376 | |
377 | 377 | /** |
378 | - * @param mixed $var |
|
378 | + * @param string $var |
|
379 | 379 | * @param string $var_name |
380 | 380 | * @param string $file |
381 | 381 | * @param int|string $line |
@@ -513,7 +513,7 @@ discard block |
||
513 | 513 | * @param mixed $var |
514 | 514 | * @param string $var_name |
515 | 515 | * @param string $file |
516 | - * @param int|string $line |
|
516 | + * @param integer $line |
|
517 | 517 | * @param int $heading_tag |
518 | 518 | * @param bool $die |
519 | 519 | */ |
@@ -576,7 +576,7 @@ discard block |
||
576 | 576 | |
577 | 577 | /** |
578 | 578 | * @deprecated 4.9.39.rc.034 |
579 | - * @param null $timer_name |
|
579 | + * @param string $timer_name |
|
580 | 580 | */ |
581 | 581 | public function start_timer($timer_name = null) |
582 | 582 | { |
@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <?php use EventEspresso\core\services\Benchmark; |
2 | 2 | |
3 | 3 | if (! defined('EVENT_ESPRESSO_VERSION')) { |
4 | - exit('No direct script access allowed'); |
|
4 | + exit('No direct script access allowed'); |
|
5 | 5 | } |
6 | 6 | |
7 | 7 | |
@@ -17,632 +17,632 @@ discard block |
||
17 | 17 | class EEH_Debug_Tools |
18 | 18 | { |
19 | 19 | |
20 | - /** |
|
21 | - * instance of the EEH_Autoloader object |
|
22 | - * |
|
23 | - * @var $_instance |
|
24 | - * @access private |
|
25 | - */ |
|
26 | - private static $_instance; |
|
27 | - |
|
28 | - /** |
|
29 | - * @var array |
|
30 | - */ |
|
31 | - protected $_memory_usage_points = array(); |
|
32 | - |
|
33 | - |
|
34 | - |
|
35 | - /** |
|
36 | - * @singleton method used to instantiate class object |
|
37 | - * @access public |
|
38 | - * @return EEH_Debug_Tools |
|
39 | - */ |
|
40 | - public static function instance() |
|
41 | - { |
|
42 | - // check if class object is instantiated, and instantiated properly |
|
43 | - if (! self::$_instance instanceof EEH_Debug_Tools) { |
|
44 | - self::$_instance = new self(); |
|
45 | - } |
|
46 | - return self::$_instance; |
|
47 | - } |
|
48 | - |
|
49 | - |
|
50 | - |
|
51 | - /** |
|
52 | - * private class constructor |
|
53 | - */ |
|
54 | - private function __construct() |
|
55 | - { |
|
56 | - // load Kint PHP debugging library |
|
57 | - if (! class_exists('Kint') && file_exists(EE_PLUGIN_DIR_PATH . 'tests' . DS . 'kint' . DS . 'Kint.class.php')) { |
|
58 | - // despite EE4 having a check for an existing copy of the Kint debugging class, |
|
59 | - // if another plugin was loaded AFTER EE4 and they did NOT perform a similar check, |
|
60 | - // then hilarity would ensue as PHP throws a "Cannot redeclare class Kint" error |
|
61 | - // so we've moved it to our test folder so that it is not included with production releases |
|
62 | - // plz use https://wordpress.org/plugins/kint-debugger/ if testing production versions of EE |
|
63 | - require_once(EE_PLUGIN_DIR_PATH . 'tests' . DS . 'kint' . DS . 'Kint.class.php'); |
|
64 | - } |
|
65 | - // if ( ! defined('DOING_AJAX') || $_REQUEST['noheader'] !== 'true' || ! isset( $_REQUEST['noheader'], $_REQUEST['TB_iframe'] ) ) { |
|
66 | - //add_action( 'shutdown', array($this,'espresso_session_footer_dump') ); |
|
67 | - // } |
|
68 | - $plugin = basename(EE_PLUGIN_DIR_PATH); |
|
69 | - add_action("activate_{$plugin}", array('EEH_Debug_Tools', 'ee_plugin_activation_errors')); |
|
70 | - add_action('activated_plugin', array('EEH_Debug_Tools', 'ee_plugin_activation_errors')); |
|
71 | - add_action('shutdown', array('EEH_Debug_Tools', 'show_db_name')); |
|
72 | - } |
|
73 | - |
|
74 | - |
|
75 | - |
|
76 | - /** |
|
77 | - * show_db_name |
|
78 | - * |
|
79 | - * @return void |
|
80 | - */ |
|
81 | - public static function show_db_name() |
|
82 | - { |
|
83 | - if (! defined('DOING_AJAX') && (defined('EE_ERROR_EMAILS') && EE_ERROR_EMAILS)) { |
|
84 | - echo '<p style="font-size:10px;font-weight:normal;color:#E76700;margin: 1em 2em; text-align: right;">DB_NAME: ' |
|
85 | - . DB_NAME |
|
86 | - . '</p>'; |
|
87 | - } |
|
88 | - if (EE_DEBUG) { |
|
89 | - Benchmark::displayResults(); |
|
90 | - } |
|
91 | - } |
|
92 | - |
|
93 | - |
|
94 | - |
|
95 | - /** |
|
96 | - * dump EE_Session object at bottom of page after everything else has happened |
|
97 | - * |
|
98 | - * @return void |
|
99 | - */ |
|
100 | - public function espresso_session_footer_dump() |
|
101 | - { |
|
102 | - if ( |
|
103 | - (defined('WP_DEBUG') && WP_DEBUG) |
|
104 | - && ! defined('DOING_AJAX') |
|
105 | - && class_exists('Kint') |
|
106 | - && function_exists('wp_get_current_user') |
|
107 | - && current_user_can('update_core') |
|
108 | - && class_exists('EE_Registry') |
|
109 | - ) { |
|
110 | - Kint::dump(EE_Registry::instance()->SSN->id()); |
|
111 | - Kint::dump(EE_Registry::instance()->SSN); |
|
112 | - // Kint::dump( EE_Registry::instance()->SSN->get_session_data('cart')->get_tickets() ); |
|
113 | - $this->espresso_list_hooked_functions(); |
|
114 | - Benchmark::displayResults(); |
|
115 | - } |
|
116 | - } |
|
117 | - |
|
118 | - |
|
119 | - |
|
120 | - /** |
|
121 | - * List All Hooked Functions |
|
122 | - * to list all functions for a specific hook, add ee_list_hooks={hook-name} to URL |
|
123 | - * http://wp.smashingmagazine.com/2009/08/18/10-useful-wordpress-hook-hacks/ |
|
124 | - * |
|
125 | - * @param string $tag |
|
126 | - * @return void |
|
127 | - */ |
|
128 | - public function espresso_list_hooked_functions($tag = '') |
|
129 | - { |
|
130 | - global $wp_filter; |
|
131 | - echo '<br/><br/><br/><h3>Hooked Functions</h3>'; |
|
132 | - if ($tag) { |
|
133 | - $hook[$tag] = $wp_filter[$tag]; |
|
134 | - if (! is_array($hook[$tag])) { |
|
135 | - trigger_error("Nothing found for '$tag' hook", E_USER_WARNING); |
|
136 | - return; |
|
137 | - } |
|
138 | - echo '<h5>For Tag: ' . $tag . '</h5>'; |
|
139 | - } else { |
|
140 | - $hook = is_array($wp_filter) ? $wp_filter : array($wp_filter); |
|
141 | - ksort($hook); |
|
142 | - } |
|
143 | - foreach ($hook as $tag_name => $priorities) { |
|
144 | - echo "<br />>>>>>\t<strong>$tag_name</strong><br />"; |
|
145 | - ksort($priorities); |
|
146 | - foreach ($priorities as $priority => $function) { |
|
147 | - echo $priority; |
|
148 | - foreach ($function as $name => $properties) { |
|
149 | - echo "\t$name<br />"; |
|
150 | - } |
|
151 | - } |
|
152 | - } |
|
153 | - } |
|
154 | - |
|
155 | - |
|
156 | - |
|
157 | - /** |
|
158 | - * registered_filter_callbacks |
|
159 | - * |
|
160 | - * @param string $hook_name |
|
161 | - * @return array |
|
162 | - */ |
|
163 | - public static function registered_filter_callbacks($hook_name = '') |
|
164 | - { |
|
165 | - $filters = array(); |
|
166 | - global $wp_filter; |
|
167 | - if (isset($wp_filter[$hook_name])) { |
|
168 | - $filters[$hook_name] = array(); |
|
169 | - foreach ($wp_filter[$hook_name] as $priority => $callbacks) { |
|
170 | - $filters[$hook_name][$priority] = array(); |
|
171 | - foreach ($callbacks as $callback) { |
|
172 | - $filters[$hook_name][$priority][] = $callback['function']; |
|
173 | - } |
|
174 | - } |
|
175 | - } |
|
176 | - return $filters; |
|
177 | - } |
|
178 | - |
|
179 | - |
|
180 | - |
|
181 | - /** |
|
182 | - * captures plugin activation errors for debugging |
|
183 | - * |
|
184 | - * @return void |
|
185 | - * @throws EE_Error |
|
186 | - */ |
|
187 | - public static function ee_plugin_activation_errors() |
|
188 | - { |
|
189 | - if (WP_DEBUG) { |
|
190 | - $activation_errors = ob_get_contents(); |
|
191 | - if (! empty($activation_errors)) { |
|
192 | - $activation_errors = date('Y-m-d H:i:s') . "\n" . $activation_errors; |
|
193 | - } |
|
194 | - espresso_load_required('EEH_File', EE_HELPERS . 'EEH_File.helper.php'); |
|
195 | - if (class_exists('EEH_File')) { |
|
196 | - try { |
|
197 | - EEH_File::ensure_file_exists_and_is_writable( |
|
198 | - EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . 'espresso_plugin_activation_errors.html' |
|
199 | - ); |
|
200 | - EEH_File::write_to_file( |
|
201 | - EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . 'espresso_plugin_activation_errors.html', |
|
202 | - $activation_errors |
|
203 | - ); |
|
204 | - } catch (EE_Error $e) { |
|
205 | - EE_Error::add_error( |
|
206 | - sprintf( |
|
207 | - __( |
|
208 | - 'The Event Espresso activation errors file could not be setup because: %s', |
|
209 | - 'event_espresso' |
|
210 | - ), |
|
211 | - $e->getMessage() |
|
212 | - ), |
|
213 | - __FILE__, __FUNCTION__, __LINE__ |
|
214 | - ); |
|
215 | - } |
|
216 | - } else { |
|
217 | - // old school attempt |
|
218 | - file_put_contents( |
|
219 | - EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . 'espresso_plugin_activation_errors.html', |
|
220 | - $activation_errors |
|
221 | - ); |
|
222 | - } |
|
223 | - $activation_errors = get_option('ee_plugin_activation_errors', '') . $activation_errors; |
|
224 | - update_option('ee_plugin_activation_errors', $activation_errors); |
|
225 | - } |
|
226 | - } |
|
227 | - |
|
228 | - |
|
229 | - |
|
230 | - /** |
|
231 | - * This basically mimics the WordPress _doing_it_wrong() function except adds our own messaging etc. |
|
232 | - * Very useful for providing helpful messages to developers when the method of doing something has been deprecated, |
|
233 | - * or we want to make sure they use something the right way. |
|
234 | - * |
|
235 | - * @access public |
|
236 | - * @param string $function The function that was called |
|
237 | - * @param string $message A message explaining what has been done incorrectly |
|
238 | - * @param string $version The version of Event Espresso where the error was added |
|
239 | - * @param string $applies_when a version string for when you want the doing_it_wrong notice to begin appearing |
|
240 | - * for a deprecated function. This allows deprecation to occur during one version, |
|
241 | - * but not have any notices appear until a later version. This allows developers |
|
242 | - * extra time to update their code before notices appear. |
|
243 | - * @param int $error_type |
|
244 | - * @uses trigger_error() |
|
245 | - */ |
|
246 | - public function doing_it_wrong( |
|
247 | - $function, |
|
248 | - $message, |
|
249 | - $version, |
|
250 | - $applies_when = '', |
|
251 | - $error_type = null |
|
252 | - ) { |
|
253 | - $applies_when = ! empty($applies_when) ? $applies_when : espresso_version(); |
|
254 | - $error_type = $error_type !== null ? $error_type : E_USER_NOTICE; |
|
255 | - // because we swapped the parameter order around for the last two params, |
|
256 | - // let's verify that some third party isn't still passing an error type value for the third param |
|
257 | - if (is_int($applies_when)) { |
|
258 | - $error_type = $applies_when; |
|
259 | - $applies_when = espresso_version(); |
|
260 | - } |
|
261 | - // if not displaying notices yet, then just leave |
|
262 | - if (version_compare(espresso_version(), $applies_when, '<')) { |
|
263 | - return; |
|
264 | - } |
|
265 | - do_action('AHEE__EEH_Debug_Tools__doing_it_wrong_run', $function, $message, $version); |
|
266 | - $version = $version === null |
|
267 | - ? '' |
|
268 | - : sprintf( |
|
269 | - __('(This message was added in version %s of Event Espresso)', 'event_espresso'), |
|
270 | - $version |
|
271 | - ); |
|
272 | - $error_message = sprintf( |
|
273 | - esc_html__('%1$s was called %2$sincorrectly%3$s. %4$s %5$s', 'event_espresso'), |
|
274 | - $function, |
|
275 | - '<strong>', |
|
276 | - '</strong>', |
|
277 | - $message, |
|
278 | - $version |
|
279 | - ); |
|
280 | - // don't trigger error if doing ajax, |
|
281 | - // instead we'll add a transient EE_Error notice that in theory should show on the next request. |
|
282 | - if (defined('DOING_AJAX') && DOING_AJAX) { |
|
283 | - $error_message .= ' ' . esc_html__( |
|
284 | - 'This is a doing_it_wrong message that was triggered during an ajax request. The request params on this request were: ', |
|
285 | - 'event_espresso' |
|
286 | - ); |
|
287 | - $error_message .= '<ul><li>'; |
|
288 | - $error_message .= implode('</li><li>', EE_Registry::instance()->REQ->params()); |
|
289 | - $error_message .= '</ul>'; |
|
290 | - EE_Error::add_error($error_message, 'debug::doing_it_wrong', $function, '42'); |
|
291 | - //now we set this on the transient so it shows up on the next request. |
|
292 | - EE_Error::get_notices(false, true); |
|
293 | - } else { |
|
294 | - trigger_error($error_message, $error_type); |
|
295 | - } |
|
296 | - } |
|
297 | - |
|
298 | - |
|
299 | - |
|
300 | - |
|
301 | - /** |
|
302 | - * Logger helpers |
|
303 | - */ |
|
304 | - /** |
|
305 | - * debug |
|
306 | - * |
|
307 | - * @param string $class |
|
308 | - * @param string $func |
|
309 | - * @param string $line |
|
310 | - * @param array $info |
|
311 | - * @param bool $display_request |
|
312 | - * @param string $debug_index |
|
313 | - * @param string $debug_key |
|
314 | - * @throws EE_Error |
|
315 | - * @throws \EventEspresso\core\exceptions\InvalidSessionDataException |
|
316 | - */ |
|
317 | - public static function log( |
|
318 | - $class = '', |
|
319 | - $func = '', |
|
320 | - $line = '', |
|
321 | - $info = array(), |
|
322 | - $display_request = false, |
|
323 | - $debug_index = '', |
|
324 | - $debug_key = 'EE_DEBUG_SPCO' |
|
325 | - ) { |
|
326 | - if (WP_DEBUG) { |
|
327 | - $debug_key = $debug_key . '_' . EE_Session::instance()->id(); |
|
328 | - $debug_data = get_option($debug_key, array()); |
|
329 | - $default_data = array( |
|
330 | - $class => $func . '() : ' . $line, |
|
331 | - 'REQ' => $display_request ? $_REQUEST : '', |
|
332 | - ); |
|
333 | - // don't serialize objects |
|
334 | - $info = self::strip_objects($info); |
|
335 | - $index = ! empty($debug_index) ? $debug_index : 0; |
|
336 | - if (! isset($debug_data[$index])) { |
|
337 | - $debug_data[$index] = array(); |
|
338 | - } |
|
339 | - $debug_data[$index][microtime()] = array_merge($default_data, $info); |
|
340 | - update_option($debug_key, $debug_data); |
|
341 | - } |
|
342 | - } |
|
343 | - |
|
344 | - |
|
345 | - |
|
346 | - /** |
|
347 | - * strip_objects |
|
348 | - * |
|
349 | - * @param array $info |
|
350 | - * @return array |
|
351 | - */ |
|
352 | - public static function strip_objects($info = array()) |
|
353 | - { |
|
354 | - foreach ($info as $key => $value) { |
|
355 | - if (is_array($value)) { |
|
356 | - $info[$key] = self::strip_objects($value); |
|
357 | - } else if (is_object($value)) { |
|
358 | - $object_class = get_class($value); |
|
359 | - $info[$object_class] = array(); |
|
360 | - $info[$object_class]['ID'] = method_exists($value, 'ID') ? $value->ID() : spl_object_hash($value); |
|
361 | - if (method_exists($value, 'ID')) { |
|
362 | - $info[$object_class]['ID'] = $value->ID(); |
|
363 | - } |
|
364 | - if (method_exists($value, 'status')) { |
|
365 | - $info[$object_class]['status'] = $value->status(); |
|
366 | - } else if (method_exists($value, 'status_ID')) { |
|
367 | - $info[$object_class]['status'] = $value->status_ID(); |
|
368 | - } |
|
369 | - unset($info[$key]); |
|
370 | - } |
|
371 | - } |
|
372 | - return (array)$info; |
|
373 | - } |
|
374 | - |
|
375 | - |
|
376 | - |
|
377 | - /** |
|
378 | - * @param mixed $var |
|
379 | - * @param string $var_name |
|
380 | - * @param string $file |
|
381 | - * @param int|string $line |
|
382 | - * @param int $heading_tag |
|
383 | - * @param bool $die |
|
384 | - * @param string $margin |
|
385 | - */ |
|
386 | - public static function printv( |
|
387 | - $var, |
|
388 | - $var_name = '', |
|
389 | - $file = '', |
|
390 | - $line = '', |
|
391 | - $heading_tag = 5, |
|
392 | - $die = false, |
|
393 | - $margin = '' |
|
394 | - ) { |
|
395 | - $var_name = ! $var_name ? 'string' : $var_name; |
|
396 | - $var_name = ucwords(str_replace('$', '', $var_name)); |
|
397 | - $is_method = method_exists($var_name, $var); |
|
398 | - $var_name = ucwords(str_replace('_', ' ', $var_name)); |
|
399 | - $heading_tag = is_int($heading_tag) ? "h{$heading_tag}" : 'h5'; |
|
400 | - $result = EEH_Debug_Tools::heading($var_name, $heading_tag, $margin); |
|
401 | - $result .= $is_method |
|
402 | - ? EEH_Debug_Tools::grey_span('::') . EEH_Debug_Tools::orange_span($var . '()') |
|
403 | - : EEH_Debug_Tools::grey_span(' : ') . EEH_Debug_Tools::orange_span($var); |
|
404 | - $result .= EEH_Debug_Tools::file_and_line($file, $line); |
|
405 | - $result .= EEH_Debug_Tools::headingX($heading_tag); |
|
406 | - if ($die) { |
|
407 | - die($result); |
|
408 | - } |
|
409 | - echo $result; |
|
410 | - } |
|
411 | - |
|
412 | - |
|
413 | - |
|
414 | - /** |
|
415 | - * @param string $var_name |
|
416 | - * @param string $heading_tag |
|
417 | - * @param string $margin |
|
418 | - * @return string |
|
419 | - */ |
|
420 | - protected static function heading($var_name = '', $heading_tag = 'h5', $margin = '') |
|
421 | - { |
|
422 | - if (defined('EE_TESTS_DIR')) { |
|
423 | - return "\n{$var_name}"; |
|
424 | - } |
|
425 | - $margin = "25px 0 0 {$margin}"; |
|
426 | - return '<' . $heading_tag . ' style="color:#2EA2CC; margin:' . $margin . ';"><b>' . $var_name . '</b>'; |
|
427 | - } |
|
428 | - |
|
429 | - |
|
430 | - |
|
431 | - /** |
|
432 | - * @param string $heading_tag |
|
433 | - * @return string |
|
434 | - */ |
|
435 | - protected static function headingX($heading_tag = 'h5') |
|
436 | - { |
|
437 | - if (defined('EE_TESTS_DIR')) { |
|
438 | - return ''; |
|
439 | - } |
|
440 | - return '</' . $heading_tag . '>'; |
|
441 | - } |
|
442 | - |
|
443 | - |
|
444 | - |
|
445 | - /** |
|
446 | - * @param string $content |
|
447 | - * @return string |
|
448 | - */ |
|
449 | - protected static function grey_span($content = '') |
|
450 | - { |
|
451 | - if (defined('EE_TESTS_DIR')) { |
|
452 | - return $content; |
|
453 | - } |
|
454 | - return '<span style="color:#999">' . $content . '</span>'; |
|
455 | - } |
|
456 | - |
|
457 | - |
|
458 | - |
|
459 | - /** |
|
460 | - * @param string $file |
|
461 | - * @param int $line |
|
462 | - * @return string |
|
463 | - */ |
|
464 | - protected static function file_and_line($file, $line) |
|
465 | - { |
|
466 | - if ($file === '' || $line === '') { |
|
467 | - return ''; |
|
468 | - } |
|
469 | - if (defined('EE_TESTS_DIR')) { |
|
470 | - return "\n (" . $file . ' line no: ' . $line . ' ) '; |
|
471 | - } |
|
472 | - return '<br /><span style="font-size:9px;font-weight:normal;color:#666;line-height: 12px;">' |
|
473 | - . $file |
|
474 | - . '<br />line no: ' |
|
475 | - . $line |
|
476 | - . '</span>'; |
|
477 | - } |
|
478 | - |
|
479 | - |
|
480 | - |
|
481 | - /** |
|
482 | - * @param string $content |
|
483 | - * @return string |
|
484 | - */ |
|
485 | - protected static function orange_span($content = '') |
|
486 | - { |
|
487 | - if (defined('EE_TESTS_DIR')) { |
|
488 | - return $content; |
|
489 | - } |
|
490 | - return '<span style="color:#E76700">' . $content . '</span>'; |
|
491 | - } |
|
492 | - |
|
493 | - |
|
494 | - |
|
495 | - /** |
|
496 | - * @param mixed $var |
|
497 | - * @return string |
|
498 | - */ |
|
499 | - protected static function pre_span($var) |
|
500 | - { |
|
501 | - ob_start(); |
|
502 | - var_dump($var); |
|
503 | - $var = ob_get_clean(); |
|
504 | - if (defined('EE_TESTS_DIR')) { |
|
505 | - return "\n" . $var; |
|
506 | - } |
|
507 | - return '<pre style="color:#999; padding:1em; background: #fff">' . $var . '</pre>'; |
|
508 | - } |
|
509 | - |
|
510 | - |
|
511 | - |
|
512 | - /** |
|
513 | - * @param mixed $var |
|
514 | - * @param string $var_name |
|
515 | - * @param string $file |
|
516 | - * @param int|string $line |
|
517 | - * @param int $heading_tag |
|
518 | - * @param bool $die |
|
519 | - */ |
|
520 | - public static function printr( |
|
521 | - $var, |
|
522 | - $var_name = '', |
|
523 | - $file = '', |
|
524 | - $line = '', |
|
525 | - $heading_tag = 5, |
|
526 | - $die = false |
|
527 | - ) { |
|
528 | - // return; |
|
529 | - $file = str_replace(rtrim(ABSPATH, '\\/'), '', $file); |
|
530 | - $margin = is_admin() ? ' 180px' : '0'; |
|
531 | - //$print_r = false; |
|
532 | - if (is_string($var)) { |
|
533 | - EEH_Debug_Tools::printv($var, $var_name, $file, $line, $heading_tag, $die, $margin); |
|
534 | - return; |
|
535 | - } |
|
536 | - if (is_object($var)) { |
|
537 | - $var_name = ! $var_name ? 'object' : $var_name; |
|
538 | - //$print_r = true; |
|
539 | - } else if (is_array($var)) { |
|
540 | - $var_name = ! $var_name ? 'array' : $var_name; |
|
541 | - //$print_r = true; |
|
542 | - } else if (is_numeric($var)) { |
|
543 | - $var_name = ! $var_name ? 'numeric' : $var_name; |
|
544 | - } else if ($var === null) { |
|
545 | - $var_name = ! $var_name ? 'null' : $var_name; |
|
546 | - } |
|
547 | - $var_name = ucwords(str_replace(array('$', '_'), array('', ' '), $var_name)); |
|
548 | - $heading_tag = is_int($heading_tag) ? "h{$heading_tag}" : 'h5'; |
|
549 | - $result = EEH_Debug_Tools::heading($var_name, $heading_tag, $margin); |
|
550 | - $result .= EEH_Debug_Tools::grey_span(' : ') . EEH_Debug_Tools::orange_span( |
|
551 | - EEH_Debug_Tools::pre_span($var) |
|
552 | - ); |
|
553 | - $result .= EEH_Debug_Tools::file_and_line($file, $line); |
|
554 | - $result .= EEH_Debug_Tools::headingX($heading_tag); |
|
555 | - if ($die) { |
|
556 | - die($result); |
|
557 | - } |
|
558 | - echo $result; |
|
559 | - } |
|
560 | - |
|
561 | - |
|
562 | - |
|
563 | - /******************** deprecated ********************/ |
|
564 | - |
|
565 | - |
|
566 | - |
|
567 | - /** |
|
568 | - * @deprecated 4.9.39.rc.034 |
|
569 | - */ |
|
570 | - public function reset_times() |
|
571 | - { |
|
572 | - Benchmark::resetTimes(); |
|
573 | - } |
|
574 | - |
|
575 | - |
|
576 | - |
|
577 | - /** |
|
578 | - * @deprecated 4.9.39.rc.034 |
|
579 | - * @param null $timer_name |
|
580 | - */ |
|
581 | - public function start_timer($timer_name = null) |
|
582 | - { |
|
583 | - Benchmark::startTimer($timer_name); |
|
584 | - } |
|
585 | - |
|
586 | - |
|
587 | - |
|
588 | - /** |
|
589 | - * @deprecated 4.9.39.rc.034 |
|
590 | - * @param string $timer_name |
|
591 | - */ |
|
592 | - public function stop_timer($timer_name = '') |
|
593 | - { |
|
594 | - Benchmark::stopTimer($timer_name); |
|
595 | - } |
|
596 | - |
|
597 | - |
|
598 | - |
|
599 | - /** |
|
600 | - * @deprecated 4.9.39.rc.034 |
|
601 | - * @param string $label The label to show for this time eg "Start of calling Some_Class::some_function" |
|
602 | - * @param boolean $output_now whether to echo now, or wait until EEH_Debug_Tools::show_times() is called |
|
603 | - * @return void |
|
604 | - */ |
|
605 | - public function measure_memory($label, $output_now = false) |
|
606 | - { |
|
607 | - Benchmark::measureMemory($label, $output_now); |
|
608 | - } |
|
609 | - |
|
610 | - |
|
611 | - |
|
612 | - /** |
|
613 | - * @deprecated 4.9.39.rc.034 |
|
614 | - * @param int $size |
|
615 | - * @return string |
|
616 | - */ |
|
617 | - public function convert($size) |
|
618 | - { |
|
619 | - return Benchmark::convert($size); |
|
620 | - } |
|
621 | - |
|
622 | - |
|
623 | - |
|
624 | - /** |
|
625 | - * @deprecated 4.9.39.rc.034 |
|
626 | - * @param bool $output_now |
|
627 | - * @return string |
|
628 | - */ |
|
629 | - public function show_times($output_now = true) |
|
630 | - { |
|
631 | - return Benchmark::displayResults($output_now); |
|
632 | - } |
|
633 | - |
|
634 | - |
|
635 | - |
|
636 | - /** |
|
637 | - * @deprecated 4.9.39.rc.034 |
|
638 | - * @param string $timer_name |
|
639 | - * @param float $total_time |
|
640 | - * @return string |
|
641 | - */ |
|
642 | - public function format_time($timer_name, $total_time) |
|
643 | - { |
|
644 | - return Benchmark::formatTime($timer_name, $total_time); |
|
645 | - } |
|
20 | + /** |
|
21 | + * instance of the EEH_Autoloader object |
|
22 | + * |
|
23 | + * @var $_instance |
|
24 | + * @access private |
|
25 | + */ |
|
26 | + private static $_instance; |
|
27 | + |
|
28 | + /** |
|
29 | + * @var array |
|
30 | + */ |
|
31 | + protected $_memory_usage_points = array(); |
|
32 | + |
|
33 | + |
|
34 | + |
|
35 | + /** |
|
36 | + * @singleton method used to instantiate class object |
|
37 | + * @access public |
|
38 | + * @return EEH_Debug_Tools |
|
39 | + */ |
|
40 | + public static function instance() |
|
41 | + { |
|
42 | + // check if class object is instantiated, and instantiated properly |
|
43 | + if (! self::$_instance instanceof EEH_Debug_Tools) { |
|
44 | + self::$_instance = new self(); |
|
45 | + } |
|
46 | + return self::$_instance; |
|
47 | + } |
|
48 | + |
|
49 | + |
|
50 | + |
|
51 | + /** |
|
52 | + * private class constructor |
|
53 | + */ |
|
54 | + private function __construct() |
|
55 | + { |
|
56 | + // load Kint PHP debugging library |
|
57 | + if (! class_exists('Kint') && file_exists(EE_PLUGIN_DIR_PATH . 'tests' . DS . 'kint' . DS . 'Kint.class.php')) { |
|
58 | + // despite EE4 having a check for an existing copy of the Kint debugging class, |
|
59 | + // if another plugin was loaded AFTER EE4 and they did NOT perform a similar check, |
|
60 | + // then hilarity would ensue as PHP throws a "Cannot redeclare class Kint" error |
|
61 | + // so we've moved it to our test folder so that it is not included with production releases |
|
62 | + // plz use https://wordpress.org/plugins/kint-debugger/ if testing production versions of EE |
|
63 | + require_once(EE_PLUGIN_DIR_PATH . 'tests' . DS . 'kint' . DS . 'Kint.class.php'); |
|
64 | + } |
|
65 | + // if ( ! defined('DOING_AJAX') || $_REQUEST['noheader'] !== 'true' || ! isset( $_REQUEST['noheader'], $_REQUEST['TB_iframe'] ) ) { |
|
66 | + //add_action( 'shutdown', array($this,'espresso_session_footer_dump') ); |
|
67 | + // } |
|
68 | + $plugin = basename(EE_PLUGIN_DIR_PATH); |
|
69 | + add_action("activate_{$plugin}", array('EEH_Debug_Tools', 'ee_plugin_activation_errors')); |
|
70 | + add_action('activated_plugin', array('EEH_Debug_Tools', 'ee_plugin_activation_errors')); |
|
71 | + add_action('shutdown', array('EEH_Debug_Tools', 'show_db_name')); |
|
72 | + } |
|
73 | + |
|
74 | + |
|
75 | + |
|
76 | + /** |
|
77 | + * show_db_name |
|
78 | + * |
|
79 | + * @return void |
|
80 | + */ |
|
81 | + public static function show_db_name() |
|
82 | + { |
|
83 | + if (! defined('DOING_AJAX') && (defined('EE_ERROR_EMAILS') && EE_ERROR_EMAILS)) { |
|
84 | + echo '<p style="font-size:10px;font-weight:normal;color:#E76700;margin: 1em 2em; text-align: right;">DB_NAME: ' |
|
85 | + . DB_NAME |
|
86 | + . '</p>'; |
|
87 | + } |
|
88 | + if (EE_DEBUG) { |
|
89 | + Benchmark::displayResults(); |
|
90 | + } |
|
91 | + } |
|
92 | + |
|
93 | + |
|
94 | + |
|
95 | + /** |
|
96 | + * dump EE_Session object at bottom of page after everything else has happened |
|
97 | + * |
|
98 | + * @return void |
|
99 | + */ |
|
100 | + public function espresso_session_footer_dump() |
|
101 | + { |
|
102 | + if ( |
|
103 | + (defined('WP_DEBUG') && WP_DEBUG) |
|
104 | + && ! defined('DOING_AJAX') |
|
105 | + && class_exists('Kint') |
|
106 | + && function_exists('wp_get_current_user') |
|
107 | + && current_user_can('update_core') |
|
108 | + && class_exists('EE_Registry') |
|
109 | + ) { |
|
110 | + Kint::dump(EE_Registry::instance()->SSN->id()); |
|
111 | + Kint::dump(EE_Registry::instance()->SSN); |
|
112 | + // Kint::dump( EE_Registry::instance()->SSN->get_session_data('cart')->get_tickets() ); |
|
113 | + $this->espresso_list_hooked_functions(); |
|
114 | + Benchmark::displayResults(); |
|
115 | + } |
|
116 | + } |
|
117 | + |
|
118 | + |
|
119 | + |
|
120 | + /** |
|
121 | + * List All Hooked Functions |
|
122 | + * to list all functions for a specific hook, add ee_list_hooks={hook-name} to URL |
|
123 | + * http://wp.smashingmagazine.com/2009/08/18/10-useful-wordpress-hook-hacks/ |
|
124 | + * |
|
125 | + * @param string $tag |
|
126 | + * @return void |
|
127 | + */ |
|
128 | + public function espresso_list_hooked_functions($tag = '') |
|
129 | + { |
|
130 | + global $wp_filter; |
|
131 | + echo '<br/><br/><br/><h3>Hooked Functions</h3>'; |
|
132 | + if ($tag) { |
|
133 | + $hook[$tag] = $wp_filter[$tag]; |
|
134 | + if (! is_array($hook[$tag])) { |
|
135 | + trigger_error("Nothing found for '$tag' hook", E_USER_WARNING); |
|
136 | + return; |
|
137 | + } |
|
138 | + echo '<h5>For Tag: ' . $tag . '</h5>'; |
|
139 | + } else { |
|
140 | + $hook = is_array($wp_filter) ? $wp_filter : array($wp_filter); |
|
141 | + ksort($hook); |
|
142 | + } |
|
143 | + foreach ($hook as $tag_name => $priorities) { |
|
144 | + echo "<br />>>>>>\t<strong>$tag_name</strong><br />"; |
|
145 | + ksort($priorities); |
|
146 | + foreach ($priorities as $priority => $function) { |
|
147 | + echo $priority; |
|
148 | + foreach ($function as $name => $properties) { |
|
149 | + echo "\t$name<br />"; |
|
150 | + } |
|
151 | + } |
|
152 | + } |
|
153 | + } |
|
154 | + |
|
155 | + |
|
156 | + |
|
157 | + /** |
|
158 | + * registered_filter_callbacks |
|
159 | + * |
|
160 | + * @param string $hook_name |
|
161 | + * @return array |
|
162 | + */ |
|
163 | + public static function registered_filter_callbacks($hook_name = '') |
|
164 | + { |
|
165 | + $filters = array(); |
|
166 | + global $wp_filter; |
|
167 | + if (isset($wp_filter[$hook_name])) { |
|
168 | + $filters[$hook_name] = array(); |
|
169 | + foreach ($wp_filter[$hook_name] as $priority => $callbacks) { |
|
170 | + $filters[$hook_name][$priority] = array(); |
|
171 | + foreach ($callbacks as $callback) { |
|
172 | + $filters[$hook_name][$priority][] = $callback['function']; |
|
173 | + } |
|
174 | + } |
|
175 | + } |
|
176 | + return $filters; |
|
177 | + } |
|
178 | + |
|
179 | + |
|
180 | + |
|
181 | + /** |
|
182 | + * captures plugin activation errors for debugging |
|
183 | + * |
|
184 | + * @return void |
|
185 | + * @throws EE_Error |
|
186 | + */ |
|
187 | + public static function ee_plugin_activation_errors() |
|
188 | + { |
|
189 | + if (WP_DEBUG) { |
|
190 | + $activation_errors = ob_get_contents(); |
|
191 | + if (! empty($activation_errors)) { |
|
192 | + $activation_errors = date('Y-m-d H:i:s') . "\n" . $activation_errors; |
|
193 | + } |
|
194 | + espresso_load_required('EEH_File', EE_HELPERS . 'EEH_File.helper.php'); |
|
195 | + if (class_exists('EEH_File')) { |
|
196 | + try { |
|
197 | + EEH_File::ensure_file_exists_and_is_writable( |
|
198 | + EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . 'espresso_plugin_activation_errors.html' |
|
199 | + ); |
|
200 | + EEH_File::write_to_file( |
|
201 | + EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . 'espresso_plugin_activation_errors.html', |
|
202 | + $activation_errors |
|
203 | + ); |
|
204 | + } catch (EE_Error $e) { |
|
205 | + EE_Error::add_error( |
|
206 | + sprintf( |
|
207 | + __( |
|
208 | + 'The Event Espresso activation errors file could not be setup because: %s', |
|
209 | + 'event_espresso' |
|
210 | + ), |
|
211 | + $e->getMessage() |
|
212 | + ), |
|
213 | + __FILE__, __FUNCTION__, __LINE__ |
|
214 | + ); |
|
215 | + } |
|
216 | + } else { |
|
217 | + // old school attempt |
|
218 | + file_put_contents( |
|
219 | + EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . 'espresso_plugin_activation_errors.html', |
|
220 | + $activation_errors |
|
221 | + ); |
|
222 | + } |
|
223 | + $activation_errors = get_option('ee_plugin_activation_errors', '') . $activation_errors; |
|
224 | + update_option('ee_plugin_activation_errors', $activation_errors); |
|
225 | + } |
|
226 | + } |
|
227 | + |
|
228 | + |
|
229 | + |
|
230 | + /** |
|
231 | + * This basically mimics the WordPress _doing_it_wrong() function except adds our own messaging etc. |
|
232 | + * Very useful for providing helpful messages to developers when the method of doing something has been deprecated, |
|
233 | + * or we want to make sure they use something the right way. |
|
234 | + * |
|
235 | + * @access public |
|
236 | + * @param string $function The function that was called |
|
237 | + * @param string $message A message explaining what has been done incorrectly |
|
238 | + * @param string $version The version of Event Espresso where the error was added |
|
239 | + * @param string $applies_when a version string for when you want the doing_it_wrong notice to begin appearing |
|
240 | + * for a deprecated function. This allows deprecation to occur during one version, |
|
241 | + * but not have any notices appear until a later version. This allows developers |
|
242 | + * extra time to update their code before notices appear. |
|
243 | + * @param int $error_type |
|
244 | + * @uses trigger_error() |
|
245 | + */ |
|
246 | + public function doing_it_wrong( |
|
247 | + $function, |
|
248 | + $message, |
|
249 | + $version, |
|
250 | + $applies_when = '', |
|
251 | + $error_type = null |
|
252 | + ) { |
|
253 | + $applies_when = ! empty($applies_when) ? $applies_when : espresso_version(); |
|
254 | + $error_type = $error_type !== null ? $error_type : E_USER_NOTICE; |
|
255 | + // because we swapped the parameter order around for the last two params, |
|
256 | + // let's verify that some third party isn't still passing an error type value for the third param |
|
257 | + if (is_int($applies_when)) { |
|
258 | + $error_type = $applies_when; |
|
259 | + $applies_when = espresso_version(); |
|
260 | + } |
|
261 | + // if not displaying notices yet, then just leave |
|
262 | + if (version_compare(espresso_version(), $applies_when, '<')) { |
|
263 | + return; |
|
264 | + } |
|
265 | + do_action('AHEE__EEH_Debug_Tools__doing_it_wrong_run', $function, $message, $version); |
|
266 | + $version = $version === null |
|
267 | + ? '' |
|
268 | + : sprintf( |
|
269 | + __('(This message was added in version %s of Event Espresso)', 'event_espresso'), |
|
270 | + $version |
|
271 | + ); |
|
272 | + $error_message = sprintf( |
|
273 | + esc_html__('%1$s was called %2$sincorrectly%3$s. %4$s %5$s', 'event_espresso'), |
|
274 | + $function, |
|
275 | + '<strong>', |
|
276 | + '</strong>', |
|
277 | + $message, |
|
278 | + $version |
|
279 | + ); |
|
280 | + // don't trigger error if doing ajax, |
|
281 | + // instead we'll add a transient EE_Error notice that in theory should show on the next request. |
|
282 | + if (defined('DOING_AJAX') && DOING_AJAX) { |
|
283 | + $error_message .= ' ' . esc_html__( |
|
284 | + 'This is a doing_it_wrong message that was triggered during an ajax request. The request params on this request were: ', |
|
285 | + 'event_espresso' |
|
286 | + ); |
|
287 | + $error_message .= '<ul><li>'; |
|
288 | + $error_message .= implode('</li><li>', EE_Registry::instance()->REQ->params()); |
|
289 | + $error_message .= '</ul>'; |
|
290 | + EE_Error::add_error($error_message, 'debug::doing_it_wrong', $function, '42'); |
|
291 | + //now we set this on the transient so it shows up on the next request. |
|
292 | + EE_Error::get_notices(false, true); |
|
293 | + } else { |
|
294 | + trigger_error($error_message, $error_type); |
|
295 | + } |
|
296 | + } |
|
297 | + |
|
298 | + |
|
299 | + |
|
300 | + |
|
301 | + /** |
|
302 | + * Logger helpers |
|
303 | + */ |
|
304 | + /** |
|
305 | + * debug |
|
306 | + * |
|
307 | + * @param string $class |
|
308 | + * @param string $func |
|
309 | + * @param string $line |
|
310 | + * @param array $info |
|
311 | + * @param bool $display_request |
|
312 | + * @param string $debug_index |
|
313 | + * @param string $debug_key |
|
314 | + * @throws EE_Error |
|
315 | + * @throws \EventEspresso\core\exceptions\InvalidSessionDataException |
|
316 | + */ |
|
317 | + public static function log( |
|
318 | + $class = '', |
|
319 | + $func = '', |
|
320 | + $line = '', |
|
321 | + $info = array(), |
|
322 | + $display_request = false, |
|
323 | + $debug_index = '', |
|
324 | + $debug_key = 'EE_DEBUG_SPCO' |
|
325 | + ) { |
|
326 | + if (WP_DEBUG) { |
|
327 | + $debug_key = $debug_key . '_' . EE_Session::instance()->id(); |
|
328 | + $debug_data = get_option($debug_key, array()); |
|
329 | + $default_data = array( |
|
330 | + $class => $func . '() : ' . $line, |
|
331 | + 'REQ' => $display_request ? $_REQUEST : '', |
|
332 | + ); |
|
333 | + // don't serialize objects |
|
334 | + $info = self::strip_objects($info); |
|
335 | + $index = ! empty($debug_index) ? $debug_index : 0; |
|
336 | + if (! isset($debug_data[$index])) { |
|
337 | + $debug_data[$index] = array(); |
|
338 | + } |
|
339 | + $debug_data[$index][microtime()] = array_merge($default_data, $info); |
|
340 | + update_option($debug_key, $debug_data); |
|
341 | + } |
|
342 | + } |
|
343 | + |
|
344 | + |
|
345 | + |
|
346 | + /** |
|
347 | + * strip_objects |
|
348 | + * |
|
349 | + * @param array $info |
|
350 | + * @return array |
|
351 | + */ |
|
352 | + public static function strip_objects($info = array()) |
|
353 | + { |
|
354 | + foreach ($info as $key => $value) { |
|
355 | + if (is_array($value)) { |
|
356 | + $info[$key] = self::strip_objects($value); |
|
357 | + } else if (is_object($value)) { |
|
358 | + $object_class = get_class($value); |
|
359 | + $info[$object_class] = array(); |
|
360 | + $info[$object_class]['ID'] = method_exists($value, 'ID') ? $value->ID() : spl_object_hash($value); |
|
361 | + if (method_exists($value, 'ID')) { |
|
362 | + $info[$object_class]['ID'] = $value->ID(); |
|
363 | + } |
|
364 | + if (method_exists($value, 'status')) { |
|
365 | + $info[$object_class]['status'] = $value->status(); |
|
366 | + } else if (method_exists($value, 'status_ID')) { |
|
367 | + $info[$object_class]['status'] = $value->status_ID(); |
|
368 | + } |
|
369 | + unset($info[$key]); |
|
370 | + } |
|
371 | + } |
|
372 | + return (array)$info; |
|
373 | + } |
|
374 | + |
|
375 | + |
|
376 | + |
|
377 | + /** |
|
378 | + * @param mixed $var |
|
379 | + * @param string $var_name |
|
380 | + * @param string $file |
|
381 | + * @param int|string $line |
|
382 | + * @param int $heading_tag |
|
383 | + * @param bool $die |
|
384 | + * @param string $margin |
|
385 | + */ |
|
386 | + public static function printv( |
|
387 | + $var, |
|
388 | + $var_name = '', |
|
389 | + $file = '', |
|
390 | + $line = '', |
|
391 | + $heading_tag = 5, |
|
392 | + $die = false, |
|
393 | + $margin = '' |
|
394 | + ) { |
|
395 | + $var_name = ! $var_name ? 'string' : $var_name; |
|
396 | + $var_name = ucwords(str_replace('$', '', $var_name)); |
|
397 | + $is_method = method_exists($var_name, $var); |
|
398 | + $var_name = ucwords(str_replace('_', ' ', $var_name)); |
|
399 | + $heading_tag = is_int($heading_tag) ? "h{$heading_tag}" : 'h5'; |
|
400 | + $result = EEH_Debug_Tools::heading($var_name, $heading_tag, $margin); |
|
401 | + $result .= $is_method |
|
402 | + ? EEH_Debug_Tools::grey_span('::') . EEH_Debug_Tools::orange_span($var . '()') |
|
403 | + : EEH_Debug_Tools::grey_span(' : ') . EEH_Debug_Tools::orange_span($var); |
|
404 | + $result .= EEH_Debug_Tools::file_and_line($file, $line); |
|
405 | + $result .= EEH_Debug_Tools::headingX($heading_tag); |
|
406 | + if ($die) { |
|
407 | + die($result); |
|
408 | + } |
|
409 | + echo $result; |
|
410 | + } |
|
411 | + |
|
412 | + |
|
413 | + |
|
414 | + /** |
|
415 | + * @param string $var_name |
|
416 | + * @param string $heading_tag |
|
417 | + * @param string $margin |
|
418 | + * @return string |
|
419 | + */ |
|
420 | + protected static function heading($var_name = '', $heading_tag = 'h5', $margin = '') |
|
421 | + { |
|
422 | + if (defined('EE_TESTS_DIR')) { |
|
423 | + return "\n{$var_name}"; |
|
424 | + } |
|
425 | + $margin = "25px 0 0 {$margin}"; |
|
426 | + return '<' . $heading_tag . ' style="color:#2EA2CC; margin:' . $margin . ';"><b>' . $var_name . '</b>'; |
|
427 | + } |
|
428 | + |
|
429 | + |
|
430 | + |
|
431 | + /** |
|
432 | + * @param string $heading_tag |
|
433 | + * @return string |
|
434 | + */ |
|
435 | + protected static function headingX($heading_tag = 'h5') |
|
436 | + { |
|
437 | + if (defined('EE_TESTS_DIR')) { |
|
438 | + return ''; |
|
439 | + } |
|
440 | + return '</' . $heading_tag . '>'; |
|
441 | + } |
|
442 | + |
|
443 | + |
|
444 | + |
|
445 | + /** |
|
446 | + * @param string $content |
|
447 | + * @return string |
|
448 | + */ |
|
449 | + protected static function grey_span($content = '') |
|
450 | + { |
|
451 | + if (defined('EE_TESTS_DIR')) { |
|
452 | + return $content; |
|
453 | + } |
|
454 | + return '<span style="color:#999">' . $content . '</span>'; |
|
455 | + } |
|
456 | + |
|
457 | + |
|
458 | + |
|
459 | + /** |
|
460 | + * @param string $file |
|
461 | + * @param int $line |
|
462 | + * @return string |
|
463 | + */ |
|
464 | + protected static function file_and_line($file, $line) |
|
465 | + { |
|
466 | + if ($file === '' || $line === '') { |
|
467 | + return ''; |
|
468 | + } |
|
469 | + if (defined('EE_TESTS_DIR')) { |
|
470 | + return "\n (" . $file . ' line no: ' . $line . ' ) '; |
|
471 | + } |
|
472 | + return '<br /><span style="font-size:9px;font-weight:normal;color:#666;line-height: 12px;">' |
|
473 | + . $file |
|
474 | + . '<br />line no: ' |
|
475 | + . $line |
|
476 | + . '</span>'; |
|
477 | + } |
|
478 | + |
|
479 | + |
|
480 | + |
|
481 | + /** |
|
482 | + * @param string $content |
|
483 | + * @return string |
|
484 | + */ |
|
485 | + protected static function orange_span($content = '') |
|
486 | + { |
|
487 | + if (defined('EE_TESTS_DIR')) { |
|
488 | + return $content; |
|
489 | + } |
|
490 | + return '<span style="color:#E76700">' . $content . '</span>'; |
|
491 | + } |
|
492 | + |
|
493 | + |
|
494 | + |
|
495 | + /** |
|
496 | + * @param mixed $var |
|
497 | + * @return string |
|
498 | + */ |
|
499 | + protected static function pre_span($var) |
|
500 | + { |
|
501 | + ob_start(); |
|
502 | + var_dump($var); |
|
503 | + $var = ob_get_clean(); |
|
504 | + if (defined('EE_TESTS_DIR')) { |
|
505 | + return "\n" . $var; |
|
506 | + } |
|
507 | + return '<pre style="color:#999; padding:1em; background: #fff">' . $var . '</pre>'; |
|
508 | + } |
|
509 | + |
|
510 | + |
|
511 | + |
|
512 | + /** |
|
513 | + * @param mixed $var |
|
514 | + * @param string $var_name |
|
515 | + * @param string $file |
|
516 | + * @param int|string $line |
|
517 | + * @param int $heading_tag |
|
518 | + * @param bool $die |
|
519 | + */ |
|
520 | + public static function printr( |
|
521 | + $var, |
|
522 | + $var_name = '', |
|
523 | + $file = '', |
|
524 | + $line = '', |
|
525 | + $heading_tag = 5, |
|
526 | + $die = false |
|
527 | + ) { |
|
528 | + // return; |
|
529 | + $file = str_replace(rtrim(ABSPATH, '\\/'), '', $file); |
|
530 | + $margin = is_admin() ? ' 180px' : '0'; |
|
531 | + //$print_r = false; |
|
532 | + if (is_string($var)) { |
|
533 | + EEH_Debug_Tools::printv($var, $var_name, $file, $line, $heading_tag, $die, $margin); |
|
534 | + return; |
|
535 | + } |
|
536 | + if (is_object($var)) { |
|
537 | + $var_name = ! $var_name ? 'object' : $var_name; |
|
538 | + //$print_r = true; |
|
539 | + } else if (is_array($var)) { |
|
540 | + $var_name = ! $var_name ? 'array' : $var_name; |
|
541 | + //$print_r = true; |
|
542 | + } else if (is_numeric($var)) { |
|
543 | + $var_name = ! $var_name ? 'numeric' : $var_name; |
|
544 | + } else if ($var === null) { |
|
545 | + $var_name = ! $var_name ? 'null' : $var_name; |
|
546 | + } |
|
547 | + $var_name = ucwords(str_replace(array('$', '_'), array('', ' '), $var_name)); |
|
548 | + $heading_tag = is_int($heading_tag) ? "h{$heading_tag}" : 'h5'; |
|
549 | + $result = EEH_Debug_Tools::heading($var_name, $heading_tag, $margin); |
|
550 | + $result .= EEH_Debug_Tools::grey_span(' : ') . EEH_Debug_Tools::orange_span( |
|
551 | + EEH_Debug_Tools::pre_span($var) |
|
552 | + ); |
|
553 | + $result .= EEH_Debug_Tools::file_and_line($file, $line); |
|
554 | + $result .= EEH_Debug_Tools::headingX($heading_tag); |
|
555 | + if ($die) { |
|
556 | + die($result); |
|
557 | + } |
|
558 | + echo $result; |
|
559 | + } |
|
560 | + |
|
561 | + |
|
562 | + |
|
563 | + /******************** deprecated ********************/ |
|
564 | + |
|
565 | + |
|
566 | + |
|
567 | + /** |
|
568 | + * @deprecated 4.9.39.rc.034 |
|
569 | + */ |
|
570 | + public function reset_times() |
|
571 | + { |
|
572 | + Benchmark::resetTimes(); |
|
573 | + } |
|
574 | + |
|
575 | + |
|
576 | + |
|
577 | + /** |
|
578 | + * @deprecated 4.9.39.rc.034 |
|
579 | + * @param null $timer_name |
|
580 | + */ |
|
581 | + public function start_timer($timer_name = null) |
|
582 | + { |
|
583 | + Benchmark::startTimer($timer_name); |
|
584 | + } |
|
585 | + |
|
586 | + |
|
587 | + |
|
588 | + /** |
|
589 | + * @deprecated 4.9.39.rc.034 |
|
590 | + * @param string $timer_name |
|
591 | + */ |
|
592 | + public function stop_timer($timer_name = '') |
|
593 | + { |
|
594 | + Benchmark::stopTimer($timer_name); |
|
595 | + } |
|
596 | + |
|
597 | + |
|
598 | + |
|
599 | + /** |
|
600 | + * @deprecated 4.9.39.rc.034 |
|
601 | + * @param string $label The label to show for this time eg "Start of calling Some_Class::some_function" |
|
602 | + * @param boolean $output_now whether to echo now, or wait until EEH_Debug_Tools::show_times() is called |
|
603 | + * @return void |
|
604 | + */ |
|
605 | + public function measure_memory($label, $output_now = false) |
|
606 | + { |
|
607 | + Benchmark::measureMemory($label, $output_now); |
|
608 | + } |
|
609 | + |
|
610 | + |
|
611 | + |
|
612 | + /** |
|
613 | + * @deprecated 4.9.39.rc.034 |
|
614 | + * @param int $size |
|
615 | + * @return string |
|
616 | + */ |
|
617 | + public function convert($size) |
|
618 | + { |
|
619 | + return Benchmark::convert($size); |
|
620 | + } |
|
621 | + |
|
622 | + |
|
623 | + |
|
624 | + /** |
|
625 | + * @deprecated 4.9.39.rc.034 |
|
626 | + * @param bool $output_now |
|
627 | + * @return string |
|
628 | + */ |
|
629 | + public function show_times($output_now = true) |
|
630 | + { |
|
631 | + return Benchmark::displayResults($output_now); |
|
632 | + } |
|
633 | + |
|
634 | + |
|
635 | + |
|
636 | + /** |
|
637 | + * @deprecated 4.9.39.rc.034 |
|
638 | + * @param string $timer_name |
|
639 | + * @param float $total_time |
|
640 | + * @return string |
|
641 | + */ |
|
642 | + public function format_time($timer_name, $total_time) |
|
643 | + { |
|
644 | + return Benchmark::formatTime($timer_name, $total_time); |
|
645 | + } |
|
646 | 646 | |
647 | 647 | |
648 | 648 | |
@@ -655,31 +655,31 @@ discard block |
||
655 | 655 | * Plugin URI: http://upthemes.com/plugins/kint-debugger/ |
656 | 656 | */ |
657 | 657 | if (class_exists('Kint') && ! function_exists('dump_wp_query')) { |
658 | - function dump_wp_query() |
|
659 | - { |
|
660 | - global $wp_query; |
|
661 | - d($wp_query); |
|
662 | - } |
|
658 | + function dump_wp_query() |
|
659 | + { |
|
660 | + global $wp_query; |
|
661 | + d($wp_query); |
|
662 | + } |
|
663 | 663 | } |
664 | 664 | /** |
665 | 665 | * borrowed from Kint Debugger |
666 | 666 | * Plugin URI: http://upthemes.com/plugins/kint-debugger/ |
667 | 667 | */ |
668 | 668 | if (class_exists('Kint') && ! function_exists('dump_wp')) { |
669 | - function dump_wp() |
|
670 | - { |
|
671 | - global $wp; |
|
672 | - d($wp); |
|
673 | - } |
|
669 | + function dump_wp() |
|
670 | + { |
|
671 | + global $wp; |
|
672 | + d($wp); |
|
673 | + } |
|
674 | 674 | } |
675 | 675 | /** |
676 | 676 | * borrowed from Kint Debugger |
677 | 677 | * Plugin URI: http://upthemes.com/plugins/kint-debugger/ |
678 | 678 | */ |
679 | 679 | if (class_exists('Kint') && ! function_exists('dump_post')) { |
680 | - function dump_post() |
|
681 | - { |
|
682 | - global $post; |
|
683 | - d($post); |
|
684 | - } |
|
680 | + function dump_post() |
|
681 | + { |
|
682 | + global $post; |
|
683 | + d($post); |
|
684 | + } |
|
685 | 685 | } |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php use EventEspresso\core\services\Benchmark; |
2 | 2 | |
3 | -if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
3 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
4 | 4 | exit('No direct script access allowed'); |
5 | 5 | } |
6 | 6 | |
@@ -40,7 +40,7 @@ discard block |
||
40 | 40 | public static function instance() |
41 | 41 | { |
42 | 42 | // check if class object is instantiated, and instantiated properly |
43 | - if (! self::$_instance instanceof EEH_Debug_Tools) { |
|
43 | + if ( ! self::$_instance instanceof EEH_Debug_Tools) { |
|
44 | 44 | self::$_instance = new self(); |
45 | 45 | } |
46 | 46 | return self::$_instance; |
@@ -54,13 +54,13 @@ discard block |
||
54 | 54 | private function __construct() |
55 | 55 | { |
56 | 56 | // load Kint PHP debugging library |
57 | - if (! class_exists('Kint') && file_exists(EE_PLUGIN_DIR_PATH . 'tests' . DS . 'kint' . DS . 'Kint.class.php')) { |
|
57 | + if ( ! class_exists('Kint') && file_exists(EE_PLUGIN_DIR_PATH.'tests'.DS.'kint'.DS.'Kint.class.php')) { |
|
58 | 58 | // despite EE4 having a check for an existing copy of the Kint debugging class, |
59 | 59 | // if another plugin was loaded AFTER EE4 and they did NOT perform a similar check, |
60 | 60 | // then hilarity would ensue as PHP throws a "Cannot redeclare class Kint" error |
61 | 61 | // so we've moved it to our test folder so that it is not included with production releases |
62 | 62 | // plz use https://wordpress.org/plugins/kint-debugger/ if testing production versions of EE |
63 | - require_once(EE_PLUGIN_DIR_PATH . 'tests' . DS . 'kint' . DS . 'Kint.class.php'); |
|
63 | + require_once(EE_PLUGIN_DIR_PATH.'tests'.DS.'kint'.DS.'Kint.class.php'); |
|
64 | 64 | } |
65 | 65 | // if ( ! defined('DOING_AJAX') || $_REQUEST['noheader'] !== 'true' || ! isset( $_REQUEST['noheader'], $_REQUEST['TB_iframe'] ) ) { |
66 | 66 | //add_action( 'shutdown', array($this,'espresso_session_footer_dump') ); |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | */ |
81 | 81 | public static function show_db_name() |
82 | 82 | { |
83 | - if (! defined('DOING_AJAX') && (defined('EE_ERROR_EMAILS') && EE_ERROR_EMAILS)) { |
|
83 | + if ( ! defined('DOING_AJAX') && (defined('EE_ERROR_EMAILS') && EE_ERROR_EMAILS)) { |
|
84 | 84 | echo '<p style="font-size:10px;font-weight:normal;color:#E76700;margin: 1em 2em; text-align: right;">DB_NAME: ' |
85 | 85 | . DB_NAME |
86 | 86 | . '</p>'; |
@@ -131,11 +131,11 @@ discard block |
||
131 | 131 | echo '<br/><br/><br/><h3>Hooked Functions</h3>'; |
132 | 132 | if ($tag) { |
133 | 133 | $hook[$tag] = $wp_filter[$tag]; |
134 | - if (! is_array($hook[$tag])) { |
|
134 | + if ( ! is_array($hook[$tag])) { |
|
135 | 135 | trigger_error("Nothing found for '$tag' hook", E_USER_WARNING); |
136 | 136 | return; |
137 | 137 | } |
138 | - echo '<h5>For Tag: ' . $tag . '</h5>'; |
|
138 | + echo '<h5>For Tag: '.$tag.'</h5>'; |
|
139 | 139 | } else { |
140 | 140 | $hook = is_array($wp_filter) ? $wp_filter : array($wp_filter); |
141 | 141 | ksort($hook); |
@@ -188,17 +188,17 @@ discard block |
||
188 | 188 | { |
189 | 189 | if (WP_DEBUG) { |
190 | 190 | $activation_errors = ob_get_contents(); |
191 | - if (! empty($activation_errors)) { |
|
192 | - $activation_errors = date('Y-m-d H:i:s') . "\n" . $activation_errors; |
|
191 | + if ( ! empty($activation_errors)) { |
|
192 | + $activation_errors = date('Y-m-d H:i:s')."\n".$activation_errors; |
|
193 | 193 | } |
194 | - espresso_load_required('EEH_File', EE_HELPERS . 'EEH_File.helper.php'); |
|
194 | + espresso_load_required('EEH_File', EE_HELPERS.'EEH_File.helper.php'); |
|
195 | 195 | if (class_exists('EEH_File')) { |
196 | 196 | try { |
197 | 197 | EEH_File::ensure_file_exists_and_is_writable( |
198 | - EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . 'espresso_plugin_activation_errors.html' |
|
198 | + EVENT_ESPRESSO_UPLOAD_DIR.'logs'.DS.'espresso_plugin_activation_errors.html' |
|
199 | 199 | ); |
200 | 200 | EEH_File::write_to_file( |
201 | - EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . 'espresso_plugin_activation_errors.html', |
|
201 | + EVENT_ESPRESSO_UPLOAD_DIR.'logs'.DS.'espresso_plugin_activation_errors.html', |
|
202 | 202 | $activation_errors |
203 | 203 | ); |
204 | 204 | } catch (EE_Error $e) { |
@@ -216,11 +216,11 @@ discard block |
||
216 | 216 | } else { |
217 | 217 | // old school attempt |
218 | 218 | file_put_contents( |
219 | - EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . 'espresso_plugin_activation_errors.html', |
|
219 | + EVENT_ESPRESSO_UPLOAD_DIR.'logs'.DS.'espresso_plugin_activation_errors.html', |
|
220 | 220 | $activation_errors |
221 | 221 | ); |
222 | 222 | } |
223 | - $activation_errors = get_option('ee_plugin_activation_errors', '') . $activation_errors; |
|
223 | + $activation_errors = get_option('ee_plugin_activation_errors', '').$activation_errors; |
|
224 | 224 | update_option('ee_plugin_activation_errors', $activation_errors); |
225 | 225 | } |
226 | 226 | } |
@@ -280,7 +280,7 @@ discard block |
||
280 | 280 | // don't trigger error if doing ajax, |
281 | 281 | // instead we'll add a transient EE_Error notice that in theory should show on the next request. |
282 | 282 | if (defined('DOING_AJAX') && DOING_AJAX) { |
283 | - $error_message .= ' ' . esc_html__( |
|
283 | + $error_message .= ' '.esc_html__( |
|
284 | 284 | 'This is a doing_it_wrong message that was triggered during an ajax request. The request params on this request were: ', |
285 | 285 | 'event_espresso' |
286 | 286 | ); |
@@ -324,16 +324,16 @@ discard block |
||
324 | 324 | $debug_key = 'EE_DEBUG_SPCO' |
325 | 325 | ) { |
326 | 326 | if (WP_DEBUG) { |
327 | - $debug_key = $debug_key . '_' . EE_Session::instance()->id(); |
|
327 | + $debug_key = $debug_key.'_'.EE_Session::instance()->id(); |
|
328 | 328 | $debug_data = get_option($debug_key, array()); |
329 | 329 | $default_data = array( |
330 | - $class => $func . '() : ' . $line, |
|
330 | + $class => $func.'() : '.$line, |
|
331 | 331 | 'REQ' => $display_request ? $_REQUEST : '', |
332 | 332 | ); |
333 | 333 | // don't serialize objects |
334 | 334 | $info = self::strip_objects($info); |
335 | 335 | $index = ! empty($debug_index) ? $debug_index : 0; |
336 | - if (! isset($debug_data[$index])) { |
|
336 | + if ( ! isset($debug_data[$index])) { |
|
337 | 337 | $debug_data[$index] = array(); |
338 | 338 | } |
339 | 339 | $debug_data[$index][microtime()] = array_merge($default_data, $info); |
@@ -369,7 +369,7 @@ discard block |
||
369 | 369 | unset($info[$key]); |
370 | 370 | } |
371 | 371 | } |
372 | - return (array)$info; |
|
372 | + return (array) $info; |
|
373 | 373 | } |
374 | 374 | |
375 | 375 | |
@@ -399,8 +399,8 @@ discard block |
||
399 | 399 | $heading_tag = is_int($heading_tag) ? "h{$heading_tag}" : 'h5'; |
400 | 400 | $result = EEH_Debug_Tools::heading($var_name, $heading_tag, $margin); |
401 | 401 | $result .= $is_method |
402 | - ? EEH_Debug_Tools::grey_span('::') . EEH_Debug_Tools::orange_span($var . '()') |
|
403 | - : EEH_Debug_Tools::grey_span(' : ') . EEH_Debug_Tools::orange_span($var); |
|
402 | + ? EEH_Debug_Tools::grey_span('::').EEH_Debug_Tools::orange_span($var.'()') |
|
403 | + : EEH_Debug_Tools::grey_span(' : ').EEH_Debug_Tools::orange_span($var); |
|
404 | 404 | $result .= EEH_Debug_Tools::file_and_line($file, $line); |
405 | 405 | $result .= EEH_Debug_Tools::headingX($heading_tag); |
406 | 406 | if ($die) { |
@@ -423,7 +423,7 @@ discard block |
||
423 | 423 | return "\n{$var_name}"; |
424 | 424 | } |
425 | 425 | $margin = "25px 0 0 {$margin}"; |
426 | - return '<' . $heading_tag . ' style="color:#2EA2CC; margin:' . $margin . ';"><b>' . $var_name . '</b>'; |
|
426 | + return '<'.$heading_tag.' style="color:#2EA2CC; margin:'.$margin.';"><b>'.$var_name.'</b>'; |
|
427 | 427 | } |
428 | 428 | |
429 | 429 | |
@@ -437,7 +437,7 @@ discard block |
||
437 | 437 | if (defined('EE_TESTS_DIR')) { |
438 | 438 | return ''; |
439 | 439 | } |
440 | - return '</' . $heading_tag . '>'; |
|
440 | + return '</'.$heading_tag.'>'; |
|
441 | 441 | } |
442 | 442 | |
443 | 443 | |
@@ -451,7 +451,7 @@ discard block |
||
451 | 451 | if (defined('EE_TESTS_DIR')) { |
452 | 452 | return $content; |
453 | 453 | } |
454 | - return '<span style="color:#999">' . $content . '</span>'; |
|
454 | + return '<span style="color:#999">'.$content.'</span>'; |
|
455 | 455 | } |
456 | 456 | |
457 | 457 | |
@@ -467,7 +467,7 @@ discard block |
||
467 | 467 | return ''; |
468 | 468 | } |
469 | 469 | if (defined('EE_TESTS_DIR')) { |
470 | - return "\n (" . $file . ' line no: ' . $line . ' ) '; |
|
470 | + return "\n (".$file.' line no: '.$line.' ) '; |
|
471 | 471 | } |
472 | 472 | return '<br /><span style="font-size:9px;font-weight:normal;color:#666;line-height: 12px;">' |
473 | 473 | . $file |
@@ -487,7 +487,7 @@ discard block |
||
487 | 487 | if (defined('EE_TESTS_DIR')) { |
488 | 488 | return $content; |
489 | 489 | } |
490 | - return '<span style="color:#E76700">' . $content . '</span>'; |
|
490 | + return '<span style="color:#E76700">'.$content.'</span>'; |
|
491 | 491 | } |
492 | 492 | |
493 | 493 | |
@@ -502,9 +502,9 @@ discard block |
||
502 | 502 | var_dump($var); |
503 | 503 | $var = ob_get_clean(); |
504 | 504 | if (defined('EE_TESTS_DIR')) { |
505 | - return "\n" . $var; |
|
505 | + return "\n".$var; |
|
506 | 506 | } |
507 | - return '<pre style="color:#999; padding:1em; background: #fff">' . $var . '</pre>'; |
|
507 | + return '<pre style="color:#999; padding:1em; background: #fff">'.$var.'</pre>'; |
|
508 | 508 | } |
509 | 509 | |
510 | 510 | |
@@ -547,7 +547,7 @@ discard block |
||
547 | 547 | $var_name = ucwords(str_replace(array('$', '_'), array('', ' '), $var_name)); |
548 | 548 | $heading_tag = is_int($heading_tag) ? "h{$heading_tag}" : 'h5'; |
549 | 549 | $result = EEH_Debug_Tools::heading($var_name, $heading_tag, $margin); |
550 | - $result .= EEH_Debug_Tools::grey_span(' : ') . EEH_Debug_Tools::orange_span( |
|
550 | + $result .= EEH_Debug_Tools::grey_span(' : ').EEH_Debug_Tools::orange_span( |
|
551 | 551 | EEH_Debug_Tools::pre_span($var) |
552 | 552 | ); |
553 | 553 | $result .= EEH_Debug_Tools::file_and_line($file, $line); |
@@ -14,121 +14,121 @@ |
||
14 | 14 | abstract class EED_Module extends EE_Configurable implements ResettableInterface |
15 | 15 | { |
16 | 16 | |
17 | - /** |
|
18 | - * rendered output to be returned to WP |
|
19 | - * |
|
20 | - * @var string $output |
|
21 | - */ |
|
22 | - protected $output = ''; |
|
23 | - |
|
24 | - /** |
|
25 | - * the current active espresso template theme |
|
26 | - * |
|
27 | - * @var string $theme |
|
28 | - */ |
|
29 | - protected $theme = ''; |
|
30 | - |
|
31 | - |
|
32 | - |
|
33 | - /** |
|
34 | - * @return void |
|
35 | - */ |
|
36 | - public static function reset() |
|
37 | - { |
|
38 | - $module_name = get_called_class(); |
|
39 | - new $module_name(); |
|
40 | - } |
|
41 | - |
|
42 | - |
|
43 | - |
|
44 | - /** |
|
45 | - * set_hooks - for hooking into EE Core, other modules, etc |
|
46 | - * |
|
47 | - * @access public |
|
48 | - * @return void |
|
49 | - */ |
|
50 | - public static function set_hooks() |
|
51 | - { |
|
52 | - } |
|
53 | - |
|
54 | - |
|
55 | - |
|
56 | - /** |
|
57 | - * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
58 | - * |
|
59 | - * @access public |
|
60 | - * @return void |
|
61 | - */ |
|
62 | - public static function set_hooks_admin() |
|
63 | - { |
|
64 | - } |
|
65 | - |
|
66 | - |
|
67 | - |
|
68 | - /** |
|
69 | - * run - initial module setup |
|
70 | - * this method is primarily used for activating resources in the EE_Front_Controller thru the use of filters |
|
71 | - * |
|
72 | - * @access public |
|
73 | - * @var WP $WP |
|
74 | - * @return void |
|
75 | - */ |
|
76 | - abstract public function run($WP); |
|
77 | - |
|
78 | - |
|
79 | - |
|
80 | - /** |
|
81 | - * EED_Module constructor. |
|
82 | - */ |
|
83 | - final public function __construct() |
|
84 | - { |
|
85 | - $this->theme = EE_Config::get_current_theme(); |
|
86 | - $module_name = $this->module_name(); |
|
87 | - EE_Registry::instance()->modules->{$module_name} = $this; |
|
88 | - } |
|
89 | - |
|
90 | - |
|
91 | - |
|
92 | - /** |
|
93 | - * @param $module_name |
|
94 | - * @return EED_Module |
|
95 | - */ |
|
96 | - protected static function get_instance($module_name = '') |
|
97 | - { |
|
98 | - $module_name = ! empty($module_name) |
|
99 | - ? $module_name |
|
100 | - : get_called_class(); |
|
101 | - if ( |
|
102 | - ! isset(EE_Registry::instance()->modules->{$module_name}) |
|
103 | - || ! EE_Registry::instance()->modules->{$module_name} instanceof EED_Module |
|
104 | - ) { |
|
105 | - EE_Registry::instance()->add_module($module_name); |
|
106 | - } |
|
107 | - return EE_Registry::instance()->get_module($module_name); |
|
108 | - } |
|
109 | - |
|
110 | - |
|
111 | - |
|
112 | - /** |
|
113 | - * module_name |
|
114 | - * |
|
115 | - * @access public |
|
116 | - * @return string |
|
117 | - */ |
|
118 | - public function module_name() |
|
119 | - { |
|
120 | - return get_class($this); |
|
121 | - } |
|
122 | - |
|
123 | - |
|
124 | - |
|
125 | - /** |
|
126 | - * @return string |
|
127 | - */ |
|
128 | - public function theme() |
|
129 | - { |
|
130 | - return $this->theme; |
|
131 | - } |
|
17 | + /** |
|
18 | + * rendered output to be returned to WP |
|
19 | + * |
|
20 | + * @var string $output |
|
21 | + */ |
|
22 | + protected $output = ''; |
|
23 | + |
|
24 | + /** |
|
25 | + * the current active espresso template theme |
|
26 | + * |
|
27 | + * @var string $theme |
|
28 | + */ |
|
29 | + protected $theme = ''; |
|
30 | + |
|
31 | + |
|
32 | + |
|
33 | + /** |
|
34 | + * @return void |
|
35 | + */ |
|
36 | + public static function reset() |
|
37 | + { |
|
38 | + $module_name = get_called_class(); |
|
39 | + new $module_name(); |
|
40 | + } |
|
41 | + |
|
42 | + |
|
43 | + |
|
44 | + /** |
|
45 | + * set_hooks - for hooking into EE Core, other modules, etc |
|
46 | + * |
|
47 | + * @access public |
|
48 | + * @return void |
|
49 | + */ |
|
50 | + public static function set_hooks() |
|
51 | + { |
|
52 | + } |
|
53 | + |
|
54 | + |
|
55 | + |
|
56 | + /** |
|
57 | + * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
58 | + * |
|
59 | + * @access public |
|
60 | + * @return void |
|
61 | + */ |
|
62 | + public static function set_hooks_admin() |
|
63 | + { |
|
64 | + } |
|
65 | + |
|
66 | + |
|
67 | + |
|
68 | + /** |
|
69 | + * run - initial module setup |
|
70 | + * this method is primarily used for activating resources in the EE_Front_Controller thru the use of filters |
|
71 | + * |
|
72 | + * @access public |
|
73 | + * @var WP $WP |
|
74 | + * @return void |
|
75 | + */ |
|
76 | + abstract public function run($WP); |
|
77 | + |
|
78 | + |
|
79 | + |
|
80 | + /** |
|
81 | + * EED_Module constructor. |
|
82 | + */ |
|
83 | + final public function __construct() |
|
84 | + { |
|
85 | + $this->theme = EE_Config::get_current_theme(); |
|
86 | + $module_name = $this->module_name(); |
|
87 | + EE_Registry::instance()->modules->{$module_name} = $this; |
|
88 | + } |
|
89 | + |
|
90 | + |
|
91 | + |
|
92 | + /** |
|
93 | + * @param $module_name |
|
94 | + * @return EED_Module |
|
95 | + */ |
|
96 | + protected static function get_instance($module_name = '') |
|
97 | + { |
|
98 | + $module_name = ! empty($module_name) |
|
99 | + ? $module_name |
|
100 | + : get_called_class(); |
|
101 | + if ( |
|
102 | + ! isset(EE_Registry::instance()->modules->{$module_name}) |
|
103 | + || ! EE_Registry::instance()->modules->{$module_name} instanceof EED_Module |
|
104 | + ) { |
|
105 | + EE_Registry::instance()->add_module($module_name); |
|
106 | + } |
|
107 | + return EE_Registry::instance()->get_module($module_name); |
|
108 | + } |
|
109 | + |
|
110 | + |
|
111 | + |
|
112 | + /** |
|
113 | + * module_name |
|
114 | + * |
|
115 | + * @access public |
|
116 | + * @return string |
|
117 | + */ |
|
118 | + public function module_name() |
|
119 | + { |
|
120 | + return get_class($this); |
|
121 | + } |
|
122 | + |
|
123 | + |
|
124 | + |
|
125 | + /** |
|
126 | + * @return string |
|
127 | + */ |
|
128 | + public function theme() |
|
129 | + { |
|
130 | + return $this->theme; |
|
131 | + } |
|
132 | 132 | |
133 | 133 | |
134 | 134 |
@@ -297,13 +297,13 @@ discard block |
||
297 | 297 | */ |
298 | 298 | public static function localize_i18n_js_strings() |
299 | 299 | { |
300 | - $i18n_js_strings = (array)EE_Registry::$i18n_js_strings; |
|
300 | + $i18n_js_strings = (array) EE_Registry::$i18n_js_strings; |
|
301 | 301 | foreach ($i18n_js_strings as $key => $value) { |
302 | 302 | if (is_scalar($value)) { |
303 | - $i18n_js_strings[$key] = html_entity_decode((string)$value, ENT_QUOTES, 'UTF-8'); |
|
303 | + $i18n_js_strings[$key] = html_entity_decode((string) $value, ENT_QUOTES, 'UTF-8'); |
|
304 | 304 | } |
305 | 305 | } |
306 | - return "/* <![CDATA[ */ var eei18n = " . wp_json_encode($i18n_js_strings) . '; /* ]]> */'; |
|
306 | + return "/* <![CDATA[ */ var eei18n = ".wp_json_encode($i18n_js_strings).'; /* ]]> */'; |
|
307 | 307 | } |
308 | 308 | |
309 | 309 | |
@@ -354,9 +354,9 @@ discard block |
||
354 | 354 | EE_CORE, |
355 | 355 | EE_ADMIN, |
356 | 356 | EE_CPTS, |
357 | - EE_CORE . 'data_migration_scripts' . DS, |
|
358 | - EE_CORE . 'request_stack' . DS, |
|
359 | - EE_CORE . 'middleware' . DS, |
|
357 | + EE_CORE.'data_migration_scripts'.DS, |
|
358 | + EE_CORE.'request_stack'.DS, |
|
359 | + EE_CORE.'middleware'.DS, |
|
360 | 360 | ) |
361 | 361 | ); |
362 | 362 | // retrieve instantiated class |
@@ -379,7 +379,7 @@ discard block |
||
379 | 379 | $service_paths = apply_filters( |
380 | 380 | 'FHEE__EE_Registry__load_service__service_paths', |
381 | 381 | array( |
382 | - EE_CORE . 'services' . DS, |
|
382 | + EE_CORE.'services'.DS, |
|
383 | 383 | ) |
384 | 384 | ); |
385 | 385 | // retrieve instantiated class |
@@ -459,10 +459,10 @@ discard block |
||
459 | 459 | { |
460 | 460 | $paths = array( |
461 | 461 | EE_LIBRARIES, |
462 | - EE_LIBRARIES . 'messages' . DS, |
|
463 | - EE_LIBRARIES . 'shortcodes' . DS, |
|
464 | - EE_LIBRARIES . 'qtips' . DS, |
|
465 | - EE_LIBRARIES . 'payment_methods' . DS, |
|
462 | + EE_LIBRARIES.'messages'.DS, |
|
463 | + EE_LIBRARIES.'shortcodes'.DS, |
|
464 | + EE_LIBRARIES.'qtips'.DS, |
|
465 | + EE_LIBRARIES.'payment_methods'.DS, |
|
466 | 466 | ); |
467 | 467 | // retrieve instantiated class |
468 | 468 | return $this->_load($paths, 'EE_', $class_name, 'lib', $arguments, false, $cache, $load_only); |
@@ -501,10 +501,10 @@ discard block |
||
501 | 501 | public function load_model_class($class_name, $arguments = array(), $load_only = true) |
502 | 502 | { |
503 | 503 | $paths = array( |
504 | - EE_MODELS . 'fields' . DS, |
|
505 | - EE_MODELS . 'helpers' . DS, |
|
506 | - EE_MODELS . 'relations' . DS, |
|
507 | - EE_MODELS . 'strategies' . DS, |
|
504 | + EE_MODELS.'fields'.DS, |
|
505 | + EE_MODELS.'helpers'.DS, |
|
506 | + EE_MODELS.'relations'.DS, |
|
507 | + EE_MODELS.'strategies'.DS, |
|
508 | 508 | ); |
509 | 509 | // retrieve instantiated class |
510 | 510 | return $this->_load($paths, 'EE_', $class_name, '', $arguments, false, true, $load_only); |
@@ -591,7 +591,7 @@ discard block |
||
591 | 591 | $class_name = $this->_dependency_map->get_alias($class_name); |
592 | 592 | if ( ! class_exists($class_name)) { |
593 | 593 | // maybe the class is registered with a preceding \ |
594 | - $class_name = strpos($class_name, '\\') !== 0 ? '\\' . $class_name : $class_name; |
|
594 | + $class_name = strpos($class_name, '\\') !== 0 ? '\\'.$class_name : $class_name; |
|
595 | 595 | // still doesn't exist ? |
596 | 596 | if ( ! class_exists($class_name)) { |
597 | 597 | return null; |
@@ -658,7 +658,7 @@ discard block |
||
658 | 658 | // make sure $class_prefix is uppercase |
659 | 659 | $class_prefix = strtoupper(trim($class_prefix)); |
660 | 660 | // add class prefix ONCE!!! |
661 | - $class_name = $class_prefix . str_replace($class_prefix, '', $class_name); |
|
661 | + $class_name = $class_prefix.str_replace($class_prefix, '', $class_name); |
|
662 | 662 | } |
663 | 663 | $class_name = $this->_dependency_map->get_alias($class_name); |
664 | 664 | $class_exists = class_exists($class_name); |
@@ -721,8 +721,8 @@ discard block |
||
721 | 721 | return $this; |
722 | 722 | } |
723 | 723 | // have to specify something, but not anything that will conflict |
724 | - $class_abbreviation = isset($this->_class_abbreviations[ $class_name ]) |
|
725 | - ? $this->_class_abbreviations[ $class_name ] |
|
724 | + $class_abbreviation = isset($this->_class_abbreviations[$class_name]) |
|
725 | + ? $this->_class_abbreviations[$class_name] |
|
726 | 726 | : 'FANCY_BATMAN_PANTS'; |
727 | 727 | $class_name = str_replace('\\', '_', $class_name); |
728 | 728 | // check if class has already been loaded, and return it if it has been |
@@ -753,8 +753,8 @@ discard block |
||
753 | 753 | public function clear_cached_class($class_name, $addon = false) |
754 | 754 | { |
755 | 755 | // have to specify something, but not anything that will conflict |
756 | - $class_abbreviation = isset($this->_class_abbreviations[ $class_name ]) |
|
757 | - ? $this->_class_abbreviations[ $class_name ] |
|
756 | + $class_abbreviation = isset($this->_class_abbreviations[$class_name]) |
|
757 | + ? $this->_class_abbreviations[$class_name] |
|
758 | 758 | : 'FANCY_BATMAN_PANTS'; |
759 | 759 | $class_name = str_replace('\\', '_', $class_name); |
760 | 760 | // check if class has already been loaded, and return it if it has been |
@@ -799,9 +799,9 @@ discard block |
||
799 | 799 | // convert all separators to proper DS, if no filepath, then use EE_CLASSES |
800 | 800 | $file_path = $file_path ? str_replace(array('/', '\\'), DS, $file_path) : EE_CLASSES; |
801 | 801 | // prep file type |
802 | - $type = ! empty($type) ? trim($type, '.') . '.' : ''; |
|
802 | + $type = ! empty($type) ? trim($type, '.').'.' : ''; |
|
803 | 803 | // build full file path |
804 | - $file_paths[$key] = rtrim($file_path, DS) . DS . $class_name . '.' . $type . 'php'; |
|
804 | + $file_paths[$key] = rtrim($file_path, DS).DS.$class_name.'.'.$type.'php'; |
|
805 | 805 | //does the file exist and can be read ? |
806 | 806 | if (is_readable($file_paths[$key])) { |
807 | 807 | return $file_paths[$key]; |
@@ -832,12 +832,12 @@ discard block |
||
832 | 832 | //does the file exist and can it be read ? |
833 | 833 | if ( ! $path) { |
834 | 834 | // so sorry, can't find the file |
835 | - throw new EE_Error ( |
|
835 | + throw new EE_Error( |
|
836 | 836 | sprintf( |
837 | 837 | __('The %1$s file %2$s could not be located or is not readable due to file permissions. Please ensure that the following filepath(s) are correct: %3$s', 'event_espresso'), |
838 | 838 | trim($type, '.'), |
839 | 839 | $class_name, |
840 | - '<br />' . implode(',<br />', $file_paths) |
|
840 | + '<br />'.implode(',<br />', $file_paths) |
|
841 | 841 | ) |
842 | 842 | ); |
843 | 843 | } |
@@ -1318,7 +1318,7 @@ discard block |
||
1318 | 1318 | */ |
1319 | 1319 | private static function _reset_and_unset_object($object, $reset_models) |
1320 | 1320 | { |
1321 | - if (! is_object($object)) { |
|
1321 | + if ( ! is_object($object)) { |
|
1322 | 1322 | // don't unset anything that's not an object |
1323 | 1323 | return false; |
1324 | 1324 | } |
@@ -309,7 +309,7 @@ |
||
309 | 309 | |
310 | 310 | |
311 | 311 | /** |
312 | - * @param $module |
|
312 | + * @param string $module |
|
313 | 313 | * @throws ReflectionException |
314 | 314 | */ |
315 | 315 | public function add_module($module) |
@@ -19,1471 +19,1471 @@ |
||
19 | 19 | class EE_Registry implements ResettableInterface |
20 | 20 | { |
21 | 21 | |
22 | - /** |
|
23 | - * EE_Registry Object |
|
24 | - * |
|
25 | - * @var EE_Registry $_instance |
|
26 | - * @access private |
|
27 | - */ |
|
28 | - private static $_instance = null; |
|
29 | - |
|
30 | - /** |
|
31 | - * @var EE_Dependency_Map $_dependency_map |
|
32 | - * @access protected |
|
33 | - */ |
|
34 | - protected $_dependency_map = null; |
|
35 | - |
|
36 | - /** |
|
37 | - * @var array $_class_abbreviations |
|
38 | - * @access protected |
|
39 | - */ |
|
40 | - protected $_class_abbreviations = array(); |
|
41 | - |
|
42 | - /** |
|
43 | - * @access public |
|
44 | - * @var \EventEspresso\core\services\commands\CommandBusInterface $BUS |
|
45 | - */ |
|
46 | - public $BUS; |
|
47 | - |
|
48 | - /** |
|
49 | - * EE_Cart Object |
|
50 | - * |
|
51 | - * @access public |
|
52 | - * @var EE_Cart $CART |
|
53 | - */ |
|
54 | - public $CART = null; |
|
55 | - |
|
56 | - /** |
|
57 | - * EE_Config Object |
|
58 | - * |
|
59 | - * @access public |
|
60 | - * @var EE_Config $CFG |
|
61 | - */ |
|
62 | - public $CFG = null; |
|
63 | - |
|
64 | - /** |
|
65 | - * EE_Network_Config Object |
|
66 | - * |
|
67 | - * @access public |
|
68 | - * @var EE_Network_Config $NET_CFG |
|
69 | - */ |
|
70 | - public $NET_CFG = null; |
|
71 | - |
|
72 | - /** |
|
73 | - * StdClass object for storing library classes in |
|
74 | - * |
|
75 | - * @public LIB |
|
76 | - * @var StdClass $LIB |
|
77 | - */ |
|
78 | - public $LIB = null; |
|
79 | - |
|
80 | - /** |
|
81 | - * EE_Request_Handler Object |
|
82 | - * |
|
83 | - * @access public |
|
84 | - * @var EE_Request_Handler $REQ |
|
85 | - */ |
|
86 | - public $REQ = null; |
|
87 | - |
|
88 | - /** |
|
89 | - * EE_Session Object |
|
90 | - * |
|
91 | - * @access public |
|
92 | - * @var EE_Session $SSN |
|
93 | - */ |
|
94 | - public $SSN = null; |
|
95 | - |
|
96 | - /** |
|
97 | - * holds the ee capabilities object. |
|
98 | - * |
|
99 | - * @since 4.5.0 |
|
100 | - * @var EE_Capabilities |
|
101 | - */ |
|
102 | - public $CAP = null; |
|
103 | - |
|
104 | - /** |
|
105 | - * holds the EE_Message_Resource_Manager object. |
|
106 | - * |
|
107 | - * @since 4.9.0 |
|
108 | - * @var EE_Message_Resource_Manager |
|
109 | - */ |
|
110 | - public $MRM = null; |
|
111 | - |
|
112 | - |
|
113 | - /** |
|
114 | - * Holds the Assets Registry instance |
|
115 | - * @var Registry |
|
116 | - */ |
|
117 | - public $AssetsRegistry = null; |
|
118 | - |
|
119 | - /** |
|
120 | - * $addons - StdClass object for holding addons which have registered themselves to work with EE core |
|
121 | - * |
|
122 | - * @access public |
|
123 | - * @var EE_Addon[] |
|
124 | - */ |
|
125 | - public $addons = null; |
|
126 | - |
|
127 | - /** |
|
128 | - * $models |
|
129 | - * @access public |
|
130 | - * @var EEM_Base[] $models keys are 'short names' (eg Event), values are class names (eg 'EEM_Event') |
|
131 | - */ |
|
132 | - public $models = array(); |
|
133 | - |
|
134 | - /** |
|
135 | - * $modules |
|
136 | - * @access public |
|
137 | - * @var EED_Module[] $modules |
|
138 | - */ |
|
139 | - public $modules = null; |
|
140 | - |
|
141 | - /** |
|
142 | - * $shortcodes |
|
143 | - * @access public |
|
144 | - * @var EES_Shortcode[] $shortcodes |
|
145 | - */ |
|
146 | - public $shortcodes = null; |
|
147 | - |
|
148 | - /** |
|
149 | - * $widgets |
|
150 | - * @access public |
|
151 | - * @var WP_Widget[] $widgets |
|
152 | - */ |
|
153 | - public $widgets = null; |
|
154 | - |
|
155 | - /** |
|
156 | - * $non_abstract_db_models |
|
157 | - * @access public |
|
158 | - * @var array this is an array of all implemented model names (i.e. not the parent abstract models, or models |
|
159 | - * which don't actually fetch items from the DB in the normal way (ie, are not children of EEM_Base)). |
|
160 | - * Keys are model "short names" (eg "Event") as used in model relations, and values are |
|
161 | - * classnames (eg "EEM_Event") |
|
162 | - */ |
|
163 | - public $non_abstract_db_models = array(); |
|
164 | - |
|
165 | - |
|
166 | - /** |
|
167 | - * $i18n_js_strings - internationalization for JS strings |
|
168 | - * usage: EE_Registry::i18n_js_strings['string_key'] = __( 'string to translate.', 'event_espresso' ); |
|
169 | - * in js file: var translatedString = eei18n.string_key; |
|
170 | - * |
|
171 | - * @access public |
|
172 | - * @var array |
|
173 | - */ |
|
174 | - public static $i18n_js_strings = array(); |
|
175 | - |
|
176 | - |
|
177 | - /** |
|
178 | - * $main_file - path to espresso.php |
|
179 | - * |
|
180 | - * @access public |
|
181 | - * @var array |
|
182 | - */ |
|
183 | - public $main_file; |
|
184 | - |
|
185 | - /** |
|
186 | - * array of ReflectionClass objects where the key is the class name |
|
187 | - * |
|
188 | - * @access public |
|
189 | - * @var ReflectionClass[] |
|
190 | - */ |
|
191 | - public $_reflectors; |
|
192 | - |
|
193 | - /** |
|
194 | - * boolean flag to indicate whether or not to load/save dependencies from/to the cache |
|
195 | - * |
|
196 | - * @access protected |
|
197 | - * @var boolean $_cache_on |
|
198 | - */ |
|
199 | - protected $_cache_on = true; |
|
200 | - |
|
201 | - |
|
202 | - |
|
203 | - /** |
|
204 | - * @singleton method used to instantiate class object |
|
205 | - * @access public |
|
206 | - * @param \EE_Dependency_Map $dependency_map |
|
207 | - * @return \EE_Registry instance |
|
208 | - */ |
|
209 | - public static function instance(\EE_Dependency_Map $dependency_map = null) |
|
210 | - { |
|
211 | - // check if class object is instantiated |
|
212 | - if ( ! self::$_instance instanceof EE_Registry) { |
|
213 | - self::$_instance = new EE_Registry($dependency_map); |
|
214 | - } |
|
215 | - return self::$_instance; |
|
216 | - } |
|
217 | - |
|
218 | - |
|
219 | - |
|
220 | - /** |
|
221 | - *protected constructor to prevent direct creation |
|
222 | - * |
|
223 | - * @Constructor |
|
224 | - * @access protected |
|
225 | - * @param \EE_Dependency_Map $dependency_map |
|
226 | - */ |
|
227 | - protected function __construct(\EE_Dependency_Map $dependency_map) |
|
228 | - { |
|
229 | - $this->_dependency_map = $dependency_map; |
|
230 | - $this->LIB = new stdClass(); |
|
231 | - $this->addons = new stdClass(); |
|
232 | - $this->modules = new stdClass(); |
|
233 | - $this->shortcodes = new stdClass(); |
|
234 | - $this->widgets = new stdClass(); |
|
235 | - add_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading', array($this, 'initialize')); |
|
236 | - } |
|
237 | - |
|
238 | - |
|
239 | - |
|
240 | - /** |
|
241 | - * initialize |
|
242 | - */ |
|
243 | - public function initialize() |
|
244 | - { |
|
245 | - $this->_class_abbreviations = apply_filters( |
|
246 | - 'FHEE__EE_Registry____construct___class_abbreviations', |
|
247 | - array( |
|
248 | - 'EE_Config' => 'CFG', |
|
249 | - 'EE_Session' => 'SSN', |
|
250 | - 'EE_Capabilities' => 'CAP', |
|
251 | - 'EE_Cart' => 'CART', |
|
252 | - 'EE_Network_Config' => 'NET_CFG', |
|
253 | - 'EE_Request_Handler' => 'REQ', |
|
254 | - 'EE_Message_Resource_Manager' => 'MRM', |
|
255 | - 'EventEspresso\core\services\commands\CommandBus' => 'BUS', |
|
256 | - 'EventEspresso\core\services\assets\Registry' => 'AssetsRegistry', |
|
257 | - ) |
|
258 | - ); |
|
259 | - $this->load_core('Base', array(), true); |
|
260 | - // add our request and response objects to the cache |
|
261 | - $request_loader = $this->_dependency_map->class_loader('EE_Request'); |
|
262 | - $this->_set_cached_class( |
|
263 | - $request_loader(), |
|
264 | - 'EE_Request' |
|
265 | - ); |
|
266 | - $response_loader = $this->_dependency_map->class_loader('EE_Response'); |
|
267 | - $this->_set_cached_class( |
|
268 | - $response_loader(), |
|
269 | - 'EE_Response' |
|
270 | - ); |
|
271 | - add_action('AHEE__EE_System__set_hooks_for_core', array($this, 'init')); |
|
272 | - } |
|
273 | - |
|
274 | - |
|
275 | - |
|
276 | - /** |
|
277 | - * init |
|
278 | - * |
|
279 | - * @access public |
|
280 | - * @return void |
|
281 | - */ |
|
282 | - public function init() |
|
283 | - { |
|
284 | - // Get current page protocol |
|
285 | - $protocol = isset($_SERVER['HTTPS']) ? 'https://' : 'http://'; |
|
286 | - // Output admin-ajax.php URL with same protocol as current page |
|
287 | - self::$i18n_js_strings['ajax_url'] = admin_url('admin-ajax.php', $protocol); |
|
288 | - self::$i18n_js_strings['wp_debug'] = defined('WP_DEBUG') ? WP_DEBUG : false; |
|
289 | - } |
|
290 | - |
|
291 | - |
|
292 | - |
|
293 | - /** |
|
294 | - * localize_i18n_js_strings |
|
295 | - * |
|
296 | - * @return string |
|
297 | - */ |
|
298 | - public static function localize_i18n_js_strings() |
|
299 | - { |
|
300 | - $i18n_js_strings = (array)EE_Registry::$i18n_js_strings; |
|
301 | - foreach ($i18n_js_strings as $key => $value) { |
|
302 | - if (is_scalar($value)) { |
|
303 | - $i18n_js_strings[$key] = html_entity_decode((string)$value, ENT_QUOTES, 'UTF-8'); |
|
304 | - } |
|
305 | - } |
|
306 | - return "/* <![CDATA[ */ var eei18n = " . wp_json_encode($i18n_js_strings) . '; /* ]]> */'; |
|
307 | - } |
|
308 | - |
|
309 | - |
|
310 | - |
|
311 | - /** |
|
312 | - * @param $module |
|
313 | - * @throws ReflectionException |
|
314 | - */ |
|
315 | - public function add_module($module) |
|
316 | - { |
|
317 | - if ($module instanceof EED_Module) { |
|
318 | - $module_class = get_class($module); |
|
319 | - $this->modules->{$module_class} = $module; |
|
320 | - } else { |
|
321 | - if ( ! class_exists('EE_Module_Request_Router')) { |
|
322 | - $this->load_core('Module_Request_Router'); |
|
323 | - } |
|
324 | - EE_Module_Request_Router::module_factory($module); |
|
325 | - } |
|
326 | - } |
|
327 | - |
|
328 | - |
|
329 | - |
|
330 | - /** |
|
331 | - * @param string $module_name |
|
332 | - * @return mixed EED_Module | NULL |
|
333 | - */ |
|
334 | - public function get_module($module_name = '') |
|
335 | - { |
|
336 | - return isset($this->modules->{$module_name}) ? $this->modules->{$module_name} : null; |
|
337 | - } |
|
338 | - |
|
339 | - |
|
340 | - |
|
341 | - /** |
|
342 | - * loads core classes - must be singletons |
|
343 | - * |
|
344 | - * @access public |
|
345 | - * @param string $class_name - simple class name ie: session |
|
346 | - * @param mixed $arguments |
|
347 | - * @param bool $load_only |
|
348 | - * @return mixed |
|
349 | - */ |
|
350 | - public function load_core($class_name, $arguments = array(), $load_only = false) |
|
351 | - { |
|
352 | - $core_paths = apply_filters( |
|
353 | - 'FHEE__EE_Registry__load_core__core_paths', |
|
354 | - array( |
|
355 | - EE_CORE, |
|
356 | - EE_ADMIN, |
|
357 | - EE_CPTS, |
|
358 | - EE_CORE . 'data_migration_scripts' . DS, |
|
359 | - EE_CORE . 'request_stack' . DS, |
|
360 | - EE_CORE . 'middleware' . DS, |
|
361 | - ) |
|
362 | - ); |
|
363 | - // retrieve instantiated class |
|
364 | - return $this->_load($core_paths, 'EE_', $class_name, 'core', $arguments, false, true, $load_only); |
|
365 | - } |
|
366 | - |
|
367 | - |
|
368 | - |
|
369 | - /** |
|
370 | - * loads service classes |
|
371 | - * |
|
372 | - * @access public |
|
373 | - * @param string $class_name - simple class name ie: session |
|
374 | - * @param mixed $arguments |
|
375 | - * @param bool $load_only |
|
376 | - * @return mixed |
|
377 | - */ |
|
378 | - public function load_service($class_name, $arguments = array(), $load_only = false) |
|
379 | - { |
|
380 | - $service_paths = apply_filters( |
|
381 | - 'FHEE__EE_Registry__load_service__service_paths', |
|
382 | - array( |
|
383 | - EE_CORE . 'services' . DS, |
|
384 | - ) |
|
385 | - ); |
|
386 | - // retrieve instantiated class |
|
387 | - return $this->_load($service_paths, 'EE_', $class_name, 'class', $arguments, false, true, $load_only); |
|
388 | - } |
|
389 | - |
|
390 | - |
|
391 | - |
|
392 | - /** |
|
393 | - * loads data_migration_scripts |
|
394 | - * |
|
395 | - * @access public |
|
396 | - * @param string $class_name - class name for the DMS ie: EE_DMS_Core_4_2_0 |
|
397 | - * @param mixed $arguments |
|
398 | - * @return EE_Data_Migration_Script_Base|mixed |
|
399 | - */ |
|
400 | - public function load_dms($class_name, $arguments = array()) |
|
401 | - { |
|
402 | - // retrieve instantiated class |
|
403 | - return $this->_load(EE_Data_Migration_Manager::instance()->get_data_migration_script_folders(), 'EE_DMS_', $class_name, 'dms', $arguments, false, false, false); |
|
404 | - } |
|
405 | - |
|
406 | - |
|
407 | - |
|
408 | - /** |
|
409 | - * loads object creating classes - must be singletons |
|
410 | - * |
|
411 | - * @param string $class_name - simple class name ie: attendee |
|
412 | - * @param mixed $arguments - an array of arguments to pass to the class |
|
413 | - * @param bool $from_db - some classes are instantiated from the db and thus call a different method to instantiate |
|
414 | - * @param bool $cache if you don't want the class to be stored in the internal cache (non-persistent) then set this to FALSE (ie. when instantiating model objects from client in a loop) |
|
415 | - * @param bool $load_only whether or not to just load the file and NOT instantiate, or load AND instantiate (default) |
|
416 | - * @return EE_Base_Class | bool |
|
417 | - */ |
|
418 | - public function load_class($class_name, $arguments = array(), $from_db = false, $cache = true, $load_only = false) |
|
419 | - { |
|
420 | - $paths = apply_filters('FHEE__EE_Registry__load_class__paths', array( |
|
421 | - EE_CORE, |
|
422 | - EE_CLASSES, |
|
423 | - EE_BUSINESS, |
|
424 | - )); |
|
425 | - // retrieve instantiated class |
|
426 | - return $this->_load($paths, 'EE_', $class_name, 'class', $arguments, $from_db, $cache, $load_only); |
|
427 | - } |
|
428 | - |
|
429 | - |
|
430 | - |
|
431 | - /** |
|
432 | - * loads helper classes - must be singletons |
|
433 | - * |
|
434 | - * @param string $class_name - simple class name ie: price |
|
435 | - * @param mixed $arguments |
|
436 | - * @param bool $load_only |
|
437 | - * @return EEH_Base | bool |
|
438 | - */ |
|
439 | - public function load_helper($class_name, $arguments = array(), $load_only = true) |
|
440 | - { |
|
441 | - // todo: add doing_it_wrong() in a few versions after all addons have had calls to this method removed |
|
442 | - $helper_paths = apply_filters('FHEE__EE_Registry__load_helper__helper_paths', array(EE_HELPERS)); |
|
443 | - // retrieve instantiated class |
|
444 | - return $this->_load($helper_paths, 'EEH_', $class_name, 'helper', $arguments, false, true, $load_only); |
|
445 | - } |
|
446 | - |
|
447 | - |
|
448 | - |
|
449 | - /** |
|
450 | - * loads core classes - must be singletons |
|
451 | - * |
|
452 | - * @access public |
|
453 | - * @param string $class_name - simple class name ie: session |
|
454 | - * @param mixed $arguments |
|
455 | - * @param bool $load_only |
|
456 | - * @param bool $cache whether to cache the object or not. |
|
457 | - * @return mixed |
|
458 | - */ |
|
459 | - public function load_lib($class_name, $arguments = array(), $load_only = false, $cache = true) |
|
460 | - { |
|
461 | - $paths = array( |
|
462 | - EE_LIBRARIES, |
|
463 | - EE_LIBRARIES . 'messages' . DS, |
|
464 | - EE_LIBRARIES . 'shortcodes' . DS, |
|
465 | - EE_LIBRARIES . 'qtips' . DS, |
|
466 | - EE_LIBRARIES . 'payment_methods' . DS, |
|
467 | - ); |
|
468 | - // retrieve instantiated class |
|
469 | - return $this->_load($paths, 'EE_', $class_name, 'lib', $arguments, false, $cache, $load_only); |
|
470 | - } |
|
471 | - |
|
472 | - |
|
473 | - |
|
474 | - /** |
|
475 | - * loads model classes - must be singletons |
|
476 | - * |
|
477 | - * @param string $class_name - simple class name ie: price |
|
478 | - * @param mixed $arguments |
|
479 | - * @param bool $load_only |
|
480 | - * @return EEM_Base | bool |
|
481 | - */ |
|
482 | - public function load_model($class_name, $arguments = array(), $load_only = false) |
|
483 | - { |
|
484 | - $paths = apply_filters('FHEE__EE_Registry__load_model__paths', array( |
|
485 | - EE_MODELS, |
|
486 | - EE_CORE, |
|
487 | - )); |
|
488 | - // retrieve instantiated class |
|
489 | - return $this->_load($paths, 'EEM_', $class_name, 'model', $arguments, false, true, $load_only); |
|
490 | - } |
|
491 | - |
|
492 | - |
|
493 | - |
|
494 | - /** |
|
495 | - * loads model classes - must be singletons |
|
496 | - * |
|
497 | - * @param string $class_name - simple class name ie: price |
|
498 | - * @param mixed $arguments |
|
499 | - * @param bool $load_only |
|
500 | - * @return mixed | bool |
|
501 | - */ |
|
502 | - public function load_model_class($class_name, $arguments = array(), $load_only = true) |
|
503 | - { |
|
504 | - $paths = array( |
|
505 | - EE_MODELS . 'fields' . DS, |
|
506 | - EE_MODELS . 'helpers' . DS, |
|
507 | - EE_MODELS . 'relations' . DS, |
|
508 | - EE_MODELS . 'strategies' . DS, |
|
509 | - ); |
|
510 | - // retrieve instantiated class |
|
511 | - return $this->_load($paths, 'EE_', $class_name, '', $arguments, false, true, $load_only); |
|
512 | - } |
|
513 | - |
|
514 | - |
|
515 | - |
|
516 | - /** |
|
517 | - * Determines if $model_name is the name of an actual EE model. |
|
518 | - * |
|
519 | - * @param string $model_name like Event, Attendee, Question_Group_Question, etc. |
|
520 | - * @return boolean |
|
521 | - */ |
|
522 | - public function is_model_name($model_name) |
|
523 | - { |
|
524 | - return isset($this->models[$model_name]) ? true : false; |
|
525 | - } |
|
526 | - |
|
527 | - |
|
528 | - |
|
529 | - /** |
|
530 | - * generic class loader |
|
531 | - * |
|
532 | - * @param string $path_to_file - directory path to file location, not including filename |
|
533 | - * @param string $file_name - file name ie: my_file.php, including extension |
|
534 | - * @param string $type - file type - core? class? helper? model? |
|
535 | - * @param mixed $arguments |
|
536 | - * @param bool $load_only |
|
537 | - * @return mixed |
|
538 | - */ |
|
539 | - public function load_file($path_to_file, $file_name, $type = '', $arguments = array(), $load_only = true) |
|
540 | - { |
|
541 | - // retrieve instantiated class |
|
542 | - return $this->_load($path_to_file, '', $file_name, $type, $arguments, false, true, $load_only); |
|
543 | - } |
|
544 | - |
|
545 | - |
|
546 | - |
|
547 | - /** |
|
548 | - * load_addon |
|
549 | - * |
|
550 | - * @param string $path_to_file - directory path to file location, not including filename |
|
551 | - * @param string $class_name - full class name ie: My_Class |
|
552 | - * @param string $type - file type - core? class? helper? model? |
|
553 | - * @param mixed $arguments |
|
554 | - * @param bool $load_only |
|
555 | - * @return EE_Addon |
|
556 | - */ |
|
557 | - public function load_addon($path_to_file, $class_name, $type = 'class', $arguments = array(), $load_only = false) |
|
558 | - { |
|
559 | - // retrieve instantiated class |
|
560 | - return $this->_load($path_to_file, 'addon', $class_name, $type, $arguments, false, true, $load_only); |
|
561 | - } |
|
562 | - |
|
563 | - |
|
564 | - |
|
565 | - /** |
|
566 | - * instantiates, caches, and automatically resolves dependencies |
|
567 | - * for classes that use a Fully Qualified Class Name. |
|
568 | - * if the class is not capable of being loaded using PSR-4 autoloading, |
|
569 | - * then you need to use one of the existing load_*() methods |
|
570 | - * which can resolve the classname and filepath from the passed arguments |
|
571 | - * |
|
572 | - * @param bool|string $class_name Fully Qualified Class Name |
|
573 | - * @param array $arguments an argument, or array of arguments to pass to the class upon instantiation |
|
574 | - * @param bool $cache whether to cache the instantiated object for reuse |
|
575 | - * @param bool $from_db some classes are instantiated from the db |
|
576 | - * and thus call a different method to instantiate |
|
577 | - * @param bool $load_only if true, will only load the file, but will NOT instantiate an object |
|
578 | - * @param bool|string $addon if true, will cache the object in the EE_Registry->$addons array |
|
579 | - * @return mixed null = failure to load or instantiate class object. |
|
580 | - * object = class loaded and instantiated successfully. |
|
581 | - * bool = fail or success when $load_only is true |
|
582 | - */ |
|
583 | - public function create( |
|
584 | - $class_name = false, |
|
585 | - $arguments = array(), |
|
586 | - $cache = false, |
|
587 | - $from_db = false, |
|
588 | - $load_only = false, |
|
589 | - $addon = false |
|
590 | - ) { |
|
591 | - $class_name = ltrim($class_name, '\\'); |
|
592 | - $class_name = $this->_dependency_map->get_alias($class_name); |
|
593 | - if ( ! class_exists($class_name)) { |
|
594 | - // maybe the class is registered with a preceding \ |
|
595 | - $class_name = strpos($class_name, '\\') !== 0 ? '\\' . $class_name : $class_name; |
|
596 | - // still doesn't exist ? |
|
597 | - if ( ! class_exists($class_name)) { |
|
598 | - return null; |
|
599 | - } |
|
600 | - } |
|
601 | - // if we're only loading the class and it already exists, then let's just return true immediately |
|
602 | - if ($load_only) { |
|
603 | - return true; |
|
604 | - } |
|
605 | - $addon = $addon ? 'addon' : ''; |
|
606 | - // $this->_cache_on is toggled during the recursive loading that can occur with dependency injection |
|
607 | - // $cache is controlled by individual calls to separate Registry loader methods like load_class() |
|
608 | - // $load_only is also controlled by individual calls to separate Registry loader methods like load_file() |
|
609 | - if ($this->_cache_on && $cache && ! $load_only) { |
|
610 | - // return object if it's already cached |
|
611 | - $cached_class = $this->_get_cached_class($class_name, $addon); |
|
612 | - if ($cached_class !== null) { |
|
613 | - return $cached_class; |
|
614 | - } |
|
615 | - } |
|
616 | - // instantiate the requested object |
|
617 | - $class_obj = $this->_create_object($class_name, $arguments, $addon, $from_db); |
|
618 | - if ($this->_cache_on && $cache) { |
|
619 | - // save it for later... kinda like gum { : $ |
|
620 | - $this->_set_cached_class($class_obj, $class_name, $addon, $from_db); |
|
621 | - } |
|
622 | - $this->_cache_on = true; |
|
623 | - return $class_obj; |
|
624 | - } |
|
625 | - |
|
626 | - |
|
627 | - |
|
628 | - /** |
|
629 | - * instantiates, caches, and injects dependencies for classes |
|
630 | - * |
|
631 | - * @param array $file_paths an array of paths to folders to look in |
|
632 | - * @param string $class_prefix EE or EEM or... ??? |
|
633 | - * @param bool|string $class_name $class name |
|
634 | - * @param string $type file type - core? class? helper? model? |
|
635 | - * @param mixed $arguments an argument or array of arguments to pass to the class upon instantiation |
|
636 | - * @param bool $from_db some classes are instantiated from the db |
|
637 | - * and thus call a different method to instantiate |
|
638 | - * @param bool $cache whether to cache the instantiated object for reuse |
|
639 | - * @param bool $load_only if true, will only load the file, but will NOT instantiate an object |
|
640 | - * @return null|object|bool null = failure to load or instantiate class object. |
|
641 | - * object = class loaded and instantiated successfully. |
|
642 | - * bool = fail or success when $load_only is true |
|
643 | - */ |
|
644 | - protected function _load( |
|
645 | - $file_paths = array(), |
|
646 | - $class_prefix = 'EE_', |
|
647 | - $class_name = false, |
|
648 | - $type = 'class', |
|
649 | - $arguments = array(), |
|
650 | - $from_db = false, |
|
651 | - $cache = true, |
|
652 | - $load_only = false |
|
653 | - ) { |
|
654 | - $class_name = ltrim($class_name, '\\'); |
|
655 | - // strip php file extension |
|
656 | - $class_name = str_replace('.php', '', trim($class_name)); |
|
657 | - // does the class have a prefix ? |
|
658 | - if ( ! empty($class_prefix) && $class_prefix != 'addon') { |
|
659 | - // make sure $class_prefix is uppercase |
|
660 | - $class_prefix = strtoupper(trim($class_prefix)); |
|
661 | - // add class prefix ONCE!!! |
|
662 | - $class_name = $class_prefix . str_replace($class_prefix, '', $class_name); |
|
663 | - } |
|
664 | - $class_name = $this->_dependency_map->get_alias($class_name); |
|
665 | - $class_exists = class_exists($class_name); |
|
666 | - // if we're only loading the class and it already exists, then let's just return true immediately |
|
667 | - if ($load_only && $class_exists) { |
|
668 | - return true; |
|
669 | - } |
|
670 | - // $this->_cache_on is toggled during the recursive loading that can occur with dependency injection |
|
671 | - // $cache is controlled by individual calls to separate Registry loader methods like load_class() |
|
672 | - // $load_only is also controlled by individual calls to separate Registry loader methods like load_file() |
|
673 | - if ($this->_cache_on && $cache && ! $load_only) { |
|
674 | - // return object if it's already cached |
|
675 | - $cached_class = $this->_get_cached_class($class_name, $class_prefix); |
|
676 | - if ($cached_class !== null) { |
|
677 | - return $cached_class; |
|
678 | - } |
|
679 | - } |
|
680 | - // if the class doesn't already exist.. then we need to try and find the file and load it |
|
681 | - if ( ! $class_exists) { |
|
682 | - // get full path to file |
|
683 | - $path = $this->_resolve_path($class_name, $type, $file_paths); |
|
684 | - // load the file |
|
685 | - $loaded = $this->_require_file($path, $class_name, $type, $file_paths); |
|
686 | - // if loading failed, or we are only loading a file but NOT instantiating an object |
|
687 | - if ( ! $loaded || $load_only) { |
|
688 | - // return boolean if only loading, or null if an object was expected |
|
689 | - return $load_only ? $loaded : null; |
|
690 | - } |
|
691 | - } |
|
692 | - // instantiate the requested object |
|
693 | - $class_obj = $this->_create_object($class_name, $arguments, $type, $from_db); |
|
694 | - if ($this->_cache_on && $cache) { |
|
695 | - // save it for later... kinda like gum { : $ |
|
696 | - $this->_set_cached_class($class_obj, $class_name, $class_prefix, $from_db); |
|
697 | - } |
|
698 | - $this->_cache_on = true; |
|
699 | - return $class_obj; |
|
700 | - } |
|
701 | - |
|
702 | - |
|
703 | - |
|
704 | - |
|
705 | - /** |
|
706 | - * _get_cached_class |
|
707 | - * attempts to find a cached version of the requested class |
|
708 | - * by looking in the following places: |
|
709 | - * $this->{$class_abbreviation} ie: $this->CART |
|
710 | - * $this->{$class_name} ie: $this->Some_Class |
|
711 | - * $this->LIB->{$class_name} ie: $this->LIB->Some_Class |
|
712 | - * $this->addon->{$class_name} ie: $this->addon->Some_Addon_Class |
|
713 | - * |
|
714 | - * @access protected |
|
715 | - * @param string $class_name |
|
716 | - * @param string $class_prefix |
|
717 | - * @return mixed |
|
718 | - */ |
|
719 | - protected function _get_cached_class($class_name, $class_prefix = '') |
|
720 | - { |
|
721 | - if ($class_name === 'EE_Registry') { |
|
722 | - return $this; |
|
723 | - } |
|
724 | - // have to specify something, but not anything that will conflict |
|
725 | - $class_abbreviation = isset($this->_class_abbreviations[ $class_name ]) |
|
726 | - ? $this->_class_abbreviations[ $class_name ] |
|
727 | - : 'FANCY_BATMAN_PANTS'; |
|
728 | - $class_name = str_replace('\\', '_', $class_name); |
|
729 | - // check if class has already been loaded, and return it if it has been |
|
730 | - if (isset($this->{$class_abbreviation}) && ! is_null($this->{$class_abbreviation})) { |
|
731 | - return $this->{$class_abbreviation}; |
|
732 | - } |
|
733 | - if (isset ($this->{$class_name})) { |
|
734 | - return $this->{$class_name}; |
|
735 | - } |
|
736 | - if (isset ($this->LIB->{$class_name})) { |
|
737 | - return $this->LIB->{$class_name}; |
|
738 | - } |
|
739 | - if ($class_prefix === 'addon' && isset ($this->addons->{$class_name})) { |
|
740 | - return $this->addons->{$class_name}; |
|
741 | - } |
|
742 | - return null; |
|
743 | - } |
|
744 | - |
|
745 | - |
|
746 | - |
|
747 | - /** |
|
748 | - * removes a cached version of the requested class |
|
749 | - * |
|
750 | - * @param string $class_name |
|
751 | - * @param boolean $addon |
|
752 | - * @return boolean |
|
753 | - */ |
|
754 | - public function clear_cached_class($class_name, $addon = false) |
|
755 | - { |
|
756 | - // have to specify something, but not anything that will conflict |
|
757 | - $class_abbreviation = isset($this->_class_abbreviations[ $class_name ]) |
|
758 | - ? $this->_class_abbreviations[ $class_name ] |
|
759 | - : 'FANCY_BATMAN_PANTS'; |
|
760 | - $class_name = str_replace('\\', '_', $class_name); |
|
761 | - // check if class has already been loaded, and return it if it has been |
|
762 | - if (isset($this->{$class_abbreviation}) && ! is_null($this->{$class_abbreviation})) { |
|
763 | - $this->{$class_abbreviation} = null; |
|
764 | - return true; |
|
765 | - } |
|
766 | - if (isset($this->{$class_name})) { |
|
767 | - $this->{$class_name} = null; |
|
768 | - return true; |
|
769 | - } |
|
770 | - if (isset($this->LIB->{$class_name})) { |
|
771 | - unset($this->LIB->{$class_name}); |
|
772 | - return true; |
|
773 | - } |
|
774 | - if ($addon && isset($this->addons->{$class_name})) { |
|
775 | - unset($this->addons->{$class_name}); |
|
776 | - return true; |
|
777 | - } |
|
778 | - return false; |
|
779 | - } |
|
780 | - |
|
781 | - |
|
782 | - /** |
|
783 | - * _resolve_path |
|
784 | - * attempts to find a full valid filepath for the requested class. |
|
785 | - * loops thru each of the base paths in the $file_paths array and appends : "{classname} . {file type} . php" |
|
786 | - * then returns that path if the target file has been found and is readable |
|
787 | - * |
|
788 | - * @access protected |
|
789 | - * @param string $class_name |
|
790 | - * @param string $type |
|
791 | - * @param array $file_paths |
|
792 | - * @return string | bool |
|
793 | - */ |
|
794 | - protected function _resolve_path($class_name, $type = '', $file_paths = array()) |
|
795 | - { |
|
796 | - // make sure $file_paths is an array |
|
797 | - $file_paths = is_array($file_paths) ? $file_paths : array($file_paths); |
|
798 | - // cycle thru paths |
|
799 | - foreach ($file_paths as $key => $file_path) { |
|
800 | - // convert all separators to proper DS, if no filepath, then use EE_CLASSES |
|
801 | - $file_path = $file_path ? str_replace(array('/', '\\'), DS, $file_path) : EE_CLASSES; |
|
802 | - // prep file type |
|
803 | - $type = ! empty($type) ? trim($type, '.') . '.' : ''; |
|
804 | - // build full file path |
|
805 | - $file_paths[$key] = rtrim($file_path, DS) . DS . $class_name . '.' . $type . 'php'; |
|
806 | - //does the file exist and can be read ? |
|
807 | - if (is_readable($file_paths[$key])) { |
|
808 | - return $file_paths[$key]; |
|
809 | - } |
|
810 | - } |
|
811 | - return false; |
|
812 | - } |
|
813 | - |
|
814 | - |
|
815 | - |
|
816 | - /** |
|
817 | - * _require_file |
|
818 | - * basically just performs a require_once() |
|
819 | - * but with some error handling |
|
820 | - * |
|
821 | - * @access protected |
|
822 | - * @param string $path |
|
823 | - * @param string $class_name |
|
824 | - * @param string $type |
|
825 | - * @param array $file_paths |
|
826 | - * @return boolean |
|
827 | - * @throws \EE_Error |
|
828 | - */ |
|
829 | - protected function _require_file($path, $class_name, $type = '', $file_paths = array()) |
|
830 | - { |
|
831 | - // don't give up! you gotta... |
|
832 | - try { |
|
833 | - //does the file exist and can it be read ? |
|
834 | - if ( ! $path) { |
|
835 | - // so sorry, can't find the file |
|
836 | - throw new EE_Error ( |
|
837 | - sprintf( |
|
838 | - __('The %1$s file %2$s could not be located or is not readable due to file permissions. Please ensure that the following filepath(s) are correct: %3$s', 'event_espresso'), |
|
839 | - trim($type, '.'), |
|
840 | - $class_name, |
|
841 | - '<br />' . implode(',<br />', $file_paths) |
|
842 | - ) |
|
843 | - ); |
|
844 | - } |
|
845 | - // get the file |
|
846 | - require_once($path); |
|
847 | - // if the class isn't already declared somewhere |
|
848 | - if (class_exists($class_name, false) === false) { |
|
849 | - // so sorry, not a class |
|
850 | - throw new EE_Error( |
|
851 | - sprintf( |
|
852 | - __('The %s file %s does not appear to contain the %s Class.', 'event_espresso'), |
|
853 | - $type, |
|
854 | - $path, |
|
855 | - $class_name |
|
856 | - ) |
|
857 | - ); |
|
858 | - } |
|
859 | - } catch (EE_Error $e) { |
|
860 | - $e->get_error(); |
|
861 | - return false; |
|
862 | - } |
|
863 | - return true; |
|
864 | - } |
|
865 | - |
|
866 | - |
|
867 | - |
|
868 | - /** |
|
869 | - * _create_object |
|
870 | - * Attempts to instantiate the requested class via any of the |
|
871 | - * commonly used instantiation methods employed throughout EE. |
|
872 | - * The priority for instantiation is as follows: |
|
873 | - * - abstract classes or any class flagged as "load only" (no instantiation occurs) |
|
874 | - * - model objects via their 'new_instance_from_db' method |
|
875 | - * - model objects via their 'new_instance' method |
|
876 | - * - "singleton" classes" via their 'instance' method |
|
877 | - * - standard instantiable classes via their __constructor |
|
878 | - * Prior to instantiation, if the classname exists in the dependency_map, |
|
879 | - * then the constructor for the requested class will be examined to determine |
|
880 | - * if any dependencies exist, and if they can be injected. |
|
881 | - * If so, then those classes will be added to the array of arguments passed to the constructor |
|
882 | - * |
|
883 | - * @access protected |
|
884 | - * @param string $class_name |
|
885 | - * @param array $arguments |
|
886 | - * @param string $type |
|
887 | - * @param bool $from_db |
|
888 | - * @return null | object |
|
889 | - * @throws \EE_Error |
|
890 | - */ |
|
891 | - protected function _create_object($class_name, $arguments = array(), $type = '', $from_db = false) |
|
892 | - { |
|
893 | - $class_obj = null; |
|
894 | - $instantiation_mode = '0) none'; |
|
895 | - // don't give up! you gotta... |
|
896 | - try { |
|
897 | - // create reflection |
|
898 | - $reflector = $this->get_ReflectionClass($class_name); |
|
899 | - // make sure arguments are an array |
|
900 | - $arguments = is_array($arguments) ? $arguments : array($arguments); |
|
901 | - // and if arguments array is numerically and sequentially indexed, then we want it to remain as is, |
|
902 | - // else wrap it in an additional array so that it doesn't get split into multiple parameters |
|
903 | - $arguments = $this->_array_is_numerically_and_sequentially_indexed($arguments) |
|
904 | - ? $arguments |
|
905 | - : array($arguments); |
|
906 | - // attempt to inject dependencies ? |
|
907 | - if ($this->_dependency_map->has($class_name)) { |
|
908 | - $arguments = $this->_resolve_dependencies($reflector, $class_name, $arguments); |
|
909 | - } |
|
910 | - // instantiate the class if possible |
|
911 | - if ($reflector->isAbstract()) { |
|
912 | - // nothing to instantiate, loading file was enough |
|
913 | - // does not throw an exception so $instantiation_mode is unused |
|
914 | - // $instantiation_mode = "1) no constructor abstract class"; |
|
915 | - $class_obj = true; |
|
916 | - } else if ($reflector->getConstructor() === null && $reflector->isInstantiable() && empty($arguments)) { |
|
917 | - // no constructor = static methods only... nothing to instantiate, loading file was enough |
|
918 | - $instantiation_mode = "2) no constructor but instantiable"; |
|
919 | - $class_obj = $reflector->newInstance(); |
|
920 | - } else if ($from_db && method_exists($class_name, 'new_instance_from_db')) { |
|
921 | - $instantiation_mode = "3) new_instance_from_db()"; |
|
922 | - $class_obj = call_user_func_array(array($class_name, 'new_instance_from_db'), $arguments); |
|
923 | - } else if (method_exists($class_name, 'new_instance')) { |
|
924 | - $instantiation_mode = "4) new_instance()"; |
|
925 | - $class_obj = call_user_func_array(array($class_name, 'new_instance'), $arguments); |
|
926 | - } else if (method_exists($class_name, 'instance')) { |
|
927 | - $instantiation_mode = "5) instance()"; |
|
928 | - $class_obj = call_user_func_array(array($class_name, 'instance'), $arguments); |
|
929 | - } else if ($reflector->isInstantiable()) { |
|
930 | - $instantiation_mode = "6) constructor"; |
|
931 | - $class_obj = $reflector->newInstanceArgs($arguments); |
|
932 | - } else { |
|
933 | - // heh ? something's not right ! |
|
934 | - throw new EE_Error( |
|
935 | - sprintf( |
|
936 | - __('The %s file %s could not be instantiated.', 'event_espresso'), |
|
937 | - $type, |
|
938 | - $class_name |
|
939 | - ) |
|
940 | - ); |
|
941 | - } |
|
942 | - } catch (Exception $e) { |
|
943 | - if ( ! $e instanceof EE_Error) { |
|
944 | - $e = new EE_Error( |
|
945 | - sprintf( |
|
946 | - __('The following error occurred while attempting to instantiate "%1$s": %2$s %3$s %2$s instantiation mode : %4$s', 'event_espresso'), |
|
947 | - $class_name, |
|
948 | - '<br />', |
|
949 | - $e->getMessage(), |
|
950 | - $instantiation_mode |
|
951 | - ) |
|
952 | - ); |
|
953 | - } |
|
954 | - $e->get_error(); |
|
955 | - } |
|
956 | - return $class_obj; |
|
957 | - } |
|
958 | - |
|
959 | - |
|
960 | - |
|
961 | - /** |
|
962 | - * @see http://stackoverflow.com/questions/173400/how-to-check-if-php-array-is-associative-or-sequential |
|
963 | - * @param array $array |
|
964 | - * @return bool |
|
965 | - */ |
|
966 | - protected function _array_is_numerically_and_sequentially_indexed(array $array) |
|
967 | - { |
|
968 | - return ! empty($array) ? array_keys($array) === range(0, count($array) - 1) : true; |
|
969 | - } |
|
970 | - |
|
971 | - |
|
972 | - |
|
973 | - /** |
|
974 | - * getReflectionClass |
|
975 | - * checks if a ReflectionClass object has already been generated for a class |
|
976 | - * and returns that instead of creating a new one |
|
977 | - * |
|
978 | - * @access public |
|
979 | - * @param string $class_name |
|
980 | - * @return ReflectionClass |
|
981 | - */ |
|
982 | - public function get_ReflectionClass($class_name) |
|
983 | - { |
|
984 | - if ( |
|
985 | - ! isset($this->_reflectors[$class_name]) |
|
986 | - || ! $this->_reflectors[$class_name] instanceof ReflectionClass |
|
987 | - ) { |
|
988 | - $this->_reflectors[$class_name] = new ReflectionClass($class_name); |
|
989 | - } |
|
990 | - return $this->_reflectors[$class_name]; |
|
991 | - } |
|
992 | - |
|
993 | - |
|
994 | - |
|
995 | - /** |
|
996 | - * _resolve_dependencies |
|
997 | - * examines the constructor for the requested class to determine |
|
998 | - * if any dependencies exist, and if they can be injected. |
|
999 | - * If so, then those classes will be added to the array of arguments passed to the constructor |
|
1000 | - * PLZ NOTE: this is achieved by type hinting the constructor params |
|
1001 | - * For example: |
|
1002 | - * if attempting to load a class "Foo" with the following constructor: |
|
1003 | - * __construct( Bar $bar_class, Fighter $grohl_class ) |
|
1004 | - * then $bar_class and $grohl_class will be added to the $arguments array, |
|
1005 | - * but only IF they are NOT already present in the incoming arguments array, |
|
1006 | - * and the correct classes can be loaded |
|
1007 | - * |
|
1008 | - * @access protected |
|
1009 | - * @param ReflectionClass $reflector |
|
1010 | - * @param string $class_name |
|
1011 | - * @param array $arguments |
|
1012 | - * @return array |
|
1013 | - * @throws \ReflectionException |
|
1014 | - */ |
|
1015 | - protected function _resolve_dependencies(ReflectionClass $reflector, $class_name, $arguments = array()) |
|
1016 | - { |
|
1017 | - // let's examine the constructor |
|
1018 | - $constructor = $reflector->getConstructor(); |
|
1019 | - // whu? huh? nothing? |
|
1020 | - if ( ! $constructor) { |
|
1021 | - return $arguments; |
|
1022 | - } |
|
1023 | - // get constructor parameters |
|
1024 | - $params = $constructor->getParameters(); |
|
1025 | - // and the keys for the incoming arguments array so that we can compare existing arguments with what is expected |
|
1026 | - $argument_keys = array_keys($arguments); |
|
1027 | - // now loop thru all of the constructors expected parameters |
|
1028 | - foreach ($params as $index => $param) { |
|
1029 | - // is this a dependency for a specific class ? |
|
1030 | - $param_class = $param->getClass() ? $param->getClass()->name : null; |
|
1031 | - // BUT WAIT !!! This class may be an alias for something else (or getting replaced at runtime) |
|
1032 | - $param_class = $this->_dependency_map->has_alias($param_class, $class_name) |
|
1033 | - ? $this->_dependency_map->get_alias($param_class, $class_name) |
|
1034 | - : $param_class; |
|
1035 | - if ( |
|
1036 | - // param is not even a class |
|
1037 | - empty($param_class) |
|
1038 | - // and something already exists in the incoming arguments for this param |
|
1039 | - && isset($argument_keys[$index], $arguments[$argument_keys[$index]]) |
|
1040 | - ) { |
|
1041 | - // so let's skip this argument and move on to the next |
|
1042 | - continue; |
|
1043 | - } |
|
1044 | - if ( |
|
1045 | - // parameter is type hinted as a class, exists as an incoming argument, AND it's the correct class |
|
1046 | - ! empty($param_class) |
|
1047 | - && isset($argument_keys[$index], $arguments[$argument_keys[$index]]) |
|
1048 | - && $arguments[$argument_keys[$index]] instanceof $param_class |
|
1049 | - ) { |
|
1050 | - // skip this argument and move on to the next |
|
1051 | - continue; |
|
1052 | - } |
|
1053 | - if ( |
|
1054 | - // parameter is type hinted as a class, and should be injected |
|
1055 | - ! empty($param_class) |
|
1056 | - && $this->_dependency_map->has_dependency_for_class($class_name, $param_class) |
|
1057 | - ) { |
|
1058 | - $arguments = $this->_resolve_dependency($class_name, $param_class, $arguments, $index); |
|
1059 | - } else { |
|
1060 | - try { |
|
1061 | - $arguments[$index] = $param->getDefaultValue(); |
|
1062 | - } catch (ReflectionException $e) { |
|
1063 | - throw new ReflectionException( |
|
1064 | - sprintf( |
|
1065 | - __('%1$s for parameter "$%2$s"', 'event_espresso'), |
|
1066 | - $e->getMessage(), |
|
1067 | - $param->getName() |
|
1068 | - ) |
|
1069 | - ); |
|
1070 | - } |
|
1071 | - } |
|
1072 | - } |
|
1073 | - return $arguments; |
|
1074 | - } |
|
1075 | - |
|
1076 | - |
|
1077 | - |
|
1078 | - /** |
|
1079 | - * @access protected |
|
1080 | - * @param string $class_name |
|
1081 | - * @param string $param_class |
|
1082 | - * @param array $arguments |
|
1083 | - * @param mixed $index |
|
1084 | - * @return array |
|
1085 | - */ |
|
1086 | - protected function _resolve_dependency($class_name, $param_class, $arguments, $index) |
|
1087 | - { |
|
1088 | - $dependency = null; |
|
1089 | - // should dependency be loaded from cache ? |
|
1090 | - $cache_on = $this->_dependency_map->loading_strategy_for_class_dependency($class_name, $param_class) |
|
1091 | - !== EE_Dependency_Map::load_new_object |
|
1092 | - ? true |
|
1093 | - : false; |
|
1094 | - // we might have a dependency... |
|
1095 | - // let's MAYBE try and find it in our cache if that's what's been requested |
|
1096 | - $cached_class = $cache_on ? $this->_get_cached_class($param_class) : null; |
|
1097 | - // and grab it if it exists |
|
1098 | - if ($cached_class instanceof $param_class) { |
|
1099 | - $dependency = $cached_class; |
|
1100 | - } else if ($param_class !== $class_name) { |
|
1101 | - // obtain the loader method from the dependency map |
|
1102 | - $loader = $this->_dependency_map->class_loader($param_class); |
|
1103 | - // is loader a custom closure ? |
|
1104 | - if ($loader instanceof Closure) { |
|
1105 | - $dependency = $loader(); |
|
1106 | - } else { |
|
1107 | - // set the cache on property for the recursive loading call |
|
1108 | - $this->_cache_on = $cache_on; |
|
1109 | - // if not, then let's try and load it via the registry |
|
1110 | - if ($loader && method_exists($this, $loader)) { |
|
1111 | - $dependency = $this->{$loader}($param_class); |
|
1112 | - } else { |
|
1113 | - $dependency = $this->create($param_class, array(), $cache_on); |
|
1114 | - } |
|
1115 | - } |
|
1116 | - } |
|
1117 | - // did we successfully find the correct dependency ? |
|
1118 | - if ($dependency instanceof $param_class) { |
|
1119 | - // then let's inject it into the incoming array of arguments at the correct location |
|
1120 | - if (isset($argument_keys[$index])) { |
|
1121 | - $arguments[$argument_keys[$index]] = $dependency; |
|
1122 | - } else { |
|
1123 | - $arguments[$index] = $dependency; |
|
1124 | - } |
|
1125 | - } |
|
1126 | - return $arguments; |
|
1127 | - } |
|
1128 | - |
|
1129 | - |
|
1130 | - |
|
1131 | - /** |
|
1132 | - * _set_cached_class |
|
1133 | - * attempts to cache the instantiated class locally |
|
1134 | - * in one of the following places, in the following order: |
|
1135 | - * $this->{class_abbreviation} ie: $this->CART |
|
1136 | - * $this->{$class_name} ie: $this->Some_Class |
|
1137 | - * $this->addon->{$$class_name} ie: $this->addon->Some_Addon_Class |
|
1138 | - * $this->LIB->{$class_name} ie: $this->LIB->Some_Class |
|
1139 | - * |
|
1140 | - * @access protected |
|
1141 | - * @param object $class_obj |
|
1142 | - * @param string $class_name |
|
1143 | - * @param string $class_prefix |
|
1144 | - * @param bool $from_db |
|
1145 | - * @return void |
|
1146 | - */ |
|
1147 | - protected function _set_cached_class($class_obj, $class_name, $class_prefix = '', $from_db = false) |
|
1148 | - { |
|
1149 | - if ($class_name === 'EE_Registry' || empty($class_obj)) { |
|
1150 | - return; |
|
1151 | - } |
|
1152 | - // return newly instantiated class |
|
1153 | - if (isset($this->_class_abbreviations[$class_name])) { |
|
1154 | - $class_abbreviation = $this->_class_abbreviations[$class_name]; |
|
1155 | - $this->{$class_abbreviation} = $class_obj; |
|
1156 | - return; |
|
1157 | - } |
|
1158 | - $class_name = str_replace('\\', '_', $class_name); |
|
1159 | - if (property_exists($this, $class_name)) { |
|
1160 | - $this->{$class_name} = $class_obj; |
|
1161 | - return; |
|
1162 | - } |
|
1163 | - if ($class_prefix === 'addon') { |
|
1164 | - $this->addons->{$class_name} = $class_obj; |
|
1165 | - return; |
|
1166 | - } |
|
1167 | - if ( ! $from_db) { |
|
1168 | - $this->LIB->{$class_name} = $class_obj; |
|
1169 | - } |
|
1170 | - } |
|
1171 | - |
|
1172 | - |
|
1173 | - |
|
1174 | - /** |
|
1175 | - * call any loader that's been registered in the EE_Dependency_Map::$_class_loaders array |
|
1176 | - * |
|
1177 | - * @param string $classname PLEASE NOTE: the class name needs to match what's registered |
|
1178 | - * in the EE_Dependency_Map::$_class_loaders array, |
|
1179 | - * including the class prefix, ie: "EE_", "EEM_", "EEH_", etc |
|
1180 | - * @param array $arguments |
|
1181 | - * @return object |
|
1182 | - */ |
|
1183 | - public static function factory($classname, $arguments = array()) |
|
1184 | - { |
|
1185 | - $loader = self::instance()->_dependency_map->class_loader($classname); |
|
1186 | - if ($loader instanceof Closure) { |
|
1187 | - return $loader($arguments); |
|
1188 | - } |
|
1189 | - if (method_exists(EE_Registry::instance(), $loader)) { |
|
1190 | - return EE_Registry::instance()->{$loader}($classname, $arguments); |
|
1191 | - } |
|
1192 | - return null; |
|
1193 | - } |
|
1194 | - |
|
1195 | - |
|
1196 | - |
|
1197 | - /** |
|
1198 | - * Gets the addon by its name/slug (not classname. For that, just |
|
1199 | - * use the classname as the property name on EE_Config::instance()->addons) |
|
1200 | - * |
|
1201 | - * @param string $name |
|
1202 | - * @return EE_Addon |
|
1203 | - */ |
|
1204 | - public function get_addon_by_name($name) |
|
1205 | - { |
|
1206 | - foreach ($this->addons as $addon) { |
|
1207 | - if ($addon->name() == $name) { |
|
1208 | - return $addon; |
|
1209 | - } |
|
1210 | - } |
|
1211 | - return null; |
|
1212 | - } |
|
1213 | - |
|
1214 | - |
|
1215 | - |
|
1216 | - /** |
|
1217 | - * Gets an array of all the registered addons, where the keys are their names. (ie, what each returns for their name() function) They're already available on EE_Config::instance()->addons as properties, where each property's name is |
|
1218 | - * the addon's classname. So if you just want to get the addon by classname, use EE_Config::instance()->addons->{classname} |
|
1219 | - * |
|
1220 | - * @return EE_Addon[] where the KEYS are the addon's name() |
|
1221 | - */ |
|
1222 | - public function get_addons_by_name() |
|
1223 | - { |
|
1224 | - $addons = array(); |
|
1225 | - foreach ($this->addons as $addon) { |
|
1226 | - $addons[$addon->name()] = $addon; |
|
1227 | - } |
|
1228 | - return $addons; |
|
1229 | - } |
|
1230 | - |
|
1231 | - |
|
1232 | - |
|
1233 | - /** |
|
1234 | - * Resets the specified model's instance AND makes sure EE_Registry doesn't keep |
|
1235 | - * a stale copy of it around |
|
1236 | - * |
|
1237 | - * @param string $model_name |
|
1238 | - * @return \EEM_Base |
|
1239 | - * @throws \EE_Error |
|
1240 | - */ |
|
1241 | - public function reset_model($model_name) |
|
1242 | - { |
|
1243 | - $model_class_name = strpos($model_name, 'EEM_') !== 0 ? "EEM_{$model_name}" : $model_name; |
|
1244 | - if ( ! isset($this->LIB->{$model_class_name}) || ! $this->LIB->{$model_class_name} instanceof EEM_Base) { |
|
1245 | - return null; |
|
1246 | - } |
|
1247 | - //get that model reset it and make sure we nuke the old reference to it |
|
1248 | - if ($this->LIB->{$model_class_name} instanceof $model_class_name && is_callable(array($model_class_name, 'reset'))) { |
|
1249 | - $this->LIB->{$model_class_name} = $this->LIB->{$model_class_name}->reset(); |
|
1250 | - } else { |
|
1251 | - throw new EE_Error(sprintf(__('Model %s does not have a method "reset"', 'event_espresso'), $model_name)); |
|
1252 | - } |
|
1253 | - return $this->LIB->{$model_class_name}; |
|
1254 | - } |
|
1255 | - |
|
1256 | - |
|
1257 | - |
|
1258 | - /** |
|
1259 | - * Resets the registry. |
|
1260 | - * The criteria for what gets reset is based on what can be shared between sites on the same request when switch_to_blog |
|
1261 | - * is used in a multisite install. Here is a list of things that are NOT reset. |
|
1262 | - * - $_dependency_map |
|
1263 | - * - $_class_abbreviations |
|
1264 | - * - $NET_CFG (EE_Network_Config): The config is shared network wide so no need to reset. |
|
1265 | - * - $REQ: Still on the same request so no need to change. |
|
1266 | - * - $CAP: There is no site specific state in the EE_Capability class. |
|
1267 | - * - $SSN: Although ideally, the session should not be shared between site switches, we can't reset it because only one Session |
|
1268 | - * can be active in a single request. Resetting could resolve in "headers already sent" errors. |
|
1269 | - * - $addons: In multisite, the state of the addons is something controlled via hooks etc in a normal request. So |
|
1270 | - * for now, we won't reset the addons because it could break calls to an add-ons class/methods in the |
|
1271 | - * switch or on the restore. |
|
1272 | - * - $modules |
|
1273 | - * - $shortcodes |
|
1274 | - * - $widgets |
|
1275 | - * |
|
1276 | - * @param boolean $hard whether to reset data in the database too, or just refresh |
|
1277 | - * the Registry to its state at the beginning of the request |
|
1278 | - * @param boolean $reinstantiate whether to create new instances of EE_Registry's singletons too, |
|
1279 | - * or just reset without re-instantiating (handy to set to FALSE if you're not sure if you CAN |
|
1280 | - * currently reinstantiate the singletons at the moment) |
|
1281 | - * @param bool $reset_models Defaults to true. When false, then the models are not reset. This is so client |
|
1282 | - * code instead can just change the model context to a different blog id if necessary |
|
1283 | - * @return EE_Registry |
|
1284 | - */ |
|
1285 | - public static function reset($hard = false, $reinstantiate = true, $reset_models = true) |
|
1286 | - { |
|
1287 | - $instance = self::instance(); |
|
1288 | - $instance->_cache_on = true; |
|
1289 | - // reset some "special" classes |
|
1290 | - EEH_Activation::reset(); |
|
1291 | - $instance->CFG = $instance->CFG->reset($hard, $reinstantiate); |
|
1292 | - $instance->CART = null; |
|
1293 | - $instance->MRM = null; |
|
1294 | - $instance->AssetsRegistry = null; |
|
1295 | - $instance->AssetsRegistry = $instance->create('EventEspresso\core\services\assets\Registry'); |
|
1296 | - //messages reset |
|
1297 | - EED_Messages::reset(); |
|
1298 | - //handle of objects cached on LIB |
|
1299 | - foreach (array('LIB', 'modules') as $cache) { |
|
1300 | - foreach ($instance->{$cache} as $class_name => $class) { |
|
1301 | - if (EE_Registry::_reset_and_unset_object($class, $reset_models)) { |
|
1302 | - unset($instance->{$cache}->{$class_name}); |
|
1303 | - } |
|
1304 | - } |
|
1305 | - } |
|
1306 | - return $instance; |
|
1307 | - } |
|
1308 | - |
|
1309 | - |
|
1310 | - |
|
1311 | - /** |
|
1312 | - * if passed object implements ResettableInterface, then call it's reset() method |
|
1313 | - * if passed object implements InterminableInterface, then return false, |
|
1314 | - * to indicate that it should NOT be cleared from the Registry cache |
|
1315 | - * |
|
1316 | - * @param $object |
|
1317 | - * @param bool $reset_models |
|
1318 | - * @return bool returns true if cached object should be unset |
|
1319 | - */ |
|
1320 | - private static function _reset_and_unset_object($object, $reset_models) |
|
1321 | - { |
|
1322 | - if (! is_object($object)) { |
|
1323 | - // don't unset anything that's not an object |
|
1324 | - return false; |
|
1325 | - } |
|
1326 | - if ($object instanceof EED_Module) { |
|
1327 | - $object::reset(); |
|
1328 | - // don't unset modules |
|
1329 | - return false; |
|
1330 | - } |
|
1331 | - if ($object instanceof ResettableInterface) { |
|
1332 | - if ($object instanceof EEM_Base) { |
|
1333 | - if ($reset_models) { |
|
1334 | - $object->reset(); |
|
1335 | - return true; |
|
1336 | - } |
|
1337 | - return false; |
|
1338 | - } |
|
1339 | - $object->reset(); |
|
1340 | - return true; |
|
1341 | - } |
|
1342 | - if ( ! $object instanceof InterminableInterface) { |
|
1343 | - return true; |
|
1344 | - } |
|
1345 | - return false; |
|
1346 | - } |
|
1347 | - |
|
1348 | - |
|
1349 | - |
|
1350 | - /** |
|
1351 | - * @override magic methods |
|
1352 | - * @return void |
|
1353 | - */ |
|
1354 | - public final function __destruct() |
|
1355 | - { |
|
1356 | - } |
|
1357 | - |
|
1358 | - |
|
1359 | - |
|
1360 | - /** |
|
1361 | - * @param $a |
|
1362 | - * @param $b |
|
1363 | - */ |
|
1364 | - public final function __call($a, $b) |
|
1365 | - { |
|
1366 | - } |
|
1367 | - |
|
1368 | - |
|
1369 | - |
|
1370 | - /** |
|
1371 | - * @param $a |
|
1372 | - */ |
|
1373 | - public final function __get($a) |
|
1374 | - { |
|
1375 | - } |
|
1376 | - |
|
1377 | - |
|
1378 | - |
|
1379 | - /** |
|
1380 | - * @param $a |
|
1381 | - * @param $b |
|
1382 | - */ |
|
1383 | - public final function __set($a, $b) |
|
1384 | - { |
|
1385 | - } |
|
1386 | - |
|
1387 | - |
|
1388 | - |
|
1389 | - /** |
|
1390 | - * @param $a |
|
1391 | - */ |
|
1392 | - public final function __isset($a) |
|
1393 | - { |
|
1394 | - } |
|
22 | + /** |
|
23 | + * EE_Registry Object |
|
24 | + * |
|
25 | + * @var EE_Registry $_instance |
|
26 | + * @access private |
|
27 | + */ |
|
28 | + private static $_instance = null; |
|
29 | + |
|
30 | + /** |
|
31 | + * @var EE_Dependency_Map $_dependency_map |
|
32 | + * @access protected |
|
33 | + */ |
|
34 | + protected $_dependency_map = null; |
|
35 | + |
|
36 | + /** |
|
37 | + * @var array $_class_abbreviations |
|
38 | + * @access protected |
|
39 | + */ |
|
40 | + protected $_class_abbreviations = array(); |
|
41 | + |
|
42 | + /** |
|
43 | + * @access public |
|
44 | + * @var \EventEspresso\core\services\commands\CommandBusInterface $BUS |
|
45 | + */ |
|
46 | + public $BUS; |
|
47 | + |
|
48 | + /** |
|
49 | + * EE_Cart Object |
|
50 | + * |
|
51 | + * @access public |
|
52 | + * @var EE_Cart $CART |
|
53 | + */ |
|
54 | + public $CART = null; |
|
55 | + |
|
56 | + /** |
|
57 | + * EE_Config Object |
|
58 | + * |
|
59 | + * @access public |
|
60 | + * @var EE_Config $CFG |
|
61 | + */ |
|
62 | + public $CFG = null; |
|
63 | + |
|
64 | + /** |
|
65 | + * EE_Network_Config Object |
|
66 | + * |
|
67 | + * @access public |
|
68 | + * @var EE_Network_Config $NET_CFG |
|
69 | + */ |
|
70 | + public $NET_CFG = null; |
|
71 | + |
|
72 | + /** |
|
73 | + * StdClass object for storing library classes in |
|
74 | + * |
|
75 | + * @public LIB |
|
76 | + * @var StdClass $LIB |
|
77 | + */ |
|
78 | + public $LIB = null; |
|
79 | + |
|
80 | + /** |
|
81 | + * EE_Request_Handler Object |
|
82 | + * |
|
83 | + * @access public |
|
84 | + * @var EE_Request_Handler $REQ |
|
85 | + */ |
|
86 | + public $REQ = null; |
|
87 | + |
|
88 | + /** |
|
89 | + * EE_Session Object |
|
90 | + * |
|
91 | + * @access public |
|
92 | + * @var EE_Session $SSN |
|
93 | + */ |
|
94 | + public $SSN = null; |
|
95 | + |
|
96 | + /** |
|
97 | + * holds the ee capabilities object. |
|
98 | + * |
|
99 | + * @since 4.5.0 |
|
100 | + * @var EE_Capabilities |
|
101 | + */ |
|
102 | + public $CAP = null; |
|
103 | + |
|
104 | + /** |
|
105 | + * holds the EE_Message_Resource_Manager object. |
|
106 | + * |
|
107 | + * @since 4.9.0 |
|
108 | + * @var EE_Message_Resource_Manager |
|
109 | + */ |
|
110 | + public $MRM = null; |
|
111 | + |
|
112 | + |
|
113 | + /** |
|
114 | + * Holds the Assets Registry instance |
|
115 | + * @var Registry |
|
116 | + */ |
|
117 | + public $AssetsRegistry = null; |
|
118 | + |
|
119 | + /** |
|
120 | + * $addons - StdClass object for holding addons which have registered themselves to work with EE core |
|
121 | + * |
|
122 | + * @access public |
|
123 | + * @var EE_Addon[] |
|
124 | + */ |
|
125 | + public $addons = null; |
|
126 | + |
|
127 | + /** |
|
128 | + * $models |
|
129 | + * @access public |
|
130 | + * @var EEM_Base[] $models keys are 'short names' (eg Event), values are class names (eg 'EEM_Event') |
|
131 | + */ |
|
132 | + public $models = array(); |
|
133 | + |
|
134 | + /** |
|
135 | + * $modules |
|
136 | + * @access public |
|
137 | + * @var EED_Module[] $modules |
|
138 | + */ |
|
139 | + public $modules = null; |
|
140 | + |
|
141 | + /** |
|
142 | + * $shortcodes |
|
143 | + * @access public |
|
144 | + * @var EES_Shortcode[] $shortcodes |
|
145 | + */ |
|
146 | + public $shortcodes = null; |
|
147 | + |
|
148 | + /** |
|
149 | + * $widgets |
|
150 | + * @access public |
|
151 | + * @var WP_Widget[] $widgets |
|
152 | + */ |
|
153 | + public $widgets = null; |
|
154 | + |
|
155 | + /** |
|
156 | + * $non_abstract_db_models |
|
157 | + * @access public |
|
158 | + * @var array this is an array of all implemented model names (i.e. not the parent abstract models, or models |
|
159 | + * which don't actually fetch items from the DB in the normal way (ie, are not children of EEM_Base)). |
|
160 | + * Keys are model "short names" (eg "Event") as used in model relations, and values are |
|
161 | + * classnames (eg "EEM_Event") |
|
162 | + */ |
|
163 | + public $non_abstract_db_models = array(); |
|
164 | + |
|
165 | + |
|
166 | + /** |
|
167 | + * $i18n_js_strings - internationalization for JS strings |
|
168 | + * usage: EE_Registry::i18n_js_strings['string_key'] = __( 'string to translate.', 'event_espresso' ); |
|
169 | + * in js file: var translatedString = eei18n.string_key; |
|
170 | + * |
|
171 | + * @access public |
|
172 | + * @var array |
|
173 | + */ |
|
174 | + public static $i18n_js_strings = array(); |
|
175 | + |
|
176 | + |
|
177 | + /** |
|
178 | + * $main_file - path to espresso.php |
|
179 | + * |
|
180 | + * @access public |
|
181 | + * @var array |
|
182 | + */ |
|
183 | + public $main_file; |
|
184 | + |
|
185 | + /** |
|
186 | + * array of ReflectionClass objects where the key is the class name |
|
187 | + * |
|
188 | + * @access public |
|
189 | + * @var ReflectionClass[] |
|
190 | + */ |
|
191 | + public $_reflectors; |
|
192 | + |
|
193 | + /** |
|
194 | + * boolean flag to indicate whether or not to load/save dependencies from/to the cache |
|
195 | + * |
|
196 | + * @access protected |
|
197 | + * @var boolean $_cache_on |
|
198 | + */ |
|
199 | + protected $_cache_on = true; |
|
200 | + |
|
201 | + |
|
202 | + |
|
203 | + /** |
|
204 | + * @singleton method used to instantiate class object |
|
205 | + * @access public |
|
206 | + * @param \EE_Dependency_Map $dependency_map |
|
207 | + * @return \EE_Registry instance |
|
208 | + */ |
|
209 | + public static function instance(\EE_Dependency_Map $dependency_map = null) |
|
210 | + { |
|
211 | + // check if class object is instantiated |
|
212 | + if ( ! self::$_instance instanceof EE_Registry) { |
|
213 | + self::$_instance = new EE_Registry($dependency_map); |
|
214 | + } |
|
215 | + return self::$_instance; |
|
216 | + } |
|
217 | + |
|
218 | + |
|
219 | + |
|
220 | + /** |
|
221 | + *protected constructor to prevent direct creation |
|
222 | + * |
|
223 | + * @Constructor |
|
224 | + * @access protected |
|
225 | + * @param \EE_Dependency_Map $dependency_map |
|
226 | + */ |
|
227 | + protected function __construct(\EE_Dependency_Map $dependency_map) |
|
228 | + { |
|
229 | + $this->_dependency_map = $dependency_map; |
|
230 | + $this->LIB = new stdClass(); |
|
231 | + $this->addons = new stdClass(); |
|
232 | + $this->modules = new stdClass(); |
|
233 | + $this->shortcodes = new stdClass(); |
|
234 | + $this->widgets = new stdClass(); |
|
235 | + add_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading', array($this, 'initialize')); |
|
236 | + } |
|
237 | + |
|
238 | + |
|
239 | + |
|
240 | + /** |
|
241 | + * initialize |
|
242 | + */ |
|
243 | + public function initialize() |
|
244 | + { |
|
245 | + $this->_class_abbreviations = apply_filters( |
|
246 | + 'FHEE__EE_Registry____construct___class_abbreviations', |
|
247 | + array( |
|
248 | + 'EE_Config' => 'CFG', |
|
249 | + 'EE_Session' => 'SSN', |
|
250 | + 'EE_Capabilities' => 'CAP', |
|
251 | + 'EE_Cart' => 'CART', |
|
252 | + 'EE_Network_Config' => 'NET_CFG', |
|
253 | + 'EE_Request_Handler' => 'REQ', |
|
254 | + 'EE_Message_Resource_Manager' => 'MRM', |
|
255 | + 'EventEspresso\core\services\commands\CommandBus' => 'BUS', |
|
256 | + 'EventEspresso\core\services\assets\Registry' => 'AssetsRegistry', |
|
257 | + ) |
|
258 | + ); |
|
259 | + $this->load_core('Base', array(), true); |
|
260 | + // add our request and response objects to the cache |
|
261 | + $request_loader = $this->_dependency_map->class_loader('EE_Request'); |
|
262 | + $this->_set_cached_class( |
|
263 | + $request_loader(), |
|
264 | + 'EE_Request' |
|
265 | + ); |
|
266 | + $response_loader = $this->_dependency_map->class_loader('EE_Response'); |
|
267 | + $this->_set_cached_class( |
|
268 | + $response_loader(), |
|
269 | + 'EE_Response' |
|
270 | + ); |
|
271 | + add_action('AHEE__EE_System__set_hooks_for_core', array($this, 'init')); |
|
272 | + } |
|
273 | + |
|
274 | + |
|
275 | + |
|
276 | + /** |
|
277 | + * init |
|
278 | + * |
|
279 | + * @access public |
|
280 | + * @return void |
|
281 | + */ |
|
282 | + public function init() |
|
283 | + { |
|
284 | + // Get current page protocol |
|
285 | + $protocol = isset($_SERVER['HTTPS']) ? 'https://' : 'http://'; |
|
286 | + // Output admin-ajax.php URL with same protocol as current page |
|
287 | + self::$i18n_js_strings['ajax_url'] = admin_url('admin-ajax.php', $protocol); |
|
288 | + self::$i18n_js_strings['wp_debug'] = defined('WP_DEBUG') ? WP_DEBUG : false; |
|
289 | + } |
|
290 | + |
|
291 | + |
|
292 | + |
|
293 | + /** |
|
294 | + * localize_i18n_js_strings |
|
295 | + * |
|
296 | + * @return string |
|
297 | + */ |
|
298 | + public static function localize_i18n_js_strings() |
|
299 | + { |
|
300 | + $i18n_js_strings = (array)EE_Registry::$i18n_js_strings; |
|
301 | + foreach ($i18n_js_strings as $key => $value) { |
|
302 | + if (is_scalar($value)) { |
|
303 | + $i18n_js_strings[$key] = html_entity_decode((string)$value, ENT_QUOTES, 'UTF-8'); |
|
304 | + } |
|
305 | + } |
|
306 | + return "/* <![CDATA[ */ var eei18n = " . wp_json_encode($i18n_js_strings) . '; /* ]]> */'; |
|
307 | + } |
|
308 | + |
|
309 | + |
|
310 | + |
|
311 | + /** |
|
312 | + * @param $module |
|
313 | + * @throws ReflectionException |
|
314 | + */ |
|
315 | + public function add_module($module) |
|
316 | + { |
|
317 | + if ($module instanceof EED_Module) { |
|
318 | + $module_class = get_class($module); |
|
319 | + $this->modules->{$module_class} = $module; |
|
320 | + } else { |
|
321 | + if ( ! class_exists('EE_Module_Request_Router')) { |
|
322 | + $this->load_core('Module_Request_Router'); |
|
323 | + } |
|
324 | + EE_Module_Request_Router::module_factory($module); |
|
325 | + } |
|
326 | + } |
|
327 | + |
|
328 | + |
|
329 | + |
|
330 | + /** |
|
331 | + * @param string $module_name |
|
332 | + * @return mixed EED_Module | NULL |
|
333 | + */ |
|
334 | + public function get_module($module_name = '') |
|
335 | + { |
|
336 | + return isset($this->modules->{$module_name}) ? $this->modules->{$module_name} : null; |
|
337 | + } |
|
338 | + |
|
339 | + |
|
340 | + |
|
341 | + /** |
|
342 | + * loads core classes - must be singletons |
|
343 | + * |
|
344 | + * @access public |
|
345 | + * @param string $class_name - simple class name ie: session |
|
346 | + * @param mixed $arguments |
|
347 | + * @param bool $load_only |
|
348 | + * @return mixed |
|
349 | + */ |
|
350 | + public function load_core($class_name, $arguments = array(), $load_only = false) |
|
351 | + { |
|
352 | + $core_paths = apply_filters( |
|
353 | + 'FHEE__EE_Registry__load_core__core_paths', |
|
354 | + array( |
|
355 | + EE_CORE, |
|
356 | + EE_ADMIN, |
|
357 | + EE_CPTS, |
|
358 | + EE_CORE . 'data_migration_scripts' . DS, |
|
359 | + EE_CORE . 'request_stack' . DS, |
|
360 | + EE_CORE . 'middleware' . DS, |
|
361 | + ) |
|
362 | + ); |
|
363 | + // retrieve instantiated class |
|
364 | + return $this->_load($core_paths, 'EE_', $class_name, 'core', $arguments, false, true, $load_only); |
|
365 | + } |
|
366 | + |
|
367 | + |
|
368 | + |
|
369 | + /** |
|
370 | + * loads service classes |
|
371 | + * |
|
372 | + * @access public |
|
373 | + * @param string $class_name - simple class name ie: session |
|
374 | + * @param mixed $arguments |
|
375 | + * @param bool $load_only |
|
376 | + * @return mixed |
|
377 | + */ |
|
378 | + public function load_service($class_name, $arguments = array(), $load_only = false) |
|
379 | + { |
|
380 | + $service_paths = apply_filters( |
|
381 | + 'FHEE__EE_Registry__load_service__service_paths', |
|
382 | + array( |
|
383 | + EE_CORE . 'services' . DS, |
|
384 | + ) |
|
385 | + ); |
|
386 | + // retrieve instantiated class |
|
387 | + return $this->_load($service_paths, 'EE_', $class_name, 'class', $arguments, false, true, $load_only); |
|
388 | + } |
|
389 | + |
|
390 | + |
|
391 | + |
|
392 | + /** |
|
393 | + * loads data_migration_scripts |
|
394 | + * |
|
395 | + * @access public |
|
396 | + * @param string $class_name - class name for the DMS ie: EE_DMS_Core_4_2_0 |
|
397 | + * @param mixed $arguments |
|
398 | + * @return EE_Data_Migration_Script_Base|mixed |
|
399 | + */ |
|
400 | + public function load_dms($class_name, $arguments = array()) |
|
401 | + { |
|
402 | + // retrieve instantiated class |
|
403 | + return $this->_load(EE_Data_Migration_Manager::instance()->get_data_migration_script_folders(), 'EE_DMS_', $class_name, 'dms', $arguments, false, false, false); |
|
404 | + } |
|
405 | + |
|
406 | + |
|
407 | + |
|
408 | + /** |
|
409 | + * loads object creating classes - must be singletons |
|
410 | + * |
|
411 | + * @param string $class_name - simple class name ie: attendee |
|
412 | + * @param mixed $arguments - an array of arguments to pass to the class |
|
413 | + * @param bool $from_db - some classes are instantiated from the db and thus call a different method to instantiate |
|
414 | + * @param bool $cache if you don't want the class to be stored in the internal cache (non-persistent) then set this to FALSE (ie. when instantiating model objects from client in a loop) |
|
415 | + * @param bool $load_only whether or not to just load the file and NOT instantiate, or load AND instantiate (default) |
|
416 | + * @return EE_Base_Class | bool |
|
417 | + */ |
|
418 | + public function load_class($class_name, $arguments = array(), $from_db = false, $cache = true, $load_only = false) |
|
419 | + { |
|
420 | + $paths = apply_filters('FHEE__EE_Registry__load_class__paths', array( |
|
421 | + EE_CORE, |
|
422 | + EE_CLASSES, |
|
423 | + EE_BUSINESS, |
|
424 | + )); |
|
425 | + // retrieve instantiated class |
|
426 | + return $this->_load($paths, 'EE_', $class_name, 'class', $arguments, $from_db, $cache, $load_only); |
|
427 | + } |
|
428 | + |
|
429 | + |
|
430 | + |
|
431 | + /** |
|
432 | + * loads helper classes - must be singletons |
|
433 | + * |
|
434 | + * @param string $class_name - simple class name ie: price |
|
435 | + * @param mixed $arguments |
|
436 | + * @param bool $load_only |
|
437 | + * @return EEH_Base | bool |
|
438 | + */ |
|
439 | + public function load_helper($class_name, $arguments = array(), $load_only = true) |
|
440 | + { |
|
441 | + // todo: add doing_it_wrong() in a few versions after all addons have had calls to this method removed |
|
442 | + $helper_paths = apply_filters('FHEE__EE_Registry__load_helper__helper_paths', array(EE_HELPERS)); |
|
443 | + // retrieve instantiated class |
|
444 | + return $this->_load($helper_paths, 'EEH_', $class_name, 'helper', $arguments, false, true, $load_only); |
|
445 | + } |
|
446 | + |
|
447 | + |
|
448 | + |
|
449 | + /** |
|
450 | + * loads core classes - must be singletons |
|
451 | + * |
|
452 | + * @access public |
|
453 | + * @param string $class_name - simple class name ie: session |
|
454 | + * @param mixed $arguments |
|
455 | + * @param bool $load_only |
|
456 | + * @param bool $cache whether to cache the object or not. |
|
457 | + * @return mixed |
|
458 | + */ |
|
459 | + public function load_lib($class_name, $arguments = array(), $load_only = false, $cache = true) |
|
460 | + { |
|
461 | + $paths = array( |
|
462 | + EE_LIBRARIES, |
|
463 | + EE_LIBRARIES . 'messages' . DS, |
|
464 | + EE_LIBRARIES . 'shortcodes' . DS, |
|
465 | + EE_LIBRARIES . 'qtips' . DS, |
|
466 | + EE_LIBRARIES . 'payment_methods' . DS, |
|
467 | + ); |
|
468 | + // retrieve instantiated class |
|
469 | + return $this->_load($paths, 'EE_', $class_name, 'lib', $arguments, false, $cache, $load_only); |
|
470 | + } |
|
471 | + |
|
472 | + |
|
473 | + |
|
474 | + /** |
|
475 | + * loads model classes - must be singletons |
|
476 | + * |
|
477 | + * @param string $class_name - simple class name ie: price |
|
478 | + * @param mixed $arguments |
|
479 | + * @param bool $load_only |
|
480 | + * @return EEM_Base | bool |
|
481 | + */ |
|
482 | + public function load_model($class_name, $arguments = array(), $load_only = false) |
|
483 | + { |
|
484 | + $paths = apply_filters('FHEE__EE_Registry__load_model__paths', array( |
|
485 | + EE_MODELS, |
|
486 | + EE_CORE, |
|
487 | + )); |
|
488 | + // retrieve instantiated class |
|
489 | + return $this->_load($paths, 'EEM_', $class_name, 'model', $arguments, false, true, $load_only); |
|
490 | + } |
|
491 | + |
|
492 | + |
|
493 | + |
|
494 | + /** |
|
495 | + * loads model classes - must be singletons |
|
496 | + * |
|
497 | + * @param string $class_name - simple class name ie: price |
|
498 | + * @param mixed $arguments |
|
499 | + * @param bool $load_only |
|
500 | + * @return mixed | bool |
|
501 | + */ |
|
502 | + public function load_model_class($class_name, $arguments = array(), $load_only = true) |
|
503 | + { |
|
504 | + $paths = array( |
|
505 | + EE_MODELS . 'fields' . DS, |
|
506 | + EE_MODELS . 'helpers' . DS, |
|
507 | + EE_MODELS . 'relations' . DS, |
|
508 | + EE_MODELS . 'strategies' . DS, |
|
509 | + ); |
|
510 | + // retrieve instantiated class |
|
511 | + return $this->_load($paths, 'EE_', $class_name, '', $arguments, false, true, $load_only); |
|
512 | + } |
|
513 | + |
|
514 | + |
|
515 | + |
|
516 | + /** |
|
517 | + * Determines if $model_name is the name of an actual EE model. |
|
518 | + * |
|
519 | + * @param string $model_name like Event, Attendee, Question_Group_Question, etc. |
|
520 | + * @return boolean |
|
521 | + */ |
|
522 | + public function is_model_name($model_name) |
|
523 | + { |
|
524 | + return isset($this->models[$model_name]) ? true : false; |
|
525 | + } |
|
526 | + |
|
527 | + |
|
528 | + |
|
529 | + /** |
|
530 | + * generic class loader |
|
531 | + * |
|
532 | + * @param string $path_to_file - directory path to file location, not including filename |
|
533 | + * @param string $file_name - file name ie: my_file.php, including extension |
|
534 | + * @param string $type - file type - core? class? helper? model? |
|
535 | + * @param mixed $arguments |
|
536 | + * @param bool $load_only |
|
537 | + * @return mixed |
|
538 | + */ |
|
539 | + public function load_file($path_to_file, $file_name, $type = '', $arguments = array(), $load_only = true) |
|
540 | + { |
|
541 | + // retrieve instantiated class |
|
542 | + return $this->_load($path_to_file, '', $file_name, $type, $arguments, false, true, $load_only); |
|
543 | + } |
|
544 | + |
|
545 | + |
|
546 | + |
|
547 | + /** |
|
548 | + * load_addon |
|
549 | + * |
|
550 | + * @param string $path_to_file - directory path to file location, not including filename |
|
551 | + * @param string $class_name - full class name ie: My_Class |
|
552 | + * @param string $type - file type - core? class? helper? model? |
|
553 | + * @param mixed $arguments |
|
554 | + * @param bool $load_only |
|
555 | + * @return EE_Addon |
|
556 | + */ |
|
557 | + public function load_addon($path_to_file, $class_name, $type = 'class', $arguments = array(), $load_only = false) |
|
558 | + { |
|
559 | + // retrieve instantiated class |
|
560 | + return $this->_load($path_to_file, 'addon', $class_name, $type, $arguments, false, true, $load_only); |
|
561 | + } |
|
562 | + |
|
563 | + |
|
564 | + |
|
565 | + /** |
|
566 | + * instantiates, caches, and automatically resolves dependencies |
|
567 | + * for classes that use a Fully Qualified Class Name. |
|
568 | + * if the class is not capable of being loaded using PSR-4 autoloading, |
|
569 | + * then you need to use one of the existing load_*() methods |
|
570 | + * which can resolve the classname and filepath from the passed arguments |
|
571 | + * |
|
572 | + * @param bool|string $class_name Fully Qualified Class Name |
|
573 | + * @param array $arguments an argument, or array of arguments to pass to the class upon instantiation |
|
574 | + * @param bool $cache whether to cache the instantiated object for reuse |
|
575 | + * @param bool $from_db some classes are instantiated from the db |
|
576 | + * and thus call a different method to instantiate |
|
577 | + * @param bool $load_only if true, will only load the file, but will NOT instantiate an object |
|
578 | + * @param bool|string $addon if true, will cache the object in the EE_Registry->$addons array |
|
579 | + * @return mixed null = failure to load or instantiate class object. |
|
580 | + * object = class loaded and instantiated successfully. |
|
581 | + * bool = fail or success when $load_only is true |
|
582 | + */ |
|
583 | + public function create( |
|
584 | + $class_name = false, |
|
585 | + $arguments = array(), |
|
586 | + $cache = false, |
|
587 | + $from_db = false, |
|
588 | + $load_only = false, |
|
589 | + $addon = false |
|
590 | + ) { |
|
591 | + $class_name = ltrim($class_name, '\\'); |
|
592 | + $class_name = $this->_dependency_map->get_alias($class_name); |
|
593 | + if ( ! class_exists($class_name)) { |
|
594 | + // maybe the class is registered with a preceding \ |
|
595 | + $class_name = strpos($class_name, '\\') !== 0 ? '\\' . $class_name : $class_name; |
|
596 | + // still doesn't exist ? |
|
597 | + if ( ! class_exists($class_name)) { |
|
598 | + return null; |
|
599 | + } |
|
600 | + } |
|
601 | + // if we're only loading the class and it already exists, then let's just return true immediately |
|
602 | + if ($load_only) { |
|
603 | + return true; |
|
604 | + } |
|
605 | + $addon = $addon ? 'addon' : ''; |
|
606 | + // $this->_cache_on is toggled during the recursive loading that can occur with dependency injection |
|
607 | + // $cache is controlled by individual calls to separate Registry loader methods like load_class() |
|
608 | + // $load_only is also controlled by individual calls to separate Registry loader methods like load_file() |
|
609 | + if ($this->_cache_on && $cache && ! $load_only) { |
|
610 | + // return object if it's already cached |
|
611 | + $cached_class = $this->_get_cached_class($class_name, $addon); |
|
612 | + if ($cached_class !== null) { |
|
613 | + return $cached_class; |
|
614 | + } |
|
615 | + } |
|
616 | + // instantiate the requested object |
|
617 | + $class_obj = $this->_create_object($class_name, $arguments, $addon, $from_db); |
|
618 | + if ($this->_cache_on && $cache) { |
|
619 | + // save it for later... kinda like gum { : $ |
|
620 | + $this->_set_cached_class($class_obj, $class_name, $addon, $from_db); |
|
621 | + } |
|
622 | + $this->_cache_on = true; |
|
623 | + return $class_obj; |
|
624 | + } |
|
625 | + |
|
626 | + |
|
627 | + |
|
628 | + /** |
|
629 | + * instantiates, caches, and injects dependencies for classes |
|
630 | + * |
|
631 | + * @param array $file_paths an array of paths to folders to look in |
|
632 | + * @param string $class_prefix EE or EEM or... ??? |
|
633 | + * @param bool|string $class_name $class name |
|
634 | + * @param string $type file type - core? class? helper? model? |
|
635 | + * @param mixed $arguments an argument or array of arguments to pass to the class upon instantiation |
|
636 | + * @param bool $from_db some classes are instantiated from the db |
|
637 | + * and thus call a different method to instantiate |
|
638 | + * @param bool $cache whether to cache the instantiated object for reuse |
|
639 | + * @param bool $load_only if true, will only load the file, but will NOT instantiate an object |
|
640 | + * @return null|object|bool null = failure to load or instantiate class object. |
|
641 | + * object = class loaded and instantiated successfully. |
|
642 | + * bool = fail or success when $load_only is true |
|
643 | + */ |
|
644 | + protected function _load( |
|
645 | + $file_paths = array(), |
|
646 | + $class_prefix = 'EE_', |
|
647 | + $class_name = false, |
|
648 | + $type = 'class', |
|
649 | + $arguments = array(), |
|
650 | + $from_db = false, |
|
651 | + $cache = true, |
|
652 | + $load_only = false |
|
653 | + ) { |
|
654 | + $class_name = ltrim($class_name, '\\'); |
|
655 | + // strip php file extension |
|
656 | + $class_name = str_replace('.php', '', trim($class_name)); |
|
657 | + // does the class have a prefix ? |
|
658 | + if ( ! empty($class_prefix) && $class_prefix != 'addon') { |
|
659 | + // make sure $class_prefix is uppercase |
|
660 | + $class_prefix = strtoupper(trim($class_prefix)); |
|
661 | + // add class prefix ONCE!!! |
|
662 | + $class_name = $class_prefix . str_replace($class_prefix, '', $class_name); |
|
663 | + } |
|
664 | + $class_name = $this->_dependency_map->get_alias($class_name); |
|
665 | + $class_exists = class_exists($class_name); |
|
666 | + // if we're only loading the class and it already exists, then let's just return true immediately |
|
667 | + if ($load_only && $class_exists) { |
|
668 | + return true; |
|
669 | + } |
|
670 | + // $this->_cache_on is toggled during the recursive loading that can occur with dependency injection |
|
671 | + // $cache is controlled by individual calls to separate Registry loader methods like load_class() |
|
672 | + // $load_only is also controlled by individual calls to separate Registry loader methods like load_file() |
|
673 | + if ($this->_cache_on && $cache && ! $load_only) { |
|
674 | + // return object if it's already cached |
|
675 | + $cached_class = $this->_get_cached_class($class_name, $class_prefix); |
|
676 | + if ($cached_class !== null) { |
|
677 | + return $cached_class; |
|
678 | + } |
|
679 | + } |
|
680 | + // if the class doesn't already exist.. then we need to try and find the file and load it |
|
681 | + if ( ! $class_exists) { |
|
682 | + // get full path to file |
|
683 | + $path = $this->_resolve_path($class_name, $type, $file_paths); |
|
684 | + // load the file |
|
685 | + $loaded = $this->_require_file($path, $class_name, $type, $file_paths); |
|
686 | + // if loading failed, or we are only loading a file but NOT instantiating an object |
|
687 | + if ( ! $loaded || $load_only) { |
|
688 | + // return boolean if only loading, or null if an object was expected |
|
689 | + return $load_only ? $loaded : null; |
|
690 | + } |
|
691 | + } |
|
692 | + // instantiate the requested object |
|
693 | + $class_obj = $this->_create_object($class_name, $arguments, $type, $from_db); |
|
694 | + if ($this->_cache_on && $cache) { |
|
695 | + // save it for later... kinda like gum { : $ |
|
696 | + $this->_set_cached_class($class_obj, $class_name, $class_prefix, $from_db); |
|
697 | + } |
|
698 | + $this->_cache_on = true; |
|
699 | + return $class_obj; |
|
700 | + } |
|
701 | + |
|
702 | + |
|
703 | + |
|
704 | + |
|
705 | + /** |
|
706 | + * _get_cached_class |
|
707 | + * attempts to find a cached version of the requested class |
|
708 | + * by looking in the following places: |
|
709 | + * $this->{$class_abbreviation} ie: $this->CART |
|
710 | + * $this->{$class_name} ie: $this->Some_Class |
|
711 | + * $this->LIB->{$class_name} ie: $this->LIB->Some_Class |
|
712 | + * $this->addon->{$class_name} ie: $this->addon->Some_Addon_Class |
|
713 | + * |
|
714 | + * @access protected |
|
715 | + * @param string $class_name |
|
716 | + * @param string $class_prefix |
|
717 | + * @return mixed |
|
718 | + */ |
|
719 | + protected function _get_cached_class($class_name, $class_prefix = '') |
|
720 | + { |
|
721 | + if ($class_name === 'EE_Registry') { |
|
722 | + return $this; |
|
723 | + } |
|
724 | + // have to specify something, but not anything that will conflict |
|
725 | + $class_abbreviation = isset($this->_class_abbreviations[ $class_name ]) |
|
726 | + ? $this->_class_abbreviations[ $class_name ] |
|
727 | + : 'FANCY_BATMAN_PANTS'; |
|
728 | + $class_name = str_replace('\\', '_', $class_name); |
|
729 | + // check if class has already been loaded, and return it if it has been |
|
730 | + if (isset($this->{$class_abbreviation}) && ! is_null($this->{$class_abbreviation})) { |
|
731 | + return $this->{$class_abbreviation}; |
|
732 | + } |
|
733 | + if (isset ($this->{$class_name})) { |
|
734 | + return $this->{$class_name}; |
|
735 | + } |
|
736 | + if (isset ($this->LIB->{$class_name})) { |
|
737 | + return $this->LIB->{$class_name}; |
|
738 | + } |
|
739 | + if ($class_prefix === 'addon' && isset ($this->addons->{$class_name})) { |
|
740 | + return $this->addons->{$class_name}; |
|
741 | + } |
|
742 | + return null; |
|
743 | + } |
|
744 | + |
|
745 | + |
|
746 | + |
|
747 | + /** |
|
748 | + * removes a cached version of the requested class |
|
749 | + * |
|
750 | + * @param string $class_name |
|
751 | + * @param boolean $addon |
|
752 | + * @return boolean |
|
753 | + */ |
|
754 | + public function clear_cached_class($class_name, $addon = false) |
|
755 | + { |
|
756 | + // have to specify something, but not anything that will conflict |
|
757 | + $class_abbreviation = isset($this->_class_abbreviations[ $class_name ]) |
|
758 | + ? $this->_class_abbreviations[ $class_name ] |
|
759 | + : 'FANCY_BATMAN_PANTS'; |
|
760 | + $class_name = str_replace('\\', '_', $class_name); |
|
761 | + // check if class has already been loaded, and return it if it has been |
|
762 | + if (isset($this->{$class_abbreviation}) && ! is_null($this->{$class_abbreviation})) { |
|
763 | + $this->{$class_abbreviation} = null; |
|
764 | + return true; |
|
765 | + } |
|
766 | + if (isset($this->{$class_name})) { |
|
767 | + $this->{$class_name} = null; |
|
768 | + return true; |
|
769 | + } |
|
770 | + if (isset($this->LIB->{$class_name})) { |
|
771 | + unset($this->LIB->{$class_name}); |
|
772 | + return true; |
|
773 | + } |
|
774 | + if ($addon && isset($this->addons->{$class_name})) { |
|
775 | + unset($this->addons->{$class_name}); |
|
776 | + return true; |
|
777 | + } |
|
778 | + return false; |
|
779 | + } |
|
780 | + |
|
781 | + |
|
782 | + /** |
|
783 | + * _resolve_path |
|
784 | + * attempts to find a full valid filepath for the requested class. |
|
785 | + * loops thru each of the base paths in the $file_paths array and appends : "{classname} . {file type} . php" |
|
786 | + * then returns that path if the target file has been found and is readable |
|
787 | + * |
|
788 | + * @access protected |
|
789 | + * @param string $class_name |
|
790 | + * @param string $type |
|
791 | + * @param array $file_paths |
|
792 | + * @return string | bool |
|
793 | + */ |
|
794 | + protected function _resolve_path($class_name, $type = '', $file_paths = array()) |
|
795 | + { |
|
796 | + // make sure $file_paths is an array |
|
797 | + $file_paths = is_array($file_paths) ? $file_paths : array($file_paths); |
|
798 | + // cycle thru paths |
|
799 | + foreach ($file_paths as $key => $file_path) { |
|
800 | + // convert all separators to proper DS, if no filepath, then use EE_CLASSES |
|
801 | + $file_path = $file_path ? str_replace(array('/', '\\'), DS, $file_path) : EE_CLASSES; |
|
802 | + // prep file type |
|
803 | + $type = ! empty($type) ? trim($type, '.') . '.' : ''; |
|
804 | + // build full file path |
|
805 | + $file_paths[$key] = rtrim($file_path, DS) . DS . $class_name . '.' . $type . 'php'; |
|
806 | + //does the file exist and can be read ? |
|
807 | + if (is_readable($file_paths[$key])) { |
|
808 | + return $file_paths[$key]; |
|
809 | + } |
|
810 | + } |
|
811 | + return false; |
|
812 | + } |
|
813 | + |
|
814 | + |
|
815 | + |
|
816 | + /** |
|
817 | + * _require_file |
|
818 | + * basically just performs a require_once() |
|
819 | + * but with some error handling |
|
820 | + * |
|
821 | + * @access protected |
|
822 | + * @param string $path |
|
823 | + * @param string $class_name |
|
824 | + * @param string $type |
|
825 | + * @param array $file_paths |
|
826 | + * @return boolean |
|
827 | + * @throws \EE_Error |
|
828 | + */ |
|
829 | + protected function _require_file($path, $class_name, $type = '', $file_paths = array()) |
|
830 | + { |
|
831 | + // don't give up! you gotta... |
|
832 | + try { |
|
833 | + //does the file exist and can it be read ? |
|
834 | + if ( ! $path) { |
|
835 | + // so sorry, can't find the file |
|
836 | + throw new EE_Error ( |
|
837 | + sprintf( |
|
838 | + __('The %1$s file %2$s could not be located or is not readable due to file permissions. Please ensure that the following filepath(s) are correct: %3$s', 'event_espresso'), |
|
839 | + trim($type, '.'), |
|
840 | + $class_name, |
|
841 | + '<br />' . implode(',<br />', $file_paths) |
|
842 | + ) |
|
843 | + ); |
|
844 | + } |
|
845 | + // get the file |
|
846 | + require_once($path); |
|
847 | + // if the class isn't already declared somewhere |
|
848 | + if (class_exists($class_name, false) === false) { |
|
849 | + // so sorry, not a class |
|
850 | + throw new EE_Error( |
|
851 | + sprintf( |
|
852 | + __('The %s file %s does not appear to contain the %s Class.', 'event_espresso'), |
|
853 | + $type, |
|
854 | + $path, |
|
855 | + $class_name |
|
856 | + ) |
|
857 | + ); |
|
858 | + } |
|
859 | + } catch (EE_Error $e) { |
|
860 | + $e->get_error(); |
|
861 | + return false; |
|
862 | + } |
|
863 | + return true; |
|
864 | + } |
|
865 | + |
|
866 | + |
|
867 | + |
|
868 | + /** |
|
869 | + * _create_object |
|
870 | + * Attempts to instantiate the requested class via any of the |
|
871 | + * commonly used instantiation methods employed throughout EE. |
|
872 | + * The priority for instantiation is as follows: |
|
873 | + * - abstract classes or any class flagged as "load only" (no instantiation occurs) |
|
874 | + * - model objects via their 'new_instance_from_db' method |
|
875 | + * - model objects via their 'new_instance' method |
|
876 | + * - "singleton" classes" via their 'instance' method |
|
877 | + * - standard instantiable classes via their __constructor |
|
878 | + * Prior to instantiation, if the classname exists in the dependency_map, |
|
879 | + * then the constructor for the requested class will be examined to determine |
|
880 | + * if any dependencies exist, and if they can be injected. |
|
881 | + * If so, then those classes will be added to the array of arguments passed to the constructor |
|
882 | + * |
|
883 | + * @access protected |
|
884 | + * @param string $class_name |
|
885 | + * @param array $arguments |
|
886 | + * @param string $type |
|
887 | + * @param bool $from_db |
|
888 | + * @return null | object |
|
889 | + * @throws \EE_Error |
|
890 | + */ |
|
891 | + protected function _create_object($class_name, $arguments = array(), $type = '', $from_db = false) |
|
892 | + { |
|
893 | + $class_obj = null; |
|
894 | + $instantiation_mode = '0) none'; |
|
895 | + // don't give up! you gotta... |
|
896 | + try { |
|
897 | + // create reflection |
|
898 | + $reflector = $this->get_ReflectionClass($class_name); |
|
899 | + // make sure arguments are an array |
|
900 | + $arguments = is_array($arguments) ? $arguments : array($arguments); |
|
901 | + // and if arguments array is numerically and sequentially indexed, then we want it to remain as is, |
|
902 | + // else wrap it in an additional array so that it doesn't get split into multiple parameters |
|
903 | + $arguments = $this->_array_is_numerically_and_sequentially_indexed($arguments) |
|
904 | + ? $arguments |
|
905 | + : array($arguments); |
|
906 | + // attempt to inject dependencies ? |
|
907 | + if ($this->_dependency_map->has($class_name)) { |
|
908 | + $arguments = $this->_resolve_dependencies($reflector, $class_name, $arguments); |
|
909 | + } |
|
910 | + // instantiate the class if possible |
|
911 | + if ($reflector->isAbstract()) { |
|
912 | + // nothing to instantiate, loading file was enough |
|
913 | + // does not throw an exception so $instantiation_mode is unused |
|
914 | + // $instantiation_mode = "1) no constructor abstract class"; |
|
915 | + $class_obj = true; |
|
916 | + } else if ($reflector->getConstructor() === null && $reflector->isInstantiable() && empty($arguments)) { |
|
917 | + // no constructor = static methods only... nothing to instantiate, loading file was enough |
|
918 | + $instantiation_mode = "2) no constructor but instantiable"; |
|
919 | + $class_obj = $reflector->newInstance(); |
|
920 | + } else if ($from_db && method_exists($class_name, 'new_instance_from_db')) { |
|
921 | + $instantiation_mode = "3) new_instance_from_db()"; |
|
922 | + $class_obj = call_user_func_array(array($class_name, 'new_instance_from_db'), $arguments); |
|
923 | + } else if (method_exists($class_name, 'new_instance')) { |
|
924 | + $instantiation_mode = "4) new_instance()"; |
|
925 | + $class_obj = call_user_func_array(array($class_name, 'new_instance'), $arguments); |
|
926 | + } else if (method_exists($class_name, 'instance')) { |
|
927 | + $instantiation_mode = "5) instance()"; |
|
928 | + $class_obj = call_user_func_array(array($class_name, 'instance'), $arguments); |
|
929 | + } else if ($reflector->isInstantiable()) { |
|
930 | + $instantiation_mode = "6) constructor"; |
|
931 | + $class_obj = $reflector->newInstanceArgs($arguments); |
|
932 | + } else { |
|
933 | + // heh ? something's not right ! |
|
934 | + throw new EE_Error( |
|
935 | + sprintf( |
|
936 | + __('The %s file %s could not be instantiated.', 'event_espresso'), |
|
937 | + $type, |
|
938 | + $class_name |
|
939 | + ) |
|
940 | + ); |
|
941 | + } |
|
942 | + } catch (Exception $e) { |
|
943 | + if ( ! $e instanceof EE_Error) { |
|
944 | + $e = new EE_Error( |
|
945 | + sprintf( |
|
946 | + __('The following error occurred while attempting to instantiate "%1$s": %2$s %3$s %2$s instantiation mode : %4$s', 'event_espresso'), |
|
947 | + $class_name, |
|
948 | + '<br />', |
|
949 | + $e->getMessage(), |
|
950 | + $instantiation_mode |
|
951 | + ) |
|
952 | + ); |
|
953 | + } |
|
954 | + $e->get_error(); |
|
955 | + } |
|
956 | + return $class_obj; |
|
957 | + } |
|
958 | + |
|
959 | + |
|
960 | + |
|
961 | + /** |
|
962 | + * @see http://stackoverflow.com/questions/173400/how-to-check-if-php-array-is-associative-or-sequential |
|
963 | + * @param array $array |
|
964 | + * @return bool |
|
965 | + */ |
|
966 | + protected function _array_is_numerically_and_sequentially_indexed(array $array) |
|
967 | + { |
|
968 | + return ! empty($array) ? array_keys($array) === range(0, count($array) - 1) : true; |
|
969 | + } |
|
970 | + |
|
971 | + |
|
972 | + |
|
973 | + /** |
|
974 | + * getReflectionClass |
|
975 | + * checks if a ReflectionClass object has already been generated for a class |
|
976 | + * and returns that instead of creating a new one |
|
977 | + * |
|
978 | + * @access public |
|
979 | + * @param string $class_name |
|
980 | + * @return ReflectionClass |
|
981 | + */ |
|
982 | + public function get_ReflectionClass($class_name) |
|
983 | + { |
|
984 | + if ( |
|
985 | + ! isset($this->_reflectors[$class_name]) |
|
986 | + || ! $this->_reflectors[$class_name] instanceof ReflectionClass |
|
987 | + ) { |
|
988 | + $this->_reflectors[$class_name] = new ReflectionClass($class_name); |
|
989 | + } |
|
990 | + return $this->_reflectors[$class_name]; |
|
991 | + } |
|
992 | + |
|
993 | + |
|
994 | + |
|
995 | + /** |
|
996 | + * _resolve_dependencies |
|
997 | + * examines the constructor for the requested class to determine |
|
998 | + * if any dependencies exist, and if they can be injected. |
|
999 | + * If so, then those classes will be added to the array of arguments passed to the constructor |
|
1000 | + * PLZ NOTE: this is achieved by type hinting the constructor params |
|
1001 | + * For example: |
|
1002 | + * if attempting to load a class "Foo" with the following constructor: |
|
1003 | + * __construct( Bar $bar_class, Fighter $grohl_class ) |
|
1004 | + * then $bar_class and $grohl_class will be added to the $arguments array, |
|
1005 | + * but only IF they are NOT already present in the incoming arguments array, |
|
1006 | + * and the correct classes can be loaded |
|
1007 | + * |
|
1008 | + * @access protected |
|
1009 | + * @param ReflectionClass $reflector |
|
1010 | + * @param string $class_name |
|
1011 | + * @param array $arguments |
|
1012 | + * @return array |
|
1013 | + * @throws \ReflectionException |
|
1014 | + */ |
|
1015 | + protected function _resolve_dependencies(ReflectionClass $reflector, $class_name, $arguments = array()) |
|
1016 | + { |
|
1017 | + // let's examine the constructor |
|
1018 | + $constructor = $reflector->getConstructor(); |
|
1019 | + // whu? huh? nothing? |
|
1020 | + if ( ! $constructor) { |
|
1021 | + return $arguments; |
|
1022 | + } |
|
1023 | + // get constructor parameters |
|
1024 | + $params = $constructor->getParameters(); |
|
1025 | + // and the keys for the incoming arguments array so that we can compare existing arguments with what is expected |
|
1026 | + $argument_keys = array_keys($arguments); |
|
1027 | + // now loop thru all of the constructors expected parameters |
|
1028 | + foreach ($params as $index => $param) { |
|
1029 | + // is this a dependency for a specific class ? |
|
1030 | + $param_class = $param->getClass() ? $param->getClass()->name : null; |
|
1031 | + // BUT WAIT !!! This class may be an alias for something else (or getting replaced at runtime) |
|
1032 | + $param_class = $this->_dependency_map->has_alias($param_class, $class_name) |
|
1033 | + ? $this->_dependency_map->get_alias($param_class, $class_name) |
|
1034 | + : $param_class; |
|
1035 | + if ( |
|
1036 | + // param is not even a class |
|
1037 | + empty($param_class) |
|
1038 | + // and something already exists in the incoming arguments for this param |
|
1039 | + && isset($argument_keys[$index], $arguments[$argument_keys[$index]]) |
|
1040 | + ) { |
|
1041 | + // so let's skip this argument and move on to the next |
|
1042 | + continue; |
|
1043 | + } |
|
1044 | + if ( |
|
1045 | + // parameter is type hinted as a class, exists as an incoming argument, AND it's the correct class |
|
1046 | + ! empty($param_class) |
|
1047 | + && isset($argument_keys[$index], $arguments[$argument_keys[$index]]) |
|
1048 | + && $arguments[$argument_keys[$index]] instanceof $param_class |
|
1049 | + ) { |
|
1050 | + // skip this argument and move on to the next |
|
1051 | + continue; |
|
1052 | + } |
|
1053 | + if ( |
|
1054 | + // parameter is type hinted as a class, and should be injected |
|
1055 | + ! empty($param_class) |
|
1056 | + && $this->_dependency_map->has_dependency_for_class($class_name, $param_class) |
|
1057 | + ) { |
|
1058 | + $arguments = $this->_resolve_dependency($class_name, $param_class, $arguments, $index); |
|
1059 | + } else { |
|
1060 | + try { |
|
1061 | + $arguments[$index] = $param->getDefaultValue(); |
|
1062 | + } catch (ReflectionException $e) { |
|
1063 | + throw new ReflectionException( |
|
1064 | + sprintf( |
|
1065 | + __('%1$s for parameter "$%2$s"', 'event_espresso'), |
|
1066 | + $e->getMessage(), |
|
1067 | + $param->getName() |
|
1068 | + ) |
|
1069 | + ); |
|
1070 | + } |
|
1071 | + } |
|
1072 | + } |
|
1073 | + return $arguments; |
|
1074 | + } |
|
1075 | + |
|
1076 | + |
|
1077 | + |
|
1078 | + /** |
|
1079 | + * @access protected |
|
1080 | + * @param string $class_name |
|
1081 | + * @param string $param_class |
|
1082 | + * @param array $arguments |
|
1083 | + * @param mixed $index |
|
1084 | + * @return array |
|
1085 | + */ |
|
1086 | + protected function _resolve_dependency($class_name, $param_class, $arguments, $index) |
|
1087 | + { |
|
1088 | + $dependency = null; |
|
1089 | + // should dependency be loaded from cache ? |
|
1090 | + $cache_on = $this->_dependency_map->loading_strategy_for_class_dependency($class_name, $param_class) |
|
1091 | + !== EE_Dependency_Map::load_new_object |
|
1092 | + ? true |
|
1093 | + : false; |
|
1094 | + // we might have a dependency... |
|
1095 | + // let's MAYBE try and find it in our cache if that's what's been requested |
|
1096 | + $cached_class = $cache_on ? $this->_get_cached_class($param_class) : null; |
|
1097 | + // and grab it if it exists |
|
1098 | + if ($cached_class instanceof $param_class) { |
|
1099 | + $dependency = $cached_class; |
|
1100 | + } else if ($param_class !== $class_name) { |
|
1101 | + // obtain the loader method from the dependency map |
|
1102 | + $loader = $this->_dependency_map->class_loader($param_class); |
|
1103 | + // is loader a custom closure ? |
|
1104 | + if ($loader instanceof Closure) { |
|
1105 | + $dependency = $loader(); |
|
1106 | + } else { |
|
1107 | + // set the cache on property for the recursive loading call |
|
1108 | + $this->_cache_on = $cache_on; |
|
1109 | + // if not, then let's try and load it via the registry |
|
1110 | + if ($loader && method_exists($this, $loader)) { |
|
1111 | + $dependency = $this->{$loader}($param_class); |
|
1112 | + } else { |
|
1113 | + $dependency = $this->create($param_class, array(), $cache_on); |
|
1114 | + } |
|
1115 | + } |
|
1116 | + } |
|
1117 | + // did we successfully find the correct dependency ? |
|
1118 | + if ($dependency instanceof $param_class) { |
|
1119 | + // then let's inject it into the incoming array of arguments at the correct location |
|
1120 | + if (isset($argument_keys[$index])) { |
|
1121 | + $arguments[$argument_keys[$index]] = $dependency; |
|
1122 | + } else { |
|
1123 | + $arguments[$index] = $dependency; |
|
1124 | + } |
|
1125 | + } |
|
1126 | + return $arguments; |
|
1127 | + } |
|
1128 | + |
|
1129 | + |
|
1130 | + |
|
1131 | + /** |
|
1132 | + * _set_cached_class |
|
1133 | + * attempts to cache the instantiated class locally |
|
1134 | + * in one of the following places, in the following order: |
|
1135 | + * $this->{class_abbreviation} ie: $this->CART |
|
1136 | + * $this->{$class_name} ie: $this->Some_Class |
|
1137 | + * $this->addon->{$$class_name} ie: $this->addon->Some_Addon_Class |
|
1138 | + * $this->LIB->{$class_name} ie: $this->LIB->Some_Class |
|
1139 | + * |
|
1140 | + * @access protected |
|
1141 | + * @param object $class_obj |
|
1142 | + * @param string $class_name |
|
1143 | + * @param string $class_prefix |
|
1144 | + * @param bool $from_db |
|
1145 | + * @return void |
|
1146 | + */ |
|
1147 | + protected function _set_cached_class($class_obj, $class_name, $class_prefix = '', $from_db = false) |
|
1148 | + { |
|
1149 | + if ($class_name === 'EE_Registry' || empty($class_obj)) { |
|
1150 | + return; |
|
1151 | + } |
|
1152 | + // return newly instantiated class |
|
1153 | + if (isset($this->_class_abbreviations[$class_name])) { |
|
1154 | + $class_abbreviation = $this->_class_abbreviations[$class_name]; |
|
1155 | + $this->{$class_abbreviation} = $class_obj; |
|
1156 | + return; |
|
1157 | + } |
|
1158 | + $class_name = str_replace('\\', '_', $class_name); |
|
1159 | + if (property_exists($this, $class_name)) { |
|
1160 | + $this->{$class_name} = $class_obj; |
|
1161 | + return; |
|
1162 | + } |
|
1163 | + if ($class_prefix === 'addon') { |
|
1164 | + $this->addons->{$class_name} = $class_obj; |
|
1165 | + return; |
|
1166 | + } |
|
1167 | + if ( ! $from_db) { |
|
1168 | + $this->LIB->{$class_name} = $class_obj; |
|
1169 | + } |
|
1170 | + } |
|
1171 | + |
|
1172 | + |
|
1173 | + |
|
1174 | + /** |
|
1175 | + * call any loader that's been registered in the EE_Dependency_Map::$_class_loaders array |
|
1176 | + * |
|
1177 | + * @param string $classname PLEASE NOTE: the class name needs to match what's registered |
|
1178 | + * in the EE_Dependency_Map::$_class_loaders array, |
|
1179 | + * including the class prefix, ie: "EE_", "EEM_", "EEH_", etc |
|
1180 | + * @param array $arguments |
|
1181 | + * @return object |
|
1182 | + */ |
|
1183 | + public static function factory($classname, $arguments = array()) |
|
1184 | + { |
|
1185 | + $loader = self::instance()->_dependency_map->class_loader($classname); |
|
1186 | + if ($loader instanceof Closure) { |
|
1187 | + return $loader($arguments); |
|
1188 | + } |
|
1189 | + if (method_exists(EE_Registry::instance(), $loader)) { |
|
1190 | + return EE_Registry::instance()->{$loader}($classname, $arguments); |
|
1191 | + } |
|
1192 | + return null; |
|
1193 | + } |
|
1194 | + |
|
1195 | + |
|
1196 | + |
|
1197 | + /** |
|
1198 | + * Gets the addon by its name/slug (not classname. For that, just |
|
1199 | + * use the classname as the property name on EE_Config::instance()->addons) |
|
1200 | + * |
|
1201 | + * @param string $name |
|
1202 | + * @return EE_Addon |
|
1203 | + */ |
|
1204 | + public function get_addon_by_name($name) |
|
1205 | + { |
|
1206 | + foreach ($this->addons as $addon) { |
|
1207 | + if ($addon->name() == $name) { |
|
1208 | + return $addon; |
|
1209 | + } |
|
1210 | + } |
|
1211 | + return null; |
|
1212 | + } |
|
1213 | + |
|
1214 | + |
|
1215 | + |
|
1216 | + /** |
|
1217 | + * Gets an array of all the registered addons, where the keys are their names. (ie, what each returns for their name() function) They're already available on EE_Config::instance()->addons as properties, where each property's name is |
|
1218 | + * the addon's classname. So if you just want to get the addon by classname, use EE_Config::instance()->addons->{classname} |
|
1219 | + * |
|
1220 | + * @return EE_Addon[] where the KEYS are the addon's name() |
|
1221 | + */ |
|
1222 | + public function get_addons_by_name() |
|
1223 | + { |
|
1224 | + $addons = array(); |
|
1225 | + foreach ($this->addons as $addon) { |
|
1226 | + $addons[$addon->name()] = $addon; |
|
1227 | + } |
|
1228 | + return $addons; |
|
1229 | + } |
|
1230 | + |
|
1231 | + |
|
1232 | + |
|
1233 | + /** |
|
1234 | + * Resets the specified model's instance AND makes sure EE_Registry doesn't keep |
|
1235 | + * a stale copy of it around |
|
1236 | + * |
|
1237 | + * @param string $model_name |
|
1238 | + * @return \EEM_Base |
|
1239 | + * @throws \EE_Error |
|
1240 | + */ |
|
1241 | + public function reset_model($model_name) |
|
1242 | + { |
|
1243 | + $model_class_name = strpos($model_name, 'EEM_') !== 0 ? "EEM_{$model_name}" : $model_name; |
|
1244 | + if ( ! isset($this->LIB->{$model_class_name}) || ! $this->LIB->{$model_class_name} instanceof EEM_Base) { |
|
1245 | + return null; |
|
1246 | + } |
|
1247 | + //get that model reset it and make sure we nuke the old reference to it |
|
1248 | + if ($this->LIB->{$model_class_name} instanceof $model_class_name && is_callable(array($model_class_name, 'reset'))) { |
|
1249 | + $this->LIB->{$model_class_name} = $this->LIB->{$model_class_name}->reset(); |
|
1250 | + } else { |
|
1251 | + throw new EE_Error(sprintf(__('Model %s does not have a method "reset"', 'event_espresso'), $model_name)); |
|
1252 | + } |
|
1253 | + return $this->LIB->{$model_class_name}; |
|
1254 | + } |
|
1255 | + |
|
1256 | + |
|
1257 | + |
|
1258 | + /** |
|
1259 | + * Resets the registry. |
|
1260 | + * The criteria for what gets reset is based on what can be shared between sites on the same request when switch_to_blog |
|
1261 | + * is used in a multisite install. Here is a list of things that are NOT reset. |
|
1262 | + * - $_dependency_map |
|
1263 | + * - $_class_abbreviations |
|
1264 | + * - $NET_CFG (EE_Network_Config): The config is shared network wide so no need to reset. |
|
1265 | + * - $REQ: Still on the same request so no need to change. |
|
1266 | + * - $CAP: There is no site specific state in the EE_Capability class. |
|
1267 | + * - $SSN: Although ideally, the session should not be shared between site switches, we can't reset it because only one Session |
|
1268 | + * can be active in a single request. Resetting could resolve in "headers already sent" errors. |
|
1269 | + * - $addons: In multisite, the state of the addons is something controlled via hooks etc in a normal request. So |
|
1270 | + * for now, we won't reset the addons because it could break calls to an add-ons class/methods in the |
|
1271 | + * switch or on the restore. |
|
1272 | + * - $modules |
|
1273 | + * - $shortcodes |
|
1274 | + * - $widgets |
|
1275 | + * |
|
1276 | + * @param boolean $hard whether to reset data in the database too, or just refresh |
|
1277 | + * the Registry to its state at the beginning of the request |
|
1278 | + * @param boolean $reinstantiate whether to create new instances of EE_Registry's singletons too, |
|
1279 | + * or just reset without re-instantiating (handy to set to FALSE if you're not sure if you CAN |
|
1280 | + * currently reinstantiate the singletons at the moment) |
|
1281 | + * @param bool $reset_models Defaults to true. When false, then the models are not reset. This is so client |
|
1282 | + * code instead can just change the model context to a different blog id if necessary |
|
1283 | + * @return EE_Registry |
|
1284 | + */ |
|
1285 | + public static function reset($hard = false, $reinstantiate = true, $reset_models = true) |
|
1286 | + { |
|
1287 | + $instance = self::instance(); |
|
1288 | + $instance->_cache_on = true; |
|
1289 | + // reset some "special" classes |
|
1290 | + EEH_Activation::reset(); |
|
1291 | + $instance->CFG = $instance->CFG->reset($hard, $reinstantiate); |
|
1292 | + $instance->CART = null; |
|
1293 | + $instance->MRM = null; |
|
1294 | + $instance->AssetsRegistry = null; |
|
1295 | + $instance->AssetsRegistry = $instance->create('EventEspresso\core\services\assets\Registry'); |
|
1296 | + //messages reset |
|
1297 | + EED_Messages::reset(); |
|
1298 | + //handle of objects cached on LIB |
|
1299 | + foreach (array('LIB', 'modules') as $cache) { |
|
1300 | + foreach ($instance->{$cache} as $class_name => $class) { |
|
1301 | + if (EE_Registry::_reset_and_unset_object($class, $reset_models)) { |
|
1302 | + unset($instance->{$cache}->{$class_name}); |
|
1303 | + } |
|
1304 | + } |
|
1305 | + } |
|
1306 | + return $instance; |
|
1307 | + } |
|
1308 | + |
|
1309 | + |
|
1310 | + |
|
1311 | + /** |
|
1312 | + * if passed object implements ResettableInterface, then call it's reset() method |
|
1313 | + * if passed object implements InterminableInterface, then return false, |
|
1314 | + * to indicate that it should NOT be cleared from the Registry cache |
|
1315 | + * |
|
1316 | + * @param $object |
|
1317 | + * @param bool $reset_models |
|
1318 | + * @return bool returns true if cached object should be unset |
|
1319 | + */ |
|
1320 | + private static function _reset_and_unset_object($object, $reset_models) |
|
1321 | + { |
|
1322 | + if (! is_object($object)) { |
|
1323 | + // don't unset anything that's not an object |
|
1324 | + return false; |
|
1325 | + } |
|
1326 | + if ($object instanceof EED_Module) { |
|
1327 | + $object::reset(); |
|
1328 | + // don't unset modules |
|
1329 | + return false; |
|
1330 | + } |
|
1331 | + if ($object instanceof ResettableInterface) { |
|
1332 | + if ($object instanceof EEM_Base) { |
|
1333 | + if ($reset_models) { |
|
1334 | + $object->reset(); |
|
1335 | + return true; |
|
1336 | + } |
|
1337 | + return false; |
|
1338 | + } |
|
1339 | + $object->reset(); |
|
1340 | + return true; |
|
1341 | + } |
|
1342 | + if ( ! $object instanceof InterminableInterface) { |
|
1343 | + return true; |
|
1344 | + } |
|
1345 | + return false; |
|
1346 | + } |
|
1347 | + |
|
1348 | + |
|
1349 | + |
|
1350 | + /** |
|
1351 | + * @override magic methods |
|
1352 | + * @return void |
|
1353 | + */ |
|
1354 | + public final function __destruct() |
|
1355 | + { |
|
1356 | + } |
|
1357 | + |
|
1358 | + |
|
1359 | + |
|
1360 | + /** |
|
1361 | + * @param $a |
|
1362 | + * @param $b |
|
1363 | + */ |
|
1364 | + public final function __call($a, $b) |
|
1365 | + { |
|
1366 | + } |
|
1367 | + |
|
1368 | + |
|
1369 | + |
|
1370 | + /** |
|
1371 | + * @param $a |
|
1372 | + */ |
|
1373 | + public final function __get($a) |
|
1374 | + { |
|
1375 | + } |
|
1376 | + |
|
1377 | + |
|
1378 | + |
|
1379 | + /** |
|
1380 | + * @param $a |
|
1381 | + * @param $b |
|
1382 | + */ |
|
1383 | + public final function __set($a, $b) |
|
1384 | + { |
|
1385 | + } |
|
1386 | + |
|
1387 | + |
|
1388 | + |
|
1389 | + /** |
|
1390 | + * @param $a |
|
1391 | + */ |
|
1392 | + public final function __isset($a) |
|
1393 | + { |
|
1394 | + } |
|
1395 | 1395 | |
1396 | 1396 | |
1397 | 1397 | |
1398 | - /** |
|
1399 | - * @param $a |
|
1400 | - */ |
|
1401 | - public final function __unset($a) |
|
1402 | - { |
|
1403 | - } |
|
1398 | + /** |
|
1399 | + * @param $a |
|
1400 | + */ |
|
1401 | + public final function __unset($a) |
|
1402 | + { |
|
1403 | + } |
|
1404 | 1404 | |
1405 | 1405 | |
1406 | 1406 | |
1407 | - /** |
|
1408 | - * @return array |
|
1409 | - */ |
|
1410 | - public final function __sleep() |
|
1411 | - { |
|
1412 | - return array(); |
|
1413 | - } |
|
1407 | + /** |
|
1408 | + * @return array |
|
1409 | + */ |
|
1410 | + public final function __sleep() |
|
1411 | + { |
|
1412 | + return array(); |
|
1413 | + } |
|
1414 | 1414 | |
1415 | 1415 | |
1416 | 1416 | |
1417 | - public final function __wakeup() |
|
1418 | - { |
|
1419 | - } |
|
1417 | + public final function __wakeup() |
|
1418 | + { |
|
1419 | + } |
|
1420 | 1420 | |
1421 | 1421 | |
1422 | 1422 | |
1423 | - /** |
|
1424 | - * @return string |
|
1425 | - */ |
|
1426 | - public final function __toString() |
|
1427 | - { |
|
1428 | - return ''; |
|
1429 | - } |
|
1423 | + /** |
|
1424 | + * @return string |
|
1425 | + */ |
|
1426 | + public final function __toString() |
|
1427 | + { |
|
1428 | + return ''; |
|
1429 | + } |
|
1430 | 1430 | |
1431 | 1431 | |
1432 | 1432 | |
1433 | - public final function __invoke() |
|
1434 | - { |
|
1435 | - } |
|
1433 | + public final function __invoke() |
|
1434 | + { |
|
1435 | + } |
|
1436 | 1436 | |
1437 | 1437 | |
1438 | 1438 | |
1439 | - public final static function __set_state($array = array()) |
|
1440 | - { |
|
1441 | - return EE_Registry::instance(); |
|
1442 | - } |
|
1439 | + public final static function __set_state($array = array()) |
|
1440 | + { |
|
1441 | + return EE_Registry::instance(); |
|
1442 | + } |
|
1443 | 1443 | |
1444 | 1444 | |
1445 | 1445 | |
1446 | - public final function __clone() |
|
1447 | - { |
|
1448 | - } |
|
1446 | + public final function __clone() |
|
1447 | + { |
|
1448 | + } |
|
1449 | 1449 | |
1450 | 1450 | |
1451 | 1451 | |
1452 | - /** |
|
1453 | - * @param $a |
|
1454 | - * @param $b |
|
1455 | - */ |
|
1456 | - public final static function __callStatic($a, $b) |
|
1457 | - { |
|
1458 | - } |
|
1452 | + /** |
|
1453 | + * @param $a |
|
1454 | + * @param $b |
|
1455 | + */ |
|
1456 | + public final static function __callStatic($a, $b) |
|
1457 | + { |
|
1458 | + } |
|
1459 | 1459 | |
1460 | 1460 | |
1461 | 1461 | |
1462 | - /** |
|
1463 | - * Gets all the custom post type models defined |
|
1464 | - * |
|
1465 | - * @return array keys are model "short names" (Eg "Event") and keys are classnames (eg "EEM_Event") |
|
1466 | - */ |
|
1467 | - public function cpt_models() |
|
1468 | - { |
|
1469 | - $cpt_models = array(); |
|
1470 | - foreach ($this->non_abstract_db_models as $short_name => $classname) { |
|
1471 | - if (is_subclass_of($classname, 'EEM_CPT_Base')) { |
|
1472 | - $cpt_models[$short_name] = $classname; |
|
1473 | - } |
|
1474 | - } |
|
1475 | - return $cpt_models; |
|
1476 | - } |
|
1462 | + /** |
|
1463 | + * Gets all the custom post type models defined |
|
1464 | + * |
|
1465 | + * @return array keys are model "short names" (Eg "Event") and keys are classnames (eg "EEM_Event") |
|
1466 | + */ |
|
1467 | + public function cpt_models() |
|
1468 | + { |
|
1469 | + $cpt_models = array(); |
|
1470 | + foreach ($this->non_abstract_db_models as $short_name => $classname) { |
|
1471 | + if (is_subclass_of($classname, 'EEM_CPT_Base')) { |
|
1472 | + $cpt_models[$short_name] = $classname; |
|
1473 | + } |
|
1474 | + } |
|
1475 | + return $cpt_models; |
|
1476 | + } |
|
1477 | 1477 | |
1478 | 1478 | |
1479 | 1479 | |
1480 | - /** |
|
1481 | - * @return \EE_Config |
|
1482 | - */ |
|
1483 | - public static function CFG() |
|
1484 | - { |
|
1485 | - return self::instance()->CFG; |
|
1486 | - } |
|
1480 | + /** |
|
1481 | + * @return \EE_Config |
|
1482 | + */ |
|
1483 | + public static function CFG() |
|
1484 | + { |
|
1485 | + return self::instance()->CFG; |
|
1486 | + } |
|
1487 | 1487 | |
1488 | 1488 | |
1489 | 1489 | } |
@@ -17,74 +17,74 @@ discard block |
||
17 | 17 | class EEH_Schema { |
18 | 18 | |
19 | 19 | |
20 | - /** |
|
21 | - * generates JSON-based linked data for an event |
|
22 | - * |
|
23 | - * @param EE_Event $event |
|
24 | - * @throws EE_Error |
|
25 | - */ |
|
26 | - public static function add_json_linked_data_for_event(EE_Event $event) |
|
27 | - { |
|
28 | - //Check we have a valid datetime for the event |
|
29 | - if(! $event->primary_datetime() instanceof EE_Datetime) { |
|
30 | - return; |
|
31 | - } |
|
32 | - |
|
33 | - $template_args = array( |
|
34 | - 'event_permalink' => '', |
|
35 | - 'event_name' => '', |
|
36 | - 'event_description' => '', |
|
37 | - 'event_start' => '', |
|
38 | - 'event_end' => '', |
|
39 | - 'currency' => '', |
|
40 | - 'event_tickets' => array(), |
|
41 | - 'venue_name' => '', |
|
42 | - 'venue_url' => '', |
|
43 | - 'venue_locality' => '', |
|
44 | - 'venue_region' => '', |
|
45 | - 'event_image' => '', |
|
46 | - ); |
|
47 | - $template_args['event_permalink'] = $event->get_permalink(); |
|
48 | - $template_args['event_name'] = $event->name(); |
|
49 | - $template_args['event_description'] = wp_strip_all_tags($event->short_description(200)); |
|
50 | - // clone datetime so that date formats don't override those for the original datetime |
|
51 | - $primary_datetime = clone $event->primary_datetime(); |
|
52 | - $template_args['event_start'] = $primary_datetime->start_date(DateTime::ATOM); |
|
53 | - $template_args['event_end'] = $primary_datetime->end_date(DateTime::ATOM); |
|
54 | - unset($primary_datetime); |
|
55 | - $template_args['currency'] = EE_Registry::instance()->CFG->currency->code; |
|
56 | - foreach ($event->tickets() as $original_ticket) { |
|
57 | - // clone tickets so that date formats don't override those for the original ticket |
|
58 | - $ticket= clone $original_ticket; |
|
59 | - $ID = $ticket->ID(); |
|
60 | - $template_args['event_tickets'][$ID]['start_date'] = $ticket->start_date(DateTime::ATOM, null); |
|
61 | - $template_args['event_tickets'][$ID]['end_date'] = $ticket->end_date(DateTime::ATOM, null); |
|
62 | - $template_args['event_tickets'][$ID]['price'] = number_format( |
|
63 | - $ticket->price(), |
|
64 | - EE_Registry::instance()->CFG->currency->dec_plc, |
|
65 | - EE_Registry::instance()->CFG->currency->dec_mrk, |
|
66 | - EE_Registry::instance()->CFG->currency->thsnds |
|
67 | - ); |
|
68 | - unset($ticket); |
|
69 | - } |
|
70 | - $VNU_ID = espresso_venue_id(); |
|
71 | - if ( ! empty($VNU_ID) && ! espresso_is_venue_private($VNU_ID)) { |
|
72 | - $venue = EEH_Venue_View::get_venue($VNU_ID); |
|
73 | - $template_args['venue_name'] = get_the_title($VNU_ID); |
|
74 | - $template_args['venue_url'] = get_permalink($VNU_ID); |
|
75 | - $template_args['venue_locality'] = $venue->city(); |
|
76 | - $template_args['venue_region'] = $venue->state_name(); |
|
77 | - } |
|
78 | - $template_args['event_image'] = $event->feature_image_url(); |
|
79 | - $template_args = apply_filters( |
|
80 | - 'FHEE__EEH_Schema__add_json_linked_data_for_event__template_args', |
|
81 | - $template_args, |
|
82 | - $event, |
|
83 | - $VNU_ID |
|
84 | - ); |
|
85 | - extract($template_args, EXTR_OVERWRITE); |
|
86 | - include EE_TEMPLATES . 'json_linked_data_for_event.template.php'; |
|
87 | - } |
|
20 | + /** |
|
21 | + * generates JSON-based linked data for an event |
|
22 | + * |
|
23 | + * @param EE_Event $event |
|
24 | + * @throws EE_Error |
|
25 | + */ |
|
26 | + public static function add_json_linked_data_for_event(EE_Event $event) |
|
27 | + { |
|
28 | + //Check we have a valid datetime for the event |
|
29 | + if(! $event->primary_datetime() instanceof EE_Datetime) { |
|
30 | + return; |
|
31 | + } |
|
32 | + |
|
33 | + $template_args = array( |
|
34 | + 'event_permalink' => '', |
|
35 | + 'event_name' => '', |
|
36 | + 'event_description' => '', |
|
37 | + 'event_start' => '', |
|
38 | + 'event_end' => '', |
|
39 | + 'currency' => '', |
|
40 | + 'event_tickets' => array(), |
|
41 | + 'venue_name' => '', |
|
42 | + 'venue_url' => '', |
|
43 | + 'venue_locality' => '', |
|
44 | + 'venue_region' => '', |
|
45 | + 'event_image' => '', |
|
46 | + ); |
|
47 | + $template_args['event_permalink'] = $event->get_permalink(); |
|
48 | + $template_args['event_name'] = $event->name(); |
|
49 | + $template_args['event_description'] = wp_strip_all_tags($event->short_description(200)); |
|
50 | + // clone datetime so that date formats don't override those for the original datetime |
|
51 | + $primary_datetime = clone $event->primary_datetime(); |
|
52 | + $template_args['event_start'] = $primary_datetime->start_date(DateTime::ATOM); |
|
53 | + $template_args['event_end'] = $primary_datetime->end_date(DateTime::ATOM); |
|
54 | + unset($primary_datetime); |
|
55 | + $template_args['currency'] = EE_Registry::instance()->CFG->currency->code; |
|
56 | + foreach ($event->tickets() as $original_ticket) { |
|
57 | + // clone tickets so that date formats don't override those for the original ticket |
|
58 | + $ticket= clone $original_ticket; |
|
59 | + $ID = $ticket->ID(); |
|
60 | + $template_args['event_tickets'][$ID]['start_date'] = $ticket->start_date(DateTime::ATOM, null); |
|
61 | + $template_args['event_tickets'][$ID]['end_date'] = $ticket->end_date(DateTime::ATOM, null); |
|
62 | + $template_args['event_tickets'][$ID]['price'] = number_format( |
|
63 | + $ticket->price(), |
|
64 | + EE_Registry::instance()->CFG->currency->dec_plc, |
|
65 | + EE_Registry::instance()->CFG->currency->dec_mrk, |
|
66 | + EE_Registry::instance()->CFG->currency->thsnds |
|
67 | + ); |
|
68 | + unset($ticket); |
|
69 | + } |
|
70 | + $VNU_ID = espresso_venue_id(); |
|
71 | + if ( ! empty($VNU_ID) && ! espresso_is_venue_private($VNU_ID)) { |
|
72 | + $venue = EEH_Venue_View::get_venue($VNU_ID); |
|
73 | + $template_args['venue_name'] = get_the_title($VNU_ID); |
|
74 | + $template_args['venue_url'] = get_permalink($VNU_ID); |
|
75 | + $template_args['venue_locality'] = $venue->city(); |
|
76 | + $template_args['venue_region'] = $venue->state_name(); |
|
77 | + } |
|
78 | + $template_args['event_image'] = $event->feature_image_url(); |
|
79 | + $template_args = apply_filters( |
|
80 | + 'FHEE__EEH_Schema__add_json_linked_data_for_event__template_args', |
|
81 | + $template_args, |
|
82 | + $event, |
|
83 | + $VNU_ID |
|
84 | + ); |
|
85 | + extract($template_args, EXTR_OVERWRITE); |
|
86 | + include EE_TEMPLATES . 'json_linked_data_for_event.template.php'; |
|
87 | + } |
|
88 | 88 | |
89 | 89 | |
90 | 90 | /** |
@@ -98,8 +98,8 @@ discard block |
||
98 | 98 | */ |
99 | 99 | public static function location( $location = null ) { |
100 | 100 | return ! empty( $location ) ? '<div itemprop="location" itemscope itemtype="http://schema.org/Place">' |
101 | - . $location |
|
102 | - . '</div>' : ''; |
|
101 | + . $location |
|
102 | + . '</div>' : ''; |
|
103 | 103 | } |
104 | 104 | |
105 | 105 | |
@@ -219,8 +219,8 @@ discard block |
||
219 | 219 | */ |
220 | 220 | public static function postalCode( EEI_Address $obj_with_address = null ) { |
221 | 221 | return $obj_with_address->zip() !== null && $obj_with_address->zip() !== '' ? '<span itemprop="postalCode">' |
222 | - . $obj_with_address->zip() |
|
223 | - . '</span>' : ''; |
|
222 | + . $obj_with_address->zip() |
|
223 | + . '</span>' : ''; |
|
224 | 224 | } |
225 | 225 | |
226 | 226 | |
@@ -254,7 +254,7 @@ discard block |
||
254 | 254 | //Check the URL includes a scheme |
255 | 255 | $parsed_url = parse_url($url); |
256 | 256 | if ( empty($parsed_url['scheme']) ) { |
257 | - $url = 'http://' . ltrim($url, '/'); |
|
257 | + $url = 'http://' . ltrim($url, '/'); |
|
258 | 258 | } |
259 | 259 | |
260 | 260 | $atts = ''; |
@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
|
4 | - exit( 'No direct script access allowed' ); |
|
3 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
4 | + exit('No direct script access allowed'); |
|
5 | 5 | } |
6 | 6 | |
7 | 7 | |
@@ -26,7 +26,7 @@ discard block |
||
26 | 26 | public static function add_json_linked_data_for_event(EE_Event $event) |
27 | 27 | { |
28 | 28 | //Check we have a valid datetime for the event |
29 | - if(! $event->primary_datetime() instanceof EE_Datetime) { |
|
29 | + if ( ! $event->primary_datetime() instanceof EE_Datetime) { |
|
30 | 30 | return; |
31 | 31 | } |
32 | 32 | |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | $template_args['currency'] = EE_Registry::instance()->CFG->currency->code; |
56 | 56 | foreach ($event->tickets() as $original_ticket) { |
57 | 57 | // clone tickets so that date formats don't override those for the original ticket |
58 | - $ticket= clone $original_ticket; |
|
58 | + $ticket = clone $original_ticket; |
|
59 | 59 | $ID = $ticket->ID(); |
60 | 60 | $template_args['event_tickets'][$ID]['start_date'] = $ticket->start_date(DateTime::ATOM, null); |
61 | 61 | $template_args['event_tickets'][$ID]['end_date'] = $ticket->end_date(DateTime::ATOM, null); |
@@ -83,7 +83,7 @@ discard block |
||
83 | 83 | $VNU_ID |
84 | 84 | ); |
85 | 85 | extract($template_args, EXTR_OVERWRITE); |
86 | - include EE_TEMPLATES . 'json_linked_data_for_event.template.php'; |
|
86 | + include EE_TEMPLATES.'json_linked_data_for_event.template.php'; |
|
87 | 87 | } |
88 | 88 | |
89 | 89 | |
@@ -96,8 +96,8 @@ discard block |
||
96 | 96 | * @param string $location |
97 | 97 | * @return string |
98 | 98 | */ |
99 | - public static function location( $location = null ) { |
|
100 | - return ! empty( $location ) ? '<div itemprop="location" itemscope itemtype="http://schema.org/Place">' |
|
99 | + public static function location($location = null) { |
|
100 | + return ! empty($location) ? '<div itemprop="location" itemscope itemtype="http://schema.org/Place">' |
|
101 | 101 | . $location |
102 | 102 | . '</div>' : ''; |
103 | 103 | } |
@@ -112,8 +112,8 @@ discard block |
||
112 | 112 | * @param string $name |
113 | 113 | * @return string |
114 | 114 | */ |
115 | - public static function name( $name = null ) { |
|
116 | - return ! empty( $name ) ? '<span itemprop="name">' . $name . '</span>' : ''; |
|
115 | + public static function name($name = null) { |
|
116 | + return ! empty($name) ? '<span itemprop="name">'.$name.'</span>' : ''; |
|
117 | 117 | } |
118 | 118 | |
119 | 119 | |
@@ -126,9 +126,9 @@ discard block |
||
126 | 126 | * @param EEI_Address $obj_with_address |
127 | 127 | * @return string |
128 | 128 | */ |
129 | - public static function streetAddress( EEI_Address $obj_with_address = null ) { |
|
129 | + public static function streetAddress(EEI_Address $obj_with_address = null) { |
|
130 | 130 | return $obj_with_address->address() !== null && $obj_with_address->address() !== '' |
131 | - ? '<span itemprop="streetAddress">' . $obj_with_address->address() . '</span>' : ''; |
|
131 | + ? '<span itemprop="streetAddress">'.$obj_with_address->address().'</span>' : ''; |
|
132 | 132 | } |
133 | 133 | |
134 | 134 | |
@@ -141,14 +141,14 @@ discard block |
||
141 | 141 | * @param EEI_Address $obj_with_address |
142 | 142 | * @return string |
143 | 143 | */ |
144 | - public static function postOfficeBoxNumber( EEI_Address $obj_with_address = null ) { |
|
144 | + public static function postOfficeBoxNumber(EEI_Address $obj_with_address = null) { |
|
145 | 145 | // regex check for some form of PO Box or P.O. Box, etc, etc, etc |
146 | - if ( preg_match( |
|
146 | + if (preg_match( |
|
147 | 147 | "/^\s*((P(OST)?.?\s*(O(FF(ICE)?)?)?.?\s+(B(IN|OX))?)|B(IN|OX))/i", |
148 | 148 | $obj_with_address->address2() |
149 | - ) ) { |
|
149 | + )) { |
|
150 | 150 | return $obj_with_address->address2() !== null && $obj_with_address->address2() !== '' |
151 | - ? '<span itemprop="postOfficeBoxNumber">' . $obj_with_address->address2() . '</span>' : ''; |
|
151 | + ? '<span itemprop="postOfficeBoxNumber">'.$obj_with_address->address2().'</span>' : ''; |
|
152 | 152 | } else { |
153 | 153 | return $obj_with_address->address2(); |
154 | 154 | } |
@@ -164,9 +164,9 @@ discard block |
||
164 | 164 | * @param EEI_Address $obj_with_address |
165 | 165 | * @return string |
166 | 166 | */ |
167 | - public static function addressLocality( EEI_Address $obj_with_address = null ) { |
|
167 | + public static function addressLocality(EEI_Address $obj_with_address = null) { |
|
168 | 168 | return $obj_with_address->city() !== null && $obj_with_address->city() !== '' |
169 | - ? '<span itemprop="addressLocality">' . $obj_with_address->city() . '</span>' : ''; |
|
169 | + ? '<span itemprop="addressLocality">'.$obj_with_address->city().'</span>' : ''; |
|
170 | 170 | } |
171 | 171 | |
172 | 172 | |
@@ -179,10 +179,10 @@ discard block |
||
179 | 179 | * @param EEI_Address $obj_with_address |
180 | 180 | * @return string |
181 | 181 | */ |
182 | - public static function addressRegion( EEI_Address $obj_with_address = null ) { |
|
182 | + public static function addressRegion(EEI_Address $obj_with_address = null) { |
|
183 | 183 | $state = $obj_with_address->state_name(); |
184 | - if ( ! empty( $state ) ) { |
|
185 | - return '<span itemprop="addressRegion">' . $state . '</span>'; |
|
184 | + if ( ! empty($state)) { |
|
185 | + return '<span itemprop="addressRegion">'.$state.'</span>'; |
|
186 | 186 | } else { |
187 | 187 | return ''; |
188 | 188 | } |
@@ -198,10 +198,10 @@ discard block |
||
198 | 198 | * @param EEI_Address $obj_with_address |
199 | 199 | * @return string |
200 | 200 | */ |
201 | - public static function addressCountry( EEI_Address $obj_with_address = null ) { |
|
201 | + public static function addressCountry(EEI_Address $obj_with_address = null) { |
|
202 | 202 | $country = $obj_with_address->country_name(); |
203 | - if ( ! empty( $country ) ) { |
|
204 | - return '<span itemprop="addressCountry">' . $country . '</span>'; |
|
203 | + if ( ! empty($country)) { |
|
204 | + return '<span itemprop="addressCountry">'.$country.'</span>'; |
|
205 | 205 | } else { |
206 | 206 | return ''; |
207 | 207 | } |
@@ -217,7 +217,7 @@ discard block |
||
217 | 217 | * @param EEI_Address $obj_with_address |
218 | 218 | * @return string |
219 | 219 | */ |
220 | - public static function postalCode( EEI_Address $obj_with_address = null ) { |
|
220 | + public static function postalCode(EEI_Address $obj_with_address = null) { |
|
221 | 221 | return $obj_with_address->zip() !== null && $obj_with_address->zip() !== '' ? '<span itemprop="postalCode">' |
222 | 222 | . $obj_with_address->zip() |
223 | 223 | . '</span>' : ''; |
@@ -233,8 +233,8 @@ discard block |
||
233 | 233 | * @param string $phone_nmbr |
234 | 234 | * @return string |
235 | 235 | */ |
236 | - public static function telephone( $phone_nmbr = null ) { |
|
237 | - return $phone_nmbr !== null && $phone_nmbr !== '' ? '<span itemprop="telephone">' . $phone_nmbr . '</span>' |
|
236 | + public static function telephone($phone_nmbr = null) { |
|
237 | + return $phone_nmbr !== null && $phone_nmbr !== '' ? '<span itemprop="telephone">'.$phone_nmbr.'</span>' |
|
238 | 238 | : ''; |
239 | 239 | } |
240 | 240 | |
@@ -250,19 +250,19 @@ discard block |
||
250 | 250 | * @param array $attributes - array of additional link attributes in attribute_name => value pairs. ie: array( 'title' => 'click here', 'class' => 'link-class' ) |
251 | 251 | * @return string (link) |
252 | 252 | */ |
253 | - public static function url( $url = null, $text = null, $attributes = array() ) { |
|
253 | + public static function url($url = null, $text = null, $attributes = array()) { |
|
254 | 254 | //Check the URL includes a scheme |
255 | 255 | $parsed_url = parse_url($url); |
256 | - if ( empty($parsed_url['scheme']) ) { |
|
257 | - $url = 'http://' . ltrim($url, '/'); |
|
256 | + if (empty($parsed_url['scheme'])) { |
|
257 | + $url = 'http://'.ltrim($url, '/'); |
|
258 | 258 | } |
259 | 259 | |
260 | 260 | $atts = ''; |
261 | - foreach ( $attributes as $attribute => $value ) { |
|
262 | - $atts .= ' ' . $attribute . '="' . $value . '"'; |
|
261 | + foreach ($attributes as $attribute => $value) { |
|
262 | + $atts .= ' '.$attribute.'="'.$value.'"'; |
|
263 | 263 | } |
264 | 264 | $text = $text !== null && $text !== '' ? $text : $url; |
265 | - return $url !== null && $url !== '' ? '<a itemprop="url" href="' . $url . '"' . $atts . '>' . $text . '</a>' |
|
265 | + return $url !== null && $url !== '' ? '<a itemprop="url" href="'.$url.'"'.$atts.'>'.$text.'</a>' |
|
266 | 266 | : ''; |
267 | 267 | } |
268 | 268 |
@@ -165,7 +165,7 @@ |
||
165 | 165 | |
166 | 166 | /** |
167 | 167 | * @param EE_Event $item |
168 | - * @return mixed|string |
|
168 | + * @return string |
|
169 | 169 | */ |
170 | 170 | public function column_id(EE_Event $item) |
171 | 171 | { |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | if (! defined('EVENT_ESPRESSO_VERSION')) { |
3 | - exit('NO direct script access allowed'); |
|
3 | + exit('NO direct script access allowed'); |
|
4 | 4 | } |
5 | 5 | |
6 | 6 | /** |
@@ -26,406 +26,406 @@ discard block |
||
26 | 26 | { |
27 | 27 | |
28 | 28 | |
29 | - /** |
|
30 | - * @var EE_Datetime |
|
31 | - */ |
|
32 | - private $_dtt; |
|
33 | - |
|
34 | - |
|
35 | - /** |
|
36 | - * Events_Admin_List_Table constructor. |
|
37 | - * |
|
38 | - * @param EE_Admin_Page $admin_page |
|
39 | - */ |
|
40 | - public function __construct($admin_page) |
|
41 | - { |
|
42 | - parent::__construct($admin_page); |
|
43 | - require_once(EE_HELPERS . 'EEH_DTT_Helper.helper.php'); |
|
44 | - } |
|
45 | - |
|
46 | - |
|
47 | - /** |
|
48 | - * Initial setup of data properties for the list table. |
|
49 | - */ |
|
50 | - protected function _setup_data() |
|
51 | - { |
|
52 | - $this->_data = $this->_admin_page->get_events($this->_per_page, $this->_current_page); |
|
53 | - $this->_all_data_count = $this->_admin_page->get_events(0, 0, true); |
|
54 | - } |
|
55 | - |
|
56 | - |
|
57 | - /** |
|
58 | - * Set up of additional properties for the list table. |
|
59 | - */ |
|
60 | - protected function _set_properties() |
|
61 | - { |
|
62 | - $this->_wp_list_args = array( |
|
63 | - 'singular' => __('event', 'event_espresso'), |
|
64 | - 'plural' => __('events', 'event_espresso'), |
|
65 | - 'ajax' => true, //for now |
|
66 | - 'screen' => $this->_admin_page->get_current_screen()->id, |
|
67 | - ); |
|
68 | - |
|
69 | - |
|
70 | - $this->_columns = array( |
|
71 | - 'cb' => '<input type="checkbox" />', |
|
72 | - 'id' => __('ID', 'event_espresso'), |
|
73 | - 'name' => __('Name', 'event_espresso'), |
|
74 | - 'author' => __('Author', 'event_espresso'), |
|
75 | - 'venue' => __('Venue', 'event_espresso'), |
|
76 | - 'start_date_time' => __('Event Start', 'event_espresso'), |
|
77 | - 'reg_begins' => __('On Sale', 'event_espresso'), |
|
78 | - 'attendees' => '<span class="dashicons dashicons-groups ee-icon-color-ee-green ee-icon-size-20"></span>', |
|
79 | - //'tkts_sold' => __('Tickets Sold', 'event_espresso'), |
|
80 | - 'actions' => __('Actions', 'event_espresso'), |
|
81 | - ); |
|
82 | - |
|
83 | - |
|
84 | - $this->_sortable_columns = array( |
|
85 | - 'id' => array('EVT_ID' => true), |
|
86 | - 'name' => array('EVT_name' => false), |
|
87 | - 'author' => array('EVT_wp_user' => false), |
|
88 | - 'venue' => array('Venue.VNU_name' => false), |
|
89 | - 'start_date_time' => array('Datetime.DTT_EVT_start' => false), |
|
90 | - 'reg_begins' => array('Datetime.Ticket.TKT_start_date' => false), |
|
91 | - ); |
|
92 | - |
|
93 | - $this->_primary_column = 'id'; |
|
94 | - |
|
95 | - $this->_hidden_columns = array('author'); |
|
96 | - } |
|
97 | - |
|
98 | - |
|
99 | - /** |
|
100 | - * @return array |
|
101 | - */ |
|
102 | - protected function _get_table_filters() |
|
103 | - { |
|
104 | - return array(); //no filters with decaf |
|
105 | - } |
|
106 | - |
|
107 | - |
|
108 | - /** |
|
109 | - * Setup of views properties. |
|
110 | - */ |
|
111 | - protected function _add_view_counts() |
|
112 | - { |
|
113 | - $this->_views['all']['count'] = $this->_admin_page->total_events(); |
|
114 | - $this->_views['draft']['count'] = $this->_admin_page->total_events_draft(); |
|
115 | - if (EE_Registry::instance()->CAP->current_user_can('ee_delete_events', 'espresso_events_trash_events')) { |
|
116 | - $this->_views['trash']['count'] = $this->_admin_page->total_trashed_events(); |
|
117 | - } |
|
118 | - } |
|
119 | - |
|
120 | - |
|
121 | - /** |
|
122 | - * @param EE_Event $item |
|
123 | - * @return string |
|
124 | - */ |
|
125 | - protected function _get_row_class($item) |
|
126 | - { |
|
127 | - $class = parent::_get_row_class($item); |
|
128 | - //add status class |
|
129 | - $class .= $item instanceof EE_Event ? ' ee-status-strip event-status-' . $item->get_active_status() : ''; |
|
130 | - if ($this->_has_checkbox_column) { |
|
131 | - $class .= ' has-checkbox-column'; |
|
132 | - } |
|
133 | - return $class; |
|
134 | - } |
|
135 | - |
|
136 | - |
|
137 | - /** |
|
138 | - * @param EE_Event $item |
|
139 | - * @return string |
|
140 | - */ |
|
141 | - public function column_status(EE_Event $item) |
|
142 | - { |
|
143 | - return '<span class="ee-status-strip ee-status-strip-td event-status-' . $item->get_active_status() . '"></span>'; |
|
144 | - }/**/ |
|
145 | - |
|
146 | - |
|
147 | - /** |
|
148 | - * @param EE_Event $item |
|
149 | - * @return string |
|
150 | - */ |
|
151 | - public function column_cb($item) |
|
152 | - { |
|
153 | - if (! $item instanceof EE_Event) { |
|
154 | - return ''; |
|
155 | - } |
|
156 | - $this->_dtt = $item->primary_datetime(); //set this for use in other columns |
|
157 | - |
|
158 | - //does event have any attached registrations? |
|
159 | - $regs = $item->count_related('Registration'); |
|
160 | - return $regs > 0 && $this->_view == 'trash' ? '<span class="ee-lock-icon"></span>' : sprintf( |
|
161 | - '<input type="checkbox" name="EVT_IDs[]" value="%s" />', $item->ID() |
|
162 | - ); |
|
163 | - } |
|
164 | - |
|
165 | - |
|
166 | - /** |
|
167 | - * @param EE_Event $item |
|
168 | - * @return mixed|string |
|
169 | - */ |
|
170 | - public function column_id(EE_Event $item) |
|
171 | - { |
|
172 | - $content = $item->ID(); |
|
173 | - $content .= ' <span class="show-on-mobile-view-only">' . $item->name() . '</span>'; |
|
174 | - return $content; |
|
175 | - } |
|
176 | - |
|
177 | - |
|
178 | - /** |
|
179 | - * @param EE_Event $item |
|
180 | - * @return string |
|
181 | - */ |
|
182 | - public function column_name(EE_Event $item) |
|
183 | - { |
|
184 | - $edit_query_args = array( |
|
185 | - 'action' => 'edit', |
|
186 | - 'post' => $item->ID(), |
|
187 | - ); |
|
188 | - $edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL); |
|
189 | - $actions = $this->_column_name_action_setup($item); |
|
190 | - $status = ''; //$item->status() !== 'publish' ? ' (' . $item->status() . ')' : ''; |
|
191 | - $content = '<strong><a class="row-title" href="' . $edit_link . '">' . $item->name() . '</a></strong>' . $status; |
|
192 | - $content .= '<br><span class="ee-status-text-small">' . EEH_Template::pretty_status($item->get_active_status(), |
|
193 | - false, 'sentence') . '</span>'; |
|
194 | - $content .= $this->row_actions($actions); |
|
195 | - return $content; |
|
196 | - |
|
197 | - } |
|
198 | - |
|
199 | - |
|
200 | - /** |
|
201 | - * Just a method for setting up the actions for the name column |
|
202 | - * |
|
203 | - * @param EE_Event $item |
|
204 | - * @return array array of actions |
|
205 | - */ |
|
206 | - protected function _column_name_action_setup(EE_Event $item) |
|
207 | - { |
|
208 | - //todo: remove when attendees is active |
|
209 | - if (! defined('REG_ADMIN_URL')) { |
|
210 | - define('REG_ADMIN_URL', EVENTS_ADMIN_URL); |
|
211 | - } |
|
212 | - |
|
213 | - $actions = array(); |
|
214 | - |
|
215 | - if (EE_Registry::instance()->CAP->current_user_can('ee_edit_event', 'espresso_events_edit', $item->ID())) { |
|
216 | - $edit_query_args = array( |
|
217 | - 'action' => 'edit', |
|
218 | - 'post' => $item->ID(), |
|
219 | - ); |
|
220 | - $edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL); |
|
221 | - $actions['edit'] = '<a href="' . $edit_link . '" title="' . esc_attr__('Edit Event', |
|
222 | - 'event_espresso') . '">' . __('Edit', 'event_espresso') . '</a>'; |
|
223 | - |
|
224 | - } |
|
225 | - |
|
226 | - if (EE_Registry::instance()->CAP->current_user_can('ee_read_registration', |
|
227 | - 'espresso_registrations_view_registration', $item->ID())) { |
|
228 | - $attendees_query_args = array( |
|
229 | - 'action' => 'default', |
|
230 | - 'event_id' => $item->ID(), |
|
231 | - ); |
|
232 | - $attendees_link = EE_Admin_Page::add_query_args_and_nonce($attendees_query_args, REG_ADMIN_URL); |
|
233 | - $actions['attendees'] = '<a href="' . $attendees_link . '" title="' . esc_attr__('View Registrations', |
|
234 | - 'event_espresso') . '">' . __('Registrations', 'event_espresso') . '</a>'; |
|
235 | - } |
|
236 | - |
|
237 | - if (EE_Registry::instance()->CAP->current_user_can('ee_delete_event', 'espresso_events_trash_event', |
|
238 | - $item->ID())) { |
|
239 | - $trash_event_query_args = array( |
|
240 | - 'action' => 'trash_event', |
|
241 | - 'EVT_ID' => $item->ID(), |
|
242 | - ); |
|
243 | - $trash_event_link = EE_Admin_Page::add_query_args_and_nonce($trash_event_query_args, |
|
244 | - EVENTS_ADMIN_URL); |
|
245 | - } |
|
246 | - |
|
247 | - if (EE_Registry::instance()->CAP->current_user_can('ee_delete_event', 'espresso_events_restore_event', |
|
248 | - $item->ID())) { |
|
249 | - $restore_event_query_args = array( |
|
250 | - 'action' => 'restore_event', |
|
251 | - 'EVT_ID' => $item->ID(), |
|
252 | - ); |
|
253 | - $restore_event_link = EE_Admin_Page::add_query_args_and_nonce($restore_event_query_args, |
|
254 | - EVENTS_ADMIN_URL); |
|
255 | - } |
|
256 | - |
|
257 | - if (EE_Registry::instance()->CAP->current_user_can('ee_delete_event', 'espresso_events_delete_event', |
|
258 | - $item->ID())) { |
|
259 | - $delete_event_query_args = array( |
|
260 | - 'action' => 'delete_event', |
|
261 | - 'EVT_ID' => $item->ID(), |
|
262 | - ); |
|
263 | - $delete_event_link = EE_Admin_Page::add_query_args_and_nonce($delete_event_query_args, |
|
264 | - EVENTS_ADMIN_URL); |
|
265 | - } |
|
266 | - |
|
267 | - $view_link = get_permalink($item->ID()); |
|
268 | - |
|
269 | - $actions['view'] = '<a href="' . $view_link . '" title="' . esc_attr__('View Event', |
|
270 | - 'event_espresso') . '">' . __('View', 'event_espresso') . '</a>'; |
|
271 | - |
|
272 | - switch ($item->get('status')) { |
|
273 | - case 'trash' : |
|
274 | - if (EE_Registry::instance()->CAP->current_user_can('ee_delete_event', 'espresso_events_restore_event', |
|
275 | - $item->ID())) { |
|
276 | - $actions['restore_from_trash'] = '<a href="' . $restore_event_link . '" title="' . esc_attr__('Restore from Trash', |
|
277 | - 'event_espresso') . '">' . __('Restore from Trash', 'event_espresso') . '</a>'; |
|
278 | - } |
|
279 | - if ($item->count_related('Registration') === 0 && EE_Registry::instance()->CAP->current_user_can('ee_delete_event', |
|
280 | - 'espresso_events_delete_event', $item->ID())) { |
|
281 | - $actions['delete'] = '<a href="' . $delete_event_link . '" title="' . esc_attr__('Delete Permanently', |
|
282 | - 'event_espresso') . '">' . __('Delete Permanently', 'event_espresso') . '</a>'; |
|
283 | - } |
|
284 | - break; |
|
285 | - default : |
|
286 | - if (EE_Registry::instance()->CAP->current_user_can('ee_delete_event', 'espresso_events_trash_event', |
|
287 | - $item->ID())) { |
|
288 | - $actions['move to trash'] = '<a href="' . $trash_event_link . '" title="' . esc_attr__('Trash Event', |
|
289 | - 'event_espresso') . '">' . __('Trash', 'event_espresso') . '</a>'; |
|
290 | - } |
|
291 | - } |
|
292 | - return $actions; |
|
293 | - } |
|
294 | - |
|
295 | - |
|
296 | - /** |
|
297 | - * @param EE_Event $item |
|
298 | - * @return string |
|
299 | - */ |
|
300 | - public function column_author(EE_Event $item) |
|
301 | - { |
|
302 | - //user author info |
|
303 | - $event_author = get_userdata($item->wp_user()); |
|
304 | - $gravatar = get_avatar($item->wp_user(), '15'); |
|
305 | - //filter link |
|
306 | - $query_args = array( |
|
307 | - 'action' => 'default', |
|
308 | - 'EVT_wp_user' => $item->wp_user(), |
|
309 | - ); |
|
310 | - $filter_url = EE_Admin_Page::add_query_args_and_nonce($query_args, EVENTS_ADMIN_URL); |
|
311 | - return $gravatar . ' <a href="' . $filter_url . '" title="' . esc_attr__('Click to filter events by this author.', |
|
312 | - 'event_espresso') . '">' . $event_author->display_name . '</a>'; |
|
313 | - } |
|
314 | - |
|
315 | - |
|
316 | - /** |
|
317 | - * @param EE_Event $item |
|
318 | - * @return string |
|
319 | - */ |
|
320 | - public function column_venue(EE_Event $item) |
|
321 | - { |
|
322 | - $venue = $item->get_first_related('Venue'); |
|
323 | - return ! empty($venue) ? $venue->name() : ''; |
|
324 | - } |
|
325 | - |
|
326 | - |
|
327 | - /** |
|
328 | - * @param EE_Event $item |
|
329 | - * @throws EE_Error |
|
330 | - */ |
|
331 | - public function column_start_date_time(EE_Event $item) |
|
332 | - { |
|
333 | - echo ! empty($this->_dtt) ? $this->_dtt->get_i18n_datetime('DTT_EVT_start') : __('No Date was saved for this Event', |
|
334 | - 'event_espresso'); |
|
335 | - //display in user's timezone? |
|
336 | - echo ! empty($this->_dtt) ? $this->_dtt->display_in_my_timezone('DTT_EVT_start', 'get_i18n_datetime', '', |
|
337 | - 'My Timezone: ') : ''; |
|
338 | - |
|
339 | - } |
|
340 | - |
|
341 | - |
|
342 | - /** |
|
343 | - * @param EE_Event $item |
|
344 | - * @throws EE_Error |
|
345 | - */ |
|
346 | - public function column_reg_begins(EE_Event $item) |
|
347 | - { |
|
348 | - $reg_start = $item->get_ticket_with_earliest_start_time(); |
|
349 | - echo ! empty($reg_start) ? $reg_start->get_i18n_datetime('TKT_start_date') : __('No Tickets have been setup for this Event', |
|
350 | - 'event_espresso'); |
|
351 | - //display in user's timezone? |
|
352 | - echo ! empty($reg_start) ? $reg_start->display_in_my_timezone('TKT_start_date', 'get_i18n_datetime', '', |
|
353 | - 'My Timezone: ') : '';/**/ |
|
354 | - } |
|
355 | - |
|
356 | - |
|
357 | - /** |
|
358 | - * @param EE_Event $item |
|
359 | - * @return int|string |
|
360 | - */ |
|
361 | - public function column_attendees(EE_Event $item) |
|
362 | - { |
|
363 | - $attendees_query_args = array( |
|
364 | - 'action' => 'default', |
|
365 | - 'event_id' => $item->ID(), |
|
366 | - ); |
|
367 | - $attendees_link = EE_Admin_Page::add_query_args_and_nonce($attendees_query_args, REG_ADMIN_URL); |
|
368 | - $registered_attendees = EEM_Registration::instance()->get_event_registration_count($item->ID()); |
|
369 | - return EE_Registry::instance()->CAP->current_user_can('ee_read_registration', |
|
370 | - 'espresso_registrations_view_registration', |
|
371 | - $item->ID()) ? '<a href="' . $attendees_link . '">' . $registered_attendees . '</a>' : $registered_attendees; |
|
372 | - } |
|
373 | - |
|
374 | - |
|
375 | - /** |
|
376 | - * @param EE_Event $item |
|
377 | - * @return float |
|
378 | - */ |
|
379 | - public function column_tkts_sold(EE_Event $item) |
|
380 | - { |
|
381 | - return EEM_Ticket::instance()->sum(array(array('Datetime.EVT_ID' => $item->ID())), 'TKT_sold'); |
|
382 | - } |
|
383 | - |
|
384 | - |
|
385 | - /** |
|
386 | - * @param EE_Event $item |
|
387 | - * @return string |
|
388 | - */ |
|
389 | - public function column_actions(EE_Event $item) |
|
390 | - { |
|
391 | - //todo: remove when attendees is active |
|
392 | - if (! defined('REG_ADMIN_URL')) { |
|
393 | - define('REG_ADMIN_URL', EVENTS_ADMIN_URL); |
|
394 | - } |
|
395 | - $actionlinks = array(); |
|
396 | - |
|
397 | - $view_link = get_permalink($item->ID()); |
|
398 | - |
|
399 | - $actionlinks[] = '<a href="' . $view_link . '" title="' . esc_attr__('View Event', |
|
400 | - 'event_espresso') . '" target="_blank">'; |
|
401 | - $actionlinks[] = '<div class="dashicons dashicons-search"></div></a>'; |
|
402 | - |
|
403 | - if (EE_Registry::instance()->CAP->current_user_can('ee_edit_event', 'espresso_events_edit', $item->ID())) { |
|
404 | - $edit_query_args = array( |
|
405 | - 'action' => 'edit', |
|
406 | - 'post' => $item->ID(), |
|
407 | - ); |
|
408 | - $edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL); |
|
409 | - $actionlinks[] = '<a href="' . $edit_link . '" title="' . esc_attr__('Edit Event', |
|
410 | - 'event_espresso') . '"><div class="ee-icon ee-icon-calendar-edit"></div></a>'; |
|
411 | - } |
|
412 | - |
|
413 | - if (EE_Registry::instance()->CAP->current_user_can('ee_read_registration', |
|
414 | - 'espresso_registrations_view_registration', $item->ID())) { |
|
415 | - $attendees_query_args = array( |
|
416 | - 'action' => 'default', |
|
417 | - 'event_id' => $item->ID(), |
|
418 | - ); |
|
419 | - $attendees_link = EE_Admin_Page::add_query_args_and_nonce($attendees_query_args, REG_ADMIN_URL); |
|
420 | - $actionlinks[] = '<a href="' . $attendees_link . '" title="' . esc_attr__('View Registrants', |
|
421 | - 'event_espresso') . '"><div class="dashicons dashicons-groups"></div></a>'; |
|
422 | - } |
|
423 | - |
|
424 | - $actionlinks = apply_filters('FHEE__Events_Admin_List_Table__column_actions__action_links', $actionlinks, |
|
425 | - $item); |
|
426 | - |
|
427 | - return $this->_action_string(implode("\n\t", $actionlinks), $item, 'div'); |
|
428 | - } |
|
29 | + /** |
|
30 | + * @var EE_Datetime |
|
31 | + */ |
|
32 | + private $_dtt; |
|
33 | + |
|
34 | + |
|
35 | + /** |
|
36 | + * Events_Admin_List_Table constructor. |
|
37 | + * |
|
38 | + * @param EE_Admin_Page $admin_page |
|
39 | + */ |
|
40 | + public function __construct($admin_page) |
|
41 | + { |
|
42 | + parent::__construct($admin_page); |
|
43 | + require_once(EE_HELPERS . 'EEH_DTT_Helper.helper.php'); |
|
44 | + } |
|
45 | + |
|
46 | + |
|
47 | + /** |
|
48 | + * Initial setup of data properties for the list table. |
|
49 | + */ |
|
50 | + protected function _setup_data() |
|
51 | + { |
|
52 | + $this->_data = $this->_admin_page->get_events($this->_per_page, $this->_current_page); |
|
53 | + $this->_all_data_count = $this->_admin_page->get_events(0, 0, true); |
|
54 | + } |
|
55 | + |
|
56 | + |
|
57 | + /** |
|
58 | + * Set up of additional properties for the list table. |
|
59 | + */ |
|
60 | + protected function _set_properties() |
|
61 | + { |
|
62 | + $this->_wp_list_args = array( |
|
63 | + 'singular' => __('event', 'event_espresso'), |
|
64 | + 'plural' => __('events', 'event_espresso'), |
|
65 | + 'ajax' => true, //for now |
|
66 | + 'screen' => $this->_admin_page->get_current_screen()->id, |
|
67 | + ); |
|
68 | + |
|
69 | + |
|
70 | + $this->_columns = array( |
|
71 | + 'cb' => '<input type="checkbox" />', |
|
72 | + 'id' => __('ID', 'event_espresso'), |
|
73 | + 'name' => __('Name', 'event_espresso'), |
|
74 | + 'author' => __('Author', 'event_espresso'), |
|
75 | + 'venue' => __('Venue', 'event_espresso'), |
|
76 | + 'start_date_time' => __('Event Start', 'event_espresso'), |
|
77 | + 'reg_begins' => __('On Sale', 'event_espresso'), |
|
78 | + 'attendees' => '<span class="dashicons dashicons-groups ee-icon-color-ee-green ee-icon-size-20"></span>', |
|
79 | + //'tkts_sold' => __('Tickets Sold', 'event_espresso'), |
|
80 | + 'actions' => __('Actions', 'event_espresso'), |
|
81 | + ); |
|
82 | + |
|
83 | + |
|
84 | + $this->_sortable_columns = array( |
|
85 | + 'id' => array('EVT_ID' => true), |
|
86 | + 'name' => array('EVT_name' => false), |
|
87 | + 'author' => array('EVT_wp_user' => false), |
|
88 | + 'venue' => array('Venue.VNU_name' => false), |
|
89 | + 'start_date_time' => array('Datetime.DTT_EVT_start' => false), |
|
90 | + 'reg_begins' => array('Datetime.Ticket.TKT_start_date' => false), |
|
91 | + ); |
|
92 | + |
|
93 | + $this->_primary_column = 'id'; |
|
94 | + |
|
95 | + $this->_hidden_columns = array('author'); |
|
96 | + } |
|
97 | + |
|
98 | + |
|
99 | + /** |
|
100 | + * @return array |
|
101 | + */ |
|
102 | + protected function _get_table_filters() |
|
103 | + { |
|
104 | + return array(); //no filters with decaf |
|
105 | + } |
|
106 | + |
|
107 | + |
|
108 | + /** |
|
109 | + * Setup of views properties. |
|
110 | + */ |
|
111 | + protected function _add_view_counts() |
|
112 | + { |
|
113 | + $this->_views['all']['count'] = $this->_admin_page->total_events(); |
|
114 | + $this->_views['draft']['count'] = $this->_admin_page->total_events_draft(); |
|
115 | + if (EE_Registry::instance()->CAP->current_user_can('ee_delete_events', 'espresso_events_trash_events')) { |
|
116 | + $this->_views['trash']['count'] = $this->_admin_page->total_trashed_events(); |
|
117 | + } |
|
118 | + } |
|
119 | + |
|
120 | + |
|
121 | + /** |
|
122 | + * @param EE_Event $item |
|
123 | + * @return string |
|
124 | + */ |
|
125 | + protected function _get_row_class($item) |
|
126 | + { |
|
127 | + $class = parent::_get_row_class($item); |
|
128 | + //add status class |
|
129 | + $class .= $item instanceof EE_Event ? ' ee-status-strip event-status-' . $item->get_active_status() : ''; |
|
130 | + if ($this->_has_checkbox_column) { |
|
131 | + $class .= ' has-checkbox-column'; |
|
132 | + } |
|
133 | + return $class; |
|
134 | + } |
|
135 | + |
|
136 | + |
|
137 | + /** |
|
138 | + * @param EE_Event $item |
|
139 | + * @return string |
|
140 | + */ |
|
141 | + public function column_status(EE_Event $item) |
|
142 | + { |
|
143 | + return '<span class="ee-status-strip ee-status-strip-td event-status-' . $item->get_active_status() . '"></span>'; |
|
144 | + }/**/ |
|
145 | + |
|
146 | + |
|
147 | + /** |
|
148 | + * @param EE_Event $item |
|
149 | + * @return string |
|
150 | + */ |
|
151 | + public function column_cb($item) |
|
152 | + { |
|
153 | + if (! $item instanceof EE_Event) { |
|
154 | + return ''; |
|
155 | + } |
|
156 | + $this->_dtt = $item->primary_datetime(); //set this for use in other columns |
|
157 | + |
|
158 | + //does event have any attached registrations? |
|
159 | + $regs = $item->count_related('Registration'); |
|
160 | + return $regs > 0 && $this->_view == 'trash' ? '<span class="ee-lock-icon"></span>' : sprintf( |
|
161 | + '<input type="checkbox" name="EVT_IDs[]" value="%s" />', $item->ID() |
|
162 | + ); |
|
163 | + } |
|
164 | + |
|
165 | + |
|
166 | + /** |
|
167 | + * @param EE_Event $item |
|
168 | + * @return mixed|string |
|
169 | + */ |
|
170 | + public function column_id(EE_Event $item) |
|
171 | + { |
|
172 | + $content = $item->ID(); |
|
173 | + $content .= ' <span class="show-on-mobile-view-only">' . $item->name() . '</span>'; |
|
174 | + return $content; |
|
175 | + } |
|
176 | + |
|
177 | + |
|
178 | + /** |
|
179 | + * @param EE_Event $item |
|
180 | + * @return string |
|
181 | + */ |
|
182 | + public function column_name(EE_Event $item) |
|
183 | + { |
|
184 | + $edit_query_args = array( |
|
185 | + 'action' => 'edit', |
|
186 | + 'post' => $item->ID(), |
|
187 | + ); |
|
188 | + $edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL); |
|
189 | + $actions = $this->_column_name_action_setup($item); |
|
190 | + $status = ''; //$item->status() !== 'publish' ? ' (' . $item->status() . ')' : ''; |
|
191 | + $content = '<strong><a class="row-title" href="' . $edit_link . '">' . $item->name() . '</a></strong>' . $status; |
|
192 | + $content .= '<br><span class="ee-status-text-small">' . EEH_Template::pretty_status($item->get_active_status(), |
|
193 | + false, 'sentence') . '</span>'; |
|
194 | + $content .= $this->row_actions($actions); |
|
195 | + return $content; |
|
196 | + |
|
197 | + } |
|
198 | + |
|
199 | + |
|
200 | + /** |
|
201 | + * Just a method for setting up the actions for the name column |
|
202 | + * |
|
203 | + * @param EE_Event $item |
|
204 | + * @return array array of actions |
|
205 | + */ |
|
206 | + protected function _column_name_action_setup(EE_Event $item) |
|
207 | + { |
|
208 | + //todo: remove when attendees is active |
|
209 | + if (! defined('REG_ADMIN_URL')) { |
|
210 | + define('REG_ADMIN_URL', EVENTS_ADMIN_URL); |
|
211 | + } |
|
212 | + |
|
213 | + $actions = array(); |
|
214 | + |
|
215 | + if (EE_Registry::instance()->CAP->current_user_can('ee_edit_event', 'espresso_events_edit', $item->ID())) { |
|
216 | + $edit_query_args = array( |
|
217 | + 'action' => 'edit', |
|
218 | + 'post' => $item->ID(), |
|
219 | + ); |
|
220 | + $edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL); |
|
221 | + $actions['edit'] = '<a href="' . $edit_link . '" title="' . esc_attr__('Edit Event', |
|
222 | + 'event_espresso') . '">' . __('Edit', 'event_espresso') . '</a>'; |
|
223 | + |
|
224 | + } |
|
225 | + |
|
226 | + if (EE_Registry::instance()->CAP->current_user_can('ee_read_registration', |
|
227 | + 'espresso_registrations_view_registration', $item->ID())) { |
|
228 | + $attendees_query_args = array( |
|
229 | + 'action' => 'default', |
|
230 | + 'event_id' => $item->ID(), |
|
231 | + ); |
|
232 | + $attendees_link = EE_Admin_Page::add_query_args_and_nonce($attendees_query_args, REG_ADMIN_URL); |
|
233 | + $actions['attendees'] = '<a href="' . $attendees_link . '" title="' . esc_attr__('View Registrations', |
|
234 | + 'event_espresso') . '">' . __('Registrations', 'event_espresso') . '</a>'; |
|
235 | + } |
|
236 | + |
|
237 | + if (EE_Registry::instance()->CAP->current_user_can('ee_delete_event', 'espresso_events_trash_event', |
|
238 | + $item->ID())) { |
|
239 | + $trash_event_query_args = array( |
|
240 | + 'action' => 'trash_event', |
|
241 | + 'EVT_ID' => $item->ID(), |
|
242 | + ); |
|
243 | + $trash_event_link = EE_Admin_Page::add_query_args_and_nonce($trash_event_query_args, |
|
244 | + EVENTS_ADMIN_URL); |
|
245 | + } |
|
246 | + |
|
247 | + if (EE_Registry::instance()->CAP->current_user_can('ee_delete_event', 'espresso_events_restore_event', |
|
248 | + $item->ID())) { |
|
249 | + $restore_event_query_args = array( |
|
250 | + 'action' => 'restore_event', |
|
251 | + 'EVT_ID' => $item->ID(), |
|
252 | + ); |
|
253 | + $restore_event_link = EE_Admin_Page::add_query_args_and_nonce($restore_event_query_args, |
|
254 | + EVENTS_ADMIN_URL); |
|
255 | + } |
|
256 | + |
|
257 | + if (EE_Registry::instance()->CAP->current_user_can('ee_delete_event', 'espresso_events_delete_event', |
|
258 | + $item->ID())) { |
|
259 | + $delete_event_query_args = array( |
|
260 | + 'action' => 'delete_event', |
|
261 | + 'EVT_ID' => $item->ID(), |
|
262 | + ); |
|
263 | + $delete_event_link = EE_Admin_Page::add_query_args_and_nonce($delete_event_query_args, |
|
264 | + EVENTS_ADMIN_URL); |
|
265 | + } |
|
266 | + |
|
267 | + $view_link = get_permalink($item->ID()); |
|
268 | + |
|
269 | + $actions['view'] = '<a href="' . $view_link . '" title="' . esc_attr__('View Event', |
|
270 | + 'event_espresso') . '">' . __('View', 'event_espresso') . '</a>'; |
|
271 | + |
|
272 | + switch ($item->get('status')) { |
|
273 | + case 'trash' : |
|
274 | + if (EE_Registry::instance()->CAP->current_user_can('ee_delete_event', 'espresso_events_restore_event', |
|
275 | + $item->ID())) { |
|
276 | + $actions['restore_from_trash'] = '<a href="' . $restore_event_link . '" title="' . esc_attr__('Restore from Trash', |
|
277 | + 'event_espresso') . '">' . __('Restore from Trash', 'event_espresso') . '</a>'; |
|
278 | + } |
|
279 | + if ($item->count_related('Registration') === 0 && EE_Registry::instance()->CAP->current_user_can('ee_delete_event', |
|
280 | + 'espresso_events_delete_event', $item->ID())) { |
|
281 | + $actions['delete'] = '<a href="' . $delete_event_link . '" title="' . esc_attr__('Delete Permanently', |
|
282 | + 'event_espresso') . '">' . __('Delete Permanently', 'event_espresso') . '</a>'; |
|
283 | + } |
|
284 | + break; |
|
285 | + default : |
|
286 | + if (EE_Registry::instance()->CAP->current_user_can('ee_delete_event', 'espresso_events_trash_event', |
|
287 | + $item->ID())) { |
|
288 | + $actions['move to trash'] = '<a href="' . $trash_event_link . '" title="' . esc_attr__('Trash Event', |
|
289 | + 'event_espresso') . '">' . __('Trash', 'event_espresso') . '</a>'; |
|
290 | + } |
|
291 | + } |
|
292 | + return $actions; |
|
293 | + } |
|
294 | + |
|
295 | + |
|
296 | + /** |
|
297 | + * @param EE_Event $item |
|
298 | + * @return string |
|
299 | + */ |
|
300 | + public function column_author(EE_Event $item) |
|
301 | + { |
|
302 | + //user author info |
|
303 | + $event_author = get_userdata($item->wp_user()); |
|
304 | + $gravatar = get_avatar($item->wp_user(), '15'); |
|
305 | + //filter link |
|
306 | + $query_args = array( |
|
307 | + 'action' => 'default', |
|
308 | + 'EVT_wp_user' => $item->wp_user(), |
|
309 | + ); |
|
310 | + $filter_url = EE_Admin_Page::add_query_args_and_nonce($query_args, EVENTS_ADMIN_URL); |
|
311 | + return $gravatar . ' <a href="' . $filter_url . '" title="' . esc_attr__('Click to filter events by this author.', |
|
312 | + 'event_espresso') . '">' . $event_author->display_name . '</a>'; |
|
313 | + } |
|
314 | + |
|
315 | + |
|
316 | + /** |
|
317 | + * @param EE_Event $item |
|
318 | + * @return string |
|
319 | + */ |
|
320 | + public function column_venue(EE_Event $item) |
|
321 | + { |
|
322 | + $venue = $item->get_first_related('Venue'); |
|
323 | + return ! empty($venue) ? $venue->name() : ''; |
|
324 | + } |
|
325 | + |
|
326 | + |
|
327 | + /** |
|
328 | + * @param EE_Event $item |
|
329 | + * @throws EE_Error |
|
330 | + */ |
|
331 | + public function column_start_date_time(EE_Event $item) |
|
332 | + { |
|
333 | + echo ! empty($this->_dtt) ? $this->_dtt->get_i18n_datetime('DTT_EVT_start') : __('No Date was saved for this Event', |
|
334 | + 'event_espresso'); |
|
335 | + //display in user's timezone? |
|
336 | + echo ! empty($this->_dtt) ? $this->_dtt->display_in_my_timezone('DTT_EVT_start', 'get_i18n_datetime', '', |
|
337 | + 'My Timezone: ') : ''; |
|
338 | + |
|
339 | + } |
|
340 | + |
|
341 | + |
|
342 | + /** |
|
343 | + * @param EE_Event $item |
|
344 | + * @throws EE_Error |
|
345 | + */ |
|
346 | + public function column_reg_begins(EE_Event $item) |
|
347 | + { |
|
348 | + $reg_start = $item->get_ticket_with_earliest_start_time(); |
|
349 | + echo ! empty($reg_start) ? $reg_start->get_i18n_datetime('TKT_start_date') : __('No Tickets have been setup for this Event', |
|
350 | + 'event_espresso'); |
|
351 | + //display in user's timezone? |
|
352 | + echo ! empty($reg_start) ? $reg_start->display_in_my_timezone('TKT_start_date', 'get_i18n_datetime', '', |
|
353 | + 'My Timezone: ') : '';/**/ |
|
354 | + } |
|
355 | + |
|
356 | + |
|
357 | + /** |
|
358 | + * @param EE_Event $item |
|
359 | + * @return int|string |
|
360 | + */ |
|
361 | + public function column_attendees(EE_Event $item) |
|
362 | + { |
|
363 | + $attendees_query_args = array( |
|
364 | + 'action' => 'default', |
|
365 | + 'event_id' => $item->ID(), |
|
366 | + ); |
|
367 | + $attendees_link = EE_Admin_Page::add_query_args_and_nonce($attendees_query_args, REG_ADMIN_URL); |
|
368 | + $registered_attendees = EEM_Registration::instance()->get_event_registration_count($item->ID()); |
|
369 | + return EE_Registry::instance()->CAP->current_user_can('ee_read_registration', |
|
370 | + 'espresso_registrations_view_registration', |
|
371 | + $item->ID()) ? '<a href="' . $attendees_link . '">' . $registered_attendees . '</a>' : $registered_attendees; |
|
372 | + } |
|
373 | + |
|
374 | + |
|
375 | + /** |
|
376 | + * @param EE_Event $item |
|
377 | + * @return float |
|
378 | + */ |
|
379 | + public function column_tkts_sold(EE_Event $item) |
|
380 | + { |
|
381 | + return EEM_Ticket::instance()->sum(array(array('Datetime.EVT_ID' => $item->ID())), 'TKT_sold'); |
|
382 | + } |
|
383 | + |
|
384 | + |
|
385 | + /** |
|
386 | + * @param EE_Event $item |
|
387 | + * @return string |
|
388 | + */ |
|
389 | + public function column_actions(EE_Event $item) |
|
390 | + { |
|
391 | + //todo: remove when attendees is active |
|
392 | + if (! defined('REG_ADMIN_URL')) { |
|
393 | + define('REG_ADMIN_URL', EVENTS_ADMIN_URL); |
|
394 | + } |
|
395 | + $actionlinks = array(); |
|
396 | + |
|
397 | + $view_link = get_permalink($item->ID()); |
|
398 | + |
|
399 | + $actionlinks[] = '<a href="' . $view_link . '" title="' . esc_attr__('View Event', |
|
400 | + 'event_espresso') . '" target="_blank">'; |
|
401 | + $actionlinks[] = '<div class="dashicons dashicons-search"></div></a>'; |
|
402 | + |
|
403 | + if (EE_Registry::instance()->CAP->current_user_can('ee_edit_event', 'espresso_events_edit', $item->ID())) { |
|
404 | + $edit_query_args = array( |
|
405 | + 'action' => 'edit', |
|
406 | + 'post' => $item->ID(), |
|
407 | + ); |
|
408 | + $edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL); |
|
409 | + $actionlinks[] = '<a href="' . $edit_link . '" title="' . esc_attr__('Edit Event', |
|
410 | + 'event_espresso') . '"><div class="ee-icon ee-icon-calendar-edit"></div></a>'; |
|
411 | + } |
|
412 | + |
|
413 | + if (EE_Registry::instance()->CAP->current_user_can('ee_read_registration', |
|
414 | + 'espresso_registrations_view_registration', $item->ID())) { |
|
415 | + $attendees_query_args = array( |
|
416 | + 'action' => 'default', |
|
417 | + 'event_id' => $item->ID(), |
|
418 | + ); |
|
419 | + $attendees_link = EE_Admin_Page::add_query_args_and_nonce($attendees_query_args, REG_ADMIN_URL); |
|
420 | + $actionlinks[] = '<a href="' . $attendees_link . '" title="' . esc_attr__('View Registrants', |
|
421 | + 'event_espresso') . '"><div class="dashicons dashicons-groups"></div></a>'; |
|
422 | + } |
|
423 | + |
|
424 | + $actionlinks = apply_filters('FHEE__Events_Admin_List_Table__column_actions__action_links', $actionlinks, |
|
425 | + $item); |
|
426 | + |
|
427 | + return $this->_action_string(implode("\n\t", $actionlinks), $item, 'div'); |
|
428 | + } |
|
429 | 429 | |
430 | 430 | |
431 | 431 | } |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
2 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
3 | 3 | exit('NO direct script access allowed'); |
4 | 4 | } |
5 | 5 | |
@@ -40,7 +40,7 @@ discard block |
||
40 | 40 | public function __construct($admin_page) |
41 | 41 | { |
42 | 42 | parent::__construct($admin_page); |
43 | - require_once(EE_HELPERS . 'EEH_DTT_Helper.helper.php'); |
|
43 | + require_once(EE_HELPERS.'EEH_DTT_Helper.helper.php'); |
|
44 | 44 | } |
45 | 45 | |
46 | 46 | |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | { |
127 | 127 | $class = parent::_get_row_class($item); |
128 | 128 | //add status class |
129 | - $class .= $item instanceof EE_Event ? ' ee-status-strip event-status-' . $item->get_active_status() : ''; |
|
129 | + $class .= $item instanceof EE_Event ? ' ee-status-strip event-status-'.$item->get_active_status() : ''; |
|
130 | 130 | if ($this->_has_checkbox_column) { |
131 | 131 | $class .= ' has-checkbox-column'; |
132 | 132 | } |
@@ -140,7 +140,7 @@ discard block |
||
140 | 140 | */ |
141 | 141 | public function column_status(EE_Event $item) |
142 | 142 | { |
143 | - return '<span class="ee-status-strip ee-status-strip-td event-status-' . $item->get_active_status() . '"></span>'; |
|
143 | + return '<span class="ee-status-strip ee-status-strip-td event-status-'.$item->get_active_status().'"></span>'; |
|
144 | 144 | }/**/ |
145 | 145 | |
146 | 146 | |
@@ -150,7 +150,7 @@ discard block |
||
150 | 150 | */ |
151 | 151 | public function column_cb($item) |
152 | 152 | { |
153 | - if (! $item instanceof EE_Event) { |
|
153 | + if ( ! $item instanceof EE_Event) { |
|
154 | 154 | return ''; |
155 | 155 | } |
156 | 156 | $this->_dtt = $item->primary_datetime(); //set this for use in other columns |
@@ -170,7 +170,7 @@ discard block |
||
170 | 170 | public function column_id(EE_Event $item) |
171 | 171 | { |
172 | 172 | $content = $item->ID(); |
173 | - $content .= ' <span class="show-on-mobile-view-only">' . $item->name() . '</span>'; |
|
173 | + $content .= ' <span class="show-on-mobile-view-only">'.$item->name().'</span>'; |
|
174 | 174 | return $content; |
175 | 175 | } |
176 | 176 | |
@@ -188,9 +188,9 @@ discard block |
||
188 | 188 | $edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL); |
189 | 189 | $actions = $this->_column_name_action_setup($item); |
190 | 190 | $status = ''; //$item->status() !== 'publish' ? ' (' . $item->status() . ')' : ''; |
191 | - $content = '<strong><a class="row-title" href="' . $edit_link . '">' . $item->name() . '</a></strong>' . $status; |
|
192 | - $content .= '<br><span class="ee-status-text-small">' . EEH_Template::pretty_status($item->get_active_status(), |
|
193 | - false, 'sentence') . '</span>'; |
|
191 | + $content = '<strong><a class="row-title" href="'.$edit_link.'">'.$item->name().'</a></strong>'.$status; |
|
192 | + $content .= '<br><span class="ee-status-text-small">'.EEH_Template::pretty_status($item->get_active_status(), |
|
193 | + false, 'sentence').'</span>'; |
|
194 | 194 | $content .= $this->row_actions($actions); |
195 | 195 | return $content; |
196 | 196 | |
@@ -206,7 +206,7 @@ discard block |
||
206 | 206 | protected function _column_name_action_setup(EE_Event $item) |
207 | 207 | { |
208 | 208 | //todo: remove when attendees is active |
209 | - if (! defined('REG_ADMIN_URL')) { |
|
209 | + if ( ! defined('REG_ADMIN_URL')) { |
|
210 | 210 | define('REG_ADMIN_URL', EVENTS_ADMIN_URL); |
211 | 211 | } |
212 | 212 | |
@@ -218,8 +218,8 @@ discard block |
||
218 | 218 | 'post' => $item->ID(), |
219 | 219 | ); |
220 | 220 | $edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL); |
221 | - $actions['edit'] = '<a href="' . $edit_link . '" title="' . esc_attr__('Edit Event', |
|
222 | - 'event_espresso') . '">' . __('Edit', 'event_espresso') . '</a>'; |
|
221 | + $actions['edit'] = '<a href="'.$edit_link.'" title="'.esc_attr__('Edit Event', |
|
222 | + 'event_espresso').'">'.__('Edit', 'event_espresso').'</a>'; |
|
223 | 223 | |
224 | 224 | } |
225 | 225 | |
@@ -230,8 +230,8 @@ discard block |
||
230 | 230 | 'event_id' => $item->ID(), |
231 | 231 | ); |
232 | 232 | $attendees_link = EE_Admin_Page::add_query_args_and_nonce($attendees_query_args, REG_ADMIN_URL); |
233 | - $actions['attendees'] = '<a href="' . $attendees_link . '" title="' . esc_attr__('View Registrations', |
|
234 | - 'event_espresso') . '">' . __('Registrations', 'event_espresso') . '</a>'; |
|
233 | + $actions['attendees'] = '<a href="'.$attendees_link.'" title="'.esc_attr__('View Registrations', |
|
234 | + 'event_espresso').'">'.__('Registrations', 'event_espresso').'</a>'; |
|
235 | 235 | } |
236 | 236 | |
237 | 237 | if (EE_Registry::instance()->CAP->current_user_can('ee_delete_event', 'espresso_events_trash_event', |
@@ -240,7 +240,7 @@ discard block |
||
240 | 240 | 'action' => 'trash_event', |
241 | 241 | 'EVT_ID' => $item->ID(), |
242 | 242 | ); |
243 | - $trash_event_link = EE_Admin_Page::add_query_args_and_nonce($trash_event_query_args, |
|
243 | + $trash_event_link = EE_Admin_Page::add_query_args_and_nonce($trash_event_query_args, |
|
244 | 244 | EVENTS_ADMIN_URL); |
245 | 245 | } |
246 | 246 | |
@@ -250,7 +250,7 @@ discard block |
||
250 | 250 | 'action' => 'restore_event', |
251 | 251 | 'EVT_ID' => $item->ID(), |
252 | 252 | ); |
253 | - $restore_event_link = EE_Admin_Page::add_query_args_and_nonce($restore_event_query_args, |
|
253 | + $restore_event_link = EE_Admin_Page::add_query_args_and_nonce($restore_event_query_args, |
|
254 | 254 | EVENTS_ADMIN_URL); |
255 | 255 | } |
256 | 256 | |
@@ -260,33 +260,33 @@ discard block |
||
260 | 260 | 'action' => 'delete_event', |
261 | 261 | 'EVT_ID' => $item->ID(), |
262 | 262 | ); |
263 | - $delete_event_link = EE_Admin_Page::add_query_args_and_nonce($delete_event_query_args, |
|
263 | + $delete_event_link = EE_Admin_Page::add_query_args_and_nonce($delete_event_query_args, |
|
264 | 264 | EVENTS_ADMIN_URL); |
265 | 265 | } |
266 | 266 | |
267 | 267 | $view_link = get_permalink($item->ID()); |
268 | 268 | |
269 | - $actions['view'] = '<a href="' . $view_link . '" title="' . esc_attr__('View Event', |
|
270 | - 'event_espresso') . '">' . __('View', 'event_espresso') . '</a>'; |
|
269 | + $actions['view'] = '<a href="'.$view_link.'" title="'.esc_attr__('View Event', |
|
270 | + 'event_espresso').'">'.__('View', 'event_espresso').'</a>'; |
|
271 | 271 | |
272 | 272 | switch ($item->get('status')) { |
273 | 273 | case 'trash' : |
274 | 274 | if (EE_Registry::instance()->CAP->current_user_can('ee_delete_event', 'espresso_events_restore_event', |
275 | 275 | $item->ID())) { |
276 | - $actions['restore_from_trash'] = '<a href="' . $restore_event_link . '" title="' . esc_attr__('Restore from Trash', |
|
277 | - 'event_espresso') . '">' . __('Restore from Trash', 'event_espresso') . '</a>'; |
|
276 | + $actions['restore_from_trash'] = '<a href="'.$restore_event_link.'" title="'.esc_attr__('Restore from Trash', |
|
277 | + 'event_espresso').'">'.__('Restore from Trash', 'event_espresso').'</a>'; |
|
278 | 278 | } |
279 | 279 | if ($item->count_related('Registration') === 0 && EE_Registry::instance()->CAP->current_user_can('ee_delete_event', |
280 | 280 | 'espresso_events_delete_event', $item->ID())) { |
281 | - $actions['delete'] = '<a href="' . $delete_event_link . '" title="' . esc_attr__('Delete Permanently', |
|
282 | - 'event_espresso') . '">' . __('Delete Permanently', 'event_espresso') . '</a>'; |
|
281 | + $actions['delete'] = '<a href="'.$delete_event_link.'" title="'.esc_attr__('Delete Permanently', |
|
282 | + 'event_espresso').'">'.__('Delete Permanently', 'event_espresso').'</a>'; |
|
283 | 283 | } |
284 | 284 | break; |
285 | 285 | default : |
286 | 286 | if (EE_Registry::instance()->CAP->current_user_can('ee_delete_event', 'espresso_events_trash_event', |
287 | 287 | $item->ID())) { |
288 | - $actions['move to trash'] = '<a href="' . $trash_event_link . '" title="' . esc_attr__('Trash Event', |
|
289 | - 'event_espresso') . '">' . __('Trash', 'event_espresso') . '</a>'; |
|
288 | + $actions['move to trash'] = '<a href="'.$trash_event_link.'" title="'.esc_attr__('Trash Event', |
|
289 | + 'event_espresso').'">'.__('Trash', 'event_espresso').'</a>'; |
|
290 | 290 | } |
291 | 291 | } |
292 | 292 | return $actions; |
@@ -308,8 +308,8 @@ discard block |
||
308 | 308 | 'EVT_wp_user' => $item->wp_user(), |
309 | 309 | ); |
310 | 310 | $filter_url = EE_Admin_Page::add_query_args_and_nonce($query_args, EVENTS_ADMIN_URL); |
311 | - return $gravatar . ' <a href="' . $filter_url . '" title="' . esc_attr__('Click to filter events by this author.', |
|
312 | - 'event_espresso') . '">' . $event_author->display_name . '</a>'; |
|
311 | + return $gravatar.' <a href="'.$filter_url.'" title="'.esc_attr__('Click to filter events by this author.', |
|
312 | + 'event_espresso').'">'.$event_author->display_name.'</a>'; |
|
313 | 313 | } |
314 | 314 | |
315 | 315 | |
@@ -350,7 +350,7 @@ discard block |
||
350 | 350 | 'event_espresso'); |
351 | 351 | //display in user's timezone? |
352 | 352 | echo ! empty($reg_start) ? $reg_start->display_in_my_timezone('TKT_start_date', 'get_i18n_datetime', '', |
353 | - 'My Timezone: ') : '';/**/ |
|
353 | + 'My Timezone: ') : ''; /**/ |
|
354 | 354 | } |
355 | 355 | |
356 | 356 | |
@@ -368,7 +368,7 @@ discard block |
||
368 | 368 | $registered_attendees = EEM_Registration::instance()->get_event_registration_count($item->ID()); |
369 | 369 | return EE_Registry::instance()->CAP->current_user_can('ee_read_registration', |
370 | 370 | 'espresso_registrations_view_registration', |
371 | - $item->ID()) ? '<a href="' . $attendees_link . '">' . $registered_attendees . '</a>' : $registered_attendees; |
|
371 | + $item->ID()) ? '<a href="'.$attendees_link.'">'.$registered_attendees.'</a>' : $registered_attendees; |
|
372 | 372 | } |
373 | 373 | |
374 | 374 | |
@@ -389,15 +389,15 @@ discard block |
||
389 | 389 | public function column_actions(EE_Event $item) |
390 | 390 | { |
391 | 391 | //todo: remove when attendees is active |
392 | - if (! defined('REG_ADMIN_URL')) { |
|
392 | + if ( ! defined('REG_ADMIN_URL')) { |
|
393 | 393 | define('REG_ADMIN_URL', EVENTS_ADMIN_URL); |
394 | 394 | } |
395 | 395 | $actionlinks = array(); |
396 | 396 | |
397 | 397 | $view_link = get_permalink($item->ID()); |
398 | 398 | |
399 | - $actionlinks[] = '<a href="' . $view_link . '" title="' . esc_attr__('View Event', |
|
400 | - 'event_espresso') . '" target="_blank">'; |
|
399 | + $actionlinks[] = '<a href="'.$view_link.'" title="'.esc_attr__('View Event', |
|
400 | + 'event_espresso').'" target="_blank">'; |
|
401 | 401 | $actionlinks[] = '<div class="dashicons dashicons-search"></div></a>'; |
402 | 402 | |
403 | 403 | if (EE_Registry::instance()->CAP->current_user_can('ee_edit_event', 'espresso_events_edit', $item->ID())) { |
@@ -406,8 +406,8 @@ discard block |
||
406 | 406 | 'post' => $item->ID(), |
407 | 407 | ); |
408 | 408 | $edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL); |
409 | - $actionlinks[] = '<a href="' . $edit_link . '" title="' . esc_attr__('Edit Event', |
|
410 | - 'event_espresso') . '"><div class="ee-icon ee-icon-calendar-edit"></div></a>'; |
|
409 | + $actionlinks[] = '<a href="'.$edit_link.'" title="'.esc_attr__('Edit Event', |
|
410 | + 'event_espresso').'"><div class="ee-icon ee-icon-calendar-edit"></div></a>'; |
|
411 | 411 | } |
412 | 412 | |
413 | 413 | if (EE_Registry::instance()->CAP->current_user_can('ee_read_registration', |
@@ -417,8 +417,8 @@ discard block |
||
417 | 417 | 'event_id' => $item->ID(), |
418 | 418 | ); |
419 | 419 | $attendees_link = EE_Admin_Page::add_query_args_and_nonce($attendees_query_args, REG_ADMIN_URL); |
420 | - $actionlinks[] = '<a href="' . $attendees_link . '" title="' . esc_attr__('View Registrants', |
|
421 | - 'event_espresso') . '"><div class="dashicons dashicons-groups"></div></a>'; |
|
420 | + $actionlinks[] = '<a href="'.$attendees_link.'" title="'.esc_attr__('View Registrants', |
|
421 | + 'event_espresso').'"><div class="dashicons dashicons-groups"></div></a>'; |
|
422 | 422 | } |
423 | 423 | |
424 | 424 | $actionlinks = apply_filters('FHEE__Events_Admin_List_Table__column_actions__action_links', $actionlinks, |
@@ -17,243 +17,243 @@ |
||
17 | 17 | final class EE_Module_Request_Router implements InterminableInterface |
18 | 18 | { |
19 | 19 | |
20 | - /** |
|
21 | - * @var array $_previous_routes |
|
22 | - */ |
|
23 | - private static $_previous_routes = array(); |
|
20 | + /** |
|
21 | + * @var array $_previous_routes |
|
22 | + */ |
|
23 | + private static $_previous_routes = array(); |
|
24 | 24 | |
25 | - /** |
|
26 | - * @var WP_Query $WP_Query |
|
27 | - */ |
|
28 | - public $WP_Query; |
|
25 | + /** |
|
26 | + * @var WP_Query $WP_Query |
|
27 | + */ |
|
28 | + public $WP_Query; |
|
29 | 29 | |
30 | 30 | |
31 | 31 | |
32 | - /** |
|
33 | - * EE_Module_Request_Router constructor. |
|
34 | - */ |
|
35 | - public function __construct() |
|
36 | - { |
|
37 | - } |
|
32 | + /** |
|
33 | + * EE_Module_Request_Router constructor. |
|
34 | + */ |
|
35 | + public function __construct() |
|
36 | + { |
|
37 | + } |
|
38 | 38 | |
39 | 39 | |
40 | 40 | |
41 | - /** |
|
42 | - * on the first call to this method, it checks the EE_Request_Handler for a "route" |
|
43 | - * on subsequent calls to this method, |
|
44 | - * instead of checking the EE_Request_Handler for a route, it checks the previous routes array, |
|
45 | - * and checks if the last called route has any forwarding routes registered for it |
|
46 | - * |
|
47 | - * @param WP_Query $WP_Query |
|
48 | - * @return NULL|string |
|
49 | - * @throws EE_Error |
|
50 | - * @throws ReflectionException |
|
51 | - */ |
|
52 | - public function get_route(WP_Query $WP_Query) |
|
53 | - { |
|
54 | - $this->WP_Query = $WP_Query; |
|
55 | - // assume this if first route being called |
|
56 | - $previous_route = false; |
|
57 | - // but is it really ??? |
|
58 | - if (! empty(self::$_previous_routes)) { |
|
59 | - // get last run route |
|
60 | - $previous_routes = array_values(self::$_previous_routes); |
|
61 | - $previous_route = array_pop($previous_routes); |
|
62 | - } |
|
63 | - // has another route already been run ? |
|
64 | - if ($previous_route) { |
|
65 | - // check if forwarding has been set |
|
66 | - $current_route = $this->get_forward($previous_route); |
|
67 | - try { |
|
68 | - //check for recursive forwarding |
|
69 | - if (isset(self::$_previous_routes[$current_route])) { |
|
70 | - throw new EE_Error( |
|
71 | - sprintf( |
|
72 | - __( |
|
73 | - 'An error occurred. The %s route has already been called, and therefore can not be forwarded to, because an infinite loop would be created and break the interweb.', |
|
74 | - 'event_espresso' |
|
75 | - ), |
|
76 | - $current_route |
|
77 | - ) |
|
78 | - ); |
|
79 | - } |
|
80 | - } catch (EE_Error $e) { |
|
81 | - $e->get_error(); |
|
82 | - return null; |
|
83 | - } |
|
84 | - } else { |
|
85 | - // first route called |
|
86 | - $current_route = null; |
|
87 | - // grab all routes |
|
88 | - $routes = EE_Config::get_routes(); |
|
89 | - //d( $routes ); |
|
90 | - foreach ($routes as $key => $route) { |
|
91 | - // check request for module route |
|
92 | - if (EE_Registry::instance()->REQ->is_set($key)) { |
|
93 | - //echo '<b style="color:#2EA2CC;">key : <span style="color:#E76700">' . $key . '</span></b><br />'; |
|
94 | - $current_route = sanitize_text_field(EE_Registry::instance()->REQ->get($key)); |
|
95 | - if ($current_route) { |
|
96 | - $current_route = array($key, $current_route); |
|
97 | - //echo '<b style="color:#2EA2CC;">current_route : <span style="color:#E76700">' . $current_route . '</span></b><br />'; |
|
98 | - break; |
|
99 | - } |
|
100 | - } |
|
101 | - } |
|
102 | - } |
|
103 | - // sorry, but I can't read what you route ! |
|
104 | - if (empty($current_route)) { |
|
105 | - return null; |
|
106 | - } |
|
107 | - //add route to previous routes array |
|
108 | - self::$_previous_routes[] = $current_route; |
|
109 | - return $current_route; |
|
110 | - } |
|
41 | + /** |
|
42 | + * on the first call to this method, it checks the EE_Request_Handler for a "route" |
|
43 | + * on subsequent calls to this method, |
|
44 | + * instead of checking the EE_Request_Handler for a route, it checks the previous routes array, |
|
45 | + * and checks if the last called route has any forwarding routes registered for it |
|
46 | + * |
|
47 | + * @param WP_Query $WP_Query |
|
48 | + * @return NULL|string |
|
49 | + * @throws EE_Error |
|
50 | + * @throws ReflectionException |
|
51 | + */ |
|
52 | + public function get_route(WP_Query $WP_Query) |
|
53 | + { |
|
54 | + $this->WP_Query = $WP_Query; |
|
55 | + // assume this if first route being called |
|
56 | + $previous_route = false; |
|
57 | + // but is it really ??? |
|
58 | + if (! empty(self::$_previous_routes)) { |
|
59 | + // get last run route |
|
60 | + $previous_routes = array_values(self::$_previous_routes); |
|
61 | + $previous_route = array_pop($previous_routes); |
|
62 | + } |
|
63 | + // has another route already been run ? |
|
64 | + if ($previous_route) { |
|
65 | + // check if forwarding has been set |
|
66 | + $current_route = $this->get_forward($previous_route); |
|
67 | + try { |
|
68 | + //check for recursive forwarding |
|
69 | + if (isset(self::$_previous_routes[$current_route])) { |
|
70 | + throw new EE_Error( |
|
71 | + sprintf( |
|
72 | + __( |
|
73 | + 'An error occurred. The %s route has already been called, and therefore can not be forwarded to, because an infinite loop would be created and break the interweb.', |
|
74 | + 'event_espresso' |
|
75 | + ), |
|
76 | + $current_route |
|
77 | + ) |
|
78 | + ); |
|
79 | + } |
|
80 | + } catch (EE_Error $e) { |
|
81 | + $e->get_error(); |
|
82 | + return null; |
|
83 | + } |
|
84 | + } else { |
|
85 | + // first route called |
|
86 | + $current_route = null; |
|
87 | + // grab all routes |
|
88 | + $routes = EE_Config::get_routes(); |
|
89 | + //d( $routes ); |
|
90 | + foreach ($routes as $key => $route) { |
|
91 | + // check request for module route |
|
92 | + if (EE_Registry::instance()->REQ->is_set($key)) { |
|
93 | + //echo '<b style="color:#2EA2CC;">key : <span style="color:#E76700">' . $key . '</span></b><br />'; |
|
94 | + $current_route = sanitize_text_field(EE_Registry::instance()->REQ->get($key)); |
|
95 | + if ($current_route) { |
|
96 | + $current_route = array($key, $current_route); |
|
97 | + //echo '<b style="color:#2EA2CC;">current_route : <span style="color:#E76700">' . $current_route . '</span></b><br />'; |
|
98 | + break; |
|
99 | + } |
|
100 | + } |
|
101 | + } |
|
102 | + } |
|
103 | + // sorry, but I can't read what you route ! |
|
104 | + if (empty($current_route)) { |
|
105 | + return null; |
|
106 | + } |
|
107 | + //add route to previous routes array |
|
108 | + self::$_previous_routes[] = $current_route; |
|
109 | + return $current_route; |
|
110 | + } |
|
111 | 111 | |
112 | 112 | |
113 | 113 | |
114 | - /** |
|
115 | - * this method simply takes a valid route, and resolves what module class method the route points to |
|
116 | - * |
|
117 | - * @param string $key |
|
118 | - * @param string $current_route |
|
119 | - * @return mixed EED_Module | boolean |
|
120 | - * @throws EE_Error |
|
121 | - * @throws ReflectionException |
|
122 | - */ |
|
123 | - public function resolve_route($key, $current_route) |
|
124 | - { |
|
125 | - // get module method that route has been mapped to |
|
126 | - $module_method = EE_Config::get_route($current_route, $key); |
|
127 | - //EEH_Debug_Tools::printr( $module_method, '$module_method <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' ); |
|
128 | - // verify result was returned |
|
129 | - if (empty($module_method)) { |
|
130 | - $msg = sprintf( |
|
131 | - __('The requested route %s could not be mapped to any registered modules.', 'event_espresso'), |
|
132 | - $current_route |
|
133 | - ); |
|
134 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
135 | - return false; |
|
136 | - } |
|
137 | - // verify that result is an array |
|
138 | - if (! is_array($module_method)) { |
|
139 | - $msg = sprintf(__('The %s route has not been properly registered.', 'event_espresso'), $current_route); |
|
140 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
141 | - return false; |
|
142 | - } |
|
143 | - // grab module name |
|
144 | - $module_name = $module_method[0]; |
|
145 | - // verify that a class method was registered properly |
|
146 | - if (! isset($module_method[1])) { |
|
147 | - $msg = sprintf( |
|
148 | - __('A class method for the %s route has not been properly registered.', 'event_espresso'), |
|
149 | - $current_route |
|
150 | - ); |
|
151 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
152 | - return false; |
|
153 | - } |
|
154 | - // grab method |
|
155 | - $method = $module_method[1]; |
|
156 | - // verify that class exists |
|
157 | - if (! class_exists($module_name)) { |
|
158 | - $msg = sprintf(__('The requested %s class could not be found.', 'event_espresso'), $module_name); |
|
159 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
160 | - return false; |
|
161 | - } |
|
162 | - // verify that method exists |
|
163 | - if (! method_exists($module_name, $method)) { |
|
164 | - $msg = sprintf( |
|
165 | - __('The class method %s for the %s route is in invalid.', 'event_espresso'), $method, $current_route |
|
166 | - ); |
|
167 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
168 | - return false; |
|
169 | - } |
|
170 | - // instantiate module and call route method |
|
171 | - return $this->_module_router($module_name, $method); |
|
172 | - } |
|
114 | + /** |
|
115 | + * this method simply takes a valid route, and resolves what module class method the route points to |
|
116 | + * |
|
117 | + * @param string $key |
|
118 | + * @param string $current_route |
|
119 | + * @return mixed EED_Module | boolean |
|
120 | + * @throws EE_Error |
|
121 | + * @throws ReflectionException |
|
122 | + */ |
|
123 | + public function resolve_route($key, $current_route) |
|
124 | + { |
|
125 | + // get module method that route has been mapped to |
|
126 | + $module_method = EE_Config::get_route($current_route, $key); |
|
127 | + //EEH_Debug_Tools::printr( $module_method, '$module_method <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' ); |
|
128 | + // verify result was returned |
|
129 | + if (empty($module_method)) { |
|
130 | + $msg = sprintf( |
|
131 | + __('The requested route %s could not be mapped to any registered modules.', 'event_espresso'), |
|
132 | + $current_route |
|
133 | + ); |
|
134 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
135 | + return false; |
|
136 | + } |
|
137 | + // verify that result is an array |
|
138 | + if (! is_array($module_method)) { |
|
139 | + $msg = sprintf(__('The %s route has not been properly registered.', 'event_espresso'), $current_route); |
|
140 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
141 | + return false; |
|
142 | + } |
|
143 | + // grab module name |
|
144 | + $module_name = $module_method[0]; |
|
145 | + // verify that a class method was registered properly |
|
146 | + if (! isset($module_method[1])) { |
|
147 | + $msg = sprintf( |
|
148 | + __('A class method for the %s route has not been properly registered.', 'event_espresso'), |
|
149 | + $current_route |
|
150 | + ); |
|
151 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
152 | + return false; |
|
153 | + } |
|
154 | + // grab method |
|
155 | + $method = $module_method[1]; |
|
156 | + // verify that class exists |
|
157 | + if (! class_exists($module_name)) { |
|
158 | + $msg = sprintf(__('The requested %s class could not be found.', 'event_espresso'), $module_name); |
|
159 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
160 | + return false; |
|
161 | + } |
|
162 | + // verify that method exists |
|
163 | + if (! method_exists($module_name, $method)) { |
|
164 | + $msg = sprintf( |
|
165 | + __('The class method %s for the %s route is in invalid.', 'event_espresso'), $method, $current_route |
|
166 | + ); |
|
167 | + EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
168 | + return false; |
|
169 | + } |
|
170 | + // instantiate module and call route method |
|
171 | + return $this->_module_router($module_name, $method); |
|
172 | + } |
|
173 | 173 | |
174 | 174 | |
175 | 175 | |
176 | - /** |
|
177 | - * this method instantiates modules and calls the method that was defined when the route was registered |
|
178 | - * |
|
179 | - * @param string $module_name |
|
180 | - * @return EED_Module|object|null |
|
181 | - * @throws ReflectionException |
|
182 | - */ |
|
183 | - public static function module_factory($module_name) |
|
184 | - { |
|
185 | - if ($module_name === 'EED_Module') { |
|
186 | - EE_Error::add_error( |
|
187 | - sprintf( |
|
188 | - __( |
|
189 | - 'EED_Module is an abstract parent class an can not be instantiated. Please provide a proper module name.', |
|
190 | - 'event_espresso' |
|
191 | - ), $module_name |
|
192 | - ), __FILE__, __FUNCTION__, __LINE__ |
|
193 | - ); |
|
194 | - return null; |
|
195 | - } |
|
196 | - // instantiate module class |
|
197 | - $module = new $module_name(); |
|
198 | - // ensure that class is actually a module |
|
199 | - if (! $module instanceof EED_Module) { |
|
200 | - EE_Error::add_error( |
|
201 | - sprintf(__('The requested %s module is not of the class EED_Module.', 'event_espresso'), $module_name), |
|
202 | - __FILE__, __FUNCTION__, __LINE__ |
|
203 | - ); |
|
204 | - return null; |
|
205 | - } |
|
206 | - return $module; |
|
207 | - } |
|
176 | + /** |
|
177 | + * this method instantiates modules and calls the method that was defined when the route was registered |
|
178 | + * |
|
179 | + * @param string $module_name |
|
180 | + * @return EED_Module|object|null |
|
181 | + * @throws ReflectionException |
|
182 | + */ |
|
183 | + public static function module_factory($module_name) |
|
184 | + { |
|
185 | + if ($module_name === 'EED_Module') { |
|
186 | + EE_Error::add_error( |
|
187 | + sprintf( |
|
188 | + __( |
|
189 | + 'EED_Module is an abstract parent class an can not be instantiated. Please provide a proper module name.', |
|
190 | + 'event_espresso' |
|
191 | + ), $module_name |
|
192 | + ), __FILE__, __FUNCTION__, __LINE__ |
|
193 | + ); |
|
194 | + return null; |
|
195 | + } |
|
196 | + // instantiate module class |
|
197 | + $module = new $module_name(); |
|
198 | + // ensure that class is actually a module |
|
199 | + if (! $module instanceof EED_Module) { |
|
200 | + EE_Error::add_error( |
|
201 | + sprintf(__('The requested %s module is not of the class EED_Module.', 'event_espresso'), $module_name), |
|
202 | + __FILE__, __FUNCTION__, __LINE__ |
|
203 | + ); |
|
204 | + return null; |
|
205 | + } |
|
206 | + return $module; |
|
207 | + } |
|
208 | 208 | |
209 | 209 | |
210 | 210 | |
211 | - /** |
|
212 | - * this method instantiates modules and calls the method that was defined when the route was registered |
|
213 | - * |
|
214 | - * @param string $module_name |
|
215 | - * @param string $method |
|
216 | - * @return EED_Module|null |
|
217 | - * @throws EE_Error |
|
218 | - * @throws ReflectionException |
|
219 | - */ |
|
220 | - private function _module_router($module_name, $method) |
|
221 | - { |
|
222 | - // instantiate module class |
|
223 | - $module = EE_Module_Request_Router::module_factory($module_name); |
|
224 | - if ($module instanceof EED_Module) { |
|
225 | - // and call whatever action the route was for |
|
226 | - try { |
|
227 | - call_user_func(array($module, $method), $this->WP_Query); |
|
228 | - } catch (EE_Error $e) { |
|
229 | - $e->get_error(); |
|
230 | - return null; |
|
231 | - } |
|
232 | - } |
|
233 | - return $module; |
|
234 | - } |
|
211 | + /** |
|
212 | + * this method instantiates modules and calls the method that was defined when the route was registered |
|
213 | + * |
|
214 | + * @param string $module_name |
|
215 | + * @param string $method |
|
216 | + * @return EED_Module|null |
|
217 | + * @throws EE_Error |
|
218 | + * @throws ReflectionException |
|
219 | + */ |
|
220 | + private function _module_router($module_name, $method) |
|
221 | + { |
|
222 | + // instantiate module class |
|
223 | + $module = EE_Module_Request_Router::module_factory($module_name); |
|
224 | + if ($module instanceof EED_Module) { |
|
225 | + // and call whatever action the route was for |
|
226 | + try { |
|
227 | + call_user_func(array($module, $method), $this->WP_Query); |
|
228 | + } catch (EE_Error $e) { |
|
229 | + $e->get_error(); |
|
230 | + return null; |
|
231 | + } |
|
232 | + } |
|
233 | + return $module; |
|
234 | + } |
|
235 | 235 | |
236 | 236 | |
237 | 237 | |
238 | - /** |
|
239 | - * @param $current_route |
|
240 | - * @return string |
|
241 | - */ |
|
242 | - public function get_forward($current_route) |
|
243 | - { |
|
244 | - return EE_Config::get_forward($current_route); |
|
245 | - } |
|
238 | + /** |
|
239 | + * @param $current_route |
|
240 | + * @return string |
|
241 | + */ |
|
242 | + public function get_forward($current_route) |
|
243 | + { |
|
244 | + return EE_Config::get_forward($current_route); |
|
245 | + } |
|
246 | 246 | |
247 | 247 | |
248 | 248 | |
249 | - /** |
|
250 | - * @param $current_route |
|
251 | - * @return string |
|
252 | - */ |
|
253 | - public function get_view($current_route) |
|
254 | - { |
|
255 | - return EE_Config::get_view($current_route); |
|
256 | - } |
|
249 | + /** |
|
250 | + * @param $current_route |
|
251 | + * @return string |
|
252 | + */ |
|
253 | + public function get_view($current_route) |
|
254 | + { |
|
255 | + return EE_Config::get_view($current_route); |
|
256 | + } |
|
257 | 257 | |
258 | 258 | |
259 | 259 | } |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | // assume this if first route being called |
56 | 56 | $previous_route = false; |
57 | 57 | // but is it really ??? |
58 | - if (! empty(self::$_previous_routes)) { |
|
58 | + if ( ! empty(self::$_previous_routes)) { |
|
59 | 59 | // get last run route |
60 | 60 | $previous_routes = array_values(self::$_previous_routes); |
61 | 61 | $previous_route = array_pop($previous_routes); |
@@ -135,36 +135,36 @@ discard block |
||
135 | 135 | return false; |
136 | 136 | } |
137 | 137 | // verify that result is an array |
138 | - if (! is_array($module_method)) { |
|
138 | + if ( ! is_array($module_method)) { |
|
139 | 139 | $msg = sprintf(__('The %s route has not been properly registered.', 'event_espresso'), $current_route); |
140 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
140 | + EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__); |
|
141 | 141 | return false; |
142 | 142 | } |
143 | 143 | // grab module name |
144 | 144 | $module_name = $module_method[0]; |
145 | 145 | // verify that a class method was registered properly |
146 | - if (! isset($module_method[1])) { |
|
146 | + if ( ! isset($module_method[1])) { |
|
147 | 147 | $msg = sprintf( |
148 | 148 | __('A class method for the %s route has not been properly registered.', 'event_espresso'), |
149 | 149 | $current_route |
150 | 150 | ); |
151 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
151 | + EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__); |
|
152 | 152 | return false; |
153 | 153 | } |
154 | 154 | // grab method |
155 | 155 | $method = $module_method[1]; |
156 | 156 | // verify that class exists |
157 | - if (! class_exists($module_name)) { |
|
157 | + if ( ! class_exists($module_name)) { |
|
158 | 158 | $msg = sprintf(__('The requested %s class could not be found.', 'event_espresso'), $module_name); |
159 | 159 | EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
160 | 160 | return false; |
161 | 161 | } |
162 | 162 | // verify that method exists |
163 | - if (! method_exists($module_name, $method)) { |
|
163 | + if ( ! method_exists($module_name, $method)) { |
|
164 | 164 | $msg = sprintf( |
165 | 165 | __('The class method %s for the %s route is in invalid.', 'event_espresso'), $method, $current_route |
166 | 166 | ); |
167 | - EE_Error::add_error($msg . '||' . $msg, __FILE__, __FUNCTION__, __LINE__); |
|
167 | + EE_Error::add_error($msg.'||'.$msg, __FILE__, __FUNCTION__, __LINE__); |
|
168 | 168 | return false; |
169 | 169 | } |
170 | 170 | // instantiate module and call route method |
@@ -196,7 +196,7 @@ discard block |
||
196 | 196 | // instantiate module class |
197 | 197 | $module = new $module_name(); |
198 | 198 | // ensure that class is actually a module |
199 | - if (! $module instanceof EED_Module) { |
|
199 | + if ( ! $module instanceof EED_Module) { |
|
200 | 200 | EE_Error::add_error( |
201 | 201 | sprintf(__('The requested %s module is not of the class EED_Module.', 'event_espresso'), $module_name), |
202 | 202 | __FILE__, __FUNCTION__, __LINE__ |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php if (! defined('EVENT_ESPRESSO_VERSION')) { |
2 | - exit('No direct script access allowed'); |
|
2 | + exit('No direct script access allowed'); |
|
3 | 3 | } |
4 | 4 | |
5 | 5 | /** |
@@ -23,104 +23,104 @@ discard block |
||
23 | 23 | { |
24 | 24 | |
25 | 25 | |
26 | - /** |
|
27 | - * REG_date |
|
28 | - */ |
|
29 | - function column_REG_date(EE_Registration $item) |
|
30 | - { |
|
26 | + /** |
|
27 | + * REG_date |
|
28 | + */ |
|
29 | + function column_REG_date(EE_Registration $item) |
|
30 | + { |
|
31 | 31 | |
32 | - //Build row actions |
|
33 | - $actions = array(); |
|
32 | + //Build row actions |
|
33 | + $actions = array(); |
|
34 | 34 | |
35 | - //Build row actions |
|
36 | - $check_in_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
37 | - 'action' => 'event_registrations', |
|
38 | - 'event_id' => $item->event_ID(), |
|
39 | - ), REG_ADMIN_URL); |
|
40 | - $actions['check_in'] = EE_Registry::instance()->CAP->current_user_can('ee_read_checkin', |
|
41 | - 'espresso_registrations_registration_checkins', $item->ID()) ? ' |
|
35 | + //Build row actions |
|
36 | + $check_in_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
37 | + 'action' => 'event_registrations', |
|
38 | + 'event_id' => $item->event_ID(), |
|
39 | + ), REG_ADMIN_URL); |
|
40 | + $actions['check_in'] = EE_Registry::instance()->CAP->current_user_can('ee_read_checkin', |
|
41 | + 'espresso_registrations_registration_checkins', $item->ID()) ? ' |
|
42 | 42 | <a href="' . $check_in_url . '" title="' . esc_attr__('The Check-In List allows you to easily toggle check-in status for this event', |
43 | - 'event_espresso') . '">' . __('View Check-ins', 'event_espresso') . '</a>' : __('View Check-ins', |
|
44 | - 'event_espresso'); |
|
43 | + 'event_espresso') . '">' . __('View Check-ins', 'event_espresso') . '</a>' : __('View Check-ins', |
|
44 | + 'event_espresso'); |
|
45 | 45 | |
46 | - $view_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
47 | - 'action' => 'view_transaction', |
|
48 | - 'TXN_ID' => $item->transaction()->ID(), |
|
49 | - ), TXN_ADMIN_URL); |
|
50 | - $REG_date = EE_Regisry::instance()->CAP->current_user_can('ee_read_transaction', |
|
51 | - 'espresso_transactions_view_transaction') ? '<a href="' . $view_lnk_url . '" title="' . esc_attr__('View Transaction Details', |
|
52 | - 'event_espresso') . '">' . $item->get_i18n_datetime('REG_date') . '</a>' : $item->get_i18n_datetime('REG_date'); |
|
46 | + $view_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
47 | + 'action' => 'view_transaction', |
|
48 | + 'TXN_ID' => $item->transaction()->ID(), |
|
49 | + ), TXN_ADMIN_URL); |
|
50 | + $REG_date = EE_Regisry::instance()->CAP->current_user_can('ee_read_transaction', |
|
51 | + 'espresso_transactions_view_transaction') ? '<a href="' . $view_lnk_url . '" title="' . esc_attr__('View Transaction Details', |
|
52 | + 'event_espresso') . '">' . $item->get_i18n_datetime('REG_date') . '</a>' : $item->get_i18n_datetime('REG_date'); |
|
53 | 53 | |
54 | - return sprintf('%1$s %2$s', $REG_date, $this->row_actions($actions)); |
|
54 | + return sprintf('%1$s %2$s', $REG_date, $this->row_actions($actions)); |
|
55 | 55 | |
56 | - } |
|
56 | + } |
|
57 | 57 | |
58 | 58 | |
59 | - /** |
|
60 | - * column_default |
|
61 | - * |
|
62 | - * @param \EE_Registration $item |
|
63 | - * @return string |
|
64 | - */ |
|
65 | - public function column_DTT_EVT_start(EE_Registration $item) |
|
66 | - { |
|
67 | - $remove_defaults = array('default_where_conditions' => 'none'); |
|
68 | - $ticket = $item->ticket(); |
|
69 | - $datetimes = $ticket instanceof EE_Ticket ? $ticket->datetimes($remove_defaults) : array(); |
|
70 | - $EVT_ID = $item->event_ID(); |
|
71 | - $datetime_string = ''; |
|
72 | - foreach ($datetimes as $datetime) { |
|
73 | - if ( |
|
74 | - EE_Registry::instance()->CAP->current_user_can( |
|
75 | - 'ee_read_checkin', |
|
76 | - 'espresso_registrations_registration_checkins', |
|
77 | - $item->ID() |
|
78 | - ) |
|
79 | - ) { |
|
80 | - // open "a" tag and "href" |
|
81 | - $datetime_string .= '<a href="'; |
|
82 | - // checkin URL |
|
83 | - $datetime_string .= EE_Admin_Page::add_query_args_and_nonce( |
|
84 | - array( |
|
85 | - 'action' => 'event_registrations', |
|
86 | - 'event_id' => $EVT_ID, |
|
87 | - 'DTT_ID' => $datetime->ID(), |
|
88 | - ), |
|
89 | - REG_ADMIN_URL |
|
90 | - ); |
|
91 | - // close "href" |
|
92 | - $datetime_string .= '"'; |
|
93 | - // open "title" tag |
|
94 | - $datetime_string .= ' title="'; |
|
95 | - // link title text |
|
96 | - $datetime_string .= esc_attr__('View Checkins for this Event', 'event_espresso'); |
|
97 | - // close "title" tag and end of "a" tag opening |
|
98 | - $datetime_string .= '">'; |
|
99 | - // link text |
|
100 | - $datetime_string .= $datetime->get_i18n_datetime('DTT_EVT_start'); |
|
101 | - // close "a" tag |
|
102 | - $datetime_string .= '</a>'; |
|
103 | - } else { |
|
104 | - $datetime_string .= $datetime->get_i18n_datetime('DTT_EVT_start'); |
|
105 | - } |
|
106 | - // add a "View Registrations" link that filters list by event AND datetime |
|
107 | - $datetime_string .= $this->row_actions( |
|
108 | - array( |
|
109 | - 'event_datetime_filter' => '<a href="' . EE_Admin_Page::add_query_args_and_nonce( |
|
110 | - array('event_id' => $EVT_ID, 'datetime_id' => $datetime->ID()), |
|
111 | - REG_ADMIN_URL |
|
112 | - ) . '" title="' . sprintf( |
|
113 | - esc_attr__( |
|
114 | - 'Filter this list to only show registrations for this datetime %s', |
|
115 | - 'event_espresso' |
|
116 | - ), |
|
117 | - $datetime->name() |
|
118 | - ) . '">' . __('View Registrations', 'event_espresso') . '</a>', |
|
119 | - ) |
|
120 | - ); |
|
121 | - } |
|
122 | - return $datetime_string; |
|
123 | - } |
|
59 | + /** |
|
60 | + * column_default |
|
61 | + * |
|
62 | + * @param \EE_Registration $item |
|
63 | + * @return string |
|
64 | + */ |
|
65 | + public function column_DTT_EVT_start(EE_Registration $item) |
|
66 | + { |
|
67 | + $remove_defaults = array('default_where_conditions' => 'none'); |
|
68 | + $ticket = $item->ticket(); |
|
69 | + $datetimes = $ticket instanceof EE_Ticket ? $ticket->datetimes($remove_defaults) : array(); |
|
70 | + $EVT_ID = $item->event_ID(); |
|
71 | + $datetime_string = ''; |
|
72 | + foreach ($datetimes as $datetime) { |
|
73 | + if ( |
|
74 | + EE_Registry::instance()->CAP->current_user_can( |
|
75 | + 'ee_read_checkin', |
|
76 | + 'espresso_registrations_registration_checkins', |
|
77 | + $item->ID() |
|
78 | + ) |
|
79 | + ) { |
|
80 | + // open "a" tag and "href" |
|
81 | + $datetime_string .= '<a href="'; |
|
82 | + // checkin URL |
|
83 | + $datetime_string .= EE_Admin_Page::add_query_args_and_nonce( |
|
84 | + array( |
|
85 | + 'action' => 'event_registrations', |
|
86 | + 'event_id' => $EVT_ID, |
|
87 | + 'DTT_ID' => $datetime->ID(), |
|
88 | + ), |
|
89 | + REG_ADMIN_URL |
|
90 | + ); |
|
91 | + // close "href" |
|
92 | + $datetime_string .= '"'; |
|
93 | + // open "title" tag |
|
94 | + $datetime_string .= ' title="'; |
|
95 | + // link title text |
|
96 | + $datetime_string .= esc_attr__('View Checkins for this Event', 'event_espresso'); |
|
97 | + // close "title" tag and end of "a" tag opening |
|
98 | + $datetime_string .= '">'; |
|
99 | + // link text |
|
100 | + $datetime_string .= $datetime->get_i18n_datetime('DTT_EVT_start'); |
|
101 | + // close "a" tag |
|
102 | + $datetime_string .= '</a>'; |
|
103 | + } else { |
|
104 | + $datetime_string .= $datetime->get_i18n_datetime('DTT_EVT_start'); |
|
105 | + } |
|
106 | + // add a "View Registrations" link that filters list by event AND datetime |
|
107 | + $datetime_string .= $this->row_actions( |
|
108 | + array( |
|
109 | + 'event_datetime_filter' => '<a href="' . EE_Admin_Page::add_query_args_and_nonce( |
|
110 | + array('event_id' => $EVT_ID, 'datetime_id' => $datetime->ID()), |
|
111 | + REG_ADMIN_URL |
|
112 | + ) . '" title="' . sprintf( |
|
113 | + esc_attr__( |
|
114 | + 'Filter this list to only show registrations for this datetime %s', |
|
115 | + 'event_espresso' |
|
116 | + ), |
|
117 | + $datetime->name() |
|
118 | + ) . '">' . __('View Registrations', 'event_espresso') . '</a>', |
|
119 | + ) |
|
120 | + ); |
|
121 | + } |
|
122 | + return $datetime_string; |
|
123 | + } |
|
124 | 124 | |
125 | 125 | |
126 | 126 | } //end Extend_EE_Registrations_List_Table |
@@ -1,4 +1,4 @@ discard block |
||
1 | -<?php if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
1 | +<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
2 | 2 | exit('No direct script access allowed'); |
3 | 3 | } |
4 | 4 | |
@@ -33,23 +33,23 @@ discard block |
||
33 | 33 | $actions = array(); |
34 | 34 | |
35 | 35 | //Build row actions |
36 | - $check_in_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
36 | + $check_in_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
37 | 37 | 'action' => 'event_registrations', |
38 | 38 | 'event_id' => $item->event_ID(), |
39 | 39 | ), REG_ADMIN_URL); |
40 | 40 | $actions['check_in'] = EE_Registry::instance()->CAP->current_user_can('ee_read_checkin', |
41 | 41 | 'espresso_registrations_registration_checkins', $item->ID()) ? ' |
42 | - <a href="' . $check_in_url . '" title="' . esc_attr__('The Check-In List allows you to easily toggle check-in status for this event', |
|
43 | - 'event_espresso') . '">' . __('View Check-ins', 'event_espresso') . '</a>' : __('View Check-ins', |
|
42 | + <a href="' . $check_in_url.'" title="'.esc_attr__('The Check-In List allows you to easily toggle check-in status for this event', |
|
43 | + 'event_espresso').'">'.__('View Check-ins', 'event_espresso').'</a>' : __('View Check-ins', |
|
44 | 44 | 'event_espresso'); |
45 | 45 | |
46 | 46 | $view_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
47 | 47 | 'action' => 'view_transaction', |
48 | 48 | 'TXN_ID' => $item->transaction()->ID(), |
49 | 49 | ), TXN_ADMIN_URL); |
50 | - $REG_date = EE_Regisry::instance()->CAP->current_user_can('ee_read_transaction', |
|
51 | - 'espresso_transactions_view_transaction') ? '<a href="' . $view_lnk_url . '" title="' . esc_attr__('View Transaction Details', |
|
52 | - 'event_espresso') . '">' . $item->get_i18n_datetime('REG_date') . '</a>' : $item->get_i18n_datetime('REG_date'); |
|
50 | + $REG_date = EE_Regisry::instance()->CAP->current_user_can('ee_read_transaction', |
|
51 | + 'espresso_transactions_view_transaction') ? '<a href="'.$view_lnk_url.'" title="'.esc_attr__('View Transaction Details', |
|
52 | + 'event_espresso').'">'.$item->get_i18n_datetime('REG_date').'</a>' : $item->get_i18n_datetime('REG_date'); |
|
53 | 53 | |
54 | 54 | return sprintf('%1$s %2$s', $REG_date, $this->row_actions($actions)); |
55 | 55 | |
@@ -106,16 +106,16 @@ discard block |
||
106 | 106 | // add a "View Registrations" link that filters list by event AND datetime |
107 | 107 | $datetime_string .= $this->row_actions( |
108 | 108 | array( |
109 | - 'event_datetime_filter' => '<a href="' . EE_Admin_Page::add_query_args_and_nonce( |
|
109 | + 'event_datetime_filter' => '<a href="'.EE_Admin_Page::add_query_args_and_nonce( |
|
110 | 110 | array('event_id' => $EVT_ID, 'datetime_id' => $datetime->ID()), |
111 | 111 | REG_ADMIN_URL |
112 | - ) . '" title="' . sprintf( |
|
112 | + ).'" title="'.sprintf( |
|
113 | 113 | esc_attr__( |
114 | 114 | 'Filter this list to only show registrations for this datetime %s', |
115 | 115 | 'event_espresso' |
116 | 116 | ), |
117 | 117 | $datetime->name() |
118 | - ) . '">' . __('View Registrations', 'event_espresso') . '</a>', |
|
118 | + ).'">'.__('View Registrations', 'event_espresso').'</a>', |
|
119 | 119 | ) |
120 | 120 | ); |
121 | 121 | } |
@@ -17,7 +17,7 @@ discard block |
||
17 | 17 | use WP_Post; |
18 | 18 | |
19 | 19 | if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
20 | - exit( 'No direct script access allowed' ); |
|
20 | + exit( 'No direct script access allowed' ); |
|
21 | 21 | } |
22 | 22 | |
23 | 23 | |
@@ -34,707 +34,707 @@ discard block |
||
34 | 34 | class DisplayTicketSelector |
35 | 35 | { |
36 | 36 | |
37 | - /** |
|
38 | - * event that ticket selector is being generated for |
|
39 | - * |
|
40 | - * @access protected |
|
41 | - * @var EE_Event $event |
|
42 | - */ |
|
43 | - protected $event; |
|
44 | - |
|
45 | - /** |
|
46 | - * Used to flag when the ticket selector is being called from an external iframe. |
|
47 | - * |
|
48 | - * @var bool $iframe |
|
49 | - */ |
|
50 | - protected $iframe = false; |
|
51 | - |
|
52 | - /** |
|
53 | - * max attendees that can register for event at one time |
|
54 | - * |
|
55 | - * @var int $max_attendees |
|
56 | - */ |
|
57 | - private $max_attendees = EE_INF; |
|
58 | - |
|
59 | - /** |
|
60 | - *@var string $date_format |
|
61 | - */ |
|
62 | - private $date_format; |
|
63 | - |
|
64 | - /** |
|
65 | - *@var string $time_format |
|
66 | - */ |
|
67 | - private $time_format; |
|
68 | - |
|
69 | - /** |
|
70 | - *@var boolean $display_full_ui |
|
71 | - */ |
|
72 | - private $display_full_ui; |
|
73 | - |
|
74 | - |
|
75 | - |
|
76 | - /** |
|
77 | - * DisplayTicketSelector constructor. |
|
78 | - */ |
|
79 | - public function __construct() |
|
80 | - { |
|
81 | - $this->date_format = apply_filters( |
|
82 | - 'FHEE__EED_Ticket_Selector__display_ticket_selector__date_format', |
|
83 | - get_option('date_format') |
|
84 | - ); |
|
85 | - $this->time_format = apply_filters( |
|
86 | - 'FHEE__EED_Ticket_Selector__display_ticket_selector__time_format', |
|
87 | - get_option('time_format') |
|
88 | - ); |
|
89 | - } |
|
90 | - |
|
91 | - |
|
92 | - |
|
93 | - /** |
|
94 | - * @param boolean $iframe |
|
95 | - */ |
|
96 | - public function setIframe( $iframe = true ) |
|
97 | - { |
|
98 | - $this->iframe = filter_var( $iframe, FILTER_VALIDATE_BOOLEAN ); |
|
99 | - } |
|
100 | - |
|
101 | - |
|
102 | - /** |
|
103 | - * finds and sets the \EE_Event object for use throughout class |
|
104 | - * |
|
105 | - * @param mixed $event |
|
106 | - * @return bool |
|
107 | - * @throws EE_Error |
|
108 | - */ |
|
109 | - protected function setEvent( $event = null ) |
|
110 | - { |
|
111 | - if ( $event === null ) { |
|
112 | - global $post; |
|
113 | - $event = $post; |
|
114 | - } |
|
115 | - if ( $event instanceof EE_Event ) { |
|
116 | - $this->event = $event; |
|
117 | - } else if ( $event instanceof WP_Post ) { |
|
118 | - if ( isset( $event->EE_Event ) && $event->EE_Event instanceof EE_Event ) { |
|
119 | - $this->event = $event->EE_Event; |
|
120 | - } else if ( $event->post_type === 'espresso_events' ) { |
|
121 | - $event->EE_Event = EEM_Event::instance()->instantiate_class_from_post_object( $event ); |
|
122 | - $this->event = $event->EE_Event; |
|
123 | - } |
|
124 | - } else { |
|
125 | - $user_msg = __( 'No Event object or an invalid Event object was supplied.', 'event_espresso' ); |
|
126 | - $dev_msg = $user_msg . __( |
|
127 | - 'In order to generate a ticket selector, please ensure you are passing either an EE_Event object or a WP_Post object of the post type "espresso_event" to the EE_Ticket_Selector class constructor.', |
|
128 | - 'event_espresso' |
|
129 | - ); |
|
130 | - EE_Error::add_error( $user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__ ); |
|
131 | - return false; |
|
132 | - } |
|
133 | - return true; |
|
134 | - } |
|
135 | - |
|
136 | - |
|
137 | - |
|
138 | - /** |
|
139 | - * @return int |
|
140 | - */ |
|
141 | - public function getMaxAttendees() |
|
142 | - { |
|
143 | - return $this->max_attendees; |
|
144 | - } |
|
145 | - |
|
146 | - |
|
147 | - |
|
148 | - /** |
|
149 | - * @param int $max_attendees |
|
150 | - */ |
|
151 | - public function setMaxAttendees($max_attendees) |
|
152 | - { |
|
153 | - $this->max_attendees = absint( |
|
154 | - apply_filters( |
|
155 | - 'FHEE__EE_Ticket_Selector__display_ticket_selector__max_tickets', |
|
156 | - $max_attendees |
|
157 | - ) |
|
158 | - ); |
|
159 | - } |
|
160 | - |
|
161 | - |
|
162 | - |
|
163 | - /** |
|
164 | - * Returns whether or not the full ticket selector should be shown or not. |
|
165 | - * Currently, it displays on the frontend (including ajax requests) but not the backend |
|
166 | - * @return bool |
|
167 | - */ |
|
168 | - private function display_full_ui() |
|
169 | - { |
|
170 | - if ($this->display_full_ui === null) { |
|
171 | - $this->display_full_ui = ! is_admin() || (defined('DOING_AJAX') && DOING_AJAX); |
|
172 | - } |
|
173 | - return $this->display_full_ui; |
|
174 | - } |
|
175 | - |
|
176 | - |
|
177 | - /** |
|
178 | - * creates buttons for selecting number of attendees for an event |
|
179 | - * |
|
180 | - * @param WP_Post|int $event |
|
181 | - * @param bool $view_details |
|
182 | - * @return string |
|
183 | - * @throws EE_Error |
|
184 | - */ |
|
185 | - public function display( $event = null, $view_details = false ) |
|
186 | - { |
|
187 | - // reset filter for displaying submit button |
|
188 | - remove_filter( 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true' ); |
|
189 | - // poke and prod incoming event till it tells us what it is |
|
190 | - if ( ! $this->setEvent( $event ) ) { |
|
191 | - return false; |
|
192 | - } |
|
193 | - // begin gathering template arguments by getting event status |
|
194 | - $template_args = array( 'event_status' => $this->event->get_active_status() ); |
|
195 | - if ( $this->activeEventAndShowTicketSelector($event, $template_args['event_status'], $view_details) ) { |
|
196 | - return ! is_single() ? $this->displayViewDetailsButton() : ''; |
|
197 | - } |
|
198 | - // filter the maximum qty that can appear in the Ticket Selector qty dropdowns |
|
199 | - $this->setMaxAttendees($this->event->additional_limit()); |
|
200 | - if ($this->getMaxAttendees() < 1) { |
|
201 | - return $this->ticketSalesClosedMessage(); |
|
202 | - } |
|
203 | - // is the event expired ? |
|
204 | - $template_args['event_is_expired'] = $this->event->is_expired(); |
|
205 | - if ( $template_args[ 'event_is_expired' ] ) { |
|
206 | - return $this->expiredEventMessage(); |
|
207 | - } |
|
208 | - // get all tickets for this event ordered by the datetime |
|
209 | - $tickets = $this->getTickets(); |
|
210 | - if (count($tickets) < 1) { |
|
211 | - return $this->noTicketAvailableMessage(); |
|
212 | - } |
|
213 | - if (EED_Events_Archive::is_iframe()){ |
|
214 | - $this->setIframe(); |
|
215 | - } |
|
216 | - // redirecting to another site for registration ?? |
|
217 | - $external_url = (string) $this->event->external_url(); |
|
218 | - // if redirecting to another site for registration, then we don't load the TS |
|
219 | - $ticket_selector = $external_url |
|
220 | - ? $this->externalEventRegistration() |
|
221 | - : $this->loadTicketSelector($tickets,$template_args); |
|
222 | - // now set up the form (but not for the admin) |
|
223 | - $ticket_selector = $this->display_full_ui() |
|
224 | - ? $this->formOpen($this->event->ID(), $external_url) . $ticket_selector |
|
225 | - : $ticket_selector; |
|
226 | - // submit button and form close tag |
|
227 | - $ticket_selector .= $this->display_full_ui() ? $this->displaySubmitButton($external_url) : ''; |
|
228 | - return $ticket_selector; |
|
229 | - } |
|
230 | - |
|
231 | - |
|
232 | - |
|
233 | - /** |
|
234 | - * displayTicketSelector |
|
235 | - * examines the event properties and determines whether a Ticket Selector should be displayed |
|
236 | - * |
|
237 | - * @param WP_Post|int $event |
|
238 | - * @param string $_event_active_status |
|
239 | - * @param bool $view_details |
|
240 | - * @return bool |
|
241 | - * @throws EE_Error |
|
242 | - */ |
|
243 | - protected function activeEventAndShowTicketSelector($event, $_event_active_status, $view_details) |
|
244 | - { |
|
245 | - $event_post = $this->event instanceof EE_Event ? $this->event->ID() : $event; |
|
246 | - return $this->display_full_ui |
|
247 | - && ( |
|
248 | - ! $this->event->display_ticket_selector() |
|
249 | - || $view_details |
|
250 | - || post_password_required($event_post) |
|
251 | - || ( |
|
252 | - $_event_active_status !== EE_Datetime::active |
|
253 | - && $_event_active_status !== EE_Datetime::upcoming |
|
254 | - && $_event_active_status !== EE_Datetime::sold_out |
|
255 | - && ! ( |
|
256 | - $_event_active_status === EE_Datetime::inactive |
|
257 | - && is_user_logged_in() |
|
258 | - ) |
|
259 | - ) |
|
260 | - ); |
|
261 | - } |
|
262 | - |
|
263 | - |
|
264 | - |
|
265 | - /** |
|
266 | - * noTicketAvailableMessage |
|
267 | - * notice displayed if event is expired |
|
268 | - * |
|
269 | - * @return string |
|
270 | - * @throws EE_Error |
|
271 | - */ |
|
272 | - protected function expiredEventMessage() |
|
273 | - { |
|
274 | - return '<div class="ee-event-expired-notice"><span class="important-notice">' . esc_html__( |
|
275 | - 'We\'re sorry, but all tickets sales have ended because the event is expired.', |
|
276 | - 'event_espresso' |
|
277 | - ) . '</span></div><!-- .ee-event-expired-notice -->'; |
|
278 | - } |
|
279 | - |
|
280 | - |
|
281 | - |
|
282 | - /** |
|
283 | - * noTicketAvailableMessage |
|
284 | - * notice displayed if event has no more tickets available |
|
285 | - * |
|
286 | - * @return string |
|
287 | - * @throws EE_Error |
|
288 | - */ |
|
289 | - protected function noTicketAvailableMessage() |
|
290 | - { |
|
291 | - $no_ticket_available_msg = esc_html__( 'We\'re sorry, but all ticket sales have ended.', 'event_espresso' ); |
|
292 | - if (current_user_can('edit_post', $this->event->ID())) { |
|
293 | - $no_ticket_available_msg .= sprintf( |
|
294 | - esc_html__( |
|
295 | - '%1$sNote to Event Admin:%2$sNo tickets were found for this event. This effectively turns off ticket sales. Please ensure that at least one ticket is available for if you want people to be able to register.%3$s(click to edit this event)%4$s', |
|
296 | - 'event_espresso' |
|
297 | - ), |
|
298 | - '<div class="ee-attention" style="text-align: left;"><b>', |
|
299 | - '</b><br />', |
|
300 | - '<span class="edit-link"><a class="post-edit-link" href="'.get_edit_post_link($this->event->ID()).'">', |
|
301 | - '</a></span></div><!-- .ee-attention noTicketAvailableMessage -->' |
|
302 | - ); |
|
303 | - } |
|
304 | - return ' |
|
37 | + /** |
|
38 | + * event that ticket selector is being generated for |
|
39 | + * |
|
40 | + * @access protected |
|
41 | + * @var EE_Event $event |
|
42 | + */ |
|
43 | + protected $event; |
|
44 | + |
|
45 | + /** |
|
46 | + * Used to flag when the ticket selector is being called from an external iframe. |
|
47 | + * |
|
48 | + * @var bool $iframe |
|
49 | + */ |
|
50 | + protected $iframe = false; |
|
51 | + |
|
52 | + /** |
|
53 | + * max attendees that can register for event at one time |
|
54 | + * |
|
55 | + * @var int $max_attendees |
|
56 | + */ |
|
57 | + private $max_attendees = EE_INF; |
|
58 | + |
|
59 | + /** |
|
60 | + *@var string $date_format |
|
61 | + */ |
|
62 | + private $date_format; |
|
63 | + |
|
64 | + /** |
|
65 | + *@var string $time_format |
|
66 | + */ |
|
67 | + private $time_format; |
|
68 | + |
|
69 | + /** |
|
70 | + *@var boolean $display_full_ui |
|
71 | + */ |
|
72 | + private $display_full_ui; |
|
73 | + |
|
74 | + |
|
75 | + |
|
76 | + /** |
|
77 | + * DisplayTicketSelector constructor. |
|
78 | + */ |
|
79 | + public function __construct() |
|
80 | + { |
|
81 | + $this->date_format = apply_filters( |
|
82 | + 'FHEE__EED_Ticket_Selector__display_ticket_selector__date_format', |
|
83 | + get_option('date_format') |
|
84 | + ); |
|
85 | + $this->time_format = apply_filters( |
|
86 | + 'FHEE__EED_Ticket_Selector__display_ticket_selector__time_format', |
|
87 | + get_option('time_format') |
|
88 | + ); |
|
89 | + } |
|
90 | + |
|
91 | + |
|
92 | + |
|
93 | + /** |
|
94 | + * @param boolean $iframe |
|
95 | + */ |
|
96 | + public function setIframe( $iframe = true ) |
|
97 | + { |
|
98 | + $this->iframe = filter_var( $iframe, FILTER_VALIDATE_BOOLEAN ); |
|
99 | + } |
|
100 | + |
|
101 | + |
|
102 | + /** |
|
103 | + * finds and sets the \EE_Event object for use throughout class |
|
104 | + * |
|
105 | + * @param mixed $event |
|
106 | + * @return bool |
|
107 | + * @throws EE_Error |
|
108 | + */ |
|
109 | + protected function setEvent( $event = null ) |
|
110 | + { |
|
111 | + if ( $event === null ) { |
|
112 | + global $post; |
|
113 | + $event = $post; |
|
114 | + } |
|
115 | + if ( $event instanceof EE_Event ) { |
|
116 | + $this->event = $event; |
|
117 | + } else if ( $event instanceof WP_Post ) { |
|
118 | + if ( isset( $event->EE_Event ) && $event->EE_Event instanceof EE_Event ) { |
|
119 | + $this->event = $event->EE_Event; |
|
120 | + } else if ( $event->post_type === 'espresso_events' ) { |
|
121 | + $event->EE_Event = EEM_Event::instance()->instantiate_class_from_post_object( $event ); |
|
122 | + $this->event = $event->EE_Event; |
|
123 | + } |
|
124 | + } else { |
|
125 | + $user_msg = __( 'No Event object or an invalid Event object was supplied.', 'event_espresso' ); |
|
126 | + $dev_msg = $user_msg . __( |
|
127 | + 'In order to generate a ticket selector, please ensure you are passing either an EE_Event object or a WP_Post object of the post type "espresso_event" to the EE_Ticket_Selector class constructor.', |
|
128 | + 'event_espresso' |
|
129 | + ); |
|
130 | + EE_Error::add_error( $user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__ ); |
|
131 | + return false; |
|
132 | + } |
|
133 | + return true; |
|
134 | + } |
|
135 | + |
|
136 | + |
|
137 | + |
|
138 | + /** |
|
139 | + * @return int |
|
140 | + */ |
|
141 | + public function getMaxAttendees() |
|
142 | + { |
|
143 | + return $this->max_attendees; |
|
144 | + } |
|
145 | + |
|
146 | + |
|
147 | + |
|
148 | + /** |
|
149 | + * @param int $max_attendees |
|
150 | + */ |
|
151 | + public function setMaxAttendees($max_attendees) |
|
152 | + { |
|
153 | + $this->max_attendees = absint( |
|
154 | + apply_filters( |
|
155 | + 'FHEE__EE_Ticket_Selector__display_ticket_selector__max_tickets', |
|
156 | + $max_attendees |
|
157 | + ) |
|
158 | + ); |
|
159 | + } |
|
160 | + |
|
161 | + |
|
162 | + |
|
163 | + /** |
|
164 | + * Returns whether or not the full ticket selector should be shown or not. |
|
165 | + * Currently, it displays on the frontend (including ajax requests) but not the backend |
|
166 | + * @return bool |
|
167 | + */ |
|
168 | + private function display_full_ui() |
|
169 | + { |
|
170 | + if ($this->display_full_ui === null) { |
|
171 | + $this->display_full_ui = ! is_admin() || (defined('DOING_AJAX') && DOING_AJAX); |
|
172 | + } |
|
173 | + return $this->display_full_ui; |
|
174 | + } |
|
175 | + |
|
176 | + |
|
177 | + /** |
|
178 | + * creates buttons for selecting number of attendees for an event |
|
179 | + * |
|
180 | + * @param WP_Post|int $event |
|
181 | + * @param bool $view_details |
|
182 | + * @return string |
|
183 | + * @throws EE_Error |
|
184 | + */ |
|
185 | + public function display( $event = null, $view_details = false ) |
|
186 | + { |
|
187 | + // reset filter for displaying submit button |
|
188 | + remove_filter( 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true' ); |
|
189 | + // poke and prod incoming event till it tells us what it is |
|
190 | + if ( ! $this->setEvent( $event ) ) { |
|
191 | + return false; |
|
192 | + } |
|
193 | + // begin gathering template arguments by getting event status |
|
194 | + $template_args = array( 'event_status' => $this->event->get_active_status() ); |
|
195 | + if ( $this->activeEventAndShowTicketSelector($event, $template_args['event_status'], $view_details) ) { |
|
196 | + return ! is_single() ? $this->displayViewDetailsButton() : ''; |
|
197 | + } |
|
198 | + // filter the maximum qty that can appear in the Ticket Selector qty dropdowns |
|
199 | + $this->setMaxAttendees($this->event->additional_limit()); |
|
200 | + if ($this->getMaxAttendees() < 1) { |
|
201 | + return $this->ticketSalesClosedMessage(); |
|
202 | + } |
|
203 | + // is the event expired ? |
|
204 | + $template_args['event_is_expired'] = $this->event->is_expired(); |
|
205 | + if ( $template_args[ 'event_is_expired' ] ) { |
|
206 | + return $this->expiredEventMessage(); |
|
207 | + } |
|
208 | + // get all tickets for this event ordered by the datetime |
|
209 | + $tickets = $this->getTickets(); |
|
210 | + if (count($tickets) < 1) { |
|
211 | + return $this->noTicketAvailableMessage(); |
|
212 | + } |
|
213 | + if (EED_Events_Archive::is_iframe()){ |
|
214 | + $this->setIframe(); |
|
215 | + } |
|
216 | + // redirecting to another site for registration ?? |
|
217 | + $external_url = (string) $this->event->external_url(); |
|
218 | + // if redirecting to another site for registration, then we don't load the TS |
|
219 | + $ticket_selector = $external_url |
|
220 | + ? $this->externalEventRegistration() |
|
221 | + : $this->loadTicketSelector($tickets,$template_args); |
|
222 | + // now set up the form (but not for the admin) |
|
223 | + $ticket_selector = $this->display_full_ui() |
|
224 | + ? $this->formOpen($this->event->ID(), $external_url) . $ticket_selector |
|
225 | + : $ticket_selector; |
|
226 | + // submit button and form close tag |
|
227 | + $ticket_selector .= $this->display_full_ui() ? $this->displaySubmitButton($external_url) : ''; |
|
228 | + return $ticket_selector; |
|
229 | + } |
|
230 | + |
|
231 | + |
|
232 | + |
|
233 | + /** |
|
234 | + * displayTicketSelector |
|
235 | + * examines the event properties and determines whether a Ticket Selector should be displayed |
|
236 | + * |
|
237 | + * @param WP_Post|int $event |
|
238 | + * @param string $_event_active_status |
|
239 | + * @param bool $view_details |
|
240 | + * @return bool |
|
241 | + * @throws EE_Error |
|
242 | + */ |
|
243 | + protected function activeEventAndShowTicketSelector($event, $_event_active_status, $view_details) |
|
244 | + { |
|
245 | + $event_post = $this->event instanceof EE_Event ? $this->event->ID() : $event; |
|
246 | + return $this->display_full_ui |
|
247 | + && ( |
|
248 | + ! $this->event->display_ticket_selector() |
|
249 | + || $view_details |
|
250 | + || post_password_required($event_post) |
|
251 | + || ( |
|
252 | + $_event_active_status !== EE_Datetime::active |
|
253 | + && $_event_active_status !== EE_Datetime::upcoming |
|
254 | + && $_event_active_status !== EE_Datetime::sold_out |
|
255 | + && ! ( |
|
256 | + $_event_active_status === EE_Datetime::inactive |
|
257 | + && is_user_logged_in() |
|
258 | + ) |
|
259 | + ) |
|
260 | + ); |
|
261 | + } |
|
262 | + |
|
263 | + |
|
264 | + |
|
265 | + /** |
|
266 | + * noTicketAvailableMessage |
|
267 | + * notice displayed if event is expired |
|
268 | + * |
|
269 | + * @return string |
|
270 | + * @throws EE_Error |
|
271 | + */ |
|
272 | + protected function expiredEventMessage() |
|
273 | + { |
|
274 | + return '<div class="ee-event-expired-notice"><span class="important-notice">' . esc_html__( |
|
275 | + 'We\'re sorry, but all tickets sales have ended because the event is expired.', |
|
276 | + 'event_espresso' |
|
277 | + ) . '</span></div><!-- .ee-event-expired-notice -->'; |
|
278 | + } |
|
279 | + |
|
280 | + |
|
281 | + |
|
282 | + /** |
|
283 | + * noTicketAvailableMessage |
|
284 | + * notice displayed if event has no more tickets available |
|
285 | + * |
|
286 | + * @return string |
|
287 | + * @throws EE_Error |
|
288 | + */ |
|
289 | + protected function noTicketAvailableMessage() |
|
290 | + { |
|
291 | + $no_ticket_available_msg = esc_html__( 'We\'re sorry, but all ticket sales have ended.', 'event_espresso' ); |
|
292 | + if (current_user_can('edit_post', $this->event->ID())) { |
|
293 | + $no_ticket_available_msg .= sprintf( |
|
294 | + esc_html__( |
|
295 | + '%1$sNote to Event Admin:%2$sNo tickets were found for this event. This effectively turns off ticket sales. Please ensure that at least one ticket is available for if you want people to be able to register.%3$s(click to edit this event)%4$s', |
|
296 | + 'event_espresso' |
|
297 | + ), |
|
298 | + '<div class="ee-attention" style="text-align: left;"><b>', |
|
299 | + '</b><br />', |
|
300 | + '<span class="edit-link"><a class="post-edit-link" href="'.get_edit_post_link($this->event->ID()).'">', |
|
301 | + '</a></span></div><!-- .ee-attention noTicketAvailableMessage -->' |
|
302 | + ); |
|
303 | + } |
|
304 | + return ' |
|
305 | 305 | <div class="ee-event-expired-notice"> |
306 | 306 | <span class="important-notice">' . $no_ticket_available_msg . '</span> |
307 | 307 | </div><!-- .ee-event-expired-notice -->'; |
308 | - } |
|
309 | - |
|
310 | - |
|
311 | - |
|
312 | - /** |
|
313 | - * ticketSalesClosed |
|
314 | - * notice displayed if event ticket sales are turned off |
|
315 | - * |
|
316 | - * @return string |
|
317 | - * @throws EE_Error |
|
318 | - */ |
|
319 | - protected function ticketSalesClosedMessage() |
|
320 | - { |
|
321 | - $sales_closed_msg = esc_html__( |
|
322 | - 'We\'re sorry, but ticket sales have been closed at this time. Please check back again later.', |
|
323 | - 'event_espresso' |
|
324 | - ); |
|
325 | - if (current_user_can('edit_post', $this->event->ID())) { |
|
326 | - $sales_closed_msg .= sprintf( |
|
327 | - esc_html__( |
|
328 | - '%sNote to Event Admin:%sThe "Maximum number of tickets allowed per order for this event" in the Event Registration Options has been set to "0". This effectively turns off ticket sales. %s(click to edit this event)%s', |
|
329 | - 'event_espresso' |
|
330 | - ), |
|
331 | - '<div class="ee-attention" style="text-align: left;"><b>', |
|
332 | - '</b><br />', |
|
333 | - '<span class="edit-link"><a class="post-edit-link" href="'.get_edit_post_link($this->event->ID()).'">', |
|
334 | - '</a></span></div><!-- .ee-attention ticketSalesClosedMessage -->' |
|
335 | - ); |
|
336 | - } |
|
337 | - return '<p><span class="important-notice">' . $sales_closed_msg . '</span></p>'; |
|
338 | - } |
|
339 | - |
|
340 | - |
|
341 | - |
|
342 | - /** |
|
343 | - * getTickets |
|
344 | - * |
|
345 | - * @return \EE_Base_Class[]|\EE_Ticket[] |
|
346 | - * @throws EE_Error |
|
347 | - */ |
|
348 | - protected function getTickets() |
|
349 | - { |
|
350 | - $ticket_query_args = array( |
|
351 | - array('Datetime.EVT_ID' => $this->event->ID()), |
|
352 | - 'order_by' => array( |
|
353 | - 'TKT_order' => 'ASC', |
|
354 | - 'TKT_required' => 'DESC', |
|
355 | - 'TKT_start_date' => 'ASC', |
|
356 | - 'TKT_end_date' => 'ASC', |
|
357 | - 'Datetime.DTT_EVT_start' => 'DESC', |
|
358 | - ), |
|
359 | - ); |
|
360 | - if ( |
|
361 | - ! ( |
|
362 | - EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector instanceof EE_Ticket_Selector_Config |
|
363 | - && EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector->show_expired_tickets |
|
364 | - ) |
|
365 | - ) { |
|
366 | - //use the correct applicable time query depending on what version of core is being run. |
|
367 | - $current_time = method_exists('EEM_Datetime', 'current_time_for_query') |
|
368 | - ? time() |
|
369 | - : current_time('timestamp'); |
|
370 | - $ticket_query_args[0]['TKT_end_date'] = array('>', $current_time); |
|
371 | - } |
|
372 | - return EEM_Ticket::instance()->get_all($ticket_query_args); |
|
373 | - } |
|
374 | - |
|
375 | - |
|
376 | - |
|
377 | - /** |
|
378 | - * loadTicketSelector |
|
379 | - * begins to assemble template arguments |
|
380 | - * and decides whether to load a "simple" ticket selector, or the standard |
|
381 | - * |
|
382 | - * @param \EE_Ticket[] $tickets |
|
383 | - * @param array $template_args |
|
384 | - * @return string |
|
385 | - * @throws EE_Error |
|
386 | - */ |
|
387 | - protected function loadTicketSelector(array $tickets, array $template_args) |
|
388 | - { |
|
389 | - $template_args['event'] = $this->event; |
|
390 | - $template_args['EVT_ID'] = $this->event->ID(); |
|
391 | - $template_args['event_is_expired'] = $this->event->is_expired(); |
|
392 | - $template_args['max_atndz'] = $this->getMaxAttendees(); |
|
393 | - $template_args['date_format'] = $this->date_format; |
|
394 | - $template_args['time_format'] = $this->time_format; |
|
395 | - /** |
|
396 | - * Filters the anchor ID used when redirecting to the Ticket Selector if no quantity selected |
|
397 | - * |
|
398 | - * @since 4.9.13 |
|
399 | - * @param string '#tkt-slctr-tbl-' . $EVT_ID The html ID to anchor to |
|
400 | - * @param int $EVT_ID The Event ID |
|
401 | - */ |
|
402 | - $template_args['anchor_id'] = apply_filters( |
|
403 | - 'FHEE__EE_Ticket_Selector__redirect_anchor_id', |
|
404 | - '#tkt-slctr-tbl-' . $this->event->ID(), |
|
405 | - $this->event->ID() |
|
406 | - ); |
|
407 | - $template_args['tickets'] = $tickets; |
|
408 | - $template_args['ticket_count'] = count($tickets); |
|
409 | - $ticket_selector = $this->simpleTicketSelector( $tickets, $template_args); |
|
410 | - return $ticket_selector instanceof TicketSelectorSimple |
|
411 | - ? $ticket_selector |
|
412 | - : new TicketSelectorStandard( |
|
413 | - $this->event, |
|
414 | - $tickets, |
|
415 | - $this->getMaxAttendees(), |
|
416 | - $template_args, |
|
417 | - $this->date_format, |
|
418 | - $this->time_format |
|
419 | - ); |
|
420 | - } |
|
421 | - |
|
422 | - |
|
423 | - |
|
424 | - /** |
|
425 | - * simpleTicketSelector |
|
426 | - * there's one ticket, and max attendees is set to one, |
|
427 | - * so if the event is free, then this is a "simple" ticket selector |
|
428 | - * a.k.a. "Dude Where's my Ticket Selector?" |
|
429 | - * |
|
430 | - * @param \EE_Ticket[] $tickets |
|
431 | - * @param array $template_args |
|
432 | - * @return string |
|
433 | - * @throws EE_Error |
|
434 | - */ |
|
435 | - protected function simpleTicketSelector($tickets, array $template_args) |
|
436 | - { |
|
437 | - // if there is only ONE ticket with a max qty of ONE |
|
438 | - if (count($tickets) > 1 || $this->getMaxAttendees() !== 1) { |
|
439 | - return ''; |
|
440 | - } |
|
441 | - /** @var \EE_Ticket $ticket */ |
|
442 | - $ticket = reset($tickets); |
|
443 | - // if the ticket is free... then not much need for the ticket selector |
|
444 | - if ( |
|
445 | - apply_filters( |
|
446 | - 'FHEE__ticket_selector_chart_template__hide_ticket_selector', |
|
447 | - $ticket->is_free(), |
|
448 | - $this->event->ID() |
|
449 | - ) |
|
450 | - ) { |
|
451 | - return new TicketSelectorSimple( |
|
452 | - $this->event, |
|
453 | - $ticket, |
|
454 | - $this->getMaxAttendees(), |
|
455 | - $template_args |
|
456 | - ); |
|
457 | - } |
|
458 | - return ''; |
|
459 | - } |
|
460 | - |
|
461 | - |
|
462 | - |
|
463 | - /** |
|
464 | - * externalEventRegistration |
|
465 | - * |
|
466 | - * @return string |
|
467 | - */ |
|
468 | - public function externalEventRegistration() |
|
469 | - { |
|
470 | - // if not we still need to trigger the display of the submit button |
|
471 | - add_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true'); |
|
472 | - //display notice to admin that registration is external |
|
473 | - return $this->display_full_ui() |
|
474 | - ? esc_html__( |
|
475 | - 'Registration is at an external URL for this event.', |
|
476 | - 'event_espresso' |
|
477 | - ) |
|
478 | - : ''; |
|
479 | - } |
|
480 | - |
|
481 | - |
|
482 | - |
|
483 | - /** |
|
484 | - * formOpen |
|
485 | - * |
|
486 | - * @param int $ID |
|
487 | - * @param string $external_url |
|
488 | - * @return string |
|
489 | - */ |
|
490 | - public function formOpen( $ID = 0, $external_url = '' ) |
|
491 | - { |
|
492 | - // if redirecting, we don't need any anything else |
|
493 | - if ( $external_url ) { |
|
494 | - $html = '<form method="GET" action="' . EEH_URL::refactor_url($external_url) . '"'; |
|
495 | - // open link in new window ? |
|
496 | - $html .= apply_filters( |
|
497 | - 'FHEE__EventEspresso_modules_ticket_selector_DisplayTicketSelector__formOpen__external_url_target_blank', |
|
498 | - EED_Events_Archive::is_iframe() |
|
499 | - ) |
|
500 | - ? ' target="_blank"' |
|
501 | - : ''; |
|
502 | - $html .= '>'; |
|
503 | - $query_args = EEH_URL::get_query_string( $external_url ); |
|
504 | - foreach ( (array)$query_args as $query_arg => $value ) { |
|
505 | - $html .= '<input type="hidden" name="' . $query_arg . '" value="' . $value . '">'; |
|
506 | - } |
|
507 | - return $html; |
|
508 | - } |
|
509 | - // if there is no submit button, then don't start building a form |
|
510 | - // because the "View Details" button will build its own form |
|
511 | - if ( ! apply_filters( 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit', false ) ) { |
|
512 | - return ''; |
|
513 | - } |
|
514 | - $checkout_url = EEH_Event_View::event_link_url( $ID ); |
|
515 | - if ( ! $checkout_url ) { |
|
516 | - EE_Error::add_error( |
|
517 | - esc_html__( 'The URL for the Event Details page could not be retrieved.', 'event_espresso' ), |
|
518 | - __FILE__, |
|
519 | - __FUNCTION__, |
|
520 | - __LINE__ |
|
521 | - ); |
|
522 | - } |
|
523 | - // set no cache headers and constants |
|
524 | - EE_System::do_not_cache(); |
|
525 | - $extra_params = $this->iframe ? ' target="_blank"' : ''; |
|
526 | - $html = '<form method="POST" action="' . $checkout_url . '"' . $extra_params . '>'; |
|
527 | - $html .= '<input type="hidden" name="ee" value="process_ticket_selections">'; |
|
528 | - $html = apply_filters( 'FHEE__EE_Ticket_Selector__ticket_selector_form_open__html', $html, $this->event ); |
|
529 | - return $html; |
|
530 | - } |
|
531 | - |
|
532 | - |
|
533 | - |
|
534 | - /** |
|
535 | - * displaySubmitButton |
|
536 | - * |
|
537 | - * @param string $external_url |
|
538 | - * @return string |
|
539 | - * @throws EE_Error |
|
540 | - */ |
|
541 | - public function displaySubmitButton($external_url = '') |
|
542 | - { |
|
543 | - $html = ''; |
|
544 | - if ($this->display_full_ui()) { |
|
545 | - // standard TS displayed with submit button, ie: "Register Now" |
|
546 | - if (apply_filters('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', false)) { |
|
547 | - $html .= $this->displayRegisterNowButton(); |
|
548 | - $html .= empty($external_url) |
|
549 | - ? $this->ticketSelectorEndDiv() |
|
550 | - : $this->clearTicketSelector(); |
|
551 | - $html .= '<br/>' . $this->formClose(); |
|
552 | - } else if ($this->getMaxAttendees() === 1) { |
|
553 | - // its a "Dude Where's my Ticket Selector?" (DWMTS) type event (ie: $_max_atndz === 1) |
|
554 | - if ($this->event->is_sold_out()) { |
|
555 | - // then instead of a View Details or Submit button, just display a "Sold Out" message |
|
556 | - $html .= apply_filters( |
|
557 | - 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__sold_out_msg', |
|
558 | - sprintf( |
|
559 | - __( |
|
560 | - '%1$s"%2$s" is currently sold out.%4$sPlease check back again later, as spots may become available.%3$s', |
|
561 | - 'event_espresso' |
|
562 | - ), |
|
563 | - '<p class="no-ticket-selector-msg clear-float">', |
|
564 | - $this->event->name(), |
|
565 | - '</p>', |
|
566 | - '<br />' |
|
567 | - ), |
|
568 | - $this->event |
|
569 | - ); |
|
570 | - if ( |
|
571 | - apply_filters( |
|
572 | - 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__no_tickets_but_display_register_now_button', |
|
573 | - false, |
|
574 | - $this->event |
|
575 | - ) |
|
576 | - ) { |
|
577 | - $html .= $this->displayRegisterNowButton(); |
|
578 | - } |
|
579 | - // sold out DWMTS event, no TS, no submit or view details button, but has additional content |
|
580 | - $html .= $this->ticketSelectorEndDiv(); |
|
581 | - } else if ( |
|
582 | - apply_filters('FHEE__EE_Ticket_Selector__hide_ticket_selector', false) |
|
583 | - && ! is_single() |
|
584 | - ) { |
|
585 | - // this is a "Dude Where's my Ticket Selector?" (DWMTS) type event, |
|
586 | - // but no tickets are available, so display event's "View Details" button. |
|
587 | - // it is being viewed via somewhere other than a single post |
|
588 | - $html .= $this->displayViewDetailsButton(true); |
|
589 | - } else { |
|
590 | - $html .= $this->ticketSelectorEndDiv(); |
|
591 | - } |
|
592 | - } else if (is_archive()) { |
|
593 | - // event list, no tickets available so display event's "View Details" button |
|
594 | - $html .= $this->ticketSelectorEndDiv(); |
|
595 | - $html .= $this->displayViewDetailsButton(); |
|
596 | - } else { |
|
597 | - if ( |
|
598 | - apply_filters( |
|
599 | - 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__no_tickets_but_display_register_now_button', |
|
600 | - false, |
|
601 | - $this->event |
|
602 | - ) |
|
603 | - ) { |
|
604 | - $html .= $this->displayRegisterNowButton(); |
|
605 | - } |
|
606 | - // no submit or view details button, and no additional content |
|
607 | - $html .= $this->ticketSelectorEndDiv(); |
|
608 | - } |
|
609 | - if ( ! $this->iframe && ! is_archive()) { |
|
610 | - $html .= EEH_Template::powered_by_event_espresso('', '', array('utm_content' => 'ticket_selector')); |
|
611 | - } |
|
612 | - } |
|
613 | - return apply_filters( |
|
614 | - 'FHEE__EventEspresso_modules_ticket_selector_DisplayTicketSelector__displaySubmitButton__html', |
|
615 | - $html, |
|
616 | - $this->event |
|
617 | - ); |
|
618 | - } |
|
619 | - |
|
620 | - |
|
621 | - |
|
622 | - /** |
|
623 | - * @return string |
|
624 | - * @throws EE_Error |
|
625 | - */ |
|
626 | - public function displayRegisterNowButton() |
|
627 | - { |
|
628 | - $btn_text = apply_filters( |
|
629 | - 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__btn_text', |
|
630 | - __('Register Now', 'event_espresso'), |
|
631 | - $this->event |
|
632 | - ); |
|
633 | - $external_url = $this->event->external_url(); |
|
634 | - $html = EEH_HTML::div( |
|
635 | - '', 'ticket-selector-submit-' . $this->event->ID() . '-btn-wrap', 'ticket-selector-submit-btn-wrap' |
|
636 | - ); |
|
637 | - $html .= '<input id="ticket-selector-submit-' . $this->event->ID() . '-btn"'; |
|
638 | - $html .= ' class="ticket-selector-submit-btn '; |
|
639 | - $html .= empty($external_url) ? 'ticket-selector-submit-ajax"' : '"'; |
|
640 | - $html .= ' type="submit" value="' . $btn_text . '" />'; |
|
641 | - $html .= EEH_HTML::divx() . '<!-- .ticket-selector-submit-btn-wrap -->'; |
|
642 | - $html .= apply_filters( |
|
643 | - 'FHEE__EE_Ticket_Selector__after_ticket_selector_submit', |
|
644 | - '', |
|
645 | - $this->event |
|
646 | - ); |
|
647 | - return $html; |
|
648 | - } |
|
649 | - |
|
650 | - |
|
651 | - /** |
|
652 | - * displayViewDetailsButton |
|
653 | - * |
|
654 | - * @param bool $DWMTS indicates a "Dude Where's my Ticket Selector?" (DWMTS) type event |
|
655 | - * (ie: $_max_atndz === 1) where there are no available tickets, |
|
656 | - * either because they are sold out, expired, or not yet on sale. |
|
657 | - * In this case, we need to close the form BEFORE adding any closing divs |
|
658 | - * @return string |
|
659 | - * @throws EE_Error |
|
660 | - */ |
|
661 | - public function displayViewDetailsButton( $DWMTS = false ) |
|
662 | - { |
|
663 | - if ( ! $this->event->get_permalink() ) { |
|
664 | - EE_Error::add_error( |
|
665 | - esc_html__( 'The URL for the Event Details page could not be retrieved.', 'event_espresso' ), |
|
666 | - __FILE__, __FUNCTION__, __LINE__ |
|
667 | - ); |
|
668 | - } |
|
669 | - $view_details_btn = '<form method="POST" action="'; |
|
670 | - $view_details_btn .= apply_filters( |
|
671 | - 'FHEE__EE_Ticket_Selector__display_view_details_btn__btn_url', |
|
672 | - $this->event->get_permalink(), |
|
673 | - $this->event |
|
674 | - ); |
|
675 | - $view_details_btn .= '"'; |
|
676 | - // open link in new window ? |
|
677 | - $view_details_btn .= apply_filters( |
|
678 | - 'FHEE__EventEspresso_modules_ticket_selector_DisplayTicketSelector__displayViewDetailsButton__url_target_blank', |
|
679 | - EED_Events_Archive::is_iframe() |
|
680 | - ) |
|
681 | - ? ' target="_blank"' |
|
682 | - : ''; |
|
683 | - $view_details_btn .='>'; |
|
684 | - $btn_text = apply_filters( |
|
685 | - 'FHEE__EE_Ticket_Selector__display_view_details_btn__btn_text', |
|
686 | - esc_html__('View Details', 'event_espresso'), |
|
687 | - $this->event |
|
688 | - ); |
|
689 | - $view_details_btn .= '<input id="ticket-selector-submit-' |
|
690 | - . $this->event->ID() |
|
691 | - . '-btn" class="ticket-selector-submit-btn view-details-btn" type="submit" value="' |
|
692 | - . $btn_text |
|
693 | - . '" />'; |
|
694 | - $view_details_btn .= apply_filters( 'FHEE__EE_Ticket_Selector__after_view_details_btn', '', $this->event ); |
|
695 | - if ($DWMTS) { |
|
696 | - $view_details_btn .= $this->formClose(); |
|
697 | - $view_details_btn .= $this->ticketSelectorEndDiv(); |
|
698 | - $view_details_btn .= '<br/>'; |
|
699 | - } else { |
|
700 | - $view_details_btn .= $this->clearTicketSelector(); |
|
701 | - $view_details_btn .= '<br/>'; |
|
702 | - $view_details_btn .= $this->formClose(); |
|
703 | - } |
|
704 | - return $view_details_btn; |
|
705 | - } |
|
706 | - |
|
707 | - |
|
708 | - |
|
709 | - /** |
|
710 | - * @return string |
|
711 | - */ |
|
712 | - public function ticketSelectorEndDiv() |
|
713 | - { |
|
714 | - return $this->clearTicketSelector() . '</div><!-- ticketSelectorEndDiv -->'; |
|
715 | - } |
|
716 | - |
|
717 | - |
|
718 | - |
|
719 | - /** |
|
720 | - * @return string |
|
721 | - */ |
|
722 | - public function clearTicketSelector() |
|
723 | - { |
|
724 | - // standard TS displayed, appears after a "Register Now" or "view Details" button |
|
725 | - return '<div class="clear"></div><!-- clearTicketSelector -->'; |
|
726 | - } |
|
727 | - |
|
728 | - |
|
729 | - |
|
730 | - /** |
|
731 | - * @access public |
|
732 | - * @return string |
|
733 | - */ |
|
734 | - public function formClose() |
|
735 | - { |
|
736 | - return '</form>'; |
|
737 | - } |
|
308 | + } |
|
309 | + |
|
310 | + |
|
311 | + |
|
312 | + /** |
|
313 | + * ticketSalesClosed |
|
314 | + * notice displayed if event ticket sales are turned off |
|
315 | + * |
|
316 | + * @return string |
|
317 | + * @throws EE_Error |
|
318 | + */ |
|
319 | + protected function ticketSalesClosedMessage() |
|
320 | + { |
|
321 | + $sales_closed_msg = esc_html__( |
|
322 | + 'We\'re sorry, but ticket sales have been closed at this time. Please check back again later.', |
|
323 | + 'event_espresso' |
|
324 | + ); |
|
325 | + if (current_user_can('edit_post', $this->event->ID())) { |
|
326 | + $sales_closed_msg .= sprintf( |
|
327 | + esc_html__( |
|
328 | + '%sNote to Event Admin:%sThe "Maximum number of tickets allowed per order for this event" in the Event Registration Options has been set to "0". This effectively turns off ticket sales. %s(click to edit this event)%s', |
|
329 | + 'event_espresso' |
|
330 | + ), |
|
331 | + '<div class="ee-attention" style="text-align: left;"><b>', |
|
332 | + '</b><br />', |
|
333 | + '<span class="edit-link"><a class="post-edit-link" href="'.get_edit_post_link($this->event->ID()).'">', |
|
334 | + '</a></span></div><!-- .ee-attention ticketSalesClosedMessage -->' |
|
335 | + ); |
|
336 | + } |
|
337 | + return '<p><span class="important-notice">' . $sales_closed_msg . '</span></p>'; |
|
338 | + } |
|
339 | + |
|
340 | + |
|
341 | + |
|
342 | + /** |
|
343 | + * getTickets |
|
344 | + * |
|
345 | + * @return \EE_Base_Class[]|\EE_Ticket[] |
|
346 | + * @throws EE_Error |
|
347 | + */ |
|
348 | + protected function getTickets() |
|
349 | + { |
|
350 | + $ticket_query_args = array( |
|
351 | + array('Datetime.EVT_ID' => $this->event->ID()), |
|
352 | + 'order_by' => array( |
|
353 | + 'TKT_order' => 'ASC', |
|
354 | + 'TKT_required' => 'DESC', |
|
355 | + 'TKT_start_date' => 'ASC', |
|
356 | + 'TKT_end_date' => 'ASC', |
|
357 | + 'Datetime.DTT_EVT_start' => 'DESC', |
|
358 | + ), |
|
359 | + ); |
|
360 | + if ( |
|
361 | + ! ( |
|
362 | + EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector instanceof EE_Ticket_Selector_Config |
|
363 | + && EE_Registry::instance()->CFG->template_settings->EED_Ticket_Selector->show_expired_tickets |
|
364 | + ) |
|
365 | + ) { |
|
366 | + //use the correct applicable time query depending on what version of core is being run. |
|
367 | + $current_time = method_exists('EEM_Datetime', 'current_time_for_query') |
|
368 | + ? time() |
|
369 | + : current_time('timestamp'); |
|
370 | + $ticket_query_args[0]['TKT_end_date'] = array('>', $current_time); |
|
371 | + } |
|
372 | + return EEM_Ticket::instance()->get_all($ticket_query_args); |
|
373 | + } |
|
374 | + |
|
375 | + |
|
376 | + |
|
377 | + /** |
|
378 | + * loadTicketSelector |
|
379 | + * begins to assemble template arguments |
|
380 | + * and decides whether to load a "simple" ticket selector, or the standard |
|
381 | + * |
|
382 | + * @param \EE_Ticket[] $tickets |
|
383 | + * @param array $template_args |
|
384 | + * @return string |
|
385 | + * @throws EE_Error |
|
386 | + */ |
|
387 | + protected function loadTicketSelector(array $tickets, array $template_args) |
|
388 | + { |
|
389 | + $template_args['event'] = $this->event; |
|
390 | + $template_args['EVT_ID'] = $this->event->ID(); |
|
391 | + $template_args['event_is_expired'] = $this->event->is_expired(); |
|
392 | + $template_args['max_atndz'] = $this->getMaxAttendees(); |
|
393 | + $template_args['date_format'] = $this->date_format; |
|
394 | + $template_args['time_format'] = $this->time_format; |
|
395 | + /** |
|
396 | + * Filters the anchor ID used when redirecting to the Ticket Selector if no quantity selected |
|
397 | + * |
|
398 | + * @since 4.9.13 |
|
399 | + * @param string '#tkt-slctr-tbl-' . $EVT_ID The html ID to anchor to |
|
400 | + * @param int $EVT_ID The Event ID |
|
401 | + */ |
|
402 | + $template_args['anchor_id'] = apply_filters( |
|
403 | + 'FHEE__EE_Ticket_Selector__redirect_anchor_id', |
|
404 | + '#tkt-slctr-tbl-' . $this->event->ID(), |
|
405 | + $this->event->ID() |
|
406 | + ); |
|
407 | + $template_args['tickets'] = $tickets; |
|
408 | + $template_args['ticket_count'] = count($tickets); |
|
409 | + $ticket_selector = $this->simpleTicketSelector( $tickets, $template_args); |
|
410 | + return $ticket_selector instanceof TicketSelectorSimple |
|
411 | + ? $ticket_selector |
|
412 | + : new TicketSelectorStandard( |
|
413 | + $this->event, |
|
414 | + $tickets, |
|
415 | + $this->getMaxAttendees(), |
|
416 | + $template_args, |
|
417 | + $this->date_format, |
|
418 | + $this->time_format |
|
419 | + ); |
|
420 | + } |
|
421 | + |
|
422 | + |
|
423 | + |
|
424 | + /** |
|
425 | + * simpleTicketSelector |
|
426 | + * there's one ticket, and max attendees is set to one, |
|
427 | + * so if the event is free, then this is a "simple" ticket selector |
|
428 | + * a.k.a. "Dude Where's my Ticket Selector?" |
|
429 | + * |
|
430 | + * @param \EE_Ticket[] $tickets |
|
431 | + * @param array $template_args |
|
432 | + * @return string |
|
433 | + * @throws EE_Error |
|
434 | + */ |
|
435 | + protected function simpleTicketSelector($tickets, array $template_args) |
|
436 | + { |
|
437 | + // if there is only ONE ticket with a max qty of ONE |
|
438 | + if (count($tickets) > 1 || $this->getMaxAttendees() !== 1) { |
|
439 | + return ''; |
|
440 | + } |
|
441 | + /** @var \EE_Ticket $ticket */ |
|
442 | + $ticket = reset($tickets); |
|
443 | + // if the ticket is free... then not much need for the ticket selector |
|
444 | + if ( |
|
445 | + apply_filters( |
|
446 | + 'FHEE__ticket_selector_chart_template__hide_ticket_selector', |
|
447 | + $ticket->is_free(), |
|
448 | + $this->event->ID() |
|
449 | + ) |
|
450 | + ) { |
|
451 | + return new TicketSelectorSimple( |
|
452 | + $this->event, |
|
453 | + $ticket, |
|
454 | + $this->getMaxAttendees(), |
|
455 | + $template_args |
|
456 | + ); |
|
457 | + } |
|
458 | + return ''; |
|
459 | + } |
|
460 | + |
|
461 | + |
|
462 | + |
|
463 | + /** |
|
464 | + * externalEventRegistration |
|
465 | + * |
|
466 | + * @return string |
|
467 | + */ |
|
468 | + public function externalEventRegistration() |
|
469 | + { |
|
470 | + // if not we still need to trigger the display of the submit button |
|
471 | + add_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true'); |
|
472 | + //display notice to admin that registration is external |
|
473 | + return $this->display_full_ui() |
|
474 | + ? esc_html__( |
|
475 | + 'Registration is at an external URL for this event.', |
|
476 | + 'event_espresso' |
|
477 | + ) |
|
478 | + : ''; |
|
479 | + } |
|
480 | + |
|
481 | + |
|
482 | + |
|
483 | + /** |
|
484 | + * formOpen |
|
485 | + * |
|
486 | + * @param int $ID |
|
487 | + * @param string $external_url |
|
488 | + * @return string |
|
489 | + */ |
|
490 | + public function formOpen( $ID = 0, $external_url = '' ) |
|
491 | + { |
|
492 | + // if redirecting, we don't need any anything else |
|
493 | + if ( $external_url ) { |
|
494 | + $html = '<form method="GET" action="' . EEH_URL::refactor_url($external_url) . '"'; |
|
495 | + // open link in new window ? |
|
496 | + $html .= apply_filters( |
|
497 | + 'FHEE__EventEspresso_modules_ticket_selector_DisplayTicketSelector__formOpen__external_url_target_blank', |
|
498 | + EED_Events_Archive::is_iframe() |
|
499 | + ) |
|
500 | + ? ' target="_blank"' |
|
501 | + : ''; |
|
502 | + $html .= '>'; |
|
503 | + $query_args = EEH_URL::get_query_string( $external_url ); |
|
504 | + foreach ( (array)$query_args as $query_arg => $value ) { |
|
505 | + $html .= '<input type="hidden" name="' . $query_arg . '" value="' . $value . '">'; |
|
506 | + } |
|
507 | + return $html; |
|
508 | + } |
|
509 | + // if there is no submit button, then don't start building a form |
|
510 | + // because the "View Details" button will build its own form |
|
511 | + if ( ! apply_filters( 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit', false ) ) { |
|
512 | + return ''; |
|
513 | + } |
|
514 | + $checkout_url = EEH_Event_View::event_link_url( $ID ); |
|
515 | + if ( ! $checkout_url ) { |
|
516 | + EE_Error::add_error( |
|
517 | + esc_html__( 'The URL for the Event Details page could not be retrieved.', 'event_espresso' ), |
|
518 | + __FILE__, |
|
519 | + __FUNCTION__, |
|
520 | + __LINE__ |
|
521 | + ); |
|
522 | + } |
|
523 | + // set no cache headers and constants |
|
524 | + EE_System::do_not_cache(); |
|
525 | + $extra_params = $this->iframe ? ' target="_blank"' : ''; |
|
526 | + $html = '<form method="POST" action="' . $checkout_url . '"' . $extra_params . '>'; |
|
527 | + $html .= '<input type="hidden" name="ee" value="process_ticket_selections">'; |
|
528 | + $html = apply_filters( 'FHEE__EE_Ticket_Selector__ticket_selector_form_open__html', $html, $this->event ); |
|
529 | + return $html; |
|
530 | + } |
|
531 | + |
|
532 | + |
|
533 | + |
|
534 | + /** |
|
535 | + * displaySubmitButton |
|
536 | + * |
|
537 | + * @param string $external_url |
|
538 | + * @return string |
|
539 | + * @throws EE_Error |
|
540 | + */ |
|
541 | + public function displaySubmitButton($external_url = '') |
|
542 | + { |
|
543 | + $html = ''; |
|
544 | + if ($this->display_full_ui()) { |
|
545 | + // standard TS displayed with submit button, ie: "Register Now" |
|
546 | + if (apply_filters('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', false)) { |
|
547 | + $html .= $this->displayRegisterNowButton(); |
|
548 | + $html .= empty($external_url) |
|
549 | + ? $this->ticketSelectorEndDiv() |
|
550 | + : $this->clearTicketSelector(); |
|
551 | + $html .= '<br/>' . $this->formClose(); |
|
552 | + } else if ($this->getMaxAttendees() === 1) { |
|
553 | + // its a "Dude Where's my Ticket Selector?" (DWMTS) type event (ie: $_max_atndz === 1) |
|
554 | + if ($this->event->is_sold_out()) { |
|
555 | + // then instead of a View Details or Submit button, just display a "Sold Out" message |
|
556 | + $html .= apply_filters( |
|
557 | + 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__sold_out_msg', |
|
558 | + sprintf( |
|
559 | + __( |
|
560 | + '%1$s"%2$s" is currently sold out.%4$sPlease check back again later, as spots may become available.%3$s', |
|
561 | + 'event_espresso' |
|
562 | + ), |
|
563 | + '<p class="no-ticket-selector-msg clear-float">', |
|
564 | + $this->event->name(), |
|
565 | + '</p>', |
|
566 | + '<br />' |
|
567 | + ), |
|
568 | + $this->event |
|
569 | + ); |
|
570 | + if ( |
|
571 | + apply_filters( |
|
572 | + 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__no_tickets_but_display_register_now_button', |
|
573 | + false, |
|
574 | + $this->event |
|
575 | + ) |
|
576 | + ) { |
|
577 | + $html .= $this->displayRegisterNowButton(); |
|
578 | + } |
|
579 | + // sold out DWMTS event, no TS, no submit or view details button, but has additional content |
|
580 | + $html .= $this->ticketSelectorEndDiv(); |
|
581 | + } else if ( |
|
582 | + apply_filters('FHEE__EE_Ticket_Selector__hide_ticket_selector', false) |
|
583 | + && ! is_single() |
|
584 | + ) { |
|
585 | + // this is a "Dude Where's my Ticket Selector?" (DWMTS) type event, |
|
586 | + // but no tickets are available, so display event's "View Details" button. |
|
587 | + // it is being viewed via somewhere other than a single post |
|
588 | + $html .= $this->displayViewDetailsButton(true); |
|
589 | + } else { |
|
590 | + $html .= $this->ticketSelectorEndDiv(); |
|
591 | + } |
|
592 | + } else if (is_archive()) { |
|
593 | + // event list, no tickets available so display event's "View Details" button |
|
594 | + $html .= $this->ticketSelectorEndDiv(); |
|
595 | + $html .= $this->displayViewDetailsButton(); |
|
596 | + } else { |
|
597 | + if ( |
|
598 | + apply_filters( |
|
599 | + 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__no_tickets_but_display_register_now_button', |
|
600 | + false, |
|
601 | + $this->event |
|
602 | + ) |
|
603 | + ) { |
|
604 | + $html .= $this->displayRegisterNowButton(); |
|
605 | + } |
|
606 | + // no submit or view details button, and no additional content |
|
607 | + $html .= $this->ticketSelectorEndDiv(); |
|
608 | + } |
|
609 | + if ( ! $this->iframe && ! is_archive()) { |
|
610 | + $html .= EEH_Template::powered_by_event_espresso('', '', array('utm_content' => 'ticket_selector')); |
|
611 | + } |
|
612 | + } |
|
613 | + return apply_filters( |
|
614 | + 'FHEE__EventEspresso_modules_ticket_selector_DisplayTicketSelector__displaySubmitButton__html', |
|
615 | + $html, |
|
616 | + $this->event |
|
617 | + ); |
|
618 | + } |
|
619 | + |
|
620 | + |
|
621 | + |
|
622 | + /** |
|
623 | + * @return string |
|
624 | + * @throws EE_Error |
|
625 | + */ |
|
626 | + public function displayRegisterNowButton() |
|
627 | + { |
|
628 | + $btn_text = apply_filters( |
|
629 | + 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit__btn_text', |
|
630 | + __('Register Now', 'event_espresso'), |
|
631 | + $this->event |
|
632 | + ); |
|
633 | + $external_url = $this->event->external_url(); |
|
634 | + $html = EEH_HTML::div( |
|
635 | + '', 'ticket-selector-submit-' . $this->event->ID() . '-btn-wrap', 'ticket-selector-submit-btn-wrap' |
|
636 | + ); |
|
637 | + $html .= '<input id="ticket-selector-submit-' . $this->event->ID() . '-btn"'; |
|
638 | + $html .= ' class="ticket-selector-submit-btn '; |
|
639 | + $html .= empty($external_url) ? 'ticket-selector-submit-ajax"' : '"'; |
|
640 | + $html .= ' type="submit" value="' . $btn_text . '" />'; |
|
641 | + $html .= EEH_HTML::divx() . '<!-- .ticket-selector-submit-btn-wrap -->'; |
|
642 | + $html .= apply_filters( |
|
643 | + 'FHEE__EE_Ticket_Selector__after_ticket_selector_submit', |
|
644 | + '', |
|
645 | + $this->event |
|
646 | + ); |
|
647 | + return $html; |
|
648 | + } |
|
649 | + |
|
650 | + |
|
651 | + /** |
|
652 | + * displayViewDetailsButton |
|
653 | + * |
|
654 | + * @param bool $DWMTS indicates a "Dude Where's my Ticket Selector?" (DWMTS) type event |
|
655 | + * (ie: $_max_atndz === 1) where there are no available tickets, |
|
656 | + * either because they are sold out, expired, or not yet on sale. |
|
657 | + * In this case, we need to close the form BEFORE adding any closing divs |
|
658 | + * @return string |
|
659 | + * @throws EE_Error |
|
660 | + */ |
|
661 | + public function displayViewDetailsButton( $DWMTS = false ) |
|
662 | + { |
|
663 | + if ( ! $this->event->get_permalink() ) { |
|
664 | + EE_Error::add_error( |
|
665 | + esc_html__( 'The URL for the Event Details page could not be retrieved.', 'event_espresso' ), |
|
666 | + __FILE__, __FUNCTION__, __LINE__ |
|
667 | + ); |
|
668 | + } |
|
669 | + $view_details_btn = '<form method="POST" action="'; |
|
670 | + $view_details_btn .= apply_filters( |
|
671 | + 'FHEE__EE_Ticket_Selector__display_view_details_btn__btn_url', |
|
672 | + $this->event->get_permalink(), |
|
673 | + $this->event |
|
674 | + ); |
|
675 | + $view_details_btn .= '"'; |
|
676 | + // open link in new window ? |
|
677 | + $view_details_btn .= apply_filters( |
|
678 | + 'FHEE__EventEspresso_modules_ticket_selector_DisplayTicketSelector__displayViewDetailsButton__url_target_blank', |
|
679 | + EED_Events_Archive::is_iframe() |
|
680 | + ) |
|
681 | + ? ' target="_blank"' |
|
682 | + : ''; |
|
683 | + $view_details_btn .='>'; |
|
684 | + $btn_text = apply_filters( |
|
685 | + 'FHEE__EE_Ticket_Selector__display_view_details_btn__btn_text', |
|
686 | + esc_html__('View Details', 'event_espresso'), |
|
687 | + $this->event |
|
688 | + ); |
|
689 | + $view_details_btn .= '<input id="ticket-selector-submit-' |
|
690 | + . $this->event->ID() |
|
691 | + . '-btn" class="ticket-selector-submit-btn view-details-btn" type="submit" value="' |
|
692 | + . $btn_text |
|
693 | + . '" />'; |
|
694 | + $view_details_btn .= apply_filters( 'FHEE__EE_Ticket_Selector__after_view_details_btn', '', $this->event ); |
|
695 | + if ($DWMTS) { |
|
696 | + $view_details_btn .= $this->formClose(); |
|
697 | + $view_details_btn .= $this->ticketSelectorEndDiv(); |
|
698 | + $view_details_btn .= '<br/>'; |
|
699 | + } else { |
|
700 | + $view_details_btn .= $this->clearTicketSelector(); |
|
701 | + $view_details_btn .= '<br/>'; |
|
702 | + $view_details_btn .= $this->formClose(); |
|
703 | + } |
|
704 | + return $view_details_btn; |
|
705 | + } |
|
706 | + |
|
707 | + |
|
708 | + |
|
709 | + /** |
|
710 | + * @return string |
|
711 | + */ |
|
712 | + public function ticketSelectorEndDiv() |
|
713 | + { |
|
714 | + return $this->clearTicketSelector() . '</div><!-- ticketSelectorEndDiv -->'; |
|
715 | + } |
|
716 | + |
|
717 | + |
|
718 | + |
|
719 | + /** |
|
720 | + * @return string |
|
721 | + */ |
|
722 | + public function clearTicketSelector() |
|
723 | + { |
|
724 | + // standard TS displayed, appears after a "Register Now" or "view Details" button |
|
725 | + return '<div class="clear"></div><!-- clearTicketSelector -->'; |
|
726 | + } |
|
727 | + |
|
728 | + |
|
729 | + |
|
730 | + /** |
|
731 | + * @access public |
|
732 | + * @return string |
|
733 | + */ |
|
734 | + public function formClose() |
|
735 | + { |
|
736 | + return '</form>'; |
|
737 | + } |
|
738 | 738 | |
739 | 739 | |
740 | 740 |
@@ -16,8 +16,8 @@ discard block |
||
16 | 16 | use EEM_Ticket; |
17 | 17 | use WP_Post; |
18 | 18 | |
19 | -if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
|
20 | - exit( 'No direct script access allowed' ); |
|
19 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
20 | + exit('No direct script access allowed'); |
|
21 | 21 | } |
22 | 22 | |
23 | 23 | |
@@ -93,9 +93,9 @@ discard block |
||
93 | 93 | /** |
94 | 94 | * @param boolean $iframe |
95 | 95 | */ |
96 | - public function setIframe( $iframe = true ) |
|
96 | + public function setIframe($iframe = true) |
|
97 | 97 | { |
98 | - $this->iframe = filter_var( $iframe, FILTER_VALIDATE_BOOLEAN ); |
|
98 | + $this->iframe = filter_var($iframe, FILTER_VALIDATE_BOOLEAN); |
|
99 | 99 | } |
100 | 100 | |
101 | 101 | |
@@ -106,28 +106,28 @@ discard block |
||
106 | 106 | * @return bool |
107 | 107 | * @throws EE_Error |
108 | 108 | */ |
109 | - protected function setEvent( $event = null ) |
|
109 | + protected function setEvent($event = null) |
|
110 | 110 | { |
111 | - if ( $event === null ) { |
|
111 | + if ($event === null) { |
|
112 | 112 | global $post; |
113 | 113 | $event = $post; |
114 | 114 | } |
115 | - if ( $event instanceof EE_Event ) { |
|
115 | + if ($event instanceof EE_Event) { |
|
116 | 116 | $this->event = $event; |
117 | - } else if ( $event instanceof WP_Post ) { |
|
118 | - if ( isset( $event->EE_Event ) && $event->EE_Event instanceof EE_Event ) { |
|
117 | + } else if ($event instanceof WP_Post) { |
|
118 | + if (isset($event->EE_Event) && $event->EE_Event instanceof EE_Event) { |
|
119 | 119 | $this->event = $event->EE_Event; |
120 | - } else if ( $event->post_type === 'espresso_events' ) { |
|
121 | - $event->EE_Event = EEM_Event::instance()->instantiate_class_from_post_object( $event ); |
|
120 | + } else if ($event->post_type === 'espresso_events') { |
|
121 | + $event->EE_Event = EEM_Event::instance()->instantiate_class_from_post_object($event); |
|
122 | 122 | $this->event = $event->EE_Event; |
123 | 123 | } |
124 | 124 | } else { |
125 | - $user_msg = __( 'No Event object or an invalid Event object was supplied.', 'event_espresso' ); |
|
126 | - $dev_msg = $user_msg . __( |
|
125 | + $user_msg = __('No Event object or an invalid Event object was supplied.', 'event_espresso'); |
|
126 | + $dev_msg = $user_msg.__( |
|
127 | 127 | 'In order to generate a ticket selector, please ensure you are passing either an EE_Event object or a WP_Post object of the post type "espresso_event" to the EE_Ticket_Selector class constructor.', |
128 | 128 | 'event_espresso' |
129 | 129 | ); |
130 | - EE_Error::add_error( $user_msg . '||' . $dev_msg, __FILE__, __FUNCTION__, __LINE__ ); |
|
130 | + EE_Error::add_error($user_msg.'||'.$dev_msg, __FILE__, __FUNCTION__, __LINE__); |
|
131 | 131 | return false; |
132 | 132 | } |
133 | 133 | return true; |
@@ -182,17 +182,17 @@ discard block |
||
182 | 182 | * @return string |
183 | 183 | * @throws EE_Error |
184 | 184 | */ |
185 | - public function display( $event = null, $view_details = false ) |
|
185 | + public function display($event = null, $view_details = false) |
|
186 | 186 | { |
187 | 187 | // reset filter for displaying submit button |
188 | - remove_filter( 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true' ); |
|
188 | + remove_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true'); |
|
189 | 189 | // poke and prod incoming event till it tells us what it is |
190 | - if ( ! $this->setEvent( $event ) ) { |
|
190 | + if ( ! $this->setEvent($event)) { |
|
191 | 191 | return false; |
192 | 192 | } |
193 | 193 | // begin gathering template arguments by getting event status |
194 | - $template_args = array( 'event_status' => $this->event->get_active_status() ); |
|
195 | - if ( $this->activeEventAndShowTicketSelector($event, $template_args['event_status'], $view_details) ) { |
|
194 | + $template_args = array('event_status' => $this->event->get_active_status()); |
|
195 | + if ($this->activeEventAndShowTicketSelector($event, $template_args['event_status'], $view_details)) { |
|
196 | 196 | return ! is_single() ? $this->displayViewDetailsButton() : ''; |
197 | 197 | } |
198 | 198 | // filter the maximum qty that can appear in the Ticket Selector qty dropdowns |
@@ -202,7 +202,7 @@ discard block |
||
202 | 202 | } |
203 | 203 | // is the event expired ? |
204 | 204 | $template_args['event_is_expired'] = $this->event->is_expired(); |
205 | - if ( $template_args[ 'event_is_expired' ] ) { |
|
205 | + if ($template_args['event_is_expired']) { |
|
206 | 206 | return $this->expiredEventMessage(); |
207 | 207 | } |
208 | 208 | // get all tickets for this event ordered by the datetime |
@@ -210,7 +210,7 @@ discard block |
||
210 | 210 | if (count($tickets) < 1) { |
211 | 211 | return $this->noTicketAvailableMessage(); |
212 | 212 | } |
213 | - if (EED_Events_Archive::is_iframe()){ |
|
213 | + if (EED_Events_Archive::is_iframe()) { |
|
214 | 214 | $this->setIframe(); |
215 | 215 | } |
216 | 216 | // redirecting to another site for registration ?? |
@@ -218,10 +218,10 @@ discard block |
||
218 | 218 | // if redirecting to another site for registration, then we don't load the TS |
219 | 219 | $ticket_selector = $external_url |
220 | 220 | ? $this->externalEventRegistration() |
221 | - : $this->loadTicketSelector($tickets,$template_args); |
|
221 | + : $this->loadTicketSelector($tickets, $template_args); |
|
222 | 222 | // now set up the form (but not for the admin) |
223 | 223 | $ticket_selector = $this->display_full_ui() |
224 | - ? $this->formOpen($this->event->ID(), $external_url) . $ticket_selector |
|
224 | + ? $this->formOpen($this->event->ID(), $external_url).$ticket_selector |
|
225 | 225 | : $ticket_selector; |
226 | 226 | // submit button and form close tag |
227 | 227 | $ticket_selector .= $this->display_full_ui() ? $this->displaySubmitButton($external_url) : ''; |
@@ -271,10 +271,10 @@ discard block |
||
271 | 271 | */ |
272 | 272 | protected function expiredEventMessage() |
273 | 273 | { |
274 | - return '<div class="ee-event-expired-notice"><span class="important-notice">' . esc_html__( |
|
274 | + return '<div class="ee-event-expired-notice"><span class="important-notice">'.esc_html__( |
|
275 | 275 | 'We\'re sorry, but all tickets sales have ended because the event is expired.', |
276 | 276 | 'event_espresso' |
277 | - ) . '</span></div><!-- .ee-event-expired-notice -->'; |
|
277 | + ).'</span></div><!-- .ee-event-expired-notice -->'; |
|
278 | 278 | } |
279 | 279 | |
280 | 280 | |
@@ -288,7 +288,7 @@ discard block |
||
288 | 288 | */ |
289 | 289 | protected function noTicketAvailableMessage() |
290 | 290 | { |
291 | - $no_ticket_available_msg = esc_html__( 'We\'re sorry, but all ticket sales have ended.', 'event_espresso' ); |
|
291 | + $no_ticket_available_msg = esc_html__('We\'re sorry, but all ticket sales have ended.', 'event_espresso'); |
|
292 | 292 | if (current_user_can('edit_post', $this->event->ID())) { |
293 | 293 | $no_ticket_available_msg .= sprintf( |
294 | 294 | esc_html__( |
@@ -303,7 +303,7 @@ discard block |
||
303 | 303 | } |
304 | 304 | return ' |
305 | 305 | <div class="ee-event-expired-notice"> |
306 | - <span class="important-notice">' . $no_ticket_available_msg . '</span> |
|
306 | + <span class="important-notice">' . $no_ticket_available_msg.'</span> |
|
307 | 307 | </div><!-- .ee-event-expired-notice -->'; |
308 | 308 | } |
309 | 309 | |
@@ -334,7 +334,7 @@ discard block |
||
334 | 334 | '</a></span></div><!-- .ee-attention ticketSalesClosedMessage -->' |
335 | 335 | ); |
336 | 336 | } |
337 | - return '<p><span class="important-notice">' . $sales_closed_msg . '</span></p>'; |
|
337 | + return '<p><span class="important-notice">'.$sales_closed_msg.'</span></p>'; |
|
338 | 338 | } |
339 | 339 | |
340 | 340 | |
@@ -401,12 +401,12 @@ discard block |
||
401 | 401 | */ |
402 | 402 | $template_args['anchor_id'] = apply_filters( |
403 | 403 | 'FHEE__EE_Ticket_Selector__redirect_anchor_id', |
404 | - '#tkt-slctr-tbl-' . $this->event->ID(), |
|
404 | + '#tkt-slctr-tbl-'.$this->event->ID(), |
|
405 | 405 | $this->event->ID() |
406 | 406 | ); |
407 | 407 | $template_args['tickets'] = $tickets; |
408 | 408 | $template_args['ticket_count'] = count($tickets); |
409 | - $ticket_selector = $this->simpleTicketSelector( $tickets, $template_args); |
|
409 | + $ticket_selector = $this->simpleTicketSelector($tickets, $template_args); |
|
410 | 410 | return $ticket_selector instanceof TicketSelectorSimple |
411 | 411 | ? $ticket_selector |
412 | 412 | : new TicketSelectorStandard( |
@@ -487,11 +487,11 @@ discard block |
||
487 | 487 | * @param string $external_url |
488 | 488 | * @return string |
489 | 489 | */ |
490 | - public function formOpen( $ID = 0, $external_url = '' ) |
|
490 | + public function formOpen($ID = 0, $external_url = '') |
|
491 | 491 | { |
492 | 492 | // if redirecting, we don't need any anything else |
493 | - if ( $external_url ) { |
|
494 | - $html = '<form method="GET" action="' . EEH_URL::refactor_url($external_url) . '"'; |
|
493 | + if ($external_url) { |
|
494 | + $html = '<form method="GET" action="'.EEH_URL::refactor_url($external_url).'"'; |
|
495 | 495 | // open link in new window ? |
496 | 496 | $html .= apply_filters( |
497 | 497 | 'FHEE__EventEspresso_modules_ticket_selector_DisplayTicketSelector__formOpen__external_url_target_blank', |
@@ -500,21 +500,21 @@ discard block |
||
500 | 500 | ? ' target="_blank"' |
501 | 501 | : ''; |
502 | 502 | $html .= '>'; |
503 | - $query_args = EEH_URL::get_query_string( $external_url ); |
|
504 | - foreach ( (array)$query_args as $query_arg => $value ) { |
|
505 | - $html .= '<input type="hidden" name="' . $query_arg . '" value="' . $value . '">'; |
|
503 | + $query_args = EEH_URL::get_query_string($external_url); |
|
504 | + foreach ((array) $query_args as $query_arg => $value) { |
|
505 | + $html .= '<input type="hidden" name="'.$query_arg.'" value="'.$value.'">'; |
|
506 | 506 | } |
507 | 507 | return $html; |
508 | 508 | } |
509 | 509 | // if there is no submit button, then don't start building a form |
510 | 510 | // because the "View Details" button will build its own form |
511 | - if ( ! apply_filters( 'FHEE__EE_Ticket_Selector__display_ticket_selector_submit', false ) ) { |
|
511 | + if ( ! apply_filters('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', false)) { |
|
512 | 512 | return ''; |
513 | 513 | } |
514 | - $checkout_url = EEH_Event_View::event_link_url( $ID ); |
|
515 | - if ( ! $checkout_url ) { |
|
514 | + $checkout_url = EEH_Event_View::event_link_url($ID); |
|
515 | + if ( ! $checkout_url) { |
|
516 | 516 | EE_Error::add_error( |
517 | - esc_html__( 'The URL for the Event Details page could not be retrieved.', 'event_espresso' ), |
|
517 | + esc_html__('The URL for the Event Details page could not be retrieved.', 'event_espresso'), |
|
518 | 518 | __FILE__, |
519 | 519 | __FUNCTION__, |
520 | 520 | __LINE__ |
@@ -523,9 +523,9 @@ discard block |
||
523 | 523 | // set no cache headers and constants |
524 | 524 | EE_System::do_not_cache(); |
525 | 525 | $extra_params = $this->iframe ? ' target="_blank"' : ''; |
526 | - $html = '<form method="POST" action="' . $checkout_url . '"' . $extra_params . '>'; |
|
526 | + $html = '<form method="POST" action="'.$checkout_url.'"'.$extra_params.'>'; |
|
527 | 527 | $html .= '<input type="hidden" name="ee" value="process_ticket_selections">'; |
528 | - $html = apply_filters( 'FHEE__EE_Ticket_Selector__ticket_selector_form_open__html', $html, $this->event ); |
|
528 | + $html = apply_filters('FHEE__EE_Ticket_Selector__ticket_selector_form_open__html', $html, $this->event); |
|
529 | 529 | return $html; |
530 | 530 | } |
531 | 531 | |
@@ -548,7 +548,7 @@ discard block |
||
548 | 548 | $html .= empty($external_url) |
549 | 549 | ? $this->ticketSelectorEndDiv() |
550 | 550 | : $this->clearTicketSelector(); |
551 | - $html .= '<br/>' . $this->formClose(); |
|
551 | + $html .= '<br/>'.$this->formClose(); |
|
552 | 552 | } else if ($this->getMaxAttendees() === 1) { |
553 | 553 | // its a "Dude Where's my Ticket Selector?" (DWMTS) type event (ie: $_max_atndz === 1) |
554 | 554 | if ($this->event->is_sold_out()) { |
@@ -577,7 +577,7 @@ discard block |
||
577 | 577 | $html .= $this->displayRegisterNowButton(); |
578 | 578 | } |
579 | 579 | // sold out DWMTS event, no TS, no submit or view details button, but has additional content |
580 | - $html .= $this->ticketSelectorEndDiv(); |
|
580 | + $html .= $this->ticketSelectorEndDiv(); |
|
581 | 581 | } else if ( |
582 | 582 | apply_filters('FHEE__EE_Ticket_Selector__hide_ticket_selector', false) |
583 | 583 | && ! is_single() |
@@ -632,13 +632,13 @@ discard block |
||
632 | 632 | ); |
633 | 633 | $external_url = $this->event->external_url(); |
634 | 634 | $html = EEH_HTML::div( |
635 | - '', 'ticket-selector-submit-' . $this->event->ID() . '-btn-wrap', 'ticket-selector-submit-btn-wrap' |
|
635 | + '', 'ticket-selector-submit-'.$this->event->ID().'-btn-wrap', 'ticket-selector-submit-btn-wrap' |
|
636 | 636 | ); |
637 | - $html .= '<input id="ticket-selector-submit-' . $this->event->ID() . '-btn"'; |
|
637 | + $html .= '<input id="ticket-selector-submit-'.$this->event->ID().'-btn"'; |
|
638 | 638 | $html .= ' class="ticket-selector-submit-btn '; |
639 | 639 | $html .= empty($external_url) ? 'ticket-selector-submit-ajax"' : '"'; |
640 | - $html .= ' type="submit" value="' . $btn_text . '" />'; |
|
641 | - $html .= EEH_HTML::divx() . '<!-- .ticket-selector-submit-btn-wrap -->'; |
|
640 | + $html .= ' type="submit" value="'.$btn_text.'" />'; |
|
641 | + $html .= EEH_HTML::divx().'<!-- .ticket-selector-submit-btn-wrap -->'; |
|
642 | 642 | $html .= apply_filters( |
643 | 643 | 'FHEE__EE_Ticket_Selector__after_ticket_selector_submit', |
644 | 644 | '', |
@@ -658,11 +658,11 @@ discard block |
||
658 | 658 | * @return string |
659 | 659 | * @throws EE_Error |
660 | 660 | */ |
661 | - public function displayViewDetailsButton( $DWMTS = false ) |
|
661 | + public function displayViewDetailsButton($DWMTS = false) |
|
662 | 662 | { |
663 | - if ( ! $this->event->get_permalink() ) { |
|
663 | + if ( ! $this->event->get_permalink()) { |
|
664 | 664 | EE_Error::add_error( |
665 | - esc_html__( 'The URL for the Event Details page could not be retrieved.', 'event_espresso' ), |
|
665 | + esc_html__('The URL for the Event Details page could not be retrieved.', 'event_espresso'), |
|
666 | 666 | __FILE__, __FUNCTION__, __LINE__ |
667 | 667 | ); |
668 | 668 | } |
@@ -680,7 +680,7 @@ discard block |
||
680 | 680 | ) |
681 | 681 | ? ' target="_blank"' |
682 | 682 | : ''; |
683 | - $view_details_btn .='>'; |
|
683 | + $view_details_btn .= '>'; |
|
684 | 684 | $btn_text = apply_filters( |
685 | 685 | 'FHEE__EE_Ticket_Selector__display_view_details_btn__btn_text', |
686 | 686 | esc_html__('View Details', 'event_espresso'), |
@@ -691,7 +691,7 @@ discard block |
||
691 | 691 | . '-btn" class="ticket-selector-submit-btn view-details-btn" type="submit" value="' |
692 | 692 | . $btn_text |
693 | 693 | . '" />'; |
694 | - $view_details_btn .= apply_filters( 'FHEE__EE_Ticket_Selector__after_view_details_btn', '', $this->event ); |
|
694 | + $view_details_btn .= apply_filters('FHEE__EE_Ticket_Selector__after_view_details_btn', '', $this->event); |
|
695 | 695 | if ($DWMTS) { |
696 | 696 | $view_details_btn .= $this->formClose(); |
697 | 697 | $view_details_btn .= $this->ticketSelectorEndDiv(); |
@@ -711,7 +711,7 @@ discard block |
||
711 | 711 | */ |
712 | 712 | public function ticketSelectorEndDiv() |
713 | 713 | { |
714 | - return $this->clearTicketSelector() . '</div><!-- ticketSelectorEndDiv -->'; |
|
714 | + return $this->clearTicketSelector().'</div><!-- ticketSelectorEndDiv -->'; |
|
715 | 715 | } |
716 | 716 | |
717 | 717 |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php if ( ! defined('ABSPATH')) { |
2 | - exit('No direct script access allowed'); |
|
2 | + exit('No direct script access allowed'); |
|
3 | 3 | } |
4 | 4 | /* |
5 | 5 | Plugin Name: Event Espresso |
@@ -40,243 +40,243 @@ discard block |
||
40 | 40 | * @since 4.0 |
41 | 41 | */ |
42 | 42 | if (function_exists('espresso_version')) { |
43 | - /** |
|
44 | - * espresso_duplicate_plugin_error |
|
45 | - * displays if more than one version of EE is activated at the same time |
|
46 | - */ |
|
47 | - function espresso_duplicate_plugin_error() |
|
48 | - { |
|
49 | - ?> |
|
43 | + /** |
|
44 | + * espresso_duplicate_plugin_error |
|
45 | + * displays if more than one version of EE is activated at the same time |
|
46 | + */ |
|
47 | + function espresso_duplicate_plugin_error() |
|
48 | + { |
|
49 | + ?> |
|
50 | 50 | <div class="error"> |
51 | 51 | <p> |
52 | 52 | <?php echo esc_html__( |
53 | - 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
54 | - 'event_espresso' |
|
55 | - ); ?> |
|
53 | + 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
54 | + 'event_espresso' |
|
55 | + ); ?> |
|
56 | 56 | </p> |
57 | 57 | </div> |
58 | 58 | <?php |
59 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
60 | - } |
|
59 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
60 | + } |
|
61 | 61 | |
62 | - add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
62 | + add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
63 | 63 | } else { |
64 | - define('EE_MIN_PHP_VER_REQUIRED', '5.3.9'); |
|
65 | - if ( ! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
66 | - /** |
|
67 | - * espresso_minimum_php_version_error |
|
68 | - * |
|
69 | - * @return void |
|
70 | - */ |
|
71 | - function espresso_minimum_php_version_error() |
|
72 | - { |
|
73 | - ?> |
|
64 | + define('EE_MIN_PHP_VER_REQUIRED', '5.3.9'); |
|
65 | + if ( ! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
66 | + /** |
|
67 | + * espresso_minimum_php_version_error |
|
68 | + * |
|
69 | + * @return void |
|
70 | + */ |
|
71 | + function espresso_minimum_php_version_error() |
|
72 | + { |
|
73 | + ?> |
|
74 | 74 | <div class="error"> |
75 | 75 | <p> |
76 | 76 | <?php |
77 | - printf( |
|
78 | - esc_html__( |
|
79 | - 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
80 | - 'event_espresso' |
|
81 | - ), |
|
82 | - EE_MIN_PHP_VER_REQUIRED, |
|
83 | - PHP_VERSION, |
|
84 | - '<br/>', |
|
85 | - '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
86 | - ); |
|
87 | - ?> |
|
77 | + printf( |
|
78 | + esc_html__( |
|
79 | + 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
80 | + 'event_espresso' |
|
81 | + ), |
|
82 | + EE_MIN_PHP_VER_REQUIRED, |
|
83 | + PHP_VERSION, |
|
84 | + '<br/>', |
|
85 | + '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
86 | + ); |
|
87 | + ?> |
|
88 | 88 | </p> |
89 | 89 | </div> |
90 | 90 | <?php |
91 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
92 | - } |
|
91 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
92 | + } |
|
93 | 93 | |
94 | - add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
95 | - } else { |
|
96 | - /** |
|
97 | - * espresso_version |
|
98 | - * Returns the plugin version |
|
99 | - * |
|
100 | - * @return string |
|
101 | - */ |
|
102 | - function espresso_version() |
|
103 | - { |
|
104 | - return apply_filters('FHEE__espresso__espresso_version', '4.9.46.rc.012'); |
|
105 | - } |
|
94 | + add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
95 | + } else { |
|
96 | + /** |
|
97 | + * espresso_version |
|
98 | + * Returns the plugin version |
|
99 | + * |
|
100 | + * @return string |
|
101 | + */ |
|
102 | + function espresso_version() |
|
103 | + { |
|
104 | + return apply_filters('FHEE__espresso__espresso_version', '4.9.46.rc.012'); |
|
105 | + } |
|
106 | 106 | |
107 | - // define versions |
|
108 | - define('EVENT_ESPRESSO_VERSION', espresso_version()); |
|
109 | - define('EE_MIN_WP_VER_REQUIRED', '4.1'); |
|
110 | - define('EE_MIN_WP_VER_RECOMMENDED', '4.4.2'); |
|
111 | - define('EE_MIN_PHP_VER_RECOMMENDED', '5.4.44'); |
|
112 | - define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
113 | - //used to be DIRECTORY_SEPARATOR, but that caused issues on windows |
|
114 | - if ( ! defined('DS')) { |
|
115 | - define('DS', '/'); |
|
116 | - } |
|
117 | - if ( ! defined('PS')) { |
|
118 | - define('PS', PATH_SEPARATOR); |
|
119 | - } |
|
120 | - if ( ! defined('SP')) { |
|
121 | - define('SP', ' '); |
|
122 | - } |
|
123 | - if ( ! defined('EENL')) { |
|
124 | - define('EENL', "\n"); |
|
125 | - } |
|
126 | - define('EE_SUPPORT_EMAIL', '[email protected]'); |
|
127 | - // define the plugin directory and URL |
|
128 | - define('EE_PLUGIN_BASENAME', plugin_basename(EVENT_ESPRESSO_MAIN_FILE)); |
|
129 | - define('EE_PLUGIN_DIR_PATH', plugin_dir_path(EVENT_ESPRESSO_MAIN_FILE)); |
|
130 | - define('EE_PLUGIN_DIR_URL', plugin_dir_url(EVENT_ESPRESSO_MAIN_FILE)); |
|
131 | - // main root folder paths |
|
132 | - define('EE_ADMIN_PAGES', EE_PLUGIN_DIR_PATH . 'admin_pages' . DS); |
|
133 | - define('EE_CORE', EE_PLUGIN_DIR_PATH . 'core' . DS); |
|
134 | - define('EE_MODULES', EE_PLUGIN_DIR_PATH . 'modules' . DS); |
|
135 | - define('EE_PUBLIC', EE_PLUGIN_DIR_PATH . 'public' . DS); |
|
136 | - define('EE_SHORTCODES', EE_PLUGIN_DIR_PATH . 'shortcodes' . DS); |
|
137 | - define('EE_WIDGETS', EE_PLUGIN_DIR_PATH . 'widgets' . DS); |
|
138 | - define('EE_PAYMENT_METHODS', EE_PLUGIN_DIR_PATH . 'payment_methods' . DS); |
|
139 | - define('EE_CAFF_PATH', EE_PLUGIN_DIR_PATH . 'caffeinated' . DS); |
|
140 | - // core system paths |
|
141 | - define('EE_ADMIN', EE_CORE . 'admin' . DS); |
|
142 | - define('EE_CPTS', EE_CORE . 'CPTs' . DS); |
|
143 | - define('EE_CLASSES', EE_CORE . 'db_classes' . DS); |
|
144 | - define('EE_INTERFACES', EE_CORE . 'interfaces' . DS); |
|
145 | - define('EE_BUSINESS', EE_CORE . 'business' . DS); |
|
146 | - define('EE_MODELS', EE_CORE . 'db_models' . DS); |
|
147 | - define('EE_HELPERS', EE_CORE . 'helpers' . DS); |
|
148 | - define('EE_LIBRARIES', EE_CORE . 'libraries' . DS); |
|
149 | - define('EE_TEMPLATES', EE_CORE . 'templates' . DS); |
|
150 | - define('EE_THIRD_PARTY', EE_CORE . 'third_party_libs' . DS); |
|
151 | - define('EE_GLOBAL_ASSETS', EE_TEMPLATES . 'global_assets' . DS); |
|
152 | - define('EE_FORM_SECTIONS', EE_LIBRARIES . 'form_sections' . DS); |
|
153 | - // gateways |
|
154 | - define('EE_GATEWAYS', EE_MODULES . 'gateways' . DS); |
|
155 | - define('EE_GATEWAYS_URL', EE_PLUGIN_DIR_URL . 'modules' . DS . 'gateways' . DS); |
|
156 | - // asset URL paths |
|
157 | - define('EE_TEMPLATES_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'templates' . DS); |
|
158 | - define('EE_GLOBAL_ASSETS_URL', EE_TEMPLATES_URL . 'global_assets' . DS); |
|
159 | - define('EE_IMAGES_URL', EE_GLOBAL_ASSETS_URL . 'images' . DS); |
|
160 | - define('EE_THIRD_PARTY_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'third_party_libs' . DS); |
|
161 | - define('EE_HELPERS_ASSETS', EE_PLUGIN_DIR_URL . 'core/helpers/assets/'); |
|
162 | - define('EE_LIBRARIES_URL', EE_PLUGIN_DIR_URL . 'core/libraries/'); |
|
163 | - // define upload paths |
|
164 | - $uploads = wp_upload_dir(); |
|
165 | - // define the uploads directory and URL |
|
166 | - define('EVENT_ESPRESSO_UPLOAD_DIR', $uploads['basedir'] . DS . 'espresso' . DS); |
|
167 | - define('EVENT_ESPRESSO_UPLOAD_URL', $uploads['baseurl'] . DS . 'espresso' . DS); |
|
168 | - // define the templates directory and URL |
|
169 | - define('EVENT_ESPRESSO_TEMPLATE_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'templates' . DS); |
|
170 | - define('EVENT_ESPRESSO_TEMPLATE_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'templates' . DS); |
|
171 | - // define the gateway directory and URL |
|
172 | - define('EVENT_ESPRESSO_GATEWAY_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'gateways' . DS); |
|
173 | - define('EVENT_ESPRESSO_GATEWAY_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'gateways' . DS); |
|
174 | - // languages folder/path |
|
175 | - define('EE_LANGUAGES_SAFE_LOC', '..' . DS . 'uploads' . DS . 'espresso' . DS . 'languages' . DS); |
|
176 | - define('EE_LANGUAGES_SAFE_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'languages' . DS); |
|
177 | - //check for dompdf fonts in uploads |
|
178 | - if (file_exists(EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS)) { |
|
179 | - define('DOMPDF_FONT_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS); |
|
180 | - } |
|
181 | - //ajax constants |
|
182 | - define( |
|
183 | - 'EE_FRONT_AJAX', |
|
184 | - isset($_REQUEST['ee_front_ajax']) || isset($_REQUEST['data']['ee_front_ajax']) ? true : false |
|
185 | - ); |
|
186 | - define( |
|
187 | - 'EE_ADMIN_AJAX', |
|
188 | - isset($_REQUEST['ee_admin_ajax']) || isset($_REQUEST['data']['ee_admin_ajax']) ? true : false |
|
189 | - ); |
|
190 | - //just a handy constant occasionally needed for finding values representing infinity in the DB |
|
191 | - //you're better to use this than its straight value (currently -1) in case you ever |
|
192 | - //want to change its default value! or find when -1 means infinity |
|
193 | - define('EE_INF_IN_DB', -1); |
|
194 | - define('EE_INF', INF > (float)PHP_INT_MAX ? INF : PHP_INT_MAX); |
|
195 | - define('EE_DEBUG', false); |
|
196 | - // for older WP versions |
|
197 | - if ( ! defined('MONTH_IN_SECONDS')) { |
|
198 | - define('MONTH_IN_SECONDS', DAY_IN_SECONDS * 30); |
|
199 | - } |
|
200 | - /** |
|
201 | - * espresso_plugin_activation |
|
202 | - * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
203 | - */ |
|
204 | - function espresso_plugin_activation() |
|
205 | - { |
|
206 | - update_option('ee_espresso_activation', true); |
|
207 | - } |
|
107 | + // define versions |
|
108 | + define('EVENT_ESPRESSO_VERSION', espresso_version()); |
|
109 | + define('EE_MIN_WP_VER_REQUIRED', '4.1'); |
|
110 | + define('EE_MIN_WP_VER_RECOMMENDED', '4.4.2'); |
|
111 | + define('EE_MIN_PHP_VER_RECOMMENDED', '5.4.44'); |
|
112 | + define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
113 | + //used to be DIRECTORY_SEPARATOR, but that caused issues on windows |
|
114 | + if ( ! defined('DS')) { |
|
115 | + define('DS', '/'); |
|
116 | + } |
|
117 | + if ( ! defined('PS')) { |
|
118 | + define('PS', PATH_SEPARATOR); |
|
119 | + } |
|
120 | + if ( ! defined('SP')) { |
|
121 | + define('SP', ' '); |
|
122 | + } |
|
123 | + if ( ! defined('EENL')) { |
|
124 | + define('EENL', "\n"); |
|
125 | + } |
|
126 | + define('EE_SUPPORT_EMAIL', '[email protected]'); |
|
127 | + // define the plugin directory and URL |
|
128 | + define('EE_PLUGIN_BASENAME', plugin_basename(EVENT_ESPRESSO_MAIN_FILE)); |
|
129 | + define('EE_PLUGIN_DIR_PATH', plugin_dir_path(EVENT_ESPRESSO_MAIN_FILE)); |
|
130 | + define('EE_PLUGIN_DIR_URL', plugin_dir_url(EVENT_ESPRESSO_MAIN_FILE)); |
|
131 | + // main root folder paths |
|
132 | + define('EE_ADMIN_PAGES', EE_PLUGIN_DIR_PATH . 'admin_pages' . DS); |
|
133 | + define('EE_CORE', EE_PLUGIN_DIR_PATH . 'core' . DS); |
|
134 | + define('EE_MODULES', EE_PLUGIN_DIR_PATH . 'modules' . DS); |
|
135 | + define('EE_PUBLIC', EE_PLUGIN_DIR_PATH . 'public' . DS); |
|
136 | + define('EE_SHORTCODES', EE_PLUGIN_DIR_PATH . 'shortcodes' . DS); |
|
137 | + define('EE_WIDGETS', EE_PLUGIN_DIR_PATH . 'widgets' . DS); |
|
138 | + define('EE_PAYMENT_METHODS', EE_PLUGIN_DIR_PATH . 'payment_methods' . DS); |
|
139 | + define('EE_CAFF_PATH', EE_PLUGIN_DIR_PATH . 'caffeinated' . DS); |
|
140 | + // core system paths |
|
141 | + define('EE_ADMIN', EE_CORE . 'admin' . DS); |
|
142 | + define('EE_CPTS', EE_CORE . 'CPTs' . DS); |
|
143 | + define('EE_CLASSES', EE_CORE . 'db_classes' . DS); |
|
144 | + define('EE_INTERFACES', EE_CORE . 'interfaces' . DS); |
|
145 | + define('EE_BUSINESS', EE_CORE . 'business' . DS); |
|
146 | + define('EE_MODELS', EE_CORE . 'db_models' . DS); |
|
147 | + define('EE_HELPERS', EE_CORE . 'helpers' . DS); |
|
148 | + define('EE_LIBRARIES', EE_CORE . 'libraries' . DS); |
|
149 | + define('EE_TEMPLATES', EE_CORE . 'templates' . DS); |
|
150 | + define('EE_THIRD_PARTY', EE_CORE . 'third_party_libs' . DS); |
|
151 | + define('EE_GLOBAL_ASSETS', EE_TEMPLATES . 'global_assets' . DS); |
|
152 | + define('EE_FORM_SECTIONS', EE_LIBRARIES . 'form_sections' . DS); |
|
153 | + // gateways |
|
154 | + define('EE_GATEWAYS', EE_MODULES . 'gateways' . DS); |
|
155 | + define('EE_GATEWAYS_URL', EE_PLUGIN_DIR_URL . 'modules' . DS . 'gateways' . DS); |
|
156 | + // asset URL paths |
|
157 | + define('EE_TEMPLATES_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'templates' . DS); |
|
158 | + define('EE_GLOBAL_ASSETS_URL', EE_TEMPLATES_URL . 'global_assets' . DS); |
|
159 | + define('EE_IMAGES_URL', EE_GLOBAL_ASSETS_URL . 'images' . DS); |
|
160 | + define('EE_THIRD_PARTY_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'third_party_libs' . DS); |
|
161 | + define('EE_HELPERS_ASSETS', EE_PLUGIN_DIR_URL . 'core/helpers/assets/'); |
|
162 | + define('EE_LIBRARIES_URL', EE_PLUGIN_DIR_URL . 'core/libraries/'); |
|
163 | + // define upload paths |
|
164 | + $uploads = wp_upload_dir(); |
|
165 | + // define the uploads directory and URL |
|
166 | + define('EVENT_ESPRESSO_UPLOAD_DIR', $uploads['basedir'] . DS . 'espresso' . DS); |
|
167 | + define('EVENT_ESPRESSO_UPLOAD_URL', $uploads['baseurl'] . DS . 'espresso' . DS); |
|
168 | + // define the templates directory and URL |
|
169 | + define('EVENT_ESPRESSO_TEMPLATE_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'templates' . DS); |
|
170 | + define('EVENT_ESPRESSO_TEMPLATE_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'templates' . DS); |
|
171 | + // define the gateway directory and URL |
|
172 | + define('EVENT_ESPRESSO_GATEWAY_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'gateways' . DS); |
|
173 | + define('EVENT_ESPRESSO_GATEWAY_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'gateways' . DS); |
|
174 | + // languages folder/path |
|
175 | + define('EE_LANGUAGES_SAFE_LOC', '..' . DS . 'uploads' . DS . 'espresso' . DS . 'languages' . DS); |
|
176 | + define('EE_LANGUAGES_SAFE_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'languages' . DS); |
|
177 | + //check for dompdf fonts in uploads |
|
178 | + if (file_exists(EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS)) { |
|
179 | + define('DOMPDF_FONT_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS); |
|
180 | + } |
|
181 | + //ajax constants |
|
182 | + define( |
|
183 | + 'EE_FRONT_AJAX', |
|
184 | + isset($_REQUEST['ee_front_ajax']) || isset($_REQUEST['data']['ee_front_ajax']) ? true : false |
|
185 | + ); |
|
186 | + define( |
|
187 | + 'EE_ADMIN_AJAX', |
|
188 | + isset($_REQUEST['ee_admin_ajax']) || isset($_REQUEST['data']['ee_admin_ajax']) ? true : false |
|
189 | + ); |
|
190 | + //just a handy constant occasionally needed for finding values representing infinity in the DB |
|
191 | + //you're better to use this than its straight value (currently -1) in case you ever |
|
192 | + //want to change its default value! or find when -1 means infinity |
|
193 | + define('EE_INF_IN_DB', -1); |
|
194 | + define('EE_INF', INF > (float)PHP_INT_MAX ? INF : PHP_INT_MAX); |
|
195 | + define('EE_DEBUG', false); |
|
196 | + // for older WP versions |
|
197 | + if ( ! defined('MONTH_IN_SECONDS')) { |
|
198 | + define('MONTH_IN_SECONDS', DAY_IN_SECONDS * 30); |
|
199 | + } |
|
200 | + /** |
|
201 | + * espresso_plugin_activation |
|
202 | + * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
203 | + */ |
|
204 | + function espresso_plugin_activation() |
|
205 | + { |
|
206 | + update_option('ee_espresso_activation', true); |
|
207 | + } |
|
208 | 208 | |
209 | - register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
210 | - /** |
|
211 | - * espresso_load_error_handling |
|
212 | - * this function loads EE's class for handling exceptions and errors |
|
213 | - */ |
|
214 | - function espresso_load_error_handling() |
|
215 | - { |
|
216 | - // load debugging tools |
|
217 | - if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) { |
|
218 | - require_once(EE_HELPERS . 'EEH_Debug_Tools.helper.php'); |
|
219 | - EEH_Debug_Tools::instance(); |
|
220 | - } |
|
221 | - // load error handling |
|
222 | - if (is_readable(EE_CORE . 'EE_Error.core.php')) { |
|
223 | - require_once(EE_CORE . 'EE_Error.core.php'); |
|
224 | - } else { |
|
225 | - wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso')); |
|
226 | - } |
|
227 | - } |
|
209 | + register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
210 | + /** |
|
211 | + * espresso_load_error_handling |
|
212 | + * this function loads EE's class for handling exceptions and errors |
|
213 | + */ |
|
214 | + function espresso_load_error_handling() |
|
215 | + { |
|
216 | + // load debugging tools |
|
217 | + if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) { |
|
218 | + require_once(EE_HELPERS . 'EEH_Debug_Tools.helper.php'); |
|
219 | + EEH_Debug_Tools::instance(); |
|
220 | + } |
|
221 | + // load error handling |
|
222 | + if (is_readable(EE_CORE . 'EE_Error.core.php')) { |
|
223 | + require_once(EE_CORE . 'EE_Error.core.php'); |
|
224 | + } else { |
|
225 | + wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso')); |
|
226 | + } |
|
227 | + } |
|
228 | 228 | |
229 | - /** |
|
230 | - * espresso_load_required |
|
231 | - * given a class name and path, this function will load that file or throw an exception |
|
232 | - * |
|
233 | - * @param string $classname |
|
234 | - * @param string $full_path_to_file |
|
235 | - * @throws EE_Error |
|
236 | - */ |
|
237 | - function espresso_load_required($classname, $full_path_to_file) |
|
238 | - { |
|
239 | - static $error_handling_loaded = false; |
|
240 | - if ( ! $error_handling_loaded) { |
|
241 | - espresso_load_error_handling(); |
|
242 | - $error_handling_loaded = true; |
|
243 | - } |
|
244 | - if (is_readable($full_path_to_file)) { |
|
245 | - require_once($full_path_to_file); |
|
246 | - } else { |
|
247 | - throw new EE_Error ( |
|
248 | - sprintf( |
|
249 | - esc_html__( |
|
250 | - 'The %s class file could not be located or is not readable due to file permissions.', |
|
251 | - 'event_espresso' |
|
252 | - ), |
|
253 | - $classname |
|
254 | - ) |
|
255 | - ); |
|
256 | - } |
|
257 | - } |
|
229 | + /** |
|
230 | + * espresso_load_required |
|
231 | + * given a class name and path, this function will load that file or throw an exception |
|
232 | + * |
|
233 | + * @param string $classname |
|
234 | + * @param string $full_path_to_file |
|
235 | + * @throws EE_Error |
|
236 | + */ |
|
237 | + function espresso_load_required($classname, $full_path_to_file) |
|
238 | + { |
|
239 | + static $error_handling_loaded = false; |
|
240 | + if ( ! $error_handling_loaded) { |
|
241 | + espresso_load_error_handling(); |
|
242 | + $error_handling_loaded = true; |
|
243 | + } |
|
244 | + if (is_readable($full_path_to_file)) { |
|
245 | + require_once($full_path_to_file); |
|
246 | + } else { |
|
247 | + throw new EE_Error ( |
|
248 | + sprintf( |
|
249 | + esc_html__( |
|
250 | + 'The %s class file could not be located or is not readable due to file permissions.', |
|
251 | + 'event_espresso' |
|
252 | + ), |
|
253 | + $classname |
|
254 | + ) |
|
255 | + ); |
|
256 | + } |
|
257 | + } |
|
258 | 258 | |
259 | - espresso_load_required('EEH_Base', EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php'); |
|
260 | - espresso_load_required('EEH_File', EE_CORE . 'helpers' . DS . 'EEH_File.helper.php'); |
|
261 | - espresso_load_required('EE_Bootstrap', EE_CORE . 'EE_Bootstrap.core.php'); |
|
262 | - new EE_Bootstrap(); |
|
263 | - } |
|
259 | + espresso_load_required('EEH_Base', EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php'); |
|
260 | + espresso_load_required('EEH_File', EE_CORE . 'helpers' . DS . 'EEH_File.helper.php'); |
|
261 | + espresso_load_required('EE_Bootstrap', EE_CORE . 'EE_Bootstrap.core.php'); |
|
262 | + new EE_Bootstrap(); |
|
263 | + } |
|
264 | 264 | } |
265 | 265 | if ( ! function_exists('espresso_deactivate_plugin')) { |
266 | - /** |
|
267 | - * deactivate_plugin |
|
268 | - * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
269 | - * |
|
270 | - * @access public |
|
271 | - * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
272 | - * @return void |
|
273 | - */ |
|
274 | - function espresso_deactivate_plugin($plugin_basename = '') |
|
275 | - { |
|
276 | - if ( ! function_exists('deactivate_plugins')) { |
|
277 | - require_once(ABSPATH . 'wp-admin/includes/plugin.php'); |
|
278 | - } |
|
279 | - unset($_GET['activate'], $_REQUEST['activate']); |
|
280 | - deactivate_plugins($plugin_basename); |
|
281 | - } |
|
266 | + /** |
|
267 | + * deactivate_plugin |
|
268 | + * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
269 | + * |
|
270 | + * @access public |
|
271 | + * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
272 | + * @return void |
|
273 | + */ |
|
274 | + function espresso_deactivate_plugin($plugin_basename = '') |
|
275 | + { |
|
276 | + if ( ! function_exists('deactivate_plugins')) { |
|
277 | + require_once(ABSPATH . 'wp-admin/includes/plugin.php'); |
|
278 | + } |
|
279 | + unset($_GET['activate'], $_REQUEST['activate']); |
|
280 | + deactivate_plugins($plugin_basename); |
|
281 | + } |
|
282 | 282 | } |
283 | 283 | \ No newline at end of file |