@@ -129,54 +129,54 @@ discard block |
||
129 | 129 | define('EE_PLUGIN_DIR_PATH', plugin_dir_path(EVENT_ESPRESSO_MAIN_FILE)); |
130 | 130 | define('EE_PLUGIN_DIR_URL', plugin_dir_url(EVENT_ESPRESSO_MAIN_FILE)); |
131 | 131 | // main root folder paths |
132 | - define('EE_ADMIN_PAGES', EE_PLUGIN_DIR_PATH . 'admin_pages' . DS); |
|
133 | - define('EE_CORE', EE_PLUGIN_DIR_PATH . 'core' . DS); |
|
134 | - define('EE_MODULES', EE_PLUGIN_DIR_PATH . 'modules' . DS); |
|
135 | - define('EE_PUBLIC', EE_PLUGIN_DIR_PATH . 'public' . DS); |
|
136 | - define('EE_SHORTCODES', EE_PLUGIN_DIR_PATH . 'shortcodes' . DS); |
|
137 | - define('EE_WIDGETS', EE_PLUGIN_DIR_PATH . 'widgets' . DS); |
|
138 | - define('EE_PAYMENT_METHODS', EE_PLUGIN_DIR_PATH . 'payment_methods' . DS); |
|
139 | - define('EE_CAFF_PATH', EE_PLUGIN_DIR_PATH . 'caffeinated' . DS); |
|
132 | + define('EE_ADMIN_PAGES', EE_PLUGIN_DIR_PATH.'admin_pages'.DS); |
|
133 | + define('EE_CORE', EE_PLUGIN_DIR_PATH.'core'.DS); |
|
134 | + define('EE_MODULES', EE_PLUGIN_DIR_PATH.'modules'.DS); |
|
135 | + define('EE_PUBLIC', EE_PLUGIN_DIR_PATH.'public'.DS); |
|
136 | + define('EE_SHORTCODES', EE_PLUGIN_DIR_PATH.'shortcodes'.DS); |
|
137 | + define('EE_WIDGETS', EE_PLUGIN_DIR_PATH.'widgets'.DS); |
|
138 | + define('EE_PAYMENT_METHODS', EE_PLUGIN_DIR_PATH.'payment_methods'.DS); |
|
139 | + define('EE_CAFF_PATH', EE_PLUGIN_DIR_PATH.'caffeinated'.DS); |
|
140 | 140 | // core system paths |
141 | - define('EE_ADMIN', EE_CORE . 'admin' . DS); |
|
142 | - define('EE_CPTS', EE_CORE . 'CPTs' . DS); |
|
143 | - define('EE_CLASSES', EE_CORE . 'db_classes' . DS); |
|
144 | - define('EE_INTERFACES', EE_CORE . 'interfaces' . DS); |
|
145 | - define('EE_BUSINESS', EE_CORE . 'business' . DS); |
|
146 | - define('EE_MODELS', EE_CORE . 'db_models' . DS); |
|
147 | - define('EE_HELPERS', EE_CORE . 'helpers' . DS); |
|
148 | - define('EE_LIBRARIES', EE_CORE . 'libraries' . DS); |
|
149 | - define('EE_TEMPLATES', EE_CORE . 'templates' . DS); |
|
150 | - define('EE_THIRD_PARTY', EE_CORE . 'third_party_libs' . DS); |
|
151 | - define('EE_GLOBAL_ASSETS', EE_TEMPLATES . 'global_assets' . DS); |
|
152 | - define('EE_FORM_SECTIONS', EE_LIBRARIES . 'form_sections' . DS); |
|
141 | + define('EE_ADMIN', EE_CORE.'admin'.DS); |
|
142 | + define('EE_CPTS', EE_CORE.'CPTs'.DS); |
|
143 | + define('EE_CLASSES', EE_CORE.'db_classes'.DS); |
|
144 | + define('EE_INTERFACES', EE_CORE.'interfaces'.DS); |
|
145 | + define('EE_BUSINESS', EE_CORE.'business'.DS); |
|
146 | + define('EE_MODELS', EE_CORE.'db_models'.DS); |
|
147 | + define('EE_HELPERS', EE_CORE.'helpers'.DS); |
|
148 | + define('EE_LIBRARIES', EE_CORE.'libraries'.DS); |
|
149 | + define('EE_TEMPLATES', EE_CORE.'templates'.DS); |
|
150 | + define('EE_THIRD_PARTY', EE_CORE.'third_party_libs'.DS); |
|
151 | + define('EE_GLOBAL_ASSETS', EE_TEMPLATES.'global_assets'.DS); |
|
152 | + define('EE_FORM_SECTIONS', EE_LIBRARIES.'form_sections'.DS); |
|
153 | 153 | // gateways |
154 | - define('EE_GATEWAYS', EE_MODULES . 'gateways' . DS); |
|
155 | - define('EE_GATEWAYS_URL', EE_PLUGIN_DIR_URL . 'modules' . DS . 'gateways' . DS); |
|
154 | + define('EE_GATEWAYS', EE_MODULES.'gateways'.DS); |
|
155 | + define('EE_GATEWAYS_URL', EE_PLUGIN_DIR_URL.'modules'.DS.'gateways'.DS); |
|
156 | 156 | // asset URL paths |
157 | - define('EE_TEMPLATES_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'templates' . DS); |
|
158 | - define('EE_GLOBAL_ASSETS_URL', EE_TEMPLATES_URL . 'global_assets' . DS); |
|
159 | - define('EE_IMAGES_URL', EE_GLOBAL_ASSETS_URL . 'images' . DS); |
|
160 | - define('EE_THIRD_PARTY_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'third_party_libs' . DS); |
|
161 | - define('EE_HELPERS_ASSETS', EE_PLUGIN_DIR_URL . 'core/helpers/assets/'); |
|
162 | - define('EE_LIBRARIES_URL', EE_PLUGIN_DIR_URL . 'core/libraries/'); |
|
157 | + define('EE_TEMPLATES_URL', EE_PLUGIN_DIR_URL.'core'.DS.'templates'.DS); |
|
158 | + define('EE_GLOBAL_ASSETS_URL', EE_TEMPLATES_URL.'global_assets'.DS); |
|
159 | + define('EE_IMAGES_URL', EE_GLOBAL_ASSETS_URL.'images'.DS); |
|
160 | + define('EE_THIRD_PARTY_URL', EE_PLUGIN_DIR_URL.'core'.DS.'third_party_libs'.DS); |
|
161 | + define('EE_HELPERS_ASSETS', EE_PLUGIN_DIR_URL.'core/helpers/assets/'); |
|
162 | + define('EE_LIBRARIES_URL', EE_PLUGIN_DIR_URL.'core/libraries/'); |
|
163 | 163 | // define upload paths |
164 | 164 | $uploads = wp_upload_dir(); |
165 | 165 | // define the uploads directory and URL |
166 | - define('EVENT_ESPRESSO_UPLOAD_DIR', $uploads['basedir'] . DS . 'espresso' . DS); |
|
167 | - define('EVENT_ESPRESSO_UPLOAD_URL', $uploads['baseurl'] . DS . 'espresso' . DS); |
|
166 | + define('EVENT_ESPRESSO_UPLOAD_DIR', $uploads['basedir'].DS.'espresso'.DS); |
|
167 | + define('EVENT_ESPRESSO_UPLOAD_URL', $uploads['baseurl'].DS.'espresso'.DS); |
|
168 | 168 | // define the templates directory and URL |
169 | - define('EVENT_ESPRESSO_TEMPLATE_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'templates' . DS); |
|
170 | - define('EVENT_ESPRESSO_TEMPLATE_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'templates' . DS); |
|
169 | + define('EVENT_ESPRESSO_TEMPLATE_DIR', $uploads['basedir'].DS.'espresso'.DS.'templates'.DS); |
|
170 | + define('EVENT_ESPRESSO_TEMPLATE_URL', $uploads['baseurl'].DS.'espresso'.DS.'templates'.DS); |
|
171 | 171 | // define the gateway directory and URL |
172 | - define('EVENT_ESPRESSO_GATEWAY_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'gateways' . DS); |
|
173 | - define('EVENT_ESPRESSO_GATEWAY_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'gateways' . DS); |
|
172 | + define('EVENT_ESPRESSO_GATEWAY_DIR', $uploads['basedir'].DS.'espresso'.DS.'gateways'.DS); |
|
173 | + define('EVENT_ESPRESSO_GATEWAY_URL', $uploads['baseurl'].DS.'espresso'.DS.'gateways'.DS); |
|
174 | 174 | // languages folder/path |
175 | - define('EE_LANGUAGES_SAFE_LOC', '..' . DS . 'uploads' . DS . 'espresso' . DS . 'languages' . DS); |
|
176 | - define('EE_LANGUAGES_SAFE_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'languages' . DS); |
|
175 | + define('EE_LANGUAGES_SAFE_LOC', '..'.DS.'uploads'.DS.'espresso'.DS.'languages'.DS); |
|
176 | + define('EE_LANGUAGES_SAFE_DIR', EVENT_ESPRESSO_UPLOAD_DIR.'languages'.DS); |
|
177 | 177 | //check for dompdf fonts in uploads |
178 | - if (file_exists(EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS)) { |
|
179 | - define('DOMPDF_FONT_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS); |
|
178 | + if (file_exists(EVENT_ESPRESSO_UPLOAD_DIR.'fonts'.DS)) { |
|
179 | + define('DOMPDF_FONT_DIR', EVENT_ESPRESSO_UPLOAD_DIR.'fonts'.DS); |
|
180 | 180 | } |
181 | 181 | //ajax constants |
182 | 182 | define( |
@@ -191,7 +191,7 @@ discard block |
||
191 | 191 | //you're better to use this than its straight value (currently -1) in case you ever |
192 | 192 | //want to change its default value! or find when -1 means infinity |
193 | 193 | define('EE_INF_IN_DB', -1); |
194 | - define('EE_INF', INF > (float)PHP_INT_MAX ? INF : PHP_INT_MAX); |
|
194 | + define('EE_INF', INF > (float) PHP_INT_MAX ? INF : PHP_INT_MAX); |
|
195 | 195 | define('EE_DEBUG', false); |
196 | 196 | // for older WP versions |
197 | 197 | if ( ! defined('MONTH_IN_SECONDS')) { |
@@ -214,13 +214,13 @@ discard block |
||
214 | 214 | function espresso_load_error_handling() |
215 | 215 | { |
216 | 216 | // load debugging tools |
217 | - if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) { |
|
218 | - require_once(EE_HELPERS . 'EEH_Debug_Tools.helper.php'); |
|
217 | + if (WP_DEBUG === true && is_readable(EE_HELPERS.'EEH_Debug_Tools.helper.php')) { |
|
218 | + require_once(EE_HELPERS.'EEH_Debug_Tools.helper.php'); |
|
219 | 219 | EEH_Debug_Tools::instance(); |
220 | 220 | } |
221 | 221 | // load error handling |
222 | - if (is_readable(EE_CORE . 'EE_Error.core.php')) { |
|
223 | - require_once(EE_CORE . 'EE_Error.core.php'); |
|
222 | + if (is_readable(EE_CORE.'EE_Error.core.php')) { |
|
223 | + require_once(EE_CORE.'EE_Error.core.php'); |
|
224 | 224 | } else { |
225 | 225 | wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso')); |
226 | 226 | } |
@@ -244,7 +244,7 @@ discard block |
||
244 | 244 | if (is_readable($full_path_to_file)) { |
245 | 245 | require_once($full_path_to_file); |
246 | 246 | } else { |
247 | - throw new EE_Error ( |
|
247 | + throw new EE_Error( |
|
248 | 248 | sprintf( |
249 | 249 | esc_html__( |
250 | 250 | 'The %s class file could not be located or is not readable due to file permissions.', |
@@ -256,9 +256,9 @@ discard block |
||
256 | 256 | } |
257 | 257 | } |
258 | 258 | |
259 | - espresso_load_required('EEH_Base', EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php'); |
|
260 | - espresso_load_required('EEH_File', EE_CORE . 'helpers' . DS . 'EEH_File.helper.php'); |
|
261 | - espresso_load_required('EE_Bootstrap', EE_CORE . 'EE_Bootstrap.core.php'); |
|
259 | + espresso_load_required('EEH_Base', EE_CORE.'helpers'.DS.'EEH_Base.helper.php'); |
|
260 | + espresso_load_required('EEH_File', EE_CORE.'helpers'.DS.'EEH_File.helper.php'); |
|
261 | + espresso_load_required('EE_Bootstrap', EE_CORE.'EE_Bootstrap.core.php'); |
|
262 | 262 | new EE_Bootstrap(); |
263 | 263 | } |
264 | 264 | } |
@@ -274,7 +274,7 @@ discard block |
||
274 | 274 | function espresso_deactivate_plugin($plugin_basename = '') |
275 | 275 | { |
276 | 276 | if ( ! function_exists('deactivate_plugins')) { |
277 | - require_once(ABSPATH . 'wp-admin/includes/plugin.php'); |
|
277 | + require_once(ABSPATH.'wp-admin/includes/plugin.php'); |
|
278 | 278 | } |
279 | 279 | unset($_GET['activate'], $_REQUEST['activate']); |
280 | 280 | deactivate_plugins($plugin_basename); |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php if ( ! defined('ABSPATH')) { |
2 | - exit('No direct script access allowed'); |
|
2 | + exit('No direct script access allowed'); |
|
3 | 3 | } |
4 | 4 | /* |
5 | 5 | Plugin Name: Event Espresso |
@@ -40,243 +40,243 @@ discard block |
||
40 | 40 | * @since 4.0 |
41 | 41 | */ |
42 | 42 | if (function_exists('espresso_version')) { |
43 | - /** |
|
44 | - * espresso_duplicate_plugin_error |
|
45 | - * displays if more than one version of EE is activated at the same time |
|
46 | - */ |
|
47 | - function espresso_duplicate_plugin_error() |
|
48 | - { |
|
49 | - ?> |
|
43 | + /** |
|
44 | + * espresso_duplicate_plugin_error |
|
45 | + * displays if more than one version of EE is activated at the same time |
|
46 | + */ |
|
47 | + function espresso_duplicate_plugin_error() |
|
48 | + { |
|
49 | + ?> |
|
50 | 50 | <div class="error"> |
51 | 51 | <p> |
52 | 52 | <?php echo esc_html__( |
53 | - 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
54 | - 'event_espresso' |
|
55 | - ); ?> |
|
53 | + 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
54 | + 'event_espresso' |
|
55 | + ); ?> |
|
56 | 56 | </p> |
57 | 57 | </div> |
58 | 58 | <?php |
59 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
60 | - } |
|
59 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
60 | + } |
|
61 | 61 | |
62 | - add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
62 | + add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
63 | 63 | } else { |
64 | - define('EE_MIN_PHP_VER_REQUIRED', '5.3.9'); |
|
65 | - if ( ! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
66 | - /** |
|
67 | - * espresso_minimum_php_version_error |
|
68 | - * |
|
69 | - * @return void |
|
70 | - */ |
|
71 | - function espresso_minimum_php_version_error() |
|
72 | - { |
|
73 | - ?> |
|
64 | + define('EE_MIN_PHP_VER_REQUIRED', '5.3.9'); |
|
65 | + if ( ! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
66 | + /** |
|
67 | + * espresso_minimum_php_version_error |
|
68 | + * |
|
69 | + * @return void |
|
70 | + */ |
|
71 | + function espresso_minimum_php_version_error() |
|
72 | + { |
|
73 | + ?> |
|
74 | 74 | <div class="error"> |
75 | 75 | <p> |
76 | 76 | <?php |
77 | - printf( |
|
78 | - esc_html__( |
|
79 | - 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
80 | - 'event_espresso' |
|
81 | - ), |
|
82 | - EE_MIN_PHP_VER_REQUIRED, |
|
83 | - PHP_VERSION, |
|
84 | - '<br/>', |
|
85 | - '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
86 | - ); |
|
87 | - ?> |
|
77 | + printf( |
|
78 | + esc_html__( |
|
79 | + 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
80 | + 'event_espresso' |
|
81 | + ), |
|
82 | + EE_MIN_PHP_VER_REQUIRED, |
|
83 | + PHP_VERSION, |
|
84 | + '<br/>', |
|
85 | + '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
86 | + ); |
|
87 | + ?> |
|
88 | 88 | </p> |
89 | 89 | </div> |
90 | 90 | <?php |
91 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
92 | - } |
|
91 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
92 | + } |
|
93 | 93 | |
94 | - add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
95 | - } else { |
|
96 | - /** |
|
97 | - * espresso_version |
|
98 | - * Returns the plugin version |
|
99 | - * |
|
100 | - * @return string |
|
101 | - */ |
|
102 | - function espresso_version() |
|
103 | - { |
|
104 | - return apply_filters('FHEE__espresso__espresso_version', '4.9.29.rc.003'); |
|
105 | - } |
|
94 | + add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
95 | + } else { |
|
96 | + /** |
|
97 | + * espresso_version |
|
98 | + * Returns the plugin version |
|
99 | + * |
|
100 | + * @return string |
|
101 | + */ |
|
102 | + function espresso_version() |
|
103 | + { |
|
104 | + return apply_filters('FHEE__espresso__espresso_version', '4.9.29.rc.003'); |
|
105 | + } |
|
106 | 106 | |
107 | - // define versions |
|
108 | - define('EVENT_ESPRESSO_VERSION', espresso_version()); |
|
109 | - define('EE_MIN_WP_VER_REQUIRED', '4.1'); |
|
110 | - define('EE_MIN_WP_VER_RECOMMENDED', '4.4.2'); |
|
111 | - define('EE_MIN_PHP_VER_RECOMMENDED', '5.4.44'); |
|
112 | - define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
113 | - //used to be DIRECTORY_SEPARATOR, but that caused issues on windows |
|
114 | - if ( ! defined('DS')) { |
|
115 | - define('DS', '/'); |
|
116 | - } |
|
117 | - if ( ! defined('PS')) { |
|
118 | - define('PS', PATH_SEPARATOR); |
|
119 | - } |
|
120 | - if ( ! defined('SP')) { |
|
121 | - define('SP', ' '); |
|
122 | - } |
|
123 | - if ( ! defined('EENL')) { |
|
124 | - define('EENL', "\n"); |
|
125 | - } |
|
126 | - define('EE_SUPPORT_EMAIL', '[email protected]'); |
|
127 | - // define the plugin directory and URL |
|
128 | - define('EE_PLUGIN_BASENAME', plugin_basename(EVENT_ESPRESSO_MAIN_FILE)); |
|
129 | - define('EE_PLUGIN_DIR_PATH', plugin_dir_path(EVENT_ESPRESSO_MAIN_FILE)); |
|
130 | - define('EE_PLUGIN_DIR_URL', plugin_dir_url(EVENT_ESPRESSO_MAIN_FILE)); |
|
131 | - // main root folder paths |
|
132 | - define('EE_ADMIN_PAGES', EE_PLUGIN_DIR_PATH . 'admin_pages' . DS); |
|
133 | - define('EE_CORE', EE_PLUGIN_DIR_PATH . 'core' . DS); |
|
134 | - define('EE_MODULES', EE_PLUGIN_DIR_PATH . 'modules' . DS); |
|
135 | - define('EE_PUBLIC', EE_PLUGIN_DIR_PATH . 'public' . DS); |
|
136 | - define('EE_SHORTCODES', EE_PLUGIN_DIR_PATH . 'shortcodes' . DS); |
|
137 | - define('EE_WIDGETS', EE_PLUGIN_DIR_PATH . 'widgets' . DS); |
|
138 | - define('EE_PAYMENT_METHODS', EE_PLUGIN_DIR_PATH . 'payment_methods' . DS); |
|
139 | - define('EE_CAFF_PATH', EE_PLUGIN_DIR_PATH . 'caffeinated' . DS); |
|
140 | - // core system paths |
|
141 | - define('EE_ADMIN', EE_CORE . 'admin' . DS); |
|
142 | - define('EE_CPTS', EE_CORE . 'CPTs' . DS); |
|
143 | - define('EE_CLASSES', EE_CORE . 'db_classes' . DS); |
|
144 | - define('EE_INTERFACES', EE_CORE . 'interfaces' . DS); |
|
145 | - define('EE_BUSINESS', EE_CORE . 'business' . DS); |
|
146 | - define('EE_MODELS', EE_CORE . 'db_models' . DS); |
|
147 | - define('EE_HELPERS', EE_CORE . 'helpers' . DS); |
|
148 | - define('EE_LIBRARIES', EE_CORE . 'libraries' . DS); |
|
149 | - define('EE_TEMPLATES', EE_CORE . 'templates' . DS); |
|
150 | - define('EE_THIRD_PARTY', EE_CORE . 'third_party_libs' . DS); |
|
151 | - define('EE_GLOBAL_ASSETS', EE_TEMPLATES . 'global_assets' . DS); |
|
152 | - define('EE_FORM_SECTIONS', EE_LIBRARIES . 'form_sections' . DS); |
|
153 | - // gateways |
|
154 | - define('EE_GATEWAYS', EE_MODULES . 'gateways' . DS); |
|
155 | - define('EE_GATEWAYS_URL', EE_PLUGIN_DIR_URL . 'modules' . DS . 'gateways' . DS); |
|
156 | - // asset URL paths |
|
157 | - define('EE_TEMPLATES_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'templates' . DS); |
|
158 | - define('EE_GLOBAL_ASSETS_URL', EE_TEMPLATES_URL . 'global_assets' . DS); |
|
159 | - define('EE_IMAGES_URL', EE_GLOBAL_ASSETS_URL . 'images' . DS); |
|
160 | - define('EE_THIRD_PARTY_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'third_party_libs' . DS); |
|
161 | - define('EE_HELPERS_ASSETS', EE_PLUGIN_DIR_URL . 'core/helpers/assets/'); |
|
162 | - define('EE_LIBRARIES_URL', EE_PLUGIN_DIR_URL . 'core/libraries/'); |
|
163 | - // define upload paths |
|
164 | - $uploads = wp_upload_dir(); |
|
165 | - // define the uploads directory and URL |
|
166 | - define('EVENT_ESPRESSO_UPLOAD_DIR', $uploads['basedir'] . DS . 'espresso' . DS); |
|
167 | - define('EVENT_ESPRESSO_UPLOAD_URL', $uploads['baseurl'] . DS . 'espresso' . DS); |
|
168 | - // define the templates directory and URL |
|
169 | - define('EVENT_ESPRESSO_TEMPLATE_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'templates' . DS); |
|
170 | - define('EVENT_ESPRESSO_TEMPLATE_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'templates' . DS); |
|
171 | - // define the gateway directory and URL |
|
172 | - define('EVENT_ESPRESSO_GATEWAY_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'gateways' . DS); |
|
173 | - define('EVENT_ESPRESSO_GATEWAY_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'gateways' . DS); |
|
174 | - // languages folder/path |
|
175 | - define('EE_LANGUAGES_SAFE_LOC', '..' . DS . 'uploads' . DS . 'espresso' . DS . 'languages' . DS); |
|
176 | - define('EE_LANGUAGES_SAFE_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'languages' . DS); |
|
177 | - //check for dompdf fonts in uploads |
|
178 | - if (file_exists(EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS)) { |
|
179 | - define('DOMPDF_FONT_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS); |
|
180 | - } |
|
181 | - //ajax constants |
|
182 | - define( |
|
183 | - 'EE_FRONT_AJAX', |
|
184 | - isset($_REQUEST['ee_front_ajax']) || isset($_REQUEST['data']['ee_front_ajax']) ? true : false |
|
185 | - ); |
|
186 | - define( |
|
187 | - 'EE_ADMIN_AJAX', |
|
188 | - isset($_REQUEST['ee_admin_ajax']) || isset($_REQUEST['data']['ee_admin_ajax']) ? true : false |
|
189 | - ); |
|
190 | - //just a handy constant occasionally needed for finding values representing infinity in the DB |
|
191 | - //you're better to use this than its straight value (currently -1) in case you ever |
|
192 | - //want to change its default value! or find when -1 means infinity |
|
193 | - define('EE_INF_IN_DB', -1); |
|
194 | - define('EE_INF', INF > (float)PHP_INT_MAX ? INF : PHP_INT_MAX); |
|
195 | - define('EE_DEBUG', false); |
|
196 | - // for older WP versions |
|
197 | - if ( ! defined('MONTH_IN_SECONDS')) { |
|
198 | - define('MONTH_IN_SECONDS', DAY_IN_SECONDS * 30); |
|
199 | - } |
|
200 | - /** |
|
201 | - * espresso_plugin_activation |
|
202 | - * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
203 | - */ |
|
204 | - function espresso_plugin_activation() |
|
205 | - { |
|
206 | - update_option('ee_espresso_activation', true); |
|
207 | - } |
|
107 | + // define versions |
|
108 | + define('EVENT_ESPRESSO_VERSION', espresso_version()); |
|
109 | + define('EE_MIN_WP_VER_REQUIRED', '4.1'); |
|
110 | + define('EE_MIN_WP_VER_RECOMMENDED', '4.4.2'); |
|
111 | + define('EE_MIN_PHP_VER_RECOMMENDED', '5.4.44'); |
|
112 | + define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
113 | + //used to be DIRECTORY_SEPARATOR, but that caused issues on windows |
|
114 | + if ( ! defined('DS')) { |
|
115 | + define('DS', '/'); |
|
116 | + } |
|
117 | + if ( ! defined('PS')) { |
|
118 | + define('PS', PATH_SEPARATOR); |
|
119 | + } |
|
120 | + if ( ! defined('SP')) { |
|
121 | + define('SP', ' '); |
|
122 | + } |
|
123 | + if ( ! defined('EENL')) { |
|
124 | + define('EENL', "\n"); |
|
125 | + } |
|
126 | + define('EE_SUPPORT_EMAIL', '[email protected]'); |
|
127 | + // define the plugin directory and URL |
|
128 | + define('EE_PLUGIN_BASENAME', plugin_basename(EVENT_ESPRESSO_MAIN_FILE)); |
|
129 | + define('EE_PLUGIN_DIR_PATH', plugin_dir_path(EVENT_ESPRESSO_MAIN_FILE)); |
|
130 | + define('EE_PLUGIN_DIR_URL', plugin_dir_url(EVENT_ESPRESSO_MAIN_FILE)); |
|
131 | + // main root folder paths |
|
132 | + define('EE_ADMIN_PAGES', EE_PLUGIN_DIR_PATH . 'admin_pages' . DS); |
|
133 | + define('EE_CORE', EE_PLUGIN_DIR_PATH . 'core' . DS); |
|
134 | + define('EE_MODULES', EE_PLUGIN_DIR_PATH . 'modules' . DS); |
|
135 | + define('EE_PUBLIC', EE_PLUGIN_DIR_PATH . 'public' . DS); |
|
136 | + define('EE_SHORTCODES', EE_PLUGIN_DIR_PATH . 'shortcodes' . DS); |
|
137 | + define('EE_WIDGETS', EE_PLUGIN_DIR_PATH . 'widgets' . DS); |
|
138 | + define('EE_PAYMENT_METHODS', EE_PLUGIN_DIR_PATH . 'payment_methods' . DS); |
|
139 | + define('EE_CAFF_PATH', EE_PLUGIN_DIR_PATH . 'caffeinated' . DS); |
|
140 | + // core system paths |
|
141 | + define('EE_ADMIN', EE_CORE . 'admin' . DS); |
|
142 | + define('EE_CPTS', EE_CORE . 'CPTs' . DS); |
|
143 | + define('EE_CLASSES', EE_CORE . 'db_classes' . DS); |
|
144 | + define('EE_INTERFACES', EE_CORE . 'interfaces' . DS); |
|
145 | + define('EE_BUSINESS', EE_CORE . 'business' . DS); |
|
146 | + define('EE_MODELS', EE_CORE . 'db_models' . DS); |
|
147 | + define('EE_HELPERS', EE_CORE . 'helpers' . DS); |
|
148 | + define('EE_LIBRARIES', EE_CORE . 'libraries' . DS); |
|
149 | + define('EE_TEMPLATES', EE_CORE . 'templates' . DS); |
|
150 | + define('EE_THIRD_PARTY', EE_CORE . 'third_party_libs' . DS); |
|
151 | + define('EE_GLOBAL_ASSETS', EE_TEMPLATES . 'global_assets' . DS); |
|
152 | + define('EE_FORM_SECTIONS', EE_LIBRARIES . 'form_sections' . DS); |
|
153 | + // gateways |
|
154 | + define('EE_GATEWAYS', EE_MODULES . 'gateways' . DS); |
|
155 | + define('EE_GATEWAYS_URL', EE_PLUGIN_DIR_URL . 'modules' . DS . 'gateways' . DS); |
|
156 | + // asset URL paths |
|
157 | + define('EE_TEMPLATES_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'templates' . DS); |
|
158 | + define('EE_GLOBAL_ASSETS_URL', EE_TEMPLATES_URL . 'global_assets' . DS); |
|
159 | + define('EE_IMAGES_URL', EE_GLOBAL_ASSETS_URL . 'images' . DS); |
|
160 | + define('EE_THIRD_PARTY_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'third_party_libs' . DS); |
|
161 | + define('EE_HELPERS_ASSETS', EE_PLUGIN_DIR_URL . 'core/helpers/assets/'); |
|
162 | + define('EE_LIBRARIES_URL', EE_PLUGIN_DIR_URL . 'core/libraries/'); |
|
163 | + // define upload paths |
|
164 | + $uploads = wp_upload_dir(); |
|
165 | + // define the uploads directory and URL |
|
166 | + define('EVENT_ESPRESSO_UPLOAD_DIR', $uploads['basedir'] . DS . 'espresso' . DS); |
|
167 | + define('EVENT_ESPRESSO_UPLOAD_URL', $uploads['baseurl'] . DS . 'espresso' . DS); |
|
168 | + // define the templates directory and URL |
|
169 | + define('EVENT_ESPRESSO_TEMPLATE_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'templates' . DS); |
|
170 | + define('EVENT_ESPRESSO_TEMPLATE_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'templates' . DS); |
|
171 | + // define the gateway directory and URL |
|
172 | + define('EVENT_ESPRESSO_GATEWAY_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'gateways' . DS); |
|
173 | + define('EVENT_ESPRESSO_GATEWAY_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'gateways' . DS); |
|
174 | + // languages folder/path |
|
175 | + define('EE_LANGUAGES_SAFE_LOC', '..' . DS . 'uploads' . DS . 'espresso' . DS . 'languages' . DS); |
|
176 | + define('EE_LANGUAGES_SAFE_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'languages' . DS); |
|
177 | + //check for dompdf fonts in uploads |
|
178 | + if (file_exists(EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS)) { |
|
179 | + define('DOMPDF_FONT_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS); |
|
180 | + } |
|
181 | + //ajax constants |
|
182 | + define( |
|
183 | + 'EE_FRONT_AJAX', |
|
184 | + isset($_REQUEST['ee_front_ajax']) || isset($_REQUEST['data']['ee_front_ajax']) ? true : false |
|
185 | + ); |
|
186 | + define( |
|
187 | + 'EE_ADMIN_AJAX', |
|
188 | + isset($_REQUEST['ee_admin_ajax']) || isset($_REQUEST['data']['ee_admin_ajax']) ? true : false |
|
189 | + ); |
|
190 | + //just a handy constant occasionally needed for finding values representing infinity in the DB |
|
191 | + //you're better to use this than its straight value (currently -1) in case you ever |
|
192 | + //want to change its default value! or find when -1 means infinity |
|
193 | + define('EE_INF_IN_DB', -1); |
|
194 | + define('EE_INF', INF > (float)PHP_INT_MAX ? INF : PHP_INT_MAX); |
|
195 | + define('EE_DEBUG', false); |
|
196 | + // for older WP versions |
|
197 | + if ( ! defined('MONTH_IN_SECONDS')) { |
|
198 | + define('MONTH_IN_SECONDS', DAY_IN_SECONDS * 30); |
|
199 | + } |
|
200 | + /** |
|
201 | + * espresso_plugin_activation |
|
202 | + * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
203 | + */ |
|
204 | + function espresso_plugin_activation() |
|
205 | + { |
|
206 | + update_option('ee_espresso_activation', true); |
|
207 | + } |
|
208 | 208 | |
209 | - register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
210 | - /** |
|
211 | - * espresso_load_error_handling |
|
212 | - * this function loads EE's class for handling exceptions and errors |
|
213 | - */ |
|
214 | - function espresso_load_error_handling() |
|
215 | - { |
|
216 | - // load debugging tools |
|
217 | - if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) { |
|
218 | - require_once(EE_HELPERS . 'EEH_Debug_Tools.helper.php'); |
|
219 | - EEH_Debug_Tools::instance(); |
|
220 | - } |
|
221 | - // load error handling |
|
222 | - if (is_readable(EE_CORE . 'EE_Error.core.php')) { |
|
223 | - require_once(EE_CORE . 'EE_Error.core.php'); |
|
224 | - } else { |
|
225 | - wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso')); |
|
226 | - } |
|
227 | - } |
|
209 | + register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
210 | + /** |
|
211 | + * espresso_load_error_handling |
|
212 | + * this function loads EE's class for handling exceptions and errors |
|
213 | + */ |
|
214 | + function espresso_load_error_handling() |
|
215 | + { |
|
216 | + // load debugging tools |
|
217 | + if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) { |
|
218 | + require_once(EE_HELPERS . 'EEH_Debug_Tools.helper.php'); |
|
219 | + EEH_Debug_Tools::instance(); |
|
220 | + } |
|
221 | + // load error handling |
|
222 | + if (is_readable(EE_CORE . 'EE_Error.core.php')) { |
|
223 | + require_once(EE_CORE . 'EE_Error.core.php'); |
|
224 | + } else { |
|
225 | + wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso')); |
|
226 | + } |
|
227 | + } |
|
228 | 228 | |
229 | - /** |
|
230 | - * espresso_load_required |
|
231 | - * given a class name and path, this function will load that file or throw an exception |
|
232 | - * |
|
233 | - * @param string $classname |
|
234 | - * @param string $full_path_to_file |
|
235 | - * @throws EE_Error |
|
236 | - */ |
|
237 | - function espresso_load_required($classname, $full_path_to_file) |
|
238 | - { |
|
239 | - static $error_handling_loaded = false; |
|
240 | - if ( ! $error_handling_loaded) { |
|
241 | - espresso_load_error_handling(); |
|
242 | - $error_handling_loaded = true; |
|
243 | - } |
|
244 | - if (is_readable($full_path_to_file)) { |
|
245 | - require_once($full_path_to_file); |
|
246 | - } else { |
|
247 | - throw new EE_Error ( |
|
248 | - sprintf( |
|
249 | - esc_html__( |
|
250 | - 'The %s class file could not be located or is not readable due to file permissions.', |
|
251 | - 'event_espresso' |
|
252 | - ), |
|
253 | - $classname |
|
254 | - ) |
|
255 | - ); |
|
256 | - } |
|
257 | - } |
|
229 | + /** |
|
230 | + * espresso_load_required |
|
231 | + * given a class name and path, this function will load that file or throw an exception |
|
232 | + * |
|
233 | + * @param string $classname |
|
234 | + * @param string $full_path_to_file |
|
235 | + * @throws EE_Error |
|
236 | + */ |
|
237 | + function espresso_load_required($classname, $full_path_to_file) |
|
238 | + { |
|
239 | + static $error_handling_loaded = false; |
|
240 | + if ( ! $error_handling_loaded) { |
|
241 | + espresso_load_error_handling(); |
|
242 | + $error_handling_loaded = true; |
|
243 | + } |
|
244 | + if (is_readable($full_path_to_file)) { |
|
245 | + require_once($full_path_to_file); |
|
246 | + } else { |
|
247 | + throw new EE_Error ( |
|
248 | + sprintf( |
|
249 | + esc_html__( |
|
250 | + 'The %s class file could not be located or is not readable due to file permissions.', |
|
251 | + 'event_espresso' |
|
252 | + ), |
|
253 | + $classname |
|
254 | + ) |
|
255 | + ); |
|
256 | + } |
|
257 | + } |
|
258 | 258 | |
259 | - espresso_load_required('EEH_Base', EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php'); |
|
260 | - espresso_load_required('EEH_File', EE_CORE . 'helpers' . DS . 'EEH_File.helper.php'); |
|
261 | - espresso_load_required('EE_Bootstrap', EE_CORE . 'EE_Bootstrap.core.php'); |
|
262 | - new EE_Bootstrap(); |
|
263 | - } |
|
259 | + espresso_load_required('EEH_Base', EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php'); |
|
260 | + espresso_load_required('EEH_File', EE_CORE . 'helpers' . DS . 'EEH_File.helper.php'); |
|
261 | + espresso_load_required('EE_Bootstrap', EE_CORE . 'EE_Bootstrap.core.php'); |
|
262 | + new EE_Bootstrap(); |
|
263 | + } |
|
264 | 264 | } |
265 | 265 | if ( ! function_exists('espresso_deactivate_plugin')) { |
266 | - /** |
|
267 | - * deactivate_plugin |
|
268 | - * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
269 | - * |
|
270 | - * @access public |
|
271 | - * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
272 | - * @return void |
|
273 | - */ |
|
274 | - function espresso_deactivate_plugin($plugin_basename = '') |
|
275 | - { |
|
276 | - if ( ! function_exists('deactivate_plugins')) { |
|
277 | - require_once(ABSPATH . 'wp-admin/includes/plugin.php'); |
|
278 | - } |
|
279 | - unset($_GET['activate'], $_REQUEST['activate']); |
|
280 | - deactivate_plugins($plugin_basename); |
|
281 | - } |
|
266 | + /** |
|
267 | + * deactivate_plugin |
|
268 | + * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
269 | + * |
|
270 | + * @access public |
|
271 | + * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
272 | + * @return void |
|
273 | + */ |
|
274 | + function espresso_deactivate_plugin($plugin_basename = '') |
|
275 | + { |
|
276 | + if ( ! function_exists('deactivate_plugins')) { |
|
277 | + require_once(ABSPATH . 'wp-admin/includes/plugin.php'); |
|
278 | + } |
|
279 | + unset($_GET['activate'], $_REQUEST['activate']); |
|
280 | + deactivate_plugins($plugin_basename); |
|
281 | + } |
|
282 | 282 | } |
@@ -16,222 +16,222 @@ |
||
16 | 16 | class Registry |
17 | 17 | { |
18 | 18 | |
19 | - /** |
|
20 | - * This holds the jsdata data object that will be exposed on pages that enqueue the `eejs-core` script. |
|
21 | - * @var array |
|
22 | - */ |
|
23 | - protected $jsdata = array(); |
|
24 | - |
|
25 | - |
|
26 | - /** |
|
27 | - * Registry constructor. |
|
28 | - * Hooking into WP actions for script registry. |
|
29 | - */ |
|
30 | - public function __construct() |
|
31 | - { |
|
32 | - add_action('wp_enqueue_scripts', array($this, 'scripts'), 100); |
|
33 | - add_action('admin_enqueue_scripts', array($this, 'scripts'), 100); |
|
34 | - } |
|
35 | - |
|
36 | - |
|
37 | - /** |
|
38 | - * Callback for the WP script actions. |
|
39 | - * Used to register globally accessible core scripts. |
|
40 | - * Also used to add the eejs.data object to the source for any js having eejs-core as a dependency. |
|
41 | - */ |
|
42 | - public function scripts() |
|
43 | - { |
|
44 | - global $wp_version; |
|
45 | - wp_register_script( |
|
46 | - 'eejs-core', |
|
47 | - EE_PLUGIN_DIR_URL . 'core/services/assets/core_assets/eejs-core.js', |
|
48 | - array(), |
|
49 | - espresso_version(), |
|
50 | - true |
|
51 | - ); |
|
52 | - //only run this if WordPress 4.4.0 > is in use. |
|
53 | - if (version_compare($wp_version, '4.4.0', '>')) { |
|
54 | - //js.api |
|
55 | - wp_register_script( |
|
56 | - 'eejs-api', |
|
57 | - EE_LIBRARIES_URL . 'rest_api/assets/js/eejs-api.min.js', |
|
58 | - array('underscore', 'eejs-core'), |
|
59 | - espresso_version(), |
|
60 | - true |
|
61 | - ); |
|
62 | - $this->jsdata['paths'] = array('rest_route' => rest_url('ee/v4.8.36/')); |
|
63 | - |
|
64 | - wp_localize_script('eejs-core', 'eejs', array('data' => $this->jsdata)); |
|
65 | - } |
|
66 | - } |
|
67 | - |
|
68 | - |
|
69 | - /** |
|
70 | - * Used to add data to eejs.data object. |
|
71 | - * |
|
72 | - * Note: Overriding existing data is not allowed. |
|
73 | - * |
|
74 | - * Data will be accessible as a javascript object when you list `eejs-core` as a dependency for your javascript. |
|
75 | - * If the data you add is something like this: |
|
76 | - * |
|
77 | - * $this->addData( 'my_plugin_data', array( 'foo' => 'gar' ) ); |
|
78 | - * |
|
79 | - * It will be exposed in the page source as: |
|
80 | - * |
|
81 | - * eejs.data.my_plugin_data.foo == gar |
|
82 | - * |
|
83 | - * @param string $key Key used to access your data |
|
84 | - * @param string|array $value Value to attach to key |
|
85 | - * @throws InvalidArgumentException |
|
86 | - */ |
|
87 | - public function addData($key, $value) |
|
88 | - { |
|
89 | - if ($this->verifyDataNotExisting($key)) { |
|
90 | - $this->jsdata[$key] = $value; |
|
91 | - } |
|
92 | - } |
|
93 | - |
|
94 | - |
|
95 | - /** |
|
96 | - * Similar to addData except this allows for users to push values to an existing key where the values on key are |
|
97 | - * elements in an array. |
|
98 | - * |
|
99 | - * When you use this method, the value you include will be appended to the end of an array on $key. |
|
100 | - * |
|
101 | - * So if the $key was 'test' and you added a value of 'my_data' then it would be represented in the javascript object |
|
102 | - * like this, |
|
103 | - * |
|
104 | - * eejs.data.test = [ |
|
105 | - * my_data, |
|
106 | - * ] |
|
107 | - * |
|
108 | - * If there has already been a scalar value attached to the data object given key, then |
|
109 | - * this will throw an exception. |
|
110 | - * |
|
111 | - * @param string $key Key to attach data to. |
|
112 | - * @param string|array $value Value being registered. |
|
113 | - * @throws InvalidArgumentException |
|
114 | - */ |
|
115 | - public function pushData($key, $value) |
|
116 | - { |
|
117 | - if (isset($this->jsdata[$key]) |
|
118 | - && ! is_array($this->jsdata[$key]) |
|
119 | - ) { |
|
120 | - throw new invalidArgumentException( |
|
121 | - sprintf( |
|
122 | - __( |
|
123 | - 'The value for %1$s is already set and it is not an array. The %2$s method can only be used to |
|
19 | + /** |
|
20 | + * This holds the jsdata data object that will be exposed on pages that enqueue the `eejs-core` script. |
|
21 | + * @var array |
|
22 | + */ |
|
23 | + protected $jsdata = array(); |
|
24 | + |
|
25 | + |
|
26 | + /** |
|
27 | + * Registry constructor. |
|
28 | + * Hooking into WP actions for script registry. |
|
29 | + */ |
|
30 | + public function __construct() |
|
31 | + { |
|
32 | + add_action('wp_enqueue_scripts', array($this, 'scripts'), 100); |
|
33 | + add_action('admin_enqueue_scripts', array($this, 'scripts'), 100); |
|
34 | + } |
|
35 | + |
|
36 | + |
|
37 | + /** |
|
38 | + * Callback for the WP script actions. |
|
39 | + * Used to register globally accessible core scripts. |
|
40 | + * Also used to add the eejs.data object to the source for any js having eejs-core as a dependency. |
|
41 | + */ |
|
42 | + public function scripts() |
|
43 | + { |
|
44 | + global $wp_version; |
|
45 | + wp_register_script( |
|
46 | + 'eejs-core', |
|
47 | + EE_PLUGIN_DIR_URL . 'core/services/assets/core_assets/eejs-core.js', |
|
48 | + array(), |
|
49 | + espresso_version(), |
|
50 | + true |
|
51 | + ); |
|
52 | + //only run this if WordPress 4.4.0 > is in use. |
|
53 | + if (version_compare($wp_version, '4.4.0', '>')) { |
|
54 | + //js.api |
|
55 | + wp_register_script( |
|
56 | + 'eejs-api', |
|
57 | + EE_LIBRARIES_URL . 'rest_api/assets/js/eejs-api.min.js', |
|
58 | + array('underscore', 'eejs-core'), |
|
59 | + espresso_version(), |
|
60 | + true |
|
61 | + ); |
|
62 | + $this->jsdata['paths'] = array('rest_route' => rest_url('ee/v4.8.36/')); |
|
63 | + |
|
64 | + wp_localize_script('eejs-core', 'eejs', array('data' => $this->jsdata)); |
|
65 | + } |
|
66 | + } |
|
67 | + |
|
68 | + |
|
69 | + /** |
|
70 | + * Used to add data to eejs.data object. |
|
71 | + * |
|
72 | + * Note: Overriding existing data is not allowed. |
|
73 | + * |
|
74 | + * Data will be accessible as a javascript object when you list `eejs-core` as a dependency for your javascript. |
|
75 | + * If the data you add is something like this: |
|
76 | + * |
|
77 | + * $this->addData( 'my_plugin_data', array( 'foo' => 'gar' ) ); |
|
78 | + * |
|
79 | + * It will be exposed in the page source as: |
|
80 | + * |
|
81 | + * eejs.data.my_plugin_data.foo == gar |
|
82 | + * |
|
83 | + * @param string $key Key used to access your data |
|
84 | + * @param string|array $value Value to attach to key |
|
85 | + * @throws InvalidArgumentException |
|
86 | + */ |
|
87 | + public function addData($key, $value) |
|
88 | + { |
|
89 | + if ($this->verifyDataNotExisting($key)) { |
|
90 | + $this->jsdata[$key] = $value; |
|
91 | + } |
|
92 | + } |
|
93 | + |
|
94 | + |
|
95 | + /** |
|
96 | + * Similar to addData except this allows for users to push values to an existing key where the values on key are |
|
97 | + * elements in an array. |
|
98 | + * |
|
99 | + * When you use this method, the value you include will be appended to the end of an array on $key. |
|
100 | + * |
|
101 | + * So if the $key was 'test' and you added a value of 'my_data' then it would be represented in the javascript object |
|
102 | + * like this, |
|
103 | + * |
|
104 | + * eejs.data.test = [ |
|
105 | + * my_data, |
|
106 | + * ] |
|
107 | + * |
|
108 | + * If there has already been a scalar value attached to the data object given key, then |
|
109 | + * this will throw an exception. |
|
110 | + * |
|
111 | + * @param string $key Key to attach data to. |
|
112 | + * @param string|array $value Value being registered. |
|
113 | + * @throws InvalidArgumentException |
|
114 | + */ |
|
115 | + public function pushData($key, $value) |
|
116 | + { |
|
117 | + if (isset($this->jsdata[$key]) |
|
118 | + && ! is_array($this->jsdata[$key]) |
|
119 | + ) { |
|
120 | + throw new invalidArgumentException( |
|
121 | + sprintf( |
|
122 | + __( |
|
123 | + 'The value for %1$s is already set and it is not an array. The %2$s method can only be used to |
|
124 | 124 | push values to this data element when it is an array.', |
125 | - 'event_espresso' |
|
126 | - ), |
|
127 | - $key, |
|
128 | - __METHOD__ |
|
129 | - ) |
|
130 | - ); |
|
131 | - } |
|
132 | - |
|
133 | - $this->jsdata[$key][] = $value; |
|
134 | - } |
|
135 | - |
|
136 | - |
|
137 | - /** |
|
138 | - * Used to set content used by javascript for a template. |
|
139 | - * Note: Overrides of existing registered templates are not allowed. |
|
140 | - * |
|
141 | - * @param string $template_reference |
|
142 | - * @param string $template_content |
|
143 | - * @throws InvalidArgumentException |
|
144 | - */ |
|
145 | - public function addTemplate($template_reference, $template_content) |
|
146 | - { |
|
147 | - if (! isset($this->jsdata['templates'])) { |
|
148 | - $this->jsdata['templates'] = array(); |
|
149 | - } |
|
150 | - |
|
151 | - //no overrides allowed. |
|
152 | - if (isset($this->jsdata['templates'][$template_reference])) { |
|
153 | - throw new invalidArgumentException( |
|
154 | - sprintf( |
|
155 | - __( |
|
156 | - 'The %1$s key already exists for the templates array in the js data array. No overrides are allowed.', |
|
157 | - 'event_espresso' |
|
158 | - ), |
|
159 | - $template_reference |
|
160 | - ) |
|
161 | - ); |
|
162 | - } else { |
|
163 | - $this->jsdata['templates'][$template_reference] = $template_content; |
|
164 | - } |
|
165 | - } |
|
166 | - |
|
167 | - |
|
168 | - /** |
|
169 | - * Retrieve the template content already registered for the given reference. |
|
170 | - * @param string $template_reference |
|
171 | - * @return string |
|
172 | - */ |
|
173 | - public function getTemplate($template_reference) |
|
174 | - { |
|
175 | - return isset($this->jsdata['templates'], $this->jsdata['templates'][$template_reference]) |
|
176 | - ? $this->jsdata['templates'][$template_reference] |
|
177 | - : ''; |
|
178 | - } |
|
179 | - |
|
180 | - |
|
181 | - /** |
|
182 | - * Retrieve registered data. |
|
183 | - * |
|
184 | - * @param string $key Name of key to attach data to. |
|
185 | - * @return mixed If there is no for the given key, then false is returned. |
|
186 | - */ |
|
187 | - public function getData($key) |
|
188 | - { |
|
189 | - return isset($this->jsdata[$key]) |
|
190 | - ? $this->jsdata[$key] |
|
191 | - : false; |
|
192 | - } |
|
193 | - |
|
194 | - |
|
195 | - |
|
196 | - |
|
197 | - /** |
|
198 | - * Verifies whether the given data exists already on the jsdata array. |
|
199 | - * |
|
200 | - * Overriding data is not allowed. |
|
201 | - * |
|
202 | - * @param string $key Index for data. |
|
203 | - * @return bool If valid then return true. |
|
204 | - * @throws InvalidArgumentException if data already exists. |
|
205 | - */ |
|
206 | - protected function verifyDataNotExisting($key) |
|
207 | - { |
|
208 | - if (isset($this->jsdata[$key])) { |
|
209 | - if (is_array($this->jsdata[$key])) { |
|
210 | - throw new InvalidArgumentException( |
|
211 | - sprintf( |
|
212 | - __( |
|
213 | - 'The value for %1$s already exists in the Registry::eejs object. |
|
125 | + 'event_espresso' |
|
126 | + ), |
|
127 | + $key, |
|
128 | + __METHOD__ |
|
129 | + ) |
|
130 | + ); |
|
131 | + } |
|
132 | + |
|
133 | + $this->jsdata[$key][] = $value; |
|
134 | + } |
|
135 | + |
|
136 | + |
|
137 | + /** |
|
138 | + * Used to set content used by javascript for a template. |
|
139 | + * Note: Overrides of existing registered templates are not allowed. |
|
140 | + * |
|
141 | + * @param string $template_reference |
|
142 | + * @param string $template_content |
|
143 | + * @throws InvalidArgumentException |
|
144 | + */ |
|
145 | + public function addTemplate($template_reference, $template_content) |
|
146 | + { |
|
147 | + if (! isset($this->jsdata['templates'])) { |
|
148 | + $this->jsdata['templates'] = array(); |
|
149 | + } |
|
150 | + |
|
151 | + //no overrides allowed. |
|
152 | + if (isset($this->jsdata['templates'][$template_reference])) { |
|
153 | + throw new invalidArgumentException( |
|
154 | + sprintf( |
|
155 | + __( |
|
156 | + 'The %1$s key already exists for the templates array in the js data array. No overrides are allowed.', |
|
157 | + 'event_espresso' |
|
158 | + ), |
|
159 | + $template_reference |
|
160 | + ) |
|
161 | + ); |
|
162 | + } else { |
|
163 | + $this->jsdata['templates'][$template_reference] = $template_content; |
|
164 | + } |
|
165 | + } |
|
166 | + |
|
167 | + |
|
168 | + /** |
|
169 | + * Retrieve the template content already registered for the given reference. |
|
170 | + * @param string $template_reference |
|
171 | + * @return string |
|
172 | + */ |
|
173 | + public function getTemplate($template_reference) |
|
174 | + { |
|
175 | + return isset($this->jsdata['templates'], $this->jsdata['templates'][$template_reference]) |
|
176 | + ? $this->jsdata['templates'][$template_reference] |
|
177 | + : ''; |
|
178 | + } |
|
179 | + |
|
180 | + |
|
181 | + /** |
|
182 | + * Retrieve registered data. |
|
183 | + * |
|
184 | + * @param string $key Name of key to attach data to. |
|
185 | + * @return mixed If there is no for the given key, then false is returned. |
|
186 | + */ |
|
187 | + public function getData($key) |
|
188 | + { |
|
189 | + return isset($this->jsdata[$key]) |
|
190 | + ? $this->jsdata[$key] |
|
191 | + : false; |
|
192 | + } |
|
193 | + |
|
194 | + |
|
195 | + |
|
196 | + |
|
197 | + /** |
|
198 | + * Verifies whether the given data exists already on the jsdata array. |
|
199 | + * |
|
200 | + * Overriding data is not allowed. |
|
201 | + * |
|
202 | + * @param string $key Index for data. |
|
203 | + * @return bool If valid then return true. |
|
204 | + * @throws InvalidArgumentException if data already exists. |
|
205 | + */ |
|
206 | + protected function verifyDataNotExisting($key) |
|
207 | + { |
|
208 | + if (isset($this->jsdata[$key])) { |
|
209 | + if (is_array($this->jsdata[$key])) { |
|
210 | + throw new InvalidArgumentException( |
|
211 | + sprintf( |
|
212 | + __( |
|
213 | + 'The value for %1$s already exists in the Registry::eejs object. |
|
214 | 214 | Overrides are not allowed. Since the value of this data is an array, you may want to use the |
215 | 215 | %2$s method to push your value to the array.', |
216 | - 'event_espresso' |
|
217 | - ), |
|
218 | - $key, |
|
219 | - 'pushData()' |
|
220 | - ) |
|
221 | - ); |
|
222 | - } else { |
|
223 | - throw new InvalidArgumentException( |
|
224 | - sprintf( |
|
225 | - __( |
|
226 | - 'The value for %1$s already exists in the Registry::eejs object. Overrides are not |
|
216 | + 'event_espresso' |
|
217 | + ), |
|
218 | + $key, |
|
219 | + 'pushData()' |
|
220 | + ) |
|
221 | + ); |
|
222 | + } else { |
|
223 | + throw new InvalidArgumentException( |
|
224 | + sprintf( |
|
225 | + __( |
|
226 | + 'The value for %1$s already exists in the Registry::eejs object. Overrides are not |
|
227 | 227 | allowed. Consider attaching your value to a different key', |
228 | - 'event_espresso' |
|
229 | - ), |
|
230 | - $key |
|
231 | - ) |
|
232 | - ); |
|
233 | - } |
|
234 | - } |
|
235 | - return true; |
|
236 | - } |
|
228 | + 'event_espresso' |
|
229 | + ), |
|
230 | + $key |
|
231 | + ) |
|
232 | + ); |
|
233 | + } |
|
234 | + } |
|
235 | + return true; |
|
236 | + } |
|
237 | 237 | } |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | global $wp_version; |
45 | 45 | wp_register_script( |
46 | 46 | 'eejs-core', |
47 | - EE_PLUGIN_DIR_URL . 'core/services/assets/core_assets/eejs-core.js', |
|
47 | + EE_PLUGIN_DIR_URL.'core/services/assets/core_assets/eejs-core.js', |
|
48 | 48 | array(), |
49 | 49 | espresso_version(), |
50 | 50 | true |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | //js.api |
55 | 55 | wp_register_script( |
56 | 56 | 'eejs-api', |
57 | - EE_LIBRARIES_URL . 'rest_api/assets/js/eejs-api.min.js', |
|
57 | + EE_LIBRARIES_URL.'rest_api/assets/js/eejs-api.min.js', |
|
58 | 58 | array('underscore', 'eejs-core'), |
59 | 59 | espresso_version(), |
60 | 60 | true |
@@ -144,7 +144,7 @@ discard block |
||
144 | 144 | */ |
145 | 145 | public function addTemplate($template_reference, $template_content) |
146 | 146 | { |
147 | - if (! isset($this->jsdata['templates'])) { |
|
147 | + if ( ! isset($this->jsdata['templates'])) { |
|
148 | 148 | $this->jsdata['templates'] = array(); |
149 | 149 | } |
150 | 150 |
@@ -16,25 +16,25 @@ |
||
16 | 16 | class TriggerStrategyHook extends TriggerStrategy |
17 | 17 | { |
18 | 18 | |
19 | - /** |
|
20 | - * This allows strategies to set up whatever hooks are necessary to trigger their logic. |
|
21 | - * All overriding methods should call: $this->setAutomatedAction($automated_action) |
|
22 | - * |
|
23 | - * @param AutomatedActionInterface $automated_action |
|
24 | - */ |
|
25 | - public function set(AutomatedActionInterface $automated_action) |
|
26 | - { |
|
27 | - \EEH_Debug_Tools::printr(__FUNCTION__, __CLASS__, __FILE__, __LINE__, 2); |
|
28 | - $this->setAutomatedAction($automated_action); |
|
29 | - $extra_data = $automated_action->getData(); |
|
30 | - // todo: might want to change where these parameters are saved |
|
31 | - // todo: maybe make them part of the AMA_trigger_value field ? |
|
32 | - $priority = isset($extra_data->hook, $extra_data->hook->priority) ? $extra_data->hook->priority : 10; |
|
33 | - $arguments = isset($extra_data->hook, $extra_data->hook->arguments) ? $extra_data->hook->arguments : 1; |
|
34 | - // \EEH_Debug_Tools::printr($priority, '$priority', __FILE__, __LINE__); |
|
35 | - // \EEH_Debug_Tools::printr($arguments, '$arguments', __FILE__, __LINE__); |
|
36 | - add_action($automated_action->getTriggerValue(), array($this, 'triggerCallback'), $priority, $arguments); |
|
37 | - } |
|
19 | + /** |
|
20 | + * This allows strategies to set up whatever hooks are necessary to trigger their logic. |
|
21 | + * All overriding methods should call: $this->setAutomatedAction($automated_action) |
|
22 | + * |
|
23 | + * @param AutomatedActionInterface $automated_action |
|
24 | + */ |
|
25 | + public function set(AutomatedActionInterface $automated_action) |
|
26 | + { |
|
27 | + \EEH_Debug_Tools::printr(__FUNCTION__, __CLASS__, __FILE__, __LINE__, 2); |
|
28 | + $this->setAutomatedAction($automated_action); |
|
29 | + $extra_data = $automated_action->getData(); |
|
30 | + // todo: might want to change where these parameters are saved |
|
31 | + // todo: maybe make them part of the AMA_trigger_value field ? |
|
32 | + $priority = isset($extra_data->hook, $extra_data->hook->priority) ? $extra_data->hook->priority : 10; |
|
33 | + $arguments = isset($extra_data->hook, $extra_data->hook->arguments) ? $extra_data->hook->arguments : 1; |
|
34 | + // \EEH_Debug_Tools::printr($priority, '$priority', __FILE__, __LINE__); |
|
35 | + // \EEH_Debug_Tools::printr($arguments, '$arguments', __FILE__, __LINE__); |
|
36 | + add_action($automated_action->getTriggerValue(), array($this, 'triggerCallback'), $priority, $arguments); |
|
37 | + } |
|
38 | 38 | |
39 | 39 | |
40 | 40 |
@@ -23,217 +23,217 @@ |
||
23 | 23 | abstract class TriggerStrategy |
24 | 24 | { |
25 | 25 | |
26 | - /** |
|
27 | - * @var RuleManager $rule_manager |
|
28 | - */ |
|
29 | - private $rule_manager; |
|
26 | + /** |
|
27 | + * @var RuleManager $rule_manager |
|
28 | + */ |
|
29 | + private $rule_manager; |
|
30 | 30 | |
31 | - /** |
|
32 | - * @var AutomatedActionInterface $automated_action |
|
33 | - */ |
|
34 | - private $automated_action; |
|
31 | + /** |
|
32 | + * @var AutomatedActionInterface $automated_action |
|
33 | + */ |
|
34 | + private $automated_action; |
|
35 | 35 | |
36 | - /** |
|
37 | - * @var array $callback_args |
|
38 | - */ |
|
39 | - private $callback_args = array(); |
|
36 | + /** |
|
37 | + * @var array $callback_args |
|
38 | + */ |
|
39 | + private $callback_args = array(); |
|
40 | 40 | |
41 | - /** |
|
42 | - * @var boolean $pulled |
|
43 | - */ |
|
44 | - private $pulled = false; |
|
41 | + /** |
|
42 | + * @var boolean $pulled |
|
43 | + */ |
|
44 | + private $pulled = false; |
|
45 | 45 | |
46 | - /** |
|
47 | - * @var Collection $rules |
|
48 | - */ |
|
49 | - private $rules; |
|
46 | + /** |
|
47 | + * @var Collection $rules |
|
48 | + */ |
|
49 | + private $rules; |
|
50 | 50 | |
51 | 51 | |
52 | 52 | |
53 | - /** |
|
54 | - * TriggerStrategy constructor. |
|
55 | - * |
|
56 | - * @param RuleManager $rule_manager |
|
57 | - */ |
|
58 | - public function __construct(RuleManager $rule_manager) |
|
59 | - { |
|
60 | - $this->rule_manager = $rule_manager; |
|
61 | - } |
|
53 | + /** |
|
54 | + * TriggerStrategy constructor. |
|
55 | + * |
|
56 | + * @param RuleManager $rule_manager |
|
57 | + */ |
|
58 | + public function __construct(RuleManager $rule_manager) |
|
59 | + { |
|
60 | + $this->rule_manager = $rule_manager; |
|
61 | + } |
|
62 | 62 | |
63 | 63 | |
64 | 64 | |
65 | - /** |
|
66 | - * @return AutomatedActionInterface |
|
67 | - */ |
|
68 | - public function getAutomatedAction() |
|
69 | - { |
|
70 | - return $this->automated_action; |
|
71 | - } |
|
65 | + /** |
|
66 | + * @return AutomatedActionInterface |
|
67 | + */ |
|
68 | + public function getAutomatedAction() |
|
69 | + { |
|
70 | + return $this->automated_action; |
|
71 | + } |
|
72 | 72 | |
73 | 73 | |
74 | 74 | |
75 | - /** |
|
76 | - * @param \EventEspresso\core\services\automated_actions\AutomatedActionInterface $automated_action |
|
77 | - */ |
|
78 | - public function setAutomatedAction(AutomatedActionInterface $automated_action) { |
|
79 | - $this->automated_action = $automated_action; |
|
80 | - } |
|
81 | - |
|
82 | - |
|
83 | - |
|
84 | - |
|
85 | - /** |
|
86 | - * @return array |
|
87 | - */ |
|
88 | - public function getCallbackArgs() |
|
89 | - { |
|
90 | - return $this->callback_args; |
|
91 | - } |
|
92 | - |
|
93 | - |
|
94 | - |
|
95 | - /** |
|
96 | - * @param array $callback_args |
|
97 | - */ |
|
98 | - public function setCallbackArgs(array $callback_args = array()) |
|
99 | - { |
|
100 | - $this->callback_args = $callback_args; |
|
101 | - } |
|
102 | - |
|
103 | - |
|
104 | - |
|
105 | - /** |
|
106 | - * @return bool |
|
107 | - */ |
|
108 | - public function pulled() |
|
109 | - { |
|
110 | - return $this->pulled; |
|
111 | - } |
|
112 | - |
|
113 | - |
|
114 | - |
|
115 | - /** |
|
116 | - * @param bool $pulled |
|
117 | - */ |
|
118 | - public function setPulled($pulled = true) |
|
119 | - { |
|
120 | - $this->pulled = filter_var($pulled, FILTER_VALIDATE_BOOLEAN); |
|
121 | - } |
|
122 | - |
|
123 | - |
|
124 | - |
|
125 | - /** |
|
126 | - * @return Collection |
|
127 | - * @throws InvalidArgumentException |
|
128 | - * @throws InvalidInterfaceException |
|
129 | - * @throws InvalidEntityException |
|
130 | - * @throws DomainException |
|
131 | - */ |
|
132 | - public function getRules() |
|
133 | - { |
|
134 | - if ($this->rules === null) { |
|
135 | - $this->setRules(); |
|
136 | - } |
|
137 | - return $this->rules; |
|
138 | - } |
|
139 | - |
|
140 | - |
|
141 | - |
|
142 | - /** |
|
143 | - * @return void |
|
144 | - * @throws InvalidArgumentException |
|
145 | - * @throws InvalidInterfaceException |
|
146 | - * @throws InvalidEntityException |
|
147 | - * @throws DomainException |
|
148 | - */ |
|
149 | - private function setRules() |
|
150 | - { |
|
151 | - $this->rules = $this->rule_manager->retrieveRulesForObject( |
|
152 | - 'Automated Action', |
|
153 | - $this->automated_action->getID() |
|
154 | - ); |
|
155 | - } |
|
156 | - |
|
157 | - |
|
158 | - |
|
159 | - /** |
|
160 | - * This is required and should be overridden by all trigger types, |
|
161 | - * as it allows strategies to set up whatever hooks are necessary to trigger their logic. |
|
162 | - * All overriding methods should call: $this->setAutomatedAction($automated_action) |
|
163 | - * |
|
164 | - * @param AutomatedActionInterface $automated_action |
|
165 | - */ |
|
166 | - abstract public function set(AutomatedActionInterface $automated_action); |
|
167 | - |
|
168 | - |
|
169 | - |
|
170 | - /** |
|
171 | - * callback method for all strategies (regardless of type), |
|
172 | - * that runs when the trigger is "pulled". |
|
173 | - * At this point strategies should ONLY proceed to collect data |
|
174 | - * required for the action, store it for later processing, |
|
175 | - * and call setPulled() to indicate that the trigger was successful |
|
176 | - * (meaning data results for the action were retrieved). |
|
177 | - * This allows control over when that happens |
|
178 | - * because the moment the trigger is pulled |
|
179 | - * may not be the most optimum time for data processing. |
|
180 | - * By default, logic processing will occur during "shutdown", |
|
181 | - * but can be overridden by an AutomatedActionStrategy class |
|
182 | - * |
|
183 | - * @throws InvalidArgumentException |
|
184 | - * @throws InvalidInterfaceException |
|
185 | - * @throws InvalidEntityException |
|
186 | - * @throws DomainException |
|
187 | - */ |
|
188 | - public function triggerCallback() { |
|
189 | - \EEH_Debug_Tools::printr(__FUNCTION__, __CLASS__, __FILE__, __LINE__, 2); |
|
190 | - $this->setCallbackArgs(func_get_args()); |
|
191 | - $this->execute( |
|
192 | - $this->getQueryParamsForRules() |
|
193 | - ); |
|
194 | - } |
|
195 | - |
|
196 | - |
|
197 | - |
|
198 | - /** |
|
199 | - * @return array |
|
200 | - * @throws InvalidArgumentException |
|
201 | - * @throws InvalidInterfaceException |
|
202 | - * @throws InvalidEntityException |
|
203 | - * @throws DomainException |
|
204 | - */ |
|
205 | - public function getQueryParamsForRules() |
|
206 | - { |
|
207 | - return $this->rule_manager->getQueryParamsForRules( |
|
208 | - $this->getRules() |
|
209 | - ); |
|
210 | - } |
|
211 | - |
|
212 | - |
|
213 | - |
|
214 | - /** |
|
215 | - * when a trigger has been "pulled", |
|
216 | - * either by a do_action or scheduled cron, |
|
217 | - * this is the TriggerStrategy method that will run |
|
218 | - * to continue processing the trigger. |
|
219 | - * This will typically mean retrieving objects from the db. |
|
220 | - * By default, this method does nothing but set callback args |
|
221 | - * to be used for querying during the 'shutdown' hook when |
|
222 | - * AutomatedActionManager::processActions() runs, |
|
223 | - * but can be overridden to perform querying now. |
|
224 | - * |
|
225 | - * @param array $query_params |
|
226 | - * @return void |
|
227 | - */ |
|
228 | - public function execute(array $query_params) |
|
229 | - { |
|
230 | - \EEH_Debug_Tools::printr(__FUNCTION__, __CLASS__, __FILE__, __LINE__, 2); |
|
231 | - $this->setCallbackArgs( |
|
232 | - array_merge($this->callback_args, array('query_params' => $query_params)) |
|
233 | - ); |
|
234 | - // \EEH_Debug_Tools::printr($this->callback_args, '$this->callback_args', __FILE__, __LINE__); |
|
235 | - $this->setPulled(); |
|
236 | - } |
|
75 | + /** |
|
76 | + * @param \EventEspresso\core\services\automated_actions\AutomatedActionInterface $automated_action |
|
77 | + */ |
|
78 | + public function setAutomatedAction(AutomatedActionInterface $automated_action) { |
|
79 | + $this->automated_action = $automated_action; |
|
80 | + } |
|
81 | + |
|
82 | + |
|
83 | + |
|
84 | + |
|
85 | + /** |
|
86 | + * @return array |
|
87 | + */ |
|
88 | + public function getCallbackArgs() |
|
89 | + { |
|
90 | + return $this->callback_args; |
|
91 | + } |
|
92 | + |
|
93 | + |
|
94 | + |
|
95 | + /** |
|
96 | + * @param array $callback_args |
|
97 | + */ |
|
98 | + public function setCallbackArgs(array $callback_args = array()) |
|
99 | + { |
|
100 | + $this->callback_args = $callback_args; |
|
101 | + } |
|
102 | + |
|
103 | + |
|
104 | + |
|
105 | + /** |
|
106 | + * @return bool |
|
107 | + */ |
|
108 | + public function pulled() |
|
109 | + { |
|
110 | + return $this->pulled; |
|
111 | + } |
|
112 | + |
|
113 | + |
|
114 | + |
|
115 | + /** |
|
116 | + * @param bool $pulled |
|
117 | + */ |
|
118 | + public function setPulled($pulled = true) |
|
119 | + { |
|
120 | + $this->pulled = filter_var($pulled, FILTER_VALIDATE_BOOLEAN); |
|
121 | + } |
|
122 | + |
|
123 | + |
|
124 | + |
|
125 | + /** |
|
126 | + * @return Collection |
|
127 | + * @throws InvalidArgumentException |
|
128 | + * @throws InvalidInterfaceException |
|
129 | + * @throws InvalidEntityException |
|
130 | + * @throws DomainException |
|
131 | + */ |
|
132 | + public function getRules() |
|
133 | + { |
|
134 | + if ($this->rules === null) { |
|
135 | + $this->setRules(); |
|
136 | + } |
|
137 | + return $this->rules; |
|
138 | + } |
|
139 | + |
|
140 | + |
|
141 | + |
|
142 | + /** |
|
143 | + * @return void |
|
144 | + * @throws InvalidArgumentException |
|
145 | + * @throws InvalidInterfaceException |
|
146 | + * @throws InvalidEntityException |
|
147 | + * @throws DomainException |
|
148 | + */ |
|
149 | + private function setRules() |
|
150 | + { |
|
151 | + $this->rules = $this->rule_manager->retrieveRulesForObject( |
|
152 | + 'Automated Action', |
|
153 | + $this->automated_action->getID() |
|
154 | + ); |
|
155 | + } |
|
156 | + |
|
157 | + |
|
158 | + |
|
159 | + /** |
|
160 | + * This is required and should be overridden by all trigger types, |
|
161 | + * as it allows strategies to set up whatever hooks are necessary to trigger their logic. |
|
162 | + * All overriding methods should call: $this->setAutomatedAction($automated_action) |
|
163 | + * |
|
164 | + * @param AutomatedActionInterface $automated_action |
|
165 | + */ |
|
166 | + abstract public function set(AutomatedActionInterface $automated_action); |
|
167 | + |
|
168 | + |
|
169 | + |
|
170 | + /** |
|
171 | + * callback method for all strategies (regardless of type), |
|
172 | + * that runs when the trigger is "pulled". |
|
173 | + * At this point strategies should ONLY proceed to collect data |
|
174 | + * required for the action, store it for later processing, |
|
175 | + * and call setPulled() to indicate that the trigger was successful |
|
176 | + * (meaning data results for the action were retrieved). |
|
177 | + * This allows control over when that happens |
|
178 | + * because the moment the trigger is pulled |
|
179 | + * may not be the most optimum time for data processing. |
|
180 | + * By default, logic processing will occur during "shutdown", |
|
181 | + * but can be overridden by an AutomatedActionStrategy class |
|
182 | + * |
|
183 | + * @throws InvalidArgumentException |
|
184 | + * @throws InvalidInterfaceException |
|
185 | + * @throws InvalidEntityException |
|
186 | + * @throws DomainException |
|
187 | + */ |
|
188 | + public function triggerCallback() { |
|
189 | + \EEH_Debug_Tools::printr(__FUNCTION__, __CLASS__, __FILE__, __LINE__, 2); |
|
190 | + $this->setCallbackArgs(func_get_args()); |
|
191 | + $this->execute( |
|
192 | + $this->getQueryParamsForRules() |
|
193 | + ); |
|
194 | + } |
|
195 | + |
|
196 | + |
|
197 | + |
|
198 | + /** |
|
199 | + * @return array |
|
200 | + * @throws InvalidArgumentException |
|
201 | + * @throws InvalidInterfaceException |
|
202 | + * @throws InvalidEntityException |
|
203 | + * @throws DomainException |
|
204 | + */ |
|
205 | + public function getQueryParamsForRules() |
|
206 | + { |
|
207 | + return $this->rule_manager->getQueryParamsForRules( |
|
208 | + $this->getRules() |
|
209 | + ); |
|
210 | + } |
|
211 | + |
|
212 | + |
|
213 | + |
|
214 | + /** |
|
215 | + * when a trigger has been "pulled", |
|
216 | + * either by a do_action or scheduled cron, |
|
217 | + * this is the TriggerStrategy method that will run |
|
218 | + * to continue processing the trigger. |
|
219 | + * This will typically mean retrieving objects from the db. |
|
220 | + * By default, this method does nothing but set callback args |
|
221 | + * to be used for querying during the 'shutdown' hook when |
|
222 | + * AutomatedActionManager::processActions() runs, |
|
223 | + * but can be overridden to perform querying now. |
|
224 | + * |
|
225 | + * @param array $query_params |
|
226 | + * @return void |
|
227 | + */ |
|
228 | + public function execute(array $query_params) |
|
229 | + { |
|
230 | + \EEH_Debug_Tools::printr(__FUNCTION__, __CLASS__, __FILE__, __LINE__, 2); |
|
231 | + $this->setCallbackArgs( |
|
232 | + array_merge($this->callback_args, array('query_params' => $query_params)) |
|
233 | + ); |
|
234 | + // \EEH_Debug_Tools::printr($this->callback_args, '$this->callback_args', __FILE__, __LINE__); |
|
235 | + $this->setPulled(); |
|
236 | + } |
|
237 | 237 | |
238 | 238 | |
239 | 239 | } |
@@ -20,137 +20,137 @@ |
||
20 | 20 | class CronManager implements JobSchedulerInterface |
21 | 21 | { |
22 | 22 | |
23 | - /** |
|
24 | - * @var $crons Collection |
|
25 | - */ |
|
26 | - private $crons; |
|
27 | - |
|
28 | - |
|
29 | - |
|
30 | - /** |
|
31 | - * CronManager constructor. |
|
32 | - * |
|
33 | - * @param Collection $crons |
|
34 | - * @throws InvalidInterfaceException |
|
35 | - */ |
|
36 | - public function __construct(Collection $crons = null) |
|
37 | - { |
|
38 | - $this->crons = $crons instanceof Collection |
|
39 | - ? $crons |
|
40 | - : new Collection('EventEspresso\core\services\automated_actions\Cron'); |
|
41 | - } |
|
42 | - |
|
43 | - |
|
44 | - |
|
45 | - /** |
|
46 | - * @param string $identifier |
|
47 | - * @return bool |
|
48 | - * @throws InvalidEntityException |
|
49 | - */ |
|
50 | - public function hasJob($identifier) { |
|
51 | - return $this->crons->has($identifier); |
|
52 | - } |
|
53 | - |
|
54 | - |
|
55 | - |
|
56 | - /** |
|
57 | - * @param JobInterface $cron |
|
58 | - * @param string $identifier |
|
59 | - * @return bool |
|
60 | - * @throws InvalidEntityException |
|
61 | - */ |
|
62 | - public function addJob(JobInterface $cron, $identifier) { |
|
63 | - if ($this->crons->has($identifier)) { |
|
64 | - return false; |
|
65 | - } |
|
66 | - return $this->crons->add($cron, $identifier); |
|
67 | - } |
|
68 | - |
|
69 | - |
|
70 | - |
|
71 | - /** |
|
72 | - * @param array $crons |
|
73 | - * @throws InvalidEntityException |
|
74 | - */ |
|
75 | - public function addJobs($crons = array()) { |
|
76 | - $crons = is_array($crons) ? $crons : array($crons); |
|
77 | - foreach ($crons as $identifier => $cron) { |
|
78 | - $this->addJob($cron, $identifier); |
|
79 | - } |
|
80 | - } |
|
81 | - |
|
82 | - |
|
83 | - |
|
84 | - /** |
|
85 | - * @param string $identifier |
|
86 | - * @return Cron|null |
|
87 | - */ |
|
88 | - public function getJob($identifier) |
|
89 | - { |
|
90 | - if ($this->crons->has($identifier)) { |
|
91 | - return $this->crons->get($identifier); |
|
92 | - } |
|
93 | - return null; |
|
94 | - } |
|
95 | - |
|
96 | - |
|
97 | - |
|
98 | - /** |
|
99 | - * @param JobInterface|Cron $cron |
|
100 | - * @return void |
|
101 | - */ |
|
102 | - public function scheduleJob(JobInterface $cron) |
|
103 | - { |
|
104 | - if ( ! $this->nextScheduledJob($cron)) { |
|
105 | - if ($cron->getRecurrence() === '') { |
|
106 | - wp_schedule_single_event( |
|
107 | - $cron->getTimestamp(), |
|
108 | - $cron->getActionHook(), |
|
109 | - $cron->getData() |
|
110 | - ); |
|
111 | - } else { |
|
112 | - wp_schedule_event( |
|
113 | - $cron->getTimestamp(), |
|
114 | - $cron->getRecurrence(), |
|
115 | - $cron->getActionHook(), |
|
116 | - $cron->getData() |
|
117 | - ); |
|
118 | - } |
|
119 | - } |
|
120 | - } |
|
121 | - |
|
122 | - |
|
123 | - |
|
124 | - /** |
|
125 | - * @param JobInterface|Cron $cron |
|
126 | - * @return int |
|
127 | - */ |
|
128 | - public function nextScheduledJob(JobInterface $cron) |
|
129 | - { |
|
130 | - return wp_next_scheduled($cron->getActionHook(), $cron->getData()); |
|
131 | - } |
|
132 | - |
|
133 | - |
|
134 | - |
|
135 | - /** |
|
136 | - * @param JobInterface|Cron $cron |
|
137 | - * @return void |
|
138 | - */ |
|
139 | - public function clearScheduledJob(JobInterface $cron) |
|
140 | - { |
|
141 | - wp_clear_scheduled_hook($cron->getActionHook(), $cron->getData()); |
|
142 | - } |
|
143 | - |
|
144 | - |
|
145 | - |
|
146 | - /** |
|
147 | - * @param JobInterface|Cron $cron |
|
148 | - * @return void |
|
149 | - */ |
|
150 | - public function unscheduleJob(JobInterface $cron) |
|
151 | - { |
|
152 | - wp_unschedule_event($cron->getTimestamp(), $cron->getActionHook(), $cron->getData()); |
|
153 | - } |
|
23 | + /** |
|
24 | + * @var $crons Collection |
|
25 | + */ |
|
26 | + private $crons; |
|
27 | + |
|
28 | + |
|
29 | + |
|
30 | + /** |
|
31 | + * CronManager constructor. |
|
32 | + * |
|
33 | + * @param Collection $crons |
|
34 | + * @throws InvalidInterfaceException |
|
35 | + */ |
|
36 | + public function __construct(Collection $crons = null) |
|
37 | + { |
|
38 | + $this->crons = $crons instanceof Collection |
|
39 | + ? $crons |
|
40 | + : new Collection('EventEspresso\core\services\automated_actions\Cron'); |
|
41 | + } |
|
42 | + |
|
43 | + |
|
44 | + |
|
45 | + /** |
|
46 | + * @param string $identifier |
|
47 | + * @return bool |
|
48 | + * @throws InvalidEntityException |
|
49 | + */ |
|
50 | + public function hasJob($identifier) { |
|
51 | + return $this->crons->has($identifier); |
|
52 | + } |
|
53 | + |
|
54 | + |
|
55 | + |
|
56 | + /** |
|
57 | + * @param JobInterface $cron |
|
58 | + * @param string $identifier |
|
59 | + * @return bool |
|
60 | + * @throws InvalidEntityException |
|
61 | + */ |
|
62 | + public function addJob(JobInterface $cron, $identifier) { |
|
63 | + if ($this->crons->has($identifier)) { |
|
64 | + return false; |
|
65 | + } |
|
66 | + return $this->crons->add($cron, $identifier); |
|
67 | + } |
|
68 | + |
|
69 | + |
|
70 | + |
|
71 | + /** |
|
72 | + * @param array $crons |
|
73 | + * @throws InvalidEntityException |
|
74 | + */ |
|
75 | + public function addJobs($crons = array()) { |
|
76 | + $crons = is_array($crons) ? $crons : array($crons); |
|
77 | + foreach ($crons as $identifier => $cron) { |
|
78 | + $this->addJob($cron, $identifier); |
|
79 | + } |
|
80 | + } |
|
81 | + |
|
82 | + |
|
83 | + |
|
84 | + /** |
|
85 | + * @param string $identifier |
|
86 | + * @return Cron|null |
|
87 | + */ |
|
88 | + public function getJob($identifier) |
|
89 | + { |
|
90 | + if ($this->crons->has($identifier)) { |
|
91 | + return $this->crons->get($identifier); |
|
92 | + } |
|
93 | + return null; |
|
94 | + } |
|
95 | + |
|
96 | + |
|
97 | + |
|
98 | + /** |
|
99 | + * @param JobInterface|Cron $cron |
|
100 | + * @return void |
|
101 | + */ |
|
102 | + public function scheduleJob(JobInterface $cron) |
|
103 | + { |
|
104 | + if ( ! $this->nextScheduledJob($cron)) { |
|
105 | + if ($cron->getRecurrence() === '') { |
|
106 | + wp_schedule_single_event( |
|
107 | + $cron->getTimestamp(), |
|
108 | + $cron->getActionHook(), |
|
109 | + $cron->getData() |
|
110 | + ); |
|
111 | + } else { |
|
112 | + wp_schedule_event( |
|
113 | + $cron->getTimestamp(), |
|
114 | + $cron->getRecurrence(), |
|
115 | + $cron->getActionHook(), |
|
116 | + $cron->getData() |
|
117 | + ); |
|
118 | + } |
|
119 | + } |
|
120 | + } |
|
121 | + |
|
122 | + |
|
123 | + |
|
124 | + /** |
|
125 | + * @param JobInterface|Cron $cron |
|
126 | + * @return int |
|
127 | + */ |
|
128 | + public function nextScheduledJob(JobInterface $cron) |
|
129 | + { |
|
130 | + return wp_next_scheduled($cron->getActionHook(), $cron->getData()); |
|
131 | + } |
|
132 | + |
|
133 | + |
|
134 | + |
|
135 | + /** |
|
136 | + * @param JobInterface|Cron $cron |
|
137 | + * @return void |
|
138 | + */ |
|
139 | + public function clearScheduledJob(JobInterface $cron) |
|
140 | + { |
|
141 | + wp_clear_scheduled_hook($cron->getActionHook(), $cron->getData()); |
|
142 | + } |
|
143 | + |
|
144 | + |
|
145 | + |
|
146 | + /** |
|
147 | + * @param JobInterface|Cron $cron |
|
148 | + * @return void |
|
149 | + */ |
|
150 | + public function unscheduleJob(JobInterface $cron) |
|
151 | + { |
|
152 | + wp_unschedule_event($cron->getTimestamp(), $cron->getActionHook(), $cron->getData()); |
|
153 | + } |
|
154 | 154 | |
155 | 155 | |
156 | 156 |
@@ -16,17 +16,17 @@ |
||
16 | 16 | class TriggerStrategyHourly extends TriggerStrategyCron |
17 | 17 | { |
18 | 18 | |
19 | - const RECURRENCE = 'hourly'; |
|
19 | + const RECURRENCE = 'hourly'; |
|
20 | 20 | |
21 | 21 | |
22 | 22 | |
23 | - /** |
|
24 | - * @return string |
|
25 | - */ |
|
26 | - public function getRecurrence() |
|
27 | - { |
|
28 | - return TriggerStrategyHourly::RECURRENCE; |
|
29 | - } |
|
23 | + /** |
|
24 | + * @return string |
|
25 | + */ |
|
26 | + public function getRecurrence() |
|
27 | + { |
|
28 | + return TriggerStrategyHourly::RECURRENCE; |
|
29 | + } |
|
30 | 30 | |
31 | 31 | |
32 | 32 |
@@ -20,39 +20,39 @@ |
||
20 | 20 | abstract class TriggerStrategyCron extends TriggerStrategy |
21 | 21 | { |
22 | 22 | |
23 | - /** |
|
24 | - * @var JobSchedulerInterface $job_scheduler |
|
25 | - */ |
|
26 | - protected $job_scheduler; |
|
27 | - |
|
28 | - |
|
29 | - |
|
30 | - /** |
|
31 | - * TriggerStrategyCron constructor |
|
32 | - * |
|
33 | - * @param RuleManager $rule_manager |
|
34 | - * @param JobSchedulerInterface $job_scheduler |
|
35 | - * @throws InvalidInterfaceException |
|
36 | - */ |
|
37 | - public function __construct(RuleManager $rule_manager, JobSchedulerInterface $job_scheduler) |
|
38 | - { |
|
39 | - $this->job_scheduler = $job_scheduler; |
|
40 | - parent::__construct($rule_manager); |
|
41 | - } |
|
42 | - |
|
43 | - |
|
44 | - |
|
45 | - /** |
|
46 | - * This allows strategies to set up whatever hooks are necessary to trigger their logic. |
|
47 | - * All overriding methods should call: $this->setAutomatedAction($automated_action) |
|
48 | - * |
|
49 | - * @param AutomatedActionInterface $automated_action |
|
50 | - */ |
|
51 | - public function set(AutomatedActionInterface $automated_action) |
|
52 | - { |
|
53 | - \EEH_Debug_Tools::printr(__FUNCTION__, __CLASS__, __FILE__, __LINE__, 2); |
|
54 | - $this->setAutomatedAction($automated_action); |
|
55 | - } |
|
23 | + /** |
|
24 | + * @var JobSchedulerInterface $job_scheduler |
|
25 | + */ |
|
26 | + protected $job_scheduler; |
|
27 | + |
|
28 | + |
|
29 | + |
|
30 | + /** |
|
31 | + * TriggerStrategyCron constructor |
|
32 | + * |
|
33 | + * @param RuleManager $rule_manager |
|
34 | + * @param JobSchedulerInterface $job_scheduler |
|
35 | + * @throws InvalidInterfaceException |
|
36 | + */ |
|
37 | + public function __construct(RuleManager $rule_manager, JobSchedulerInterface $job_scheduler) |
|
38 | + { |
|
39 | + $this->job_scheduler = $job_scheduler; |
|
40 | + parent::__construct($rule_manager); |
|
41 | + } |
|
42 | + |
|
43 | + |
|
44 | + |
|
45 | + /** |
|
46 | + * This allows strategies to set up whatever hooks are necessary to trigger their logic. |
|
47 | + * All overriding methods should call: $this->setAutomatedAction($automated_action) |
|
48 | + * |
|
49 | + * @param AutomatedActionInterface $automated_action |
|
50 | + */ |
|
51 | + public function set(AutomatedActionInterface $automated_action) |
|
52 | + { |
|
53 | + \EEH_Debug_Tools::printr(__FUNCTION__, __CLASS__, __FILE__, __LINE__, 2); |
|
54 | + $this->setAutomatedAction($automated_action); |
|
55 | + } |
|
56 | 56 | |
57 | 57 | |
58 | 58 |
@@ -26,145 +26,145 @@ |
||
26 | 26 | { |
27 | 27 | |
28 | 28 | |
29 | - /** |
|
30 | - * @var Collection $automated_actions |
|
31 | - */ |
|
32 | - private $automated_actions; |
|
33 | - |
|
34 | - |
|
35 | - /** |
|
36 | - * @var AutomatedActionFactory $automated_action_factory |
|
37 | - */ |
|
38 | - private $automated_action_factory; |
|
39 | - |
|
40 | - /** |
|
41 | - * @type CapabilitiesChecker $capabilities_checker |
|
42 | - */ |
|
43 | - private $capabilities_checker; |
|
44 | - |
|
45 | - |
|
46 | - |
|
47 | - /** |
|
48 | - * AutomatedActionManager constructor |
|
49 | - * |
|
50 | - * @param AutomatedActionFactory $automated_action_factory |
|
51 | - * @param CapabilitiesChecker $capabilities_checker |
|
52 | - * @throws InvalidInterfaceException |
|
53 | - */ |
|
54 | - public function __construct( |
|
55 | - AutomatedActionFactory $automated_action_factory, |
|
56 | - CapabilitiesChecker $capabilities_checker |
|
57 | - ) { |
|
58 | - Benchmark::startTimer(__METHOD__); |
|
59 | - $this->automated_actions = new Collection( |
|
60 | - 'EventEspresso\core\services\automated_actions\AutomatedActionInterface' |
|
61 | - ); |
|
62 | - $this->automated_action_factory = $automated_action_factory; |
|
63 | - $this->capabilities_checker = $capabilities_checker; |
|
64 | - add_action('AHEE__EE_System__initialize', array($this, 'initialize')); |
|
65 | - Benchmark::stopTimer(__METHOD__); |
|
66 | - } |
|
67 | - |
|
68 | - |
|
69 | - |
|
70 | - /** |
|
71 | - * @throws \DomainException |
|
72 | - * @throws InvalidEntityException |
|
73 | - * @throws InsufficientPermissionsException |
|
74 | - * @throws InvalidClassException |
|
75 | - */ |
|
76 | - public function initialize() |
|
77 | - { |
|
78 | - $results = $this->getActiveActions(); |
|
79 | - $this->generateActionObjects($results); |
|
80 | - $this->setTriggers(); |
|
81 | - add_action('shutdown', array($this, 'processActions')); |
|
82 | - } |
|
83 | - |
|
84 | - |
|
85 | - |
|
86 | - /** |
|
87 | - * @return array |
|
88 | - * @throws \DomainException |
|
89 | - */ |
|
90 | - protected function getActiveActions() |
|
91 | - { |
|
92 | - Benchmark::startTimer(__METHOD__); |
|
93 | - global $wpdb; |
|
94 | - $results = $wpdb->get_results( |
|
95 | - "SELECT * FROM {$wpdb->prefix}esp_automated_action WHERE AMA_is_active = 1;" |
|
96 | - ); |
|
97 | - if ($results instanceof \WP_Error) { |
|
98 | - throw new \DomainException( |
|
99 | - $results->get_error_message() |
|
100 | - ); |
|
101 | - } |
|
102 | - $results = is_array($results) ? $results : array($results); |
|
103 | - Benchmark::stopTimer(__METHOD__); |
|
104 | - return $results; |
|
105 | - } |
|
106 | - |
|
107 | - |
|
108 | - |
|
109 | - /** |
|
110 | - * @param array $results |
|
111 | - * @throws InvalidEntityException |
|
112 | - * @throws \DomainException |
|
113 | - */ |
|
114 | - protected function generateActionObjects(array $results) |
|
115 | - { |
|
116 | - Benchmark::startTimer(__METHOD__); |
|
117 | - foreach ($results as $result) { |
|
118 | - $this->automated_actions->add( |
|
119 | - $this->automated_action_factory->create($result), |
|
120 | - $result->AMA_name |
|
121 | - ); |
|
122 | - } |
|
123 | - Benchmark::stopTimer(__METHOD__); |
|
124 | - } |
|
125 | - |
|
126 | - |
|
127 | - |
|
128 | - /** |
|
129 | - * @throws InsufficientPermissionsException |
|
130 | - * @throws InvalidClassException |
|
131 | - */ |
|
132 | - public function setTriggers() |
|
133 | - { |
|
134 | - \EEH_Debug_Tools::printr(__FUNCTION__, __CLASS__, __FILE__, __LINE__, 2); |
|
135 | - Benchmark::startTimer(__METHOD__); |
|
136 | - foreach ($this->automated_actions as $automated_action) { |
|
137 | - /** @var AutomatedActionInterface $automated_action */ |
|
138 | - if ($automated_action instanceof RequiresCapCheckInterface) { |
|
139 | - $this->capabilities_checker->processCapCheck( |
|
140 | - $automated_action->getCapCheck() |
|
141 | - ); |
|
142 | - } |
|
143 | - $automated_action->setTrigger(); |
|
144 | - } |
|
145 | - Benchmark::stopTimer(__METHOD__); |
|
146 | - } |
|
147 | - |
|
148 | - |
|
149 | - |
|
150 | - /** |
|
151 | - * |
|
152 | - */ |
|
153 | - public function processActions() |
|
154 | - { |
|
155 | - \EEH_Debug_Tools::printr('', 'SHUTDOWN HOOK', __FILE__, __LINE__, 2); |
|
156 | - \EEH_Debug_Tools::printr(__FUNCTION__, __CLASS__, __FILE__, __LINE__, 2); |
|
157 | - Benchmark::startTimer(__METHOD__); |
|
158 | - foreach ($this->automated_actions as $automated_action) { |
|
159 | - /** @var AutomatedActionInterface $automated_action */ |
|
160 | - if ( ! $automated_action->triggerPulled() || $automated_action->hasRun()) { |
|
161 | - continue; |
|
162 | - } |
|
163 | - $automated_action->process(); |
|
164 | - } |
|
165 | - Benchmark::stopTimer(__METHOD__); |
|
166 | - Benchmark::displayResults(); |
|
167 | - } |
|
29 | + /** |
|
30 | + * @var Collection $automated_actions |
|
31 | + */ |
|
32 | + private $automated_actions; |
|
33 | + |
|
34 | + |
|
35 | + /** |
|
36 | + * @var AutomatedActionFactory $automated_action_factory |
|
37 | + */ |
|
38 | + private $automated_action_factory; |
|
39 | + |
|
40 | + /** |
|
41 | + * @type CapabilitiesChecker $capabilities_checker |
|
42 | + */ |
|
43 | + private $capabilities_checker; |
|
44 | + |
|
45 | + |
|
46 | + |
|
47 | + /** |
|
48 | + * AutomatedActionManager constructor |
|
49 | + * |
|
50 | + * @param AutomatedActionFactory $automated_action_factory |
|
51 | + * @param CapabilitiesChecker $capabilities_checker |
|
52 | + * @throws InvalidInterfaceException |
|
53 | + */ |
|
54 | + public function __construct( |
|
55 | + AutomatedActionFactory $automated_action_factory, |
|
56 | + CapabilitiesChecker $capabilities_checker |
|
57 | + ) { |
|
58 | + Benchmark::startTimer(__METHOD__); |
|
59 | + $this->automated_actions = new Collection( |
|
60 | + 'EventEspresso\core\services\automated_actions\AutomatedActionInterface' |
|
61 | + ); |
|
62 | + $this->automated_action_factory = $automated_action_factory; |
|
63 | + $this->capabilities_checker = $capabilities_checker; |
|
64 | + add_action('AHEE__EE_System__initialize', array($this, 'initialize')); |
|
65 | + Benchmark::stopTimer(__METHOD__); |
|
66 | + } |
|
67 | + |
|
68 | + |
|
69 | + |
|
70 | + /** |
|
71 | + * @throws \DomainException |
|
72 | + * @throws InvalidEntityException |
|
73 | + * @throws InsufficientPermissionsException |
|
74 | + * @throws InvalidClassException |
|
75 | + */ |
|
76 | + public function initialize() |
|
77 | + { |
|
78 | + $results = $this->getActiveActions(); |
|
79 | + $this->generateActionObjects($results); |
|
80 | + $this->setTriggers(); |
|
81 | + add_action('shutdown', array($this, 'processActions')); |
|
82 | + } |
|
83 | + |
|
84 | + |
|
85 | + |
|
86 | + /** |
|
87 | + * @return array |
|
88 | + * @throws \DomainException |
|
89 | + */ |
|
90 | + protected function getActiveActions() |
|
91 | + { |
|
92 | + Benchmark::startTimer(__METHOD__); |
|
93 | + global $wpdb; |
|
94 | + $results = $wpdb->get_results( |
|
95 | + "SELECT * FROM {$wpdb->prefix}esp_automated_action WHERE AMA_is_active = 1;" |
|
96 | + ); |
|
97 | + if ($results instanceof \WP_Error) { |
|
98 | + throw new \DomainException( |
|
99 | + $results->get_error_message() |
|
100 | + ); |
|
101 | + } |
|
102 | + $results = is_array($results) ? $results : array($results); |
|
103 | + Benchmark::stopTimer(__METHOD__); |
|
104 | + return $results; |
|
105 | + } |
|
106 | + |
|
107 | + |
|
108 | + |
|
109 | + /** |
|
110 | + * @param array $results |
|
111 | + * @throws InvalidEntityException |
|
112 | + * @throws \DomainException |
|
113 | + */ |
|
114 | + protected function generateActionObjects(array $results) |
|
115 | + { |
|
116 | + Benchmark::startTimer(__METHOD__); |
|
117 | + foreach ($results as $result) { |
|
118 | + $this->automated_actions->add( |
|
119 | + $this->automated_action_factory->create($result), |
|
120 | + $result->AMA_name |
|
121 | + ); |
|
122 | + } |
|
123 | + Benchmark::stopTimer(__METHOD__); |
|
124 | + } |
|
125 | + |
|
126 | + |
|
127 | + |
|
128 | + /** |
|
129 | + * @throws InsufficientPermissionsException |
|
130 | + * @throws InvalidClassException |
|
131 | + */ |
|
132 | + public function setTriggers() |
|
133 | + { |
|
134 | + \EEH_Debug_Tools::printr(__FUNCTION__, __CLASS__, __FILE__, __LINE__, 2); |
|
135 | + Benchmark::startTimer(__METHOD__); |
|
136 | + foreach ($this->automated_actions as $automated_action) { |
|
137 | + /** @var AutomatedActionInterface $automated_action */ |
|
138 | + if ($automated_action instanceof RequiresCapCheckInterface) { |
|
139 | + $this->capabilities_checker->processCapCheck( |
|
140 | + $automated_action->getCapCheck() |
|
141 | + ); |
|
142 | + } |
|
143 | + $automated_action->setTrigger(); |
|
144 | + } |
|
145 | + Benchmark::stopTimer(__METHOD__); |
|
146 | + } |
|
147 | + |
|
148 | + |
|
149 | + |
|
150 | + /** |
|
151 | + * |
|
152 | + */ |
|
153 | + public function processActions() |
|
154 | + { |
|
155 | + \EEH_Debug_Tools::printr('', 'SHUTDOWN HOOK', __FILE__, __LINE__, 2); |
|
156 | + \EEH_Debug_Tools::printr(__FUNCTION__, __CLASS__, __FILE__, __LINE__, 2); |
|
157 | + Benchmark::startTimer(__METHOD__); |
|
158 | + foreach ($this->automated_actions as $automated_action) { |
|
159 | + /** @var AutomatedActionInterface $automated_action */ |
|
160 | + if ( ! $automated_action->triggerPulled() || $automated_action->hasRun()) { |
|
161 | + continue; |
|
162 | + } |
|
163 | + $automated_action->process(); |
|
164 | + } |
|
165 | + Benchmark::stopTimer(__METHOD__); |
|
166 | + Benchmark::displayResults(); |
|
167 | + } |
|
168 | 168 | |
169 | 169 | |
170 | 170 | } |
@@ -10,56 +10,56 @@ |
||
10 | 10 | interface JobSchedulerInterface |
11 | 11 | { |
12 | 12 | |
13 | - /** |
|
14 | - * @param string $identifier |
|
15 | - * @return bool |
|
16 | - * @throws InvalidEntityException |
|
17 | - */ |
|
18 | - public function hasJob($identifier); |
|
13 | + /** |
|
14 | + * @param string $identifier |
|
15 | + * @return bool |
|
16 | + * @throws InvalidEntityException |
|
17 | + */ |
|
18 | + public function hasJob($identifier); |
|
19 | 19 | |
20 | - /** |
|
21 | - * @param JobInterface $job |
|
22 | - * @param string $identifier |
|
23 | - * @return bool |
|
24 | - * @throws InvalidEntityException |
|
25 | - */ |
|
26 | - public function addJob(JobInterface $job, $identifier); |
|
20 | + /** |
|
21 | + * @param JobInterface $job |
|
22 | + * @param string $identifier |
|
23 | + * @return bool |
|
24 | + * @throws InvalidEntityException |
|
25 | + */ |
|
26 | + public function addJob(JobInterface $job, $identifier); |
|
27 | 27 | |
28 | - /** |
|
29 | - * @param array $crons |
|
30 | - * @throws InvalidEntityException |
|
31 | - */ |
|
32 | - public function addJobs($crons = array()); |
|
28 | + /** |
|
29 | + * @param array $crons |
|
30 | + * @throws InvalidEntityException |
|
31 | + */ |
|
32 | + public function addJobs($crons = array()); |
|
33 | 33 | |
34 | - /** |
|
35 | - * @param string $identifier |
|
36 | - * @return JobInterface|null |
|
37 | - */ |
|
38 | - public function getJob($identifier); |
|
34 | + /** |
|
35 | + * @param string $identifier |
|
36 | + * @return JobInterface|null |
|
37 | + */ |
|
38 | + public function getJob($identifier); |
|
39 | 39 | |
40 | - /** |
|
41 | - * @param JobInterface $job |
|
42 | - * @return void |
|
43 | - */ |
|
44 | - public function scheduleJob(JobInterface $job); |
|
40 | + /** |
|
41 | + * @param JobInterface $job |
|
42 | + * @return void |
|
43 | + */ |
|
44 | + public function scheduleJob(JobInterface $job); |
|
45 | 45 | |
46 | - /** |
|
47 | - * @param JobInterface $job |
|
48 | - * @return int |
|
49 | - */ |
|
50 | - public function nextScheduledJob(JobInterface $job); |
|
46 | + /** |
|
47 | + * @param JobInterface $job |
|
48 | + * @return int |
|
49 | + */ |
|
50 | + public function nextScheduledJob(JobInterface $job); |
|
51 | 51 | |
52 | - /** |
|
53 | - * @param JobInterface $job |
|
54 | - * @return void |
|
55 | - */ |
|
56 | - public function clearScheduledJob(JobInterface $job); |
|
52 | + /** |
|
53 | + * @param JobInterface $job |
|
54 | + * @return void |
|
55 | + */ |
|
56 | + public function clearScheduledJob(JobInterface $job); |
|
57 | 57 | |
58 | - /** |
|
59 | - * @param JobInterface $job |
|
60 | - * @return void |
|
61 | - */ |
|
62 | - public function unscheduleJob(JobInterface $job); |
|
58 | + /** |
|
59 | + * @param JobInterface $job |
|
60 | + * @return void |
|
61 | + */ |
|
62 | + public function unscheduleJob(JobInterface $job); |
|
63 | 63 | |
64 | 64 | } |
65 | 65 | // End of file JobSchedulerInterface.php |