public function __construct($config, $tmp_dir = 'tmp')
{
/**
* Important!
* This class must be put in a file which be stored in 2 subdir with root dir
* If you store this file on other folder, you must change $store_dir below
*/
$store_dir = '/../../../../';
$this->root_dir = preg_replace('/[\\/]+$/', '', str_replace(DIRECTORY_SEPARATOR, '/', realpath(dirname(__FILE__) . $store_dir)));
// Custom some config
if (!empty($config['version'])) {
$this->site_config['version'] = $config['version'];
}
if (!empty($config['version'])) {
$this->site_config['sitekey'] = $config['sitekey'];
}
if (!empty($config['site_charset'])) {
$this->site_config['site_charset'] = $config['site_charset'];
}
// Find my domain
$server_name = preg_replace('/^[a-z]+\\:\\/\\//i', '', $this->get_Env(array('HTTP_HOST', 'SERVER_NAME')));
$server_protocol = strtolower(preg_replace('/^([^\\/]+)\\/*(.*)$/', '\\1', $this->get_Env('SERVER_PROTOCOL'))) . ($this->get_Env('HTTPS') == 'on' ? 's' : '');
$server_port = $this->get_Env('SERVER_PORT');
$server_port = $server_port == '80' ? '' : ':' . $server_port;
if (filter_var($server_name, FILTER_VALIDATE_IP, FILTER_FLAG_IPV6) === false) {
$this->site_config['my_domain'] = $server_protocol . '://' . $server_name . $server_port;
} else {
$this->site_config['my_domain'] = $server_protocol . '://[' . $server_name . ']' . $server_port;
}
// Check user custom temp dir
$this->tmp_dir = $this->root_dir . '/' . $tmp_dir;
if (!is_dir($this->tmp_dir)) {
$this->tmp_dir = $this->root_dir . '/tmp';
}
}