From 5138b32717c9a54de0882e0319a70eda2bb2c63a Mon Sep 17 00:00:00 2001 From: Patrick Davison Date: Thu, 21 Feb 2013 22:25:51 -0800 Subject: Score page improvements. --- .htaccess | 8 +++++++ ajax/maps.ajax.php | 62 ++++++++++++++++++++++++++++++++++++++++++------------ pages/scores.php | 37 ++++++++++++++++++++++---------- 3 files changed, 83 insertions(+), 24 deletions(-) diff --git a/.htaccess b/.htaccess index c8a1820..f300bce 100644 --- a/.htaccess +++ b/.htaccess @@ -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 @@ ';