<?php
<364666827@qq.com>,开发者QQ群:50304283
namespace app\common\behavior;
use app\system\model\SystemConfig as ConfigModel;
use app\system\model\SystemModule as ModuleModel;
use app\system\model\SystemPlugins as PluginsModel;
use Env;
use Request;
use Lang;
use View;
class Base
{
public function run()
{
$module = strtolower(Request::module());
if (defined('INSTALL_ENTRANCE')) return;
config(PluginsModel::getConfig());
config(ModuleModel::getConfig());
config(ConfigModel::getConfig());
$theme = 'default';
if ($module != 'index' && !defined('ENTRANCE')) {
if (empty($module)) {
$module = config('default_module');
}
$modInfo = ModuleModel::where(['name' => $module, 'status' => 2])->find();
if (!$modInfo) {
exit($module.' 模块可能未启用或者未安装!');
}
$theme = $modInfo['theme'] ? $modInfo['theme'] : 'default';
}
$entry = request()->baseFile();
$rootDir= preg_replace(['/index.php$/', '/plugins.php$/', '/'.config('sys.admin_path').'$/'], ['', '', ''], $entry);
define('ROOT_DIR', $rootDir);
$viewReplaceStr = [
'__ROOT_DIR__' => $rootDir,
'__STATIC__' => $rootDir.'static',
'__UPLOAD__' => $rootDir.'upload',
'__PLUGINS__' => $rootDir.'plugins',
'__ADMIN_CSS__' => $rootDir.'static/system/css',
'__ADMIN_JS__' => $rootDir.'static/system/js',
'__ADMIN_IMG__' => $rootDir.'static/system/image',
'__ADMIN_MOD_CSS__' => $rootDir.'static/'.$module.'/css',
'__ADMIN_MOD_JS__' => $rootDir.'static/'.$module.'/js',
'__ADMIN_MOD_IMG__' => $rootDir.'static/'.$module.'/image',
'__PUBLIC_CSS__' => $rootDir.'static/css',
'__PUBLIC_JS__' => $rootDir.'static/js',
'__PUBLIC_IMG__' => $rootDir.'static/image',
'__CSS__' => $rootDir.'theme/'.$module.'/'.$theme.'/static/css',
'__JS__' => $rootDir.'theme/'.$module.'/'.$theme.'/static/js',
'__IMG__' => $rootDir.'theme/'.$module.'/'.$theme.'/static/image',
'__WAP_CSS__' => $rootDir.'theme/'.$module.'/'.$theme.'/wap/static/css',
'__WAP_JS__' => $rootDir.'theme/'.$module.'/'.$theme.'/wap/static/js',
'__WAP_IMG__' => $rootDir.'theme/'.$module.'/'.$theme.'/wap/static/image',
];
if (isset($_GET['_p'])) {
$viewReplaceStr = array_merge($viewReplaceStr, [
'__PLUGINS_CSS__' => $rootDir.'static/plugins/'.$_GET['_p'].'/static/css',
'__PLUGINS_JS__' => $rootDir.'static/plugins/'.$_GET['_p'].'/static/js',
'__PLUGINS_IMG__' => $rootDir.'static/plugins/'.$_GET['_p'].'/static/image',
]);
}
View::config(['tpl_replace_string' => $viewReplaceStr]);
if(defined('ENTRANCE') && ENTRANCE == 'admin') {
if ($module == 'index') {
header('Location: '.url('system/publics/index'));
exit;
}
if (isset($_GET['lang']) && !empty($_GET['lang'])) {
cookie('admin_language', $_GET['lang']);
} elseif (cookie('admin_language')) {
Lang::range(cookie('admin_language'));
} else {
cookie('admin_language', config('default_lang'));
}
} else {
if (config('base.site_status') != 1) {
exit('站点已关闭!');
}
if (Request::isMobile() === true &&
config('base.wap_site_status') &&
file_exists('.'.ROOT_DIR.'theme/'.$module.'/'.$theme.'/wap/')) {
$wapDomain = preg_replace(['/http:\/\/$/', '/https:\/\/$/'], ['', ''], config('base.wap_domain'));
if ($wapDomain && input('server.http_host') != $wapDomain) {
if (input('server.https') && input('server.https') == 'on') {
header('Location: https://'.$wapDomain);
}
header('Location: http://'.$wapDomain);
}
$viewPath = 'theme/'.$module.'/'.$theme.'/wap/';
} else {
$viewPath = 'theme/'.$module.'/'.$theme.'/';
}
View::config(['view_path' => $viewPath]);
if (isset($_GET['lang']) && !empty($_GET['lang'])) {
cookie('_language', $_GET['lang']);
} elseif (cookie('_language')) {
Lang::range(cookie('_language'));
} else {
cookie('_language', Lang::range());
}
}
}
}