1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
|
<?
ob_start("ob_gzhandler");
include('../includes/mapclass.php');
include('../includes/maps.php');
include('../includes/sqlEmbedded.php');
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);
if ($map == null) {
header("Status: 404 Not Found");
exit;
}
sendCacheHeaders();
echo json_encode($map);
exit;
}
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');
include_once('../includes/maps.php');
$sql = "SELECT `code`, `name`, `mapExpireTime`
FROM `maps`
INNER JOIN `mapOfTheDay` ON mapID = maps.ID
WHERE maps.ID = '$mapID'
";
$result = mysql_query($sql);
if (mysql_num_rows($result) > 0) {
list($code, $name, $mapExpireTime) = mysql_fetch_row($result);
if ($code == '') return null;
$map = new map($code, $mapID);
$map->name = $name;
$map->dateExpires = strtotime($mapExpireTime);
return $map;
}
}
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 > ?
AND mapDate <= ?
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("ss", $date, $date);
$stmt->execute();
$stmt->bind_result($mapID);
while ($stmt->fetch()) {
$ids[] = $mapID;
}
return $ids;
}
?>
|