request->request("keyValue"); if (!$keyValue) { $type = $this->request->request("type"); $name = $this->request->request("name"); if ($name) { //$files[] = ['name' => $name . '.html']; } //设置过滤方法 $this->request->filter(['strip_tags']); $config = get_addon_config('blog'); $themeDir = ADDON_PATH . 'blog' . DS . 'view' . DS . $config['theme'] . DS; $dh = opendir($themeDir); while (false !== ($filename = readdir($dh))) { if ($filename == '.' || $filename == '..') { continue; } if ($type) { $rule = $type == 'channel' ? '(channel|list)' : $type; if (!preg_match("/^{$rule}(.*)/i", $filename)) { continue; } } $files[] = ['name' => $filename]; } } else { $files[] = ['name' => $keyValue]; } return $result = ['total' => count($files), 'list' => $files]; } /** * 检查内容是否包含违禁词 * @throws \Exception */ public function check_content_islegal() { $config = get_addon_config('blog'); $content = $this->request->post('content'); if (!$content) { $this->error(__('Please input your content')); } if ($config['audittype'] == 'local') { // 敏感词过滤 $handle = SensitiveHelper::init()->setTreeByFile(ADDON_PATH . 'blog/data/words.dic'); //首先检测是否合法 $arr = $handle->getBadWord($content); if ($arr) { $this->error(__('The content is not legal'), null, $arr); } else { $this->success(__('The content is legal')); } } else { $client = new AipContentCensor($config['aip_appid'], $config['aip_apikey'], $config['aip_secretkey']); $result = $client->antiSpam($content); if (isset($result['result']) && $result['result']['spam'] > 0) { $arr = []; foreach (array_merge($result['result']['review'], $result['result']['reject']) as $index => $item) { $arr[] = $item['hit']; } $this->error(__('The content is not legal'), null, $arr); } else { $this->success(__('The content is legal')); } } } /** * 获取关键字 * @throws \Exception */ public function get_content_keywords() { $config = get_addon_config('blog'); $title = $this->request->post('title'); $tags = $this->request->post('tags', ''); $content = $this->request->post('content'); if (!$content) { $this->error(__('Please input your content')); } $keywords = Service::getContentTags($title); $keywords = in_array($title, $keywords) ? [] : $keywords; $keywords = array_filter(array_merge([$tags], $keywords)); $description = mb_substr(strip_tags($content), 0, 200); $data = [ "keywords" => implode(',', $keywords), "description" => $description ]; $this->success("提取成功", null, $data); } /** * 获取标题拼音 */ public function get_title_pinyin() { $config = get_addon_config('blog'); $title = $this->request->post("title"); //分隔符 $delimiter = $this->request->post("delimiter", ""); $pinyin = new \Overtrue\Pinyin\Pinyin('Overtrue\Pinyin\MemoryFileDictLoader'); if ($title) { $result = $pinyin->permalink($title, $delimiter); $this->success("", null, ['pinyin' => $result]); } else { $this->error(__('Parameter %s can not be empty', 'name')); } } }