summaryrefslogtreecommitdiff
path: root/includes/functions.php
diff options
context:
space:
mode:
authorMinteck <contact@minteck.org>2022-08-31 22:03:07 +0200
committerMinteck <contact@minteck.org>2022-08-31 22:03:07 +0200
commitb5f589c323f415bb42ea7069cb4d1a8a2233dd69 (patch)
treec3b80234ab7f463a2e7b8b672ceff57422b3496b /includes/functions.php
parent09bd0164ebc020a54b944b7326dcba496fb5d82c (diff)
downloadpluralconnect-b5f589c323f415bb42ea7069cb4d1a8a2233dd69.tar.gz
pluralconnect-b5f589c323f415bb42ea7069cb4d1a8a2233dd69.tar.bz2
pluralconnect-b5f589c323f415bb42ea7069cb4d1a8a2233dd69.zip
Update I guess - Stuffie
Diffstat (limited to 'includes/functions.php')
-rw-r--r--includes/functions.php100
1 files changed, 100 insertions, 0 deletions
diff --git a/includes/functions.php b/includes/functions.php
index 51317ca..db4a8df 100644
--- a/includes/functions.php
+++ b/includes/functions.php
@@ -34,6 +34,26 @@ if (!function_exists("getSystemMember")) {
}
}
+if (!function_exists("getMemberWithoutSystem")) {
+ function getMemberWithoutSystem(string $id) {
+ $member = null;
+
+ $members1 = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/ynmuc-members.json"), true);
+ foreach ($members1 as $m) {
+ $m["_system"] = "ynmuc";
+ if ($m["id"] === $id) $member = $m;
+ }
+
+ $members2 = json_decode(file_get_contents($_SERVER['DOCUMENT_ROOT'] . "/includes/data/gdapd-members.json"), true);
+ foreach ($members2 as $m) {
+ $m["_system"] = "gdapd";
+ if ($m["id"] === $id) $member = $m;
+ }
+
+ return $member;
+ }
+}
+
if (!function_exists("showMembersFromList")) {
function showMembersFromList(array $list) {
foreach ($list as $member) { if ($member['name'] !== "unknown" && $member['name'] !== "fusion") {
@@ -167,6 +187,86 @@ if (!function_exists("timeAgo")) {
}
}
+if (!function_exists("timeIn")) {
+ function timeIn($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 = $time - $now;
+ if ($difference <= 10 && $difference >= 0) {
+ return $tense = "now";
+ } elseif ($difference > 0) {
+ $tense = "in";
+ } else {
+ $tense = "ago";
+ }
+
+ for ($j = 0; $difference >= $lengths[$j] && $j < count($lengths)-1; $j++) {
+ $difference /= $lengths[$j];
+ }
+
+ $difference = round($difference);
+
+ $period = $periods[$j] . ($difference >1 ? "s" :'');
+ return "{$tense} {$difference} {$period}";
+ }
+}
+
+if (!function_exists("duration")) {
+ function duration($seconds) {
+ if ($seconds >= 60) {
+ if (floor($seconds / 60) >= 60) {
+ if (floor($seconds / 3600) >= 24) {
+ $days = floor($seconds / 86400);
+ return $days . " day" . ($days > 1 ? "s" : "");
+ } else {
+ $hours = floor($seconds / 3600);
+ return $hours . " hour" . ($hours > 1 ? "s" : "");
+ }
+ } else {
+ $minutes = floor($seconds / 60);
+ return $minutes . " minute" . ($minutes > 1 ? "s" : "");
+ }
+ } else {
+ return $seconds . " seconds";
+ }
+ }
+}
+
+if (!function_exists("relativeDate")) {
+ function relativeDate($date, $showTime = true) {
+ if (!is_numeric($date)) $date = strtotime($date);
+
+ if (!$showTime) {
+ if (date('Y-m-d', $date) === date('Y-m-d')) {
+ return "today";
+ } elseif (date('Y-m-d', $date) === date('Y-m-d', time() + 86400)) {
+ return "tomorrow";
+ } elseif ($date < time() + 518400) {
+ return date('l', $date);
+ } else {
+ return date('D j M', $date);
+ }
+ } else {
+ if (date('Y-m-d', $date) === date('Y-m-d')) {
+ return "today, <span class='time-adjust'>" . date('H:i', $date) . "</span>";
+ } elseif (date('Y-m-d', $date) === date('Y-m-d', time() + 86400)) {
+ return "tomorrow, <span class='time-adjust'>" . date('H:i', $date) . "</span>";
+ } elseif ($date < time() + 518400) {
+ return date('l', $date) . ", <span class='time-adjust'>" . date('H:i', $date) . "</span>";
+ } else {
+ return date('D j M', $date) . ", <span class='time-adjust'>" . date('H:i', $date) . "</span>";
+ }
+ }
+ }
+}
+
if (!function_exists("getMemberSystem")) {
function getMemberSystem(string $id) {
$list = scoreOrderGlobal();