12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- <?php
- namespace app\common\behavior;
- use think\Config;
- use think\Lang;
- use think\Loader;
- class Common
- {
- public function appDispatch(&$dispatch)
- {
- $pathinfoArr = explode('/', request()->pathinfo());
- if (!Config::get('url_domain_deploy') && $pathinfoArr && in_array($pathinfoArr[0], ['index', 'api'])) {
-
- \think\App::route(false);
- }
- }
- 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'));
- }
-
- if (!class_exists('Form')) {
- 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);
- }
- }
|