<?php
// 精迅CMS框架入口文件
define('SYS_START_TIME', microtime(true)); //系统开始时间
define('SYS_START_MEMORY', memory_get_usage()); //系统开始内存
define('MAGIC_QUOTES_GPC', get_magic_quotes_gpc());
define('IN_JXCMS', true);
define('JXCMS_VERSION', '2.1');
define('JXCMS_RELEASE', '20130913');
define('JXCMS_ROOT', substr(str_replace('\\', '/', dirname(__FILE__)), 0, -5));
define('SCRIPT_NAME', isset($_SERVER['SCRIPT_NAME'])?$_SERVER['SCRIPT_NAME']:preg_replace('/(.*)\.php(.*)/i', '${1}.php', $_SERVER['PHP_SELF']));
$t = str_replace('\\', '/', substr(getcwd(), strlen(JXCMS_ROOT)));
if ($t) $t .= '/';
defined('MODULE_DIR') or define('MODULE_DIR', $t);
if (!defined('DEFAULT_C')) {
	$t = basename(SCRIPT_NAME);
	$t = substr($t, 0, strpos($t, '.'));
	define('DEFAULT_C', $t);
}
require JXCMS_ROOT . 'jxcms/Lib/global.func.php';
if (C('APP_GZIP', 1) && function_exists('ob_gzhandler')) ob_start('ob_gzhandler');
date_default_timezone_set(C('APP_DEFAULT_TIMEZONE', 1)); // 设置系统时区
define('TIME', time()); //定义系统时间
switch(C('APP_DEBUG', 1)){
	case 0:
		error_reporting(0);
		break;
	case 1:
		error_reporting(E_ERROR | E_PARSE);
		break;
	default:
		error_reporting(E_ALL);
}
// 获取当前IP地址
if (getenv('HTTP_CLIENT_IP') && strcasecmp(getenv('HTTP_CLIENT_IP'), 'unknown')) {
	$t = getenv('HTTP_CLIENT_IP');
} elseif (getenv('HTTP_X_FORWARDED_FOR') && strcasecmp(getenv('HTTP_X_FORWARDED_FOR'), 'unknown')) {
	$t = getenv('HTTP_X_FORWARDED_FOR');
} elseif (getenv('REMOTE_ADDR') && strcasecmp(getenv('REMOTE_ADDR'), 'unknown')) {
	$t = getenv('REMOTE_ADDR');
} elseif (isset($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] && strcasecmp($_SERVER['REMOTE_ADDR'], 'unknown')) {
	$t = $_SERVER['REMOTE_ADDR'];
}
$t = preg_match("/[\d\.]{7,15}/", $t, $matches) ? $matches[0] : 'unknown';
define('IP', $t); //定义当前IP常量
// 处理REQUEST_URI
if (!isset($_SERVER['REQUEST_URI'])) {
	$_SERVER['REQUEST_URI'] = $_SERVER['PHP_SELF'];
	if (isset($_SERVER['QUERY_STRING'])) $_SERVER['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING'];
}
$t = $_SERVER['SERVER_PORT'] == '443' ? 'https://' : 'http://';
$t .= C('APP_DOMAIN', 1)?C('APP_DOMAIN', 1):$_SERVER['HTTP_HOST'];
define('URL', $t . $_SERVER['REQUEST_URI']); //当前页面地址
define('APP_URL', $t . C('APP_DIR', 1, 'root')); //应用根目录所在地址,完整URL,独立目录模块中与ROOT_URL不同
define('ROOT_URL', $t . C('APP_DIR', 1)); //根目录所在地址,完整URL
define('ROOT_PATH', C('fullurl')?ROOT_URL:C('APP_DIR', 1)); //根目录所在路径,根据后台设置是绝对地址或相对地址
unset($t);
if (MODULE_DIR && (substr(MODULE_DIR, -1) != '/' or substr_count(MODULE_DIR, '/') > 1)) show_error(L('MODULE_DIR_ERROR'));
import('Lib/Core/App', 'jxcms');
import('Lib/Core/Base', 'jxcms');
if (C('WEBSCAN', 1) && !defined('IN_ADMIN')) Webscan :: run();
