-
Notifications
You must be signed in to change notification settings - Fork 28
/
manage-panel.php
270 lines (241 loc) · 9.2 KB
/
manage-panel.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
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
<?php
/**
* copyright 2011 Stephen Just <[email protected]>
* 2014-2015 Daniel Butum <danibutum at gmail dot com>
* This file is part of stk-addons.
*
* stk-addons is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* stk-addons is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with stk-addons. If not, see <http://www.gnu.org/licenses/>.
*/
require_once(__DIR__ . DIRECTORY_SEPARATOR . "config.php");
AccessControl::setLevel(AccessControl::PERM_EDIT_ADDONS);
$_GET['action'] = (isset($_GET['action'])) ? $_GET['action'] : null;
switch ($_GET['view'])
{
case 'overview':
$tpl = StkTemplate::get("manage/page/overview.tpl");
$tpl_data = [
"addons" => [],
"images" => [],
"archives" => []
];
// Get all add-ons
$addons = array_merge(
Addon::getAll(Addon::KART),
Addon::getAll(Addon::TRACK),
Addon::getAll(Addon::ARENA)
);
/**@var Addon[] $addons */
foreach ($addons as $addon)
{
// populate addons
$unapproved = [];
$addon_revisions = $addon->getAllRevisions();
// Don't list if the latest revision is approved
$last_revision = Util::array_last($addon_revisions);
if (!Addon::isApproved($last_revision["status"]))
{
foreach ($addon_revisions as $rev_n => $revision)
{
// see if approved
if (!Addon::isApproved($revision["status"]))
{
$unapproved[] = $revision["revision"];
}
}
}
// add to view
if ($unapproved)
{
$tpl_data["addons"][] = [
"href" => $addon->getLink(),
"name" => h($addon->getName()),
"unapproved" => implode(', ', $unapproved)
];
}
// populate images
$unapproved = [];
foreach ($addon->getImages() as $image)
{
if (!$image->isApproved())
{
$unapproved[] =
'<img src="' . ROOT_LOCATION . 'image.php?size=' . StkImage::SIZE_MEDIUM . '&pic=' . $image->getPath() . '" />';
}
}
// add to view
if ($unapproved)
{
$tpl_data["images"][] = [
"href" => $addon->getLink(),
"name" => h($addon->getName()),
"unapproved" => implode("<br>", $unapproved)
];
}
// populate archives
$unapproved = 0;
foreach ($addon->getSourceFiles() as $archive)
{
if (!$archive->isApproved())
{
$unapproved++;
}
}
// add to view
if ($unapproved)
{
$tpl_data["archives"][] = [
"href" => $addon->getLink(),
"name" => h($addon->getName()),
"unapproved" => $unapproved
];
}
}
$tpl->assign("overview", $tpl_data);
break;
case 'general':
if (!User::hasPermission(AccessControl::PERM_EDIT_SETTINGS))
{
exit("You do not have the necessary permission");
}
$tpl = StkTemplate::get("manage/page/general.tpl");
$tpl_data = [
Config::XML_UPDATE_TIME => (int)Config::get(Config::XML_UPDATE_TIME),
Config::ALLOWED_ADDON_EXTENSIONS => Config::get(Config::ALLOWED_ADDON_EXTENSIONS),
Config::ALLOWED_SOURCE_EXTENSIONS => Config::get(Config::ALLOWED_SOURCE_EXTENSIONS),
Config::EMAIL_ADMIN => Config::get(Config::EMAIL_ADMIN),
Config::EMAIL_LIST => Config::get(Config::EMAIL_LIST),
Config::SHOW_INVISIBLE_ADDONS => [
"options" => [
0 => _h("False"),
1 => _h("True"),
],
"selected" => (Config::get(Config::SHOW_INVISIBLE_ADDONS) == 1) ? 1 : 0
],
Config::FEED_BLOG => Config::get(Config::FEED_BLOG),
Config::IMAGE_MAX_DIMENSION => (int)Config::get(Config::IMAGE_MAX_DIMENSION),
Config::APACHE_REWRITES => Config::get(Config::APACHE_REWRITES),
];
$tpl->assign("general", $tpl_data);
break;
case 'news':
/*
* TODO Allow selecting from a list of conditions rather than typing. Too typo-prone.
* TODO Type semicolon-delimited expressions, e.g. stkversion > 0.7.0;addonid not installed;
* TODO Allow editing in future, in case of goofs or changes.
*/
if (!User::hasPermission(AccessControl::PERM_EDIT_SETTINGS))
{
exit("You do not have the necessary permission");
}
$tpl = StkTemplate::get("manage/page/news.tpl");
$tpl_data = ["items" => News::getAll()];
$tpl->assign("news", $tpl_data);
break;
case 'clients':
/*
* TODO Allow changing association of user-agent strings with versions of STK
* TODO Allow setting various components of the generated XML for each different user-agent
* TODO Make XML generating script generate files for each configuration set
* TODO Make download script provide a certain file based on the user-agent
*/
if (!User::hasPermission(AccessControl::PERM_EDIT_SETTINGS))
{
exit("You do not have the necessary permission");
}
$tpl = StkTemplate::get("manage/page/clients.tpl");
$tpl_data = [
"items" => DBConnection::get()->query(
'SELECT * FROM `{DB_VERSION}_clients`
ORDER BY `agent_string` ASC',
DBConnection::FETCH_ALL
)
];
$tpl->assign("clients", $tpl_data);
break;
case 'cache':
// TODO List cache files
if (!User::hasPermission(AccessControl::PERM_EDIT_SETTINGS))
{
exit("You do not have the necessary permission");
}
$tpl = StkTemplate::get("manage/page/cache.tpl");
$tpl_data = [];
$tpl->assign("cache", $tpl_data);
break;
case 'files':
$tpl = StkTemplate::get("manage/page/files.tpl");
$tpl_data = [];
$files = File::getAllFiles();
$items = [];
foreach ($files as $file)
{
$references = "";
switch ($file["type"])
{
case File::ADDON:
$references = [];
try
{
$rev_files = DBConnection::get()->query(
'SELECT * FROM `{DB_VERSION}_addon_revisions`
WHERE `file_id` = :id',
DBConnection::FETCH_ALL,
[':id' => $file["id"]]
);
// add to
foreach ($rev_files as $rev_file)
{
$references[] = $rev_file['addon_id'];
}
}
catch(DBException $e)
{
throw new Exception("Error on selecting all addon revisions");
}
$references = implode(', ', $references);
break;
default:
$references = "TODO";
break;
}
$file["addon_type"] = Addon::typeToString($file["addon_type"]);
$file["references"] = $references;
$items[] = $file;
}
$tpl_data["items"] = $items;
$tpl->assign("upload", $tpl_data);
break;
case 'logs':
$tpl = StkTemplate::get("manage/page/logs.tpl");
$tpl_data = ["items" => StkLog::getEvents()];
$tpl->assign("logs", $tpl_data);
break;
case 'roles':
if (!User::hasPermission(AccessControl::PERM_EDIT_PERMISSIONS))
{
exit("You do not have the necessary permission");
}
$tpl = StkTemplate::get("manage/page/roles.tpl");
$tpl_data = [
"roles" => AccessControl::getRoleNames(),
"permissions" => AccessControl::getPermissionsChecked()
];
$tpl->assign("roles", $tpl_data);
break;
default:
// TODO maybe redirect
exit(_h('Invalid page. You may have followed a broken link.'));
}
// output the view
echo $tpl;