@@ -9,22 +9,22 @@ discard block |
||
9 | 9 | */ |
10 | 10 | function espresso_load_error_handling() |
11 | 11 | { |
12 | - static $error_handling_loaded = false; |
|
13 | - if ($error_handling_loaded) { |
|
14 | - return; |
|
15 | - } |
|
16 | - // load debugging tools |
|
17 | - if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) { |
|
18 | - require_once EE_HELPERS . 'EEH_Debug_Tools.helper.php'; |
|
19 | - \EEH_Debug_Tools::instance(); |
|
20 | - } |
|
21 | - // load error handling |
|
22 | - if (is_readable(EE_CORE . 'EE_Error.core.php')) { |
|
23 | - require_once EE_CORE . 'EE_Error.core.php'; |
|
24 | - } else { |
|
25 | - wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso')); |
|
26 | - } |
|
27 | - $error_handling_loaded = true; |
|
12 | + static $error_handling_loaded = false; |
|
13 | + if ($error_handling_loaded) { |
|
14 | + return; |
|
15 | + } |
|
16 | + // load debugging tools |
|
17 | + if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) { |
|
18 | + require_once EE_HELPERS . 'EEH_Debug_Tools.helper.php'; |
|
19 | + \EEH_Debug_Tools::instance(); |
|
20 | + } |
|
21 | + // load error handling |
|
22 | + if (is_readable(EE_CORE . 'EE_Error.core.php')) { |
|
23 | + require_once EE_CORE . 'EE_Error.core.php'; |
|
24 | + } else { |
|
25 | + wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso')); |
|
26 | + } |
|
27 | + $error_handling_loaded = true; |
|
28 | 28 | } |
29 | 29 | |
30 | 30 | |
@@ -38,19 +38,19 @@ discard block |
||
38 | 38 | */ |
39 | 39 | function espresso_load_required($classname, $full_path_to_file) |
40 | 40 | { |
41 | - if (is_readable($full_path_to_file)) { |
|
42 | - require_once $full_path_to_file; |
|
43 | - } else { |
|
44 | - throw new \EE_Error ( |
|
45 | - sprintf( |
|
46 | - esc_html__( |
|
47 | - 'The %s class file could not be located or is not readable due to file permissions.', |
|
48 | - 'event_espresso' |
|
49 | - ), |
|
50 | - $classname |
|
51 | - ) |
|
52 | - ); |
|
53 | - } |
|
41 | + if (is_readable($full_path_to_file)) { |
|
42 | + require_once $full_path_to_file; |
|
43 | + } else { |
|
44 | + throw new \EE_Error ( |
|
45 | + sprintf( |
|
46 | + esc_html__( |
|
47 | + 'The %s class file could not be located or is not readable due to file permissions.', |
|
48 | + 'event_espresso' |
|
49 | + ), |
|
50 | + $classname |
|
51 | + ) |
|
52 | + ); |
|
53 | + } |
|
54 | 54 | } |
55 | 55 | |
56 | 56 | |
@@ -69,41 +69,41 @@ discard block |
||
69 | 69 | */ |
70 | 70 | function bootstrap_espresso() |
71 | 71 | { |
72 | - require_once __DIR__ . '/espresso_definitions.php'; |
|
73 | - try { |
|
74 | - espresso_load_error_handling(); |
|
75 | - espresso_load_required( |
|
76 | - 'EEH_Base', |
|
77 | - EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php' |
|
78 | - ); |
|
79 | - espresso_load_required( |
|
80 | - 'EEH_File', |
|
81 | - EE_CORE . 'interfaces' . DS . 'EEHI_File.interface.php' |
|
82 | - ); |
|
83 | - espresso_load_required( |
|
84 | - 'EEH_File', |
|
85 | - EE_CORE . 'helpers' . DS . 'EEH_File.helper.php' |
|
86 | - ); |
|
87 | - espresso_load_required( |
|
88 | - 'EEH_Array', |
|
89 | - EE_CORE . 'helpers' . DS . 'EEH_Array.helper.php' |
|
90 | - ); |
|
91 | - // instantiate and configure PSR4 autoloader |
|
92 | - espresso_load_required( |
|
93 | - 'Psr4Autoloader', |
|
94 | - EE_CORE . 'Psr4Autoloader.php' |
|
95 | - ); |
|
96 | - espresso_load_required( |
|
97 | - 'EE_Psr4AutoloaderInit', |
|
98 | - EE_CORE . 'EE_Psr4AutoloaderInit.core.php' |
|
99 | - ); |
|
100 | - $AutoloaderInit = new EE_Psr4AutoloaderInit(); |
|
101 | - $AutoloaderInit->initializeAutoloader(); |
|
102 | - new EventEspresso\core\services\bootstrap\BootstrapCore(); |
|
103 | - } catch (Exception $e) { |
|
104 | - require_once EE_CORE . 'exceptions' . DS . 'ExceptionStackTraceDisplay.php'; |
|
105 | - new EventEspresso\core\exceptions\ExceptionStackTraceDisplay($e); |
|
106 | - } |
|
72 | + require_once __DIR__ . '/espresso_definitions.php'; |
|
73 | + try { |
|
74 | + espresso_load_error_handling(); |
|
75 | + espresso_load_required( |
|
76 | + 'EEH_Base', |
|
77 | + EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php' |
|
78 | + ); |
|
79 | + espresso_load_required( |
|
80 | + 'EEH_File', |
|
81 | + EE_CORE . 'interfaces' . DS . 'EEHI_File.interface.php' |
|
82 | + ); |
|
83 | + espresso_load_required( |
|
84 | + 'EEH_File', |
|
85 | + EE_CORE . 'helpers' . DS . 'EEH_File.helper.php' |
|
86 | + ); |
|
87 | + espresso_load_required( |
|
88 | + 'EEH_Array', |
|
89 | + EE_CORE . 'helpers' . DS . 'EEH_Array.helper.php' |
|
90 | + ); |
|
91 | + // instantiate and configure PSR4 autoloader |
|
92 | + espresso_load_required( |
|
93 | + 'Psr4Autoloader', |
|
94 | + EE_CORE . 'Psr4Autoloader.php' |
|
95 | + ); |
|
96 | + espresso_load_required( |
|
97 | + 'EE_Psr4AutoloaderInit', |
|
98 | + EE_CORE . 'EE_Psr4AutoloaderInit.core.php' |
|
99 | + ); |
|
100 | + $AutoloaderInit = new EE_Psr4AutoloaderInit(); |
|
101 | + $AutoloaderInit->initializeAutoloader(); |
|
102 | + new EventEspresso\core\services\bootstrap\BootstrapCore(); |
|
103 | + } catch (Exception $e) { |
|
104 | + require_once EE_CORE . 'exceptions' . DS . 'ExceptionStackTraceDisplay.php'; |
|
105 | + new EventEspresso\core\exceptions\ExceptionStackTraceDisplay($e); |
|
106 | + } |
|
107 | 107 | } |
108 | 108 | |
109 | 109 |
@@ -14,13 +14,13 @@ discard block |
||
14 | 14 | return; |
15 | 15 | } |
16 | 16 | // load debugging tools |
17 | - if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) { |
|
18 | - require_once EE_HELPERS . 'EEH_Debug_Tools.helper.php'; |
|
17 | + if (WP_DEBUG === true && is_readable(EE_HELPERS.'EEH_Debug_Tools.helper.php')) { |
|
18 | + require_once EE_HELPERS.'EEH_Debug_Tools.helper.php'; |
|
19 | 19 | \EEH_Debug_Tools::instance(); |
20 | 20 | } |
21 | 21 | // load error handling |
22 | - if (is_readable(EE_CORE . 'EE_Error.core.php')) { |
|
23 | - require_once EE_CORE . 'EE_Error.core.php'; |
|
22 | + if (is_readable(EE_CORE.'EE_Error.core.php')) { |
|
23 | + require_once EE_CORE.'EE_Error.core.php'; |
|
24 | 24 | } else { |
25 | 25 | wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso')); |
26 | 26 | } |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | if (is_readable($full_path_to_file)) { |
42 | 42 | require_once $full_path_to_file; |
43 | 43 | } else { |
44 | - throw new \EE_Error ( |
|
44 | + throw new \EE_Error( |
|
45 | 45 | sprintf( |
46 | 46 | esc_html__( |
47 | 47 | 'The %s class file could not be located or is not readable due to file permissions.', |
@@ -69,39 +69,39 @@ discard block |
||
69 | 69 | */ |
70 | 70 | function bootstrap_espresso() |
71 | 71 | { |
72 | - require_once __DIR__ . '/espresso_definitions.php'; |
|
72 | + require_once __DIR__.'/espresso_definitions.php'; |
|
73 | 73 | try { |
74 | 74 | espresso_load_error_handling(); |
75 | 75 | espresso_load_required( |
76 | 76 | 'EEH_Base', |
77 | - EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php' |
|
77 | + EE_CORE.'helpers'.DS.'EEH_Base.helper.php' |
|
78 | 78 | ); |
79 | 79 | espresso_load_required( |
80 | 80 | 'EEH_File', |
81 | - EE_CORE . 'interfaces' . DS . 'EEHI_File.interface.php' |
|
81 | + EE_CORE.'interfaces'.DS.'EEHI_File.interface.php' |
|
82 | 82 | ); |
83 | 83 | espresso_load_required( |
84 | 84 | 'EEH_File', |
85 | - EE_CORE . 'helpers' . DS . 'EEH_File.helper.php' |
|
85 | + EE_CORE.'helpers'.DS.'EEH_File.helper.php' |
|
86 | 86 | ); |
87 | 87 | espresso_load_required( |
88 | 88 | 'EEH_Array', |
89 | - EE_CORE . 'helpers' . DS . 'EEH_Array.helper.php' |
|
89 | + EE_CORE.'helpers'.DS.'EEH_Array.helper.php' |
|
90 | 90 | ); |
91 | 91 | // instantiate and configure PSR4 autoloader |
92 | 92 | espresso_load_required( |
93 | 93 | 'Psr4Autoloader', |
94 | - EE_CORE . 'Psr4Autoloader.php' |
|
94 | + EE_CORE.'Psr4Autoloader.php' |
|
95 | 95 | ); |
96 | 96 | espresso_load_required( |
97 | 97 | 'EE_Psr4AutoloaderInit', |
98 | - EE_CORE . 'EE_Psr4AutoloaderInit.core.php' |
|
98 | + EE_CORE.'EE_Psr4AutoloaderInit.core.php' |
|
99 | 99 | ); |
100 | 100 | $AutoloaderInit = new EE_Psr4AutoloaderInit(); |
101 | 101 | $AutoloaderInit->initializeAutoloader(); |
102 | 102 | new EventEspresso\core\services\bootstrap\BootstrapCore(); |
103 | 103 | } catch (Exception $e) { |
104 | - require_once EE_CORE . 'exceptions' . DS . 'ExceptionStackTraceDisplay.php'; |
|
104 | + require_once EE_CORE.'exceptions'.DS.'ExceptionStackTraceDisplay.php'; |
|
105 | 105 | new EventEspresso\core\exceptions\ExceptionStackTraceDisplay($e); |
106 | 106 | } |
107 | 107 | } |
@@ -38,7 +38,7 @@ discard block |
||
38 | 38 | * @since 4.0 |
39 | 39 | */ |
40 | 40 | if (function_exists('espresso_version')) { |
41 | - if (! function_exists('espresso_duplicate_plugin_error')) { |
|
41 | + if ( ! function_exists('espresso_duplicate_plugin_error')) { |
|
42 | 42 | /** |
43 | 43 | * espresso_duplicate_plugin_error |
44 | 44 | * displays if more than one version of EE is activated at the same time |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | |
64 | 64 | } else { |
65 | 65 | define('EE_MIN_PHP_VER_REQUIRED', '5.3.9'); |
66 | - if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
66 | + if ( ! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
67 | 67 | /** |
68 | 68 | * espresso_minimum_php_version_error |
69 | 69 | * @return void |
@@ -116,11 +116,11 @@ discard block |
||
116 | 116 | |
117 | 117 | register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
118 | 118 | |
119 | - require_once __DIR__ . '/core/bootstrap_espresso.php'; |
|
119 | + require_once __DIR__.'/core/bootstrap_espresso.php'; |
|
120 | 120 | bootstrap_espresso(); |
121 | 121 | } |
122 | 122 | } |
123 | -if (! function_exists('espresso_deactivate_plugin')) { |
|
123 | +if ( ! function_exists('espresso_deactivate_plugin')) { |
|
124 | 124 | /** |
125 | 125 | * deactivate_plugin |
126 | 126 | * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
@@ -131,8 +131,8 @@ discard block |
||
131 | 131 | */ |
132 | 132 | function espresso_deactivate_plugin($plugin_basename = '') |
133 | 133 | { |
134 | - if (! function_exists('deactivate_plugins')) { |
|
135 | - require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
134 | + if ( ! function_exists('deactivate_plugins')) { |
|
135 | + require_once ABSPATH.'wp-admin/includes/plugin.php'; |
|
136 | 136 | } |
137 | 137 | unset($_GET['activate'], $_REQUEST['activate']); |
138 | 138 | deactivate_plugins($plugin_basename); |
@@ -38,103 +38,103 @@ |
||
38 | 38 | * @since 4.0 |
39 | 39 | */ |
40 | 40 | if (function_exists('espresso_version')) { |
41 | - if (! function_exists('espresso_duplicate_plugin_error')) { |
|
42 | - /** |
|
43 | - * espresso_duplicate_plugin_error |
|
44 | - * displays if more than one version of EE is activated at the same time |
|
45 | - */ |
|
46 | - function espresso_duplicate_plugin_error() |
|
47 | - { |
|
48 | - ?> |
|
41 | + if (! function_exists('espresso_duplicate_plugin_error')) { |
|
42 | + /** |
|
43 | + * espresso_duplicate_plugin_error |
|
44 | + * displays if more than one version of EE is activated at the same time |
|
45 | + */ |
|
46 | + function espresso_duplicate_plugin_error() |
|
47 | + { |
|
48 | + ?> |
|
49 | 49 | <div class="error"> |
50 | 50 | <p> |
51 | 51 | <?php |
52 | - echo esc_html__( |
|
53 | - 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
54 | - 'event_espresso' |
|
55 | - ); ?> |
|
52 | + echo esc_html__( |
|
53 | + 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
54 | + 'event_espresso' |
|
55 | + ); ?> |
|
56 | 56 | </p> |
57 | 57 | </div> |
58 | 58 | <?php |
59 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
60 | - } |
|
61 | - } |
|
62 | - add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
59 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
60 | + } |
|
61 | + } |
|
62 | + add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
63 | 63 | |
64 | 64 | } else { |
65 | - define('EE_MIN_PHP_VER_REQUIRED', '5.3.9'); |
|
66 | - if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
67 | - /** |
|
68 | - * espresso_minimum_php_version_error |
|
69 | - * @return void |
|
70 | - */ |
|
71 | - function espresso_minimum_php_version_error() |
|
72 | - { |
|
73 | - ?> |
|
65 | + define('EE_MIN_PHP_VER_REQUIRED', '5.3.9'); |
|
66 | + if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
67 | + /** |
|
68 | + * espresso_minimum_php_version_error |
|
69 | + * @return void |
|
70 | + */ |
|
71 | + function espresso_minimum_php_version_error() |
|
72 | + { |
|
73 | + ?> |
|
74 | 74 | <div class="error"> |
75 | 75 | <p> |
76 | 76 | <?php |
77 | - printf( |
|
78 | - esc_html__( |
|
79 | - 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
80 | - 'event_espresso' |
|
81 | - ), |
|
82 | - EE_MIN_PHP_VER_REQUIRED, |
|
83 | - PHP_VERSION, |
|
84 | - '<br/>', |
|
85 | - '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
86 | - ); |
|
87 | - ?> |
|
77 | + printf( |
|
78 | + esc_html__( |
|
79 | + 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
80 | + 'event_espresso' |
|
81 | + ), |
|
82 | + EE_MIN_PHP_VER_REQUIRED, |
|
83 | + PHP_VERSION, |
|
84 | + '<br/>', |
|
85 | + '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
86 | + ); |
|
87 | + ?> |
|
88 | 88 | </p> |
89 | 89 | </div> |
90 | 90 | <?php |
91 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
92 | - } |
|
91 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
92 | + } |
|
93 | 93 | |
94 | - add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
95 | - } else { |
|
96 | - define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
97 | - /** |
|
98 | - * espresso_version |
|
99 | - * Returns the plugin version |
|
100 | - * |
|
101 | - * @return string |
|
102 | - */ |
|
103 | - function espresso_version() |
|
104 | - { |
|
105 | - return apply_filters('FHEE__espresso__espresso_version', '4.9.59.rc.020'); |
|
106 | - } |
|
94 | + add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
95 | + } else { |
|
96 | + define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
97 | + /** |
|
98 | + * espresso_version |
|
99 | + * Returns the plugin version |
|
100 | + * |
|
101 | + * @return string |
|
102 | + */ |
|
103 | + function espresso_version() |
|
104 | + { |
|
105 | + return apply_filters('FHEE__espresso__espresso_version', '4.9.59.rc.020'); |
|
106 | + } |
|
107 | 107 | |
108 | - /** |
|
109 | - * espresso_plugin_activation |
|
110 | - * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
111 | - */ |
|
112 | - function espresso_plugin_activation() |
|
113 | - { |
|
114 | - update_option('ee_espresso_activation', true); |
|
115 | - } |
|
108 | + /** |
|
109 | + * espresso_plugin_activation |
|
110 | + * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
111 | + */ |
|
112 | + function espresso_plugin_activation() |
|
113 | + { |
|
114 | + update_option('ee_espresso_activation', true); |
|
115 | + } |
|
116 | 116 | |
117 | - register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
117 | + register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
118 | 118 | |
119 | - require_once __DIR__ . '/core/bootstrap_espresso.php'; |
|
120 | - bootstrap_espresso(); |
|
121 | - } |
|
119 | + require_once __DIR__ . '/core/bootstrap_espresso.php'; |
|
120 | + bootstrap_espresso(); |
|
121 | + } |
|
122 | 122 | } |
123 | 123 | if (! function_exists('espresso_deactivate_plugin')) { |
124 | - /** |
|
125 | - * deactivate_plugin |
|
126 | - * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
127 | - * |
|
128 | - * @access public |
|
129 | - * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
130 | - * @return void |
|
131 | - */ |
|
132 | - function espresso_deactivate_plugin($plugin_basename = '') |
|
133 | - { |
|
134 | - if (! function_exists('deactivate_plugins')) { |
|
135 | - require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
136 | - } |
|
137 | - unset($_GET['activate'], $_REQUEST['activate']); |
|
138 | - deactivate_plugins($plugin_basename); |
|
139 | - } |
|
124 | + /** |
|
125 | + * deactivate_plugin |
|
126 | + * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
127 | + * |
|
128 | + * @access public |
|
129 | + * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
130 | + * @return void |
|
131 | + */ |
|
132 | + function espresso_deactivate_plugin($plugin_basename = '') |
|
133 | + { |
|
134 | + if (! function_exists('deactivate_plugins')) { |
|
135 | + require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
|
136 | + } |
|
137 | + unset($_GET['activate'], $_REQUEST['activate']); |
|
138 | + deactivate_plugins($plugin_basename); |
|
139 | + } |
|
140 | 140 | } |
@@ -25,1144 +25,1144 @@ |
||
25 | 25 | { |
26 | 26 | |
27 | 27 | |
28 | - /** |
|
29 | - * possibly truncated version of the EE core version string |
|
30 | - * |
|
31 | - * @var string |
|
32 | - */ |
|
33 | - protected static $_core_version = ''; |
|
28 | + /** |
|
29 | + * possibly truncated version of the EE core version string |
|
30 | + * |
|
31 | + * @var string |
|
32 | + */ |
|
33 | + protected static $_core_version = ''; |
|
34 | 34 | |
35 | - /** |
|
36 | - * Holds values for registered addons |
|
37 | - * |
|
38 | - * @var array |
|
39 | - */ |
|
40 | - protected static $_settings = array(); |
|
35 | + /** |
|
36 | + * Holds values for registered addons |
|
37 | + * |
|
38 | + * @var array |
|
39 | + */ |
|
40 | + protected static $_settings = array(); |
|
41 | 41 | |
42 | - /** |
|
43 | - * @var array $_incompatible_addons keys are addon SLUGS |
|
44 | - * (first argument passed to EE_Register_Addon::register()), keys are |
|
45 | - * their MINIMUM VERSION (with all 5 parts. Eg 1.2.3.rc.004). |
|
46 | - * Generally this should be used sparingly, as we don't want to muddle up |
|
47 | - * EE core with knowledge of ALL the addons out there. |
|
48 | - * If you want NO versions of an addon to run with a certain version of core, |
|
49 | - * it's usually best to define the addon's "min_core_version" as part of its call |
|
50 | - * to EE_Register_Addon::register(), rather than using this array with a super high value for its |
|
51 | - * minimum plugin version. |
|
52 | - * @access protected |
|
53 | - */ |
|
54 | - protected static $_incompatible_addons = array( |
|
55 | - 'Multi_Event_Registration' => '2.0.11.rc.002', |
|
56 | - 'Promotions' => '1.0.0.rc.084', |
|
57 | - ); |
|
42 | + /** |
|
43 | + * @var array $_incompatible_addons keys are addon SLUGS |
|
44 | + * (first argument passed to EE_Register_Addon::register()), keys are |
|
45 | + * their MINIMUM VERSION (with all 5 parts. Eg 1.2.3.rc.004). |
|
46 | + * Generally this should be used sparingly, as we don't want to muddle up |
|
47 | + * EE core with knowledge of ALL the addons out there. |
|
48 | + * If you want NO versions of an addon to run with a certain version of core, |
|
49 | + * it's usually best to define the addon's "min_core_version" as part of its call |
|
50 | + * to EE_Register_Addon::register(), rather than using this array with a super high value for its |
|
51 | + * minimum plugin version. |
|
52 | + * @access protected |
|
53 | + */ |
|
54 | + protected static $_incompatible_addons = array( |
|
55 | + 'Multi_Event_Registration' => '2.0.11.rc.002', |
|
56 | + 'Promotions' => '1.0.0.rc.084', |
|
57 | + ); |
|
58 | 58 | |
59 | 59 | |
60 | - /** |
|
61 | - * We should always be comparing core to a version like '4.3.0.rc.000', |
|
62 | - * not just '4.3.0'. |
|
63 | - * So if the addon developer doesn't provide that full version string, |
|
64 | - * fill in the blanks for them |
|
65 | - * |
|
66 | - * @param string $min_core_version |
|
67 | - * @return string always like '4.3.0.rc.000' |
|
68 | - */ |
|
69 | - protected static function _effective_version($min_core_version) |
|
70 | - { |
|
71 | - // versions: 4 . 3 . 1 . p . 123 |
|
72 | - // offsets: 0 . 1 . 2 . 3 . 4 |
|
73 | - $version_parts = explode('.', $min_core_version); |
|
74 | - //check they specified the micro version (after 2nd period) |
|
75 | - if (! isset($version_parts[2])) { |
|
76 | - $version_parts[2] = '0'; |
|
77 | - } |
|
78 | - //if they didn't specify the 'p', or 'rc' part. Just assume the lowest possible |
|
79 | - //soon we can assume that's 'rc', but this current version is 'alpha' |
|
80 | - if (! isset($version_parts[3])) { |
|
81 | - $version_parts[3] = 'dev'; |
|
82 | - } |
|
83 | - if (! isset($version_parts[4])) { |
|
84 | - $version_parts[4] = '000'; |
|
85 | - } |
|
86 | - return implode('.', $version_parts); |
|
87 | - } |
|
60 | + /** |
|
61 | + * We should always be comparing core to a version like '4.3.0.rc.000', |
|
62 | + * not just '4.3.0'. |
|
63 | + * So if the addon developer doesn't provide that full version string, |
|
64 | + * fill in the blanks for them |
|
65 | + * |
|
66 | + * @param string $min_core_version |
|
67 | + * @return string always like '4.3.0.rc.000' |
|
68 | + */ |
|
69 | + protected static function _effective_version($min_core_version) |
|
70 | + { |
|
71 | + // versions: 4 . 3 . 1 . p . 123 |
|
72 | + // offsets: 0 . 1 . 2 . 3 . 4 |
|
73 | + $version_parts = explode('.', $min_core_version); |
|
74 | + //check they specified the micro version (after 2nd period) |
|
75 | + if (! isset($version_parts[2])) { |
|
76 | + $version_parts[2] = '0'; |
|
77 | + } |
|
78 | + //if they didn't specify the 'p', or 'rc' part. Just assume the lowest possible |
|
79 | + //soon we can assume that's 'rc', but this current version is 'alpha' |
|
80 | + if (! isset($version_parts[3])) { |
|
81 | + $version_parts[3] = 'dev'; |
|
82 | + } |
|
83 | + if (! isset($version_parts[4])) { |
|
84 | + $version_parts[4] = '000'; |
|
85 | + } |
|
86 | + return implode('.', $version_parts); |
|
87 | + } |
|
88 | 88 | |
89 | 89 | |
90 | - /** |
|
91 | - * Returns whether or not the min core version requirement of the addon is met |
|
92 | - * |
|
93 | - * @param string $min_core_version the minimum core version required by the addon |
|
94 | - * @param string $actual_core_version the actual core version, optional |
|
95 | - * @return boolean |
|
96 | - */ |
|
97 | - public static function _meets_min_core_version_requirement( |
|
98 | - $min_core_version, |
|
99 | - $actual_core_version = EVENT_ESPRESSO_VERSION |
|
100 | - ) { |
|
101 | - return version_compare( |
|
102 | - self::_effective_version($actual_core_version), |
|
103 | - self::_effective_version($min_core_version), |
|
104 | - '>=' |
|
105 | - ); |
|
106 | - } |
|
90 | + /** |
|
91 | + * Returns whether or not the min core version requirement of the addon is met |
|
92 | + * |
|
93 | + * @param string $min_core_version the minimum core version required by the addon |
|
94 | + * @param string $actual_core_version the actual core version, optional |
|
95 | + * @return boolean |
|
96 | + */ |
|
97 | + public static function _meets_min_core_version_requirement( |
|
98 | + $min_core_version, |
|
99 | + $actual_core_version = EVENT_ESPRESSO_VERSION |
|
100 | + ) { |
|
101 | + return version_compare( |
|
102 | + self::_effective_version($actual_core_version), |
|
103 | + self::_effective_version($min_core_version), |
|
104 | + '>=' |
|
105 | + ); |
|
106 | + } |
|
107 | 107 | |
108 | 108 | |
109 | - /** |
|
110 | - * Method for registering new EE_Addons. |
|
111 | - * Should be called AFTER AHEE__EE_System__load_espresso_addons but BEFORE |
|
112 | - * AHEE__EE_System___detect_if_activation_or_upgrade__begin in order to register all its components. However, it |
|
113 | - * may also be called after the 'activate_plugin' action (when an addon is activated), because an activating addon |
|
114 | - * won't be loaded by WP until after AHEE__EE_System__load_espresso_addons has fired. If its called after |
|
115 | - * 'activate_plugin', it registers the addon still, but its components are not registered |
|
116 | - * (they shouldn't be needed anyways, because it's just an activation request and they won't have a chance to do |
|
117 | - * anything anyways). Instead, it just sets the newly-activated addon's activation indicator wp option and returns |
|
118 | - * (so that we can detect that the addon has activated on the subsequent request) |
|
119 | - * |
|
120 | - * @since 4.3.0 |
|
121 | - * @param string $addon_name the EE_Addon's name. Required. |
|
122 | - * @param array $setup_args { |
|
123 | - * An array of arguments provided for registering the |
|
124 | - * message type. |
|
125 | - * @type string $class_name the addon's main file name. |
|
126 | - * If left blank, generated from the addon name, |
|
127 | - * changes something like "calendar" to "EE_Calendar" |
|
128 | - * @type string $min_core_version the minimum version of EE Core that the |
|
129 | - * addon will work with. eg "4.8.1.rc.084" |
|
130 | - * @type string $version the "software" version for the addon. eg |
|
131 | - * "1.0.0.p" for a first stable release, or |
|
132 | - * "1.0.0.rc.043" for a version in progress |
|
133 | - * @type string $main_file_path the full server path to the main file |
|
134 | - * loaded directly by WP |
|
135 | - * @type string $domain_fqcn Fully Qualified Class Name |
|
136 | - * for the addon's Domain class |
|
137 | - * (see EventEspresso\core\domain\Domain) |
|
138 | - * @type string $admin_path full server path to the folder where the |
|
139 | - * addon\'s admin files reside |
|
140 | - * @type string $admin_callback a method to be called when the EE Admin is |
|
141 | - * first invoked, can be used for hooking into |
|
142 | - * any admin page |
|
143 | - * @type string $config_section the section name for this addon's |
|
144 | - * configuration settings section |
|
145 | - * (defaults to "addons") |
|
146 | - * @type string $config_class the class name for this addon's |
|
147 | - * configuration settings object |
|
148 | - * @type string $config_name the class name for this addon's |
|
149 | - * configuration settings object |
|
150 | - * @type string $autoloader_paths an array of class names and the full server |
|
151 | - * paths to those files. Required. |
|
152 | - * @type string $autoloader_folders an array of "full server paths" for any |
|
153 | - * folders containing classes that might be |
|
154 | - * invoked by the addon |
|
155 | - * @type string $dms_paths an array of full server paths to folders that |
|
156 | - * contain data migration scripts. Required. |
|
157 | - * @type string $module_paths an array of full server paths to any |
|
158 | - * EED_Modules used by the addon |
|
159 | - * @type string $shortcode_paths an array of full server paths to folders |
|
160 | - * that contain EES_Shortcodes |
|
161 | - * @type string $widget_paths an array of full server paths to folders |
|
162 | - * that contain WP_Widgets |
|
163 | - * @type string $pue_options |
|
164 | - * @type array $capabilities an array indexed by role name |
|
165 | - * (i.e administrator,author ) and the values |
|
166 | - * are an array of caps to add to the role. |
|
167 | - * 'administrator' => array( |
|
168 | - * 'read_addon', |
|
169 | - * 'edit_addon', |
|
170 | - * etc. |
|
171 | - * ). |
|
172 | - * @type EE_Meta_Capability_Map[] $capability_maps an array of EE_Meta_Capability_Map object |
|
173 | - * for any addons that need to register any |
|
174 | - * special meta mapped capabilities. Should |
|
175 | - * be indexed where the key is the |
|
176 | - * EE_Meta_Capability_Map class name and the |
|
177 | - * values are the arguments sent to the class. |
|
178 | - * @type array $model_paths array of folders containing DB models |
|
179 | - * @see EE_Register_Model |
|
180 | - * @type array $class_paths array of folders containing DB classes |
|
181 | - * @see EE_Register_Model |
|
182 | - * @type array $model_extension_paths array of folders containing DB model |
|
183 | - * extensions |
|
184 | - * @see EE_Register_Model_Extension |
|
185 | - * @type array $class_extension_paths array of folders containing DB class |
|
186 | - * extensions |
|
187 | - * @see EE_Register_Model_Extension |
|
188 | - * @type array message_types { |
|
189 | - * An array of message types with the key as |
|
190 | - * the message type name and the values as |
|
191 | - * below: |
|
192 | - * @type string $mtfilename The filename of the message type being |
|
193 | - * registered. This will be the main |
|
194 | - * EE_{Message Type Name}_message_type class. |
|
195 | - * (eg. EE_Declined_Registration_message_type.class.php) |
|
196 | - * Required. |
|
197 | - * @type array $autoloadpaths An array of paths to add to the messages |
|
198 | - * autoloader for the new message type. |
|
199 | - * Required. |
|
200 | - * @type array $messengers_to_activate_with An array of messengers that this message |
|
201 | - * type should activate with. Each value in |
|
202 | - * the |
|
203 | - * array |
|
204 | - * should match the name property of a |
|
205 | - * EE_messenger. Optional. |
|
206 | - * @type array $messengers_to_validate_with An array of messengers that this message |
|
207 | - * type should validate with. Each value in |
|
208 | - * the |
|
209 | - * array |
|
210 | - * should match the name property of an |
|
211 | - * EE_messenger. |
|
212 | - * Optional. |
|
213 | - * } |
|
214 | - * @type array $custom_post_types |
|
215 | - * @type array $custom_taxonomies |
|
216 | - * @type array $payment_method_paths each element is the folder containing the |
|
217 | - * EE_PMT_Base child class |
|
218 | - * (eg, |
|
219 | - * '/wp-content/plugins/my_plugin/Payomatic/' |
|
220 | - * which contains the files |
|
221 | - * EE_PMT_Payomatic.pm.php) |
|
222 | - * @type array $default_terms |
|
223 | - * @type array $namespace { |
|
224 | - * An array with two items for registering the |
|
225 | - * addon's namespace. (If, for some reason, you |
|
226 | - * require additional namespaces, |
|
227 | - * use EventEspresso\core\Psr4Autoloader::addNamespace() |
|
228 | - * directly) |
|
229 | - * @see EventEspresso\core\Psr4Autoloader::addNamespace() |
|
230 | - * @type string $FQNS the namespace prefix |
|
231 | - * @type string $DIR a base directory for class files in the |
|
232 | - * namespace. |
|
233 | - * } |
|
234 | - * } |
|
235 | - * @return void |
|
236 | - * @throws DomainException |
|
237 | - * @throws EE_Error |
|
238 | - * @throws InvalidArgumentException |
|
239 | - * @throws ReflectionException |
|
240 | - * @throws InvalidDataTypeException |
|
241 | - * @throws InvalidInterfaceException |
|
242 | - */ |
|
243 | - public static function register($addon_name = '', $setup_args = array()) |
|
244 | - { |
|
245 | - // required fields MUST be present, so let's make sure they are. |
|
246 | - EE_Register_Addon::_verify_parameters($addon_name, $setup_args); |
|
247 | - // get class name for addon |
|
248 | - $class_name = EE_Register_Addon::_parse_class_name($addon_name, $setup_args); |
|
249 | - //setup $_settings array from incoming values. |
|
250 | - $addon_settings = EE_Register_Addon::_get_addon_settings($class_name, $setup_args); |
|
251 | - // setup PUE |
|
252 | - EE_Register_Addon::_parse_pue_options($addon_name, $class_name, $setup_args); |
|
253 | - // does this addon work with this version of core or WordPress ? |
|
254 | - if (! EE_Register_Addon::_addon_is_compatible($addon_name, $addon_settings)) { |
|
255 | - return; |
|
256 | - } |
|
257 | - // register namespaces |
|
258 | - EE_Register_Addon::_setup_namespaces($addon_settings); |
|
259 | - // check if this is an activation request |
|
260 | - if (EE_Register_Addon::_addon_activation($addon_name, $addon_settings)) { |
|
261 | - // dont bother setting up the rest of the addon atm |
|
262 | - return; |
|
263 | - } |
|
264 | - // we need cars |
|
265 | - EE_Register_Addon::_setup_autoloaders($addon_name); |
|
266 | - // register new models and extensions |
|
267 | - EE_Register_Addon::_register_models_and_extensions($addon_name); |
|
268 | - // setup DMS |
|
269 | - EE_Register_Addon::_register_data_migration_scripts($addon_name); |
|
270 | - // if config_class is present let's register config. |
|
271 | - EE_Register_Addon::_register_config($addon_name); |
|
272 | - // register admin pages |
|
273 | - EE_Register_Addon::_register_admin_pages($addon_name); |
|
274 | - // add to list of modules to be registered |
|
275 | - EE_Register_Addon::_register_modules($addon_name); |
|
276 | - // add to list of shortcodes to be registered |
|
277 | - EE_Register_Addon::_register_shortcodes($addon_name); |
|
278 | - // add to list of widgets to be registered |
|
279 | - EE_Register_Addon::_register_widgets($addon_name); |
|
280 | - // register capability related stuff. |
|
281 | - EE_Register_Addon::_register_capabilities($addon_name); |
|
282 | - // any message type to register? |
|
283 | - EE_Register_Addon::_register_message_types($addon_name); |
|
284 | - // any custom post type/ custom capabilities or default terms to register |
|
285 | - EE_Register_Addon::_register_custom_post_types($addon_name); |
|
286 | - // and any payment methods |
|
287 | - EE_Register_Addon::_register_payment_methods($addon_name); |
|
288 | - // load and instantiate main addon class |
|
289 | - $addon = EE_Register_Addon::_load_and_init_addon_class($addon_name); |
|
290 | - //delay calling after_registration hook on each addon until after all add-ons have been registered. |
|
291 | - add_action('AHEE__EE_System__load_espresso_addons__complete', array($addon, 'after_registration'), 999); |
|
292 | - } |
|
109 | + /** |
|
110 | + * Method for registering new EE_Addons. |
|
111 | + * Should be called AFTER AHEE__EE_System__load_espresso_addons but BEFORE |
|
112 | + * AHEE__EE_System___detect_if_activation_or_upgrade__begin in order to register all its components. However, it |
|
113 | + * may also be called after the 'activate_plugin' action (when an addon is activated), because an activating addon |
|
114 | + * won't be loaded by WP until after AHEE__EE_System__load_espresso_addons has fired. If its called after |
|
115 | + * 'activate_plugin', it registers the addon still, but its components are not registered |
|
116 | + * (they shouldn't be needed anyways, because it's just an activation request and they won't have a chance to do |
|
117 | + * anything anyways). Instead, it just sets the newly-activated addon's activation indicator wp option and returns |
|
118 | + * (so that we can detect that the addon has activated on the subsequent request) |
|
119 | + * |
|
120 | + * @since 4.3.0 |
|
121 | + * @param string $addon_name the EE_Addon's name. Required. |
|
122 | + * @param array $setup_args { |
|
123 | + * An array of arguments provided for registering the |
|
124 | + * message type. |
|
125 | + * @type string $class_name the addon's main file name. |
|
126 | + * If left blank, generated from the addon name, |
|
127 | + * changes something like "calendar" to "EE_Calendar" |
|
128 | + * @type string $min_core_version the minimum version of EE Core that the |
|
129 | + * addon will work with. eg "4.8.1.rc.084" |
|
130 | + * @type string $version the "software" version for the addon. eg |
|
131 | + * "1.0.0.p" for a first stable release, or |
|
132 | + * "1.0.0.rc.043" for a version in progress |
|
133 | + * @type string $main_file_path the full server path to the main file |
|
134 | + * loaded directly by WP |
|
135 | + * @type string $domain_fqcn Fully Qualified Class Name |
|
136 | + * for the addon's Domain class |
|
137 | + * (see EventEspresso\core\domain\Domain) |
|
138 | + * @type string $admin_path full server path to the folder where the |
|
139 | + * addon\'s admin files reside |
|
140 | + * @type string $admin_callback a method to be called when the EE Admin is |
|
141 | + * first invoked, can be used for hooking into |
|
142 | + * any admin page |
|
143 | + * @type string $config_section the section name for this addon's |
|
144 | + * configuration settings section |
|
145 | + * (defaults to "addons") |
|
146 | + * @type string $config_class the class name for this addon's |
|
147 | + * configuration settings object |
|
148 | + * @type string $config_name the class name for this addon's |
|
149 | + * configuration settings object |
|
150 | + * @type string $autoloader_paths an array of class names and the full server |
|
151 | + * paths to those files. Required. |
|
152 | + * @type string $autoloader_folders an array of "full server paths" for any |
|
153 | + * folders containing classes that might be |
|
154 | + * invoked by the addon |
|
155 | + * @type string $dms_paths an array of full server paths to folders that |
|
156 | + * contain data migration scripts. Required. |
|
157 | + * @type string $module_paths an array of full server paths to any |
|
158 | + * EED_Modules used by the addon |
|
159 | + * @type string $shortcode_paths an array of full server paths to folders |
|
160 | + * that contain EES_Shortcodes |
|
161 | + * @type string $widget_paths an array of full server paths to folders |
|
162 | + * that contain WP_Widgets |
|
163 | + * @type string $pue_options |
|
164 | + * @type array $capabilities an array indexed by role name |
|
165 | + * (i.e administrator,author ) and the values |
|
166 | + * are an array of caps to add to the role. |
|
167 | + * 'administrator' => array( |
|
168 | + * 'read_addon', |
|
169 | + * 'edit_addon', |
|
170 | + * etc. |
|
171 | + * ). |
|
172 | + * @type EE_Meta_Capability_Map[] $capability_maps an array of EE_Meta_Capability_Map object |
|
173 | + * for any addons that need to register any |
|
174 | + * special meta mapped capabilities. Should |
|
175 | + * be indexed where the key is the |
|
176 | + * EE_Meta_Capability_Map class name and the |
|
177 | + * values are the arguments sent to the class. |
|
178 | + * @type array $model_paths array of folders containing DB models |
|
179 | + * @see EE_Register_Model |
|
180 | + * @type array $class_paths array of folders containing DB classes |
|
181 | + * @see EE_Register_Model |
|
182 | + * @type array $model_extension_paths array of folders containing DB model |
|
183 | + * extensions |
|
184 | + * @see EE_Register_Model_Extension |
|
185 | + * @type array $class_extension_paths array of folders containing DB class |
|
186 | + * extensions |
|
187 | + * @see EE_Register_Model_Extension |
|
188 | + * @type array message_types { |
|
189 | + * An array of message types with the key as |
|
190 | + * the message type name and the values as |
|
191 | + * below: |
|
192 | + * @type string $mtfilename The filename of the message type being |
|
193 | + * registered. This will be the main |
|
194 | + * EE_{Message Type Name}_message_type class. |
|
195 | + * (eg. EE_Declined_Registration_message_type.class.php) |
|
196 | + * Required. |
|
197 | + * @type array $autoloadpaths An array of paths to add to the messages |
|
198 | + * autoloader for the new message type. |
|
199 | + * Required. |
|
200 | + * @type array $messengers_to_activate_with An array of messengers that this message |
|
201 | + * type should activate with. Each value in |
|
202 | + * the |
|
203 | + * array |
|
204 | + * should match the name property of a |
|
205 | + * EE_messenger. Optional. |
|
206 | + * @type array $messengers_to_validate_with An array of messengers that this message |
|
207 | + * type should validate with. Each value in |
|
208 | + * the |
|
209 | + * array |
|
210 | + * should match the name property of an |
|
211 | + * EE_messenger. |
|
212 | + * Optional. |
|
213 | + * } |
|
214 | + * @type array $custom_post_types |
|
215 | + * @type array $custom_taxonomies |
|
216 | + * @type array $payment_method_paths each element is the folder containing the |
|
217 | + * EE_PMT_Base child class |
|
218 | + * (eg, |
|
219 | + * '/wp-content/plugins/my_plugin/Payomatic/' |
|
220 | + * which contains the files |
|
221 | + * EE_PMT_Payomatic.pm.php) |
|
222 | + * @type array $default_terms |
|
223 | + * @type array $namespace { |
|
224 | + * An array with two items for registering the |
|
225 | + * addon's namespace. (If, for some reason, you |
|
226 | + * require additional namespaces, |
|
227 | + * use EventEspresso\core\Psr4Autoloader::addNamespace() |
|
228 | + * directly) |
|
229 | + * @see EventEspresso\core\Psr4Autoloader::addNamespace() |
|
230 | + * @type string $FQNS the namespace prefix |
|
231 | + * @type string $DIR a base directory for class files in the |
|
232 | + * namespace. |
|
233 | + * } |
|
234 | + * } |
|
235 | + * @return void |
|
236 | + * @throws DomainException |
|
237 | + * @throws EE_Error |
|
238 | + * @throws InvalidArgumentException |
|
239 | + * @throws ReflectionException |
|
240 | + * @throws InvalidDataTypeException |
|
241 | + * @throws InvalidInterfaceException |
|
242 | + */ |
|
243 | + public static function register($addon_name = '', $setup_args = array()) |
|
244 | + { |
|
245 | + // required fields MUST be present, so let's make sure they are. |
|
246 | + EE_Register_Addon::_verify_parameters($addon_name, $setup_args); |
|
247 | + // get class name for addon |
|
248 | + $class_name = EE_Register_Addon::_parse_class_name($addon_name, $setup_args); |
|
249 | + //setup $_settings array from incoming values. |
|
250 | + $addon_settings = EE_Register_Addon::_get_addon_settings($class_name, $setup_args); |
|
251 | + // setup PUE |
|
252 | + EE_Register_Addon::_parse_pue_options($addon_name, $class_name, $setup_args); |
|
253 | + // does this addon work with this version of core or WordPress ? |
|
254 | + if (! EE_Register_Addon::_addon_is_compatible($addon_name, $addon_settings)) { |
|
255 | + return; |
|
256 | + } |
|
257 | + // register namespaces |
|
258 | + EE_Register_Addon::_setup_namespaces($addon_settings); |
|
259 | + // check if this is an activation request |
|
260 | + if (EE_Register_Addon::_addon_activation($addon_name, $addon_settings)) { |
|
261 | + // dont bother setting up the rest of the addon atm |
|
262 | + return; |
|
263 | + } |
|
264 | + // we need cars |
|
265 | + EE_Register_Addon::_setup_autoloaders($addon_name); |
|
266 | + // register new models and extensions |
|
267 | + EE_Register_Addon::_register_models_and_extensions($addon_name); |
|
268 | + // setup DMS |
|
269 | + EE_Register_Addon::_register_data_migration_scripts($addon_name); |
|
270 | + // if config_class is present let's register config. |
|
271 | + EE_Register_Addon::_register_config($addon_name); |
|
272 | + // register admin pages |
|
273 | + EE_Register_Addon::_register_admin_pages($addon_name); |
|
274 | + // add to list of modules to be registered |
|
275 | + EE_Register_Addon::_register_modules($addon_name); |
|
276 | + // add to list of shortcodes to be registered |
|
277 | + EE_Register_Addon::_register_shortcodes($addon_name); |
|
278 | + // add to list of widgets to be registered |
|
279 | + EE_Register_Addon::_register_widgets($addon_name); |
|
280 | + // register capability related stuff. |
|
281 | + EE_Register_Addon::_register_capabilities($addon_name); |
|
282 | + // any message type to register? |
|
283 | + EE_Register_Addon::_register_message_types($addon_name); |
|
284 | + // any custom post type/ custom capabilities or default terms to register |
|
285 | + EE_Register_Addon::_register_custom_post_types($addon_name); |
|
286 | + // and any payment methods |
|
287 | + EE_Register_Addon::_register_payment_methods($addon_name); |
|
288 | + // load and instantiate main addon class |
|
289 | + $addon = EE_Register_Addon::_load_and_init_addon_class($addon_name); |
|
290 | + //delay calling after_registration hook on each addon until after all add-ons have been registered. |
|
291 | + add_action('AHEE__EE_System__load_espresso_addons__complete', array($addon, 'after_registration'), 999); |
|
292 | + } |
|
293 | 293 | |
294 | 294 | |
295 | - /** |
|
296 | - * @param string $addon_name |
|
297 | - * @param array $setup_args |
|
298 | - * @return void |
|
299 | - * @throws EE_Error |
|
300 | - */ |
|
301 | - private static function _verify_parameters($addon_name, array $setup_args) |
|
302 | - { |
|
303 | - // required fields MUST be present, so let's make sure they are. |
|
304 | - if (empty($addon_name) || ! is_array($setup_args)) { |
|
305 | - throw new EE_Error( |
|
306 | - __( |
|
307 | - 'In order to register an EE_Addon with EE_Register_Addon::register(), you must include the "addon_name" (the name of the addon), and an array of arguments.', |
|
308 | - 'event_espresso' |
|
309 | - ) |
|
310 | - ); |
|
311 | - } |
|
312 | - if (! isset($setup_args['main_file_path']) || empty($setup_args['main_file_path'])) { |
|
313 | - throw new EE_Error( |
|
314 | - sprintf( |
|
315 | - __( |
|
316 | - 'When registering an addon, you didn\'t provide the "main_file_path", which is the full path to the main file loaded directly by Wordpress. You only provided %s', |
|
317 | - 'event_espresso' |
|
318 | - ), |
|
319 | - implode(',', array_keys($setup_args)) |
|
320 | - ) |
|
321 | - ); |
|
322 | - } |
|
323 | - // check that addon has not already been registered with that name |
|
324 | - if (isset(self::$_settings[ $addon_name ]) && ! did_action('activate_plugin')) { |
|
325 | - throw new EE_Error( |
|
326 | - sprintf( |
|
327 | - __( |
|
328 | - 'An EE_Addon with the name "%s" has already been registered and each EE_Addon requires a unique name.', |
|
329 | - 'event_espresso' |
|
330 | - ), |
|
331 | - $addon_name |
|
332 | - ) |
|
333 | - ); |
|
334 | - } |
|
335 | - } |
|
295 | + /** |
|
296 | + * @param string $addon_name |
|
297 | + * @param array $setup_args |
|
298 | + * @return void |
|
299 | + * @throws EE_Error |
|
300 | + */ |
|
301 | + private static function _verify_parameters($addon_name, array $setup_args) |
|
302 | + { |
|
303 | + // required fields MUST be present, so let's make sure they are. |
|
304 | + if (empty($addon_name) || ! is_array($setup_args)) { |
|
305 | + throw new EE_Error( |
|
306 | + __( |
|
307 | + 'In order to register an EE_Addon with EE_Register_Addon::register(), you must include the "addon_name" (the name of the addon), and an array of arguments.', |
|
308 | + 'event_espresso' |
|
309 | + ) |
|
310 | + ); |
|
311 | + } |
|
312 | + if (! isset($setup_args['main_file_path']) || empty($setup_args['main_file_path'])) { |
|
313 | + throw new EE_Error( |
|
314 | + sprintf( |
|
315 | + __( |
|
316 | + 'When registering an addon, you didn\'t provide the "main_file_path", which is the full path to the main file loaded directly by Wordpress. You only provided %s', |
|
317 | + 'event_espresso' |
|
318 | + ), |
|
319 | + implode(',', array_keys($setup_args)) |
|
320 | + ) |
|
321 | + ); |
|
322 | + } |
|
323 | + // check that addon has not already been registered with that name |
|
324 | + if (isset(self::$_settings[ $addon_name ]) && ! did_action('activate_plugin')) { |
|
325 | + throw new EE_Error( |
|
326 | + sprintf( |
|
327 | + __( |
|
328 | + 'An EE_Addon with the name "%s" has already been registered and each EE_Addon requires a unique name.', |
|
329 | + 'event_espresso' |
|
330 | + ), |
|
331 | + $addon_name |
|
332 | + ) |
|
333 | + ); |
|
334 | + } |
|
335 | + } |
|
336 | 336 | |
337 | 337 | |
338 | - /** |
|
339 | - * @param string $addon_name |
|
340 | - * @param array $setup_args |
|
341 | - * @return string |
|
342 | - */ |
|
343 | - private static function _parse_class_name($addon_name, array $setup_args) |
|
344 | - { |
|
345 | - if (empty($setup_args['class_name'])) { |
|
346 | - // generate one by first separating name with spaces |
|
347 | - $class_name = str_replace(array('-', '_'), ' ', trim($addon_name)); |
|
348 | - //capitalize, then replace spaces with underscores |
|
349 | - $class_name = str_replace(' ', '_', ucwords($class_name)); |
|
350 | - } else { |
|
351 | - $class_name = $setup_args['class_name']; |
|
352 | - } |
|
353 | - // check if classname is fully qualified or is a legacy classname already prefixed with 'EE_' |
|
354 | - return strpos($class_name, '\\') || strpos($class_name, 'EE_') === 0 |
|
355 | - ? $class_name |
|
356 | - : 'EE_' . $class_name; |
|
357 | - } |
|
338 | + /** |
|
339 | + * @param string $addon_name |
|
340 | + * @param array $setup_args |
|
341 | + * @return string |
|
342 | + */ |
|
343 | + private static function _parse_class_name($addon_name, array $setup_args) |
|
344 | + { |
|
345 | + if (empty($setup_args['class_name'])) { |
|
346 | + // generate one by first separating name with spaces |
|
347 | + $class_name = str_replace(array('-', '_'), ' ', trim($addon_name)); |
|
348 | + //capitalize, then replace spaces with underscores |
|
349 | + $class_name = str_replace(' ', '_', ucwords($class_name)); |
|
350 | + } else { |
|
351 | + $class_name = $setup_args['class_name']; |
|
352 | + } |
|
353 | + // check if classname is fully qualified or is a legacy classname already prefixed with 'EE_' |
|
354 | + return strpos($class_name, '\\') || strpos($class_name, 'EE_') === 0 |
|
355 | + ? $class_name |
|
356 | + : 'EE_' . $class_name; |
|
357 | + } |
|
358 | 358 | |
359 | 359 | |
360 | - /** |
|
361 | - * @param string $class_name |
|
362 | - * @param array $setup_args |
|
363 | - * @return array |
|
364 | - */ |
|
365 | - private static function _get_addon_settings($class_name, array $setup_args) |
|
366 | - { |
|
367 | - //setup $_settings array from incoming values. |
|
368 | - $addon_settings = array( |
|
369 | - // generated from the addon name, changes something like "calendar" to "EE_Calendar" |
|
370 | - 'class_name' => $class_name, |
|
371 | - // the addon slug for use in URLs, etc |
|
372 | - 'plugin_slug' => isset($setup_args['plugin_slug']) |
|
373 | - ? (string) $setup_args['plugin_slug'] |
|
374 | - : '', |
|
375 | - // page slug to be used when generating the "Settings" link on the WP plugin page |
|
376 | - 'plugin_action_slug' => isset($setup_args['plugin_action_slug']) |
|
377 | - ? (string) $setup_args['plugin_action_slug'] |
|
378 | - : '', |
|
379 | - // the "software" version for the addon |
|
380 | - 'version' => isset($setup_args['version']) |
|
381 | - ? (string) $setup_args['version'] |
|
382 | - : '', |
|
383 | - // the minimum version of EE Core that the addon will work with |
|
384 | - 'min_core_version' => isset($setup_args['min_core_version']) |
|
385 | - ? (string) $setup_args['min_core_version'] |
|
386 | - : '', |
|
387 | - // the minimum version of WordPress that the addon will work with |
|
388 | - 'min_wp_version' => isset($setup_args['min_wp_version']) |
|
389 | - ? (string) $setup_args['min_wp_version'] |
|
390 | - : EE_MIN_WP_VER_REQUIRED, |
|
391 | - // full server path to main file (file loaded directly by WP) |
|
392 | - 'main_file_path' => isset($setup_args['main_file_path']) |
|
393 | - ? (string) $setup_args['main_file_path'] |
|
394 | - : '', |
|
395 | - // Fully Qualified Class Name for the addon's Domain class |
|
396 | - 'domain_fqcn' => isset($setup_args['domain_fqcn']) |
|
397 | - ? (string) $setup_args['domain_fqcn'] |
|
398 | - : '', |
|
399 | - // path to folder containing files for integrating with the EE core admin and/or setting up EE admin pages |
|
400 | - 'admin_path' => isset($setup_args['admin_path']) |
|
401 | - ? (string) $setup_args['admin_path'] : '', |
|
402 | - // a method to be called when the EE Admin is first invoked, can be used for hooking into any admin page |
|
403 | - 'admin_callback' => isset($setup_args['admin_callback']) |
|
404 | - ? (string) $setup_args['admin_callback'] |
|
405 | - : '', |
|
406 | - // the section name for this addon's configuration settings section (defaults to "addons") |
|
407 | - 'config_section' => isset($setup_args['config_section']) |
|
408 | - ? (string) $setup_args['config_section'] |
|
409 | - : 'addons', |
|
410 | - // the class name for this addon's configuration settings object |
|
411 | - 'config_class' => isset($setup_args['config_class']) |
|
412 | - ? (string) $setup_args['config_class'] : '', |
|
413 | - //the name given to the config for this addons' configuration settings object (optional) |
|
414 | - 'config_name' => isset($setup_args['config_name']) |
|
415 | - ? (string) $setup_args['config_name'] : '', |
|
416 | - // an array of "class names" => "full server paths" for any classes that might be invoked by the addon |
|
417 | - 'autoloader_paths' => isset($setup_args['autoloader_paths']) |
|
418 | - ? (array) $setup_args['autoloader_paths'] |
|
419 | - : array(), |
|
420 | - // an array of "full server paths" for any folders containing classes that might be invoked by the addon |
|
421 | - 'autoloader_folders' => isset($setup_args['autoloader_folders']) |
|
422 | - ? (array) $setup_args['autoloader_folders'] |
|
423 | - : array(), |
|
424 | - // array of full server paths to any EE_DMS data migration scripts used by the addon |
|
425 | - 'dms_paths' => isset($setup_args['dms_paths']) |
|
426 | - ? (array) $setup_args['dms_paths'] |
|
427 | - : array(), |
|
428 | - // array of full server paths to any EED_Modules used by the addon |
|
429 | - 'module_paths' => isset($setup_args['module_paths']) |
|
430 | - ? (array) $setup_args['module_paths'] |
|
431 | - : array(), |
|
432 | - // array of full server paths to any EES_Shortcodes used by the addon |
|
433 | - 'shortcode_paths' => isset($setup_args['shortcode_paths']) |
|
434 | - ? (array) $setup_args['shortcode_paths'] |
|
435 | - : array(), |
|
436 | - 'shortcode_fqcns' => isset($setup_args['shortcode_fqcns']) |
|
437 | - ? (array) $setup_args['shortcode_fqcns'] |
|
438 | - : array(), |
|
439 | - // array of full server paths to any WP_Widgets used by the addon |
|
440 | - 'widget_paths' => isset($setup_args['widget_paths']) |
|
441 | - ? (array) $setup_args['widget_paths'] |
|
442 | - : array(), |
|
443 | - // array of PUE options used by the addon |
|
444 | - 'pue_options' => isset($setup_args['pue_options']) |
|
445 | - ? (array) $setup_args['pue_options'] |
|
446 | - : array(), |
|
447 | - 'message_types' => isset($setup_args['message_types']) |
|
448 | - ? (array) $setup_args['message_types'] |
|
449 | - : array(), |
|
450 | - 'capabilities' => isset($setup_args['capabilities']) |
|
451 | - ? (array) $setup_args['capabilities'] |
|
452 | - : array(), |
|
453 | - 'capability_maps' => isset($setup_args['capability_maps']) |
|
454 | - ? (array) $setup_args['capability_maps'] |
|
455 | - : array(), |
|
456 | - 'model_paths' => isset($setup_args['model_paths']) |
|
457 | - ? (array) $setup_args['model_paths'] |
|
458 | - : array(), |
|
459 | - 'class_paths' => isset($setup_args['class_paths']) |
|
460 | - ? (array) $setup_args['class_paths'] |
|
461 | - : array(), |
|
462 | - 'model_extension_paths' => isset($setup_args['model_extension_paths']) |
|
463 | - ? (array) $setup_args['model_extension_paths'] |
|
464 | - : array(), |
|
465 | - 'class_extension_paths' => isset($setup_args['class_extension_paths']) |
|
466 | - ? (array) $setup_args['class_extension_paths'] |
|
467 | - : array(), |
|
468 | - 'custom_post_types' => isset($setup_args['custom_post_types']) |
|
469 | - ? (array) $setup_args['custom_post_types'] |
|
470 | - : array(), |
|
471 | - 'custom_taxonomies' => isset($setup_args['custom_taxonomies']) |
|
472 | - ? (array) $setup_args['custom_taxonomies'] |
|
473 | - : array(), |
|
474 | - 'payment_method_paths' => isset($setup_args['payment_method_paths']) |
|
475 | - ? (array) $setup_args['payment_method_paths'] |
|
476 | - : array(), |
|
477 | - 'default_terms' => isset($setup_args['default_terms']) |
|
478 | - ? (array) $setup_args['default_terms'] |
|
479 | - : array(), |
|
480 | - // if not empty, inserts a new table row after this plugin's row on the WP Plugins page |
|
481 | - // that can be used for adding upgrading/marketing info |
|
482 | - 'plugins_page_row' => isset($setup_args['plugins_page_row']) |
|
483 | - ? $setup_args['plugins_page_row'] |
|
484 | - : '', |
|
485 | - 'namespace' => isset( |
|
486 | - $setup_args['namespace']['FQNS'], |
|
487 | - $setup_args['namespace']['DIR'] |
|
488 | - ) |
|
489 | - ? (array) $setup_args['namespace'] |
|
490 | - : array(), |
|
491 | - ); |
|
492 | - // if plugin_action_slug is NOT set, but an admin page path IS set, |
|
493 | - // then let's just use the plugin_slug since that will be used for linking to the admin page |
|
494 | - $addon_settings['plugin_action_slug'] = empty($addon_settings['plugin_action_slug']) |
|
495 | - && ! empty($addon_settings['admin_path']) |
|
496 | - ? $addon_settings['plugin_slug'] |
|
497 | - : $addon_settings['plugin_action_slug']; |
|
498 | - // full server path to main file (file loaded directly by WP) |
|
499 | - $addon_settings['plugin_basename'] = plugin_basename($addon_settings['main_file_path']); |
|
500 | - return $addon_settings; |
|
501 | - } |
|
360 | + /** |
|
361 | + * @param string $class_name |
|
362 | + * @param array $setup_args |
|
363 | + * @return array |
|
364 | + */ |
|
365 | + private static function _get_addon_settings($class_name, array $setup_args) |
|
366 | + { |
|
367 | + //setup $_settings array from incoming values. |
|
368 | + $addon_settings = array( |
|
369 | + // generated from the addon name, changes something like "calendar" to "EE_Calendar" |
|
370 | + 'class_name' => $class_name, |
|
371 | + // the addon slug for use in URLs, etc |
|
372 | + 'plugin_slug' => isset($setup_args['plugin_slug']) |
|
373 | + ? (string) $setup_args['plugin_slug'] |
|
374 | + : '', |
|
375 | + // page slug to be used when generating the "Settings" link on the WP plugin page |
|
376 | + 'plugin_action_slug' => isset($setup_args['plugin_action_slug']) |
|
377 | + ? (string) $setup_args['plugin_action_slug'] |
|
378 | + : '', |
|
379 | + // the "software" version for the addon |
|
380 | + 'version' => isset($setup_args['version']) |
|
381 | + ? (string) $setup_args['version'] |
|
382 | + : '', |
|
383 | + // the minimum version of EE Core that the addon will work with |
|
384 | + 'min_core_version' => isset($setup_args['min_core_version']) |
|
385 | + ? (string) $setup_args['min_core_version'] |
|
386 | + : '', |
|
387 | + // the minimum version of WordPress that the addon will work with |
|
388 | + 'min_wp_version' => isset($setup_args['min_wp_version']) |
|
389 | + ? (string) $setup_args['min_wp_version'] |
|
390 | + : EE_MIN_WP_VER_REQUIRED, |
|
391 | + // full server path to main file (file loaded directly by WP) |
|
392 | + 'main_file_path' => isset($setup_args['main_file_path']) |
|
393 | + ? (string) $setup_args['main_file_path'] |
|
394 | + : '', |
|
395 | + // Fully Qualified Class Name for the addon's Domain class |
|
396 | + 'domain_fqcn' => isset($setup_args['domain_fqcn']) |
|
397 | + ? (string) $setup_args['domain_fqcn'] |
|
398 | + : '', |
|
399 | + // path to folder containing files for integrating with the EE core admin and/or setting up EE admin pages |
|
400 | + 'admin_path' => isset($setup_args['admin_path']) |
|
401 | + ? (string) $setup_args['admin_path'] : '', |
|
402 | + // a method to be called when the EE Admin is first invoked, can be used for hooking into any admin page |
|
403 | + 'admin_callback' => isset($setup_args['admin_callback']) |
|
404 | + ? (string) $setup_args['admin_callback'] |
|
405 | + : '', |
|
406 | + // the section name for this addon's configuration settings section (defaults to "addons") |
|
407 | + 'config_section' => isset($setup_args['config_section']) |
|
408 | + ? (string) $setup_args['config_section'] |
|
409 | + : 'addons', |
|
410 | + // the class name for this addon's configuration settings object |
|
411 | + 'config_class' => isset($setup_args['config_class']) |
|
412 | + ? (string) $setup_args['config_class'] : '', |
|
413 | + //the name given to the config for this addons' configuration settings object (optional) |
|
414 | + 'config_name' => isset($setup_args['config_name']) |
|
415 | + ? (string) $setup_args['config_name'] : '', |
|
416 | + // an array of "class names" => "full server paths" for any classes that might be invoked by the addon |
|
417 | + 'autoloader_paths' => isset($setup_args['autoloader_paths']) |
|
418 | + ? (array) $setup_args['autoloader_paths'] |
|
419 | + : array(), |
|
420 | + // an array of "full server paths" for any folders containing classes that might be invoked by the addon |
|
421 | + 'autoloader_folders' => isset($setup_args['autoloader_folders']) |
|
422 | + ? (array) $setup_args['autoloader_folders'] |
|
423 | + : array(), |
|
424 | + // array of full server paths to any EE_DMS data migration scripts used by the addon |
|
425 | + 'dms_paths' => isset($setup_args['dms_paths']) |
|
426 | + ? (array) $setup_args['dms_paths'] |
|
427 | + : array(), |
|
428 | + // array of full server paths to any EED_Modules used by the addon |
|
429 | + 'module_paths' => isset($setup_args['module_paths']) |
|
430 | + ? (array) $setup_args['module_paths'] |
|
431 | + : array(), |
|
432 | + // array of full server paths to any EES_Shortcodes used by the addon |
|
433 | + 'shortcode_paths' => isset($setup_args['shortcode_paths']) |
|
434 | + ? (array) $setup_args['shortcode_paths'] |
|
435 | + : array(), |
|
436 | + 'shortcode_fqcns' => isset($setup_args['shortcode_fqcns']) |
|
437 | + ? (array) $setup_args['shortcode_fqcns'] |
|
438 | + : array(), |
|
439 | + // array of full server paths to any WP_Widgets used by the addon |
|
440 | + 'widget_paths' => isset($setup_args['widget_paths']) |
|
441 | + ? (array) $setup_args['widget_paths'] |
|
442 | + : array(), |
|
443 | + // array of PUE options used by the addon |
|
444 | + 'pue_options' => isset($setup_args['pue_options']) |
|
445 | + ? (array) $setup_args['pue_options'] |
|
446 | + : array(), |
|
447 | + 'message_types' => isset($setup_args['message_types']) |
|
448 | + ? (array) $setup_args['message_types'] |
|
449 | + : array(), |
|
450 | + 'capabilities' => isset($setup_args['capabilities']) |
|
451 | + ? (array) $setup_args['capabilities'] |
|
452 | + : array(), |
|
453 | + 'capability_maps' => isset($setup_args['capability_maps']) |
|
454 | + ? (array) $setup_args['capability_maps'] |
|
455 | + : array(), |
|
456 | + 'model_paths' => isset($setup_args['model_paths']) |
|
457 | + ? (array) $setup_args['model_paths'] |
|
458 | + : array(), |
|
459 | + 'class_paths' => isset($setup_args['class_paths']) |
|
460 | + ? (array) $setup_args['class_paths'] |
|
461 | + : array(), |
|
462 | + 'model_extension_paths' => isset($setup_args['model_extension_paths']) |
|
463 | + ? (array) $setup_args['model_extension_paths'] |
|
464 | + : array(), |
|
465 | + 'class_extension_paths' => isset($setup_args['class_extension_paths']) |
|
466 | + ? (array) $setup_args['class_extension_paths'] |
|
467 | + : array(), |
|
468 | + 'custom_post_types' => isset($setup_args['custom_post_types']) |
|
469 | + ? (array) $setup_args['custom_post_types'] |
|
470 | + : array(), |
|
471 | + 'custom_taxonomies' => isset($setup_args['custom_taxonomies']) |
|
472 | + ? (array) $setup_args['custom_taxonomies'] |
|
473 | + : array(), |
|
474 | + 'payment_method_paths' => isset($setup_args['payment_method_paths']) |
|
475 | + ? (array) $setup_args['payment_method_paths'] |
|
476 | + : array(), |
|
477 | + 'default_terms' => isset($setup_args['default_terms']) |
|
478 | + ? (array) $setup_args['default_terms'] |
|
479 | + : array(), |
|
480 | + // if not empty, inserts a new table row after this plugin's row on the WP Plugins page |
|
481 | + // that can be used for adding upgrading/marketing info |
|
482 | + 'plugins_page_row' => isset($setup_args['plugins_page_row']) |
|
483 | + ? $setup_args['plugins_page_row'] |
|
484 | + : '', |
|
485 | + 'namespace' => isset( |
|
486 | + $setup_args['namespace']['FQNS'], |
|
487 | + $setup_args['namespace']['DIR'] |
|
488 | + ) |
|
489 | + ? (array) $setup_args['namespace'] |
|
490 | + : array(), |
|
491 | + ); |
|
492 | + // if plugin_action_slug is NOT set, but an admin page path IS set, |
|
493 | + // then let's just use the plugin_slug since that will be used for linking to the admin page |
|
494 | + $addon_settings['plugin_action_slug'] = empty($addon_settings['plugin_action_slug']) |
|
495 | + && ! empty($addon_settings['admin_path']) |
|
496 | + ? $addon_settings['plugin_slug'] |
|
497 | + : $addon_settings['plugin_action_slug']; |
|
498 | + // full server path to main file (file loaded directly by WP) |
|
499 | + $addon_settings['plugin_basename'] = plugin_basename($addon_settings['main_file_path']); |
|
500 | + return $addon_settings; |
|
501 | + } |
|
502 | 502 | |
503 | 503 | |
504 | - /** |
|
505 | - * @param string $addon_name |
|
506 | - * @param array $addon_settings |
|
507 | - * @return boolean |
|
508 | - */ |
|
509 | - private static function _addon_is_compatible($addon_name, array $addon_settings) |
|
510 | - { |
|
511 | - global $wp_version; |
|
512 | - $incompatibility_message = ''; |
|
513 | - //check whether this addon version is compatible with EE core |
|
514 | - if ( |
|
515 | - isset(EE_Register_Addon::$_incompatible_addons[ $addon_name ]) |
|
516 | - && ! self::_meets_min_core_version_requirement( |
|
517 | - EE_Register_Addon::$_incompatible_addons[ $addon_name ], |
|
518 | - $addon_settings['version'] |
|
519 | - ) |
|
520 | - ) { |
|
521 | - $incompatibility_message = sprintf( |
|
522 | - __( |
|
523 | - '%4$sIMPORTANT!%5$sThe Event Espresso "%1$s" addon is not compatible with this version of Event Espresso.%2$sPlease upgrade your "%1$s" addon to version %3$s or newer to resolve this issue.' |
|
524 | - ), |
|
525 | - $addon_name, |
|
526 | - '<br />', |
|
527 | - EE_Register_Addon::$_incompatible_addons[ $addon_name ], |
|
528 | - '<span style="font-weight: bold; color: #D54E21;">', |
|
529 | - '</span><br />' |
|
530 | - ); |
|
531 | - } elseif ( |
|
532 | - ! self::_meets_min_core_version_requirement($addon_settings['min_core_version'], espresso_version()) |
|
533 | - ) { |
|
534 | - $incompatibility_message = sprintf( |
|
535 | - __( |
|
536 | - '%5$sIMPORTANT!%6$sThe Event Espresso "%1$s" addon requires Event Espresso Core version "%2$s" or higher in order to run.%4$sYour version of Event Espresso Core is currently at "%3$s". Please upgrade Event Espresso Core first and then re-activate "%1$s".', |
|
537 | - 'event_espresso' |
|
538 | - ), |
|
539 | - $addon_name, |
|
540 | - self::_effective_version($addon_settings['min_core_version']), |
|
541 | - self::_effective_version(espresso_version()), |
|
542 | - '<br />', |
|
543 | - '<span style="font-weight: bold; color: #D54E21;">', |
|
544 | - '</span><br />' |
|
545 | - ); |
|
546 | - } elseif (version_compare($wp_version, $addon_settings['min_wp_version'], '<')) { |
|
547 | - $incompatibility_message = sprintf( |
|
548 | - __( |
|
549 | - '%4$sIMPORTANT!%5$sThe Event Espresso "%1$s" addon requires WordPress version "%2$s" or greater.%3$sPlease update your version of WordPress to use the "%1$s" addon and to keep your site secure.', |
|
550 | - 'event_espresso' |
|
551 | - ), |
|
552 | - $addon_name, |
|
553 | - $addon_settings['min_wp_version'], |
|
554 | - '<br />', |
|
555 | - '<span style="font-weight: bold; color: #D54E21;">', |
|
556 | - '</span><br />' |
|
557 | - ); |
|
558 | - } |
|
559 | - if (! empty($incompatibility_message)) { |
|
560 | - // remove 'activate' from the REQUEST |
|
561 | - // so WP doesn't erroneously tell the user the plugin activated fine when it didn't |
|
562 | - unset($_GET['activate'], $_REQUEST['activate']); |
|
563 | - if (current_user_can('activate_plugins')) { |
|
564 | - // show an error message indicating the plugin didn't activate properly |
|
565 | - EE_Error::add_error($incompatibility_message, __FILE__, __FUNCTION__, __LINE__); |
|
566 | - } |
|
567 | - // BAIL FROM THE ADDON REGISTRATION PROCESS |
|
568 | - return false; |
|
569 | - } |
|
570 | - // addon IS compatible |
|
571 | - return true; |
|
572 | - } |
|
504 | + /** |
|
505 | + * @param string $addon_name |
|
506 | + * @param array $addon_settings |
|
507 | + * @return boolean |
|
508 | + */ |
|
509 | + private static function _addon_is_compatible($addon_name, array $addon_settings) |
|
510 | + { |
|
511 | + global $wp_version; |
|
512 | + $incompatibility_message = ''; |
|
513 | + //check whether this addon version is compatible with EE core |
|
514 | + if ( |
|
515 | + isset(EE_Register_Addon::$_incompatible_addons[ $addon_name ]) |
|
516 | + && ! self::_meets_min_core_version_requirement( |
|
517 | + EE_Register_Addon::$_incompatible_addons[ $addon_name ], |
|
518 | + $addon_settings['version'] |
|
519 | + ) |
|
520 | + ) { |
|
521 | + $incompatibility_message = sprintf( |
|
522 | + __( |
|
523 | + '%4$sIMPORTANT!%5$sThe Event Espresso "%1$s" addon is not compatible with this version of Event Espresso.%2$sPlease upgrade your "%1$s" addon to version %3$s or newer to resolve this issue.' |
|
524 | + ), |
|
525 | + $addon_name, |
|
526 | + '<br />', |
|
527 | + EE_Register_Addon::$_incompatible_addons[ $addon_name ], |
|
528 | + '<span style="font-weight: bold; color: #D54E21;">', |
|
529 | + '</span><br />' |
|
530 | + ); |
|
531 | + } elseif ( |
|
532 | + ! self::_meets_min_core_version_requirement($addon_settings['min_core_version'], espresso_version()) |
|
533 | + ) { |
|
534 | + $incompatibility_message = sprintf( |
|
535 | + __( |
|
536 | + '%5$sIMPORTANT!%6$sThe Event Espresso "%1$s" addon requires Event Espresso Core version "%2$s" or higher in order to run.%4$sYour version of Event Espresso Core is currently at "%3$s". Please upgrade Event Espresso Core first and then re-activate "%1$s".', |
|
537 | + 'event_espresso' |
|
538 | + ), |
|
539 | + $addon_name, |
|
540 | + self::_effective_version($addon_settings['min_core_version']), |
|
541 | + self::_effective_version(espresso_version()), |
|
542 | + '<br />', |
|
543 | + '<span style="font-weight: bold; color: #D54E21;">', |
|
544 | + '</span><br />' |
|
545 | + ); |
|
546 | + } elseif (version_compare($wp_version, $addon_settings['min_wp_version'], '<')) { |
|
547 | + $incompatibility_message = sprintf( |
|
548 | + __( |
|
549 | + '%4$sIMPORTANT!%5$sThe Event Espresso "%1$s" addon requires WordPress version "%2$s" or greater.%3$sPlease update your version of WordPress to use the "%1$s" addon and to keep your site secure.', |
|
550 | + 'event_espresso' |
|
551 | + ), |
|
552 | + $addon_name, |
|
553 | + $addon_settings['min_wp_version'], |
|
554 | + '<br />', |
|
555 | + '<span style="font-weight: bold; color: #D54E21;">', |
|
556 | + '</span><br />' |
|
557 | + ); |
|
558 | + } |
|
559 | + if (! empty($incompatibility_message)) { |
|
560 | + // remove 'activate' from the REQUEST |
|
561 | + // so WP doesn't erroneously tell the user the plugin activated fine when it didn't |
|
562 | + unset($_GET['activate'], $_REQUEST['activate']); |
|
563 | + if (current_user_can('activate_plugins')) { |
|
564 | + // show an error message indicating the plugin didn't activate properly |
|
565 | + EE_Error::add_error($incompatibility_message, __FILE__, __FUNCTION__, __LINE__); |
|
566 | + } |
|
567 | + // BAIL FROM THE ADDON REGISTRATION PROCESS |
|
568 | + return false; |
|
569 | + } |
|
570 | + // addon IS compatible |
|
571 | + return true; |
|
572 | + } |
|
573 | 573 | |
574 | 574 | |
575 | - /** |
|
576 | - * if plugin update engine is being used for auto-updates, |
|
577 | - * then let's set that up now before going any further so that ALL addons can be updated |
|
578 | - * (not needed if PUE is not being used) |
|
579 | - * |
|
580 | - * @param string $addon_name |
|
581 | - * @param string $class_name |
|
582 | - * @param array $setup_args |
|
583 | - * @return void |
|
584 | - */ |
|
585 | - private static function _parse_pue_options($addon_name, $class_name, array $setup_args) |
|
586 | - { |
|
587 | - if (! empty($setup_args['pue_options'])) { |
|
588 | - self::$_settings[ $addon_name ]['pue_options'] = array( |
|
589 | - 'pue_plugin_slug' => isset($setup_args['pue_options']['pue_plugin_slug']) |
|
590 | - ? (string) $setup_args['pue_options']['pue_plugin_slug'] |
|
591 | - : 'espresso_' . strtolower($class_name), |
|
592 | - 'plugin_basename' => isset($setup_args['pue_options']['plugin_basename']) |
|
593 | - ? (string) $setup_args['pue_options']['plugin_basename'] |
|
594 | - : plugin_basename($setup_args['main_file_path']), |
|
595 | - 'checkPeriod' => isset($setup_args['pue_options']['checkPeriod']) |
|
596 | - ? (string) $setup_args['pue_options']['checkPeriod'] |
|
597 | - : '24', |
|
598 | - 'use_wp_update' => isset($setup_args['pue_options']['use_wp_update']) |
|
599 | - ? (string) $setup_args['pue_options']['use_wp_update'] |
|
600 | - : false, |
|
601 | - ); |
|
602 | - add_action( |
|
603 | - 'AHEE__EE_System__brew_espresso__after_pue_init', |
|
604 | - array('EE_Register_Addon', 'load_pue_update') |
|
605 | - ); |
|
606 | - } |
|
607 | - } |
|
575 | + /** |
|
576 | + * if plugin update engine is being used for auto-updates, |
|
577 | + * then let's set that up now before going any further so that ALL addons can be updated |
|
578 | + * (not needed if PUE is not being used) |
|
579 | + * |
|
580 | + * @param string $addon_name |
|
581 | + * @param string $class_name |
|
582 | + * @param array $setup_args |
|
583 | + * @return void |
|
584 | + */ |
|
585 | + private static function _parse_pue_options($addon_name, $class_name, array $setup_args) |
|
586 | + { |
|
587 | + if (! empty($setup_args['pue_options'])) { |
|
588 | + self::$_settings[ $addon_name ]['pue_options'] = array( |
|
589 | + 'pue_plugin_slug' => isset($setup_args['pue_options']['pue_plugin_slug']) |
|
590 | + ? (string) $setup_args['pue_options']['pue_plugin_slug'] |
|
591 | + : 'espresso_' . strtolower($class_name), |
|
592 | + 'plugin_basename' => isset($setup_args['pue_options']['plugin_basename']) |
|
593 | + ? (string) $setup_args['pue_options']['plugin_basename'] |
|
594 | + : plugin_basename($setup_args['main_file_path']), |
|
595 | + 'checkPeriod' => isset($setup_args['pue_options']['checkPeriod']) |
|
596 | + ? (string) $setup_args['pue_options']['checkPeriod'] |
|
597 | + : '24', |
|
598 | + 'use_wp_update' => isset($setup_args['pue_options']['use_wp_update']) |
|
599 | + ? (string) $setup_args['pue_options']['use_wp_update'] |
|
600 | + : false, |
|
601 | + ); |
|
602 | + add_action( |
|
603 | + 'AHEE__EE_System__brew_espresso__after_pue_init', |
|
604 | + array('EE_Register_Addon', 'load_pue_update') |
|
605 | + ); |
|
606 | + } |
|
607 | + } |
|
608 | 608 | |
609 | 609 | |
610 | - /** |
|
611 | - * register namespaces right away before any other files or classes get loaded, but AFTER the version checks |
|
612 | - * |
|
613 | - * @param array $addon_settings |
|
614 | - * @return void |
|
615 | - */ |
|
616 | - private static function _setup_namespaces(array $addon_settings) |
|
617 | - { |
|
618 | - // |
|
619 | - if ( |
|
620 | - isset( |
|
621 | - $addon_settings['namespace']['FQNS'], |
|
622 | - $addon_settings['namespace']['DIR'] |
|
623 | - ) |
|
624 | - ) { |
|
625 | - EE_Psr4AutoloaderInit::psr4_loader()->addNamespace( |
|
626 | - $addon_settings['namespace']['FQNS'], |
|
627 | - $addon_settings['namespace']['DIR'] |
|
628 | - ); |
|
629 | - } |
|
630 | - } |
|
610 | + /** |
|
611 | + * register namespaces right away before any other files or classes get loaded, but AFTER the version checks |
|
612 | + * |
|
613 | + * @param array $addon_settings |
|
614 | + * @return void |
|
615 | + */ |
|
616 | + private static function _setup_namespaces(array $addon_settings) |
|
617 | + { |
|
618 | + // |
|
619 | + if ( |
|
620 | + isset( |
|
621 | + $addon_settings['namespace']['FQNS'], |
|
622 | + $addon_settings['namespace']['DIR'] |
|
623 | + ) |
|
624 | + ) { |
|
625 | + EE_Psr4AutoloaderInit::psr4_loader()->addNamespace( |
|
626 | + $addon_settings['namespace']['FQNS'], |
|
627 | + $addon_settings['namespace']['DIR'] |
|
628 | + ); |
|
629 | + } |
|
630 | + } |
|
631 | 631 | |
632 | 632 | |
633 | - /** |
|
634 | - * @param string $addon_name |
|
635 | - * @param array $addon_settings |
|
636 | - * @return bool |
|
637 | - * @throws EE_Error |
|
638 | - * @throws InvalidArgumentException |
|
639 | - * @throws ReflectionException |
|
640 | - * @throws InvalidDataTypeException |
|
641 | - * @throws InvalidInterfaceException |
|
642 | - */ |
|
643 | - private static function _addon_activation($addon_name, array $addon_settings) |
|
644 | - { |
|
645 | - // this is an activation request |
|
646 | - if (did_action('activate_plugin')) { |
|
647 | - //to find if THIS is the addon that was activated, just check if we have already registered it or not |
|
648 | - //(as the newly-activated addon wasn't around the first time addons were registered). |
|
649 | - //Note: the presence of pue_options in the addon registration options will initialize the $_settings |
|
650 | - //property for the add-on, but the add-on is only partially initialized. Hence, the additional check. |
|
651 | - if (! isset(self::$_settings[ $addon_name ]) |
|
652 | - || (isset(self::$_settings[ $addon_name ]) |
|
653 | - && ! isset(self::$_settings[ $addon_name ]['class_name']) |
|
654 | - ) |
|
655 | - ) { |
|
656 | - self::$_settings[ $addon_name ] = $addon_settings; |
|
657 | - $addon = self::_load_and_init_addon_class($addon_name); |
|
658 | - $addon->set_activation_indicator_option(); |
|
659 | - // dont bother setting up the rest of the addon. |
|
660 | - // we know it was just activated and the request will end soon |
|
661 | - } |
|
662 | - return true; |
|
663 | - } |
|
664 | - // make sure this was called in the right place! |
|
665 | - if ( |
|
666 | - ! did_action('AHEE__EE_System__load_espresso_addons') |
|
667 | - || did_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin') |
|
668 | - ) { |
|
669 | - EE_Error::doing_it_wrong( |
|
670 | - __METHOD__, |
|
671 | - sprintf( |
|
672 | - __( |
|
673 | - 'An attempt to register an EE_Addon named "%s" has failed because it was not registered at the correct time. Please use the "AHEE__EE_System__load_espresso_addons" hook to register addons.', |
|
674 | - 'event_espresso' |
|
675 | - ), |
|
676 | - $addon_name |
|
677 | - ), |
|
678 | - '4.3.0' |
|
679 | - ); |
|
680 | - } |
|
681 | - // make sure addon settings are set correctly without overwriting anything existing |
|
682 | - if (isset(self::$_settings[ $addon_name ])) { |
|
683 | - self::$_settings[ $addon_name ] += $addon_settings; |
|
684 | - } else { |
|
685 | - self::$_settings[ $addon_name ] = $addon_settings; |
|
686 | - } |
|
687 | - return false; |
|
688 | - } |
|
633 | + /** |
|
634 | + * @param string $addon_name |
|
635 | + * @param array $addon_settings |
|
636 | + * @return bool |
|
637 | + * @throws EE_Error |
|
638 | + * @throws InvalidArgumentException |
|
639 | + * @throws ReflectionException |
|
640 | + * @throws InvalidDataTypeException |
|
641 | + * @throws InvalidInterfaceException |
|
642 | + */ |
|
643 | + private static function _addon_activation($addon_name, array $addon_settings) |
|
644 | + { |
|
645 | + // this is an activation request |
|
646 | + if (did_action('activate_plugin')) { |
|
647 | + //to find if THIS is the addon that was activated, just check if we have already registered it or not |
|
648 | + //(as the newly-activated addon wasn't around the first time addons were registered). |
|
649 | + //Note: the presence of pue_options in the addon registration options will initialize the $_settings |
|
650 | + //property for the add-on, but the add-on is only partially initialized. Hence, the additional check. |
|
651 | + if (! isset(self::$_settings[ $addon_name ]) |
|
652 | + || (isset(self::$_settings[ $addon_name ]) |
|
653 | + && ! isset(self::$_settings[ $addon_name ]['class_name']) |
|
654 | + ) |
|
655 | + ) { |
|
656 | + self::$_settings[ $addon_name ] = $addon_settings; |
|
657 | + $addon = self::_load_and_init_addon_class($addon_name); |
|
658 | + $addon->set_activation_indicator_option(); |
|
659 | + // dont bother setting up the rest of the addon. |
|
660 | + // we know it was just activated and the request will end soon |
|
661 | + } |
|
662 | + return true; |
|
663 | + } |
|
664 | + // make sure this was called in the right place! |
|
665 | + if ( |
|
666 | + ! did_action('AHEE__EE_System__load_espresso_addons') |
|
667 | + || did_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin') |
|
668 | + ) { |
|
669 | + EE_Error::doing_it_wrong( |
|
670 | + __METHOD__, |
|
671 | + sprintf( |
|
672 | + __( |
|
673 | + 'An attempt to register an EE_Addon named "%s" has failed because it was not registered at the correct time. Please use the "AHEE__EE_System__load_espresso_addons" hook to register addons.', |
|
674 | + 'event_espresso' |
|
675 | + ), |
|
676 | + $addon_name |
|
677 | + ), |
|
678 | + '4.3.0' |
|
679 | + ); |
|
680 | + } |
|
681 | + // make sure addon settings are set correctly without overwriting anything existing |
|
682 | + if (isset(self::$_settings[ $addon_name ])) { |
|
683 | + self::$_settings[ $addon_name ] += $addon_settings; |
|
684 | + } else { |
|
685 | + self::$_settings[ $addon_name ] = $addon_settings; |
|
686 | + } |
|
687 | + return false; |
|
688 | + } |
|
689 | 689 | |
690 | 690 | |
691 | - /** |
|
692 | - * @param string $addon_name |
|
693 | - * @return void |
|
694 | - * @throws EE_Error |
|
695 | - */ |
|
696 | - private static function _setup_autoloaders($addon_name) |
|
697 | - { |
|
698 | - if (! empty(self::$_settings[ $addon_name ]['autoloader_paths'])) { |
|
699 | - // setup autoloader for single file |
|
700 | - EEH_Autoloader::instance()->register_autoloader(self::$_settings[ $addon_name ]['autoloader_paths']); |
|
701 | - } |
|
702 | - // setup autoloaders for folders |
|
703 | - if (! empty(self::$_settings[ $addon_name ]['autoloader_folders'])) { |
|
704 | - foreach ((array) self::$_settings[ $addon_name ]['autoloader_folders'] as $autoloader_folder) { |
|
705 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder($autoloader_folder); |
|
706 | - } |
|
707 | - } |
|
708 | - } |
|
691 | + /** |
|
692 | + * @param string $addon_name |
|
693 | + * @return void |
|
694 | + * @throws EE_Error |
|
695 | + */ |
|
696 | + private static function _setup_autoloaders($addon_name) |
|
697 | + { |
|
698 | + if (! empty(self::$_settings[ $addon_name ]['autoloader_paths'])) { |
|
699 | + // setup autoloader for single file |
|
700 | + EEH_Autoloader::instance()->register_autoloader(self::$_settings[ $addon_name ]['autoloader_paths']); |
|
701 | + } |
|
702 | + // setup autoloaders for folders |
|
703 | + if (! empty(self::$_settings[ $addon_name ]['autoloader_folders'])) { |
|
704 | + foreach ((array) self::$_settings[ $addon_name ]['autoloader_folders'] as $autoloader_folder) { |
|
705 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder($autoloader_folder); |
|
706 | + } |
|
707 | + } |
|
708 | + } |
|
709 | 709 | |
710 | 710 | |
711 | - /** |
|
712 | - * register new models and extensions |
|
713 | - * |
|
714 | - * @param string $addon_name |
|
715 | - * @return void |
|
716 | - * @throws EE_Error |
|
717 | - */ |
|
718 | - private static function _register_models_and_extensions($addon_name) |
|
719 | - { |
|
720 | - // register new models |
|
721 | - if ( |
|
722 | - ! empty(self::$_settings[ $addon_name ]['model_paths']) |
|
723 | - || ! empty(self::$_settings[ $addon_name ]['class_paths']) |
|
724 | - ) { |
|
725 | - EE_Register_Model::register( |
|
726 | - $addon_name, |
|
727 | - array( |
|
728 | - 'model_paths' => self::$_settings[ $addon_name ]['model_paths'], |
|
729 | - 'class_paths' => self::$_settings[ $addon_name ]['class_paths'], |
|
730 | - ) |
|
731 | - ); |
|
732 | - } |
|
733 | - // register model extensions |
|
734 | - if ( |
|
735 | - ! empty(self::$_settings[ $addon_name ]['model_extension_paths']) |
|
736 | - || ! empty(self::$_settings[ $addon_name ]['class_extension_paths']) |
|
737 | - ) { |
|
738 | - EE_Register_Model_Extensions::register( |
|
739 | - $addon_name, |
|
740 | - array( |
|
741 | - 'model_extension_paths' => self::$_settings[ $addon_name ]['model_extension_paths'], |
|
742 | - 'class_extension_paths' => self::$_settings[ $addon_name ]['class_extension_paths'], |
|
743 | - ) |
|
744 | - ); |
|
745 | - } |
|
746 | - } |
|
711 | + /** |
|
712 | + * register new models and extensions |
|
713 | + * |
|
714 | + * @param string $addon_name |
|
715 | + * @return void |
|
716 | + * @throws EE_Error |
|
717 | + */ |
|
718 | + private static function _register_models_and_extensions($addon_name) |
|
719 | + { |
|
720 | + // register new models |
|
721 | + if ( |
|
722 | + ! empty(self::$_settings[ $addon_name ]['model_paths']) |
|
723 | + || ! empty(self::$_settings[ $addon_name ]['class_paths']) |
|
724 | + ) { |
|
725 | + EE_Register_Model::register( |
|
726 | + $addon_name, |
|
727 | + array( |
|
728 | + 'model_paths' => self::$_settings[ $addon_name ]['model_paths'], |
|
729 | + 'class_paths' => self::$_settings[ $addon_name ]['class_paths'], |
|
730 | + ) |
|
731 | + ); |
|
732 | + } |
|
733 | + // register model extensions |
|
734 | + if ( |
|
735 | + ! empty(self::$_settings[ $addon_name ]['model_extension_paths']) |
|
736 | + || ! empty(self::$_settings[ $addon_name ]['class_extension_paths']) |
|
737 | + ) { |
|
738 | + EE_Register_Model_Extensions::register( |
|
739 | + $addon_name, |
|
740 | + array( |
|
741 | + 'model_extension_paths' => self::$_settings[ $addon_name ]['model_extension_paths'], |
|
742 | + 'class_extension_paths' => self::$_settings[ $addon_name ]['class_extension_paths'], |
|
743 | + ) |
|
744 | + ); |
|
745 | + } |
|
746 | + } |
|
747 | 747 | |
748 | 748 | |
749 | - /** |
|
750 | - * @param string $addon_name |
|
751 | - * @return void |
|
752 | - * @throws EE_Error |
|
753 | - */ |
|
754 | - private static function _register_data_migration_scripts($addon_name) |
|
755 | - { |
|
756 | - // setup DMS |
|
757 | - if (! empty(self::$_settings[ $addon_name ]['dms_paths'])) { |
|
758 | - EE_Register_Data_Migration_Scripts::register( |
|
759 | - $addon_name, |
|
760 | - array('dms_paths' => self::$_settings[ $addon_name ]['dms_paths']) |
|
761 | - ); |
|
762 | - } |
|
763 | - } |
|
749 | + /** |
|
750 | + * @param string $addon_name |
|
751 | + * @return void |
|
752 | + * @throws EE_Error |
|
753 | + */ |
|
754 | + private static function _register_data_migration_scripts($addon_name) |
|
755 | + { |
|
756 | + // setup DMS |
|
757 | + if (! empty(self::$_settings[ $addon_name ]['dms_paths'])) { |
|
758 | + EE_Register_Data_Migration_Scripts::register( |
|
759 | + $addon_name, |
|
760 | + array('dms_paths' => self::$_settings[ $addon_name ]['dms_paths']) |
|
761 | + ); |
|
762 | + } |
|
763 | + } |
|
764 | 764 | |
765 | 765 | |
766 | - /** |
|
767 | - * @param string $addon_name |
|
768 | - * @return void |
|
769 | - * @throws EE_Error |
|
770 | - */ |
|
771 | - private static function _register_config($addon_name) |
|
772 | - { |
|
773 | - // if config_class is present let's register config. |
|
774 | - if (! empty(self::$_settings[ $addon_name ]['config_class'])) { |
|
775 | - EE_Register_Config::register( |
|
776 | - self::$_settings[ $addon_name ]['config_class'], |
|
777 | - array( |
|
778 | - 'config_section' => self::$_settings[ $addon_name ]['config_section'], |
|
779 | - 'config_name' => self::$_settings[ $addon_name ]['config_name'], |
|
780 | - ) |
|
781 | - ); |
|
782 | - } |
|
783 | - } |
|
766 | + /** |
|
767 | + * @param string $addon_name |
|
768 | + * @return void |
|
769 | + * @throws EE_Error |
|
770 | + */ |
|
771 | + private static function _register_config($addon_name) |
|
772 | + { |
|
773 | + // if config_class is present let's register config. |
|
774 | + if (! empty(self::$_settings[ $addon_name ]['config_class'])) { |
|
775 | + EE_Register_Config::register( |
|
776 | + self::$_settings[ $addon_name ]['config_class'], |
|
777 | + array( |
|
778 | + 'config_section' => self::$_settings[ $addon_name ]['config_section'], |
|
779 | + 'config_name' => self::$_settings[ $addon_name ]['config_name'], |
|
780 | + ) |
|
781 | + ); |
|
782 | + } |
|
783 | + } |
|
784 | 784 | |
785 | 785 | |
786 | - /** |
|
787 | - * @param string $addon_name |
|
788 | - * @return void |
|
789 | - * @throws EE_Error |
|
790 | - */ |
|
791 | - private static function _register_admin_pages($addon_name) |
|
792 | - { |
|
793 | - if (! empty(self::$_settings[ $addon_name ]['admin_path'])) { |
|
794 | - EE_Register_Admin_Page::register( |
|
795 | - $addon_name, |
|
796 | - array('page_path' => self::$_settings[ $addon_name ]['admin_path']) |
|
797 | - ); |
|
798 | - } |
|
799 | - } |
|
786 | + /** |
|
787 | + * @param string $addon_name |
|
788 | + * @return void |
|
789 | + * @throws EE_Error |
|
790 | + */ |
|
791 | + private static function _register_admin_pages($addon_name) |
|
792 | + { |
|
793 | + if (! empty(self::$_settings[ $addon_name ]['admin_path'])) { |
|
794 | + EE_Register_Admin_Page::register( |
|
795 | + $addon_name, |
|
796 | + array('page_path' => self::$_settings[ $addon_name ]['admin_path']) |
|
797 | + ); |
|
798 | + } |
|
799 | + } |
|
800 | 800 | |
801 | 801 | |
802 | - /** |
|
803 | - * @param string $addon_name |
|
804 | - * @return void |
|
805 | - * @throws EE_Error |
|
806 | - */ |
|
807 | - private static function _register_modules($addon_name) |
|
808 | - { |
|
809 | - if (! empty(self::$_settings[ $addon_name ]['module_paths'])) { |
|
810 | - EE_Register_Module::register( |
|
811 | - $addon_name, |
|
812 | - array('module_paths' => self::$_settings[ $addon_name ]['module_paths']) |
|
813 | - ); |
|
814 | - } |
|
815 | - } |
|
802 | + /** |
|
803 | + * @param string $addon_name |
|
804 | + * @return void |
|
805 | + * @throws EE_Error |
|
806 | + */ |
|
807 | + private static function _register_modules($addon_name) |
|
808 | + { |
|
809 | + if (! empty(self::$_settings[ $addon_name ]['module_paths'])) { |
|
810 | + EE_Register_Module::register( |
|
811 | + $addon_name, |
|
812 | + array('module_paths' => self::$_settings[ $addon_name ]['module_paths']) |
|
813 | + ); |
|
814 | + } |
|
815 | + } |
|
816 | 816 | |
817 | 817 | |
818 | - /** |
|
819 | - * @param string $addon_name |
|
820 | - * @return void |
|
821 | - * @throws EE_Error |
|
822 | - */ |
|
823 | - private static function _register_shortcodes($addon_name) |
|
824 | - { |
|
825 | - if (! empty(self::$_settings[ $addon_name ]['shortcode_paths']) |
|
826 | - || ! empty(self::$_settings[ $addon_name ]['shortcode_fqcns']) |
|
827 | - ) { |
|
828 | - EE_Register_Shortcode::register( |
|
829 | - $addon_name, |
|
830 | - array( |
|
831 | - 'shortcode_paths' => isset(self::$_settings[ $addon_name ]['shortcode_paths']) |
|
832 | - ? self::$_settings[ $addon_name ]['shortcode_paths'] |
|
833 | - : array(), |
|
834 | - 'shortcode_fqcns' => isset(self::$_settings[ $addon_name ]['shortcode_fqcns']) |
|
835 | - ? self::$_settings[ $addon_name ]['shortcode_fqcns'] |
|
836 | - : array(), |
|
837 | - ) |
|
838 | - ); |
|
839 | - } |
|
840 | - } |
|
818 | + /** |
|
819 | + * @param string $addon_name |
|
820 | + * @return void |
|
821 | + * @throws EE_Error |
|
822 | + */ |
|
823 | + private static function _register_shortcodes($addon_name) |
|
824 | + { |
|
825 | + if (! empty(self::$_settings[ $addon_name ]['shortcode_paths']) |
|
826 | + || ! empty(self::$_settings[ $addon_name ]['shortcode_fqcns']) |
|
827 | + ) { |
|
828 | + EE_Register_Shortcode::register( |
|
829 | + $addon_name, |
|
830 | + array( |
|
831 | + 'shortcode_paths' => isset(self::$_settings[ $addon_name ]['shortcode_paths']) |
|
832 | + ? self::$_settings[ $addon_name ]['shortcode_paths'] |
|
833 | + : array(), |
|
834 | + 'shortcode_fqcns' => isset(self::$_settings[ $addon_name ]['shortcode_fqcns']) |
|
835 | + ? self::$_settings[ $addon_name ]['shortcode_fqcns'] |
|
836 | + : array(), |
|
837 | + ) |
|
838 | + ); |
|
839 | + } |
|
840 | + } |
|
841 | 841 | |
842 | 842 | |
843 | - /** |
|
844 | - * @param string $addon_name |
|
845 | - * @return void |
|
846 | - * @throws EE_Error |
|
847 | - */ |
|
848 | - private static function _register_widgets($addon_name) |
|
849 | - { |
|
850 | - if (! empty(self::$_settings[ $addon_name ]['widget_paths'])) { |
|
851 | - EE_Register_Widget::register( |
|
852 | - $addon_name, |
|
853 | - array('widget_paths' => self::$_settings[ $addon_name ]['widget_paths']) |
|
854 | - ); |
|
855 | - } |
|
856 | - } |
|
843 | + /** |
|
844 | + * @param string $addon_name |
|
845 | + * @return void |
|
846 | + * @throws EE_Error |
|
847 | + */ |
|
848 | + private static function _register_widgets($addon_name) |
|
849 | + { |
|
850 | + if (! empty(self::$_settings[ $addon_name ]['widget_paths'])) { |
|
851 | + EE_Register_Widget::register( |
|
852 | + $addon_name, |
|
853 | + array('widget_paths' => self::$_settings[ $addon_name ]['widget_paths']) |
|
854 | + ); |
|
855 | + } |
|
856 | + } |
|
857 | 857 | |
858 | 858 | |
859 | - /** |
|
860 | - * @param string $addon_name |
|
861 | - * @return void |
|
862 | - * @throws EE_Error |
|
863 | - */ |
|
864 | - private static function _register_capabilities($addon_name) |
|
865 | - { |
|
866 | - if (! empty(self::$_settings[ $addon_name ]['capabilities'])) { |
|
867 | - EE_Register_Capabilities::register( |
|
868 | - $addon_name, |
|
869 | - array( |
|
870 | - 'capabilities' => self::$_settings[ $addon_name ]['capabilities'], |
|
871 | - 'capability_maps' => self::$_settings[ $addon_name ]['capability_maps'], |
|
872 | - ) |
|
873 | - ); |
|
874 | - } |
|
875 | - } |
|
859 | + /** |
|
860 | + * @param string $addon_name |
|
861 | + * @return void |
|
862 | + * @throws EE_Error |
|
863 | + */ |
|
864 | + private static function _register_capabilities($addon_name) |
|
865 | + { |
|
866 | + if (! empty(self::$_settings[ $addon_name ]['capabilities'])) { |
|
867 | + EE_Register_Capabilities::register( |
|
868 | + $addon_name, |
|
869 | + array( |
|
870 | + 'capabilities' => self::$_settings[ $addon_name ]['capabilities'], |
|
871 | + 'capability_maps' => self::$_settings[ $addon_name ]['capability_maps'], |
|
872 | + ) |
|
873 | + ); |
|
874 | + } |
|
875 | + } |
|
876 | 876 | |
877 | 877 | |
878 | - /** |
|
879 | - * @param string $addon_name |
|
880 | - * @return void |
|
881 | - * @throws EE_Error |
|
882 | - */ |
|
883 | - private static function _register_message_types($addon_name) |
|
884 | - { |
|
885 | - if (! empty(self::$_settings[ $addon_name ]['message_types'])) { |
|
886 | - add_action( |
|
887 | - 'EE_Brewing_Regular___messages_caf', |
|
888 | - array('EE_Register_Addon', 'register_message_types') |
|
889 | - ); |
|
890 | - } |
|
891 | - } |
|
878 | + /** |
|
879 | + * @param string $addon_name |
|
880 | + * @return void |
|
881 | + * @throws EE_Error |
|
882 | + */ |
|
883 | + private static function _register_message_types($addon_name) |
|
884 | + { |
|
885 | + if (! empty(self::$_settings[ $addon_name ]['message_types'])) { |
|
886 | + add_action( |
|
887 | + 'EE_Brewing_Regular___messages_caf', |
|
888 | + array('EE_Register_Addon', 'register_message_types') |
|
889 | + ); |
|
890 | + } |
|
891 | + } |
|
892 | 892 | |
893 | 893 | |
894 | - /** |
|
895 | - * @param string $addon_name |
|
896 | - * @return void |
|
897 | - * @throws EE_Error |
|
898 | - */ |
|
899 | - private static function _register_custom_post_types($addon_name) |
|
900 | - { |
|
901 | - if ( |
|
902 | - ! empty(self::$_settings[ $addon_name ]['custom_post_types']) |
|
903 | - || ! empty(self::$_settings[ $addon_name ]['custom_taxonomies']) |
|
904 | - ) { |
|
905 | - EE_Register_CPT::register( |
|
906 | - $addon_name, |
|
907 | - array( |
|
908 | - 'cpts' => self::$_settings[ $addon_name ]['custom_post_types'], |
|
909 | - 'cts' => self::$_settings[ $addon_name ]['custom_taxonomies'], |
|
910 | - 'default_terms' => self::$_settings[ $addon_name ]['default_terms'], |
|
911 | - ) |
|
912 | - ); |
|
913 | - } |
|
914 | - } |
|
894 | + /** |
|
895 | + * @param string $addon_name |
|
896 | + * @return void |
|
897 | + * @throws EE_Error |
|
898 | + */ |
|
899 | + private static function _register_custom_post_types($addon_name) |
|
900 | + { |
|
901 | + if ( |
|
902 | + ! empty(self::$_settings[ $addon_name ]['custom_post_types']) |
|
903 | + || ! empty(self::$_settings[ $addon_name ]['custom_taxonomies']) |
|
904 | + ) { |
|
905 | + EE_Register_CPT::register( |
|
906 | + $addon_name, |
|
907 | + array( |
|
908 | + 'cpts' => self::$_settings[ $addon_name ]['custom_post_types'], |
|
909 | + 'cts' => self::$_settings[ $addon_name ]['custom_taxonomies'], |
|
910 | + 'default_terms' => self::$_settings[ $addon_name ]['default_terms'], |
|
911 | + ) |
|
912 | + ); |
|
913 | + } |
|
914 | + } |
|
915 | 915 | |
916 | 916 | |
917 | - /** |
|
918 | - * @param string $addon_name |
|
919 | - * @return void |
|
920 | - * @throws InvalidArgumentException |
|
921 | - * @throws InvalidInterfaceException |
|
922 | - * @throws InvalidDataTypeException |
|
923 | - * @throws DomainException |
|
924 | - * @throws EE_Error |
|
925 | - */ |
|
926 | - private static function _register_payment_methods($addon_name) |
|
927 | - { |
|
928 | - if (! empty(self::$_settings[ $addon_name ]['payment_method_paths'])) { |
|
929 | - EE_Register_Payment_Method::register( |
|
930 | - $addon_name, |
|
931 | - array('payment_method_paths' => self::$_settings[ $addon_name ]['payment_method_paths']) |
|
932 | - ); |
|
933 | - } |
|
934 | - } |
|
917 | + /** |
|
918 | + * @param string $addon_name |
|
919 | + * @return void |
|
920 | + * @throws InvalidArgumentException |
|
921 | + * @throws InvalidInterfaceException |
|
922 | + * @throws InvalidDataTypeException |
|
923 | + * @throws DomainException |
|
924 | + * @throws EE_Error |
|
925 | + */ |
|
926 | + private static function _register_payment_methods($addon_name) |
|
927 | + { |
|
928 | + if (! empty(self::$_settings[ $addon_name ]['payment_method_paths'])) { |
|
929 | + EE_Register_Payment_Method::register( |
|
930 | + $addon_name, |
|
931 | + array('payment_method_paths' => self::$_settings[ $addon_name ]['payment_method_paths']) |
|
932 | + ); |
|
933 | + } |
|
934 | + } |
|
935 | 935 | |
936 | 936 | |
937 | - /** |
|
938 | - * Loads and instantiates the EE_Addon class and adds it onto the registry |
|
939 | - * |
|
940 | - * @param string $addon_name |
|
941 | - * @return EE_Addon |
|
942 | - * @throws InvalidArgumentException |
|
943 | - * @throws InvalidInterfaceException |
|
944 | - * @throws InvalidDataTypeException |
|
945 | - * @throws ReflectionException |
|
946 | - * @throws EE_Error |
|
947 | - */ |
|
948 | - private static function _load_and_init_addon_class($addon_name) |
|
949 | - { |
|
950 | - $loader = EventEspresso\core\services\loaders\LoaderFactory::getLoader(); |
|
951 | - $addon = $loader->getShared( |
|
952 | - self::$_settings[ $addon_name ]['class_name'], |
|
953 | - array('EE_Registry::create(addon)' => true) |
|
954 | - ); |
|
955 | - // setter inject dep map if required |
|
956 | - if($addon instanceof RequiresDependencyMapInterface && $addon->dependencyMap() === null){ |
|
957 | - $addon->setDependencyMap($loader->getShared('EE_Dependency_Map')); |
|
958 | - } |
|
959 | - // setter inject domain if required |
|
960 | - if( |
|
961 | - $addon instanceof RequiresDomainInterface |
|
962 | - && self::$_settings[ $addon_name ]['domain_fqcn'] !== '' |
|
963 | - && $addon->domain() === null |
|
964 | - ){ |
|
965 | - $addon->setDomain( |
|
966 | - $loader->getShared( |
|
967 | - self::$_settings[ $addon_name ]['domain_fqcn'], |
|
968 | - array( |
|
969 | - self::$_settings[ $addon_name ]['main_file_path'], |
|
970 | - self::$_settings[ $addon_name ]['version'] |
|
971 | - ) |
|
972 | - ) |
|
973 | - ); |
|
974 | - } |
|
937 | + /** |
|
938 | + * Loads and instantiates the EE_Addon class and adds it onto the registry |
|
939 | + * |
|
940 | + * @param string $addon_name |
|
941 | + * @return EE_Addon |
|
942 | + * @throws InvalidArgumentException |
|
943 | + * @throws InvalidInterfaceException |
|
944 | + * @throws InvalidDataTypeException |
|
945 | + * @throws ReflectionException |
|
946 | + * @throws EE_Error |
|
947 | + */ |
|
948 | + private static function _load_and_init_addon_class($addon_name) |
|
949 | + { |
|
950 | + $loader = EventEspresso\core\services\loaders\LoaderFactory::getLoader(); |
|
951 | + $addon = $loader->getShared( |
|
952 | + self::$_settings[ $addon_name ]['class_name'], |
|
953 | + array('EE_Registry::create(addon)' => true) |
|
954 | + ); |
|
955 | + // setter inject dep map if required |
|
956 | + if($addon instanceof RequiresDependencyMapInterface && $addon->dependencyMap() === null){ |
|
957 | + $addon->setDependencyMap($loader->getShared('EE_Dependency_Map')); |
|
958 | + } |
|
959 | + // setter inject domain if required |
|
960 | + if( |
|
961 | + $addon instanceof RequiresDomainInterface |
|
962 | + && self::$_settings[ $addon_name ]['domain_fqcn'] !== '' |
|
963 | + && $addon->domain() === null |
|
964 | + ){ |
|
965 | + $addon->setDomain( |
|
966 | + $loader->getShared( |
|
967 | + self::$_settings[ $addon_name ]['domain_fqcn'], |
|
968 | + array( |
|
969 | + self::$_settings[ $addon_name ]['main_file_path'], |
|
970 | + self::$_settings[ $addon_name ]['version'] |
|
971 | + ) |
|
972 | + ) |
|
973 | + ); |
|
974 | + } |
|
975 | 975 | |
976 | - $addon->set_name($addon_name); |
|
977 | - $addon->set_plugin_slug(self::$_settings[ $addon_name ]['plugin_slug']); |
|
978 | - $addon->set_plugin_basename(self::$_settings[ $addon_name ]['plugin_basename']); |
|
979 | - $addon->set_main_plugin_file(self::$_settings[ $addon_name ]['main_file_path']); |
|
980 | - $addon->set_plugin_action_slug(self::$_settings[ $addon_name ]['plugin_action_slug']); |
|
981 | - $addon->set_plugins_page_row(self::$_settings[ $addon_name ]['plugins_page_row']); |
|
982 | - $addon->set_version(self::$_settings[ $addon_name ]['version']); |
|
983 | - $addon->set_min_core_version(self::_effective_version(self::$_settings[ $addon_name ]['min_core_version'])); |
|
984 | - $addon->set_config_section(self::$_settings[ $addon_name ]['config_section']); |
|
985 | - $addon->set_config_class(self::$_settings[ $addon_name ]['config_class']); |
|
986 | - $addon->set_config_name(self::$_settings[ $addon_name ]['config_name']); |
|
987 | - //unfortunately this can't be hooked in upon construction, because we don't have |
|
988 | - //the plugin mainfile's path upon construction. |
|
989 | - register_deactivation_hook($addon->get_main_plugin_file(), array($addon, 'deactivation')); |
|
990 | - // call any additional admin_callback functions during load_admin_controller hook |
|
991 | - if (! empty(self::$_settings[ $addon_name ]['admin_callback'])) { |
|
992 | - add_action( |
|
993 | - 'AHEE__EE_System__load_controllers__load_admin_controllers', |
|
994 | - array($addon, self::$_settings[ $addon_name ]['admin_callback']) |
|
995 | - ); |
|
996 | - } |
|
997 | - return $addon; |
|
998 | - } |
|
976 | + $addon->set_name($addon_name); |
|
977 | + $addon->set_plugin_slug(self::$_settings[ $addon_name ]['plugin_slug']); |
|
978 | + $addon->set_plugin_basename(self::$_settings[ $addon_name ]['plugin_basename']); |
|
979 | + $addon->set_main_plugin_file(self::$_settings[ $addon_name ]['main_file_path']); |
|
980 | + $addon->set_plugin_action_slug(self::$_settings[ $addon_name ]['plugin_action_slug']); |
|
981 | + $addon->set_plugins_page_row(self::$_settings[ $addon_name ]['plugins_page_row']); |
|
982 | + $addon->set_version(self::$_settings[ $addon_name ]['version']); |
|
983 | + $addon->set_min_core_version(self::_effective_version(self::$_settings[ $addon_name ]['min_core_version'])); |
|
984 | + $addon->set_config_section(self::$_settings[ $addon_name ]['config_section']); |
|
985 | + $addon->set_config_class(self::$_settings[ $addon_name ]['config_class']); |
|
986 | + $addon->set_config_name(self::$_settings[ $addon_name ]['config_name']); |
|
987 | + //unfortunately this can't be hooked in upon construction, because we don't have |
|
988 | + //the plugin mainfile's path upon construction. |
|
989 | + register_deactivation_hook($addon->get_main_plugin_file(), array($addon, 'deactivation')); |
|
990 | + // call any additional admin_callback functions during load_admin_controller hook |
|
991 | + if (! empty(self::$_settings[ $addon_name ]['admin_callback'])) { |
|
992 | + add_action( |
|
993 | + 'AHEE__EE_System__load_controllers__load_admin_controllers', |
|
994 | + array($addon, self::$_settings[ $addon_name ]['admin_callback']) |
|
995 | + ); |
|
996 | + } |
|
997 | + return $addon; |
|
998 | + } |
|
999 | 999 | |
1000 | 1000 | |
1001 | - /** |
|
1002 | - * load_pue_update - Update notifications |
|
1003 | - * |
|
1004 | - * @return void |
|
1005 | - * @throws InvalidArgumentException |
|
1006 | - * @throws InvalidDataTypeException |
|
1007 | - * @throws InvalidInterfaceException |
|
1008 | - */ |
|
1009 | - public static function load_pue_update() |
|
1010 | - { |
|
1011 | - // load PUE client |
|
1012 | - require_once EE_THIRD_PARTY . 'pue' . DS . 'pue-client.php'; |
|
1013 | - // cycle thru settings |
|
1014 | - foreach (self::$_settings as $settings) { |
|
1015 | - if (! empty($settings['pue_options'])) { |
|
1016 | - // initiate the class and start the plugin update engine! |
|
1017 | - new PluginUpdateEngineChecker( |
|
1018 | - // host file URL |
|
1019 | - 'https://eventespresso.com', |
|
1020 | - // plugin slug(s) |
|
1021 | - array( |
|
1022 | - 'premium' => array('p' => $settings['pue_options']['pue_plugin_slug']), |
|
1023 | - 'prerelease' => array('beta' => $settings['pue_options']['pue_plugin_slug'] . '-pr'), |
|
1024 | - ), |
|
1025 | - // options |
|
1026 | - array( |
|
1027 | - 'apikey' => EE_Registry::instance()->NET_CFG->core->site_license_key, |
|
1028 | - 'lang_domain' => 'event_espresso', |
|
1029 | - 'checkPeriod' => $settings['pue_options']['checkPeriod'], |
|
1030 | - 'option_key' => 'site_license_key', |
|
1031 | - 'options_page_slug' => 'event_espresso', |
|
1032 | - 'plugin_basename' => $settings['pue_options']['plugin_basename'], |
|
1033 | - // if use_wp_update is TRUE it means you want FREE versions of the plugin to be updated from WP |
|
1034 | - 'use_wp_update' => $settings['pue_options']['use_wp_update'], |
|
1035 | - ) |
|
1036 | - ); |
|
1037 | - } |
|
1038 | - } |
|
1039 | - } |
|
1001 | + /** |
|
1002 | + * load_pue_update - Update notifications |
|
1003 | + * |
|
1004 | + * @return void |
|
1005 | + * @throws InvalidArgumentException |
|
1006 | + * @throws InvalidDataTypeException |
|
1007 | + * @throws InvalidInterfaceException |
|
1008 | + */ |
|
1009 | + public static function load_pue_update() |
|
1010 | + { |
|
1011 | + // load PUE client |
|
1012 | + require_once EE_THIRD_PARTY . 'pue' . DS . 'pue-client.php'; |
|
1013 | + // cycle thru settings |
|
1014 | + foreach (self::$_settings as $settings) { |
|
1015 | + if (! empty($settings['pue_options'])) { |
|
1016 | + // initiate the class and start the plugin update engine! |
|
1017 | + new PluginUpdateEngineChecker( |
|
1018 | + // host file URL |
|
1019 | + 'https://eventespresso.com', |
|
1020 | + // plugin slug(s) |
|
1021 | + array( |
|
1022 | + 'premium' => array('p' => $settings['pue_options']['pue_plugin_slug']), |
|
1023 | + 'prerelease' => array('beta' => $settings['pue_options']['pue_plugin_slug'] . '-pr'), |
|
1024 | + ), |
|
1025 | + // options |
|
1026 | + array( |
|
1027 | + 'apikey' => EE_Registry::instance()->NET_CFG->core->site_license_key, |
|
1028 | + 'lang_domain' => 'event_espresso', |
|
1029 | + 'checkPeriod' => $settings['pue_options']['checkPeriod'], |
|
1030 | + 'option_key' => 'site_license_key', |
|
1031 | + 'options_page_slug' => 'event_espresso', |
|
1032 | + 'plugin_basename' => $settings['pue_options']['plugin_basename'], |
|
1033 | + // if use_wp_update is TRUE it means you want FREE versions of the plugin to be updated from WP |
|
1034 | + 'use_wp_update' => $settings['pue_options']['use_wp_update'], |
|
1035 | + ) |
|
1036 | + ); |
|
1037 | + } |
|
1038 | + } |
|
1039 | + } |
|
1040 | 1040 | |
1041 | 1041 | |
1042 | - /** |
|
1043 | - * Callback for EE_Brewing_Regular__messages_caf hook used to register message types. |
|
1044 | - * |
|
1045 | - * @since 4.4.0 |
|
1046 | - * @return void |
|
1047 | - * @throws EE_Error |
|
1048 | - */ |
|
1049 | - public static function register_message_types() |
|
1050 | - { |
|
1051 | - foreach (self::$_settings as $addon_name => $settings) { |
|
1052 | - if (! empty($settings['message_types'])) { |
|
1053 | - foreach ((array) $settings['message_types'] as $message_type => $message_type_settings) { |
|
1054 | - EE_Register_Message_Type::register($message_type, $message_type_settings); |
|
1055 | - } |
|
1056 | - } |
|
1057 | - } |
|
1058 | - } |
|
1042 | + /** |
|
1043 | + * Callback for EE_Brewing_Regular__messages_caf hook used to register message types. |
|
1044 | + * |
|
1045 | + * @since 4.4.0 |
|
1046 | + * @return void |
|
1047 | + * @throws EE_Error |
|
1048 | + */ |
|
1049 | + public static function register_message_types() |
|
1050 | + { |
|
1051 | + foreach (self::$_settings as $addon_name => $settings) { |
|
1052 | + if (! empty($settings['message_types'])) { |
|
1053 | + foreach ((array) $settings['message_types'] as $message_type => $message_type_settings) { |
|
1054 | + EE_Register_Message_Type::register($message_type, $message_type_settings); |
|
1055 | + } |
|
1056 | + } |
|
1057 | + } |
|
1058 | + } |
|
1059 | 1059 | |
1060 | 1060 | |
1061 | - /** |
|
1062 | - * This deregisters an addon that was previously registered with a specific addon_name. |
|
1063 | - * |
|
1064 | - * @since 4.3.0 |
|
1065 | - * @param string $addon_name the name for the addon that was previously registered |
|
1066 | - * @throws DomainException |
|
1067 | - * @throws EE_Error |
|
1068 | - * @throws InvalidArgumentException |
|
1069 | - * @throws InvalidDataTypeException |
|
1070 | - * @throws InvalidInterfaceException |
|
1071 | - */ |
|
1072 | - public static function deregister($addon_name = null) |
|
1073 | - { |
|
1074 | - if (isset(self::$_settings[ $addon_name ]['class_name'])) { |
|
1075 | - try { |
|
1076 | - do_action('AHEE__EE_Register_Addon__deregister__before', $addon_name); |
|
1077 | - $class_name = self::$_settings[$addon_name]['class_name']; |
|
1078 | - if (! empty(self::$_settings[$addon_name]['dms_paths'])) { |
|
1079 | - // setup DMS |
|
1080 | - EE_Register_Data_Migration_Scripts::deregister($addon_name); |
|
1081 | - } |
|
1082 | - if (! empty(self::$_settings[$addon_name]['admin_path'])) { |
|
1083 | - // register admin page |
|
1084 | - EE_Register_Admin_Page::deregister($addon_name); |
|
1085 | - } |
|
1086 | - if (! empty(self::$_settings[$addon_name]['module_paths'])) { |
|
1087 | - // add to list of modules to be registered |
|
1088 | - EE_Register_Module::deregister($addon_name); |
|
1089 | - } |
|
1090 | - if (! empty(self::$_settings[$addon_name]['shortcode_paths']) |
|
1091 | - || ! empty(self::$_settings[$addon_name]['shortcode_fqcns']) |
|
1092 | - ) { |
|
1093 | - // add to list of shortcodes to be registered |
|
1094 | - EE_Register_Shortcode::deregister($addon_name); |
|
1095 | - } |
|
1096 | - if (! empty(self::$_settings[$addon_name]['config_class'])) { |
|
1097 | - // if config_class present let's register config. |
|
1098 | - EE_Register_Config::deregister(self::$_settings[$addon_name]['config_class']); |
|
1099 | - } |
|
1100 | - if (! empty(self::$_settings[$addon_name]['widget_paths'])) { |
|
1101 | - // add to list of widgets to be registered |
|
1102 | - EE_Register_Widget::deregister($addon_name); |
|
1103 | - } |
|
1104 | - if (! empty(self::$_settings[$addon_name]['model_paths']) |
|
1105 | - || ! empty(self::$_settings[$addon_name]['class_paths']) |
|
1106 | - ) { |
|
1107 | - // add to list of shortcodes to be registered |
|
1108 | - EE_Register_Model::deregister($addon_name); |
|
1109 | - } |
|
1110 | - if (! empty(self::$_settings[$addon_name]['model_extension_paths']) |
|
1111 | - || ! empty(self::$_settings[$addon_name]['class_extension_paths']) |
|
1112 | - ) { |
|
1113 | - // add to list of shortcodes to be registered |
|
1114 | - EE_Register_Model_Extensions::deregister($addon_name); |
|
1115 | - } |
|
1116 | - if (! empty(self::$_settings[$addon_name]['message_types'])) { |
|
1117 | - foreach ( |
|
1118 | - (array)self::$_settings[$addon_name]['message_types'] as $message_type => |
|
1119 | - $message_type_settings |
|
1120 | - ) { |
|
1121 | - EE_Register_Message_Type::deregister($message_type); |
|
1122 | - } |
|
1123 | - } |
|
1124 | - //deregister capabilities for addon |
|
1125 | - if ( |
|
1126 | - ! empty(self::$_settings[$addon_name]['capabilities']) |
|
1127 | - || ! empty(self::$_settings[$addon_name]['capability_maps']) |
|
1128 | - ) { |
|
1129 | - EE_Register_Capabilities::deregister($addon_name); |
|
1130 | - } |
|
1131 | - //deregister custom_post_types for addon |
|
1132 | - if (! empty(self::$_settings[$addon_name]['custom_post_types'])) { |
|
1133 | - EE_Register_CPT::deregister($addon_name); |
|
1134 | - } |
|
1135 | - if (! empty(self::$_settings[$addon_name]['payment_method_paths'])) { |
|
1136 | - EE_Register_Payment_Method::deregister($addon_name); |
|
1137 | - } |
|
1138 | - $addon = EE_Registry::instance()->getAddon($class_name); |
|
1139 | - if ($addon instanceof EE_Addon) { |
|
1140 | - remove_action( |
|
1141 | - 'deactivate_' . $addon->get_main_plugin_file_basename(), |
|
1142 | - array($addon, 'deactivation') |
|
1143 | - ); |
|
1144 | - remove_action( |
|
1145 | - 'AHEE__EE_System__perform_activations_upgrades_and_migrations', |
|
1146 | - array($addon, 'initialize_db_if_no_migrations_required') |
|
1147 | - ); |
|
1148 | - //remove `after_registration` call |
|
1149 | - remove_action( |
|
1150 | - 'AHEE__EE_System__load_espresso_addons__complete', |
|
1151 | - array($addon, 'after_registration'), |
|
1152 | - 999 |
|
1153 | - ); |
|
1154 | - } |
|
1155 | - EE_Registry::instance()->removeAddon($class_name); |
|
1156 | - } catch (OutOfBoundsException $addon_not_yet_registered_exception) { |
|
1157 | - //the add-on was not yet registered in the registry, so RegistryContainer::__get() throws this exception. |
|
1158 | - //also no need to worry about this or log it, it's ok to deregister an add-on before its registered in the registry |
|
1159 | - } catch (Exception $e) { |
|
1160 | - new ExceptionLogger($e); |
|
1161 | - } |
|
1162 | - unset(self::$_settings[ $addon_name ]); |
|
1163 | - do_action('AHEE__EE_Register_Addon__deregister__after', $addon_name); |
|
1164 | - } |
|
1165 | - } |
|
1061 | + /** |
|
1062 | + * This deregisters an addon that was previously registered with a specific addon_name. |
|
1063 | + * |
|
1064 | + * @since 4.3.0 |
|
1065 | + * @param string $addon_name the name for the addon that was previously registered |
|
1066 | + * @throws DomainException |
|
1067 | + * @throws EE_Error |
|
1068 | + * @throws InvalidArgumentException |
|
1069 | + * @throws InvalidDataTypeException |
|
1070 | + * @throws InvalidInterfaceException |
|
1071 | + */ |
|
1072 | + public static function deregister($addon_name = null) |
|
1073 | + { |
|
1074 | + if (isset(self::$_settings[ $addon_name ]['class_name'])) { |
|
1075 | + try { |
|
1076 | + do_action('AHEE__EE_Register_Addon__deregister__before', $addon_name); |
|
1077 | + $class_name = self::$_settings[$addon_name]['class_name']; |
|
1078 | + if (! empty(self::$_settings[$addon_name]['dms_paths'])) { |
|
1079 | + // setup DMS |
|
1080 | + EE_Register_Data_Migration_Scripts::deregister($addon_name); |
|
1081 | + } |
|
1082 | + if (! empty(self::$_settings[$addon_name]['admin_path'])) { |
|
1083 | + // register admin page |
|
1084 | + EE_Register_Admin_Page::deregister($addon_name); |
|
1085 | + } |
|
1086 | + if (! empty(self::$_settings[$addon_name]['module_paths'])) { |
|
1087 | + // add to list of modules to be registered |
|
1088 | + EE_Register_Module::deregister($addon_name); |
|
1089 | + } |
|
1090 | + if (! empty(self::$_settings[$addon_name]['shortcode_paths']) |
|
1091 | + || ! empty(self::$_settings[$addon_name]['shortcode_fqcns']) |
|
1092 | + ) { |
|
1093 | + // add to list of shortcodes to be registered |
|
1094 | + EE_Register_Shortcode::deregister($addon_name); |
|
1095 | + } |
|
1096 | + if (! empty(self::$_settings[$addon_name]['config_class'])) { |
|
1097 | + // if config_class present let's register config. |
|
1098 | + EE_Register_Config::deregister(self::$_settings[$addon_name]['config_class']); |
|
1099 | + } |
|
1100 | + if (! empty(self::$_settings[$addon_name]['widget_paths'])) { |
|
1101 | + // add to list of widgets to be registered |
|
1102 | + EE_Register_Widget::deregister($addon_name); |
|
1103 | + } |
|
1104 | + if (! empty(self::$_settings[$addon_name]['model_paths']) |
|
1105 | + || ! empty(self::$_settings[$addon_name]['class_paths']) |
|
1106 | + ) { |
|
1107 | + // add to list of shortcodes to be registered |
|
1108 | + EE_Register_Model::deregister($addon_name); |
|
1109 | + } |
|
1110 | + if (! empty(self::$_settings[$addon_name]['model_extension_paths']) |
|
1111 | + || ! empty(self::$_settings[$addon_name]['class_extension_paths']) |
|
1112 | + ) { |
|
1113 | + // add to list of shortcodes to be registered |
|
1114 | + EE_Register_Model_Extensions::deregister($addon_name); |
|
1115 | + } |
|
1116 | + if (! empty(self::$_settings[$addon_name]['message_types'])) { |
|
1117 | + foreach ( |
|
1118 | + (array)self::$_settings[$addon_name]['message_types'] as $message_type => |
|
1119 | + $message_type_settings |
|
1120 | + ) { |
|
1121 | + EE_Register_Message_Type::deregister($message_type); |
|
1122 | + } |
|
1123 | + } |
|
1124 | + //deregister capabilities for addon |
|
1125 | + if ( |
|
1126 | + ! empty(self::$_settings[$addon_name]['capabilities']) |
|
1127 | + || ! empty(self::$_settings[$addon_name]['capability_maps']) |
|
1128 | + ) { |
|
1129 | + EE_Register_Capabilities::deregister($addon_name); |
|
1130 | + } |
|
1131 | + //deregister custom_post_types for addon |
|
1132 | + if (! empty(self::$_settings[$addon_name]['custom_post_types'])) { |
|
1133 | + EE_Register_CPT::deregister($addon_name); |
|
1134 | + } |
|
1135 | + if (! empty(self::$_settings[$addon_name]['payment_method_paths'])) { |
|
1136 | + EE_Register_Payment_Method::deregister($addon_name); |
|
1137 | + } |
|
1138 | + $addon = EE_Registry::instance()->getAddon($class_name); |
|
1139 | + if ($addon instanceof EE_Addon) { |
|
1140 | + remove_action( |
|
1141 | + 'deactivate_' . $addon->get_main_plugin_file_basename(), |
|
1142 | + array($addon, 'deactivation') |
|
1143 | + ); |
|
1144 | + remove_action( |
|
1145 | + 'AHEE__EE_System__perform_activations_upgrades_and_migrations', |
|
1146 | + array($addon, 'initialize_db_if_no_migrations_required') |
|
1147 | + ); |
|
1148 | + //remove `after_registration` call |
|
1149 | + remove_action( |
|
1150 | + 'AHEE__EE_System__load_espresso_addons__complete', |
|
1151 | + array($addon, 'after_registration'), |
|
1152 | + 999 |
|
1153 | + ); |
|
1154 | + } |
|
1155 | + EE_Registry::instance()->removeAddon($class_name); |
|
1156 | + } catch (OutOfBoundsException $addon_not_yet_registered_exception) { |
|
1157 | + //the add-on was not yet registered in the registry, so RegistryContainer::__get() throws this exception. |
|
1158 | + //also no need to worry about this or log it, it's ok to deregister an add-on before its registered in the registry |
|
1159 | + } catch (Exception $e) { |
|
1160 | + new ExceptionLogger($e); |
|
1161 | + } |
|
1162 | + unset(self::$_settings[ $addon_name ]); |
|
1163 | + do_action('AHEE__EE_Register_Addon__deregister__after', $addon_name); |
|
1164 | + } |
|
1165 | + } |
|
1166 | 1166 | |
1167 | 1167 | |
1168 | 1168 | } |
@@ -72,15 +72,15 @@ discard block |
||
72 | 72 | // offsets: 0 . 1 . 2 . 3 . 4 |
73 | 73 | $version_parts = explode('.', $min_core_version); |
74 | 74 | //check they specified the micro version (after 2nd period) |
75 | - if (! isset($version_parts[2])) { |
|
75 | + if ( ! isset($version_parts[2])) { |
|
76 | 76 | $version_parts[2] = '0'; |
77 | 77 | } |
78 | 78 | //if they didn't specify the 'p', or 'rc' part. Just assume the lowest possible |
79 | 79 | //soon we can assume that's 'rc', but this current version is 'alpha' |
80 | - if (! isset($version_parts[3])) { |
|
80 | + if ( ! isset($version_parts[3])) { |
|
81 | 81 | $version_parts[3] = 'dev'; |
82 | 82 | } |
83 | - if (! isset($version_parts[4])) { |
|
83 | + if ( ! isset($version_parts[4])) { |
|
84 | 84 | $version_parts[4] = '000'; |
85 | 85 | } |
86 | 86 | return implode('.', $version_parts); |
@@ -251,7 +251,7 @@ discard block |
||
251 | 251 | // setup PUE |
252 | 252 | EE_Register_Addon::_parse_pue_options($addon_name, $class_name, $setup_args); |
253 | 253 | // does this addon work with this version of core or WordPress ? |
254 | - if (! EE_Register_Addon::_addon_is_compatible($addon_name, $addon_settings)) { |
|
254 | + if ( ! EE_Register_Addon::_addon_is_compatible($addon_name, $addon_settings)) { |
|
255 | 255 | return; |
256 | 256 | } |
257 | 257 | // register namespaces |
@@ -309,7 +309,7 @@ discard block |
||
309 | 309 | ) |
310 | 310 | ); |
311 | 311 | } |
312 | - if (! isset($setup_args['main_file_path']) || empty($setup_args['main_file_path'])) { |
|
312 | + if ( ! isset($setup_args['main_file_path']) || empty($setup_args['main_file_path'])) { |
|
313 | 313 | throw new EE_Error( |
314 | 314 | sprintf( |
315 | 315 | __( |
@@ -321,7 +321,7 @@ discard block |
||
321 | 321 | ); |
322 | 322 | } |
323 | 323 | // check that addon has not already been registered with that name |
324 | - if (isset(self::$_settings[ $addon_name ]) && ! did_action('activate_plugin')) { |
|
324 | + if (isset(self::$_settings[$addon_name]) && ! did_action('activate_plugin')) { |
|
325 | 325 | throw new EE_Error( |
326 | 326 | sprintf( |
327 | 327 | __( |
@@ -353,7 +353,7 @@ discard block |
||
353 | 353 | // check if classname is fully qualified or is a legacy classname already prefixed with 'EE_' |
354 | 354 | return strpos($class_name, '\\') || strpos($class_name, 'EE_') === 0 |
355 | 355 | ? $class_name |
356 | - : 'EE_' . $class_name; |
|
356 | + : 'EE_'.$class_name; |
|
357 | 357 | } |
358 | 358 | |
359 | 359 | |
@@ -512,9 +512,9 @@ discard block |
||
512 | 512 | $incompatibility_message = ''; |
513 | 513 | //check whether this addon version is compatible with EE core |
514 | 514 | if ( |
515 | - isset(EE_Register_Addon::$_incompatible_addons[ $addon_name ]) |
|
515 | + isset(EE_Register_Addon::$_incompatible_addons[$addon_name]) |
|
516 | 516 | && ! self::_meets_min_core_version_requirement( |
517 | - EE_Register_Addon::$_incompatible_addons[ $addon_name ], |
|
517 | + EE_Register_Addon::$_incompatible_addons[$addon_name], |
|
518 | 518 | $addon_settings['version'] |
519 | 519 | ) |
520 | 520 | ) { |
@@ -524,7 +524,7 @@ discard block |
||
524 | 524 | ), |
525 | 525 | $addon_name, |
526 | 526 | '<br />', |
527 | - EE_Register_Addon::$_incompatible_addons[ $addon_name ], |
|
527 | + EE_Register_Addon::$_incompatible_addons[$addon_name], |
|
528 | 528 | '<span style="font-weight: bold; color: #D54E21;">', |
529 | 529 | '</span><br />' |
530 | 530 | ); |
@@ -556,7 +556,7 @@ discard block |
||
556 | 556 | '</span><br />' |
557 | 557 | ); |
558 | 558 | } |
559 | - if (! empty($incompatibility_message)) { |
|
559 | + if ( ! empty($incompatibility_message)) { |
|
560 | 560 | // remove 'activate' from the REQUEST |
561 | 561 | // so WP doesn't erroneously tell the user the plugin activated fine when it didn't |
562 | 562 | unset($_GET['activate'], $_REQUEST['activate']); |
@@ -584,11 +584,11 @@ discard block |
||
584 | 584 | */ |
585 | 585 | private static function _parse_pue_options($addon_name, $class_name, array $setup_args) |
586 | 586 | { |
587 | - if (! empty($setup_args['pue_options'])) { |
|
588 | - self::$_settings[ $addon_name ]['pue_options'] = array( |
|
587 | + if ( ! empty($setup_args['pue_options'])) { |
|
588 | + self::$_settings[$addon_name]['pue_options'] = array( |
|
589 | 589 | 'pue_plugin_slug' => isset($setup_args['pue_options']['pue_plugin_slug']) |
590 | 590 | ? (string) $setup_args['pue_options']['pue_plugin_slug'] |
591 | - : 'espresso_' . strtolower($class_name), |
|
591 | + : 'espresso_'.strtolower($class_name), |
|
592 | 592 | 'plugin_basename' => isset($setup_args['pue_options']['plugin_basename']) |
593 | 593 | ? (string) $setup_args['pue_options']['plugin_basename'] |
594 | 594 | : plugin_basename($setup_args['main_file_path']), |
@@ -648,12 +648,12 @@ discard block |
||
648 | 648 | //(as the newly-activated addon wasn't around the first time addons were registered). |
649 | 649 | //Note: the presence of pue_options in the addon registration options will initialize the $_settings |
650 | 650 | //property for the add-on, but the add-on is only partially initialized. Hence, the additional check. |
651 | - if (! isset(self::$_settings[ $addon_name ]) |
|
652 | - || (isset(self::$_settings[ $addon_name ]) |
|
653 | - && ! isset(self::$_settings[ $addon_name ]['class_name']) |
|
651 | + if ( ! isset(self::$_settings[$addon_name]) |
|
652 | + || (isset(self::$_settings[$addon_name]) |
|
653 | + && ! isset(self::$_settings[$addon_name]['class_name']) |
|
654 | 654 | ) |
655 | 655 | ) { |
656 | - self::$_settings[ $addon_name ] = $addon_settings; |
|
656 | + self::$_settings[$addon_name] = $addon_settings; |
|
657 | 657 | $addon = self::_load_and_init_addon_class($addon_name); |
658 | 658 | $addon->set_activation_indicator_option(); |
659 | 659 | // dont bother setting up the rest of the addon. |
@@ -679,10 +679,10 @@ discard block |
||
679 | 679 | ); |
680 | 680 | } |
681 | 681 | // make sure addon settings are set correctly without overwriting anything existing |
682 | - if (isset(self::$_settings[ $addon_name ])) { |
|
683 | - self::$_settings[ $addon_name ] += $addon_settings; |
|
682 | + if (isset(self::$_settings[$addon_name])) { |
|
683 | + self::$_settings[$addon_name] += $addon_settings; |
|
684 | 684 | } else { |
685 | - self::$_settings[ $addon_name ] = $addon_settings; |
|
685 | + self::$_settings[$addon_name] = $addon_settings; |
|
686 | 686 | } |
687 | 687 | return false; |
688 | 688 | } |
@@ -695,13 +695,13 @@ discard block |
||
695 | 695 | */ |
696 | 696 | private static function _setup_autoloaders($addon_name) |
697 | 697 | { |
698 | - if (! empty(self::$_settings[ $addon_name ]['autoloader_paths'])) { |
|
698 | + if ( ! empty(self::$_settings[$addon_name]['autoloader_paths'])) { |
|
699 | 699 | // setup autoloader for single file |
700 | - EEH_Autoloader::instance()->register_autoloader(self::$_settings[ $addon_name ]['autoloader_paths']); |
|
700 | + EEH_Autoloader::instance()->register_autoloader(self::$_settings[$addon_name]['autoloader_paths']); |
|
701 | 701 | } |
702 | 702 | // setup autoloaders for folders |
703 | - if (! empty(self::$_settings[ $addon_name ]['autoloader_folders'])) { |
|
704 | - foreach ((array) self::$_settings[ $addon_name ]['autoloader_folders'] as $autoloader_folder) { |
|
703 | + if ( ! empty(self::$_settings[$addon_name]['autoloader_folders'])) { |
|
704 | + foreach ((array) self::$_settings[$addon_name]['autoloader_folders'] as $autoloader_folder) { |
|
705 | 705 | EEH_Autoloader::register_autoloaders_for_each_file_in_folder($autoloader_folder); |
706 | 706 | } |
707 | 707 | } |
@@ -719,27 +719,27 @@ discard block |
||
719 | 719 | { |
720 | 720 | // register new models |
721 | 721 | if ( |
722 | - ! empty(self::$_settings[ $addon_name ]['model_paths']) |
|
723 | - || ! empty(self::$_settings[ $addon_name ]['class_paths']) |
|
722 | + ! empty(self::$_settings[$addon_name]['model_paths']) |
|
723 | + || ! empty(self::$_settings[$addon_name]['class_paths']) |
|
724 | 724 | ) { |
725 | 725 | EE_Register_Model::register( |
726 | 726 | $addon_name, |
727 | 727 | array( |
728 | - 'model_paths' => self::$_settings[ $addon_name ]['model_paths'], |
|
729 | - 'class_paths' => self::$_settings[ $addon_name ]['class_paths'], |
|
728 | + 'model_paths' => self::$_settings[$addon_name]['model_paths'], |
|
729 | + 'class_paths' => self::$_settings[$addon_name]['class_paths'], |
|
730 | 730 | ) |
731 | 731 | ); |
732 | 732 | } |
733 | 733 | // register model extensions |
734 | 734 | if ( |
735 | - ! empty(self::$_settings[ $addon_name ]['model_extension_paths']) |
|
736 | - || ! empty(self::$_settings[ $addon_name ]['class_extension_paths']) |
|
735 | + ! empty(self::$_settings[$addon_name]['model_extension_paths']) |
|
736 | + || ! empty(self::$_settings[$addon_name]['class_extension_paths']) |
|
737 | 737 | ) { |
738 | 738 | EE_Register_Model_Extensions::register( |
739 | 739 | $addon_name, |
740 | 740 | array( |
741 | - 'model_extension_paths' => self::$_settings[ $addon_name ]['model_extension_paths'], |
|
742 | - 'class_extension_paths' => self::$_settings[ $addon_name ]['class_extension_paths'], |
|
741 | + 'model_extension_paths' => self::$_settings[$addon_name]['model_extension_paths'], |
|
742 | + 'class_extension_paths' => self::$_settings[$addon_name]['class_extension_paths'], |
|
743 | 743 | ) |
744 | 744 | ); |
745 | 745 | } |
@@ -754,10 +754,10 @@ discard block |
||
754 | 754 | private static function _register_data_migration_scripts($addon_name) |
755 | 755 | { |
756 | 756 | // setup DMS |
757 | - if (! empty(self::$_settings[ $addon_name ]['dms_paths'])) { |
|
757 | + if ( ! empty(self::$_settings[$addon_name]['dms_paths'])) { |
|
758 | 758 | EE_Register_Data_Migration_Scripts::register( |
759 | 759 | $addon_name, |
760 | - array('dms_paths' => self::$_settings[ $addon_name ]['dms_paths']) |
|
760 | + array('dms_paths' => self::$_settings[$addon_name]['dms_paths']) |
|
761 | 761 | ); |
762 | 762 | } |
763 | 763 | } |
@@ -771,12 +771,12 @@ discard block |
||
771 | 771 | private static function _register_config($addon_name) |
772 | 772 | { |
773 | 773 | // if config_class is present let's register config. |
774 | - if (! empty(self::$_settings[ $addon_name ]['config_class'])) { |
|
774 | + if ( ! empty(self::$_settings[$addon_name]['config_class'])) { |
|
775 | 775 | EE_Register_Config::register( |
776 | - self::$_settings[ $addon_name ]['config_class'], |
|
776 | + self::$_settings[$addon_name]['config_class'], |
|
777 | 777 | array( |
778 | - 'config_section' => self::$_settings[ $addon_name ]['config_section'], |
|
779 | - 'config_name' => self::$_settings[ $addon_name ]['config_name'], |
|
778 | + 'config_section' => self::$_settings[$addon_name]['config_section'], |
|
779 | + 'config_name' => self::$_settings[$addon_name]['config_name'], |
|
780 | 780 | ) |
781 | 781 | ); |
782 | 782 | } |
@@ -790,10 +790,10 @@ discard block |
||
790 | 790 | */ |
791 | 791 | private static function _register_admin_pages($addon_name) |
792 | 792 | { |
793 | - if (! empty(self::$_settings[ $addon_name ]['admin_path'])) { |
|
793 | + if ( ! empty(self::$_settings[$addon_name]['admin_path'])) { |
|
794 | 794 | EE_Register_Admin_Page::register( |
795 | 795 | $addon_name, |
796 | - array('page_path' => self::$_settings[ $addon_name ]['admin_path']) |
|
796 | + array('page_path' => self::$_settings[$addon_name]['admin_path']) |
|
797 | 797 | ); |
798 | 798 | } |
799 | 799 | } |
@@ -806,10 +806,10 @@ discard block |
||
806 | 806 | */ |
807 | 807 | private static function _register_modules($addon_name) |
808 | 808 | { |
809 | - if (! empty(self::$_settings[ $addon_name ]['module_paths'])) { |
|
809 | + if ( ! empty(self::$_settings[$addon_name]['module_paths'])) { |
|
810 | 810 | EE_Register_Module::register( |
811 | 811 | $addon_name, |
812 | - array('module_paths' => self::$_settings[ $addon_name ]['module_paths']) |
|
812 | + array('module_paths' => self::$_settings[$addon_name]['module_paths']) |
|
813 | 813 | ); |
814 | 814 | } |
815 | 815 | } |
@@ -822,17 +822,17 @@ discard block |
||
822 | 822 | */ |
823 | 823 | private static function _register_shortcodes($addon_name) |
824 | 824 | { |
825 | - if (! empty(self::$_settings[ $addon_name ]['shortcode_paths']) |
|
826 | - || ! empty(self::$_settings[ $addon_name ]['shortcode_fqcns']) |
|
825 | + if ( ! empty(self::$_settings[$addon_name]['shortcode_paths']) |
|
826 | + || ! empty(self::$_settings[$addon_name]['shortcode_fqcns']) |
|
827 | 827 | ) { |
828 | 828 | EE_Register_Shortcode::register( |
829 | 829 | $addon_name, |
830 | 830 | array( |
831 | - 'shortcode_paths' => isset(self::$_settings[ $addon_name ]['shortcode_paths']) |
|
832 | - ? self::$_settings[ $addon_name ]['shortcode_paths'] |
|
831 | + 'shortcode_paths' => isset(self::$_settings[$addon_name]['shortcode_paths']) |
|
832 | + ? self::$_settings[$addon_name]['shortcode_paths'] |
|
833 | 833 | : array(), |
834 | - 'shortcode_fqcns' => isset(self::$_settings[ $addon_name ]['shortcode_fqcns']) |
|
835 | - ? self::$_settings[ $addon_name ]['shortcode_fqcns'] |
|
834 | + 'shortcode_fqcns' => isset(self::$_settings[$addon_name]['shortcode_fqcns']) |
|
835 | + ? self::$_settings[$addon_name]['shortcode_fqcns'] |
|
836 | 836 | : array(), |
837 | 837 | ) |
838 | 838 | ); |
@@ -847,10 +847,10 @@ discard block |
||
847 | 847 | */ |
848 | 848 | private static function _register_widgets($addon_name) |
849 | 849 | { |
850 | - if (! empty(self::$_settings[ $addon_name ]['widget_paths'])) { |
|
850 | + if ( ! empty(self::$_settings[$addon_name]['widget_paths'])) { |
|
851 | 851 | EE_Register_Widget::register( |
852 | 852 | $addon_name, |
853 | - array('widget_paths' => self::$_settings[ $addon_name ]['widget_paths']) |
|
853 | + array('widget_paths' => self::$_settings[$addon_name]['widget_paths']) |
|
854 | 854 | ); |
855 | 855 | } |
856 | 856 | } |
@@ -863,12 +863,12 @@ discard block |
||
863 | 863 | */ |
864 | 864 | private static function _register_capabilities($addon_name) |
865 | 865 | { |
866 | - if (! empty(self::$_settings[ $addon_name ]['capabilities'])) { |
|
866 | + if ( ! empty(self::$_settings[$addon_name]['capabilities'])) { |
|
867 | 867 | EE_Register_Capabilities::register( |
868 | 868 | $addon_name, |
869 | 869 | array( |
870 | - 'capabilities' => self::$_settings[ $addon_name ]['capabilities'], |
|
871 | - 'capability_maps' => self::$_settings[ $addon_name ]['capability_maps'], |
|
870 | + 'capabilities' => self::$_settings[$addon_name]['capabilities'], |
|
871 | + 'capability_maps' => self::$_settings[$addon_name]['capability_maps'], |
|
872 | 872 | ) |
873 | 873 | ); |
874 | 874 | } |
@@ -882,7 +882,7 @@ discard block |
||
882 | 882 | */ |
883 | 883 | private static function _register_message_types($addon_name) |
884 | 884 | { |
885 | - if (! empty(self::$_settings[ $addon_name ]['message_types'])) { |
|
885 | + if ( ! empty(self::$_settings[$addon_name]['message_types'])) { |
|
886 | 886 | add_action( |
887 | 887 | 'EE_Brewing_Regular___messages_caf', |
888 | 888 | array('EE_Register_Addon', 'register_message_types') |
@@ -899,15 +899,15 @@ discard block |
||
899 | 899 | private static function _register_custom_post_types($addon_name) |
900 | 900 | { |
901 | 901 | if ( |
902 | - ! empty(self::$_settings[ $addon_name ]['custom_post_types']) |
|
903 | - || ! empty(self::$_settings[ $addon_name ]['custom_taxonomies']) |
|
902 | + ! empty(self::$_settings[$addon_name]['custom_post_types']) |
|
903 | + || ! empty(self::$_settings[$addon_name]['custom_taxonomies']) |
|
904 | 904 | ) { |
905 | 905 | EE_Register_CPT::register( |
906 | 906 | $addon_name, |
907 | 907 | array( |
908 | - 'cpts' => self::$_settings[ $addon_name ]['custom_post_types'], |
|
909 | - 'cts' => self::$_settings[ $addon_name ]['custom_taxonomies'], |
|
910 | - 'default_terms' => self::$_settings[ $addon_name ]['default_terms'], |
|
908 | + 'cpts' => self::$_settings[$addon_name]['custom_post_types'], |
|
909 | + 'cts' => self::$_settings[$addon_name]['custom_taxonomies'], |
|
910 | + 'default_terms' => self::$_settings[$addon_name]['default_terms'], |
|
911 | 911 | ) |
912 | 912 | ); |
913 | 913 | } |
@@ -925,10 +925,10 @@ discard block |
||
925 | 925 | */ |
926 | 926 | private static function _register_payment_methods($addon_name) |
927 | 927 | { |
928 | - if (! empty(self::$_settings[ $addon_name ]['payment_method_paths'])) { |
|
928 | + if ( ! empty(self::$_settings[$addon_name]['payment_method_paths'])) { |
|
929 | 929 | EE_Register_Payment_Method::register( |
930 | 930 | $addon_name, |
931 | - array('payment_method_paths' => self::$_settings[ $addon_name ]['payment_method_paths']) |
|
931 | + array('payment_method_paths' => self::$_settings[$addon_name]['payment_method_paths']) |
|
932 | 932 | ); |
933 | 933 | } |
934 | 934 | } |
@@ -949,49 +949,49 @@ discard block |
||
949 | 949 | { |
950 | 950 | $loader = EventEspresso\core\services\loaders\LoaderFactory::getLoader(); |
951 | 951 | $addon = $loader->getShared( |
952 | - self::$_settings[ $addon_name ]['class_name'], |
|
952 | + self::$_settings[$addon_name]['class_name'], |
|
953 | 953 | array('EE_Registry::create(addon)' => true) |
954 | 954 | ); |
955 | 955 | // setter inject dep map if required |
956 | - if($addon instanceof RequiresDependencyMapInterface && $addon->dependencyMap() === null){ |
|
956 | + if ($addon instanceof RequiresDependencyMapInterface && $addon->dependencyMap() === null) { |
|
957 | 957 | $addon->setDependencyMap($loader->getShared('EE_Dependency_Map')); |
958 | 958 | } |
959 | 959 | // setter inject domain if required |
960 | - if( |
|
960 | + if ( |
|
961 | 961 | $addon instanceof RequiresDomainInterface |
962 | - && self::$_settings[ $addon_name ]['domain_fqcn'] !== '' |
|
962 | + && self::$_settings[$addon_name]['domain_fqcn'] !== '' |
|
963 | 963 | && $addon->domain() === null |
964 | - ){ |
|
964 | + ) { |
|
965 | 965 | $addon->setDomain( |
966 | 966 | $loader->getShared( |
967 | - self::$_settings[ $addon_name ]['domain_fqcn'], |
|
967 | + self::$_settings[$addon_name]['domain_fqcn'], |
|
968 | 968 | array( |
969 | - self::$_settings[ $addon_name ]['main_file_path'], |
|
970 | - self::$_settings[ $addon_name ]['version'] |
|
969 | + self::$_settings[$addon_name]['main_file_path'], |
|
970 | + self::$_settings[$addon_name]['version'] |
|
971 | 971 | ) |
972 | 972 | ) |
973 | 973 | ); |
974 | 974 | } |
975 | 975 | |
976 | 976 | $addon->set_name($addon_name); |
977 | - $addon->set_plugin_slug(self::$_settings[ $addon_name ]['plugin_slug']); |
|
978 | - $addon->set_plugin_basename(self::$_settings[ $addon_name ]['plugin_basename']); |
|
979 | - $addon->set_main_plugin_file(self::$_settings[ $addon_name ]['main_file_path']); |
|
980 | - $addon->set_plugin_action_slug(self::$_settings[ $addon_name ]['plugin_action_slug']); |
|
981 | - $addon->set_plugins_page_row(self::$_settings[ $addon_name ]['plugins_page_row']); |
|
982 | - $addon->set_version(self::$_settings[ $addon_name ]['version']); |
|
983 | - $addon->set_min_core_version(self::_effective_version(self::$_settings[ $addon_name ]['min_core_version'])); |
|
984 | - $addon->set_config_section(self::$_settings[ $addon_name ]['config_section']); |
|
985 | - $addon->set_config_class(self::$_settings[ $addon_name ]['config_class']); |
|
986 | - $addon->set_config_name(self::$_settings[ $addon_name ]['config_name']); |
|
977 | + $addon->set_plugin_slug(self::$_settings[$addon_name]['plugin_slug']); |
|
978 | + $addon->set_plugin_basename(self::$_settings[$addon_name]['plugin_basename']); |
|
979 | + $addon->set_main_plugin_file(self::$_settings[$addon_name]['main_file_path']); |
|
980 | + $addon->set_plugin_action_slug(self::$_settings[$addon_name]['plugin_action_slug']); |
|
981 | + $addon->set_plugins_page_row(self::$_settings[$addon_name]['plugins_page_row']); |
|
982 | + $addon->set_version(self::$_settings[$addon_name]['version']); |
|
983 | + $addon->set_min_core_version(self::_effective_version(self::$_settings[$addon_name]['min_core_version'])); |
|
984 | + $addon->set_config_section(self::$_settings[$addon_name]['config_section']); |
|
985 | + $addon->set_config_class(self::$_settings[$addon_name]['config_class']); |
|
986 | + $addon->set_config_name(self::$_settings[$addon_name]['config_name']); |
|
987 | 987 | //unfortunately this can't be hooked in upon construction, because we don't have |
988 | 988 | //the plugin mainfile's path upon construction. |
989 | 989 | register_deactivation_hook($addon->get_main_plugin_file(), array($addon, 'deactivation')); |
990 | 990 | // call any additional admin_callback functions during load_admin_controller hook |
991 | - if (! empty(self::$_settings[ $addon_name ]['admin_callback'])) { |
|
991 | + if ( ! empty(self::$_settings[$addon_name]['admin_callback'])) { |
|
992 | 992 | add_action( |
993 | 993 | 'AHEE__EE_System__load_controllers__load_admin_controllers', |
994 | - array($addon, self::$_settings[ $addon_name ]['admin_callback']) |
|
994 | + array($addon, self::$_settings[$addon_name]['admin_callback']) |
|
995 | 995 | ); |
996 | 996 | } |
997 | 997 | return $addon; |
@@ -1009,10 +1009,10 @@ discard block |
||
1009 | 1009 | public static function load_pue_update() |
1010 | 1010 | { |
1011 | 1011 | // load PUE client |
1012 | - require_once EE_THIRD_PARTY . 'pue' . DS . 'pue-client.php'; |
|
1012 | + require_once EE_THIRD_PARTY.'pue'.DS.'pue-client.php'; |
|
1013 | 1013 | // cycle thru settings |
1014 | 1014 | foreach (self::$_settings as $settings) { |
1015 | - if (! empty($settings['pue_options'])) { |
|
1015 | + if ( ! empty($settings['pue_options'])) { |
|
1016 | 1016 | // initiate the class and start the plugin update engine! |
1017 | 1017 | new PluginUpdateEngineChecker( |
1018 | 1018 | // host file URL |
@@ -1020,7 +1020,7 @@ discard block |
||
1020 | 1020 | // plugin slug(s) |
1021 | 1021 | array( |
1022 | 1022 | 'premium' => array('p' => $settings['pue_options']['pue_plugin_slug']), |
1023 | - 'prerelease' => array('beta' => $settings['pue_options']['pue_plugin_slug'] . '-pr'), |
|
1023 | + 'prerelease' => array('beta' => $settings['pue_options']['pue_plugin_slug'].'-pr'), |
|
1024 | 1024 | ), |
1025 | 1025 | // options |
1026 | 1026 | array( |
@@ -1049,7 +1049,7 @@ discard block |
||
1049 | 1049 | public static function register_message_types() |
1050 | 1050 | { |
1051 | 1051 | foreach (self::$_settings as $addon_name => $settings) { |
1052 | - if (! empty($settings['message_types'])) { |
|
1052 | + if ( ! empty($settings['message_types'])) { |
|
1053 | 1053 | foreach ((array) $settings['message_types'] as $message_type => $message_type_settings) { |
1054 | 1054 | EE_Register_Message_Type::register($message_type, $message_type_settings); |
1055 | 1055 | } |
@@ -1071,51 +1071,51 @@ discard block |
||
1071 | 1071 | */ |
1072 | 1072 | public static function deregister($addon_name = null) |
1073 | 1073 | { |
1074 | - if (isset(self::$_settings[ $addon_name ]['class_name'])) { |
|
1074 | + if (isset(self::$_settings[$addon_name]['class_name'])) { |
|
1075 | 1075 | try { |
1076 | 1076 | do_action('AHEE__EE_Register_Addon__deregister__before', $addon_name); |
1077 | 1077 | $class_name = self::$_settings[$addon_name]['class_name']; |
1078 | - if (! empty(self::$_settings[$addon_name]['dms_paths'])) { |
|
1078 | + if ( ! empty(self::$_settings[$addon_name]['dms_paths'])) { |
|
1079 | 1079 | // setup DMS |
1080 | 1080 | EE_Register_Data_Migration_Scripts::deregister($addon_name); |
1081 | 1081 | } |
1082 | - if (! empty(self::$_settings[$addon_name]['admin_path'])) { |
|
1082 | + if ( ! empty(self::$_settings[$addon_name]['admin_path'])) { |
|
1083 | 1083 | // register admin page |
1084 | 1084 | EE_Register_Admin_Page::deregister($addon_name); |
1085 | 1085 | } |
1086 | - if (! empty(self::$_settings[$addon_name]['module_paths'])) { |
|
1086 | + if ( ! empty(self::$_settings[$addon_name]['module_paths'])) { |
|
1087 | 1087 | // add to list of modules to be registered |
1088 | 1088 | EE_Register_Module::deregister($addon_name); |
1089 | 1089 | } |
1090 | - if (! empty(self::$_settings[$addon_name]['shortcode_paths']) |
|
1090 | + if ( ! empty(self::$_settings[$addon_name]['shortcode_paths']) |
|
1091 | 1091 | || ! empty(self::$_settings[$addon_name]['shortcode_fqcns']) |
1092 | 1092 | ) { |
1093 | 1093 | // add to list of shortcodes to be registered |
1094 | 1094 | EE_Register_Shortcode::deregister($addon_name); |
1095 | 1095 | } |
1096 | - if (! empty(self::$_settings[$addon_name]['config_class'])) { |
|
1096 | + if ( ! empty(self::$_settings[$addon_name]['config_class'])) { |
|
1097 | 1097 | // if config_class present let's register config. |
1098 | 1098 | EE_Register_Config::deregister(self::$_settings[$addon_name]['config_class']); |
1099 | 1099 | } |
1100 | - if (! empty(self::$_settings[$addon_name]['widget_paths'])) { |
|
1100 | + if ( ! empty(self::$_settings[$addon_name]['widget_paths'])) { |
|
1101 | 1101 | // add to list of widgets to be registered |
1102 | 1102 | EE_Register_Widget::deregister($addon_name); |
1103 | 1103 | } |
1104 | - if (! empty(self::$_settings[$addon_name]['model_paths']) |
|
1104 | + if ( ! empty(self::$_settings[$addon_name]['model_paths']) |
|
1105 | 1105 | || ! empty(self::$_settings[$addon_name]['class_paths']) |
1106 | 1106 | ) { |
1107 | 1107 | // add to list of shortcodes to be registered |
1108 | 1108 | EE_Register_Model::deregister($addon_name); |
1109 | 1109 | } |
1110 | - if (! empty(self::$_settings[$addon_name]['model_extension_paths']) |
|
1110 | + if ( ! empty(self::$_settings[$addon_name]['model_extension_paths']) |
|
1111 | 1111 | || ! empty(self::$_settings[$addon_name]['class_extension_paths']) |
1112 | 1112 | ) { |
1113 | 1113 | // add to list of shortcodes to be registered |
1114 | 1114 | EE_Register_Model_Extensions::deregister($addon_name); |
1115 | 1115 | } |
1116 | - if (! empty(self::$_settings[$addon_name]['message_types'])) { |
|
1116 | + if ( ! empty(self::$_settings[$addon_name]['message_types'])) { |
|
1117 | 1117 | foreach ( |
1118 | - (array)self::$_settings[$addon_name]['message_types'] as $message_type => |
|
1118 | + (array) self::$_settings[$addon_name]['message_types'] as $message_type => |
|
1119 | 1119 | $message_type_settings |
1120 | 1120 | ) { |
1121 | 1121 | EE_Register_Message_Type::deregister($message_type); |
@@ -1129,16 +1129,16 @@ discard block |
||
1129 | 1129 | EE_Register_Capabilities::deregister($addon_name); |
1130 | 1130 | } |
1131 | 1131 | //deregister custom_post_types for addon |
1132 | - if (! empty(self::$_settings[$addon_name]['custom_post_types'])) { |
|
1132 | + if ( ! empty(self::$_settings[$addon_name]['custom_post_types'])) { |
|
1133 | 1133 | EE_Register_CPT::deregister($addon_name); |
1134 | 1134 | } |
1135 | - if (! empty(self::$_settings[$addon_name]['payment_method_paths'])) { |
|
1135 | + if ( ! empty(self::$_settings[$addon_name]['payment_method_paths'])) { |
|
1136 | 1136 | EE_Register_Payment_Method::deregister($addon_name); |
1137 | 1137 | } |
1138 | 1138 | $addon = EE_Registry::instance()->getAddon($class_name); |
1139 | 1139 | if ($addon instanceof EE_Addon) { |
1140 | 1140 | remove_action( |
1141 | - 'deactivate_' . $addon->get_main_plugin_file_basename(), |
|
1141 | + 'deactivate_'.$addon->get_main_plugin_file_basename(), |
|
1142 | 1142 | array($addon, 'deactivation') |
1143 | 1143 | ); |
1144 | 1144 | remove_action( |
@@ -1159,7 +1159,7 @@ discard block |
||
1159 | 1159 | } catch (Exception $e) { |
1160 | 1160 | new ExceptionLogger($e); |
1161 | 1161 | } |
1162 | - unset(self::$_settings[ $addon_name ]); |
|
1162 | + unset(self::$_settings[$addon_name]); |
|
1163 | 1163 | do_action('AHEE__EE_Register_Addon__deregister__after', $addon_name); |
1164 | 1164 | } |
1165 | 1165 | } |
@@ -45,25 +45,25 @@ discard block |
||
45 | 45 | * @param bool $password_check |
46 | 46 | * @return \EE_Venue|null |
47 | 47 | */ |
48 | - public static function get_venue( $VNU_ID = 0, $look_in_event = TRUE, $privacy_check = true, $password_check = true ) { |
|
49 | - $VNU_ID = absint( $VNU_ID ); |
|
48 | + public static function get_venue($VNU_ID = 0, $look_in_event = TRUE, $privacy_check = true, $password_check = true) { |
|
49 | + $VNU_ID = absint($VNU_ID); |
|
50 | 50 | // do we already have the Venue you are looking for? |
51 | - if ( EEH_Venue_View::$_venue instanceof EE_Venue && $VNU_ID ) { |
|
51 | + if (EEH_Venue_View::$_venue instanceof EE_Venue && $VNU_ID) { |
|
52 | 52 | //If the Venue ID matches $VNU_ID, return the venue. |
53 | - if( EEH_Venue_View::$_venue->ID() === $VNU_ID ) { |
|
54 | - return EEH_Venue_View::_get_venue( $privacy_check ); |
|
53 | + if (EEH_Venue_View::$_venue->ID() === $VNU_ID) { |
|
54 | + return EEH_Venue_View::_get_venue($privacy_check); |
|
55 | 55 | } |
56 | 56 | //If the Venue ID does not match, try pulling a venue using $VNU_ID. |
57 | - $venue = EEM_Venue::instance()->get_one_by_ID( $VNU_ID ); |
|
58 | - if( $venue instanceof EE_Venue ) { |
|
57 | + $venue = EEM_Venue::instance()->get_one_by_ID($VNU_ID); |
|
58 | + if ($venue instanceof EE_Venue) { |
|
59 | 59 | EEH_Venue_View::$_venue = $venue; |
60 | - return EEH_Venue_View::_get_venue( $privacy_check ); |
|
60 | + return EEH_Venue_View::_get_venue($privacy_check); |
|
61 | 61 | } |
62 | 62 | } |
63 | 63 | // international newspaper? |
64 | 64 | global $post; |
65 | - if ( $post instanceof WP_Post ) { |
|
66 | - switch ( $post->post_type ) { |
|
65 | + if ($post instanceof WP_Post) { |
|
66 | + switch ($post->post_type) { |
|
67 | 67 | // if this is being called from an EE_Venue post, |
68 | 68 | // and the EE_Venue post corresponds to the EE_Venue that is being asked for, |
69 | 69 | // then we can try to just grab the attached EE_Venue object |
@@ -71,31 +71,31 @@ discard block |
||
71 | 71 | // the post already contains the related EE_Venue object AND one of the following is TRUE: |
72 | 72 | // the requested Venue ID matches the post ID OR... |
73 | 73 | // there was no specific Venue ID requested |
74 | - if ( isset( $post->EE_Venue ) && ( $VNU_ID == $post->ID || ! $VNU_ID )) { |
|
74 | + if (isset($post->EE_Venue) && ($VNU_ID == $post->ID || ! $VNU_ID)) { |
|
75 | 75 | // use existing related EE_Venue object |
76 | - EEH_Venue_View::$_venue = $post->EE_Venue; |
|
77 | - } else if ( $VNU_ID ) { |
|
76 | + EEH_Venue_View::$_venue = $post->EE_Venue; |
|
77 | + } else if ($VNU_ID) { |
|
78 | 78 | // there WAS a specific Venue ID requested, but it's NOT the current post object |
79 | - EEH_Venue_View::$_venue = EEM_Venue::instance()->get_one_by_ID( $VNU_ID ); |
|
79 | + EEH_Venue_View::$_venue = EEM_Venue::instance()->get_one_by_ID($VNU_ID); |
|
80 | 80 | } else { |
81 | 81 | // no specific Venue ID requested, so use post ID to generate EE_Venue object |
82 | - EEH_Venue_View::$_venue = EEM_Venue::instance()->get_one_by_ID( $post->ID ); |
|
82 | + EEH_Venue_View::$_venue = EEM_Venue::instance()->get_one_by_ID($post->ID); |
|
83 | 83 | } |
84 | 84 | break; |
85 | 85 | |
86 | 86 | case 'espresso_events': |
87 | - if ( $look_in_event ) { |
|
87 | + if ($look_in_event) { |
|
88 | 88 | // grab the events related venues |
89 | 89 | $venues = EEH_Venue_View::get_event_venues(); |
90 | 90 | // make sure the result is an array |
91 | - $venues = is_array( $venues ) ? $venues : array(); |
|
91 | + $venues = is_array($venues) ? $venues : array(); |
|
92 | 92 | // do we have an ID for a specific venue? |
93 | - if ( $VNU_ID ) { |
|
93 | + if ($VNU_ID) { |
|
94 | 94 | // loop thru the related venues |
95 | - foreach( $venues as $venue ) { |
|
96 | - if ( $venue instanceof EE_Venue ) { |
|
95 | + foreach ($venues as $venue) { |
|
96 | + if ($venue instanceof EE_Venue) { |
|
97 | 97 | // until we find the venue we're looking for |
98 | - if ( $venue->ID() == $VNU_ID ) { |
|
98 | + if ($venue->ID() == $VNU_ID) { |
|
99 | 99 | EEH_Venue_View::$_venue = $venue; |
100 | 100 | break; |
101 | 101 | } |
@@ -105,7 +105,7 @@ discard block |
||
105 | 105 | // then the global post is an events post and this function was called with no argument |
106 | 106 | } else { |
107 | 107 | // just grab the first related event venue |
108 | - EEH_Venue_View::$_venue = reset( $venues ); |
|
108 | + EEH_Venue_View::$_venue = reset($venues); |
|
109 | 109 | } |
110 | 110 | } |
111 | 111 | break; |
@@ -113,11 +113,11 @@ discard block |
||
113 | 113 | } |
114 | 114 | } |
115 | 115 | // now if we STILL do NOT have an EE_Venue model object, BUT we have a Venue ID... |
116 | - if ( ! EEH_Venue_View::$_venue instanceof EE_Venue && $VNU_ID ) { |
|
116 | + if ( ! EEH_Venue_View::$_venue instanceof EE_Venue && $VNU_ID) { |
|
117 | 117 | // sigh... pull it from the db |
118 | - EEH_Venue_View::$_venue = EEM_Venue::instance()->get_one_by_ID( $VNU_ID ); |
|
118 | + EEH_Venue_View::$_venue = EEM_Venue::instance()->get_one_by_ID($VNU_ID); |
|
119 | 119 | } |
120 | - return EEH_Venue_View::_get_venue( $privacy_check, $password_check ); |
|
120 | + return EEH_Venue_View::_get_venue($privacy_check, $password_check); |
|
121 | 121 | } |
122 | 122 | |
123 | 123 | |
@@ -130,13 +130,13 @@ discard block |
||
130 | 130 | * @param bool $password_check |
131 | 131 | * @return EE_Venue |
132 | 132 | */ |
133 | - protected static function _get_venue( $privacy_check = true, $password_check = true ) { |
|
133 | + protected static function _get_venue($privacy_check = true, $password_check = true) { |
|
134 | 134 | // check for private venues. |
135 | 135 | if ( |
136 | 136 | EEH_Venue_View::$_venue instanceof EE_Venue |
137 | 137 | && EEH_Venue_View::$_venue->status() == 'private' |
138 | 138 | && $privacy_check |
139 | - && ! EE_Registry::instance()->CAP->current_user_can( 'ee_read_private_venues', 'get_venues' ) |
|
139 | + && ! EE_Registry::instance()->CAP->current_user_can('ee_read_private_venues', 'get_venues') |
|
140 | 140 | ) { |
141 | 141 | return null; |
142 | 142 | } |
@@ -144,7 +144,7 @@ discard block |
||
144 | 144 | if ( |
145 | 145 | EEH_Venue_View::$_venue instanceof EE_Venue |
146 | 146 | && $password_check |
147 | - && post_password_required( EEH_Venue_View::$_venue->ID() ) |
|
147 | + && post_password_required(EEH_Venue_View::$_venue->ID()) |
|
148 | 148 | ) { |
149 | 149 | return null; |
150 | 150 | } |
@@ -161,8 +161,8 @@ discard block |
||
161 | 161 | */ |
162 | 162 | public static function get_event_venues() { |
163 | 163 | global $post; |
164 | - if ( $post->post_type == 'espresso_events' ) { |
|
165 | - if ( isset( $post->EE_Event ) && $post->EE_Event instanceof EE_Event ) { |
|
164 | + if ($post->post_type == 'espresso_events') { |
|
165 | + if (isset($post->EE_Event) && $post->EE_Event instanceof EE_Event) { |
|
166 | 166 | return $post->EE_Event->venues(); |
167 | 167 | } |
168 | 168 | } |
@@ -182,9 +182,9 @@ discard block |
||
182 | 182 | * |
183 | 183 | * @return bool|null |
184 | 184 | */ |
185 | - public static function is_venue_private( $VNU_ID = false ) { |
|
186 | - $venue = EEH_Venue_View::get_venue( $VNU_ID, true, true ); |
|
187 | - if ( ! $venue instanceof EE_Venue ) { |
|
185 | + public static function is_venue_private($VNU_ID = false) { |
|
186 | + $venue = EEH_Venue_View::get_venue($VNU_ID, true, true); |
|
187 | + if ( ! $venue instanceof EE_Venue) { |
|
188 | 188 | return null; |
189 | 189 | } |
190 | 190 | |
@@ -199,11 +199,11 @@ discard block |
||
199 | 199 | * @param bool $VNU_ID venue to check (optional). If not included will use internally derived venue object. |
200 | 200 | * @return bool |
201 | 201 | */ |
202 | - public static function is_venue_password_protected( $VNU_ID = false ) { |
|
203 | - $venue = EEH_Venue_View::get_venue( $VNU_ID, true, true, false ); |
|
202 | + public static function is_venue_password_protected($VNU_ID = false) { |
|
203 | + $venue = EEH_Venue_View::get_venue($VNU_ID, true, true, false); |
|
204 | 204 | if ( |
205 | 205 | $venue instanceof EE_Venue |
206 | - && post_password_required( $venue->ID() ) |
|
206 | + && post_password_required($venue->ID()) |
|
207 | 207 | ) { |
208 | 208 | return true; |
209 | 209 | } |
@@ -220,13 +220,13 @@ discard block |
||
220 | 220 | * |
221 | 221 | * @return string |
222 | 222 | */ |
223 | - public static function password_protected_venue_form( $VNU_ID = false ) { |
|
224 | - $venue = EEH_Venue_View::get_venue( $VNU_ID, true, true, false ); |
|
223 | + public static function password_protected_venue_form($VNU_ID = false) { |
|
224 | + $venue = EEH_Venue_View::get_venue($VNU_ID, true, true, false); |
|
225 | 225 | if ( |
226 | 226 | $venue instanceof EE_Venue |
227 | - && post_password_required( $venue->ID() ) |
|
227 | + && post_password_required($venue->ID()) |
|
228 | 228 | ) { |
229 | - return get_the_password_form( $venue->ID() ); |
|
229 | + return get_the_password_form($venue->ID()); |
|
230 | 230 | } |
231 | 231 | return ''; |
232 | 232 | } |
@@ -240,9 +240,9 @@ discard block |
||
240 | 240 | * @param int $VNU_ID |
241 | 241 | * @return string |
242 | 242 | */ |
243 | - public static function venue_description( $VNU_ID = 0 ) { |
|
244 | - $venue = EEH_Venue_View::get_venue( $VNU_ID ); |
|
245 | - if ( $venue instanceof EE_Venue ) { |
|
243 | + public static function venue_description($VNU_ID = 0) { |
|
244 | + $venue = EEH_Venue_View::get_venue($VNU_ID); |
|
245 | + if ($venue instanceof EE_Venue) { |
|
246 | 246 | return$venue->description(); |
247 | 247 | } |
248 | 248 | return ''; |
@@ -257,12 +257,12 @@ discard block |
||
257 | 257 | * @param int $VNU_ID |
258 | 258 | * @return string |
259 | 259 | */ |
260 | - public static function venue_excerpt( $VNU_ID = 0 ) { |
|
261 | - $venue = EEH_Venue_View::get_venue( $VNU_ID ); |
|
262 | - if ( $venue instanceof EE_Venue ) { |
|
260 | + public static function venue_excerpt($VNU_ID = 0) { |
|
261 | + $venue = EEH_Venue_View::get_venue($VNU_ID); |
|
262 | + if ($venue instanceof EE_Venue) { |
|
263 | 263 | $excerpt = $venue->excerpt() != NULL && $venue->excerpt() ? $venue->excerpt() : $venue->description(); |
264 | - $venue_link = ' ' . EEH_Venue_View::venue_details_link( $venue->ID(), __( 'more', 'event_espresso' ) . '…' ); |
|
265 | - return ! empty( $excerpt ) ? wp_trim_words( $excerpt, 25, '' ) . $venue_link : ''; |
|
264 | + $venue_link = ' '.EEH_Venue_View::venue_details_link($venue->ID(), __('more', 'event_espresso').'…'); |
|
265 | + return ! empty($excerpt) ? wp_trim_words($excerpt, 25, '').$venue_link : ''; |
|
266 | 266 | } |
267 | 267 | return ''; |
268 | 268 | } |
@@ -277,22 +277,22 @@ discard block |
||
277 | 277 | * @param bool $hide_uncategorized |
278 | 278 | * @return string |
279 | 279 | */ |
280 | - public static function venue_categories( $VNU_ID = 0, $hide_uncategorized = TRUE ) { |
|
280 | + public static function venue_categories($VNU_ID = 0, $hide_uncategorized = TRUE) { |
|
281 | 281 | $category_links = array(); |
282 | - $venue = EEH_Venue_View::get_venue( $VNU_ID ); |
|
283 | - if ( $venue instanceof EE_Venue ) { |
|
282 | + $venue = EEH_Venue_View::get_venue($VNU_ID); |
|
283 | + if ($venue instanceof EE_Venue) { |
|
284 | 284 | // get category terms |
285 | - if ( $venue_categories = get_the_terms( $venue->ID(), 'espresso_venue_categories' )) { |
|
285 | + if ($venue_categories = get_the_terms($venue->ID(), 'espresso_venue_categories')) { |
|
286 | 286 | // loop thru terms and create links |
287 | - foreach ( $venue_categories as $term ) { |
|
288 | - $url = get_term_link( $term, 'espresso_venue_categories' ); |
|
289 | - if ( ! is_wp_error( $url ) && (( $hide_uncategorized && strtolower( $term->name ) != __( 'uncategorized', 'event_espresso' )) || ! $hide_uncategorized )) { |
|
290 | - $category_links[] = '<a href="' . esc_url( $url ) . '" rel="tag">' . $term->name . '</a> '; |
|
287 | + foreach ($venue_categories as $term) { |
|
288 | + $url = get_term_link($term, 'espresso_venue_categories'); |
|
289 | + if ( ! is_wp_error($url) && (($hide_uncategorized && strtolower($term->name) != __('uncategorized', 'event_espresso')) || ! $hide_uncategorized)) { |
|
290 | + $category_links[] = '<a href="'.esc_url($url).'" rel="tag">'.$term->name.'</a> '; |
|
291 | 291 | } |
292 | 292 | } |
293 | 293 | } |
294 | 294 | } |
295 | - return implode( ', ', $category_links ); |
|
295 | + return implode(', ', $category_links); |
|
296 | 296 | } |
297 | 297 | |
298 | 298 | |
@@ -307,10 +307,10 @@ discard block |
||
307 | 307 | * @param bool $add_wrapper |
308 | 308 | * @return string |
309 | 309 | */ |
310 | - public static function venue_address( $type = 'multiline', $VNU_ID = 0, $use_schema = true, $add_wrapper = true ) { |
|
311 | - $venue = EEH_Venue_View::get_venue( $VNU_ID ); |
|
312 | - if ( $venue instanceof EE_Venue ) { |
|
313 | - return EEH_Address::format( $venue, $type, $use_schema, $add_wrapper ); |
|
310 | + public static function venue_address($type = 'multiline', $VNU_ID = 0, $use_schema = true, $add_wrapper = true) { |
|
311 | + $venue = EEH_Venue_View::get_venue($VNU_ID); |
|
312 | + if ($venue instanceof EE_Venue) { |
|
313 | + return EEH_Address::format($venue, $type, $use_schema, $add_wrapper); |
|
314 | 314 | } |
315 | 315 | return ''; |
316 | 316 | } |
@@ -324,10 +324,10 @@ discard block |
||
324 | 324 | * @param int $VNU_ID |
325 | 325 | * @return bool|string |
326 | 326 | */ |
327 | - public static function venue_has_address( $VNU_ID = 0 ) { |
|
328 | - $venue = EEH_Venue_View::get_venue( $VNU_ID ); |
|
329 | - if ( $venue instanceof EE_Venue ) { |
|
330 | - return EEH_Address::format( $venue, 'inline', FALSE, FALSE ); |
|
327 | + public static function venue_has_address($VNU_ID = 0) { |
|
328 | + $venue = EEH_Venue_View::get_venue($VNU_ID); |
|
329 | + if ($venue instanceof EE_Venue) { |
|
330 | + return EEH_Address::format($venue, 'inline', FALSE, FALSE); |
|
331 | 331 | } |
332 | 332 | return false; |
333 | 333 | } |
@@ -342,30 +342,30 @@ discard block |
||
342 | 342 | * @param int $VNU_ID |
343 | 343 | * @return string |
344 | 344 | */ |
345 | - public static function venue_name( $link_to = 'details', $VNU_ID = 0 ) { |
|
346 | - $venue = EEH_Venue_View::get_venue( $VNU_ID ); |
|
347 | - if ( $venue instanceof EE_Venue ) { |
|
345 | + public static function venue_name($link_to = 'details', $VNU_ID = 0) { |
|
346 | + $venue = EEH_Venue_View::get_venue($VNU_ID); |
|
347 | + if ($venue instanceof EE_Venue) { |
|
348 | 348 | $venue_name = apply_filters( |
349 | 349 | 'FHEE__EEH_Venue__venue_name__append_private_venue_name', |
350 | 350 | EEH_Venue_View::is_venue_private() |
351 | - ? EEH_Venue_View::$_venue->name() . " " . __( '(Private)', 'event_espresso' ) |
|
351 | + ? EEH_Venue_View::$_venue->name()." ".__('(Private)', 'event_espresso') |
|
352 | 352 | : EEH_Venue_View::$_venue->name(), |
353 | 353 | EEH_Venue_View::$_venue |
354 | 354 | ); |
355 | - $venue_name = EEH_Schema::name( $venue_name ); |
|
355 | + $venue_name = EEH_Schema::name($venue_name); |
|
356 | 356 | |
357 | 357 | //if venue is trashed then ignore the "link to" setting because the venue is trashed. |
358 | - if ( $venue->get('status') == 'trash' ) { |
|
358 | + if ($venue->get('status') == 'trash') { |
|
359 | 359 | $link_to = ''; |
360 | 360 | } |
361 | - switch( $link_to ) { |
|
361 | + switch ($link_to) { |
|
362 | 362 | |
363 | 363 | case 'details' : |
364 | - return EEH_Venue_View::venue_details_link( $venue->ID(), $venue_name ); |
|
364 | + return EEH_Venue_View::venue_details_link($venue->ID(), $venue_name); |
|
365 | 365 | break; |
366 | 366 | |
367 | 367 | case 'website' : |
368 | - return EEH_Venue_View::venue_website_link( $venue->ID(), $venue_name ); |
|
368 | + return EEH_Venue_View::venue_website_link($venue->ID(), $venue_name); |
|
369 | 369 | break; |
370 | 370 | |
371 | 371 | default : |
@@ -385,10 +385,10 @@ discard block |
||
385 | 385 | * @param string $text |
386 | 386 | * @return string |
387 | 387 | */ |
388 | - public static function venue_details_link( $VNU_ID = 0, $text = '' ) { |
|
389 | - $venue = EEH_Venue_View::get_venue( $VNU_ID ); |
|
390 | - if ( $venue instanceof EE_Venue ) { |
|
391 | - return EEH_Schema::url( get_permalink( $venue->ID() ), $text ); |
|
388 | + public static function venue_details_link($VNU_ID = 0, $text = '') { |
|
389 | + $venue = EEH_Venue_View::get_venue($VNU_ID); |
|
390 | + if ($venue instanceof EE_Venue) { |
|
391 | + return EEH_Schema::url(get_permalink($venue->ID()), $text); |
|
392 | 392 | } |
393 | 393 | return ''; |
394 | 394 | } |
@@ -403,12 +403,12 @@ discard block |
||
403 | 403 | * @param string $text |
404 | 404 | * @return string |
405 | 405 | */ |
406 | - public static function venue_website_link( $VNU_ID = 0, $text = '' ) { |
|
407 | - $venue = EEH_Venue_View::get_venue( $VNU_ID ); |
|
408 | - if ( $venue instanceof EE_Venue ) { |
|
406 | + public static function venue_website_link($VNU_ID = 0, $text = '') { |
|
407 | + $venue = EEH_Venue_View::get_venue($VNU_ID); |
|
408 | + if ($venue instanceof EE_Venue) { |
|
409 | 409 | $url = $venue->venue_url(); |
410 | - $text = ! empty( $text ) ? $text : $url; |
|
411 | - return ! empty( $url ) ? EEH_Schema::url( $url, $text ) : ''; |
|
410 | + $text = ! empty($text) ? $text : $url; |
|
411 | + return ! empty($url) ? EEH_Schema::url($url, $text) : ''; |
|
412 | 412 | } |
413 | 413 | return ''; |
414 | 414 | } |
@@ -422,10 +422,10 @@ discard block |
||
422 | 422 | * @param int $VNU_ID |
423 | 423 | * @return string |
424 | 424 | */ |
425 | - public static function venue_phone( $VNU_ID = 0) { |
|
426 | - $venue = EEH_Venue_View::get_venue( $VNU_ID ); |
|
427 | - if ( $venue instanceof EE_Venue ) { |
|
428 | - return EEH_Schema::telephone( $venue->phone() ); |
|
425 | + public static function venue_phone($VNU_ID = 0) { |
|
426 | + $venue = EEH_Venue_View::get_venue($VNU_ID); |
|
427 | + if ($venue instanceof EE_Venue) { |
|
428 | + return EEH_Schema::telephone($venue->phone()); |
|
429 | 429 | } |
430 | 430 | return ''; |
431 | 431 | } |
@@ -441,48 +441,48 @@ discard block |
||
441 | 441 | * @param array $gmap map options |
442 | 442 | * @return string |
443 | 443 | */ |
444 | - public static function venue_gmap( $VNU_ID = 0, $map_ID = FALSE, $gmap = array() ) { |
|
444 | + public static function venue_gmap($VNU_ID = 0, $map_ID = FALSE, $gmap = array()) { |
|
445 | 445 | |
446 | - $venue = EEH_Venue_View::get_venue( $VNU_ID ); |
|
447 | - if ( $venue instanceof EE_Venue ) { |
|
446 | + $venue = EEH_Venue_View::get_venue($VNU_ID); |
|
447 | + if ($venue instanceof EE_Venue) { |
|
448 | 448 | // check for global espresso_events post and use it's ID if no map_ID is set |
449 | 449 | global $post; |
450 | - $map_ID = empty( $map_ID ) && $post->post_type == 'espresso_events' ? $post->ID : $map_ID; |
|
450 | + $map_ID = empty($map_ID) && $post->post_type == 'espresso_events' ? $post->ID : $map_ID; |
|
451 | 451 | // grab map settings |
452 | 452 | $map_cfg = EE_Registry::instance()->CFG->map_settings; |
453 | 453 | // are maps enabled ? |
454 | - if ( $map_cfg->use_google_maps && $venue->enable_for_gmap() ) { |
|
454 | + if ($map_cfg->use_google_maps && $venue->enable_for_gmap()) { |
|
455 | 455 | |
456 | 456 | $details_page = is_single(); |
457 | 457 | $options = array(); |
458 | - $options['map_ID'] = $map_ID && $map_ID != $venue->ID() ? $map_ID . '-' . $venue->ID()/* . '-' . $static_map_id*/ : $venue->ID()/* . '-' . $static_map_id*/; |
|
458 | + $options['map_ID'] = $map_ID && $map_ID != $venue->ID() ? $map_ID.'-'.$venue->ID()/* . '-' . $static_map_id*/ : $venue->ID()/* . '-' . $static_map_id*/; |
|
459 | 459 | |
460 | - $options['location'] = EEH_Address::format( $venue, 'inline', FALSE, FALSE ); |
|
460 | + $options['location'] = EEH_Address::format($venue, 'inline', FALSE, FALSE); |
|
461 | 461 | |
462 | 462 | $options['ee_map_width'] = $details_page ? $map_cfg->event_details_map_width : $map_cfg->event_list_map_width; |
463 | - $options['ee_map_width'] = isset( $gmap['ee_map_width'] ) && ! empty( $gmap['ee_map_width'] ) ? $gmap['ee_map_width'] : $options['ee_map_width']; |
|
463 | + $options['ee_map_width'] = isset($gmap['ee_map_width']) && ! empty($gmap['ee_map_width']) ? $gmap['ee_map_width'] : $options['ee_map_width']; |
|
464 | 464 | |
465 | 465 | $options['ee_map_height'] = $details_page ? $map_cfg->event_details_map_height : $map_cfg->event_list_map_height; |
466 | - $options['ee_map_height'] = isset( $gmap['ee_map_height'] ) && ! empty( $gmap['ee_map_height'] ) ? $gmap['ee_map_height'] : $options['ee_map_height']; |
|
466 | + $options['ee_map_height'] = isset($gmap['ee_map_height']) && ! empty($gmap['ee_map_height']) ? $gmap['ee_map_height'] : $options['ee_map_height']; |
|
467 | 467 | |
468 | 468 | $options['ee_map_zoom'] = $details_page ? $map_cfg->event_details_map_zoom : $map_cfg->event_list_map_zoom; |
469 | - $options['ee_map_zoom'] = isset( $gmap['ee_map_zoom'] ) && ! empty( $gmap['ee_map_zoom'] ) ? $gmap['ee_map_zoom'] : $options['ee_map_zoom']; |
|
469 | + $options['ee_map_zoom'] = isset($gmap['ee_map_zoom']) && ! empty($gmap['ee_map_zoom']) ? $gmap['ee_map_zoom'] : $options['ee_map_zoom']; |
|
470 | 470 | |
471 | 471 | $options['ee_map_nav_display'] = $details_page ? $map_cfg->event_details_display_nav : $map_cfg->event_list_display_nav; |
472 | - $options['ee_map_nav_display'] = isset( $gmap['ee_map_nav_display'] ) && ! empty( $gmap['ee_map_nav_display'] ) ? 'true' : $options['ee_map_nav_display'];; |
|
472 | + $options['ee_map_nav_display'] = isset($gmap['ee_map_nav_display']) && ! empty($gmap['ee_map_nav_display']) ? 'true' : $options['ee_map_nav_display']; ; |
|
473 | 473 | |
474 | 474 | $options['ee_map_nav_size'] = $details_page ? $map_cfg->event_details_nav_size : $map_cfg->event_list_nav_size; |
475 | - $options['ee_map_nav_size'] = isset( $gmap['ee_map_nav_size'] ) && ! empty( $gmap['ee_map_nav_size'] )? $gmap['ee_map_nav_size'] : $options['ee_map_nav_size']; |
|
475 | + $options['ee_map_nav_size'] = isset($gmap['ee_map_nav_size']) && ! empty($gmap['ee_map_nav_size']) ? $gmap['ee_map_nav_size'] : $options['ee_map_nav_size']; |
|
476 | 476 | |
477 | 477 | $options['ee_map_type_control'] = $details_page ? $map_cfg->event_details_control_type : $map_cfg->event_list_control_type; |
478 | - $options['ee_map_type_control'] = isset( $gmap['ee_map_type_control'] ) && ! empty( $gmap['ee_map_type_control'] )? $gmap['ee_map_type_control'] : $options['ee_map_type_control']; |
|
478 | + $options['ee_map_type_control'] = isset($gmap['ee_map_type_control']) && ! empty($gmap['ee_map_type_control']) ? $gmap['ee_map_type_control'] : $options['ee_map_type_control']; |
|
479 | 479 | |
480 | 480 | $options['ee_map_align'] = $details_page ? $map_cfg->event_details_map_align : $map_cfg->event_list_map_align; |
481 | - $options['ee_map_align'] = isset( $gmap['ee_map_align'] ) && ! empty( $gmap['ee_map_align'] )? $gmap['ee_map_align'] : $options['ee_map_align']; |
|
481 | + $options['ee_map_align'] = isset($gmap['ee_map_align']) && ! empty($gmap['ee_map_align']) ? $gmap['ee_map_align'] : $options['ee_map_align']; |
|
482 | 482 | |
483 | - $options['ee_static_url'] = isset( $gmap['ee_static_url'] ) && ! empty( $gmap['ee_static_url'] ) ? (bool)absint( $gmap['ee_static_url'] ) : $venue->google_map_link(); |
|
483 | + $options['ee_static_url'] = isset($gmap['ee_static_url']) && ! empty($gmap['ee_static_url']) ? (bool) absint($gmap['ee_static_url']) : $venue->google_map_link(); |
|
484 | 484 | |
485 | - return EEH_Maps::google_map( $options ); |
|
485 | + return EEH_Maps::google_map($options); |
|
486 | 486 | |
487 | 487 | } |
488 | 488 | } |
@@ -497,7 +497,7 @@ discard block |
||
497 | 497 | * @param array $atts like EEH_Maps::google_map_link |
498 | 498 | * @return string |
499 | 499 | */ |
500 | - public static function espresso_google_static_map( EE_Venue $venue, $atts = array() ){ |
|
500 | + public static function espresso_google_static_map(EE_Venue $venue, $atts = array()) { |
|
501 | 501 | $state = $venue->state_obj(); |
502 | 502 | $country = $venue->country_obj(); |
503 | 503 | $atts = shortcode_atts( |
@@ -528,23 +528,23 @@ discard block |
||
528 | 528 | * @param string $after |
529 | 529 | * @return string |
530 | 530 | */ |
531 | - public static function edit_venue_link( $VNU_ID = 0, $link = '', $before = '<p class="edit-venue-lnk small-txt">', $after = '</p>' ) { |
|
532 | - $venue = EEH_Venue_View::get_venue( $VNU_ID ); |
|
533 | - if ( $venue instanceof EE_Venue ) { |
|
531 | + public static function edit_venue_link($VNU_ID = 0, $link = '', $before = '<p class="edit-venue-lnk small-txt">', $after = '</p>') { |
|
532 | + $venue = EEH_Venue_View::get_venue($VNU_ID); |
|
533 | + if ($venue instanceof EE_Venue) { |
|
534 | 534 | // can the user edit this post ? |
535 | - if ( current_user_can( 'edit_post', $venue->ID() )) { |
|
535 | + if (current_user_can('edit_post', $venue->ID())) { |
|
536 | 536 | // set link text |
537 | - $link = ! empty( $link ) ? $link : __('edit this venue'); |
|
537 | + $link = ! empty($link) ? $link : __('edit this venue'); |
|
538 | 538 | // generate nonce |
539 | - $nonce = wp_create_nonce( 'edit_nonce' ); |
|
539 | + $nonce = wp_create_nonce('edit_nonce'); |
|
540 | 540 | // generate url to venue editor for this venue |
541 | - $url = add_query_arg( array( 'page' => 'espresso_venues', 'action' => 'edit', 'post' => $venue->ID(), 'edit_nonce' => $nonce ), admin_url( 'admin.php' ) ); |
|
541 | + $url = add_query_arg(array('page' => 'espresso_venues', 'action' => 'edit', 'post' => $venue->ID(), 'edit_nonce' => $nonce), admin_url('admin.php')); |
|
542 | 542 | // get edit CPT text |
543 | - $post_type_obj = get_post_type_object( 'espresso_venues' ); |
|
543 | + $post_type_obj = get_post_type_object('espresso_venues'); |
|
544 | 544 | // build final link html |
545 | - $link = '<a class="post-edit-link" href="' . $url . '" title="' . esc_attr( $post_type_obj->labels->edit_item ) . '">' . $link . '</a>'; |
|
545 | + $link = '<a class="post-edit-link" href="'.$url.'" title="'.esc_attr($post_type_obj->labels->edit_item).'">'.$link.'</a>'; |
|
546 | 546 | // put it all together |
547 | - return $before . apply_filters( 'edit_post_link', $link, $venue->ID() ) . $after; |
|
547 | + return $before.apply_filters('edit_post_link', $link, $venue->ID()).$after; |
|
548 | 548 | } |
549 | 549 | } |
550 | 550 | return ''; |
@@ -2,7 +2,7 @@ discard block |
||
2 | 2 | use \EventEspresso\core\exceptions\SendMessageException; |
3 | 3 | |
4 | 4 | if (! defined('EVENT_ESPRESSO_VERSION')) { |
5 | - exit('No direct script access allowed'); |
|
5 | + exit('No direct script access allowed'); |
|
6 | 6 | } |
7 | 7 | |
8 | 8 | /** |
@@ -18,693 +18,693 @@ discard block |
||
18 | 18 | { |
19 | 19 | |
20 | 20 | |
21 | - /** |
|
22 | - * @type string reference for sending action |
|
23 | - */ |
|
24 | - const action_sending = 'sending'; |
|
25 | - |
|
26 | - /** |
|
27 | - * @type string reference for generation action |
|
28 | - */ |
|
29 | - const action_generating = 'generation'; |
|
30 | - |
|
31 | - |
|
32 | - /** |
|
33 | - * @type EE_Message_Repository $_message_repository |
|
34 | - */ |
|
35 | - protected $_message_repository; |
|
36 | - |
|
37 | - /** |
|
38 | - * Sets the limit of how many messages are generated per process. |
|
39 | - * |
|
40 | - * @type int |
|
41 | - */ |
|
42 | - protected $_batch_count; |
|
43 | - |
|
44 | - |
|
45 | - /** |
|
46 | - * This is an array of cached queue items being stored in this object. |
|
47 | - * The array keys will be the ID of the EE_Message in the db if saved. If the EE_Message |
|
48 | - * is not saved to the db then its key will be an increment of "UNS" (i.e. UNS1, UNS2 etc.) |
|
49 | - * |
|
50 | - * @type EE_Message[] |
|
51 | - */ |
|
52 | - protected $_cached_queue_items; |
|
53 | - |
|
54 | - /** |
|
55 | - * Tracks the number of unsaved queue items. |
|
56 | - * |
|
57 | - * @type int |
|
58 | - */ |
|
59 | - protected $_unsaved_count = 0; |
|
60 | - |
|
61 | - /** |
|
62 | - * used to record if a do_messenger_hooks has already been called for a message type. This prevents multiple |
|
63 | - * hooks getting fired if users have setup their action/filter hooks to prevent duplicate calls. |
|
64 | - * |
|
65 | - * @type array |
|
66 | - */ |
|
67 | - protected $_did_hook = array(); |
|
68 | - |
|
69 | - |
|
70 | - /** |
|
71 | - * Constructor. |
|
72 | - * Setup all the initial properties and load a EE_Message_Repository. |
|
73 | - * |
|
74 | - * @param \EE_Message_Repository $message_repository |
|
75 | - */ |
|
76 | - public function __construct(EE_Message_Repository $message_repository) |
|
77 | - { |
|
78 | - $this->_batch_count = apply_filters('FHEE__EE_Messages_Queue___batch_count', 50); |
|
79 | - $this->_message_repository = $message_repository; |
|
80 | - } |
|
81 | - |
|
82 | - |
|
83 | - /** |
|
84 | - * Add a EE_Message object to the queue |
|
85 | - * |
|
86 | - * @param EE_Message $message |
|
87 | - * @param array $data This will be an array of data to attach to the object in the repository. If the |
|
88 | - * object is persisted, this data will be saved on an extra_meta object related to |
|
89 | - * EE_Message. |
|
90 | - * @param bool $preview Whether this EE_Message represents a preview or not. |
|
91 | - * @param bool $test_send This indicates whether to do a test send instead of actual send. A test send will |
|
92 | - * use the messenger send method but typically is based on preview data. |
|
93 | - * @return bool Whether the message was successfully added to the repository or not. |
|
94 | - */ |
|
95 | - public function add(EE_Message $message, $data = array(), $preview = false, $test_send = false) |
|
96 | - { |
|
97 | - $data['preview'] = $preview; |
|
98 | - $data['test_send'] = $test_send; |
|
99 | - return $this->_message_repository->add($message, $data); |
|
100 | - } |
|
101 | - |
|
102 | - |
|
103 | - /** |
|
104 | - * Removes EE_Message from _queue that matches the given EE_Message if the pointer is on a matching EE_Message |
|
105 | - * |
|
106 | - * @param EE_Message $message The message to detach from the queue |
|
107 | - * @param bool $persist This flag indicates whether to attempt to delete the object from the db as well. |
|
108 | - * @return bool |
|
109 | - */ |
|
110 | - public function remove(EE_Message $message, $persist = false) |
|
111 | - { |
|
112 | - if ($persist && $this->_message_repository->current() !== $message) { |
|
113 | - //get pointer on right message |
|
114 | - if ($this->_message_repository->has($message)) { |
|
115 | - $this->_message_repository->rewind(); |
|
116 | - while ($this->_message_repository->valid()) { |
|
117 | - if ($this->_message_repository->current() === $message) { |
|
118 | - break; |
|
119 | - } |
|
120 | - $this->_message_repository->next(); |
|
121 | - } |
|
122 | - } else { |
|
123 | - return false; |
|
124 | - } |
|
125 | - } |
|
126 | - return $persist ? $this->_message_repository->delete() : $this->_message_repository->remove($message); |
|
127 | - } |
|
128 | - |
|
129 | - |
|
130 | - /** |
|
131 | - * Persists all queued EE_Message objects to the db. |
|
132 | - * |
|
133 | - * @param bool $do_hooks_only @see EE_Message_Repository::saveAll |
|
134 | - * @return array @see EE_Messages_Repository::saveAll() for return values. |
|
135 | - */ |
|
136 | - public function save($do_hooks_only = false) |
|
137 | - { |
|
138 | - return $this->_message_repository->saveAll($do_hooks_only); |
|
139 | - } |
|
140 | - |
|
141 | - |
|
142 | - /** |
|
143 | - * @return EE_Message_Repository |
|
144 | - */ |
|
145 | - public function get_message_repository() |
|
146 | - { |
|
147 | - return $this->_message_repository; |
|
148 | - } |
|
149 | - |
|
150 | - |
|
151 | - /** |
|
152 | - * This does the following things: |
|
153 | - * 1. Checks if there is a lock on generation (prevents race conditions). If there is a lock then exits (return |
|
154 | - * false). |
|
155 | - * 2. If no lock, sets lock, then retrieves a batch of non-generated EE_Message objects and adds to queue |
|
156 | - * 3. Returns bool. True = batch ready. False = no batch ready (or nothing available for generation). |
|
157 | - * Note: Callers should make sure they release the lock otherwise batch generation will be prevented from |
|
158 | - * continuing. The lock is on a transient that is set to expire after one hour as a fallback in case locks are not |
|
159 | - * removed. |
|
160 | - * |
|
161 | - * @return bool true if successfully retrieved batch, false no batch ready. |
|
162 | - */ |
|
163 | - public function get_batch_to_generate() |
|
164 | - { |
|
165 | - if ($this->is_locked(EE_Messages_Queue::action_generating)) { |
|
166 | - return false; |
|
167 | - } |
|
168 | - |
|
169 | - //lock batch generation to prevent race conditions. |
|
170 | - $this->lock_queue(EE_Messages_Queue::action_generating); |
|
171 | - |
|
172 | - $query_args = array( |
|
173 | - // key 0 = where conditions |
|
174 | - 0 => array('STS_ID' => EEM_Message::status_incomplete), |
|
175 | - 'order_by' => $this->_get_priority_orderby(), |
|
176 | - 'limit' => $this->_batch_count, |
|
177 | - ); |
|
178 | - $messages = EEM_Message::instance()->get_all($query_args); |
|
179 | - |
|
180 | - if ( ! $messages) { |
|
181 | - return false; //nothing to generate |
|
182 | - } |
|
183 | - |
|
184 | - foreach ($messages as $message) { |
|
185 | - if ($message instanceof EE_Message) { |
|
186 | - $data = $message->all_extra_meta_array(); |
|
187 | - $this->add($message, $data); |
|
188 | - } |
|
189 | - } |
|
190 | - return true; |
|
191 | - } |
|
192 | - |
|
193 | - |
|
194 | - /** |
|
195 | - * This does the following things: |
|
196 | - * 1. Checks if there is a lock on sending (prevents race conditions). If there is a lock then exits (return |
|
197 | - * false). |
|
198 | - * 2. Grabs the allowed number of messages to send for the rate_limit. If cannot send any more messages, then |
|
199 | - * return false. |
|
200 | - * 2. If no lock, sets lock, then retrieves a batch of EE_Message objects, adds to queue and triggers execution. |
|
201 | - * 3. On success or unsuccessful send, sets status appropriately. |
|
202 | - * 4. Saves messages via the queue |
|
203 | - * 5. Releases lock. |
|
204 | - * |
|
205 | - * @return bool true on success, false if something preventing sending (i.e. lock set). Note: true does not |
|
206 | - * necessarily mean that all messages were successfully sent. It just means that this method |
|
207 | - * successfully completed. On true, client may want to call $this->count_STS_in_queue( |
|
208 | - * EEM_Message::status_failed ) to see if any failed EE_Message objects. Each failed message object |
|
209 | - * will also have a saved error message on it to assist with notifying user. |
|
210 | - */ |
|
211 | - public function get_to_send_batch_and_send() |
|
212 | - { |
|
213 | - $rate_limit = $this->get_rate_limit(); |
|
214 | - if ($rate_limit < 1 || $this->is_locked(EE_Messages_Queue::action_sending)) { |
|
215 | - return false; |
|
216 | - } |
|
217 | - |
|
218 | - $this->lock_queue(EE_Messages_Queue::action_sending); |
|
219 | - |
|
220 | - $batch = $this->_batch_count < $rate_limit ? $this->_batch_count : $rate_limit; |
|
221 | - |
|
222 | - $query_args = array( |
|
223 | - // key 0 = where conditions |
|
224 | - 0 => array('STS_ID' => array('IN', EEM_Message::instance()->stati_indicating_to_send())), |
|
225 | - 'order_by' => $this->_get_priority_orderby(), |
|
226 | - 'limit' => $batch, |
|
227 | - ); |
|
228 | - |
|
229 | - $messages_to_send = EEM_Message::instance()->get_all($query_args); |
|
230 | - |
|
231 | - |
|
232 | - //any to send? |
|
233 | - if ( ! $messages_to_send) { |
|
234 | - $this->unlock_queue(EE_Messages_Queue::action_sending); |
|
235 | - return false; |
|
236 | - } |
|
237 | - |
|
238 | - $queue_count = 0; |
|
239 | - |
|
240 | - //add to queue. |
|
241 | - foreach ($messages_to_send as $message) { |
|
242 | - if ($message instanceof EE_Message) { |
|
243 | - $queue_count++; |
|
244 | - $this->add($message); |
|
245 | - } |
|
246 | - } |
|
247 | - |
|
248 | - //send messages (this also updates the rate limit) |
|
249 | - $this->execute(); |
|
250 | - |
|
251 | - //release lock |
|
252 | - $this->unlock_queue(EE_Messages_Queue::action_sending); |
|
253 | - //update rate limit |
|
254 | - $this->set_rate_limit($queue_count); |
|
255 | - return true; |
|
256 | - } |
|
257 | - |
|
258 | - |
|
259 | - /** |
|
260 | - * Locks the queue so that no other queues can call the "batch" methods. |
|
261 | - * |
|
262 | - * @param string $type The type of queue being locked. |
|
263 | - */ |
|
264 | - public function lock_queue($type = EE_Messages_Queue::action_generating) |
|
265 | - { |
|
266 | - update_option($this->_get_lock_key($type), $this->_get_lock_expiry($type)); |
|
267 | - } |
|
268 | - |
|
269 | - |
|
270 | - /** |
|
271 | - * Unlocks the queue so that batch methods can be used. |
|
272 | - * |
|
273 | - * @param string $type The type of queue being unlocked. |
|
274 | - */ |
|
275 | - public function unlock_queue($type = EE_Messages_Queue::action_generating) |
|
276 | - { |
|
277 | - delete_option($this->_get_lock_key($type)); |
|
278 | - } |
|
279 | - |
|
280 | - |
|
281 | - /** |
|
282 | - * Retrieve the key used for the lock transient. |
|
283 | - * |
|
284 | - * @param string $type The type of lock. |
|
285 | - * @return string |
|
286 | - */ |
|
287 | - protected function _get_lock_key($type = EE_Messages_Queue::action_generating) |
|
288 | - { |
|
289 | - return '_ee_lock_' . $type; |
|
290 | - } |
|
291 | - |
|
292 | - |
|
293 | - /** |
|
294 | - * Retrieve the expiry time for the lock transient. |
|
295 | - * |
|
296 | - * @param string $type The type of lock |
|
297 | - * @return int time to expiry in seconds. |
|
298 | - */ |
|
299 | - protected function _get_lock_expiry($type = EE_Messages_Queue::action_generating) |
|
300 | - { |
|
301 | - return time() + (int) apply_filters('FHEE__EE_Messages_Queue__lock_expiry', HOUR_IN_SECONDS, $type); |
|
302 | - } |
|
303 | - |
|
304 | - |
|
305 | - /** |
|
306 | - * Returns the key used for rate limit transient. |
|
307 | - * |
|
308 | - * @return string |
|
309 | - */ |
|
310 | - protected function _get_rate_limit_key() |
|
311 | - { |
|
312 | - return '_ee_rate_limit'; |
|
313 | - } |
|
314 | - |
|
315 | - |
|
316 | - /** |
|
317 | - * Returns the rate limit expiry time. |
|
318 | - * |
|
319 | - * @return int |
|
320 | - */ |
|
321 | - protected function _get_rate_limit_expiry() |
|
322 | - { |
|
323 | - return time() + (int) apply_filters('FHEE__EE_Messages_Queue__rate_limit_expiry', HOUR_IN_SECONDS); |
|
324 | - } |
|
325 | - |
|
326 | - |
|
327 | - /** |
|
328 | - * Returns the default rate limit for sending messages. |
|
329 | - * |
|
330 | - * @return int |
|
331 | - */ |
|
332 | - protected function _default_rate_limit() |
|
333 | - { |
|
334 | - return (int) apply_filters('FHEE__EE_Messages_Queue___rate_limit', 200); |
|
335 | - } |
|
336 | - |
|
337 | - |
|
338 | - /** |
|
339 | - * Return the orderby array for priority. |
|
340 | - * |
|
341 | - * @return array |
|
342 | - */ |
|
343 | - protected function _get_priority_orderby() |
|
344 | - { |
|
345 | - return array( |
|
346 | - 'MSG_priority' => 'ASC', |
|
347 | - 'MSG_modified' => 'DESC', |
|
348 | - ); |
|
349 | - } |
|
350 | - |
|
351 | - |
|
352 | - /** |
|
353 | - * Returns whether batch methods are "locked" or not. |
|
354 | - * |
|
355 | - * @param string $type The type of lock being checked for. |
|
356 | - * @return bool |
|
357 | - */ |
|
358 | - public function is_locked($type = EE_Messages_Queue::action_generating) |
|
359 | - { |
|
360 | - $lock = (int) get_option($this->_get_lock_key($type), 0); |
|
361 | - /** |
|
362 | - * This filters the default is_locked behaviour. |
|
363 | - */ |
|
364 | - $is_locked = filter_var( |
|
365 | - apply_filters( |
|
366 | - 'FHEE__EE_Messages_Queue__is_locked', |
|
367 | - $lock > time(), |
|
368 | - $this |
|
369 | - ), |
|
370 | - FILTER_VALIDATE_BOOLEAN |
|
371 | - ); |
|
372 | - |
|
373 | - /** |
|
374 | - * @see usage of this filter in EE_Messages_Queue::initiate_request_by_priority() method. |
|
375 | - * Also implemented here because messages processed on the same request should not have any locks applied. |
|
376 | - */ |
|
377 | - if ( |
|
378 | - apply_filters('FHEE__EE_Messages_Processor__initiate_request_by_priority__do_immediate_processing', false) |
|
379 | - || EE_Registry::instance()->NET_CFG->core->do_messages_on_same_request |
|
380 | - ) { |
|
381 | - $is_locked = false; |
|
382 | - } |
|
383 | - |
|
384 | - |
|
385 | - return $is_locked; |
|
386 | - } |
|
387 | - |
|
388 | - |
|
389 | - /** |
|
390 | - * Retrieves the rate limit that may be cached as a transient. |
|
391 | - * If the rate limit is not set, then this sets the default rate limit and expiry and returns it. |
|
392 | - * |
|
393 | - * @param bool $return_expiry If true then return the expiry time not the rate_limit. |
|
394 | - * @return int |
|
395 | - */ |
|
396 | - protected function get_rate_limit($return_expiry = false) |
|
397 | - { |
|
398 | - $stored_rate_info = get_option($this->_get_rate_limit_key(), array()); |
|
399 | - $rate_limit = isset($stored_rate_info[0]) |
|
400 | - ? (int) $stored_rate_info[0] |
|
401 | - : 0; |
|
402 | - $expiry = isset($stored_rate_info[1]) |
|
403 | - ? (int) $stored_rate_info[1] |
|
404 | - : 0; |
|
405 | - //set the default for tracking? |
|
406 | - if (empty($stored_rate_info) || time() > $expiry) { |
|
407 | - $expiry = $this->_get_rate_limit_expiry(); |
|
408 | - $rate_limit = $this->_default_rate_limit(); |
|
409 | - update_option($this->_get_rate_limit_key(), array($rate_limit, $expiry)); |
|
410 | - } |
|
411 | - return $return_expiry ? $expiry : $rate_limit; |
|
412 | - } |
|
413 | - |
|
414 | - |
|
415 | - /** |
|
416 | - * This updates existing rate limit with the new limit which is the old minus the batch. |
|
417 | - * |
|
418 | - * @param int $batch_completed This sets the new rate limit based on the given batch that was completed. |
|
419 | - */ |
|
420 | - protected function set_rate_limit($batch_completed) |
|
421 | - { |
|
422 | - //first get the most up to date rate limit (in case its expired and reset) |
|
423 | - $rate_limit = $this->get_rate_limit(); |
|
424 | - $expiry = $this->get_rate_limit(true); |
|
425 | - $new_limit = $rate_limit - $batch_completed; |
|
426 | - //updating the transient option directly to avoid resetting the expiry. |
|
427 | - |
|
428 | - update_option($this->_get_rate_limit_key(), array($new_limit, $expiry)); |
|
429 | - } |
|
430 | - |
|
431 | - |
|
432 | - /** |
|
433 | - * This method checks the queue for ANY EE_Message objects with a priority matching the given priority passed in. |
|
434 | - * If that exists, then we immediately initiate a non-blocking request to do the requested action type. |
|
435 | - * Note: Keep in mind that there is the possibility that the request will not execute if there is already another |
|
436 | - * request running on a queue for the given task. |
|
437 | - * |
|
438 | - * @param string $task This indicates what type of request is going to be initiated. |
|
439 | - * @param int $priority This indicates the priority that triggers initiating the request. |
|
440 | - */ |
|
441 | - public function initiate_request_by_priority($task = 'generate', $priority = EEM_Message::priority_high) |
|
442 | - { |
|
443 | - //determine what status is matched with the priority as part of the trigger conditions. |
|
444 | - $status = $task == 'generate' |
|
445 | - ? EEM_Message::status_incomplete |
|
446 | - : EEM_Message::instance()->stati_indicating_to_send(); |
|
447 | - // always make sure we save because either this will get executed immediately on a separate request |
|
448 | - // or remains in the queue for the regularly scheduled queue batch. |
|
449 | - $this->save(); |
|
450 | - /** |
|
451 | - * This filter/option allows users to override processing of messages on separate requests and instead have everything |
|
452 | - * happen on the same request. If this is utilized remember: |
|
453 | - * - message priorities don't matter |
|
454 | - * - existing unprocessed messages in the queue will not get processed unless manually triggered. |
|
455 | - * - things will be perceived to take longer to happen for end users (i.e. registrations) because of the additional |
|
456 | - * processing happening on the same request. |
|
457 | - * - any race condition protection (locks) are removed because they don't apply when things are processed on |
|
458 | - * the same request. |
|
459 | - */ |
|
460 | - if ( |
|
461 | - apply_filters('FHEE__EE_Messages_Processor__initiate_request_by_priority__do_immediate_processing', false) |
|
462 | - || EE_Registry::instance()->NET_CFG->core->do_messages_on_same_request |
|
463 | - ) { |
|
464 | - $messages_processor = EE_Registry::instance()->load_lib('Messages_Processor'); |
|
465 | - if ($messages_processor instanceof EE_Messages_Processor) { |
|
466 | - return $messages_processor->process_immediately_from_queue($this); |
|
467 | - } |
|
468 | - //if we get here then that means the messages processor couldn't be loaded so messages will just remain |
|
469 | - //queued for manual triggering by end user. |
|
470 | - } |
|
471 | - |
|
472 | - if ($this->_message_repository->count_by_priority_and_status($priority, $status)) { |
|
473 | - EE_Messages_Scheduler::initiate_scheduled_non_blocking_request($task); |
|
474 | - } |
|
475 | - } |
|
476 | - |
|
477 | - |
|
478 | - /** |
|
479 | - * Loops through the EE_Message objects in the _queue and calls the messenger send methods for each message. |
|
480 | - * |
|
481 | - * @param bool $save Used to indicate whether to save the message queue after sending |
|
482 | - * (default will save). |
|
483 | - * @param mixed $sending_messenger (optional) When the sending messenger is different than |
|
484 | - * what is on the EE_Message object in the queue. |
|
485 | - * For instance, showing the browser view of an email message, |
|
486 | - * or giving a pdf generated view of an html document. |
|
487 | - * This should be an instance of EE_messenger but if you call this |
|
488 | - * method |
|
489 | - * intending it to be a sending messenger but a valid one could not be |
|
490 | - * retrieved then send in an instance of EE_Error that contains the |
|
491 | - * related error message. |
|
492 | - * @param bool|int $by_priority When set, this indicates that only messages |
|
493 | - * matching the given priority should be executed. |
|
494 | - * @return int Number of messages sent. Note, 0 does not mean that no messages were processed. |
|
495 | - * Also, if the messenger is an request type messenger (or a preview), |
|
496 | - * its entirely possible that the messenger will exit before |
|
497 | - */ |
|
498 | - public function execute($save = true, $sending_messenger = null, $by_priority = false) |
|
499 | - { |
|
500 | - $messages_sent = 0; |
|
501 | - $this->_did_hook = array(); |
|
502 | - $this->_message_repository->rewind(); |
|
503 | - |
|
504 | - while ($this->_message_repository->valid()) { |
|
505 | - $error_messages = array(); |
|
506 | - /** @type EE_Message $message */ |
|
507 | - $message = $this->_message_repository->current(); |
|
508 | - //only process things that are queued for sending |
|
509 | - if (! in_array($message->STS_ID(), EEM_Message::instance()->stati_indicating_to_send())) { |
|
510 | - $this->_message_repository->next(); |
|
511 | - continue; |
|
512 | - } |
|
513 | - //if $by_priority is set and does not match then continue; |
|
514 | - if ($by_priority && $by_priority != $message->priority()) { |
|
515 | - $this->_message_repository->next(); |
|
516 | - continue; |
|
517 | - } |
|
518 | - //error checking |
|
519 | - if (! $message->valid_messenger()) { |
|
520 | - $error_messages[] = sprintf( |
|
521 | - __('The %s messenger is not active at time of sending.', 'event_espresso'), |
|
522 | - $message->messenger() |
|
523 | - ); |
|
524 | - } |
|
525 | - if (! $message->valid_message_type()) { |
|
526 | - $error_messages[] = sprintf( |
|
527 | - __('The %s message type is not active at the time of sending.', 'event_espresso'), |
|
528 | - $message->message_type() |
|
529 | - ); |
|
530 | - } |
|
531 | - // if there was supposed to be a sending messenger for this message, but it was invalid/inactive, |
|
532 | - // then it will instead be an EE_Error object, so let's check for that |
|
533 | - if ($sending_messenger instanceof EE_Error) { |
|
534 | - $error_messages[] = $sending_messenger->getMessage(); |
|
535 | - } |
|
536 | - // if there are no errors, then let's process the message |
|
537 | - if (empty($error_messages)) { |
|
538 | - if ($save) { |
|
539 | - $message->set_messenger_is_executing(); |
|
540 | - } |
|
541 | - if ($this->_process_message($message, $sending_messenger)) { |
|
542 | - $messages_sent++; |
|
543 | - } |
|
544 | - } |
|
545 | - $this->_set_error_message($message, $error_messages); |
|
546 | - //add modified time |
|
547 | - $message->set_modified(time()); |
|
548 | - //we save each message after its processed to make sure its status persists in case PHP times-out or runs |
|
549 | - //out of memory. @see https://events.codebasehq.com/projects/event-espresso/tickets/10281 |
|
550 | - if ($save) { |
|
551 | - $message->save(); |
|
552 | - } |
|
553 | - |
|
554 | - $this->_message_repository->next(); |
|
555 | - } |
|
556 | - if ($save) { |
|
557 | - $this->save(true); |
|
558 | - } |
|
559 | - return $messages_sent; |
|
560 | - } |
|
561 | - |
|
562 | - |
|
563 | - /** |
|
564 | - * _process_message |
|
565 | - * |
|
566 | - * @param EE_Message $message |
|
567 | - * @param mixed $sending_messenger (optional) |
|
568 | - * @return bool |
|
569 | - */ |
|
570 | - protected function _process_message(EE_Message $message, $sending_messenger = null) |
|
571 | - { |
|
572 | - // these *should* have been validated in the execute() method above |
|
573 | - $messenger = $message->messenger_object(); |
|
574 | - $message_type = $message->message_type_object(); |
|
575 | - //do actions for sending messenger if it differs from generating messenger and swap values. |
|
576 | - if ( |
|
577 | - $sending_messenger instanceof EE_messenger |
|
578 | - && $messenger instanceof EE_messenger |
|
579 | - && $sending_messenger->name != $messenger->name |
|
580 | - ) { |
|
581 | - $messenger->do_secondary_messenger_hooks($sending_messenger->name); |
|
582 | - $messenger = $sending_messenger; |
|
583 | - } |
|
584 | - // send using messenger, but double check objects |
|
585 | - if ($messenger instanceof EE_messenger && $message_type instanceof EE_message_type) { |
|
586 | - //set hook for message type (but only if not using another messenger to send). |
|
587 | - if ( ! isset($this->_did_hook[$message_type->name])) { |
|
588 | - $message_type->do_messenger_hooks($messenger); |
|
589 | - $this->_did_hook[$message_type->name] = 1; |
|
590 | - } |
|
591 | - //if preview then use preview method |
|
592 | - return $this->_message_repository->is_preview() |
|
593 | - ? $this->_do_preview($message, $messenger, $message_type, $this->_message_repository->is_test_send()) |
|
594 | - : $this->_do_send($message, $messenger, $message_type); |
|
595 | - } |
|
596 | - return false; |
|
597 | - } |
|
598 | - |
|
599 | - |
|
600 | - /** |
|
601 | - * The intention of this method is to count how many EE_Message objects |
|
602 | - * are in the queue with a given status. |
|
603 | - * Example usage: |
|
604 | - * After a caller calls the "EE_Message_Queue::execute()" method, the caller can check if there were any failed |
|
605 | - * sends by calling $queue->count_STS_in_queue( EEM_Message_Queue::status_failed ). |
|
606 | - * |
|
607 | - * @param array|string $status Stati to check for in queue |
|
608 | - * @return int Count of EE_Message's matching the given status. |
|
609 | - */ |
|
610 | - public function count_STS_in_queue($status) |
|
611 | - { |
|
612 | - $count = 0; |
|
613 | - $status = is_array($status) ? $status : array($status); |
|
614 | - $this->_message_repository->rewind(); |
|
615 | - foreach ($this->_message_repository as $message) { |
|
616 | - if (in_array($message->STS_ID(), $status)) { |
|
617 | - $count++; |
|
618 | - } |
|
619 | - } |
|
620 | - return $count; |
|
621 | - } |
|
622 | - |
|
623 | - |
|
624 | - /** |
|
625 | - * Executes the get_preview method on the provided messenger. |
|
626 | - * |
|
627 | - * @param EE_Message $message |
|
628 | - * @param EE_messenger $messenger |
|
629 | - * @param EE_message_type $message_type |
|
630 | - * @param $test_send |
|
631 | - * @return bool true means all went well, false means, not so much. |
|
632 | - */ |
|
633 | - protected function _do_preview( |
|
634 | - EE_Message $message, |
|
635 | - EE_messenger $messenger, |
|
636 | - EE_message_type $message_type, |
|
637 | - $test_send |
|
638 | - ) { |
|
639 | - if ($preview = $messenger->get_preview($message, $message_type, $test_send)) { |
|
640 | - if ( ! $test_send) { |
|
641 | - $message->set_content($preview); |
|
642 | - } |
|
643 | - $message->set_STS_ID(EEM_Message::status_sent); |
|
644 | - return true; |
|
645 | - } else { |
|
646 | - $message->set_STS_ID(EEM_Message::status_failed); |
|
647 | - return false; |
|
648 | - } |
|
649 | - } |
|
650 | - |
|
651 | - |
|
652 | - /** |
|
653 | - * Executes the send method on the provided messenger |
|
654 | - * EE_Messengers are expected to: |
|
655 | - * - return true if the send was successful. |
|
656 | - * - return false if the send was unsuccessful but can be tried again. |
|
657 | - * - throw an Exception if the send was unsuccessful and cannot be tried again. |
|
658 | - * |
|
659 | - * @param EE_Message $message |
|
660 | - * @param EE_messenger $messenger |
|
661 | - * @param EE_message_type $message_type |
|
662 | - * @return bool true means all went well, false means, not so much. |
|
663 | - */ |
|
664 | - protected function _do_send(EE_Message $message, EE_messenger $messenger, EE_message_type $message_type) |
|
665 | - { |
|
666 | - try { |
|
667 | - if ($messenger->send_message($message, $message_type)) { |
|
668 | - $message->set_STS_ID(EEM_Message::status_sent); |
|
669 | - return true; |
|
670 | - } else { |
|
671 | - $message->set_STS_ID(EEM_Message::status_retry); |
|
672 | - return false; |
|
673 | - } |
|
674 | - } catch (SendMessageException $e) { |
|
675 | - $message->set_STS_ID(EEM_Message::status_failed); |
|
676 | - $message->set_error_message($e->getMessage()); |
|
677 | - return false; |
|
678 | - } |
|
679 | - } |
|
680 | - |
|
681 | - |
|
682 | - /** |
|
683 | - * This sets any necessary error messages on the message object and its status to failed. |
|
684 | - * |
|
685 | - * @param EE_Message $message |
|
686 | - * @param array $error_messages the response from the messenger. |
|
687 | - */ |
|
688 | - protected function _set_error_message(EE_Message $message, $error_messages) |
|
689 | - { |
|
690 | - $error_messages = (array)$error_messages; |
|
691 | - if (in_array($message->STS_ID(), EEM_Message::instance()->stati_indicating_failed_sending())) { |
|
692 | - $notices = EE_Error::has_notices(); |
|
693 | - $error_messages[] = __( |
|
694 | - 'Messenger and Message Type were valid and active, but the messenger send method failed.', |
|
695 | - 'event_espresso' |
|
696 | - ); |
|
697 | - if ($notices === 1) { |
|
698 | - $notices = EE_Error::get_vanilla_notices(); |
|
699 | - $notices['errors'] = isset($notices['errors']) ? $notices['errors'] : array(); |
|
700 | - $error_messages[] = implode("\n", $notices['errors']); |
|
701 | - } |
|
702 | - } |
|
703 | - if (count($error_messages) > 0) { |
|
704 | - $msg = __('Message was not executed successfully.', 'event_espresso'); |
|
705 | - $msg = $msg . "\n" . implode("\n", $error_messages); |
|
706 | - $message->set_error_message($msg); |
|
707 | - } |
|
708 | - } |
|
21 | + /** |
|
22 | + * @type string reference for sending action |
|
23 | + */ |
|
24 | + const action_sending = 'sending'; |
|
25 | + |
|
26 | + /** |
|
27 | + * @type string reference for generation action |
|
28 | + */ |
|
29 | + const action_generating = 'generation'; |
|
30 | + |
|
31 | + |
|
32 | + /** |
|
33 | + * @type EE_Message_Repository $_message_repository |
|
34 | + */ |
|
35 | + protected $_message_repository; |
|
36 | + |
|
37 | + /** |
|
38 | + * Sets the limit of how many messages are generated per process. |
|
39 | + * |
|
40 | + * @type int |
|
41 | + */ |
|
42 | + protected $_batch_count; |
|
43 | + |
|
44 | + |
|
45 | + /** |
|
46 | + * This is an array of cached queue items being stored in this object. |
|
47 | + * The array keys will be the ID of the EE_Message in the db if saved. If the EE_Message |
|
48 | + * is not saved to the db then its key will be an increment of "UNS" (i.e. UNS1, UNS2 etc.) |
|
49 | + * |
|
50 | + * @type EE_Message[] |
|
51 | + */ |
|
52 | + protected $_cached_queue_items; |
|
53 | + |
|
54 | + /** |
|
55 | + * Tracks the number of unsaved queue items. |
|
56 | + * |
|
57 | + * @type int |
|
58 | + */ |
|
59 | + protected $_unsaved_count = 0; |
|
60 | + |
|
61 | + /** |
|
62 | + * used to record if a do_messenger_hooks has already been called for a message type. This prevents multiple |
|
63 | + * hooks getting fired if users have setup their action/filter hooks to prevent duplicate calls. |
|
64 | + * |
|
65 | + * @type array |
|
66 | + */ |
|
67 | + protected $_did_hook = array(); |
|
68 | + |
|
69 | + |
|
70 | + /** |
|
71 | + * Constructor. |
|
72 | + * Setup all the initial properties and load a EE_Message_Repository. |
|
73 | + * |
|
74 | + * @param \EE_Message_Repository $message_repository |
|
75 | + */ |
|
76 | + public function __construct(EE_Message_Repository $message_repository) |
|
77 | + { |
|
78 | + $this->_batch_count = apply_filters('FHEE__EE_Messages_Queue___batch_count', 50); |
|
79 | + $this->_message_repository = $message_repository; |
|
80 | + } |
|
81 | + |
|
82 | + |
|
83 | + /** |
|
84 | + * Add a EE_Message object to the queue |
|
85 | + * |
|
86 | + * @param EE_Message $message |
|
87 | + * @param array $data This will be an array of data to attach to the object in the repository. If the |
|
88 | + * object is persisted, this data will be saved on an extra_meta object related to |
|
89 | + * EE_Message. |
|
90 | + * @param bool $preview Whether this EE_Message represents a preview or not. |
|
91 | + * @param bool $test_send This indicates whether to do a test send instead of actual send. A test send will |
|
92 | + * use the messenger send method but typically is based on preview data. |
|
93 | + * @return bool Whether the message was successfully added to the repository or not. |
|
94 | + */ |
|
95 | + public function add(EE_Message $message, $data = array(), $preview = false, $test_send = false) |
|
96 | + { |
|
97 | + $data['preview'] = $preview; |
|
98 | + $data['test_send'] = $test_send; |
|
99 | + return $this->_message_repository->add($message, $data); |
|
100 | + } |
|
101 | + |
|
102 | + |
|
103 | + /** |
|
104 | + * Removes EE_Message from _queue that matches the given EE_Message if the pointer is on a matching EE_Message |
|
105 | + * |
|
106 | + * @param EE_Message $message The message to detach from the queue |
|
107 | + * @param bool $persist This flag indicates whether to attempt to delete the object from the db as well. |
|
108 | + * @return bool |
|
109 | + */ |
|
110 | + public function remove(EE_Message $message, $persist = false) |
|
111 | + { |
|
112 | + if ($persist && $this->_message_repository->current() !== $message) { |
|
113 | + //get pointer on right message |
|
114 | + if ($this->_message_repository->has($message)) { |
|
115 | + $this->_message_repository->rewind(); |
|
116 | + while ($this->_message_repository->valid()) { |
|
117 | + if ($this->_message_repository->current() === $message) { |
|
118 | + break; |
|
119 | + } |
|
120 | + $this->_message_repository->next(); |
|
121 | + } |
|
122 | + } else { |
|
123 | + return false; |
|
124 | + } |
|
125 | + } |
|
126 | + return $persist ? $this->_message_repository->delete() : $this->_message_repository->remove($message); |
|
127 | + } |
|
128 | + |
|
129 | + |
|
130 | + /** |
|
131 | + * Persists all queued EE_Message objects to the db. |
|
132 | + * |
|
133 | + * @param bool $do_hooks_only @see EE_Message_Repository::saveAll |
|
134 | + * @return array @see EE_Messages_Repository::saveAll() for return values. |
|
135 | + */ |
|
136 | + public function save($do_hooks_only = false) |
|
137 | + { |
|
138 | + return $this->_message_repository->saveAll($do_hooks_only); |
|
139 | + } |
|
140 | + |
|
141 | + |
|
142 | + /** |
|
143 | + * @return EE_Message_Repository |
|
144 | + */ |
|
145 | + public function get_message_repository() |
|
146 | + { |
|
147 | + return $this->_message_repository; |
|
148 | + } |
|
149 | + |
|
150 | + |
|
151 | + /** |
|
152 | + * This does the following things: |
|
153 | + * 1. Checks if there is a lock on generation (prevents race conditions). If there is a lock then exits (return |
|
154 | + * false). |
|
155 | + * 2. If no lock, sets lock, then retrieves a batch of non-generated EE_Message objects and adds to queue |
|
156 | + * 3. Returns bool. True = batch ready. False = no batch ready (or nothing available for generation). |
|
157 | + * Note: Callers should make sure they release the lock otherwise batch generation will be prevented from |
|
158 | + * continuing. The lock is on a transient that is set to expire after one hour as a fallback in case locks are not |
|
159 | + * removed. |
|
160 | + * |
|
161 | + * @return bool true if successfully retrieved batch, false no batch ready. |
|
162 | + */ |
|
163 | + public function get_batch_to_generate() |
|
164 | + { |
|
165 | + if ($this->is_locked(EE_Messages_Queue::action_generating)) { |
|
166 | + return false; |
|
167 | + } |
|
168 | + |
|
169 | + //lock batch generation to prevent race conditions. |
|
170 | + $this->lock_queue(EE_Messages_Queue::action_generating); |
|
171 | + |
|
172 | + $query_args = array( |
|
173 | + // key 0 = where conditions |
|
174 | + 0 => array('STS_ID' => EEM_Message::status_incomplete), |
|
175 | + 'order_by' => $this->_get_priority_orderby(), |
|
176 | + 'limit' => $this->_batch_count, |
|
177 | + ); |
|
178 | + $messages = EEM_Message::instance()->get_all($query_args); |
|
179 | + |
|
180 | + if ( ! $messages) { |
|
181 | + return false; //nothing to generate |
|
182 | + } |
|
183 | + |
|
184 | + foreach ($messages as $message) { |
|
185 | + if ($message instanceof EE_Message) { |
|
186 | + $data = $message->all_extra_meta_array(); |
|
187 | + $this->add($message, $data); |
|
188 | + } |
|
189 | + } |
|
190 | + return true; |
|
191 | + } |
|
192 | + |
|
193 | + |
|
194 | + /** |
|
195 | + * This does the following things: |
|
196 | + * 1. Checks if there is a lock on sending (prevents race conditions). If there is a lock then exits (return |
|
197 | + * false). |
|
198 | + * 2. Grabs the allowed number of messages to send for the rate_limit. If cannot send any more messages, then |
|
199 | + * return false. |
|
200 | + * 2. If no lock, sets lock, then retrieves a batch of EE_Message objects, adds to queue and triggers execution. |
|
201 | + * 3. On success or unsuccessful send, sets status appropriately. |
|
202 | + * 4. Saves messages via the queue |
|
203 | + * 5. Releases lock. |
|
204 | + * |
|
205 | + * @return bool true on success, false if something preventing sending (i.e. lock set). Note: true does not |
|
206 | + * necessarily mean that all messages were successfully sent. It just means that this method |
|
207 | + * successfully completed. On true, client may want to call $this->count_STS_in_queue( |
|
208 | + * EEM_Message::status_failed ) to see if any failed EE_Message objects. Each failed message object |
|
209 | + * will also have a saved error message on it to assist with notifying user. |
|
210 | + */ |
|
211 | + public function get_to_send_batch_and_send() |
|
212 | + { |
|
213 | + $rate_limit = $this->get_rate_limit(); |
|
214 | + if ($rate_limit < 1 || $this->is_locked(EE_Messages_Queue::action_sending)) { |
|
215 | + return false; |
|
216 | + } |
|
217 | + |
|
218 | + $this->lock_queue(EE_Messages_Queue::action_sending); |
|
219 | + |
|
220 | + $batch = $this->_batch_count < $rate_limit ? $this->_batch_count : $rate_limit; |
|
221 | + |
|
222 | + $query_args = array( |
|
223 | + // key 0 = where conditions |
|
224 | + 0 => array('STS_ID' => array('IN', EEM_Message::instance()->stati_indicating_to_send())), |
|
225 | + 'order_by' => $this->_get_priority_orderby(), |
|
226 | + 'limit' => $batch, |
|
227 | + ); |
|
228 | + |
|
229 | + $messages_to_send = EEM_Message::instance()->get_all($query_args); |
|
230 | + |
|
231 | + |
|
232 | + //any to send? |
|
233 | + if ( ! $messages_to_send) { |
|
234 | + $this->unlock_queue(EE_Messages_Queue::action_sending); |
|
235 | + return false; |
|
236 | + } |
|
237 | + |
|
238 | + $queue_count = 0; |
|
239 | + |
|
240 | + //add to queue. |
|
241 | + foreach ($messages_to_send as $message) { |
|
242 | + if ($message instanceof EE_Message) { |
|
243 | + $queue_count++; |
|
244 | + $this->add($message); |
|
245 | + } |
|
246 | + } |
|
247 | + |
|
248 | + //send messages (this also updates the rate limit) |
|
249 | + $this->execute(); |
|
250 | + |
|
251 | + //release lock |
|
252 | + $this->unlock_queue(EE_Messages_Queue::action_sending); |
|
253 | + //update rate limit |
|
254 | + $this->set_rate_limit($queue_count); |
|
255 | + return true; |
|
256 | + } |
|
257 | + |
|
258 | + |
|
259 | + /** |
|
260 | + * Locks the queue so that no other queues can call the "batch" methods. |
|
261 | + * |
|
262 | + * @param string $type The type of queue being locked. |
|
263 | + */ |
|
264 | + public function lock_queue($type = EE_Messages_Queue::action_generating) |
|
265 | + { |
|
266 | + update_option($this->_get_lock_key($type), $this->_get_lock_expiry($type)); |
|
267 | + } |
|
268 | + |
|
269 | + |
|
270 | + /** |
|
271 | + * Unlocks the queue so that batch methods can be used. |
|
272 | + * |
|
273 | + * @param string $type The type of queue being unlocked. |
|
274 | + */ |
|
275 | + public function unlock_queue($type = EE_Messages_Queue::action_generating) |
|
276 | + { |
|
277 | + delete_option($this->_get_lock_key($type)); |
|
278 | + } |
|
279 | + |
|
280 | + |
|
281 | + /** |
|
282 | + * Retrieve the key used for the lock transient. |
|
283 | + * |
|
284 | + * @param string $type The type of lock. |
|
285 | + * @return string |
|
286 | + */ |
|
287 | + protected function _get_lock_key($type = EE_Messages_Queue::action_generating) |
|
288 | + { |
|
289 | + return '_ee_lock_' . $type; |
|
290 | + } |
|
291 | + |
|
292 | + |
|
293 | + /** |
|
294 | + * Retrieve the expiry time for the lock transient. |
|
295 | + * |
|
296 | + * @param string $type The type of lock |
|
297 | + * @return int time to expiry in seconds. |
|
298 | + */ |
|
299 | + protected function _get_lock_expiry($type = EE_Messages_Queue::action_generating) |
|
300 | + { |
|
301 | + return time() + (int) apply_filters('FHEE__EE_Messages_Queue__lock_expiry', HOUR_IN_SECONDS, $type); |
|
302 | + } |
|
303 | + |
|
304 | + |
|
305 | + /** |
|
306 | + * Returns the key used for rate limit transient. |
|
307 | + * |
|
308 | + * @return string |
|
309 | + */ |
|
310 | + protected function _get_rate_limit_key() |
|
311 | + { |
|
312 | + return '_ee_rate_limit'; |
|
313 | + } |
|
314 | + |
|
315 | + |
|
316 | + /** |
|
317 | + * Returns the rate limit expiry time. |
|
318 | + * |
|
319 | + * @return int |
|
320 | + */ |
|
321 | + protected function _get_rate_limit_expiry() |
|
322 | + { |
|
323 | + return time() + (int) apply_filters('FHEE__EE_Messages_Queue__rate_limit_expiry', HOUR_IN_SECONDS); |
|
324 | + } |
|
325 | + |
|
326 | + |
|
327 | + /** |
|
328 | + * Returns the default rate limit for sending messages. |
|
329 | + * |
|
330 | + * @return int |
|
331 | + */ |
|
332 | + protected function _default_rate_limit() |
|
333 | + { |
|
334 | + return (int) apply_filters('FHEE__EE_Messages_Queue___rate_limit', 200); |
|
335 | + } |
|
336 | + |
|
337 | + |
|
338 | + /** |
|
339 | + * Return the orderby array for priority. |
|
340 | + * |
|
341 | + * @return array |
|
342 | + */ |
|
343 | + protected function _get_priority_orderby() |
|
344 | + { |
|
345 | + return array( |
|
346 | + 'MSG_priority' => 'ASC', |
|
347 | + 'MSG_modified' => 'DESC', |
|
348 | + ); |
|
349 | + } |
|
350 | + |
|
351 | + |
|
352 | + /** |
|
353 | + * Returns whether batch methods are "locked" or not. |
|
354 | + * |
|
355 | + * @param string $type The type of lock being checked for. |
|
356 | + * @return bool |
|
357 | + */ |
|
358 | + public function is_locked($type = EE_Messages_Queue::action_generating) |
|
359 | + { |
|
360 | + $lock = (int) get_option($this->_get_lock_key($type), 0); |
|
361 | + /** |
|
362 | + * This filters the default is_locked behaviour. |
|
363 | + */ |
|
364 | + $is_locked = filter_var( |
|
365 | + apply_filters( |
|
366 | + 'FHEE__EE_Messages_Queue__is_locked', |
|
367 | + $lock > time(), |
|
368 | + $this |
|
369 | + ), |
|
370 | + FILTER_VALIDATE_BOOLEAN |
|
371 | + ); |
|
372 | + |
|
373 | + /** |
|
374 | + * @see usage of this filter in EE_Messages_Queue::initiate_request_by_priority() method. |
|
375 | + * Also implemented here because messages processed on the same request should not have any locks applied. |
|
376 | + */ |
|
377 | + if ( |
|
378 | + apply_filters('FHEE__EE_Messages_Processor__initiate_request_by_priority__do_immediate_processing', false) |
|
379 | + || EE_Registry::instance()->NET_CFG->core->do_messages_on_same_request |
|
380 | + ) { |
|
381 | + $is_locked = false; |
|
382 | + } |
|
383 | + |
|
384 | + |
|
385 | + return $is_locked; |
|
386 | + } |
|
387 | + |
|
388 | + |
|
389 | + /** |
|
390 | + * Retrieves the rate limit that may be cached as a transient. |
|
391 | + * If the rate limit is not set, then this sets the default rate limit and expiry and returns it. |
|
392 | + * |
|
393 | + * @param bool $return_expiry If true then return the expiry time not the rate_limit. |
|
394 | + * @return int |
|
395 | + */ |
|
396 | + protected function get_rate_limit($return_expiry = false) |
|
397 | + { |
|
398 | + $stored_rate_info = get_option($this->_get_rate_limit_key(), array()); |
|
399 | + $rate_limit = isset($stored_rate_info[0]) |
|
400 | + ? (int) $stored_rate_info[0] |
|
401 | + : 0; |
|
402 | + $expiry = isset($stored_rate_info[1]) |
|
403 | + ? (int) $stored_rate_info[1] |
|
404 | + : 0; |
|
405 | + //set the default for tracking? |
|
406 | + if (empty($stored_rate_info) || time() > $expiry) { |
|
407 | + $expiry = $this->_get_rate_limit_expiry(); |
|
408 | + $rate_limit = $this->_default_rate_limit(); |
|
409 | + update_option($this->_get_rate_limit_key(), array($rate_limit, $expiry)); |
|
410 | + } |
|
411 | + return $return_expiry ? $expiry : $rate_limit; |
|
412 | + } |
|
413 | + |
|
414 | + |
|
415 | + /** |
|
416 | + * This updates existing rate limit with the new limit which is the old minus the batch. |
|
417 | + * |
|
418 | + * @param int $batch_completed This sets the new rate limit based on the given batch that was completed. |
|
419 | + */ |
|
420 | + protected function set_rate_limit($batch_completed) |
|
421 | + { |
|
422 | + //first get the most up to date rate limit (in case its expired and reset) |
|
423 | + $rate_limit = $this->get_rate_limit(); |
|
424 | + $expiry = $this->get_rate_limit(true); |
|
425 | + $new_limit = $rate_limit - $batch_completed; |
|
426 | + //updating the transient option directly to avoid resetting the expiry. |
|
427 | + |
|
428 | + update_option($this->_get_rate_limit_key(), array($new_limit, $expiry)); |
|
429 | + } |
|
430 | + |
|
431 | + |
|
432 | + /** |
|
433 | + * This method checks the queue for ANY EE_Message objects with a priority matching the given priority passed in. |
|
434 | + * If that exists, then we immediately initiate a non-blocking request to do the requested action type. |
|
435 | + * Note: Keep in mind that there is the possibility that the request will not execute if there is already another |
|
436 | + * request running on a queue for the given task. |
|
437 | + * |
|
438 | + * @param string $task This indicates what type of request is going to be initiated. |
|
439 | + * @param int $priority This indicates the priority that triggers initiating the request. |
|
440 | + */ |
|
441 | + public function initiate_request_by_priority($task = 'generate', $priority = EEM_Message::priority_high) |
|
442 | + { |
|
443 | + //determine what status is matched with the priority as part of the trigger conditions. |
|
444 | + $status = $task == 'generate' |
|
445 | + ? EEM_Message::status_incomplete |
|
446 | + : EEM_Message::instance()->stati_indicating_to_send(); |
|
447 | + // always make sure we save because either this will get executed immediately on a separate request |
|
448 | + // or remains in the queue for the regularly scheduled queue batch. |
|
449 | + $this->save(); |
|
450 | + /** |
|
451 | + * This filter/option allows users to override processing of messages on separate requests and instead have everything |
|
452 | + * happen on the same request. If this is utilized remember: |
|
453 | + * - message priorities don't matter |
|
454 | + * - existing unprocessed messages in the queue will not get processed unless manually triggered. |
|
455 | + * - things will be perceived to take longer to happen for end users (i.e. registrations) because of the additional |
|
456 | + * processing happening on the same request. |
|
457 | + * - any race condition protection (locks) are removed because they don't apply when things are processed on |
|
458 | + * the same request. |
|
459 | + */ |
|
460 | + if ( |
|
461 | + apply_filters('FHEE__EE_Messages_Processor__initiate_request_by_priority__do_immediate_processing', false) |
|
462 | + || EE_Registry::instance()->NET_CFG->core->do_messages_on_same_request |
|
463 | + ) { |
|
464 | + $messages_processor = EE_Registry::instance()->load_lib('Messages_Processor'); |
|
465 | + if ($messages_processor instanceof EE_Messages_Processor) { |
|
466 | + return $messages_processor->process_immediately_from_queue($this); |
|
467 | + } |
|
468 | + //if we get here then that means the messages processor couldn't be loaded so messages will just remain |
|
469 | + //queued for manual triggering by end user. |
|
470 | + } |
|
471 | + |
|
472 | + if ($this->_message_repository->count_by_priority_and_status($priority, $status)) { |
|
473 | + EE_Messages_Scheduler::initiate_scheduled_non_blocking_request($task); |
|
474 | + } |
|
475 | + } |
|
476 | + |
|
477 | + |
|
478 | + /** |
|
479 | + * Loops through the EE_Message objects in the _queue and calls the messenger send methods for each message. |
|
480 | + * |
|
481 | + * @param bool $save Used to indicate whether to save the message queue after sending |
|
482 | + * (default will save). |
|
483 | + * @param mixed $sending_messenger (optional) When the sending messenger is different than |
|
484 | + * what is on the EE_Message object in the queue. |
|
485 | + * For instance, showing the browser view of an email message, |
|
486 | + * or giving a pdf generated view of an html document. |
|
487 | + * This should be an instance of EE_messenger but if you call this |
|
488 | + * method |
|
489 | + * intending it to be a sending messenger but a valid one could not be |
|
490 | + * retrieved then send in an instance of EE_Error that contains the |
|
491 | + * related error message. |
|
492 | + * @param bool|int $by_priority When set, this indicates that only messages |
|
493 | + * matching the given priority should be executed. |
|
494 | + * @return int Number of messages sent. Note, 0 does not mean that no messages were processed. |
|
495 | + * Also, if the messenger is an request type messenger (or a preview), |
|
496 | + * its entirely possible that the messenger will exit before |
|
497 | + */ |
|
498 | + public function execute($save = true, $sending_messenger = null, $by_priority = false) |
|
499 | + { |
|
500 | + $messages_sent = 0; |
|
501 | + $this->_did_hook = array(); |
|
502 | + $this->_message_repository->rewind(); |
|
503 | + |
|
504 | + while ($this->_message_repository->valid()) { |
|
505 | + $error_messages = array(); |
|
506 | + /** @type EE_Message $message */ |
|
507 | + $message = $this->_message_repository->current(); |
|
508 | + //only process things that are queued for sending |
|
509 | + if (! in_array($message->STS_ID(), EEM_Message::instance()->stati_indicating_to_send())) { |
|
510 | + $this->_message_repository->next(); |
|
511 | + continue; |
|
512 | + } |
|
513 | + //if $by_priority is set and does not match then continue; |
|
514 | + if ($by_priority && $by_priority != $message->priority()) { |
|
515 | + $this->_message_repository->next(); |
|
516 | + continue; |
|
517 | + } |
|
518 | + //error checking |
|
519 | + if (! $message->valid_messenger()) { |
|
520 | + $error_messages[] = sprintf( |
|
521 | + __('The %s messenger is not active at time of sending.', 'event_espresso'), |
|
522 | + $message->messenger() |
|
523 | + ); |
|
524 | + } |
|
525 | + if (! $message->valid_message_type()) { |
|
526 | + $error_messages[] = sprintf( |
|
527 | + __('The %s message type is not active at the time of sending.', 'event_espresso'), |
|
528 | + $message->message_type() |
|
529 | + ); |
|
530 | + } |
|
531 | + // if there was supposed to be a sending messenger for this message, but it was invalid/inactive, |
|
532 | + // then it will instead be an EE_Error object, so let's check for that |
|
533 | + if ($sending_messenger instanceof EE_Error) { |
|
534 | + $error_messages[] = $sending_messenger->getMessage(); |
|
535 | + } |
|
536 | + // if there are no errors, then let's process the message |
|
537 | + if (empty($error_messages)) { |
|
538 | + if ($save) { |
|
539 | + $message->set_messenger_is_executing(); |
|
540 | + } |
|
541 | + if ($this->_process_message($message, $sending_messenger)) { |
|
542 | + $messages_sent++; |
|
543 | + } |
|
544 | + } |
|
545 | + $this->_set_error_message($message, $error_messages); |
|
546 | + //add modified time |
|
547 | + $message->set_modified(time()); |
|
548 | + //we save each message after its processed to make sure its status persists in case PHP times-out or runs |
|
549 | + //out of memory. @see https://events.codebasehq.com/projects/event-espresso/tickets/10281 |
|
550 | + if ($save) { |
|
551 | + $message->save(); |
|
552 | + } |
|
553 | + |
|
554 | + $this->_message_repository->next(); |
|
555 | + } |
|
556 | + if ($save) { |
|
557 | + $this->save(true); |
|
558 | + } |
|
559 | + return $messages_sent; |
|
560 | + } |
|
561 | + |
|
562 | + |
|
563 | + /** |
|
564 | + * _process_message |
|
565 | + * |
|
566 | + * @param EE_Message $message |
|
567 | + * @param mixed $sending_messenger (optional) |
|
568 | + * @return bool |
|
569 | + */ |
|
570 | + protected function _process_message(EE_Message $message, $sending_messenger = null) |
|
571 | + { |
|
572 | + // these *should* have been validated in the execute() method above |
|
573 | + $messenger = $message->messenger_object(); |
|
574 | + $message_type = $message->message_type_object(); |
|
575 | + //do actions for sending messenger if it differs from generating messenger and swap values. |
|
576 | + if ( |
|
577 | + $sending_messenger instanceof EE_messenger |
|
578 | + && $messenger instanceof EE_messenger |
|
579 | + && $sending_messenger->name != $messenger->name |
|
580 | + ) { |
|
581 | + $messenger->do_secondary_messenger_hooks($sending_messenger->name); |
|
582 | + $messenger = $sending_messenger; |
|
583 | + } |
|
584 | + // send using messenger, but double check objects |
|
585 | + if ($messenger instanceof EE_messenger && $message_type instanceof EE_message_type) { |
|
586 | + //set hook for message type (but only if not using another messenger to send). |
|
587 | + if ( ! isset($this->_did_hook[$message_type->name])) { |
|
588 | + $message_type->do_messenger_hooks($messenger); |
|
589 | + $this->_did_hook[$message_type->name] = 1; |
|
590 | + } |
|
591 | + //if preview then use preview method |
|
592 | + return $this->_message_repository->is_preview() |
|
593 | + ? $this->_do_preview($message, $messenger, $message_type, $this->_message_repository->is_test_send()) |
|
594 | + : $this->_do_send($message, $messenger, $message_type); |
|
595 | + } |
|
596 | + return false; |
|
597 | + } |
|
598 | + |
|
599 | + |
|
600 | + /** |
|
601 | + * The intention of this method is to count how many EE_Message objects |
|
602 | + * are in the queue with a given status. |
|
603 | + * Example usage: |
|
604 | + * After a caller calls the "EE_Message_Queue::execute()" method, the caller can check if there were any failed |
|
605 | + * sends by calling $queue->count_STS_in_queue( EEM_Message_Queue::status_failed ). |
|
606 | + * |
|
607 | + * @param array|string $status Stati to check for in queue |
|
608 | + * @return int Count of EE_Message's matching the given status. |
|
609 | + */ |
|
610 | + public function count_STS_in_queue($status) |
|
611 | + { |
|
612 | + $count = 0; |
|
613 | + $status = is_array($status) ? $status : array($status); |
|
614 | + $this->_message_repository->rewind(); |
|
615 | + foreach ($this->_message_repository as $message) { |
|
616 | + if (in_array($message->STS_ID(), $status)) { |
|
617 | + $count++; |
|
618 | + } |
|
619 | + } |
|
620 | + return $count; |
|
621 | + } |
|
622 | + |
|
623 | + |
|
624 | + /** |
|
625 | + * Executes the get_preview method on the provided messenger. |
|
626 | + * |
|
627 | + * @param EE_Message $message |
|
628 | + * @param EE_messenger $messenger |
|
629 | + * @param EE_message_type $message_type |
|
630 | + * @param $test_send |
|
631 | + * @return bool true means all went well, false means, not so much. |
|
632 | + */ |
|
633 | + protected function _do_preview( |
|
634 | + EE_Message $message, |
|
635 | + EE_messenger $messenger, |
|
636 | + EE_message_type $message_type, |
|
637 | + $test_send |
|
638 | + ) { |
|
639 | + if ($preview = $messenger->get_preview($message, $message_type, $test_send)) { |
|
640 | + if ( ! $test_send) { |
|
641 | + $message->set_content($preview); |
|
642 | + } |
|
643 | + $message->set_STS_ID(EEM_Message::status_sent); |
|
644 | + return true; |
|
645 | + } else { |
|
646 | + $message->set_STS_ID(EEM_Message::status_failed); |
|
647 | + return false; |
|
648 | + } |
|
649 | + } |
|
650 | + |
|
651 | + |
|
652 | + /** |
|
653 | + * Executes the send method on the provided messenger |
|
654 | + * EE_Messengers are expected to: |
|
655 | + * - return true if the send was successful. |
|
656 | + * - return false if the send was unsuccessful but can be tried again. |
|
657 | + * - throw an Exception if the send was unsuccessful and cannot be tried again. |
|
658 | + * |
|
659 | + * @param EE_Message $message |
|
660 | + * @param EE_messenger $messenger |
|
661 | + * @param EE_message_type $message_type |
|
662 | + * @return bool true means all went well, false means, not so much. |
|
663 | + */ |
|
664 | + protected function _do_send(EE_Message $message, EE_messenger $messenger, EE_message_type $message_type) |
|
665 | + { |
|
666 | + try { |
|
667 | + if ($messenger->send_message($message, $message_type)) { |
|
668 | + $message->set_STS_ID(EEM_Message::status_sent); |
|
669 | + return true; |
|
670 | + } else { |
|
671 | + $message->set_STS_ID(EEM_Message::status_retry); |
|
672 | + return false; |
|
673 | + } |
|
674 | + } catch (SendMessageException $e) { |
|
675 | + $message->set_STS_ID(EEM_Message::status_failed); |
|
676 | + $message->set_error_message($e->getMessage()); |
|
677 | + return false; |
|
678 | + } |
|
679 | + } |
|
680 | + |
|
681 | + |
|
682 | + /** |
|
683 | + * This sets any necessary error messages on the message object and its status to failed. |
|
684 | + * |
|
685 | + * @param EE_Message $message |
|
686 | + * @param array $error_messages the response from the messenger. |
|
687 | + */ |
|
688 | + protected function _set_error_message(EE_Message $message, $error_messages) |
|
689 | + { |
|
690 | + $error_messages = (array)$error_messages; |
|
691 | + if (in_array($message->STS_ID(), EEM_Message::instance()->stati_indicating_failed_sending())) { |
|
692 | + $notices = EE_Error::has_notices(); |
|
693 | + $error_messages[] = __( |
|
694 | + 'Messenger and Message Type were valid and active, but the messenger send method failed.', |
|
695 | + 'event_espresso' |
|
696 | + ); |
|
697 | + if ($notices === 1) { |
|
698 | + $notices = EE_Error::get_vanilla_notices(); |
|
699 | + $notices['errors'] = isset($notices['errors']) ? $notices['errors'] : array(); |
|
700 | + $error_messages[] = implode("\n", $notices['errors']); |
|
701 | + } |
|
702 | + } |
|
703 | + if (count($error_messages) > 0) { |
|
704 | + $msg = __('Message was not executed successfully.', 'event_espresso'); |
|
705 | + $msg = $msg . "\n" . implode("\n", $error_messages); |
|
706 | + $message->set_error_message($msg); |
|
707 | + } |
|
708 | + } |
|
709 | 709 | |
710 | 710 | } //end EE_Messages_Queue class |
@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | use \EventEspresso\core\exceptions\SendMessageException; |
3 | 3 | |
4 | -if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
4 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
5 | 5 | exit('No direct script access allowed'); |
6 | 6 | } |
7 | 7 | |
@@ -175,7 +175,7 @@ discard block |
||
175 | 175 | 'order_by' => $this->_get_priority_orderby(), |
176 | 176 | 'limit' => $this->_batch_count, |
177 | 177 | ); |
178 | - $messages = EEM_Message::instance()->get_all($query_args); |
|
178 | + $messages = EEM_Message::instance()->get_all($query_args); |
|
179 | 179 | |
180 | 180 | if ( ! $messages) { |
181 | 181 | return false; //nothing to generate |
@@ -286,7 +286,7 @@ discard block |
||
286 | 286 | */ |
287 | 287 | protected function _get_lock_key($type = EE_Messages_Queue::action_generating) |
288 | 288 | { |
289 | - return '_ee_lock_' . $type; |
|
289 | + return '_ee_lock_'.$type; |
|
290 | 290 | } |
291 | 291 | |
292 | 292 | |
@@ -506,7 +506,7 @@ discard block |
||
506 | 506 | /** @type EE_Message $message */ |
507 | 507 | $message = $this->_message_repository->current(); |
508 | 508 | //only process things that are queued for sending |
509 | - if (! in_array($message->STS_ID(), EEM_Message::instance()->stati_indicating_to_send())) { |
|
509 | + if ( ! in_array($message->STS_ID(), EEM_Message::instance()->stati_indicating_to_send())) { |
|
510 | 510 | $this->_message_repository->next(); |
511 | 511 | continue; |
512 | 512 | } |
@@ -516,13 +516,13 @@ discard block |
||
516 | 516 | continue; |
517 | 517 | } |
518 | 518 | //error checking |
519 | - if (! $message->valid_messenger()) { |
|
519 | + if ( ! $message->valid_messenger()) { |
|
520 | 520 | $error_messages[] = sprintf( |
521 | 521 | __('The %s messenger is not active at time of sending.', 'event_espresso'), |
522 | 522 | $message->messenger() |
523 | 523 | ); |
524 | 524 | } |
525 | - if (! $message->valid_message_type()) { |
|
525 | + if ( ! $message->valid_message_type()) { |
|
526 | 526 | $error_messages[] = sprintf( |
527 | 527 | __('The %s message type is not active at the time of sending.', 'event_espresso'), |
528 | 528 | $message->message_type() |
@@ -687,7 +687,7 @@ discard block |
||
687 | 687 | */ |
688 | 688 | protected function _set_error_message(EE_Message $message, $error_messages) |
689 | 689 | { |
690 | - $error_messages = (array)$error_messages; |
|
690 | + $error_messages = (array) $error_messages; |
|
691 | 691 | if (in_array($message->STS_ID(), EEM_Message::instance()->stati_indicating_failed_sending())) { |
692 | 692 | $notices = EE_Error::has_notices(); |
693 | 693 | $error_messages[] = __( |
@@ -702,7 +702,7 @@ discard block |
||
702 | 702 | } |
703 | 703 | if (count($error_messages) > 0) { |
704 | 704 | $msg = __('Message was not executed successfully.', 'event_espresso'); |
705 | - $msg = $msg . "\n" . implode("\n", $error_messages); |
|
705 | + $msg = $msg."\n".implode("\n", $error_messages); |
|
706 | 706 | $message->set_error_message($msg); |
707 | 707 | } |
708 | 708 | } |
@@ -101,7 +101,7 @@ |
||
101 | 101 | /** |
102 | 102 | * _get_table_filters |
103 | 103 | * |
104 | - * @return array |
|
104 | + * @return string[] |
|
105 | 105 | */ |
106 | 106 | protected function _get_table_filters() |
107 | 107 | { |
@@ -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 | |
@@ -27,205 +27,205 @@ discard block |
||
27 | 27 | class Payment_Log_Admin_List_Table extends EE_Admin_List_Table |
28 | 28 | { |
29 | 29 | |
30 | - /** |
|
31 | - * @param \EE_Admin_Page $admin_page |
|
32 | - * @return Payment_Log_Admin_List_Table |
|
33 | - */ |
|
34 | - public function __construct($admin_page) |
|
35 | - { |
|
36 | - parent::__construct($admin_page); |
|
37 | - } |
|
38 | - |
|
39 | - |
|
40 | - |
|
41 | - /** |
|
42 | - * _setup_data |
|
43 | - * |
|
44 | - * @return void |
|
45 | - */ |
|
46 | - protected function _setup_data() |
|
47 | - { |
|
48 | - $this->_data = $this->_admin_page->get_payment_logs($this->_per_page, $this->_current_page); |
|
49 | - // if(isset($this->_req_data['status'] ) && $this->_req_data['status'] == 'trash'){ |
|
50 | - // $this->_data = $this->_admin_page->get_trashed_questions( $this->_per_page,$this->_current_page, FALSE ); |
|
51 | - // }else{ |
|
52 | - // $this->_data = $this->_admin_page->get_questions( $this->_per_page,$this->_current_page, FALSE ); |
|
53 | - // } |
|
54 | - $this->_all_data_count = $this->_admin_page->get_payment_logs($this->_per_page, $this->_current_page, true); |
|
55 | - add_action('AHEE__EE_Admin_List_Table__extra_tablenav__after_bottom_buttons', array($this, 'add_download_logs_checkbox')); |
|
56 | - } |
|
57 | - |
|
58 | - |
|
59 | - |
|
60 | - /** |
|
61 | - * add_download_logs_checkbox |
|
62 | - * adds a checkbox to the bottom of the list table, instead of at the top with the rest of the filters |
|
63 | - * |
|
64 | - * @return void |
|
65 | - */ |
|
66 | - public function add_download_logs_checkbox() |
|
67 | - { |
|
68 | - echo "<input type='submit' class='button-primary' id='download_results' name='download_results' value='" . __('Download Results', 'event_espresso') . "'>"; |
|
69 | - } |
|
70 | - |
|
71 | - |
|
72 | - |
|
73 | - /** |
|
74 | - * _set_properties |
|
75 | - * |
|
76 | - * @return void |
|
77 | - */ |
|
78 | - protected function _set_properties() |
|
79 | - { |
|
80 | - $this->_wp_list_args = array( |
|
81 | - 'singular' => __('payment log', 'event_espresso'), |
|
82 | - 'plural' => __('payment logs', 'event_espresso'), |
|
83 | - 'ajax' => true, //for now, |
|
84 | - 'screen' => $this->_admin_page->get_current_screen()->id, |
|
85 | - ); |
|
86 | - $this->_columns = array( |
|
87 | - 'cb' => '<input type="checkbox" />', |
|
88 | - 'id' => __('ID', 'event_espresso'), |
|
89 | - 'LOG_time' => __('Time', 'event_espresso'), |
|
90 | - 'PMD_ID' => __('Payment Method', 'event_espresso'), |
|
91 | - 'TXN_ID' => __('Transaction ID', 'event_espresso'), |
|
92 | - ); |
|
93 | - $this->_sortable_columns = array( |
|
94 | - 'LOG_time' => array('LOG_time' => true), |
|
95 | - ); |
|
96 | - $this->_hidden_columns = array(); |
|
97 | - } |
|
98 | - |
|
99 | - |
|
100 | - |
|
101 | - /** |
|
102 | - * _get_table_filters |
|
103 | - * |
|
104 | - * @return array |
|
105 | - */ |
|
106 | - protected function _get_table_filters() |
|
107 | - { |
|
108 | - $filters = array(); |
|
109 | - //todo we're currently using old functions here. We need to move things into the Events_Admin_Page() class as methods. |
|
110 | - $payment_methods = EEM_Payment_Method::instance()->get_all(); |
|
111 | - $payment_method_names = array(array('id' => 'all', 'text' => __("All", 'event_espresso')), array('id' => '0', 'text' => __("Unknown Payment Method", 'event_espresso'))); |
|
112 | - foreach ($payment_methods as $payment_method) { |
|
113 | - $payment_method_names[] = array('id' => $payment_method->ID(), 'text' => $payment_method->admin_name()); |
|
114 | - } |
|
115 | - $filters[] = EEH_Form_Fields::select_input('_payment_method', $payment_method_names, isset($this->_req_data['_payment_method']) ? $this->_req_data['_payment_method'] : 'all'); |
|
116 | - $start_date = isset($this->_req_data['payment-filter-start-date']) ? wp_strip_all_tags($this->_req_data['payment-filter-start-date']) : date('m/d/Y', strtotime('-6 months')); |
|
117 | - $end_date = isset($this->_req_data['payment-filter-end-date']) ? wp_strip_all_tags($this->_req_data['payment-filter-end-date']) : date('m/d/Y'); |
|
118 | - ob_start(); |
|
119 | - ?> |
|
30 | + /** |
|
31 | + * @param \EE_Admin_Page $admin_page |
|
32 | + * @return Payment_Log_Admin_List_Table |
|
33 | + */ |
|
34 | + public function __construct($admin_page) |
|
35 | + { |
|
36 | + parent::__construct($admin_page); |
|
37 | + } |
|
38 | + |
|
39 | + |
|
40 | + |
|
41 | + /** |
|
42 | + * _setup_data |
|
43 | + * |
|
44 | + * @return void |
|
45 | + */ |
|
46 | + protected function _setup_data() |
|
47 | + { |
|
48 | + $this->_data = $this->_admin_page->get_payment_logs($this->_per_page, $this->_current_page); |
|
49 | + // if(isset($this->_req_data['status'] ) && $this->_req_data['status'] == 'trash'){ |
|
50 | + // $this->_data = $this->_admin_page->get_trashed_questions( $this->_per_page,$this->_current_page, FALSE ); |
|
51 | + // }else{ |
|
52 | + // $this->_data = $this->_admin_page->get_questions( $this->_per_page,$this->_current_page, FALSE ); |
|
53 | + // } |
|
54 | + $this->_all_data_count = $this->_admin_page->get_payment_logs($this->_per_page, $this->_current_page, true); |
|
55 | + add_action('AHEE__EE_Admin_List_Table__extra_tablenav__after_bottom_buttons', array($this, 'add_download_logs_checkbox')); |
|
56 | + } |
|
57 | + |
|
58 | + |
|
59 | + |
|
60 | + /** |
|
61 | + * add_download_logs_checkbox |
|
62 | + * adds a checkbox to the bottom of the list table, instead of at the top with the rest of the filters |
|
63 | + * |
|
64 | + * @return void |
|
65 | + */ |
|
66 | + public function add_download_logs_checkbox() |
|
67 | + { |
|
68 | + echo "<input type='submit' class='button-primary' id='download_results' name='download_results' value='" . __('Download Results', 'event_espresso') . "'>"; |
|
69 | + } |
|
70 | + |
|
71 | + |
|
72 | + |
|
73 | + /** |
|
74 | + * _set_properties |
|
75 | + * |
|
76 | + * @return void |
|
77 | + */ |
|
78 | + protected function _set_properties() |
|
79 | + { |
|
80 | + $this->_wp_list_args = array( |
|
81 | + 'singular' => __('payment log', 'event_espresso'), |
|
82 | + 'plural' => __('payment logs', 'event_espresso'), |
|
83 | + 'ajax' => true, //for now, |
|
84 | + 'screen' => $this->_admin_page->get_current_screen()->id, |
|
85 | + ); |
|
86 | + $this->_columns = array( |
|
87 | + 'cb' => '<input type="checkbox" />', |
|
88 | + 'id' => __('ID', 'event_espresso'), |
|
89 | + 'LOG_time' => __('Time', 'event_espresso'), |
|
90 | + 'PMD_ID' => __('Payment Method', 'event_espresso'), |
|
91 | + 'TXN_ID' => __('Transaction ID', 'event_espresso'), |
|
92 | + ); |
|
93 | + $this->_sortable_columns = array( |
|
94 | + 'LOG_time' => array('LOG_time' => true), |
|
95 | + ); |
|
96 | + $this->_hidden_columns = array(); |
|
97 | + } |
|
98 | + |
|
99 | + |
|
100 | + |
|
101 | + /** |
|
102 | + * _get_table_filters |
|
103 | + * |
|
104 | + * @return array |
|
105 | + */ |
|
106 | + protected function _get_table_filters() |
|
107 | + { |
|
108 | + $filters = array(); |
|
109 | + //todo we're currently using old functions here. We need to move things into the Events_Admin_Page() class as methods. |
|
110 | + $payment_methods = EEM_Payment_Method::instance()->get_all(); |
|
111 | + $payment_method_names = array(array('id' => 'all', 'text' => __("All", 'event_espresso')), array('id' => '0', 'text' => __("Unknown Payment Method", 'event_espresso'))); |
|
112 | + foreach ($payment_methods as $payment_method) { |
|
113 | + $payment_method_names[] = array('id' => $payment_method->ID(), 'text' => $payment_method->admin_name()); |
|
114 | + } |
|
115 | + $filters[] = EEH_Form_Fields::select_input('_payment_method', $payment_method_names, isset($this->_req_data['_payment_method']) ? $this->_req_data['_payment_method'] : 'all'); |
|
116 | + $start_date = isset($this->_req_data['payment-filter-start-date']) ? wp_strip_all_tags($this->_req_data['payment-filter-start-date']) : date('m/d/Y', strtotime('-6 months')); |
|
117 | + $end_date = isset($this->_req_data['payment-filter-end-date']) ? wp_strip_all_tags($this->_req_data['payment-filter-end-date']) : date('m/d/Y'); |
|
118 | + ob_start(); |
|
119 | + ?> |
|
120 | 120 | <label for="txn-filter-start-date"><?php _e('Display Transactions from ', 'event_espresso'); ?></label> |
121 | 121 | <input id="payment-filter-start-date" class="datepicker" type="text" value="<?php echo $start_date; ?>" name="payment-filter-start-date" size="15"/> |
122 | 122 | <label for="txn-filter-end-date"><?php _e(' until ', 'event_espresso'); ?></label> |
123 | 123 | <input id="payment-filter-end-date" class="datepicker" type="text" value="<?php echo $end_date; ?>" name="payment-filter-end-date" size="15"/> |
124 | 124 | <?php |
125 | - $filters[] = ob_get_clean(); |
|
126 | - return $filters; |
|
127 | - } |
|
128 | - |
|
129 | - |
|
130 | - |
|
131 | - /** |
|
132 | - * _add_view_counts |
|
133 | - * |
|
134 | - * @return void |
|
135 | - */ |
|
136 | - protected function _add_view_counts() |
|
137 | - { |
|
138 | - $this->_views['all']['count'] = $this->_admin_page->get_payment_logs($this->_per_page, $this->_current_page, true); |
|
139 | - } |
|
140 | - |
|
141 | - |
|
142 | - |
|
143 | - /** |
|
144 | - * column_cb |
|
145 | - * |
|
146 | - * @param \EE_Change_Log $item |
|
147 | - * @return string |
|
148 | - */ |
|
149 | - public function column_cb($item) |
|
150 | - { |
|
151 | - return sprintf('<input type="checkbox" class="option_id" name="checkbox[%1$d]" value="%1$d" />', $item->ID()); |
|
152 | - } |
|
153 | - |
|
154 | - |
|
155 | - |
|
156 | - /** |
|
157 | - * column_id |
|
158 | - * |
|
159 | - * @param \EE_Change_Log $item |
|
160 | - * @return string |
|
161 | - */ |
|
162 | - public function column_id(EE_Change_Log $item) |
|
163 | - { |
|
164 | - $details_query_args = array( |
|
165 | - 'action' => 'payment_log_details', |
|
166 | - 'ID' => $item->ID(), |
|
167 | - ); |
|
168 | - $url = EE_Admin_Page::add_query_args_and_nonce($details_query_args, EE_PAYMENTS_ADMIN_URL); |
|
169 | - return "<a href='$url'>{$item->ID()}</a>"; |
|
170 | - } |
|
171 | - |
|
172 | - |
|
173 | - |
|
174 | - /** |
|
175 | - * column_LOG_time |
|
176 | - * |
|
177 | - * @param \EE_Change_Log $item |
|
178 | - * @return string |
|
179 | - */ |
|
180 | - public function column_LOG_time(EE_Change_Log $item) |
|
181 | - { |
|
182 | - return $item->get_datetime('LOG_time'); |
|
183 | - } |
|
184 | - |
|
185 | - |
|
186 | - |
|
187 | - /** |
|
188 | - * column_PMD_ID |
|
189 | - * |
|
190 | - * @param \EE_Change_Log $item |
|
191 | - * @return string |
|
192 | - */ |
|
193 | - public function column_PMD_ID(EE_Change_Log $item) |
|
194 | - { |
|
195 | - if ($item->object() instanceof EE_Payment_Method) { |
|
196 | - return $item->object()->admin_name(); |
|
197 | - } elseif ($item->object() instanceof EE_Payment && $item->object()->payment_method()) { |
|
198 | - return $item->object()->payment_method()->admin_name(); |
|
199 | - } else { |
|
200 | - return __("No longer exists", 'event_espresso'); |
|
201 | - } |
|
202 | - } |
|
203 | - |
|
204 | - |
|
205 | - |
|
206 | - /** |
|
207 | - * column_TXN_ID |
|
208 | - * |
|
209 | - * @param \EE_Change_Log $item |
|
210 | - * @return string |
|
211 | - */ |
|
212 | - public function column_TXN_ID(EE_Change_Log $item) |
|
213 | - { |
|
214 | - if ($item->object() instanceof EE_Payment) { |
|
215 | - if (EE_Registry::instance()->CAP->current_user_can('ee_read_transaction', 'espresso_transactions_view_transaction', $item->object()->TXN_ID())) { |
|
216 | - $view_txn_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'view_transaction', 'TXN_ID' => $item->object()->TXN_ID()), TXN_ADMIN_URL); |
|
217 | - return '<a href="' |
|
218 | - . $view_txn_lnk_url |
|
219 | - . '" title="' |
|
220 | - . sprintf(esc_attr__('click to view transaction #%s', 'event_espresso'), $item->object()->TXN_ID()) |
|
221 | - . '">' |
|
222 | - . sprintf(__('view txn %s', 'event_espresso'), $item->object()->TXN_ID()) |
|
223 | - . '</a>'; |
|
224 | - } |
|
225 | - } else { |
|
226 | - return __("Unable to find transaction", 'event_espresso'); |
|
227 | - } |
|
228 | - } |
|
125 | + $filters[] = ob_get_clean(); |
|
126 | + return $filters; |
|
127 | + } |
|
128 | + |
|
129 | + |
|
130 | + |
|
131 | + /** |
|
132 | + * _add_view_counts |
|
133 | + * |
|
134 | + * @return void |
|
135 | + */ |
|
136 | + protected function _add_view_counts() |
|
137 | + { |
|
138 | + $this->_views['all']['count'] = $this->_admin_page->get_payment_logs($this->_per_page, $this->_current_page, true); |
|
139 | + } |
|
140 | + |
|
141 | + |
|
142 | + |
|
143 | + /** |
|
144 | + * column_cb |
|
145 | + * |
|
146 | + * @param \EE_Change_Log $item |
|
147 | + * @return string |
|
148 | + */ |
|
149 | + public function column_cb($item) |
|
150 | + { |
|
151 | + return sprintf('<input type="checkbox" class="option_id" name="checkbox[%1$d]" value="%1$d" />', $item->ID()); |
|
152 | + } |
|
153 | + |
|
154 | + |
|
155 | + |
|
156 | + /** |
|
157 | + * column_id |
|
158 | + * |
|
159 | + * @param \EE_Change_Log $item |
|
160 | + * @return string |
|
161 | + */ |
|
162 | + public function column_id(EE_Change_Log $item) |
|
163 | + { |
|
164 | + $details_query_args = array( |
|
165 | + 'action' => 'payment_log_details', |
|
166 | + 'ID' => $item->ID(), |
|
167 | + ); |
|
168 | + $url = EE_Admin_Page::add_query_args_and_nonce($details_query_args, EE_PAYMENTS_ADMIN_URL); |
|
169 | + return "<a href='$url'>{$item->ID()}</a>"; |
|
170 | + } |
|
171 | + |
|
172 | + |
|
173 | + |
|
174 | + /** |
|
175 | + * column_LOG_time |
|
176 | + * |
|
177 | + * @param \EE_Change_Log $item |
|
178 | + * @return string |
|
179 | + */ |
|
180 | + public function column_LOG_time(EE_Change_Log $item) |
|
181 | + { |
|
182 | + return $item->get_datetime('LOG_time'); |
|
183 | + } |
|
184 | + |
|
185 | + |
|
186 | + |
|
187 | + /** |
|
188 | + * column_PMD_ID |
|
189 | + * |
|
190 | + * @param \EE_Change_Log $item |
|
191 | + * @return string |
|
192 | + */ |
|
193 | + public function column_PMD_ID(EE_Change_Log $item) |
|
194 | + { |
|
195 | + if ($item->object() instanceof EE_Payment_Method) { |
|
196 | + return $item->object()->admin_name(); |
|
197 | + } elseif ($item->object() instanceof EE_Payment && $item->object()->payment_method()) { |
|
198 | + return $item->object()->payment_method()->admin_name(); |
|
199 | + } else { |
|
200 | + return __("No longer exists", 'event_espresso'); |
|
201 | + } |
|
202 | + } |
|
203 | + |
|
204 | + |
|
205 | + |
|
206 | + /** |
|
207 | + * column_TXN_ID |
|
208 | + * |
|
209 | + * @param \EE_Change_Log $item |
|
210 | + * @return string |
|
211 | + */ |
|
212 | + public function column_TXN_ID(EE_Change_Log $item) |
|
213 | + { |
|
214 | + if ($item->object() instanceof EE_Payment) { |
|
215 | + if (EE_Registry::instance()->CAP->current_user_can('ee_read_transaction', 'espresso_transactions_view_transaction', $item->object()->TXN_ID())) { |
|
216 | + $view_txn_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'view_transaction', 'TXN_ID' => $item->object()->TXN_ID()), TXN_ADMIN_URL); |
|
217 | + return '<a href="' |
|
218 | + . $view_txn_lnk_url |
|
219 | + . '" title="' |
|
220 | + . sprintf(esc_attr__('click to view transaction #%s', 'event_espresso'), $item->object()->TXN_ID()) |
|
221 | + . '">' |
|
222 | + . sprintf(__('view txn %s', 'event_espresso'), $item->object()->TXN_ID()) |
|
223 | + . '</a>'; |
|
224 | + } |
|
225 | + } else { |
|
226 | + return __("Unable to find transaction", 'event_espresso'); |
|
227 | + } |
|
228 | + } |
|
229 | 229 | |
230 | 230 | |
231 | 231 |
@@ -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 | |
@@ -65,7 +65,7 @@ discard block |
||
65 | 65 | */ |
66 | 66 | public function add_download_logs_checkbox() |
67 | 67 | { |
68 | - echo "<input type='submit' class='button-primary' id='download_results' name='download_results' value='" . __('Download Results', 'event_espresso') . "'>"; |
|
68 | + echo "<input type='submit' class='button-primary' id='download_results' name='download_results' value='".__('Download Results', 'event_espresso')."'>"; |
|
69 | 69 | } |
70 | 70 | |
71 | 71 |
@@ -2,11 +2,9 @@ |
||
2 | 2 | namespace EventEspresso\core\libraries\rest_api; |
3 | 3 | |
4 | 4 | use DomainException; |
5 | -use EE_Capabilities; |
|
6 | 5 | use EE_Datetime_Field; |
7 | 6 | use EE_Error; |
8 | 7 | use EE_Infinite_Integer_Field; |
9 | -use EE_Maybe_Serialized_Simple_HTML_Field; |
|
10 | 8 | use EE_Model_Field_Base; |
11 | 9 | use EE_Serialized_Text_Field; |
12 | 10 | use EEM_Base; |
@@ -12,7 +12,7 @@ discard block |
||
12 | 12 | use EEM_Base; |
13 | 13 | |
14 | 14 | if (! defined('EVENT_ESPRESSO_VERSION')) { |
15 | - exit('No direct script access allowed'); |
|
15 | + exit('No direct script access allowed'); |
|
16 | 16 | } |
17 | 17 | |
18 | 18 | |
@@ -37,837 +37,837 @@ discard block |
||
37 | 37 | class ModelDataTranslator |
38 | 38 | { |
39 | 39 | |
40 | - /** |
|
41 | - * We used to use -1 for infinity in the rest api, but that's ambiguous for |
|
42 | - * fields that COULD contain -1; so we use null |
|
43 | - */ |
|
44 | - const EE_INF_IN_REST = null; |
|
45 | - |
|
46 | - |
|
47 | - |
|
48 | - /** |
|
49 | - * Prepares a possible array of input values from JSON for use by the models |
|
50 | - * |
|
51 | - * @param EE_Model_Field_Base $field_obj |
|
52 | - * @param mixed $original_value_maybe_array |
|
53 | - * @param string $requested_version |
|
54 | - * @param string $timezone_string treat values as being in this timezone |
|
55 | - * @return mixed |
|
56 | - * @throws RestException |
|
57 | - */ |
|
58 | - public static function prepareFieldValuesFromJson( |
|
59 | - $field_obj, |
|
60 | - $original_value_maybe_array, |
|
61 | - $requested_version, |
|
62 | - $timezone_string = 'UTC' |
|
63 | - ) { |
|
64 | - if (is_array($original_value_maybe_array) |
|
65 | - && ! $field_obj instanceof EE_Serialized_Text_Field |
|
66 | - ) { |
|
67 | - $new_value_maybe_array = array(); |
|
68 | - foreach ($original_value_maybe_array as $array_key => $array_item) { |
|
69 | - $new_value_maybe_array[$array_key] = ModelDataTranslator::prepareFieldValueFromJson( |
|
70 | - $field_obj, |
|
71 | - $array_item, |
|
72 | - $requested_version, |
|
73 | - $timezone_string |
|
74 | - ); |
|
75 | - } |
|
76 | - } else { |
|
77 | - $new_value_maybe_array = ModelDataTranslator::prepareFieldValueFromJson( |
|
78 | - $field_obj, |
|
79 | - $original_value_maybe_array, |
|
80 | - $requested_version, |
|
81 | - $timezone_string |
|
82 | - ); |
|
83 | - } |
|
84 | - return $new_value_maybe_array; |
|
85 | - } |
|
86 | - |
|
87 | - |
|
88 | - |
|
89 | - /** |
|
90 | - * Prepares an array of field values FOR use in JSON/REST API |
|
91 | - * |
|
92 | - * @param EE_Model_Field_Base $field_obj |
|
93 | - * @param mixed $original_value_maybe_array |
|
94 | - * @param string $request_version (eg 4.8.36) |
|
95 | - * @return array |
|
96 | - */ |
|
97 | - public static function prepareFieldValuesForJson($field_obj, $original_value_maybe_array, $request_version) |
|
98 | - { |
|
99 | - if (is_array($original_value_maybe_array)) { |
|
100 | - $new_value = array(); |
|
101 | - foreach ($original_value_maybe_array as $key => $value) { |
|
102 | - $new_value[$key] = ModelDataTranslator::prepareFieldValuesForJson($field_obj, $value, $request_version); |
|
103 | - } |
|
104 | - } else { |
|
105 | - $new_value = ModelDataTranslator::prepareFieldValueForJson( |
|
106 | - $field_obj, |
|
107 | - $original_value_maybe_array, |
|
108 | - $request_version |
|
109 | - ); |
|
110 | - } |
|
111 | - return $new_value; |
|
112 | - } |
|
113 | - |
|
114 | - |
|
115 | - /** |
|
116 | - * Prepares incoming data from the json or $_REQUEST parameters for the models' |
|
117 | - * "$query_params". |
|
118 | - * |
|
119 | - * @param EE_Model_Field_Base $field_obj |
|
120 | - * @param mixed $original_value |
|
121 | - * @param string $requested_version |
|
122 | - * @param string $timezone_string treat values as being in this timezone |
|
123 | - * @return mixed |
|
124 | - * @throws RestException |
|
125 | - * @throws DomainException |
|
126 | - * @throws EE_Error |
|
127 | - */ |
|
128 | - public static function prepareFieldValueFromJson( |
|
129 | - $field_obj, |
|
130 | - $original_value, |
|
131 | - $requested_version, |
|
132 | - $timezone_string = 'UTC' // UTC |
|
133 | - ) { |
|
134 | - //check if they accidentally submitted an error value. If so throw an exception |
|
135 | - if (is_array($original_value) |
|
136 | - && isset($original_value['error_code'], $original_value['error_message'])) { |
|
137 | - throw new RestException( |
|
138 | - 'rest_submitted_error_value', |
|
139 | - sprintf( |
|
140 | - esc_html__( |
|
141 | - 'You tried to submit a JSON error object as a value for %1$s. That\'s not allowed.', |
|
142 | - 'event_espresso' |
|
143 | - ), |
|
144 | - $field_obj->get_name() |
|
145 | - ), |
|
146 | - array( |
|
147 | - 'status' => 400, |
|
148 | - ) |
|
149 | - ); |
|
150 | - } |
|
151 | - //double-check for serialized PHP. We never accept serialized PHP. No way Jose. |
|
152 | - ModelDataTranslator::throwExceptionIfContainsSerializedData($original_value); |
|
153 | - $timezone_string = $timezone_string !== '' ? $timezone_string : get_option('timezone_string', ''); |
|
154 | - $new_value = null; |
|
155 | - //walk through the submitted data and double-check for serialized PHP. We never accept serialized PHP. No |
|
156 | - // way Jose. |
|
157 | - ModelDataTranslator::throwExceptionIfContainsSerializedData($original_value); |
|
158 | - if ($field_obj instanceof EE_Infinite_Integer_Field |
|
159 | - && in_array($original_value, array(null, ''), true) |
|
160 | - ) { |
|
161 | - $new_value = EE_INF; |
|
162 | - } elseif ($field_obj instanceof EE_Datetime_Field) { |
|
163 | - $new_value = rest_parse_date( |
|
164 | - self::getTimestampWithTimezoneOffset($original_value, $field_obj, $timezone_string) |
|
165 | - ); |
|
166 | - if ($new_value === false) { |
|
167 | - throw new RestException( |
|
168 | - 'invalid_format_for_timestamp', |
|
169 | - sprintf( |
|
170 | - esc_html__( |
|
171 | - 'Timestamps received on a request as the value for Date and Time fields must be in %1$s/%2$s format. The timestamp provided (%3$s) is not that format.', |
|
172 | - 'event_espresso' |
|
173 | - ), |
|
174 | - 'RFC3339', |
|
175 | - 'ISO8601', |
|
176 | - $original_value |
|
177 | - ), |
|
178 | - array( |
|
179 | - 'status' => 400 |
|
180 | - ) |
|
181 | - ); |
|
182 | - } |
|
183 | - } else { |
|
184 | - $new_value = $original_value; |
|
185 | - } |
|
186 | - return $new_value; |
|
187 | - } |
|
188 | - |
|
189 | - |
|
190 | - /** |
|
191 | - * This checks if the incoming timestamp has timezone information already on it and if it doesn't then adds timezone |
|
192 | - * information via details obtained from the host site. |
|
193 | - * |
|
194 | - * @param string $original_timestamp |
|
195 | - * @param EE_Datetime_Field $datetime_field |
|
196 | - * @param $timezone_string |
|
197 | - * @return string |
|
198 | - * @throws DomainException |
|
199 | - */ |
|
200 | - private static function getTimestampWithTimezoneOffset( |
|
201 | - $original_timestamp, |
|
202 | - EE_Datetime_Field $datetime_field, |
|
203 | - $timezone_string |
|
204 | - ) { |
|
205 | - //already have timezone information? |
|
206 | - if (preg_match('/Z|(\+|\-)(\d{2}:\d{2})/', $original_timestamp)) { |
|
207 | - //yes, we're ignoring the timezone. |
|
208 | - return $original_timestamp; |
|
209 | - } |
|
210 | - //need to append timezone |
|
211 | - list($offset_sign, $offset_secs) = self::parseTimezoneOffset( |
|
212 | - $datetime_field->get_timezone_offset( |
|
213 | - new \DateTimeZone($timezone_string), |
|
214 | - $original_timestamp |
|
215 | - ) |
|
216 | - ); |
|
217 | - $offset_string = |
|
218 | - str_pad( |
|
219 | - floor($offset_secs / HOUR_IN_SECONDS), |
|
220 | - 2, |
|
221 | - '0', |
|
222 | - STR_PAD_LEFT |
|
223 | - ) |
|
224 | - . ':' |
|
225 | - . str_pad( |
|
226 | - ($offset_secs % HOUR_IN_SECONDS) / MINUTE_IN_SECONDS, |
|
227 | - 2, |
|
228 | - '0', |
|
229 | - STR_PAD_LEFT |
|
230 | - ); |
|
231 | - return $original_timestamp . $offset_sign . $offset_string; |
|
232 | - } |
|
233 | - |
|
234 | - |
|
235 | - |
|
236 | - /** |
|
237 | - * Throws an exception if $data is a serialized PHP string (or somehow an actually PHP object, although I don't |
|
238 | - * think that can happen). If $data is an array, recurses into its keys and values |
|
239 | - * @param mixed $data |
|
240 | - * @throws RestException |
|
241 | - * @return void |
|
242 | - */ |
|
243 | - public static function throwExceptionIfContainsSerializedData($data) |
|
244 | - { |
|
245 | - if (is_array($data)) { |
|
246 | - foreach ($data as $key => $value) { |
|
247 | - ModelDataTranslator::throwExceptionIfContainsSerializedData($key); |
|
248 | - ModelDataTranslator::throwExceptionIfContainsSerializedData($value); |
|
249 | - } |
|
250 | - } else { |
|
251 | - if (is_serialized($data) || is_object($data)) { |
|
252 | - throw new RestException( |
|
253 | - 'serialized_data_submission_prohibited', |
|
254 | - esc_html__( |
|
255 | - // @codingStandardsIgnoreStart |
|
256 | - 'You tried to submit a string of serialized text. Serialized PHP is prohibited over the EE4 REST API.', |
|
257 | - // @codingStandardsIgnoreEnd |
|
258 | - 'event_espresso' |
|
259 | - ) |
|
260 | - ); |
|
261 | - } |
|
262 | - } |
|
263 | - } |
|
264 | - |
|
265 | - |
|
266 | - |
|
267 | - /** |
|
268 | - * determines what's going on with them timezone strings |
|
269 | - * |
|
270 | - * @param int $timezone_offset |
|
271 | - * @return array |
|
272 | - */ |
|
273 | - private static function parseTimezoneOffset($timezone_offset) |
|
274 | - { |
|
275 | - $first_char = substr((string)$timezone_offset, 0, 1); |
|
276 | - if ($first_char === '+' || $first_char === '-') { |
|
277 | - $offset_sign = $first_char; |
|
278 | - $offset_secs = substr((string)$timezone_offset, 1); |
|
279 | - } else { |
|
280 | - $offset_sign = '+'; |
|
281 | - $offset_secs = $timezone_offset; |
|
282 | - } |
|
283 | - return array($offset_sign, $offset_secs); |
|
284 | - } |
|
285 | - |
|
286 | - |
|
287 | - |
|
288 | - /** |
|
289 | - * Prepares a field's value for display in the API |
|
290 | - * |
|
291 | - * @param EE_Model_Field_Base $field_obj |
|
292 | - * @param mixed $original_value |
|
293 | - * @param string $requested_version |
|
294 | - * @return mixed |
|
295 | - */ |
|
296 | - public static function prepareFieldValueForJson($field_obj, $original_value, $requested_version) |
|
297 | - { |
|
298 | - if ($original_value === EE_INF) { |
|
299 | - $new_value = ModelDataTranslator::EE_INF_IN_REST; |
|
300 | - } elseif ($field_obj instanceof EE_Datetime_Field) { |
|
301 | - if (is_string($original_value)) { |
|
302 | - //did they submit a string of a unix timestamp? |
|
303 | - if (is_numeric($original_value)) { |
|
304 | - $datetime_obj = new \DateTime(); |
|
305 | - $datetime_obj->setTimestamp((int)$original_value); |
|
306 | - } else { |
|
307 | - //first, check if its a MySQL timestamp in GMT |
|
308 | - $datetime_obj = \DateTime::createFromFormat('Y-m-d H:i:s', $original_value); |
|
309 | - } |
|
310 | - if (! $datetime_obj instanceof \DateTime) { |
|
311 | - //so it's not a unix timestamp or a MySQL timestamp. Maybe its in the field's date/time format? |
|
312 | - $datetime_obj = $field_obj->prepare_for_set($original_value); |
|
313 | - } |
|
314 | - $original_value = $datetime_obj; |
|
315 | - } |
|
316 | - if ($original_value instanceof \DateTime) { |
|
317 | - $new_value = $original_value->format('Y-m-d H:i:s'); |
|
318 | - } elseif (is_int($original_value) || is_float($original_value)) { |
|
319 | - $new_value = date('Y-m-d H:i:s', $original_value); |
|
320 | - } elseif($original_value === null || $original_value === '') { |
|
321 | - $new_value = null; |
|
322 | - } else { |
|
323 | - //so it's not a datetime object, unix timestamp (as string or int), |
|
324 | - //MySQL timestamp, or even a string in the field object's format. So no idea what it is |
|
325 | - throw new \EE_Error( |
|
326 | - sprintf( |
|
327 | - esc_html__( |
|
328 | - // @codingStandardsIgnoreStart |
|
329 | - 'The value "%1$s" for the field "%2$s" on model "%3$s" could not be understood. It should be a PHP DateTime, unix timestamp, MySQL date, or string in the format "%4$s".', |
|
330 | - // @codingStandardsIgnoreEnd |
|
331 | - 'event_espressso' |
|
332 | - ), |
|
333 | - $original_value, |
|
334 | - $field_obj->get_name(), |
|
335 | - $field_obj->get_model_name(), |
|
336 | - $field_obj->get_time_format() . ' ' . $field_obj->get_time_format() |
|
337 | - ) |
|
338 | - ); |
|
339 | - } |
|
340 | - $new_value = mysql_to_rfc3339($new_value); |
|
341 | - } else { |
|
342 | - $new_value = $original_value; |
|
343 | - } |
|
344 | - //are we about to send an object? just don't. We have no good way to represent it in JSON. |
|
345 | - // can't just check using is_object() because that missed PHP incomplete objects |
|
346 | - if (! ModelDataTranslator::isRepresentableInJson($new_value)) { |
|
347 | - $new_value = array( |
|
348 | - 'error_code' => 'php_object_not_return', |
|
349 | - 'error_message' => esc_html__('The value of this field in the database is a PHP object, which can\'t be represented in JSON.', 'event_espresso') |
|
350 | - ); |
|
351 | - } |
|
352 | - return apply_filters( |
|
353 | - 'FHEE__EventEspresso\core\libraries\rest_api\Model_Data_Translator__prepare_field_for_rest_api', |
|
354 | - $new_value, |
|
355 | - $field_obj, |
|
356 | - $original_value, |
|
357 | - $requested_version |
|
358 | - ); |
|
359 | - } |
|
360 | - |
|
361 | - |
|
362 | - |
|
363 | - /** |
|
364 | - * Prepares condition-query-parameters (like what's in where and having) from |
|
365 | - * the format expected in the API to use in the models |
|
366 | - * |
|
367 | - * @param array $inputted_query_params_of_this_type |
|
368 | - * @param EEM_Base $model |
|
369 | - * @param string $requested_version |
|
370 | - * @param boolean $writing whether this data will be written to the DB, or if we're just building a query. |
|
371 | - * If we're writing to the DB, we don't expect any operators, or any logic query parameters, |
|
372 | - * and we also won't accept serialized data unless the current user has unfiltered_html. |
|
373 | - * @return array |
|
374 | - * @throws DomainException |
|
375 | - * @throws RestException |
|
376 | - * @throws EE_Error |
|
377 | - */ |
|
378 | - public static function prepareConditionsQueryParamsForModels( |
|
379 | - $inputted_query_params_of_this_type, |
|
380 | - EEM_Base $model, |
|
381 | - $requested_version, |
|
382 | - $writing = false |
|
383 | - ) { |
|
384 | - $query_param_for_models = array(); |
|
385 | - $valid_operators = $model->valid_operators(); |
|
386 | - foreach ($inputted_query_params_of_this_type as $query_param_key => $query_param_value) { |
|
387 | - $is_gmt_datetime_field = false; |
|
388 | - $query_param_sans_stars = ModelDataTranslator::removeStarsAndAnythingAfterFromConditionQueryParamKey( |
|
389 | - $query_param_key |
|
390 | - ); |
|
391 | - $field = ModelDataTranslator::deduceFieldFromQueryParam( |
|
392 | - $query_param_sans_stars, |
|
393 | - $model |
|
394 | - ); |
|
395 | - //double-check is it a *_gmt field? |
|
396 | - if (! $field instanceof EE_Model_Field_Base |
|
397 | - && ModelDataTranslator::isGmtDateFieldName($query_param_sans_stars) |
|
398 | - ) { |
|
399 | - //yep, take off '_gmt', and find the field |
|
400 | - $query_param_key = ModelDataTranslator::removeGmtFromFieldName($query_param_sans_stars); |
|
401 | - $field = ModelDataTranslator::deduceFieldFromQueryParam( |
|
402 | - $query_param_key, |
|
403 | - $model |
|
404 | - ); |
|
405 | - $timezone = 'UTC'; |
|
406 | - $is_gmt_datetime_field = true; |
|
407 | - } elseif ($field instanceof EE_Datetime_Field) { |
|
408 | - //so it's not a GMT field. Set the timezone on the model to the default |
|
409 | - $timezone = \EEH_DTT_Helper::get_valid_timezone_string(); |
|
410 | - } else { |
|
411 | - //just keep using what's already set for the timezone |
|
412 | - $timezone = $model->get_timezone(); |
|
413 | - } |
|
414 | - if ($field instanceof EE_Model_Field_Base) { |
|
415 | - if (! $writing && is_array($query_param_value)) { |
|
416 | - if (! \EEH_Array::is_array_numerically_and_sequentially_indexed($query_param_value)) { |
|
417 | - if (defined('EE_REST_API_DEBUG_MODE') && EE_REST_API_DEBUG_MODE) { |
|
418 | - throw new RestException( |
|
419 | - 'numerically_indexed_array_of_values_only', |
|
420 | - sprintf( |
|
421 | - esc_html__( |
|
422 | - 'The array provided for the parameter "%1$s" should be numerically indexed.', |
|
423 | - 'event_espresso' |
|
424 | - ), |
|
425 | - $query_param_key |
|
426 | - ), |
|
427 | - array( |
|
428 | - 'status' => 400, |
|
429 | - ) |
|
430 | - ); |
|
431 | - } |
|
432 | - } |
|
433 | - //did they specify an operator? |
|
434 | - if (isset($query_param_value[0]) |
|
435 | - && isset($valid_operators[$query_param_value[0]]) |
|
436 | - ) { |
|
437 | - $op = $query_param_value[0]; |
|
438 | - $translated_value = array($op); |
|
439 | - if (array_key_exists($op, $model->valid_in_style_operators()) |
|
440 | - && isset($query_param_value[1]) |
|
441 | - && ! isset($query_param_value[2]) |
|
442 | - ) { |
|
443 | - $translated_value[] = ModelDataTranslator::prepareFieldValuesFromJson( |
|
444 | - $field, |
|
445 | - $query_param_value[1], |
|
446 | - $requested_version, |
|
447 | - $timezone |
|
448 | - ); |
|
449 | - } elseif (array_key_exists($op, $model->valid_between_style_operators()) |
|
450 | - && isset($query_param_value[1], $query_param_value[2]) |
|
451 | - && !isset($query_param_value[3]) |
|
452 | - ) { |
|
453 | - $translated_value[] = ModelDataTranslator::prepareFieldValuesFromJson( |
|
454 | - $field, |
|
455 | - $query_param_value[1], |
|
456 | - $requested_version, |
|
457 | - $timezone |
|
458 | - ); |
|
459 | - $translated_value[] = ModelDataTranslator::prepareFieldValuesFromJson( |
|
460 | - $field, |
|
461 | - $query_param_value[2], |
|
462 | - $requested_version, |
|
463 | - $timezone |
|
464 | - ); |
|
465 | - } elseif (array_key_exists($op, $model->valid_like_style_operators()) |
|
466 | - && isset($query_param_value[1]) |
|
467 | - && ! isset($query_param_value[2]) |
|
468 | - ) { |
|
469 | - //we want to leave this value mostly-as-is (eg don't force it to be a float |
|
470 | - //or a boolean or an enum value. Leave it as-is with wildcards etc) |
|
471 | - //but do verify it at least doesn't have any serialized data |
|
472 | - ModelDataTranslator::throwExceptionIfContainsSerializedData($query_param_value[1]); |
|
473 | - $translated_value[] = $query_param_value[1]; |
|
474 | - } elseif (array_key_exists($op, $model->valid_null_style_operators()) |
|
475 | - && !isset($query_param_value[1])) { |
|
476 | - //no arguments should have been provided, so don't look for any |
|
477 | - } elseif (isset($query_param_value[1]) |
|
478 | - && !isset($query_param_value[2]) |
|
479 | - && ! array_key_exists( |
|
480 | - $op, |
|
481 | - array_merge( |
|
482 | - $model->valid_in_style_operators(), |
|
483 | - $model->valid_null_style_operators(), |
|
484 | - $model->valid_like_style_operators(), |
|
485 | - $model->valid_between_style_operators() |
|
486 | - ) |
|
487 | - ) |
|
488 | - ) { |
|
489 | - //it's a valid operator, but none of the exceptions. Treat it normally. |
|
490 | - $translated_value[] = ModelDataTranslator::prepareFieldValuesFromJson( |
|
491 | - $field, |
|
492 | - $query_param_value[1], |
|
493 | - $requested_version, |
|
494 | - $timezone |
|
495 | - ); |
|
496 | - } else { |
|
497 | - //so they provided a valid operator, but wrong number of arguments |
|
498 | - if (defined('EE_REST_API_DEBUG_MODE') && EE_REST_API_DEBUG_MODE) { |
|
499 | - throw new RestException( |
|
500 | - 'wrong_number_of_arguments', |
|
501 | - sprintf( |
|
502 | - esc_html__( |
|
503 | - 'The operator you provided, "%1$s" had the wrong number of arguments', |
|
504 | - 'event_espresso' |
|
505 | - ), |
|
506 | - $op |
|
507 | - ), |
|
508 | - array( |
|
509 | - 'status' => 400, |
|
510 | - ) |
|
511 | - ); |
|
512 | - } |
|
513 | - $translated_value = null; |
|
514 | - } |
|
515 | - } else { |
|
516 | - //so they didn't provide a valid operator |
|
517 | - if (defined('EE_REST_API_DEBUG_MODE') && EE_REST_API_DEBUG_MODE) { |
|
518 | - throw new RestException( |
|
519 | - 'invalid_operator', |
|
520 | - sprintf( |
|
521 | - esc_html__( |
|
522 | - 'You provided an invalid parameter, with key "%1$s" and value "%2$s"', |
|
523 | - 'event_espresso' |
|
524 | - ), |
|
525 | - $query_param_key, |
|
526 | - $query_param_value |
|
527 | - ), |
|
528 | - array( |
|
529 | - 'status' => 400, |
|
530 | - ) |
|
531 | - ); |
|
532 | - } |
|
533 | - //if we aren't in debug mode, then just try our best to fulfill the user's request |
|
534 | - $translated_value = null; |
|
535 | - } |
|
536 | - } else { |
|
537 | - $translated_value = ModelDataTranslator::prepareFieldValueFromJson( |
|
538 | - $field, |
|
539 | - $query_param_value, |
|
540 | - $requested_version, |
|
541 | - $timezone |
|
542 | - ); |
|
543 | - } |
|
544 | - if ( |
|
545 | - (isset($query_param_for_models[$query_param_key]) && $is_gmt_datetime_field) |
|
546 | - || |
|
547 | - $translated_value === null |
|
548 | - ) { |
|
549 | - //they have already provided a non-gmt field, ignore the gmt one. That's what WP core |
|
550 | - //currently does (they might change it though). See https://core.trac.wordpress.org/ticket/39954 |
|
551 | - //OR we couldn't create a translated value from their input |
|
552 | - continue; |
|
553 | - } |
|
554 | - $query_param_for_models[$query_param_key] = $translated_value; |
|
555 | - } else { |
|
556 | - //so this param doesn't correspond to a field eh? |
|
557 | - if ($writing) { |
|
558 | - //always tell API clients about invalid parameters when they're creating data. Otherwise, |
|
559 | - //they are probably going to create invalid data |
|
560 | - throw new RestException( |
|
561 | - 'invalid_field', |
|
562 | - sprintf( |
|
563 | - esc_html__('You have provided an invalid parameter: "%1$s"', 'event_espresso'), |
|
564 | - $query_param_key |
|
565 | - ) |
|
566 | - ); |
|
567 | - } else { |
|
568 | - //so it's not for a field, is it a logic query param key? |
|
569 | - if (in_array( |
|
570 | - $query_param_sans_stars, |
|
571 | - $model->logic_query_param_keys() |
|
572 | - )) { |
|
573 | - $query_param_for_models[$query_param_key] = ModelDataTranslator::prepareConditionsQueryParamsForModels( |
|
574 | - $query_param_value, |
|
575 | - $model, |
|
576 | - $requested_version |
|
577 | - ); |
|
578 | - } elseif (defined('EE_REST_API_DEBUG_MODE') && EE_REST_API_DEBUG_MODE) { |
|
579 | - //only tell API clients they got it wrong if we're in debug mode |
|
580 | - //otherwise try our best ot fulfill their request by ignoring this invalid data |
|
581 | - throw new RestException( |
|
582 | - 'invalid_parameter', |
|
583 | - sprintf( |
|
584 | - esc_html__( |
|
585 | - 'You provided an invalid parameter, with key "%1$s"', |
|
586 | - 'event_espresso' |
|
587 | - ), |
|
588 | - $query_param_sans_stars |
|
589 | - ), |
|
590 | - array( |
|
591 | - 'status' => 400, |
|
592 | - ) |
|
593 | - ); |
|
594 | - } |
|
595 | - } |
|
596 | - } |
|
597 | - } |
|
598 | - return $query_param_for_models; |
|
599 | - } |
|
600 | - |
|
601 | - |
|
602 | - |
|
603 | - /** |
|
604 | - * Mostly checks if the last 4 characters are "_gmt", indicating its a |
|
605 | - * gmt date field name |
|
606 | - * |
|
607 | - * @param string $field_name |
|
608 | - * @return boolean |
|
609 | - */ |
|
610 | - public static function isGmtDateFieldName($field_name) |
|
611 | - { |
|
612 | - return substr( |
|
613 | - ModelDataTranslator::removeStarsAndAnythingAfterFromConditionQueryParamKey($field_name), |
|
614 | - -4, |
|
615 | - 4 |
|
616 | - ) === '_gmt'; |
|
617 | - } |
|
618 | - |
|
619 | - |
|
620 | - |
|
621 | - /** |
|
622 | - * Removes the last "_gmt" part of a field name (and if there is no "_gmt" at the end, leave it alone) |
|
623 | - * |
|
624 | - * @param string $field_name |
|
625 | - * @return string |
|
626 | - */ |
|
627 | - public static function removeGmtFromFieldName($field_name) |
|
628 | - { |
|
629 | - if (! ModelDataTranslator::isGmtDateFieldName($field_name)) { |
|
630 | - return $field_name; |
|
631 | - } |
|
632 | - $query_param_sans_stars = ModelDataTranslator::removeStarsAndAnythingAfterFromConditionQueryParamKey( |
|
633 | - $field_name |
|
634 | - ); |
|
635 | - $query_param_sans_gmt_and_sans_stars = substr( |
|
636 | - $query_param_sans_stars, |
|
637 | - 0, |
|
638 | - strrpos( |
|
639 | - $field_name, |
|
640 | - '_gmt' |
|
641 | - ) |
|
642 | - ); |
|
643 | - return str_replace($query_param_sans_stars, $query_param_sans_gmt_and_sans_stars, $field_name); |
|
644 | - } |
|
645 | - |
|
646 | - |
|
647 | - |
|
648 | - /** |
|
649 | - * Takes a field name from the REST API and prepares it for the model querying |
|
650 | - * |
|
651 | - * @param string $field_name |
|
652 | - * @return string |
|
653 | - */ |
|
654 | - public static function prepareFieldNameFromJson($field_name) |
|
655 | - { |
|
656 | - if (ModelDataTranslator::isGmtDateFieldName($field_name)) { |
|
657 | - return ModelDataTranslator::removeGmtFromFieldName($field_name); |
|
658 | - } |
|
659 | - return $field_name; |
|
660 | - } |
|
661 | - |
|
662 | - |
|
663 | - |
|
664 | - /** |
|
665 | - * Takes array of field names from REST API and prepares for models |
|
666 | - * |
|
667 | - * @param array $field_names |
|
668 | - * @return array of field names (possibly include model prefixes) |
|
669 | - */ |
|
670 | - public static function prepareFieldNamesFromJson(array $field_names) |
|
671 | - { |
|
672 | - $new_array = array(); |
|
673 | - foreach ($field_names as $key => $field_name) { |
|
674 | - $new_array[$key] = ModelDataTranslator::prepareFieldNameFromJson($field_name); |
|
675 | - } |
|
676 | - return $new_array; |
|
677 | - } |
|
678 | - |
|
679 | - |
|
680 | - |
|
681 | - /** |
|
682 | - * Takes array where array keys are field names (possibly with model path prefixes) |
|
683 | - * from the REST API and prepares them for model querying |
|
684 | - * |
|
685 | - * @param array $field_names_as_keys |
|
686 | - * @return array |
|
687 | - */ |
|
688 | - public static function prepareFieldNamesInArrayKeysFromJson(array $field_names_as_keys) |
|
689 | - { |
|
690 | - $new_array = array(); |
|
691 | - foreach ($field_names_as_keys as $field_name => $value) { |
|
692 | - $new_array[ModelDataTranslator::prepareFieldNameFromJson($field_name)] = $value; |
|
693 | - } |
|
694 | - return $new_array; |
|
695 | - } |
|
696 | - |
|
697 | - |
|
698 | - |
|
699 | - /** |
|
700 | - * Prepares an array of model query params for use in the REST API |
|
701 | - * |
|
702 | - * @param array $model_query_params |
|
703 | - * @param EEM_Base $model |
|
704 | - * @param string $requested_version eg "4.8.36". If null is provided, defaults to the latest release of the EE4 |
|
705 | - * REST API |
|
706 | - * @return array which can be passed into the EE4 REST API when querying a model resource |
|
707 | - * @throws EE_Error |
|
708 | - */ |
|
709 | - public static function prepareQueryParamsForRestApi( |
|
710 | - array $model_query_params, |
|
711 | - EEM_Base $model, |
|
712 | - $requested_version = null |
|
713 | - ) { |
|
714 | - if ($requested_version === null) { |
|
715 | - $requested_version = \EED_Core_Rest_Api::latest_rest_api_version(); |
|
716 | - } |
|
717 | - $rest_query_params = $model_query_params; |
|
718 | - if (isset($model_query_params[0])) { |
|
719 | - $rest_query_params['where'] = ModelDataTranslator::prepareConditionsQueryParamsForRestApi( |
|
720 | - $model_query_params[0], |
|
721 | - $model, |
|
722 | - $requested_version |
|
723 | - ); |
|
724 | - unset($rest_query_params[0]); |
|
725 | - } |
|
726 | - if (isset($model_query_params['having'])) { |
|
727 | - $rest_query_params['having'] = ModelDataTranslator::prepareConditionsQueryParamsForRestApi( |
|
728 | - $model_query_params['having'], |
|
729 | - $model, |
|
730 | - $requested_version |
|
731 | - ); |
|
732 | - } |
|
733 | - return apply_filters( |
|
734 | - 'FHEE__EventEspresso\core\libraries\rest_api\Model_Data_Translator__prepare_query_params_for_rest_api', |
|
735 | - $rest_query_params, |
|
736 | - $model_query_params, |
|
737 | - $model, |
|
738 | - $requested_version |
|
739 | - ); |
|
740 | - } |
|
741 | - |
|
742 | - |
|
743 | - |
|
744 | - /** |
|
745 | - * Prepares all the sub-conditions query parameters (eg having or where conditions) for use in the rest api |
|
746 | - * |
|
747 | - * @param array $inputted_query_params_of_this_type eg like the "where" or "having" conditions query params |
|
748 | - * passed into EEM_Base::get_all() |
|
749 | - * @param EEM_Base $model |
|
750 | - * @param string $requested_version eg "4.8.36" |
|
751 | - * @return array ready for use in the rest api query params |
|
752 | - * @throws EE_Error |
|
753 | - * @throws ObjectDetectedException if somehow a PHP object were in the query params' values, |
|
754 | - * (which would be really unusual) |
|
755 | - */ |
|
756 | - public static function prepareConditionsQueryParamsForRestApi( |
|
757 | - $inputted_query_params_of_this_type, |
|
758 | - EEM_Base $model, |
|
759 | - $requested_version |
|
760 | - ) { |
|
761 | - $query_param_for_models = array(); |
|
762 | - foreach ($inputted_query_params_of_this_type as $query_param_key => $query_param_value) { |
|
763 | - $field = ModelDataTranslator::deduceFieldFromQueryParam( |
|
764 | - ModelDataTranslator::removeStarsAndAnythingAfterFromConditionQueryParamKey($query_param_key), |
|
765 | - $model |
|
766 | - ); |
|
767 | - if ($field instanceof EE_Model_Field_Base) { |
|
768 | - //did they specify an operator? |
|
769 | - if (is_array($query_param_value)) { |
|
770 | - $op = $query_param_value[0]; |
|
771 | - $translated_value = array($op); |
|
772 | - if (isset($query_param_value[1])) { |
|
773 | - $value = $query_param_value[1]; |
|
774 | - $translated_value[1] = ModelDataTranslator::prepareFieldValuesForJson( |
|
775 | - $field, |
|
776 | - $value, |
|
777 | - $requested_version |
|
778 | - ); |
|
779 | - } |
|
780 | - } else { |
|
781 | - $translated_value = ModelDataTranslator::prepareFieldValueForJson( |
|
782 | - $field, |
|
783 | - $query_param_value, |
|
784 | - $requested_version |
|
785 | - ); |
|
786 | - } |
|
787 | - $query_param_for_models[$query_param_key] = $translated_value; |
|
788 | - } else { |
|
789 | - //so it's not for a field, assume it's a logic query param key |
|
790 | - $query_param_for_models[$query_param_key] = ModelDataTranslator::prepareConditionsQueryParamsForRestApi( |
|
791 | - $query_param_value, |
|
792 | - $model, |
|
793 | - $requested_version |
|
794 | - ); |
|
795 | - } |
|
796 | - } |
|
797 | - return $query_param_for_models; |
|
798 | - } |
|
799 | - |
|
800 | - |
|
801 | - |
|
802 | - /** |
|
803 | - * @param $condition_query_param_key |
|
804 | - * @return string |
|
805 | - */ |
|
806 | - public static function removeStarsAndAnythingAfterFromConditionQueryParamKey($condition_query_param_key) |
|
807 | - { |
|
808 | - $pos_of_star = strpos($condition_query_param_key, '*'); |
|
809 | - if ($pos_of_star === false) { |
|
810 | - return $condition_query_param_key; |
|
811 | - } else { |
|
812 | - $condition_query_param_sans_star = substr($condition_query_param_key, 0, $pos_of_star); |
|
813 | - return $condition_query_param_sans_star; |
|
814 | - } |
|
815 | - } |
|
816 | - |
|
817 | - |
|
818 | - |
|
819 | - /** |
|
820 | - * Takes the input parameter and finds the model field that it indicates. |
|
821 | - * |
|
822 | - * @param string $query_param_name like Registration.Transaction.TXN_ID, Event.Datetime.start_time, or REG_ID |
|
823 | - * @param EEM_Base $model |
|
824 | - * @return EE_Model_Field_Base |
|
825 | - * @throws EE_Error |
|
826 | - */ |
|
827 | - public static function deduceFieldFromQueryParam($query_param_name, EEM_Base $model) |
|
828 | - { |
|
829 | - //ok, now proceed with deducing which part is the model's name, and which is the field's name |
|
830 | - //which will help us find the database table and column |
|
831 | - $query_param_parts = explode('.', $query_param_name); |
|
832 | - if (empty($query_param_parts)) { |
|
833 | - throw new EE_Error( |
|
834 | - sprintf( |
|
835 | - __( |
|
836 | - '_extract_column_name is empty when trying to extract column and table name from %s', |
|
837 | - 'event_espresso' |
|
838 | - ), |
|
839 | - $query_param_name |
|
840 | - ) |
|
841 | - ); |
|
842 | - } |
|
843 | - $number_of_parts = count($query_param_parts); |
|
844 | - $last_query_param_part = $query_param_parts[count($query_param_parts) - 1]; |
|
845 | - if ($number_of_parts === 1) { |
|
846 | - $field_name = $last_query_param_part; |
|
847 | - } else {// $number_of_parts >= 2 |
|
848 | - //the last part is the column name, and there are only 2parts. therefore... |
|
849 | - $field_name = $last_query_param_part; |
|
850 | - $model = \EE_Registry::instance()->load_model($query_param_parts[$number_of_parts - 2]); |
|
851 | - } |
|
852 | - try { |
|
853 | - return $model->field_settings_for($field_name, false); |
|
854 | - } catch (EE_Error $e) { |
|
855 | - return null; |
|
856 | - } |
|
857 | - } |
|
858 | - |
|
859 | - |
|
860 | - |
|
861 | - /** |
|
862 | - * Returns true if $data can be easily represented in JSON. |
|
863 | - * Basically, objects and resources can't be represented in JSON easily. |
|
864 | - * @param mixed $data |
|
865 | - * @return bool |
|
866 | - */ |
|
867 | - protected static function isRepresentableInJson($data) |
|
868 | - { |
|
869 | - return is_scalar($data) |
|
870 | - || is_array($data) |
|
871 | - || is_null($data); |
|
872 | - } |
|
40 | + /** |
|
41 | + * We used to use -1 for infinity in the rest api, but that's ambiguous for |
|
42 | + * fields that COULD contain -1; so we use null |
|
43 | + */ |
|
44 | + const EE_INF_IN_REST = null; |
|
45 | + |
|
46 | + |
|
47 | + |
|
48 | + /** |
|
49 | + * Prepares a possible array of input values from JSON for use by the models |
|
50 | + * |
|
51 | + * @param EE_Model_Field_Base $field_obj |
|
52 | + * @param mixed $original_value_maybe_array |
|
53 | + * @param string $requested_version |
|
54 | + * @param string $timezone_string treat values as being in this timezone |
|
55 | + * @return mixed |
|
56 | + * @throws RestException |
|
57 | + */ |
|
58 | + public static function prepareFieldValuesFromJson( |
|
59 | + $field_obj, |
|
60 | + $original_value_maybe_array, |
|
61 | + $requested_version, |
|
62 | + $timezone_string = 'UTC' |
|
63 | + ) { |
|
64 | + if (is_array($original_value_maybe_array) |
|
65 | + && ! $field_obj instanceof EE_Serialized_Text_Field |
|
66 | + ) { |
|
67 | + $new_value_maybe_array = array(); |
|
68 | + foreach ($original_value_maybe_array as $array_key => $array_item) { |
|
69 | + $new_value_maybe_array[$array_key] = ModelDataTranslator::prepareFieldValueFromJson( |
|
70 | + $field_obj, |
|
71 | + $array_item, |
|
72 | + $requested_version, |
|
73 | + $timezone_string |
|
74 | + ); |
|
75 | + } |
|
76 | + } else { |
|
77 | + $new_value_maybe_array = ModelDataTranslator::prepareFieldValueFromJson( |
|
78 | + $field_obj, |
|
79 | + $original_value_maybe_array, |
|
80 | + $requested_version, |
|
81 | + $timezone_string |
|
82 | + ); |
|
83 | + } |
|
84 | + return $new_value_maybe_array; |
|
85 | + } |
|
86 | + |
|
87 | + |
|
88 | + |
|
89 | + /** |
|
90 | + * Prepares an array of field values FOR use in JSON/REST API |
|
91 | + * |
|
92 | + * @param EE_Model_Field_Base $field_obj |
|
93 | + * @param mixed $original_value_maybe_array |
|
94 | + * @param string $request_version (eg 4.8.36) |
|
95 | + * @return array |
|
96 | + */ |
|
97 | + public static function prepareFieldValuesForJson($field_obj, $original_value_maybe_array, $request_version) |
|
98 | + { |
|
99 | + if (is_array($original_value_maybe_array)) { |
|
100 | + $new_value = array(); |
|
101 | + foreach ($original_value_maybe_array as $key => $value) { |
|
102 | + $new_value[$key] = ModelDataTranslator::prepareFieldValuesForJson($field_obj, $value, $request_version); |
|
103 | + } |
|
104 | + } else { |
|
105 | + $new_value = ModelDataTranslator::prepareFieldValueForJson( |
|
106 | + $field_obj, |
|
107 | + $original_value_maybe_array, |
|
108 | + $request_version |
|
109 | + ); |
|
110 | + } |
|
111 | + return $new_value; |
|
112 | + } |
|
113 | + |
|
114 | + |
|
115 | + /** |
|
116 | + * Prepares incoming data from the json or $_REQUEST parameters for the models' |
|
117 | + * "$query_params". |
|
118 | + * |
|
119 | + * @param EE_Model_Field_Base $field_obj |
|
120 | + * @param mixed $original_value |
|
121 | + * @param string $requested_version |
|
122 | + * @param string $timezone_string treat values as being in this timezone |
|
123 | + * @return mixed |
|
124 | + * @throws RestException |
|
125 | + * @throws DomainException |
|
126 | + * @throws EE_Error |
|
127 | + */ |
|
128 | + public static function prepareFieldValueFromJson( |
|
129 | + $field_obj, |
|
130 | + $original_value, |
|
131 | + $requested_version, |
|
132 | + $timezone_string = 'UTC' // UTC |
|
133 | + ) { |
|
134 | + //check if they accidentally submitted an error value. If so throw an exception |
|
135 | + if (is_array($original_value) |
|
136 | + && isset($original_value['error_code'], $original_value['error_message'])) { |
|
137 | + throw new RestException( |
|
138 | + 'rest_submitted_error_value', |
|
139 | + sprintf( |
|
140 | + esc_html__( |
|
141 | + 'You tried to submit a JSON error object as a value for %1$s. That\'s not allowed.', |
|
142 | + 'event_espresso' |
|
143 | + ), |
|
144 | + $field_obj->get_name() |
|
145 | + ), |
|
146 | + array( |
|
147 | + 'status' => 400, |
|
148 | + ) |
|
149 | + ); |
|
150 | + } |
|
151 | + //double-check for serialized PHP. We never accept serialized PHP. No way Jose. |
|
152 | + ModelDataTranslator::throwExceptionIfContainsSerializedData($original_value); |
|
153 | + $timezone_string = $timezone_string !== '' ? $timezone_string : get_option('timezone_string', ''); |
|
154 | + $new_value = null; |
|
155 | + //walk through the submitted data and double-check for serialized PHP. We never accept serialized PHP. No |
|
156 | + // way Jose. |
|
157 | + ModelDataTranslator::throwExceptionIfContainsSerializedData($original_value); |
|
158 | + if ($field_obj instanceof EE_Infinite_Integer_Field |
|
159 | + && in_array($original_value, array(null, ''), true) |
|
160 | + ) { |
|
161 | + $new_value = EE_INF; |
|
162 | + } elseif ($field_obj instanceof EE_Datetime_Field) { |
|
163 | + $new_value = rest_parse_date( |
|
164 | + self::getTimestampWithTimezoneOffset($original_value, $field_obj, $timezone_string) |
|
165 | + ); |
|
166 | + if ($new_value === false) { |
|
167 | + throw new RestException( |
|
168 | + 'invalid_format_for_timestamp', |
|
169 | + sprintf( |
|
170 | + esc_html__( |
|
171 | + 'Timestamps received on a request as the value for Date and Time fields must be in %1$s/%2$s format. The timestamp provided (%3$s) is not that format.', |
|
172 | + 'event_espresso' |
|
173 | + ), |
|
174 | + 'RFC3339', |
|
175 | + 'ISO8601', |
|
176 | + $original_value |
|
177 | + ), |
|
178 | + array( |
|
179 | + 'status' => 400 |
|
180 | + ) |
|
181 | + ); |
|
182 | + } |
|
183 | + } else { |
|
184 | + $new_value = $original_value; |
|
185 | + } |
|
186 | + return $new_value; |
|
187 | + } |
|
188 | + |
|
189 | + |
|
190 | + /** |
|
191 | + * This checks if the incoming timestamp has timezone information already on it and if it doesn't then adds timezone |
|
192 | + * information via details obtained from the host site. |
|
193 | + * |
|
194 | + * @param string $original_timestamp |
|
195 | + * @param EE_Datetime_Field $datetime_field |
|
196 | + * @param $timezone_string |
|
197 | + * @return string |
|
198 | + * @throws DomainException |
|
199 | + */ |
|
200 | + private static function getTimestampWithTimezoneOffset( |
|
201 | + $original_timestamp, |
|
202 | + EE_Datetime_Field $datetime_field, |
|
203 | + $timezone_string |
|
204 | + ) { |
|
205 | + //already have timezone information? |
|
206 | + if (preg_match('/Z|(\+|\-)(\d{2}:\d{2})/', $original_timestamp)) { |
|
207 | + //yes, we're ignoring the timezone. |
|
208 | + return $original_timestamp; |
|
209 | + } |
|
210 | + //need to append timezone |
|
211 | + list($offset_sign, $offset_secs) = self::parseTimezoneOffset( |
|
212 | + $datetime_field->get_timezone_offset( |
|
213 | + new \DateTimeZone($timezone_string), |
|
214 | + $original_timestamp |
|
215 | + ) |
|
216 | + ); |
|
217 | + $offset_string = |
|
218 | + str_pad( |
|
219 | + floor($offset_secs / HOUR_IN_SECONDS), |
|
220 | + 2, |
|
221 | + '0', |
|
222 | + STR_PAD_LEFT |
|
223 | + ) |
|
224 | + . ':' |
|
225 | + . str_pad( |
|
226 | + ($offset_secs % HOUR_IN_SECONDS) / MINUTE_IN_SECONDS, |
|
227 | + 2, |
|
228 | + '0', |
|
229 | + STR_PAD_LEFT |
|
230 | + ); |
|
231 | + return $original_timestamp . $offset_sign . $offset_string; |
|
232 | + } |
|
233 | + |
|
234 | + |
|
235 | + |
|
236 | + /** |
|
237 | + * Throws an exception if $data is a serialized PHP string (or somehow an actually PHP object, although I don't |
|
238 | + * think that can happen). If $data is an array, recurses into its keys and values |
|
239 | + * @param mixed $data |
|
240 | + * @throws RestException |
|
241 | + * @return void |
|
242 | + */ |
|
243 | + public static function throwExceptionIfContainsSerializedData($data) |
|
244 | + { |
|
245 | + if (is_array($data)) { |
|
246 | + foreach ($data as $key => $value) { |
|
247 | + ModelDataTranslator::throwExceptionIfContainsSerializedData($key); |
|
248 | + ModelDataTranslator::throwExceptionIfContainsSerializedData($value); |
|
249 | + } |
|
250 | + } else { |
|
251 | + if (is_serialized($data) || is_object($data)) { |
|
252 | + throw new RestException( |
|
253 | + 'serialized_data_submission_prohibited', |
|
254 | + esc_html__( |
|
255 | + // @codingStandardsIgnoreStart |
|
256 | + 'You tried to submit a string of serialized text. Serialized PHP is prohibited over the EE4 REST API.', |
|
257 | + // @codingStandardsIgnoreEnd |
|
258 | + 'event_espresso' |
|
259 | + ) |
|
260 | + ); |
|
261 | + } |
|
262 | + } |
|
263 | + } |
|
264 | + |
|
265 | + |
|
266 | + |
|
267 | + /** |
|
268 | + * determines what's going on with them timezone strings |
|
269 | + * |
|
270 | + * @param int $timezone_offset |
|
271 | + * @return array |
|
272 | + */ |
|
273 | + private static function parseTimezoneOffset($timezone_offset) |
|
274 | + { |
|
275 | + $first_char = substr((string)$timezone_offset, 0, 1); |
|
276 | + if ($first_char === '+' || $first_char === '-') { |
|
277 | + $offset_sign = $first_char; |
|
278 | + $offset_secs = substr((string)$timezone_offset, 1); |
|
279 | + } else { |
|
280 | + $offset_sign = '+'; |
|
281 | + $offset_secs = $timezone_offset; |
|
282 | + } |
|
283 | + return array($offset_sign, $offset_secs); |
|
284 | + } |
|
285 | + |
|
286 | + |
|
287 | + |
|
288 | + /** |
|
289 | + * Prepares a field's value for display in the API |
|
290 | + * |
|
291 | + * @param EE_Model_Field_Base $field_obj |
|
292 | + * @param mixed $original_value |
|
293 | + * @param string $requested_version |
|
294 | + * @return mixed |
|
295 | + */ |
|
296 | + public static function prepareFieldValueForJson($field_obj, $original_value, $requested_version) |
|
297 | + { |
|
298 | + if ($original_value === EE_INF) { |
|
299 | + $new_value = ModelDataTranslator::EE_INF_IN_REST; |
|
300 | + } elseif ($field_obj instanceof EE_Datetime_Field) { |
|
301 | + if (is_string($original_value)) { |
|
302 | + //did they submit a string of a unix timestamp? |
|
303 | + if (is_numeric($original_value)) { |
|
304 | + $datetime_obj = new \DateTime(); |
|
305 | + $datetime_obj->setTimestamp((int)$original_value); |
|
306 | + } else { |
|
307 | + //first, check if its a MySQL timestamp in GMT |
|
308 | + $datetime_obj = \DateTime::createFromFormat('Y-m-d H:i:s', $original_value); |
|
309 | + } |
|
310 | + if (! $datetime_obj instanceof \DateTime) { |
|
311 | + //so it's not a unix timestamp or a MySQL timestamp. Maybe its in the field's date/time format? |
|
312 | + $datetime_obj = $field_obj->prepare_for_set($original_value); |
|
313 | + } |
|
314 | + $original_value = $datetime_obj; |
|
315 | + } |
|
316 | + if ($original_value instanceof \DateTime) { |
|
317 | + $new_value = $original_value->format('Y-m-d H:i:s'); |
|
318 | + } elseif (is_int($original_value) || is_float($original_value)) { |
|
319 | + $new_value = date('Y-m-d H:i:s', $original_value); |
|
320 | + } elseif($original_value === null || $original_value === '') { |
|
321 | + $new_value = null; |
|
322 | + } else { |
|
323 | + //so it's not a datetime object, unix timestamp (as string or int), |
|
324 | + //MySQL timestamp, or even a string in the field object's format. So no idea what it is |
|
325 | + throw new \EE_Error( |
|
326 | + sprintf( |
|
327 | + esc_html__( |
|
328 | + // @codingStandardsIgnoreStart |
|
329 | + 'The value "%1$s" for the field "%2$s" on model "%3$s" could not be understood. It should be a PHP DateTime, unix timestamp, MySQL date, or string in the format "%4$s".', |
|
330 | + // @codingStandardsIgnoreEnd |
|
331 | + 'event_espressso' |
|
332 | + ), |
|
333 | + $original_value, |
|
334 | + $field_obj->get_name(), |
|
335 | + $field_obj->get_model_name(), |
|
336 | + $field_obj->get_time_format() . ' ' . $field_obj->get_time_format() |
|
337 | + ) |
|
338 | + ); |
|
339 | + } |
|
340 | + $new_value = mysql_to_rfc3339($new_value); |
|
341 | + } else { |
|
342 | + $new_value = $original_value; |
|
343 | + } |
|
344 | + //are we about to send an object? just don't. We have no good way to represent it in JSON. |
|
345 | + // can't just check using is_object() because that missed PHP incomplete objects |
|
346 | + if (! ModelDataTranslator::isRepresentableInJson($new_value)) { |
|
347 | + $new_value = array( |
|
348 | + 'error_code' => 'php_object_not_return', |
|
349 | + 'error_message' => esc_html__('The value of this field in the database is a PHP object, which can\'t be represented in JSON.', 'event_espresso') |
|
350 | + ); |
|
351 | + } |
|
352 | + return apply_filters( |
|
353 | + 'FHEE__EventEspresso\core\libraries\rest_api\Model_Data_Translator__prepare_field_for_rest_api', |
|
354 | + $new_value, |
|
355 | + $field_obj, |
|
356 | + $original_value, |
|
357 | + $requested_version |
|
358 | + ); |
|
359 | + } |
|
360 | + |
|
361 | + |
|
362 | + |
|
363 | + /** |
|
364 | + * Prepares condition-query-parameters (like what's in where and having) from |
|
365 | + * the format expected in the API to use in the models |
|
366 | + * |
|
367 | + * @param array $inputted_query_params_of_this_type |
|
368 | + * @param EEM_Base $model |
|
369 | + * @param string $requested_version |
|
370 | + * @param boolean $writing whether this data will be written to the DB, or if we're just building a query. |
|
371 | + * If we're writing to the DB, we don't expect any operators, or any logic query parameters, |
|
372 | + * and we also won't accept serialized data unless the current user has unfiltered_html. |
|
373 | + * @return array |
|
374 | + * @throws DomainException |
|
375 | + * @throws RestException |
|
376 | + * @throws EE_Error |
|
377 | + */ |
|
378 | + public static function prepareConditionsQueryParamsForModels( |
|
379 | + $inputted_query_params_of_this_type, |
|
380 | + EEM_Base $model, |
|
381 | + $requested_version, |
|
382 | + $writing = false |
|
383 | + ) { |
|
384 | + $query_param_for_models = array(); |
|
385 | + $valid_operators = $model->valid_operators(); |
|
386 | + foreach ($inputted_query_params_of_this_type as $query_param_key => $query_param_value) { |
|
387 | + $is_gmt_datetime_field = false; |
|
388 | + $query_param_sans_stars = ModelDataTranslator::removeStarsAndAnythingAfterFromConditionQueryParamKey( |
|
389 | + $query_param_key |
|
390 | + ); |
|
391 | + $field = ModelDataTranslator::deduceFieldFromQueryParam( |
|
392 | + $query_param_sans_stars, |
|
393 | + $model |
|
394 | + ); |
|
395 | + //double-check is it a *_gmt field? |
|
396 | + if (! $field instanceof EE_Model_Field_Base |
|
397 | + && ModelDataTranslator::isGmtDateFieldName($query_param_sans_stars) |
|
398 | + ) { |
|
399 | + //yep, take off '_gmt', and find the field |
|
400 | + $query_param_key = ModelDataTranslator::removeGmtFromFieldName($query_param_sans_stars); |
|
401 | + $field = ModelDataTranslator::deduceFieldFromQueryParam( |
|
402 | + $query_param_key, |
|
403 | + $model |
|
404 | + ); |
|
405 | + $timezone = 'UTC'; |
|
406 | + $is_gmt_datetime_field = true; |
|
407 | + } elseif ($field instanceof EE_Datetime_Field) { |
|
408 | + //so it's not a GMT field. Set the timezone on the model to the default |
|
409 | + $timezone = \EEH_DTT_Helper::get_valid_timezone_string(); |
|
410 | + } else { |
|
411 | + //just keep using what's already set for the timezone |
|
412 | + $timezone = $model->get_timezone(); |
|
413 | + } |
|
414 | + if ($field instanceof EE_Model_Field_Base) { |
|
415 | + if (! $writing && is_array($query_param_value)) { |
|
416 | + if (! \EEH_Array::is_array_numerically_and_sequentially_indexed($query_param_value)) { |
|
417 | + if (defined('EE_REST_API_DEBUG_MODE') && EE_REST_API_DEBUG_MODE) { |
|
418 | + throw new RestException( |
|
419 | + 'numerically_indexed_array_of_values_only', |
|
420 | + sprintf( |
|
421 | + esc_html__( |
|
422 | + 'The array provided for the parameter "%1$s" should be numerically indexed.', |
|
423 | + 'event_espresso' |
|
424 | + ), |
|
425 | + $query_param_key |
|
426 | + ), |
|
427 | + array( |
|
428 | + 'status' => 400, |
|
429 | + ) |
|
430 | + ); |
|
431 | + } |
|
432 | + } |
|
433 | + //did they specify an operator? |
|
434 | + if (isset($query_param_value[0]) |
|
435 | + && isset($valid_operators[$query_param_value[0]]) |
|
436 | + ) { |
|
437 | + $op = $query_param_value[0]; |
|
438 | + $translated_value = array($op); |
|
439 | + if (array_key_exists($op, $model->valid_in_style_operators()) |
|
440 | + && isset($query_param_value[1]) |
|
441 | + && ! isset($query_param_value[2]) |
|
442 | + ) { |
|
443 | + $translated_value[] = ModelDataTranslator::prepareFieldValuesFromJson( |
|
444 | + $field, |
|
445 | + $query_param_value[1], |
|
446 | + $requested_version, |
|
447 | + $timezone |
|
448 | + ); |
|
449 | + } elseif (array_key_exists($op, $model->valid_between_style_operators()) |
|
450 | + && isset($query_param_value[1], $query_param_value[2]) |
|
451 | + && !isset($query_param_value[3]) |
|
452 | + ) { |
|
453 | + $translated_value[] = ModelDataTranslator::prepareFieldValuesFromJson( |
|
454 | + $field, |
|
455 | + $query_param_value[1], |
|
456 | + $requested_version, |
|
457 | + $timezone |
|
458 | + ); |
|
459 | + $translated_value[] = ModelDataTranslator::prepareFieldValuesFromJson( |
|
460 | + $field, |
|
461 | + $query_param_value[2], |
|
462 | + $requested_version, |
|
463 | + $timezone |
|
464 | + ); |
|
465 | + } elseif (array_key_exists($op, $model->valid_like_style_operators()) |
|
466 | + && isset($query_param_value[1]) |
|
467 | + && ! isset($query_param_value[2]) |
|
468 | + ) { |
|
469 | + //we want to leave this value mostly-as-is (eg don't force it to be a float |
|
470 | + //or a boolean or an enum value. Leave it as-is with wildcards etc) |
|
471 | + //but do verify it at least doesn't have any serialized data |
|
472 | + ModelDataTranslator::throwExceptionIfContainsSerializedData($query_param_value[1]); |
|
473 | + $translated_value[] = $query_param_value[1]; |
|
474 | + } elseif (array_key_exists($op, $model->valid_null_style_operators()) |
|
475 | + && !isset($query_param_value[1])) { |
|
476 | + //no arguments should have been provided, so don't look for any |
|
477 | + } elseif (isset($query_param_value[1]) |
|
478 | + && !isset($query_param_value[2]) |
|
479 | + && ! array_key_exists( |
|
480 | + $op, |
|
481 | + array_merge( |
|
482 | + $model->valid_in_style_operators(), |
|
483 | + $model->valid_null_style_operators(), |
|
484 | + $model->valid_like_style_operators(), |
|
485 | + $model->valid_between_style_operators() |
|
486 | + ) |
|
487 | + ) |
|
488 | + ) { |
|
489 | + //it's a valid operator, but none of the exceptions. Treat it normally. |
|
490 | + $translated_value[] = ModelDataTranslator::prepareFieldValuesFromJson( |
|
491 | + $field, |
|
492 | + $query_param_value[1], |
|
493 | + $requested_version, |
|
494 | + $timezone |
|
495 | + ); |
|
496 | + } else { |
|
497 | + //so they provided a valid operator, but wrong number of arguments |
|
498 | + if (defined('EE_REST_API_DEBUG_MODE') && EE_REST_API_DEBUG_MODE) { |
|
499 | + throw new RestException( |
|
500 | + 'wrong_number_of_arguments', |
|
501 | + sprintf( |
|
502 | + esc_html__( |
|
503 | + 'The operator you provided, "%1$s" had the wrong number of arguments', |
|
504 | + 'event_espresso' |
|
505 | + ), |
|
506 | + $op |
|
507 | + ), |
|
508 | + array( |
|
509 | + 'status' => 400, |
|
510 | + ) |
|
511 | + ); |
|
512 | + } |
|
513 | + $translated_value = null; |
|
514 | + } |
|
515 | + } else { |
|
516 | + //so they didn't provide a valid operator |
|
517 | + if (defined('EE_REST_API_DEBUG_MODE') && EE_REST_API_DEBUG_MODE) { |
|
518 | + throw new RestException( |
|
519 | + 'invalid_operator', |
|
520 | + sprintf( |
|
521 | + esc_html__( |
|
522 | + 'You provided an invalid parameter, with key "%1$s" and value "%2$s"', |
|
523 | + 'event_espresso' |
|
524 | + ), |
|
525 | + $query_param_key, |
|
526 | + $query_param_value |
|
527 | + ), |
|
528 | + array( |
|
529 | + 'status' => 400, |
|
530 | + ) |
|
531 | + ); |
|
532 | + } |
|
533 | + //if we aren't in debug mode, then just try our best to fulfill the user's request |
|
534 | + $translated_value = null; |
|
535 | + } |
|
536 | + } else { |
|
537 | + $translated_value = ModelDataTranslator::prepareFieldValueFromJson( |
|
538 | + $field, |
|
539 | + $query_param_value, |
|
540 | + $requested_version, |
|
541 | + $timezone |
|
542 | + ); |
|
543 | + } |
|
544 | + if ( |
|
545 | + (isset($query_param_for_models[$query_param_key]) && $is_gmt_datetime_field) |
|
546 | + || |
|
547 | + $translated_value === null |
|
548 | + ) { |
|
549 | + //they have already provided a non-gmt field, ignore the gmt one. That's what WP core |
|
550 | + //currently does (they might change it though). See https://core.trac.wordpress.org/ticket/39954 |
|
551 | + //OR we couldn't create a translated value from their input |
|
552 | + continue; |
|
553 | + } |
|
554 | + $query_param_for_models[$query_param_key] = $translated_value; |
|
555 | + } else { |
|
556 | + //so this param doesn't correspond to a field eh? |
|
557 | + if ($writing) { |
|
558 | + //always tell API clients about invalid parameters when they're creating data. Otherwise, |
|
559 | + //they are probably going to create invalid data |
|
560 | + throw new RestException( |
|
561 | + 'invalid_field', |
|
562 | + sprintf( |
|
563 | + esc_html__('You have provided an invalid parameter: "%1$s"', 'event_espresso'), |
|
564 | + $query_param_key |
|
565 | + ) |
|
566 | + ); |
|
567 | + } else { |
|
568 | + //so it's not for a field, is it a logic query param key? |
|
569 | + if (in_array( |
|
570 | + $query_param_sans_stars, |
|
571 | + $model->logic_query_param_keys() |
|
572 | + )) { |
|
573 | + $query_param_for_models[$query_param_key] = ModelDataTranslator::prepareConditionsQueryParamsForModels( |
|
574 | + $query_param_value, |
|
575 | + $model, |
|
576 | + $requested_version |
|
577 | + ); |
|
578 | + } elseif (defined('EE_REST_API_DEBUG_MODE') && EE_REST_API_DEBUG_MODE) { |
|
579 | + //only tell API clients they got it wrong if we're in debug mode |
|
580 | + //otherwise try our best ot fulfill their request by ignoring this invalid data |
|
581 | + throw new RestException( |
|
582 | + 'invalid_parameter', |
|
583 | + sprintf( |
|
584 | + esc_html__( |
|
585 | + 'You provided an invalid parameter, with key "%1$s"', |
|
586 | + 'event_espresso' |
|
587 | + ), |
|
588 | + $query_param_sans_stars |
|
589 | + ), |
|
590 | + array( |
|
591 | + 'status' => 400, |
|
592 | + ) |
|
593 | + ); |
|
594 | + } |
|
595 | + } |
|
596 | + } |
|
597 | + } |
|
598 | + return $query_param_for_models; |
|
599 | + } |
|
600 | + |
|
601 | + |
|
602 | + |
|
603 | + /** |
|
604 | + * Mostly checks if the last 4 characters are "_gmt", indicating its a |
|
605 | + * gmt date field name |
|
606 | + * |
|
607 | + * @param string $field_name |
|
608 | + * @return boolean |
|
609 | + */ |
|
610 | + public static function isGmtDateFieldName($field_name) |
|
611 | + { |
|
612 | + return substr( |
|
613 | + ModelDataTranslator::removeStarsAndAnythingAfterFromConditionQueryParamKey($field_name), |
|
614 | + -4, |
|
615 | + 4 |
|
616 | + ) === '_gmt'; |
|
617 | + } |
|
618 | + |
|
619 | + |
|
620 | + |
|
621 | + /** |
|
622 | + * Removes the last "_gmt" part of a field name (and if there is no "_gmt" at the end, leave it alone) |
|
623 | + * |
|
624 | + * @param string $field_name |
|
625 | + * @return string |
|
626 | + */ |
|
627 | + public static function removeGmtFromFieldName($field_name) |
|
628 | + { |
|
629 | + if (! ModelDataTranslator::isGmtDateFieldName($field_name)) { |
|
630 | + return $field_name; |
|
631 | + } |
|
632 | + $query_param_sans_stars = ModelDataTranslator::removeStarsAndAnythingAfterFromConditionQueryParamKey( |
|
633 | + $field_name |
|
634 | + ); |
|
635 | + $query_param_sans_gmt_and_sans_stars = substr( |
|
636 | + $query_param_sans_stars, |
|
637 | + 0, |
|
638 | + strrpos( |
|
639 | + $field_name, |
|
640 | + '_gmt' |
|
641 | + ) |
|
642 | + ); |
|
643 | + return str_replace($query_param_sans_stars, $query_param_sans_gmt_and_sans_stars, $field_name); |
|
644 | + } |
|
645 | + |
|
646 | + |
|
647 | + |
|
648 | + /** |
|
649 | + * Takes a field name from the REST API and prepares it for the model querying |
|
650 | + * |
|
651 | + * @param string $field_name |
|
652 | + * @return string |
|
653 | + */ |
|
654 | + public static function prepareFieldNameFromJson($field_name) |
|
655 | + { |
|
656 | + if (ModelDataTranslator::isGmtDateFieldName($field_name)) { |
|
657 | + return ModelDataTranslator::removeGmtFromFieldName($field_name); |
|
658 | + } |
|
659 | + return $field_name; |
|
660 | + } |
|
661 | + |
|
662 | + |
|
663 | + |
|
664 | + /** |
|
665 | + * Takes array of field names from REST API and prepares for models |
|
666 | + * |
|
667 | + * @param array $field_names |
|
668 | + * @return array of field names (possibly include model prefixes) |
|
669 | + */ |
|
670 | + public static function prepareFieldNamesFromJson(array $field_names) |
|
671 | + { |
|
672 | + $new_array = array(); |
|
673 | + foreach ($field_names as $key => $field_name) { |
|
674 | + $new_array[$key] = ModelDataTranslator::prepareFieldNameFromJson($field_name); |
|
675 | + } |
|
676 | + return $new_array; |
|
677 | + } |
|
678 | + |
|
679 | + |
|
680 | + |
|
681 | + /** |
|
682 | + * Takes array where array keys are field names (possibly with model path prefixes) |
|
683 | + * from the REST API and prepares them for model querying |
|
684 | + * |
|
685 | + * @param array $field_names_as_keys |
|
686 | + * @return array |
|
687 | + */ |
|
688 | + public static function prepareFieldNamesInArrayKeysFromJson(array $field_names_as_keys) |
|
689 | + { |
|
690 | + $new_array = array(); |
|
691 | + foreach ($field_names_as_keys as $field_name => $value) { |
|
692 | + $new_array[ModelDataTranslator::prepareFieldNameFromJson($field_name)] = $value; |
|
693 | + } |
|
694 | + return $new_array; |
|
695 | + } |
|
696 | + |
|
697 | + |
|
698 | + |
|
699 | + /** |
|
700 | + * Prepares an array of model query params for use in the REST API |
|
701 | + * |
|
702 | + * @param array $model_query_params |
|
703 | + * @param EEM_Base $model |
|
704 | + * @param string $requested_version eg "4.8.36". If null is provided, defaults to the latest release of the EE4 |
|
705 | + * REST API |
|
706 | + * @return array which can be passed into the EE4 REST API when querying a model resource |
|
707 | + * @throws EE_Error |
|
708 | + */ |
|
709 | + public static function prepareQueryParamsForRestApi( |
|
710 | + array $model_query_params, |
|
711 | + EEM_Base $model, |
|
712 | + $requested_version = null |
|
713 | + ) { |
|
714 | + if ($requested_version === null) { |
|
715 | + $requested_version = \EED_Core_Rest_Api::latest_rest_api_version(); |
|
716 | + } |
|
717 | + $rest_query_params = $model_query_params; |
|
718 | + if (isset($model_query_params[0])) { |
|
719 | + $rest_query_params['where'] = ModelDataTranslator::prepareConditionsQueryParamsForRestApi( |
|
720 | + $model_query_params[0], |
|
721 | + $model, |
|
722 | + $requested_version |
|
723 | + ); |
|
724 | + unset($rest_query_params[0]); |
|
725 | + } |
|
726 | + if (isset($model_query_params['having'])) { |
|
727 | + $rest_query_params['having'] = ModelDataTranslator::prepareConditionsQueryParamsForRestApi( |
|
728 | + $model_query_params['having'], |
|
729 | + $model, |
|
730 | + $requested_version |
|
731 | + ); |
|
732 | + } |
|
733 | + return apply_filters( |
|
734 | + 'FHEE__EventEspresso\core\libraries\rest_api\Model_Data_Translator__prepare_query_params_for_rest_api', |
|
735 | + $rest_query_params, |
|
736 | + $model_query_params, |
|
737 | + $model, |
|
738 | + $requested_version |
|
739 | + ); |
|
740 | + } |
|
741 | + |
|
742 | + |
|
743 | + |
|
744 | + /** |
|
745 | + * Prepares all the sub-conditions query parameters (eg having or where conditions) for use in the rest api |
|
746 | + * |
|
747 | + * @param array $inputted_query_params_of_this_type eg like the "where" or "having" conditions query params |
|
748 | + * passed into EEM_Base::get_all() |
|
749 | + * @param EEM_Base $model |
|
750 | + * @param string $requested_version eg "4.8.36" |
|
751 | + * @return array ready for use in the rest api query params |
|
752 | + * @throws EE_Error |
|
753 | + * @throws ObjectDetectedException if somehow a PHP object were in the query params' values, |
|
754 | + * (which would be really unusual) |
|
755 | + */ |
|
756 | + public static function prepareConditionsQueryParamsForRestApi( |
|
757 | + $inputted_query_params_of_this_type, |
|
758 | + EEM_Base $model, |
|
759 | + $requested_version |
|
760 | + ) { |
|
761 | + $query_param_for_models = array(); |
|
762 | + foreach ($inputted_query_params_of_this_type as $query_param_key => $query_param_value) { |
|
763 | + $field = ModelDataTranslator::deduceFieldFromQueryParam( |
|
764 | + ModelDataTranslator::removeStarsAndAnythingAfterFromConditionQueryParamKey($query_param_key), |
|
765 | + $model |
|
766 | + ); |
|
767 | + if ($field instanceof EE_Model_Field_Base) { |
|
768 | + //did they specify an operator? |
|
769 | + if (is_array($query_param_value)) { |
|
770 | + $op = $query_param_value[0]; |
|
771 | + $translated_value = array($op); |
|
772 | + if (isset($query_param_value[1])) { |
|
773 | + $value = $query_param_value[1]; |
|
774 | + $translated_value[1] = ModelDataTranslator::prepareFieldValuesForJson( |
|
775 | + $field, |
|
776 | + $value, |
|
777 | + $requested_version |
|
778 | + ); |
|
779 | + } |
|
780 | + } else { |
|
781 | + $translated_value = ModelDataTranslator::prepareFieldValueForJson( |
|
782 | + $field, |
|
783 | + $query_param_value, |
|
784 | + $requested_version |
|
785 | + ); |
|
786 | + } |
|
787 | + $query_param_for_models[$query_param_key] = $translated_value; |
|
788 | + } else { |
|
789 | + //so it's not for a field, assume it's a logic query param key |
|
790 | + $query_param_for_models[$query_param_key] = ModelDataTranslator::prepareConditionsQueryParamsForRestApi( |
|
791 | + $query_param_value, |
|
792 | + $model, |
|
793 | + $requested_version |
|
794 | + ); |
|
795 | + } |
|
796 | + } |
|
797 | + return $query_param_for_models; |
|
798 | + } |
|
799 | + |
|
800 | + |
|
801 | + |
|
802 | + /** |
|
803 | + * @param $condition_query_param_key |
|
804 | + * @return string |
|
805 | + */ |
|
806 | + public static function removeStarsAndAnythingAfterFromConditionQueryParamKey($condition_query_param_key) |
|
807 | + { |
|
808 | + $pos_of_star = strpos($condition_query_param_key, '*'); |
|
809 | + if ($pos_of_star === false) { |
|
810 | + return $condition_query_param_key; |
|
811 | + } else { |
|
812 | + $condition_query_param_sans_star = substr($condition_query_param_key, 0, $pos_of_star); |
|
813 | + return $condition_query_param_sans_star; |
|
814 | + } |
|
815 | + } |
|
816 | + |
|
817 | + |
|
818 | + |
|
819 | + /** |
|
820 | + * Takes the input parameter and finds the model field that it indicates. |
|
821 | + * |
|
822 | + * @param string $query_param_name like Registration.Transaction.TXN_ID, Event.Datetime.start_time, or REG_ID |
|
823 | + * @param EEM_Base $model |
|
824 | + * @return EE_Model_Field_Base |
|
825 | + * @throws EE_Error |
|
826 | + */ |
|
827 | + public static function deduceFieldFromQueryParam($query_param_name, EEM_Base $model) |
|
828 | + { |
|
829 | + //ok, now proceed with deducing which part is the model's name, and which is the field's name |
|
830 | + //which will help us find the database table and column |
|
831 | + $query_param_parts = explode('.', $query_param_name); |
|
832 | + if (empty($query_param_parts)) { |
|
833 | + throw new EE_Error( |
|
834 | + sprintf( |
|
835 | + __( |
|
836 | + '_extract_column_name is empty when trying to extract column and table name from %s', |
|
837 | + 'event_espresso' |
|
838 | + ), |
|
839 | + $query_param_name |
|
840 | + ) |
|
841 | + ); |
|
842 | + } |
|
843 | + $number_of_parts = count($query_param_parts); |
|
844 | + $last_query_param_part = $query_param_parts[count($query_param_parts) - 1]; |
|
845 | + if ($number_of_parts === 1) { |
|
846 | + $field_name = $last_query_param_part; |
|
847 | + } else {// $number_of_parts >= 2 |
|
848 | + //the last part is the column name, and there are only 2parts. therefore... |
|
849 | + $field_name = $last_query_param_part; |
|
850 | + $model = \EE_Registry::instance()->load_model($query_param_parts[$number_of_parts - 2]); |
|
851 | + } |
|
852 | + try { |
|
853 | + return $model->field_settings_for($field_name, false); |
|
854 | + } catch (EE_Error $e) { |
|
855 | + return null; |
|
856 | + } |
|
857 | + } |
|
858 | + |
|
859 | + |
|
860 | + |
|
861 | + /** |
|
862 | + * Returns true if $data can be easily represented in JSON. |
|
863 | + * Basically, objects and resources can't be represented in JSON easily. |
|
864 | + * @param mixed $data |
|
865 | + * @return bool |
|
866 | + */ |
|
867 | + protected static function isRepresentableInJson($data) |
|
868 | + { |
|
869 | + return is_scalar($data) |
|
870 | + || is_array($data) |
|
871 | + || is_null($data); |
|
872 | + } |
|
873 | 873 | } |
@@ -11,7 +11,7 @@ discard block |
||
11 | 11 | use EE_Serialized_Text_Field; |
12 | 12 | use EEM_Base; |
13 | 13 | |
14 | -if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
14 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
15 | 15 | exit('No direct script access allowed'); |
16 | 16 | } |
17 | 17 | |
@@ -228,7 +228,7 @@ discard block |
||
228 | 228 | '0', |
229 | 229 | STR_PAD_LEFT |
230 | 230 | ); |
231 | - return $original_timestamp . $offset_sign . $offset_string; |
|
231 | + return $original_timestamp.$offset_sign.$offset_string; |
|
232 | 232 | } |
233 | 233 | |
234 | 234 | |
@@ -272,10 +272,10 @@ discard block |
||
272 | 272 | */ |
273 | 273 | private static function parseTimezoneOffset($timezone_offset) |
274 | 274 | { |
275 | - $first_char = substr((string)$timezone_offset, 0, 1); |
|
275 | + $first_char = substr((string) $timezone_offset, 0, 1); |
|
276 | 276 | if ($first_char === '+' || $first_char === '-') { |
277 | 277 | $offset_sign = $first_char; |
278 | - $offset_secs = substr((string)$timezone_offset, 1); |
|
278 | + $offset_secs = substr((string) $timezone_offset, 1); |
|
279 | 279 | } else { |
280 | 280 | $offset_sign = '+'; |
281 | 281 | $offset_secs = $timezone_offset; |
@@ -302,12 +302,12 @@ discard block |
||
302 | 302 | //did they submit a string of a unix timestamp? |
303 | 303 | if (is_numeric($original_value)) { |
304 | 304 | $datetime_obj = new \DateTime(); |
305 | - $datetime_obj->setTimestamp((int)$original_value); |
|
305 | + $datetime_obj->setTimestamp((int) $original_value); |
|
306 | 306 | } else { |
307 | 307 | //first, check if its a MySQL timestamp in GMT |
308 | 308 | $datetime_obj = \DateTime::createFromFormat('Y-m-d H:i:s', $original_value); |
309 | 309 | } |
310 | - if (! $datetime_obj instanceof \DateTime) { |
|
310 | + if ( ! $datetime_obj instanceof \DateTime) { |
|
311 | 311 | //so it's not a unix timestamp or a MySQL timestamp. Maybe its in the field's date/time format? |
312 | 312 | $datetime_obj = $field_obj->prepare_for_set($original_value); |
313 | 313 | } |
@@ -317,7 +317,7 @@ discard block |
||
317 | 317 | $new_value = $original_value->format('Y-m-d H:i:s'); |
318 | 318 | } elseif (is_int($original_value) || is_float($original_value)) { |
319 | 319 | $new_value = date('Y-m-d H:i:s', $original_value); |
320 | - } elseif($original_value === null || $original_value === '') { |
|
320 | + } elseif ($original_value === null || $original_value === '') { |
|
321 | 321 | $new_value = null; |
322 | 322 | } else { |
323 | 323 | //so it's not a datetime object, unix timestamp (as string or int), |
@@ -333,7 +333,7 @@ discard block |
||
333 | 333 | $original_value, |
334 | 334 | $field_obj->get_name(), |
335 | 335 | $field_obj->get_model_name(), |
336 | - $field_obj->get_time_format() . ' ' . $field_obj->get_time_format() |
|
336 | + $field_obj->get_time_format().' '.$field_obj->get_time_format() |
|
337 | 337 | ) |
338 | 338 | ); |
339 | 339 | } |
@@ -343,7 +343,7 @@ discard block |
||
343 | 343 | } |
344 | 344 | //are we about to send an object? just don't. We have no good way to represent it in JSON. |
345 | 345 | // can't just check using is_object() because that missed PHP incomplete objects |
346 | - if (! ModelDataTranslator::isRepresentableInJson($new_value)) { |
|
346 | + if ( ! ModelDataTranslator::isRepresentableInJson($new_value)) { |
|
347 | 347 | $new_value = array( |
348 | 348 | 'error_code' => 'php_object_not_return', |
349 | 349 | 'error_message' => esc_html__('The value of this field in the database is a PHP object, which can\'t be represented in JSON.', 'event_espresso') |
@@ -393,7 +393,7 @@ discard block |
||
393 | 393 | $model |
394 | 394 | ); |
395 | 395 | //double-check is it a *_gmt field? |
396 | - if (! $field instanceof EE_Model_Field_Base |
|
396 | + if ( ! $field instanceof EE_Model_Field_Base |
|
397 | 397 | && ModelDataTranslator::isGmtDateFieldName($query_param_sans_stars) |
398 | 398 | ) { |
399 | 399 | //yep, take off '_gmt', and find the field |
@@ -412,8 +412,8 @@ discard block |
||
412 | 412 | $timezone = $model->get_timezone(); |
413 | 413 | } |
414 | 414 | if ($field instanceof EE_Model_Field_Base) { |
415 | - if (! $writing && is_array($query_param_value)) { |
|
416 | - if (! \EEH_Array::is_array_numerically_and_sequentially_indexed($query_param_value)) { |
|
415 | + if ( ! $writing && is_array($query_param_value)) { |
|
416 | + if ( ! \EEH_Array::is_array_numerically_and_sequentially_indexed($query_param_value)) { |
|
417 | 417 | if (defined('EE_REST_API_DEBUG_MODE') && EE_REST_API_DEBUG_MODE) { |
418 | 418 | throw new RestException( |
419 | 419 | 'numerically_indexed_array_of_values_only', |
@@ -448,7 +448,7 @@ discard block |
||
448 | 448 | ); |
449 | 449 | } elseif (array_key_exists($op, $model->valid_between_style_operators()) |
450 | 450 | && isset($query_param_value[1], $query_param_value[2]) |
451 | - && !isset($query_param_value[3]) |
|
451 | + && ! isset($query_param_value[3]) |
|
452 | 452 | ) { |
453 | 453 | $translated_value[] = ModelDataTranslator::prepareFieldValuesFromJson( |
454 | 454 | $field, |
@@ -472,10 +472,10 @@ discard block |
||
472 | 472 | ModelDataTranslator::throwExceptionIfContainsSerializedData($query_param_value[1]); |
473 | 473 | $translated_value[] = $query_param_value[1]; |
474 | 474 | } elseif (array_key_exists($op, $model->valid_null_style_operators()) |
475 | - && !isset($query_param_value[1])) { |
|
475 | + && ! isset($query_param_value[1])) { |
|
476 | 476 | //no arguments should have been provided, so don't look for any |
477 | 477 | } elseif (isset($query_param_value[1]) |
478 | - && !isset($query_param_value[2]) |
|
478 | + && ! isset($query_param_value[2]) |
|
479 | 479 | && ! array_key_exists( |
480 | 480 | $op, |
481 | 481 | array_merge( |
@@ -626,7 +626,7 @@ discard block |
||
626 | 626 | */ |
627 | 627 | public static function removeGmtFromFieldName($field_name) |
628 | 628 | { |
629 | - if (! ModelDataTranslator::isGmtDateFieldName($field_name)) { |
|
629 | + if ( ! ModelDataTranslator::isGmtDateFieldName($field_name)) { |
|
630 | 630 | return $field_name; |
631 | 631 | } |
632 | 632 | $query_param_sans_stars = ModelDataTranslator::removeStarsAndAnythingAfterFromConditionQueryParamKey( |
@@ -21,1015 +21,1015 @@ |
||
21 | 21 | { |
22 | 22 | |
23 | 23 | |
24 | - /** |
|
25 | - * return the timezone set for the WP install |
|
26 | - * |
|
27 | - * @return string valid timezone string for PHP DateTimeZone() class |
|
28 | - * @throws InvalidArgumentException |
|
29 | - * @throws InvalidDataTypeException |
|
30 | - * @throws InvalidInterfaceException |
|
31 | - */ |
|
32 | - public static function get_timezone() |
|
33 | - { |
|
34 | - return EEH_DTT_Helper::get_valid_timezone_string(); |
|
35 | - } |
|
24 | + /** |
|
25 | + * return the timezone set for the WP install |
|
26 | + * |
|
27 | + * @return string valid timezone string for PHP DateTimeZone() class |
|
28 | + * @throws InvalidArgumentException |
|
29 | + * @throws InvalidDataTypeException |
|
30 | + * @throws InvalidInterfaceException |
|
31 | + */ |
|
32 | + public static function get_timezone() |
|
33 | + { |
|
34 | + return EEH_DTT_Helper::get_valid_timezone_string(); |
|
35 | + } |
|
36 | 36 | |
37 | 37 | |
38 | - /** |
|
39 | - * get_valid_timezone_string |
|
40 | - * ensures that a valid timezone string is returned |
|
41 | - * |
|
42 | - * @param string $timezone_string |
|
43 | - * @return string |
|
44 | - * @throws InvalidArgumentException |
|
45 | - * @throws InvalidDataTypeException |
|
46 | - * @throws InvalidInterfaceException |
|
47 | - */ |
|
48 | - public static function get_valid_timezone_string($timezone_string = '') |
|
49 | - { |
|
50 | - return self::getHelperAdapter()->getValidTimezoneString($timezone_string); |
|
51 | - } |
|
38 | + /** |
|
39 | + * get_valid_timezone_string |
|
40 | + * ensures that a valid timezone string is returned |
|
41 | + * |
|
42 | + * @param string $timezone_string |
|
43 | + * @return string |
|
44 | + * @throws InvalidArgumentException |
|
45 | + * @throws InvalidDataTypeException |
|
46 | + * @throws InvalidInterfaceException |
|
47 | + */ |
|
48 | + public static function get_valid_timezone_string($timezone_string = '') |
|
49 | + { |
|
50 | + return self::getHelperAdapter()->getValidTimezoneString($timezone_string); |
|
51 | + } |
|
52 | 52 | |
53 | 53 | |
54 | - /** |
|
55 | - * This only purpose for this static method is to validate that the incoming timezone is a valid php timezone. |
|
56 | - * |
|
57 | - * @static |
|
58 | - * @param string $timezone_string Timezone string to check |
|
59 | - * @param bool $throw_error |
|
60 | - * @return bool |
|
61 | - * @throws InvalidArgumentException |
|
62 | - * @throws InvalidDataTypeException |
|
63 | - * @throws InvalidInterfaceException |
|
64 | - */ |
|
65 | - public static function validate_timezone($timezone_string, $throw_error = true) |
|
66 | - { |
|
67 | - return self::getHelperAdapter()->validateTimezone($timezone_string, $throw_error); |
|
68 | - } |
|
54 | + /** |
|
55 | + * This only purpose for this static method is to validate that the incoming timezone is a valid php timezone. |
|
56 | + * |
|
57 | + * @static |
|
58 | + * @param string $timezone_string Timezone string to check |
|
59 | + * @param bool $throw_error |
|
60 | + * @return bool |
|
61 | + * @throws InvalidArgumentException |
|
62 | + * @throws InvalidDataTypeException |
|
63 | + * @throws InvalidInterfaceException |
|
64 | + */ |
|
65 | + public static function validate_timezone($timezone_string, $throw_error = true) |
|
66 | + { |
|
67 | + return self::getHelperAdapter()->validateTimezone($timezone_string, $throw_error); |
|
68 | + } |
|
69 | 69 | |
70 | 70 | |
71 | - /** |
|
72 | - * This returns a string that can represent the provided gmt offset in format that can be passed into |
|
73 | - * DateTimeZone. This is NOT a string that can be passed as a value on the WordPress timezone_string option. |
|
74 | - * |
|
75 | - * @param float|string $gmt_offset |
|
76 | - * @return string |
|
77 | - * @throws InvalidArgumentException |
|
78 | - * @throws InvalidDataTypeException |
|
79 | - * @throws InvalidInterfaceException |
|
80 | - */ |
|
81 | - public static function get_timezone_string_from_gmt_offset($gmt_offset = '') |
|
82 | - { |
|
83 | - return self::getHelperAdapter()->getTimezoneStringFromGmtOffset($gmt_offset); |
|
84 | - } |
|
71 | + /** |
|
72 | + * This returns a string that can represent the provided gmt offset in format that can be passed into |
|
73 | + * DateTimeZone. This is NOT a string that can be passed as a value on the WordPress timezone_string option. |
|
74 | + * |
|
75 | + * @param float|string $gmt_offset |
|
76 | + * @return string |
|
77 | + * @throws InvalidArgumentException |
|
78 | + * @throws InvalidDataTypeException |
|
79 | + * @throws InvalidInterfaceException |
|
80 | + */ |
|
81 | + public static function get_timezone_string_from_gmt_offset($gmt_offset = '') |
|
82 | + { |
|
83 | + return self::getHelperAdapter()->getTimezoneStringFromGmtOffset($gmt_offset); |
|
84 | + } |
|
85 | 85 | |
86 | 86 | |
87 | - /** |
|
88 | - * Gets the site's GMT offset based on either the timezone string |
|
89 | - * (in which case teh gmt offset will vary depending on the location's |
|
90 | - * observance of daylight savings time) or the gmt_offset wp option |
|
91 | - * |
|
92 | - * @return int seconds offset |
|
93 | - * @throws InvalidArgumentException |
|
94 | - * @throws InvalidDataTypeException |
|
95 | - * @throws InvalidInterfaceException |
|
96 | - */ |
|
97 | - public static function get_site_timezone_gmt_offset() |
|
98 | - { |
|
99 | - return self::getHelperAdapter()->getSiteTimezoneGmtOffset(); |
|
100 | - } |
|
87 | + /** |
|
88 | + * Gets the site's GMT offset based on either the timezone string |
|
89 | + * (in which case teh gmt offset will vary depending on the location's |
|
90 | + * observance of daylight savings time) or the gmt_offset wp option |
|
91 | + * |
|
92 | + * @return int seconds offset |
|
93 | + * @throws InvalidArgumentException |
|
94 | + * @throws InvalidDataTypeException |
|
95 | + * @throws InvalidInterfaceException |
|
96 | + */ |
|
97 | + public static function get_site_timezone_gmt_offset() |
|
98 | + { |
|
99 | + return self::getHelperAdapter()->getSiteTimezoneGmtOffset(); |
|
100 | + } |
|
101 | 101 | |
102 | 102 | |
103 | - /** |
|
104 | - * Depending on PHP version, |
|
105 | - * there might not be valid current timezone strings to match these gmt_offsets in its timezone tables. |
|
106 | - * To get around that, for these fringe timezones we bump them to a known valid offset. |
|
107 | - * This method should ONLY be called after first verifying an timezone_string cannot be retrieved for the offset. |
|
108 | - * |
|
109 | - * @deprecated 4.9.54.rc Developers this was always meant to only be an internally used method. This will be |
|
110 | - * removed in a future version of EE. |
|
111 | - * @param int $gmt_offset |
|
112 | - * @return int |
|
113 | - * @throws InvalidArgumentException |
|
114 | - * @throws InvalidDataTypeException |
|
115 | - * @throws InvalidInterfaceException |
|
116 | - */ |
|
117 | - public static function adjust_invalid_gmt_offsets($gmt_offset = 0) |
|
118 | - { |
|
119 | - return self::getHelperAdapter()->adjustInvalidGmtOffsets($gmt_offset); |
|
120 | - } |
|
103 | + /** |
|
104 | + * Depending on PHP version, |
|
105 | + * there might not be valid current timezone strings to match these gmt_offsets in its timezone tables. |
|
106 | + * To get around that, for these fringe timezones we bump them to a known valid offset. |
|
107 | + * This method should ONLY be called after first verifying an timezone_string cannot be retrieved for the offset. |
|
108 | + * |
|
109 | + * @deprecated 4.9.54.rc Developers this was always meant to only be an internally used method. This will be |
|
110 | + * removed in a future version of EE. |
|
111 | + * @param int $gmt_offset |
|
112 | + * @return int |
|
113 | + * @throws InvalidArgumentException |
|
114 | + * @throws InvalidDataTypeException |
|
115 | + * @throws InvalidInterfaceException |
|
116 | + */ |
|
117 | + public static function adjust_invalid_gmt_offsets($gmt_offset = 0) |
|
118 | + { |
|
119 | + return self::getHelperAdapter()->adjustInvalidGmtOffsets($gmt_offset); |
|
120 | + } |
|
121 | 121 | |
122 | 122 | |
123 | - /** |
|
124 | - * get_timezone_string_from_abbreviations_list |
|
125 | - * |
|
126 | - * @deprecated 4.9.54.rc Developers, this was never intended to be public. This is a soft deprecation for now. |
|
127 | - * If you are using this, you'll want to work out an alternate way of getting the value. |
|
128 | - * @param int $gmt_offset |
|
129 | - * @param bool $coerce If true, we attempt to coerce with our adjustment table @see self::adjust_invalid_gmt_offset. |
|
130 | - * @return string |
|
131 | - * @throws EE_Error |
|
132 | - * @throws InvalidArgumentException |
|
133 | - * @throws InvalidDataTypeException |
|
134 | - * @throws InvalidInterfaceException |
|
135 | - */ |
|
136 | - public static function get_timezone_string_from_abbreviations_list($gmt_offset = 0, $coerce = true) |
|
137 | - { |
|
138 | - $gmt_offset = (int) $gmt_offset; |
|
139 | - /** @var array[] $abbreviations */ |
|
140 | - $abbreviations = DateTimeZone::listAbbreviations(); |
|
141 | - foreach ($abbreviations as $abbreviation) { |
|
142 | - foreach ($abbreviation as $timezone) { |
|
143 | - if ((int) $timezone['offset'] === $gmt_offset && (bool) $timezone['dst'] === false) { |
|
144 | - try { |
|
145 | - $offset = self::get_timezone_offset(new DateTimeZone($timezone['timezone_id'])); |
|
146 | - if ($offset !== $gmt_offset) { |
|
147 | - continue; |
|
148 | - } |
|
149 | - return $timezone['timezone_id']; |
|
150 | - } catch (Exception $e) { |
|
151 | - continue; |
|
152 | - } |
|
153 | - } |
|
154 | - } |
|
155 | - } |
|
156 | - //if $coerce is true, let's see if we can get a timezone string after the offset is adjusted |
|
157 | - if ($coerce === true) { |
|
158 | - $timezone_string = self::get_timezone_string_from_abbreviations_list( |
|
159 | - self::adjust_invalid_gmt_offsets($gmt_offset), |
|
160 | - false |
|
161 | - ); |
|
162 | - if ($timezone_string) { |
|
163 | - return $timezone_string; |
|
164 | - } |
|
165 | - } |
|
166 | - throw new EE_Error( |
|
167 | - sprintf( |
|
168 | - esc_html__( |
|
169 | - 'The provided GMT offset (%1$s), is invalid, please check with %2$sthis list%3$s for what valid timezones can be used', |
|
170 | - 'event_espresso' |
|
171 | - ), |
|
172 | - $gmt_offset / HOUR_IN_SECONDS, |
|
173 | - '<a href="http://www.php.net/manual/en/timezones.php">', |
|
174 | - '</a>' |
|
175 | - ) |
|
176 | - ); |
|
177 | - } |
|
123 | + /** |
|
124 | + * get_timezone_string_from_abbreviations_list |
|
125 | + * |
|
126 | + * @deprecated 4.9.54.rc Developers, this was never intended to be public. This is a soft deprecation for now. |
|
127 | + * If you are using this, you'll want to work out an alternate way of getting the value. |
|
128 | + * @param int $gmt_offset |
|
129 | + * @param bool $coerce If true, we attempt to coerce with our adjustment table @see self::adjust_invalid_gmt_offset. |
|
130 | + * @return string |
|
131 | + * @throws EE_Error |
|
132 | + * @throws InvalidArgumentException |
|
133 | + * @throws InvalidDataTypeException |
|
134 | + * @throws InvalidInterfaceException |
|
135 | + */ |
|
136 | + public static function get_timezone_string_from_abbreviations_list($gmt_offset = 0, $coerce = true) |
|
137 | + { |
|
138 | + $gmt_offset = (int) $gmt_offset; |
|
139 | + /** @var array[] $abbreviations */ |
|
140 | + $abbreviations = DateTimeZone::listAbbreviations(); |
|
141 | + foreach ($abbreviations as $abbreviation) { |
|
142 | + foreach ($abbreviation as $timezone) { |
|
143 | + if ((int) $timezone['offset'] === $gmt_offset && (bool) $timezone['dst'] === false) { |
|
144 | + try { |
|
145 | + $offset = self::get_timezone_offset(new DateTimeZone($timezone['timezone_id'])); |
|
146 | + if ($offset !== $gmt_offset) { |
|
147 | + continue; |
|
148 | + } |
|
149 | + return $timezone['timezone_id']; |
|
150 | + } catch (Exception $e) { |
|
151 | + continue; |
|
152 | + } |
|
153 | + } |
|
154 | + } |
|
155 | + } |
|
156 | + //if $coerce is true, let's see if we can get a timezone string after the offset is adjusted |
|
157 | + if ($coerce === true) { |
|
158 | + $timezone_string = self::get_timezone_string_from_abbreviations_list( |
|
159 | + self::adjust_invalid_gmt_offsets($gmt_offset), |
|
160 | + false |
|
161 | + ); |
|
162 | + if ($timezone_string) { |
|
163 | + return $timezone_string; |
|
164 | + } |
|
165 | + } |
|
166 | + throw new EE_Error( |
|
167 | + sprintf( |
|
168 | + esc_html__( |
|
169 | + 'The provided GMT offset (%1$s), is invalid, please check with %2$sthis list%3$s for what valid timezones can be used', |
|
170 | + 'event_espresso' |
|
171 | + ), |
|
172 | + $gmt_offset / HOUR_IN_SECONDS, |
|
173 | + '<a href="http://www.php.net/manual/en/timezones.php">', |
|
174 | + '</a>' |
|
175 | + ) |
|
176 | + ); |
|
177 | + } |
|
178 | 178 | |
179 | 179 | |
180 | - /** |
|
181 | - * Get Timezone Transitions |
|
182 | - * |
|
183 | - * @param DateTimeZone $date_time_zone |
|
184 | - * @param int|null $time |
|
185 | - * @param bool $first_only |
|
186 | - * @return array |
|
187 | - * @throws InvalidArgumentException |
|
188 | - * @throws InvalidDataTypeException |
|
189 | - * @throws InvalidInterfaceException |
|
190 | - */ |
|
191 | - public static function get_timezone_transitions(DateTimeZone $date_time_zone, $time = null, $first_only = true) |
|
192 | - { |
|
193 | - return self::getHelperAdapter()->getTimezoneTransitions($date_time_zone, $time, $first_only); |
|
194 | - } |
|
180 | + /** |
|
181 | + * Get Timezone Transitions |
|
182 | + * |
|
183 | + * @param DateTimeZone $date_time_zone |
|
184 | + * @param int|null $time |
|
185 | + * @param bool $first_only |
|
186 | + * @return array |
|
187 | + * @throws InvalidArgumentException |
|
188 | + * @throws InvalidDataTypeException |
|
189 | + * @throws InvalidInterfaceException |
|
190 | + */ |
|
191 | + public static function get_timezone_transitions(DateTimeZone $date_time_zone, $time = null, $first_only = true) |
|
192 | + { |
|
193 | + return self::getHelperAdapter()->getTimezoneTransitions($date_time_zone, $time, $first_only); |
|
194 | + } |
|
195 | 195 | |
196 | 196 | |
197 | - /** |
|
198 | - * Get Timezone Offset for given timezone object. |
|
199 | - * |
|
200 | - * @param DateTimeZone $date_time_zone |
|
201 | - * @param null $time |
|
202 | - * @return mixed |
|
203 | - * @throws InvalidArgumentException |
|
204 | - * @throws InvalidDataTypeException |
|
205 | - * @throws InvalidInterfaceException |
|
206 | - */ |
|
207 | - public static function get_timezone_offset(DateTimeZone $date_time_zone, $time = null) |
|
208 | - { |
|
209 | - return self::getHelperAdapter()->getTimezoneOffset($date_time_zone, $time); |
|
210 | - } |
|
197 | + /** |
|
198 | + * Get Timezone Offset for given timezone object. |
|
199 | + * |
|
200 | + * @param DateTimeZone $date_time_zone |
|
201 | + * @param null $time |
|
202 | + * @return mixed |
|
203 | + * @throws InvalidArgumentException |
|
204 | + * @throws InvalidDataTypeException |
|
205 | + * @throws InvalidInterfaceException |
|
206 | + */ |
|
207 | + public static function get_timezone_offset(DateTimeZone $date_time_zone, $time = null) |
|
208 | + { |
|
209 | + return self::getHelperAdapter()->getTimezoneOffset($date_time_zone, $time); |
|
210 | + } |
|
211 | 211 | |
212 | 212 | |
213 | - /** |
|
214 | - * Prints a select input for the given timezone string. |
|
215 | - * @param string $timezone_string |
|
216 | - * @deprecatd 4.9.54.rc Soft deprecation. Consider using \EEH_DTT_Helper::wp_timezone_choice instead. |
|
217 | - * @throws InvalidArgumentException |
|
218 | - * @throws InvalidDataTypeException |
|
219 | - * @throws InvalidInterfaceException |
|
220 | - */ |
|
221 | - public static function timezone_select_input($timezone_string = '') |
|
222 | - { |
|
223 | - self::getHelperAdapter()->timezoneSelectInput($timezone_string); |
|
224 | - } |
|
213 | + /** |
|
214 | + * Prints a select input for the given timezone string. |
|
215 | + * @param string $timezone_string |
|
216 | + * @deprecatd 4.9.54.rc Soft deprecation. Consider using \EEH_DTT_Helper::wp_timezone_choice instead. |
|
217 | + * @throws InvalidArgumentException |
|
218 | + * @throws InvalidDataTypeException |
|
219 | + * @throws InvalidInterfaceException |
|
220 | + */ |
|
221 | + public static function timezone_select_input($timezone_string = '') |
|
222 | + { |
|
223 | + self::getHelperAdapter()->timezoneSelectInput($timezone_string); |
|
224 | + } |
|
225 | 225 | |
226 | 226 | |
227 | - /** |
|
228 | - * This method will take an incoming unix timestamp and add the offset to it for the given timezone_string. |
|
229 | - * If no unix timestamp is given then time() is used. If no timezone is given then the set timezone string for |
|
230 | - * the site is used. |
|
231 | - * This is used typically when using a Unix timestamp any core WP functions that expect their specially |
|
232 | - * computed timestamp (i.e. date_i18n() ) |
|
233 | - * |
|
234 | - * @param int $unix_timestamp if 0, then time() will be used. |
|
235 | - * @param string $timezone_string timezone_string. If empty, then the current set timezone for the |
|
236 | - * site will be used. |
|
237 | - * @return int $unix_timestamp with the offset applied for the given timezone. |
|
238 | - * @throws InvalidArgumentException |
|
239 | - * @throws InvalidDataTypeException |
|
240 | - * @throws InvalidInterfaceException |
|
241 | - */ |
|
242 | - public static function get_timestamp_with_offset($unix_timestamp = 0, $timezone_string = '') |
|
243 | - { |
|
244 | - return self::getHelperAdapter()->getTimestampWithOffset($unix_timestamp, $timezone_string); |
|
245 | - } |
|
227 | + /** |
|
228 | + * This method will take an incoming unix timestamp and add the offset to it for the given timezone_string. |
|
229 | + * If no unix timestamp is given then time() is used. If no timezone is given then the set timezone string for |
|
230 | + * the site is used. |
|
231 | + * This is used typically when using a Unix timestamp any core WP functions that expect their specially |
|
232 | + * computed timestamp (i.e. date_i18n() ) |
|
233 | + * |
|
234 | + * @param int $unix_timestamp if 0, then time() will be used. |
|
235 | + * @param string $timezone_string timezone_string. If empty, then the current set timezone for the |
|
236 | + * site will be used. |
|
237 | + * @return int $unix_timestamp with the offset applied for the given timezone. |
|
238 | + * @throws InvalidArgumentException |
|
239 | + * @throws InvalidDataTypeException |
|
240 | + * @throws InvalidInterfaceException |
|
241 | + */ |
|
242 | + public static function get_timestamp_with_offset($unix_timestamp = 0, $timezone_string = '') |
|
243 | + { |
|
244 | + return self::getHelperAdapter()->getTimestampWithOffset($unix_timestamp, $timezone_string); |
|
245 | + } |
|
246 | 246 | |
247 | 247 | |
248 | - /** |
|
249 | - * _set_date_time_field |
|
250 | - * modifies EE_Base_Class EE_Datetime_Field objects |
|
251 | - * |
|
252 | - * @param EE_Base_Class $obj EE_Base_Class object |
|
253 | - * @param DateTime $DateTime PHP DateTime object |
|
254 | - * @param string $datetime_field_name the datetime fieldname to be manipulated |
|
255 | - * @return EE_Base_Class |
|
256 | - * @throws EE_Error |
|
257 | - */ |
|
258 | - protected static function _set_date_time_field(EE_Base_Class $obj, DateTime $DateTime, $datetime_field_name) |
|
259 | - { |
|
260 | - // grab current datetime format |
|
261 | - $current_format = $obj->get_format(); |
|
262 | - // set new full timestamp format |
|
263 | - $obj->set_date_format(EE_Datetime_Field::mysql_date_format); |
|
264 | - $obj->set_time_format(EE_Datetime_Field::mysql_time_format); |
|
265 | - // set the new date value using a full timestamp format so that no data is lost |
|
266 | - $obj->set($datetime_field_name, $DateTime->format(EE_Datetime_Field::mysql_timestamp_format)); |
|
267 | - // reset datetime formats |
|
268 | - $obj->set_date_format($current_format[0]); |
|
269 | - $obj->set_time_format($current_format[1]); |
|
270 | - return $obj; |
|
271 | - } |
|
248 | + /** |
|
249 | + * _set_date_time_field |
|
250 | + * modifies EE_Base_Class EE_Datetime_Field objects |
|
251 | + * |
|
252 | + * @param EE_Base_Class $obj EE_Base_Class object |
|
253 | + * @param DateTime $DateTime PHP DateTime object |
|
254 | + * @param string $datetime_field_name the datetime fieldname to be manipulated |
|
255 | + * @return EE_Base_Class |
|
256 | + * @throws EE_Error |
|
257 | + */ |
|
258 | + protected static function _set_date_time_field(EE_Base_Class $obj, DateTime $DateTime, $datetime_field_name) |
|
259 | + { |
|
260 | + // grab current datetime format |
|
261 | + $current_format = $obj->get_format(); |
|
262 | + // set new full timestamp format |
|
263 | + $obj->set_date_format(EE_Datetime_Field::mysql_date_format); |
|
264 | + $obj->set_time_format(EE_Datetime_Field::mysql_time_format); |
|
265 | + // set the new date value using a full timestamp format so that no data is lost |
|
266 | + $obj->set($datetime_field_name, $DateTime->format(EE_Datetime_Field::mysql_timestamp_format)); |
|
267 | + // reset datetime formats |
|
268 | + $obj->set_date_format($current_format[0]); |
|
269 | + $obj->set_time_format($current_format[1]); |
|
270 | + return $obj; |
|
271 | + } |
|
272 | 272 | |
273 | 273 | |
274 | - /** |
|
275 | - * date_time_add |
|
276 | - * helper for doing simple datetime calculations on a given datetime from EE_Base_Class |
|
277 | - * and modifying it IN the EE_Base_Class so you don't have to do anything else. |
|
278 | - * |
|
279 | - * @param EE_Base_Class $obj EE_Base_Class object |
|
280 | - * @param string $datetime_field_name name of the EE_Datetime_Filed datatype db column to be manipulated |
|
281 | - * @param string $period what you are adding. The options are (years, months, days, hours, |
|
282 | - * minutes, seconds) defaults to years |
|
283 | - * @param integer $value what you want to increment the time by |
|
284 | - * @return EE_Base_Class return the EE_Base_Class object so right away you can do something with it |
|
285 | - * (chaining) |
|
286 | - * @throws EE_Error |
|
287 | - * @throws Exception |
|
288 | - */ |
|
289 | - public static function date_time_add(EE_Base_Class $obj, $datetime_field_name, $period = 'years', $value = 1) |
|
290 | - { |
|
291 | - //get the raw UTC date. |
|
292 | - $DateTime = $obj->get_DateTime_object($datetime_field_name); |
|
293 | - $DateTime = EEH_DTT_Helper::calc_date($DateTime, $period, $value); |
|
294 | - return EEH_DTT_Helper::_set_date_time_field($obj, $DateTime, $datetime_field_name); |
|
295 | - } |
|
274 | + /** |
|
275 | + * date_time_add |
|
276 | + * helper for doing simple datetime calculations on a given datetime from EE_Base_Class |
|
277 | + * and modifying it IN the EE_Base_Class so you don't have to do anything else. |
|
278 | + * |
|
279 | + * @param EE_Base_Class $obj EE_Base_Class object |
|
280 | + * @param string $datetime_field_name name of the EE_Datetime_Filed datatype db column to be manipulated |
|
281 | + * @param string $period what you are adding. The options are (years, months, days, hours, |
|
282 | + * minutes, seconds) defaults to years |
|
283 | + * @param integer $value what you want to increment the time by |
|
284 | + * @return EE_Base_Class return the EE_Base_Class object so right away you can do something with it |
|
285 | + * (chaining) |
|
286 | + * @throws EE_Error |
|
287 | + * @throws Exception |
|
288 | + */ |
|
289 | + public static function date_time_add(EE_Base_Class $obj, $datetime_field_name, $period = 'years', $value = 1) |
|
290 | + { |
|
291 | + //get the raw UTC date. |
|
292 | + $DateTime = $obj->get_DateTime_object($datetime_field_name); |
|
293 | + $DateTime = EEH_DTT_Helper::calc_date($DateTime, $period, $value); |
|
294 | + return EEH_DTT_Helper::_set_date_time_field($obj, $DateTime, $datetime_field_name); |
|
295 | + } |
|
296 | 296 | |
297 | 297 | |
298 | - /** |
|
299 | - * date_time_subtract |
|
300 | - * same as date_time_add except subtracting value instead of adding. |
|
301 | - * |
|
302 | - * @param EE_Base_Class $obj |
|
303 | - * @param string $datetime_field_name name of the EE_Datetime_Filed datatype db column to be manipulated |
|
304 | - * @param string $period |
|
305 | - * @param int $value |
|
306 | - * @return EE_Base_Class |
|
307 | - * @throws EE_Error |
|
308 | - * @throws Exception |
|
309 | - */ |
|
310 | - public static function date_time_subtract(EE_Base_Class $obj, $datetime_field_name, $period = 'years', $value = 1) |
|
311 | - { |
|
312 | - //get the raw UTC date |
|
313 | - $DateTime = $obj->get_DateTime_object($datetime_field_name); |
|
314 | - $DateTime = EEH_DTT_Helper::calc_date($DateTime, $period, $value, '-'); |
|
315 | - return EEH_DTT_Helper::_set_date_time_field($obj, $DateTime, $datetime_field_name); |
|
316 | - } |
|
298 | + /** |
|
299 | + * date_time_subtract |
|
300 | + * same as date_time_add except subtracting value instead of adding. |
|
301 | + * |
|
302 | + * @param EE_Base_Class $obj |
|
303 | + * @param string $datetime_field_name name of the EE_Datetime_Filed datatype db column to be manipulated |
|
304 | + * @param string $period |
|
305 | + * @param int $value |
|
306 | + * @return EE_Base_Class |
|
307 | + * @throws EE_Error |
|
308 | + * @throws Exception |
|
309 | + */ |
|
310 | + public static function date_time_subtract(EE_Base_Class $obj, $datetime_field_name, $period = 'years', $value = 1) |
|
311 | + { |
|
312 | + //get the raw UTC date |
|
313 | + $DateTime = $obj->get_DateTime_object($datetime_field_name); |
|
314 | + $DateTime = EEH_DTT_Helper::calc_date($DateTime, $period, $value, '-'); |
|
315 | + return EEH_DTT_Helper::_set_date_time_field($obj, $DateTime, $datetime_field_name); |
|
316 | + } |
|
317 | 317 | |
318 | 318 | |
319 | - /** |
|
320 | - * Simply takes an incoming DateTime object and does calculations on it based on the incoming parameters |
|
321 | - * |
|
322 | - * @param DateTime $DateTime DateTime object |
|
323 | - * @param string $period a value to indicate what interval is being used in the calculation. The options are |
|
324 | - * 'years', 'months', 'days', 'hours', 'minutes', 'seconds'. Defaults to years. |
|
325 | - * @param int|string $value What you want to increment the date by |
|
326 | - * @param string $operand What operand you wish to use for the calculation |
|
327 | - * @return DateTime return whatever type came in. |
|
328 | - * @throws Exception |
|
329 | - * @throws EE_Error |
|
330 | - */ |
|
331 | - protected static function _modify_datetime_object(DateTime $DateTime, $period = 'years', $value = 1, $operand = '+') |
|
332 | - { |
|
333 | - if (! $DateTime instanceof DateTime) { |
|
334 | - throw new EE_Error( |
|
335 | - sprintf( |
|
336 | - esc_html__('Expected a PHP DateTime object, but instead received %1$s', 'event_espresso'), |
|
337 | - print_r($DateTime, true) |
|
338 | - ) |
|
339 | - ); |
|
340 | - } |
|
341 | - switch ($period) { |
|
342 | - case 'years' : |
|
343 | - $value = 'P' . $value . 'Y'; |
|
344 | - break; |
|
345 | - case 'months' : |
|
346 | - $value = 'P' . $value . 'M'; |
|
347 | - break; |
|
348 | - case 'weeks' : |
|
349 | - $value = 'P' . $value . 'W'; |
|
350 | - break; |
|
351 | - case 'days' : |
|
352 | - $value = 'P' . $value . 'D'; |
|
353 | - break; |
|
354 | - case 'hours' : |
|
355 | - $value = 'PT' . $value . 'H'; |
|
356 | - break; |
|
357 | - case 'minutes' : |
|
358 | - $value = 'PT' . $value . 'M'; |
|
359 | - break; |
|
360 | - case 'seconds' : |
|
361 | - $value = 'PT' . $value . 'S'; |
|
362 | - break; |
|
363 | - } |
|
364 | - switch ($operand) { |
|
365 | - case '+': |
|
366 | - $DateTime->add(new DateInterval($value)); |
|
367 | - break; |
|
368 | - case '-': |
|
369 | - $DateTime->sub(new DateInterval($value)); |
|
370 | - break; |
|
371 | - } |
|
372 | - return $DateTime; |
|
373 | - } |
|
319 | + /** |
|
320 | + * Simply takes an incoming DateTime object and does calculations on it based on the incoming parameters |
|
321 | + * |
|
322 | + * @param DateTime $DateTime DateTime object |
|
323 | + * @param string $period a value to indicate what interval is being used in the calculation. The options are |
|
324 | + * 'years', 'months', 'days', 'hours', 'minutes', 'seconds'. Defaults to years. |
|
325 | + * @param int|string $value What you want to increment the date by |
|
326 | + * @param string $operand What operand you wish to use for the calculation |
|
327 | + * @return DateTime return whatever type came in. |
|
328 | + * @throws Exception |
|
329 | + * @throws EE_Error |
|
330 | + */ |
|
331 | + protected static function _modify_datetime_object(DateTime $DateTime, $period = 'years', $value = 1, $operand = '+') |
|
332 | + { |
|
333 | + if (! $DateTime instanceof DateTime) { |
|
334 | + throw new EE_Error( |
|
335 | + sprintf( |
|
336 | + esc_html__('Expected a PHP DateTime object, but instead received %1$s', 'event_espresso'), |
|
337 | + print_r($DateTime, true) |
|
338 | + ) |
|
339 | + ); |
|
340 | + } |
|
341 | + switch ($period) { |
|
342 | + case 'years' : |
|
343 | + $value = 'P' . $value . 'Y'; |
|
344 | + break; |
|
345 | + case 'months' : |
|
346 | + $value = 'P' . $value . 'M'; |
|
347 | + break; |
|
348 | + case 'weeks' : |
|
349 | + $value = 'P' . $value . 'W'; |
|
350 | + break; |
|
351 | + case 'days' : |
|
352 | + $value = 'P' . $value . 'D'; |
|
353 | + break; |
|
354 | + case 'hours' : |
|
355 | + $value = 'PT' . $value . 'H'; |
|
356 | + break; |
|
357 | + case 'minutes' : |
|
358 | + $value = 'PT' . $value . 'M'; |
|
359 | + break; |
|
360 | + case 'seconds' : |
|
361 | + $value = 'PT' . $value . 'S'; |
|
362 | + break; |
|
363 | + } |
|
364 | + switch ($operand) { |
|
365 | + case '+': |
|
366 | + $DateTime->add(new DateInterval($value)); |
|
367 | + break; |
|
368 | + case '-': |
|
369 | + $DateTime->sub(new DateInterval($value)); |
|
370 | + break; |
|
371 | + } |
|
372 | + return $DateTime; |
|
373 | + } |
|
374 | 374 | |
375 | 375 | |
376 | - /** |
|
377 | - * Simply takes an incoming Unix timestamp and does calculations on it based on the incoming parameters |
|
378 | - * |
|
379 | - * @param int $timestamp Unix timestamp |
|
380 | - * @param string $period a value to indicate what interval is being used in the calculation. The options are |
|
381 | - * 'years', 'months', 'days', 'hours', 'minutes', 'seconds'. Defaults to years. |
|
382 | - * @param integer $value What you want to increment the date by |
|
383 | - * @param string $operand What operand you wish to use for the calculation |
|
384 | - * @return int |
|
385 | - * @throws EE_Error |
|
386 | - */ |
|
387 | - protected static function _modify_timestamp($timestamp, $period = 'years', $value = 1, $operand = '+') |
|
388 | - { |
|
389 | - if (! preg_match(EE_Datetime_Field::unix_timestamp_regex, $timestamp)) { |
|
390 | - throw new EE_Error( |
|
391 | - sprintf( |
|
392 | - esc_html__('Expected a Unix timestamp, but instead received %1$s', 'event_espresso'), |
|
393 | - print_r($timestamp, true) |
|
394 | - ) |
|
395 | - ); |
|
396 | - } |
|
397 | - switch ($period) { |
|
398 | - case 'years' : |
|
399 | - $value = YEAR_IN_SECONDS * $value; |
|
400 | - break; |
|
401 | - case 'months' : |
|
402 | - $value = YEAR_IN_SECONDS / 12 * $value; |
|
403 | - break; |
|
404 | - case 'weeks' : |
|
405 | - $value = WEEK_IN_SECONDS * $value; |
|
406 | - break; |
|
407 | - case 'days' : |
|
408 | - $value = DAY_IN_SECONDS * $value; |
|
409 | - break; |
|
410 | - case 'hours' : |
|
411 | - $value = HOUR_IN_SECONDS * $value; |
|
412 | - break; |
|
413 | - case 'minutes' : |
|
414 | - $value = MINUTE_IN_SECONDS * $value; |
|
415 | - break; |
|
416 | - } |
|
417 | - switch ($operand) { |
|
418 | - case '+': |
|
419 | - $timestamp += $value; |
|
420 | - break; |
|
421 | - case '-': |
|
422 | - $timestamp -= $value; |
|
423 | - break; |
|
424 | - } |
|
425 | - return $timestamp; |
|
426 | - } |
|
376 | + /** |
|
377 | + * Simply takes an incoming Unix timestamp and does calculations on it based on the incoming parameters |
|
378 | + * |
|
379 | + * @param int $timestamp Unix timestamp |
|
380 | + * @param string $period a value to indicate what interval is being used in the calculation. The options are |
|
381 | + * 'years', 'months', 'days', 'hours', 'minutes', 'seconds'. Defaults to years. |
|
382 | + * @param integer $value What you want to increment the date by |
|
383 | + * @param string $operand What operand you wish to use for the calculation |
|
384 | + * @return int |
|
385 | + * @throws EE_Error |
|
386 | + */ |
|
387 | + protected static function _modify_timestamp($timestamp, $period = 'years', $value = 1, $operand = '+') |
|
388 | + { |
|
389 | + if (! preg_match(EE_Datetime_Field::unix_timestamp_regex, $timestamp)) { |
|
390 | + throw new EE_Error( |
|
391 | + sprintf( |
|
392 | + esc_html__('Expected a Unix timestamp, but instead received %1$s', 'event_espresso'), |
|
393 | + print_r($timestamp, true) |
|
394 | + ) |
|
395 | + ); |
|
396 | + } |
|
397 | + switch ($period) { |
|
398 | + case 'years' : |
|
399 | + $value = YEAR_IN_SECONDS * $value; |
|
400 | + break; |
|
401 | + case 'months' : |
|
402 | + $value = YEAR_IN_SECONDS / 12 * $value; |
|
403 | + break; |
|
404 | + case 'weeks' : |
|
405 | + $value = WEEK_IN_SECONDS * $value; |
|
406 | + break; |
|
407 | + case 'days' : |
|
408 | + $value = DAY_IN_SECONDS * $value; |
|
409 | + break; |
|
410 | + case 'hours' : |
|
411 | + $value = HOUR_IN_SECONDS * $value; |
|
412 | + break; |
|
413 | + case 'minutes' : |
|
414 | + $value = MINUTE_IN_SECONDS * $value; |
|
415 | + break; |
|
416 | + } |
|
417 | + switch ($operand) { |
|
418 | + case '+': |
|
419 | + $timestamp += $value; |
|
420 | + break; |
|
421 | + case '-': |
|
422 | + $timestamp -= $value; |
|
423 | + break; |
|
424 | + } |
|
425 | + return $timestamp; |
|
426 | + } |
|
427 | 427 | |
428 | 428 | |
429 | - /** |
|
430 | - * Simply takes an incoming UTC timestamp or DateTime object and does calculations on it based on the incoming |
|
431 | - * parameters and returns the new timestamp or DateTime. |
|
432 | - * |
|
433 | - * @param int | DateTime $DateTime_or_timestamp DateTime object or Unix timestamp |
|
434 | - * @param string $period a value to indicate what interval is being used in the |
|
435 | - * calculation. The options are 'years', 'months', 'days', 'hours', |
|
436 | - * 'minutes', 'seconds'. Defaults to years. |
|
437 | - * @param integer $value What you want to increment the date by |
|
438 | - * @param string $operand What operand you wish to use for the calculation |
|
439 | - * @return mixed string|DateTime return whatever type came in. |
|
440 | - * @throws Exception |
|
441 | - * @throws EE_Error |
|
442 | - */ |
|
443 | - public static function calc_date($DateTime_or_timestamp, $period = 'years', $value = 1, $operand = '+') |
|
444 | - { |
|
445 | - if ($DateTime_or_timestamp instanceof DateTime) { |
|
446 | - return EEH_DTT_Helper::_modify_datetime_object( |
|
447 | - $DateTime_or_timestamp, |
|
448 | - $period, |
|
449 | - $value, |
|
450 | - $operand |
|
451 | - ); |
|
452 | - } |
|
453 | - if (preg_match(EE_Datetime_Field::unix_timestamp_regex, $DateTime_or_timestamp)) { |
|
454 | - return EEH_DTT_Helper::_modify_timestamp( |
|
455 | - $DateTime_or_timestamp, |
|
456 | - $period, |
|
457 | - $value, |
|
458 | - $operand |
|
459 | - ); |
|
460 | - } |
|
461 | - //error |
|
462 | - return $DateTime_or_timestamp; |
|
463 | - } |
|
429 | + /** |
|
430 | + * Simply takes an incoming UTC timestamp or DateTime object and does calculations on it based on the incoming |
|
431 | + * parameters and returns the new timestamp or DateTime. |
|
432 | + * |
|
433 | + * @param int | DateTime $DateTime_or_timestamp DateTime object or Unix timestamp |
|
434 | + * @param string $period a value to indicate what interval is being used in the |
|
435 | + * calculation. The options are 'years', 'months', 'days', 'hours', |
|
436 | + * 'minutes', 'seconds'. Defaults to years. |
|
437 | + * @param integer $value What you want to increment the date by |
|
438 | + * @param string $operand What operand you wish to use for the calculation |
|
439 | + * @return mixed string|DateTime return whatever type came in. |
|
440 | + * @throws Exception |
|
441 | + * @throws EE_Error |
|
442 | + */ |
|
443 | + public static function calc_date($DateTime_or_timestamp, $period = 'years', $value = 1, $operand = '+') |
|
444 | + { |
|
445 | + if ($DateTime_or_timestamp instanceof DateTime) { |
|
446 | + return EEH_DTT_Helper::_modify_datetime_object( |
|
447 | + $DateTime_or_timestamp, |
|
448 | + $period, |
|
449 | + $value, |
|
450 | + $operand |
|
451 | + ); |
|
452 | + } |
|
453 | + if (preg_match(EE_Datetime_Field::unix_timestamp_regex, $DateTime_or_timestamp)) { |
|
454 | + return EEH_DTT_Helper::_modify_timestamp( |
|
455 | + $DateTime_or_timestamp, |
|
456 | + $period, |
|
457 | + $value, |
|
458 | + $operand |
|
459 | + ); |
|
460 | + } |
|
461 | + //error |
|
462 | + return $DateTime_or_timestamp; |
|
463 | + } |
|
464 | 464 | |
465 | 465 | |
466 | - /** |
|
467 | - * The purpose of this helper method is to receive an incoming format string in php date/time format |
|
468 | - * and spit out the js and moment.js equivalent formats. |
|
469 | - * Note, if no format string is given, then it is assumed the user wants what is set for WP. |
|
470 | - * Note, js date and time formats are those used by the jquery-ui datepicker and the jquery-ui date- |
|
471 | - * time picker. |
|
472 | - * |
|
473 | - * @see http://stackoverflow.com/posts/16725290/ for the code inspiration. |
|
474 | - * @param string $date_format_string |
|
475 | - * @param string $time_format_string |
|
476 | - * @return array |
|
477 | - * array( |
|
478 | - * 'js' => array ( |
|
479 | - * 'date' => //date format |
|
480 | - * 'time' => //time format |
|
481 | - * ), |
|
482 | - * 'moment' => //date and time format. |
|
483 | - * ) |
|
484 | - */ |
|
485 | - public static function convert_php_to_js_and_moment_date_formats( |
|
486 | - $date_format_string = null, |
|
487 | - $time_format_string = null |
|
488 | - ) { |
|
489 | - if ($date_format_string === null) { |
|
490 | - $date_format_string = (string) get_option('date_format'); |
|
491 | - } |
|
492 | - if ($time_format_string === null) { |
|
493 | - $time_format_string = (string) get_option('time_format'); |
|
494 | - } |
|
495 | - $date_format = self::_php_to_js_moment_converter($date_format_string); |
|
496 | - $time_format = self::_php_to_js_moment_converter($time_format_string); |
|
497 | - return array( |
|
498 | - 'js' => array( |
|
499 | - 'date' => $date_format['js'], |
|
500 | - 'time' => $time_format['js'], |
|
501 | - ), |
|
502 | - 'moment' => $date_format['moment'] . ' ' . $time_format['moment'], |
|
503 | - ); |
|
504 | - } |
|
466 | + /** |
|
467 | + * The purpose of this helper method is to receive an incoming format string in php date/time format |
|
468 | + * and spit out the js and moment.js equivalent formats. |
|
469 | + * Note, if no format string is given, then it is assumed the user wants what is set for WP. |
|
470 | + * Note, js date and time formats are those used by the jquery-ui datepicker and the jquery-ui date- |
|
471 | + * time picker. |
|
472 | + * |
|
473 | + * @see http://stackoverflow.com/posts/16725290/ for the code inspiration. |
|
474 | + * @param string $date_format_string |
|
475 | + * @param string $time_format_string |
|
476 | + * @return array |
|
477 | + * array( |
|
478 | + * 'js' => array ( |
|
479 | + * 'date' => //date format |
|
480 | + * 'time' => //time format |
|
481 | + * ), |
|
482 | + * 'moment' => //date and time format. |
|
483 | + * ) |
|
484 | + */ |
|
485 | + public static function convert_php_to_js_and_moment_date_formats( |
|
486 | + $date_format_string = null, |
|
487 | + $time_format_string = null |
|
488 | + ) { |
|
489 | + if ($date_format_string === null) { |
|
490 | + $date_format_string = (string) get_option('date_format'); |
|
491 | + } |
|
492 | + if ($time_format_string === null) { |
|
493 | + $time_format_string = (string) get_option('time_format'); |
|
494 | + } |
|
495 | + $date_format = self::_php_to_js_moment_converter($date_format_string); |
|
496 | + $time_format = self::_php_to_js_moment_converter($time_format_string); |
|
497 | + return array( |
|
498 | + 'js' => array( |
|
499 | + 'date' => $date_format['js'], |
|
500 | + 'time' => $time_format['js'], |
|
501 | + ), |
|
502 | + 'moment' => $date_format['moment'] . ' ' . $time_format['moment'], |
|
503 | + ); |
|
504 | + } |
|
505 | 505 | |
506 | 506 | |
507 | - /** |
|
508 | - * This converts incoming format string into js and moment variations. |
|
509 | - * |
|
510 | - * @param string $format_string incoming php format string |
|
511 | - * @return array js and moment formats. |
|
512 | - */ |
|
513 | - protected static function _php_to_js_moment_converter($format_string) |
|
514 | - { |
|
515 | - /** |
|
516 | - * This is a map of symbols for formats. |
|
517 | - * The index is the php symbol, the equivalent values are in the array. |
|
518 | - * |
|
519 | - * @var array |
|
520 | - */ |
|
521 | - $symbols_map = array( |
|
522 | - // Day |
|
523 | - //01 |
|
524 | - 'd' => array( |
|
525 | - 'js' => 'dd', |
|
526 | - 'moment' => 'DD', |
|
527 | - ), |
|
528 | - //Mon |
|
529 | - 'D' => array( |
|
530 | - 'js' => 'D', |
|
531 | - 'moment' => 'ddd', |
|
532 | - ), |
|
533 | - //1,2,...31 |
|
534 | - 'j' => array( |
|
535 | - 'js' => 'd', |
|
536 | - 'moment' => 'D', |
|
537 | - ), |
|
538 | - //Monday |
|
539 | - 'l' => array( |
|
540 | - 'js' => 'DD', |
|
541 | - 'moment' => 'dddd', |
|
542 | - ), |
|
543 | - //ISO numeric representation of the day of the week (1-6) |
|
544 | - 'N' => array( |
|
545 | - 'js' => '', |
|
546 | - 'moment' => 'E', |
|
547 | - ), |
|
548 | - //st,nd.rd |
|
549 | - 'S' => array( |
|
550 | - 'js' => '', |
|
551 | - 'moment' => 'o', |
|
552 | - ), |
|
553 | - //numeric representation of day of week (0-6) |
|
554 | - 'w' => array( |
|
555 | - 'js' => '', |
|
556 | - 'moment' => 'd', |
|
557 | - ), |
|
558 | - //day of year starting from 0 (0-365) |
|
559 | - 'z' => array( |
|
560 | - 'js' => 'o', |
|
561 | - 'moment' => 'DDD' //note moment does not start with 0 so will need to modify by subtracting 1 |
|
562 | - ), |
|
563 | - // Week |
|
564 | - //ISO-8601 week number of year (weeks starting on monday) |
|
565 | - 'W' => array( |
|
566 | - 'js' => '', |
|
567 | - 'moment' => 'w', |
|
568 | - ), |
|
569 | - // Month |
|
570 | - // January...December |
|
571 | - 'F' => array( |
|
572 | - 'js' => 'MM', |
|
573 | - 'moment' => 'MMMM', |
|
574 | - ), |
|
575 | - //01...12 |
|
576 | - 'm' => array( |
|
577 | - 'js' => 'mm', |
|
578 | - 'moment' => 'MM', |
|
579 | - ), |
|
580 | - //Jan...Dec |
|
581 | - 'M' => array( |
|
582 | - 'js' => 'M', |
|
583 | - 'moment' => 'MMM', |
|
584 | - ), |
|
585 | - //1-12 |
|
586 | - 'n' => array( |
|
587 | - 'js' => 'm', |
|
588 | - 'moment' => 'M', |
|
589 | - ), |
|
590 | - //number of days in given month |
|
591 | - 't' => array( |
|
592 | - 'js' => '', |
|
593 | - 'moment' => '', |
|
594 | - ), |
|
595 | - // Year |
|
596 | - //whether leap year or not 1/0 |
|
597 | - 'L' => array( |
|
598 | - 'js' => '', |
|
599 | - 'moment' => '', |
|
600 | - ), |
|
601 | - //ISO-8601 year number |
|
602 | - 'o' => array( |
|
603 | - 'js' => '', |
|
604 | - 'moment' => 'GGGG', |
|
605 | - ), |
|
606 | - //1999...2003 |
|
607 | - 'Y' => array( |
|
608 | - 'js' => 'yy', |
|
609 | - 'moment' => 'YYYY', |
|
610 | - ), |
|
611 | - //99...03 |
|
612 | - 'y' => array( |
|
613 | - 'js' => 'y', |
|
614 | - 'moment' => 'YY', |
|
615 | - ), |
|
616 | - // Time |
|
617 | - // am/pm |
|
618 | - 'a' => array( |
|
619 | - 'js' => 'tt', |
|
620 | - 'moment' => 'a', |
|
621 | - ), |
|
622 | - // AM/PM |
|
623 | - 'A' => array( |
|
624 | - 'js' => 'TT', |
|
625 | - 'moment' => 'A', |
|
626 | - ), |
|
627 | - // Swatch Internet Time?!? |
|
628 | - 'B' => array( |
|
629 | - 'js' => '', |
|
630 | - 'moment' => '', |
|
631 | - ), |
|
632 | - //1...12 |
|
633 | - 'g' => array( |
|
634 | - 'js' => 'h', |
|
635 | - 'moment' => 'h', |
|
636 | - ), |
|
637 | - //0...23 |
|
638 | - 'G' => array( |
|
639 | - 'js' => 'H', |
|
640 | - 'moment' => 'H', |
|
641 | - ), |
|
642 | - //01...12 |
|
643 | - 'h' => array( |
|
644 | - 'js' => 'hh', |
|
645 | - 'moment' => 'hh', |
|
646 | - ), |
|
647 | - //00...23 |
|
648 | - 'H' => array( |
|
649 | - 'js' => 'HH', |
|
650 | - 'moment' => 'HH', |
|
651 | - ), |
|
652 | - //00..59 |
|
653 | - 'i' => array( |
|
654 | - 'js' => 'mm', |
|
655 | - 'moment' => 'mm', |
|
656 | - ), |
|
657 | - //seconds... 00...59 |
|
658 | - 's' => array( |
|
659 | - 'js' => 'ss', |
|
660 | - 'moment' => 'ss', |
|
661 | - ), |
|
662 | - //microseconds |
|
663 | - 'u' => array( |
|
664 | - 'js' => '', |
|
665 | - 'moment' => '', |
|
666 | - ), |
|
667 | - ); |
|
668 | - $jquery_ui_format = ''; |
|
669 | - $moment_format = ''; |
|
670 | - $escaping = false; |
|
671 | - $format_string_length = strlen($format_string); |
|
672 | - for ($i = 0; $i < $format_string_length; $i++) { |
|
673 | - $char = $format_string[ $i ]; |
|
674 | - if ($char === '\\') { // PHP date format escaping character |
|
675 | - $i++; |
|
676 | - if ($escaping) { |
|
677 | - $jquery_ui_format .= $format_string[ $i ]; |
|
678 | - $moment_format .= $format_string[ $i ]; |
|
679 | - } else { |
|
680 | - $jquery_ui_format .= '\'' . $format_string[ $i ]; |
|
681 | - $moment_format .= $format_string[ $i ]; |
|
682 | - } |
|
683 | - $escaping = true; |
|
684 | - } else { |
|
685 | - if ($escaping) { |
|
686 | - $jquery_ui_format .= "'"; |
|
687 | - $moment_format .= "'"; |
|
688 | - $escaping = false; |
|
689 | - } |
|
690 | - if (isset($symbols_map[ $char ])) { |
|
691 | - $jquery_ui_format .= $symbols_map[ $char ]['js']; |
|
692 | - $moment_format .= $symbols_map[ $char ]['moment']; |
|
693 | - } else { |
|
694 | - $jquery_ui_format .= $char; |
|
695 | - $moment_format .= $char; |
|
696 | - } |
|
697 | - } |
|
698 | - } |
|
699 | - return array('js' => $jquery_ui_format, 'moment' => $moment_format); |
|
700 | - } |
|
507 | + /** |
|
508 | + * This converts incoming format string into js and moment variations. |
|
509 | + * |
|
510 | + * @param string $format_string incoming php format string |
|
511 | + * @return array js and moment formats. |
|
512 | + */ |
|
513 | + protected static function _php_to_js_moment_converter($format_string) |
|
514 | + { |
|
515 | + /** |
|
516 | + * This is a map of symbols for formats. |
|
517 | + * The index is the php symbol, the equivalent values are in the array. |
|
518 | + * |
|
519 | + * @var array |
|
520 | + */ |
|
521 | + $symbols_map = array( |
|
522 | + // Day |
|
523 | + //01 |
|
524 | + 'd' => array( |
|
525 | + 'js' => 'dd', |
|
526 | + 'moment' => 'DD', |
|
527 | + ), |
|
528 | + //Mon |
|
529 | + 'D' => array( |
|
530 | + 'js' => 'D', |
|
531 | + 'moment' => 'ddd', |
|
532 | + ), |
|
533 | + //1,2,...31 |
|
534 | + 'j' => array( |
|
535 | + 'js' => 'd', |
|
536 | + 'moment' => 'D', |
|
537 | + ), |
|
538 | + //Monday |
|
539 | + 'l' => array( |
|
540 | + 'js' => 'DD', |
|
541 | + 'moment' => 'dddd', |
|
542 | + ), |
|
543 | + //ISO numeric representation of the day of the week (1-6) |
|
544 | + 'N' => array( |
|
545 | + 'js' => '', |
|
546 | + 'moment' => 'E', |
|
547 | + ), |
|
548 | + //st,nd.rd |
|
549 | + 'S' => array( |
|
550 | + 'js' => '', |
|
551 | + 'moment' => 'o', |
|
552 | + ), |
|
553 | + //numeric representation of day of week (0-6) |
|
554 | + 'w' => array( |
|
555 | + 'js' => '', |
|
556 | + 'moment' => 'd', |
|
557 | + ), |
|
558 | + //day of year starting from 0 (0-365) |
|
559 | + 'z' => array( |
|
560 | + 'js' => 'o', |
|
561 | + 'moment' => 'DDD' //note moment does not start with 0 so will need to modify by subtracting 1 |
|
562 | + ), |
|
563 | + // Week |
|
564 | + //ISO-8601 week number of year (weeks starting on monday) |
|
565 | + 'W' => array( |
|
566 | + 'js' => '', |
|
567 | + 'moment' => 'w', |
|
568 | + ), |
|
569 | + // Month |
|
570 | + // January...December |
|
571 | + 'F' => array( |
|
572 | + 'js' => 'MM', |
|
573 | + 'moment' => 'MMMM', |
|
574 | + ), |
|
575 | + //01...12 |
|
576 | + 'm' => array( |
|
577 | + 'js' => 'mm', |
|
578 | + 'moment' => 'MM', |
|
579 | + ), |
|
580 | + //Jan...Dec |
|
581 | + 'M' => array( |
|
582 | + 'js' => 'M', |
|
583 | + 'moment' => 'MMM', |
|
584 | + ), |
|
585 | + //1-12 |
|
586 | + 'n' => array( |
|
587 | + 'js' => 'm', |
|
588 | + 'moment' => 'M', |
|
589 | + ), |
|
590 | + //number of days in given month |
|
591 | + 't' => array( |
|
592 | + 'js' => '', |
|
593 | + 'moment' => '', |
|
594 | + ), |
|
595 | + // Year |
|
596 | + //whether leap year or not 1/0 |
|
597 | + 'L' => array( |
|
598 | + 'js' => '', |
|
599 | + 'moment' => '', |
|
600 | + ), |
|
601 | + //ISO-8601 year number |
|
602 | + 'o' => array( |
|
603 | + 'js' => '', |
|
604 | + 'moment' => 'GGGG', |
|
605 | + ), |
|
606 | + //1999...2003 |
|
607 | + 'Y' => array( |
|
608 | + 'js' => 'yy', |
|
609 | + 'moment' => 'YYYY', |
|
610 | + ), |
|
611 | + //99...03 |
|
612 | + 'y' => array( |
|
613 | + 'js' => 'y', |
|
614 | + 'moment' => 'YY', |
|
615 | + ), |
|
616 | + // Time |
|
617 | + // am/pm |
|
618 | + 'a' => array( |
|
619 | + 'js' => 'tt', |
|
620 | + 'moment' => 'a', |
|
621 | + ), |
|
622 | + // AM/PM |
|
623 | + 'A' => array( |
|
624 | + 'js' => 'TT', |
|
625 | + 'moment' => 'A', |
|
626 | + ), |
|
627 | + // Swatch Internet Time?!? |
|
628 | + 'B' => array( |
|
629 | + 'js' => '', |
|
630 | + 'moment' => '', |
|
631 | + ), |
|
632 | + //1...12 |
|
633 | + 'g' => array( |
|
634 | + 'js' => 'h', |
|
635 | + 'moment' => 'h', |
|
636 | + ), |
|
637 | + //0...23 |
|
638 | + 'G' => array( |
|
639 | + 'js' => 'H', |
|
640 | + 'moment' => 'H', |
|
641 | + ), |
|
642 | + //01...12 |
|
643 | + 'h' => array( |
|
644 | + 'js' => 'hh', |
|
645 | + 'moment' => 'hh', |
|
646 | + ), |
|
647 | + //00...23 |
|
648 | + 'H' => array( |
|
649 | + 'js' => 'HH', |
|
650 | + 'moment' => 'HH', |
|
651 | + ), |
|
652 | + //00..59 |
|
653 | + 'i' => array( |
|
654 | + 'js' => 'mm', |
|
655 | + 'moment' => 'mm', |
|
656 | + ), |
|
657 | + //seconds... 00...59 |
|
658 | + 's' => array( |
|
659 | + 'js' => 'ss', |
|
660 | + 'moment' => 'ss', |
|
661 | + ), |
|
662 | + //microseconds |
|
663 | + 'u' => array( |
|
664 | + 'js' => '', |
|
665 | + 'moment' => '', |
|
666 | + ), |
|
667 | + ); |
|
668 | + $jquery_ui_format = ''; |
|
669 | + $moment_format = ''; |
|
670 | + $escaping = false; |
|
671 | + $format_string_length = strlen($format_string); |
|
672 | + for ($i = 0; $i < $format_string_length; $i++) { |
|
673 | + $char = $format_string[ $i ]; |
|
674 | + if ($char === '\\') { // PHP date format escaping character |
|
675 | + $i++; |
|
676 | + if ($escaping) { |
|
677 | + $jquery_ui_format .= $format_string[ $i ]; |
|
678 | + $moment_format .= $format_string[ $i ]; |
|
679 | + } else { |
|
680 | + $jquery_ui_format .= '\'' . $format_string[ $i ]; |
|
681 | + $moment_format .= $format_string[ $i ]; |
|
682 | + } |
|
683 | + $escaping = true; |
|
684 | + } else { |
|
685 | + if ($escaping) { |
|
686 | + $jquery_ui_format .= "'"; |
|
687 | + $moment_format .= "'"; |
|
688 | + $escaping = false; |
|
689 | + } |
|
690 | + if (isset($symbols_map[ $char ])) { |
|
691 | + $jquery_ui_format .= $symbols_map[ $char ]['js']; |
|
692 | + $moment_format .= $symbols_map[ $char ]['moment']; |
|
693 | + } else { |
|
694 | + $jquery_ui_format .= $char; |
|
695 | + $moment_format .= $char; |
|
696 | + } |
|
697 | + } |
|
698 | + } |
|
699 | + return array('js' => $jquery_ui_format, 'moment' => $moment_format); |
|
700 | + } |
|
701 | 701 | |
702 | 702 | |
703 | - /** |
|
704 | - * This takes an incoming format string and validates it to ensure it will work fine with PHP. |
|
705 | - * |
|
706 | - * @param string $format_string Incoming format string for php date(). |
|
707 | - * @return mixed bool|array If all is okay then TRUE is returned. Otherwise an array of validation |
|
708 | - * errors is returned. So for client code calling, check for is_array() to |
|
709 | - * indicate failed validations. |
|
710 | - */ |
|
711 | - public static function validate_format_string($format_string) |
|
712 | - { |
|
713 | - $error_msg = array(); |
|
714 | - //time format checks |
|
715 | - switch (true) { |
|
716 | - case strpos($format_string, 'h') !== false : |
|
717 | - case strpos($format_string, 'g') !== false : |
|
718 | - /** |
|
719 | - * if the time string has a lowercase 'h' which == 12 hour time format and there |
|
720 | - * is not any ante meridiem format ('a' or 'A'). Then throw an error because its |
|
721 | - * too ambiguous and PHP won't be able to figure out whether 1 = 1pm or 1am. |
|
722 | - */ |
|
723 | - if (stripos($format_string, 'A') === false) { |
|
724 | - $error_msg[] = esc_html__( |
|
725 | - 'There is a time format for 12 hour time but no "a" or "A" to indicate am/pm. Without this distinction, PHP is unable to determine if a "1" for the hour value equals "1pm" or "1am".', |
|
726 | - 'event_espresso' |
|
727 | - ); |
|
728 | - } |
|
729 | - break; |
|
730 | - } |
|
731 | - return empty($error_msg) ? true : $error_msg; |
|
732 | - } |
|
703 | + /** |
|
704 | + * This takes an incoming format string and validates it to ensure it will work fine with PHP. |
|
705 | + * |
|
706 | + * @param string $format_string Incoming format string for php date(). |
|
707 | + * @return mixed bool|array If all is okay then TRUE is returned. Otherwise an array of validation |
|
708 | + * errors is returned. So for client code calling, check for is_array() to |
|
709 | + * indicate failed validations. |
|
710 | + */ |
|
711 | + public static function validate_format_string($format_string) |
|
712 | + { |
|
713 | + $error_msg = array(); |
|
714 | + //time format checks |
|
715 | + switch (true) { |
|
716 | + case strpos($format_string, 'h') !== false : |
|
717 | + case strpos($format_string, 'g') !== false : |
|
718 | + /** |
|
719 | + * if the time string has a lowercase 'h' which == 12 hour time format and there |
|
720 | + * is not any ante meridiem format ('a' or 'A'). Then throw an error because its |
|
721 | + * too ambiguous and PHP won't be able to figure out whether 1 = 1pm or 1am. |
|
722 | + */ |
|
723 | + if (stripos($format_string, 'A') === false) { |
|
724 | + $error_msg[] = esc_html__( |
|
725 | + 'There is a time format for 12 hour time but no "a" or "A" to indicate am/pm. Without this distinction, PHP is unable to determine if a "1" for the hour value equals "1pm" or "1am".', |
|
726 | + 'event_espresso' |
|
727 | + ); |
|
728 | + } |
|
729 | + break; |
|
730 | + } |
|
731 | + return empty($error_msg) ? true : $error_msg; |
|
732 | + } |
|
733 | 733 | |
734 | 734 | |
735 | - /** |
|
736 | - * If the the first date starts at midnight on one day, and the next date ends at midnight on the |
|
737 | - * very next day then this method will return true. |
|
738 | - * If $date_1 = 2015-12-15 00:00:00 and $date_2 = 2015-12-16 00:00:00 then this function will return true. |
|
739 | - * If $date_1 = 2015-12-15 03:00:00 and $date_2 = 2015-12_16 03:00:00 then this function will return false. |
|
740 | - * If $date_1 = 2015-12-15 00:00:00 and $date_2 = 2015-12-15 00:00:00 then this function will return true. |
|
741 | - * |
|
742 | - * @param mixed $date_1 |
|
743 | - * @param mixed $date_2 |
|
744 | - * @return bool |
|
745 | - */ |
|
746 | - public static function dates_represent_one_24_hour_date($date_1, $date_2) |
|
747 | - { |
|
735 | + /** |
|
736 | + * If the the first date starts at midnight on one day, and the next date ends at midnight on the |
|
737 | + * very next day then this method will return true. |
|
738 | + * If $date_1 = 2015-12-15 00:00:00 and $date_2 = 2015-12-16 00:00:00 then this function will return true. |
|
739 | + * If $date_1 = 2015-12-15 03:00:00 and $date_2 = 2015-12_16 03:00:00 then this function will return false. |
|
740 | + * If $date_1 = 2015-12-15 00:00:00 and $date_2 = 2015-12-15 00:00:00 then this function will return true. |
|
741 | + * |
|
742 | + * @param mixed $date_1 |
|
743 | + * @param mixed $date_2 |
|
744 | + * @return bool |
|
745 | + */ |
|
746 | + public static function dates_represent_one_24_hour_date($date_1, $date_2) |
|
747 | + { |
|
748 | 748 | |
749 | - if ( |
|
750 | - (! $date_1 instanceof DateTime || ! $date_2 instanceof DateTime) |
|
751 | - || ($date_1->format(EE_Datetime_Field::mysql_time_format) !== '00:00:00' |
|
752 | - || $date_2->format( |
|
753 | - EE_Datetime_Field::mysql_time_format |
|
754 | - ) !== '00:00:00') |
|
755 | - ) { |
|
756 | - return false; |
|
757 | - } |
|
758 | - return $date_2->format('U') - $date_1->format('U') === 86400; |
|
759 | - } |
|
749 | + if ( |
|
750 | + (! $date_1 instanceof DateTime || ! $date_2 instanceof DateTime) |
|
751 | + || ($date_1->format(EE_Datetime_Field::mysql_time_format) !== '00:00:00' |
|
752 | + || $date_2->format( |
|
753 | + EE_Datetime_Field::mysql_time_format |
|
754 | + ) !== '00:00:00') |
|
755 | + ) { |
|
756 | + return false; |
|
757 | + } |
|
758 | + return $date_2->format('U') - $date_1->format('U') === 86400; |
|
759 | + } |
|
760 | 760 | |
761 | 761 | |
762 | - /** |
|
763 | - * This returns the appropriate query interval string that can be used in sql queries involving mysql Date |
|
764 | - * Functions. |
|
765 | - * |
|
766 | - * @param string $timezone_string A timezone string in a valid format to instantiate a DateTimeZone object. |
|
767 | - * @param string $field_for_interval The Database field that is the interval is applied to in the query. |
|
768 | - * @return string |
|
769 | - */ |
|
770 | - public static function get_sql_query_interval_for_offset($timezone_string, $field_for_interval) |
|
771 | - { |
|
772 | - try { |
|
773 | - /** need to account for timezone offset on the selects */ |
|
774 | - $DateTimeZone = new DateTimeZone($timezone_string); |
|
775 | - } catch (Exception $e) { |
|
776 | - $DateTimeZone = null; |
|
777 | - } |
|
778 | - /** |
|
779 | - * Note get_option( 'gmt_offset') returns a value in hours, whereas DateTimeZone::getOffset returns values in seconds. |
|
780 | - * Hence we do the calc for DateTimeZone::getOffset. |
|
781 | - */ |
|
782 | - $offset = $DateTimeZone instanceof DateTimeZone |
|
783 | - ? $DateTimeZone->getOffset(new DateTime('now')) / HOUR_IN_SECONDS |
|
784 | - : (float) get_option('gmt_offset'); |
|
785 | - $query_interval = $offset < 0 |
|
786 | - ? 'DATE_SUB(' . $field_for_interval . ', INTERVAL ' . $offset * -1 . ' HOUR)' |
|
787 | - : 'DATE_ADD(' . $field_for_interval . ', INTERVAL ' . $offset . ' HOUR)'; |
|
788 | - return $query_interval; |
|
789 | - } |
|
762 | + /** |
|
763 | + * This returns the appropriate query interval string that can be used in sql queries involving mysql Date |
|
764 | + * Functions. |
|
765 | + * |
|
766 | + * @param string $timezone_string A timezone string in a valid format to instantiate a DateTimeZone object. |
|
767 | + * @param string $field_for_interval The Database field that is the interval is applied to in the query. |
|
768 | + * @return string |
|
769 | + */ |
|
770 | + public static function get_sql_query_interval_for_offset($timezone_string, $field_for_interval) |
|
771 | + { |
|
772 | + try { |
|
773 | + /** need to account for timezone offset on the selects */ |
|
774 | + $DateTimeZone = new DateTimeZone($timezone_string); |
|
775 | + } catch (Exception $e) { |
|
776 | + $DateTimeZone = null; |
|
777 | + } |
|
778 | + /** |
|
779 | + * Note get_option( 'gmt_offset') returns a value in hours, whereas DateTimeZone::getOffset returns values in seconds. |
|
780 | + * Hence we do the calc for DateTimeZone::getOffset. |
|
781 | + */ |
|
782 | + $offset = $DateTimeZone instanceof DateTimeZone |
|
783 | + ? $DateTimeZone->getOffset(new DateTime('now')) / HOUR_IN_SECONDS |
|
784 | + : (float) get_option('gmt_offset'); |
|
785 | + $query_interval = $offset < 0 |
|
786 | + ? 'DATE_SUB(' . $field_for_interval . ', INTERVAL ' . $offset * -1 . ' HOUR)' |
|
787 | + : 'DATE_ADD(' . $field_for_interval . ', INTERVAL ' . $offset . ' HOUR)'; |
|
788 | + return $query_interval; |
|
789 | + } |
|
790 | 790 | |
791 | 791 | |
792 | - /** |
|
793 | - * Retrieves the site's default timezone and returns it formatted so it's ready for display |
|
794 | - * to users. If you want to customize how its displayed feel free to fetch the 'timezone_string' |
|
795 | - * and 'gmt_offset' WordPress options directly; or use the filter |
|
796 | - * FHEE__EEH_DTT_Helper__get_timezone_string_for_display |
|
797 | - * (although note that we remove any HTML that may be added) |
|
798 | - * |
|
799 | - * @return string |
|
800 | - */ |
|
801 | - public static function get_timezone_string_for_display() |
|
802 | - { |
|
803 | - $pretty_timezone = apply_filters('FHEE__EEH_DTT_Helper__get_timezone_string_for_display', ''); |
|
804 | - if (! empty($pretty_timezone)) { |
|
805 | - return esc_html($pretty_timezone); |
|
806 | - } |
|
807 | - $timezone_string = get_option('timezone_string'); |
|
808 | - if ($timezone_string) { |
|
809 | - static $mo_loaded = false; |
|
810 | - // Load translations for continents and cities just like wp_timezone_choice does |
|
811 | - if (! $mo_loaded) { |
|
812 | - $locale = get_locale(); |
|
813 | - $mofile = WP_LANG_DIR . '/continents-cities-' . $locale . '.mo'; |
|
814 | - load_textdomain('continents-cities', $mofile); |
|
815 | - $mo_loaded = true; |
|
816 | - } |
|
817 | - //well that was easy. |
|
818 | - $parts = explode('/', $timezone_string); |
|
819 | - //remove the continent |
|
820 | - unset($parts[0]); |
|
821 | - $t_parts = array(); |
|
822 | - foreach ($parts as $part) { |
|
823 | - $t_parts[] = translate(str_replace('_', ' ', $part), 'continents-cities'); |
|
824 | - } |
|
825 | - return implode(' - ', $t_parts); |
|
826 | - } |
|
827 | - //they haven't set the timezone string, so let's return a string like "UTC+1" |
|
828 | - $gmt_offset = get_option('gmt_offset'); |
|
829 | - $prefix = (int) $gmt_offset >= 0 ? '+' : ''; |
|
830 | - $parts = explode('.', (string) $gmt_offset); |
|
831 | - if (count($parts) === 1) { |
|
832 | - $parts[1] = '00'; |
|
833 | - } else { |
|
834 | - //convert the part after the decimal, eg "5" (from x.5) or "25" (from x.25) |
|
835 | - //to minutes, eg 30 or 15, respectively |
|
836 | - $hour_fraction = (float) ('0.' . $parts[1]); |
|
837 | - $parts[1] = (string) $hour_fraction * 60; |
|
838 | - } |
|
839 | - return sprintf(__('UTC%1$s', 'event_espresso'), $prefix . implode(':', $parts)); |
|
840 | - } |
|
792 | + /** |
|
793 | + * Retrieves the site's default timezone and returns it formatted so it's ready for display |
|
794 | + * to users. If you want to customize how its displayed feel free to fetch the 'timezone_string' |
|
795 | + * and 'gmt_offset' WordPress options directly; or use the filter |
|
796 | + * FHEE__EEH_DTT_Helper__get_timezone_string_for_display |
|
797 | + * (although note that we remove any HTML that may be added) |
|
798 | + * |
|
799 | + * @return string |
|
800 | + */ |
|
801 | + public static function get_timezone_string_for_display() |
|
802 | + { |
|
803 | + $pretty_timezone = apply_filters('FHEE__EEH_DTT_Helper__get_timezone_string_for_display', ''); |
|
804 | + if (! empty($pretty_timezone)) { |
|
805 | + return esc_html($pretty_timezone); |
|
806 | + } |
|
807 | + $timezone_string = get_option('timezone_string'); |
|
808 | + if ($timezone_string) { |
|
809 | + static $mo_loaded = false; |
|
810 | + // Load translations for continents and cities just like wp_timezone_choice does |
|
811 | + if (! $mo_loaded) { |
|
812 | + $locale = get_locale(); |
|
813 | + $mofile = WP_LANG_DIR . '/continents-cities-' . $locale . '.mo'; |
|
814 | + load_textdomain('continents-cities', $mofile); |
|
815 | + $mo_loaded = true; |
|
816 | + } |
|
817 | + //well that was easy. |
|
818 | + $parts = explode('/', $timezone_string); |
|
819 | + //remove the continent |
|
820 | + unset($parts[0]); |
|
821 | + $t_parts = array(); |
|
822 | + foreach ($parts as $part) { |
|
823 | + $t_parts[] = translate(str_replace('_', ' ', $part), 'continents-cities'); |
|
824 | + } |
|
825 | + return implode(' - ', $t_parts); |
|
826 | + } |
|
827 | + //they haven't set the timezone string, so let's return a string like "UTC+1" |
|
828 | + $gmt_offset = get_option('gmt_offset'); |
|
829 | + $prefix = (int) $gmt_offset >= 0 ? '+' : ''; |
|
830 | + $parts = explode('.', (string) $gmt_offset); |
|
831 | + if (count($parts) === 1) { |
|
832 | + $parts[1] = '00'; |
|
833 | + } else { |
|
834 | + //convert the part after the decimal, eg "5" (from x.5) or "25" (from x.25) |
|
835 | + //to minutes, eg 30 or 15, respectively |
|
836 | + $hour_fraction = (float) ('0.' . $parts[1]); |
|
837 | + $parts[1] = (string) $hour_fraction * 60; |
|
838 | + } |
|
839 | + return sprintf(__('UTC%1$s', 'event_espresso'), $prefix . implode(':', $parts)); |
|
840 | + } |
|
841 | 841 | |
842 | 842 | |
843 | 843 | |
844 | - /** |
|
845 | - * So PHP does this awesome thing where if you are trying to get a timestamp |
|
846 | - * for a month using a string like "February" or "February 2017", |
|
847 | - * and you don't specify a day as part of your string, |
|
848 | - * then PHP will use whatever the current day of the month is. |
|
849 | - * IF the current day of the month happens to be the 30th or 31st, |
|
850 | - * then PHP gets really confused by a date like February 30, |
|
851 | - * so instead of saying |
|
852 | - * "Hey February only has 28 days (this year)... |
|
853 | - * ...you must have meant the last day of the month!" |
|
854 | - * PHP does the next most logical thing, and bumps the date up to March 2nd, |
|
855 | - * because someone requesting February 30th obviously meant March 1st! |
|
856 | - * The way around this is to always set the day to the first, |
|
857 | - * so that the month will stay on the month you wanted. |
|
858 | - * this method will add that "1" into your date regardless of the format. |
|
859 | - * |
|
860 | - * @param string $month |
|
861 | - * @return string |
|
862 | - */ |
|
863 | - public static function first_of_month_timestamp($month = '') |
|
864 | - { |
|
865 | - $month = (string) $month; |
|
866 | - $year = ''; |
|
867 | - // check if the incoming string has a year in it or not |
|
868 | - if (preg_match('/\b\d{4}\b/', $month, $matches)) { |
|
869 | - $year = $matches[0]; |
|
870 | - // ten remove that from the month string as well as any spaces |
|
871 | - $month = trim(str_replace($year, '', $month)); |
|
872 | - // add a space before the year |
|
873 | - $year = " {$year}"; |
|
874 | - } |
|
875 | - // return timestamp for something like "February 1 2017" |
|
876 | - return strtotime("{$month} 1{$year}"); |
|
877 | - } |
|
844 | + /** |
|
845 | + * So PHP does this awesome thing where if you are trying to get a timestamp |
|
846 | + * for a month using a string like "February" or "February 2017", |
|
847 | + * and you don't specify a day as part of your string, |
|
848 | + * then PHP will use whatever the current day of the month is. |
|
849 | + * IF the current day of the month happens to be the 30th or 31st, |
|
850 | + * then PHP gets really confused by a date like February 30, |
|
851 | + * so instead of saying |
|
852 | + * "Hey February only has 28 days (this year)... |
|
853 | + * ...you must have meant the last day of the month!" |
|
854 | + * PHP does the next most logical thing, and bumps the date up to March 2nd, |
|
855 | + * because someone requesting February 30th obviously meant March 1st! |
|
856 | + * The way around this is to always set the day to the first, |
|
857 | + * so that the month will stay on the month you wanted. |
|
858 | + * this method will add that "1" into your date regardless of the format. |
|
859 | + * |
|
860 | + * @param string $month |
|
861 | + * @return string |
|
862 | + */ |
|
863 | + public static function first_of_month_timestamp($month = '') |
|
864 | + { |
|
865 | + $month = (string) $month; |
|
866 | + $year = ''; |
|
867 | + // check if the incoming string has a year in it or not |
|
868 | + if (preg_match('/\b\d{4}\b/', $month, $matches)) { |
|
869 | + $year = $matches[0]; |
|
870 | + // ten remove that from the month string as well as any spaces |
|
871 | + $month = trim(str_replace($year, '', $month)); |
|
872 | + // add a space before the year |
|
873 | + $year = " {$year}"; |
|
874 | + } |
|
875 | + // return timestamp for something like "February 1 2017" |
|
876 | + return strtotime("{$month} 1{$year}"); |
|
877 | + } |
|
878 | 878 | |
879 | 879 | |
880 | - /** |
|
881 | - * This simply returns the timestamp for tomorrow (midnight next day) in this sites timezone. So it may be midnight |
|
882 | - * for this sites timezone, but the timestamp could be some other time GMT. |
|
883 | - */ |
|
884 | - public static function tomorrow() |
|
885 | - { |
|
886 | - //The multiplication of -1 ensures that we switch positive offsets to negative and negative offsets to positive |
|
887 | - //before adding to the timestamp. Why? Because we want tomorrow to be for midnight the next day in THIS timezone |
|
888 | - //not an offset from midnight in UTC. So if we're starting with UTC 00:00:00, then we want to make sure the |
|
889 | - //final timestamp is equivalent to midnight in this timezone as represented in GMT. |
|
890 | - return strtotime('tomorrow') + (self::get_site_timezone_gmt_offset() * -1); |
|
891 | - } |
|
880 | + /** |
|
881 | + * This simply returns the timestamp for tomorrow (midnight next day) in this sites timezone. So it may be midnight |
|
882 | + * for this sites timezone, but the timestamp could be some other time GMT. |
|
883 | + */ |
|
884 | + public static function tomorrow() |
|
885 | + { |
|
886 | + //The multiplication of -1 ensures that we switch positive offsets to negative and negative offsets to positive |
|
887 | + //before adding to the timestamp. Why? Because we want tomorrow to be for midnight the next day in THIS timezone |
|
888 | + //not an offset from midnight in UTC. So if we're starting with UTC 00:00:00, then we want to make sure the |
|
889 | + //final timestamp is equivalent to midnight in this timezone as represented in GMT. |
|
890 | + return strtotime('tomorrow') + (self::get_site_timezone_gmt_offset() * -1); |
|
891 | + } |
|
892 | 892 | |
893 | 893 | |
894 | - /** |
|
895 | - * ** |
|
896 | - * Gives a nicely-formatted list of timezone strings. |
|
897 | - * Copied from the core wp function by the same name so we could customize to remove UTC offsets. |
|
898 | - * |
|
899 | - * @since 4.9.40.rc.008 |
|
900 | - * @staticvar bool $mo_loaded |
|
901 | - * @staticvar string $locale_loaded |
|
902 | - * @param string $selected_zone Selected timezone. |
|
903 | - * @param string $locale Optional. Locale to load the timezones in. Default current site locale. |
|
904 | - * @return string |
|
905 | - */ |
|
906 | - public static function wp_timezone_choice($selected_zone, $locale = null) |
|
907 | - { |
|
908 | - static $mo_loaded = false, $locale_loaded = null; |
|
909 | - $continents = array( |
|
910 | - 'Africa', |
|
911 | - 'America', |
|
912 | - 'Antarctica', |
|
913 | - 'Arctic', |
|
914 | - 'Asia', |
|
915 | - 'Atlantic', |
|
916 | - 'Australia', |
|
917 | - 'Europe', |
|
918 | - 'Indian', |
|
919 | - 'Pacific', |
|
920 | - ); |
|
921 | - // Load translations for continents and cities. |
|
922 | - if (! $mo_loaded || $locale !== $locale_loaded) { |
|
923 | - $locale_loaded = $locale ? $locale : get_locale(); |
|
924 | - $mofile = WP_LANG_DIR . '/continents-cities-' . $locale_loaded . '.mo'; |
|
925 | - unload_textdomain('continents-cities'); |
|
926 | - load_textdomain('continents-cities', $mofile); |
|
927 | - $mo_loaded = true; |
|
928 | - } |
|
929 | - $zone_data = array(); |
|
930 | - foreach (timezone_identifiers_list() as $zone) { |
|
931 | - $zone = explode('/', $zone); |
|
932 | - if (! in_array($zone[0], $continents, true)) { |
|
933 | - continue; |
|
934 | - } |
|
935 | - // This determines what gets set and translated - we don't translate Etc/* strings here, they are done later |
|
936 | - $exists = array( |
|
937 | - 0 => isset($zone[0]) && $zone[0], |
|
938 | - 1 => isset($zone[1]) && $zone[1], |
|
939 | - 2 => isset($zone[2]) && $zone[2], |
|
940 | - ); |
|
941 | - $exists[3] = $exists[0] && $zone[0] !== 'Etc'; |
|
942 | - $exists[4] = $exists[1] && $exists[3]; |
|
943 | - $exists[5] = $exists[2] && $exists[3]; |
|
944 | - $zone_data[] = array( |
|
945 | - 'continent' => $exists[0] ? $zone[0] : '', |
|
946 | - 'city' => $exists[1] ? $zone[1] : '', |
|
947 | - 'subcity' => $exists[2] ? $zone[2] : '', |
|
948 | - 't_continent' => $exists[3] |
|
949 | - ? translate(str_replace('_', ' ', $zone[0]), 'continents-cities') |
|
950 | - : '', |
|
951 | - 't_city' => $exists[4] |
|
952 | - ? translate(str_replace('_', ' ', $zone[1]), 'continents-cities') |
|
953 | - : '', |
|
954 | - 't_subcity' => $exists[5] |
|
955 | - ? translate(str_replace('_', ' ', $zone[2]), 'continents-cities') |
|
956 | - : '', |
|
957 | - ); |
|
958 | - } |
|
959 | - usort($zone_data, '_wp_timezone_choice_usort_callback'); |
|
960 | - $structure = array(); |
|
961 | - if (empty($selected_zone)) { |
|
962 | - $structure[] = '<option selected="selected" value="">' . __('Select a city') . '</option>'; |
|
963 | - } |
|
964 | - foreach ($zone_data as $key => $zone) { |
|
965 | - // Build value in an array to join later |
|
966 | - $value = array($zone['continent']); |
|
967 | - if (empty($zone['city'])) { |
|
968 | - // It's at the continent level (generally won't happen) |
|
969 | - $display = $zone['t_continent']; |
|
970 | - } else { |
|
971 | - // It's inside a continent group |
|
972 | - // Continent optgroup |
|
973 | - if (! isset($zone_data[ $key - 1 ]) || $zone_data[ $key - 1 ]['continent'] !== $zone['continent']) { |
|
974 | - $label = $zone['t_continent']; |
|
975 | - $structure[] = '<optgroup label="' . esc_attr($label) . '">'; |
|
976 | - } |
|
977 | - // Add the city to the value |
|
978 | - $value[] = $zone['city']; |
|
979 | - $display = $zone['t_city']; |
|
980 | - if (! empty($zone['subcity'])) { |
|
981 | - // Add the subcity to the value |
|
982 | - $value[] = $zone['subcity']; |
|
983 | - $display .= ' - ' . $zone['t_subcity']; |
|
984 | - } |
|
985 | - } |
|
986 | - // Build the value |
|
987 | - $value = implode('/', $value); |
|
988 | - $selected = $value === $selected_zone ? ' selected="selected"' : ''; |
|
989 | - $structure[] = '<option value="' . esc_attr($value) . '"' . $selected . '>' |
|
990 | - . esc_html($display) |
|
991 | - . '</option>'; |
|
992 | - // Close continent optgroup |
|
993 | - if (! empty($zone['city']) |
|
994 | - && ( |
|
995 | - ! isset($zone_data[ $key + 1 ]) |
|
996 | - || (isset($zone_data[ $key + 1 ]) && $zone_data[ $key + 1 ]['continent'] !== $zone['continent']) |
|
997 | - ) |
|
998 | - ) { |
|
999 | - $structure[] = '</optgroup>'; |
|
1000 | - } |
|
1001 | - } |
|
1002 | - return implode("\n", $structure); |
|
1003 | - } |
|
894 | + /** |
|
895 | + * ** |
|
896 | + * Gives a nicely-formatted list of timezone strings. |
|
897 | + * Copied from the core wp function by the same name so we could customize to remove UTC offsets. |
|
898 | + * |
|
899 | + * @since 4.9.40.rc.008 |
|
900 | + * @staticvar bool $mo_loaded |
|
901 | + * @staticvar string $locale_loaded |
|
902 | + * @param string $selected_zone Selected timezone. |
|
903 | + * @param string $locale Optional. Locale to load the timezones in. Default current site locale. |
|
904 | + * @return string |
|
905 | + */ |
|
906 | + public static function wp_timezone_choice($selected_zone, $locale = null) |
|
907 | + { |
|
908 | + static $mo_loaded = false, $locale_loaded = null; |
|
909 | + $continents = array( |
|
910 | + 'Africa', |
|
911 | + 'America', |
|
912 | + 'Antarctica', |
|
913 | + 'Arctic', |
|
914 | + 'Asia', |
|
915 | + 'Atlantic', |
|
916 | + 'Australia', |
|
917 | + 'Europe', |
|
918 | + 'Indian', |
|
919 | + 'Pacific', |
|
920 | + ); |
|
921 | + // Load translations for continents and cities. |
|
922 | + if (! $mo_loaded || $locale !== $locale_loaded) { |
|
923 | + $locale_loaded = $locale ? $locale : get_locale(); |
|
924 | + $mofile = WP_LANG_DIR . '/continents-cities-' . $locale_loaded . '.mo'; |
|
925 | + unload_textdomain('continents-cities'); |
|
926 | + load_textdomain('continents-cities', $mofile); |
|
927 | + $mo_loaded = true; |
|
928 | + } |
|
929 | + $zone_data = array(); |
|
930 | + foreach (timezone_identifiers_list() as $zone) { |
|
931 | + $zone = explode('/', $zone); |
|
932 | + if (! in_array($zone[0], $continents, true)) { |
|
933 | + continue; |
|
934 | + } |
|
935 | + // This determines what gets set and translated - we don't translate Etc/* strings here, they are done later |
|
936 | + $exists = array( |
|
937 | + 0 => isset($zone[0]) && $zone[0], |
|
938 | + 1 => isset($zone[1]) && $zone[1], |
|
939 | + 2 => isset($zone[2]) && $zone[2], |
|
940 | + ); |
|
941 | + $exists[3] = $exists[0] && $zone[0] !== 'Etc'; |
|
942 | + $exists[4] = $exists[1] && $exists[3]; |
|
943 | + $exists[5] = $exists[2] && $exists[3]; |
|
944 | + $zone_data[] = array( |
|
945 | + 'continent' => $exists[0] ? $zone[0] : '', |
|
946 | + 'city' => $exists[1] ? $zone[1] : '', |
|
947 | + 'subcity' => $exists[2] ? $zone[2] : '', |
|
948 | + 't_continent' => $exists[3] |
|
949 | + ? translate(str_replace('_', ' ', $zone[0]), 'continents-cities') |
|
950 | + : '', |
|
951 | + 't_city' => $exists[4] |
|
952 | + ? translate(str_replace('_', ' ', $zone[1]), 'continents-cities') |
|
953 | + : '', |
|
954 | + 't_subcity' => $exists[5] |
|
955 | + ? translate(str_replace('_', ' ', $zone[2]), 'continents-cities') |
|
956 | + : '', |
|
957 | + ); |
|
958 | + } |
|
959 | + usort($zone_data, '_wp_timezone_choice_usort_callback'); |
|
960 | + $structure = array(); |
|
961 | + if (empty($selected_zone)) { |
|
962 | + $structure[] = '<option selected="selected" value="">' . __('Select a city') . '</option>'; |
|
963 | + } |
|
964 | + foreach ($zone_data as $key => $zone) { |
|
965 | + // Build value in an array to join later |
|
966 | + $value = array($zone['continent']); |
|
967 | + if (empty($zone['city'])) { |
|
968 | + // It's at the continent level (generally won't happen) |
|
969 | + $display = $zone['t_continent']; |
|
970 | + } else { |
|
971 | + // It's inside a continent group |
|
972 | + // Continent optgroup |
|
973 | + if (! isset($zone_data[ $key - 1 ]) || $zone_data[ $key - 1 ]['continent'] !== $zone['continent']) { |
|
974 | + $label = $zone['t_continent']; |
|
975 | + $structure[] = '<optgroup label="' . esc_attr($label) . '">'; |
|
976 | + } |
|
977 | + // Add the city to the value |
|
978 | + $value[] = $zone['city']; |
|
979 | + $display = $zone['t_city']; |
|
980 | + if (! empty($zone['subcity'])) { |
|
981 | + // Add the subcity to the value |
|
982 | + $value[] = $zone['subcity']; |
|
983 | + $display .= ' - ' . $zone['t_subcity']; |
|
984 | + } |
|
985 | + } |
|
986 | + // Build the value |
|
987 | + $value = implode('/', $value); |
|
988 | + $selected = $value === $selected_zone ? ' selected="selected"' : ''; |
|
989 | + $structure[] = '<option value="' . esc_attr($value) . '"' . $selected . '>' |
|
990 | + . esc_html($display) |
|
991 | + . '</option>'; |
|
992 | + // Close continent optgroup |
|
993 | + if (! empty($zone['city']) |
|
994 | + && ( |
|
995 | + ! isset($zone_data[ $key + 1 ]) |
|
996 | + || (isset($zone_data[ $key + 1 ]) && $zone_data[ $key + 1 ]['continent'] !== $zone['continent']) |
|
997 | + ) |
|
998 | + ) { |
|
999 | + $structure[] = '</optgroup>'; |
|
1000 | + } |
|
1001 | + } |
|
1002 | + return implode("\n", $structure); |
|
1003 | + } |
|
1004 | 1004 | |
1005 | 1005 | |
1006 | - /** |
|
1007 | - * Shim for the WP function `get_user_locale` that was added in WordPress 4.7.0 |
|
1008 | - * |
|
1009 | - * @param int|WP_User $user_id |
|
1010 | - * @return string |
|
1011 | - */ |
|
1012 | - public static function get_user_locale($user_id = 0) |
|
1013 | - { |
|
1014 | - if (function_exists('get_user_locale')) { |
|
1015 | - return get_user_locale($user_id); |
|
1016 | - } |
|
1017 | - return get_locale(); |
|
1018 | - } |
|
1006 | + /** |
|
1007 | + * Shim for the WP function `get_user_locale` that was added in WordPress 4.7.0 |
|
1008 | + * |
|
1009 | + * @param int|WP_User $user_id |
|
1010 | + * @return string |
|
1011 | + */ |
|
1012 | + public static function get_user_locale($user_id = 0) |
|
1013 | + { |
|
1014 | + if (function_exists('get_user_locale')) { |
|
1015 | + return get_user_locale($user_id); |
|
1016 | + } |
|
1017 | + return get_locale(); |
|
1018 | + } |
|
1019 | 1019 | |
1020 | 1020 | |
1021 | - /** |
|
1022 | - * Return the appropriate helper adapter for DTT related things. |
|
1023 | - * |
|
1024 | - * @return HelperInterface |
|
1025 | - * @throws InvalidArgumentException |
|
1026 | - * @throws InvalidDataTypeException |
|
1027 | - * @throws InvalidInterfaceException |
|
1028 | - */ |
|
1029 | - private static function getHelperAdapter() { |
|
1030 | - $dtt_helper_fqcn = PHP_VERSION_ID < 50600 |
|
1031 | - ? 'EventEspresso\core\services\helpers\datetime\PhpCompatLessFiveSixHelper' |
|
1032 | - : 'EventEspresso\core\services\helpers\datetime\PhpCompatGreaterFiveSixHelper'; |
|
1033 | - return LoaderFactory::getLoader()->getShared($dtt_helper_fqcn); |
|
1034 | - } |
|
1021 | + /** |
|
1022 | + * Return the appropriate helper adapter for DTT related things. |
|
1023 | + * |
|
1024 | + * @return HelperInterface |
|
1025 | + * @throws InvalidArgumentException |
|
1026 | + * @throws InvalidDataTypeException |
|
1027 | + * @throws InvalidInterfaceException |
|
1028 | + */ |
|
1029 | + private static function getHelperAdapter() { |
|
1030 | + $dtt_helper_fqcn = PHP_VERSION_ID < 50600 |
|
1031 | + ? 'EventEspresso\core\services\helpers\datetime\PhpCompatLessFiveSixHelper' |
|
1032 | + : 'EventEspresso\core\services\helpers\datetime\PhpCompatGreaterFiveSixHelper'; |
|
1033 | + return LoaderFactory::getLoader()->getShared($dtt_helper_fqcn); |
|
1034 | + } |
|
1035 | 1035 | } |
1036 | 1036 | \ No newline at end of file |
@@ -45,8 +45,8 @@ |
||
45 | 45 | } |
46 | 46 | } |
47 | 47 | } |
48 | - return true; |
|
49 | - } |
|
48 | + return true; |
|
49 | + } |
|
50 | 50 | |
51 | 51 | |
52 | 52 |