-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
54 lines (45 loc) · 1.41 KB
/
index.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
<?php
require_once(__DIR__."/Plugin.php");
header("Content-Type: application/json");
$response = [];
if (empty($_FILES) || $_FILES["plugin"]["error"]) {
$response["message"] = "no file uploaded";
http_response_code(400);
echo json_encode($response);
return;
}
$original_file = basename($_FILES["plugin"]["name"]);
$original_file_type = strtolower(pathinfo($original_file, PATHINFO_EXTENSION));
if ($original_file_type != "pmf") {
echo "only pmf files are allowed";
http_response_code(400);
echo json_encode($response);
return;
}
$temp_file = tempnam(sys_get_temp_dir(), $original_file);
if (!move_uploaded_file($_FILES["plugin"]["tmp_name"], $temp_file)) {
$response["message"] = "error uploading file";
http_response_code(500);
echo json_encode($response);
return;
}
try {
$plugin = new PMFPlugin($temp_file);
function utf8ize($mixed) {
if (is_array($mixed)) {
foreach ($mixed as $key => $value) {
$mixed[$key] = utf8ize($value);
}
} elseif (is_string($mixed)) {
return mb_convert_encoding($mixed, "UTF-8", "UTF-8");
}
return $mixed;
}
$response["plugin"] = utf8ize($plugin->getPluginInfo())["code"];
} catch (Exception $e) {
$response["message"] = "error processing plugin";
http_response_code(500);
echo json_encode($response);
return;
}
echo json_encode($response);