<?php
/*
  PHP version 5
  Copyright (c) 2002-2019ECISP.CN、EarcLink.COM
  警告：这不是一个免费的软件，请在许可范围内使用，请尊重知识产权，侵权必究，举报有奖
  作者：黄祥云 E-mail:6326420@qq.com  QQ:6326420 TEL:18665655030 / 13797552220
*/
if (!file_exists(ESPCMS_FILE_ROOT . 'espcms_datacache/install.lock') && !file_exists(ESPCMS_FILE_ROOT . 'espcms_datacache/espcms_config.php')) {
    header('Content-type: text/html; charset=utf-8');
    header('location:espcms_install/');
    exit;
}
if (file_exists(ESPCMS_FILE_ROOT . 'espcms_datacache/espcms_config.php')) {
    require_once(ESPCMS_FILE_ROOT . 'espcms_datacache/espcms_config.php');
} else {
    exit('错误：数据库文件错误');
}
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_public/espcms_tool.php');
define("ESPCMS_WWW_URL", espcms_host('WWW_RT'));
define("ESPCMS_URL_RT", espcms_host('RT'));
define("ESPCMS_ADMIN_URL", espcms_host('AP'));
global $espcms_version, $espcms_db_version, $espcms_tinymce_version, $loading_php_version, $loading_mysql_version, $loading_mysql_version_hig;
$php_current_version = espcms_loadcheck_php_versions();
espcms_load_constant();
espcms_bug_mode();
espcms_cache_constant();
$_SERVER = espcms_server_vars();
espcms_command();
$timeoffset = preg_match("/^[0-9.\-]+$/i", $espcms_command['BASIC_TIMEZONE']) ? $espcms_command['BASIC_TIMEZONE'] * -1 : 8 * -1;
date_default_timezone_set("Etc/GMT$timeoffset");
if (defined('ESPCMS_WEB_TYPE') && ESPCMS_WEB_TYPE == 'WAP') {
    if (preg_match('/^[\w]{2,50}$/u', $_GET['lng'])) {
        setcookie('ESPCMS_WAP_LNG_COOKIE', $_GET['lng']);
        $ESPCMS_WEB_LAN = $_GET['lng'];
    } else {
        $ESPCMS_WEB_LAN = $_COOKIE['ESPCMS_WAP_LNG_COOKIE'] && preg_match('/^[\w]{2,50}$/u', $_COOKIE['ESPCMS_WAP_LNG_COOKIE']) ? $_COOKIE['ESPCMS_WAP_LNG_COOKIE'] : $espcms_command['HOME_LNG'];
    }
    define("ESPCMS_WEB_LAN", $ESPCMS_WEB_LAN);
} else {
    if (!defined('ESPCMS_WEB_LAN')) {
        define("ESPCMS_WEB_LAN", $espcms_command['HOME_LNG']);
    }
}
if (defined('ESPCMS_ROOT_STATE') && ESPCMS_ROOT_STATE) {
    define("ESPCMS_URL", espcms_host('AP'));
} else {
    if (!$espcms_command['IS_HTMLDIR']) {
        $espcms_soft_path = str_replace('/index.php', '', $_SERVER['PHP_SELF']);
        $espcms_soft_path_array = explode('/', $espcms_soft_path);
        $espcms_soft_path_array_len = count($espcms_soft_path_array) - 1;
        $espcms_run_path_array = array();
        for ($i = 0; $i < $espcms_soft_path_array_len; $i++) {
            $espcms_run_path_array[] = $espcms_soft_path_array[$i];
        }
        $espcms_run_path = implode('/', $espcms_run_path_array);
        define("ESPCMS_URL", espcms_host('URL') . $espcms_run_path . '/');
    } else {
        define("ESPCMS_URL", preg_replace('/' . str_replace('/', '\/', $espcms_command['FILE_HTMLDIR']) . '(.*)/i', '', espcms_host('AP')));
    }
}
if ($espcms_command['IS_CLOSE']) {
    exit($espcms_command['CLOSE_CONTENT']);
}
$espcms_link_db = require_espcms_link_db();
espcms_loadcheck_mysql_versions();
espcms_magic_quotes();
spl_autoload_register('web_autoload');
$ac_name = espcms_get_ac() ? espcms_get_ac() : ESPCMS_WEB_RUN_AC;
$at_name = espcms_get_at() ? espcms_get_at() : ESPCMS_WEB_RUN_AT;
$espcms_db_cache = espcms_start_cache();
require_once(ESPCMS_FILE_ROOT . 'espcms_public/espcms_db.php');
require_once(ESPCMS_FILE_ROOT . 'espcms_public/espcms_dbsave.php');
$espcms_web_templates = espcms_web_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));
}
