forked from modstart/ModStartBlog
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMBlog.php
More file actions
72 lines (65 loc) · 2.28 KB
/
Copy pathMBlog.php
File metadata and controls
72 lines (65 loc) · 2.28 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
<?php
use ModStart\Core\Assets\AssetsUtil;
use ModStart\Core\Dao\ModelUtil;
use ModStart\Core\Util\HtmlUtil;
use ModStart\Core\Util\TagUtil;
use Module\Blog\Util\BlogCategoryUtil;
use Module\Blog\Util\BlogTagUtil;
class MBlog
{
public static function categoryTree()
{
return BlogCategoryUtil::categoryTree();
}
public static function latestBlog($limit)
{
$paginateData = self::paginateBlog(0, 1, $limit);
return $paginateData['records'];
}
public static function paginateBlog($categoryId, $page = 1, $pageSize = 10, $option = [])
{
if ($categoryId > 0) {
$option['whereIn'][] = ['categoryId', BlogCategoryUtil::childrenIds($categoryId)];
}
$option['where']['isPublished'] = true;
if (!isset($option['order'])) {
$option['order'] = ['postTime', 'desc'];
}
if (!isset($option['whereOperate'])) {
$option['whereOperate'] = [];
}
$option['whereOperate'] = array_merge([
['postTime', '<', date('Y-m-d H:i:s')],
], $option['whereOperate']);
$paginateData = ModelUtil::paginate('blog', $page, $pageSize, $option);
$records = $paginateData['records'];
ModelUtil::decodeRecordsJson($records, 'images');
TagUtil::recordsString2Array($records, 'tag');
foreach ($records as $i => $v) {
$records[$i]['_category'] = BlogCategoryUtil::get($v['categoryId']);
$records[$i]['images'] = AssetsUtil::fixFull($v['images']);
$records[$i]['_cover'] = null;
if (isset($records[$i]['images'][0])) {
$records[$i]['_cover'] = $records[$i]['images'][0];
}
if (empty($records[$i]['_cover'])) {
$ret = HtmlUtil::extractTextAndImages($v['content']);
if (isset($ret['images'][0])) {
$records[$i]['_cover'] = AssetsUtil::fixFull($ret['images'][0]);
}
}
}
return [
'records' => $records,
'total' => $paginateData['total'],
];
}
public static function getCategory($categoryId)
{
return BlogCategoryUtil::get($categoryId);
}
public static function tags()
{
return BlogTagUtil::all();
}
}