<?php
if (substr(PHP_VERSION, 0, 1) != '5')exit("本系统运行环境要求PHP版本5及以上！");
if(!defined('APP_PATH')||!defined('I_PATH')){exit('Access Denied');}
require(I_PATH."/functions.php");

$GLOBALS['LD_I'] = spConfigReady(require(I_PATH."/inc.php"),$iConfig);
if('debug' == func_get_iglobal(array('mode'))){
	define("SP_DEBUG",TRUE); 
}else{
	define("SP_DEBUG",FALSE); 
}


if (SP_DEBUG) {
	if( substr(PHP_VERSION, 0, 3) == "5.3" ){
		error_reporting(E_ALL & ~E_NOTICE & ~E_WARNING & ~E_DEPRECATED);
	}else{
		error_reporting(E_ALL & ~E_NOTICE & ~E_WARNING);
	}
} else {
	error_reporting(0);
}
@set_magic_quotes_runtime(0);

import(func_get_iglobal(array('sp_core_path'))."/controllerBase.php", FALSE, TRUE);
import(func_get_iglobal(array('sp_core_path'))."/modelBase.php", FALSE, TRUE);
import(func_get_iglobal(array('sp_core_path'))."/viewBase.php", FALSE, TRUE);

if(func_get_iglobal(array('rewrite','rewrite_open'))==1){
	func_set_iglobal(array('url','url_path_base'),func_get_iglobal(array('rewrite','rewrite_dir')).'index.php');
}else{
	if('' == func_get_iglobal(array('url','url_path_base'))){
		if(basename($_SERVER['SCRIPT_NAME']) === basename($_SERVER['SCRIPT_FILENAME']))
			func_set_iglobal(array('url','url_path_base'),$_SERVER['SCRIPT_NAME']);
		elseif (basename($_SERVER['PHP_SELF']) === basename($_SERVER['SCRIPT_FILENAME']))
			func_set_iglobal(array('url','url_path_base'),$_SERVER['PHP_SELF']);
		elseif (isset($_SERVER['ORIG_SCRIPT_NAME']) && basename($_SERVER['ORIG_SCRIPT_NAME']) === basename($_SERVER['SCRIPT_FILENAME']))
			//$GLOBALS['LD_I']['url']["url_path_base"] = $_SERVER['ORIG_SCRIPT_NAME'];
			func_set_iglobal(array('url','url_path_base'),$_SERVER['ORIG_SCRIPT_NAME']);
	}
}
$GLOBALS['WWW']=pathinfo(func_get_iglobal(array('url','url_path_base')));
$GLOBALS['WWW']=str_replace($GLOBALS['WWW']["basename"],'',func_get_iglobal(array('url','url_path_base')));
$GLOBALS['TURL']=$GLOBALS['WWW'].'template/'.$iConfig['ext']['view_themes'].'/';//系统模板目录

if(TRUE == func_get_iglobal(array('url','url_path_info')) && !empty($_SERVER['PATH_INFO'])){
	$url_args = explode("/", $_SERVER['PATH_INFO']);$url_sort = array();
	for($u = 1; $u < count($url_args); $u++){
		if($u == 1)$url_sort[func_get_iglobal(array('url_controller'))] = $url_args[$u];
		elseif($u == 2)$url_sort[func_get_iglobal(array('url_action'))] = $url_args[$u];
		else {$url_sort[$url_args[$u]] = isset($url_args[$u+1]) ? $url_args[$u+1] : "";$u+=1;}}
	if("POST" == strtoupper($_SERVER['REQUEST_METHOD'])){$_REQUEST = $_POST =  $_POST + $url_sort;
	}else{$_REQUEST = $_GET = $_GET + $url_sort;}
}

$__controller = isset($_REQUEST[func_get_iglobal(array('url_controller'))]) ? 
	$_REQUEST[func_get_iglobal(array('url_controller'))] : 
	func_get_iglobal(array('default_controller'));
$__action = isset($_REQUEST[$GLOBALS['LD_I']["url_action"]]) ? 
	$_REQUEST[func_get_iglobal(array('url_action'))] : 
	func_get_iglobal(array('default_action'));
$GLOBALS['S']=array('http'=>syExt('http_path'),'title'=>syExt('site_title'),'keywords'=>syExt('site_keywords'),'description'=>syExt('site_description'));