InitHtmlLogic.php
11.0 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
<?php
/**
* @remark :
* @name :InitHtmlLogic.php
* @author :lyh
* @method :post
* @time :2023/12/27 10:39
*/
namespace App\Http\Logic\Bside\BTemplate;
use App\Http\Logic\Bside\BaseLogic;
use App\Models\Template\BTemplate;
use App\Models\Template\BTemplateCommon;
use App\Models\Template\BTemplateMain;
use App\Models\Template\Setting;
use App\Models\Template\TemplateTypeMain;
class InitHtmlLogic extends BaseLogic
{
public function __construct()
{
parent::__construct();
$this->param = $this->requestAll;
}
/**
* @remark :获取非定制项目复合页数据
* @name :getDetailHtml
* @author :lyh
* @method :post $param (type:类型,2产品 3博客 4新闻 对应扩展模块的id)
* @time :2023/12/27 10:50
*/
public function getDetailHtml(){
$template_id = $this->getTemplateId();
$is_custom = $this->param['is_custom'] ?? 0;//TODO::1:代表扩展模块
$is_list = $this->param['is_list'] ?? 0;//TODO::1:代表分类列表模块
//获取设置的默认中间部分
$bTemplateMainModel = new BTemplateMain();
$mainInfo = $bTemplateMainModel->read(['project_id'=>$this->user['project_id'],'type'=>$this->param['type'],'is_list'=>$is_list,'is_custom'=>$is_custom]);
if($mainInfo === false){
$main_html = $this->getInitModule($this->param['type'],$is_list);
$main_style = "<style id='globalsojs-styles'></style>";
}else{
$main_html = $mainInfo['main_html'];
$main_style = $mainInfo['main_css'];
}
$commonInfo = $this->getTypeCommonHtml($template_id,$this->param['type'],$is_custom,$is_list); //获取头部
$html = $commonInfo['head_css'].$main_style.$commonInfo['footer_css'].$commonInfo['other'].$commonInfo['head_html'].$main_html.$commonInfo['footer_html'];
$html = $this->getHeadFooter($html);//组装数据
return $this->success($html);
}
/**
* @remark :保存复合页数据
* @name :saveDetailHtml
* @author :lyh
* @method :post
* @time :2023/12/27 11:57
*/
public function saveDetailHtml(){
$template_id = $this->getTemplateId();
$is_custom = $this->param['is_custom'] ?? 0;//TODO::1:代表扩展模块
$is_list = $this->param['is_list'] ?? 0;//TODO::1:代表分类列表模块
//保存中间部分
$bTemplateMainModel = new BTemplateMain();
$mainInfo = $bTemplateMainModel->read(['project_id'=>$this->user['project_id'],'type'=>$this->param['type'],'is_custom'=>$is_custom,'is_list'=>$is_list]);
if($mainInfo === false){
$data = [
'main_html'=>characterTruncation($this->param['html'],'/<main\b[^>]*>(.*?)<\/main>/s'),
'main_css'=>characterTruncation($this->param['html'],'/<style id="globalsojs-styles">(.*?)<\/style>/s'),
'section_list_id'=>$this->param['section_list_id'] ?? '',
'project_id'=>$this->user['project_id'],
'type'=>$this->param['type'],
'is_custom'=>$is_custom,
'is_list'=>$is_list
];
$bTemplateMainModel->add($data);
}else{
$data = [
'main_html'=>characterTruncation($this->param['html'],'/<main\b[^>]*>(.*?)<\/main>/s'),
'main_css'=>characterTruncation($this->param['html'],'/<style id="globalsojs-styles">(.*?)<\/style>/s'),
'section_list_id'=>$this->param['section_list_id'] ?? '',
];
$bTemplateMainModel->edit($data,['id'=>$mainInfo['id']]);
}
$this->saveDetailCommonHtml($this->param['html'],$this->param['type'],$template_id,$is_custom,$is_list);
return $this->success();
}
/**
* @remark :保存详情页模版头部底部
* @name :saveDetailCommonHtml
* @author :lyh
* @method :post
* @time :2023/12/15 18:12
*/
public function saveDetailCommonHtml($html,$type,$template_id,$is_custom,$is_list){
$publicData = $this->handleCommonParam($html);
$templateCommonModel = new BTemplateCommon();
//查看当前模板是否有独立头部,有独立头部,更新独立头部,无独立头部,更新公共头部
$is_head = $this->user['configuration']['is_head'] ?? 0;
if($is_custom == BTemplate::SOURCE_CUSTOM){//todo::扩展模块无独立头部底部
$is_head = BTemplate::IS_NO_HEADER;
}
if($is_head == BTemplate::IS_HEADER) {
//有独立头部,更新独立头部
$commonType = $this->getHeaderType($type,$is_list);
$templateCommonInfo = $templateCommonModel->read(['project_id'=>$this->user['project_id'],'template_id'=>$template_id,'type'=>$commonType]);
if($templateCommonInfo === false){
$publicData['type'] = $type;
$publicData['project_id'] = $this->user['project_id'];
$publicData['template_id'] = $template_id;
$templateCommonModel->add($publicData);
}else{
$templateCommonModel->edit($publicData,['id'=>$templateCommonInfo['id']]);
}
}else{
//更新首页头部底部
$templateCommonModel->edit($publicData,['type'=>BTemplate::SOURCE_HOME,'project_id'=>$this->user['project_id'],'template_id'=>$template_id]);
}
return $this->success();
}
/**
* @remark :保存时字符串处理
* @name :handleCommonParam
* @author :lyh
* @method :post
* @time :2023/6/29 15:35
*/
public function handleCommonParam($html){
//字符串截取
$param['head_html'] = characterTruncation($html,'/<header\b[^>]*>(.*?)<\/header>/s');
$param['footer_html'] = characterTruncation($html,'/<footer\b[^>]*>(.*?)<\/footer>/s');
$param['head_css'] = characterTruncation($html,'/<style id="globalsojs-header">(.*?)<\/style>/s');
$param['footer_css'] = characterTruncation($html,'/<style id="globalsojs-footer">(.*?)<\/style>/s');
$footer_other = str_replace('<header','',characterTruncation($html,'/<style id="globalsojs-footer">(.*?)<header/s'));
$param['other'] = preg_replace('/<style id="globalsojs-footer">(.*?)<\/style>/s', '', $footer_other);
return $this->success($param);
}
/**
* @remark :默认复合页数据
* @name :getProductModule
* @author :lyh
* @method :post
* @time :2023/7/27 15:08
*/
public function getInitModule($type,$is_custom,$is_list){
if($is_custom == BTemplate::SOURCE_CUSTOM) {
$type = BTemplate::TYPE_CUSTOM;
}
$mainModel = new TemplateTypeMain();
$info = $mainModel->read(['type'=>$type,'is_list'=>$is_list]);
return $info['main_html'];
}
/**
* @remark :根据type获取头部html
* @name :getHeaderFooter
* @author :lyh
* @method :post
* @time :2023/12/15 18:06
*/
public function getTypeCommonHtml($template_id,$type,$is_custom,$is_list){
//判断当前项目是否有设置独立头部的权限
$is_head = $this->user['configuration']['is_head'] ?? 0;
if($is_custom == BTemplate::SOURCE_CUSTOM){//todo::拓展模块默认取首页
$is_head = BTemplate::IS_NO_HEADER;
}
//获取首页公共部分
$templateCommonModel = new BTemplateCommon();
if($is_head == BTemplate::IS_HEADER) {
//有独立头部,获取独立头部
$commonType = $this->getHeaderType($type,$is_list);
$commonInfo = $templateCommonModel->read(['template_id'=>$template_id,'project_id'=>$this->user['project_id'],'type'=>$commonType]);
}else{
//首页头底
$commonInfo = $templateCommonModel->read(['template_id'=>$template_id,'project_id'=>$this->user['project_id'],'type'=>BTemplate::SOURCE_HOME]);
}
return $this->success($commonInfo);
}
/**
* @remark :独立头部获取头部底部类型
* @name :getHeaderType
* @author :lyh
* @method :post
* @time :2023/12/27 11:36
*/
public function getHeaderType($type,$is_list){
$resultType = BTemplate::SOURCE_HOME;
if($type == BTemplate::SOURCE_PRODUCT){
if($is_list == BTemplate::IS_LIST){
$resultType = BTemplate::TYPE_THREE;
}else{
$resultType = BTemplate::TYPE_TWO;
}
}
if($type == BTemplate::SOURCE_BLOG){
if($is_list == BTemplate::IS_LIST){
$resultType = BTemplate::TYPE_FIVE;
}else{
$resultType = BTemplate::TYPE_FOUR;
}
}
if($type == BTemplate::SOURCE_NEWS){
if($is_list == BTemplate::IS_LIST){
$resultType = BTemplate::TYPE_SEVEN;
}else{
$resultType = BTemplate::TYPE_SIX;
}
}
return $this->success($resultType);
}
/**
* @remark :获取模版id
* @name :getTemplateId
* @author :lyh
* @method :post
* @time :2023/12/27 10:51
*/
public function getTemplateId(){
$bSettingModel = new Setting();
$bSettingInfo = $bSettingModel->read(['project_id'=>$this->user['project_id']],['id','template_id']);
if($bSettingInfo === false){
$this->fail('请先设置模板');
}
return $this->success($bSettingInfo['template_id']);
}
/**
* @remark :获取代码块
* @name :getVisualizationInfo
* @author :lyh
* @method :post
* @time :2023/11/17 14:44
*/
public function getCustomizedHtml(){
$is_list = $this->param['is_list'] ?? 0;
$bTemplateMainModel = new BTemplateMain();
$info = $bTemplateMainModel->read(['type'=>$this->param['type'],'is_list'=>$is_list]);
if($info === false){
$html = '';
}else{
$html = $info['main_html'];
}
return $this->success(['html'=>$html]);
}
/**
* @remark :保存定制html
* @name :saveHtml
* @author :lyh
* @method :post
* @time :2023/11/15 10:12
*/
public function saveCustomizedHtml(){
try {
$is_list = $this->param['is_list'] ?? 0;
$bTemplateMainModel = new BTemplateMain();
$mainInfo = $bTemplateMainModel->read(['type'=>$this->param['type'],'is_list'=>$is_list]);
if($mainInfo === false){
$mainData = [
'project_id'=>$this->user['project_id'],
'type'=>$this->param['type'],
'is_list'=>$is_list,
'main_html'=>$this->param['html']
];
$bTemplateMainModel->add($mainData);
}else{
$bTemplateMainModel->edit(['main_html'=>$this->param['html']],['id'=>$mainInfo['id']]);
}
}catch (\Exception $exception){
$this->fail('保存失败,请联系开发人员');
}
return $this->success();
}
}