<?php
namespace app\common\behavior;
use think\Config;
use think\Lang;
use think\Loader;
class Common
{
public function moduleInit(&$request)
{
mb_internal_encoding("UTF-8");
$url = preg_replace("/\/(\w+)\.php$/i", '', $request->root());
if (!Config::get('view_replace_str.__CDN__'))
{
Config::set('view_replace_str.__CDN__', $url);
}
if (!Config::get('view_replace_str.__PUBLIC__'))
{
Config::set('view_replace_str.__PUBLIC__', $url . '/');
}
if (!Config::get('view_replace_str.__ROOT__'))
{
Config::set('view_replace_str.__ROOT__', preg_replace("/\/public\/$/", '', $url . '/'));
}
if (!Config::get('site.cdnurl'))
{
Config::set('site.cdnurl', $url);
}
if (!Config::get('upload.cdnurl'))
{
Config::set('upload.cdnurl', $url);
}
if (Config::get('app_debug'))
{
Config::set('site.version', time());
Config::set('exception_tmpl', THINK_PATH . 'tpl' . DS . 'think_exception.tpl');
}
if (Config::get('app_trace') && $request->isAjax())
{
Config::set('app_trace', false);
}
if (Config::get('lang_switch_on') && $request->get('lang'))
{
\think\Cookie::set('think_var', $request->get('lang'));
}
class_alias('fast\\Form', 'Form');
}
public function addonBegin(&$request)
{
Lang::load([
APP_PATH . 'common' . DS . 'lang' . DS . $request->langset() . DS . 'addon' . EXT,
]);
$this->moduleInit($request);
}
}