forked from lincanbin/Carbon-Forum
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dashboard.php
230 lines (221 loc) · 8.17 KB
/
dashboard.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
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
<?php
include(__DIR__ . '/common.php');
require(__DIR__ . '/language/' . ForumLanguage . '/dashboard.php');
Auth(5);
$BasicMessage = '';
$PageMessage = '';
$AdvancedMessage = '';
$OauthMessage = '';
$CacheMessage = '';
$Action = Request('Post', 'Action', false);
$OauthData = json_decode($Config['CacheOauth'], true);
$OauthData = $OauthData?$OauthData:array();
$OauthConfig = json_decode(preg_replace("/\/\*[\s\S]+?\*\//", "", file_get_contents("includes/Oauth.config.json")), true);
switch ($Action) {
case 'Cache':
set_time_limit(0);
UpdateConfig(array(
'NumFiles' => intval($DB->single('SELECT count(ID) FROM ' . $Prefix . 'upload')),
'NumTopics' => intval($DB->single('SELECT count(*) FROM ' . $Prefix . 'topics WHERE IsDel=0')),
'NumPosts' => intval($DB->single('SELECT sum(Replies) FROM ' . $Prefix . 'topics WHERE IsDel=0')),
'NumUsers' => intval($DB->single('SELECT count(ID) FROM ' . $Prefix . 'users')),
'NumTags' => intval($DB->single('SELECT count(ID) FROM ' . $Prefix . 'tags')),
'CacheHotTags' => json_encode($DB->query('SELECT ID,Name,Icon,TotalPosts,Followers FROM ' . $Prefix . 'tags
WHERE IsEnabled=1
ORDER BY TotalPosts DESC
LIMIT ' . $Config['TopicsPerPage']))
));
$DB->query('UPDATE ' . $Prefix . 'users u
SET u.Topics=(SELECT count(*) FROM ' . $Prefix . 'topics t
WHERE t.UserName=u.UserName AND IsDel=0),
u.Replies=(SELECT count(*) FROM ' . $Prefix . 'posts p
WHERE p.UserName=u.UserName AND p.IsTopic=0),
u.Followers=(SELECT count(*) FROM ' . $Prefix . 'favorites f
WHERE f.FavoriteID=u.ID AND Type=3)
');
$DB->query('UPDATE ' . $Prefix . 'topics t
SET t.Replies=(SELECT count(*) FROM ' . $Prefix . 'posts p
WHERE p.TopicID=t.ID AND p.IsTopic=0 AND p.IsDel=0),
t.Favorites=(SELECT count(*) FROM ' . $Prefix . 'favorites f
WHERE f.FavoriteID=t.ID AND Type=1)
');
$DB->query('UPDATE ' . $Prefix . 'tags t
SET t.TotalPosts=(SELECT count(*) FROM ' . $Prefix . 'topics topic
WHERE topic.ID in (
SELECT TopicID FROM ' . $Prefix . 'posttags p
WHERE p.TagID=t.ID)
AND topic.IsDel=0),
t.Followers=(SELECT count(*) FROM ' . $Prefix . 'favorites f
WHERE f.FavoriteID=t.ID AND f.Type=2)
');
if ($MCache) {
if (extension_loaded('memcached') || extension_loaded('memcache') || extension_loaded('xcache')) {
//MemCached or MemCache
$MCache->flush();
} elseif (extension_loaded('redis')) {
//Redis
//https://github.com/phpredis/phpredis
$MCache->flushAll();
}
}
$CacheMessage = $Lang['Successfully_Refreshed'];
break;
case 'Statistics':
set_time_limit(0);
$DB->query('DELETE FROM ' . $Prefix . 'statistics');
$StatisticsTime = strtotime(date('Y-m-d', $DB->single('SELECT UserRegTime FROM ' . $Prefix . 'users ORDER BY ID ASC LIMIT 1')));
while ($StatisticsTime < ($TimeStamp - 86400)) {
$StatisticsTimeAddOneDay = $StatisticsTime + 86400;
//echo date('Y-m-d', $StatisticsTime);
//echo '<br />';
$DB->query('INSERT INTO `' . $Prefix . 'statistics`
(
`DaysUsers`,
`DaysPosts`,
`DaysTopics`,
`TotalUsers`,
`TotalPosts`,
`TotalTopics`,
`DaysDate`,
`DateCreated`
)
SELECT
(SELECT count(*) FROM ' . $Prefix . 'users u
WHERE u.UserRegTime >= ' . $StatisticsTime . '
AND u.UserRegTime < ' . $StatisticsTimeAddOneDay . ' ),
(SELECT count(*) FROM ' . $Prefix . 'posts p
WHERE p.PostTime >= ' . $StatisticsTime . '
AND p.PostTime < ' . $StatisticsTimeAddOneDay . '
AND p.IsTopic = 0),
(SELECT count(*) FROM ' . $Prefix . 'topics t
WHERE t.PostTime >= ' . $StatisticsTime . '
AND t.PostTime < ' . $StatisticsTimeAddOneDay . '
AND t.IsDel = 0),
(SELECT count(*) FROM ' . $Prefix . 'users u
WHERE u.UserRegTime < ' . $StatisticsTimeAddOneDay . ' ),
(SELECT count(*) FROM ' . $Prefix . 'posts p
WHERE p.TopicID NOT IN (SELECT ID FROM ' . $Prefix . 'topics t
WHERE t.PostTime < ' . $StatisticsTimeAddOneDay . '
AND t.IsDel = 1)
AND p.PostTime < ' . $StatisticsTimeAddOneDay . '
AND p.IsTopic = 0 ),
(SELECT count(*) FROM ' . $Prefix . 'topics t
WHERE t.PostTime < ' . $StatisticsTimeAddOneDay . '
AND t.IsDel = 0),
:DaysDate,
:DateCreated
FROM dual
WHERE NOT EXISTS(
SELECT * FROM `' . $Prefix . 'statistics`
WHERE DaysDate = :DaysDate2
)
', array(
'DaysDate' => date('Y-m-d', $StatisticsTime),
'DaysDate2' => date('Y-m-d', $StatisticsTime),
'DateCreated' => $StatisticsTimeAddOneDay - 1
));
$StatisticsTime = $StatisticsTimeAddOneDay;
}
$CacheMessage = $Lang['Successfully_Refreshed'];
break;
case 'AddOauth':
$AppName = $_POST['AppName'];
$AppKey = $_POST['AppKey'];
$AppSecret = $_POST['AppSecret'];
foreach ($AppName as $Key => $Value) {
if($AppName[$Key] && $AppKey[$Key] && $AppSecret[$Key]){
if(isset($OauthData[$Value])){
$DB->query('UPDATE `' . $Prefix . 'app`
SET
`AppKey` = ?,
`AppSecret` = ?,
`Time` = ?
WHERE `AppName` = ?',
array(
$AppKey[$Key],
$AppSecret[$Key],
$TimeStamp,
$AppName[$Key]
)
);
}else{
$DB->query('INSERT INTO `' . $Prefix . 'app`(ID, AppName, AppKey, AppSecret, Time)
SELECT ?,?,?,?,?
FROM dual
WHERE NOT EXISTS(
SELECT *
FROM `' . $Prefix . 'app`
WHERE AppName = ?
);', array(
null,
$AppName[$Key],
$AppKey[$Key],
$AppSecret[$Key],
$TimeStamp,
$AppName[$Key]
)
);
}
}else{
if(isset($OauthData[$Value])){
//$DB->query('DELETE FROM `' . $Prefix . 'app` WHERE AppName = ?;', array($AppName[$Key]));
}
}
}
$OauthData = array();
foreach ($DB->query('SELECT * FROM `' . $Prefix . 'app`') as $Value) {
$OauthData[$Value['AppName']] = $Value;
$OauthData[$Value['AppName']]['Alias'] = $OauthConfig[$Value['AppName']]['Alias'];
$OauthData[$Value['AppName']]['LogoUrl'] = $OauthConfig[$Value['AppName']]['LogoUrl'];
$OauthData[$Value['AppName']]['ButtonImageUrl'] = $OauthConfig[$Value['AppName']]['ButtonImageUrl'];
}
UpdateConfig(array('CacheOauth' => json_encode($OauthData)));
$OauthMessage = $Lang['Oauth_Settings_Successfully_Saved'];
break;
default:
$NewConfig = $_POST;
//Fool-proofing
if ($Action == 'Basic') {
$NewConfig['TopicsPerPage'] = intval(Request('Post', 'TopicsPerPage', 20));
$NewConfig['PostsPerPage'] = intval(Request('Post', 'PostsPerPage', 20));
$NewConfig['MaxTagsNum'] = intval(Request('Post', 'MaxTagsNum', 5));
$NewConfig['MaxTagChars'] = intval(Request('Post', 'MaxTagChars', 128));
$NewConfig['MaxPostChars'] = intval(Request('Post', 'MaxPostChars', 65536));
}
//Fool-proofing
if ($Action == 'Advanced') {
if ($NewConfig['MobileDomainName'] == $_SERVER['HTTP_HOST']) {
$NewConfig['MobileDomainName'] = $Config['MobileDomainName'];
}
if ($NewConfig['AppDomainName'] == $_SERVER['HTTP_HOST']) {
$NewConfig['AppDomainName'] = $Config['AppDomainName'];
}
}
foreach ($NewConfig as $Key => $Value) {
if (!array_key_exists($Key, $Config) || $Value == $Config[$Key]) {
unset($NewConfig[$Key]);
} else {
$Config[$Key] = $NewConfig[$Key];
}
}
UpdateConfig($NewConfig);
switch ($Action) {
case 'Basic':
$BasicMessage = str_replace('{{NewConfig}}', count($NewConfig), $Lang['Basic_Settings_Successfully_Saved']);
break;
case 'Page':
$PageMessage = str_replace('{{NewConfig}}', count($NewConfig), $Lang['Page_Settings_Successfully_Saved']);
break;
case 'Advanced':
$AdvancedMessage = str_replace('{{NewConfig}}', count($NewConfig), $Lang['Advanced_Settings_Successfully_Saved']);
break;
default:
break;
}
break;
}
$DB->CloseConnection();
// 页面变量
$PageTitle = $Lang['System_Settings'];
$ContentFile = $TemplatePath . 'dashboard.php';
include($TemplatePath . 'layout.php');