-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcrud.php
63 lines (51 loc) · 1.57 KB
/
crud.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
<?php
error_reporting(0);
function stdDir($dir) { return trim($dir, '/')."/"; }
class CRUD {
public $userDir;
function __construct() {
$config = json_decode(file_get_contents("../manager.conf") ?? "{}", true);
if(!$config) die("{success: 0, error: 1}");
$dir = $config["svg-path"];
if(!is_dir($dir)) mkdir($dir); // Make directory if not exist.
$this->userDir = stdDir($dir);
}
public function addIcon(?string $fileName, $fileContent): bool {
if($fileName && $fileContent) {
return boolval(file_put_contents($this->userDir.$fileName, $fileContent));
} else {
return false;
}
}
public function removeIcon(?string $fileName): bool {
return $fileName ? unlink($this->userDir.$fileName) : false;
}
public function generateFont(): array {
$output = "";
$result = 0;
exec("python3 font-generator.py", $output, $result);
return [!$result, $output];
}
}
$data = json_decode(file_get_contents('php://input'), true);
if($data) {
$crud = new CRUD;
$success = false;
$message = "";
switch($data["op"]) {
case "add":
$success = $crud->addIcon($data["name"], $data["content"]);
break;
case "remove":
$success = $crud->removeIcon($data["name"]);
break;
case "generateFont":
list($success, $message) = $crud->generateFont();
break;
}
echo json_encode([
"success" => $success,
"message" => $message,
]);
}
?>