summaryrefslogtreecommitdiff
path: root/Application/TransactionsList
diff options
context:
space:
mode:
authorMinteck <contact@minteck.org>2022-06-06 17:10:14 +0200
committerMinteck <contact@minteck.org>2022-06-06 17:10:14 +0200
commit10b1ace835d908d32f99874facf8811534087d5b (patch)
treeecf068e4ac40f7470ca2b5ac6bd13bd8fbe13ba9 /Application/TransactionsList
downloadbits-server-10b1ace835d908d32f99874facf8811534087d5b.tar.gz
bits-server-10b1ace835d908d32f99874facf8811534087d5b.tar.bz2
bits-server-10b1ace835d908d32f99874facf8811534087d5b.zip
Initial commit
Diffstat (limited to 'Application/TransactionsList')
-rw-r--r--Application/TransactionsList/index.php52
1 files changed, 52 insertions, 0 deletions
diff --git a/Application/TransactionsList/index.php b/Application/TransactionsList/index.php
new file mode 100644
index 0000000..185e94b
--- /dev/null
+++ b/Application/TransactionsList/index.php
@@ -0,0 +1,52 @@
+<?php
+
+function timeAgo($time): string {
+ if (!is_numeric($time)) {
+ $time = strtotime($time);
+ }
+
+ $periods = ["second", "minute", "hour", "day", "week", "month", "year", "age"];
+ $lengths = array("60", "60", "24", "7", "4.35", "12", "100");
+
+ $now = time();
+
+ $difference = $now - $time;
+ if ($difference <= 10 && $difference >= 0) {
+ return $tense = "now";
+ } elseif ($difference > 0) {
+ $tense = "ago";
+ } else {
+ $tense = "later";
+ }
+
+ for ($j = 0; $difference >= $lengths[$j] && $j < count($lengths)-1; $j++) {
+ $difference /= $lengths[$j];
+ }
+
+ $difference = round($difference);
+
+ $period = $periods[$j] . ($difference >1 ? "s" :'');
+ return "{$difference} {$period} {$tense} ";
+}
+
+require_once $_SERVER['DOCUMENT_ROOT'] . "/Private/SessionManager.php";
+header("Content-Type: application/json");
+
+$users = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/Private/Data/Users.json"), true);
+$list = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/Private/Data/Transactions.json"), true);
+$plist = [];
+
+foreach ($list as $item) {
+ $item["author"] = [
+ "id" => $item["author"],
+ "name" => $users[$item["author"]] ?? $item["author"],
+ "avatar" => "https://account.minteck.org/hub/api/rest/avatar/" . $item["author"] . "?dpr=2&size=48"
+ ];
+ $item["date"] = [
+ "absolute" => $item["date"],
+ "relative" => trim(timeAgo($item["date"]))
+ ];
+ $plist[] = $item;
+}
+
+die(json_encode($plist)); \ No newline at end of file