index.php 4.2 KB

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