diff --git a/incl/comments/getGJAccountComments.php b/incl/comments/getGJAccountComments.php index 9c90aa0bd..8fd3b0568 100644 --- a/incl/comments/getGJAccountComments.php +++ b/incl/comments/getGJAccountComments.php @@ -22,8 +22,7 @@ $commentcount = $countquery->fetchColumn(); foreach($result as &$comment1) { if($comment1["commentID"]!=""){ - if(time() - 86400 > $comment1["timestamp"] OR date('d', $comment1["timestamp"]) < date('d', time())) $uploadDate = date("d.m.Y", $comment1["timestamp"]); - else $uploadDate = date("G:i", $comment1["timestamp"]); + $uploadDate = $gs->formatTimestamp($comment1["timestamp"], true); $reply = $db->prepare("SELECT count(*) FROM replies WHERE commentID = :id"); $reply->execute([':id' => $comment1["commentID"]]); $reply = $reply->fetchColumn(); diff --git a/incl/comments/getGJComments.php b/incl/comments/getGJComments.php index 142bb26f1..c4cbb699c 100644 --- a/incl/comments/getGJComments.php +++ b/incl/comments/getGJComments.php @@ -59,7 +59,7 @@ foreach($result as &$comment1) { if($comment1["commentID"]!=""){ - $uploadDate = date("d/m/Y G.i", $comment1["timestamp"]); + $uploadDate = $gs->formatTimestamp($comment1["timestamp"], true); $commentText = ($gameVersion < 20) ? base64_decode($comment1["comment"]) : $comment1["comment"]; if($displayLevelID) $commentstring .= "1~".$comment1["levelID"]."~"; $commentstring .= "2~".$commentText."~3~".$comment1["userID"]."~4~".$comment1["likes"]."~5~0~7~".$comment1["isSpam"]."~9~".$uploadDate."~6~".$comment1["commentID"]."~10~".$comment1["percent"]; diff --git a/incl/levels/downloadGJLevel.php b/incl/levels/downloadGJLevel.php index 4a4ec0c62..a702318b9 100644 --- a/incl/levels/downloadGJLevel.php +++ b/incl/levels/downloadGJLevel.php @@ -83,8 +83,8 @@ $query6->execute([':levelID' => $levelID, ':ip' => $ip]); } //getting the days since uploaded... or outputting the date in Y-M-D format at least for now... - $uploadDate = date("d-m-Y G-i", $result["uploadDate"]); - $updateDate = date("d-m-Y G-i", $result["updateDate"]); + $uploadDate = $gs->formatTimestamp($result["uploadDate"], true); + $updateDate = $gs->formatTimestamp($result["updateDate"], true); //password xor $pass = $result["password"]; $desc = $result["levelDesc"]; diff --git a/incl/lib/mainLib.php b/incl/lib/mainLib.php index 9b030908c..8eccc7bbe 100644 --- a/incl/lib/mainLib.php +++ b/incl/lib/mainLib.php @@ -1208,4 +1208,39 @@ public function mail($mail = '', $user = '', $isForgotPass = false) { return $m->send(); } } + function formatTimestamp($timestamp, $removeAgo = false) { + $timeDifference = time() - $timestamp; + $minute = 60; + $hour = 3600; + $day = 86400; + $week = 604800; + $month = 2592000; + $year = 31536000; + + $ago = $removeAgo ? '' : ' ago'; + + if ($timeDifference <= 1) { + return '1 second' . $ago; + } elseif ($timeDifference < $minute) { + return $timeDifference . ' second' . ($timeDifference > 1 ? 's' : '') . $ago; + } elseif ($timeDifference < $hour) { + $minutes = round($timeDifference / $minute); + return $minutes . ' minute' . ($minutes > 1 ? 's' : '') . $ago; + } elseif ($timeDifference < $day) { + $hours = round($timeDifference / $hour); + return $hours . ' hour' . ($hours > 1 ? 's' : '') . $ago; + } elseif ($timeDifference < $week) { + $days = round($timeDifference / $day); + return $days . ' day' . ($days > 1 ? 's' : '') . $ago; + } elseif ($timeDifference < $month) { + $weeks = round($timeDifference / $week); + return $weeks . ' week' . ($weeks > 1 ? 's' : '') . $ago; + } elseif ($timeDifference < $year) { + $months = round($timeDifference / $month); + return $months . ' month' . ($months > 1 ? 's' : '') . $ago; + } else { + $years = round($timeDifference / $year); + return $years . ' year' . ($years > 1 ? 's' : '') . $ago; + } + } } diff --git a/incl/messages/downloadGJMessage.php b/incl/messages/downloadGJMessage.php index 195828437..f37422d89 100644 --- a/incl/messages/downloadGJMessage.php +++ b/incl/messages/downloadGJMessage.php @@ -3,6 +3,8 @@ include "../lib/connection.php"; require_once "../lib/GJPCheck.php"; require_once "../lib/exploitPatch.php"; +require_once "../lib/mainLib.php"; +$gs = new mainLib(); $accountID = GJPCheck::getAccountIDOrDie(); $messageID = ExploitPatch::remove($_POST["messageID"]); @@ -25,6 +27,6 @@ $query=$db->prepare("SELECT userName,userID,extID FROM users WHERE extID = :accountID"); $query->execute([':accountID' => $accountID]); $result12 = $query->fetch(); -$uploadDate = date("d/m/Y G.i", $result["timestamp"]); +$uploadDate = $gs->formatTimestamp($result["timestamp"], true); echo "6:".$result12["userName"].":3:".$result12["userID"].":2:".$result12["extID"].":1:".$result["messageID"].":4:".$result["subject"].":8:".$result["isNew"].":9:".$isSender.":5:".$result["body"].":7:".$uploadDate.""; -?> \ No newline at end of file +?> diff --git a/incl/messages/getGJMessages.php b/incl/messages/getGJMessages.php index 4d55c66e4..bc941d8c2 100644 --- a/incl/messages/getGJMessages.php +++ b/incl/messages/getGJMessages.php @@ -4,6 +4,8 @@ include "../lib/connection.php"; require_once "../lib/GJPCheck.php"; require_once "../lib/exploitPatch.php"; +require_once "../lib/mainLib.php"; +$gs = new mainLib(); $msgstring = ""; //code begins $toAccountID = GJPCheck::getAccountIDOrDie(); @@ -30,7 +32,7 @@ } foreach ($result as &$message1) { if($message1["messageID"]!=""){ - $uploadDate = date("d/m/Y G.i", $message1["timestamp"]); + $uploadDate = $gs->formatTimestamp($message1["timestamp"], true); if($getSent == 1){ $accountID = $message1["toAccountID"]; }else{ @@ -44,4 +46,4 @@ } $msgstring = substr($msgstring, 0, -1); echo $msgstring ."#".$msgcount.":".$offset.":10"; -?> \ No newline at end of file +?> diff --git a/incl/profiles/getGJUserInfo.php b/incl/profiles/getGJUserInfo.php index 614804b29..1475d1f10 100644 --- a/incl/profiles/getGJUserInfo.php +++ b/incl/profiles/getGJUserInfo.php @@ -87,7 +87,7 @@ $INCrequests = $query->rowCount(); $INCrequestinfo = $query->fetch(); if($INCrequests > 0){ - $uploaddate = date("d/m/Y G.i", $INCrequestinfo["uploadDate"]); + $uploaddate = $gs->formatTimestamp($INCrequestinfo["uploadDate"], true); $friendstate = 3; } //check if OUTCOMING friend request diff --git a/incl/relationships/getGJFriendRequests.php b/incl/relationships/getGJFriendRequests.php index bb04eb352..a80feb20f 100644 --- a/incl/relationships/getGJFriendRequests.php +++ b/incl/relationships/getGJFriendRequests.php @@ -3,6 +3,8 @@ include "../lib/connection.php"; require_once "../lib/exploitPatch.php"; require_once "../lib/GJPCheck.php"; +require_once "../lib/mainLib.php"; +$gs = new mainLib(); $reqstring = ""; $getSent = !empty($_POST["getSent"]) ? ExploitPatch::remove($_POST["getSent"]) : 0; @@ -43,7 +45,7 @@ $query->execute([':requester' => $requester]); $result2 = $query->fetchAll(); $user = $result2[0]; - $uploadTime = date("d/m/Y G.i", $request["uploadDate"]); + $uploadTime = $gs->formatTimestamp($request["uploadDate"], true); if(is_numeric($user["extID"])){ $extid = $user["extID"]; }else{ diff --git a/incl/scores/getGJLevelScores.php b/incl/scores/getGJLevelScores.php index aa58e0b33..4a5660984 100644 --- a/incl/scores/getGJLevelScores.php +++ b/incl/scores/getGJLevelScores.php @@ -75,7 +75,7 @@ $query2 = $db->prepare("SELECT userName, userID, icon, color1, color2, color3, iconType, special, extID, isBanned FROM users WHERE extID = :extID"); $query2->execute([':extID' => $extID]); $user = $query2->fetch(); - $time = date("d/m/Y G.i", $score["uploadDate"]); + $time = $gs->formatTimestamp($score["uploadDate"], true); if($user["isBanned"] == 0){ if($score["percent"] == 100) $place = 1; else if($score["percent"] > 75) $place = 2;