作者 赵彬吉
... ... @@ -39,14 +39,15 @@ class HtmlCollect extends Command
public function handle()
{
while (true) {
// while (true) {
$this->start_collect();
}
// }
}
protected function start_collect()
{
$task_id = $this->get_task();
// $task_id = $this->get_task();
$task_id = '437_5995';
if ($task_id === false) {
//所有项目采集完成
sleep(60);
... ... @@ -291,7 +292,8 @@ class HtmlCollect extends Command
$path_arr = explode('.', $path);
if (
(empty($host) || $host == $web_url_domain || $host == $home_url)
(empty($scheme) || $scheme == 'https' || $scheme == 'http')
&& (empty($host) || $host == $web_url_domain || $host == $home_url)
&& $path
&& (strpos($path, '.') !== false)
&& (!in_array(end($path_arr), ['html', 'php', 'com', 'xml']))
... ... @@ -335,17 +337,21 @@ class HtmlCollect extends Command
]);
$html = str_replace($vs['url'], getImageUrl($new_source), $html);
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] ?? [];
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] ?? [];
$url_arr = explode('/', $vs['url_complete']);
$target_arr = explode('/', $new_source);
foreach ($css_source as $vcs) {
foreach ($source_list as $vcs) {
$vcs = str_replace('"', '', $vcs);
$vcs_arr = parse_url($vcs);
if (isset($vcs_arr['domain'])) {
//不是相对路径,不下载
continue;
... ...
... ... @@ -283,6 +283,9 @@ class HtmlLanguageCollect extends Command
{
if ($url) {
$url = str_replace('"', '', $url);
if(strpos($url,'mailto:') !== false){
return false;
}
$arr = parse_url($url);
$scheme = $arr['scheme'] ?? '';
$host = $arr['host'] ?? '';
... ... @@ -291,7 +294,8 @@ class HtmlLanguageCollect extends Command
$path_arr = explode('.', $path);
if (
(empty($host) || $host == $web_url_domain || $host == $home_url)
(empty($scheme) || $scheme == 'https' || $scheme == 'http')
&& (empty($host) || $host == $web_url_domain || $host == $home_url)
&& $path
&& (strpos($path, '.') !== false)
&& (!in_array(end($path_arr), ['html', 'php', 'com', 'xml']))
... ...
... ... @@ -115,6 +115,7 @@ class ProjectUpdate extends Command
$page_list = array_column($data_page, 'path');
}
$is_flush = 0;
//设置数据库
$project = ProjectServer::useProject($project_id);
if ($project) {
... ... @@ -318,6 +319,7 @@ class ProjectUpdate extends Command
$this->set_map($route, RouteMap::SOURCE_PRODUCT, $id, $project_id);
CollectTask::_insert($item['url'], $project_id, RouteMap::SOURCE_PRODUCT, $id, $link_type, $language_list, $page_list);
$is_flush = 1;
} catch (\Exception $e) {
echo 'date:' . date('Y-m-d H:i:s') . ', task_id: ' . $task->id . ', error: ' . $e->getMessage() . PHP_EOL;
continue;
... ... @@ -392,6 +394,7 @@ class ProjectUpdate extends Command
$this->set_map($route, $api_type == 'news' ? RouteMap::SOURCE_NEWS : RouteMap::SOURCE_BLOG, $id, $project_id);
CollectTask::_insert($item['url'], $project_id, $api_type == 'news' ? RouteMap::SOURCE_NEWS : RouteMap::SOURCE_BLOG, $id, $link_type, $language_list, $page_list);
$is_flush = 1;
} catch (\Exception $e) {
echo 'date:' . date('Y-m-d H:i:s') . ', task_id: ' . $task->id . ', error: ' . $e->getMessage() . PHP_EOL;
continue;
... ... @@ -444,6 +447,7 @@ class ProjectUpdate extends Command
$this->set_map($route, RouteMap::SOURCE_PAGE, $id, $project_id);
CollectTask::_insert($item['url'], $project_id, RouteMap::SOURCE_PAGE, $id, $link_type, $language_list, $page_list);
$is_flush = 1;
} catch (\Exception $e) {
echo 'date:' . date('Y-m-d H:i:s') . ', task_id: ' . $task->id . ', error: ' . $e->getMessage() . PHP_EOL;
continue;
... ... @@ -462,7 +466,7 @@ class ProjectUpdate extends Command
DB::disconnect('custom_mysql');
$task->status = UpdateLog::STATUS_COM;//同步完成
if($api_type == 'post' || $api_type == 'page' || $api_type == 'news' || $api_type == 'blog'){
if($is_flush){
$task->collect_status = UpdateLog::COLLECT_STATUS_UN;
}
$task->save();
... ...
<?php
namespace App\Console\Commands\Update;
use App\Helper\Arr;
use App\Http\Logic\Bside\Product\CategoryLogic;
use App\Models\Collect\CollectSource;
use App\Models\Collect\CollectTask;
use App\Models\Com\UpdateLog;
use App\Models\Product\Category;
use App\Models\Product\Product;
use App\Models\RouteMap\RouteMap;
use App\Services\CosService;
use App\Services\ProjectServer;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
/**
* 4.0,5.0升级到6.0,内容同步
* Class ProjectImport
* @package App\Console\Commands
* @author Akun
* @date 2023/10/9 15:04
*/
class ProjectUpdateTemp extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'project_update_temp';
/**
* The console command description.
*
* @var string
*/
protected $description = '执行项目升级任务';
public function handle()
{
while (true) {
$this->start_update();
}
}
protected function start_update()
{
$list = UpdateLog::where('api_type', 'category')->get();
foreach ($list as $task) {
$project_id = $task->project_id;
$api_type = $task->api_type;
$api_url_arr = explode('?', $task->api_url);
$api_url = $api_url_arr[0];
$page_size = 20;
echo 'date:' . date('Y-m-d H:i:s') . ', task_id: ' . $task->id . ', task_type: ' . $api_type . ', update start' . PHP_EOL;
$task->status = UpdateLog::STATUS_ING;//同步中
$task->save();
$domain_arr = parse_url($api_url);
//获取网站配置
$link_type = 0;
$web_url_domain = $domain_arr['host'];
$home_url = $domain_arr['host'];
$url_web_config = 'https://' . $domain_arr['host'] . '/wp-content/cache/user_config.text';
$data_config = curl_c($url_web_config);
if ($data_config) {
$link_type = $data_config['link_type'] ?? 0;
$web_url_arr = parse_url($data_config['web_url_domain'] ?? '');
if (isset($web_url_arr['host'])) {
$web_url_domain = $web_url_arr['host'];
}
$home_url_arr = parse_url($data_config['home_url'] ?? '');
if (isset($home_url_arr['host'])) {
$home_url = $home_url_arr['host'];
}
}
//获取所有语种
$language_list = [];
$url_language = 'https://' . $domain_arr['host'] . '/wp-content/plugins/proofreading/json/user_language.json';
$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 = curl_c($url_page);
if ($data_page) {
$page_list = array_column($data_page, 'path');
}
//设置数据库
$project = ProjectServer::useProject($project_id);
if ($project) {
if ($api_type == 'category') {
//产品分类
$url = $api_url . '?' . http_build_query(['w' => 'category']);
$data = curl_c($url);
if (isset($data['code']) && $data['code'] == 200) {
$items = $data['data'] ?? [];
$this->category_insert($project_id, $items, 0);
} else {
return true;
}
} elseif ($api_type == 'post') {
//产品
$url = $api_url . '?' . http_build_query(['w' => 'post', 'page' => 1, 'pagesize' => 0]);
$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 = curl_c($url_page);
if (isset($data_page['code']) && $data_page['code'] == 200) {
$items = $data_page['data']['data'] ?? [];
$model = new Product();
$category_model = new Category();
$logic = new CategoryLogic();
foreach ($items as $item) {
$route = $this->get_url_route($item['url'] ?? '');
if ($route) {
$product = $model->read(['route' => $route], 'id');
if (!$product) {
//图片
$gallery = [];
if ($item['images'] ?? []) {
foreach ($item['images'] as $k_img => $img) {
$gallery[] = ['alt' => '这是一张产品图', 'url' => $this->source_download($img, $project_id, $domain_arr['host'], $web_url_domain, $home_url)];
}
}
//分类
$category_id = '';
if ($item['category'] ?? []) {
$category_arr = $category_model->list(['original_id' => ['in', array_column($item['category'], 'id')]]);
$category_id = $logic->getLastCategory(array_column($category_arr, 'id'));
}
try {
$item['ttile'] = $this->special2str($item['ttile'] ?? '');
$id = $model->insertGetId([
'project_id' => $project_id,
'title' => $item['ttile'],
'intro' => $item['short_description'] ?? '',
'content' => $item['content'] ?? '',
'category_id' => $category_id,
'thumb' => isset($gallery[0]) ? Arr::a2s($gallery[0]) : '',
'gallery' => Arr::a2s($gallery),
'seo_mate' => Arr::a2s([
'title' => $item['ttile'],
'keyword' => $item['keywords'] ?? '',
'description' => $item['description'] ?? ''
]),
'status' => Product::STATUS_ON,
'created_at' => $item['post_date'] ?? date('Y-m-d H:i:s'),
'updated_at' => $item['post_date'] ?? date('Y-m-d H:i:s'),
'sort' => $item['sort'] ?? 0,
'is_upgrade' => 1,
'six_read' => 1,
'route' => $route
]);
$this->set_map($route, RouteMap::SOURCE_PRODUCT, $id, $project_id);
CollectTask::_insert($item['url'], $project_id, RouteMap::SOURCE_PRODUCT, $id, $link_type, $language_list, $page_list);
} catch (\Exception $e) {
echo 'date:' . date('Y-m-d H:i:s') . ', task_id: ' . $task->id . ', error: ' . $e->getMessage() . PHP_EOL;
continue;
}
} else {
$category_id = '';
if ($item['category'] ?? []) {
$category_arr = $category_model->list(['original_id' => ['in', array_column($item['category'], 'id')]]);
$category_id = $logic->getLastCategory(array_column($category_arr, 'id'));
}
$model->edit(['category_id' => $category_id, 'product_type' => ''], ['id' => $product['id']]);
}
}
}
}
}
} else {
return true;
}
}
}
//关闭数据库
DB::disconnect('custom_mysql');
$task->status = UpdateLog::STATUS_COM;//同步完成
if ($api_type == 'post' || $api_type == 'page' || $api_type == 'news' || $api_type == 'blog') {
$task->collect_status = UpdateLog::COLLECT_STATUS_UN;
}
$task->save();
echo 'date:' . date('Y-m-d H:i:s') . ', task_id: ' . $task->id . ', task_type: ' . $api_type . ', update end ' . PHP_EOL;
sleep(2);
}
}
//获取地址路由
protected function get_url_route($url)
{
$arr = parse_url(urldecode($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];
}
//产品多级分类入库
protected function category_insert($project_id, $items, $pid = 0)
{
$model = new Category();
foreach ($items as $item) {
$route = $this->get_url_route($item['url'] ?? '');
if ($route) {
$parent = $model->read(['pid' => $pid, 'route' => $route], 'id');
if (!$parent) {
try {
$item['name'] = $this->special2str($item['name'] ?? '');
$parent_id = $model->addReturnId([
'project_id' => $project_id,
'title' => $item['name'],
'pid' => $pid,
'keywords' => $item['keywords'] ?? '',
'describe' => $item['description'] ?? '',
'original_id' => $item['id'],
'route' => $route
]);
$this->set_map($route, RouteMap::SOURCE_PRODUCT_CATE, $parent_id, $project_id);
} catch (\Exception $e) {
echo 'date:' . date('Y-m-d H:i:s') . ', category_insert error: ' . $e->getMessage() . PHP_EOL;
continue;
}
} else {
$parent_id = $parent['id'];
}
if (!empty($item['children'])) {
$this->category_insert($project_id, $item['children'], $parent_id);
}
}
}
}
//特殊字符转换
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;
}
//路由入库
protected function set_map($route, $source, $source_id, $project_id)
{
if ($route) {
$route_map = RouteMap::where('project_id', $project_id)->where('source', $source)->where('source_id', $source_id)->first();
if (!$route_map) {
$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();
}
}
}
//资源下载
protected function source_download($url, $project_id, $domain, $web_url_domain, $home_url)
{
if (!$url) {
return '';
}
$arr = parse_url($url);
$scheme = $arr['scheme'] ?? '';
$host = $arr['host'] ?? '';
$path = $arr['path'] ?? '';
$url_complete = ($scheme ?: 'https') . '://' . ($host ?: $domain) . $path;
if ((empty($host) || $host == $web_url_domain || $host == $home_url) && $path) {
$source = CollectSource::where('project_id', $project_id)->where('origin', $url)->first();
if (!$source) {
$new_url = CosService::uploadRemote($project_id, 'image_product', $url_complete);
if ($new_url) {
CollectSource::insert([
'project_id' => $project_id,
'origin' => $url,
'target' => $new_url,
'created_at' => date('Y-m-d H:i:s'),
'updated_at' => date('Y-m-d H:i:s'),
]);
return getImageUrl($new_url);
} else {
return $url_complete;
}
} else {
return getImageUrl($source['target']);
}
} else {
return $url_complete;
}
}
}
... ... @@ -46,7 +46,7 @@ class VisualizationLogic extends BaseLogic
$source = $data['source'];
$source_id = $data['source_id'];
$type = $this->getType($source,$source_id);
$typeArray = [1,3,5,7];//单页数据
$typeArray = [BTemplate::TYPE_ONE,BTemplate::TYPE_THREE,BTemplate::TYPE_FIVE,BTemplate::TYPE_SEVEN];//单页数据
if(in_array($type,$typeArray)){
$bTemplateModel = new BTemplate();
$info = $bTemplateModel->read(['source'=>$source,'source_id'=>$source_id,'template_id'=>0]);
... ... @@ -54,7 +54,7 @@ class VisualizationLogic extends BaseLogic
$html = '';
}else{
$html = $info['html'];
}
}
}else{//模块数据
$bTemplateMainModel = new BTemplateMain();
$info = $bTemplateMainModel->read(['type'=>$type]);
... ... @@ -67,6 +67,13 @@ class VisualizationLogic extends BaseLogic
return $this->success(['html'=>$html]);
}
/**
* @remark :根据type获取source类型
* @name :getSource
* @author :lyh
* @method :post
* @time :2023/12/6 11:25
*/
public function getSource($type){
$source_id = 0;
if ($type == 2){$source = 2;$source_id = 1;
... ... @@ -98,10 +105,8 @@ class VisualizationLogic extends BaseLogic
$templateInfo = $bTemplateModel->read(['source'=>$source,'source_id'=>$source_id,'template_id'=>0]);
if($templateInfo === false){
$data = [
'html'=>$this->param['html'],
'project_id'=>$this->user['project_id'],
'source'=>$source,
'source_id'=>$source_id,
'html'=>$this->param['html'], 'project_id'=>$this->user['project_id'],
'source'=>$source, 'source_id'=>$source_id,
];
$bTemplateModel->add($data);
}else{
... ... @@ -139,51 +144,83 @@ class VisualizationLogic extends BaseLogic
$page_array = (array)$this->user['is_visualization']->page_array;//获取定制界面
//查看当前类型是否是定制界面
if(in_array($type,$page_array)){//是定制界面
if(in_array($type,[1,3,5,7])){//单页
$templateInfo = $this->getWebTemplate($this->param['source'],$this->param['source_id']);//查看当前定制单页是否有代码块
if($templateInfo === false){
return $this->getVisualizationHtml($type);
}else{//非定制界面
return $this->getTemplateHtml();
}
}
/**
* @remark :定制界面获取html
* @name :getVisualizationHtml
* @author :lyh
* @method :post
* @time :2023/12/6 11:47
*/
public function getVisualizationHtml($type){
if(in_array($type,[1,3,5,7])){//单页
$templateInfo = $this->getWebTemplate($this->param['source'],$this->param['source_id']);//查看当前定制单页是否有代码块
if($templateInfo === false){
$this->fail('请先上传定制代码块');
}
return ['html'=>$templateInfo['html']];
}else{//模块页
$templateInfo = $this->getWebTemplate($this->param['source'],$this->param['source_id']);//查看当前页面是否可视化
if($templateInfo === false){//获取代码块
$bTemplateMainModel = new BTemplateMain();
$mainInfo = $bTemplateMainModel->read(['type'=>$type]);
if($mainInfo === false){
$this->fail('请先上传定制代码块');
}
return ['html'=>$templateInfo['html']];
}else{//模块页
$templateInfo = $this->getWebTemplate($this->param['source'],$this->param['source_id']);//查看当前页面是否可视化
if($templateInfo === false){//获取代码块
$bTemplateMainModel = new BTemplateMain();
$mainInfo = $bTemplateMainModel->read(['type'=>$type]);
if($mainInfo === false){
$this->fail('请先上传定制代码块');
}
return ['html'=>$mainInfo['main_html']];
}
return ['html'=>$templateInfo['html']];
return ['html'=>$mainInfo['main_html']];
}
}else{//非定制界面
$bSettingModel = new Setting();
$settingInfo = $bSettingModel->read(['project_id'=>$this->user['project_id']]);
if($settingInfo === false){
$this->fail('请先选择模版');
//替换为公共头部和底部
$templateCommonModel = new BTemplateCommon();
$headerFooterHtml = $templateCommonModel->read(['template_id'=>0,'project_id'=>$this->user['project_id'],'type'=>$type]);
$html = $templateInfo['html'];
if($headerFooterHtml !== false){
$html = preg_replace('/<header\b[^>]*>(.*?)<\/header>/s', $headerFooterHtml['head_html'], $html);
$html = preg_replace('/<footer\b[^>]*>(.*?)<\/footer>/s', $headerFooterHtml['footer_html'], $html);
$html = preg_replace('/<style id="globalsojs-header">(.*?)<\/style>/s', $headerFooterHtml['head_css'], $html);
$html = preg_replace('/<style id="globalsojs-footer">(.*?)<\/style>/s', $headerFooterHtml['footer_css'], $html);
}
$templateInfo = $this->getWebTemplate($this->param['source'],$this->param['source_id'],$settingInfo['template_id']);//查看当前页面是否可视化
if($templateInfo === false){
//根据类型在获取中间部分
$mainData = $this->getCommonMain($this->param['source'],$this->param['source_id']);
}else{
$mainData = [
'main_html'=>$templateInfo['main_html'],
'main_css'=>$templateInfo['main_css']
];
}
//获取公共头部底部
$commonInfo = $this->getCommonPage($this->param['source'],$this->param['source_id'],$settingInfo['template_id']);
//拼接数据
$html = $commonInfo['head_css'].$mainData['main_css'].$commonInfo['footer_css'].$commonInfo['other'].
$commonInfo['head_html'].$mainData['main_html'].$commonInfo['footer_html'];
$html = $this->getHeadFooter($html);
return ['html'=>$html,'template_id'=>$settingInfo['template_id']];
return ['html'=>$html];
}
}
/**
* @remark :非定制项目获取html
* @name :getTemplateHtml
* @author :lyh
* @method :post
* @time :2023/12/6 11:44
*/
public function getTemplateHtml(){
$bSettingModel = new Setting();
$settingInfo = $bSettingModel->read(['project_id'=>$this->user['project_id']]);
if($settingInfo === false){
$this->fail('请先选择模版');
}
$templateInfo = $this->getWebTemplate($this->param['source'],$this->param['source_id'],$settingInfo['template_id']);//查看当前页面是否可视化
if($templateInfo === false){
//根据类型在获取中间部分
$mainData = $this->getCommonMain($this->param['source'],$this->param['source_id']);
}else{
$mainData = [
'main_html'=>$templateInfo['main_html'],
'main_css'=>$templateInfo['main_css']
];
}
//获取公共头部底部
$commonInfo = $this->getCommonPage($this->param['source'],$this->param['source_id'],$settingInfo['template_id']);
//拼接数据
$html = $commonInfo['head_css'].$mainData['main_css'].$commonInfo['footer_css'].$commonInfo['other'].
$commonInfo['head_html'].$mainData['main_html'].$commonInfo['footer_html'];
$html = $this->getHeadFooter($html);
return $this->success(['html'=>$html,'template_id'=>$settingInfo['template_id']]);
}
/**
* @remark :拼接获取公共头部底部
* @name :getHeadFooter
* @author :lyh
... ... @@ -226,7 +263,7 @@ class VisualizationLogic extends BaseLogic
}
/**
* @remark :获取类型
* @remark :定制界面根据source+source_id获取type类型
* @name :getType
* @author :lyh
* @method :post
... ... @@ -247,7 +284,7 @@ class VisualizationLogic extends BaseLogic
}
/**
* @remark :获取设置的类型
* @remark :非定制获取设置头部底部的类型
* @name :getType
* @author :lyh
* @method :post
... ... @@ -284,7 +321,7 @@ class VisualizationLogic extends BaseLogic
$type = $this->getType($this->param['source'],$this->param['source_id']);
try {
if(in_array($type,$page_array)){//定制页面
$this->saveVisualizationHtml();
$this->saveVisualizationHtml($type);
}else{
$this->saveTemplateHtml();
}
... ... @@ -301,23 +338,53 @@ class VisualizationLogic extends BaseLogic
* @method :post
* @time :2023/12/5 15:42
*/
public function saveVisualizationHtml(){
public function saveVisualizationHtml($type){
$bTemplateModel = new BTemplate();
$templateInfo = $bTemplateModel->read([
'source'=>$this->param['source'], 'project_id'=>$this->user['project_id'],
'source_id'=>$this->param['source_id'], 'template_id'=>0
]);
if($templateInfo === false){
$this->param['project_id'] = $this->user['project_id'];
$this->param['template_id'] = 0;
// $this->param['main_html'] = characterTruncation($this->param['html'],'/<main\b[^>]*>(.*?)<\/main>/s');
// $this->param['main_css'] = characterTruncation($this->param['html'],'/<style id="globalsojs-styles">(.*?)<\/style>/s');
$bTemplateModel->add($this->param);
try {
//更新头部底部
$this->visualizationSaveHeaderFooter($type);
if($templateInfo === false){
$this->param['project_id'] = $this->user['project_id'];
$this->param['template_id'] = 0;
$bTemplateModel->add($this->param);
}else{
$param['html'] = $this->param['html'];
$bTemplateModel->edit($param,['source'=>$this->param['source'],'source_id'=>$this->param['source_id'],'template_id'=>0]);
}
}catch (\Exception $e){
$this->fail('系统错误,请联系管理员');
}
return $this->success();
}
/**
* @remark :定制界面保存头部底部
* @name :visualizationSaveHeaderFooter
* @author :lyh
* @method :post
* @time :2023/12/6 10:41
*/
public function visualizationSaveHeaderFooter($type){
//更新头部底部代码
$header_footer = [
'head_html'=>characterTruncation($this->param['html'],'/<header\b[^>]*>(.*?)<\/header>/s'),
'head_css'=>characterTruncation($this->param['html'],'/<style id="globalsojs-header">(.*?)<\/style>/s'),
'footer_html'=>characterTruncation($this->param['html'],'/<footer\b[^>]*>(.*?)<\/footer>/s'),
'footer_css'=>characterTruncation($this->param['html'],'/<style id="globalsojs-footer">(.*?)<\/style>/s'),
];
$templateCommonModel = new BTemplateCommon();
$info = $templateCommonModel->read(['template_id'=>0,'project_id'=>$this->user['project_id'],'type'=>$type]);
if($info === false){
$header_footer['template_id'] = 0;
$header_footer['project_id'] = $this->user['project_id'];
$header_footer['type'] = $type;
$templateCommonModel->add($header_footer);
}else{
// $param['main_html'] = characterTruncation($this->param['html'],'/<main\b[^>]*>(.*?)<\/main>/s');
// $param['main_css'] = characterTruncation($this->param['html'],'/<style id="globalsojs-styles">(.*?)<\/style>/s');
$param['html'] = $this->param['html'];
$bTemplateModel->edit($param,['source'=>$this->param['source'],'source_id'=>$this->param['source_id'],'template_id'=>0]);
$templateCommonModel->edit($header_footer,['template_id'=>0,'project_id'=>$this->user['project_id'],'type'=>$type]);
}
return $this->success();
}
... ...