Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix timestamps #58

Closed
wants to merge 23 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions incl/comments/getGJAccountComments.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion incl/comments/getGJComments.php
Original file line number Diff line number Diff line change
Expand Up @@ -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"];
Expand Down
4 changes: 2 additions & 2 deletions incl/levels/downloadGJLevel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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"];
Expand Down
35 changes: 35 additions & 0 deletions incl/lib/mainLib.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
6 changes: 4 additions & 2 deletions incl/messages/downloadGJMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -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"]);
Expand All @@ -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."";
?>
?>
6 changes: 4 additions & 2 deletions incl/messages/getGJMessages.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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{
Expand All @@ -44,4 +46,4 @@
}
$msgstring = substr($msgstring, 0, -1);
echo $msgstring ."#".$msgcount.":".$offset.":10";
?>
?>
2 changes: 1 addition & 1 deletion incl/profiles/getGJUserInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion incl/relationships/getGJFriendRequests.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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{
Expand Down
2 changes: 1 addition & 1 deletion incl/scores/getGJLevelScores.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down