PageRenderTime 45ms CodeModel.GetById 20ms RepoModel.GetById 1ms app.codeStats 0ms

/engine/start.php

https://github.com/masuman/elgg-1
PHP | 219 lines | 115 code | 49 blank | 55 comment | 40 complexity | 65145a485a8504125a7328df03b5e3fd MD5 | raw file
  1. <?php
  2. /**
  3. * Elgg engine bootstrapper
  4. * Loads the various elements of the Elgg engine
  5. *
  6. * @package Elgg
  7. * @subpackage Core
  8. * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html GNU Public License version 2
  9. * @author Curverider Ltd
  10. * @copyright Curverider Ltd 2008-2009
  11. * @link http://elgg.org/
  12. */
  13. /*
  14. * Basic profiling
  15. */
  16. global $START_MICROTIME;
  17. $START_MICROTIME = microtime(true);
  18. /**
  19. * Load important prerequisites
  20. */
  21. if (!include_once(dirname(__FILE__) . "/lib/exceptions.php")) { // Exceptions
  22. echo "Error in installation: could not load the Exceptions library.";
  23. exit;
  24. }
  25. if (!include_once(dirname(__FILE__) . "/lib/elgglib.php")) { // Main Elgg library
  26. echo "Elgg could not load its main library.";
  27. exit;
  28. }
  29. if (!include_once(dirname(__FILE__) . "/lib/access.php")) { // Access library
  30. echo "Error in installation: could not load the Access library.";
  31. exit;
  32. }
  33. if (!include_once(dirname(__FILE__) . "/lib/system_log.php")) { // Logging library
  34. echo "Error in installation: could not load the System Log library.";
  35. exit;
  36. }
  37. if (!include_once(dirname(__FILE__) . "/lib/export.php")) { // Export library
  38. echo "Error in installation: could not load the Export library.";
  39. exit;
  40. }
  41. if (!include_once(dirname(__FILE__) . "/lib/sessions.php")) {
  42. echo ("Error in installation: Elgg could not load the Sessions library");
  43. exit;
  44. }
  45. if (!include_once(dirname(__FILE__) . "/lib/languages.php")) { // Languages library
  46. echo "Error in installation: could not load the languages library.";
  47. exit;
  48. }
  49. if (!include_once(dirname(__FILE__) . "/lib/input.php")) { // Input library
  50. echo "Error in installation: could not load the input library.";
  51. exit;
  52. }
  53. if (!include_once(dirname(__FILE__) . "/lib/install.php")) { // Installation library
  54. echo "Error in installation: could not load the installation library.";
  55. exit;
  56. }
  57. if (!include_once(dirname(__FILE__) . "/lib/cache.php")) { // Installation library
  58. echo "Error in installation: could not load the cache library.";
  59. exit;
  60. }
  61. // Use fallback view until sanitised
  62. $oldview = get_input('view');
  63. set_input('view', 'failsafe');
  64. /**
  65. * Set light mode default
  66. */
  67. $lightmode = false;
  68. /**
  69. * Establish handlers
  70. */
  71. // Register the error handler
  72. set_error_handler('__elgg_php_error_handler');
  73. set_exception_handler('__elgg_php_exception_handler');
  74. /**
  75. * If there are basic issues with the way the installation is formed, don't bother trying
  76. * to load any more files
  77. */
  78. if ($sanitised = sanitised()) { // Begin portion for sanitised installs only
  79. /**
  80. * Load the system settings
  81. */
  82. if (!include_once(dirname(__FILE__) . "/settings.php")) // Global settings
  83. throw new InstallationException("Elgg could not load the settings file.");
  84. /**
  85. * Load and initialise the database
  86. */
  87. if (!include_once(dirname(__FILE__) . "/lib/database.php")) // Database connection
  88. throw new InstallationException("Elgg could not load the main Elgg database library.");
  89. /**
  90. * Load the remaining libraries from /lib/ in alphabetical order,
  91. * except for a few exceptions
  92. */
  93. if (!include_once(dirname(__FILE__) . "/lib/actions.php")) {
  94. throw new InstallationException("Elgg could not load the Actions library");
  95. }
  96. // We don't want to load or reload these files
  97. $file_exceptions = array(
  98. '.','..',
  99. '.DS_Store',
  100. 'Thumbs.db',
  101. '.svn',
  102. 'CVS','cvs',
  103. 'settings.php','settings.example.php','languages.php','exceptions.php','elgglib.php','access.php','database.php','actions.php','sessions.php'
  104. );
  105. // Get the list of files to include, and alphabetically sort them
  106. $files = get_library_files(dirname(__FILE__) . "/lib",$file_exceptions);
  107. asort($files);
  108. // Get config
  109. global $CONFIG;
  110. // Include them
  111. foreach($files as $file) {
  112. if (isset($CONFIG->debug) && $CONFIG->debug) error_log("Loading $file...");
  113. if (!include_once($file))
  114. throw new InstallationException("Could not load {$file}");
  115. }
  116. } else { // End portion for sanitised installs only
  117. throw new InstallationException(elgg_echo('installation:error:configuration'));
  118. }
  119. // Autodetect some default configuration settings
  120. set_default_config();
  121. // Trigger events
  122. trigger_elgg_event('boot', 'system');
  123. // Load plugins
  124. $installed = is_installed();
  125. $db_installed = is_db_installed();
  126. // Determine light mode
  127. $lm = strtolower(get_input('lightmode'));
  128. if ($lm == 'true') $lightmode = true;
  129. // Load plugins, if we're not in light mode
  130. if (($installed) && ($db_installed) && ($sanitised) && (!$lightmode)) {
  131. load_plugins();
  132. trigger_elgg_event('plugins_boot', 'system');
  133. }
  134. // Forward if we haven't been installed
  135. if ((!$installed || !$db_installed) && !substr_count($_SERVER["PHP_SELF"],"install.php") && !substr_count($_SERVER["PHP_SELF"],"css.php") && !substr_count($_SERVER["PHP_SELF"],"action_handler.php")) {
  136. header("Location: install.php");
  137. exit;
  138. }
  139. // Trigger events
  140. if (!substr_count($_SERVER["PHP_SELF"],"install.php") &&
  141. !substr_count($_SERVER["PHP_SELF"],"setup.php") &&
  142. !$lightmode
  143. && !(defined('upgrading') && upgrading == 'upgrading')) {
  144. // If default settings haven't been installed, forward to the default settings page
  145. trigger_elgg_event('init', 'system');
  146. //if (!datalist_get('default_settings')) {
  147. //forward("setup.php");
  148. //}
  149. }
  150. // System booted, return to normal view
  151. set_input('view', $oldview);
  152. if (empty($oldview)) {
  153. if (empty($CONFIG->view))
  154. $oldview = 'default';
  155. else
  156. $oldview = $CONFIG->view;
  157. }
  158. if (($installed) && ($db_installed))
  159. {
  160. $lastupdate = datalist_get('simplecache_lastupdate');
  161. $lastcached = datalist_get('simplecache_'.$oldview);
  162. if ($lastupdate == 0 || $lastcached < $lastupdate) {
  163. elgg_view_regenerate_simplecache();
  164. $lastcached = time();
  165. datalist_set('simplecache_lastupdate',$lastcached);
  166. datalist_set('simplecache_'.$oldview,$lastcached);
  167. }
  168. $CONFIG->lastcache = $lastcached;
  169. }
  170. ?>