|
1 | 1 | <?php
|
2 | 2 |
|
3 | 3 | 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; |
8 | 4 | use Module\Blog\Model\Blog;
|
9 |
| -use Module\Blog\Type\BlogVisitMode; |
10 | 5 | use Module\Blog\Util\BlogCategoryUtil;
|
11 | 6 | use Module\Blog\Util\BlogTagUtil;
|
12 | 7 |
|
13 | 8 | /**
|
14 | 9 | * @Util 博客操作
|
| 10 | + * 1 统一用单数 |
15 | 11 | */
|
16 | 12 | class MBlog
|
17 | 13 | {
|
| 14 | + /** |
| 15 | + * @Util 获取分类树 |
| 16 | + * @return array |
| 17 | + */ |
18 | 18 | public static function categoryTree()
|
19 | 19 | {
|
20 | 20 | return BlogCategoryUtil::categoryTree();
|
@@ -71,6 +71,7 @@ public static function latestBlog($limit)
|
71 | 71 | return $paginateData['records'];
|
72 | 72 | }
|
73 | 73 |
|
| 74 | + |
74 | 75 | /**
|
75 | 76 | * @Util 获取置顶博客
|
76 | 77 | * @param $limit int 限制条数
|
@@ -116,6 +117,19 @@ public static function latestBlog($limit)
|
116 | 117 | * // ...
|
117 | 118 | * ]
|
118 | 119 | */
|
| 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 | + */ |
119 | 133 | public static function topestBlog($limit)
|
120 | 134 | {
|
121 | 135 | $paginateData = self::paginateBlog(0, 1, $limit, [
|
@@ -230,6 +244,16 @@ public static function recommendBlog($limit)
|
230 | 244 | return $paginateData['records'];
|
231 | 245 | }
|
232 | 246 |
|
| 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 | + |
233 | 257 |
|
234 | 258 | /**
|
235 | 259 | * @Util 获取最热博客
|
@@ -398,65 +422,12 @@ public static function randomBlog($limit)
|
398 | 422 | */
|
399 | 423 | public static function paginateBlog($categoryId, $page = 1, $pageSize = 10, $option = [])
|
400 | 424 | {
|
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); |
424 | 426 | }
|
425 | 427 |
|
426 | 428 | public static function buildRecords($records)
|
427 | 429 | {
|
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); |
460 | 431 | }
|
461 | 432 |
|
462 | 433 | /**
|
|
0 commit comments