diff options
-rw-r--r-- | includes/exchange.txt | 2 | ||||
-rw-r--r-- | includes/util/functions.inc | 21 | ||||
-rw-r--r-- | pages/api.inc | 17 | ||||
-rw-r--r-- | pages/api/chrome.php | 4 | ||||
-rw-r--r-- | pages/api/cloudburst-img-round.php | 78 | ||||
-rw-r--r-- | pages/api/cloudburst-img2-round.php | 78 | ||||
-rw-r--r-- | pages/api/money/account.php | 62 | ||||
-rw-r--r-- | pages/api/money/accounts.php | 96 | ||||
-rw-r--r-- | pages/api/money/create.php | 99 | ||||
-rw-r--r-- | pages/api/wear/schedule.php | 117 | ||||
-rw-r--r-- | pages/money.inc | 21 |
11 files changed, 412 insertions, 183 deletions
diff --git a/includes/exchange.txt b/includes/exchange.txt index d04fb11..643c34f 100644 --- a/includes/exchange.txt +++ b/includes/exchange.txt @@ -1 +1 @@ -0.885
\ No newline at end of file +0.871
\ No newline at end of file diff --git a/includes/util/functions.inc b/includes/util/functions.inc index 3d84bb7..3bc8091 100644 --- a/includes/util/functions.inc +++ b/includes/util/functions.inc @@ -598,4 +598,25 @@ if (!function_exists("resolveMember")) { return $name; } } +} + +if (!function_exists("calculateFullAmount")) { + function calculateFullAmount($account, $asNumber = false, $gbpOnly = false): string|float|int { + global $rate; + $total = 0; + + foreach ($account["transactions"] as $transaction) { + $total += $transaction["amount"]; + } + + if ($asNumber) { + if ($gbpOnly && $account["currency"] === "eur") { + return $total * $rate; + } else { + return $total; + } + } else { + return number_format($total, 2, '.', ','); + } + } }
\ No newline at end of file diff --git a/pages/api.inc b/pages/api.inc index 5c13bac..418df76 100644 --- a/pages/api.inc +++ b/pages/api.inc @@ -7,12 +7,17 @@ if (str_ends_with($_GET['_'], "/")) { } $toplevel = explode("/", $pagename)[1]; +$middlelevel = explode("/", $pagename)[2]; -if (file_exists($_SERVER['DOCUMENT_ROOT'] . "/pages/api/" . $toplevel . ".php")) { - require_once $_SERVER['DOCUMENT_ROOT'] . "/pages/api/" . $toplevel . ".php"; +if (isset($middlelevel) && file_exists($_SERVER['DOCUMENT_ROOT'] . "/pages/api/" . $toplevel . "/" . $middlelevel . ".php") && is_file($_SERVER['DOCUMENT_ROOT'] . "/pages/api/" . $toplevel . "/" . $middlelevel . ".php")) { + require_once $_SERVER['DOCUMENT_ROOT'] . "/pages/api/" . $toplevel . "/" . $middlelevel . ".php"; } else { - header("HTTP/1.1 500 Internal Server Error"); - header("Content-Type: text/plain"); - echo("Endpoint not found"); - die(); + if (file_exists($_SERVER['DOCUMENT_ROOT'] . "/pages/api/" . $toplevel . ".php") && is_file($_SERVER['DOCUMENT_ROOT'] . "/pages/api/" . $toplevel . ".php")) { + require_once $_SERVER['DOCUMENT_ROOT'] . "/pages/api/" . $toplevel . ".php"; + } else { + header("HTTP/1.1 500 Internal Server Error"); + header("Content-Type: text/plain"); + echo("Endpoint not found"); + die(); + } }
\ No newline at end of file diff --git a/pages/api/chrome.php b/pages/api/chrome.php index c50599a..db32511 100644 --- a/pages/api/chrome.php +++ b/pages/api/chrome.php @@ -33,7 +33,7 @@ if (!isset($_GET["t"])) { <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> - <link rel="icon" href="https://git.equestria.dev/repo-avatars/1c0dad449a8e21ad16fa0efb1426c1a3301b1f26a8cb3b3902eec88bb568e34c" type="image/png"> + <link rel="icon" href="https://git.equestria.dev/equestria.dev/luna/raw/branch/mane/icons/logo.png" type="image/png"> <title>Luna for Chrome OS</title> <style> html, body { @@ -55,7 +55,7 @@ if (!isset($_GET["t"])) { <body> <div style="max-width: 65vw; margin-left: auto; margin-right: auto; height: 100vh; display: flex; align-items: center; justify-content: center; text-align: center;"> <div> - <img src="https://git.equestria.dev/repo-avatars/1c0dad449a8e21ad16fa0efb1426c1a3301b1f26a8cb3b3902eec88bb568e34c" width="128px"> + <img src="https://git.equestria.dev/equestria.dev/luna/raw/branch/mane/icons/logo.png" width="128px"> <h1>Please login to Cold Haze</h1> <p>To proceed with activating Luna on this Chromebook, you need to login to Cold Haze. You also need to make sure you properly enroled this computer into Chrome Enterprise.</p> <button onclick='window.open("https://ponies.equestria.horse/-/login/?return=/api/close&mini", "_blank", "popup,top=100,width=100,height:250")' style="cursor: pointer; background: #5958ad; color: white; border: none; padding: 5px 10px; border-radius: 5px;">Login</button> diff --git a/pages/api/cloudburst-img-round.php b/pages/api/cloudburst-img-round.php index 6400499..3238696 100644 --- a/pages/api/cloudburst-img-round.php +++ b/pages/api/cloudburst-img-round.php @@ -2,85 +2,9 @@ $fronters = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/ynmuc/fronters.json"), true); -$url = isset($fronters['members'][0]) ? ($fronters['members'][0]["avatar_url"] ?? "/assets/uploads/raindrops.png") : "/assets/uploads/raindrops.png"; +$url = isset($fronters['members'][0]) ? ($fronters['members'][0]["avatar_url"] ?? "/assets/uploads/cloudburst.png") : "/assets/uploads/cloudburst.png"; file_put_contents("/tmp/temp", file_get_contents($url)); -function imageCreateCorners($sourceImageFile, $radius) { - # test source image - if (file_exists($sourceImageFile)) { - $res = is_array($info = getimagesize($sourceImageFile)); - } - else $res = false; - - # open image - if ($res) { - $w = $info[0]; - $h = $info[1]; - switch ($info['mime']) { - case 'image/jpeg': $src = imagecreatefromjpeg($sourceImageFile); - break; - case 'image/gif': $src = imagecreatefromgif($sourceImageFile); - break; - case 'image/png': $src = imagecreatefrompng($sourceImageFile); - break; - default: - $res = false; - } - } - - # create corners - if ($res) { - - $q = 10; # change this if you want - $radius *= $q; - - # find unique color - do { - $r = rand(0, 255); - $g = rand(0, 255); - $b = rand(0, 255); - } - while (imagecolorexact($src, $r, $g, $b) < 0); - - $nw = $w*$q; - $nh = $h*$q; - - $img = imagecreatetruecolor($nw, $nh); - $alphacolor = imagecolorallocatealpha($img, $r, $g, $b, 127); - imagealphablending($img, false); - imagesavealpha($img, true); - imagefilledrectangle($img, 0, 0, $nw, $nh, $alphacolor); - - imagefill($img, 0, 0, $alphacolor); - imagecopyresampled($img, $src, 0, 0, 0, 0, $nw, $nh, $w, $h); - - imagearc($img, $radius-1, $radius-1, $radius*2, $radius*2, 180, 270, $alphacolor); - imagefilltoborder($img, 0, 0, $alphacolor, $alphacolor); - imagearc($img, $nw-$radius, $radius-1, $radius*2, $radius*2, 270, 0, $alphacolor); - imagefilltoborder($img, $nw-1, 0, $alphacolor, $alphacolor); - imagearc($img, $radius-1, $nh-$radius, $radius*2, $radius*2, 90, 180, $alphacolor); - imagefilltoborder($img, 0, $nh-1, $alphacolor, $alphacolor); - imagearc($img, $nw-$radius, $nh-$radius, $radius*2, $radius*2, 0, 90, $alphacolor); - imagefilltoborder($img, $nw-1, $nh-1, $alphacolor, $alphacolor); - imagealphablending($img, true); - imagecolortransparent($img, $alphacolor); - - # resize image down - $dest = imagecreatetruecolor($w, $h); - imagealphablending($dest, false); - imagesavealpha($dest, true); - imagefilledrectangle($dest, 0, 0, $w, $h, $alphacolor); - imagecopyresampled($dest, $img, 0, 0, 0, 0, $w, $h, $nw, $nh); - - # output image - $res = $dest; - imagedestroy($src); - imagedestroy($img); - } - - return $res; -} - header("Content-Type: image/png"); $id = bin2hex(random_bytes(8)); diff --git a/pages/api/cloudburst-img2-round.php b/pages/api/cloudburst-img2-round.php index 4ca772f..5f4f0dc 100644 --- a/pages/api/cloudburst-img2-round.php +++ b/pages/api/cloudburst-img2-round.php @@ -2,85 +2,9 @@ $fronters = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/ynmuc/fronters.json"), true); -$url = isset($fronters['members'][1]) ? ($fronters['members'][1]["avatar_url"] ?? "/assets/uploads/raindrops.png") : "/assets/uploads/raindrops.png"; +$url = isset($fronters['members'][1]) ? ($fronters['members'][1]["avatar_url"] ?? "/assets/uploads/cloudburst.png") : "/assets/uploads/cloudburst.png"; file_put_contents("/tmp/temp", file_get_contents($url)); -function imageCreateCorners($sourceImageFile, $radius) { - # test source image - if (file_exists($sourceImageFile)) { - $res = is_array($info = getimagesize($sourceImageFile)); - } - else $res = false; - - # open image - if ($res) { - $w = $info[0]; - $h = $info[1]; - switch ($info['mime']) { - case 'image/jpeg': $src = imagecreatefromjpeg($sourceImageFile); - break; - case 'image/gif': $src = imagecreatefromgif($sourceImageFile); - break; - case 'image/png': $src = imagecreatefrompng($sourceImageFile); - break; - default: - $res = false; - } - } - - # create corners - if ($res) { - - $q = 10; # change this if you want - $radius *= $q; - - # find unique color - do { - $r = rand(0, 255); - $g = rand(0, 255); - $b = rand(0, 255); - } - while (imagecolorexact($src, $r, $g, $b) < 0); - - $nw = $w*$q; - $nh = $h*$q; - - $img = imagecreatetruecolor($nw, $nh); - $alphacolor = imagecolorallocatealpha($img, $r, $g, $b, 127); - imagealphablending($img, false); - imagesavealpha($img, true); - imagefilledrectangle($img, 0, 0, $nw, $nh, $alphacolor); - - imagefill($img, 0, 0, $alphacolor); - imagecopyresampled($img, $src, 0, 0, 0, 0, $nw, $nh, $w, $h); - - imagearc($img, $radius-1, $radius-1, $radius*2, $radius*2, 180, 270, $alphacolor); - imagefilltoborder($img, 0, 0, $alphacolor, $alphacolor); - imagearc($img, $nw-$radius, $radius-1, $radius*2, $radius*2, 270, 0, $alphacolor); - imagefilltoborder($img, $nw-1, 0, $alphacolor, $alphacolor); - imagearc($img, $radius-1, $nh-$radius, $radius*2, $radius*2, 90, 180, $alphacolor); - imagefilltoborder($img, 0, $nh-1, $alphacolor, $alphacolor); - imagearc($img, $nw-$radius, $nh-$radius, $radius*2, $radius*2, 0, 90, $alphacolor); - imagefilltoborder($img, $nw-1, $nh-1, $alphacolor, $alphacolor); - imagealphablending($img, true); - imagecolortransparent($img, $alphacolor); - - # resize image down - $dest = imagecreatetruecolor($w, $h); - imagealphablending($dest, false); - imagesavealpha($dest, true); - imagefilledrectangle($dest, 0, 0, $w, $h, $alphacolor); - imagecopyresampled($dest, $img, 0, 0, 0, 0, $w, $h, $nw, $nh); - - # output image - $res = $dest; - imagedestroy($src); - imagedestroy($img); - } - - return $res; -} - header("Content-Type: image/png"); $id = bin2hex(random_bytes(8)); diff --git a/pages/api/money/account.php b/pages/api/money/account.php new file mode 100644 index 0000000..6620733 --- /dev/null +++ b/pages/api/money/account.php @@ -0,0 +1,62 @@ +<?php + +require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/util/session.inc"; global $isLoggedIn; global $_PROFILE; +require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/util/functions.inc"; +if (!$isLoggedIn) header("Location: /-/login") and die(); +header("Content-Type: application/json"); + +$accounts = array_map(function ($i) { + $name = substr($i, 0, -5); + $data = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/money/" . $i), true); + $data["_name"] = $name; + return $data; +}, array_values(array_filter(scandir($_SERVER['DOCUMENT_ROOT'] . "/includes/data/money"), function ($i) { return !str_starts_with($i, "."); }))); +$rate = (float)trim(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/exchange.txt")); +$obj = []; + +if (!isset($_GET["id"])) { + die(json_encode($obj, JSON_PRETTY_PRINT)); +} + +foreach ($accounts as $account) { + if ($account["_name"] === $_GET["id"]) { + $acc = []; + + $acc["id"] = $account["_name"]; + $acc["name"] = $account["name"]; + $acc["currency"] = $account["currency"]; + $acc["default"] = $account["default"]; + $acc["total"] = round(calculateFullAmount($account, true), 2); + $acc["interests"] = $account["interests"]; + $acc["max"] = $account["max"]; + $acc["used_percentage"] = isset($account["max"]) ? (calculateFullAmount($account, true) / $account["max"]) * 100 : null; + $acc["transactions"] = []; + + foreach ($account["transactions"] as $index => $transaction) { + $member = getMemberWithoutSystem($transaction["author"]) ?? getMemberWithoutSystem("zdtsg"); + $trans = [ + "id" => $index, + "author" => [ + "avatar" => getAsset($member["_system"], $member["id"]), + "name" => $member["display_name"] ?? $member["name"] + ], + "type" => $transaction["amount"] < 0 ? "REMOVE" : "ADD", + "amount" => round(abs($transaction["amount"]), 2), + "date" => [ + "ts" => strtotime($transaction["date"]), + "iso" => date('c', strtotime($transaction["date"])), + "relative" => timeAgo($transaction["date"]) + ], + "description" => (isset($transaction["description"]) && trim($transaction["description"]) !== "") ? trim($transaction["description"]) : null + ]; + + $acc["transactions"][] = $trans; + } + + $obj = $acc; + } +} + +/* ------------------- */ + +die(json_encode($obj, JSON_PRETTY_PRINT));
\ No newline at end of file diff --git a/pages/api/money/accounts.php b/pages/api/money/accounts.php new file mode 100644 index 0000000..22d8c77 --- /dev/null +++ b/pages/api/money/accounts.php @@ -0,0 +1,96 @@ +<?php + +require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/util/session.inc"; global $isLoggedIn; global $_PROFILE; +require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/util/functions.inc"; +if (!$isLoggedIn) header("Location: /-/login") and die(); +header("Content-Type: application/json"); + +$accounts = array_map(function ($i) { + $name = substr($i, 0, -5); + $data = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/money/" . $i), true); + $data["_name"] = $name; + return $data; +}, array_values(array_filter(scandir($_SERVER['DOCUMENT_ROOT'] . "/includes/data/money"), function ($i) { return !str_starts_with($i, "."); }))); +$rate = (float)trim(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/exchange.txt")); +$obj = [ + "total" => 0, + "exchange_rate" => $rate, + "users" => [ + "cloudburst" => [ + "total" => 0, + "accounts" => [] + ], + "raindrops" => [ + "total" => 0, + "accounts" => [] + ] + ] +]; + +$allAccounts = array_reduce(array_map(function ($i) { + return calculateFullAmount($i, true, true); +}, $accounts), function ($a, $b) { + return $a + $b; +}); +$obj["total"] = [ + "gbp" => round($allAccounts, 2), + "eur" => round($allAccounts * (1 / $rate), 2) +]; + +/* ------------------- */ + +$allAccounts = array_reduce(array_map(function ($i) { + return calculateFullAmount($i, true, true); +}, array_values(array_filter($accounts, function ($i) { return $i["owner"] === "cloudburst"; }))), function ($a, $b) { + return $a + $b; +}); + +$obj["users"]["cloudburst"]["total"] = $allAccounts; + +foreach ($accounts as $index => $account) { + if ($account["owner"] === "cloudburst") { + $acc = []; + + $acc["id"] = $account["_name"]; + $acc["name"] = $account["name"]; + $acc["currency"] = $account["currency"]; + $acc["default"] = $account["default"]; + $acc["total"] = round(calculateFullAmount($account, true), 2); + $acc["interests"] = $account["interests"]; + $acc["max"] = $account["max"]; + $acc["used_percentage"] = isset($account["max"]) ? (calculateFullAmount($account, true) / $account["max"]) * 100 : null; + + $obj["users"]["cloudburst"]["accounts"][] = $acc; + } +} +/* ------------------- */ + +$allAccounts = array_reduce(array_map(function ($i) { + return calculateFullAmount($i, true, true); +}, array_values(array_filter($accounts, function ($i) { return $i["owner"] === "raindrops"; }))), function ($a, $b) { + return $a + $b; +}); + +$obj["users"]["raindrops"]["total"] = $allAccounts; + +foreach ($accounts as $index => $account) { + if ($account["owner"] === "raindrops") { + $acc = []; + + $acc["id"] = $account["_name"]; + $acc["name"] = $account["name"]; + $acc["currency"] = $account["currency"]; + $acc["default"] = $account["default"]; + $acc["total"] = round(calculateFullAmount($account, true), 2); + $acc["interests"] = $account["interests"]; + $acc["max"] = $account["max"]; + $acc["used_percentage"] = isset($account["max"]) ? (calculateFullAmount($account, true) / $account["max"]) * 100 : null; + $acc["transactions"] = null; + + $obj["users"]["raindrops"]["accounts"][] = $acc; + } +} + +/* ------------------- */ + +die(json_encode($obj, JSON_PRETTY_PRINT));
\ No newline at end of file diff --git a/pages/api/money/create.php b/pages/api/money/create.php new file mode 100644 index 0000000..ff06a37 --- /dev/null +++ b/pages/api/money/create.php @@ -0,0 +1,99 @@ +<?php + +require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/util/session.inc"; global $isLoggedIn; global $_PROFILE; +require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/util/functions.inc"; +$app = $GLOBALS["ColdHazeApp"] = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/app.json"), true); +if (!$isLoggedIn) header("Location: /-/login") and die(); +header("Content-Type: application/json"); + +$request_raw = file_get_contents('php://input'); +$json_object = $data = json_decode($request_raw, true); + +$systemID = $_PROFILE["login"] === "cloudburst" ? "ynmuc" : "gdapd"; +$fronters = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/" . ($_PROFILE["login"] === "cloudburst" ? "ynmuc" : "gdapd") . "/fronters.json"), true)["members"]; + +if (count($fronters) > 0) { + $myId = $fronters[0]["id"]; +} else { + $myId = "zdtsg"; +} + +$accounts = array_map(function ($i) { + $name = substr($i, 0, -5); + $data = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/money/" . $i), true); + $data["_name"] = $name; + return $data; +}, array_values(array_filter(scandir($_SERVER['DOCUMENT_ROOT'] . "/includes/data/money"), function ($i) { return !str_starts_with($i, "."); }))); +$rate = (float)trim(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/exchange.txt")); + +$obj = [ + "success" => false, + "error" => null +]; + +if ($_SERVER["REQUEST_METHOD"] !== "POST") { + $obj["success"] = false; + $obj["error"] = "INVALID_METHOD"; + die(json_encode($obj, JSON_PRETTY_PRINT)); +} + +if (!isset($data["amount"]) || !isset($data["id"]) || !isset($data["description"])) { + $obj["success"] = false; + $obj["error"] = "MISSING_OPERAND"; + die(json_encode($obj, JSON_PRETTY_PRINT)); +} + +$account = array_values(array_filter($accounts, function ($i) use ($data) { return $i["_name"] === $data["id"]; }))[0] ?? null; + +if (!isset($account)) { + $obj["success"] = false; + $obj["error"] = "ACCOUNT_NOT_FOUND"; + die(json_encode($obj, JSON_PRETTY_PRINT)); +} + +if (!(isset($data["amount"]) && is_numeric($data["amount"]) && (float)$data["amount"] < 9999 && (float)$data["amount"] > -9999)) { + $obj["success"] = false; + $obj["error"] = "INVALID_AMOUNT"; + die(json_encode($obj, JSON_PRETTY_PRINT)); +} +if (!isset($data["description"])) $data["description"] = ""; + +if (strlen($data["description"]) > 150) { + $obj["success"] = false; + $obj["error"] = "DESCRIPTION_TOO_LONG"; + die(json_encode($obj, JSON_PRETTY_PRINT)); +} + +if ($data["amount"] === 0) { + $obj["success"] = false; + $obj["error"] = "AMOUNT_IS_ZERO"; + die(json_encode($obj, JSON_PRETTY_PRINT)); +} + +$ntfy = $GLOBALS["ColdHazeApp"]["ntfy"]; +file_get_contents('https://' . $ntfy["server"] . '/' . $ntfy["topic"], false, stream_context_create([ + 'http' => [ + 'method' => 'POST', + 'header' => + "Content-Type: text/plain\r\n" . + "Title: " . formatPonypush((getMember($myId)["display_name"] ?? getMember($myId)["name"]) . " created a transaction to " . $account["name"] . " (" . ucfirst($account["owner"]) . ")") . "\r\n" . + "Tags: bits\r\n" . + "Authorization: Basic " . base64_encode($ntfy["user"] . ":" . $ntfy["password"]), + 'content' => formatPonypush(($account["currency"] === "gbp" ? "£" : "€") . abs((float)$_GET["amount"]) . " were " . ((float)$_GET["amount"] >= 0 ? "added" : "removed") . " just now" . (trim($_GET["description"]) !== "" ? ": " . $_GET["description"] : "")) + ] +])); + +array_unshift($account["transactions"], [ + "author" => $myId, + "description" => $_GET["description"], + "amount" => (float)$_GET["amount"], + "date" => date('c') +]); + +$name = $account["_name"]; +unset($account["_name"]); + +file_put_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/money/" . $name . ".json", json_encode($account, JSON_PRETTY_PRINT)); + +$obj["success"] = true; +die(json_encode($obj, JSON_PRETTY_PRINT));
\ No newline at end of file diff --git a/pages/api/wear/schedule.php b/pages/api/wear/schedule.php new file mode 100644 index 0000000..cf053d8 --- /dev/null +++ b/pages/api/wear/schedule.php @@ -0,0 +1,117 @@ +<?php + +require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/util/session.inc"; global $isLoggedIn; global $_PROFILE; +require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/util/functions.inc"; +if (!$isLoggedIn) header("Location: /-/login") and die(); + +header("Content-Type: application/json"); + +$obj = [ + "today" => [], + "tomorrow" => [] +]; + +$raindrops = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/planner/gdapd.json"), true); +$cloudburst = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/planner/ynmuc.json"), true); + +if (isset($raindrops[date('Y-m-d', time())]) || isset($cloudburst[date('Y-m-d', time())])) { + $rd = $raindrops[date('Y-m-d', time())]; + $cb = $cloudburst[date('Y-m-d', time())]; + $longest = max(count($rd), count($cb)); + + for ($x = 0; $x < $longest; $x++) { + $item = []; + $item["raindrops"] = null; + $item["cloudburst"] = null; + + if (isset($rd[$x])) { + $item["raindrops"] = array_map(function ($i) use ($x, $longest) { + $member = getMemberWithoutSystem($i); + + return [ + "id" => $member["id"], + "name" => $member["display_name"] ?? $member["name"], + "avatar" => "https://ponies.equestria.horse" . getAsset($member["_system"], $member["id"]), + "flags" => [ + "pacifier" => (json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/metadata/" . $member["id"] . ".json"), true)["pacifier"] ?? false) && ($x === ($longest - 1)), + "plush" => (json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/metadata/" . $member["id"] . ".json"), true)["sleep_plush"] ?? false) && ($x === ($longest - 1)), + ] + ]; + }, array_filter($rd[$x], function ($i) { return isset($i); })); + } else if (isset($obj["today"][$x - 1]["raindrops"])) { + $item["raindrops"] = $obj["today"][$x - 1]["raindrops"]; + } + + if (isset($cb[$x])) { + $item["cloudburst"] = array_map(function ($i) use ($x, $longest) { + $member = getMemberWithoutSystem($i); + + return [ + "id" => $member["id"], + "name" => $member["display_name"] ?? $member["name"], + "avatar" => "https://ponies.equestria.horse" . getAsset($member["_system"], $member["id"]), + "flags" => [ + "pacifier" => (json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/metadata/" . $member["id"] . ".json"), true)["pacifier"] ?? false) && ($x === ($longest - 1)), + "plush" => (json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/metadata/" . $member["id"] . ".json"), true)["sleep_plush"] ?? false) && ($x === ($longest - 1)), + ] + ]; + }, array_filter($cb[$x], function ($i) { return isset($i); })); + } else if (isset($obj["today"][$x - 1]["cloudburst"])) { + $item["cloudburst"] = $obj["today"][$x - 1]["cloudburst"]; + } + + $obj["today"][] = $item; + } +} + +if (isset($raindrops[date('Y-m-d', time() + 86400)]) || isset($cloudburst[date('Y-m-d', time() + 86400)])) { + $rd = $raindrops[date('Y-m-d', time() + 86400)]; + $cb = $cloudburst[date('Y-m-d', time() + 86400)]; + $longest = max(count($rd), count($cb)); + + for ($x = 0; $x < $longest; $x++) { + $item = []; + $item["raindrops"] = null; + $item["cloudburst"] = null; + + if (isset($rd[$x])) { + $item["raindrops"] = array_map(function ($i) use ($x, $longest) { + $member = getMemberWithoutSystem($i); + + return [ + "id" => $member["id"], + "name" => $member["display_name"] ?? $member["name"], + "avatar" => "https://ponies.equestria.horse" . getAsset($member["_system"], $member["id"]), + "flags" => [ + "pacifier" => (json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/metadata/" . $member["id"] . ".json"), true)["pacifier"] ?? false) && ($x === ($longest - 1)), + "plush" => (json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/metadata/" . $member["id"] . ".json"), true)["sleep_plush"] ?? false) && ($x === ($longest - 1)), + ] + ]; + }, array_filter($rd[$x], function ($i) { return isset($i); })); + } else if (isset($obj["tomorrow"][$x - 1]["raindrops"])) { + $item["raindrops"] = $obj["tomorrow"][$x - 1]["raindrops"]; + } + + if (isset($cb[$x])) { + $item["cloudburst"] = array_map(function ($i) use ($x, $longest) { + $member = getMemberWithoutSystem($i); + + return [ + "id" => $member["id"], + "name" => $member["display_name"] ?? $member["name"], + "avatar" => "https://ponies.equestria.horse" . getAsset($member["_system"], $member["id"]), + "flags" => [ + "pacifier" => (json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/metadata/" . $member["id"] . ".json"), true)["pacifier"] ?? false) && ($x === ($longest - 1)), + "plush" => (json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/metadata/" . $member["id"] . ".json"), true)["sleep_plush"] ?? false) && ($x === ($longest - 1)), + ] + ]; + }, array_filter($cb[$x], function ($i) { return isset($i); })); + } else if (isset($obj["tomorrow"][$x - 1]["cloudburst"])) { + $item["cloudburst"] = $obj["tomorrow"][$x - 1]["cloudburst"]; + } + + $obj["tomorrow"][] = $item; + } +} + +die(json_encode($obj, JSON_PRETTY_PRINT));
\ No newline at end of file diff --git a/pages/money.inc b/pages/money.inc index 69e732c..4d93398 100644 --- a/pages/money.inc +++ b/pages/money.inc @@ -15,25 +15,6 @@ $accounts = array_map(function ($i) { require_once $_SERVER['DOCUMENT_ROOT'] . "/includes/util/functions.inc"; -function calculateFullAmount($account, $asNumber = false, $gbpOnly = false): string|float|int { - global $rate; - $total = 0; - - foreach ($account["transactions"] as $transaction) { - $total += $transaction["amount"]; - } - - if ($asNumber) { - if ($gbpOnly && $account["currency"] === "eur") { - return $total * $rate; - } else { - return $total; - } - } else { - return number_format($total, 2, '.', ','); - } -} - global $parts; if (isset($parts[2])) { if (str_contains($parts[2], "/") || !file_exists($_SERVER['DOCUMENT_ROOT'] . "/includes/data/money/" . $parts[2] . ".json")) { @@ -77,7 +58,7 @@ if ((isset($_GET["create"]) || isset($_GET["delete"])) && isset($parts[2])) { ] ])); - array_unshift($account["transactions"], [ + if ((float)$_GET["amount"] !== 0.0) array_unshift($account["transactions"], [ "author" => $myId, "description" => $_GET["description"], "amount" => (float)$_GET["amount"], |