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
|
<?php
require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/init.inc"; global $title; global $isLoggedIn; global $lang; global $pages; global $isLowerLoggedIn;
$travelling = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/travelling/travelling.json"), true);
$app = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/app.json"), true);
require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/functions.inc";
if (isset($_GET['toggleTravel']) && $isLoggedIn) {
if (isset($travelling[$_GET['member']])) {
$id = $_GET['member'];
$equestria = isset($_GET['equestria']);
$member = getSystemMember(getMemberSystem($id), $id);
$system = getMemberSystem($id);
$metadata = parseMetadata(json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/metadata/$id.json"), true));
$travellingSystem = $system === "gdapd" ? "ynmuc" : "gdapd";
if ($travelling[$_GET['member']]["travelling"]) {
$travelling[$_GET['member']]["travelling"] = false;
$travelling[$_GET['member']]["history"][count($travelling[$_GET['member']]["history"]) - 1]["end"] = date("c");
// Insert code here to run after a travelling member is DELETED.
// $id is the member ID (e.g. rirgf)
// $member is the member object
// $system is the ID of the system the member comes from
// $travellingSystem is the ID of the system the member visits
// $metadata is the ponies.equestria.horse metadata object
// $travellingMember is the member ID from the other system
if (isset($travelling[$_GET['member']]["pluralkit"])) {
$travellingMember = $travelling[$_GET['member']]["pluralkit"];
$reqOptions = [
'http' => [
'method' => "DELETE",
'header' => "Authorization: " . $app["pluralkit"][$travellingSystem === "gdapd" ? "raindrops" : "cloudburst"]
]
];
$reqContext = stream_context_create($reqOptions);
// No actual data is received on DELETE, so we don't even bother trying to collect req response; if it fails it will put a warning in the logs anyway.
sleep(1);
file_get_contents("https://api.pluralkit.me/v2/members/$travellingMember", false, $reqContext);
}
} else {
$travelling[$_GET['member']]["travelling"] = true;
$travelling[$_GET['member']]["equestria"] = $equestria;
$travelling[$_GET['member']]["pluralkit"] = null;
$travelling[$_GET['member']]["history"][] = [
"start" => date("c"),
"end" => null,
"equestria" => $equestria
];
if (!$equestria) {
// Insert code here to run after a travelling member is ADDED.
// $id is the member ID (e.g. rirgf)
// $member is the member
// $system is the system the member comes from
// $metadata is the ponies.equestria.horse metadata
// $travellingMember is unset here
// Store the travelling member ID in $travelling[$id]['pluralkit']
$reqOptions = [
'http' => [
'method' => "POST",
'header' => "Authorization: " . $app["pluralkit"][$travellingSystem === "gdapd" ? "raindrops" : "cloudburst"] . "\r\n" .
"Content-Type: application/json",
'content' => json_encode([
'name' => "$member[name]-travelling",
'display_name' => $member["display_name"],
'color' => $member["color"],
'birthday' => $member["birthday"],
'created' => $member["created"],
'pronouns' => $member["pronouns"],
'avatar_url' => $member["avatar_url"],
'banner' => $member["banner"],
'description' => "**This pony is visiting this system from the " . ($system === "gdapd" ? "Raindrops System" : "Cloudburst System") . ". They are not a permanent member of this system**\n\n$member[description]",
'proxy_tags' => array_map(function ($i) {
$i["prefix"] = "+" . $i['prefix'];
return $i;
}, $member["proxy_tags"]),
'privacy' => $member["privacy"]
])
]
];
$reqContext = stream_context_create($reqOptions);
sleep(1);
$member = json_decode(file_get_contents("https://api.pluralkit.me/v2/members", false, $reqContext), true);
// Member exists?
if (isset($member)) {
$travelling[$id]['pluralkit'] = $member["id"];
}
}
}
}
header("Location: /-/travelling");
file_put_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/travelling/travelling.json", utf8_encode(json_encode($travelling, JSON_PRETTY_PRINT)));
die();
}
require_once $_SERVER['DOCUMENT_ROOT'] . '/includes/header.inc';
global $travelling;
?>
<style>
.member-link:hover, .relation-intro:hover {
opacity: .75;
}
.member-link:active, .relation-intro:active {
opacity: .5;
}
</style>
<br>
<div class="container">
<div>
<h2>System travelling</h2>
<?php foreach ([
...array_values(array_filter(scoreOrderGlobal(), function ($i) use ($travelling) {
return $travelling[$i['id']]["travelling"];
})),
...array_values(array_filter(scoreOrderGlobal(), function ($i) use ($travelling) {
return !$travelling[$i['id']]["travelling"];
}))
] as $member): ?>
<div class="relation" style="background-color:rgba(255, 255, 255, .1);margin-bottom:10px;padding:10px;border-radius:10px;display:grid;grid-template-columns: 1fr 2fr max-content;">
<a class="relation-intro" style="background-color:rgba(255, 255, 255, .05);border-right:1px solid rgba(255, 255, 255, .1);margin:-10px;padding:10px;border-top-left-radius:10px;border-bottom-left-radius:10px;color: white;display:flex;align-items:center;text-decoration: none;" href="/<?= $member["name"] ?>">
<img src="<?= getAsset($member["system"], $member["id"], "heads") ?>" style="width:24px;"> <?= $member["display_name"] ?? $member["name"] ?>
</a>
<div class="relation-item" style="display:flex;align-items:center;margin-left:10px;padding:0 20px;">
<div>
<b style="padding-right:5px;">Current location:</b><span class="list-separator-mobile"><br></span>
<?php $system = $member['_system'] === "gdapd" ? ($travelling[$member['id']]["travelling"] ? "ynmuc" : "gdapd") : ($travelling[$member['id']]["travelling"] ? "gdapd" : "ynmuc"); ?>
<?php if ($travelling[$member['id']]["travelling"] && $travelling[$member['id']]["equestria"]): ?>
<img style="width:24px;" src="/assets/logo/equestria.png"> Equestria
<?php else: ?>
<a class="member-link" href="/<?= $system === "gdapd" ? "raindrops" : "cloudburst" ?>"><img style="width:24px;border-radius:5px;" src="<?= getAsset($system) ?>"> <?= $system === "gdapd" ? "Raindrops" : "Cloudburst" ?> System</a>
<?php endif; ?>
<?php if ($travelling[$member['id']]["travelling"]): ?>
<span class="text-muted">(<?= timeAgo($travelling[$member['id']]["history"][count($travelling[$member['id']]["history"]) - 1]["start"]) ?>)</span>
<?php endif; ?>
</div>
</div>
<div>
<?php if ($travelling[$member['id']]["travelling"]): ?>
<div class="dropdown">
<button type="button" class="btn btn-outline-danger dropdown-toggle" data-bs-toggle="dropdown" <?= $isLowerLoggedIn ? "disabled" : "" ?>>
Stop travelling
</button>
<ul class="dropdown-menu">
<li><a class="dropdown-item" href="?toggleTravel&member=<?= $member['id'] ?>">Stop travelling</a></li>
</ul>
</div>
<?php else: ?>
<div class="dropdown">
<button type="button" class="btn btn-outline-success dropdown-toggle" data-bs-toggle="dropdown" <?= $isLowerLoggedIn ? "disabled" : "" ?>>
Start travelling
</button>
<ul class="dropdown-menu">
<li><a class="dropdown-item" href="?toggleTravel&member=<?= $member['id'] ?>"><img style="width:24px;border-radius:5px;" src="<?= getAsset($system === "gdapd" ? "ynmuc" : "gdapd") ?>"> <?= $system === "gdapd" ? "Cloudburst" : "Raindrops" ?> System</a></li>
<li><a class="dropdown-item" href="?toggleTravel&equestria&member=<?= $member['id'] ?>"><img style="width:24px;" src="/assets/logo/equestria.png"> Equestria</a></li>
</ul>
</div>
<?php endif; ?>
</div>
</div>
<?php endforeach; ?>
</div>
<style>
@media (max-width: 991px) {
.relation {
grid-template-columns: 1fr !important;
}
.relation-intro {
text-align: center;
border-bottom-left-radius: 0 !important;
border-top-right-radius: 10px;
border-right: none !important;
border-bottom: 1px solid rgba(255, 255, 255, .1);
}
.relation-item-marefriends {
margin-top: 20px !important;
}
.relation-item {
margin-top: 10px;
margin-left: 0 !important;
padding: 10px 0 !important;
text-align: center;
}
}
</style>
</div>
<?php require_once $_SERVER['DOCUMENT_ROOT'] . '/includes/footer.inc'; ?>
|