forked from supertuxkart/stk-addons
-
Notifications
You must be signed in to change notification settings - Fork 0
/
upload.php
173 lines (160 loc) · 5.5 KB
/
upload.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
<?php
/**
* copyright 2009 Lucas Baudin <[email protected]>
* 2014 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_ADD_ADDON);
// used to set the post field with the same name
$upload_type = !empty($_GET['upload-type']) ? Upload::stringToType($_GET['upload-type']) : null;
$addon_type_string = !empty($_GET['type']) ? $_GET['type'] : null; // addon type
$addon_type = Addon::stringToType($addon_type_string);
$addon_name = !empty($_GET['name']) ? $_GET['name'] : null; // addon name
$tpl = StkTemplate::get('upload.tpl')
->addBootstrapFileInputLibrary()
->addScriptInclude("upload.js");
$upload_form = [
// add new things for this addon
"is_update" => Addon::isAllowedType($addon_type) && $addon_name,
"addon" => [
"type" => $addon_type_string,
"name" => $addon_name,
],
"upload_type" => [
"options" => [
Upload::SOURCE => _h('Source Archive'),
Upload::IMAGE => _h('Image File') . ' (.png, .jpg, .jpeg)',
Upload::REVISION => _h('Addon Revision')
],
"selected" => $upload_type,
"default" => Upload::ADDON // default value when the upload type is not defined
],
"display" => true,
];
if (isset($_GET["submit"])) // form submitted
{
if (empty($_POST))
{
$upload_form["display"] = false;
$tpl->assign("upload", $upload_form);
$tpl->assign(
"errors",
_h("You did not submit anything/Maximum POST (upload) size exceeded (your file is too large!)")
);
exit($tpl);
}
$l_author = !empty($_POST["l_author"]) ? (int)$_POST["l_author"] : null;
$expected_type = !empty($_POST['upload-type']) ? (int)$_POST['upload-type'] : null;
function getAgreement($l_author, $expected_type)
{
// Check to make sure all form boxes are good
$required_fields_license = [
'license_gpl',
'license_cc-by',
'license_cc-by-sa',
'license_pd',
'license_bsd',
'license_other',
];
// at least one of the checkboxes must be checked
if (count($required_fields_license) === count(Validate::ensureIsSet($_POST, $required_fields_license)))
{
return false;
}
if (!isset($_POST['l_agreement']) || !$l_author)
{
return false;
}
if ($expected_type === Upload::IMAGE) // do not require License.txt file
{
if ($l_author !== 1 && $l_author !== 2)
{
return false;
}
}
else
{
// the 2 big radios with checkboxes
if ($l_author === 1 && !isset($_POST['l_licensefile1']))
{
return false;
}
if ($l_author === 2 && !isset($_POST['l_licensefile2']))
{
return false;
}
}
return true;
}
if (getAgreement($l_author, $expected_type) === true) // upload process
{
$upload_form["display"] = false;
// Generate a note to moderators for license verification
$moderator_message = '';
if (isset($_POST['license_other']))
{
$moderator_message .= 'Auto-message: Moderator: Please verify that license is "free"' . "\n";
}
if ($l_author == 1)
{
$moderator_message .= 'Auto-message: Content is solely created by uploader.' . "\n";
}
else // 2
{
$moderator_message .= 'Auto-message: Content contains third-party open content.' . "\n";
}
try
{
$upload = new Upload($_FILES['file_addon'], $addon_name, $addon_type, $expected_type, $moderator_message);
$tpl->assign("warnings", $upload->getWarningMessage());
$tpl->assign("success", $upload->getSuccessMessage());
}
catch (UploadException $e)
{
$tpl->assign("errors", $e->getMessage());
}
catch (Exception $e)
{
if (DEBUG_MODE)
{
// Let the fancy UI catch it.
throw $e;
}
else
{
$tpl->assign(
"errors",
'Unexpected exception: ' . $e->getMessage() .
'<strong>If this is ever visible, that\'s a bug!</strong>'
);
}
}
}
else
{
$upload_form["display"] = false;
$tpl->assign(
"errors",
_h(
'Your response to the agreement was unacceptable.' .
'You may not upload this content to the STK Addons website.'
)
);
}
}
$tpl->assign("upload", $upload_form);
echo $tpl;