forked from Ysurac/FlightAirMap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
archive-geojson.php
388 lines (369 loc) · 15.1 KB
/
archive-geojson.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
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
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
<?php
// This script can be slow...
set_time_limit(0);
ini_set('max_execution_time',6000);
require_once('require/class.Connection.php');
require_once('require/class.Common.php');
if (isset($globalProtect) && $globalProtect) {
@session_start();
if (!isset($_SESSION['protect']) || !isset($_SERVER['HTTP_REFERER'])) {
echo 'You must access this page using the right way.';
die();
}
}
$tracker = false;
$marine = false;
if (isset($_GET['tracker'])) {
$tracker = true;
}
if (isset($_GET['marine'])) {
$marine = true;
}
if ($tracker) {
require_once('require/class.Tracker.php');
require_once('require/class.TrackerArchive.php');
}
elseif ($marine) {
require_once('require/class.Marine.php');
require_once('require/class.MarineArchive.php');
}
else {
require_once('require/class.Spotter.php');
require_once('require/class.SpotterArchive.php');
}
$begintime = microtime(true);
if ($tracker) {
$Tracker = new Tracker();
$TrackerArchive = new TrackerArchive();
}
elseif ($marine) {
$Marine = new Marine();
$MarineArchive = new MarineArchive();
}
else {
$Spotter = new Spotter();
$SpotterArchive = new SpotterArchive();
}
$Common = new Common();
if (isset($_GET['download'])) {
if ($_GET['download'] == "true") {
header('Content-disposition: attachment; filename="flightairmap-archive.json"');
}
}
header('Content-Type: text/javascript');
if (!isset($globalJsonCompress)) $compress = true;
else $compress = $globalJsonCompress;
$from_archive = false;
$min = false;
$allhistory = false;
$filter['source'] = array();
if ((!isset($globalMapVAchoose) || $globalMapVAchoose) && isset($globalVATSIM) && $globalVATSIM && isset($_COOKIE['filter_ShowVATSIM']) && $_COOKIE['filter_ShowVATSIM'] == 'true') $filter['source'] = array_merge($filter['source'],array('vatsimtxt'));
if ((!isset($globalMapVAchoose) || $globalMapVAchoose) && isset($globalIVAO) && $globalIVAO && isset($_COOKIE['filter_ShowIVAO']) && $_COOKIE['filter_ShowIVAO'] == 'true') $filter['source'] = array_merge($filter['source'],array('whazzup'));
if ((!isset($globalMapVAchoose) || $globalMapVAchoose) && isset($globalphpVMS) && $globalphpVMS && isset($_COOKIE['filter_ShowVMS']) && $_COOKIE['filter_ShowVMS'] == 'true') $filter['source'] = array_merge($filter['source'],array('phpvmacars'));
if ((!isset($globalMapchoose) || $globalMapchoose) && isset($globalSBS1) && $globalSBS1 && isset($_COOKIE['filter_ShowSBS1']) && $_COOKIE['filter_ShowSBS1'] == 'true') $filter['source'] = array_merge($filter['source'],array('sbs','famaprs'));
if ((!isset($globalMapchoose) || $globalMapchoose) && isset($globalAPRS) && $globalAPRS && isset($_COOKIE['filter_ShowAPRS']) && $_COOKIE['filter_ShowAPRS'] == 'true') $filter['source'] = array_merge($filter['source'],array('aprs'));
if (isset($_COOKIE['filter_ident']) && $_COOKIE['filter_ident'] != '') $filter['ident'] = filter_var($_COOKIE['filter_ident'],FILTER_SANITIZE_STRING);
if (isset($_COOKIE['filter_mmsi']) && $_COOKIE['filter_mmsi'] != '') $filter['mmsi'] = filter_var($_COOKIE['filter_mmsi'],FILTER_SANITIZE_STRING);
if (isset($_COOKIE['filter_Airlines']) && $_COOKIE['filter_Airlines'] != '') $filter['airlines'] = filter_var_array(explode(',',$_COOKIE['filter_Airlines']),FILTER_SANITIZE_STRING);
if (isset($_COOKIE['filter_Sources']) && $_COOKIE['filter_Sources'] != '') $filter['source_aprs'] = filter_var_array(explode(',',$_COOKIE['filter_Sources']),FILTER_SANITIZE_STRING);
if (isset($_COOKIE['filter_airlinestype']) && $_COOKIE['filter_airlinestype'] != 'all') $filter['airlinestype'] = filter_var($_COOKIE['filter_airlinestype'],FILTER_SANITIZE_STRING);
if (isset($_COOKIE['filter_alliance']) && $_COOKIE['filter_alliance'] != 'all') $filter['alliance'] = filter_var($_COOKIE['filter_alliance'],FILTER_SANITIZE_STRING);
if (isset($globalMapPopup) && !$globalMapPopup && !(isset($_COOKIE['flightpopup']) && $_COOKIE['flightpopup'] == 'true')) {
$min = true;
} else $min = false;
if (isset($_GET['ident'])) {
$ident = filter_input(INPUT_GET,'ident',FILTER_SANITIZE_STRING);
$from_archive = true;
if ($tracker) {
$spotter_array = $TrackerArchive->getLastArchiveTrackerDataByIdent($ident);
}
elseif ($marine) {
$spotter_array = $MarineArchive->getLastArchiveMarineDataByIdent($ident);
}
else {
$spotter_array = $SpotterArchive->getLastArchiveSpotterDataByIdent($ident);
}
$allhistory = true;
}
elseif (isset($_GET['flightaware_id'])) {
$flightaware_id = filter_input(INPUT_GET,'flightaware_id',FILTER_SANITIZE_STRING);
$from_archive = true;
if ($tracker) {
$spotter_array = $TrackerArchive->getLastArchiveTrackerDataById($flightaware_id);
}
elseif ($marine) {
$spotter_array = $MarineArchive->getLastArchiveMarineDataById($flightaware_id);
}
else {
$spotter_array = $SpotterArchive->getLastArchiveSpotterDataById($flightaware_id);
}
$allhistory = true;
}
elseif (isset($_GET['archive']) && isset($_GET['begindate']) && isset($_GET['enddate']) && isset($_GET['speed'])) {
$from_archive = true;
$begindate = filter_input(INPUT_GET,'begindate',FILTER_SANITIZE_NUMBER_INT);
if (isset($globalAircraftMaxUpdate)) $begindate = $begindate - $globalAircraftMaxUpdate;
else $begindate = $begindate - 3000;
$enddate = filter_input(INPUT_GET,'enddate',FILTER_SANITIZE_NUMBER_INT);
$archivespeed = filter_input(INPUT_GET,'speed',FILTER_SANITIZE_NUMBER_INT);
$part = filter_input(INPUT_GET,'part',FILTER_SANITIZE_NUMBER_INT);
if ($part == '') $part = 0;
if ($begindate != '' && $enddate != '') {
$begindate = date('Y-m-d H:i:s',$begindate);
$enddate = date('Y-m-d H:i:s',$enddate);
//$spotter_array = $SpotterArchive->getMinLiveSpotterDataPlayback($begindate,$enddate,$filter);
if ($tracker) {
$spotter_array = $TrackerArchive->getMinLiveTrackerData($begindate,$enddate,$filter);
}
elseif ($marine) {
$spotter_array = $MarineArchive->getMinLiveMarineData($begindate,$enddate,$filter);
}
else {
$spotter_array = $SpotterArchive->getMinLiveSpotterData($begindate,$enddate,$filter,$part);
}
}
}
if (!empty($spotter_array)) {
//$flightcnt = $SpotterArchive->getLiveSpotterCount($begindate,$enddate,$filter);
$flightcnt = 0;
if ($flightcnt == '') $flightcnt = 0;
} else $flightcnt = 0;
$sqltime = round(microtime(true)-$begintime,2);
$pfi = '';
//var_dump($spotter_array);
$j = 0;
$aircrafts_shadow = array();
$output = '{';
$output .= '"type": "FeatureCollection",';
if ($min) $output .= '"minimal": "true",';
else $output .= '"minimal": "false",';
$output .= '"fc": "'.$flightcnt.'",';
$output .= '"sqt": "'.$sqltime.'",';
$begin = true;
if (!empty($spotter_array) && is_array($spotter_array)) {
$output .= '"features": [';
foreach($spotter_array as $spotter_item) {
$j++;
date_default_timezone_set('UTC');
if ($tracker) {
if ($pfi != $spotter_item['famtrackid']) {
$pfi = $spotter_item['famtrackid'];
$begin = true;
} else $spotter_history_array = 0;
}
elseif ($marine) {
if ($pfi != $spotter_item['fammarine_d']) {
$pfi = $spotter_item['fammarine_id'];
$begin = true;
} else $spotter_history_array = 0;
}
else {
if ($pfi != $spotter_item['flightaware_id']) {
$pfi = $spotter_item['flightaware_id'];
$begin = true;
}
}
if ($begin) {
if ($j > 1) {
if (isset($output_time)) {
$output_time = substr($output_time, 0, -1);
$output .= '"time": ['.$output_time.']';
}
$output .= '},';
$output .= '"geometry": {';
//$output .= '"type": "MultiPoint",';
$output .= '"type": "LineString",';
$output .= '"coordinates": [';
if (isset($output_history)) {
$output_history = substr($output_history, 0, -1);
$output .= $output_history;
}
$output .= ']}},';
}
$pfi = $spotter_item['flightaware_id'];
$output_history = '';
$output_time = '';
$output_timediff = '';
$previousts = 0;
$end = false;
$k = 0;
}
if ($end === false) {
$k++;
$output_history .= '['.$spotter_item['longitude'].', '.$spotter_item['latitude'].'],';
$output_time .= (strtotime($spotter_item['date'])*1000).',';
$previousts = strtotime($spotter_item['date']);
if ($k > 1 && (strtotime($spotter_item['date'])*1000 > $enddate)) $end = true;
}
if ($begin) {
$begin = false;
//location of aircraft
$output .= '{';
$output .= '"type": "Feature",';
$output .= '"properties": {';
$output .= '"fi": "'.$pfi.'",';
if (isset($begindate)) $output .= '"archive_date": "'.$begindate.'",';
if (isset($spotter_item['ident']) && $spotter_item['ident'] != '') {
$output .= '"c": "'.str_replace('\\','',$spotter_item['ident']).'",';
//"
} else {
$output .= '"c": "NA",';
}
if (!isset($spotter_item['aircraft_shadow']) && !$tracker && !$marine) {
if (!isset($spotter_item['aircraft_icao']) || $spotter_item['aircraft_icao'] == '') $spotter_item['aircraft_shadow'] = '';
else {
$aircraft_icao = $spotter_item['aircraft_icao'];
$aircraft_info = $Spotter->getAllAircraftInfo($spotter_item['aircraft_icao']);
if (count($aircraft_info) > 0) $spotter_item['aircraft_shadow'] = $aircraft_info[0]['aircraft_shadow'];
elseif (isset($spotter_item['format_source']) && $spotter_item['format_source'] == 'aprs') $spotter_item['aircraft_shadow'] = 'PA18.png';
elseif ($aircraft_icao == 'PARAGLIDER') $spotter_item['aircraft_shadow'] = 'PARAGLIDER.png';
else $spotter_item['aircraft_shadow'] = '';
$aircrafts_shadow[$aircraft_icao] = $spotter_item['aircraft_shadow'];
}
}
if (!isset($spotter_item['aircraft_shadow']) || $spotter_item['aircraft_shadow'] == '') {
if ($tracker) {
if (isset($spotter_item['type']) && $spotter_item['type'] == 'Ambulance') {
if ($compress) $output .= '"as": "ambulance.png",';
else $output .= '"aircraft_shadow": "ambulance.png",';
}
elseif (isset($spotter_item['type']) && $spotter_item['type'] == 'Police') {
if ($compress) $output .= '"as": "police.png",';
else $output .= '"aircraft_shadow": "police.png",';
}
elseif (isset($spotter_item['type']) && $spotter_item['type'] == 'Yacht (Sail)') {
if ($compress) $output .= '"as": "ship.png",';
else $output .= '"aircraft_shadow": "ship.png",';
}
elseif (isset($spotter_item['type']) && $spotter_item['type'] == 'Ship (Power Boat)') {
if ($compress) $output .= '"as": "ship.png",';
else $output .= '"aircraft_shadow": "ship.png",';
}
elseif (isset($spotter_item['type']) && $spotter_item['type'] == 'Shuttle') {
if ($compress) $output .= '"as": "ship.png",';
else $output .= '"aircraft_shadow": "ship.png",';
}
elseif (isset($spotter_item['type']) && $spotter_item['type'] == 'Truck') {
if ($compress) $output .= '"as": "truck.png",';
else $output .= '"aircraft_shadow": "truck.png",';
}
elseif (isset($spotter_item['type']) && $spotter_item['type'] == 'Truck (18 Wheeler)') {
if ($compress) $output .= '"as": "truck.png",';
else $output .= '"aircraft_shadow": "truck.png",';
}
elseif (isset($spotter_item['type']) && $spotter_item['type'] == 'Aircraft (small)') {
if ($compress) $output .= '"as": "aircraft.png",';
else $output .= '"aircraft_shadow": "aircraft.png",';
}
elseif (isset($spotter_item['type']) && $spotter_item['type'] == 'Large Aircraft') {
if ($compress) $output .= '"as": "aircraft.png",';
else $output .= '"aircraft_shadow": "aircraft.png",';
}
elseif (isset($spotter_item['type']) && $spotter_item['type'] == 'Helicopter') {
if ($compress) $output .= '"as": "helico.png",';
else $output .= '"aircraft_shadow": "helico.png",';
}
elseif (isset($spotter_item['type']) && $spotter_item['type'] == 'Railroad Engine') {
if ($compress) $output .= '"as": "rail.png",';
else $output .= '"aircraft_shadow": "rail.png",';
}
elseif (isset($spotter_item['type']) && $spotter_item['type'] == 'Firetruck') {
if ($compress) $output .= '"as": "firetruck.png",';
else $output .= '"aircraft_shadow": "firetruck.png",';
}
elseif (isset($spotter_item['type']) && $spotter_item['type'] == 'Bus') {
if ($compress) $output .= '"as": "bus.png",';
else $output .= '"aircraft_shadow": "bus.png",';
}
elseif (isset($spotter_item['type']) && $spotter_item['type'] == 'Phone') {
if ($compress) $output .= '"as": "phone.png",';
else $output .= '"aircraft_shadow": "phone.png",';
}
elseif (isset($spotter_item['type']) && $spotter_item['type'] == 'Jogger') {
if ($compress) $output .= '"as": "jogger.png",';
else $output .= '"aircraft_shadow": "jogger.png",';
}
elseif (isset($spotter_item['type']) && $spotter_item['type'] == 'Bike') {
if ($compress) $output .= '"as": "bike.png",';
else $output .= '"aircraft_shadow": "bike.png",';
}
elseif (isset($spotter_item['type']) && $spotter_item['type'] == 'Motorcycle') {
if ($compress) $output .= '"as": "motorcycle.png",';
else $output .= '"aircraft_shadow": "motorcycle.png",';
}
elseif (isset($spotter_item['type']) && $spotter_item['type'] == 'Balloon') {
if ($compress) $output .= '"as": "balloon.png",';
else $output .= '"aircraft_shadow": "balloon.png",';
}
else {
if ($compress) $output .= '"as": "car.png",';
else $output .= '"aircraft_shadow": "car.png",';
}
}
elseif ($marine) {
if ($compress) $output .= '"as": "ship.png",';
else $output .= '"aircraft_shadow": "ship.png",';
}
else {
if ($compress) $output .= '"as": "default.png",';
else $output .= '"aircraft_shadow": "default.png",';
}
} else {
if ($compress) $output .= '"as": "'.$spotter_item['aircraft_shadow'].'",';
else $output .= '"aircraft_shadow": "'.$spotter_item['aircraft_shadow'].'",';
}
if (isset($spotter_item['date_iso_8601'])) {
$output .= '"date_update": "'.date("M j, Y, g:i a T", strtotime($spotter_item['date_iso_8601'])).'",';
}
if (isset($spotter_item['date'])) {
$output .= '"lu": "'.strtotime($spotter_item['date']).'",';
}
if (isset($spotter_item['squawk'])) {
$output .= '"sq": "'.$spotter_item['squawk'].'",';
}
if (isset($spotter_item['squawk_usage'])) {
$output .= '"squawk_usage": "'.$spotter_item['squawk_usage'].'",';
}
if (isset($spotter_item['type'])) {
$output .= '"t": "'.$spotter_item['type'].'",';
} elseif ($marine) {
$output .= '"t": "ship",';
} else {
$output .= '"t": "aircraft",';
}
}
}
if ($j > 1) {
if (isset($output_time)) {
$output_time = substr($output_time, 0, -1);
$output .= '"time": ['.$output_time.']';
}
$output .= '},';
$output .= '"geometry": {';
//$output .= '"type": "MultiPoint",';
$output .= '"type": "LineString",';
$output .= '"coordinates": [';
if (isset($output_history)) {
$output_history = substr($output_history, 0, -1);
$output .= $output_history;
}
$output .= ']';
$output .= '}';
$output .= '},';
}
$output = substr($output, 0, -1);
$output .= ']';
$output .= ',"initial_sqltime": "'.$sqltime.'",';
$output .= '"totaltime": "'.round(microtime(true)-$begintime,2).'",';
if (isset($begindate)) $output .= '"archive_date": "'.$begindate.'",';
$output .= '"fc": "'.$flightcnt.'"';
} else {
$output .= '"features": ';
$output .= '{';
$output .= '"type": "Feature",';
$output .= '"properties": {';
$output .= '"fc": "'.$flightcnt.'"}}';
}
$output .= '}';
print $output;
?>