-
Notifications
You must be signed in to change notification settings - Fork 4
/
source
369 lines (324 loc) · 10.5 KB
/
source
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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
<?php
error_reporting(0);
//putenv("GMT");
//putenv("TZ=America/Los_Angeles");
if (!isset($_POST['zone'])) {
putenv("TZ=US/Pacific");
date_default_timezone_set('America/Los_Angeles');
} else {
putenv("TZ=".$_POST["zone"]."");
date_default_timezone_set("".$_POST["zone"]."");
}
if (@$_POST['start'] == "") {
$start = strtotime("Today");
} else {
$start = strtotime($_POST["start"]);
}
if (@$_POST['end'] == "") {
$end = $start + 31449600;
} else {
$end = strtotime($_POST["end"]);
}
if (@$_POST['rise_off'] == "") {
$rise_off = "0";
} else {
$rise_off = $_POST["rise_off"]*60;
}
if (@$_POST['set_off'] == "") {
$set_off = "0";
} else {
$set_off = $_POST["set_off"]*60;
}
if (@$_POST['lat'] == "") {
$lat = 45.58753958079636;
} else {
$lat = $_POST["lat"];
}
if (@$_POST['lon'] == "") {
$lon = -122.58886098861694;
} else {
$lon = $_POST["lon"];
}
if (@$_POST['twelve'] == "") {
$twelve = "";
} else {
$twelve = "yes";
}
if (@$_POST['description'] == "") {
$description = "";
} else {
$description = str_replace(array("\r\n", "\r", "\n"), "", stripslashes($_POST["description"]));
}
if (isset($_POST["submit"])) {
//header("Content-type: text/plain");
header('Content-Type: text/calendar; charset=utf-8');
header('Content-Disposition: attachment; filename="ical_sun.ics"');
echo "BEGIN:VCALENDAR
CALSCALE:GREGORIAN
METHOD:PUBLISH
PRODID:-//Apple Computer\, Inc//iCal 1.0//EN
X-WR-CALNAME;VALUE=TEXT:Sunrise and/or Sunset Times for $lat,$lon
VERSION:2.0\n";
$i = 0;
$day = $start;
while ($day <= $end ) {
if ($i <= 365) {
if (isset($_POST['sunrise'])) {
echo "BEGIN:VEVENT\n";
$sunrise = date_sun_info($day, $lat, $lon);
$real_sunrise = date("His",$sunrise[sunrise]);
$offset_sunrise = date("His",$sunrise[sunrise]+$rise_off);
$rise_day = date("Ymd", $day);
if ($twelve == "yes") {
$real_sunrise = date("his",$sunrise[sunrise]);
echo "UID:$rise_day"."T"."$offset_sunrise
SUMMARY:Sunrise : ".substr($real_sunrise,0,2).":".substr($real_sunrise,2,2)." AM
DTSTAMP:$rise_day"."T"."$offset_sunrise
DTSTART:$rise_day"."T"."$offset_sunrise
DTEND:$rise_day"."T"."$offset_sunrise
DESCRIPTION:$description
URL:http://pdxvr.com/ical_sun.php
END:VEVENT\n";
} else {
echo "UID:$rise_day"."T"."$offset_sunrise
SUMMARY:Sunrise : ".substr($real_sunrise,0,2).":".substr($real_sunrise,2,2)."
DTSTAMP:$rise_day"."T"."$offset_sunrise
DTSTART:$rise_day"."T"."$offset_sunrise
DTEND:$rise_day"."T"."$offset_sunrise
DESCRIPTION:$description
URL:http://pdxvr.com/ical_sun.php
END:VEVENT\n";
}
}
if (isset($_POST['sunset'])) {
echo "BEGIN:VEVENT\n";
$sunset = date_sun_info($day, $lat, $lon);
$real_sunset = date("His",$sunset[sunset]);
$offset_sunset = date("His",$sunset[sunset]+$set_off);
$set_day = date("Ymd", $day);
if ($twelve == "yes") {
$real_sunset = date("his",$sunset[sunset]);
echo "UID:$set_day"."T"."$offset_sunset
SUMMARY:Sunset : ".substr($real_sunset,0,2).":".substr($real_sunset,2,2)." PM
DTSTAMP:$set_day"."T"."$offset_sunset
DTSTART:$set_day"."T"."$offset_sunset
DTEND:$set_day"."T"."$offset_sunset
DESCRIPTION:$description
URL:http://pdxvr.com/ical_sun.php
END:VEVENT\n";
} else {
echo "UID:$set_day"."T"."$offset_sunset
SUMMARY:Sunset : ".substr($real_sunset,0,2).":".substr($real_sunset,2,2)."
DTSTAMP:$set_day"."T"."$offset_sunset
DTSTART:$set_day"."T"."$offset_sunset
DTEND:$set_day"."T"."$offset_sunset
DESCRIPTION:$description
URL:http://pdxvr.com/ical_sun.php
END:VEVENT\n";
}
}
$day = mktime(0,0,0,date("m", $day),date("d", $day)+1,date("Y", $day));
}
$i++;
}
echo "END:VCALENDAR";
} else {
putenv("TZ-America/Los_Angeles");
$sunrise = date_sun_info(strtotime("Today"), $lat, $lon);
$sunset = date_sun_info(strtotime("Today"), $lat, $lon);
$sunrise[sunrise];
$sunset[sunset];
echo "<!doctype html>
<html lang=\"en\">
<head>
<meta charset=\"utf-8\">
<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0\"><title>Free Online iCal Sunrise and Sunset Calendar Generator</title>
<style>
body {
font-size: 16px;
font-family: Courier new, Courier, monospace;
font-weight: bold;
}
input, select, textarea {
font-size: 20px;
font-family: Courier new, Courier, monospace;
font-weight: bold;
padding: 8px;
margin: 5px 0;
}
input[type=checkbox] {
transform: scale(2);
}
.check {
border: 1px solid #ccc;
margin-left: 10px;
}
input[type=submit] {
-webkit-appearance: none;
border-radius: 5px;
font-size: 22px;
}
button {
-webkit-appearance: none;
border-radius: 5px;
font-size: 22px;
padding: 20px;
font-family: Courier new, Courier, monospace;
font-weight: bold;
}
.select {
border-radius: 5px;
}
.cboxl {
}
.cboxr {
margin: -21px 0 0 30px;
}
@media screen and (max-width:1400px) {
body {
font-size: 22px;
max-width: 100%;
}
input, select, textarea {
font-size: 22px;
font-family: Courier;
font-weight: bold;
padding: 20px;
margin: 5px 0;
width: 100%;
}
input[type=checkbox] {
transform: scale(.7);
width: 20px;
}
button {
-webkit-appearance: none;
border-radius: 5px;
font-size: 22px;
padding: 20px;
font-family: Courier new, Courier, monospace;
font-weight: bold;
width: 100%;
}
.check {
border: 1px solid #ccc;
margin-left: 0px;
}
.cboxr {
margin: -40px 0 0 35px;
}
}
</style>
";
?>
</head>
<?php
echo "<body style=\"padding: 20px; margin: 0;\"><h1>Free Online iCal Sunrise and Sunset Calendar Generator</h1>
<b>Local Information - Portland Oregon - Pacific Standard (US/Pacific)</b>
<br>
This script was last updated on ".date('d M, Y', getlastmod())."<br>
Today - ".date('d M Y', strtotime("Today"))."
<br>
Sunrise - ".date('H:i', $sunrise[sunrise])."<br>
Sunset - ".date('H:i', $sunset[sunset])."
<hr>";
echo "<p>Use the form below to generate an iCal-formatted calendar for your location.<br>
Use the 'offset' if you need to schedule an event (or notification) before or after the actual sunrise or sunset time - or whatever.<br>
<br></p>
<p style=\"color: red;\">NOTE: Before you import the ICS, please check it. It's a lot of hassle to remove a year of individual events.
<br><br>
You cannot subscribe to the calendar. You must come back here annualy or generate multiple years of calendars at a time now.<p>
<span style=\"color: red;\">*</span> = Required for accurate results, location defaults to Portland International Airport, Oregon, USA <a target=\"_blank\" style=\"text-decoration: none;\" href=\"https://maps.google.com/?q=45.58753,-122.58886\">(45.58753, -122.58886)</a>
<br><br><br>
<button onclick=\"getLocation()\">Get Geo Location</button>
<p id=\"getGeo\"> </p>
<form method=\"post\">
latitude (decimal i.e. 45.5555)<br><input type=\"text\" name=\"lat\" id=\"lat\" ><span style=\"color: red;\"> *</span>
<br><hr><br>
longitude (decimal - don't forget the minus sign if in the west)<br><input type=\"text\" name=\"lon\" id=\"lon\" ><span style=\"color: red;\"> *</span>
<br><hr><br>
start date (MM/DD/YYYY) defaults to today<br><input type=\"text\" name=\"start\" >
<br><hr><br>
end date (MM/DD/YYYY) defaults to one year from today (maximum 365 days)<br><input type=\"text\" name=\"end\" >
<br><hr><br>
sunrise offset in minutes (use \"+15\" or \"-15\" for example)<br><input type=\"text\" name=\"rise_off\" >
<br><hr><br>
sunset offset in minutes (use \"+15\" or \"-15)\" for example
<br><input type=\"text\" name=\"set_off\" >
<br><hr><br>
<select class=\"select\" name=\"zone\">";
$zone = timezone_identifiers_list();
echo "<option>America/Los_Angeles</option>";
foreach ($zone as $key => $value) {
echo "<option>$value</option>";
}
echo "
</select><span style=\"color: red;\"> *</span> <b>important</b> - your timezone<br>
<br><hr><br>
<span style=\"color: red;\">check one or both of the boxes below</span>
<br>
<br>
<div class=\"cboxl\"><input type=\"checkbox\" class=\"check\" name=\"sunrise\" id=\"sunrise\"></div><div class=\"cboxr\"><label for=\"sunrise\"> generate sunrise times</label></div>
<br>
<br>
<div class=\"cboxl\"><input type=\"checkbox\" class=\"check\" name=\"sunset\" id=\"sunset\"></div><div class=\"cboxr\"><label for=\"sunset\"> generate sunset times</label></div>
<br>
<hr>
<br>
<div class=\"cboxl\"><input type=\"checkbox\" class=\"check\" name=\"twelve\" id=\"twelve\"></div><div class=\"cboxr\"><label for=\"twelve\"> use 12 hour times (AM/PM)</label></div>
<br>
<br>
<br>
<!--
<input type=\"checkbox\" name=\"dst\"/> check this to automatically remove the default US daylight savings time adjustment<br>
-->
Enter Description Here :
<br>
<textarea style=\"width: 100%; height: 200px;\" name=\"description\"></textarea><input type=\"submit\" name=\"submit\" style=\"padding: 20px; font-family: Courier new, Courier, monospace\" value=\"Submit\" >
</form>
";
?>
<script>alert("\nI disabled subscriptions.\n\nPlease download an ICS file as needed.");</script>
<script>
let myapp = {
x: document.getElementById("getGeo"),
lat: document.getElementById("lat"),
lon: document.getElementById("lon"),
};
function getLocation() {
myapp.x.innerHTML = ' ';
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition, showError);
} else {
"Geolocation is not supported by this browser.";
}
}
function showPosition(position) {
// myapp.x.innerHTML = "Latitude: " + position.coords.latitude +
// "<br>Longitude: " + position.coords.longitude;
myapp.lat.value = Math.round(position.coords.latitude * 100) / 100;
myapp.lon.value = Math.round(position.coords.longitude * 100) / 100;
}
function showError(error) {
myapp.lat.value = "";
myapp.lon.value = "";
myapp.x.innerHTML = "<br>Error message: " + error.message;
}
</script>
<?php
echo "
<h2>NOTES</h2>
<span style=\"line-height: 22px;\">
I wrote this in late 2009, updated it for different versions of PHP, then in 2022 to add 12 hour time, accessibility fixes, location services, and updated the sunrise / sunset calculations. I do NOT do anything with your location. It's only passed back to this form where it's used to calculate the events.
<br><br>
DAYLIGHT SAVING TIME:<br>
PHP appears to have DST built in but you must select the correct time zone. America/Phoenix, won't give you DST because Arizona doesn't do DST.
<br><br>
<strong>Problems or questions</strong> - <a href=\"https://finch.red/contact\" target=\"_blank\">contact me</a> or <a href=\"https://paypal.me/crowdotblack?country.x=US&locale.x=en_US\" target=\"_blank\">buy me a coffee</a>
<br><br>
<a href=\"https://github.com/pdxvr/ical_sunrise_sunset/blob/main/source\" target=\"_blank\">Source code</a>
</span><br>
</body>
</html>";
}
?>