|
<?php |
|
|
|
class MY_Config extends CI_Config { |
|
|
|
/** |
|
* Loads in custom server-specific configurations |
|
* |
|
* Additional config variables set |
|
* server_name - the part of the hostname to the left of '.topleveldomain.com' |
|
* |
|
*/ |
|
public function load($file = '', $use_sections = FALSE, $fail_gracefully = FALSE) { |
|
parent::load($file,$use_sections,$fail_gracefully); |
|
$server_name = $this->server_name(); |
|
$this->config['server_name'] = $server_name; |
|
if (array_key_exists('servers',$this->config)) { |
|
$server_configs = $this->config['servers']; |
|
if (array_key_exists($server_name,$server_configs)) { |
|
while(list($k,$v) = each($server_configs[$server_name])) { |
|
$this->config[$k] = $v; |
|
} |
|
} |
|
unset($this->config['servers']); |
|
} |
|
} |
|
|
|
public function dump() { |
|
print "<pre>"; |
|
print_r($this->config); |
|
print "</pre>"; |
|
} |
|
|
|
|
|
/** |
|
* Returns the portion of the domain before the [domain_name].[tld] |
|
* @return string |
|
*/ |
|
public function server_name() { |
|
$server = $_SERVER['SERVER_NAME']; |
|
$parts = explode('.',$server); |
|
array_pop($parts); # .com |
|
array_pop($parts); # domain |
|
$server = join('.',$parts); |
|
if (!array_key_exists('servers',$this->config)) { |
|
return $server; |
|
} |
|
$equiv = $this->config['servers']['equiv']; |
|
if (array_key_exists($server,$equiv)) { |
|
$server = $equiv[$server]; |
|
} |
|
return $server; |
|
} |
|
|
|
function is_localhost() { |
|
return ($this->server_name() == 'localhost' || substr($this->server_name(),0,5) == 'local'); |
|
} |
|
|
|
function is_live() { |
|
return ($this->server_name() == 'www' || $this->server_name() == '' ); |
|
} |
|
} |
|
|
|
?> |