Hubzilla core code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

188 lines
4.5 KiB

  1. <?php /** @file */
  2. namespace Zotlabs\Web;
  3. class WebServer {
  4. public function run() {
  5. /*
  6. * Bootstrap the application, load configuration, load modules, load theme, etc.
  7. */
  8. require_once('boot.php');
  9. if(file_exists('.htsite.php'))
  10. include('.htsite.php');
  11. // miniApp is a conversion object from old style .htconfig.php files
  12. $a = new \miniApp;
  13. // our central App object
  14. \App::init();
  15. /*
  16. * Load the configuration file which contains our DB credentials.
  17. * Ignore errors. If the file doesn't exist or is empty, we are running in
  18. * installation mode.
  19. */
  20. \App::$install = ((file_exists('.htconfig.php') && filesize('.htconfig.php')) ? false : true);
  21. @include('.htconfig.php');
  22. if(! defined('UNO'))
  23. define('UNO', 0);
  24. $a->convert();
  25. \App::$timezone = ((x($default_timezone)) ? $default_timezone : 'UTC');
  26. date_default_timezone_set(\App::$timezone);
  27. /*
  28. * Try to open the database;
  29. */
  30. require_once('include/dba/dba_driver.php');
  31. if(! \App::$install) {
  32. \DBA::dba_factory($db_host, $db_port, $db_user, $db_pass, $db_data, $db_type, \App::$install);
  33. if(! \DBA::$dba->connected) {
  34. system_unavailable();
  35. }
  36. unset($db_host, $db_port, $db_user, $db_pass, $db_data, $db_type);
  37. /**
  38. * Load configs from db. Overwrite configs from .htconfig.php
  39. */
  40. load_config('config');
  41. load_config('system');
  42. load_config('feature');
  43. \App::$session = new Session();
  44. \App::$session->init();
  45. load_hooks();
  46. call_hooks('init_1');
  47. }
  48. \App::$language = get_best_language();
  49. load_translation_table(\App::$language,\App::$install);
  50. /**
  51. *
  52. * Important stuff we always need to do.
  53. *
  54. * The order of these may be important so use caution if you think they're all
  55. * intertwingled with no logical order and decide to sort it out. Some of the
  56. * dependencies have changed, but at least at one time in the recent past - the
  57. * order was critical to everything working properly
  58. *
  59. */
  60. if(\App::$session) {
  61. \App::$session->start();
  62. }
  63. else {
  64. session_start();
  65. register_shutdown_function('session_write_close');
  66. }
  67. /**
  68. * Language was set earlier, but we can over-ride it in the session.
  69. * We have to do it here because the session was just now opened.
  70. */
  71. if(array_key_exists('system_language',$_POST)) {
  72. if(strlen($_POST['system_language']))
  73. $_SESSION['language'] = $_POST['system_language'];
  74. else
  75. unset($_SESSION['language']);
  76. }
  77. if((x($_SESSION, 'language')) && ($_SESSION['language'] !== $lang)) {
  78. \App::$language = $_SESSION['language'];
  79. load_translation_table(\App::$language);
  80. }
  81. if((x($_GET,'zid')) && (! \App::$install)) {
  82. \App::$query_string = strip_zids(\App::$query_string);
  83. if(! local_channel()) {
  84. $_SESSION['my_address'] = $_GET['zid'];
  85. zid_init($a);
  86. }
  87. }
  88. if((x($_SESSION, 'authenticated')) || (x($_POST, 'auth-params')) || (\App::$module === 'login'))
  89. require('include/auth.php');
  90. if(! x($_SESSION, 'sysmsg'))
  91. $_SESSION['sysmsg'] = array();
  92. if(! x($_SESSION, 'sysmsg_info'))
  93. $_SESSION['sysmsg_info'] = array();
  94. /*
  95. * check_config() is responsible for running update scripts. These automatically
  96. * update the DB schema whenever we push a new one out. It also checks to see if
  97. * any plugins have been added or removed and reacts accordingly.
  98. */
  99. if(\App::$install) {
  100. /* Allow an exception for the view module so that pcss will be interpreted during installation */
  101. if(\App::$module != 'view')
  102. \App::$module = 'setup';
  103. }
  104. else
  105. check_config($a);
  106. nav_set_selected('nothing');
  107. $Router = new Router($a);
  108. /* initialise content region */
  109. if(! x(\App::$page, 'content'))
  110. \App::$page['content'] = '';
  111. call_hooks('page_content_top', \App::$page['content']);
  112. $Router->Dispatch($a);
  113. // If you're just visiting, let javascript take you home
  114. if(x($_SESSION, 'visitor_home')) {
  115. $homebase = $_SESSION['visitor_home'];
  116. } elseif(local_channel()) {
  117. $homebase = z_root() . '/channel/' . \App::$channel['channel_address'];
  118. }
  119. if(isset($homebase)) {
  120. \App::$page['content'] .= '<script>var homebase = "' . $homebase . '";</script>';
  121. }
  122. // now that we've been through the module content, see if the page reported
  123. // a permission problem and if so, a 403 response would seem to be in order.
  124. if(stristr(implode("", $_SESSION['sysmsg']), t('Permission denied'))) {
  125. header($_SERVER['SERVER_PROTOCOL'] . ' 403 ' . t('Permission denied.'));
  126. }
  127. call_hooks('page_end', \App::$page['content']);
  128. construct_page($a);
  129. killme();
  130. }
  131. }