作者 刘锟

合并分支 'akun' 到 'master'

Akun



查看合并请求 !213
... ... @@ -122,19 +122,19 @@ class ProjectImport extends Command
$total_count += 1;
try {
if ($task->type == ImportTask::TYPE_NEWS) {
if ((new NewsLogic())->importNews($task->project_id, $task->user_id, $v)) {
if ((new NewsLogic())->importNews($task->project_id, $task->user_id, $task->domain, $v)) {
$success_count += 1;
} else {
$repeat_count += 1;
}
} elseif ($task->type == ImportTask::TYPE_BLOG) {
if ((new BlogLogic())->importBlog($task->project_id, $task->user_id, $v)) {
if ((new BlogLogic())->importBlog($task->project_id, $task->user_id, $task->domain, $v)) {
$success_count += 1;
} else {
$repeat_count += 1;
}
} else {
if ((new ProductLogic())->importProduct($task->project_id, $task->user_id, $v)) {
if ((new ProductLogic())->importProduct($task->project_id, $task->user_id, $task->domain, $v)) {
$success_count += 1;
} else {
$repeat_count += 1;
... ...
... ... @@ -654,40 +654,41 @@ function redis_add($key,$val,$ttl=3600){
/**
* 判断远程地址是否需要下载
* @param $url
* @param $project_id
* @param $domain
* @param $is_complete
* @author Akun
* @return bool
* @date 2023/12/08 14:17
*/
function check_remote_url_down($url){
if(!$url){
return false;
}
function check_remote_url_down($url,$project_id,$domain,$is_complete=0){
if(substr($url,0,2) == '//'){
return false;
if (!$url) {
return '';
}
$arr = parse_url($url);
$scheme = $arr['scheme'] ?? '';
$host = $arr['host'] ?? '';
$path = $arr['path'] ?? '';
if($scheme && !in_array($scheme,['http','https'])){
return false;
}
if(!$host){
return false;
}
$host_arr = explode('.',$host);
if(strpos($host_arr[0],'cdn') !== false){
return false;
}
$path = $arr['path'] ?? '';
if(strpos($path, '.') === false){
$url_complete = ($scheme ?: 'https') . '://' . ($host ?: $domain) . $path;
if (
(empty($scheme) || $scheme == 'https' || $scheme == 'http')
&& (empty($host) || (strpos($host_arr[0], 'cdn') === false))
&& $path
&& (substr($path, 0, 1) == '/')
&& (strpos($path, '.') !== false)
) {
$new_url = CosService::uploadRemote($project_id,'image_product',$url_complete);
if($new_url){
return $is_complete ? getImageUrl($new_url) : $new_url;
}else{
return false;
}
}else{
return false;
}
return true;
}
... ...
... ... @@ -224,13 +224,14 @@ class BlogLogic extends BaseLogic
* 博客导入
* @param $project_id
* @param $user_id
* @param $domain
* @param $data
* @return bool
* @throws \Exception
* @author Akun
* @date 2023/09/20 17:51
*/
public function importBlog($project_id, $user_id, $data)
public function importBlog($project_id, $user_id, $domain, $data)
{
$route = $data[1]??'';//自定义路由
if($route){
... ... @@ -253,7 +254,8 @@ class BlogLogic extends BaseLogic
preg_match_all('/<img\s+[^>]*?src\s*=\s*(\'|\")(.*?)\\1[^>]*?\/?\s*>/i', $data[4], $result);
if($result[2]??[]){
foreach ($result[2] as $img){
check_remote_url_down($img) && $data[4] = str_replace($img,getImageUrl(CosService::uploadRemote($project_id,'image_news',$img)),$data[4]);
$new_img = check_remote_url_down($img,$project_id,$domain,1);
$new_img && $data[4] = str_replace($img,$new_img,$data[4]);
}
}
... ... @@ -261,7 +263,8 @@ class BlogLogic extends BaseLogic
preg_match_all('/<source\s+[^>]*?src\s*=\s*(\'|\")(.*?)\\1[^>]*?\/?\s*>/i', $data[4], $result_video);
if($result_video[2]??[]){
foreach ($result_video[2] as $video){
check_remote_url_down($video) && $data[4] = str_replace($video,getImageUrl(CosService::uploadRemote($project_id,'image_news',$video)),$data[4]);
$new_video = check_remote_url_down($video,$project_id,$domain,1);
$new_video && $data[4] = str_replace($video,$new_video,$data[4]);
}
}
... ... @@ -270,7 +273,10 @@ class BlogLogic extends BaseLogic
$img = '';
if($data[5]??''){
$img = check_remote_url_down($data[5]) ? CosService::uploadRemote($project_id, 'image_news', $data[5]) : $data[5];
$one_img = check_remote_url_down($data[5],$project_id,$domain);
if($one_img){
$img = $one_img;
}
}
$seo_title = '';
... ...
... ... @@ -257,13 +257,14 @@ class NewsLogic extends BaseLogic
* 新闻导入
* @param $project_id
* @param $user_id
* @param $domain
* @param $data
* @return bool
* @throws \Exception
* @author Akun
* @date 2023/09/20 17:51
*/
public function importNews($project_id, $user_id, $data)
public function importNews($project_id, $user_id, $domain, $data)
{
$route = $data[1]??'';//自定义路由
if($route){
... ... @@ -286,7 +287,8 @@ class NewsLogic extends BaseLogic
preg_match_all('/<img\s+[^>]*?src\s*=\s*(\'|\")(.*?)\\1[^>]*?\/?\s*>/i', $data[4], $result);
if($result[2]??[]){
foreach ($result[2] as $img){
check_remote_url_down($img) && $data[4] = str_replace($img,getImageUrl(CosService::uploadRemote($project_id,'image_news',$img)),$data[4]);
$new_img = check_remote_url_down($img,$project_id,$domain,1);
$new_img && $data[4] = str_replace($img,$new_img,$data[4]);
}
}
... ... @@ -294,7 +296,8 @@ class NewsLogic extends BaseLogic
preg_match_all('/<source\s+[^>]*?src\s*=\s*(\'|\")(.*?)\\1[^>]*?\/?\s*>/i', $data[4], $result_video);
if($result_video[2]??[]){
foreach ($result_video[2] as $video){
check_remote_url_down($video) && $data[4] = str_replace($video,getImageUrl(CosService::uploadRemote($project_id,'image_news',$video)),$data[4]);
$new_video = check_remote_url_down($video,$project_id,$domain,1);
$new_video && $data[4] = str_replace($video,$new_video,$data[4]);
}
}
... ... @@ -303,7 +306,10 @@ class NewsLogic extends BaseLogic
$img = '';
if($data[5]??''){
$img = check_remote_url_down($data[5]) ? CosService::uploadRemote($project_id, 'image_news', $data[5]) : $data[5];
$one_img = check_remote_url_down($data[5],$project_id,$domain);
if($one_img){
$img = $one_img;
}
}
$seo_title = '';
... ...
... ... @@ -584,13 +584,14 @@ class ProductLogic extends BaseLogic
* 产品导入
* @param $project_id
* @param $user_id
* @param $domain
* @param $data
* @return bool
* @throws \Exception
* @author Akun
* @date 2023/09/21 14:55
*/
public function importProduct($project_id, $user_id, $data)
public function importProduct($project_id, $user_id, $domain, $data)
{
$route = $data[1]??'';//自定义路由
if($route){
... ... @@ -622,7 +623,7 @@ class ProductLogic extends BaseLogic
$img_arr = explode('^v6sp$',$data[7]);
foreach ($img_arr as $v_img){
if($v_img){
$one_img = check_remote_url_down($v_img) ? CosService::uploadRemote($project_id,'image_product',$v_img) : $v_img;
$one_img = check_remote_url_down($v_img,$project_id,$domain);
if($one_img){
$one_gallery = [
'alt' => '这是一张产品图',
... ... @@ -645,7 +646,8 @@ class ProductLogic extends BaseLogic
preg_match_all('/<img\s+[^>]*?src\s*=\s*(\'|\")(.*?)\\1[^>]*?\/?\s*>/i', $data[5], $result_intro);
if($result_intro[2]??[]){
foreach ($result_intro[2] as $vi_img){
check_remote_url_down($vi_img) && $data[5] = str_replace($vi_img,getImageUrl(CosService::uploadRemote($project_id,'image_product',$vi_img)),$data[5]);
$new_vi_img = check_remote_url_down($vi_img,$project_id,$domain,1);
$new_vi_img && $data[5] = str_replace($vi_img,$new_vi_img,$data[5]);
}
}
... ... @@ -653,7 +655,8 @@ class ProductLogic extends BaseLogic
preg_match_all('/<source\s+[^>]*?src\s*=\s*(\'|\")(.*?)\\1[^>]*?\/?\s*>/i', $data[5], $result_intro_video);
if($result_intro_video[2]??[]){
foreach ($result_intro_video[2] as $vi_video){
check_remote_url_down($vi_video) && $data[5] = str_replace($vi_video,getImageUrl(CosService::uploadRemote($project_id,'image_product',$vi_video)),$data[5]);
$new_vi_video = check_remote_url_down($vi_video,$project_id,$domain,1);
$new_vi_video && $data[5] = str_replace($vi_video,$new_vi_video,$data[5]);
}
}
... ... @@ -666,7 +669,8 @@ class ProductLogic extends BaseLogic
preg_match_all('/<img\s+[^>]*?src\s*=\s*(\'|\")(.*?)\\1[^>]*?\/?\s*>/i', $data[6], $result_content);
if($result_content[2]??[]){
foreach ($result_content[2] as $vc_img){
check_remote_url_down($vc_img) && $data[6] = str_replace($vc_img,getImageUrl(CosService::uploadRemote($project_id,'image_product',$vc_img)),$data[6]);
$new_vc_img = check_remote_url_down($vc_img,$project_id,$domain,1);
$new_vc_img && $data[6] = str_replace($vc_img,$new_vc_img,$data[6]);
}
}
... ... @@ -674,7 +678,8 @@ class ProductLogic extends BaseLogic
preg_match_all('/<source\s+[^>]*?src\s*=\s*(\'|\")(.*?)\\1[^>]*?\/?\s*>/i', $data[6], $result_content_video);
if($result_content_video[2]??[]){
foreach ($result_content_video[2] as $vc_video){
check_remote_url_down($vc_video) && $data[6] = str_replace($vc_video,getImageUrl(CosService::uploadRemote($project_id,'image_product',$vc_video)),$data[6]);
$new_vc_video = check_remote_url_down($vc_video,$project_id,$domain,1);
$new_vc_video && $data[6] = str_replace($vc_video,$new_vc_video,$data[6]);
}
}
... ... @@ -715,7 +720,8 @@ class ProductLogic extends BaseLogic
if($result_desc[2]??[]){
foreach ($result_desc[2] as $vdesc_img){
check_remote_url_down($vdesc_img) && $v_desc['text'] = str_replace($vdesc_img,getImageUrl(CosService::uploadRemote($project_id,'image_product',$vdesc_img)),$v_desc['text']);
$new_vdesc_img = check_remote_url_down($vdesc_img,$project_id,$domain,1);
$new_vdesc_img && $v_desc['text'] = str_replace($vdesc_img,$new_vdesc_img,$v_desc['text']);
}
}
... ... @@ -723,19 +729,32 @@ class ProductLogic extends BaseLogic
preg_match_all('/<source\s+[^>]*?src\s*=\s*(\'|\")(.*?)\\1[^>]*?\/?\s*>/i', $v_desc['text'], $result_desc_video);
if($result_desc_video[2]??[]){
foreach ($result_desc_video[2] as $vdesc_video){
check_remote_url_down($vdesc_video) && $v_desc['text'] = str_replace($vdesc_video,getImageUrl(CosService::uploadRemote($project_id,'image_product',$vdesc_video)),$v_desc['text']);
$new_vdesc_video = check_remote_url_down($vdesc_video,$project_id,$domain,1);
$new_vdesc_video && $v_desc['text'] = str_replace($vdesc_video,$new_vdesc_video,$v_desc['text']);
}
}
}
}
//处理参数
$attrs = [];
if($data[4]??''){
$attr_arr = json_decode($data[4],true);
foreach ($attr_arr as $ka=>$va){
$attrs[] = [
'key' => $ka,
'value' => $va
];
}
}
$id = $this->model->addReturnId(
[
'project_id' => $project_id,
'title' => $data[0],
'thumb' => $thumb,
'gallery' => Arr::a2s($gallery),
'attrs' => trim($data[4]) ? $data[4] : Arr::a2s([]),
'attrs' => Arr::a2s($attrs),
'category_id' => $category_id,
'keyword_id' => $keyword_id,
'intro' => $intro,
... ...