/** * 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); }