summaryrefslogtreecommitdiff
path: root/pages/travelling.php
diff options
context:
space:
mode:
authorMinteck <contact@minteck.org>2022-08-26 22:29:23 +0200
committerMinteck <contact@minteck.org>2022-08-26 22:29:23 +0200
commit09bd0164ebc020a54b944b7326dcba496fb5d82c (patch)
tree0c5e765e627ecc94e534ccb6e2bc83917d58dc4c /pages/travelling.php
parenta2df9a69dcc14cb70118cda2ded499055e7ee358 (diff)
downloadpluralconnect-09bd0164ebc020a54b944b7326dcba496fb5d82c.tar.gz
pluralconnect-09bd0164ebc020a54b944b7326dcba496fb5d82c.tar.bz2
pluralconnect-09bd0164ebc020a54b944b7326dcba496fb5d82c.zip
idk when was the last commit so I'm making a new one - Violet Dawn
Diffstat (limited to 'pages/travelling.php')
-rw-r--r--pages/travelling.php81
1 files changed, 78 insertions, 3 deletions
diff --git a/pages/travelling.php b/pages/travelling.php
index 260ea15..affe92e 100644
--- a/pages/travelling.php
+++ b/pages/travelling.php
@@ -3,18 +3,93 @@
require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/session.php"; global $isLoggedIn;
if (!$isLoggedIn) header("Location: /login") and die();
$travelling = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/travelling.json"), true);
+$app = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/app.json"), true);
+
+require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/functions.php";
if (isset($_GET['toggleTravel'])) {
if (isset($travelling[$_GET['member']])) {
+ $id = $_GET['member'];
+ $member = getSystemMember(getMemberSystem($id), $id);
+ $system = getMemberSystem($id);
+ $metadata = parseMetadata(json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/$system-$id-metadata.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']]["pluralkit"] = null;
$travelling[$_GET['member']]["history"][] = [
"start" => date("c"),
"end" => null
];
+
+ // 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"];
+ }
}
}
@@ -23,7 +98,7 @@ if (isset($_GET['toggleTravel'])) {
die();
}
-$title = "System Travelling"; require_once $_SERVER['DOCUMENT_ROOT'] . '/includes/header.php';
+$title = "System travels manager"; require_once $_SERVER['DOCUMENT_ROOT'] . '/includes/header.php';
global $travelling;
?>
@@ -44,8 +119,8 @@ global $travelling;
<h2>System Travelling</h2>
<?php foreach (scoreOrderGlobal() 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["_system"] === "gdapd" ? "raindrops" : "cloudburst" ?>/<?= $member["name"] ?>">
- <img src="/assets/uploads/pt<?= file_exists($_SERVER['DOCUMENT_ROOT'] . "/assets/uploads/pt-" . $member['name'] . ".png") ? "-" . $member['name'] : "" ?>.png" style="width:24px;">&nbsp;<?= $member["display_name"] ?? $member["name"] ?>
+ <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="/assets/uploads/pt<?= file_exists($_SERVER['DOCUMENT_ROOT'] . "/assets/uploads/pt-" . resolveMember($member['name']) . ".png") ? "-" . $member['name'] : "" ?>.png" style="width:24px;">&nbsp;<?= $member["display_name"] ?? $member["name"] ?>
</a>
<div class="relation-item" style="display:flex;align-items:center;margin-left:10px;padding:0 20px;">