"/[a-zA-Z0-9\-_\x{4e00}-\x{9fa5}]+/u", // 'id' => "\d+", // ]); $config = get_addon_config('shop'); $taglib = Config::get('template.taglib_pre_load'); Config::set('template.taglib_pre_load', ($taglib ? $taglib . ',' : '') . 'addons\\shop\\taglib\\Shop'); Config::set('shop', $config); } /** * 脚本替换 */ public function viewFilter(& $content) { $request = \think\Request::instance(); $dispatch = $request->dispatch(); if (!$dispatch) { return; } if ($request->module() || !isset($dispatch['method'][0]) || $dispatch['method'][0] != '\think\addons\Route') { return; } $addon = isset($dispatch['var']['addon']) ? $dispatch['var']['addon'] : $request->param('addon'); if ($addon != 'shop') { return; } $style = ''; $script = ''; $result = preg_replace_callback("/<(script|style)\s(data\-render=\"(script|style)\")([\s\S]*?)>([\s\S]*?)<\/(script|style)>/i", function ($match) use (&$style, &$script) { if (isset($match[1]) && in_array($match[1], ['style', 'script'])) { ${$match[1]} .= str_replace($match[2], '', $match[0]); } return ''; }, $content); $content = preg_replace_callback('/^\s+(\{__STYLE__\}|\{__SCRIPT__\})\s+$/m', function ($matches) use ($style, $script) { return $matches[1] == '{__STYLE__}' ? $style : $script; }, $result ? $result : $content); } /** * 会员中心边栏后 * @return mixed * @throws \Exception */ public function userSidenavAfter() { $request = Request::instance(); $controllername = strtolower($request->controller()); $actionname = strtolower($request->action()); $config = get_addon_config('shop'); $usersidebar = explode(',', $config['usersidenav']); if (!$usersidebar) { return ''; } $data = [ 'controllername' => $controllername, 'actionname' => $actionname, 'usersidebar' => $usersidebar ]; return $this->fetch('view/hook/user_sidenav_after', $data); } }