summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--pages/leaderboard.php53
1 files changed, 41 insertions, 12 deletions
diff --git a/pages/leaderboard.php b/pages/leaderboard.php
index 968e4df..fafcb23 100644
--- a/pages/leaderboard.php
+++ b/pages/leaderboard.php
@@ -1,5 +1,5 @@
<?php
-htmlHeader(array('stats'), 'Pathery Scores');
+htmlHeader(array('stats'), 'Pathery Scores', 'Score history for Pathery');
?>
<body>
@@ -13,13 +13,41 @@ include('./includes/datas.php');
include_once ('./includes/db.inc.php');
-//Display stats for how many days ago?
-$daysago = 1;
-if (($_GET['daysago'] * 1) > 1) {
- $daysago = ($_GET['daysago'] * 1);
-}
+
+//Holy non-PHP included function batman.
+function date_diff($date1, $date2) {
+ $current = $date1;
+ $datetime2 = date_create($date2);
+ $count = 0;
+ while(date_create($current) < $datetime2){
+ $current = gmdate("Y-m-d", strtotime("+1 day", strtotime($current)));
+ $count++;
+ }
+ return $count;
+}
+
+$dateCurrent = date('Y-m-d', strtotime("-2 days"));
+
+//This is only used in a strtotime function, so this should be safe.
+$dateLookup = $_GET['date'];
+if (!strtotime($dateLookup))
+ $dateLookup = $dateCurrent;
+
+//!!Some validation should take place on dateLookup
+$daysago = date_diff($dateLookup, date('Y-m-d'));
+$dateAgo = strtotime("-$daysago days");
+
+$dateAsStr = date('l F dS Y', $dateAgo);
+
+$dateNextDay = date('Y-m-d', strtotime("+1 day", $dateAgo));
+$datePrevDay = date('Y-m-d', strtotime("-1 day", $dateAgo));
+
+//Offset the days-ago for map-lookups.
+$daysago--;
+if ($daysago < 1)
+ die("You must specify a date previous to today.");
$tStats = getStat(1, $daysago);
$yStats = getStat(2, $daysago);
@@ -95,16 +123,17 @@ function getStat ($type, $daysago = 1) {
<div class="wrapper">
+<div style='text-align:center;padding-bottom:7px;'>
+Showing scores for the maps played on <? echo $dateAsStr; ?>
+</div>
<div id="daynav">
<?
if ($daysago > 1) {
- $nextday = $daysago - 1;
- echo "<a href='leaderboard?daysago=1' title='Now'>Current Day</a>";
- echo "<a href='leaderboard?daysago=$nextday' title='Newer'>Next Day</a>";
+ echo "<a href='leaderboard?date=$dateCurrent' title='Now'>Current Day</a>";
+ echo "<a href='leaderboard?date=$dateNextDay' title='Newer'>Next Day</a>";
}
- $prevday = $daysago + 1;
- echo "<a href='leaderboard?daysago=$prevday' title='Older'>Previous Day</a>";
+ echo "<a href='leaderboard?date=$datePrevDay' title='Older'>Previous Day</a>";
?>
</div>
@@ -296,7 +325,7 @@ showStats(1);
</script>
<div id="copy">
- Copyright &copy; 2011 pathery.com
+ Copyright &copy; 2011-2012 pathery.com
</div>
<script src="sounds/script/soundmanager.js"></script>