作者 刘锟

update

... ... @@ -80,21 +80,21 @@ class ProjectUpdate extends Command
//获取网站配置
$link_type = 0;
$url_web_config = 'https://' . $domain_arr['host'] . '/wp-content/cache/user_config.text';
$data_config = http_get($url_web_config, ['charset' => 'UTF-8']);
$data_config = curl_c($url_web_config);
if ($data_config) {
$link_type = $data_config['link_type'];
}
//获取所有语种
$language_list = [];
$url_language = 'https://' . $domain_arr['host'] . '/wp-content/plugins/proofreading/json/user_language.json';
$data_language = http_get($url_language, ['charset' => 'UTF-8']);
$data_language = curl_c($url_language);
if ($data_language) {
$language_list = array_column($data_language, 'short');
}
//获取所有页面
$page_list = [];
$url_page = 'https://' . $domain_arr['host'] . '/wp-content/cache/pages_list.json';
$data_page = http_get($url_page, ['charset' => 'UTF-8']);
$data_page = curl_c($url_page);
if ($data_page) {
$page_list = array_column($data_page, 'path');
}
... ... @@ -105,7 +105,7 @@ class ProjectUpdate extends Command
if ($api_type == 'category') {
//分类
$url = $api_url . '?' . http_build_query(['w' => 'category']);
$data = http_get($url, ['charset' => 'UTF-8']);
$data = curl_c($url);
if (isset($data['code']) && $data['code'] == 200) {
$items = $data['data'] ?? [];
$this->category_insert($project_id, $items, 0);
... ... @@ -115,14 +115,14 @@ class ProjectUpdate extends Command
} elseif ($api_type == 'tag') {
//关键词
$url = $api_url . '?' . http_build_query(['w' => 'tag', 'page' => 1, 'pagesize' => 0]);
$data = http_get($url, ['charset' => 'UTF-8']);
$data = curl_c($url);
if (isset($data['code']) && $data['code'] == 200) {
$count = $data['data']['count'] ?? 0;
$total_page = ceil($count / $page_size);
for ($page = 1; $page <= $total_page; $page++) {
$url_page = $api_url . '?' . http_build_query(['w' => 'tag', 'page' => $page, 'pagesize' => $page_size]);
$data_page = http_get($url_page, ['charset' => 'UTF-8']);
$data_page = curl_c($url_page);
if (isset($data_page['code']) && $data_page['code'] == 200) {
$items = $data_page['data']['data'] ?? [];
... ... @@ -132,6 +132,7 @@ class ProjectUpdate extends Command
$keyword = $model->read(['title' => $item['name']], 'id');
if (!$keyword) {
try {
$item['name'] = $this->special2str($item['name']);
$id = $model->addReturnId([
'project_id' => $project_id,
'title' => $item['name'],
... ... @@ -160,7 +161,7 @@ class ProjectUpdate extends Command
} elseif ($api_type == 'website_info') {
//网站信息
$url = $api_url . '?' . http_build_query(['w' => 'website_info']);
$data = http_get($url, ['charset' => 'UTF-8']);
$data = curl_c($url);
if (isset($data['code']) && $data['code'] == 200) {
$phones = $data['data']['phones'] ?? '';
$emails = $data['data']['emails'] ?? '';
... ... @@ -212,14 +213,14 @@ class ProjectUpdate extends Command
} elseif ($api_type == 'post') {
//产品
$url = $api_url . '?' . http_build_query(['w' => 'post', 'page' => 1, 'pagesize' => 0]);
$data = http_get($url, ['charset' => 'UTF-8']);
$data = curl_c($url);
if (isset($data['code']) && $data['code'] == 200) {
$count = $data['data']['count'] ?? 0;
$total_page = ceil($count / $page_size);
for ($page = 1; $page <= $total_page; $page++) {
$url_page = $api_url . '?' . http_build_query(['w' => 'post', 'page' => $page, 'pagesize' => $page_size]);
$data_page = http_get($url_page, ['charset' => 'UTF-8']);
$data_page = curl_c($url_page);
if (isset($data_page['code']) && $data_page['code'] == 200) {
$items = $data_page['data']['data'] ?? [];
... ... @@ -256,6 +257,7 @@ class ProjectUpdate extends Command
}
}
try {
$item['ttile'] = $this->special2str($item['ttile']);
$id = $model->addReturnId([
'project_id' => $project_id,
'title' => $item['ttile'],
... ... @@ -292,14 +294,14 @@ class ProjectUpdate extends Command
} elseif ($api_type == 'news' || $api_type == 'blog') {
//新闻或博客
$url = $api_url . '?' . http_build_query(['w' => $api_type, 'page' => 1, 'pagesize' => 0]);
$data = http_get($url, ['charset' => 'UTF-8']);
$data = curl_c($url);
if (isset($data['code']) && $data['code'] == 200) {
$count = $data['data']['count'] ?? 0;
$total_page = ceil($count / $page_size);
for ($page = 1; $page <= $total_page; $page++) {
$url_page = $api_url . '?' . http_build_query(['w' => $api_type, 'page' => $page, 'pagesize' => $page_size]);
$data_page = http_get($url_page, ['charset' => 'UTF-8']);
$data_page = curl_c($url_page);
if (isset($data_page['code']) && $data_page['code'] == 200) {
$items = $data_page['data']['data'] ?? [];
... ... @@ -315,6 +317,7 @@ class ProjectUpdate extends Command
$news = $model->read(['name' => $item['ttile']], 'id');
if (!$news) {
try {
$item['ttile'] = $this->special2str($item['ttile']);
$id = $model->addReturnId([
'project_id' => $project_id,
'name' => $item['ttile'],
... ... @@ -346,14 +349,14 @@ class ProjectUpdate extends Command
} else {
//单页
$url = $api_url . '?' . http_build_query(['w' => 'page', 'page' => 1, 'pagesize' => 0]);
$data = http_get($url, ['charset' => 'UTF-8']);
$data = curl_c($url);
if (isset($data['code']) && $data['code'] == 200) {
$count = $data['data']['count'] ?? 0;
$total_page = ceil($count / $page_size);
for ($page = 1; $page <= $total_page; $page++) {
$url_page = $api_url . '?' . http_build_query(['w' => 'page', 'page' => $page, 'pagesize' => $page_size]);
$data_page = http_get($url_page, ['charset' => 'UTF-8']);
$data_page = curl_c($url_page);
if (isset($data_page['code']) && $data_page['code'] == 200) {
$items = $data_page['data']['data'] ?? [];
... ... @@ -364,6 +367,7 @@ class ProjectUpdate extends Command
$custom = $model->read(['name' => $item['ttile']], 'id');
if (!$custom) {
try {
$item['ttile'] = $this->special2str($item['ttile']);
$id = $model->addReturnId([
'project_id' => $project_id,
'name' => $item['ttile'],
... ... @@ -442,6 +446,7 @@ class ProjectUpdate extends Command
$parent = $model->read(['pid' => $pid, 'title' => $item['name']], 'id');
if (!$parent) {
try {
$item['name'] = $this->special2str($item['name']);
$parent_id = $model->addReturnId([
'project_id' => $project_id,
'title' => $item['name'],
... ... @@ -477,4 +482,27 @@ class ProjectUpdate extends Command
return [];
}
//特殊字符转换
protected function special2str($str)
{
if (strpos($str, ';') === false) {
return $str;
}
$list = [
'&lt;' => '<',
'&gt;' => '>',
'&amp;' => '&',
'&acute;' => '´',
'&quot;' => '“',
'&nbsp;' => ' '
];
foreach ($list as $k => $v) {
$str = str_replace($k, $v, $str);
}
return $str;
}
}
... ...
... ... @@ -108,6 +108,36 @@ if (!function_exists('http_get')) {
}
}
if (!function_exists('curl_c')) {
/**
* @param $url
* @return []
* @author Akun
* @date 2023/11/22 11:33
*/
function curl_c($url){
$header = array(
'Expect:',
'Content-Type: application/json; charset=utf-8'
);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/42.0.2311.135 Safari/537.36 Edge/12.246');
curl_setopt($ch, CURLOPT_AUTOREFERER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 120);
curl_setopt($ch, CURLOPT_TIMEOUT, 120);
curl_setopt($ch, CURLOPT_MAXREDIRS, 10);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSLVERSION, 'all');
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
$content = curl_exec($ch);
curl_close($ch);
return json_decode($content, true);
}
}
if (!function_exists('_get_child')) {
/**
... ...