forked from isitchristmas/web
-
Notifications
You must be signed in to change notification settings - Fork 1
/
iic.php
180 lines (152 loc) · 4.67 KB
/
iic.php
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
<?php
require 'hostip.php';
// Accepts: A time
// Returns: Whether or not it is Christmas
function isItChristmas($time = null) {
// May as well uncomment this from 12/27 through 12/23
// return "NO";
// set Christmas
$christmas = "12/25";
$ip = getIp();
// debug:
// $ip = "193.51.208.14"; // French IP
// $christmas = "12/24";
$location = null;
if ($ip) {
// db credentials, see db.php.example
require 'db.php';
DBconnect($server, $username, $password, $database);
$location = ipRoughLocate($ip);
// if we don't know the country, let's assume eastern time (mediocre)
if ($location["countryName"] == "(Unknown Country?)")
$local_time = easternTime($time);
else
$local_time = trueLocalTime($time, $location["lng"]);
}
else {
$local_time = easternTime($time);
}
$isit = (strftime("%m/%d", $local_time) == $christmas);
return $isit ? yes($location) : "NO";
}
// used to produce a country code for the JS to work with
function getCountryCode() {
$ip = getIp();
// debug:
// $ip = "193.51.208.14"; // French IP
// $ip = "71.164.115.181"; // US IP
$location = null;
if ($ip) {
// db credentials, see db.php.example
require 'db.php';
DBconnect($server, $username, $password, $database);
$location = ipRoughLocate($ip);
}
if (!$location || !$location["countryCode"] || $location["countryName"] == "(Unknown Country?)")
return "US";
else
return $location["countryCode"];
}
// Helper functions
function trueLocalTime($time, $longitude) {
// establish the GMT time we're talking about
if (!$time)
$time = gmmktime();
else
$time = gmmktime() - (time() - $time);
$time += (8 * 3600); // Dreamhost's box thinks PST is GMT, awesome
// estimate time zone from longitude (an hour for every 15 degrees from GMT)
$offset = floor($longitude / 15);
$true_local_time = $time + ($offset * 3600);
return $true_local_time;
}
function easternTime($time) {
if (!$time) $time = time();
$time += (3 * 3600); // Dreamhost is in PST, no matter what you say
return $time;
}
function yes($location) {
if (!$location || !$location["countryCode"] || $location["countryName"] == "(Unknown Country?)")
return "YES";
$code = $location["countryCode"];
// This array is IsItChristmas' sole IP
$codes = array(
"US" => "YES", // United States
"FR" => "OUI", // France
"NL" => "JA", // Netherlands
"ZA" => "JA", // South Africa
"ES" => "SÍ", // Spain
"UK" => "YES", // United Kingdom
"CA" => "YES/OUI", // Canada (English/French)
"PL" => "TAK", // Poland
"SE" => "JA", // Sweden
"LT" => "TAIP", // Lithuania
"DE" => "JA", // Germany
"IE" => "IS EA", // Ireland
"AU" => "YES", // Australia
"JP" => "HAI", // Japan
"NO" => "JA", // Norway
"IT" => "SÌ", // Italy
"HU" => "IGEN", // Hungary
"DK" => "JA", // Denmark
"FI" => "KYLLÄ", // Finland
"BE" => "JA", // Belgium
"CL" => "SÍ", // Chile
"MX" => "SÍ", // Mexico
"NZ" => "YES", // New Zealand
"AT" => "JA", // Austria
"RO" => "DA", // Romania
"CH" => "JA/OUI", // Switzerland (German/French)
"PT" => "SIM", // Portugal
"BR" => "SIM", // Brazil
"AR" => "SÍ", // Argentina
"EE" => "JAA", // Estonia
"HR" => "DA", // Croatia
"CN" => "SHI", // China (Mandarin)
"IN" => "HAJI", // India
"SG" => "YA", // Singapore
"PH" => "ÓO", // Phillipines
"IL" => "KEN", // Israel
"KR" => "NE", // Korea
"CZ" => "ANO", // Czech Republic
"SK" => "ÁNO", // Slovakia
"GR" => "NE", // Greece
"IS" => "JÁ", // Iceland
"VE" => "SÍ", // Venezuela
"SI" => "DA", // Slovenia
"TH" => "CHAI", // Thailand
"LV" => "JĀ", // Latvia
"RU" => "ДА", // Russia
"HK" => "HAI", // Hong Kong (Cantonese)
"TR" => "EVET", // Turkey
"MY" => "YA", // Malaysia
"PR" => "SÍ", // Puerto Rico
"CO" => "SÍ", // Colombia
"EC" => "SÍ", // Ecuador
"PE" => "SÍ", // Peru
"CR" => "SÍ", // Costa Rica
"UY" => "SÍ", // Uruguay
"CY" => "NE", // Cyprus
"GT" => "SÍ", // Guatemala
"SV" => "SÍ", // El Salvador
"DO" => "SÍ", // Dominican Republic
"BM" => "SIM", // Bermuda
"PA" => "SÍ", // Panama
"BO" => "SÍ", // Bolivia
"TT" => "SÍ", // Trinidad & Tobago
"DM" => "WÍ", // Dominica (Creole)
"HT" => "WÍ", // Haiti (Creole)
"JM" => "YES", // Jamaica
"BB" => "YES", // Barbado
"BZ" => "YES", // Belize
"KY" => "YES", // Cayman Islands
"NI" => "SÍ", // Nicaragua
"PY" => "HÊE", // Paraguay
"VN" => "ĐÚNG" // Vietnam
);
if (!$codes[$code])
return "YES";
else
return $codes[$code];
}
?>