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
|
<?php
require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/init.inc"; global $title; global $isLowerLoggedIn; global $isLoggedIn; global $lang; global $pages; global $app;
require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/util/functions.inc";
require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/util/bitset.inc";
if (!isset($_GET['_']) || trim($_GET['_']) === "") peh_error("Invalid request", 400);
$parts = explode("/", $_GET['_']);
array_shift($parts);
array_shift($parts);
$system = $parts[0];
$member = !isset($parts[1]) || $parts[1] === "" ? null : $parts[1];
if ($system !== "cloudburst" && $system !== "raindrops" && $system !== $app["other"]["slug"]) peh_error("Invalid system name: " . $system, 400);
$systemCommonName = $system === "cloudburst" ? "Cloudburst System" : ($system === $app["other"]["slug"] ? $app["other"]["name"] : "Raindrops System");
$systemID = $system === "cloudburst" ? "ynmuc" : ($system === $app["other"]["slug"] ? $app["other"]["id"] : "gdapd");
if ($isLowerLoggedIn && $systemID !== $app["other"]["id"]) {
header("Location: /");
die();
}
if ($member === null) {
header("Location: /");
die();
} else {
$members = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/" . $systemID . "/members.json"), true);
$memberData = null;
$memberCommonName = null;
$memberID = null;
foreach ($members as $m) {
if ($m['name'] === $member) {
$memberData = $m;
$memberCommonName = $m['display_name'] ?? $m['name'];
$memberID = $m['id'];
}
}
if ($memberData === null) {
peh_error("Not found", 404);
}
if (isset($_GET["submit"])) {
if (file_exists($_SERVER['DOCUMENT_ROOT'] . "/includes/data/metadata/" . $memberID . ".json")) {
$metadata = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/metadata/" . $memberID . ".json"), true);
} else {
die();
}
$toUpdate = [];
header("Content-Type: text/plain");
if (isset($_GET["food"]) && is_numeric($_GET["food"])) {
$toUpdate["food"] = (int)$_GET["food"];
}
if (isset($_GET["shared_memory"]) && is_numeric($_GET["shared_memory"])) {
$toUpdate["shared_memory"] = (int)$_GET["shared_memory"];
}
if (isset($_GET["species"][0])) {
if (trim($_GET["species"][0]) === "") {
$toUpdate["species"][0] = null;
} else {
$toUpdate["species"][0] = $_GET["species"][0];
}
}
if (isset($_GET["species"][1])) {
if (trim($_GET["species"][1]) === "") {
$toUpdate["species"][1] = null;
} else {
$toUpdate["species"][1] = $_GET["species"][1];
}
}
$toUpdate["alignment"] = [];
if (isset($_GET["alignment"]["sexual"])) {
$toUpdate["alignment"]["sexual"] = $_GET["alignment"]["sexual"];
}
if (isset($_GET["alignment"]["romantic"])) {
$toUpdate["alignment"]["romantic"] = $_GET["alignment"]["romantic"];
}
if (isset($_GET["interest"])) {
$toUpdate["interest"] = strip_tags($_GET["interest"]);
}
if (isset($_GET["gender"])) {
$toUpdate["gender"] = strip_tags($_GET["gender"]);
}
$regex = "/^(ynmuc|gdapd|" . $app["other"]["id"] . ")\/[a-z]{5}$/m";
if (isset($_GET["marefriends"])) {
$toUpdate["marefriends"] = array_values(array_filter(array_map(function ($i) { return trim($i); }, explode(",", $_GET["marefriends"])), function ($i) use ($regex) {
return !!preg_match($regex, $i);
}));
}
if (isset($_GET["sexfriends"])) {
$toUpdate["sexfriends"] = array_values(array_filter(array_map(function ($i) { return trim($i); }, explode(",", $_GET["sexfriends"])), function ($i) use ($regex) {
return !!preg_match($regex, $i);
}));
}
if (isset($_GET["sisters"])) {
$toUpdate["sisters"] = array_values(array_filter(array_map(function ($i) { return trim($i); }, explode(",", $_GET["sisters"])), function ($i) use ($regex) {
return !!preg_match($regex, $i);
}));
}
if (isset($_GET["caretakers"])) {
$toUpdate["caretakers"] = array_values(array_filter(array_map(function ($i) { return trim($i); }, explode(",", $_GET["caretakers"])), function ($i) use ($regex) {
return !!preg_match($regex, $i);
}));
}
if (isset($_GET["friends"])) {
$toUpdate["friends"] = array_values(array_filter(array_map(function ($i) { return trim($i); }, explode(",", $_GET["friends"])), function ($i) use ($regex) {
return !!preg_match($regex, $i);
}));
}
if (isset($_GET['regressed'])) {
if (!!preg_match("/^[a-z]{5}$/m", $_GET['regressed'])) {
$toUpdate["regression"] = $_GET['regressed'];
} else {
$toUpdate["regression"] = null;
}
}
$toUpdate["birth"] = [
"date" => "01-01",
"year" => null,
"age" => 0
];
if (isset($_GET["age"]) && is_numeric($_GET["age"])) {
$toUpdate["birth"]["age"] = (int)$_GET["age"];
} else if (isset($_GET["age"]) && preg_match("/^\d{1,2}-\d{1,2}$/", $_GET["age"]) === 1) {
$toUpdate["birth"]["age"] = $_GET["age"];
}
if (isset($_GET["birth"]) && trim($_GET['birth']) !== "" && !!preg_match("/^\d{4}-\d{2}-\d{2}$/m", $_GET['birth'])) {
$toUpdate["birth"]["year"] = (int)substr($_GET["birth"],0, 4);
$toUpdate["birth"]["date"] = substr($_GET["birth"],5);
}
if (isset($_GET["membc"])) {
$toUpdate["code"] = $_GET['membc'];
}
$flags = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/flags.json"), true);
foreach ($flags as $id => $name) if (!is_array($name)) {
if (isset($_GET['flags'][$id])) {
$toUpdate[$id] = true;
} else {
$toUpdate[$id] = false;
}
} else foreach ($name as $id2 => $_) {
if (isset($_GET['flags'][$id][$id2])) {
$toUpdate[$id][$id2] = true;
} else {
$toUpdate[$id][$id2] = false;
}
}
foreach ($toUpdate as $item => $value) {
$metadata[$item] = $value;
}
if (isset($metadata["bitset"])) unset($metadata["bitset"]);
if (isset($metadata["code"])) unset($metadata["code"]);
if (trim($metadata["species"][1]) === "") unset($metadata["species"][1]);
file_put_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/metadata/" . $memberID . ".json", json_encode($metadata));
file_put_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/cache/navigation.json", "{}");
file_put_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/cache/home.json", "{}");
header("Location: /" . $_GET['_']);
} else {
require_once $_SERVER['DOCUMENT_ROOT'] . '/includes/fragments/metadata.inc';
}
}
exit;
|