/** * BOOT main network, detect local networks * * detect network name and work out $base_url * **/ public function detectNetwork() { global $network_prefix; $host = PA_SERVER_NAME; // URL to the root of the server. $base_url = "http://%network_name%.{$this->domain_suffix}"; if (PA::$ssl_force_https_urls == true) { $base_url = str_replace('http', 'https', $base_url); } if (preg_match('/^\\./', $this->domain_suffix)) { throw new BootStrapException("Invalid domain sufix detected. Value: " . $this->domain_suffix, 1); } PA::$domain_suffix = $this->domain_suffix; if (!PA::$config->enable_networks) { // spawning disabled $network_prefix = 'default'; $network_url_prefix = PA::$config->domain_prefix; define('CURRENT_NETWORK_URL_PREFIX', PA::$config->domain_prefix); define('CURRENT_NETWORK_FSPATH', PA::$project_dir . '/networks/default'); // turn off spawning, and guess domain suffix PA::$config->enable_network_spawning = FALSE; } else { // network operation is enabled - figure out which network we're on PA::$network_capable = TRUE; // Make sure $domain_suffix is formatted correctly if (!empty($this->domain_prefix) && $this->domain_prefix != PA::$config->domain_prefix) { $network_prefix = $this->domain_prefix; $network_url_prefix = $this->domain_prefix; } else { // domain prefix points to home network $network_prefix = 'default'; $network_url_prefix = PA::$config->domain_prefix; define('CURRENT_NETWORK_URL_PREFIX', $network_url_prefix); define('CURRENT_NETWORK_FSPATH', PA::$project_dir . '/networks/default'); } } // Allow sessions to persist across entire domain ini_set('session.cookie_domain', $this->domain_suffix); $network_folder = getShadowedPath("networks/{$network_prefix}"); if ($network_folder) { // network exists if (!defined('CURRENT_NETWORK_URL_PREFIX')) { define('CURRENT_NETWORK_URL_PREFIX', $network_url_prefix); } if (!defined('CURRENT_NETWORK_FSPATH')) { define('CURRENT_NETWORK_FSPATH', $network_folder); } if (file_exists(CURRENT_NETWORK_FSPATH . '/local_config.php')) { // and it has its own config file include CURRENT_NETWORK_FSPATH . '/local_config.php'; } } elseif ($this->domain_prefix != PA::$config->domain_prefix) { throw new BootStrapException("Unable to locate network: " . htmlspecialchars($network_prefix) . "." . $this->domain_suffix, 1); } // at this point, network is detected and we can start to work with the variables they define. // put network prefix in $base_url $base_url_pa = str_replace('%network_name%', PA::$config->domain_prefix, $base_url); // LOCAL $base_url = PA::$url = str_replace('%network_name%', CURRENT_NETWORK_URL_PREFIX, $base_url); // now we are done with $base_url - it gets define()d and we work out // the relative version (for ajax) define('BASE_URL_PA', $base_url_pa); define('BASE_URL', $base_url); $base_url_parts = parse_url($base_url); PA::$local_url = preg_replace('|/$|', '', @$base_url_parts['path'] ? $base_url_parts['path'] : ''); define('BASE_URL_REL', PA::$local_url); // work out theme path and check that it exists define('CURRENT_THEME_REL_URL', PA::$local_url . '/' . PA::$theme_rel); define('CURRENT_THEME_FSPATH', PA::$theme_path); define('CURRENT_THEME_FS_CACHE_PATH', PA::$project_dir . '/web/cache'); // Finally - Load network! PA::$network_info = get_network_info($network_prefix); // NOTE this should be retrieved from network XML config file PA::$extra = unserialize(PA::$network_info->extra); }
private function bootApp($script) { global $app, $pa_page_render_start; $pa_page_render_start = microtime(TRUE); /* timing */ if (!defined("PA_DISABLE_BUFFERING")) { ob_start("pa_end_of_page_ob_filter"); } PA::$config = new PA(); PA::$project_dir = PA_PROJECT_PROJECT_DIR; PA::$core_dir = PA_PROJECT_CORE_DIR; $app = new CNBootStrap(PA_PROJECT_ROOT_DIR, $this->current_route, $this->route_query_str); $GLOBALS['app'] = $app; // make $app object available in global scope $app->loadConfigFile(APPLICATION_CONFIG_FILE); if (PA::$config->pa_installed) { $app->detectDBSettings(); } $app->autoLoadFiles($this->auto_load_list); $app->loadLanguageFiles(); default_exception(); // register default exception handler if (PA::$ssl_force_https_urls) { $this->routing_scheme = 'https'; } if (PA::$ssl_security_on) { if ($this->dispatcher_scheme != $this->routing_scheme) { $this->restoreServerData(); header("Location: " . $this->routing_scheme . "://" . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI']); // "$path_pref/$file_name" . $path_info . $guery_str); exit; } } if (PA::$profiler) { register_shutdown_function("show_profiler_statistic"); } PA::$path = PA_INSTALL_DIR; PA::$url = PA_BASE_URL; PA::$remote_ip = $app->remote_addr; if (PA::$config->pa_installed) { $app->detectNetwork(); $app->getCurrentUser(); if ($script != 'web/cnuser_login_index.php' && PA::$login_uid != SUPER_USER_ID && SITE_UNDER_MAINTAINENCE == 1) { $script = "web/cnmaintenance.php"; } } else { $script = DEFAULT_INSTALL_SCRIPT; } ob_get_clean(); return $script; }