Skip to content

Commit 04821db

Browse files
committed
新增:布局视图页面全局增加 headPrepend section
1 parent a1d255c commit 04821db

File tree

139 files changed

+582
-255
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

139 files changed

+582
-255
lines changed

config/module.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,10 @@
3434
'VisitStatistic' => [
3535
'enable' => true,
3636
],
37-
// 'AdminApi' => [
37+
// 'TemplateConverter' => [
38+
// 'enable' => true,
39+
// ],
40+
// 'BlogThemeLightA' => [
3841
// 'enable' => true,
3942
// ],
4043
// 'BlogAdminApi' => [

module/Banner/Docs/module/content.md

Lines changed: 54 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -14,45 +14,40 @@
1414

1515
## 使用方式
1616

17-
在需要使用到的地方通过如下代码调用
18-
19-
```html
20-
{!! \Module\Banner\View\BannerView::simple('位置') !!}
21-
```
22-
23-
## 模块位置信息注册
24-
25-
通过以下方式可以实现一个轮播位置,其中name为位置(position),title为标题。
26-
2717
```php
28-
class XxxBannerPositionProvider extends AbstractBannerPositionProvider
29-
{
30-
public function name()
31-
{
32-
return 'wendaHome';
33-
}
34-
35-
public function title()
36-
{
37-
return '问答首页';
38-
}
39-
}
18+
// 循环特定位置轮播
19+
@foreach(\MBanner::all('Xxx') as $banner)
20+
@if($banner['type']===\Module\Banner\Type\BannerType::IMAGE)
21+
图片
22+
<a href="{{ $banner['link'] }}">{{ $banner['image'] }}</a>
23+
@elseif($banner['type']===\Module\Banner\Type\BannerType::IMAGE_TITLE_SLOGAN_LINK)
24+
图片+标题+描述+链接
25+
<a href="{{ $banner['link'] }}">{{ $banner['image'] }}</a>
26+
@elseif($banner['type']===\Module\Banner\Type\BannerType::VIDEO)
27+
视频
28+
<a href="{{ $banner['link'] }}">{{ $banner['video'] }}</a>
29+
@endif
30+
@endforeach
31+
32+
// 循环特定位置轮播(仅包含图片)
33+
@foreach(\MBanner::allImage('Xxx') as $banner)
34+
<a href="{{ $banner['link'] }}">{{ $banner['image'] }}</a>
35+
@endforeach
4036
```
4137

42-
同时在 `ModuleServiceProvider` 中注册轮播位置
38+
### 不同位置轮播
4339

4440
```php
45-
if (class_exists(BannerPositionProvider::class)) {
46-
BannerPositionProvider::register(XxxBannerPositionProvider::class);
47-
}
41+
// 位置 Blog
42+
\MBanner::all('Blog')
43+
// 位置 Cms
44+
\MBanner::all('Cms')
4845
```
4946

50-
如此便可在通用轮播管理的页面进行轮播的管理
51-
52-
## 如何调整轮播的比例和大小
47+
### 快速渲染
5348

54-
```html
55-
{!! \Module\Banner\View\BannerView::render('位置',['bannerRatio'=>'5-2']) !!}
49+
```php
50+
{!! \Module\Banner\View\BannerView::basic('位置') !!}
5651
```
5752

5853
默认情况下,轮播使用了 `5-2` 的比例,还支持的内置比例有,调用时候只需要添加 `宽-高``bannerRatio` 变量即可。
@@ -70,4 +65,31 @@ if (class_exists(BannerPositionProvider::class)) {
7065
如果需要其他尺寸,可自行在 `module/Banner/View/pc/public/banner.blade.php` 模板文件中调整。
7166

7267

73-
{ADMIN_MENUS}
68+
## 模块位置信息注册
69+
70+
通过以下方式可以实现一个轮播位置,其中name为位置(position),title为标题。
71+
72+
```php
73+
class XxxBannerPositionBiz extends \Module\Banner\Biz\AbstractBannerPositionBiz
74+
{
75+
public function name()
76+
{
77+
return 'Xxx';
78+
}
79+
80+
public function title()
81+
{
82+
return '特定位置';
83+
}
84+
}
85+
```
86+
87+
同时在 `XxxBannerPositionBiz` 中注册轮播位置
88+
89+
```php
90+
\Module\Banner\Biz\BannerPositionBiz::register(XxxBannerPositionBiz::class);
91+
```
92+
93+
如此便可在通用轮播管理的页面进行轮播的管理
94+
95+
{ADMIN_MENUS}

module/Banner/Docs/release.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
## 1.8.0
22

3+
- 新增:轮播图获取支持近图片过滤方法
34
- 优化:视频 `Banner` 概率不播放问题
45

56
---

module/Banner/Helpers/MBanner.php

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,38 @@
11
<?php
22

3+
use Module\Banner\Type\BannerType;
34
use Module\Banner\Util\BannerUtil;
45

56
/**
67
* Class MBanner
78
*
8-
* @Util 通用轮播
9+
* @Util 轮播
910
*/
1011
class MBanner
1112
{
1213
/**
13-
* @param string $position
14-
* @return mixed
15-
*
1614
* @Util 根据位置获取轮播数据
15+
* @param $position string 位置
16+
* @return array
1717
*/
1818
public static function all($position = 'home')
1919
{
2020
return BannerUtil::listByPositionWithCache($position);
2121
}
22-
}
22+
23+
/**
24+
* @Util 根据位置获取轮播数据(仅包含图片)
25+
* @param $position string 位置
26+
* @return array
27+
*/
28+
public static function allImage($position)
29+
{
30+
$records = self::all($position);
31+
return array_values(array_filter($records, function ($item) {
32+
return in_array($item['type'], [
33+
BannerType::IMAGE,
34+
BannerType::IMAGE_TITLE_SLOGAN_LINK
35+
]);
36+
}));
37+
}
38+
}

module/Blog/Admin/Controller/ConfigController.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ public function index(AdminConfigBuilder $builder)
2323
$builder->text('Blog_Slogan', '博客标语');
2424
$builder->image('Blog_Avatar', '博客头像');
2525
$builder->text('Blog_ContactQQ', '联系方式-QQ');
26-
$builder->text('Blog_ContactEmail', '联系方式-邮箱');
2726
$builder->text('Blog_ContactWeibo', '联系方式-微博');
2827
$builder->text('Blog_ContactWechat', '联系方式-微信');
2928
});

module/Blog/Api/Controller/BlogController.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use Module\Blog\Type\BlogVisitMode;
1919
use Module\Blog\Util\BlogCategoryUtil;
2020
use Module\Blog\Util\UrlUtil;
21+
use Module\HotSearch\Util\HotSearchUtil;
2122
use Module\Member\Util\MemberUtil;
2223

2324
/**
@@ -95,6 +96,12 @@ public function paginate()
9596
// Log::info('records-' . json_encode($paginateData['records']));
9697
}
9798

99+
if ($keywords) {
100+
if (modstart_module_enabled('HotSearch')) {
101+
HotSearchUtil::hit($keywords);
102+
}
103+
}
104+
98105

99106
$category = null;
100107
if ($categoryId > 0) {
@@ -132,6 +139,7 @@ public function get()
132139
$record['images'] = AssetsUtil::fixFull($record['images']);
133140
$record['tag'] = TagUtil::string2Array($record['tag']);
134141
$record['_category'] = BlogCategoryUtil::get($record['categoryId']);
142+
$record['_date'] = date('Y-m-d', strtotime($record['postTime']));
135143

136144
$record['_visitVerified'] = false;
137145
switch ($record['visitMode']) {
@@ -161,14 +169,20 @@ public function get()
161169
$option = [];
162170
$option['where']['blogId'] = $record['id'];
163171
$option['where']['status'] = BlogCommentStatus::VERIFY_SUCCESS;
164-
165172
$option['order'] = ['id', 'desc'];
166173
$commentPaginateData = ModelUtil::paginate('blog_comment', $commentPage, $commentPageSize, $option);
167174
$comments = $commentPaginateData['records'];
168175
$commentTotal = $commentPaginateData['total'];
169176
if (modstart_module_enabled('Member')) {
170177
MemberUtil::mergeMemberUserBasics($comments);
171178
}
179+
foreach ($comments as $i => $comment) {
180+
$avatar = 'asset/image/avatar.svg';
181+
if (!empty($comment['_memberUser']['avatar'])) {
182+
$avatar = $comment['_memberUser']['avatar'];
183+
}
184+
$comments[$i]['_avatar'] = AssetsUtil::fixFull($avatar);
185+
}
172186
}
173187

174188

module/Blog/Core/MBlog.php

Lines changed: 31 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
<?php
22

33
use Illuminate\Support\Facades\DB;
4-
use ModStart\Core\Assets\AssetsUtil;
5-
use ModStart\Core\Dao\ModelUtil;
6-
use ModStart\Core\Util\HtmlUtil;
7-
use ModStart\Core\Util\TagUtil;
84
use Module\Blog\Model\Blog;
9-
use Module\Blog\Type\BlogVisitMode;
105
use Module\Blog\Util\BlogCategoryUtil;
116
use Module\Blog\Util\BlogTagUtil;
127

138
/**
149
* @Util 博客操作
10+
* 1 统一用单数
1511
*/
1612
class MBlog
1713
{
14+
/**
15+
* @Util 获取分类树
16+
* @return array
17+
*/
1818
public static function categoryTree()
1919
{
2020
return BlogCategoryUtil::categoryTree();
@@ -71,6 +71,7 @@ public static function latestBlog($limit)
7171
return $paginateData['records'];
7272
}
7373

74+
7475
/**
7576
* @Util 获取置顶博客
7677
* @param $limit int 限制条数
@@ -116,6 +117,19 @@ public static function latestBlog($limit)
116117
* // ...
117118
* ]
118119
*/
120+
public static function topBlog($limit)
121+
{
122+
$paginateData = self::paginateBlog(0, 1, $limit, [
123+
'isTop' => true,
124+
]);
125+
return $paginateData['records'];
126+
}
127+
128+
/**
129+
* @param $limit
130+
* @return mixed
131+
* @deprecated delete at 2024-05-09
132+
*/
119133
public static function topestBlog($limit)
120134
{
121135
$paginateData = self::paginateBlog(0, 1, $limit, [
@@ -230,6 +244,16 @@ public static function recommendBlog($limit)
230244
return $paginateData['records'];
231245
}
232246

247+
/**
248+
* @Util 最新评论
249+
* @param $limit int 限制条数
250+
* @return array
251+
*/
252+
public static function latestComment($limit)
253+
{
254+
return \Module\Blog\Util\BlogCommentUtil::latest($limit);
255+
}
256+
233257

234258
/**
235259
* @Util 获取最热博客
@@ -398,65 +422,12 @@ public static function randomBlog($limit)
398422
*/
399423
public static function paginateBlog($categoryId, $page = 1, $pageSize = 10, $option = [])
400424
{
401-
if ($categoryId > 0) {
402-
$option['whereIn'][] = ['categoryId', BlogCategoryUtil::childrenIds($categoryId)];
403-
}
404-
$option['where']['isPublished'] = true;
405-
if (!isset($option['order'])) {
406-
$option['order'] = [
407-
['isTop', 'desc'],
408-
['postTime', 'desc'],
409-
];
410-
}
411-
if (!isset($option['whereOperate'])) {
412-
$option['whereOperate'] = [];
413-
}
414-
$option['whereOperate'] = array_merge([
415-
['postTime', '<', date('Y-m-d H:i:s')],
416-
], $option['whereOperate']);
417-
418-
$paginateData = ModelUtil::paginate('blog', $page, $pageSize, $option);
419-
$records = self::buildRecords($paginateData['records']);
420-
return [
421-
'records' => $records,
422-
'total' => $paginateData['total'],
423-
];
425+
return \Module\Blog\Util\BlogUtil::paginateBlogsByCategoryId($categoryId, $page, $pageSize, $option);
424426
}
425427

426428
public static function buildRecords($records)
427429
{
428-
ModelUtil::decodeRecordsJson($records, 'images');
429-
TagUtil::recordsString2Array($records, 'tag');
430-
foreach ($records as $i => $v) {
431-
$records[$i]['_category'] = BlogCategoryUtil::get($v['categoryId']);
432-
$records[$i]['images'] = AssetsUtil::fixFull($v['images']);
433-
$records[$i]['_images'] = [];
434-
$records[$i]['_images'] = array_merge($records[$i]['_images'], $records[$i]['images']);
435-
$records[$i]['_cover'] = null;
436-
if (isset($records[$i]['images'][0])) {
437-
$records[$i]['_cover'] = $records[$i]['images'][0];
438-
}
439-
if (isset($v['content'])) {
440-
$ret = HtmlUtil::extractTextAndImages($v['content']);
441-
if (!empty($ret['images'])) {
442-
$ret['images'] = AssetsUtil::fixFull($ret['images']);
443-
$records[$i]['_images'] = array_merge($records[$i]['_images'], $ret['images']);
444-
}
445-
if (empty($records[$i]['_cover']) && isset($ret['images'][0])) {
446-
$records[$i]['_cover'] = $ret['images'][0];
447-
}
448-
}
449-
switch ($v['visitMode']) {
450-
case BlogVisitMode::PASSWORD:
451-
$records[$i]['content'] = null;
452-
break;
453-
case BlogVisitMode::OPEN:
454-
default:
455-
// do nothing
456-
break;
457-
}
458-
}
459-
return $records;
430+
return \Module\Blog\Util\BlogUtil::buildRecords($records);
460431
}
461432

462433
/**

module/Blog/Docs/release.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
- 新增:博客标签数量侧边栏显示数量限制可设置
55
- 新增:博客评论是否开启功能开关
66
- 新增:博客后台设置页面布局重构
7+
- 新增:适配 HotSearch 模块,支持热门搜索关键词追踪
78

89
---
910

module/Blog/Model/BlogComment.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
4+
namespace Module\Blog\Model;
5+
6+
7+
use Illuminate\Database\Eloquent\Model;
8+
9+
class BlogComment extends Model
10+
{
11+
protected $table = 'blog_comment';
12+
13+
public function blog()
14+
{
15+
return $this->belongsTo(Blog::class, 'blogId', 'id');
16+
}
17+
}

0 commit comments

Comments
 (0)