From 8cc1f13c17fa2fb5a4410542d39e650e02945634 Mon Sep 17 00:00:00 2001
From: Minteck <contact@minteck.org>
Date: Thu, 23 Feb 2023 14:20:13 +0100
Subject: Updated 27 files, added assets/uploads/pt-twilightsparkle.png and
 deleted 3 files (automated)

---
 pages/about.inc    | 16 ------------
 pages/docs.inc     | 77 +++++++++++++++++++++++++++++++++++-------------------
 pages/edit.inc     | 14 ++++++----
 pages/home.inc     |  4 +--
 pages/metadata.inc | 16 ++++++++----
 pages/page.inc     | 25 +++++++++++++-----
 6 files changed, 90 insertions(+), 62 deletions(-)

(limited to 'pages')

diff --git a/pages/about.inc b/pages/about.inc
index 0e0857e..8a62d66 100644
--- a/pages/about.inc
+++ b/pages/about.inc
@@ -44,22 +44,6 @@ $sizeData = array_reduce(array_map(function ($i) {
     return $a + $b;
 });
 
-function prettySize($bytes) {
-    if ($bytes > 1024) {
-        if ($bytes > 1024**2) {
-            if ($bytes > 1024**3) {
-                return round($bytes / 1024**3, 1) . " GB";
-            } else {
-                return round($bytes / 1024**2, 1) . " MB";
-            }
-        } else {
-            return round($bytes / 1024, 1) . " KB";
-        }
-    } else {
-        return $bytes . " B";
-    }
-}
-
 ?>
 
 <br>
diff --git a/pages/docs.inc b/pages/docs.inc
index f4ffcc3..5e0ac65 100644
--- a/pages/docs.inc
+++ b/pages/docs.inc
@@ -34,6 +34,19 @@ if ($select === "add") {
 
 require_once $_SERVER['DOCUMENT_ROOT'] . '/includes/header.inc';
 
+function showDocument($item) { ?>
+    <div style="display: grid; grid-template-columns: 2fr repeat(3, 1fr);">
+        <?= $item["name"] ?>&nbsp;
+        <?php if (str_starts_with(strip_tags($item["contents"]), "/delete")): ?>
+            <span class="badge bg-warning rounded-pill text-black" style="width: max-content;">Deleting in <?= round((($item["last"]["date"] + 86400) - time()) / 3600) ?> hours</span>
+        <?php else: ?>
+            <span class="text-muted"><?= prettySize(filesize($_SERVER['DOCUMENT_ROOT'] . "/includes/data/docs/" . $item["id"] . ".json")) ?></span>
+            <span class="relative-time text-muted" data-relative-timestamp="<?= $item["last"]["date"] ?>"><?= timeAgo($item["last"]["date"]) ?></span>
+            <span class="text-muted"><?= $item["last"]["author"] === "raindrops" ? "Raindrops System" : "Cloudburst System" ?></span>
+        <?php endif; ?>
+    </div>
+<?php }
+
 ?>
 
 <br>
@@ -249,57 +262,67 @@ require_once $_SERVER['DOCUMENT_ROOT'] . '/includes/header.inc';
                     }
                 }
 
+                foreach ($categories as $category => $_) {
+                    uasort($categories[$category], function ($a, $b) {
+                        return preg_replace("/[^a-z\d]/m", "", strtolower($b["name"])) < preg_replace("/[^a-z\d]/m", "", strtolower($a["name"]));
+                    });
+                }
+
+                foreach ($categoryFirst as $category => $_) {
+                    uasort($categoryFirst[$category], function ($a, $b) {
+                        return preg_replace("/[^a-z\d]/m", "", strtolower($b["name"])) < preg_replace("/[^a-z\d]/m", "", strtolower($a["name"]));
+                    });
+                }
+
                 uasort($unsorted, function ($a, $b) {
-                    return $b["last"]["date"] - $a["last"]["date"];
+                    return preg_replace("/[^a-z\d]/m", "", strtolower($b["name"])) < preg_replace("/[^a-z\d]/m", "", strtolower($a["name"]));
                 });
 
                 uasort($deletable, function ($a, $b) {
-                    return $b["last"]["date"] - $a["last"]["date"];
+                    return preg_replace("/[^a-z\d]/m", "", strtolower($b["name"])) < preg_replace("/[^a-z\d]/m", "", strtolower($a["name"]));
                 });
 
                 $fullList = [...$categoryFirst, ...$categories];
 
                 ?>
 
-                <?php foreach ($fullList as $category => $items): ?>
+                <?php foreach ($fullList as $category => $items): if ($category != "Archives"): ?>
                 <h4><?= str_starts_with($category, ".") ? substr($category, 1) : $category ?></h4><div class="list-group">
                 <?php foreach ($items as $item): ?>
                     <a href="/-/docs/<?= $item["id"] ?>" id="document-<?= $item["id"] ?>" class="list-group-item list-group-item-action document-listing <?php if (str_starts_with(strip_tags($item["contents"]), "/delete")): ?>opacity-75<?php endif; ?>">
-                        <?= $item["name"] ?>&nbsp;
-                        <?php if (str_starts_with(strip_tags($item["contents"]), "/delete")): ?>
-                            <span class="badge bg-warning rounded-pill text-black">Deleting in <?= round((($item["last"]["date"] + 86400) - time()) / 3600) ?> hours</span>
-                        <?php else: ?>
-                            <span class="relative-time text-muted" data-relative-timestamp="<?= $item["last"]["date"] ?>"><?= timeAgo($item["last"]["date"]) ?></span>
-                        <?php endif; ?>
+                        <?php showDocument($item) ?>
                     </a>
                 <?php endforeach; ?></div>
                 <hr>
-                <?php endforeach; ?>
+                <?php endif; endforeach; ?>
 
                 <h4>Unsorted</h4><div class="list-group">
                 <?php foreach ($unsorted as $item): ?>
                 <a href="/-/docs/<?= $item["id"] ?>" id="document-<?= $item["id"] ?>" class="list-group-item list-group-item-action document-listing <?php if (str_starts_with(strip_tags($item["contents"]), "/delete")): ?>opacity-75<?php endif; ?>">
-                    <?= $item["name"] ?>&nbsp;
-                    <?php if (str_starts_with(strip_tags($item["contents"]), "/delete")): ?>
-                    <span class="badge bg-warning rounded-pill text-black">Deleting in <?= round((($item["last"]["date"] + 86400) - time()) / 3600) ?> hours</span>
-                    <?php else: ?>
-                    <span class="relative-time text-muted" data-relative-timestamp="<?= $item["last"]["date"] ?>"><?= timeAgo($item["last"]["date"]) ?></span>
-                    <?php endif; ?>
+                    <?php showDocument($item) ?>
                 </a>
                 <?php endforeach; ?></div>
 
                 <hr>
-                <h4 id="deletable">Marked for deletion</h4><div class="list-group">
-                <?php foreach ($deletable as $item): ?>
-                <a href="/-/docs/<?= $item["id"] ?>" id="document-<?= $item["id"] ?>" class="list-group-item list-group-item-action document-listing <?php if (str_starts_with(strip_tags($item["contents"]), "/delete")): ?>opacity-75<?php endif; ?>">
-                    <?= $item["name"] ?>&nbsp;
-                    <?php if (str_starts_with(strip_tags($item["contents"]), "/delete")): ?>
-                        <span class="badge bg-warning rounded-pill text-black">Deleting in <?= round((($item["last"]["date"] + 86400) - time()) / 3600) ?> hours</span>
-                    <?php else: ?>
-                        <span class="relative-time text-muted" data-relative-timestamp="<?= $item["last"]["date"] ?>"><?= timeAgo($item["last"]["date"]) ?></span>
-                    <?php endif; ?>
-                </a>
-                <?php endforeach; ?></div>
+                <details>
+                    <summary>Show archives and marked for deletion</summary>
+
+                    <h4 style="margin-top: 10px;">Archives</h4>
+                    <div class="list-group">
+                        <?php foreach ($categories["Archives"] as $item): ?>
+                            <a href="/-/docs/<?= $item["id"] ?>" id="document-<?= $item["id"] ?>" class="list-group-item list-group-item-action document-listing <?php if (str_starts_with(strip_tags($item["contents"]), "/delete")): ?>opacity-75<?php endif; ?>">
+                                <?php showDocument($item) ?>
+                            </a>
+                        <?php endforeach; ?></div>
+
+                    <hr>
+                    <h4 id="deletable">Marked for deletion</h4><div class="list-group">
+                        <?php foreach ($deletable as $item): ?>
+                            <a href="/-/docs/<?= $item["id"] ?>" id="document-<?= $item["id"] ?>" class="list-group-item list-group-item-action document-listing <?php if (str_starts_with(strip_tags($item["contents"]), "/delete")): ?>opacity-75<?php endif; ?>">
+                                <?php showDocument($item) ?>
+                            </a>
+                        <?php endforeach; ?></div>
+                </details>
             </div>
 
             <hr>
diff --git a/pages/edit.inc b/pages/edit.inc
index 021ae4b..afaddd3 100644
--- a/pages/edit.inc
+++ b/pages/edit.inc
@@ -13,7 +13,7 @@ function getSubsystemByID(string $id) {
     return $subsystem;
 }
 
-require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/init.inc"; global $title; global $isLoggedIn; global $lang; global $pages;
+require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/init.inc"; global $isLowerLoggedIn; global $title; global $isLoggedIn; global $lang; global $pages; global $app;
 
 if (!isset($_GET['_']) || trim($_GET['_']) === "") header("Location: /?error=Invalid request") and die();
 
@@ -23,12 +23,16 @@ array_shift($parts);
 $system = $parts[0];
 $member = !isset($parts[1]) || $parts[1] === "" ? null : $parts[1];
 
-if ($system !== "cloudburst" && $system !== "raindrops") header("Location: /?error=Invalid system name: " . $system) and die();
-$systemCommonName = $system === "cloudburst" ? "Cloudburst System" : "Raindrops System";
-$systemID = $system === "cloudburst" ? "ynmuc" : "gdapd";
+if ($system !== "cloudburst" && $system !== "raindrops" && $system !== $app["other"]["slug"]) header("Location: /?error=Invalid system name: " . $system) and die();
+$systemCommonName = $system === "cloudburst" ? "Cloudburst System" : ($system === "raindrops" ? "Raindrops System" : $app["other"]["name"]);
+$systemID = $system === "cloudburst" ? "ynmuc" : ($system === "raindrops" ? "gdapd" : $app["other"]["id"]);
 
 $subsystems = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/subsystems/$systemID.json"), true) ?? [];
 
+if ($isLowerLoggedIn && $systemID !== $app["other"]["id"]) {
+    header("Location: /") and die();
+}
+
 if ($member === null) {
     require_once $_SERVER['DOCUMENT_ROOT'] . '/includes/sysedit.inc';
 } else {
@@ -58,7 +62,7 @@ if ($member === null) {
 
             require_once $_SERVER['DOCUMENT_ROOT'] . '/includes/subsysedit.inc';
         } else {
-            header("Location: /?error=System member or subsystem not found: " . $subsystemID) and die();
+            header("Location: /?error=System member or subsystem not found") and die();
         }
     }
 
diff --git a/pages/home.inc b/pages/home.inc
index d476991..4dd838e 100644
--- a/pages/home.inc
+++ b/pages/home.inc
@@ -1,4 +1,4 @@
-<?php if (isset($_GET['error'])) header("HTTP/1.1 404 Not Found"); require_once $_SERVER['DOCUMENT_ROOT'] . '/includes/header.inc'; global $readOnly; global $isNormallyLoggedIn; global $_PROFILE; global $lang; global $pages; global $isLowerLoggedIn; global $isLoggedIn; ?>
+<?php if (isset($_GET['error'])) header("HTTP/1.1 404 Not Found"); require_once $_SERVER['DOCUMENT_ROOT'] . '/includes/header.inc'; global $readOnly; global $isNormallyLoggedIn; global $_PROFILE; global $lang; global $pages; global $isLowerLoggedIn; global $app; global $isLoggedIn; ?>
 
 <br>
 <div class="container">
@@ -19,7 +19,7 @@
     <div style="text-align: center;">
         <img alt="" src="/assets/logo/newlogo<?php if ($_SERVER['HTTP_HOST'] === "fr.equestria.horse"): ?>2<?php endif; ?>.png" style="width:128px;">
         <p style="z-index:999;position:relative;background:black;margin: 20px -10px 0 -20px;padding-right:30px;height:32px;text-align: center;display:grid;grid-template-columns: repeat(<?= count($byColor) ?>, 1fr);">
-            <?php foreach ($byColor as $member): ?><a data-bs-html="true" class="rainbow-item tooltip-nohelp" title="<b><?= $member["display_name"] ?? $member["name"] ?></b><br><?= ($travelling[$member['id']]["travelling"] ? $member["_system"] === "ynmuc" : $member["_system"] === "gdapd") ? "Raindrops System" : "Cloudburst System" ?>" data-bs-toggle="tooltip" style="overflow: hidden;" href="/<?= $member["name"] ?>"><img src="<?= getAsset($member["_system"], $member["id"], "heads") ?>" style="height:32px;position:absolute;z-index:99;"></a><?php endforeach; ?>
+            <?php foreach ($byColor as $member): ?><a data-bs-html="true" class="rainbow-item tooltip-nohelp" title="<b><?= $member["display_name"] ?? $member["name"] ?></b><br><?= ($travelling[$member['id']]["travelling"] ? $member["_system"] === "ynmuc" : $member["_system"] === "gdapd") ? "Raindrops System" : ($member["_system"] === "ynmuc" ? "Cloudburst System" : $app["other"]["name"]) ?>" data-bs-toggle="tooltip" style="overflow: hidden;" href="/<?= $member["name"] ?>"><img src="<?= getAsset($member["_system"], $member["id"], "heads") ?>" style="height:32px;position:absolute;z-index:99;"></a><?php endforeach; ?>
         </p>
         <div style="margin-top:-33px;margin-bottom:0;margin-left:-20px;margin-right:20px;height:32px;text-align: center;display:grid;grid-template-columns: repeat(<?= count($byColor) ?>, 1fr);">
             <?php foreach ($byColor as $member): ?><div>
diff --git a/pages/metadata.inc b/pages/metadata.inc
index 5e2c452..0a987f3 100644
--- a/pages/metadata.inc
+++ b/pages/metadata.inc
@@ -13,7 +13,7 @@ function getSubsystemByID(string $id) {
     return $subsystem;
 }
 
-require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/init.inc"; global $title; global $isLoggedIn; global $lang; global $pages;
+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/functions.inc";
 require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/bitset.inc";
 
@@ -25,14 +25,20 @@ array_shift($parts);
 $system = $parts[0];
 $member = !isset($parts[1]) || $parts[1] === "" ? null : $parts[1];
 
-if ($system !== "cloudburst" && $system !== "raindrops") header("Location: /?error=Invalid system name: " . $system) and die();
-$systemCommonName = $system === "cloudburst" ? "Cloudburst System" : "Raindrops System";
-$systemID = $system === "cloudburst" ? "ynmuc" : "gdapd";
+if ($system !== "cloudburst" && $system !== "raindrops" && $system !== $app["other"]["slug"]) header("Location: /?error=Invalid system name: " . $system) and die();
+$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");
 
 $subsystems = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/subsystems/$systemID.json"), true) ?? [];
 
+if ($isLowerLoggedIn && $systemID !== $app["other"]["id"]) {
+    header("Location: /");
+    die();
+}
+
 if ($member === null) {
-    require_once $_SERVER['DOCUMENT_ROOT'] . '/includes/sysedit.inc';
+    header("Location: /");
+    die();
 } else {
     $isSubsystem = false;
     $members = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/" . $systemID . "/members.json"), true);
diff --git a/pages/page.inc b/pages/page.inc
index f3859d3..3bdeb2e 100644
--- a/pages/page.inc
+++ b/pages/page.inc
@@ -1,19 +1,28 @@
 <?php
 
-global $lang; global $pages;
+global $lang; global $pages; global $isLoggedIn; global $isLowerLoggedIn;
+
+$app = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/app.json"), true);
 
 $travelling = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/travelling/travelling.json"), true);
 if (!isset($_GET['_']) || trim($_GET['_']) === "") header("Location: /?error=Invalid request") and die();
 
 $parts = explode("/", $_GET['_']);
 
-if (($parts[0] !== "cloudburst" && $parts[0] !== "raindrops") && (!(count($parts) > 2) || $parts[1] === "-")) {
+if (($parts[0] !== "cloudburst" && $parts[0] !== "raindrops" && $parts[0] !== $app["other"]["slug"]) && (!(count($parts) > 2) || $parts[1] === "-")) {
     $namesCloudburst = [...array_map(function ($i) {
         return $i['name'];
     }, json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/ynmuc/members.json"), true)), "unknown-cb"];
     $namesRaindrops = [...array_map(function ($i) {
         return $i['name'];
     }, json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/gdapd/members.json"), true)), "unknown-rd"];
+    $namesOther = [];
+
+    if ($isLoggedIn || $isLowerLoggedIn) {
+        $namesOther = [...array_map(function ($i) {
+            return $i['name'];
+        }, json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/other/members.json"), true)), $app["other"]["unknown"]];
+    }
 
     $parts = explode("/", $_GET['_']);
     array_unshift($parts, "");
@@ -23,17 +32,19 @@ if (($parts[0] !== "cloudburst" && $parts[0] !== "raindrops") && (!(count($parts
         $parts[0] = "cloudburst";
     } else if (in_array($parts[1], $namesRaindrops)) {
         $parts[0] = "raindrops";
+    } else if (in_array($parts[1], $namesOther) && ($isLoggedIn || $isLowerLoggedIn)) {
+        $parts[0] = $app["other"]["slug"];
     }
 
-    if ($parts[1] === "unknown-rd" || $parts[1] === "unknown-cb") $parts[1] = "unknown";
+    if ($parts[1] === "unknown-rd" || $parts[1] === "unknown-cb" || (($isLoggedIn || $isLowerLoggedIn) && $parts[1] === $app["other"]["slug"])) $parts[1] = "unknown";
 }
 
 $system = $parts[0];
 $member = (isset($parts[1]) ? $parts[1] : null) === "" ? null : (isset($parts[1]) ? $parts[1] : null);
 
-if ($system !== "cloudburst" && $system !== "raindrops") header("Location: /?error=" . $lang["page"]["system"]) and die();
-$systemCommonName = $system === "cloudburst" ? "Cloudburst System" : "Raindrops System";
-$systemID = $system === "cloudburst" ? "ynmuc" : "gdapd";
+if ($system !== "cloudburst" && $system !== "raindrops" && ($system !== $app["other"]["slug"] && !$isLowerLoggedIn && !$isLoggedIn)) header("Location: /?error=" . $lang["page"]["system"]) and die();
+$systemCommonName = $system === "cloudburst" ? "Cloudburst System" : ($system === $app["other"]["slug"] && ($isLoggedIn || $isLowerLoggedIn) ? $app["other"]["name"] : "Raindrops System");
+$systemID = $system === "cloudburst" ? "ynmuc" : ($system === $app["other"]["slug"] && ($isLoggedIn || $isLowerLoggedIn) ? $app["other"]["id"] : "gdapd");
 
 if ($member === null) {
     global $_SystemName;
@@ -53,7 +64,7 @@ if ($member === null) {
     $memberFoundInAnotherSystem = false;
     $traveller = false;
 
-    $members = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/" . $systemID . "/members.json"), true);
+    $members = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/" . ($systemID === $app["other"]["id"] ? "other" : $systemID) . "/members.json"), true);
     $members2 = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/" . ($systemID === "gdapd" ? "ynmuc" : "gdapd") . "/members.json"), true);
     $memberData = null;
     $memberCommonName = null;
-- 
cgit