|
...
|
...
|
@@ -102,7 +102,7 @@ class HtmlCollect extends Command |
|
|
|
$source_list = $this->html_preg($new_html, $project_id, $collect_info->domain, $old_info['web_url_domain'], $old_info['home_url']);
|
|
|
|
|
|
|
|
if ($source_list) {
|
|
|
|
$html = $this->upload_source($html, $source_list, $project_id);
|
|
|
|
$html = $this->upload_source($html, $source_list, $project_id, $collect_info->domain, $old_info['web_url_domain'], $old_info['home_url']);
|
|
|
|
}
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
$collect_info->status = CollectTask::STATUS_FAIL;
|
|
...
|
...
|
@@ -321,7 +321,7 @@ class HtmlCollect extends Command |
|
|
|
}
|
|
|
|
|
|
|
|
//下载并替换资源
|
|
|
|
protected function upload_source($html, $source, $project_id)
|
|
|
|
protected function upload_source($html, $source, $project_id, $domain, $web_url_domain, $home_url)
|
|
|
|
{
|
|
|
|
foreach ($source as $vs) {
|
|
|
|
|
|
...
|
...
|
@@ -337,21 +337,17 @@ class HtmlCollect extends Command |
|
|
|
]);
|
|
|
|
$html = str_replace($vs['url'], getImageUrl($new_source), $html);
|
|
|
|
|
|
|
|
if (substr($new_source, -3, 3) == 'css' || substr($new_source, -2, 2) == 'js') {
|
|
|
|
$source_html = curl_c($vs['url_complete'], false);
|
|
|
|
if (substr($new_source, -3, 3) == 'css') {
|
|
|
|
preg_match_all("/url\(['\"](\s*[^>]+?)['\"]\)/i", $source_html, $result_source);
|
|
|
|
} else {
|
|
|
|
preg_match_all("/[large|thumb]+URL:['\"]+(\s*[^>]+?)['\"]+,/i", $source_html, $result_source);
|
|
|
|
}
|
|
|
|
$source_list = $result_source[1] ?? [];
|
|
|
|
if (substr($new_source, -3, 3) == 'css') {
|
|
|
|
// 下载css文件中的资源
|
|
|
|
$css_html = curl_c($vs['url_complete'], false);
|
|
|
|
preg_match_all("/url\(['\"](\s*[^>]+?)['\"]\)/i", $css_html, $result_css_source);
|
|
|
|
$css_source = $result_css_source[1] ?? [];
|
|
|
|
|
|
|
|
$url_arr = explode('/', $vs['url_complete']);
|
|
|
|
$target_arr = explode('/', $new_source);
|
|
|
|
foreach ($source_list as $vcs) {
|
|
|
|
foreach ($css_source as $vcs) {
|
|
|
|
$vcs = str_replace('"', '', $vcs);
|
|
|
|
$vcs_arr = parse_url($vcs);
|
|
|
|
|
|
|
|
if (isset($vcs_arr['domain'])) {
|
|
|
|
//不是相对路径,不下载
|
|
|
|
continue;
|
|
...
|
...
|
@@ -391,6 +387,34 @@ class HtmlCollect extends Command |
|
|
|
]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} elseif (substr($new_source, -2, 2) == 'js') {
|
|
|
|
$js_html = curl_c(getImageUrl($new_source), false);
|
|
|
|
preg_match_all("/[large|thumb]+URL:['\"]+(\s*[^>]+?)['\"]+,/i", $js_html, $result_js_source);
|
|
|
|
$js_source = $result_js_source[1] ?? [];
|
|
|
|
foreach ($js_source as $vjs) {
|
|
|
|
$vjs_result = $this->url_check($vjs, $project_id, $domain, $web_url_domain, $home_url);
|
|
|
|
if (!$vjs_result) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($vjs_result['download']) {
|
|
|
|
$new_vjs = CosService::uploadRemote($project_id, 'source', $vjs_result['url_complete']);
|
|
|
|
if ($new_vjs) {
|
|
|
|
CollectSource::insert([
|
|
|
|
'project_id' => $project_id,
|
|
|
|
'origin' => $vjs_result['url'],
|
|
|
|
'target' => $new_vjs,
|
|
|
|
'created_at' => date('Y-m-d H:i:s'),
|
|
|
|
'updated_at' => date('Y-m-d H:i:s'),
|
|
|
|
]);
|
|
|
|
$js_html = str_replace($vjs, getImageUrl($new_vjs), $js_html);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$js_html = str_replace($vjs, getImageUrl($vjs_result['url_complete']), $js_html);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CosService::uploadRemote($project_id, 'source', $new_source, $new_source, $js_html);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
...
|
...
|
|