/
tag.php
167 lines (140 loc) · 3.34 KB
/
tag.php
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
<?php
if (!defined('ZBP_PATH')) {
exit('Access denied');
}
/**
* Z-Blog with PHP.
*
* @author Z-BlogPHP Team
* @version 1.0 2020-07-03
*/
/**
* 获取标签信息接口.
*
* @return array
*/
function api_tag_get()
{
global $zbp;
ApiCheckAuth(false, 'view');
$tag = null;
$tagId = (int) GetVars('id');
$tagAlias = GetVars('alias');
$tagName = GetVars('name');
if ($tagId > 0) {
$tag = $zbp->GetTagByID($tagId);
} elseif ($tagAlias !== null) {
$tag = $zbp->GetTagByAlias($tagAlias);
} else {
$tag = $zbp->GetTagByName($tagName);
}
$array = ApiGetObjectArray($tag, array('Url', 'Template'));
if ($tag && $tag->ID != null) {
return array(
'data' => array('tag' => $array),
);
}
return array(
'code' => 404,
'message' => $GLOBALS['lang']['error']['97'],
);
}
/**
* 新增/修改标签接口.
*
* @return array
*/
function api_tag_post()
{
global $zbp;
ApiCheckAuth(true, 'TagPst');
try {
$tag = PostTag();
$zbp->BuildModule();
$zbp->SaveCache();
$array = ApiGetObjectArray($tag, array('Url'));
return array(
'message' => $GLOBALS['lang']['msg']['operation_succeed'],
'data' => array('tag' => $array),
);
} catch (Exception $e) {
return array(
'code' => 500,
'message' => $GLOBALS['lang']['msg']['operation_failed'] . ' ' . $e->getMessage(),
);
}
}
/**
* 删除标签接口.
*
* @return array
*/
function api_tag_delete()
{
global $zbp;
ApiVerifyCSRF(true);
ApiCheckAuth(true, 'TagDel');
if ($zbp->GetTagByID((int) GetVars('id', 'GET'))->ID == 0) {
return array(
'code' => 404,
'message' => $GLOBALS['lang']['error']['97'],
);
}
if (!DelTag()) {
return array(
'message' => $GLOBALS['lang']['msg']['operation_failed'],
);
}
$zbp->BuildModule();
$zbp->SaveCache();
return array(
'message' => $GLOBALS['lang']['msg']['operation_succeed'],
);
}
/**
* 列出标签接口.
*
* @return array
*/
function api_tag_list()
{
global $zbp;
$type = (int) GetVars('type');
$mng = (int) strtolower((string) GetVars('manage')); //&manage=1
$where = array();
$where[] = array('=', 'tag_Type', $type);
// 权限验证
//检查管理模式权限
if ($mng != 0) {
//检查管理模式权限
ApiCheckAuth(true, 'TagMng');
//ApiCheckAuth(true, 'TagAll');
$limitCount = $zbp->option['ZC_MANAGE_COUNT'];
} else {
// 默认非管理模式
ApiCheckAuth(true, 'view');
$limitCount = $zbp->option['ZC_MANAGE_COUNT'];
}
$filter = ApiGetRequestFilter(
$limitCount,
array(
'ID' => 'tag_ID',
'Order' => 'tag_Order',
'Count' => 'tag_Count',
)
);
$order = $filter['order'];
$limit = $filter['limit'];
$option = $filter['option'];
$listArr = ApiGetObjectArrayList(
$zbp->GetTagList('*', $where, $order, $limit, $option),
array('Url', 'Template')
);
$paginationArr = ApiGetPagebarInfo($option);
return array(
'data' => array(
'list' => $listArr,
'pagebar' => $paginationArr,
),
);
}