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