setTreeByFile(ADDON_PATH . 'shop/data/words.dic'); //首先检测是否合法 $isLegal = $handle->islegal($content); return $isLegal ? true : false; } elseif ($type == 'baiduyun') { $client = new AipContentCensor($config['aip_appid'], $config['aip_apikey'], $config['aip_secretkey']); $result = $client->textCensorUserDefined($content); if (!isset($result['conclusionType']) || $result['conclusionType'] > 1) { return false; } } return true; } /** * 获取标题的关键字 * @param $title * @return array */ public static function getContentTags($title) { $arr = []; $config = get_addon_config('shop'); if ($config['nlptype'] == 'local') { !defined('_VIC_WORD_DICT_PATH_') && define('_VIC_WORD_DICT_PATH_', ADDON_PATH . 'shop/data/dict.json'); $handle = new VicWord('json'); $result = $handle->getAutoWord($title); foreach ($result as $index => $item) { $arr[] = $item[0]; } } else { $client = new AipNlp($config['aip_appid'], $config['aip_apikey'], $config['aip_secretkey']); $result = $client->lexer($title); if (isset($result['items'])) { foreach ($result['items'] as $index => $item) { if (!in_array($item['pos'], ['v', 'vd', 'nd', 'a', 'ad', 'an', 'd', 'm', 'q', 'r', 'p', 'c', 'u', 'xc', 'w'])) { $arr[] = $item['item']; } } } } foreach ($arr as $index => $item) { if (mb_strlen($item) == 1) { unset($arr[$index]); } } return array_filter(array_unique($arr)); } /** * 内容关键字自动加链接 */ public static function autolinks($value) { $links = []; $value = preg_replace_callback('~(.*?|<.*?>)~i', function ($match) use (&$links) { return '<' . array_push($links, $match[1]) . '>'; }, $value); $config = get_addon_config('shop'); $autolinks = $config['autolinks']; $value = preg_replace_callback('/(' . implode('|', array_keys($autolinks)) . ')/i', function ($match) use ($autolinks) { if (!isset($autolinks[$match[1]])) { return $match[0]; } else { return '' . $match[0] . ''; } }, $value); return preg_replace_callback('/<(\d+)>/', function ($match) use (&$links) { return $links[$match[1] - 1]; }, $value); } /** * @ 获取商品模板 * @return void */ public static function getSourceTpl($tpl_id, $source_id) { if (!$tpl_id || !$source_id) { return ''; } $row = \addons\shop\model\Card::where('status', 'normal')->where('id', $tpl_id)->find(); if (empty($row)) { return ''; } $source = null; switch ($row['type']) { case 1: $source = \addons\shop\model\Coupon::getCouponInfo($source_id); break; default: $source = \addons\shop\model\Goods::get($source_id); } if (empty($source)) { return ''; } $view = new View(); $html = $view->fetch($row->content, ['source' => $source, 'tpl' => $row], [], [], true); return $html; } /** * @ 替换多余的卡片信息 * @param $value * @return void */ public static function replaceSourceTpl($value) { if (!empty($value)) { return preg_replace('/(?<=data-id=\"shop\"\>).*?(?=\