Merge branch 'master' of http://47.244.231.31:8099/zhl/globalso-v6
正在显示
5 个修改的文件
包含
109 行增加
和
384 行删除
| @@ -39,14 +39,15 @@ class HtmlCollect extends Command | @@ -39,14 +39,15 @@ class HtmlCollect extends Command | ||
| 39 | 39 | ||
| 40 | public function handle() | 40 | public function handle() |
| 41 | { | 41 | { |
| 42 | - while (true) { | 42 | +// while (true) { |
| 43 | $this->start_collect(); | 43 | $this->start_collect(); |
| 44 | - } | 44 | +// } |
| 45 | } | 45 | } |
| 46 | 46 | ||
| 47 | protected function start_collect() | 47 | protected function start_collect() |
| 48 | { | 48 | { |
| 49 | - $task_id = $this->get_task(); | 49 | +// $task_id = $this->get_task(); |
| 50 | + $task_id = '437_5995'; | ||
| 50 | if ($task_id === false) { | 51 | if ($task_id === false) { |
| 51 | //所有项目采集完成 | 52 | //所有项目采集完成 |
| 52 | sleep(60); | 53 | sleep(60); |
| @@ -291,7 +292,8 @@ class HtmlCollect extends Command | @@ -291,7 +292,8 @@ class HtmlCollect extends Command | ||
| 291 | 292 | ||
| 292 | $path_arr = explode('.', $path); | 293 | $path_arr = explode('.', $path); |
| 293 | if ( | 294 | if ( |
| 294 | - (empty($host) || $host == $web_url_domain || $host == $home_url) | 295 | + (empty($scheme) || $scheme == 'https' || $scheme == 'http') |
| 296 | + && (empty($host) || $host == $web_url_domain || $host == $home_url) | ||
| 295 | && $path | 297 | && $path |
| 296 | && (strpos($path, '.') !== false) | 298 | && (strpos($path, '.') !== false) |
| 297 | && (!in_array(end($path_arr), ['html', 'php', 'com', 'xml'])) | 299 | && (!in_array(end($path_arr), ['html', 'php', 'com', 'xml'])) |
| @@ -335,17 +337,21 @@ class HtmlCollect extends Command | @@ -335,17 +337,21 @@ class HtmlCollect extends Command | ||
| 335 | ]); | 337 | ]); |
| 336 | $html = str_replace($vs['url'], getImageUrl($new_source), $html); | 338 | $html = str_replace($vs['url'], getImageUrl($new_source), $html); |
| 337 | 339 | ||
| 340 | + if (substr($new_source, -3, 3) == 'css' || substr($new_source, -2, 2) == 'js') { | ||
| 341 | + $source_html = curl_c($vs['url_complete'], false); | ||
| 338 | if (substr($new_source, -3, 3) == 'css') { | 342 | if (substr($new_source, -3, 3) == 'css') { |
| 339 | - // 下载css文件中的资源 | ||
| 340 | - $css_html = curl_c($vs['url_complete'], false); | ||
| 341 | - preg_match_all("/url\(['\"](\s*[^>]+?)['\"]\)/i", $css_html, $result_css_source); | ||
| 342 | - $css_source = $result_css_source[1] ?? []; | 343 | + preg_match_all("/url\(['\"](\s*[^>]+?)['\"]\)/i", $source_html, $result_source); |
| 344 | + } else { | ||
| 345 | + preg_match_all("/[large|thumb]+URL:['\"]+(\s*[^>]+?)['\"]+,/i", $source_html, $result_source); | ||
| 346 | + } | ||
| 347 | + $source_list = $result_source[1] ?? []; | ||
| 343 | 348 | ||
| 344 | $url_arr = explode('/', $vs['url_complete']); | 349 | $url_arr = explode('/', $vs['url_complete']); |
| 345 | $target_arr = explode('/', $new_source); | 350 | $target_arr = explode('/', $new_source); |
| 346 | - foreach ($css_source as $vcs) { | 351 | + foreach ($source_list as $vcs) { |
| 347 | $vcs = str_replace('"', '', $vcs); | 352 | $vcs = str_replace('"', '', $vcs); |
| 348 | $vcs_arr = parse_url($vcs); | 353 | $vcs_arr = parse_url($vcs); |
| 354 | + | ||
| 349 | if (isset($vcs_arr['domain'])) { | 355 | if (isset($vcs_arr['domain'])) { |
| 350 | //不是相对路径,不下载 | 356 | //不是相对路径,不下载 |
| 351 | continue; | 357 | continue; |
| @@ -283,6 +283,9 @@ class HtmlLanguageCollect extends Command | @@ -283,6 +283,9 @@ class HtmlLanguageCollect extends Command | ||
| 283 | { | 283 | { |
| 284 | if ($url) { | 284 | if ($url) { |
| 285 | $url = str_replace('"', '', $url); | 285 | $url = str_replace('"', '', $url); |
| 286 | + if(strpos($url,'mailto:') !== false){ | ||
| 287 | + return false; | ||
| 288 | + } | ||
| 286 | $arr = parse_url($url); | 289 | $arr = parse_url($url); |
| 287 | $scheme = $arr['scheme'] ?? ''; | 290 | $scheme = $arr['scheme'] ?? ''; |
| 288 | $host = $arr['host'] ?? ''; | 291 | $host = $arr['host'] ?? ''; |
| @@ -291,7 +294,8 @@ class HtmlLanguageCollect extends Command | @@ -291,7 +294,8 @@ class HtmlLanguageCollect extends Command | ||
| 291 | 294 | ||
| 292 | $path_arr = explode('.', $path); | 295 | $path_arr = explode('.', $path); |
| 293 | if ( | 296 | if ( |
| 294 | - (empty($host) || $host == $web_url_domain || $host == $home_url) | 297 | + (empty($scheme) || $scheme == 'https' || $scheme == 'http') |
| 298 | + && (empty($host) || $host == $web_url_domain || $host == $home_url) | ||
| 295 | && $path | 299 | && $path |
| 296 | && (strpos($path, '.') !== false) | 300 | && (strpos($path, '.') !== false) |
| 297 | && (!in_array(end($path_arr), ['html', 'php', 'com', 'xml'])) | 301 | && (!in_array(end($path_arr), ['html', 'php', 'com', 'xml'])) |
| @@ -115,6 +115,7 @@ class ProjectUpdate extends Command | @@ -115,6 +115,7 @@ class ProjectUpdate extends Command | ||
| 115 | $page_list = array_column($data_page, 'path'); | 115 | $page_list = array_column($data_page, 'path'); |
| 116 | } | 116 | } |
| 117 | 117 | ||
| 118 | + $is_flush = 0; | ||
| 118 | //设置数据库 | 119 | //设置数据库 |
| 119 | $project = ProjectServer::useProject($project_id); | 120 | $project = ProjectServer::useProject($project_id); |
| 120 | if ($project) { | 121 | if ($project) { |
| @@ -318,6 +319,7 @@ class ProjectUpdate extends Command | @@ -318,6 +319,7 @@ class ProjectUpdate extends Command | ||
| 318 | $this->set_map($route, RouteMap::SOURCE_PRODUCT, $id, $project_id); | 319 | $this->set_map($route, RouteMap::SOURCE_PRODUCT, $id, $project_id); |
| 319 | 320 | ||
| 320 | CollectTask::_insert($item['url'], $project_id, RouteMap::SOURCE_PRODUCT, $id, $link_type, $language_list, $page_list); | 321 | CollectTask::_insert($item['url'], $project_id, RouteMap::SOURCE_PRODUCT, $id, $link_type, $language_list, $page_list); |
| 322 | + $is_flush = 1; | ||
| 321 | } catch (\Exception $e) { | 323 | } catch (\Exception $e) { |
| 322 | echo 'date:' . date('Y-m-d H:i:s') . ', task_id: ' . $task->id . ', error: ' . $e->getMessage() . PHP_EOL; | 324 | echo 'date:' . date('Y-m-d H:i:s') . ', task_id: ' . $task->id . ', error: ' . $e->getMessage() . PHP_EOL; |
| 323 | continue; | 325 | continue; |
| @@ -392,6 +394,7 @@ class ProjectUpdate extends Command | @@ -392,6 +394,7 @@ class ProjectUpdate extends Command | ||
| 392 | $this->set_map($route, $api_type == 'news' ? RouteMap::SOURCE_NEWS : RouteMap::SOURCE_BLOG, $id, $project_id); | 394 | $this->set_map($route, $api_type == 'news' ? RouteMap::SOURCE_NEWS : RouteMap::SOURCE_BLOG, $id, $project_id); |
| 393 | 395 | ||
| 394 | CollectTask::_insert($item['url'], $project_id, $api_type == 'news' ? RouteMap::SOURCE_NEWS : RouteMap::SOURCE_BLOG, $id, $link_type, $language_list, $page_list); | 396 | CollectTask::_insert($item['url'], $project_id, $api_type == 'news' ? RouteMap::SOURCE_NEWS : RouteMap::SOURCE_BLOG, $id, $link_type, $language_list, $page_list); |
| 397 | + $is_flush = 1; | ||
| 395 | } catch (\Exception $e) { | 398 | } catch (\Exception $e) { |
| 396 | echo 'date:' . date('Y-m-d H:i:s') . ', task_id: ' . $task->id . ', error: ' . $e->getMessage() . PHP_EOL; | 399 | echo 'date:' . date('Y-m-d H:i:s') . ', task_id: ' . $task->id . ', error: ' . $e->getMessage() . PHP_EOL; |
| 397 | continue; | 400 | continue; |
| @@ -444,6 +447,7 @@ class ProjectUpdate extends Command | @@ -444,6 +447,7 @@ class ProjectUpdate extends Command | ||
| 444 | $this->set_map($route, RouteMap::SOURCE_PAGE, $id, $project_id); | 447 | $this->set_map($route, RouteMap::SOURCE_PAGE, $id, $project_id); |
| 445 | 448 | ||
| 446 | CollectTask::_insert($item['url'], $project_id, RouteMap::SOURCE_PAGE, $id, $link_type, $language_list, $page_list); | 449 | CollectTask::_insert($item['url'], $project_id, RouteMap::SOURCE_PAGE, $id, $link_type, $language_list, $page_list); |
| 450 | + $is_flush = 1; | ||
| 447 | } catch (\Exception $e) { | 451 | } catch (\Exception $e) { |
| 448 | echo 'date:' . date('Y-m-d H:i:s') . ', task_id: ' . $task->id . ', error: ' . $e->getMessage() . PHP_EOL; | 452 | echo 'date:' . date('Y-m-d H:i:s') . ', task_id: ' . $task->id . ', error: ' . $e->getMessage() . PHP_EOL; |
| 449 | continue; | 453 | continue; |
| @@ -462,7 +466,7 @@ class ProjectUpdate extends Command | @@ -462,7 +466,7 @@ class ProjectUpdate extends Command | ||
| 462 | DB::disconnect('custom_mysql'); | 466 | DB::disconnect('custom_mysql'); |
| 463 | 467 | ||
| 464 | $task->status = UpdateLog::STATUS_COM;//同步完成 | 468 | $task->status = UpdateLog::STATUS_COM;//同步完成 |
| 465 | - if($api_type == 'post' || $api_type == 'page' || $api_type == 'news' || $api_type == 'blog'){ | 469 | + if($is_flush){ |
| 466 | $task->collect_status = UpdateLog::COLLECT_STATUS_UN; | 470 | $task->collect_status = UpdateLog::COLLECT_STATUS_UN; |
| 467 | } | 471 | } |
| 468 | $task->save(); | 472 | $task->save(); |
| 1 | -<?php | ||
| 2 | - | ||
| 3 | -namespace App\Console\Commands\Update; | ||
| 4 | - | ||
| 5 | -use App\Helper\Arr; | ||
| 6 | -use App\Http\Logic\Bside\Product\CategoryLogic; | ||
| 7 | -use App\Models\Collect\CollectSource; | ||
| 8 | -use App\Models\Collect\CollectTask; | ||
| 9 | -use App\Models\Com\UpdateLog; | ||
| 10 | -use App\Models\Product\Category; | ||
| 11 | -use App\Models\Product\Product; | ||
| 12 | -use App\Models\RouteMap\RouteMap; | ||
| 13 | -use App\Services\CosService; | ||
| 14 | -use App\Services\ProjectServer; | ||
| 15 | -use Illuminate\Console\Command; | ||
| 16 | -use Illuminate\Support\Facades\DB; | ||
| 17 | - | ||
| 18 | -/** | ||
| 19 | - * 4.0,5.0升级到6.0,内容同步 | ||
| 20 | - * Class ProjectImport | ||
| 21 | - * @package App\Console\Commands | ||
| 22 | - * @author Akun | ||
| 23 | - * @date 2023/10/9 15:04 | ||
| 24 | - */ | ||
| 25 | -class ProjectUpdateTemp extends Command | ||
| 26 | -{ | ||
| 27 | - /** | ||
| 28 | - * The name and signature of the console command. | ||
| 29 | - * | ||
| 30 | - * @var string | ||
| 31 | - */ | ||
| 32 | - protected $signature = 'project_update_temp'; | ||
| 33 | - | ||
| 34 | - /** | ||
| 35 | - * The console command description. | ||
| 36 | - * | ||
| 37 | - * @var string | ||
| 38 | - */ | ||
| 39 | - protected $description = '执行项目升级任务'; | ||
| 40 | - | ||
| 41 | - | ||
| 42 | - public function handle() | ||
| 43 | - { | ||
| 44 | - while (true) { | ||
| 45 | - $this->start_update(); | ||
| 46 | - } | ||
| 47 | - } | ||
| 48 | - | ||
| 49 | - protected function start_update() | ||
| 50 | - { | ||
| 51 | - $list = UpdateLog::where('api_type', 'category')->get(); | ||
| 52 | - | ||
| 53 | - foreach ($list as $task) { | ||
| 54 | - | ||
| 55 | - | ||
| 56 | - $project_id = $task->project_id; | ||
| 57 | - $api_type = $task->api_type; | ||
| 58 | - $api_url_arr = explode('?', $task->api_url); | ||
| 59 | - $api_url = $api_url_arr[0]; | ||
| 60 | - | ||
| 61 | - $page_size = 20; | ||
| 62 | - | ||
| 63 | - echo 'date:' . date('Y-m-d H:i:s') . ', task_id: ' . $task->id . ', task_type: ' . $api_type . ', update start' . PHP_EOL; | ||
| 64 | - | ||
| 65 | - $task->status = UpdateLog::STATUS_ING;//同步中 | ||
| 66 | - $task->save(); | ||
| 67 | - | ||
| 68 | - $domain_arr = parse_url($api_url); | ||
| 69 | - //获取网站配置 | ||
| 70 | - $link_type = 0; | ||
| 71 | - $web_url_domain = $domain_arr['host']; | ||
| 72 | - $home_url = $domain_arr['host']; | ||
| 73 | - $url_web_config = 'https://' . $domain_arr['host'] . '/wp-content/cache/user_config.text'; | ||
| 74 | - $data_config = curl_c($url_web_config); | ||
| 75 | - if ($data_config) { | ||
| 76 | - $link_type = $data_config['link_type'] ?? 0; | ||
| 77 | - | ||
| 78 | - $web_url_arr = parse_url($data_config['web_url_domain'] ?? ''); | ||
| 79 | - if (isset($web_url_arr['host'])) { | ||
| 80 | - $web_url_domain = $web_url_arr['host']; | ||
| 81 | - } | ||
| 82 | - | ||
| 83 | - $home_url_arr = parse_url($data_config['home_url'] ?? ''); | ||
| 84 | - if (isset($home_url_arr['host'])) { | ||
| 85 | - $home_url = $home_url_arr['host']; | ||
| 86 | - } | ||
| 87 | - } | ||
| 88 | - //获取所有语种 | ||
| 89 | - $language_list = []; | ||
| 90 | - $url_language = 'https://' . $domain_arr['host'] . '/wp-content/plugins/proofreading/json/user_language.json'; | ||
| 91 | - $data_language = curl_c($url_language); | ||
| 92 | - if ($data_language) { | ||
| 93 | - $language_list = array_column($data_language, 'short'); | ||
| 94 | - } | ||
| 95 | - //获取所有页面 | ||
| 96 | - $page_list = []; | ||
| 97 | - $url_page = 'https://' . $domain_arr['host'] . '/wp-content/cache/pages_list.json'; | ||
| 98 | - $data_page = curl_c($url_page); | ||
| 99 | - if ($data_page) { | ||
| 100 | - $page_list = array_column($data_page, 'path'); | ||
| 101 | - } | ||
| 102 | - | ||
| 103 | - //设置数据库 | ||
| 104 | - $project = ProjectServer::useProject($project_id); | ||
| 105 | - if ($project) { | ||
| 106 | - if ($api_type == 'category') { | ||
| 107 | - //产品分类 | ||
| 108 | - $url = $api_url . '?' . http_build_query(['w' => 'category']); | ||
| 109 | - $data = curl_c($url); | ||
| 110 | - if (isset($data['code']) && $data['code'] == 200) { | ||
| 111 | - $items = $data['data'] ?? []; | ||
| 112 | - $this->category_insert($project_id, $items, 0); | ||
| 113 | - } else { | ||
| 114 | - return true; | ||
| 115 | - } | ||
| 116 | - } elseif ($api_type == 'post') { | ||
| 117 | - //产品 | ||
| 118 | - $url = $api_url . '?' . http_build_query(['w' => 'post', 'page' => 1, 'pagesize' => 0]); | ||
| 119 | - $data = curl_c($url); | ||
| 120 | - if (isset($data['code']) && $data['code'] == 200) { | ||
| 121 | - $count = $data['data']['count'] ?? 0; | ||
| 122 | - | ||
| 123 | - $total_page = ceil($count / $page_size); | ||
| 124 | - for ($page = 1; $page <= $total_page; $page++) { | ||
| 125 | - $url_page = $api_url . '?' . http_build_query(['w' => 'post', 'page' => $page, 'pagesize' => $page_size]); | ||
| 126 | - $data_page = curl_c($url_page); | ||
| 127 | - if (isset($data_page['code']) && $data_page['code'] == 200) { | ||
| 128 | - $items = $data_page['data']['data'] ?? []; | ||
| 129 | - | ||
| 130 | - $model = new Product(); | ||
| 131 | - $category_model = new Category(); | ||
| 132 | - $logic = new CategoryLogic(); | ||
| 133 | - | ||
| 134 | - foreach ($items as $item) { | ||
| 135 | - $route = $this->get_url_route($item['url'] ?? ''); | ||
| 136 | - if ($route) { | ||
| 137 | - $product = $model->read(['route' => $route], 'id'); | ||
| 138 | - if (!$product) { | ||
| 139 | - //图片 | ||
| 140 | - $gallery = []; | ||
| 141 | - if ($item['images'] ?? []) { | ||
| 142 | - foreach ($item['images'] as $k_img => $img) { | ||
| 143 | - $gallery[] = ['alt' => '这是一张产品图', 'url' => $this->source_download($img, $project_id, $domain_arr['host'], $web_url_domain, $home_url)]; | ||
| 144 | - } | ||
| 145 | - } | ||
| 146 | - //分类 | ||
| 147 | - $category_id = ''; | ||
| 148 | - if ($item['category'] ?? []) { | ||
| 149 | - $category_arr = $category_model->list(['original_id' => ['in', array_column($item['category'], 'id')]]); | ||
| 150 | - $category_id = $logic->getLastCategory(array_column($category_arr, 'id')); | ||
| 151 | - } | ||
| 152 | - try { | ||
| 153 | - $item['ttile'] = $this->special2str($item['ttile'] ?? ''); | ||
| 154 | - $id = $model->insertGetId([ | ||
| 155 | - 'project_id' => $project_id, | ||
| 156 | - 'title' => $item['ttile'], | ||
| 157 | - 'intro' => $item['short_description'] ?? '', | ||
| 158 | - 'content' => $item['content'] ?? '', | ||
| 159 | - 'category_id' => $category_id, | ||
| 160 | - 'thumb' => isset($gallery[0]) ? Arr::a2s($gallery[0]) : '', | ||
| 161 | - 'gallery' => Arr::a2s($gallery), | ||
| 162 | - 'seo_mate' => Arr::a2s([ | ||
| 163 | - 'title' => $item['ttile'], | ||
| 164 | - 'keyword' => $item['keywords'] ?? '', | ||
| 165 | - 'description' => $item['description'] ?? '' | ||
| 166 | - ]), | ||
| 167 | - 'status' => Product::STATUS_ON, | ||
| 168 | - 'created_at' => $item['post_date'] ?? date('Y-m-d H:i:s'), | ||
| 169 | - 'updated_at' => $item['post_date'] ?? date('Y-m-d H:i:s'), | ||
| 170 | - 'sort' => $item['sort'] ?? 0, | ||
| 171 | - 'is_upgrade' => 1, | ||
| 172 | - 'six_read' => 1, | ||
| 173 | - 'route' => $route | ||
| 174 | - ]); | ||
| 175 | - $this->set_map($route, RouteMap::SOURCE_PRODUCT, $id, $project_id); | ||
| 176 | - | ||
| 177 | - CollectTask::_insert($item['url'], $project_id, RouteMap::SOURCE_PRODUCT, $id, $link_type, $language_list, $page_list); | ||
| 178 | - } catch (\Exception $e) { | ||
| 179 | - echo 'date:' . date('Y-m-d H:i:s') . ', task_id: ' . $task->id . ', error: ' . $e->getMessage() . PHP_EOL; | ||
| 180 | - continue; | ||
| 181 | - } | ||
| 182 | - } else { | ||
| 183 | - $category_id = ''; | ||
| 184 | - if ($item['category'] ?? []) { | ||
| 185 | - $category_arr = $category_model->list(['original_id' => ['in', array_column($item['category'], 'id')]]); | ||
| 186 | - $category_id = $logic->getLastCategory(array_column($category_arr, 'id')); | ||
| 187 | - } | ||
| 188 | - | ||
| 189 | - $model->edit(['category_id' => $category_id, 'product_type' => ''], ['id' => $product['id']]); | ||
| 190 | - } | ||
| 191 | - } | ||
| 192 | - } | ||
| 193 | - } | ||
| 194 | - } | ||
| 195 | - } else { | ||
| 196 | - return true; | ||
| 197 | - } | ||
| 198 | - } | ||
| 199 | - } | ||
| 200 | - //关闭数据库 | ||
| 201 | - DB::disconnect('custom_mysql'); | ||
| 202 | - | ||
| 203 | - $task->status = UpdateLog::STATUS_COM;//同步完成 | ||
| 204 | - if ($api_type == 'post' || $api_type == 'page' || $api_type == 'news' || $api_type == 'blog') { | ||
| 205 | - $task->collect_status = UpdateLog::COLLECT_STATUS_UN; | ||
| 206 | - } | ||
| 207 | - $task->save(); | ||
| 208 | - | ||
| 209 | - echo 'date:' . date('Y-m-d H:i:s') . ', task_id: ' . $task->id . ', task_type: ' . $api_type . ', update end ' . PHP_EOL; | ||
| 210 | - | ||
| 211 | - sleep(2); | ||
| 212 | - } | ||
| 213 | - } | ||
| 214 | - | ||
| 215 | - | ||
| 216 | - //获取地址路由 | ||
| 217 | - protected function get_url_route($url) | ||
| 218 | - { | ||
| 219 | - $arr = parse_url(urldecode($url)); | ||
| 220 | - if (empty($arr['path'])) { | ||
| 221 | - return ''; | ||
| 222 | - } | ||
| 223 | - $path = $arr['path']; | ||
| 224 | - | ||
| 225 | - if (strpos($path, '.') !== false) { | ||
| 226 | - $path = substr($path, 0, strpos($path, '.')); | ||
| 227 | - } | ||
| 228 | - | ||
| 229 | - $path_arr = explode('/', $path); | ||
| 230 | - | ||
| 231 | - return end($path_arr) ? end($path_arr) : $path_arr[count($path_arr) - 2]; | ||
| 232 | - } | ||
| 233 | - | ||
| 234 | - //产品多级分类入库 | ||
| 235 | - protected function category_insert($project_id, $items, $pid = 0) | ||
| 236 | - { | ||
| 237 | - $model = new Category(); | ||
| 238 | - foreach ($items as $item) { | ||
| 239 | - $route = $this->get_url_route($item['url'] ?? ''); | ||
| 240 | - if ($route) { | ||
| 241 | - $parent = $model->read(['pid' => $pid, 'route' => $route], 'id'); | ||
| 242 | - if (!$parent) { | ||
| 243 | - try { | ||
| 244 | - $item['name'] = $this->special2str($item['name'] ?? ''); | ||
| 245 | - $parent_id = $model->addReturnId([ | ||
| 246 | - 'project_id' => $project_id, | ||
| 247 | - 'title' => $item['name'], | ||
| 248 | - 'pid' => $pid, | ||
| 249 | - 'keywords' => $item['keywords'] ?? '', | ||
| 250 | - 'describe' => $item['description'] ?? '', | ||
| 251 | - 'original_id' => $item['id'], | ||
| 252 | - 'route' => $route | ||
| 253 | - ]); | ||
| 254 | - $this->set_map($route, RouteMap::SOURCE_PRODUCT_CATE, $parent_id, $project_id); | ||
| 255 | - } catch (\Exception $e) { | ||
| 256 | - echo 'date:' . date('Y-m-d H:i:s') . ', category_insert error: ' . $e->getMessage() . PHP_EOL; | ||
| 257 | - continue; | ||
| 258 | - } | ||
| 259 | - } else { | ||
| 260 | - $parent_id = $parent['id']; | ||
| 261 | - } | ||
| 262 | - | ||
| 263 | - if (!empty($item['children'])) { | ||
| 264 | - $this->category_insert($project_id, $item['children'], $parent_id); | ||
| 265 | - } | ||
| 266 | - } | ||
| 267 | - } | ||
| 268 | - } | ||
| 269 | - | ||
| 270 | - //特殊字符转换 | ||
| 271 | - protected function special2str($str) | ||
| 272 | - { | ||
| 273 | - if (strpos($str, ';') === false) { | ||
| 274 | - return $str; | ||
| 275 | - } | ||
| 276 | - | ||
| 277 | - $list = [ | ||
| 278 | - '<' => '<', | ||
| 279 | - '>' => '>', | ||
| 280 | - '&' => '&', | ||
| 281 | - '´' => '´', | ||
| 282 | - '"' => '“', | ||
| 283 | - ' ' => ' ' | ||
| 284 | - ]; | ||
| 285 | - | ||
| 286 | - foreach ($list as $k => $v) { | ||
| 287 | - $str = str_replace($k, $v, $str); | ||
| 288 | - } | ||
| 289 | - | ||
| 290 | - return $str; | ||
| 291 | - } | ||
| 292 | - | ||
| 293 | - //路由入库 | ||
| 294 | - protected function set_map($route, $source, $source_id, $project_id) | ||
| 295 | - { | ||
| 296 | - if ($route) { | ||
| 297 | - $route_map = RouteMap::where('project_id', $project_id)->where('source', $source)->where('source_id', $source_id)->first(); | ||
| 298 | - if (!$route_map) { | ||
| 299 | - $route_map = new RouteMap(); | ||
| 300 | - $route_map->project_id = $project_id; | ||
| 301 | - $route_map->source = $source; | ||
| 302 | - $route_map->source_id = $source_id; | ||
| 303 | - $route_map->route = $route; | ||
| 304 | - | ||
| 305 | - if ($source == RouteMap::SOURCE_NEWS) { | ||
| 306 | - $route_map->path = RouteMap::SOURCE_NEWS; | ||
| 307 | - } elseif ($source == RouteMap::SOURCE_BLOG) { | ||
| 308 | - $route_map->path = RouteMap::SOURCE_BLOG; | ||
| 309 | - } | ||
| 310 | - | ||
| 311 | - $route_map->save(); | ||
| 312 | - } | ||
| 313 | - } | ||
| 314 | - } | ||
| 315 | - | ||
| 316 | - //资源下载 | ||
| 317 | - protected function source_download($url, $project_id, $domain, $web_url_domain, $home_url) | ||
| 318 | - { | ||
| 319 | - if (!$url) { | ||
| 320 | - return ''; | ||
| 321 | - } | ||
| 322 | - | ||
| 323 | - $arr = parse_url($url); | ||
| 324 | - $scheme = $arr['scheme'] ?? ''; | ||
| 325 | - $host = $arr['host'] ?? ''; | ||
| 326 | - $path = $arr['path'] ?? ''; | ||
| 327 | - | ||
| 328 | - $url_complete = ($scheme ?: 'https') . '://' . ($host ?: $domain) . $path; | ||
| 329 | - | ||
| 330 | - if ((empty($host) || $host == $web_url_domain || $host == $home_url) && $path) { | ||
| 331 | - | ||
| 332 | - $source = CollectSource::where('project_id', $project_id)->where('origin', $url)->first(); | ||
| 333 | - if (!$source) { | ||
| 334 | - $new_url = CosService::uploadRemote($project_id, 'image_product', $url_complete); | ||
| 335 | - | ||
| 336 | - if ($new_url) { | ||
| 337 | - CollectSource::insert([ | ||
| 338 | - 'project_id' => $project_id, | ||
| 339 | - 'origin' => $url, | ||
| 340 | - 'target' => $new_url, | ||
| 341 | - 'created_at' => date('Y-m-d H:i:s'), | ||
| 342 | - 'updated_at' => date('Y-m-d H:i:s'), | ||
| 343 | - ]); | ||
| 344 | - | ||
| 345 | - return getImageUrl($new_url); | ||
| 346 | - } else { | ||
| 347 | - return $url_complete; | ||
| 348 | - } | ||
| 349 | - } else { | ||
| 350 | - return getImageUrl($source['target']); | ||
| 351 | - } | ||
| 352 | - } else { | ||
| 353 | - return $url_complete; | ||
| 354 | - } | ||
| 355 | - } | ||
| 356 | -} |
| @@ -46,7 +46,7 @@ class VisualizationLogic extends BaseLogic | @@ -46,7 +46,7 @@ class VisualizationLogic extends BaseLogic | ||
| 46 | $source = $data['source']; | 46 | $source = $data['source']; |
| 47 | $source_id = $data['source_id']; | 47 | $source_id = $data['source_id']; |
| 48 | $type = $this->getType($source,$source_id); | 48 | $type = $this->getType($source,$source_id); |
| 49 | - $typeArray = [1,3,5,7];//单页数据 | 49 | + $typeArray = [BTemplate::TYPE_ONE,BTemplate::TYPE_THREE,BTemplate::TYPE_FIVE,BTemplate::TYPE_SEVEN];//单页数据 |
| 50 | if(in_array($type,$typeArray)){ | 50 | if(in_array($type,$typeArray)){ |
| 51 | $bTemplateModel = new BTemplate(); | 51 | $bTemplateModel = new BTemplate(); |
| 52 | $info = $bTemplateModel->read(['source'=>$source,'source_id'=>$source_id,'template_id'=>0]); | 52 | $info = $bTemplateModel->read(['source'=>$source,'source_id'=>$source_id,'template_id'=>0]); |
| @@ -67,6 +67,13 @@ class VisualizationLogic extends BaseLogic | @@ -67,6 +67,13 @@ class VisualizationLogic extends BaseLogic | ||
| 67 | return $this->success(['html'=>$html]); | 67 | return $this->success(['html'=>$html]); |
| 68 | } | 68 | } |
| 69 | 69 | ||
| 70 | + /** | ||
| 71 | + * @remark :根据type获取source类型 | ||
| 72 | + * @name :getSource | ||
| 73 | + * @author :lyh | ||
| 74 | + * @method :post | ||
| 75 | + * @time :2023/12/6 11:25 | ||
| 76 | + */ | ||
| 70 | public function getSource($type){ | 77 | public function getSource($type){ |
| 71 | $source_id = 0; | 78 | $source_id = 0; |
| 72 | if ($type == 2){$source = 2;$source_id = 1; | 79 | if ($type == 2){$source = 2;$source_id = 1; |
| @@ -98,10 +105,8 @@ class VisualizationLogic extends BaseLogic | @@ -98,10 +105,8 @@ class VisualizationLogic extends BaseLogic | ||
| 98 | $templateInfo = $bTemplateModel->read(['source'=>$source,'source_id'=>$source_id,'template_id'=>0]); | 105 | $templateInfo = $bTemplateModel->read(['source'=>$source,'source_id'=>$source_id,'template_id'=>0]); |
| 99 | if($templateInfo === false){ | 106 | if($templateInfo === false){ |
| 100 | $data = [ | 107 | $data = [ |
| 101 | - 'html'=>$this->param['html'], | ||
| 102 | - 'project_id'=>$this->user['project_id'], | ||
| 103 | - 'source'=>$source, | ||
| 104 | - 'source_id'=>$source_id, | 108 | + 'html'=>$this->param['html'], 'project_id'=>$this->user['project_id'], |
| 109 | + 'source'=>$source, 'source_id'=>$source_id, | ||
| 105 | ]; | 110 | ]; |
| 106 | $bTemplateModel->add($data); | 111 | $bTemplateModel->add($data); |
| 107 | }else{ | 112 | }else{ |
| @@ -139,6 +144,20 @@ class VisualizationLogic extends BaseLogic | @@ -139,6 +144,20 @@ class VisualizationLogic extends BaseLogic | ||
| 139 | $page_array = (array)$this->user['is_visualization']->page_array;//获取定制界面 | 144 | $page_array = (array)$this->user['is_visualization']->page_array;//获取定制界面 |
| 140 | //查看当前类型是否是定制界面 | 145 | //查看当前类型是否是定制界面 |
| 141 | if(in_array($type,$page_array)){//是定制界面 | 146 | if(in_array($type,$page_array)){//是定制界面 |
| 147 | + return $this->getVisualizationHtml($type); | ||
| 148 | + }else{//非定制界面 | ||
| 149 | + return $this->getTemplateHtml(); | ||
| 150 | + } | ||
| 151 | + } | ||
| 152 | + | ||
| 153 | + /** | ||
| 154 | + * @remark :定制界面获取html | ||
| 155 | + * @name :getVisualizationHtml | ||
| 156 | + * @author :lyh | ||
| 157 | + * @method :post | ||
| 158 | + * @time :2023/12/6 11:47 | ||
| 159 | + */ | ||
| 160 | + public function getVisualizationHtml($type){ | ||
| 142 | if(in_array($type,[1,3,5,7])){//单页 | 161 | if(in_array($type,[1,3,5,7])){//单页 |
| 143 | $templateInfo = $this->getWebTemplate($this->param['source'],$this->param['source_id']);//查看当前定制单页是否有代码块 | 162 | $templateInfo = $this->getWebTemplate($this->param['source'],$this->param['source_id']);//查看当前定制单页是否有代码块 |
| 144 | if($templateInfo === false){ | 163 | if($templateInfo === false){ |
| @@ -155,9 +174,28 @@ class VisualizationLogic extends BaseLogic | @@ -155,9 +174,28 @@ class VisualizationLogic extends BaseLogic | ||
| 155 | } | 174 | } |
| 156 | return ['html'=>$mainInfo['main_html']]; | 175 | return ['html'=>$mainInfo['main_html']]; |
| 157 | } | 176 | } |
| 158 | - return ['html'=>$templateInfo['html']]; | 177 | + //替换为公共头部和底部 |
| 178 | + $templateCommonModel = new BTemplateCommon(); | ||
| 179 | + $headerFooterHtml = $templateCommonModel->read(['template_id'=>0,'project_id'=>$this->user['project_id'],'type'=>$type]); | ||
| 180 | + $html = $templateInfo['html']; | ||
| 181 | + if($headerFooterHtml !== false){ | ||
| 182 | + $html = preg_replace('/<header\b[^>]*>(.*?)<\/header>/s', $headerFooterHtml['head_html'], $html); | ||
| 183 | + $html = preg_replace('/<footer\b[^>]*>(.*?)<\/footer>/s', $headerFooterHtml['footer_html'], $html); | ||
| 184 | + $html = preg_replace('/<style id="globalsojs-header">(.*?)<\/style>/s', $headerFooterHtml['head_css'], $html); | ||
| 185 | + $html = preg_replace('/<style id="globalsojs-footer">(.*?)<\/style>/s', $headerFooterHtml['footer_css'], $html); | ||
| 159 | } | 186 | } |
| 160 | - }else{//非定制界面 | 187 | + return ['html'=>$html]; |
| 188 | + } | ||
| 189 | + } | ||
| 190 | + | ||
| 191 | + /** | ||
| 192 | + * @remark :非定制项目获取html | ||
| 193 | + * @name :getTemplateHtml | ||
| 194 | + * @author :lyh | ||
| 195 | + * @method :post | ||
| 196 | + * @time :2023/12/6 11:44 | ||
| 197 | + */ | ||
| 198 | + public function getTemplateHtml(){ | ||
| 161 | $bSettingModel = new Setting(); | 199 | $bSettingModel = new Setting(); |
| 162 | $settingInfo = $bSettingModel->read(['project_id'=>$this->user['project_id']]); | 200 | $settingInfo = $bSettingModel->read(['project_id'=>$this->user['project_id']]); |
| 163 | if($settingInfo === false){ | 201 | if($settingInfo === false){ |
| @@ -179,8 +217,7 @@ class VisualizationLogic extends BaseLogic | @@ -179,8 +217,7 @@ class VisualizationLogic extends BaseLogic | ||
| 179 | $html = $commonInfo['head_css'].$mainData['main_css'].$commonInfo['footer_css'].$commonInfo['other']. | 217 | $html = $commonInfo['head_css'].$mainData['main_css'].$commonInfo['footer_css'].$commonInfo['other']. |
| 180 | $commonInfo['head_html'].$mainData['main_html'].$commonInfo['footer_html']; | 218 | $commonInfo['head_html'].$mainData['main_html'].$commonInfo['footer_html']; |
| 181 | $html = $this->getHeadFooter($html); | 219 | $html = $this->getHeadFooter($html); |
| 182 | - return ['html'=>$html,'template_id'=>$settingInfo['template_id']]; | ||
| 183 | - } | 220 | + return $this->success(['html'=>$html,'template_id'=>$settingInfo['template_id']]); |
| 184 | } | 221 | } |
| 185 | 222 | ||
| 186 | /** | 223 | /** |
| @@ -226,7 +263,7 @@ class VisualizationLogic extends BaseLogic | @@ -226,7 +263,7 @@ class VisualizationLogic extends BaseLogic | ||
| 226 | } | 263 | } |
| 227 | 264 | ||
| 228 | /** | 265 | /** |
| 229 | - * @remark :获取类型 | 266 | + * @remark :定制界面根据source+source_id获取type类型 |
| 230 | * @name :getType | 267 | * @name :getType |
| 231 | * @author :lyh | 268 | * @author :lyh |
| 232 | * @method :post | 269 | * @method :post |
| @@ -247,7 +284,7 @@ class VisualizationLogic extends BaseLogic | @@ -247,7 +284,7 @@ class VisualizationLogic extends BaseLogic | ||
| 247 | } | 284 | } |
| 248 | 285 | ||
| 249 | /** | 286 | /** |
| 250 | - * @remark :获取设置的类型 | 287 | + * @remark :非定制获取设置头部底部的类型 |
| 251 | * @name :getType | 288 | * @name :getType |
| 252 | * @author :lyh | 289 | * @author :lyh |
| 253 | * @method :post | 290 | * @method :post |
| @@ -284,7 +321,7 @@ class VisualizationLogic extends BaseLogic | @@ -284,7 +321,7 @@ class VisualizationLogic extends BaseLogic | ||
| 284 | $type = $this->getType($this->param['source'],$this->param['source_id']); | 321 | $type = $this->getType($this->param['source'],$this->param['source_id']); |
| 285 | try { | 322 | try { |
| 286 | if(in_array($type,$page_array)){//定制页面 | 323 | if(in_array($type,$page_array)){//定制页面 |
| 287 | - $this->saveVisualizationHtml(); | 324 | + $this->saveVisualizationHtml($type); |
| 288 | }else{ | 325 | }else{ |
| 289 | $this->saveTemplateHtml(); | 326 | $this->saveTemplateHtml(); |
| 290 | } | 327 | } |
| @@ -301,24 +338,54 @@ class VisualizationLogic extends BaseLogic | @@ -301,24 +338,54 @@ class VisualizationLogic extends BaseLogic | ||
| 301 | * @method :post | 338 | * @method :post |
| 302 | * @time :2023/12/5 15:42 | 339 | * @time :2023/12/5 15:42 |
| 303 | */ | 340 | */ |
| 304 | - public function saveVisualizationHtml(){ | 341 | + public function saveVisualizationHtml($type){ |
| 305 | $bTemplateModel = new BTemplate(); | 342 | $bTemplateModel = new BTemplate(); |
| 306 | $templateInfo = $bTemplateModel->read([ | 343 | $templateInfo = $bTemplateModel->read([ |
| 307 | 'source'=>$this->param['source'], 'project_id'=>$this->user['project_id'], | 344 | 'source'=>$this->param['source'], 'project_id'=>$this->user['project_id'], |
| 308 | 'source_id'=>$this->param['source_id'], 'template_id'=>0 | 345 | 'source_id'=>$this->param['source_id'], 'template_id'=>0 |
| 309 | ]); | 346 | ]); |
| 347 | + try { | ||
| 348 | + //更新头部底部 | ||
| 349 | + $this->visualizationSaveHeaderFooter($type); | ||
| 310 | if($templateInfo === false){ | 350 | if($templateInfo === false){ |
| 311 | $this->param['project_id'] = $this->user['project_id']; | 351 | $this->param['project_id'] = $this->user['project_id']; |
| 312 | $this->param['template_id'] = 0; | 352 | $this->param['template_id'] = 0; |
| 313 | -// $this->param['main_html'] = characterTruncation($this->param['html'],'/<main\b[^>]*>(.*?)<\/main>/s'); | ||
| 314 | -// $this->param['main_css'] = characterTruncation($this->param['html'],'/<style id="globalsojs-styles">(.*?)<\/style>/s'); | ||
| 315 | $bTemplateModel->add($this->param); | 353 | $bTemplateModel->add($this->param); |
| 316 | }else{ | 354 | }else{ |
| 317 | -// $param['main_html'] = characterTruncation($this->param['html'],'/<main\b[^>]*>(.*?)<\/main>/s'); | ||
| 318 | -// $param['main_css'] = characterTruncation($this->param['html'],'/<style id="globalsojs-styles">(.*?)<\/style>/s'); | ||
| 319 | $param['html'] = $this->param['html']; | 355 | $param['html'] = $this->param['html']; |
| 320 | $bTemplateModel->edit($param,['source'=>$this->param['source'],'source_id'=>$this->param['source_id'],'template_id'=>0]); | 356 | $bTemplateModel->edit($param,['source'=>$this->param['source'],'source_id'=>$this->param['source_id'],'template_id'=>0]); |
| 321 | } | 357 | } |
| 358 | + }catch (\Exception $e){ | ||
| 359 | + $this->fail('系统错误,请联系管理员'); | ||
| 360 | + } | ||
| 361 | + return $this->success(); | ||
| 362 | + } | ||
| 363 | + | ||
| 364 | + /** | ||
| 365 | + * @remark :定制界面保存头部底部 | ||
| 366 | + * @name :visualizationSaveHeaderFooter | ||
| 367 | + * @author :lyh | ||
| 368 | + * @method :post | ||
| 369 | + * @time :2023/12/6 10:41 | ||
| 370 | + */ | ||
| 371 | + public function visualizationSaveHeaderFooter($type){ | ||
| 372 | + //更新头部底部代码 | ||
| 373 | + $header_footer = [ | ||
| 374 | + 'head_html'=>characterTruncation($this->param['html'],'/<header\b[^>]*>(.*?)<\/header>/s'), | ||
| 375 | + 'head_css'=>characterTruncation($this->param['html'],'/<style id="globalsojs-header">(.*?)<\/style>/s'), | ||
| 376 | + 'footer_html'=>characterTruncation($this->param['html'],'/<footer\b[^>]*>(.*?)<\/footer>/s'), | ||
| 377 | + 'footer_css'=>characterTruncation($this->param['html'],'/<style id="globalsojs-footer">(.*?)<\/style>/s'), | ||
| 378 | + ]; | ||
| 379 | + $templateCommonModel = new BTemplateCommon(); | ||
| 380 | + $info = $templateCommonModel->read(['template_id'=>0,'project_id'=>$this->user['project_id'],'type'=>$type]); | ||
| 381 | + if($info === false){ | ||
| 382 | + $header_footer['template_id'] = 0; | ||
| 383 | + $header_footer['project_id'] = $this->user['project_id']; | ||
| 384 | + $header_footer['type'] = $type; | ||
| 385 | + $templateCommonModel->add($header_footer); | ||
| 386 | + }else{ | ||
| 387 | + $templateCommonModel->edit($header_footer,['template_id'=>0,'project_id'=>$this->user['project_id'],'type'=>$type]); | ||
| 388 | + } | ||
| 322 | return $this->success(); | 389 | return $this->success(); |
| 323 | } | 390 | } |
| 324 | 391 |
-
请 注册 或 登录 后发表评论