<?php

/*
  PHP version 5
  Copyright (c) 2002-2018 ECISP.CN、EarcLink.COM
  警告：这不是一个免费的软件，请在许可范围内使用，请尊重知识产权，侵权必究，举报有奖
  作者：黄祥云 E-mail:6326420@qq.com  QQ:6326420 TEL:18665655030 / 13797552220
 */
if (file_exists(ESPCMS_FILE_ROOT . 'espcms_includes/espcms_version.php')) {
	require_once( ESPCMS_FILE_ROOT . 'espcms_includes/espcms_version.php' );
} else {
	exit('错误：版本配置文件不存在');
}
require_once( ESPCMS_FILE_ROOT . 'espcms_public/espcms_constant.php' );
require_once( ESPCMS_FILE_ROOT . 'espcms_public/espcms_function.php' );
require_once( ESPCMS_FILE_ROOT . 'espcms_public/espcms_variable.php' );
require_once( ESPCMS_FILE_ROOT . 'espcms_includes/espcms_instal.php' );
espcms_bug_mode();
espcms_load_constant();
espcms_cache_constant();
$_SERVER = espcms_server_vars();
global $espcms_version, $espcms_db_version, $espcms_tinymce_version, $loading_php_version, $espcms_license;
espcms_loadcheck_php_versions();
espcms_loadcheck_php_curl();
date_default_timezone_set('PRC');
require_once( ESPCMS_FILE_ROOT . 'espcms_public/espcms_tool.php' );
espcms_magic_quotes();
define('ESPCMS_URL', preg_replace('/' . str_replace('/', '\/', ESPCMS_INSTALL_DIRNAME) . '(.*)/i', '', espcms_host('AP')));
define('ESPCMS_WWW_URL', espcms_host('WWW_RT'));
define('ESPCMS_URL_RT', espcms_host('RT'));
$ac_name = espcms_get_ac() ? espcms_get_ac() : ESPCMS_SETUP_RUN_AC;
$at_name = espcms_get_at() ? espcms_get_at() : ESPCMS_SETUP_RUN_AT;
require_once( ESPCMS_FILE_ROOT . 'espcms_public/espcms_db.php' );
require_once( ESPCMS_FILE_ROOT . 'espcms_public/espcms_dbsave.php' );
espcms_setup_template();
$module_filename = ESPCMS_FILE_ROOT . 'espcms_web/' . $ac_name . '.php';
if (!is_file($module_filename)) {
	espcms_message_err('public_pack-espcms_module_file_err', array($ac_name));
}
include $module_filename;
$espcms_fun_name = ESPCMS_FUN_PREFIX . $at_name;
if (method_exists($ac_name, $espcms_fun_name)) {
	$control = new $ac_name;
	$control->$espcms_fun_name();
} else {
	espcms_message_err('public_pack-espcms_method_name_err', array($ac_name . '/' . $at_name));
}

function __autoload($class) {
	if (!$class) {
		espcms_message_err('public_pack-espcms_method_class_err', array($class));
	}
	$class_array = explode('\\', $class);
	if (!$class_array[0]) {
		espcms_message_err('public_pack-espcms_method_class_err', array($class));
	}
	$isObject = false;
	switch ($class_array[0]) {
		case 'application':
			$class_array[0] = 'espcms_public';
			$classFile = implode('/', $class_array);
			$isObject = true;
			break;
		case 'modul_application':
			$class_array[0] = 'espcms_interface';
			$classFile = implode('/', $class_array);
			$isObject = true;
			break;
		case 'inc_application':
			$class_array[0] = 'espcms_includes';
			$classFile = implode('/', $class_array);
			$isObject = true;
			break;
		case 'web_application':
			$class_array[0] = 'espcms_web';
			$classFile = implode('/', $class_array);
			$isObject = true;
			break;
		default:
			break;
	}
	if ($isObject) {
		$file = ESPCMS_FILE_ROOT . $classFile . '.php';
		if (!is_file($file)) {
			espcms_message_err('public_pack-espcms_module_file_err', array($class));
		} else {
			include_once($file);
		}
	}
}
