ProofreadingController.php
3.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<?php
namespace App\Http\Controllers\Bside\Setting;
use App\Enums\Common\Code;
use App\Http\Controllers\Bside\BaseController;
use App\Http\Logic\Bside\Setting\ProofreadingLogic;
class ProofreadingController extends BaseController
{
const LANGUAGE_ID = 1;//默认语言英语
const TYPE_IMAGE = 2;//校队图片
/**
* @name :lists
* @author :lyh
* @method :post
* @time :2023/6/12 10:52
*/
public function lists(ProofreadingLogic $proofreadingLogic){
//默认显示语言为英语
if(!isset($this->map['language_id']) || empty($this->map['language_id'])){
$this->map['language_id'] = $this::LANGUAGE_ID;
}
$lists = $proofreadingLogic->proofreadingList($this->map,$this->page,$this->row);
if(!empty($lists['list']) && ($this->param['type'] == $this::TYPE_IMAGE)){
foreach ($lists['list'] as $k => $v){
$lists['list'][$k]['image_link'] = getImageUrl($v['translate']);
}
}
$this->response('success',Code::SUCCESS,$lists);
}
/**
* @name :(新增/更新多语言)save
* @author :lyh
* @method :post
* @time :2023/6/12 10:52
*/
public function save(ProofreadingLogic $proofreadingLogic){
$proofreadingLogic->proofreadingSave();
$this->response('success');
}
/**
* @name :(当前项目选中的语言列表)languageList
* @author :lyh
* @method :post
* @time :2023/6/12 15:52
*/
public function languageList(ProofreadingLogic $proofreadingLogic){
$list = $proofreadingLogic->countryLanguageList($this->map,$this->order);
$this->response('success',Code::SUCCESS,$list);
}
/**
* @remark :获取Url内容
* @name :getUrlRead
* @author :lyh
* @method :post
* @time :2023/11/22 10:02
*/
public function getUrlRead($url){
$contextOptions = [
'ssl' => [
'verify_peer' => false,
'verify_peer_name' => false,
],
];
$context = stream_context_create($contextOptions);
$sourceCode = file_get_contents($url, false, $context);
$pattern = '/<style\b[^>]*>(.*?)<\/style>/s'; // 定义匹配`<style>`标签及其内容的正则表达式
$strippedContent = preg_replace($pattern, '', $sourceCode); // 删除`<style>`标签及其内容
$pattern = '/<script\b[^>]*>(.*?)<\/script>/s'; // 定义匹配`<script>`标签及其内容的正则表达式
$strippedContent = preg_replace($pattern, '', $strippedContent); // 删除`<script>`标签及其内容
$pattern = '/<link\b[^>]*>/'; // 定义匹配 `<link>` 标签的正则表达式
$strippedContent = preg_replace($pattern, '', $strippedContent); // 删除 `<link>` 标签
$pattern = '/<footer\b[^>]*>(.*?)<\/footer>/s'; // 定义匹配`<script>`标签及其内容的正则表达式
$strippedContent = preg_replace($pattern, '', $strippedContent); // 删除`<script>`标签及其内容
$pattern = '/>([^<]+)</'; // 定义匹配中间内容不是标签的正则表达式
$matches = array();
preg_match_all($pattern, $strippedContent, $matches);
$textContentArray = array_filter($matches[1], function($item) {
return !empty(trim($item));
});
$textContentArray = array_values($textContentArray);
$uniqueArray = array_unique($textContentArray);
return $this->success($uniqueArray);
}
}