isLogin() ? $auth->id : 0; $username = $auth->isLogin() ? $auth->username : __('Unknown'); // 设置过滤函数 request()->filter('trim,strip_tags,htmlspecialchars'); $controllername = Loader::parseName(request()->controller()); $actionname = strtolower(request()->action()); $path = str_replace('.', '/', $controllername) . '/' . $actionname; if (self::$ignoreRegex) { foreach (self::$ignoreRegex as $index => $item) { if (preg_match($item, $path)) { return; } } } $content = $content ?: self::$content; if (!$content) { $content = request()->param('') ?: file_get_contents("php://input"); $content = self::getPureContent($content); } $title = $title ?: self::$title; if (!$title) { $title = []; $breadcrumb = Auth::instance()->getBreadcrumb($path); foreach ($breadcrumb as $k => $v) { $title[] = $v['title']; } $title = implode(' / ', $title); } self::create([ 'title' => $title, 'content' => !is_scalar($content) ? json_encode($content, JSON_UNESCAPED_UNICODE) : $content, 'url' => substr(xss_clean(strip_tags(request()->url())), 0, 1500), 'admin_id' => $admin_id, 'username' => $username, 'useragent' => substr(request()->server('HTTP_USER_AGENT'), 0, 255), 'ip' => xss_clean(strip_tags(request()->ip())), 'company_id'=> $auth->company_id, ]); } /** * 获取已屏蔽关键信息的数据 * @param $content * @return array */ protected static function getPureContent($content) { if (!is_array($content)) { return $content; } foreach ($content as $index => &$item) { if (preg_match("/(password|salt|token)/i", $index)) { $item = "***"; } else { if (is_array($item)) { $item = self::getPureContent($item); } } } return $content; } public function admin() { return $this->belongsTo('PcAdmin', 'admin_id')->setEagerlyType(0); } }