|
...
|
...
|
@@ -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'],
|
|
...
|
...
|
@@ -139,7 +140,7 @@ class ProjectUpdate extends Command |
|
|
|
'seo_keywords' => $item['seo_keywords'] ?? '',
|
|
|
|
'seo_description' => $item['seo_description'] ?? '',
|
|
|
|
]);
|
|
|
|
$route = RouteMap::setRoute($item['url'] ? $this->get_url_route($item['url']) : $item['name'], RouteMap::SOURCE_PRODUCT_KEYWORD, $id, $project_id);
|
|
|
|
$route = $this->set_map($this->get_url_route($item['url']), RouteMap::SOURCE_PRODUCT_KEYWORD, $id, $project_id);
|
|
|
|
$model->edit(['route' => $route], ['id' => $id]);
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
echo 'date:' . date('Y-m-d H:i:s') . ', task_id: ' . $task->id . ', error: ' . $e->getMessage() . PHP_EOL;
|
|
...
|
...
|
@@ -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'],
|
|
...
|
...
|
@@ -271,7 +273,7 @@ class ProjectUpdate extends Command |
|
|
|
]),
|
|
|
|
'status' => Product::STATUS_ON
|
|
|
|
]);
|
|
|
|
$route = RouteMap::setRoute($item['url'] ? $this->get_url_route($item['url']) : $item['ttile'], RouteMap::SOURCE_PRODUCT, $id, $project_id);
|
|
|
|
$route = $this->set_map($this->get_url_route($item['url']), RouteMap::SOURCE_PRODUCT, $id, $project_id);
|
|
|
|
$model->edit(['route' => $route], ['id' => $id]);
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
echo 'date:' . date('Y-m-d H:i:s') . ', task_id: ' . $task->id . ', error: ' . $e->getMessage() . PHP_EOL;
|
|
...
|
...
|
@@ -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'],
|
|
...
|
...
|
@@ -325,7 +328,7 @@ class ProjectUpdate extends Command |
|
|
|
'image' => $item['images'][0] ?? '',
|
|
|
|
'status' => $api_type == 'news' ? News::STATUS_ONE : Blog::STATUS_ONE
|
|
|
|
]);
|
|
|
|
$route = RouteMap::setRoute($item['url'] ? $this->get_url_route($item['url']) : $item['ttile'], $api_type == 'news' ? RouteMap::SOURCE_NEWS : RouteMap::SOURCE_BLOG, $id, $project_id);
|
|
|
|
$route = $this->set_map($this->get_url_route($item['url']), $api_type == 'news' ? RouteMap::SOURCE_NEWS : RouteMap::SOURCE_BLOG, $id, $project_id);
|
|
|
|
$model->edit(['url' => $route], ['id' => $id]);
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
echo 'date:' . date('Y-m-d H:i:s') . ', task_id: ' . $task->id . ', error: ' . $e->getMessage() . PHP_EOL;
|
|
...
|
...
|
@@ -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'],
|
|
...
|
...
|
@@ -373,7 +377,7 @@ class ProjectUpdate extends Command |
|
|
|
'html' => $item['content'] ?? '',
|
|
|
|
'status' => 1
|
|
|
|
]);
|
|
|
|
$route = RouteMap::setRoute($item['url'] ? $this->get_url_route($item['url']) : $item['ttile'], RouteMap::SOURCE_PAGE, $id, $project_id);
|
|
|
|
$route = $this->set_map($this->get_url_route($item['url']), RouteMap::SOURCE_PAGE, $id, $project_id);
|
|
|
|
$model->edit(['url' => $route], ['id' => $id]);
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
echo 'date:' . date('Y-m-d H:i:s') . ', task_id: ' . $task->id . ', error: ' . $e->getMessage() . PHP_EOL;
|
|
...
|
...
|
@@ -429,8 +433,19 @@ class ProjectUpdate extends Command |
|
|
|
//获取地址路由
|
|
|
|
protected function get_url_route($url)
|
|
|
|
{
|
|
|
|
$arr = explode('/', $url);
|
|
|
|
return $arr[count($arr) - 2];
|
|
|
|
$arr = parse_url($url);
|
|
|
|
if (empty($arr['path'])) {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
$path = $arr['path'];
|
|
|
|
|
|
|
|
if (strpos($path, '.') !== false) {
|
|
|
|
$path = substr($path, 0, strpos($path, '.'));
|
|
|
|
}
|
|
|
|
|
|
|
|
$path_arr = explode('/', $path);
|
|
|
|
|
|
|
|
return end($path_arr) ? end($path_arr) : $path_arr[count($path_arr) - 2];
|
|
|
|
}
|
|
|
|
|
|
|
|
//多级分类入库
|
|
...
|
...
|
@@ -442,6 +457,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'],
|
|
...
|
...
|
@@ -449,7 +465,7 @@ class ProjectUpdate extends Command |
|
|
|
'keywords' => $item['keywords'] ?? '',
|
|
|
|
'describe' => $item['description'] ?? ''
|
|
|
|
]);
|
|
|
|
$route = RouteMap::setRoute($item['url'] ? $this->get_url_route($item['url']) : $item['name'], RouteMap::SOURCE_PRODUCT_CATE, $parent_id, $project_id);
|
|
|
|
$route = $this->set_map($this->get_url_route($item['url']), RouteMap::SOURCE_PRODUCT_CATE, $parent_id, $project_id);
|
|
|
|
$model->edit(['route' => $route], ['id' => $parent_id]);
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
echo 'date:' . date('Y-m-d H:i:s') . ', category_insert error: ' . $e->getMessage() . PHP_EOL;
|
|
...
|
...
|
@@ -477,4 +493,51 @@ class ProjectUpdate extends Command |
|
|
|
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
|
|
|
|
//特殊字符转换
|
|
|
|
protected function special2str($str)
|
|
|
|
{
|
|
|
|
if (strpos($str, ';') === false) {
|
|
|
|
return $str;
|
|
|
|
}
|
|
|
|
|
|
|
|
$list = [
|
|
|
|
'<' => '<',
|
|
|
|
'>' => '>',
|
|
|
|
'&' => '&',
|
|
|
|
'´' => '´',
|
|
|
|
'"' => '“',
|
|
|
|
' ' => ' '
|
|
|
|
];
|
|
|
|
|
|
|
|
foreach ($list as $k => $v) {
|
|
|
|
$str = str_replace($k, $v, $str);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $str;
|
|
|
|
}
|
|
|
|
|
|
|
|
//路由入库
|
|
|
|
protected function set_map($route, $source, $source_id, $project_id)
|
|
|
|
{
|
|
|
|
if (empty($route)) {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
|
|
|
|
$route_map = new RouteMap();
|
|
|
|
$route_map->project_id = $project_id;
|
|
|
|
$route_map->source = $source;
|
|
|
|
$route_map->source_id = $source_id;
|
|
|
|
$route_map->route = $route;
|
|
|
|
|
|
|
|
if ($source == RouteMap::SOURCE_NEWS) {
|
|
|
|
$route_map->path = RouteMap::SOURCE_NEWS;
|
|
|
|
} elseif ($source == RouteMap::SOURCE_BLOG) {
|
|
|
|
$route_map->path = RouteMap::SOURCE_BLOG;
|
|
|
|
}
|
|
|
|
|
|
|
|
$route_map->save();
|
|
|
|
|
|
|
|
return $route;
|
|
|
|
}
|
|
|
|
} |
...
|
...
|
|