diff options
author | Patrick Davison <snapwilliam@gmail.com> | 2013-02-21 22:25:51 -0800 |
---|---|---|
committer | Patrick Davison <snapwilliam@gmail.com> | 2013-02-21 22:25:51 -0800 |
commit | 5138b32717c9a54de0882e0319a70eda2bb2c63a (patch) | |
tree | 86df8058b0ac603d6f1fab98d3f34a861d8bad33 | |
parent | 714925aa06b68516a5f45d03c658f440f5342d33 (diff) | |
download | pathery-5138b32717c9a54de0882e0319a70eda2bb2c63a.tar.xz |
Score page improvements.
-rw-r--r-- | .htaccess | 8 | ||||
-rw-r--r-- | ajax/maps.ajax.php | 62 | ||||
-rw-r--r-- | pages/scores.php | 37 |
3 files changed, 83 insertions, 24 deletions
@@ -18,10 +18,18 @@ RewriteRule ^([a-z]+)$ /index\.php?page=$1 [QSA,NC] # GetMap Re-write
RewriteRule ^map/(.*)$ /ajax/maps\.ajax\.php?mapid=$1 [QSA,NC]
+RewriteRule ^a/map/(.*)$ /ajax/maps\.ajax\.php?mapid=$1 [QSA,NC]
+
+RewriteRule ^a/mapsbydate/(.*)$ /ajax/maps\.ajax\.php?getmapidsbydate=$1 [QSA,NC]
RewriteRule ^challenge/(.*)$ /ajax/challenges\.ajax\.php?challengeid=$1 [QSA,NC]
+RewriteRule ^a/challenge/(.*)$ /ajax/challenges\.ajax\.php?challengeid=$1 [QSA,NC]
RewriteRule ^user/(.*)$ /ajax/users\.ajax\.php?userid=$1 [QSA,NC]
+RewriteRule ^a/user/(.*)$ /ajax/users\.ajax\.php?userid=$1 [QSA,NC]
+
+RewriteRule ^a/score/(.*)$ /ajax/scores\.ajax\.php?r=$1 [QSA,NC]
+
# CSS and JS cache for 480 weeks
diff --git a/ajax/maps.ajax.php b/ajax/maps.ajax.php index 611080d..8ceade5 100644 --- a/ajax/maps.ajax.php +++ b/ajax/maps.ajax.php @@ -3,21 +3,35 @@ ob_start("ob_gzhandler"); include('../includes/mapclass.php');
include('../includes/maps.php');
+include('../includes/sqlEmbedded.php');
-//Remove the ending .js
-$tmp = explode(".", $_GET['mapid']);
-$mapID = $tmp[0] * 1;
-if (!is_int($mapID)) exit;
-
-$map = getMapObjectByID($mapID);
+if (isset($_GET['getmapidsbydate'])) {
+ //Remove the ending .js
+ $tmp = explode(".", $_GET['getmapidsbydate']);
+ $requestDate = $tmp[0];
+ sendCacheHeaders();
+ echo json_encode(getMapIDsByDate($requestDate));
+ exit;
+}
+if (isset($_GET['mapid'])) {
+ //Remove the ending .js
+ $tmp = explode(".", $_GET['mapid']);
+ $mapID = $tmp[0] * 1;
+ if (!is_int($mapID)) exit;
+ $map = getMapObjectByID($mapID);
+ sendCacheHeaders();
+ echo json_encode($map);
+ exit;
+}
-$expires = 365*24*60*60;
-//TODO: Remove this line once we're confident in data in the mapObject.
-$expires = 1*24*60*60;
-header("Cache-Control: public, maxage=".$expires);
-header('Expires: ' . gmdate('D, d M Y H:i:s', time()+$expires) . ' GMT');
-header("Content-type: text/javascript");
-echo json_encode($map);
+function sendCacheHeaders() {
+ $expires = 365*24*60*60;
+ //TODO: Remove this line once we're confident in data in the mapObject.
+ $expires = 120;
+ header("Cache-Control: public, maxage=".$expires);
+ header('Expires: ' . gmdate('D, d M Y H:i:s', time()+$expires) . ' GMT');
+ header("Content-type: text/javascript");
+}
function getMapObjectByID($mapID) {
include_once('../includes/sqlEmbedded.php');
@@ -37,5 +51,27 @@ function getMapObjectByID($mapID) { }
}
+function getMapIDsByDate($date) {
+ global $mysqli;
+ $sql = "SELECT MIN(mapOfTheDay.mapId) AS mapId
+ FROM `mapOfTheDay`
+ INNER JOIN
+ (
+ SELECT mapType, MIN(mapExpireTime) AS mapExpireTime
+ FROM mapOfTheDay
+ WHERE mapExpireTime > ?
+ GROUP BY mapType
+ ) AS expireTimes ON mapOfTheDay.mapType = expireTimes.mapType
+ AND mapOfTheDay.mapExpireTime = expireTimes.mapExpireTime
+ GROUP BY mapOfTheDay.mapType";
+ $stmt = $mysqli->prepare($sql);
+ $stmt->bind_param("s", $date);
+ $stmt->execute();
+ $stmt->bind_result($mapID);
+ while ($stmt->fetch()) {
+ $ids[] = $mapID;
+ }
+ return $ids;
+}
?>
\ No newline at end of file diff --git a/pages/scores.php b/pages/scores.php index f3ce459..3a28494 100644 --- a/pages/scores.php +++ b/pages/scores.php @@ -1,6 +1,6 @@ <?php
htmlHeader(
- array('stats', 'challenge'), 'Scores',
+ array('stats'), 'Scores',
'Score history for Pathery',
array('scores', 'dateformat')
);
@@ -30,7 +30,10 @@ playerWallEmblem = '<?PHP echo isset($wallEmblem) ? $wallEmblem : ''; ?>'; </script>
<script>
-
+//TODO: Might want to store this time globablly.
+//March 8th 2011; first started storing maps on pathery.com
+var startOfPathery = new Date();
+startOfPathery.setTime(1299571200000);
var tomorrow = new Date();
tomorrow.setTime(tomorrow.getTime() + <? echo $timeUntilNewDailyMap; ?> * 1000);
@@ -98,29 +101,39 @@ var pointerDate; function getMapIDs(request) {
switch (request) {
case "next":
- if (pointerTime.getTime() + (24*60*60*1000) < serverTime.getTime()) {
+ if (pointerTime.getTime() + (24*60*60*1000) <= serverTime.getTime()) {
pointerTime.setTime(pointerTime.getTime() + (24*60*60*1000));
pointerDate = pointerTime.format("yyyy-mm-dd");
} else return;
break;
case "prev":
- if (pointerTime.getTime() + (24*60*60*1000) > 1) {
+ if (pointerTime.getTime() > startOfPathery.getTime()) {
pointerTime.setTime(pointerTime.getTime() - (24*60*60*1000));
pointerDate = pointerTime.format("yyyy-mm-dd");
} else return;
break;
}
- $('#displayDate').html(pointerTime.format("dddd, mmmm dS, yyyy"));
+ var timeDisplayPrefix = '';
if (pointerTime.getTime() + (1*24*60*60*1000) > serverTime.getTime()) {
$('#mapNavRight').removeClass('mapNavActive');
$('#mapNavRight').addClass('mapNavDisabled');
+ timeDisplayPrefix = '<i title="(Server Time)">Today </i>';
} else {
$('#mapNavRight').addClass('mapNavActive');
$('#mapNavRight').removeClass('mapNavDisabled');
}
+ if (pointerTime.getTime() <= startOfPathery.getTime()) {
+ $('#mapNavLeft').removeClass('mapNavActive');
+ $('#mapNavLeft').addClass('mapNavDisabled');
+ timeDisplayPrefix = '<i title="The start!">Pathery Started </i>';
+ } else {
+ $('#mapNavLeft').addClass('mapNavActive');
+ $('#mapNavLeft').removeClass('mapNavDisabled');
+ }
+ $('#displayDate').html(timeDisplayPrefix+pointerTime.format("dddd, mmmm dS, yyyy"));
- var urlString = "ajax/scores.ajax.php?getmapidsbydate="+pointerDate;
+ var urlString = "a/mapsbydate/"+pointerDate+'.js';
updateHash();
$.ajax({
type: "GET",
@@ -152,15 +165,18 @@ function getMapIDsResponse(response) { //Add non-existing maps
//console.log("going through json", json);
+ var lastMapID = 0;
$.each(json, function(key, mapID) {
//console.log("add: compare:", mapID, mapsInNav);
if (jQuery.inArray(mapID, mapsInNav) == -1) {
addMapToNav(mapID);
- if (goToPointer == true && pointerMapID < 0) {
- pointerMapID = mapID;
- }
+ lastMapID = mapID;
}
});
+ if (goToPointer == true && pointerMapID < 0) {
+ pointerMapID = lastMapID;
+ }
+
//Don't queue animations...
if ($('#mapNavigation').is(':animated')) {
$("#mapNavigation").show(0);
@@ -179,8 +195,7 @@ function addMapToNav(mapID) { //$("#mapNavigation").append($newdiv1);
$("#mapNavigation").prepend($newdiv1);
- //var URLString = 'map/'+mapID+'.js';
- var URLString = 'map/'+mapID;
+ var URLString = 'a/map/'+mapID+'.js';
$.ajax({
type: "GET",
|