// +----------------------------------------------------------------------
namespace cmf\controller;
use think\Db;
use app\admin\model\ThemeModel;
use think\facade\View;
class HomeBaseController extends BaseController
{
protected function initialize()
{
// 监听home_init
hook('home_init');
parent::initialize();
$closeConfig = cmf_get_option('close_config');
$closeConfig = $closeConfig? $closeConfig : config('weixin.site');
$isClose = isset($closeConfig['close'])? $closeConfig['close'] : 2;
$accessIp = isset($closeConfig['access_ip'])? $closeConfig['access_ip'] : '';
$accessIp = $accessIp? explode(',', $accessIp) : [];
$closeMsg = isset($closeConfig['msg'])? $closeConfig['msg'] : '
网站正在升级维护中
';
$controllerName = strtolower(request()->controller());
if($controllerName != 'notify' && $isClose==1 && (empty($accessIp) || $accessIp && !in_array(get_client_ip(),$accessIp))){
echo '站点维护提示'.$closeMsg.'
'; die();
}
$siteInfo = cmf_get_site_info();
$mapConfig = config('config.map');
$mapKey = isset($mapConfig['key'])? $mapConfig['key'] : '';
$version = config('weixin.version');
$version = $version? $version.'.'.date('Hi') : date('YmdH');
$this->assign('version', $version);
View::share('mapKey', $mapKey);
View::share('site_info', $siteInfo);
}
protected function _initializeView()
{
$cmfThemePath = config('template.cmf_theme_path');
$cmfDefaultTheme = cmf_get_current_theme();
$themePath = "{$cmfThemePath}{$cmfDefaultTheme}";
$root = cmf_get_root();
//使cdn设置生效
$cdnSettings = cmf_get_option('cdn_settings');
if (empty($cdnSettings['cdn_static_root'])) {
$viewReplaceStr = [
'__ROOT__' => $root,
'__TMPL__' => "{$root}/{$themePath}",
'__STATIC__' => "{$root}/static",
'__WEB_ROOT__' => $root
];
} else {
$cdnStaticRoot = rtrim($cdnSettings['cdn_static_root'], '/');
$viewReplaceStr = [
'__ROOT__' => $root,
'__TMPL__' => "{$cdnStaticRoot}/{$themePath}",
'__STATIC__' => "{$cdnStaticRoot}/static",
'__WEB_ROOT__' => $cdnStaticRoot
];
}
config('template.view_base', WEB_ROOT . "{$themePath}/");
config('template.tpl_replace_string', $viewReplaceStr);
$themeErrorTmpl = "{$themePath}/error.html";
if (file_exists_case($themeErrorTmpl)) {
config('dispatch_error_tmpl', $themeErrorTmpl);
}
$themeSuccessTmpl = "{$themePath}/success.html";
if (file_exists_case($themeSuccessTmpl)) {
config('dispatch_success_tmpl', $themeSuccessTmpl);
}
}
/**
* 加载模板输出
* @access protected
* @param string $template 模板文件名
* @param array $vars 模板输出变量
* @param array $replace 模板替换
* @param array $config 模板参数
* @return mixed
*/
protected function fetch($template = '', $vars = [], $replace = [], $config = [])
{
$template = $this->parseTemplate($template);
$more = $this->getThemeFileMore($template);
$this->assign('theme_vars', $more['vars']);
$this->assign('theme_widgets', $more['widgets']);
$content = parent::fetch($template, $vars, $replace, $config);
$designingTheme = cookie('cmf_design_theme');
if ($designingTheme) {
$app = $this->request->module();
$controller = $this->request->controller();
$action = $this->request->action();
$output = <<
var _themeDesign=true;
var _themeTest="test";
var _app='{$app}';
var _controller='{$controller}';
var _action='{$action}';
var _themeFile='{$more['file']}';
if(parent && parent.simulatorRefresh){
parent.simulatorRefresh();
}
hello;
$pos = strripos($content, '