-
Notifications
You must be signed in to change notification settings - Fork 0
/
makecal.php
executable file
·168 lines (143 loc) · 10 KB
/
makecal.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
<?php
use Sabre\VObject;
// error_reporting(E_ALL);
include 'vendor/autoload.php';
// for local tests only
// parse_str(implode('&', array_slice($argv, 1)), $_GET);
$param_in = $_GET['p'];
$params = explode('-', $param_in);
// Send Headers for correct caching
//header('Expires: '.gmdate('D, d M Y H:i:s \G\M\T', strtotime('2016-07-03 22:00:00')));
//header('ETag: '.md5('xhazw8-Revision6'));
// make the caching more dynamic to display the "nagging" phase-out MessageFormatter
$expiry = gmdate('D, d M Y H:i:s \G\M\T', (new DateTime())->setTime(23, 58)->getTimestamp());
header('Expires: '.$expiry);
header('ETag: '.md5('xhazw8-Revision7'.$expiry));
header('cache-control: public ');
// headers for file downloaders
header('Content-Type: text/calendar; charset=utf-8');
header('Content-Disposition: attachment; filename="euro2016-schedule-'.$param_in.'.ics"');
// gamenr, date, location, phase, formal1, formal2, potential1, potential2
$games = [
['1', '10.06.2016 21:00', 'Stade de France, Saint-Denis, France', 'Group matches', 'FRA', 'ROU', ['FRA'], ['ROU']],
['2', '11.06.2016 15:00', 'Stade Bollaert-Delelis, Lens, France', 'Group matches', 'ALB', 'SUI', ['ALB'], ['SUI']],
['3', '11.06.2016 18:00', 'Stade Matmut Atlantique, Bordeaux, France', 'Group matches', 'WAL', 'SVK', ['WAL'], ['SVK']],
['4', '11.06.2016 21:00', 'Stade Vélodrome, Marseille, France', 'Group matches', 'ENG', 'RUS', ['ENG'], ['RUS']],
['5', '12.06.2016 15:00', 'Parc des Princes, Paris, France', 'Group matches', 'TUR', 'CRO', ['TUR'], ['CRO']],
['6', '12.06.2016 18:00', 'Allianz Riviera, Nice, France', 'Group matches', 'POL', 'NIR', ['POL'], ['NIR']],
['7', '12.06.2016 21:00', 'Stade Pierre-Mauroy, Lille, France', 'Group matches', 'GER', 'UKR', ['GER'], ['UKR']],
['8', '13.06.2016 15:00', 'Stadium Municipal, Toulouse, France', 'Group matches', 'ESP', 'CZE', ['ESP'], ['CZE']],
['9', '13.06.2016 18:00', 'Stade de France, Saint-Denis, France', 'Group matches', 'IRL', 'SWE', ['IRL'], ['SWE']],
['10', '13.06.2016 21:00', 'Parc Olympique Lyonnais, Lyon, France', 'Group matches', 'BEL', 'ITA', ['BEL'], ['ITA']],
['11', '14.06.2016 18:00', 'Stade Matmut Atlantique, Bordeaux, France', 'Group matches', 'AUT', 'HUN', ['AUT'], ['HUN']],
['12', '14.06.2016 21:00', 'Stade Geoffroy-Guichard, Saint-Etienne, France', 'Group matches', 'POR', 'ISL', ['POR'], ['ISL']],
['13', '15.06.2016 15:00', 'Stade Pierre-Mauroy, Lille, France', 'Group matches', 'RUS', 'SVK', ['RUS'], ['SVK']],
['14', '15.06.2016 18:00', 'Parc des Princes, Paris, France', 'Group matches', 'ROU', 'SUI', ['ROU'], ['SUI']],
['15', '15.06.2016 21:00', 'Stade Vélodrome, Marseille, France', 'Group matches', 'FRA', 'ALB', ['FRA'], ['ALB']],
['16', '16.06.2016 15:00', 'Stade Bollaert-Delelis, Lens, France', 'Group matches', 'ENG', 'WAL', ['ENG'], ['WAL']],
['17', '16.06.2016 18:00', 'Parc Olympique Lyonnais, Lyon, France', 'Group matches', 'UKR', 'NIR', ['UKR'], ['NIR']],
['18', '16.06.2016 21:00', 'Stade de France, Saint-Denis, France', 'Group matches', 'GER', 'POL', ['GER'], ['POL']],
['19', '17.06.2016 15:00', 'Stadium Municipal, Toulouse, France', 'Group matches', 'ITA', 'SWE', ['ITA'], ['SWE']],
['20', '17.06.2016 18:00', 'Stade Geoffroy-Guichard, Saint-Etienne, France', 'Group matches', 'CZE', 'CRO', ['CZE'], ['CRO']],
['21', '17.06.2016 21:00', 'Allianz Riviera, Nice, France', 'Group matches', 'ESP', 'TUR', ['ESP'], ['TUR']],
['22', '18.06.2016 15:00', 'Stade Matmut Atlantique, Bordeaux, France', 'Group matches', 'BEL', 'IRL', ['BEL'], ['IRL']],
['23', '18.06.2016 18:00', 'Stade Vélodrome, Marseille, France', 'Group matches', 'ISL', 'HUN', ['ISL'], ['HUN']],
['24', '18.06.2016 21:00', 'Parc des Princes, Paris, France', 'Group matches', 'POR', 'AUT', ['POR'], ['AUT']],
['25', '19.06.2016 21:00', 'Parc Olympique Lyonnais, Lyon, France', 'Group matches', 'ROU', 'ALB', ['ROU'], ['ALB']],
['26', '19.06.2016 21:00', 'Stade Pierre-Mauroy, Lille, France', 'Group matches', 'SUI', 'FRA', ['SUI'], ['FRA']],
['27', '20.06.2016 21:00', 'Stadium Municipal, Toulouse, France', 'Group matches', 'RUS', 'WAL', ['RUS'], ['WAL']],
['28', '20.06.2016 21:00', 'Stade Geoffroy-Guichard, Saint-Etienne, France', 'Group matches', 'SVK', 'ENG', ['SVK'], ['ENG']],
['29', '21.06.2016 18:00', 'Stade Vélodrome, Marseille, France', 'Group matches', 'UKR', 'POL', ['UKR'], ['POL']],
['30', '21.06.2016 18:00', 'Parc des Princes, Paris, France', 'Group matches', 'NIR', 'GER', ['NIR'], ['GER']],
['31', '21.06.2016 21:00', 'Stade Bollaert-Delelis, Lens, France', 'Group matches', 'CZE', 'TUR', ['CZE'], ['TUR']],
['32', '21.06.2016 21:00', 'Stade Matmut Atlantique, Bordeaux, France', 'Group matches', 'CRO', 'ESP', ['CRO'], ['ESP']],
['33', '22.06.2016 18:00', 'Stade de France, Saint-Denis, France', 'Group matches', 'ISL', 'AUT', ['ISL'], ['AUT']],
['34', '22.06.2016 18:00', 'Parc Olympique Lyonnais, Lyon, France', 'Group matches', 'HUN', 'POR', ['HUN'], ['POR']],
['35', '22.06.2016 21:00', 'Stade Pierre-Mauroy, Lille, France', 'Group matches', 'ITA', 'IRL', ['ITA'], ['IRL']],
['36', '22.06.2016 21:00', 'Allianz Riviera, Nice, France', 'Group matches', 'SWE', 'BEL', ['SWE'], ['BEL']],
// round of 16
['37', '25.06.2016 15:00', 'Stade Geoffroy-Guichard, Saint-Etienne, France', 'Round of 16', 'RA', 'RC', ['SUI'], ['POL']],
['38', '25.06.2016 18:00', 'Parc des Princes, Paris, France', 'Round of 16', 'WB', '3A/C/D', ['WAL'], ['NIR']],
['39', '25.06.2016 21:00', 'Stade Bollaert-Delelis, Lens, France', 'Round of 16', 'WD', '3B/E/F', ['CRO'], ['POR']],
['40', '26.06.2016 15:00', 'Parc Olympique Lyonnais, Lyon, France', 'Round of 16', 'WA', '3C/D/E', ['FRA'], ['IRL']],
['41', '26.06.2016 18:00', 'Stade Pierre-Mauroy, Lille, France', 'Round of 16', 'WC', '3A/B/F', ['GER'], ['SVK']],
['42', '26.06.2016 21:00', 'Stadium Municipal, Toulouse, France', 'Round of 16', 'WF', 'RE', ['HUN'], ['BEL']],
['43', '27.06.2016 18:00', 'Stade de France, Saint-Denis, France', 'Round of 16', 'WE', 'RD', ['ITA'], ['ESP']],
['44', '27.06.2016 21:00', 'Allianz Riviera, Nice, France', 'Round of 16', 'RB', 'RF', ['ENG'], ['ISL']],
// QUARTER
['45', '30.06.2016 21:00', 'Stade Vélodrome, Marseille, France', 'Quarter-Finals', 'W37', 'W39', ['POL'], ['POR']],
['46', '01.07.2016 21:00', 'Stade Pierre-Mauroy, Lille, France', 'Quarter-Finals', 'W38', 'W42', ['WAL'], ['BEL']],
['47', '02.07.2016 21:00', 'Stade Matmut Atlantique, Bordeaux, France', 'Quarter-Finals', 'W41', 'W43', ['GER'], ['ITA']],
['48', '03.07.2016 21:00', 'Stade de France, Saint-Denis, France', 'Quarter-Finals', 'W40', 'W44', ['FRA'], ['ISL']],
//HALF
['49', '06.07.2016 21:00', 'Parc Olympique Lyonnais, Lyon, France', 'Half-Finals', 'W45', 'W46', ['POR'], ['WAL']],
['50', '07.07.2016 21:00', 'Stade Vélodrome, Marseille, France', 'Half-Finals', 'W47', 'W48', ['GER'], ['FRA']],
//FINAL
['51', '10.07.2016 21:00', 'Stade de France, Saint-Denis, France', 'Final', 'W49', 'W50', ['POR'], ['FRA']],
];
$outgames = array();
// filter the games
foreach ($games as $game) {
$copygame = false;
foreach ($params as $param) {
if ($param == 'ALL') { // wants all games
$copygame = true;
} elseif ((is_array($game[6]) && in_array($param, $game[6])) || (is_array($game[7]) && in_array($param, $game[7]))) { // TEAM plays
$copygame = true;
} elseif ($game[3] == 'Round of 16' && $param == 'ALL16') {
$copygame = true;
} elseif ($game[3] == 'Quarter-Finals' && $param == 'ALLQ') {
$copygame = true;
} elseif ($game[3] == 'Half-Finals' && $param == 'ALLH') {
$copygame = true;
}/* elseif ($game[3] == 'Quarter-Finals' || $game[3] == 'Half-Finals' || $game[3] == 'Final') { // for now everyone gets the quarter/half/Final
$copygame = true;
}*/
}
if ($copygame) {
array_push($outgames, $game);
}
}
// format the calendar
$vcalendar = new VObject\Component\VCalendar();
$vcalendar->add('X-WR-CALNAME', 'EURO 2016 Schedule '.$param_in);
$vcalendar->add('X-WR-CALDESC', 'EURO 2016 Schedule '.$param_in."\nbrought to you by http://kralo.github.io/euro2016-calendar-ics-exporter/");
foreach ($outgames as $game) {
$vev = $vcalendar->add('VEVENT', ['UID' => 'euro2016_game'.$game[0]]);
// Summary and description; also resources
if ($game[6] != 'Z' && sizeof($game[6]) == 1) {
$involved = $game[6][0];
} else {
$involved = $game[4];
}
$involved .= ' - ';
if ($game[7] != 'Z' && sizeof($game[7]) == 1) {
$involved .= $game[7][0];
} else {
$involved .= $game[5];
}
$vev->add('SUMMARY', $involved.' / '.$game[3].' / EURO 2016 France');
//$ev->add_property('summary', $involved.' / '.$game[3].' / EURO 2016 France');
$vev->add('DESCRIPTION', 'Game '.$game[0]."\n"."source: http://www.uefa.com/uefaeuro/season=2016/matches/index.html\n\nbrought to you by http://kralo.github.io/euro2016-calendar-ics-exporter/");
$vev->add('location', $game[2]);
// Start-end date
$date = DateTime::createFromFormat('j.m.Y G:i T', $game[1].' CEST');
$vev->add('DTSTART', gmdate('Ymd\TGis\Z', $date->getTimestamp()));
$vev->add('DURATION', 'PT1H45M');
$vev->DTSTAMP = '20160501T235602Z';
$vev->add('categories', 'EURO2016-Schedule');
$vev->add('TRANSP', 'TRANSPARENT');
}
$vev = $vcalendar->add('VEVENT');
// Summary and description; also resources
$vev->add('SUMMARY', 'EURO 2016 France calendar subscription phasing out');
$vev->add('DESCRIPTION', "**Calendar is going to be deleted on 2016-08-31! Delete your subscription NOW**\n\nHey! Thank you for using my service!\nI hope it was of good use to you.\nWith the EURO being over, I will shut down this service on 2016-08-31\n".
"You should delete the subscription now because I don't know what your device will do once I shut it down.\nCheck out my other projects at https://github.com/kralo/");
// Start-end date
$date = new DateTime();
$vev->add('DTSTART', gmdate('Ymd\T000000\Z', $date->getTimestamp()));
$vev->add('DURATION', 'PT24H00M');
$vev->DTSTAMP = gmdate('Ymd\TGis\Z', (new DateTime())->getTimestamp());
$vev->add('categories', 'EURO2016-Schedule');
$vev->add('TRANSP', 'TRANSPARENT');
echo $vcalendar->serialize();