start.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <?php
  2. /**
  3. * Bootstraps the Elgg engine.
  4. *
  5. * This file loads the full Elgg engine, checks the installation
  6. * state, and triggers a series of events to finish booting Elgg:
  7. * - {@elgg_event boot system}
  8. * - {@elgg_event init system}
  9. * - {@elgg_event ready system}
  10. *
  11. * If Elgg is fully uninstalled, the browser will be redirected to an
  12. * installation page.
  13. *
  14. * @see install.php
  15. * @package Elgg.Core
  16. * @subpackage Core
  17. */
  18. /**
  19. * The time with microseconds when the Elgg engine was started.
  20. *
  21. * @global float
  22. */
  23. global $START_MICROTIME;
  24. $START_MICROTIME = microtime(true);
  25. // we need to register for shutdown before Symfony registers the session_write_close() function
  26. // https://github.com/Elgg/Elgg/issues/9243
  27. register_shutdown_function(function () {
  28. // There are cases where we may exit before this function is defined.
  29. // TODO move this to Application::create in 2.0
  30. if (function_exists('_elgg_shutdown_hook')) {
  31. _elgg_shutdown_hook();
  32. }
  33. });
  34. /**
  35. * Configuration values.
  36. *
  37. * The $CONFIG global contains configuration values required
  38. * for running Elgg as defined in the settings.php file.
  39. *
  40. * Plugin authors are encouraged to use elgg_get_config() instead of accessing
  41. * the global directly.
  42. *
  43. * @see elgg_get_config()
  44. * @see engine/settings.php
  45. * @global \stdClass $CONFIG
  46. */
  47. global $CONFIG;
  48. if (!isset($CONFIG)) {
  49. $CONFIG = new \stdClass;
  50. }
  51. $CONFIG->boot_complete = false;
  52. $engine_dir = dirname(__FILE__);
  53. // No settings means a fresh install
  54. if (!is_file("$engine_dir/settings.php")) {
  55. header("Location: install.php");
  56. exit;
  57. }
  58. if (!is_readable("$engine_dir/settings.php")) {
  59. echo "The Elgg settings file exists but the web server doesn't have read permission to it.";
  60. exit;
  61. }
  62. require_once "$engine_dir/settings.php";
  63. // This will be overridden by the DB value but may be needed before the upgrade script can be run.
  64. $CONFIG->default_limit = 10;
  65. require_once "$engine_dir/load.php";
  66. // Connect to database, load language files, load configuration, init session
  67. // Plugins can't use this event because they haven't been loaded yet.
  68. elgg_trigger_event('boot', 'system');
  69. // Load the plugins that are active
  70. _elgg_load_plugins();
  71. // @todo move loading plugins into a single boot function that replaces 'boot', 'system' event
  72. // and then move this code in there.
  73. // This validates the view type - first opportunity to do it is after plugins load.
  74. $viewtype = elgg_get_viewtype();
  75. if (!elgg_is_registered_viewtype($viewtype)) {
  76. elgg_set_viewtype('default');
  77. }
  78. // @todo deprecate as plugins can use 'init', 'system' event
  79. elgg_trigger_event('plugins_boot', 'system');
  80. // Complete the boot process for both engine and plugins
  81. elgg_trigger_event('init', 'system');
  82. $CONFIG->boot_complete = true;
  83. // System loaded and ready
  84. elgg_trigger_event('ready', 'system');