@@ -2,7 +2,7 @@ discard block |
||
2 | 2 | use EventEspresso\core\services\shortcodes\ShortcodesManager; |
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 | |
@@ -19,1428 +19,1428 @@ discard block |
||
19 | 19 | { |
20 | 20 | |
21 | 21 | |
22 | - /** |
|
23 | - * indicates this is a 'normal' request. Ie, not activation, nor upgrade, nor activation. |
|
24 | - * So examples of this would be a normal GET request on the frontend or backend, or a POST, etc |
|
25 | - */ |
|
26 | - const req_type_normal = 0; |
|
27 | - |
|
28 | - /** |
|
29 | - * Indicates this is a brand new installation of EE so we should install |
|
30 | - * tables and default data etc |
|
31 | - */ |
|
32 | - const req_type_new_activation = 1; |
|
33 | - |
|
34 | - /** |
|
35 | - * we've detected that EE has been reactivated (or EE was activated during maintenance mode, |
|
36 | - * and we just exited maintenance mode). We MUST check the database is setup properly |
|
37 | - * and that default data is setup too |
|
38 | - */ |
|
39 | - const req_type_reactivation = 2; |
|
40 | - |
|
41 | - /** |
|
42 | - * indicates that EE has been upgraded since its previous request. |
|
43 | - * We may have data migration scripts to call and will want to trigger maintenance mode |
|
44 | - */ |
|
45 | - const req_type_upgrade = 3; |
|
46 | - |
|
47 | - /** |
|
48 | - * TODO will detect that EE has been DOWNGRADED. We probably don't want to run in this case... |
|
49 | - */ |
|
50 | - const req_type_downgrade = 4; |
|
51 | - |
|
52 | - /** |
|
53 | - * @deprecated since version 4.6.0.dev.006 |
|
54 | - * Now whenever a new_activation is detected the request type is still just |
|
55 | - * new_activation (same for reactivation, upgrade, downgrade etc), but if we'r ein maintenance mode |
|
56 | - * EE_System::initialize_db_if_no_migrations_required and EE_Addon::initialize_db_if_no_migrations_required |
|
57 | - * will instead enqueue that EE plugin's db initialization for when we're taken out of maintenance mode. |
|
58 | - * (Specifically, when the migration manager indicates migrations are finished |
|
59 | - * EE_Data_Migration_Manager::initialize_db_for_enqueued_ee_plugins() will be called) |
|
60 | - */ |
|
61 | - const req_type_activation_but_not_installed = 5; |
|
62 | - |
|
63 | - /** |
|
64 | - * option prefix for recording the activation history (like core's "espresso_db_update") of addons |
|
65 | - */ |
|
66 | - const addon_activation_history_option_prefix = 'ee_addon_activation_history_'; |
|
67 | - |
|
68 | - |
|
69 | - /** |
|
70 | - * instance of the EE_System object |
|
71 | - * |
|
72 | - * @var $_instance |
|
73 | - * @access private |
|
74 | - */ |
|
75 | - private static $_instance = null; |
|
76 | - |
|
77 | - /** |
|
78 | - * @type EE_Registry $Registry |
|
79 | - * @access protected |
|
80 | - */ |
|
81 | - protected $registry; |
|
82 | - |
|
83 | - /** |
|
84 | - * Stores which type of request this is, options being one of the constants on EE_System starting with req_type_*. |
|
85 | - * It can be a brand-new activation, a reactivation, an upgrade, a downgrade, or a normal request. |
|
86 | - * |
|
87 | - * @var int |
|
88 | - */ |
|
89 | - private $_req_type; |
|
90 | - |
|
91 | - /** |
|
92 | - * Whether or not there was a non-micro version change in EE core version during this request |
|
93 | - * |
|
94 | - * @var boolean |
|
95 | - */ |
|
96 | - private $_major_version_change = false; |
|
97 | - |
|
98 | - |
|
99 | - |
|
100 | - /** |
|
101 | - * @singleton method used to instantiate class object |
|
102 | - * @access public |
|
103 | - * @param \EE_Registry $Registry |
|
104 | - * @return \EE_System |
|
105 | - */ |
|
106 | - public static function instance(EE_Registry $Registry = null) |
|
107 | - { |
|
108 | - // check if class object is instantiated |
|
109 | - if ( ! self::$_instance instanceof EE_System) { |
|
110 | - self::$_instance = new self($Registry); |
|
111 | - } |
|
112 | - return self::$_instance; |
|
113 | - } |
|
114 | - |
|
115 | - |
|
116 | - |
|
117 | - /** |
|
118 | - * resets the instance and returns it |
|
119 | - * |
|
120 | - * @return EE_System |
|
121 | - */ |
|
122 | - public static function reset() |
|
123 | - { |
|
124 | - self::$_instance->_req_type = null; |
|
125 | - //make sure none of the old hooks are left hanging around |
|
126 | - remove_all_actions('AHEE__EE_System__perform_activations_upgrades_and_migrations'); |
|
127 | - //we need to reset the migration manager in order for it to detect DMSs properly |
|
128 | - EE_Data_Migration_Manager::reset(); |
|
129 | - self::instance()->detect_activations_or_upgrades(); |
|
130 | - self::instance()->perform_activations_upgrades_and_migrations(); |
|
131 | - return self::instance(); |
|
132 | - } |
|
133 | - |
|
134 | - |
|
135 | - |
|
136 | - /** |
|
137 | - * sets hooks for running rest of system |
|
138 | - * provides "AHEE__EE_System__construct__complete" hook for EE Addons to use as their starting point |
|
139 | - * starting EE Addons from any other point may lead to problems |
|
140 | - * |
|
141 | - * @access private |
|
142 | - * @param \EE_Registry $Registry |
|
143 | - */ |
|
144 | - private function __construct(EE_Registry $Registry) |
|
145 | - { |
|
146 | - $this->registry = $Registry; |
|
147 | - do_action('AHEE__EE_System__construct__begin', $this); |
|
148 | - // allow addons to load first so that they can register autoloaders, set hooks for running DMS's, etc |
|
149 | - add_action('AHEE__EE_Bootstrap__load_espresso_addons', array($this, 'load_espresso_addons')); |
|
150 | - // when an ee addon is activated, we want to call the core hook(s) again |
|
151 | - // because the newly-activated addon didn't get a chance to run at all |
|
152 | - add_action('activate_plugin', array($this, 'load_espresso_addons'), 1); |
|
153 | - // detect whether install or upgrade |
|
154 | - add_action('AHEE__EE_Bootstrap__detect_activations_or_upgrades', array($this, 'detect_activations_or_upgrades'), |
|
155 | - 3); |
|
156 | - // load EE_Config, EE_Textdomain, etc |
|
157 | - add_action('AHEE__EE_Bootstrap__load_core_configuration', array($this, 'load_core_configuration'), 5); |
|
158 | - // load EE_Config, EE_Textdomain, etc |
|
159 | - add_action('AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets', |
|
160 | - array($this, 'register_shortcodes_modules_and_widgets'), 7); |
|
161 | - // you wanna get going? I wanna get going... let's get going! |
|
162 | - add_action('AHEE__EE_Bootstrap__brew_espresso', array($this, 'brew_espresso'), 9); |
|
163 | - //other housekeeping |
|
164 | - //exclude EE critical pages from wp_list_pages |
|
165 | - add_filter('wp_list_pages_excludes', array($this, 'remove_pages_from_wp_list_pages'), 10); |
|
166 | - // ALL EE Addons should use the following hook point to attach their initial setup too |
|
167 | - // it's extremely important for EE Addons to register any class autoloaders so that they can be available when the EE_Config loads |
|
168 | - do_action('AHEE__EE_System__construct__complete', $this); |
|
169 | - } |
|
170 | - |
|
171 | - |
|
172 | - |
|
173 | - /** |
|
174 | - * load_espresso_addons |
|
175 | - * allow addons to load first so that they can set hooks for running DMS's, etc |
|
176 | - * this is hooked into both: |
|
177 | - * 'AHEE__EE_Bootstrap__load_core_configuration' |
|
178 | - * which runs during the WP 'plugins_loaded' action at priority 5 |
|
179 | - * and the WP 'activate_plugin' hookpoint |
|
180 | - * |
|
181 | - * @access public |
|
182 | - * @return void |
|
183 | - */ |
|
184 | - public function load_espresso_addons() |
|
185 | - { |
|
186 | - // set autoloaders for all of the classes implementing EEI_Plugin_API |
|
187 | - // which provide helpers for EE plugin authors to more easily register certain components with EE. |
|
188 | - EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'plugin_api'); |
|
189 | - do_action('AHEE__EE_System__load_espresso_addons'); |
|
190 | - //if the WP API basic auth plugin isn't already loaded, load it now. |
|
191 | - //We want it for mobile apps. Just include the entire plugin |
|
192 | - //also, don't load the basic auth when a plugin is getting activated, because |
|
193 | - //it could be the basic auth plugin, and it doesn't check if its methods are already defined |
|
194 | - //and causes a fatal error |
|
195 | - if ( ! function_exists('json_basic_auth_handler') |
|
196 | - && ! function_exists('json_basic_auth_error') |
|
197 | - && ! ( |
|
198 | - isset($_GET['action']) |
|
199 | - && in_array($_GET['action'], array('activate', 'activate-selected')) |
|
200 | - ) |
|
201 | - && ! ( |
|
202 | - isset($_GET['activate']) |
|
203 | - && $_GET['activate'] === 'true' |
|
204 | - ) |
|
205 | - ) { |
|
206 | - include_once EE_THIRD_PARTY . 'wp-api-basic-auth' . DS . 'basic-auth.php'; |
|
207 | - } |
|
208 | - $this->_maybe_brew_regular(); |
|
209 | - do_action('AHEE__EE_System__load_espresso_addons__complete'); |
|
210 | - |
|
211 | - } |
|
212 | - |
|
213 | - |
|
214 | - |
|
215 | - /** |
|
216 | - * The purpose of this method is to simply check for a file named "caffeinated/brewing_regular.php" for any hooks |
|
217 | - * that need to be setup before our EE_System launches. |
|
218 | - * |
|
219 | - * @return void |
|
220 | - */ |
|
221 | - private function _maybe_brew_regular() |
|
222 | - { |
|
223 | - if (( ! defined('EE_DECAF') || EE_DECAF !== true) && is_readable(EE_CAFF_PATH . 'brewing_regular.php')) { |
|
224 | - require_once EE_CAFF_PATH . 'brewing_regular.php'; |
|
225 | - } |
|
226 | - } |
|
227 | - |
|
228 | - |
|
229 | - |
|
230 | - /** |
|
231 | - * detect_activations_or_upgrades |
|
232 | - * Checks for activation or upgrade of core first; |
|
233 | - * then also checks if any registered addons have been activated or upgraded |
|
234 | - * This is hooked into 'AHEE__EE_Bootstrap__detect_activations_or_upgrades' |
|
235 | - * which runs during the WP 'plugins_loaded' action at priority 3 |
|
236 | - * |
|
237 | - * @access public |
|
238 | - * @return void |
|
239 | - */ |
|
240 | - public function detect_activations_or_upgrades() |
|
241 | - { |
|
242 | - //first off: let's make sure to handle core |
|
243 | - $this->detect_if_activation_or_upgrade(); |
|
244 | - foreach ($this->registry->addons as $addon) { |
|
245 | - //detect teh request type for that addon |
|
246 | - $addon->detect_activation_or_upgrade(); |
|
247 | - } |
|
248 | - } |
|
249 | - |
|
250 | - |
|
251 | - |
|
252 | - /** |
|
253 | - * detect_if_activation_or_upgrade |
|
254 | - * Takes care of detecting whether this is a brand new install or code upgrade, |
|
255 | - * and either setting up the DB or setting up maintenance mode etc. |
|
256 | - * |
|
257 | - * @access public |
|
258 | - * @return void |
|
259 | - */ |
|
260 | - public function detect_if_activation_or_upgrade() |
|
261 | - { |
|
262 | - do_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin'); |
|
263 | - // load M-Mode class |
|
264 | - $this->registry->load_core('Maintenance_Mode'); |
|
265 | - // check if db has been updated, or if its a brand-new installation |
|
266 | - $espresso_db_update = $this->fix_espresso_db_upgrade_option(); |
|
267 | - $request_type = $this->detect_req_type($espresso_db_update); |
|
268 | - //EEH_Debug_Tools::printr( $request_type, '$request_type', __FILE__, __LINE__ ); |
|
269 | - switch ($request_type) { |
|
270 | - case EE_System::req_type_new_activation: |
|
271 | - do_action('AHEE__EE_System__detect_if_activation_or_upgrade__new_activation'); |
|
272 | - $this->_handle_core_version_change($espresso_db_update); |
|
273 | - break; |
|
274 | - case EE_System::req_type_reactivation: |
|
275 | - do_action('AHEE__EE_System__detect_if_activation_or_upgrade__reactivation'); |
|
276 | - $this->_handle_core_version_change($espresso_db_update); |
|
277 | - break; |
|
278 | - case EE_System::req_type_upgrade: |
|
279 | - do_action('AHEE__EE_System__detect_if_activation_or_upgrade__upgrade'); |
|
280 | - //migrations may be required now that we've upgraded |
|
281 | - EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old(); |
|
282 | - $this->_handle_core_version_change($espresso_db_update); |
|
283 | - // echo "done upgrade";die; |
|
284 | - break; |
|
285 | - case EE_System::req_type_downgrade: |
|
286 | - do_action('AHEE__EE_System__detect_if_activation_or_upgrade__downgrade'); |
|
287 | - //its possible migrations are no longer required |
|
288 | - EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old(); |
|
289 | - $this->_handle_core_version_change($espresso_db_update); |
|
290 | - break; |
|
291 | - case EE_System::req_type_normal: |
|
292 | - default: |
|
293 | - // $this->_maybe_redirect_to_ee_about(); |
|
294 | - break; |
|
295 | - } |
|
296 | - do_action('AHEE__EE_System__detect_if_activation_or_upgrade__complete'); |
|
297 | - } |
|
298 | - |
|
299 | - |
|
300 | - |
|
301 | - /** |
|
302 | - * Updates the list of installed versions and sets hooks for |
|
303 | - * initializing the database later during the request |
|
304 | - * |
|
305 | - * @param array $espresso_db_update |
|
306 | - */ |
|
307 | - protected function _handle_core_version_change($espresso_db_update) |
|
308 | - { |
|
309 | - $this->update_list_of_installed_versions($espresso_db_update); |
|
310 | - //get ready to verify the DB is ok (provided we aren't in maintenance mode, of course) |
|
311 | - add_action('AHEE__EE_System__perform_activations_upgrades_and_migrations', |
|
312 | - array($this, 'initialize_db_if_no_migrations_required')); |
|
313 | - } |
|
314 | - |
|
315 | - |
|
316 | - |
|
317 | - /** |
|
318 | - * standardizes the wp option 'espresso_db_upgrade' which actually stores |
|
319 | - * information about what versions of EE have been installed and activated, |
|
320 | - * NOT necessarily the state of the database |
|
321 | - * |
|
322 | - * @param null $espresso_db_update |
|
323 | - * @internal param array $espresso_db_update_value the value of the WordPress option. If not supplied, fetches it |
|
324 | - * from the options table |
|
325 | - * @return array the correct value of 'espresso_db_upgrade', after saving it, if it needed correction |
|
326 | - */ |
|
327 | - private function fix_espresso_db_upgrade_option($espresso_db_update = null) |
|
328 | - { |
|
329 | - do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__begin', $espresso_db_update); |
|
330 | - if ( ! $espresso_db_update) { |
|
331 | - $espresso_db_update = get_option('espresso_db_update'); |
|
332 | - } |
|
333 | - // check that option is an array |
|
334 | - if ( ! is_array($espresso_db_update)) { |
|
335 | - // if option is FALSE, then it never existed |
|
336 | - if ($espresso_db_update === false) { |
|
337 | - // make $espresso_db_update an array and save option with autoload OFF |
|
338 | - $espresso_db_update = array(); |
|
339 | - add_option('espresso_db_update', $espresso_db_update, '', 'no'); |
|
340 | - } else { |
|
341 | - // option is NOT FALSE but also is NOT an array, so make it an array and save it |
|
342 | - $espresso_db_update = array($espresso_db_update => array()); |
|
343 | - update_option('espresso_db_update', $espresso_db_update); |
|
344 | - } |
|
345 | - } else { |
|
346 | - $corrected_db_update = array(); |
|
347 | - //if IS an array, but is it an array where KEYS are version numbers, and values are arrays? |
|
348 | - foreach ($espresso_db_update as $should_be_version_string => $should_be_array) { |
|
349 | - if (is_int($should_be_version_string) && ! is_array($should_be_array)) { |
|
350 | - //the key is an int, and the value IS NOT an array |
|
351 | - //so it must be numerically-indexed, where values are versions installed... |
|
352 | - //fix it! |
|
353 | - $version_string = $should_be_array; |
|
354 | - $corrected_db_update[$version_string] = array('unknown-date'); |
|
355 | - } else { |
|
356 | - //ok it checks out |
|
357 | - $corrected_db_update[$should_be_version_string] = $should_be_array; |
|
358 | - } |
|
359 | - } |
|
360 | - $espresso_db_update = $corrected_db_update; |
|
361 | - update_option('espresso_db_update', $espresso_db_update); |
|
362 | - } |
|
363 | - do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__complete', $espresso_db_update); |
|
364 | - return $espresso_db_update; |
|
365 | - } |
|
366 | - |
|
367 | - |
|
368 | - |
|
369 | - /** |
|
370 | - * Does the traditional work of setting up the plugin's database and adding default data. |
|
371 | - * If migration script/process did not exist, this is what would happen on every activation/reactivation/upgrade. |
|
372 | - * NOTE: if we're in maintenance mode (which would be the case if we detect there are data |
|
373 | - * migration scripts that need to be run and a version change happens), enqueues core for database initialization, |
|
374 | - * so that it will be done when migrations are finished |
|
375 | - * |
|
376 | - * @param boolean $initialize_addons_too if true, we double-check addons' database tables etc too; |
|
377 | - * @param boolean $verify_schema if true will re-check the database tables have the correct schema. |
|
378 | - * This is a resource-intensive job |
|
379 | - * so we prefer to only do it when necessary |
|
380 | - * @return void |
|
381 | - */ |
|
382 | - public function initialize_db_if_no_migrations_required($initialize_addons_too = false, $verify_schema = true) |
|
383 | - { |
|
384 | - $request_type = $this->detect_req_type(); |
|
385 | - //only initialize system if we're not in maintenance mode. |
|
386 | - if (EE_Maintenance_Mode::instance()->level() != EE_Maintenance_Mode::level_2_complete_maintenance) { |
|
387 | - update_option('ee_flush_rewrite_rules', true); |
|
388 | - if ($verify_schema) { |
|
389 | - EEH_Activation::initialize_db_and_folders(); |
|
390 | - } |
|
391 | - EEH_Activation::initialize_db_content(); |
|
392 | - EEH_Activation::system_initialization(); |
|
393 | - if ($initialize_addons_too) { |
|
394 | - $this->initialize_addons(); |
|
395 | - } |
|
396 | - } else { |
|
397 | - EE_Data_Migration_Manager::instance()->enqueue_db_initialization_for('Core'); |
|
398 | - } |
|
399 | - if ($request_type === EE_System::req_type_new_activation |
|
400 | - || $request_type === EE_System::req_type_reactivation |
|
401 | - || ( |
|
402 | - $request_type === EE_System::req_type_upgrade |
|
403 | - && $this->is_major_version_change() |
|
404 | - ) |
|
405 | - ) { |
|
406 | - add_action('AHEE__EE_System__initialize_last', array($this, 'redirect_to_about_ee'), 9); |
|
407 | - } |
|
408 | - } |
|
409 | - |
|
410 | - |
|
411 | - |
|
412 | - /** |
|
413 | - * Initializes the db for all registered addons |
|
414 | - */ |
|
415 | - public function initialize_addons() |
|
416 | - { |
|
417 | - //foreach registered addon, make sure its db is up-to-date too |
|
418 | - foreach ($this->registry->addons as $addon) { |
|
419 | - $addon->initialize_db_if_no_migrations_required(); |
|
420 | - } |
|
421 | - } |
|
422 | - |
|
423 | - |
|
424 | - |
|
425 | - /** |
|
426 | - * Adds the current code version to the saved wp option which stores a list of all ee versions ever installed. |
|
427 | - * |
|
428 | - * @param array $version_history |
|
429 | - * @param string $current_version_to_add version to be added to the version history |
|
430 | - * @return boolean success as to whether or not this option was changed |
|
431 | - */ |
|
432 | - public function update_list_of_installed_versions($version_history = null, $current_version_to_add = null) |
|
433 | - { |
|
434 | - if ( ! $version_history) { |
|
435 | - $version_history = $this->fix_espresso_db_upgrade_option($version_history); |
|
436 | - } |
|
437 | - if ($current_version_to_add == null) { |
|
438 | - $current_version_to_add = espresso_version(); |
|
439 | - } |
|
440 | - $version_history[$current_version_to_add][] = date('Y-m-d H:i:s', time()); |
|
441 | - // re-save |
|
442 | - return update_option('espresso_db_update', $version_history); |
|
443 | - } |
|
444 | - |
|
445 | - |
|
446 | - |
|
447 | - /** |
|
448 | - * Detects if the current version indicated in the has existed in the list of |
|
449 | - * previously-installed versions of EE (espresso_db_update). Does NOT modify it (ie, no side-effect) |
|
450 | - * |
|
451 | - * @param array $espresso_db_update array from the wp option stored under the name 'espresso_db_update'. |
|
452 | - * If not supplied, fetches it from the options table. |
|
453 | - * Also, caches its result so later parts of the code can also know whether |
|
454 | - * there's been an update or not. This way we can add the current version to |
|
455 | - * espresso_db_update, but still know if this is a new install or not |
|
456 | - * @return int one of the constants on EE_System::req_type_ |
|
457 | - */ |
|
458 | - public function detect_req_type($espresso_db_update = null) |
|
459 | - { |
|
460 | - if ($this->_req_type === null) { |
|
461 | - $espresso_db_update = ! empty($espresso_db_update) ? $espresso_db_update |
|
462 | - : $this->fix_espresso_db_upgrade_option(); |
|
463 | - $this->_req_type = $this->detect_req_type_given_activation_history($espresso_db_update, |
|
464 | - 'ee_espresso_activation', espresso_version()); |
|
465 | - $this->_major_version_change = $this->_detect_major_version_change($espresso_db_update); |
|
466 | - } |
|
467 | - return $this->_req_type; |
|
468 | - } |
|
469 | - |
|
470 | - |
|
471 | - |
|
472 | - /** |
|
473 | - * Returns whether or not there was a non-micro version change (ie, change in either |
|
474 | - * the first or second number in the version. Eg 4.9.0.rc.001 to 4.10.0.rc.000, |
|
475 | - * but not 4.9.0.rc.0001 to 4.9.1.rc.0001 |
|
476 | - * |
|
477 | - * @param $activation_history |
|
478 | - * @return bool |
|
479 | - */ |
|
480 | - protected function _detect_major_version_change($activation_history) |
|
481 | - { |
|
482 | - $previous_version = EE_System::_get_most_recently_active_version_from_activation_history($activation_history); |
|
483 | - $previous_version_parts = explode('.', $previous_version); |
|
484 | - $current_version_parts = explode('.', espresso_version()); |
|
485 | - return isset($previous_version_parts[0], $previous_version_parts[1], $current_version_parts[0], $current_version_parts[1]) |
|
486 | - && ($previous_version_parts[0] !== $current_version_parts[0] |
|
487 | - || $previous_version_parts[1] !== $current_version_parts[1] |
|
488 | - ); |
|
489 | - } |
|
490 | - |
|
491 | - |
|
492 | - |
|
493 | - /** |
|
494 | - * Returns true if either the major or minor version of EE changed during this request. |
|
495 | - * Eg 4.9.0.rc.001 to 4.10.0.rc.000, but not 4.9.0.rc.0001 to 4.9.1.rc.0001 |
|
496 | - * |
|
497 | - * @return bool |
|
498 | - */ |
|
499 | - public function is_major_version_change() |
|
500 | - { |
|
501 | - return $this->_major_version_change; |
|
502 | - } |
|
503 | - |
|
504 | - |
|
505 | - |
|
506 | - /** |
|
507 | - * Determines the request type for any ee addon, given three piece of info: the current array of activation |
|
508 | - * histories (for core that' 'espresso_db_update' wp option); the name of the wordpress option which is temporarily |
|
509 | - * set upon activation of the plugin (for core it's 'ee_espresso_activation'); and the version that this plugin was |
|
510 | - * just activated to (for core that will always be espresso_version()) |
|
511 | - * |
|
512 | - * @param array $activation_history_for_addon the option's value which stores the activation history for this |
|
513 | - * ee plugin. for core that's 'espresso_db_update' |
|
514 | - * @param string $activation_indicator_option_name the name of the wordpress option that is temporarily set to |
|
515 | - * indicate that this plugin was just activated |
|
516 | - * @param string $version_to_upgrade_to the version that was just upgraded to (for core that will be |
|
517 | - * espresso_version()) |
|
518 | - * @return int one of the constants on EE_System::req_type_* |
|
519 | - */ |
|
520 | - public static function detect_req_type_given_activation_history( |
|
521 | - $activation_history_for_addon, |
|
522 | - $activation_indicator_option_name, |
|
523 | - $version_to_upgrade_to |
|
524 | - ) { |
|
525 | - $version_is_higher = self::_new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to); |
|
526 | - if ($activation_history_for_addon) { |
|
527 | - //it exists, so this isn't a completely new install |
|
528 | - //check if this version already in that list of previously installed versions |
|
529 | - if ( ! isset($activation_history_for_addon[$version_to_upgrade_to])) { |
|
530 | - //it a version we haven't seen before |
|
531 | - if ($version_is_higher === 1) { |
|
532 | - $req_type = EE_System::req_type_upgrade; |
|
533 | - } else { |
|
534 | - $req_type = EE_System::req_type_downgrade; |
|
535 | - } |
|
536 | - delete_option($activation_indicator_option_name); |
|
537 | - } else { |
|
538 | - // its not an update. maybe a reactivation? |
|
539 | - if (get_option($activation_indicator_option_name, false)) { |
|
540 | - if ($version_is_higher === -1) { |
|
541 | - $req_type = EE_System::req_type_downgrade; |
|
542 | - } elseif ($version_is_higher === 0) { |
|
543 | - //we've seen this version before, but it's an activation. must be a reactivation |
|
544 | - $req_type = EE_System::req_type_reactivation; |
|
545 | - } else {//$version_is_higher === 1 |
|
546 | - $req_type = EE_System::req_type_upgrade; |
|
547 | - } |
|
548 | - delete_option($activation_indicator_option_name); |
|
549 | - } else { |
|
550 | - //we've seen this version before and the activation indicate doesn't show it was just activated |
|
551 | - if ($version_is_higher === -1) { |
|
552 | - $req_type = EE_System::req_type_downgrade; |
|
553 | - } elseif ($version_is_higher === 0) { |
|
554 | - //we've seen this version before and it's not an activation. its normal request |
|
555 | - $req_type = EE_System::req_type_normal; |
|
556 | - } else {//$version_is_higher === 1 |
|
557 | - $req_type = EE_System::req_type_upgrade; |
|
558 | - } |
|
559 | - } |
|
560 | - } |
|
561 | - } else { |
|
562 | - //brand new install |
|
563 | - $req_type = EE_System::req_type_new_activation; |
|
564 | - delete_option($activation_indicator_option_name); |
|
565 | - } |
|
566 | - return $req_type; |
|
567 | - } |
|
568 | - |
|
569 | - |
|
570 | - |
|
571 | - /** |
|
572 | - * Detects if the $version_to_upgrade_to is higher than the most recent version in |
|
573 | - * the $activation_history_for_addon |
|
574 | - * |
|
575 | - * @param array $activation_history_for_addon (keys are versions, values are arrays of times activated, |
|
576 | - * sometimes containing 'unknown-date' |
|
577 | - * @param string $version_to_upgrade_to (current version) |
|
578 | - * @return int results of version_compare( $version_to_upgrade_to, $most_recently_active_version ). |
|
579 | - * ie, -1 if $version_to_upgrade_to is LOWER (downgrade); |
|
580 | - * 0 if $version_to_upgrade_to MATCHES (reactivation or normal request); |
|
581 | - * 1 if $version_to_upgrade_to is HIGHER (upgrade) ; |
|
582 | - */ |
|
583 | - protected static function _new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to) |
|
584 | - { |
|
585 | - //find the most recently-activated version |
|
586 | - $most_recently_active_version = EE_System::_get_most_recently_active_version_from_activation_history($activation_history_for_addon); |
|
587 | - return version_compare($version_to_upgrade_to, $most_recently_active_version); |
|
588 | - } |
|
589 | - |
|
590 | - |
|
591 | - |
|
592 | - /** |
|
593 | - * Gets the most recently active version listed in the activation history, |
|
594 | - * and if none are found (ie, it's a brand new install) returns '0.0.0.dev.000'. |
|
595 | - * |
|
596 | - * @param array $activation_history (keys are versions, values are arrays of times activated, |
|
597 | - * sometimes containing 'unknown-date' |
|
598 | - * @return string |
|
599 | - */ |
|
600 | - protected static function _get_most_recently_active_version_from_activation_history($activation_history) |
|
601 | - { |
|
602 | - $most_recently_active_version_activation = '1970-01-01 00:00:00'; |
|
603 | - $most_recently_active_version = '0.0.0.dev.000'; |
|
604 | - if (is_array($activation_history)) { |
|
605 | - foreach ($activation_history as $version => $times_activated) { |
|
606 | - //check there is a record of when this version was activated. Otherwise, |
|
607 | - //mark it as unknown |
|
608 | - if ( ! $times_activated) { |
|
609 | - $times_activated = array('unknown-date'); |
|
610 | - } |
|
611 | - if (is_string($times_activated)) { |
|
612 | - $times_activated = array($times_activated); |
|
613 | - } |
|
614 | - foreach ($times_activated as $an_activation) { |
|
615 | - if ($an_activation != 'unknown-date' && $an_activation > $most_recently_active_version_activation) { |
|
616 | - $most_recently_active_version = $version; |
|
617 | - $most_recently_active_version_activation = $an_activation == 'unknown-date' |
|
618 | - ? '1970-01-01 00:00:00' : $an_activation; |
|
619 | - } |
|
620 | - } |
|
621 | - } |
|
622 | - } |
|
623 | - return $most_recently_active_version; |
|
624 | - } |
|
625 | - |
|
626 | - |
|
627 | - |
|
628 | - /** |
|
629 | - * This redirects to the about EE page after activation |
|
630 | - * |
|
631 | - * @return void |
|
632 | - */ |
|
633 | - public function redirect_to_about_ee() |
|
634 | - { |
|
635 | - $notices = EE_Error::get_notices(false); |
|
636 | - //if current user is an admin and it's not an ajax or rest request |
|
637 | - if ( |
|
638 | - ! (defined('DOING_AJAX') && DOING_AJAX) |
|
639 | - && ! (defined('REST_REQUEST') && REST_REQUEST) |
|
640 | - && ! isset($notices['errors']) |
|
641 | - && apply_filters( |
|
642 | - 'FHEE__EE_System__redirect_to_about_ee__do_redirect', |
|
643 | - $this->registry->CAP->current_user_can('manage_options', 'espresso_about_default') |
|
644 | - ) |
|
645 | - ) { |
|
646 | - $query_params = array('page' => 'espresso_about'); |
|
647 | - if (EE_System::instance()->detect_req_type() == EE_System::req_type_new_activation) { |
|
648 | - $query_params['new_activation'] = true; |
|
649 | - } |
|
650 | - if (EE_System::instance()->detect_req_type() == EE_System::req_type_reactivation) { |
|
651 | - $query_params['reactivation'] = true; |
|
652 | - } |
|
653 | - $url = add_query_arg($query_params, admin_url('admin.php')); |
|
654 | - wp_safe_redirect($url); |
|
655 | - exit(); |
|
656 | - } |
|
657 | - } |
|
658 | - |
|
659 | - |
|
660 | - |
|
661 | - /** |
|
662 | - * load_core_configuration |
|
663 | - * this is hooked into 'AHEE__EE_Bootstrap__load_core_configuration' |
|
664 | - * which runs during the WP 'plugins_loaded' action at priority 5 |
|
665 | - * |
|
666 | - * @return void |
|
667 | - */ |
|
668 | - public function load_core_configuration() |
|
669 | - { |
|
670 | - do_action('AHEE__EE_System__load_core_configuration__begin', $this); |
|
671 | - $this->registry->load_core('EE_Load_Textdomain'); |
|
672 | - //load textdomain |
|
673 | - EE_Load_Textdomain::load_textdomain(); |
|
674 | - // load and setup EE_Config and EE_Network_Config |
|
675 | - $this->registry->load_core('Config'); |
|
676 | - $this->registry->load_core('Network_Config'); |
|
677 | - // setup autoloaders |
|
678 | - // enable logging? |
|
679 | - if ($this->registry->CFG->admin->use_full_logging) { |
|
680 | - $this->registry->load_core('Log'); |
|
681 | - } |
|
682 | - // check for activation errors |
|
683 | - $activation_errors = get_option('ee_plugin_activation_errors', false); |
|
684 | - if ($activation_errors) { |
|
685 | - EE_Error::add_error($activation_errors, __FILE__, __FUNCTION__, __LINE__); |
|
686 | - update_option('ee_plugin_activation_errors', false); |
|
687 | - } |
|
688 | - // get model names |
|
689 | - $this->_parse_model_names(); |
|
690 | - do_action('AHEE__EE_System__load_core_configuration__complete', $this); |
|
691 | - } |
|
692 | - |
|
693 | - |
|
694 | - |
|
695 | - /** |
|
696 | - * cycles through all of the models/*.model.php files, and assembles an array of model names |
|
697 | - * |
|
698 | - * @return void |
|
699 | - */ |
|
700 | - private function _parse_model_names() |
|
701 | - { |
|
702 | - //call the non-abstract db models method, which verifies the model names have been discovered |
|
703 | - //for the sake of unit tests, always re-discover the models. We could probably make this more |
|
704 | - //efficient though (e.g., have unit tests reset the registered models in a different way) |
|
705 | - $this->registry->non_abstract_db_models = array(); |
|
706 | - $this->registry->non_abstract_db_models(); |
|
707 | - } |
|
708 | - |
|
709 | - |
|
710 | - |
|
711 | - /** |
|
712 | - * register_shortcodes_modules_and_widgets |
|
713 | - * generate lists of shortcodes and modules, then verify paths and classes |
|
714 | - * This is hooked into 'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets' |
|
715 | - * which runs during the WP 'plugins_loaded' action at priority 7 |
|
716 | - * |
|
717 | - * @access public |
|
718 | - * @return void |
|
719 | - */ |
|
720 | - public function register_shortcodes_modules_and_widgets() |
|
721 | - { |
|
722 | - try { |
|
723 | - // load, register, and add shortcodes the new way |
|
724 | - new ShortcodesManager( |
|
725 | - // and the old way, but we'll put it under control of the new system |
|
726 | - EE_Config::getLegacyShortcodesManager() |
|
727 | - ); |
|
728 | - } catch (Exception $exception) { |
|
729 | - new ExceptionStackTraceDisplay($exception); |
|
730 | - } |
|
731 | - do_action('AHEE__EE_System__register_shortcodes_modules_and_widgets'); |
|
732 | - // check for addons using old hookpoint |
|
733 | - if (has_action('AHEE__EE_System__register_shortcodes_modules_and_addons')) { |
|
734 | - $this->_incompatible_addon_error(); |
|
735 | - } |
|
736 | - } |
|
737 | - |
|
738 | - |
|
739 | - |
|
740 | - /** |
|
741 | - * _incompatible_addon_error |
|
742 | - * |
|
743 | - * @access public |
|
744 | - * @return void |
|
745 | - */ |
|
746 | - private function _incompatible_addon_error() |
|
747 | - { |
|
748 | - // get array of classes hooking into here |
|
749 | - $class_names = EEH_Class_Tools::get_class_names_for_all_callbacks_on_hook('AHEE__EE_System__register_shortcodes_modules_and_addons'); |
|
750 | - if ( ! empty($class_names)) { |
|
751 | - $msg = __('The following plugins, addons, or modules appear to be incompatible with this version of Event Espresso and were automatically deactivated to avoid fatal errors:', |
|
752 | - 'event_espresso'); |
|
753 | - $msg .= '<ul>'; |
|
754 | - foreach ($class_names as $class_name) { |
|
755 | - $msg .= '<li><b>Event Espresso - ' . str_replace(array('EE_', 'EEM_', 'EED_', 'EES_', 'EEW_'), '', |
|
756 | - $class_name) . '</b></li>'; |
|
757 | - } |
|
758 | - $msg .= '</ul>'; |
|
759 | - $msg .= __('Compatibility issues can be avoided and/or resolved by keeping addons and plugins updated to the latest version.', |
|
760 | - 'event_espresso'); |
|
761 | - // save list of incompatible addons to wp-options for later use |
|
762 | - add_option('ee_incompatible_addons', $class_names, '', 'no'); |
|
763 | - if (is_admin()) { |
|
764 | - EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
765 | - } |
|
766 | - } |
|
767 | - } |
|
768 | - |
|
769 | - |
|
770 | - |
|
771 | - /** |
|
772 | - * brew_espresso |
|
773 | - * begins the process of setting hooks for initializing EE in the correct order |
|
774 | - * This is happening on the 'AHEE__EE_Bootstrap__brew_espresso' hookpoint |
|
775 | - * which runs during the WP 'plugins_loaded' action at priority 9 |
|
776 | - * |
|
777 | - * @return void |
|
778 | - */ |
|
779 | - public function brew_espresso() |
|
780 | - { |
|
781 | - do_action('AHEE__EE_System__brew_espresso__begin', $this); |
|
782 | - // load some final core systems |
|
783 | - add_action('init', array($this, 'set_hooks_for_core'), 1); |
|
784 | - add_action('init', array($this, 'perform_activations_upgrades_and_migrations'), 3); |
|
785 | - add_action('init', array($this, 'load_CPTs_and_session'), 5); |
|
786 | - add_action('init', array($this, 'load_controllers'), 7); |
|
787 | - add_action('init', array($this, 'core_loaded_and_ready'), 9); |
|
788 | - add_action('init', array($this, 'initialize'), 10); |
|
789 | - add_action('init', array($this, 'initialize_last'), 100); |
|
790 | - add_action('wp_enqueue_scripts', array($this, 'wp_enqueue_scripts'), 100); |
|
791 | - add_action('admin_enqueue_scripts', array($this, 'wp_enqueue_scripts'), 100); |
|
792 | - add_action('admin_bar_menu', array($this, 'espresso_toolbar_items'), 100); |
|
793 | - if (is_admin() && apply_filters('FHEE__EE_System__brew_espresso__load_pue', true)) { |
|
794 | - // pew pew pew |
|
795 | - $this->registry->load_core('PUE'); |
|
796 | - do_action('AHEE__EE_System__brew_espresso__after_pue_init'); |
|
797 | - } |
|
798 | - do_action('AHEE__EE_System__brew_espresso__complete', $this); |
|
799 | - } |
|
800 | - |
|
801 | - |
|
802 | - |
|
803 | - /** |
|
804 | - * set_hooks_for_core |
|
805 | - * |
|
806 | - * @access public |
|
807 | - * @return void |
|
808 | - */ |
|
809 | - public function set_hooks_for_core() |
|
810 | - { |
|
811 | - //caps need to be initialized on every request so that capability maps are set. |
|
812 | - //@see https://events.codebasehq.com/projects/event-espresso/tickets/8674 |
|
813 | - //load and setup EE_Capabilities |
|
814 | - $this->registry->load_core('Capabilities'); |
|
815 | - $this->registry->CAP->init_caps(); |
|
816 | - $this->_deactivate_incompatible_addons(); |
|
817 | - do_action('AHEE__EE_System__set_hooks_for_core'); |
|
818 | - } |
|
819 | - |
|
820 | - |
|
821 | - |
|
822 | - /** |
|
823 | - * Using the information gathered in EE_System::_incompatible_addon_error, |
|
824 | - * deactivates any addons considered incompatible with the current version of EE |
|
825 | - */ |
|
826 | - private function _deactivate_incompatible_addons() |
|
827 | - { |
|
828 | - $incompatible_addons = get_option('ee_incompatible_addons', array()); |
|
829 | - if ( ! empty($incompatible_addons)) { |
|
830 | - $active_plugins = get_option('active_plugins', array()); |
|
831 | - foreach ($active_plugins as $active_plugin) { |
|
832 | - foreach ($incompatible_addons as $incompatible_addon) { |
|
833 | - if (strpos($active_plugin, $incompatible_addon) !== false) { |
|
834 | - unset($_GET['activate']); |
|
835 | - espresso_deactivate_plugin($active_plugin); |
|
836 | - } |
|
837 | - } |
|
838 | - } |
|
839 | - } |
|
840 | - } |
|
841 | - |
|
842 | - |
|
843 | - |
|
844 | - /** |
|
845 | - * perform_activations_upgrades_and_migrations |
|
846 | - * |
|
847 | - * @access public |
|
848 | - * @return void |
|
849 | - */ |
|
850 | - public function perform_activations_upgrades_and_migrations() |
|
851 | - { |
|
852 | - //first check if we had previously attempted to setup EE's directories but failed |
|
853 | - if (EEH_Activation::upload_directories_incomplete()) { |
|
854 | - EEH_Activation::create_upload_directories(); |
|
855 | - } |
|
856 | - do_action('AHEE__EE_System__perform_activations_upgrades_and_migrations'); |
|
857 | - } |
|
858 | - |
|
859 | - |
|
860 | - |
|
861 | - /** |
|
862 | - * load_CPTs_and_session |
|
863 | - * |
|
864 | - * @access public |
|
865 | - * @return void |
|
866 | - */ |
|
867 | - public function load_CPTs_and_session() |
|
868 | - { |
|
869 | - do_action('AHEE__EE_System__load_CPTs_and_session__start'); |
|
870 | - // register Custom Post Types |
|
871 | - $this->registry->load_core('Register_CPTs'); |
|
872 | - do_action('AHEE__EE_System__load_CPTs_and_session__complete'); |
|
873 | - } |
|
874 | - |
|
875 | - |
|
876 | - |
|
877 | - /** |
|
878 | - * load_controllers |
|
879 | - * this is the best place to load any additional controllers that needs access to EE core. |
|
880 | - * it is expected that all basic core EE systems, that are not dependant on the current request are loaded at this |
|
881 | - * time |
|
882 | - * |
|
883 | - * @access public |
|
884 | - * @return void |
|
885 | - */ |
|
886 | - public function load_controllers() |
|
887 | - { |
|
888 | - do_action('AHEE__EE_System__load_controllers__start'); |
|
889 | - // let's get it started |
|
890 | - if ( ! is_admin() && ! EE_Maintenance_Mode::instance()->level()) { |
|
891 | - do_action('AHEE__EE_System__load_controllers__load_front_controllers'); |
|
892 | - $this->registry->load_core('Front_Controller'); |
|
893 | - } else if ( ! EE_FRONT_AJAX) { |
|
894 | - do_action('AHEE__EE_System__load_controllers__load_admin_controllers'); |
|
895 | - EE_Registry::instance()->load_core('Admin'); |
|
896 | - } |
|
897 | - do_action('AHEE__EE_System__load_controllers__complete'); |
|
898 | - } |
|
899 | - |
|
900 | - |
|
901 | - |
|
902 | - /** |
|
903 | - * core_loaded_and_ready |
|
904 | - * all of the basic EE core should be loaded at this point and available regardless of M-Mode |
|
905 | - * |
|
906 | - * @access public |
|
907 | - * @return void |
|
908 | - */ |
|
909 | - public function core_loaded_and_ready() |
|
910 | - { |
|
911 | - do_action('AHEE__EE_System__core_loaded_and_ready'); |
|
912 | - // load_espresso_template_tags |
|
913 | - if (is_readable(EE_PUBLIC . 'template_tags.php')) { |
|
914 | - require_once(EE_PUBLIC . 'template_tags.php'); |
|
915 | - } |
|
916 | - do_action('AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons'); |
|
917 | - $this->registry->load_core('Session'); |
|
918 | - } |
|
919 | - |
|
920 | - |
|
921 | - |
|
922 | - /** |
|
923 | - * initialize |
|
924 | - * this is the best place to begin initializing client code |
|
925 | - * |
|
926 | - * @access public |
|
927 | - * @return void |
|
928 | - */ |
|
929 | - public function initialize() |
|
930 | - { |
|
931 | - do_action('AHEE__EE_System__initialize'); |
|
932 | - } |
|
933 | - |
|
934 | - |
|
935 | - |
|
936 | - /** |
|
937 | - * initialize_last |
|
938 | - * this is run really late during the WP init hookpoint, and ensures that mostly everything else that needs to |
|
939 | - * initialize has done so |
|
940 | - * |
|
941 | - * @access public |
|
942 | - * @return void |
|
943 | - */ |
|
944 | - public function initialize_last() |
|
945 | - { |
|
946 | - do_action('AHEE__EE_System__initialize_last'); |
|
947 | - } |
|
948 | - |
|
949 | - |
|
950 | - |
|
951 | - /** |
|
952 | - * set_hooks_for_shortcodes_modules_and_addons |
|
953 | - * this is the best place for other systems to set callbacks for hooking into other parts of EE |
|
954 | - * this happens at the very beginning of the wp_loaded hookpoint |
|
955 | - * |
|
956 | - * @access public |
|
957 | - * @return void |
|
958 | - */ |
|
959 | - public function set_hooks_for_shortcodes_modules_and_addons() |
|
960 | - { |
|
961 | - // do_action( 'AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons' ); |
|
962 | - } |
|
963 | - |
|
964 | - |
|
965 | - |
|
966 | - /** |
|
967 | - * do_not_cache |
|
968 | - * sets no cache headers and defines no cache constants for WP plugins |
|
969 | - * |
|
970 | - * @access public |
|
971 | - * @return void |
|
972 | - */ |
|
973 | - public static function do_not_cache() |
|
974 | - { |
|
975 | - // set no cache constants |
|
976 | - if ( ! defined('DONOTCACHEPAGE')) { |
|
977 | - define('DONOTCACHEPAGE', true); |
|
978 | - } |
|
979 | - if ( ! defined('DONOTCACHCEOBJECT')) { |
|
980 | - define('DONOTCACHCEOBJECT', true); |
|
981 | - } |
|
982 | - if ( ! defined('DONOTCACHEDB')) { |
|
983 | - define('DONOTCACHEDB', true); |
|
984 | - } |
|
985 | - // add no cache headers |
|
986 | - add_action('send_headers', array('EE_System', 'nocache_headers'), 10); |
|
987 | - // plus a little extra for nginx and Google Chrome |
|
988 | - add_filter('nocache_headers', array('EE_System', 'extra_nocache_headers'), 10, 1); |
|
989 | - // prevent browsers from prefetching of the rel='next' link, because it may contain content that interferes with the registration process |
|
990 | - remove_action('wp_head', 'adjacent_posts_rel_link_wp_head'); |
|
991 | - } |
|
992 | - |
|
993 | - |
|
994 | - |
|
995 | - /** |
|
996 | - * extra_nocache_headers |
|
997 | - * |
|
998 | - * @access public |
|
999 | - * @param $headers |
|
1000 | - * @return array |
|
1001 | - */ |
|
1002 | - public static function extra_nocache_headers($headers) |
|
1003 | - { |
|
1004 | - // for NGINX |
|
1005 | - $headers['X-Accel-Expires'] = 0; |
|
1006 | - // plus extra for Google Chrome since it doesn't seem to respect "no-cache", but WILL respect "no-store" |
|
1007 | - $headers['Cache-Control'] = 'no-store, no-cache, must-revalidate, max-age=0'; |
|
1008 | - return $headers; |
|
1009 | - } |
|
1010 | - |
|
1011 | - |
|
1012 | - |
|
1013 | - /** |
|
1014 | - * nocache_headers |
|
1015 | - * |
|
1016 | - * @access public |
|
1017 | - * @return void |
|
1018 | - */ |
|
1019 | - public static function nocache_headers() |
|
1020 | - { |
|
1021 | - nocache_headers(); |
|
1022 | - } |
|
1023 | - |
|
1024 | - |
|
1025 | - |
|
1026 | - /** |
|
1027 | - * espresso_toolbar_items |
|
1028 | - * |
|
1029 | - * @access public |
|
1030 | - * @param WP_Admin_Bar $admin_bar |
|
1031 | - * @return void |
|
1032 | - */ |
|
1033 | - public function espresso_toolbar_items(WP_Admin_Bar $admin_bar) |
|
1034 | - { |
|
1035 | - // if in full M-Mode, or its an AJAX request, or user is NOT an admin |
|
1036 | - if (EE_Maintenance_Mode::instance()->level() == EE_Maintenance_Mode::level_2_complete_maintenance |
|
1037 | - || defined('DOING_AJAX') |
|
1038 | - || ! $this->registry->CAP->current_user_can('ee_read_ee', 'ee_admin_bar_menu_top_level') |
|
1039 | - ) { |
|
1040 | - return; |
|
1041 | - } |
|
1042 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
1043 | - $menu_class = 'espresso_menu_item_class'; |
|
1044 | - //we don't use the constants EVENTS_ADMIN_URL or REG_ADMIN_URL |
|
1045 | - //because they're only defined in each of their respective constructors |
|
1046 | - //and this might be a frontend request, in which case they aren't available |
|
1047 | - $events_admin_url = admin_url("admin.php?page=espresso_events"); |
|
1048 | - $reg_admin_url = admin_url("admin.php?page=espresso_registrations"); |
|
1049 | - $extensions_admin_url = admin_url("admin.php?page=espresso_packages"); |
|
1050 | - //Top Level |
|
1051 | - $admin_bar->add_menu(array( |
|
1052 | - 'id' => 'espresso-toolbar', |
|
1053 | - 'title' => '<span class="ee-icon ee-icon-ee-cup-thick ee-icon-size-20"></span><span class="ab-label">' |
|
1054 | - . _x('Event Espresso', 'admin bar menu group label', 'event_espresso') |
|
1055 | - . '</span>', |
|
1056 | - 'href' => $events_admin_url, |
|
1057 | - 'meta' => array( |
|
1058 | - 'title' => __('Event Espresso', 'event_espresso'), |
|
1059 | - 'class' => $menu_class . 'first', |
|
1060 | - ), |
|
1061 | - )); |
|
1062 | - //Events |
|
1063 | - if ($this->registry->CAP->current_user_can('ee_read_events', 'ee_admin_bar_menu_espresso-toolbar-events')) { |
|
1064 | - $admin_bar->add_menu(array( |
|
1065 | - 'id' => 'espresso-toolbar-events', |
|
1066 | - 'parent' => 'espresso-toolbar', |
|
1067 | - 'title' => __('Events', 'event_espresso'), |
|
1068 | - 'href' => $events_admin_url, |
|
1069 | - 'meta' => array( |
|
1070 | - 'title' => __('Events', 'event_espresso'), |
|
1071 | - 'target' => '', |
|
1072 | - 'class' => $menu_class, |
|
1073 | - ), |
|
1074 | - )); |
|
1075 | - } |
|
1076 | - if ($this->registry->CAP->current_user_can('ee_edit_events', 'ee_admin_bar_menu_espresso-toolbar-events-new')) { |
|
1077 | - //Events Add New |
|
1078 | - $admin_bar->add_menu(array( |
|
1079 | - 'id' => 'espresso-toolbar-events-new', |
|
1080 | - 'parent' => 'espresso-toolbar-events', |
|
1081 | - 'title' => __('Add New', 'event_espresso'), |
|
1082 | - 'href' => EEH_URL::add_query_args_and_nonce(array('action' => 'create_new'), $events_admin_url), |
|
1083 | - 'meta' => array( |
|
1084 | - 'title' => __('Add New', 'event_espresso'), |
|
1085 | - 'target' => '', |
|
1086 | - 'class' => $menu_class, |
|
1087 | - ), |
|
1088 | - )); |
|
1089 | - } |
|
1090 | - if (is_single() && (get_post_type() == 'espresso_events')) { |
|
1091 | - //Current post |
|
1092 | - global $post; |
|
1093 | - if ($this->registry->CAP->current_user_can('ee_edit_event', |
|
1094 | - 'ee_admin_bar_menu_espresso-toolbar-events-edit', $post->ID) |
|
1095 | - ) { |
|
1096 | - //Events Edit Current Event |
|
1097 | - $admin_bar->add_menu(array( |
|
1098 | - 'id' => 'espresso-toolbar-events-edit', |
|
1099 | - 'parent' => 'espresso-toolbar-events', |
|
1100 | - 'title' => __('Edit Event', 'event_espresso'), |
|
1101 | - 'href' => EEH_URL::add_query_args_and_nonce(array('action' => 'edit', 'post' => $post->ID), |
|
1102 | - $events_admin_url), |
|
1103 | - 'meta' => array( |
|
1104 | - 'title' => __('Edit Event', 'event_espresso'), |
|
1105 | - 'target' => '', |
|
1106 | - 'class' => $menu_class, |
|
1107 | - ), |
|
1108 | - )); |
|
1109 | - } |
|
1110 | - } |
|
1111 | - //Events View |
|
1112 | - if ($this->registry->CAP->current_user_can('ee_read_events', |
|
1113 | - 'ee_admin_bar_menu_espresso-toolbar-events-view') |
|
1114 | - ) { |
|
1115 | - $admin_bar->add_menu(array( |
|
1116 | - 'id' => 'espresso-toolbar-events-view', |
|
1117 | - 'parent' => 'espresso-toolbar-events', |
|
1118 | - 'title' => __('View', 'event_espresso'), |
|
1119 | - 'href' => $events_admin_url, |
|
1120 | - 'meta' => array( |
|
1121 | - 'title' => __('View', 'event_espresso'), |
|
1122 | - 'target' => '', |
|
1123 | - 'class' => $menu_class, |
|
1124 | - ), |
|
1125 | - )); |
|
1126 | - } |
|
1127 | - if ($this->registry->CAP->current_user_can('ee_read_events', 'ee_admin_bar_menu_espresso-toolbar-events-all')) { |
|
1128 | - //Events View All |
|
1129 | - $admin_bar->add_menu(array( |
|
1130 | - 'id' => 'espresso-toolbar-events-all', |
|
1131 | - 'parent' => 'espresso-toolbar-events-view', |
|
1132 | - 'title' => __('All', 'event_espresso'), |
|
1133 | - 'href' => $events_admin_url, |
|
1134 | - 'meta' => array( |
|
1135 | - 'title' => __('All', 'event_espresso'), |
|
1136 | - 'target' => '', |
|
1137 | - 'class' => $menu_class, |
|
1138 | - ), |
|
1139 | - )); |
|
1140 | - } |
|
1141 | - if ($this->registry->CAP->current_user_can('ee_read_events', |
|
1142 | - 'ee_admin_bar_menu_espresso-toolbar-events-today') |
|
1143 | - ) { |
|
1144 | - //Events View Today |
|
1145 | - $admin_bar->add_menu(array( |
|
1146 | - 'id' => 'espresso-toolbar-events-today', |
|
1147 | - 'parent' => 'espresso-toolbar-events-view', |
|
1148 | - 'title' => __('Today', 'event_espresso'), |
|
1149 | - 'href' => EEH_URL::add_query_args_and_nonce(array('action' => 'default', 'status' => 'today'), |
|
1150 | - $events_admin_url), |
|
1151 | - 'meta' => array( |
|
1152 | - 'title' => __('Today', 'event_espresso'), |
|
1153 | - 'target' => '', |
|
1154 | - 'class' => $menu_class, |
|
1155 | - ), |
|
1156 | - )); |
|
1157 | - } |
|
1158 | - if ($this->registry->CAP->current_user_can('ee_read_events', |
|
1159 | - 'ee_admin_bar_menu_espresso-toolbar-events-month') |
|
1160 | - ) { |
|
1161 | - //Events View This Month |
|
1162 | - $admin_bar->add_menu(array( |
|
1163 | - 'id' => 'espresso-toolbar-events-month', |
|
1164 | - 'parent' => 'espresso-toolbar-events-view', |
|
1165 | - 'title' => __('This Month', 'event_espresso'), |
|
1166 | - 'href' => EEH_URL::add_query_args_and_nonce(array('action' => 'default', 'status' => 'month'), |
|
1167 | - $events_admin_url), |
|
1168 | - 'meta' => array( |
|
1169 | - 'title' => __('This Month', 'event_espresso'), |
|
1170 | - 'target' => '', |
|
1171 | - 'class' => $menu_class, |
|
1172 | - ), |
|
1173 | - )); |
|
1174 | - } |
|
1175 | - //Registration Overview |
|
1176 | - if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
1177 | - 'ee_admin_bar_menu_espresso-toolbar-registrations') |
|
1178 | - ) { |
|
1179 | - $admin_bar->add_menu(array( |
|
1180 | - 'id' => 'espresso-toolbar-registrations', |
|
1181 | - 'parent' => 'espresso-toolbar', |
|
1182 | - 'title' => __('Registrations', 'event_espresso'), |
|
1183 | - 'href' => $reg_admin_url, |
|
1184 | - 'meta' => array( |
|
1185 | - 'title' => __('Registrations', 'event_espresso'), |
|
1186 | - 'target' => '', |
|
1187 | - 'class' => $menu_class, |
|
1188 | - ), |
|
1189 | - )); |
|
1190 | - } |
|
1191 | - //Registration Overview Today |
|
1192 | - if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
1193 | - 'ee_admin_bar_menu_espresso-toolbar-registrations-today') |
|
1194 | - ) { |
|
1195 | - $admin_bar->add_menu(array( |
|
1196 | - 'id' => 'espresso-toolbar-registrations-today', |
|
1197 | - 'parent' => 'espresso-toolbar-registrations', |
|
1198 | - 'title' => __('Today', 'event_espresso'), |
|
1199 | - 'href' => EEH_URL::add_query_args_and_nonce(array('action' => 'default', 'status' => 'today'), |
|
1200 | - $reg_admin_url), |
|
1201 | - 'meta' => array( |
|
1202 | - 'title' => __('Today', 'event_espresso'), |
|
1203 | - 'target' => '', |
|
1204 | - 'class' => $menu_class, |
|
1205 | - ), |
|
1206 | - )); |
|
1207 | - } |
|
1208 | - //Registration Overview Today Completed |
|
1209 | - if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
1210 | - 'ee_admin_bar_menu_espresso-toolbar-registrations-today-approved') |
|
1211 | - ) { |
|
1212 | - $admin_bar->add_menu(array( |
|
1213 | - 'id' => 'espresso-toolbar-registrations-today-approved', |
|
1214 | - 'parent' => 'espresso-toolbar-registrations-today', |
|
1215 | - 'title' => __('Approved', 'event_espresso'), |
|
1216 | - 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
1217 | - 'action' => 'default', |
|
1218 | - 'status' => 'today', |
|
1219 | - '_reg_status' => EEM_Registration::status_id_approved, |
|
1220 | - ), $reg_admin_url), |
|
1221 | - 'meta' => array( |
|
1222 | - 'title' => __('Approved', 'event_espresso'), |
|
1223 | - 'target' => '', |
|
1224 | - 'class' => $menu_class, |
|
1225 | - ), |
|
1226 | - )); |
|
1227 | - } |
|
1228 | - //Registration Overview Today Pending\ |
|
1229 | - if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
1230 | - 'ee_admin_bar_menu_espresso-toolbar-registrations-today-pending') |
|
1231 | - ) { |
|
1232 | - $admin_bar->add_menu(array( |
|
1233 | - 'id' => 'espresso-toolbar-registrations-today-pending', |
|
1234 | - 'parent' => 'espresso-toolbar-registrations-today', |
|
1235 | - 'title' => __('Pending', 'event_espresso'), |
|
1236 | - 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
1237 | - 'action' => 'default', |
|
1238 | - 'status' => 'today', |
|
1239 | - 'reg_status' => EEM_Registration::status_id_pending_payment, |
|
1240 | - ), $reg_admin_url), |
|
1241 | - 'meta' => array( |
|
1242 | - 'title' => __('Pending Payment', 'event_espresso'), |
|
1243 | - 'target' => '', |
|
1244 | - 'class' => $menu_class, |
|
1245 | - ), |
|
1246 | - )); |
|
1247 | - } |
|
1248 | - //Registration Overview Today Incomplete |
|
1249 | - if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
1250 | - 'ee_admin_bar_menu_espresso-toolbar-registrations-today-not-approved') |
|
1251 | - ) { |
|
1252 | - $admin_bar->add_menu(array( |
|
1253 | - 'id' => 'espresso-toolbar-registrations-today-not-approved', |
|
1254 | - 'parent' => 'espresso-toolbar-registrations-today', |
|
1255 | - 'title' => __('Not Approved', 'event_espresso'), |
|
1256 | - 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
1257 | - 'action' => 'default', |
|
1258 | - 'status' => 'today', |
|
1259 | - '_reg_status' => EEM_Registration::status_id_not_approved, |
|
1260 | - ), $reg_admin_url), |
|
1261 | - 'meta' => array( |
|
1262 | - 'title' => __('Not Approved', 'event_espresso'), |
|
1263 | - 'target' => '', |
|
1264 | - 'class' => $menu_class, |
|
1265 | - ), |
|
1266 | - )); |
|
1267 | - } |
|
1268 | - //Registration Overview Today Incomplete |
|
1269 | - if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
1270 | - 'ee_admin_bar_menu_espresso-toolbar-registrations-today-cancelled') |
|
1271 | - ) { |
|
1272 | - $admin_bar->add_menu(array( |
|
1273 | - 'id' => 'espresso-toolbar-registrations-today-cancelled', |
|
1274 | - 'parent' => 'espresso-toolbar-registrations-today', |
|
1275 | - 'title' => __('Cancelled', 'event_espresso'), |
|
1276 | - 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
1277 | - 'action' => 'default', |
|
1278 | - 'status' => 'today', |
|
1279 | - '_reg_status' => EEM_Registration::status_id_cancelled, |
|
1280 | - ), $reg_admin_url), |
|
1281 | - 'meta' => array( |
|
1282 | - 'title' => __('Cancelled', 'event_espresso'), |
|
1283 | - 'target' => '', |
|
1284 | - 'class' => $menu_class, |
|
1285 | - ), |
|
1286 | - )); |
|
1287 | - } |
|
1288 | - //Registration Overview This Month |
|
1289 | - if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
1290 | - 'ee_admin_bar_menu_espresso-toolbar-registrations-month') |
|
1291 | - ) { |
|
1292 | - $admin_bar->add_menu(array( |
|
1293 | - 'id' => 'espresso-toolbar-registrations-month', |
|
1294 | - 'parent' => 'espresso-toolbar-registrations', |
|
1295 | - 'title' => __('This Month', 'event_espresso'), |
|
1296 | - 'href' => EEH_URL::add_query_args_and_nonce(array('action' => 'default', 'status' => 'month'), |
|
1297 | - $reg_admin_url), |
|
1298 | - 'meta' => array( |
|
1299 | - 'title' => __('This Month', 'event_espresso'), |
|
1300 | - 'target' => '', |
|
1301 | - 'class' => $menu_class, |
|
1302 | - ), |
|
1303 | - )); |
|
1304 | - } |
|
1305 | - //Registration Overview This Month Approved |
|
1306 | - if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
1307 | - 'ee_admin_bar_menu_espresso-toolbar-registrations-month-approved') |
|
1308 | - ) { |
|
1309 | - $admin_bar->add_menu(array( |
|
1310 | - 'id' => 'espresso-toolbar-registrations-month-approved', |
|
1311 | - 'parent' => 'espresso-toolbar-registrations-month', |
|
1312 | - 'title' => __('Approved', 'event_espresso'), |
|
1313 | - 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
1314 | - 'action' => 'default', |
|
1315 | - 'status' => 'month', |
|
1316 | - '_reg_status' => EEM_Registration::status_id_approved, |
|
1317 | - ), $reg_admin_url), |
|
1318 | - 'meta' => array( |
|
1319 | - 'title' => __('Approved', 'event_espresso'), |
|
1320 | - 'target' => '', |
|
1321 | - 'class' => $menu_class, |
|
1322 | - ), |
|
1323 | - )); |
|
1324 | - } |
|
1325 | - //Registration Overview This Month Pending |
|
1326 | - if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
1327 | - 'ee_admin_bar_menu_espresso-toolbar-registrations-month-pending') |
|
1328 | - ) { |
|
1329 | - $admin_bar->add_menu(array( |
|
1330 | - 'id' => 'espresso-toolbar-registrations-month-pending', |
|
1331 | - 'parent' => 'espresso-toolbar-registrations-month', |
|
1332 | - 'title' => __('Pending', 'event_espresso'), |
|
1333 | - 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
1334 | - 'action' => 'default', |
|
1335 | - 'status' => 'month', |
|
1336 | - '_reg_status' => EEM_Registration::status_id_pending_payment, |
|
1337 | - ), $reg_admin_url), |
|
1338 | - 'meta' => array( |
|
1339 | - 'title' => __('Pending', 'event_espresso'), |
|
1340 | - 'target' => '', |
|
1341 | - 'class' => $menu_class, |
|
1342 | - ), |
|
1343 | - )); |
|
1344 | - } |
|
1345 | - //Registration Overview This Month Not Approved |
|
1346 | - if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
1347 | - 'ee_admin_bar_menu_espresso-toolbar-registrations-month-not-approved') |
|
1348 | - ) { |
|
1349 | - $admin_bar->add_menu(array( |
|
1350 | - 'id' => 'espresso-toolbar-registrations-month-not-approved', |
|
1351 | - 'parent' => 'espresso-toolbar-registrations-month', |
|
1352 | - 'title' => __('Not Approved', 'event_espresso'), |
|
1353 | - 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
1354 | - 'action' => 'default', |
|
1355 | - 'status' => 'month', |
|
1356 | - '_reg_status' => EEM_Registration::status_id_not_approved, |
|
1357 | - ), $reg_admin_url), |
|
1358 | - 'meta' => array( |
|
1359 | - 'title' => __('Not Approved', 'event_espresso'), |
|
1360 | - 'target' => '', |
|
1361 | - 'class' => $menu_class, |
|
1362 | - ), |
|
1363 | - )); |
|
1364 | - } |
|
1365 | - //Registration Overview This Month Cancelled |
|
1366 | - if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
1367 | - 'ee_admin_bar_menu_espresso-toolbar-registrations-month-cancelled') |
|
1368 | - ) { |
|
1369 | - $admin_bar->add_menu(array( |
|
1370 | - 'id' => 'espresso-toolbar-registrations-month-cancelled', |
|
1371 | - 'parent' => 'espresso-toolbar-registrations-month', |
|
1372 | - 'title' => __('Cancelled', 'event_espresso'), |
|
1373 | - 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
1374 | - 'action' => 'default', |
|
1375 | - 'status' => 'month', |
|
1376 | - '_reg_status' => EEM_Registration::status_id_cancelled, |
|
1377 | - ), $reg_admin_url), |
|
1378 | - 'meta' => array( |
|
1379 | - 'title' => __('Cancelled', 'event_espresso'), |
|
1380 | - 'target' => '', |
|
1381 | - 'class' => $menu_class, |
|
1382 | - ), |
|
1383 | - )); |
|
1384 | - } |
|
1385 | - //Extensions & Services |
|
1386 | - if ($this->registry->CAP->current_user_can('ee_read_ee', |
|
1387 | - 'ee_admin_bar_menu_espresso-toolbar-extensions-and-services') |
|
1388 | - ) { |
|
1389 | - $admin_bar->add_menu(array( |
|
1390 | - 'id' => 'espresso-toolbar-extensions-and-services', |
|
1391 | - 'parent' => 'espresso-toolbar', |
|
1392 | - 'title' => __('Extensions & Services', 'event_espresso'), |
|
1393 | - 'href' => $extensions_admin_url, |
|
1394 | - 'meta' => array( |
|
1395 | - 'title' => __('Extensions & Services', 'event_espresso'), |
|
1396 | - 'target' => '', |
|
1397 | - 'class' => $menu_class, |
|
1398 | - ), |
|
1399 | - )); |
|
1400 | - } |
|
1401 | - } |
|
1402 | - |
|
1403 | - |
|
1404 | - |
|
1405 | - /** |
|
1406 | - * simply hooks into "wp_list_pages_exclude" filter (for wp_list_pages method) and makes sure EE critical pages are |
|
1407 | - * never returned with the function. |
|
1408 | - * |
|
1409 | - * @param array $exclude_array any existing pages being excluded are in this array. |
|
1410 | - * @return array |
|
1411 | - */ |
|
1412 | - public function remove_pages_from_wp_list_pages($exclude_array) |
|
1413 | - { |
|
1414 | - return array_merge($exclude_array, $this->registry->CFG->core->get_critical_pages_array()); |
|
1415 | - } |
|
1416 | - |
|
1417 | - |
|
1418 | - |
|
1419 | - |
|
1420 | - |
|
1421 | - |
|
1422 | - /*********************************************** WP_ENQUEUE_SCRIPTS HOOK ***********************************************/ |
|
1423 | - /** |
|
1424 | - * wp_enqueue_scripts |
|
1425 | - * |
|
1426 | - * @access public |
|
1427 | - * @return void |
|
1428 | - */ |
|
1429 | - public function wp_enqueue_scripts() |
|
1430 | - { |
|
1431 | - // unlike other systems, EE_System_scripts loading is turned ON by default, but prior to the init hook, can be turned off via: add_filter( 'FHEE_load_EE_System_scripts', '__return_false' ); |
|
1432 | - if (apply_filters('FHEE_load_EE_System_scripts', true)) { |
|
1433 | - // jquery_validate loading is turned OFF by default, but prior to the wp_enqueue_scripts hook, can be turned back on again via: add_filter( 'FHEE_load_jquery_validate', '__return_true' ); |
|
1434 | - if (apply_filters('FHEE_load_jquery_validate', false)) { |
|
1435 | - // register jQuery Validate and additional methods |
|
1436 | - wp_register_script('jquery-validate', EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.min.js', |
|
1437 | - array('jquery'), '1.15.0', true); |
|
1438 | - wp_register_script('jquery-validate-extra-methods', |
|
1439 | - EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.additional-methods.min.js', |
|
1440 | - array('jquery', 'jquery-validate'), '1.15.0', true); |
|
1441 | - } |
|
1442 | - } |
|
1443 | - } |
|
22 | + /** |
|
23 | + * indicates this is a 'normal' request. Ie, not activation, nor upgrade, nor activation. |
|
24 | + * So examples of this would be a normal GET request on the frontend or backend, or a POST, etc |
|
25 | + */ |
|
26 | + const req_type_normal = 0; |
|
27 | + |
|
28 | + /** |
|
29 | + * Indicates this is a brand new installation of EE so we should install |
|
30 | + * tables and default data etc |
|
31 | + */ |
|
32 | + const req_type_new_activation = 1; |
|
33 | + |
|
34 | + /** |
|
35 | + * we've detected that EE has been reactivated (or EE was activated during maintenance mode, |
|
36 | + * and we just exited maintenance mode). We MUST check the database is setup properly |
|
37 | + * and that default data is setup too |
|
38 | + */ |
|
39 | + const req_type_reactivation = 2; |
|
40 | + |
|
41 | + /** |
|
42 | + * indicates that EE has been upgraded since its previous request. |
|
43 | + * We may have data migration scripts to call and will want to trigger maintenance mode |
|
44 | + */ |
|
45 | + const req_type_upgrade = 3; |
|
46 | + |
|
47 | + /** |
|
48 | + * TODO will detect that EE has been DOWNGRADED. We probably don't want to run in this case... |
|
49 | + */ |
|
50 | + const req_type_downgrade = 4; |
|
51 | + |
|
52 | + /** |
|
53 | + * @deprecated since version 4.6.0.dev.006 |
|
54 | + * Now whenever a new_activation is detected the request type is still just |
|
55 | + * new_activation (same for reactivation, upgrade, downgrade etc), but if we'r ein maintenance mode |
|
56 | + * EE_System::initialize_db_if_no_migrations_required and EE_Addon::initialize_db_if_no_migrations_required |
|
57 | + * will instead enqueue that EE plugin's db initialization for when we're taken out of maintenance mode. |
|
58 | + * (Specifically, when the migration manager indicates migrations are finished |
|
59 | + * EE_Data_Migration_Manager::initialize_db_for_enqueued_ee_plugins() will be called) |
|
60 | + */ |
|
61 | + const req_type_activation_but_not_installed = 5; |
|
62 | + |
|
63 | + /** |
|
64 | + * option prefix for recording the activation history (like core's "espresso_db_update") of addons |
|
65 | + */ |
|
66 | + const addon_activation_history_option_prefix = 'ee_addon_activation_history_'; |
|
67 | + |
|
68 | + |
|
69 | + /** |
|
70 | + * instance of the EE_System object |
|
71 | + * |
|
72 | + * @var $_instance |
|
73 | + * @access private |
|
74 | + */ |
|
75 | + private static $_instance = null; |
|
76 | + |
|
77 | + /** |
|
78 | + * @type EE_Registry $Registry |
|
79 | + * @access protected |
|
80 | + */ |
|
81 | + protected $registry; |
|
82 | + |
|
83 | + /** |
|
84 | + * Stores which type of request this is, options being one of the constants on EE_System starting with req_type_*. |
|
85 | + * It can be a brand-new activation, a reactivation, an upgrade, a downgrade, or a normal request. |
|
86 | + * |
|
87 | + * @var int |
|
88 | + */ |
|
89 | + private $_req_type; |
|
90 | + |
|
91 | + /** |
|
92 | + * Whether or not there was a non-micro version change in EE core version during this request |
|
93 | + * |
|
94 | + * @var boolean |
|
95 | + */ |
|
96 | + private $_major_version_change = false; |
|
97 | + |
|
98 | + |
|
99 | + |
|
100 | + /** |
|
101 | + * @singleton method used to instantiate class object |
|
102 | + * @access public |
|
103 | + * @param \EE_Registry $Registry |
|
104 | + * @return \EE_System |
|
105 | + */ |
|
106 | + public static function instance(EE_Registry $Registry = null) |
|
107 | + { |
|
108 | + // check if class object is instantiated |
|
109 | + if ( ! self::$_instance instanceof EE_System) { |
|
110 | + self::$_instance = new self($Registry); |
|
111 | + } |
|
112 | + return self::$_instance; |
|
113 | + } |
|
114 | + |
|
115 | + |
|
116 | + |
|
117 | + /** |
|
118 | + * resets the instance and returns it |
|
119 | + * |
|
120 | + * @return EE_System |
|
121 | + */ |
|
122 | + public static function reset() |
|
123 | + { |
|
124 | + self::$_instance->_req_type = null; |
|
125 | + //make sure none of the old hooks are left hanging around |
|
126 | + remove_all_actions('AHEE__EE_System__perform_activations_upgrades_and_migrations'); |
|
127 | + //we need to reset the migration manager in order for it to detect DMSs properly |
|
128 | + EE_Data_Migration_Manager::reset(); |
|
129 | + self::instance()->detect_activations_or_upgrades(); |
|
130 | + self::instance()->perform_activations_upgrades_and_migrations(); |
|
131 | + return self::instance(); |
|
132 | + } |
|
133 | + |
|
134 | + |
|
135 | + |
|
136 | + /** |
|
137 | + * sets hooks for running rest of system |
|
138 | + * provides "AHEE__EE_System__construct__complete" hook for EE Addons to use as their starting point |
|
139 | + * starting EE Addons from any other point may lead to problems |
|
140 | + * |
|
141 | + * @access private |
|
142 | + * @param \EE_Registry $Registry |
|
143 | + */ |
|
144 | + private function __construct(EE_Registry $Registry) |
|
145 | + { |
|
146 | + $this->registry = $Registry; |
|
147 | + do_action('AHEE__EE_System__construct__begin', $this); |
|
148 | + // allow addons to load first so that they can register autoloaders, set hooks for running DMS's, etc |
|
149 | + add_action('AHEE__EE_Bootstrap__load_espresso_addons', array($this, 'load_espresso_addons')); |
|
150 | + // when an ee addon is activated, we want to call the core hook(s) again |
|
151 | + // because the newly-activated addon didn't get a chance to run at all |
|
152 | + add_action('activate_plugin', array($this, 'load_espresso_addons'), 1); |
|
153 | + // detect whether install or upgrade |
|
154 | + add_action('AHEE__EE_Bootstrap__detect_activations_or_upgrades', array($this, 'detect_activations_or_upgrades'), |
|
155 | + 3); |
|
156 | + // load EE_Config, EE_Textdomain, etc |
|
157 | + add_action('AHEE__EE_Bootstrap__load_core_configuration', array($this, 'load_core_configuration'), 5); |
|
158 | + // load EE_Config, EE_Textdomain, etc |
|
159 | + add_action('AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets', |
|
160 | + array($this, 'register_shortcodes_modules_and_widgets'), 7); |
|
161 | + // you wanna get going? I wanna get going... let's get going! |
|
162 | + add_action('AHEE__EE_Bootstrap__brew_espresso', array($this, 'brew_espresso'), 9); |
|
163 | + //other housekeeping |
|
164 | + //exclude EE critical pages from wp_list_pages |
|
165 | + add_filter('wp_list_pages_excludes', array($this, 'remove_pages_from_wp_list_pages'), 10); |
|
166 | + // ALL EE Addons should use the following hook point to attach their initial setup too |
|
167 | + // it's extremely important for EE Addons to register any class autoloaders so that they can be available when the EE_Config loads |
|
168 | + do_action('AHEE__EE_System__construct__complete', $this); |
|
169 | + } |
|
170 | + |
|
171 | + |
|
172 | + |
|
173 | + /** |
|
174 | + * load_espresso_addons |
|
175 | + * allow addons to load first so that they can set hooks for running DMS's, etc |
|
176 | + * this is hooked into both: |
|
177 | + * 'AHEE__EE_Bootstrap__load_core_configuration' |
|
178 | + * which runs during the WP 'plugins_loaded' action at priority 5 |
|
179 | + * and the WP 'activate_plugin' hookpoint |
|
180 | + * |
|
181 | + * @access public |
|
182 | + * @return void |
|
183 | + */ |
|
184 | + public function load_espresso_addons() |
|
185 | + { |
|
186 | + // set autoloaders for all of the classes implementing EEI_Plugin_API |
|
187 | + // which provide helpers for EE plugin authors to more easily register certain components with EE. |
|
188 | + EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'plugin_api'); |
|
189 | + do_action('AHEE__EE_System__load_espresso_addons'); |
|
190 | + //if the WP API basic auth plugin isn't already loaded, load it now. |
|
191 | + //We want it for mobile apps. Just include the entire plugin |
|
192 | + //also, don't load the basic auth when a plugin is getting activated, because |
|
193 | + //it could be the basic auth plugin, and it doesn't check if its methods are already defined |
|
194 | + //and causes a fatal error |
|
195 | + if ( ! function_exists('json_basic_auth_handler') |
|
196 | + && ! function_exists('json_basic_auth_error') |
|
197 | + && ! ( |
|
198 | + isset($_GET['action']) |
|
199 | + && in_array($_GET['action'], array('activate', 'activate-selected')) |
|
200 | + ) |
|
201 | + && ! ( |
|
202 | + isset($_GET['activate']) |
|
203 | + && $_GET['activate'] === 'true' |
|
204 | + ) |
|
205 | + ) { |
|
206 | + include_once EE_THIRD_PARTY . 'wp-api-basic-auth' . DS . 'basic-auth.php'; |
|
207 | + } |
|
208 | + $this->_maybe_brew_regular(); |
|
209 | + do_action('AHEE__EE_System__load_espresso_addons__complete'); |
|
210 | + |
|
211 | + } |
|
212 | + |
|
213 | + |
|
214 | + |
|
215 | + /** |
|
216 | + * The purpose of this method is to simply check for a file named "caffeinated/brewing_regular.php" for any hooks |
|
217 | + * that need to be setup before our EE_System launches. |
|
218 | + * |
|
219 | + * @return void |
|
220 | + */ |
|
221 | + private function _maybe_brew_regular() |
|
222 | + { |
|
223 | + if (( ! defined('EE_DECAF') || EE_DECAF !== true) && is_readable(EE_CAFF_PATH . 'brewing_regular.php')) { |
|
224 | + require_once EE_CAFF_PATH . 'brewing_regular.php'; |
|
225 | + } |
|
226 | + } |
|
227 | + |
|
228 | + |
|
229 | + |
|
230 | + /** |
|
231 | + * detect_activations_or_upgrades |
|
232 | + * Checks for activation or upgrade of core first; |
|
233 | + * then also checks if any registered addons have been activated or upgraded |
|
234 | + * This is hooked into 'AHEE__EE_Bootstrap__detect_activations_or_upgrades' |
|
235 | + * which runs during the WP 'plugins_loaded' action at priority 3 |
|
236 | + * |
|
237 | + * @access public |
|
238 | + * @return void |
|
239 | + */ |
|
240 | + public function detect_activations_or_upgrades() |
|
241 | + { |
|
242 | + //first off: let's make sure to handle core |
|
243 | + $this->detect_if_activation_or_upgrade(); |
|
244 | + foreach ($this->registry->addons as $addon) { |
|
245 | + //detect teh request type for that addon |
|
246 | + $addon->detect_activation_or_upgrade(); |
|
247 | + } |
|
248 | + } |
|
249 | + |
|
250 | + |
|
251 | + |
|
252 | + /** |
|
253 | + * detect_if_activation_or_upgrade |
|
254 | + * Takes care of detecting whether this is a brand new install or code upgrade, |
|
255 | + * and either setting up the DB or setting up maintenance mode etc. |
|
256 | + * |
|
257 | + * @access public |
|
258 | + * @return void |
|
259 | + */ |
|
260 | + public function detect_if_activation_or_upgrade() |
|
261 | + { |
|
262 | + do_action('AHEE__EE_System___detect_if_activation_or_upgrade__begin'); |
|
263 | + // load M-Mode class |
|
264 | + $this->registry->load_core('Maintenance_Mode'); |
|
265 | + // check if db has been updated, or if its a brand-new installation |
|
266 | + $espresso_db_update = $this->fix_espresso_db_upgrade_option(); |
|
267 | + $request_type = $this->detect_req_type($espresso_db_update); |
|
268 | + //EEH_Debug_Tools::printr( $request_type, '$request_type', __FILE__, __LINE__ ); |
|
269 | + switch ($request_type) { |
|
270 | + case EE_System::req_type_new_activation: |
|
271 | + do_action('AHEE__EE_System__detect_if_activation_or_upgrade__new_activation'); |
|
272 | + $this->_handle_core_version_change($espresso_db_update); |
|
273 | + break; |
|
274 | + case EE_System::req_type_reactivation: |
|
275 | + do_action('AHEE__EE_System__detect_if_activation_or_upgrade__reactivation'); |
|
276 | + $this->_handle_core_version_change($espresso_db_update); |
|
277 | + break; |
|
278 | + case EE_System::req_type_upgrade: |
|
279 | + do_action('AHEE__EE_System__detect_if_activation_or_upgrade__upgrade'); |
|
280 | + //migrations may be required now that we've upgraded |
|
281 | + EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old(); |
|
282 | + $this->_handle_core_version_change($espresso_db_update); |
|
283 | + // echo "done upgrade";die; |
|
284 | + break; |
|
285 | + case EE_System::req_type_downgrade: |
|
286 | + do_action('AHEE__EE_System__detect_if_activation_or_upgrade__downgrade'); |
|
287 | + //its possible migrations are no longer required |
|
288 | + EE_Maintenance_Mode::instance()->set_maintenance_mode_if_db_old(); |
|
289 | + $this->_handle_core_version_change($espresso_db_update); |
|
290 | + break; |
|
291 | + case EE_System::req_type_normal: |
|
292 | + default: |
|
293 | + // $this->_maybe_redirect_to_ee_about(); |
|
294 | + break; |
|
295 | + } |
|
296 | + do_action('AHEE__EE_System__detect_if_activation_or_upgrade__complete'); |
|
297 | + } |
|
298 | + |
|
299 | + |
|
300 | + |
|
301 | + /** |
|
302 | + * Updates the list of installed versions and sets hooks for |
|
303 | + * initializing the database later during the request |
|
304 | + * |
|
305 | + * @param array $espresso_db_update |
|
306 | + */ |
|
307 | + protected function _handle_core_version_change($espresso_db_update) |
|
308 | + { |
|
309 | + $this->update_list_of_installed_versions($espresso_db_update); |
|
310 | + //get ready to verify the DB is ok (provided we aren't in maintenance mode, of course) |
|
311 | + add_action('AHEE__EE_System__perform_activations_upgrades_and_migrations', |
|
312 | + array($this, 'initialize_db_if_no_migrations_required')); |
|
313 | + } |
|
314 | + |
|
315 | + |
|
316 | + |
|
317 | + /** |
|
318 | + * standardizes the wp option 'espresso_db_upgrade' which actually stores |
|
319 | + * information about what versions of EE have been installed and activated, |
|
320 | + * NOT necessarily the state of the database |
|
321 | + * |
|
322 | + * @param null $espresso_db_update |
|
323 | + * @internal param array $espresso_db_update_value the value of the WordPress option. If not supplied, fetches it |
|
324 | + * from the options table |
|
325 | + * @return array the correct value of 'espresso_db_upgrade', after saving it, if it needed correction |
|
326 | + */ |
|
327 | + private function fix_espresso_db_upgrade_option($espresso_db_update = null) |
|
328 | + { |
|
329 | + do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__begin', $espresso_db_update); |
|
330 | + if ( ! $espresso_db_update) { |
|
331 | + $espresso_db_update = get_option('espresso_db_update'); |
|
332 | + } |
|
333 | + // check that option is an array |
|
334 | + if ( ! is_array($espresso_db_update)) { |
|
335 | + // if option is FALSE, then it never existed |
|
336 | + if ($espresso_db_update === false) { |
|
337 | + // make $espresso_db_update an array and save option with autoload OFF |
|
338 | + $espresso_db_update = array(); |
|
339 | + add_option('espresso_db_update', $espresso_db_update, '', 'no'); |
|
340 | + } else { |
|
341 | + // option is NOT FALSE but also is NOT an array, so make it an array and save it |
|
342 | + $espresso_db_update = array($espresso_db_update => array()); |
|
343 | + update_option('espresso_db_update', $espresso_db_update); |
|
344 | + } |
|
345 | + } else { |
|
346 | + $corrected_db_update = array(); |
|
347 | + //if IS an array, but is it an array where KEYS are version numbers, and values are arrays? |
|
348 | + foreach ($espresso_db_update as $should_be_version_string => $should_be_array) { |
|
349 | + if (is_int($should_be_version_string) && ! is_array($should_be_array)) { |
|
350 | + //the key is an int, and the value IS NOT an array |
|
351 | + //so it must be numerically-indexed, where values are versions installed... |
|
352 | + //fix it! |
|
353 | + $version_string = $should_be_array; |
|
354 | + $corrected_db_update[$version_string] = array('unknown-date'); |
|
355 | + } else { |
|
356 | + //ok it checks out |
|
357 | + $corrected_db_update[$should_be_version_string] = $should_be_array; |
|
358 | + } |
|
359 | + } |
|
360 | + $espresso_db_update = $corrected_db_update; |
|
361 | + update_option('espresso_db_update', $espresso_db_update); |
|
362 | + } |
|
363 | + do_action('FHEE__EE_System__manage_fix_espresso_db_upgrade_option__complete', $espresso_db_update); |
|
364 | + return $espresso_db_update; |
|
365 | + } |
|
366 | + |
|
367 | + |
|
368 | + |
|
369 | + /** |
|
370 | + * Does the traditional work of setting up the plugin's database and adding default data. |
|
371 | + * If migration script/process did not exist, this is what would happen on every activation/reactivation/upgrade. |
|
372 | + * NOTE: if we're in maintenance mode (which would be the case if we detect there are data |
|
373 | + * migration scripts that need to be run and a version change happens), enqueues core for database initialization, |
|
374 | + * so that it will be done when migrations are finished |
|
375 | + * |
|
376 | + * @param boolean $initialize_addons_too if true, we double-check addons' database tables etc too; |
|
377 | + * @param boolean $verify_schema if true will re-check the database tables have the correct schema. |
|
378 | + * This is a resource-intensive job |
|
379 | + * so we prefer to only do it when necessary |
|
380 | + * @return void |
|
381 | + */ |
|
382 | + public function initialize_db_if_no_migrations_required($initialize_addons_too = false, $verify_schema = true) |
|
383 | + { |
|
384 | + $request_type = $this->detect_req_type(); |
|
385 | + //only initialize system if we're not in maintenance mode. |
|
386 | + if (EE_Maintenance_Mode::instance()->level() != EE_Maintenance_Mode::level_2_complete_maintenance) { |
|
387 | + update_option('ee_flush_rewrite_rules', true); |
|
388 | + if ($verify_schema) { |
|
389 | + EEH_Activation::initialize_db_and_folders(); |
|
390 | + } |
|
391 | + EEH_Activation::initialize_db_content(); |
|
392 | + EEH_Activation::system_initialization(); |
|
393 | + if ($initialize_addons_too) { |
|
394 | + $this->initialize_addons(); |
|
395 | + } |
|
396 | + } else { |
|
397 | + EE_Data_Migration_Manager::instance()->enqueue_db_initialization_for('Core'); |
|
398 | + } |
|
399 | + if ($request_type === EE_System::req_type_new_activation |
|
400 | + || $request_type === EE_System::req_type_reactivation |
|
401 | + || ( |
|
402 | + $request_type === EE_System::req_type_upgrade |
|
403 | + && $this->is_major_version_change() |
|
404 | + ) |
|
405 | + ) { |
|
406 | + add_action('AHEE__EE_System__initialize_last', array($this, 'redirect_to_about_ee'), 9); |
|
407 | + } |
|
408 | + } |
|
409 | + |
|
410 | + |
|
411 | + |
|
412 | + /** |
|
413 | + * Initializes the db for all registered addons |
|
414 | + */ |
|
415 | + public function initialize_addons() |
|
416 | + { |
|
417 | + //foreach registered addon, make sure its db is up-to-date too |
|
418 | + foreach ($this->registry->addons as $addon) { |
|
419 | + $addon->initialize_db_if_no_migrations_required(); |
|
420 | + } |
|
421 | + } |
|
422 | + |
|
423 | + |
|
424 | + |
|
425 | + /** |
|
426 | + * Adds the current code version to the saved wp option which stores a list of all ee versions ever installed. |
|
427 | + * |
|
428 | + * @param array $version_history |
|
429 | + * @param string $current_version_to_add version to be added to the version history |
|
430 | + * @return boolean success as to whether or not this option was changed |
|
431 | + */ |
|
432 | + public function update_list_of_installed_versions($version_history = null, $current_version_to_add = null) |
|
433 | + { |
|
434 | + if ( ! $version_history) { |
|
435 | + $version_history = $this->fix_espresso_db_upgrade_option($version_history); |
|
436 | + } |
|
437 | + if ($current_version_to_add == null) { |
|
438 | + $current_version_to_add = espresso_version(); |
|
439 | + } |
|
440 | + $version_history[$current_version_to_add][] = date('Y-m-d H:i:s', time()); |
|
441 | + // re-save |
|
442 | + return update_option('espresso_db_update', $version_history); |
|
443 | + } |
|
444 | + |
|
445 | + |
|
446 | + |
|
447 | + /** |
|
448 | + * Detects if the current version indicated in the has existed in the list of |
|
449 | + * previously-installed versions of EE (espresso_db_update). Does NOT modify it (ie, no side-effect) |
|
450 | + * |
|
451 | + * @param array $espresso_db_update array from the wp option stored under the name 'espresso_db_update'. |
|
452 | + * If not supplied, fetches it from the options table. |
|
453 | + * Also, caches its result so later parts of the code can also know whether |
|
454 | + * there's been an update or not. This way we can add the current version to |
|
455 | + * espresso_db_update, but still know if this is a new install or not |
|
456 | + * @return int one of the constants on EE_System::req_type_ |
|
457 | + */ |
|
458 | + public function detect_req_type($espresso_db_update = null) |
|
459 | + { |
|
460 | + if ($this->_req_type === null) { |
|
461 | + $espresso_db_update = ! empty($espresso_db_update) ? $espresso_db_update |
|
462 | + : $this->fix_espresso_db_upgrade_option(); |
|
463 | + $this->_req_type = $this->detect_req_type_given_activation_history($espresso_db_update, |
|
464 | + 'ee_espresso_activation', espresso_version()); |
|
465 | + $this->_major_version_change = $this->_detect_major_version_change($espresso_db_update); |
|
466 | + } |
|
467 | + return $this->_req_type; |
|
468 | + } |
|
469 | + |
|
470 | + |
|
471 | + |
|
472 | + /** |
|
473 | + * Returns whether or not there was a non-micro version change (ie, change in either |
|
474 | + * the first or second number in the version. Eg 4.9.0.rc.001 to 4.10.0.rc.000, |
|
475 | + * but not 4.9.0.rc.0001 to 4.9.1.rc.0001 |
|
476 | + * |
|
477 | + * @param $activation_history |
|
478 | + * @return bool |
|
479 | + */ |
|
480 | + protected function _detect_major_version_change($activation_history) |
|
481 | + { |
|
482 | + $previous_version = EE_System::_get_most_recently_active_version_from_activation_history($activation_history); |
|
483 | + $previous_version_parts = explode('.', $previous_version); |
|
484 | + $current_version_parts = explode('.', espresso_version()); |
|
485 | + return isset($previous_version_parts[0], $previous_version_parts[1], $current_version_parts[0], $current_version_parts[1]) |
|
486 | + && ($previous_version_parts[0] !== $current_version_parts[0] |
|
487 | + || $previous_version_parts[1] !== $current_version_parts[1] |
|
488 | + ); |
|
489 | + } |
|
490 | + |
|
491 | + |
|
492 | + |
|
493 | + /** |
|
494 | + * Returns true if either the major or minor version of EE changed during this request. |
|
495 | + * Eg 4.9.0.rc.001 to 4.10.0.rc.000, but not 4.9.0.rc.0001 to 4.9.1.rc.0001 |
|
496 | + * |
|
497 | + * @return bool |
|
498 | + */ |
|
499 | + public function is_major_version_change() |
|
500 | + { |
|
501 | + return $this->_major_version_change; |
|
502 | + } |
|
503 | + |
|
504 | + |
|
505 | + |
|
506 | + /** |
|
507 | + * Determines the request type for any ee addon, given three piece of info: the current array of activation |
|
508 | + * histories (for core that' 'espresso_db_update' wp option); the name of the wordpress option which is temporarily |
|
509 | + * set upon activation of the plugin (for core it's 'ee_espresso_activation'); and the version that this plugin was |
|
510 | + * just activated to (for core that will always be espresso_version()) |
|
511 | + * |
|
512 | + * @param array $activation_history_for_addon the option's value which stores the activation history for this |
|
513 | + * ee plugin. for core that's 'espresso_db_update' |
|
514 | + * @param string $activation_indicator_option_name the name of the wordpress option that is temporarily set to |
|
515 | + * indicate that this plugin was just activated |
|
516 | + * @param string $version_to_upgrade_to the version that was just upgraded to (for core that will be |
|
517 | + * espresso_version()) |
|
518 | + * @return int one of the constants on EE_System::req_type_* |
|
519 | + */ |
|
520 | + public static function detect_req_type_given_activation_history( |
|
521 | + $activation_history_for_addon, |
|
522 | + $activation_indicator_option_name, |
|
523 | + $version_to_upgrade_to |
|
524 | + ) { |
|
525 | + $version_is_higher = self::_new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to); |
|
526 | + if ($activation_history_for_addon) { |
|
527 | + //it exists, so this isn't a completely new install |
|
528 | + //check if this version already in that list of previously installed versions |
|
529 | + if ( ! isset($activation_history_for_addon[$version_to_upgrade_to])) { |
|
530 | + //it a version we haven't seen before |
|
531 | + if ($version_is_higher === 1) { |
|
532 | + $req_type = EE_System::req_type_upgrade; |
|
533 | + } else { |
|
534 | + $req_type = EE_System::req_type_downgrade; |
|
535 | + } |
|
536 | + delete_option($activation_indicator_option_name); |
|
537 | + } else { |
|
538 | + // its not an update. maybe a reactivation? |
|
539 | + if (get_option($activation_indicator_option_name, false)) { |
|
540 | + if ($version_is_higher === -1) { |
|
541 | + $req_type = EE_System::req_type_downgrade; |
|
542 | + } elseif ($version_is_higher === 0) { |
|
543 | + //we've seen this version before, but it's an activation. must be a reactivation |
|
544 | + $req_type = EE_System::req_type_reactivation; |
|
545 | + } else {//$version_is_higher === 1 |
|
546 | + $req_type = EE_System::req_type_upgrade; |
|
547 | + } |
|
548 | + delete_option($activation_indicator_option_name); |
|
549 | + } else { |
|
550 | + //we've seen this version before and the activation indicate doesn't show it was just activated |
|
551 | + if ($version_is_higher === -1) { |
|
552 | + $req_type = EE_System::req_type_downgrade; |
|
553 | + } elseif ($version_is_higher === 0) { |
|
554 | + //we've seen this version before and it's not an activation. its normal request |
|
555 | + $req_type = EE_System::req_type_normal; |
|
556 | + } else {//$version_is_higher === 1 |
|
557 | + $req_type = EE_System::req_type_upgrade; |
|
558 | + } |
|
559 | + } |
|
560 | + } |
|
561 | + } else { |
|
562 | + //brand new install |
|
563 | + $req_type = EE_System::req_type_new_activation; |
|
564 | + delete_option($activation_indicator_option_name); |
|
565 | + } |
|
566 | + return $req_type; |
|
567 | + } |
|
568 | + |
|
569 | + |
|
570 | + |
|
571 | + /** |
|
572 | + * Detects if the $version_to_upgrade_to is higher than the most recent version in |
|
573 | + * the $activation_history_for_addon |
|
574 | + * |
|
575 | + * @param array $activation_history_for_addon (keys are versions, values are arrays of times activated, |
|
576 | + * sometimes containing 'unknown-date' |
|
577 | + * @param string $version_to_upgrade_to (current version) |
|
578 | + * @return int results of version_compare( $version_to_upgrade_to, $most_recently_active_version ). |
|
579 | + * ie, -1 if $version_to_upgrade_to is LOWER (downgrade); |
|
580 | + * 0 if $version_to_upgrade_to MATCHES (reactivation or normal request); |
|
581 | + * 1 if $version_to_upgrade_to is HIGHER (upgrade) ; |
|
582 | + */ |
|
583 | + protected static function _new_version_is_higher($activation_history_for_addon, $version_to_upgrade_to) |
|
584 | + { |
|
585 | + //find the most recently-activated version |
|
586 | + $most_recently_active_version = EE_System::_get_most_recently_active_version_from_activation_history($activation_history_for_addon); |
|
587 | + return version_compare($version_to_upgrade_to, $most_recently_active_version); |
|
588 | + } |
|
589 | + |
|
590 | + |
|
591 | + |
|
592 | + /** |
|
593 | + * Gets the most recently active version listed in the activation history, |
|
594 | + * and if none are found (ie, it's a brand new install) returns '0.0.0.dev.000'. |
|
595 | + * |
|
596 | + * @param array $activation_history (keys are versions, values are arrays of times activated, |
|
597 | + * sometimes containing 'unknown-date' |
|
598 | + * @return string |
|
599 | + */ |
|
600 | + protected static function _get_most_recently_active_version_from_activation_history($activation_history) |
|
601 | + { |
|
602 | + $most_recently_active_version_activation = '1970-01-01 00:00:00'; |
|
603 | + $most_recently_active_version = '0.0.0.dev.000'; |
|
604 | + if (is_array($activation_history)) { |
|
605 | + foreach ($activation_history as $version => $times_activated) { |
|
606 | + //check there is a record of when this version was activated. Otherwise, |
|
607 | + //mark it as unknown |
|
608 | + if ( ! $times_activated) { |
|
609 | + $times_activated = array('unknown-date'); |
|
610 | + } |
|
611 | + if (is_string($times_activated)) { |
|
612 | + $times_activated = array($times_activated); |
|
613 | + } |
|
614 | + foreach ($times_activated as $an_activation) { |
|
615 | + if ($an_activation != 'unknown-date' && $an_activation > $most_recently_active_version_activation) { |
|
616 | + $most_recently_active_version = $version; |
|
617 | + $most_recently_active_version_activation = $an_activation == 'unknown-date' |
|
618 | + ? '1970-01-01 00:00:00' : $an_activation; |
|
619 | + } |
|
620 | + } |
|
621 | + } |
|
622 | + } |
|
623 | + return $most_recently_active_version; |
|
624 | + } |
|
625 | + |
|
626 | + |
|
627 | + |
|
628 | + /** |
|
629 | + * This redirects to the about EE page after activation |
|
630 | + * |
|
631 | + * @return void |
|
632 | + */ |
|
633 | + public function redirect_to_about_ee() |
|
634 | + { |
|
635 | + $notices = EE_Error::get_notices(false); |
|
636 | + //if current user is an admin and it's not an ajax or rest request |
|
637 | + if ( |
|
638 | + ! (defined('DOING_AJAX') && DOING_AJAX) |
|
639 | + && ! (defined('REST_REQUEST') && REST_REQUEST) |
|
640 | + && ! isset($notices['errors']) |
|
641 | + && apply_filters( |
|
642 | + 'FHEE__EE_System__redirect_to_about_ee__do_redirect', |
|
643 | + $this->registry->CAP->current_user_can('manage_options', 'espresso_about_default') |
|
644 | + ) |
|
645 | + ) { |
|
646 | + $query_params = array('page' => 'espresso_about'); |
|
647 | + if (EE_System::instance()->detect_req_type() == EE_System::req_type_new_activation) { |
|
648 | + $query_params['new_activation'] = true; |
|
649 | + } |
|
650 | + if (EE_System::instance()->detect_req_type() == EE_System::req_type_reactivation) { |
|
651 | + $query_params['reactivation'] = true; |
|
652 | + } |
|
653 | + $url = add_query_arg($query_params, admin_url('admin.php')); |
|
654 | + wp_safe_redirect($url); |
|
655 | + exit(); |
|
656 | + } |
|
657 | + } |
|
658 | + |
|
659 | + |
|
660 | + |
|
661 | + /** |
|
662 | + * load_core_configuration |
|
663 | + * this is hooked into 'AHEE__EE_Bootstrap__load_core_configuration' |
|
664 | + * which runs during the WP 'plugins_loaded' action at priority 5 |
|
665 | + * |
|
666 | + * @return void |
|
667 | + */ |
|
668 | + public function load_core_configuration() |
|
669 | + { |
|
670 | + do_action('AHEE__EE_System__load_core_configuration__begin', $this); |
|
671 | + $this->registry->load_core('EE_Load_Textdomain'); |
|
672 | + //load textdomain |
|
673 | + EE_Load_Textdomain::load_textdomain(); |
|
674 | + // load and setup EE_Config and EE_Network_Config |
|
675 | + $this->registry->load_core('Config'); |
|
676 | + $this->registry->load_core('Network_Config'); |
|
677 | + // setup autoloaders |
|
678 | + // enable logging? |
|
679 | + if ($this->registry->CFG->admin->use_full_logging) { |
|
680 | + $this->registry->load_core('Log'); |
|
681 | + } |
|
682 | + // check for activation errors |
|
683 | + $activation_errors = get_option('ee_plugin_activation_errors', false); |
|
684 | + if ($activation_errors) { |
|
685 | + EE_Error::add_error($activation_errors, __FILE__, __FUNCTION__, __LINE__); |
|
686 | + update_option('ee_plugin_activation_errors', false); |
|
687 | + } |
|
688 | + // get model names |
|
689 | + $this->_parse_model_names(); |
|
690 | + do_action('AHEE__EE_System__load_core_configuration__complete', $this); |
|
691 | + } |
|
692 | + |
|
693 | + |
|
694 | + |
|
695 | + /** |
|
696 | + * cycles through all of the models/*.model.php files, and assembles an array of model names |
|
697 | + * |
|
698 | + * @return void |
|
699 | + */ |
|
700 | + private function _parse_model_names() |
|
701 | + { |
|
702 | + //call the non-abstract db models method, which verifies the model names have been discovered |
|
703 | + //for the sake of unit tests, always re-discover the models. We could probably make this more |
|
704 | + //efficient though (e.g., have unit tests reset the registered models in a different way) |
|
705 | + $this->registry->non_abstract_db_models = array(); |
|
706 | + $this->registry->non_abstract_db_models(); |
|
707 | + } |
|
708 | + |
|
709 | + |
|
710 | + |
|
711 | + /** |
|
712 | + * register_shortcodes_modules_and_widgets |
|
713 | + * generate lists of shortcodes and modules, then verify paths and classes |
|
714 | + * This is hooked into 'AHEE__EE_Bootstrap__register_shortcodes_modules_and_widgets' |
|
715 | + * which runs during the WP 'plugins_loaded' action at priority 7 |
|
716 | + * |
|
717 | + * @access public |
|
718 | + * @return void |
|
719 | + */ |
|
720 | + public function register_shortcodes_modules_and_widgets() |
|
721 | + { |
|
722 | + try { |
|
723 | + // load, register, and add shortcodes the new way |
|
724 | + new ShortcodesManager( |
|
725 | + // and the old way, but we'll put it under control of the new system |
|
726 | + EE_Config::getLegacyShortcodesManager() |
|
727 | + ); |
|
728 | + } catch (Exception $exception) { |
|
729 | + new ExceptionStackTraceDisplay($exception); |
|
730 | + } |
|
731 | + do_action('AHEE__EE_System__register_shortcodes_modules_and_widgets'); |
|
732 | + // check for addons using old hookpoint |
|
733 | + if (has_action('AHEE__EE_System__register_shortcodes_modules_and_addons')) { |
|
734 | + $this->_incompatible_addon_error(); |
|
735 | + } |
|
736 | + } |
|
737 | + |
|
738 | + |
|
739 | + |
|
740 | + /** |
|
741 | + * _incompatible_addon_error |
|
742 | + * |
|
743 | + * @access public |
|
744 | + * @return void |
|
745 | + */ |
|
746 | + private function _incompatible_addon_error() |
|
747 | + { |
|
748 | + // get array of classes hooking into here |
|
749 | + $class_names = EEH_Class_Tools::get_class_names_for_all_callbacks_on_hook('AHEE__EE_System__register_shortcodes_modules_and_addons'); |
|
750 | + if ( ! empty($class_names)) { |
|
751 | + $msg = __('The following plugins, addons, or modules appear to be incompatible with this version of Event Espresso and were automatically deactivated to avoid fatal errors:', |
|
752 | + 'event_espresso'); |
|
753 | + $msg .= '<ul>'; |
|
754 | + foreach ($class_names as $class_name) { |
|
755 | + $msg .= '<li><b>Event Espresso - ' . str_replace(array('EE_', 'EEM_', 'EED_', 'EES_', 'EEW_'), '', |
|
756 | + $class_name) . '</b></li>'; |
|
757 | + } |
|
758 | + $msg .= '</ul>'; |
|
759 | + $msg .= __('Compatibility issues can be avoided and/or resolved by keeping addons and plugins updated to the latest version.', |
|
760 | + 'event_espresso'); |
|
761 | + // save list of incompatible addons to wp-options for later use |
|
762 | + add_option('ee_incompatible_addons', $class_names, '', 'no'); |
|
763 | + if (is_admin()) { |
|
764 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
765 | + } |
|
766 | + } |
|
767 | + } |
|
768 | + |
|
769 | + |
|
770 | + |
|
771 | + /** |
|
772 | + * brew_espresso |
|
773 | + * begins the process of setting hooks for initializing EE in the correct order |
|
774 | + * This is happening on the 'AHEE__EE_Bootstrap__brew_espresso' hookpoint |
|
775 | + * which runs during the WP 'plugins_loaded' action at priority 9 |
|
776 | + * |
|
777 | + * @return void |
|
778 | + */ |
|
779 | + public function brew_espresso() |
|
780 | + { |
|
781 | + do_action('AHEE__EE_System__brew_espresso__begin', $this); |
|
782 | + // load some final core systems |
|
783 | + add_action('init', array($this, 'set_hooks_for_core'), 1); |
|
784 | + add_action('init', array($this, 'perform_activations_upgrades_and_migrations'), 3); |
|
785 | + add_action('init', array($this, 'load_CPTs_and_session'), 5); |
|
786 | + add_action('init', array($this, 'load_controllers'), 7); |
|
787 | + add_action('init', array($this, 'core_loaded_and_ready'), 9); |
|
788 | + add_action('init', array($this, 'initialize'), 10); |
|
789 | + add_action('init', array($this, 'initialize_last'), 100); |
|
790 | + add_action('wp_enqueue_scripts', array($this, 'wp_enqueue_scripts'), 100); |
|
791 | + add_action('admin_enqueue_scripts', array($this, 'wp_enqueue_scripts'), 100); |
|
792 | + add_action('admin_bar_menu', array($this, 'espresso_toolbar_items'), 100); |
|
793 | + if (is_admin() && apply_filters('FHEE__EE_System__brew_espresso__load_pue', true)) { |
|
794 | + // pew pew pew |
|
795 | + $this->registry->load_core('PUE'); |
|
796 | + do_action('AHEE__EE_System__brew_espresso__after_pue_init'); |
|
797 | + } |
|
798 | + do_action('AHEE__EE_System__brew_espresso__complete', $this); |
|
799 | + } |
|
800 | + |
|
801 | + |
|
802 | + |
|
803 | + /** |
|
804 | + * set_hooks_for_core |
|
805 | + * |
|
806 | + * @access public |
|
807 | + * @return void |
|
808 | + */ |
|
809 | + public function set_hooks_for_core() |
|
810 | + { |
|
811 | + //caps need to be initialized on every request so that capability maps are set. |
|
812 | + //@see https://events.codebasehq.com/projects/event-espresso/tickets/8674 |
|
813 | + //load and setup EE_Capabilities |
|
814 | + $this->registry->load_core('Capabilities'); |
|
815 | + $this->registry->CAP->init_caps(); |
|
816 | + $this->_deactivate_incompatible_addons(); |
|
817 | + do_action('AHEE__EE_System__set_hooks_for_core'); |
|
818 | + } |
|
819 | + |
|
820 | + |
|
821 | + |
|
822 | + /** |
|
823 | + * Using the information gathered in EE_System::_incompatible_addon_error, |
|
824 | + * deactivates any addons considered incompatible with the current version of EE |
|
825 | + */ |
|
826 | + private function _deactivate_incompatible_addons() |
|
827 | + { |
|
828 | + $incompatible_addons = get_option('ee_incompatible_addons', array()); |
|
829 | + if ( ! empty($incompatible_addons)) { |
|
830 | + $active_plugins = get_option('active_plugins', array()); |
|
831 | + foreach ($active_plugins as $active_plugin) { |
|
832 | + foreach ($incompatible_addons as $incompatible_addon) { |
|
833 | + if (strpos($active_plugin, $incompatible_addon) !== false) { |
|
834 | + unset($_GET['activate']); |
|
835 | + espresso_deactivate_plugin($active_plugin); |
|
836 | + } |
|
837 | + } |
|
838 | + } |
|
839 | + } |
|
840 | + } |
|
841 | + |
|
842 | + |
|
843 | + |
|
844 | + /** |
|
845 | + * perform_activations_upgrades_and_migrations |
|
846 | + * |
|
847 | + * @access public |
|
848 | + * @return void |
|
849 | + */ |
|
850 | + public function perform_activations_upgrades_and_migrations() |
|
851 | + { |
|
852 | + //first check if we had previously attempted to setup EE's directories but failed |
|
853 | + if (EEH_Activation::upload_directories_incomplete()) { |
|
854 | + EEH_Activation::create_upload_directories(); |
|
855 | + } |
|
856 | + do_action('AHEE__EE_System__perform_activations_upgrades_and_migrations'); |
|
857 | + } |
|
858 | + |
|
859 | + |
|
860 | + |
|
861 | + /** |
|
862 | + * load_CPTs_and_session |
|
863 | + * |
|
864 | + * @access public |
|
865 | + * @return void |
|
866 | + */ |
|
867 | + public function load_CPTs_and_session() |
|
868 | + { |
|
869 | + do_action('AHEE__EE_System__load_CPTs_and_session__start'); |
|
870 | + // register Custom Post Types |
|
871 | + $this->registry->load_core('Register_CPTs'); |
|
872 | + do_action('AHEE__EE_System__load_CPTs_and_session__complete'); |
|
873 | + } |
|
874 | + |
|
875 | + |
|
876 | + |
|
877 | + /** |
|
878 | + * load_controllers |
|
879 | + * this is the best place to load any additional controllers that needs access to EE core. |
|
880 | + * it is expected that all basic core EE systems, that are not dependant on the current request are loaded at this |
|
881 | + * time |
|
882 | + * |
|
883 | + * @access public |
|
884 | + * @return void |
|
885 | + */ |
|
886 | + public function load_controllers() |
|
887 | + { |
|
888 | + do_action('AHEE__EE_System__load_controllers__start'); |
|
889 | + // let's get it started |
|
890 | + if ( ! is_admin() && ! EE_Maintenance_Mode::instance()->level()) { |
|
891 | + do_action('AHEE__EE_System__load_controllers__load_front_controllers'); |
|
892 | + $this->registry->load_core('Front_Controller'); |
|
893 | + } else if ( ! EE_FRONT_AJAX) { |
|
894 | + do_action('AHEE__EE_System__load_controllers__load_admin_controllers'); |
|
895 | + EE_Registry::instance()->load_core('Admin'); |
|
896 | + } |
|
897 | + do_action('AHEE__EE_System__load_controllers__complete'); |
|
898 | + } |
|
899 | + |
|
900 | + |
|
901 | + |
|
902 | + /** |
|
903 | + * core_loaded_and_ready |
|
904 | + * all of the basic EE core should be loaded at this point and available regardless of M-Mode |
|
905 | + * |
|
906 | + * @access public |
|
907 | + * @return void |
|
908 | + */ |
|
909 | + public function core_loaded_and_ready() |
|
910 | + { |
|
911 | + do_action('AHEE__EE_System__core_loaded_and_ready'); |
|
912 | + // load_espresso_template_tags |
|
913 | + if (is_readable(EE_PUBLIC . 'template_tags.php')) { |
|
914 | + require_once(EE_PUBLIC . 'template_tags.php'); |
|
915 | + } |
|
916 | + do_action('AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons'); |
|
917 | + $this->registry->load_core('Session'); |
|
918 | + } |
|
919 | + |
|
920 | + |
|
921 | + |
|
922 | + /** |
|
923 | + * initialize |
|
924 | + * this is the best place to begin initializing client code |
|
925 | + * |
|
926 | + * @access public |
|
927 | + * @return void |
|
928 | + */ |
|
929 | + public function initialize() |
|
930 | + { |
|
931 | + do_action('AHEE__EE_System__initialize'); |
|
932 | + } |
|
933 | + |
|
934 | + |
|
935 | + |
|
936 | + /** |
|
937 | + * initialize_last |
|
938 | + * this is run really late during the WP init hookpoint, and ensures that mostly everything else that needs to |
|
939 | + * initialize has done so |
|
940 | + * |
|
941 | + * @access public |
|
942 | + * @return void |
|
943 | + */ |
|
944 | + public function initialize_last() |
|
945 | + { |
|
946 | + do_action('AHEE__EE_System__initialize_last'); |
|
947 | + } |
|
948 | + |
|
949 | + |
|
950 | + |
|
951 | + /** |
|
952 | + * set_hooks_for_shortcodes_modules_and_addons |
|
953 | + * this is the best place for other systems to set callbacks for hooking into other parts of EE |
|
954 | + * this happens at the very beginning of the wp_loaded hookpoint |
|
955 | + * |
|
956 | + * @access public |
|
957 | + * @return void |
|
958 | + */ |
|
959 | + public function set_hooks_for_shortcodes_modules_and_addons() |
|
960 | + { |
|
961 | + // do_action( 'AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons' ); |
|
962 | + } |
|
963 | + |
|
964 | + |
|
965 | + |
|
966 | + /** |
|
967 | + * do_not_cache |
|
968 | + * sets no cache headers and defines no cache constants for WP plugins |
|
969 | + * |
|
970 | + * @access public |
|
971 | + * @return void |
|
972 | + */ |
|
973 | + public static function do_not_cache() |
|
974 | + { |
|
975 | + // set no cache constants |
|
976 | + if ( ! defined('DONOTCACHEPAGE')) { |
|
977 | + define('DONOTCACHEPAGE', true); |
|
978 | + } |
|
979 | + if ( ! defined('DONOTCACHCEOBJECT')) { |
|
980 | + define('DONOTCACHCEOBJECT', true); |
|
981 | + } |
|
982 | + if ( ! defined('DONOTCACHEDB')) { |
|
983 | + define('DONOTCACHEDB', true); |
|
984 | + } |
|
985 | + // add no cache headers |
|
986 | + add_action('send_headers', array('EE_System', 'nocache_headers'), 10); |
|
987 | + // plus a little extra for nginx and Google Chrome |
|
988 | + add_filter('nocache_headers', array('EE_System', 'extra_nocache_headers'), 10, 1); |
|
989 | + // prevent browsers from prefetching of the rel='next' link, because it may contain content that interferes with the registration process |
|
990 | + remove_action('wp_head', 'adjacent_posts_rel_link_wp_head'); |
|
991 | + } |
|
992 | + |
|
993 | + |
|
994 | + |
|
995 | + /** |
|
996 | + * extra_nocache_headers |
|
997 | + * |
|
998 | + * @access public |
|
999 | + * @param $headers |
|
1000 | + * @return array |
|
1001 | + */ |
|
1002 | + public static function extra_nocache_headers($headers) |
|
1003 | + { |
|
1004 | + // for NGINX |
|
1005 | + $headers['X-Accel-Expires'] = 0; |
|
1006 | + // plus extra for Google Chrome since it doesn't seem to respect "no-cache", but WILL respect "no-store" |
|
1007 | + $headers['Cache-Control'] = 'no-store, no-cache, must-revalidate, max-age=0'; |
|
1008 | + return $headers; |
|
1009 | + } |
|
1010 | + |
|
1011 | + |
|
1012 | + |
|
1013 | + /** |
|
1014 | + * nocache_headers |
|
1015 | + * |
|
1016 | + * @access public |
|
1017 | + * @return void |
|
1018 | + */ |
|
1019 | + public static function nocache_headers() |
|
1020 | + { |
|
1021 | + nocache_headers(); |
|
1022 | + } |
|
1023 | + |
|
1024 | + |
|
1025 | + |
|
1026 | + /** |
|
1027 | + * espresso_toolbar_items |
|
1028 | + * |
|
1029 | + * @access public |
|
1030 | + * @param WP_Admin_Bar $admin_bar |
|
1031 | + * @return void |
|
1032 | + */ |
|
1033 | + public function espresso_toolbar_items(WP_Admin_Bar $admin_bar) |
|
1034 | + { |
|
1035 | + // if in full M-Mode, or its an AJAX request, or user is NOT an admin |
|
1036 | + if (EE_Maintenance_Mode::instance()->level() == EE_Maintenance_Mode::level_2_complete_maintenance |
|
1037 | + || defined('DOING_AJAX') |
|
1038 | + || ! $this->registry->CAP->current_user_can('ee_read_ee', 'ee_admin_bar_menu_top_level') |
|
1039 | + ) { |
|
1040 | + return; |
|
1041 | + } |
|
1042 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
1043 | + $menu_class = 'espresso_menu_item_class'; |
|
1044 | + //we don't use the constants EVENTS_ADMIN_URL or REG_ADMIN_URL |
|
1045 | + //because they're only defined in each of their respective constructors |
|
1046 | + //and this might be a frontend request, in which case they aren't available |
|
1047 | + $events_admin_url = admin_url("admin.php?page=espresso_events"); |
|
1048 | + $reg_admin_url = admin_url("admin.php?page=espresso_registrations"); |
|
1049 | + $extensions_admin_url = admin_url("admin.php?page=espresso_packages"); |
|
1050 | + //Top Level |
|
1051 | + $admin_bar->add_menu(array( |
|
1052 | + 'id' => 'espresso-toolbar', |
|
1053 | + 'title' => '<span class="ee-icon ee-icon-ee-cup-thick ee-icon-size-20"></span><span class="ab-label">' |
|
1054 | + . _x('Event Espresso', 'admin bar menu group label', 'event_espresso') |
|
1055 | + . '</span>', |
|
1056 | + 'href' => $events_admin_url, |
|
1057 | + 'meta' => array( |
|
1058 | + 'title' => __('Event Espresso', 'event_espresso'), |
|
1059 | + 'class' => $menu_class . 'first', |
|
1060 | + ), |
|
1061 | + )); |
|
1062 | + //Events |
|
1063 | + if ($this->registry->CAP->current_user_can('ee_read_events', 'ee_admin_bar_menu_espresso-toolbar-events')) { |
|
1064 | + $admin_bar->add_menu(array( |
|
1065 | + 'id' => 'espresso-toolbar-events', |
|
1066 | + 'parent' => 'espresso-toolbar', |
|
1067 | + 'title' => __('Events', 'event_espresso'), |
|
1068 | + 'href' => $events_admin_url, |
|
1069 | + 'meta' => array( |
|
1070 | + 'title' => __('Events', 'event_espresso'), |
|
1071 | + 'target' => '', |
|
1072 | + 'class' => $menu_class, |
|
1073 | + ), |
|
1074 | + )); |
|
1075 | + } |
|
1076 | + if ($this->registry->CAP->current_user_can('ee_edit_events', 'ee_admin_bar_menu_espresso-toolbar-events-new')) { |
|
1077 | + //Events Add New |
|
1078 | + $admin_bar->add_menu(array( |
|
1079 | + 'id' => 'espresso-toolbar-events-new', |
|
1080 | + 'parent' => 'espresso-toolbar-events', |
|
1081 | + 'title' => __('Add New', 'event_espresso'), |
|
1082 | + 'href' => EEH_URL::add_query_args_and_nonce(array('action' => 'create_new'), $events_admin_url), |
|
1083 | + 'meta' => array( |
|
1084 | + 'title' => __('Add New', 'event_espresso'), |
|
1085 | + 'target' => '', |
|
1086 | + 'class' => $menu_class, |
|
1087 | + ), |
|
1088 | + )); |
|
1089 | + } |
|
1090 | + if (is_single() && (get_post_type() == 'espresso_events')) { |
|
1091 | + //Current post |
|
1092 | + global $post; |
|
1093 | + if ($this->registry->CAP->current_user_can('ee_edit_event', |
|
1094 | + 'ee_admin_bar_menu_espresso-toolbar-events-edit', $post->ID) |
|
1095 | + ) { |
|
1096 | + //Events Edit Current Event |
|
1097 | + $admin_bar->add_menu(array( |
|
1098 | + 'id' => 'espresso-toolbar-events-edit', |
|
1099 | + 'parent' => 'espresso-toolbar-events', |
|
1100 | + 'title' => __('Edit Event', 'event_espresso'), |
|
1101 | + 'href' => EEH_URL::add_query_args_and_nonce(array('action' => 'edit', 'post' => $post->ID), |
|
1102 | + $events_admin_url), |
|
1103 | + 'meta' => array( |
|
1104 | + 'title' => __('Edit Event', 'event_espresso'), |
|
1105 | + 'target' => '', |
|
1106 | + 'class' => $menu_class, |
|
1107 | + ), |
|
1108 | + )); |
|
1109 | + } |
|
1110 | + } |
|
1111 | + //Events View |
|
1112 | + if ($this->registry->CAP->current_user_can('ee_read_events', |
|
1113 | + 'ee_admin_bar_menu_espresso-toolbar-events-view') |
|
1114 | + ) { |
|
1115 | + $admin_bar->add_menu(array( |
|
1116 | + 'id' => 'espresso-toolbar-events-view', |
|
1117 | + 'parent' => 'espresso-toolbar-events', |
|
1118 | + 'title' => __('View', 'event_espresso'), |
|
1119 | + 'href' => $events_admin_url, |
|
1120 | + 'meta' => array( |
|
1121 | + 'title' => __('View', 'event_espresso'), |
|
1122 | + 'target' => '', |
|
1123 | + 'class' => $menu_class, |
|
1124 | + ), |
|
1125 | + )); |
|
1126 | + } |
|
1127 | + if ($this->registry->CAP->current_user_can('ee_read_events', 'ee_admin_bar_menu_espresso-toolbar-events-all')) { |
|
1128 | + //Events View All |
|
1129 | + $admin_bar->add_menu(array( |
|
1130 | + 'id' => 'espresso-toolbar-events-all', |
|
1131 | + 'parent' => 'espresso-toolbar-events-view', |
|
1132 | + 'title' => __('All', 'event_espresso'), |
|
1133 | + 'href' => $events_admin_url, |
|
1134 | + 'meta' => array( |
|
1135 | + 'title' => __('All', 'event_espresso'), |
|
1136 | + 'target' => '', |
|
1137 | + 'class' => $menu_class, |
|
1138 | + ), |
|
1139 | + )); |
|
1140 | + } |
|
1141 | + if ($this->registry->CAP->current_user_can('ee_read_events', |
|
1142 | + 'ee_admin_bar_menu_espresso-toolbar-events-today') |
|
1143 | + ) { |
|
1144 | + //Events View Today |
|
1145 | + $admin_bar->add_menu(array( |
|
1146 | + 'id' => 'espresso-toolbar-events-today', |
|
1147 | + 'parent' => 'espresso-toolbar-events-view', |
|
1148 | + 'title' => __('Today', 'event_espresso'), |
|
1149 | + 'href' => EEH_URL::add_query_args_and_nonce(array('action' => 'default', 'status' => 'today'), |
|
1150 | + $events_admin_url), |
|
1151 | + 'meta' => array( |
|
1152 | + 'title' => __('Today', 'event_espresso'), |
|
1153 | + 'target' => '', |
|
1154 | + 'class' => $menu_class, |
|
1155 | + ), |
|
1156 | + )); |
|
1157 | + } |
|
1158 | + if ($this->registry->CAP->current_user_can('ee_read_events', |
|
1159 | + 'ee_admin_bar_menu_espresso-toolbar-events-month') |
|
1160 | + ) { |
|
1161 | + //Events View This Month |
|
1162 | + $admin_bar->add_menu(array( |
|
1163 | + 'id' => 'espresso-toolbar-events-month', |
|
1164 | + 'parent' => 'espresso-toolbar-events-view', |
|
1165 | + 'title' => __('This Month', 'event_espresso'), |
|
1166 | + 'href' => EEH_URL::add_query_args_and_nonce(array('action' => 'default', 'status' => 'month'), |
|
1167 | + $events_admin_url), |
|
1168 | + 'meta' => array( |
|
1169 | + 'title' => __('This Month', 'event_espresso'), |
|
1170 | + 'target' => '', |
|
1171 | + 'class' => $menu_class, |
|
1172 | + ), |
|
1173 | + )); |
|
1174 | + } |
|
1175 | + //Registration Overview |
|
1176 | + if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
1177 | + 'ee_admin_bar_menu_espresso-toolbar-registrations') |
|
1178 | + ) { |
|
1179 | + $admin_bar->add_menu(array( |
|
1180 | + 'id' => 'espresso-toolbar-registrations', |
|
1181 | + 'parent' => 'espresso-toolbar', |
|
1182 | + 'title' => __('Registrations', 'event_espresso'), |
|
1183 | + 'href' => $reg_admin_url, |
|
1184 | + 'meta' => array( |
|
1185 | + 'title' => __('Registrations', 'event_espresso'), |
|
1186 | + 'target' => '', |
|
1187 | + 'class' => $menu_class, |
|
1188 | + ), |
|
1189 | + )); |
|
1190 | + } |
|
1191 | + //Registration Overview Today |
|
1192 | + if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
1193 | + 'ee_admin_bar_menu_espresso-toolbar-registrations-today') |
|
1194 | + ) { |
|
1195 | + $admin_bar->add_menu(array( |
|
1196 | + 'id' => 'espresso-toolbar-registrations-today', |
|
1197 | + 'parent' => 'espresso-toolbar-registrations', |
|
1198 | + 'title' => __('Today', 'event_espresso'), |
|
1199 | + 'href' => EEH_URL::add_query_args_and_nonce(array('action' => 'default', 'status' => 'today'), |
|
1200 | + $reg_admin_url), |
|
1201 | + 'meta' => array( |
|
1202 | + 'title' => __('Today', 'event_espresso'), |
|
1203 | + 'target' => '', |
|
1204 | + 'class' => $menu_class, |
|
1205 | + ), |
|
1206 | + )); |
|
1207 | + } |
|
1208 | + //Registration Overview Today Completed |
|
1209 | + if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
1210 | + 'ee_admin_bar_menu_espresso-toolbar-registrations-today-approved') |
|
1211 | + ) { |
|
1212 | + $admin_bar->add_menu(array( |
|
1213 | + 'id' => 'espresso-toolbar-registrations-today-approved', |
|
1214 | + 'parent' => 'espresso-toolbar-registrations-today', |
|
1215 | + 'title' => __('Approved', 'event_espresso'), |
|
1216 | + 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
1217 | + 'action' => 'default', |
|
1218 | + 'status' => 'today', |
|
1219 | + '_reg_status' => EEM_Registration::status_id_approved, |
|
1220 | + ), $reg_admin_url), |
|
1221 | + 'meta' => array( |
|
1222 | + 'title' => __('Approved', 'event_espresso'), |
|
1223 | + 'target' => '', |
|
1224 | + 'class' => $menu_class, |
|
1225 | + ), |
|
1226 | + )); |
|
1227 | + } |
|
1228 | + //Registration Overview Today Pending\ |
|
1229 | + if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
1230 | + 'ee_admin_bar_menu_espresso-toolbar-registrations-today-pending') |
|
1231 | + ) { |
|
1232 | + $admin_bar->add_menu(array( |
|
1233 | + 'id' => 'espresso-toolbar-registrations-today-pending', |
|
1234 | + 'parent' => 'espresso-toolbar-registrations-today', |
|
1235 | + 'title' => __('Pending', 'event_espresso'), |
|
1236 | + 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
1237 | + 'action' => 'default', |
|
1238 | + 'status' => 'today', |
|
1239 | + 'reg_status' => EEM_Registration::status_id_pending_payment, |
|
1240 | + ), $reg_admin_url), |
|
1241 | + 'meta' => array( |
|
1242 | + 'title' => __('Pending Payment', 'event_espresso'), |
|
1243 | + 'target' => '', |
|
1244 | + 'class' => $menu_class, |
|
1245 | + ), |
|
1246 | + )); |
|
1247 | + } |
|
1248 | + //Registration Overview Today Incomplete |
|
1249 | + if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
1250 | + 'ee_admin_bar_menu_espresso-toolbar-registrations-today-not-approved') |
|
1251 | + ) { |
|
1252 | + $admin_bar->add_menu(array( |
|
1253 | + 'id' => 'espresso-toolbar-registrations-today-not-approved', |
|
1254 | + 'parent' => 'espresso-toolbar-registrations-today', |
|
1255 | + 'title' => __('Not Approved', 'event_espresso'), |
|
1256 | + 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
1257 | + 'action' => 'default', |
|
1258 | + 'status' => 'today', |
|
1259 | + '_reg_status' => EEM_Registration::status_id_not_approved, |
|
1260 | + ), $reg_admin_url), |
|
1261 | + 'meta' => array( |
|
1262 | + 'title' => __('Not Approved', 'event_espresso'), |
|
1263 | + 'target' => '', |
|
1264 | + 'class' => $menu_class, |
|
1265 | + ), |
|
1266 | + )); |
|
1267 | + } |
|
1268 | + //Registration Overview Today Incomplete |
|
1269 | + if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
1270 | + 'ee_admin_bar_menu_espresso-toolbar-registrations-today-cancelled') |
|
1271 | + ) { |
|
1272 | + $admin_bar->add_menu(array( |
|
1273 | + 'id' => 'espresso-toolbar-registrations-today-cancelled', |
|
1274 | + 'parent' => 'espresso-toolbar-registrations-today', |
|
1275 | + 'title' => __('Cancelled', 'event_espresso'), |
|
1276 | + 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
1277 | + 'action' => 'default', |
|
1278 | + 'status' => 'today', |
|
1279 | + '_reg_status' => EEM_Registration::status_id_cancelled, |
|
1280 | + ), $reg_admin_url), |
|
1281 | + 'meta' => array( |
|
1282 | + 'title' => __('Cancelled', 'event_espresso'), |
|
1283 | + 'target' => '', |
|
1284 | + 'class' => $menu_class, |
|
1285 | + ), |
|
1286 | + )); |
|
1287 | + } |
|
1288 | + //Registration Overview This Month |
|
1289 | + if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
1290 | + 'ee_admin_bar_menu_espresso-toolbar-registrations-month') |
|
1291 | + ) { |
|
1292 | + $admin_bar->add_menu(array( |
|
1293 | + 'id' => 'espresso-toolbar-registrations-month', |
|
1294 | + 'parent' => 'espresso-toolbar-registrations', |
|
1295 | + 'title' => __('This Month', 'event_espresso'), |
|
1296 | + 'href' => EEH_URL::add_query_args_and_nonce(array('action' => 'default', 'status' => 'month'), |
|
1297 | + $reg_admin_url), |
|
1298 | + 'meta' => array( |
|
1299 | + 'title' => __('This Month', 'event_espresso'), |
|
1300 | + 'target' => '', |
|
1301 | + 'class' => $menu_class, |
|
1302 | + ), |
|
1303 | + )); |
|
1304 | + } |
|
1305 | + //Registration Overview This Month Approved |
|
1306 | + if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
1307 | + 'ee_admin_bar_menu_espresso-toolbar-registrations-month-approved') |
|
1308 | + ) { |
|
1309 | + $admin_bar->add_menu(array( |
|
1310 | + 'id' => 'espresso-toolbar-registrations-month-approved', |
|
1311 | + 'parent' => 'espresso-toolbar-registrations-month', |
|
1312 | + 'title' => __('Approved', 'event_espresso'), |
|
1313 | + 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
1314 | + 'action' => 'default', |
|
1315 | + 'status' => 'month', |
|
1316 | + '_reg_status' => EEM_Registration::status_id_approved, |
|
1317 | + ), $reg_admin_url), |
|
1318 | + 'meta' => array( |
|
1319 | + 'title' => __('Approved', 'event_espresso'), |
|
1320 | + 'target' => '', |
|
1321 | + 'class' => $menu_class, |
|
1322 | + ), |
|
1323 | + )); |
|
1324 | + } |
|
1325 | + //Registration Overview This Month Pending |
|
1326 | + if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
1327 | + 'ee_admin_bar_menu_espresso-toolbar-registrations-month-pending') |
|
1328 | + ) { |
|
1329 | + $admin_bar->add_menu(array( |
|
1330 | + 'id' => 'espresso-toolbar-registrations-month-pending', |
|
1331 | + 'parent' => 'espresso-toolbar-registrations-month', |
|
1332 | + 'title' => __('Pending', 'event_espresso'), |
|
1333 | + 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
1334 | + 'action' => 'default', |
|
1335 | + 'status' => 'month', |
|
1336 | + '_reg_status' => EEM_Registration::status_id_pending_payment, |
|
1337 | + ), $reg_admin_url), |
|
1338 | + 'meta' => array( |
|
1339 | + 'title' => __('Pending', 'event_espresso'), |
|
1340 | + 'target' => '', |
|
1341 | + 'class' => $menu_class, |
|
1342 | + ), |
|
1343 | + )); |
|
1344 | + } |
|
1345 | + //Registration Overview This Month Not Approved |
|
1346 | + if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
1347 | + 'ee_admin_bar_menu_espresso-toolbar-registrations-month-not-approved') |
|
1348 | + ) { |
|
1349 | + $admin_bar->add_menu(array( |
|
1350 | + 'id' => 'espresso-toolbar-registrations-month-not-approved', |
|
1351 | + 'parent' => 'espresso-toolbar-registrations-month', |
|
1352 | + 'title' => __('Not Approved', 'event_espresso'), |
|
1353 | + 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
1354 | + 'action' => 'default', |
|
1355 | + 'status' => 'month', |
|
1356 | + '_reg_status' => EEM_Registration::status_id_not_approved, |
|
1357 | + ), $reg_admin_url), |
|
1358 | + 'meta' => array( |
|
1359 | + 'title' => __('Not Approved', 'event_espresso'), |
|
1360 | + 'target' => '', |
|
1361 | + 'class' => $menu_class, |
|
1362 | + ), |
|
1363 | + )); |
|
1364 | + } |
|
1365 | + //Registration Overview This Month Cancelled |
|
1366 | + if ($this->registry->CAP->current_user_can('ee_read_registrations', |
|
1367 | + 'ee_admin_bar_menu_espresso-toolbar-registrations-month-cancelled') |
|
1368 | + ) { |
|
1369 | + $admin_bar->add_menu(array( |
|
1370 | + 'id' => 'espresso-toolbar-registrations-month-cancelled', |
|
1371 | + 'parent' => 'espresso-toolbar-registrations-month', |
|
1372 | + 'title' => __('Cancelled', 'event_espresso'), |
|
1373 | + 'href' => EEH_URL::add_query_args_and_nonce(array( |
|
1374 | + 'action' => 'default', |
|
1375 | + 'status' => 'month', |
|
1376 | + '_reg_status' => EEM_Registration::status_id_cancelled, |
|
1377 | + ), $reg_admin_url), |
|
1378 | + 'meta' => array( |
|
1379 | + 'title' => __('Cancelled', 'event_espresso'), |
|
1380 | + 'target' => '', |
|
1381 | + 'class' => $menu_class, |
|
1382 | + ), |
|
1383 | + )); |
|
1384 | + } |
|
1385 | + //Extensions & Services |
|
1386 | + if ($this->registry->CAP->current_user_can('ee_read_ee', |
|
1387 | + 'ee_admin_bar_menu_espresso-toolbar-extensions-and-services') |
|
1388 | + ) { |
|
1389 | + $admin_bar->add_menu(array( |
|
1390 | + 'id' => 'espresso-toolbar-extensions-and-services', |
|
1391 | + 'parent' => 'espresso-toolbar', |
|
1392 | + 'title' => __('Extensions & Services', 'event_espresso'), |
|
1393 | + 'href' => $extensions_admin_url, |
|
1394 | + 'meta' => array( |
|
1395 | + 'title' => __('Extensions & Services', 'event_espresso'), |
|
1396 | + 'target' => '', |
|
1397 | + 'class' => $menu_class, |
|
1398 | + ), |
|
1399 | + )); |
|
1400 | + } |
|
1401 | + } |
|
1402 | + |
|
1403 | + |
|
1404 | + |
|
1405 | + /** |
|
1406 | + * simply hooks into "wp_list_pages_exclude" filter (for wp_list_pages method) and makes sure EE critical pages are |
|
1407 | + * never returned with the function. |
|
1408 | + * |
|
1409 | + * @param array $exclude_array any existing pages being excluded are in this array. |
|
1410 | + * @return array |
|
1411 | + */ |
|
1412 | + public function remove_pages_from_wp_list_pages($exclude_array) |
|
1413 | + { |
|
1414 | + return array_merge($exclude_array, $this->registry->CFG->core->get_critical_pages_array()); |
|
1415 | + } |
|
1416 | + |
|
1417 | + |
|
1418 | + |
|
1419 | + |
|
1420 | + |
|
1421 | + |
|
1422 | + /*********************************************** WP_ENQUEUE_SCRIPTS HOOK ***********************************************/ |
|
1423 | + /** |
|
1424 | + * wp_enqueue_scripts |
|
1425 | + * |
|
1426 | + * @access public |
|
1427 | + * @return void |
|
1428 | + */ |
|
1429 | + public function wp_enqueue_scripts() |
|
1430 | + { |
|
1431 | + // unlike other systems, EE_System_scripts loading is turned ON by default, but prior to the init hook, can be turned off via: add_filter( 'FHEE_load_EE_System_scripts', '__return_false' ); |
|
1432 | + if (apply_filters('FHEE_load_EE_System_scripts', true)) { |
|
1433 | + // jquery_validate loading is turned OFF by default, but prior to the wp_enqueue_scripts hook, can be turned back on again via: add_filter( 'FHEE_load_jquery_validate', '__return_true' ); |
|
1434 | + if (apply_filters('FHEE_load_jquery_validate', false)) { |
|
1435 | + // register jQuery Validate and additional methods |
|
1436 | + wp_register_script('jquery-validate', EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.min.js', |
|
1437 | + array('jquery'), '1.15.0', true); |
|
1438 | + wp_register_script('jquery-validate-extra-methods', |
|
1439 | + EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.additional-methods.min.js', |
|
1440 | + array('jquery', 'jquery-validate'), '1.15.0', true); |
|
1441 | + } |
|
1442 | + } |
|
1443 | + } |
|
1444 | 1444 | |
1445 | 1445 | |
1446 | 1446 |
@@ -185,7 +185,7 @@ discard block |
||
185 | 185 | { |
186 | 186 | // set autoloaders for all of the classes implementing EEI_Plugin_API |
187 | 187 | // which provide helpers for EE plugin authors to more easily register certain components with EE. |
188 | - EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_LIBRARIES . 'plugin_api'); |
|
188 | + EEH_Autoloader::instance()->register_autoloaders_for_each_file_in_folder(EE_LIBRARIES.'plugin_api'); |
|
189 | 189 | do_action('AHEE__EE_System__load_espresso_addons'); |
190 | 190 | //if the WP API basic auth plugin isn't already loaded, load it now. |
191 | 191 | //We want it for mobile apps. Just include the entire plugin |
@@ -203,7 +203,7 @@ discard block |
||
203 | 203 | && $_GET['activate'] === 'true' |
204 | 204 | ) |
205 | 205 | ) { |
206 | - include_once EE_THIRD_PARTY . 'wp-api-basic-auth' . DS . 'basic-auth.php'; |
|
206 | + include_once EE_THIRD_PARTY.'wp-api-basic-auth'.DS.'basic-auth.php'; |
|
207 | 207 | } |
208 | 208 | $this->_maybe_brew_regular(); |
209 | 209 | do_action('AHEE__EE_System__load_espresso_addons__complete'); |
@@ -220,8 +220,8 @@ discard block |
||
220 | 220 | */ |
221 | 221 | private function _maybe_brew_regular() |
222 | 222 | { |
223 | - if (( ! defined('EE_DECAF') || EE_DECAF !== true) && is_readable(EE_CAFF_PATH . 'brewing_regular.php')) { |
|
224 | - require_once EE_CAFF_PATH . 'brewing_regular.php'; |
|
223 | + if (( ! defined('EE_DECAF') || EE_DECAF !== true) && is_readable(EE_CAFF_PATH.'brewing_regular.php')) { |
|
224 | + require_once EE_CAFF_PATH.'brewing_regular.php'; |
|
225 | 225 | } |
226 | 226 | } |
227 | 227 | |
@@ -752,8 +752,8 @@ discard block |
||
752 | 752 | 'event_espresso'); |
753 | 753 | $msg .= '<ul>'; |
754 | 754 | foreach ($class_names as $class_name) { |
755 | - $msg .= '<li><b>Event Espresso - ' . str_replace(array('EE_', 'EEM_', 'EED_', 'EES_', 'EEW_'), '', |
|
756 | - $class_name) . '</b></li>'; |
|
755 | + $msg .= '<li><b>Event Espresso - '.str_replace(array('EE_', 'EEM_', 'EED_', 'EES_', 'EEW_'), '', |
|
756 | + $class_name).'</b></li>'; |
|
757 | 757 | } |
758 | 758 | $msg .= '</ul>'; |
759 | 759 | $msg .= __('Compatibility issues can be avoided and/or resolved by keeping addons and plugins updated to the latest version.', |
@@ -910,8 +910,8 @@ discard block |
||
910 | 910 | { |
911 | 911 | do_action('AHEE__EE_System__core_loaded_and_ready'); |
912 | 912 | // load_espresso_template_tags |
913 | - if (is_readable(EE_PUBLIC . 'template_tags.php')) { |
|
914 | - require_once(EE_PUBLIC . 'template_tags.php'); |
|
913 | + if (is_readable(EE_PUBLIC.'template_tags.php')) { |
|
914 | + require_once(EE_PUBLIC.'template_tags.php'); |
|
915 | 915 | } |
916 | 916 | do_action('AHEE__EE_System__set_hooks_for_shortcodes_modules_and_addons'); |
917 | 917 | $this->registry->load_core('Session'); |
@@ -1056,7 +1056,7 @@ discard block |
||
1056 | 1056 | 'href' => $events_admin_url, |
1057 | 1057 | 'meta' => array( |
1058 | 1058 | 'title' => __('Event Espresso', 'event_espresso'), |
1059 | - 'class' => $menu_class . 'first', |
|
1059 | + 'class' => $menu_class.'first', |
|
1060 | 1060 | ), |
1061 | 1061 | )); |
1062 | 1062 | //Events |
@@ -1433,10 +1433,10 @@ discard block |
||
1433 | 1433 | // jquery_validate loading is turned OFF by default, but prior to the wp_enqueue_scripts hook, can be turned back on again via: add_filter( 'FHEE_load_jquery_validate', '__return_true' ); |
1434 | 1434 | if (apply_filters('FHEE_load_jquery_validate', false)) { |
1435 | 1435 | // register jQuery Validate and additional methods |
1436 | - wp_register_script('jquery-validate', EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.min.js', |
|
1436 | + wp_register_script('jquery-validate', EE_GLOBAL_ASSETS_URL.'scripts/jquery.validate.min.js', |
|
1437 | 1437 | array('jquery'), '1.15.0', true); |
1438 | 1438 | wp_register_script('jquery-validate-extra-methods', |
1439 | - EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.additional-methods.min.js', |
|
1439 | + EE_GLOBAL_ASSETS_URL.'scripts/jquery.validate.additional-methods.min.js', |
|
1440 | 1440 | array('jquery', 'jquery-validate'), '1.15.0', true); |
1441 | 1441 | } |
1442 | 1442 | } |
@@ -16,1433 +16,1433 @@ |
||
16 | 16 | class EE_Registry |
17 | 17 | { |
18 | 18 | |
19 | - /** |
|
20 | - * EE_Registry Object |
|
21 | - * |
|
22 | - * @var EE_Registry $_instance |
|
23 | - * @access private |
|
24 | - */ |
|
25 | - private static $_instance = null; |
|
26 | - |
|
27 | - /** |
|
28 | - * @var EE_Dependency_Map $_dependency_map |
|
29 | - * @access protected |
|
30 | - */ |
|
31 | - protected $_dependency_map = null; |
|
32 | - |
|
33 | - /** |
|
34 | - * @var array $_class_abbreviations |
|
35 | - * @access protected |
|
36 | - */ |
|
37 | - protected $_class_abbreviations = array(); |
|
38 | - |
|
39 | - /** |
|
40 | - * @access public |
|
41 | - * @var \EventEspresso\core\services\commands\CommandBusInterface $BUS |
|
42 | - */ |
|
43 | - public $BUS; |
|
44 | - |
|
45 | - /** |
|
46 | - * EE_Cart Object |
|
47 | - * |
|
48 | - * @access public |
|
49 | - * @var EE_Cart $CART |
|
50 | - */ |
|
51 | - public $CART = null; |
|
52 | - |
|
53 | - /** |
|
54 | - * EE_Config Object |
|
55 | - * |
|
56 | - * @access public |
|
57 | - * @var EE_Config $CFG |
|
58 | - */ |
|
59 | - public $CFG = null; |
|
60 | - |
|
61 | - /** |
|
62 | - * EE_Network_Config Object |
|
63 | - * |
|
64 | - * @access public |
|
65 | - * @var EE_Network_Config $NET_CFG |
|
66 | - */ |
|
67 | - public $NET_CFG = null; |
|
68 | - |
|
69 | - /** |
|
70 | - * StdClass object for storing library classes in |
|
71 | - * |
|
72 | - * @public LIB |
|
73 | - * @var StdClass $LIB |
|
74 | - */ |
|
75 | - public $LIB = null; |
|
76 | - |
|
77 | - /** |
|
78 | - * EE_Request_Handler Object |
|
79 | - * |
|
80 | - * @access public |
|
81 | - * @var EE_Request_Handler $REQ |
|
82 | - */ |
|
83 | - public $REQ = null; |
|
84 | - |
|
85 | - /** |
|
86 | - * EE_Session Object |
|
87 | - * |
|
88 | - * @access public |
|
89 | - * @var EE_Session $SSN |
|
90 | - */ |
|
91 | - public $SSN = null; |
|
92 | - |
|
93 | - /** |
|
94 | - * holds the ee capabilities object. |
|
95 | - * |
|
96 | - * @since 4.5.0 |
|
97 | - * @var EE_Capabilities |
|
98 | - */ |
|
99 | - public $CAP = null; |
|
100 | - |
|
101 | - /** |
|
102 | - * holds the EE_Message_Resource_Manager object. |
|
103 | - * |
|
104 | - * @since 4.9.0 |
|
105 | - * @var EE_Message_Resource_Manager |
|
106 | - */ |
|
107 | - public $MRM = null; |
|
108 | - |
|
109 | - |
|
110 | - /** |
|
111 | - * Holds the Assets Registry instance |
|
112 | - * @var Registry |
|
113 | - */ |
|
114 | - public $AssetsRegistry = null; |
|
115 | - |
|
116 | - /** |
|
117 | - * $addons - StdClass object for holding addons which have registered themselves to work with EE core |
|
118 | - * |
|
119 | - * @access public |
|
120 | - * @var EE_Addon[] |
|
121 | - */ |
|
122 | - public $addons = null; |
|
123 | - |
|
124 | - /** |
|
125 | - * $models |
|
126 | - * @access public |
|
127 | - * @var EEM_Base[] $models keys are 'short names' (eg Event), values are class names (eg 'EEM_Event') |
|
128 | - */ |
|
129 | - public $models = array(); |
|
130 | - |
|
131 | - /** |
|
132 | - * $modules |
|
133 | - * @access public |
|
134 | - * @var EED_Module[] $modules |
|
135 | - */ |
|
136 | - public $modules = null; |
|
137 | - |
|
138 | - /** |
|
139 | - * $shortcodes |
|
140 | - * @access public |
|
141 | - * @var EES_Shortcode[] $shortcodes |
|
142 | - */ |
|
143 | - public $shortcodes = null; |
|
144 | - |
|
145 | - /** |
|
146 | - * $widgets |
|
147 | - * @access public |
|
148 | - * @var WP_Widget[] $widgets |
|
149 | - */ |
|
150 | - public $widgets = null; |
|
151 | - |
|
152 | - /** |
|
153 | - * $non_abstract_db_models |
|
154 | - * @access public but its better to use EE_Registry::non_abstract_db_models() as it verifies we've set this property before returning it |
|
155 | - * @var array this is an array of all implemented model names (i.e. not the parent abstract models, or models |
|
156 | - * which don't actually fetch items from the DB in the normal way (ie, are not children of EEM_Base)). |
|
157 | - * Keys are model "short names" (eg "Event") as used in model relations, and values are |
|
158 | - * classnames (eg "EEM_Event") |
|
159 | - */ |
|
160 | - public $non_abstract_db_models = array(); |
|
161 | - |
|
162 | - |
|
163 | - /** |
|
164 | - * $i18n_js_strings - internationalization for JS strings |
|
165 | - * usage: EE_Registry::i18n_js_strings['string_key'] = __( 'string to translate.', 'event_espresso' ); |
|
166 | - * in js file: var translatedString = eei18n.string_key; |
|
167 | - * |
|
168 | - * @access public |
|
169 | - * @var array |
|
170 | - */ |
|
171 | - public static $i18n_js_strings = array(); |
|
172 | - |
|
173 | - |
|
174 | - /** |
|
175 | - * $main_file - path to espresso.php |
|
176 | - * |
|
177 | - * @access public |
|
178 | - * @var array |
|
179 | - */ |
|
180 | - public $main_file; |
|
181 | - |
|
182 | - /** |
|
183 | - * array of ReflectionClass objects where the key is the class name |
|
184 | - * |
|
185 | - * @access public |
|
186 | - * @var ReflectionClass[] |
|
187 | - */ |
|
188 | - public $_reflectors; |
|
189 | - |
|
190 | - /** |
|
191 | - * boolean flag to indicate whether or not to load/save dependencies from/to the cache |
|
192 | - * |
|
193 | - * @access protected |
|
194 | - * @var boolean $_cache_on |
|
195 | - */ |
|
196 | - protected $_cache_on = true; |
|
197 | - |
|
198 | - |
|
199 | - |
|
200 | - /** |
|
201 | - * @singleton method used to instantiate class object |
|
202 | - * @access public |
|
203 | - * @param \EE_Dependency_Map $dependency_map |
|
204 | - * @return \EE_Registry instance |
|
205 | - */ |
|
206 | - public static function instance(\EE_Dependency_Map $dependency_map = null) |
|
207 | - { |
|
208 | - // check if class object is instantiated |
|
209 | - if ( ! self::$_instance instanceof EE_Registry) { |
|
210 | - self::$_instance = new EE_Registry($dependency_map); |
|
211 | - } |
|
212 | - return self::$_instance; |
|
213 | - } |
|
214 | - |
|
215 | - |
|
216 | - |
|
217 | - /** |
|
218 | - *protected constructor to prevent direct creation |
|
219 | - * |
|
220 | - * @Constructor |
|
221 | - * @access protected |
|
222 | - * @param \EE_Dependency_Map $dependency_map |
|
223 | - * @return \EE_Registry |
|
224 | - */ |
|
225 | - protected function __construct(\EE_Dependency_Map $dependency_map) |
|
226 | - { |
|
227 | - $this->_dependency_map = $dependency_map; |
|
228 | - add_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading', array($this, 'initialize')); |
|
229 | - } |
|
230 | - |
|
231 | - |
|
232 | - |
|
233 | - /** |
|
234 | - * initialize |
|
235 | - */ |
|
236 | - public function initialize() |
|
237 | - { |
|
238 | - $this->_class_abbreviations = apply_filters( |
|
239 | - 'FHEE__EE_Registry____construct___class_abbreviations', |
|
240 | - array( |
|
241 | - 'EE_Config' => 'CFG', |
|
242 | - 'EE_Session' => 'SSN', |
|
243 | - 'EE_Capabilities' => 'CAP', |
|
244 | - 'EE_Cart' => 'CART', |
|
245 | - 'EE_Network_Config' => 'NET_CFG', |
|
246 | - 'EE_Request_Handler' => 'REQ', |
|
247 | - 'EE_Message_Resource_Manager' => 'MRM', |
|
248 | - 'EventEspresso\core\services\commands\CommandBus' => 'BUS', |
|
249 | - ) |
|
250 | - ); |
|
251 | - // class library |
|
252 | - $this->LIB = new stdClass(); |
|
253 | - $this->addons = new stdClass(); |
|
254 | - $this->modules = new stdClass(); |
|
255 | - $this->shortcodes = new stdClass(); |
|
256 | - $this->widgets = new stdClass(); |
|
257 | - $this->load_core('Base', array(), true); |
|
258 | - // add our request and response objects to the cache |
|
259 | - $request_loader = $this->_dependency_map->class_loader('EE_Request'); |
|
260 | - $this->_set_cached_class( |
|
261 | - $request_loader(), |
|
262 | - 'EE_Request' |
|
263 | - ); |
|
264 | - $response_loader = $this->_dependency_map->class_loader('EE_Response'); |
|
265 | - $this->_set_cached_class( |
|
266 | - $response_loader(), |
|
267 | - 'EE_Response' |
|
268 | - ); |
|
269 | - add_action('AHEE__EE_System__set_hooks_for_core', array($this, 'init')); |
|
270 | - } |
|
271 | - |
|
272 | - |
|
273 | - |
|
274 | - /** |
|
275 | - * init |
|
276 | - * |
|
277 | - * @access public |
|
278 | - * @return void |
|
279 | - */ |
|
280 | - public function init() |
|
281 | - { |
|
282 | - $this->AssetsRegistry = new Registry(); |
|
283 | - // Get current page protocol |
|
284 | - $protocol = isset($_SERVER['HTTPS']) ? 'https://' : 'http://'; |
|
285 | - // Output admin-ajax.php URL with same protocol as current page |
|
286 | - self::$i18n_js_strings['ajax_url'] = admin_url('admin-ajax.php', $protocol); |
|
287 | - self::$i18n_js_strings['wp_debug'] = defined('WP_DEBUG') ? WP_DEBUG : false; |
|
288 | - } |
|
289 | - |
|
290 | - |
|
291 | - |
|
292 | - /** |
|
293 | - * localize_i18n_js_strings |
|
294 | - * |
|
295 | - * @return string |
|
296 | - */ |
|
297 | - public static function localize_i18n_js_strings() |
|
298 | - { |
|
299 | - $i18n_js_strings = (array)EE_Registry::$i18n_js_strings; |
|
300 | - foreach ($i18n_js_strings as $key => $value) { |
|
301 | - if (is_scalar($value)) { |
|
302 | - $i18n_js_strings[$key] = html_entity_decode((string)$value, ENT_QUOTES, 'UTF-8'); |
|
303 | - } |
|
304 | - } |
|
305 | - return "/* <![CDATA[ */ var eei18n = " . wp_json_encode($i18n_js_strings) . '; /* ]]> */'; |
|
306 | - } |
|
307 | - |
|
308 | - |
|
309 | - |
|
310 | - /** |
|
311 | - * @param mixed string | EED_Module $module |
|
312 | - */ |
|
313 | - public function add_module($module) |
|
314 | - { |
|
315 | - if ($module instanceof EED_Module) { |
|
316 | - $module_class = get_class($module); |
|
317 | - $this->modules->{$module_class} = $module; |
|
318 | - } else { |
|
319 | - if ( ! class_exists('EE_Module_Request_Router')) { |
|
320 | - $this->load_core('Module_Request_Router'); |
|
321 | - } |
|
322 | - $this->modules->{$module} = EE_Module_Request_Router::module_factory($module); |
|
323 | - } |
|
324 | - } |
|
325 | - |
|
326 | - |
|
327 | - |
|
328 | - /** |
|
329 | - * @param string $module_name |
|
330 | - * @return mixed EED_Module | NULL |
|
331 | - */ |
|
332 | - public function get_module($module_name = '') |
|
333 | - { |
|
334 | - return isset($this->modules->{$module_name}) ? $this->modules->{$module_name} : null; |
|
335 | - } |
|
336 | - |
|
337 | - |
|
338 | - |
|
339 | - /** |
|
340 | - * loads core classes - must be singletons |
|
341 | - * |
|
342 | - * @access public |
|
343 | - * @param string $class_name - simple class name ie: session |
|
344 | - * @param mixed $arguments |
|
345 | - * @param bool $load_only |
|
346 | - * @return mixed |
|
347 | - */ |
|
348 | - public function load_core($class_name, $arguments = array(), $load_only = false) |
|
349 | - { |
|
350 | - $core_paths = apply_filters( |
|
351 | - 'FHEE__EE_Registry__load_core__core_paths', |
|
352 | - array( |
|
353 | - EE_CORE, |
|
354 | - EE_ADMIN, |
|
355 | - EE_CPTS, |
|
356 | - EE_CORE . 'data_migration_scripts' . DS, |
|
357 | - EE_CORE . 'request_stack' . DS, |
|
358 | - EE_CORE . 'middleware' . DS, |
|
359 | - ) |
|
360 | - ); |
|
361 | - // retrieve instantiated class |
|
362 | - return $this->_load($core_paths, 'EE_', $class_name, 'core', $arguments, false, true, $load_only); |
|
363 | - } |
|
364 | - |
|
365 | - |
|
366 | - |
|
367 | - /** |
|
368 | - * loads service classes |
|
369 | - * |
|
370 | - * @access public |
|
371 | - * @param string $class_name - simple class name ie: session |
|
372 | - * @param mixed $arguments |
|
373 | - * @param bool $load_only |
|
374 | - * @return mixed |
|
375 | - */ |
|
376 | - public function load_service($class_name, $arguments = array(), $load_only = false) |
|
377 | - { |
|
378 | - $service_paths = apply_filters( |
|
379 | - 'FHEE__EE_Registry__load_service__service_paths', |
|
380 | - array( |
|
381 | - EE_CORE . 'services' . DS, |
|
382 | - ) |
|
383 | - ); |
|
384 | - // retrieve instantiated class |
|
385 | - return $this->_load($service_paths, 'EE_', $class_name, 'class', $arguments, false, true, $load_only); |
|
386 | - } |
|
387 | - |
|
388 | - |
|
389 | - |
|
390 | - /** |
|
391 | - * loads data_migration_scripts |
|
392 | - * |
|
393 | - * @access public |
|
394 | - * @param string $class_name - class name for the DMS ie: EE_DMS_Core_4_2_0 |
|
395 | - * @param mixed $arguments |
|
396 | - * @return EE_Data_Migration_Script_Base|mixed |
|
397 | - */ |
|
398 | - public function load_dms($class_name, $arguments = array()) |
|
399 | - { |
|
400 | - // retrieve instantiated class |
|
401 | - return $this->_load(EE_Data_Migration_Manager::instance()->get_data_migration_script_folders(), 'EE_DMS_', $class_name, 'dms', $arguments, false, false, false); |
|
402 | - } |
|
403 | - |
|
404 | - |
|
405 | - |
|
406 | - /** |
|
407 | - * loads object creating classes - must be singletons |
|
408 | - * |
|
409 | - * @param string $class_name - simple class name ie: attendee |
|
410 | - * @param mixed $arguments - an array of arguments to pass to the class |
|
411 | - * @param bool $from_db - some classes are instantiated from the db and thus call a different method to instantiate |
|
412 | - * @param bool $cache if you don't want the class to be stored in the internal cache (non-persistent) then set this to FALSE (ie. when instantiating model objects from client in a loop) |
|
413 | - * @param bool $load_only whether or not to just load the file and NOT instantiate, or load AND instantiate (default) |
|
414 | - * @return EE_Base_Class | bool |
|
415 | - */ |
|
416 | - public function load_class($class_name, $arguments = array(), $from_db = false, $cache = true, $load_only = false) |
|
417 | - { |
|
418 | - $paths = apply_filters('FHEE__EE_Registry__load_class__paths', array( |
|
419 | - EE_CORE, |
|
420 | - EE_CLASSES, |
|
421 | - EE_BUSINESS, |
|
422 | - )); |
|
423 | - // retrieve instantiated class |
|
424 | - return $this->_load($paths, 'EE_', $class_name, 'class', $arguments, $from_db, $cache, $load_only); |
|
425 | - } |
|
426 | - |
|
427 | - |
|
428 | - |
|
429 | - /** |
|
430 | - * loads helper classes - must be singletons |
|
431 | - * |
|
432 | - * @param string $class_name - simple class name ie: price |
|
433 | - * @param mixed $arguments |
|
434 | - * @param bool $load_only |
|
435 | - * @return EEH_Base | bool |
|
436 | - */ |
|
437 | - public function load_helper($class_name, $arguments = array(), $load_only = true) |
|
438 | - { |
|
439 | - // todo: add doing_it_wrong() in a few versions after all addons have had calls to this method removed |
|
440 | - $helper_paths = apply_filters('FHEE__EE_Registry__load_helper__helper_paths', array(EE_HELPERS)); |
|
441 | - // retrieve instantiated class |
|
442 | - return $this->_load($helper_paths, 'EEH_', $class_name, 'helper', $arguments, false, true, $load_only); |
|
443 | - } |
|
444 | - |
|
445 | - |
|
446 | - |
|
447 | - /** |
|
448 | - * loads core classes - must be singletons |
|
449 | - * |
|
450 | - * @access public |
|
451 | - * @param string $class_name - simple class name ie: session |
|
452 | - * @param mixed $arguments |
|
453 | - * @param bool $load_only |
|
454 | - * @param bool $cache whether to cache the object or not. |
|
455 | - * @return mixed |
|
456 | - */ |
|
457 | - public function load_lib($class_name, $arguments = array(), $load_only = false, $cache = true) |
|
458 | - { |
|
459 | - $paths = array( |
|
460 | - EE_LIBRARIES, |
|
461 | - EE_LIBRARIES . 'messages' . DS, |
|
462 | - EE_LIBRARIES . 'shortcodes' . DS, |
|
463 | - EE_LIBRARIES . 'qtips' . DS, |
|
464 | - EE_LIBRARIES . 'payment_methods' . DS, |
|
465 | - ); |
|
466 | - // retrieve instantiated class |
|
467 | - return $this->_load($paths, 'EE_', $class_name, 'lib', $arguments, false, $cache, $load_only); |
|
468 | - } |
|
469 | - |
|
470 | - |
|
471 | - |
|
472 | - /** |
|
473 | - * loads model classes - must be singletons |
|
474 | - * |
|
475 | - * @param string $class_name - simple class name ie: price |
|
476 | - * @param mixed $arguments |
|
477 | - * @param bool $load_only |
|
478 | - * @return EEM_Base | bool |
|
479 | - */ |
|
480 | - public function load_model($class_name, $arguments = array(), $load_only = false) |
|
481 | - { |
|
482 | - $paths = apply_filters('FHEE__EE_Registry__load_model__paths', array( |
|
483 | - EE_MODELS, |
|
484 | - EE_CORE, |
|
485 | - )); |
|
486 | - // retrieve instantiated class |
|
487 | - return $this->_load($paths, 'EEM_', $class_name, 'model', $arguments, false, true, $load_only); |
|
488 | - } |
|
489 | - |
|
490 | - |
|
491 | - |
|
492 | - /** |
|
493 | - * loads model classes - must be singletons |
|
494 | - * |
|
495 | - * @param string $class_name - simple class name ie: price |
|
496 | - * @param mixed $arguments |
|
497 | - * @param bool $load_only |
|
498 | - * @return mixed | bool |
|
499 | - */ |
|
500 | - public function load_model_class($class_name, $arguments = array(), $load_only = true) |
|
501 | - { |
|
502 | - $paths = array( |
|
503 | - EE_MODELS . 'fields' . DS, |
|
504 | - EE_MODELS . 'helpers' . DS, |
|
505 | - EE_MODELS . 'relations' . DS, |
|
506 | - EE_MODELS . 'strategies' . DS, |
|
507 | - ); |
|
508 | - // retrieve instantiated class |
|
509 | - return $this->_load($paths, 'EE_', $class_name, '', $arguments, false, true, $load_only); |
|
510 | - } |
|
511 | - |
|
512 | - |
|
513 | - |
|
514 | - /** |
|
515 | - * Determines if $model_name is the name of an actual EE model. |
|
516 | - * |
|
517 | - * @param string $model_name like Event, Attendee, Question_Group_Question, etc. |
|
518 | - * @return boolean |
|
519 | - */ |
|
520 | - public function is_model_name($model_name) |
|
521 | - { |
|
522 | - $this->_verify_models_discovered(); |
|
523 | - return isset($this->models[$model_name]) ? true : false; |
|
524 | - } |
|
525 | - |
|
526 | - |
|
527 | - |
|
528 | - /** |
|
529 | - * generic class loader |
|
530 | - * |
|
531 | - * @param string $path_to_file - directory path to file location, not including filename |
|
532 | - * @param string $file_name - file name ie: my_file.php, including extension |
|
533 | - * @param string $type - file type - core? class? helper? model? |
|
534 | - * @param mixed $arguments |
|
535 | - * @param bool $load_only |
|
536 | - * @return mixed |
|
537 | - */ |
|
538 | - public function load_file($path_to_file, $file_name, $type = '', $arguments = array(), $load_only = true) |
|
539 | - { |
|
540 | - // retrieve instantiated class |
|
541 | - return $this->_load($path_to_file, '', $file_name, $type, $arguments, false, true, $load_only); |
|
542 | - } |
|
543 | - |
|
544 | - |
|
545 | - |
|
546 | - /** |
|
547 | - * load_addon |
|
548 | - * |
|
549 | - * @param string $path_to_file - directory path to file location, not including filename |
|
550 | - * @param string $class_name - full class name ie: My_Class |
|
551 | - * @param string $type - file type - core? class? helper? model? |
|
552 | - * @param mixed $arguments |
|
553 | - * @param bool $load_only |
|
554 | - * @return EE_Addon |
|
555 | - */ |
|
556 | - public function load_addon($path_to_file, $class_name, $type = 'class', $arguments = array(), $load_only = false) |
|
557 | - { |
|
558 | - // retrieve instantiated class |
|
559 | - return $this->_load($path_to_file, 'addon', $class_name, $type, $arguments, false, true, $load_only); |
|
560 | - } |
|
561 | - |
|
562 | - |
|
563 | - |
|
564 | - /** |
|
565 | - * instantiates, caches, and automatically resolves dependencies |
|
566 | - * for classes that use a Fully Qualified Class Name. |
|
567 | - * if the class is not capable of being loaded using PSR-4 autoloading, |
|
568 | - * then you need to use one of the existing load_*() methods |
|
569 | - * which can resolve the classname and filepath from the passed arguments |
|
570 | - * |
|
571 | - * @param bool|string $class_name Fully Qualified Class Name |
|
572 | - * @param array $arguments an argument, or array of arguments to pass to the class upon instantiation |
|
573 | - * @param bool $cache whether to cache the instantiated object for reuse |
|
574 | - * @param bool $from_db some classes are instantiated from the db |
|
575 | - * and thus call a different method to instantiate |
|
576 | - * @param bool $load_only if true, will only load the file, but will NOT instantiate an object |
|
577 | - * @param bool|string $addon if true, will cache the object in the EE_Registry->$addons array |
|
578 | - * @return mixed null = failure to load or instantiate class object. |
|
579 | - * object = class loaded and instantiated successfully. |
|
580 | - * bool = fail or success when $load_only is true |
|
581 | - */ |
|
582 | - public function create( |
|
583 | - $class_name = false, |
|
584 | - $arguments = array(), |
|
585 | - $cache = false, |
|
586 | - $from_db = false, |
|
587 | - $load_only = false, |
|
588 | - $addon = false |
|
589 | - ) { |
|
590 | - $class_name = ltrim($class_name, '\\'); |
|
591 | - $class_name = $this->_dependency_map->get_alias($class_name); |
|
592 | - if ( ! class_exists($class_name)) { |
|
593 | - // maybe the class is registered with a preceding \ |
|
594 | - $class_name = strpos($class_name, '\\') !== 0 ? '\\' . $class_name : $class_name; |
|
595 | - // still doesn't exist ? |
|
596 | - if ( ! class_exists($class_name)) { |
|
597 | - return null; |
|
598 | - } |
|
599 | - } |
|
600 | - // if we're only loading the class and it already exists, then let's just return true immediately |
|
601 | - if ($load_only) { |
|
602 | - return true; |
|
603 | - } |
|
604 | - $addon = $addon ? 'addon' : ''; |
|
605 | - // $this->_cache_on is toggled during the recursive loading that can occur with dependency injection |
|
606 | - // $cache is controlled by individual calls to separate Registry loader methods like load_class() |
|
607 | - // $load_only is also controlled by individual calls to separate Registry loader methods like load_file() |
|
608 | - if ($this->_cache_on && $cache && ! $load_only) { |
|
609 | - // return object if it's already cached |
|
610 | - $cached_class = $this->_get_cached_class($class_name, $addon); |
|
611 | - if ($cached_class !== null) { |
|
612 | - return $cached_class; |
|
613 | - } |
|
614 | - } |
|
615 | - // instantiate the requested object |
|
616 | - $class_obj = $this->_create_object($class_name, $arguments, $addon, $from_db); |
|
617 | - if ($this->_cache_on && $cache) { |
|
618 | - // save it for later... kinda like gum { : $ |
|
619 | - $this->_set_cached_class($class_obj, $class_name, $addon, $from_db); |
|
620 | - } |
|
621 | - $this->_cache_on = true; |
|
622 | - return $class_obj; |
|
623 | - } |
|
624 | - |
|
625 | - |
|
626 | - |
|
627 | - /** |
|
628 | - * instantiates, caches, and injects dependencies for classes |
|
629 | - * |
|
630 | - * @param array $file_paths an array of paths to folders to look in |
|
631 | - * @param string $class_prefix EE or EEM or... ??? |
|
632 | - * @param bool|string $class_name $class name |
|
633 | - * @param string $type file type - core? class? helper? model? |
|
634 | - * @param mixed $arguments an argument or array of arguments to pass to the class upon instantiation |
|
635 | - * @param bool $from_db some classes are instantiated from the db |
|
636 | - * and thus call a different method to instantiate |
|
637 | - * @param bool $cache whether to cache the instantiated object for reuse |
|
638 | - * @param bool $load_only if true, will only load the file, but will NOT instantiate an object |
|
639 | - * @return null|object|bool null = failure to load or instantiate class object. |
|
640 | - * object = class loaded and instantiated successfully. |
|
641 | - * bool = fail or success when $load_only is true |
|
642 | - */ |
|
643 | - protected function _load( |
|
644 | - $file_paths = array(), |
|
645 | - $class_prefix = 'EE_', |
|
646 | - $class_name = false, |
|
647 | - $type = 'class', |
|
648 | - $arguments = array(), |
|
649 | - $from_db = false, |
|
650 | - $cache = true, |
|
651 | - $load_only = false |
|
652 | - ) { |
|
653 | - $class_name = ltrim($class_name, '\\'); |
|
654 | - // strip php file extension |
|
655 | - $class_name = str_replace('.php', '', trim($class_name)); |
|
656 | - // does the class have a prefix ? |
|
657 | - if ( ! empty($class_prefix) && $class_prefix != 'addon') { |
|
658 | - // make sure $class_prefix is uppercase |
|
659 | - $class_prefix = strtoupper(trim($class_prefix)); |
|
660 | - // add class prefix ONCE!!! |
|
661 | - $class_name = $class_prefix . str_replace($class_prefix, '', $class_name); |
|
662 | - } |
|
663 | - $class_name = $this->_dependency_map->get_alias($class_name); |
|
664 | - $class_exists = class_exists($class_name); |
|
665 | - // if we're only loading the class and it already exists, then let's just return true immediately |
|
666 | - if ($load_only && $class_exists) { |
|
667 | - return true; |
|
668 | - } |
|
669 | - // $this->_cache_on is toggled during the recursive loading that can occur with dependency injection |
|
670 | - // $cache is controlled by individual calls to separate Registry loader methods like load_class() |
|
671 | - // $load_only is also controlled by individual calls to separate Registry loader methods like load_file() |
|
672 | - if ($this->_cache_on && $cache && ! $load_only) { |
|
673 | - // return object if it's already cached |
|
674 | - $cached_class = $this->_get_cached_class($class_name, $class_prefix); |
|
675 | - if ($cached_class !== null) { |
|
676 | - return $cached_class; |
|
677 | - } |
|
678 | - } |
|
679 | - // if the class doesn't already exist.. then we need to try and find the file and load it |
|
680 | - if ( ! $class_exists) { |
|
681 | - // get full path to file |
|
682 | - $path = $this->_resolve_path($class_name, $type, $file_paths); |
|
683 | - // load the file |
|
684 | - $loaded = $this->_require_file($path, $class_name, $type, $file_paths); |
|
685 | - // if loading failed, or we are only loading a file but NOT instantiating an object |
|
686 | - if ( ! $loaded || $load_only) { |
|
687 | - // return boolean if only loading, or null if an object was expected |
|
688 | - return $load_only ? $loaded : null; |
|
689 | - } |
|
690 | - } |
|
691 | - // instantiate the requested object |
|
692 | - $class_obj = $this->_create_object($class_name, $arguments, $type, $from_db); |
|
693 | - if ($this->_cache_on && $cache) { |
|
694 | - // save it for later... kinda like gum { : $ |
|
695 | - $this->_set_cached_class($class_obj, $class_name, $class_prefix, $from_db); |
|
696 | - } |
|
697 | - $this->_cache_on = true; |
|
698 | - return $class_obj; |
|
699 | - } |
|
700 | - |
|
701 | - |
|
702 | - |
|
703 | - /** |
|
704 | - * _get_cached_class |
|
705 | - * attempts to find a cached version of the requested class |
|
706 | - * by looking in the following places: |
|
707 | - * $this->{$class_abbreviation} ie: $this->CART |
|
708 | - * $this->{$class_name} ie: $this->Some_Class |
|
709 | - * $this->LIB->{$class_name} ie: $this->LIB->Some_Class |
|
710 | - * $this->addon->{$class_name} ie: $this->addon->Some_Addon_Class |
|
711 | - * |
|
712 | - * @access protected |
|
713 | - * @param string $class_name |
|
714 | - * @param string $class_prefix |
|
715 | - * @return mixed |
|
716 | - */ |
|
717 | - protected function _get_cached_class($class_name, $class_prefix = '') |
|
718 | - { |
|
719 | - if (isset($this->_class_abbreviations[$class_name])) { |
|
720 | - $class_abbreviation = $this->_class_abbreviations[$class_name]; |
|
721 | - } else { |
|
722 | - // have to specify something, but not anything that will conflict |
|
723 | - $class_abbreviation = 'FANCY_BATMAN_PANTS'; |
|
724 | - } |
|
725 | - // check if class has already been loaded, and return it if it has been |
|
726 | - if (isset($this->{$class_abbreviation}) && ! is_null($this->{$class_abbreviation})) { |
|
727 | - return $this->{$class_abbreviation}; |
|
728 | - } else if (isset ($this->{$class_name})) { |
|
729 | - return $this->{$class_name}; |
|
730 | - } else if (isset ($this->LIB->{$class_name})) { |
|
731 | - return $this->LIB->{$class_name}; |
|
732 | - } else if ($class_prefix == 'addon' && isset ($this->addons->{$class_name})) { |
|
733 | - return $this->addons->{$class_name}; |
|
734 | - } |
|
735 | - return null; |
|
736 | - } |
|
737 | - |
|
738 | - |
|
739 | - |
|
740 | - /** |
|
741 | - * _resolve_path |
|
742 | - * attempts to find a full valid filepath for the requested class. |
|
743 | - * loops thru each of the base paths in the $file_paths array and appends : "{classname} . {file type} . php" |
|
744 | - * then returns that path if the target file has been found and is readable |
|
745 | - * |
|
746 | - * @access protected |
|
747 | - * @param string $class_name |
|
748 | - * @param string $type |
|
749 | - * @param array $file_paths |
|
750 | - * @return string | bool |
|
751 | - */ |
|
752 | - protected function _resolve_path($class_name, $type = '', $file_paths = array()) |
|
753 | - { |
|
754 | - // make sure $file_paths is an array |
|
755 | - $file_paths = is_array($file_paths) ? $file_paths : array($file_paths); |
|
756 | - // cycle thru paths |
|
757 | - foreach ($file_paths as $key => $file_path) { |
|
758 | - // convert all separators to proper DS, if no filepath, then use EE_CLASSES |
|
759 | - $file_path = $file_path ? str_replace(array('/', '\\'), DS, $file_path) : EE_CLASSES; |
|
760 | - // prep file type |
|
761 | - $type = ! empty($type) ? trim($type, '.') . '.' : ''; |
|
762 | - // build full file path |
|
763 | - $file_paths[$key] = rtrim($file_path, DS) . DS . $class_name . '.' . $type . 'php'; |
|
764 | - //does the file exist and can be read ? |
|
765 | - if (is_readable($file_paths[$key])) { |
|
766 | - return $file_paths[$key]; |
|
767 | - } |
|
768 | - } |
|
769 | - return false; |
|
770 | - } |
|
771 | - |
|
772 | - |
|
773 | - |
|
774 | - /** |
|
775 | - * _require_file |
|
776 | - * basically just performs a require_once() |
|
777 | - * but with some error handling |
|
778 | - * |
|
779 | - * @access protected |
|
780 | - * @param string $path |
|
781 | - * @param string $class_name |
|
782 | - * @param string $type |
|
783 | - * @param array $file_paths |
|
784 | - * @return boolean |
|
785 | - * @throws \EE_Error |
|
786 | - */ |
|
787 | - protected function _require_file($path, $class_name, $type = '', $file_paths = array()) |
|
788 | - { |
|
789 | - // don't give up! you gotta... |
|
790 | - try { |
|
791 | - //does the file exist and can it be read ? |
|
792 | - if ( ! $path) { |
|
793 | - // so sorry, can't find the file |
|
794 | - throw new EE_Error ( |
|
795 | - sprintf( |
|
796 | - __('The %1$s file %2$s could not be located or is not readable due to file permissions. Please ensure that the following filepath(s) are correct: %3$s', 'event_espresso'), |
|
797 | - trim($type, '.'), |
|
798 | - $class_name, |
|
799 | - '<br />' . implode(',<br />', $file_paths) |
|
800 | - ) |
|
801 | - ); |
|
802 | - } |
|
803 | - // get the file |
|
804 | - require_once($path); |
|
805 | - // if the class isn't already declared somewhere |
|
806 | - if (class_exists($class_name, false) === false) { |
|
807 | - // so sorry, not a class |
|
808 | - throw new EE_Error( |
|
809 | - sprintf( |
|
810 | - __('The %s file %s does not appear to contain the %s Class.', 'event_espresso'), |
|
811 | - $type, |
|
812 | - $path, |
|
813 | - $class_name |
|
814 | - ) |
|
815 | - ); |
|
816 | - } |
|
817 | - } catch (EE_Error $e) { |
|
818 | - $e->get_error(); |
|
819 | - return false; |
|
820 | - } |
|
821 | - return true; |
|
822 | - } |
|
823 | - |
|
824 | - |
|
825 | - |
|
826 | - /** |
|
827 | - * _create_object |
|
828 | - * Attempts to instantiate the requested class via any of the |
|
829 | - * commonly used instantiation methods employed throughout EE. |
|
830 | - * The priority for instantiation is as follows: |
|
831 | - * - abstract classes or any class flagged as "load only" (no instantiation occurs) |
|
832 | - * - model objects via their 'new_instance_from_db' method |
|
833 | - * - model objects via their 'new_instance' method |
|
834 | - * - "singleton" classes" via their 'instance' method |
|
835 | - * - standard instantiable classes via their __constructor |
|
836 | - * Prior to instantiation, if the classname exists in the dependency_map, |
|
837 | - * then the constructor for the requested class will be examined to determine |
|
838 | - * if any dependencies exist, and if they can be injected. |
|
839 | - * If so, then those classes will be added to the array of arguments passed to the constructor |
|
840 | - * |
|
841 | - * @access protected |
|
842 | - * @param string $class_name |
|
843 | - * @param array $arguments |
|
844 | - * @param string $type |
|
845 | - * @param bool $from_db |
|
846 | - * @return null | object |
|
847 | - * @throws \EE_Error |
|
848 | - */ |
|
849 | - protected function _create_object($class_name, $arguments = array(), $type = '', $from_db = false) |
|
850 | - { |
|
851 | - $class_obj = null; |
|
852 | - $instantiation_mode = '0) none'; |
|
853 | - // don't give up! you gotta... |
|
854 | - try { |
|
855 | - // create reflection |
|
856 | - $reflector = $this->get_ReflectionClass($class_name); |
|
857 | - // make sure arguments are an array |
|
858 | - $arguments = is_array($arguments) ? $arguments : array($arguments); |
|
859 | - // and if arguments array is numerically and sequentially indexed, then we want it to remain as is, |
|
860 | - // else wrap it in an additional array so that it doesn't get split into multiple parameters |
|
861 | - $arguments = $this->_array_is_numerically_and_sequentially_indexed($arguments) |
|
862 | - ? $arguments |
|
863 | - : array($arguments); |
|
864 | - // attempt to inject dependencies ? |
|
865 | - if ($this->_dependency_map->has($class_name)) { |
|
866 | - $arguments = $this->_resolve_dependencies($reflector, $class_name, $arguments); |
|
867 | - } |
|
868 | - // instantiate the class if possible |
|
869 | - if ($reflector->isAbstract()) { |
|
870 | - // nothing to instantiate, loading file was enough |
|
871 | - // does not throw an exception so $instantiation_mode is unused |
|
872 | - // $instantiation_mode = "1) no constructor abstract class"; |
|
873 | - $class_obj = true; |
|
874 | - } else if ($reflector->getConstructor() === null && $reflector->isInstantiable() && empty($arguments)) { |
|
875 | - // no constructor = static methods only... nothing to instantiate, loading file was enough |
|
876 | - $instantiation_mode = "2) no constructor but instantiable"; |
|
877 | - $class_obj = $reflector->newInstance(); |
|
878 | - } else if ($from_db && method_exists($class_name, 'new_instance_from_db')) { |
|
879 | - $instantiation_mode = "3) new_instance_from_db()"; |
|
880 | - $class_obj = call_user_func_array(array($class_name, 'new_instance_from_db'), $arguments); |
|
881 | - } else if (method_exists($class_name, 'new_instance')) { |
|
882 | - $instantiation_mode = "4) new_instance()"; |
|
883 | - $class_obj = call_user_func_array(array($class_name, 'new_instance'), $arguments); |
|
884 | - } else if (method_exists($class_name, 'instance')) { |
|
885 | - $instantiation_mode = "5) instance()"; |
|
886 | - $class_obj = call_user_func_array(array($class_name, 'instance'), $arguments); |
|
887 | - } else if ($reflector->isInstantiable()) { |
|
888 | - $instantiation_mode = "6) constructor"; |
|
889 | - $class_obj = $reflector->newInstanceArgs($arguments); |
|
890 | - } else { |
|
891 | - // heh ? something's not right ! |
|
892 | - throw new EE_Error( |
|
893 | - sprintf( |
|
894 | - __('The %s file %s could not be instantiated.', 'event_espresso'), |
|
895 | - $type, |
|
896 | - $class_name |
|
897 | - ) |
|
898 | - ); |
|
899 | - } |
|
900 | - } catch (Exception $e) { |
|
901 | - if ( ! $e instanceof EE_Error) { |
|
902 | - $e = new EE_Error( |
|
903 | - sprintf( |
|
904 | - __('The following error occurred while attempting to instantiate "%1$s": %2$s %3$s %2$s instantiation mode : %4$s', 'event_espresso'), |
|
905 | - $class_name, |
|
906 | - '<br />', |
|
907 | - $e->getMessage(), |
|
908 | - $instantiation_mode |
|
909 | - ) |
|
910 | - ); |
|
911 | - } |
|
912 | - $e->get_error(); |
|
913 | - } |
|
914 | - return $class_obj; |
|
915 | - } |
|
916 | - |
|
917 | - |
|
918 | - |
|
919 | - /** |
|
920 | - * @see http://stackoverflow.com/questions/173400/how-to-check-if-php-array-is-associative-or-sequential |
|
921 | - * @param array $array |
|
922 | - * @return bool |
|
923 | - */ |
|
924 | - protected function _array_is_numerically_and_sequentially_indexed(array $array) |
|
925 | - { |
|
926 | - return ! empty($array) ? array_keys($array) === range(0, count($array) - 1) : true; |
|
927 | - } |
|
928 | - |
|
929 | - |
|
930 | - |
|
931 | - /** |
|
932 | - * getReflectionClass |
|
933 | - * checks if a ReflectionClass object has already been generated for a class |
|
934 | - * and returns that instead of creating a new one |
|
935 | - * |
|
936 | - * @access public |
|
937 | - * @param string $class_name |
|
938 | - * @return ReflectionClass |
|
939 | - */ |
|
940 | - public function get_ReflectionClass($class_name) |
|
941 | - { |
|
942 | - if ( |
|
943 | - ! isset($this->_reflectors[$class_name]) |
|
944 | - || ! $this->_reflectors[$class_name] instanceof ReflectionClass |
|
945 | - ) { |
|
946 | - $this->_reflectors[$class_name] = new ReflectionClass($class_name); |
|
947 | - } |
|
948 | - return $this->_reflectors[$class_name]; |
|
949 | - } |
|
950 | - |
|
951 | - |
|
952 | - |
|
953 | - /** |
|
954 | - * _resolve_dependencies |
|
955 | - * examines the constructor for the requested class to determine |
|
956 | - * if any dependencies exist, and if they can be injected. |
|
957 | - * If so, then those classes will be added to the array of arguments passed to the constructor |
|
958 | - * PLZ NOTE: this is achieved by type hinting the constructor params |
|
959 | - * For example: |
|
960 | - * if attempting to load a class "Foo" with the following constructor: |
|
961 | - * __construct( Bar $bar_class, Fighter $grohl_class ) |
|
962 | - * then $bar_class and $grohl_class will be added to the $arguments array, |
|
963 | - * but only IF they are NOT already present in the incoming arguments array, |
|
964 | - * and the correct classes can be loaded |
|
965 | - * |
|
966 | - * @access protected |
|
967 | - * @param ReflectionClass $reflector |
|
968 | - * @param string $class_name |
|
969 | - * @param array $arguments |
|
970 | - * @return array |
|
971 | - * @throws \ReflectionException |
|
972 | - */ |
|
973 | - protected function _resolve_dependencies(ReflectionClass $reflector, $class_name, $arguments = array()) |
|
974 | - { |
|
975 | - // let's examine the constructor |
|
976 | - $constructor = $reflector->getConstructor(); |
|
977 | - // whu? huh? nothing? |
|
978 | - if ( ! $constructor) { |
|
979 | - return $arguments; |
|
980 | - } |
|
981 | - // get constructor parameters |
|
982 | - $params = $constructor->getParameters(); |
|
983 | - // and the keys for the incoming arguments array so that we can compare existing arguments with what is expected |
|
984 | - $argument_keys = array_keys($arguments); |
|
985 | - // now loop thru all of the constructors expected parameters |
|
986 | - foreach ($params as $index => $param) { |
|
987 | - // is this a dependency for a specific class ? |
|
988 | - $param_class = $param->getClass() ? $param->getClass()->name : null; |
|
989 | - if ( |
|
990 | - // param is not even a class |
|
991 | - empty($param_class) |
|
992 | - // and something already exists in the incoming arguments for this param |
|
993 | - && isset($argument_keys[$index], $arguments[$argument_keys[$index]]) |
|
994 | - ) { |
|
995 | - // so let's skip this argument and move on to the next |
|
996 | - continue; |
|
997 | - } else if ( |
|
998 | - // parameter is type hinted as a class, exists as an incoming argument, AND it's the correct class |
|
999 | - ! empty($param_class) |
|
1000 | - && isset($argument_keys[$index], $arguments[$argument_keys[$index]]) |
|
1001 | - && $arguments[$argument_keys[$index]] instanceof $param_class |
|
1002 | - ) { |
|
1003 | - // skip this argument and move on to the next |
|
1004 | - continue; |
|
1005 | - } else if ( |
|
1006 | - // parameter is type hinted as a class, and should be injected |
|
1007 | - ! empty($param_class) |
|
1008 | - && $this->_dependency_map->has_dependency_for_class($class_name, $param_class) |
|
1009 | - ) { |
|
1010 | - $arguments = $this->_resolve_dependency($class_name, $param_class, $arguments, $index); |
|
1011 | - } else { |
|
1012 | - try { |
|
1013 | - $arguments[$index] = $param->getDefaultValue(); |
|
1014 | - } catch (ReflectionException $e) { |
|
1015 | - throw new ReflectionException( |
|
1016 | - sprintf( |
|
1017 | - __('%1$s for parameter "$%2$s"', 'event_espresso'), |
|
1018 | - $e->getMessage(), |
|
1019 | - $param->getName() |
|
1020 | - ) |
|
1021 | - ); |
|
1022 | - } |
|
1023 | - } |
|
1024 | - } |
|
1025 | - return $arguments; |
|
1026 | - } |
|
1027 | - |
|
1028 | - |
|
1029 | - |
|
1030 | - /** |
|
1031 | - * @access protected |
|
1032 | - * @param string $class_name |
|
1033 | - * @param string $param_class |
|
1034 | - * @param array $arguments |
|
1035 | - * @param mixed $index |
|
1036 | - * @return array |
|
1037 | - */ |
|
1038 | - protected function _resolve_dependency($class_name, $param_class, $arguments, $index) |
|
1039 | - { |
|
1040 | - $dependency = null; |
|
1041 | - // should dependency be loaded from cache ? |
|
1042 | - $cache_on = $this->_dependency_map->loading_strategy_for_class_dependency($class_name, $param_class) |
|
1043 | - !== EE_Dependency_Map::load_new_object |
|
1044 | - ? true |
|
1045 | - : false; |
|
1046 | - // we might have a dependency... |
|
1047 | - // let's MAYBE try and find it in our cache if that's what's been requested |
|
1048 | - $cached_class = $cache_on ? $this->_get_cached_class($param_class) : null; |
|
1049 | - // and grab it if it exists |
|
1050 | - if ($cached_class instanceof $param_class) { |
|
1051 | - $dependency = $cached_class; |
|
1052 | - } else if ($param_class != $class_name) { |
|
1053 | - // obtain the loader method from the dependency map |
|
1054 | - $loader = $this->_dependency_map->class_loader($param_class); |
|
1055 | - // is loader a custom closure ? |
|
1056 | - if ($loader instanceof Closure) { |
|
1057 | - $dependency = $loader(); |
|
1058 | - } else { |
|
1059 | - // set the cache on property for the recursive loading call |
|
1060 | - $this->_cache_on = $cache_on; |
|
1061 | - // if not, then let's try and load it via the registry |
|
1062 | - if (method_exists($this, $loader)) { |
|
1063 | - $dependency = $this->{$loader}($param_class); |
|
1064 | - } else { |
|
1065 | - $dependency = $this->create($param_class, array(), $cache_on); |
|
1066 | - } |
|
1067 | - } |
|
1068 | - } |
|
1069 | - // did we successfully find the correct dependency ? |
|
1070 | - if ($dependency instanceof $param_class) { |
|
1071 | - // then let's inject it into the incoming array of arguments at the correct location |
|
1072 | - if (isset($argument_keys[$index])) { |
|
1073 | - $arguments[$argument_keys[$index]] = $dependency; |
|
1074 | - } else { |
|
1075 | - $arguments[$index] = $dependency; |
|
1076 | - } |
|
1077 | - } |
|
1078 | - return $arguments; |
|
1079 | - } |
|
1080 | - |
|
1081 | - |
|
1082 | - |
|
1083 | - /** |
|
1084 | - * _set_cached_class |
|
1085 | - * attempts to cache the instantiated class locally |
|
1086 | - * in one of the following places, in the following order: |
|
1087 | - * $this->{class_abbreviation} ie: $this->CART |
|
1088 | - * $this->{$class_name} ie: $this->Some_Class |
|
1089 | - * $this->addon->{$$class_name} ie: $this->addon->Some_Addon_Class |
|
1090 | - * $this->LIB->{$class_name} ie: $this->LIB->Some_Class |
|
1091 | - * |
|
1092 | - * @access protected |
|
1093 | - * @param object $class_obj |
|
1094 | - * @param string $class_name |
|
1095 | - * @param string $class_prefix |
|
1096 | - * @param bool $from_db |
|
1097 | - * @return void |
|
1098 | - */ |
|
1099 | - protected function _set_cached_class($class_obj, $class_name, $class_prefix = '', $from_db = false) |
|
1100 | - { |
|
1101 | - if (empty($class_obj)) { |
|
1102 | - return; |
|
1103 | - } |
|
1104 | - // return newly instantiated class |
|
1105 | - if (isset($this->_class_abbreviations[$class_name])) { |
|
1106 | - $class_abbreviation = $this->_class_abbreviations[$class_name]; |
|
1107 | - $this->{$class_abbreviation} = $class_obj; |
|
1108 | - } else if (property_exists($this, $class_name)) { |
|
1109 | - $this->{$class_name} = $class_obj; |
|
1110 | - } else if ($class_prefix == 'addon') { |
|
1111 | - $this->addons->{$class_name} = $class_obj; |
|
1112 | - } else if ( ! $from_db) { |
|
1113 | - $this->LIB->{$class_name} = $class_obj; |
|
1114 | - } |
|
1115 | - } |
|
1116 | - |
|
1117 | - |
|
1118 | - |
|
1119 | - /** |
|
1120 | - * call any loader that's been registered in the EE_Dependency_Map::$_class_loaders array |
|
1121 | - * |
|
1122 | - * @param string $classname PLEASE NOTE: the class name needs to match what's registered |
|
1123 | - * in the EE_Dependency_Map::$_class_loaders array, |
|
1124 | - * including the class prefix, ie: "EE_", "EEM_", "EEH_", etc |
|
1125 | - * @param array $arguments |
|
1126 | - * @return object |
|
1127 | - */ |
|
1128 | - public static function factory($classname, $arguments = array()) |
|
1129 | - { |
|
1130 | - $loader = self::instance()->_dependency_map->class_loader($classname); |
|
1131 | - if ($loader instanceof Closure) { |
|
1132 | - return $loader($arguments); |
|
1133 | - } else if (method_exists(EE_Registry::instance(), $loader)) { |
|
1134 | - return EE_Registry::instance()->{$loader}($classname, $arguments); |
|
1135 | - } |
|
1136 | - return null; |
|
1137 | - } |
|
1138 | - |
|
1139 | - |
|
1140 | - |
|
1141 | - /** |
|
1142 | - * Gets the addon by its name/slug (not classname. For that, just |
|
1143 | - * use the classname as the property name on EE_Config::instance()->addons) |
|
1144 | - * |
|
1145 | - * @param string $name |
|
1146 | - * @return EE_Addon |
|
1147 | - */ |
|
1148 | - public function get_addon_by_name($name) |
|
1149 | - { |
|
1150 | - foreach ($this->addons as $addon) { |
|
1151 | - if ($addon->name() == $name) { |
|
1152 | - return $addon; |
|
1153 | - } |
|
1154 | - } |
|
1155 | - return null; |
|
1156 | - } |
|
1157 | - |
|
1158 | - |
|
1159 | - |
|
1160 | - /** |
|
1161 | - * Gets an array of all the registered addons, where the keys are their names. (ie, what each returns for their name() function) They're already available on EE_Config::instance()->addons as properties, where each property's name is |
|
1162 | - * the addon's classname. So if you just want to get the addon by classname, use EE_Config::instance()->addons->{classname} |
|
1163 | - * |
|
1164 | - * @return EE_Addon[] where the KEYS are the addon's name() |
|
1165 | - */ |
|
1166 | - public function get_addons_by_name() |
|
1167 | - { |
|
1168 | - $addons = array(); |
|
1169 | - foreach ($this->addons as $addon) { |
|
1170 | - $addons[$addon->name()] = $addon; |
|
1171 | - } |
|
1172 | - return $addons; |
|
1173 | - } |
|
1174 | - |
|
1175 | - |
|
1176 | - |
|
1177 | - /** |
|
1178 | - * Resets the specified model's instance AND makes sure EE_Registry doesn't keep |
|
1179 | - * a stale copy of it around |
|
1180 | - * |
|
1181 | - * @param string $model_name |
|
1182 | - * @return \EEM_Base |
|
1183 | - * @throws \EE_Error |
|
1184 | - */ |
|
1185 | - public function reset_model($model_name) |
|
1186 | - { |
|
1187 | - $model_class_name = strpos($model_name, 'EEM_') !== 0 ? "EEM_{$model_name}" : $model_name; |
|
1188 | - if ( ! isset($this->LIB->{$model_class_name}) || ! $this->LIB->{$model_class_name} instanceof EEM_Base) { |
|
1189 | - return null; |
|
1190 | - } |
|
1191 | - //get that model reset it and make sure we nuke the old reference to it |
|
1192 | - if ($this->LIB->{$model_class_name} instanceof $model_class_name && is_callable(array($model_class_name, 'reset'))) { |
|
1193 | - $this->LIB->{$model_class_name} = $this->LIB->{$model_class_name}->reset(); |
|
1194 | - } else { |
|
1195 | - throw new EE_Error(sprintf(__('Model %s does not have a method "reset"', 'event_espresso'), $model_name)); |
|
1196 | - } |
|
1197 | - return $this->LIB->{$model_class_name}; |
|
1198 | - } |
|
1199 | - |
|
1200 | - |
|
1201 | - |
|
1202 | - /** |
|
1203 | - * Resets the registry. |
|
1204 | - * The criteria for what gets reset is based on what can be shared between sites on the same request when switch_to_blog |
|
1205 | - * is used in a multisite install. Here is a list of things that are NOT reset. |
|
1206 | - * - $_dependency_map |
|
1207 | - * - $_class_abbreviations |
|
1208 | - * - $NET_CFG (EE_Network_Config): The config is shared network wide so no need to reset. |
|
1209 | - * - $REQ: Still on the same request so no need to change. |
|
1210 | - * - $CAP: There is no site specific state in the EE_Capability class. |
|
1211 | - * - $SSN: Although ideally, the session should not be shared between site switches, we can't reset it because only one Session |
|
1212 | - * can be active in a single request. Resetting could resolve in "headers already sent" errors. |
|
1213 | - * - $addons: In multisite, the state of the addons is something controlled via hooks etc in a normal request. So |
|
1214 | - * for now, we won't reset the addons because it could break calls to an add-ons class/methods in the |
|
1215 | - * switch or on the restore. |
|
1216 | - * - $modules |
|
1217 | - * - $shortcodes |
|
1218 | - * - $widgets |
|
1219 | - * |
|
1220 | - * @param boolean $hard whether to reset data in the database too, or just refresh |
|
1221 | - * the Registry to its state at the beginning of the request |
|
1222 | - * @param boolean $reinstantiate whether to create new instances of EE_Registry's singletons too, |
|
1223 | - * or just reset without re-instantiating (handy to set to FALSE if you're not sure if you CAN |
|
1224 | - * currently reinstantiate the singletons at the moment) |
|
1225 | - * @param bool $reset_models Defaults to true. When false, then the models are not reset. This is so client |
|
1226 | - * code instead can just change the model context to a different blog id if necessary |
|
1227 | - * @return EE_Registry |
|
1228 | - */ |
|
1229 | - public static function reset($hard = false, $reinstantiate = true, $reset_models = true) |
|
1230 | - { |
|
1231 | - $instance = self::instance(); |
|
1232 | - EEH_Activation::reset(); |
|
1233 | - //properties that get reset |
|
1234 | - $instance->_cache_on = true; |
|
1235 | - $instance->CFG = EE_Config::reset($hard, $reinstantiate); |
|
1236 | - $instance->CART = null; |
|
1237 | - $instance->MRM = null; |
|
1238 | - $instance->AssetsRegistry = new Registry(); |
|
1239 | - //messages reset |
|
1240 | - EED_Messages::reset(); |
|
1241 | - if ($reset_models) { |
|
1242 | - foreach (array_keys($instance->non_abstract_db_models) as $model_name) { |
|
1243 | - $instance->reset_model($model_name); |
|
1244 | - } |
|
1245 | - } |
|
1246 | - $instance->LIB = new stdClass(); |
|
1247 | - return $instance; |
|
1248 | - } |
|
1249 | - |
|
1250 | - |
|
1251 | - |
|
1252 | - /** |
|
1253 | - * @override magic methods |
|
1254 | - * @return void |
|
1255 | - */ |
|
1256 | - final function __destruct() |
|
1257 | - { |
|
1258 | - } |
|
1259 | - |
|
1260 | - |
|
1261 | - |
|
1262 | - /** |
|
1263 | - * @param $a |
|
1264 | - * @param $b |
|
1265 | - */ |
|
1266 | - final function __call($a, $b) |
|
1267 | - { |
|
1268 | - } |
|
1269 | - |
|
1270 | - |
|
1271 | - |
|
1272 | - /** |
|
1273 | - * @param $a |
|
1274 | - */ |
|
1275 | - final function __get($a) |
|
1276 | - { |
|
1277 | - } |
|
1278 | - |
|
1279 | - |
|
1280 | - |
|
1281 | - /** |
|
1282 | - * @param $a |
|
1283 | - * @param $b |
|
1284 | - */ |
|
1285 | - final function __set($a, $b) |
|
1286 | - { |
|
1287 | - } |
|
1288 | - |
|
1289 | - |
|
1290 | - |
|
1291 | - /** |
|
1292 | - * @param $a |
|
1293 | - */ |
|
1294 | - final function __isset($a) |
|
1295 | - { |
|
1296 | - } |
|
19 | + /** |
|
20 | + * EE_Registry Object |
|
21 | + * |
|
22 | + * @var EE_Registry $_instance |
|
23 | + * @access private |
|
24 | + */ |
|
25 | + private static $_instance = null; |
|
26 | + |
|
27 | + /** |
|
28 | + * @var EE_Dependency_Map $_dependency_map |
|
29 | + * @access protected |
|
30 | + */ |
|
31 | + protected $_dependency_map = null; |
|
32 | + |
|
33 | + /** |
|
34 | + * @var array $_class_abbreviations |
|
35 | + * @access protected |
|
36 | + */ |
|
37 | + protected $_class_abbreviations = array(); |
|
38 | + |
|
39 | + /** |
|
40 | + * @access public |
|
41 | + * @var \EventEspresso\core\services\commands\CommandBusInterface $BUS |
|
42 | + */ |
|
43 | + public $BUS; |
|
44 | + |
|
45 | + /** |
|
46 | + * EE_Cart Object |
|
47 | + * |
|
48 | + * @access public |
|
49 | + * @var EE_Cart $CART |
|
50 | + */ |
|
51 | + public $CART = null; |
|
52 | + |
|
53 | + /** |
|
54 | + * EE_Config Object |
|
55 | + * |
|
56 | + * @access public |
|
57 | + * @var EE_Config $CFG |
|
58 | + */ |
|
59 | + public $CFG = null; |
|
60 | + |
|
61 | + /** |
|
62 | + * EE_Network_Config Object |
|
63 | + * |
|
64 | + * @access public |
|
65 | + * @var EE_Network_Config $NET_CFG |
|
66 | + */ |
|
67 | + public $NET_CFG = null; |
|
68 | + |
|
69 | + /** |
|
70 | + * StdClass object for storing library classes in |
|
71 | + * |
|
72 | + * @public LIB |
|
73 | + * @var StdClass $LIB |
|
74 | + */ |
|
75 | + public $LIB = null; |
|
76 | + |
|
77 | + /** |
|
78 | + * EE_Request_Handler Object |
|
79 | + * |
|
80 | + * @access public |
|
81 | + * @var EE_Request_Handler $REQ |
|
82 | + */ |
|
83 | + public $REQ = null; |
|
84 | + |
|
85 | + /** |
|
86 | + * EE_Session Object |
|
87 | + * |
|
88 | + * @access public |
|
89 | + * @var EE_Session $SSN |
|
90 | + */ |
|
91 | + public $SSN = null; |
|
92 | + |
|
93 | + /** |
|
94 | + * holds the ee capabilities object. |
|
95 | + * |
|
96 | + * @since 4.5.0 |
|
97 | + * @var EE_Capabilities |
|
98 | + */ |
|
99 | + public $CAP = null; |
|
100 | + |
|
101 | + /** |
|
102 | + * holds the EE_Message_Resource_Manager object. |
|
103 | + * |
|
104 | + * @since 4.9.0 |
|
105 | + * @var EE_Message_Resource_Manager |
|
106 | + */ |
|
107 | + public $MRM = null; |
|
108 | + |
|
109 | + |
|
110 | + /** |
|
111 | + * Holds the Assets Registry instance |
|
112 | + * @var Registry |
|
113 | + */ |
|
114 | + public $AssetsRegistry = null; |
|
115 | + |
|
116 | + /** |
|
117 | + * $addons - StdClass object for holding addons which have registered themselves to work with EE core |
|
118 | + * |
|
119 | + * @access public |
|
120 | + * @var EE_Addon[] |
|
121 | + */ |
|
122 | + public $addons = null; |
|
123 | + |
|
124 | + /** |
|
125 | + * $models |
|
126 | + * @access public |
|
127 | + * @var EEM_Base[] $models keys are 'short names' (eg Event), values are class names (eg 'EEM_Event') |
|
128 | + */ |
|
129 | + public $models = array(); |
|
130 | + |
|
131 | + /** |
|
132 | + * $modules |
|
133 | + * @access public |
|
134 | + * @var EED_Module[] $modules |
|
135 | + */ |
|
136 | + public $modules = null; |
|
137 | + |
|
138 | + /** |
|
139 | + * $shortcodes |
|
140 | + * @access public |
|
141 | + * @var EES_Shortcode[] $shortcodes |
|
142 | + */ |
|
143 | + public $shortcodes = null; |
|
144 | + |
|
145 | + /** |
|
146 | + * $widgets |
|
147 | + * @access public |
|
148 | + * @var WP_Widget[] $widgets |
|
149 | + */ |
|
150 | + public $widgets = null; |
|
151 | + |
|
152 | + /** |
|
153 | + * $non_abstract_db_models |
|
154 | + * @access public but its better to use EE_Registry::non_abstract_db_models() as it verifies we've set this property before returning it |
|
155 | + * @var array this is an array of all implemented model names (i.e. not the parent abstract models, or models |
|
156 | + * which don't actually fetch items from the DB in the normal way (ie, are not children of EEM_Base)). |
|
157 | + * Keys are model "short names" (eg "Event") as used in model relations, and values are |
|
158 | + * classnames (eg "EEM_Event") |
|
159 | + */ |
|
160 | + public $non_abstract_db_models = array(); |
|
161 | + |
|
162 | + |
|
163 | + /** |
|
164 | + * $i18n_js_strings - internationalization for JS strings |
|
165 | + * usage: EE_Registry::i18n_js_strings['string_key'] = __( 'string to translate.', 'event_espresso' ); |
|
166 | + * in js file: var translatedString = eei18n.string_key; |
|
167 | + * |
|
168 | + * @access public |
|
169 | + * @var array |
|
170 | + */ |
|
171 | + public static $i18n_js_strings = array(); |
|
172 | + |
|
173 | + |
|
174 | + /** |
|
175 | + * $main_file - path to espresso.php |
|
176 | + * |
|
177 | + * @access public |
|
178 | + * @var array |
|
179 | + */ |
|
180 | + public $main_file; |
|
181 | + |
|
182 | + /** |
|
183 | + * array of ReflectionClass objects where the key is the class name |
|
184 | + * |
|
185 | + * @access public |
|
186 | + * @var ReflectionClass[] |
|
187 | + */ |
|
188 | + public $_reflectors; |
|
189 | + |
|
190 | + /** |
|
191 | + * boolean flag to indicate whether or not to load/save dependencies from/to the cache |
|
192 | + * |
|
193 | + * @access protected |
|
194 | + * @var boolean $_cache_on |
|
195 | + */ |
|
196 | + protected $_cache_on = true; |
|
197 | + |
|
198 | + |
|
199 | + |
|
200 | + /** |
|
201 | + * @singleton method used to instantiate class object |
|
202 | + * @access public |
|
203 | + * @param \EE_Dependency_Map $dependency_map |
|
204 | + * @return \EE_Registry instance |
|
205 | + */ |
|
206 | + public static function instance(\EE_Dependency_Map $dependency_map = null) |
|
207 | + { |
|
208 | + // check if class object is instantiated |
|
209 | + if ( ! self::$_instance instanceof EE_Registry) { |
|
210 | + self::$_instance = new EE_Registry($dependency_map); |
|
211 | + } |
|
212 | + return self::$_instance; |
|
213 | + } |
|
214 | + |
|
215 | + |
|
216 | + |
|
217 | + /** |
|
218 | + *protected constructor to prevent direct creation |
|
219 | + * |
|
220 | + * @Constructor |
|
221 | + * @access protected |
|
222 | + * @param \EE_Dependency_Map $dependency_map |
|
223 | + * @return \EE_Registry |
|
224 | + */ |
|
225 | + protected function __construct(\EE_Dependency_Map $dependency_map) |
|
226 | + { |
|
227 | + $this->_dependency_map = $dependency_map; |
|
228 | + add_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading', array($this, 'initialize')); |
|
229 | + } |
|
230 | + |
|
231 | + |
|
232 | + |
|
233 | + /** |
|
234 | + * initialize |
|
235 | + */ |
|
236 | + public function initialize() |
|
237 | + { |
|
238 | + $this->_class_abbreviations = apply_filters( |
|
239 | + 'FHEE__EE_Registry____construct___class_abbreviations', |
|
240 | + array( |
|
241 | + 'EE_Config' => 'CFG', |
|
242 | + 'EE_Session' => 'SSN', |
|
243 | + 'EE_Capabilities' => 'CAP', |
|
244 | + 'EE_Cart' => 'CART', |
|
245 | + 'EE_Network_Config' => 'NET_CFG', |
|
246 | + 'EE_Request_Handler' => 'REQ', |
|
247 | + 'EE_Message_Resource_Manager' => 'MRM', |
|
248 | + 'EventEspresso\core\services\commands\CommandBus' => 'BUS', |
|
249 | + ) |
|
250 | + ); |
|
251 | + // class library |
|
252 | + $this->LIB = new stdClass(); |
|
253 | + $this->addons = new stdClass(); |
|
254 | + $this->modules = new stdClass(); |
|
255 | + $this->shortcodes = new stdClass(); |
|
256 | + $this->widgets = new stdClass(); |
|
257 | + $this->load_core('Base', array(), true); |
|
258 | + // add our request and response objects to the cache |
|
259 | + $request_loader = $this->_dependency_map->class_loader('EE_Request'); |
|
260 | + $this->_set_cached_class( |
|
261 | + $request_loader(), |
|
262 | + 'EE_Request' |
|
263 | + ); |
|
264 | + $response_loader = $this->_dependency_map->class_loader('EE_Response'); |
|
265 | + $this->_set_cached_class( |
|
266 | + $response_loader(), |
|
267 | + 'EE_Response' |
|
268 | + ); |
|
269 | + add_action('AHEE__EE_System__set_hooks_for_core', array($this, 'init')); |
|
270 | + } |
|
271 | + |
|
272 | + |
|
273 | + |
|
274 | + /** |
|
275 | + * init |
|
276 | + * |
|
277 | + * @access public |
|
278 | + * @return void |
|
279 | + */ |
|
280 | + public function init() |
|
281 | + { |
|
282 | + $this->AssetsRegistry = new Registry(); |
|
283 | + // Get current page protocol |
|
284 | + $protocol = isset($_SERVER['HTTPS']) ? 'https://' : 'http://'; |
|
285 | + // Output admin-ajax.php URL with same protocol as current page |
|
286 | + self::$i18n_js_strings['ajax_url'] = admin_url('admin-ajax.php', $protocol); |
|
287 | + self::$i18n_js_strings['wp_debug'] = defined('WP_DEBUG') ? WP_DEBUG : false; |
|
288 | + } |
|
289 | + |
|
290 | + |
|
291 | + |
|
292 | + /** |
|
293 | + * localize_i18n_js_strings |
|
294 | + * |
|
295 | + * @return string |
|
296 | + */ |
|
297 | + public static function localize_i18n_js_strings() |
|
298 | + { |
|
299 | + $i18n_js_strings = (array)EE_Registry::$i18n_js_strings; |
|
300 | + foreach ($i18n_js_strings as $key => $value) { |
|
301 | + if (is_scalar($value)) { |
|
302 | + $i18n_js_strings[$key] = html_entity_decode((string)$value, ENT_QUOTES, 'UTF-8'); |
|
303 | + } |
|
304 | + } |
|
305 | + return "/* <![CDATA[ */ var eei18n = " . wp_json_encode($i18n_js_strings) . '; /* ]]> */'; |
|
306 | + } |
|
307 | + |
|
308 | + |
|
309 | + |
|
310 | + /** |
|
311 | + * @param mixed string | EED_Module $module |
|
312 | + */ |
|
313 | + public function add_module($module) |
|
314 | + { |
|
315 | + if ($module instanceof EED_Module) { |
|
316 | + $module_class = get_class($module); |
|
317 | + $this->modules->{$module_class} = $module; |
|
318 | + } else { |
|
319 | + if ( ! class_exists('EE_Module_Request_Router')) { |
|
320 | + $this->load_core('Module_Request_Router'); |
|
321 | + } |
|
322 | + $this->modules->{$module} = EE_Module_Request_Router::module_factory($module); |
|
323 | + } |
|
324 | + } |
|
325 | + |
|
326 | + |
|
327 | + |
|
328 | + /** |
|
329 | + * @param string $module_name |
|
330 | + * @return mixed EED_Module | NULL |
|
331 | + */ |
|
332 | + public function get_module($module_name = '') |
|
333 | + { |
|
334 | + return isset($this->modules->{$module_name}) ? $this->modules->{$module_name} : null; |
|
335 | + } |
|
336 | + |
|
337 | + |
|
338 | + |
|
339 | + /** |
|
340 | + * loads core classes - must be singletons |
|
341 | + * |
|
342 | + * @access public |
|
343 | + * @param string $class_name - simple class name ie: session |
|
344 | + * @param mixed $arguments |
|
345 | + * @param bool $load_only |
|
346 | + * @return mixed |
|
347 | + */ |
|
348 | + public function load_core($class_name, $arguments = array(), $load_only = false) |
|
349 | + { |
|
350 | + $core_paths = apply_filters( |
|
351 | + 'FHEE__EE_Registry__load_core__core_paths', |
|
352 | + array( |
|
353 | + EE_CORE, |
|
354 | + EE_ADMIN, |
|
355 | + EE_CPTS, |
|
356 | + EE_CORE . 'data_migration_scripts' . DS, |
|
357 | + EE_CORE . 'request_stack' . DS, |
|
358 | + EE_CORE . 'middleware' . DS, |
|
359 | + ) |
|
360 | + ); |
|
361 | + // retrieve instantiated class |
|
362 | + return $this->_load($core_paths, 'EE_', $class_name, 'core', $arguments, false, true, $load_only); |
|
363 | + } |
|
364 | + |
|
365 | + |
|
366 | + |
|
367 | + /** |
|
368 | + * loads service classes |
|
369 | + * |
|
370 | + * @access public |
|
371 | + * @param string $class_name - simple class name ie: session |
|
372 | + * @param mixed $arguments |
|
373 | + * @param bool $load_only |
|
374 | + * @return mixed |
|
375 | + */ |
|
376 | + public function load_service($class_name, $arguments = array(), $load_only = false) |
|
377 | + { |
|
378 | + $service_paths = apply_filters( |
|
379 | + 'FHEE__EE_Registry__load_service__service_paths', |
|
380 | + array( |
|
381 | + EE_CORE . 'services' . DS, |
|
382 | + ) |
|
383 | + ); |
|
384 | + // retrieve instantiated class |
|
385 | + return $this->_load($service_paths, 'EE_', $class_name, 'class', $arguments, false, true, $load_only); |
|
386 | + } |
|
387 | + |
|
388 | + |
|
389 | + |
|
390 | + /** |
|
391 | + * loads data_migration_scripts |
|
392 | + * |
|
393 | + * @access public |
|
394 | + * @param string $class_name - class name for the DMS ie: EE_DMS_Core_4_2_0 |
|
395 | + * @param mixed $arguments |
|
396 | + * @return EE_Data_Migration_Script_Base|mixed |
|
397 | + */ |
|
398 | + public function load_dms($class_name, $arguments = array()) |
|
399 | + { |
|
400 | + // retrieve instantiated class |
|
401 | + return $this->_load(EE_Data_Migration_Manager::instance()->get_data_migration_script_folders(), 'EE_DMS_', $class_name, 'dms', $arguments, false, false, false); |
|
402 | + } |
|
403 | + |
|
404 | + |
|
405 | + |
|
406 | + /** |
|
407 | + * loads object creating classes - must be singletons |
|
408 | + * |
|
409 | + * @param string $class_name - simple class name ie: attendee |
|
410 | + * @param mixed $arguments - an array of arguments to pass to the class |
|
411 | + * @param bool $from_db - some classes are instantiated from the db and thus call a different method to instantiate |
|
412 | + * @param bool $cache if you don't want the class to be stored in the internal cache (non-persistent) then set this to FALSE (ie. when instantiating model objects from client in a loop) |
|
413 | + * @param bool $load_only whether or not to just load the file and NOT instantiate, or load AND instantiate (default) |
|
414 | + * @return EE_Base_Class | bool |
|
415 | + */ |
|
416 | + public function load_class($class_name, $arguments = array(), $from_db = false, $cache = true, $load_only = false) |
|
417 | + { |
|
418 | + $paths = apply_filters('FHEE__EE_Registry__load_class__paths', array( |
|
419 | + EE_CORE, |
|
420 | + EE_CLASSES, |
|
421 | + EE_BUSINESS, |
|
422 | + )); |
|
423 | + // retrieve instantiated class |
|
424 | + return $this->_load($paths, 'EE_', $class_name, 'class', $arguments, $from_db, $cache, $load_only); |
|
425 | + } |
|
426 | + |
|
427 | + |
|
428 | + |
|
429 | + /** |
|
430 | + * loads helper classes - must be singletons |
|
431 | + * |
|
432 | + * @param string $class_name - simple class name ie: price |
|
433 | + * @param mixed $arguments |
|
434 | + * @param bool $load_only |
|
435 | + * @return EEH_Base | bool |
|
436 | + */ |
|
437 | + public function load_helper($class_name, $arguments = array(), $load_only = true) |
|
438 | + { |
|
439 | + // todo: add doing_it_wrong() in a few versions after all addons have had calls to this method removed |
|
440 | + $helper_paths = apply_filters('FHEE__EE_Registry__load_helper__helper_paths', array(EE_HELPERS)); |
|
441 | + // retrieve instantiated class |
|
442 | + return $this->_load($helper_paths, 'EEH_', $class_name, 'helper', $arguments, false, true, $load_only); |
|
443 | + } |
|
444 | + |
|
445 | + |
|
446 | + |
|
447 | + /** |
|
448 | + * loads core classes - must be singletons |
|
449 | + * |
|
450 | + * @access public |
|
451 | + * @param string $class_name - simple class name ie: session |
|
452 | + * @param mixed $arguments |
|
453 | + * @param bool $load_only |
|
454 | + * @param bool $cache whether to cache the object or not. |
|
455 | + * @return mixed |
|
456 | + */ |
|
457 | + public function load_lib($class_name, $arguments = array(), $load_only = false, $cache = true) |
|
458 | + { |
|
459 | + $paths = array( |
|
460 | + EE_LIBRARIES, |
|
461 | + EE_LIBRARIES . 'messages' . DS, |
|
462 | + EE_LIBRARIES . 'shortcodes' . DS, |
|
463 | + EE_LIBRARIES . 'qtips' . DS, |
|
464 | + EE_LIBRARIES . 'payment_methods' . DS, |
|
465 | + ); |
|
466 | + // retrieve instantiated class |
|
467 | + return $this->_load($paths, 'EE_', $class_name, 'lib', $arguments, false, $cache, $load_only); |
|
468 | + } |
|
469 | + |
|
470 | + |
|
471 | + |
|
472 | + /** |
|
473 | + * loads model classes - must be singletons |
|
474 | + * |
|
475 | + * @param string $class_name - simple class name ie: price |
|
476 | + * @param mixed $arguments |
|
477 | + * @param bool $load_only |
|
478 | + * @return EEM_Base | bool |
|
479 | + */ |
|
480 | + public function load_model($class_name, $arguments = array(), $load_only = false) |
|
481 | + { |
|
482 | + $paths = apply_filters('FHEE__EE_Registry__load_model__paths', array( |
|
483 | + EE_MODELS, |
|
484 | + EE_CORE, |
|
485 | + )); |
|
486 | + // retrieve instantiated class |
|
487 | + return $this->_load($paths, 'EEM_', $class_name, 'model', $arguments, false, true, $load_only); |
|
488 | + } |
|
489 | + |
|
490 | + |
|
491 | + |
|
492 | + /** |
|
493 | + * loads model classes - must be singletons |
|
494 | + * |
|
495 | + * @param string $class_name - simple class name ie: price |
|
496 | + * @param mixed $arguments |
|
497 | + * @param bool $load_only |
|
498 | + * @return mixed | bool |
|
499 | + */ |
|
500 | + public function load_model_class($class_name, $arguments = array(), $load_only = true) |
|
501 | + { |
|
502 | + $paths = array( |
|
503 | + EE_MODELS . 'fields' . DS, |
|
504 | + EE_MODELS . 'helpers' . DS, |
|
505 | + EE_MODELS . 'relations' . DS, |
|
506 | + EE_MODELS . 'strategies' . DS, |
|
507 | + ); |
|
508 | + // retrieve instantiated class |
|
509 | + return $this->_load($paths, 'EE_', $class_name, '', $arguments, false, true, $load_only); |
|
510 | + } |
|
511 | + |
|
512 | + |
|
513 | + |
|
514 | + /** |
|
515 | + * Determines if $model_name is the name of an actual EE model. |
|
516 | + * |
|
517 | + * @param string $model_name like Event, Attendee, Question_Group_Question, etc. |
|
518 | + * @return boolean |
|
519 | + */ |
|
520 | + public function is_model_name($model_name) |
|
521 | + { |
|
522 | + $this->_verify_models_discovered(); |
|
523 | + return isset($this->models[$model_name]) ? true : false; |
|
524 | + } |
|
525 | + |
|
526 | + |
|
527 | + |
|
528 | + /** |
|
529 | + * generic class loader |
|
530 | + * |
|
531 | + * @param string $path_to_file - directory path to file location, not including filename |
|
532 | + * @param string $file_name - file name ie: my_file.php, including extension |
|
533 | + * @param string $type - file type - core? class? helper? model? |
|
534 | + * @param mixed $arguments |
|
535 | + * @param bool $load_only |
|
536 | + * @return mixed |
|
537 | + */ |
|
538 | + public function load_file($path_to_file, $file_name, $type = '', $arguments = array(), $load_only = true) |
|
539 | + { |
|
540 | + // retrieve instantiated class |
|
541 | + return $this->_load($path_to_file, '', $file_name, $type, $arguments, false, true, $load_only); |
|
542 | + } |
|
543 | + |
|
544 | + |
|
545 | + |
|
546 | + /** |
|
547 | + * load_addon |
|
548 | + * |
|
549 | + * @param string $path_to_file - directory path to file location, not including filename |
|
550 | + * @param string $class_name - full class name ie: My_Class |
|
551 | + * @param string $type - file type - core? class? helper? model? |
|
552 | + * @param mixed $arguments |
|
553 | + * @param bool $load_only |
|
554 | + * @return EE_Addon |
|
555 | + */ |
|
556 | + public function load_addon($path_to_file, $class_name, $type = 'class', $arguments = array(), $load_only = false) |
|
557 | + { |
|
558 | + // retrieve instantiated class |
|
559 | + return $this->_load($path_to_file, 'addon', $class_name, $type, $arguments, false, true, $load_only); |
|
560 | + } |
|
561 | + |
|
562 | + |
|
563 | + |
|
564 | + /** |
|
565 | + * instantiates, caches, and automatically resolves dependencies |
|
566 | + * for classes that use a Fully Qualified Class Name. |
|
567 | + * if the class is not capable of being loaded using PSR-4 autoloading, |
|
568 | + * then you need to use one of the existing load_*() methods |
|
569 | + * which can resolve the classname and filepath from the passed arguments |
|
570 | + * |
|
571 | + * @param bool|string $class_name Fully Qualified Class Name |
|
572 | + * @param array $arguments an argument, or array of arguments to pass to the class upon instantiation |
|
573 | + * @param bool $cache whether to cache the instantiated object for reuse |
|
574 | + * @param bool $from_db some classes are instantiated from the db |
|
575 | + * and thus call a different method to instantiate |
|
576 | + * @param bool $load_only if true, will only load the file, but will NOT instantiate an object |
|
577 | + * @param bool|string $addon if true, will cache the object in the EE_Registry->$addons array |
|
578 | + * @return mixed null = failure to load or instantiate class object. |
|
579 | + * object = class loaded and instantiated successfully. |
|
580 | + * bool = fail or success when $load_only is true |
|
581 | + */ |
|
582 | + public function create( |
|
583 | + $class_name = false, |
|
584 | + $arguments = array(), |
|
585 | + $cache = false, |
|
586 | + $from_db = false, |
|
587 | + $load_only = false, |
|
588 | + $addon = false |
|
589 | + ) { |
|
590 | + $class_name = ltrim($class_name, '\\'); |
|
591 | + $class_name = $this->_dependency_map->get_alias($class_name); |
|
592 | + if ( ! class_exists($class_name)) { |
|
593 | + // maybe the class is registered with a preceding \ |
|
594 | + $class_name = strpos($class_name, '\\') !== 0 ? '\\' . $class_name : $class_name; |
|
595 | + // still doesn't exist ? |
|
596 | + if ( ! class_exists($class_name)) { |
|
597 | + return null; |
|
598 | + } |
|
599 | + } |
|
600 | + // if we're only loading the class and it already exists, then let's just return true immediately |
|
601 | + if ($load_only) { |
|
602 | + return true; |
|
603 | + } |
|
604 | + $addon = $addon ? 'addon' : ''; |
|
605 | + // $this->_cache_on is toggled during the recursive loading that can occur with dependency injection |
|
606 | + // $cache is controlled by individual calls to separate Registry loader methods like load_class() |
|
607 | + // $load_only is also controlled by individual calls to separate Registry loader methods like load_file() |
|
608 | + if ($this->_cache_on && $cache && ! $load_only) { |
|
609 | + // return object if it's already cached |
|
610 | + $cached_class = $this->_get_cached_class($class_name, $addon); |
|
611 | + if ($cached_class !== null) { |
|
612 | + return $cached_class; |
|
613 | + } |
|
614 | + } |
|
615 | + // instantiate the requested object |
|
616 | + $class_obj = $this->_create_object($class_name, $arguments, $addon, $from_db); |
|
617 | + if ($this->_cache_on && $cache) { |
|
618 | + // save it for later... kinda like gum { : $ |
|
619 | + $this->_set_cached_class($class_obj, $class_name, $addon, $from_db); |
|
620 | + } |
|
621 | + $this->_cache_on = true; |
|
622 | + return $class_obj; |
|
623 | + } |
|
624 | + |
|
625 | + |
|
626 | + |
|
627 | + /** |
|
628 | + * instantiates, caches, and injects dependencies for classes |
|
629 | + * |
|
630 | + * @param array $file_paths an array of paths to folders to look in |
|
631 | + * @param string $class_prefix EE or EEM or... ??? |
|
632 | + * @param bool|string $class_name $class name |
|
633 | + * @param string $type file type - core? class? helper? model? |
|
634 | + * @param mixed $arguments an argument or array of arguments to pass to the class upon instantiation |
|
635 | + * @param bool $from_db some classes are instantiated from the db |
|
636 | + * and thus call a different method to instantiate |
|
637 | + * @param bool $cache whether to cache the instantiated object for reuse |
|
638 | + * @param bool $load_only if true, will only load the file, but will NOT instantiate an object |
|
639 | + * @return null|object|bool null = failure to load or instantiate class object. |
|
640 | + * object = class loaded and instantiated successfully. |
|
641 | + * bool = fail or success when $load_only is true |
|
642 | + */ |
|
643 | + protected function _load( |
|
644 | + $file_paths = array(), |
|
645 | + $class_prefix = 'EE_', |
|
646 | + $class_name = false, |
|
647 | + $type = 'class', |
|
648 | + $arguments = array(), |
|
649 | + $from_db = false, |
|
650 | + $cache = true, |
|
651 | + $load_only = false |
|
652 | + ) { |
|
653 | + $class_name = ltrim($class_name, '\\'); |
|
654 | + // strip php file extension |
|
655 | + $class_name = str_replace('.php', '', trim($class_name)); |
|
656 | + // does the class have a prefix ? |
|
657 | + if ( ! empty($class_prefix) && $class_prefix != 'addon') { |
|
658 | + // make sure $class_prefix is uppercase |
|
659 | + $class_prefix = strtoupper(trim($class_prefix)); |
|
660 | + // add class prefix ONCE!!! |
|
661 | + $class_name = $class_prefix . str_replace($class_prefix, '', $class_name); |
|
662 | + } |
|
663 | + $class_name = $this->_dependency_map->get_alias($class_name); |
|
664 | + $class_exists = class_exists($class_name); |
|
665 | + // if we're only loading the class and it already exists, then let's just return true immediately |
|
666 | + if ($load_only && $class_exists) { |
|
667 | + return true; |
|
668 | + } |
|
669 | + // $this->_cache_on is toggled during the recursive loading that can occur with dependency injection |
|
670 | + // $cache is controlled by individual calls to separate Registry loader methods like load_class() |
|
671 | + // $load_only is also controlled by individual calls to separate Registry loader methods like load_file() |
|
672 | + if ($this->_cache_on && $cache && ! $load_only) { |
|
673 | + // return object if it's already cached |
|
674 | + $cached_class = $this->_get_cached_class($class_name, $class_prefix); |
|
675 | + if ($cached_class !== null) { |
|
676 | + return $cached_class; |
|
677 | + } |
|
678 | + } |
|
679 | + // if the class doesn't already exist.. then we need to try and find the file and load it |
|
680 | + if ( ! $class_exists) { |
|
681 | + // get full path to file |
|
682 | + $path = $this->_resolve_path($class_name, $type, $file_paths); |
|
683 | + // load the file |
|
684 | + $loaded = $this->_require_file($path, $class_name, $type, $file_paths); |
|
685 | + // if loading failed, or we are only loading a file but NOT instantiating an object |
|
686 | + if ( ! $loaded || $load_only) { |
|
687 | + // return boolean if only loading, or null if an object was expected |
|
688 | + return $load_only ? $loaded : null; |
|
689 | + } |
|
690 | + } |
|
691 | + // instantiate the requested object |
|
692 | + $class_obj = $this->_create_object($class_name, $arguments, $type, $from_db); |
|
693 | + if ($this->_cache_on && $cache) { |
|
694 | + // save it for later... kinda like gum { : $ |
|
695 | + $this->_set_cached_class($class_obj, $class_name, $class_prefix, $from_db); |
|
696 | + } |
|
697 | + $this->_cache_on = true; |
|
698 | + return $class_obj; |
|
699 | + } |
|
700 | + |
|
701 | + |
|
702 | + |
|
703 | + /** |
|
704 | + * _get_cached_class |
|
705 | + * attempts to find a cached version of the requested class |
|
706 | + * by looking in the following places: |
|
707 | + * $this->{$class_abbreviation} ie: $this->CART |
|
708 | + * $this->{$class_name} ie: $this->Some_Class |
|
709 | + * $this->LIB->{$class_name} ie: $this->LIB->Some_Class |
|
710 | + * $this->addon->{$class_name} ie: $this->addon->Some_Addon_Class |
|
711 | + * |
|
712 | + * @access protected |
|
713 | + * @param string $class_name |
|
714 | + * @param string $class_prefix |
|
715 | + * @return mixed |
|
716 | + */ |
|
717 | + protected function _get_cached_class($class_name, $class_prefix = '') |
|
718 | + { |
|
719 | + if (isset($this->_class_abbreviations[$class_name])) { |
|
720 | + $class_abbreviation = $this->_class_abbreviations[$class_name]; |
|
721 | + } else { |
|
722 | + // have to specify something, but not anything that will conflict |
|
723 | + $class_abbreviation = 'FANCY_BATMAN_PANTS'; |
|
724 | + } |
|
725 | + // check if class has already been loaded, and return it if it has been |
|
726 | + if (isset($this->{$class_abbreviation}) && ! is_null($this->{$class_abbreviation})) { |
|
727 | + return $this->{$class_abbreviation}; |
|
728 | + } else if (isset ($this->{$class_name})) { |
|
729 | + return $this->{$class_name}; |
|
730 | + } else if (isset ($this->LIB->{$class_name})) { |
|
731 | + return $this->LIB->{$class_name}; |
|
732 | + } else if ($class_prefix == 'addon' && isset ($this->addons->{$class_name})) { |
|
733 | + return $this->addons->{$class_name}; |
|
734 | + } |
|
735 | + return null; |
|
736 | + } |
|
737 | + |
|
738 | + |
|
739 | + |
|
740 | + /** |
|
741 | + * _resolve_path |
|
742 | + * attempts to find a full valid filepath for the requested class. |
|
743 | + * loops thru each of the base paths in the $file_paths array and appends : "{classname} . {file type} . php" |
|
744 | + * then returns that path if the target file has been found and is readable |
|
745 | + * |
|
746 | + * @access protected |
|
747 | + * @param string $class_name |
|
748 | + * @param string $type |
|
749 | + * @param array $file_paths |
|
750 | + * @return string | bool |
|
751 | + */ |
|
752 | + protected function _resolve_path($class_name, $type = '', $file_paths = array()) |
|
753 | + { |
|
754 | + // make sure $file_paths is an array |
|
755 | + $file_paths = is_array($file_paths) ? $file_paths : array($file_paths); |
|
756 | + // cycle thru paths |
|
757 | + foreach ($file_paths as $key => $file_path) { |
|
758 | + // convert all separators to proper DS, if no filepath, then use EE_CLASSES |
|
759 | + $file_path = $file_path ? str_replace(array('/', '\\'), DS, $file_path) : EE_CLASSES; |
|
760 | + // prep file type |
|
761 | + $type = ! empty($type) ? trim($type, '.') . '.' : ''; |
|
762 | + // build full file path |
|
763 | + $file_paths[$key] = rtrim($file_path, DS) . DS . $class_name . '.' . $type . 'php'; |
|
764 | + //does the file exist and can be read ? |
|
765 | + if (is_readable($file_paths[$key])) { |
|
766 | + return $file_paths[$key]; |
|
767 | + } |
|
768 | + } |
|
769 | + return false; |
|
770 | + } |
|
771 | + |
|
772 | + |
|
773 | + |
|
774 | + /** |
|
775 | + * _require_file |
|
776 | + * basically just performs a require_once() |
|
777 | + * but with some error handling |
|
778 | + * |
|
779 | + * @access protected |
|
780 | + * @param string $path |
|
781 | + * @param string $class_name |
|
782 | + * @param string $type |
|
783 | + * @param array $file_paths |
|
784 | + * @return boolean |
|
785 | + * @throws \EE_Error |
|
786 | + */ |
|
787 | + protected function _require_file($path, $class_name, $type = '', $file_paths = array()) |
|
788 | + { |
|
789 | + // don't give up! you gotta... |
|
790 | + try { |
|
791 | + //does the file exist and can it be read ? |
|
792 | + if ( ! $path) { |
|
793 | + // so sorry, can't find the file |
|
794 | + throw new EE_Error ( |
|
795 | + sprintf( |
|
796 | + __('The %1$s file %2$s could not be located or is not readable due to file permissions. Please ensure that the following filepath(s) are correct: %3$s', 'event_espresso'), |
|
797 | + trim($type, '.'), |
|
798 | + $class_name, |
|
799 | + '<br />' . implode(',<br />', $file_paths) |
|
800 | + ) |
|
801 | + ); |
|
802 | + } |
|
803 | + // get the file |
|
804 | + require_once($path); |
|
805 | + // if the class isn't already declared somewhere |
|
806 | + if (class_exists($class_name, false) === false) { |
|
807 | + // so sorry, not a class |
|
808 | + throw new EE_Error( |
|
809 | + sprintf( |
|
810 | + __('The %s file %s does not appear to contain the %s Class.', 'event_espresso'), |
|
811 | + $type, |
|
812 | + $path, |
|
813 | + $class_name |
|
814 | + ) |
|
815 | + ); |
|
816 | + } |
|
817 | + } catch (EE_Error $e) { |
|
818 | + $e->get_error(); |
|
819 | + return false; |
|
820 | + } |
|
821 | + return true; |
|
822 | + } |
|
823 | + |
|
824 | + |
|
825 | + |
|
826 | + /** |
|
827 | + * _create_object |
|
828 | + * Attempts to instantiate the requested class via any of the |
|
829 | + * commonly used instantiation methods employed throughout EE. |
|
830 | + * The priority for instantiation is as follows: |
|
831 | + * - abstract classes or any class flagged as "load only" (no instantiation occurs) |
|
832 | + * - model objects via their 'new_instance_from_db' method |
|
833 | + * - model objects via their 'new_instance' method |
|
834 | + * - "singleton" classes" via their 'instance' method |
|
835 | + * - standard instantiable classes via their __constructor |
|
836 | + * Prior to instantiation, if the classname exists in the dependency_map, |
|
837 | + * then the constructor for the requested class will be examined to determine |
|
838 | + * if any dependencies exist, and if they can be injected. |
|
839 | + * If so, then those classes will be added to the array of arguments passed to the constructor |
|
840 | + * |
|
841 | + * @access protected |
|
842 | + * @param string $class_name |
|
843 | + * @param array $arguments |
|
844 | + * @param string $type |
|
845 | + * @param bool $from_db |
|
846 | + * @return null | object |
|
847 | + * @throws \EE_Error |
|
848 | + */ |
|
849 | + protected function _create_object($class_name, $arguments = array(), $type = '', $from_db = false) |
|
850 | + { |
|
851 | + $class_obj = null; |
|
852 | + $instantiation_mode = '0) none'; |
|
853 | + // don't give up! you gotta... |
|
854 | + try { |
|
855 | + // create reflection |
|
856 | + $reflector = $this->get_ReflectionClass($class_name); |
|
857 | + // make sure arguments are an array |
|
858 | + $arguments = is_array($arguments) ? $arguments : array($arguments); |
|
859 | + // and if arguments array is numerically and sequentially indexed, then we want it to remain as is, |
|
860 | + // else wrap it in an additional array so that it doesn't get split into multiple parameters |
|
861 | + $arguments = $this->_array_is_numerically_and_sequentially_indexed($arguments) |
|
862 | + ? $arguments |
|
863 | + : array($arguments); |
|
864 | + // attempt to inject dependencies ? |
|
865 | + if ($this->_dependency_map->has($class_name)) { |
|
866 | + $arguments = $this->_resolve_dependencies($reflector, $class_name, $arguments); |
|
867 | + } |
|
868 | + // instantiate the class if possible |
|
869 | + if ($reflector->isAbstract()) { |
|
870 | + // nothing to instantiate, loading file was enough |
|
871 | + // does not throw an exception so $instantiation_mode is unused |
|
872 | + // $instantiation_mode = "1) no constructor abstract class"; |
|
873 | + $class_obj = true; |
|
874 | + } else if ($reflector->getConstructor() === null && $reflector->isInstantiable() && empty($arguments)) { |
|
875 | + // no constructor = static methods only... nothing to instantiate, loading file was enough |
|
876 | + $instantiation_mode = "2) no constructor but instantiable"; |
|
877 | + $class_obj = $reflector->newInstance(); |
|
878 | + } else if ($from_db && method_exists($class_name, 'new_instance_from_db')) { |
|
879 | + $instantiation_mode = "3) new_instance_from_db()"; |
|
880 | + $class_obj = call_user_func_array(array($class_name, 'new_instance_from_db'), $arguments); |
|
881 | + } else if (method_exists($class_name, 'new_instance')) { |
|
882 | + $instantiation_mode = "4) new_instance()"; |
|
883 | + $class_obj = call_user_func_array(array($class_name, 'new_instance'), $arguments); |
|
884 | + } else if (method_exists($class_name, 'instance')) { |
|
885 | + $instantiation_mode = "5) instance()"; |
|
886 | + $class_obj = call_user_func_array(array($class_name, 'instance'), $arguments); |
|
887 | + } else if ($reflector->isInstantiable()) { |
|
888 | + $instantiation_mode = "6) constructor"; |
|
889 | + $class_obj = $reflector->newInstanceArgs($arguments); |
|
890 | + } else { |
|
891 | + // heh ? something's not right ! |
|
892 | + throw new EE_Error( |
|
893 | + sprintf( |
|
894 | + __('The %s file %s could not be instantiated.', 'event_espresso'), |
|
895 | + $type, |
|
896 | + $class_name |
|
897 | + ) |
|
898 | + ); |
|
899 | + } |
|
900 | + } catch (Exception $e) { |
|
901 | + if ( ! $e instanceof EE_Error) { |
|
902 | + $e = new EE_Error( |
|
903 | + sprintf( |
|
904 | + __('The following error occurred while attempting to instantiate "%1$s": %2$s %3$s %2$s instantiation mode : %4$s', 'event_espresso'), |
|
905 | + $class_name, |
|
906 | + '<br />', |
|
907 | + $e->getMessage(), |
|
908 | + $instantiation_mode |
|
909 | + ) |
|
910 | + ); |
|
911 | + } |
|
912 | + $e->get_error(); |
|
913 | + } |
|
914 | + return $class_obj; |
|
915 | + } |
|
916 | + |
|
917 | + |
|
918 | + |
|
919 | + /** |
|
920 | + * @see http://stackoverflow.com/questions/173400/how-to-check-if-php-array-is-associative-or-sequential |
|
921 | + * @param array $array |
|
922 | + * @return bool |
|
923 | + */ |
|
924 | + protected function _array_is_numerically_and_sequentially_indexed(array $array) |
|
925 | + { |
|
926 | + return ! empty($array) ? array_keys($array) === range(0, count($array) - 1) : true; |
|
927 | + } |
|
928 | + |
|
929 | + |
|
930 | + |
|
931 | + /** |
|
932 | + * getReflectionClass |
|
933 | + * checks if a ReflectionClass object has already been generated for a class |
|
934 | + * and returns that instead of creating a new one |
|
935 | + * |
|
936 | + * @access public |
|
937 | + * @param string $class_name |
|
938 | + * @return ReflectionClass |
|
939 | + */ |
|
940 | + public function get_ReflectionClass($class_name) |
|
941 | + { |
|
942 | + if ( |
|
943 | + ! isset($this->_reflectors[$class_name]) |
|
944 | + || ! $this->_reflectors[$class_name] instanceof ReflectionClass |
|
945 | + ) { |
|
946 | + $this->_reflectors[$class_name] = new ReflectionClass($class_name); |
|
947 | + } |
|
948 | + return $this->_reflectors[$class_name]; |
|
949 | + } |
|
950 | + |
|
951 | + |
|
952 | + |
|
953 | + /** |
|
954 | + * _resolve_dependencies |
|
955 | + * examines the constructor for the requested class to determine |
|
956 | + * if any dependencies exist, and if they can be injected. |
|
957 | + * If so, then those classes will be added to the array of arguments passed to the constructor |
|
958 | + * PLZ NOTE: this is achieved by type hinting the constructor params |
|
959 | + * For example: |
|
960 | + * if attempting to load a class "Foo" with the following constructor: |
|
961 | + * __construct( Bar $bar_class, Fighter $grohl_class ) |
|
962 | + * then $bar_class and $grohl_class will be added to the $arguments array, |
|
963 | + * but only IF they are NOT already present in the incoming arguments array, |
|
964 | + * and the correct classes can be loaded |
|
965 | + * |
|
966 | + * @access protected |
|
967 | + * @param ReflectionClass $reflector |
|
968 | + * @param string $class_name |
|
969 | + * @param array $arguments |
|
970 | + * @return array |
|
971 | + * @throws \ReflectionException |
|
972 | + */ |
|
973 | + protected function _resolve_dependencies(ReflectionClass $reflector, $class_name, $arguments = array()) |
|
974 | + { |
|
975 | + // let's examine the constructor |
|
976 | + $constructor = $reflector->getConstructor(); |
|
977 | + // whu? huh? nothing? |
|
978 | + if ( ! $constructor) { |
|
979 | + return $arguments; |
|
980 | + } |
|
981 | + // get constructor parameters |
|
982 | + $params = $constructor->getParameters(); |
|
983 | + // and the keys for the incoming arguments array so that we can compare existing arguments with what is expected |
|
984 | + $argument_keys = array_keys($arguments); |
|
985 | + // now loop thru all of the constructors expected parameters |
|
986 | + foreach ($params as $index => $param) { |
|
987 | + // is this a dependency for a specific class ? |
|
988 | + $param_class = $param->getClass() ? $param->getClass()->name : null; |
|
989 | + if ( |
|
990 | + // param is not even a class |
|
991 | + empty($param_class) |
|
992 | + // and something already exists in the incoming arguments for this param |
|
993 | + && isset($argument_keys[$index], $arguments[$argument_keys[$index]]) |
|
994 | + ) { |
|
995 | + // so let's skip this argument and move on to the next |
|
996 | + continue; |
|
997 | + } else if ( |
|
998 | + // parameter is type hinted as a class, exists as an incoming argument, AND it's the correct class |
|
999 | + ! empty($param_class) |
|
1000 | + && isset($argument_keys[$index], $arguments[$argument_keys[$index]]) |
|
1001 | + && $arguments[$argument_keys[$index]] instanceof $param_class |
|
1002 | + ) { |
|
1003 | + // skip this argument and move on to the next |
|
1004 | + continue; |
|
1005 | + } else if ( |
|
1006 | + // parameter is type hinted as a class, and should be injected |
|
1007 | + ! empty($param_class) |
|
1008 | + && $this->_dependency_map->has_dependency_for_class($class_name, $param_class) |
|
1009 | + ) { |
|
1010 | + $arguments = $this->_resolve_dependency($class_name, $param_class, $arguments, $index); |
|
1011 | + } else { |
|
1012 | + try { |
|
1013 | + $arguments[$index] = $param->getDefaultValue(); |
|
1014 | + } catch (ReflectionException $e) { |
|
1015 | + throw new ReflectionException( |
|
1016 | + sprintf( |
|
1017 | + __('%1$s for parameter "$%2$s"', 'event_espresso'), |
|
1018 | + $e->getMessage(), |
|
1019 | + $param->getName() |
|
1020 | + ) |
|
1021 | + ); |
|
1022 | + } |
|
1023 | + } |
|
1024 | + } |
|
1025 | + return $arguments; |
|
1026 | + } |
|
1027 | + |
|
1028 | + |
|
1029 | + |
|
1030 | + /** |
|
1031 | + * @access protected |
|
1032 | + * @param string $class_name |
|
1033 | + * @param string $param_class |
|
1034 | + * @param array $arguments |
|
1035 | + * @param mixed $index |
|
1036 | + * @return array |
|
1037 | + */ |
|
1038 | + protected function _resolve_dependency($class_name, $param_class, $arguments, $index) |
|
1039 | + { |
|
1040 | + $dependency = null; |
|
1041 | + // should dependency be loaded from cache ? |
|
1042 | + $cache_on = $this->_dependency_map->loading_strategy_for_class_dependency($class_name, $param_class) |
|
1043 | + !== EE_Dependency_Map::load_new_object |
|
1044 | + ? true |
|
1045 | + : false; |
|
1046 | + // we might have a dependency... |
|
1047 | + // let's MAYBE try and find it in our cache if that's what's been requested |
|
1048 | + $cached_class = $cache_on ? $this->_get_cached_class($param_class) : null; |
|
1049 | + // and grab it if it exists |
|
1050 | + if ($cached_class instanceof $param_class) { |
|
1051 | + $dependency = $cached_class; |
|
1052 | + } else if ($param_class != $class_name) { |
|
1053 | + // obtain the loader method from the dependency map |
|
1054 | + $loader = $this->_dependency_map->class_loader($param_class); |
|
1055 | + // is loader a custom closure ? |
|
1056 | + if ($loader instanceof Closure) { |
|
1057 | + $dependency = $loader(); |
|
1058 | + } else { |
|
1059 | + // set the cache on property for the recursive loading call |
|
1060 | + $this->_cache_on = $cache_on; |
|
1061 | + // if not, then let's try and load it via the registry |
|
1062 | + if (method_exists($this, $loader)) { |
|
1063 | + $dependency = $this->{$loader}($param_class); |
|
1064 | + } else { |
|
1065 | + $dependency = $this->create($param_class, array(), $cache_on); |
|
1066 | + } |
|
1067 | + } |
|
1068 | + } |
|
1069 | + // did we successfully find the correct dependency ? |
|
1070 | + if ($dependency instanceof $param_class) { |
|
1071 | + // then let's inject it into the incoming array of arguments at the correct location |
|
1072 | + if (isset($argument_keys[$index])) { |
|
1073 | + $arguments[$argument_keys[$index]] = $dependency; |
|
1074 | + } else { |
|
1075 | + $arguments[$index] = $dependency; |
|
1076 | + } |
|
1077 | + } |
|
1078 | + return $arguments; |
|
1079 | + } |
|
1080 | + |
|
1081 | + |
|
1082 | + |
|
1083 | + /** |
|
1084 | + * _set_cached_class |
|
1085 | + * attempts to cache the instantiated class locally |
|
1086 | + * in one of the following places, in the following order: |
|
1087 | + * $this->{class_abbreviation} ie: $this->CART |
|
1088 | + * $this->{$class_name} ie: $this->Some_Class |
|
1089 | + * $this->addon->{$$class_name} ie: $this->addon->Some_Addon_Class |
|
1090 | + * $this->LIB->{$class_name} ie: $this->LIB->Some_Class |
|
1091 | + * |
|
1092 | + * @access protected |
|
1093 | + * @param object $class_obj |
|
1094 | + * @param string $class_name |
|
1095 | + * @param string $class_prefix |
|
1096 | + * @param bool $from_db |
|
1097 | + * @return void |
|
1098 | + */ |
|
1099 | + protected function _set_cached_class($class_obj, $class_name, $class_prefix = '', $from_db = false) |
|
1100 | + { |
|
1101 | + if (empty($class_obj)) { |
|
1102 | + return; |
|
1103 | + } |
|
1104 | + // return newly instantiated class |
|
1105 | + if (isset($this->_class_abbreviations[$class_name])) { |
|
1106 | + $class_abbreviation = $this->_class_abbreviations[$class_name]; |
|
1107 | + $this->{$class_abbreviation} = $class_obj; |
|
1108 | + } else if (property_exists($this, $class_name)) { |
|
1109 | + $this->{$class_name} = $class_obj; |
|
1110 | + } else if ($class_prefix == 'addon') { |
|
1111 | + $this->addons->{$class_name} = $class_obj; |
|
1112 | + } else if ( ! $from_db) { |
|
1113 | + $this->LIB->{$class_name} = $class_obj; |
|
1114 | + } |
|
1115 | + } |
|
1116 | + |
|
1117 | + |
|
1118 | + |
|
1119 | + /** |
|
1120 | + * call any loader that's been registered in the EE_Dependency_Map::$_class_loaders array |
|
1121 | + * |
|
1122 | + * @param string $classname PLEASE NOTE: the class name needs to match what's registered |
|
1123 | + * in the EE_Dependency_Map::$_class_loaders array, |
|
1124 | + * including the class prefix, ie: "EE_", "EEM_", "EEH_", etc |
|
1125 | + * @param array $arguments |
|
1126 | + * @return object |
|
1127 | + */ |
|
1128 | + public static function factory($classname, $arguments = array()) |
|
1129 | + { |
|
1130 | + $loader = self::instance()->_dependency_map->class_loader($classname); |
|
1131 | + if ($loader instanceof Closure) { |
|
1132 | + return $loader($arguments); |
|
1133 | + } else if (method_exists(EE_Registry::instance(), $loader)) { |
|
1134 | + return EE_Registry::instance()->{$loader}($classname, $arguments); |
|
1135 | + } |
|
1136 | + return null; |
|
1137 | + } |
|
1138 | + |
|
1139 | + |
|
1140 | + |
|
1141 | + /** |
|
1142 | + * Gets the addon by its name/slug (not classname. For that, just |
|
1143 | + * use the classname as the property name on EE_Config::instance()->addons) |
|
1144 | + * |
|
1145 | + * @param string $name |
|
1146 | + * @return EE_Addon |
|
1147 | + */ |
|
1148 | + public function get_addon_by_name($name) |
|
1149 | + { |
|
1150 | + foreach ($this->addons as $addon) { |
|
1151 | + if ($addon->name() == $name) { |
|
1152 | + return $addon; |
|
1153 | + } |
|
1154 | + } |
|
1155 | + return null; |
|
1156 | + } |
|
1157 | + |
|
1158 | + |
|
1159 | + |
|
1160 | + /** |
|
1161 | + * Gets an array of all the registered addons, where the keys are their names. (ie, what each returns for their name() function) They're already available on EE_Config::instance()->addons as properties, where each property's name is |
|
1162 | + * the addon's classname. So if you just want to get the addon by classname, use EE_Config::instance()->addons->{classname} |
|
1163 | + * |
|
1164 | + * @return EE_Addon[] where the KEYS are the addon's name() |
|
1165 | + */ |
|
1166 | + public function get_addons_by_name() |
|
1167 | + { |
|
1168 | + $addons = array(); |
|
1169 | + foreach ($this->addons as $addon) { |
|
1170 | + $addons[$addon->name()] = $addon; |
|
1171 | + } |
|
1172 | + return $addons; |
|
1173 | + } |
|
1174 | + |
|
1175 | + |
|
1176 | + |
|
1177 | + /** |
|
1178 | + * Resets the specified model's instance AND makes sure EE_Registry doesn't keep |
|
1179 | + * a stale copy of it around |
|
1180 | + * |
|
1181 | + * @param string $model_name |
|
1182 | + * @return \EEM_Base |
|
1183 | + * @throws \EE_Error |
|
1184 | + */ |
|
1185 | + public function reset_model($model_name) |
|
1186 | + { |
|
1187 | + $model_class_name = strpos($model_name, 'EEM_') !== 0 ? "EEM_{$model_name}" : $model_name; |
|
1188 | + if ( ! isset($this->LIB->{$model_class_name}) || ! $this->LIB->{$model_class_name} instanceof EEM_Base) { |
|
1189 | + return null; |
|
1190 | + } |
|
1191 | + //get that model reset it and make sure we nuke the old reference to it |
|
1192 | + if ($this->LIB->{$model_class_name} instanceof $model_class_name && is_callable(array($model_class_name, 'reset'))) { |
|
1193 | + $this->LIB->{$model_class_name} = $this->LIB->{$model_class_name}->reset(); |
|
1194 | + } else { |
|
1195 | + throw new EE_Error(sprintf(__('Model %s does not have a method "reset"', 'event_espresso'), $model_name)); |
|
1196 | + } |
|
1197 | + return $this->LIB->{$model_class_name}; |
|
1198 | + } |
|
1199 | + |
|
1200 | + |
|
1201 | + |
|
1202 | + /** |
|
1203 | + * Resets the registry. |
|
1204 | + * The criteria for what gets reset is based on what can be shared between sites on the same request when switch_to_blog |
|
1205 | + * is used in a multisite install. Here is a list of things that are NOT reset. |
|
1206 | + * - $_dependency_map |
|
1207 | + * - $_class_abbreviations |
|
1208 | + * - $NET_CFG (EE_Network_Config): The config is shared network wide so no need to reset. |
|
1209 | + * - $REQ: Still on the same request so no need to change. |
|
1210 | + * - $CAP: There is no site specific state in the EE_Capability class. |
|
1211 | + * - $SSN: Although ideally, the session should not be shared between site switches, we can't reset it because only one Session |
|
1212 | + * can be active in a single request. Resetting could resolve in "headers already sent" errors. |
|
1213 | + * - $addons: In multisite, the state of the addons is something controlled via hooks etc in a normal request. So |
|
1214 | + * for now, we won't reset the addons because it could break calls to an add-ons class/methods in the |
|
1215 | + * switch or on the restore. |
|
1216 | + * - $modules |
|
1217 | + * - $shortcodes |
|
1218 | + * - $widgets |
|
1219 | + * |
|
1220 | + * @param boolean $hard whether to reset data in the database too, or just refresh |
|
1221 | + * the Registry to its state at the beginning of the request |
|
1222 | + * @param boolean $reinstantiate whether to create new instances of EE_Registry's singletons too, |
|
1223 | + * or just reset without re-instantiating (handy to set to FALSE if you're not sure if you CAN |
|
1224 | + * currently reinstantiate the singletons at the moment) |
|
1225 | + * @param bool $reset_models Defaults to true. When false, then the models are not reset. This is so client |
|
1226 | + * code instead can just change the model context to a different blog id if necessary |
|
1227 | + * @return EE_Registry |
|
1228 | + */ |
|
1229 | + public static function reset($hard = false, $reinstantiate = true, $reset_models = true) |
|
1230 | + { |
|
1231 | + $instance = self::instance(); |
|
1232 | + EEH_Activation::reset(); |
|
1233 | + //properties that get reset |
|
1234 | + $instance->_cache_on = true; |
|
1235 | + $instance->CFG = EE_Config::reset($hard, $reinstantiate); |
|
1236 | + $instance->CART = null; |
|
1237 | + $instance->MRM = null; |
|
1238 | + $instance->AssetsRegistry = new Registry(); |
|
1239 | + //messages reset |
|
1240 | + EED_Messages::reset(); |
|
1241 | + if ($reset_models) { |
|
1242 | + foreach (array_keys($instance->non_abstract_db_models) as $model_name) { |
|
1243 | + $instance->reset_model($model_name); |
|
1244 | + } |
|
1245 | + } |
|
1246 | + $instance->LIB = new stdClass(); |
|
1247 | + return $instance; |
|
1248 | + } |
|
1249 | + |
|
1250 | + |
|
1251 | + |
|
1252 | + /** |
|
1253 | + * @override magic methods |
|
1254 | + * @return void |
|
1255 | + */ |
|
1256 | + final function __destruct() |
|
1257 | + { |
|
1258 | + } |
|
1259 | + |
|
1260 | + |
|
1261 | + |
|
1262 | + /** |
|
1263 | + * @param $a |
|
1264 | + * @param $b |
|
1265 | + */ |
|
1266 | + final function __call($a, $b) |
|
1267 | + { |
|
1268 | + } |
|
1269 | + |
|
1270 | + |
|
1271 | + |
|
1272 | + /** |
|
1273 | + * @param $a |
|
1274 | + */ |
|
1275 | + final function __get($a) |
|
1276 | + { |
|
1277 | + } |
|
1278 | + |
|
1279 | + |
|
1280 | + |
|
1281 | + /** |
|
1282 | + * @param $a |
|
1283 | + * @param $b |
|
1284 | + */ |
|
1285 | + final function __set($a, $b) |
|
1286 | + { |
|
1287 | + } |
|
1288 | + |
|
1289 | + |
|
1290 | + |
|
1291 | + /** |
|
1292 | + * @param $a |
|
1293 | + */ |
|
1294 | + final function __isset($a) |
|
1295 | + { |
|
1296 | + } |
|
1297 | 1297 | |
1298 | 1298 | |
1299 | 1299 | |
1300 | - /** |
|
1301 | - * @param $a |
|
1302 | - */ |
|
1303 | - final function __unset($a) |
|
1304 | - { |
|
1305 | - } |
|
1300 | + /** |
|
1301 | + * @param $a |
|
1302 | + */ |
|
1303 | + final function __unset($a) |
|
1304 | + { |
|
1305 | + } |
|
1306 | 1306 | |
1307 | 1307 | |
1308 | 1308 | |
1309 | - /** |
|
1310 | - * @return array |
|
1311 | - */ |
|
1312 | - final function __sleep() |
|
1313 | - { |
|
1314 | - return array(); |
|
1315 | - } |
|
1309 | + /** |
|
1310 | + * @return array |
|
1311 | + */ |
|
1312 | + final function __sleep() |
|
1313 | + { |
|
1314 | + return array(); |
|
1315 | + } |
|
1316 | 1316 | |
1317 | 1317 | |
1318 | 1318 | |
1319 | - final function __wakeup() |
|
1320 | - { |
|
1321 | - } |
|
1319 | + final function __wakeup() |
|
1320 | + { |
|
1321 | + } |
|
1322 | 1322 | |
1323 | 1323 | |
1324 | 1324 | |
1325 | - /** |
|
1326 | - * @return string |
|
1327 | - */ |
|
1328 | - final function __toString() |
|
1329 | - { |
|
1330 | - return ''; |
|
1331 | - } |
|
1325 | + /** |
|
1326 | + * @return string |
|
1327 | + */ |
|
1328 | + final function __toString() |
|
1329 | + { |
|
1330 | + return ''; |
|
1331 | + } |
|
1332 | 1332 | |
1333 | 1333 | |
1334 | 1334 | |
1335 | - final function __invoke() |
|
1336 | - { |
|
1337 | - } |
|
1335 | + final function __invoke() |
|
1336 | + { |
|
1337 | + } |
|
1338 | 1338 | |
1339 | 1339 | |
1340 | 1340 | |
1341 | - final static function __set_state() |
|
1342 | - { |
|
1343 | - } |
|
1341 | + final static function __set_state() |
|
1342 | + { |
|
1343 | + } |
|
1344 | 1344 | |
1345 | 1345 | |
1346 | 1346 | |
1347 | - final function __clone() |
|
1348 | - { |
|
1349 | - } |
|
1347 | + final function __clone() |
|
1348 | + { |
|
1349 | + } |
|
1350 | 1350 | |
1351 | 1351 | |
1352 | 1352 | |
1353 | - /** |
|
1354 | - * @param $a |
|
1355 | - * @param $b |
|
1356 | - */ |
|
1357 | - final static function __callStatic($a, $b) |
|
1358 | - { |
|
1359 | - } |
|
1353 | + /** |
|
1354 | + * @param $a |
|
1355 | + * @param $b |
|
1356 | + */ |
|
1357 | + final static function __callStatic($a, $b) |
|
1358 | + { |
|
1359 | + } |
|
1360 | 1360 | |
1361 | 1361 | |
1362 | 1362 | |
1363 | - /** |
|
1364 | - * Gets all the custom post type models defined |
|
1365 | - * |
|
1366 | - * @return array keys are model "short names" (Eg "Event") and keys are classnames (eg "EEM_Event") |
|
1367 | - */ |
|
1368 | - public function cpt_models() |
|
1369 | - { |
|
1370 | - $cpt_models = array(); |
|
1371 | - foreach ($this->non_abstract_db_models() as $short_name => $classname) { |
|
1372 | - if (is_subclass_of($classname, 'EEM_CPT_Base')) { |
|
1373 | - $cpt_models[$short_name] = $classname; |
|
1374 | - } |
|
1375 | - } |
|
1376 | - return $cpt_models; |
|
1377 | - } |
|
1363 | + /** |
|
1364 | + * Gets all the custom post type models defined |
|
1365 | + * |
|
1366 | + * @return array keys are model "short names" (Eg "Event") and keys are classnames (eg "EEM_Event") |
|
1367 | + */ |
|
1368 | + public function cpt_models() |
|
1369 | + { |
|
1370 | + $cpt_models = array(); |
|
1371 | + foreach ($this->non_abstract_db_models() as $short_name => $classname) { |
|
1372 | + if (is_subclass_of($classname, 'EEM_CPT_Base')) { |
|
1373 | + $cpt_models[$short_name] = $classname; |
|
1374 | + } |
|
1375 | + } |
|
1376 | + return $cpt_models; |
|
1377 | + } |
|
1378 | 1378 | |
1379 | 1379 | |
1380 | 1380 | |
1381 | - /** |
|
1382 | - * Gets all the non-abstract database model names. If we haven't yet discovered what they are, does that |
|
1383 | - * @return array keys are model names (eg "Event") and values are their classnames (eg "EEM_Event") |
|
1384 | - */ |
|
1385 | - public function non_abstract_db_models() |
|
1386 | - { |
|
1387 | - $this->_verify_models_discovered(); |
|
1388 | - return $this->non_abstract_db_models; |
|
1389 | - } |
|
1381 | + /** |
|
1382 | + * Gets all the non-abstract database model names. If we haven't yet discovered what they are, does that |
|
1383 | + * @return array keys are model names (eg "Event") and values are their classnames (eg "EEM_Event") |
|
1384 | + */ |
|
1385 | + public function non_abstract_db_models() |
|
1386 | + { |
|
1387 | + $this->_verify_models_discovered(); |
|
1388 | + return $this->non_abstract_db_models; |
|
1389 | + } |
|
1390 | 1390 | |
1391 | 1391 | |
1392 | 1392 | |
1393 | - /** |
|
1394 | - * Gets the names of all the "models", including abstract and "non-database" models. |
|
1395 | - * Mainly all the classes from core/db_models. |
|
1396 | - * You may want to use EE_Registry::non_abstract_db_models instead |
|
1397 | - * @return array keys are model names (eg "Event") and values are their classnames (eg "EEM_Event") |
|
1398 | - */ |
|
1399 | - public function models() |
|
1400 | - { |
|
1401 | - $this->_verify_models_discovered(); |
|
1402 | - return $this->models; |
|
1403 | - } |
|
1393 | + /** |
|
1394 | + * Gets the names of all the "models", including abstract and "non-database" models. |
|
1395 | + * Mainly all the classes from core/db_models. |
|
1396 | + * You may want to use EE_Registry::non_abstract_db_models instead |
|
1397 | + * @return array keys are model names (eg "Event") and values are their classnames (eg "EEM_Event") |
|
1398 | + */ |
|
1399 | + public function models() |
|
1400 | + { |
|
1401 | + $this->_verify_models_discovered(); |
|
1402 | + return $this->models; |
|
1403 | + } |
|
1404 | 1404 | |
1405 | 1405 | |
1406 | 1406 | |
1407 | - /** |
|
1408 | - * Discovers all the models in core/db_models and remembers them on properties |
|
1409 | - * models and non_abstract_db_models |
|
1410 | - * @return void |
|
1411 | - */ |
|
1412 | - private function _verify_models_discovered() |
|
1413 | - { |
|
1414 | - if( ! $this->non_abstract_db_models |
|
1415 | - || ! $this->models){ |
|
1416 | - //get all the files in the EE_MODELS folder that end in .model.php |
|
1417 | - $models = glob(EE_MODELS . '*.model.php'); |
|
1418 | - $model_names = array(); |
|
1419 | - $non_abstract_db_models = array(); |
|
1420 | - foreach ($models as $model) { |
|
1421 | - // get model classname |
|
1422 | - $classname = EEH_File::get_classname_from_filepath_with_standard_filename($model); |
|
1423 | - $short_name = str_replace('EEM_', '', $classname); |
|
1424 | - $reflectionClass = $this->get_ReflectionClass($classname); |
|
1425 | - if ($reflectionClass->isSubclassOf('EEM_Base') && ! $reflectionClass->isAbstract()) { |
|
1426 | - $non_abstract_db_models[$short_name] = $classname; |
|
1427 | - } |
|
1428 | - $model_names[$short_name] = $classname; |
|
1429 | - } |
|
1430 | - //continue using legacy filter names (originally this logic was contained elsewhere) |
|
1431 | - $this->models = apply_filters('FHEE__EE_System__parse_model_names', $model_names); |
|
1432 | - $this->non_abstract_db_models = apply_filters('FHEE__EE_System__parse_implemented_model_names', |
|
1433 | - $non_abstract_db_models); |
|
1434 | - } |
|
1435 | - } |
|
1436 | - |
|
1437 | - |
|
1438 | - |
|
1439 | - /** |
|
1440 | - * @return \EE_Config |
|
1441 | - */ |
|
1442 | - public static function CFG() |
|
1443 | - { |
|
1444 | - return self::instance()->CFG; |
|
1445 | - } |
|
1407 | + /** |
|
1408 | + * Discovers all the models in core/db_models and remembers them on properties |
|
1409 | + * models and non_abstract_db_models |
|
1410 | + * @return void |
|
1411 | + */ |
|
1412 | + private function _verify_models_discovered() |
|
1413 | + { |
|
1414 | + if( ! $this->non_abstract_db_models |
|
1415 | + || ! $this->models){ |
|
1416 | + //get all the files in the EE_MODELS folder that end in .model.php |
|
1417 | + $models = glob(EE_MODELS . '*.model.php'); |
|
1418 | + $model_names = array(); |
|
1419 | + $non_abstract_db_models = array(); |
|
1420 | + foreach ($models as $model) { |
|
1421 | + // get model classname |
|
1422 | + $classname = EEH_File::get_classname_from_filepath_with_standard_filename($model); |
|
1423 | + $short_name = str_replace('EEM_', '', $classname); |
|
1424 | + $reflectionClass = $this->get_ReflectionClass($classname); |
|
1425 | + if ($reflectionClass->isSubclassOf('EEM_Base') && ! $reflectionClass->isAbstract()) { |
|
1426 | + $non_abstract_db_models[$short_name] = $classname; |
|
1427 | + } |
|
1428 | + $model_names[$short_name] = $classname; |
|
1429 | + } |
|
1430 | + //continue using legacy filter names (originally this logic was contained elsewhere) |
|
1431 | + $this->models = apply_filters('FHEE__EE_System__parse_model_names', $model_names); |
|
1432 | + $this->non_abstract_db_models = apply_filters('FHEE__EE_System__parse_implemented_model_names', |
|
1433 | + $non_abstract_db_models); |
|
1434 | + } |
|
1435 | + } |
|
1436 | + |
|
1437 | + |
|
1438 | + |
|
1439 | + /** |
|
1440 | + * @return \EE_Config |
|
1441 | + */ |
|
1442 | + public static function CFG() |
|
1443 | + { |
|
1444 | + return self::instance()->CFG; |
|
1445 | + } |
|
1446 | 1446 | |
1447 | 1447 | |
1448 | 1448 | } |