Completed
Push — master ( 46434e...ad133e )
by Yannick
32:08 queued 16:03
created

archive-geojson.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
// This script can be slow...
3
set_time_limit(0);
4
ini_set('max_execution_time',6000);
5
require_once('require/class.Connection.php');
6
require_once('require/class.Common.php');
7
8
if (isset($globalProtect) && $globalProtect) {
9
	@session_start();
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
10
	if (!isset($_SESSION['protect']) || !isset($_SERVER['HTTP_REFERER'])) {
11
		echo 'You must access this page using the right way.';
12
		die();
13
	}
14
}
15
16
$tracker = false;
17
$marine = false;
18
19
if (isset($_GET['tracker'])) {
20
	$tracker = true;
21
}
22
if (isset($_GET['marine'])) {
23
	$marine = true;
24
}
25
if ($tracker) {
26
	require_once('require/class.Tracker.php');
27
	require_once('require/class.TrackerArchive.php');
28
}
29
elseif ($marine) {
30
	require_once('require/class.Marine.php');
31
	require_once('require/class.MarineArchive.php');
32
}
33
else {
34
	require_once('require/class.Spotter.php');
35
	require_once('require/class.SpotterArchive.php');
36
}
37
$begintime = microtime(true);
38
if ($tracker) {
39
	$Tracker = new Tracker();
40
	$TrackerArchive = new TrackerArchive();
41
}
42
elseif ($marine) {
43
	$Marine = new Marine();
44
	$MarineArchive = new MarineArchive();
45
}
46
else {
47
	$Spotter = new Spotter();
48
	$SpotterArchive = new SpotterArchive();
49
}
50
$Common = new Common();
51
52
if (isset($_GET['download'])) {
53
	if ($_GET['download'] == "true") {
54
		header('Content-disposition: attachment; filename="flightairmap-archive.json"');
55
	}
56
}
57
header('Content-Type: text/javascript');
58
59
if (!isset($globalJsonCompress)) $compress = true;
60
else $compress = $globalJsonCompress;
61
62
$from_archive = false;
63
$min = false;
64
$allhistory = false;
65
$filter['source'] = array();
66
if ((!isset($globalMapVAchoose) || $globalMapVAchoose) && isset($globalVATSIM) && $globalVATSIM && isset($_COOKIE['filter_ShowVATSIM']) && $_COOKIE['filter_ShowVATSIM'] == 'true') $filter['source'] = array_merge($filter['source'],array('vatsimtxt'));
67
if ((!isset($globalMapVAchoose) || $globalMapVAchoose) && isset($globalIVAO) && $globalIVAO && isset($_COOKIE['filter_ShowIVAO']) && $_COOKIE['filter_ShowIVAO'] == 'true') $filter['source'] = array_merge($filter['source'],array('whazzup'));
68
if ((!isset($globalMapVAchoose) || $globalMapVAchoose) && isset($globalphpVMS) && $globalphpVMS && isset($_COOKIE['filter_ShowVMS']) && $_COOKIE['filter_ShowVMS'] == 'true') $filter['source'] = array_merge($filter['source'],array('phpvmacars'));
69
if ((!isset($globalMapchoose) || $globalMapchoose) && isset($globalSBS1) && $globalSBS1 && isset($_COOKIE['filter_ShowSBS1']) && $_COOKIE['filter_ShowSBS1'] == 'true') $filter['source'] = array_merge($filter['source'],array('sbs','famaprs'));
70
if ((!isset($globalMapchoose) || $globalMapchoose) && isset($globalAPRS) && $globalAPRS && isset($_COOKIE['filter_ShowAPRS']) && $_COOKIE['filter_ShowAPRS'] == 'true') $filter['source'] = array_merge($filter['source'],array('aprs'));
71
if (isset($_COOKIE['filter_ident']) && $_COOKIE['filter_ident'] != '') $filter['ident'] = filter_var($_COOKIE['filter_ident'],FILTER_SANITIZE_STRING);
72
if (isset($_COOKIE['filter_mmsi']) && $_COOKIE['filter_mmsi'] != '') $filter['mmsi'] = filter_var($_COOKIE['filter_mmsi'],FILTER_SANITIZE_STRING);
73
if (isset($_COOKIE['filter_Airlines']) && $_COOKIE['filter_Airlines'] != '') $filter['airlines'] = filter_var_array(explode(',',$_COOKIE['filter_Airlines']),FILTER_SANITIZE_STRING);
74
if (isset($_COOKIE['filter_Sources']) && $_COOKIE['filter_Sources'] != '') $filter['source_aprs'] = filter_var_array(explode(',',$_COOKIE['filter_Sources']),FILTER_SANITIZE_STRING);
75
if (isset($_COOKIE['filter_airlinestype']) && $_COOKIE['filter_airlinestype'] != 'all') $filter['airlinestype'] = filter_var($_COOKIE['filter_airlinestype'],FILTER_SANITIZE_STRING);
76
if (isset($_COOKIE['filter_alliance']) && $_COOKIE['filter_alliance'] != 'all') $filter['alliance'] = filter_var($_COOKIE['filter_alliance'],FILTER_SANITIZE_STRING);
77
78
if (isset($globalMapPopup) && !$globalMapPopup && !(isset($_COOKIE['flightpopup']) && $_COOKIE['flightpopup'] == 'true')) {
79
	$min = true;
80
} else $min = false;
81
82
if (isset($_GET['ident'])) {
83
	$ident = filter_input(INPUT_GET,'ident',FILTER_SANITIZE_STRING);
84
	$from_archive = true;
85
	if ($tracker) {
86
		$spotter_array = $TrackerArchive->getLastArchiveTrackerDataByIdent($ident);
87
	}
88
	elseif ($marine) {
89
		$spotter_array = $MarineArchive->getLastArchiveMarineDataByIdent($ident);
90
	}
91
	else {
92
		$spotter_array = $SpotterArchive->getLastArchiveSpotterDataByIdent($ident);
93
	}
94
	$allhistory = true;
95
}
96
elseif (isset($_GET['flightaware_id'])) {
97
	$flightaware_id = filter_input(INPUT_GET,'flightaware_id',FILTER_SANITIZE_STRING);
98
	$from_archive = true;
99
	if ($tracker) {
100
		$spotter_array = $TrackerArchive->getLastArchiveTrackerDataById($flightaware_id);
101
	}
102
	elseif ($marine) {
103
		$spotter_array = $MarineArchive->getLastArchiveMarineDataById($flightaware_id);
104
	}
105
	else {
106
		$spotter_array = $SpotterArchive->getLastArchiveSpotterDataById($flightaware_id);
107
	}
108
	$allhistory = true;
109
}
110
elseif (isset($_GET['archive']) && isset($_GET['begindate']) && isset($_GET['enddate']) && isset($_GET['speed'])) {
111
	$from_archive = true;
112
	$begindate = filter_input(INPUT_GET,'begindate',FILTER_SANITIZE_NUMBER_INT);
113
	if (isset($globalAircraftMaxUpdate)) $begindate = $begindate - $globalAircraftMaxUpdate;
114
	else $begindate = $begindate - 3000;
115
	$enddate = filter_input(INPUT_GET,'enddate',FILTER_SANITIZE_NUMBER_INT);
116
	$archivespeed = filter_input(INPUT_GET,'speed',FILTER_SANITIZE_NUMBER_INT);
117
	$part = filter_input(INPUT_GET,'part',FILTER_SANITIZE_NUMBER_INT);
118
	if ($part == '') $part = 0;
119
	
120
	if ($begindate != '' && $enddate != '') {
121
		$begindate = date('Y-m-d H:i:s',$begindate);
122
		$enddate = date('Y-m-d H:i:s',$enddate);
123
		//$spotter_array = $SpotterArchive->getMinLiveSpotterDataPlayback($begindate,$enddate,$filter);
124
		if ($tracker) {
125
			$spotter_array = $TrackerArchive->getMinLiveTrackerData($begindate,$enddate,$filter);
126
		}
127
		elseif ($marine) {
128
			$spotter_array = $MarineArchive->getMinLiveMarineData($begindate,$enddate,$filter);
129
		}
130
		else {
131
			$spotter_array = $SpotterArchive->getMinLiveSpotterData($begindate,$enddate,$filter,$part);
132
		}
133
	}
134
}
135
136
if (!empty($spotter_array)) {
137
	//$flightcnt = $SpotterArchive->getLiveSpotterCount($begindate,$enddate,$filter);
138
	$flightcnt = 0;
139
	if ($flightcnt == '') $flightcnt = 0;
140
} else $flightcnt = 0;
141
142
$sqltime = round(microtime(true)-$begintime,2);
143
144
$pfi = '';
145
//var_dump($spotter_array);
146
$j = 0;
147
$aircrafts_shadow = array();
148
$output = '{';
149
$output .= '"type": "FeatureCollection",';
150
if ($min) $output .= '"minimal": "true",';
151
else $output .= '"minimal": "false",';
152
$output .= '"fc": "'.$flightcnt.'",';
153
$output .= '"sqt": "'.$sqltime.'",';
154
$begin = true;
155
if (!empty($spotter_array) && is_array($spotter_array)) {
156
	$output .= '"features": [';
157
	foreach($spotter_array as $spotter_item) {
158
		$j++;
159
		date_default_timezone_set('UTC');
160
		if ($tracker) {
161
			if ($pfi != $spotter_item['famtrackid']) {
162
				$pfi = $spotter_item['famtrackid'];
163
				$begin = true;
164
			} else $spotter_history_array = 0;
165
		}
166
		elseif ($marine) {
167
			if ($pfi != $spotter_item['fammarine_d']) {
168
				$pfi = $spotter_item['fammarine_id'];
169
				$begin = true;
170
			} else $spotter_history_array = 0;
171
		}
172
		else {
173
			if ($pfi != $spotter_item['flightaware_id']) {
174
				$pfi = $spotter_item['flightaware_id'];
175
				$begin = true;
176
			}
177
		}
178
		if ($begin) {
179
			if ($j > 1) {
180
				if (isset($output_time)) {
181
					$output_time  = substr($output_time, 0, -1);
182
					$output .= '"time": ['.$output_time.']';
183
				}
184
				$output .= '},';
185
				$output .= '"geometry": {';
186
				//$output .= '"type": "MultiPoint",';
187
				$output .= '"type": "LineString",';
188
				$output .= '"coordinates": [';
189
				if (isset($output_history)) {
190
					$output_history  = substr($output_history, 0, -1);
191
					$output .= $output_history;
192
				}
193
				$output .= ']}},';
194
			}
195
			$pfi = $spotter_item['flightaware_id'];
196
			$output_history = '';
197
			$output_time = '';
198
			$output_timediff = '';
199
			$previousts = 0;
200
			$end = false;
201
			$k = 0;
202
		}
203
204
		if ($end === false) {
205
			$k++;
206
			$output_history .= '['.$spotter_item['longitude'].', '.$spotter_item['latitude'].'],';
207
			$output_time .= (strtotime($spotter_item['date'])*1000).',';
208
			$previousts = strtotime($spotter_item['date']);
209
			if ($k > 1 && (strtotime($spotter_item['date'])*1000 > $enddate)) $end = true;
210
		}
211
212
		if ($begin) {
213
			$begin = false;
214
			//location of aircraft
215
			$output .= '{';
216
			$output .= '"type": "Feature",';
217
			$output .= '"properties": {';
218
			$output .= '"fi": "'.$pfi.'",';
219
			if (isset($begindate)) $output .= '"archive_date": "'.$begindate.'",';
220
			if (isset($spotter_item['ident']) && $spotter_item['ident'] != '') {
221
				$output .= '"c": "'.str_replace('\\','',$spotter_item['ident']).'",';
222
				//"
223
			} else {
224
				$output .= '"c": "NA",';
225
			}
226
			if (!isset($spotter_item['aircraft_shadow']) && !$tracker && !$marine) {
227
				if (!isset($spotter_item['aircraft_icao']) || $spotter_item['aircraft_icao'] == '') $spotter_item['aircraft_shadow'] = '';
228
				else {
229
					$aircraft_icao = $spotter_item['aircraft_icao'];
230
					$aircraft_info = $Spotter->getAllAircraftInfo($spotter_item['aircraft_icao']);
231
					if (count($aircraft_info) > 0) $spotter_item['aircraft_shadow'] = $aircraft_info[0]['aircraft_shadow'];
232
					elseif (isset($spotter_item['format_source']) && $spotter_item['format_source'] == 'aprs') $spotter_item['aircraft_shadow'] = 'PA18.png';
233
					elseif ($aircraft_icao == 'PARAGLIDER') $spotter_item['aircraft_shadow'] = 'PARAGLIDER.png';
234
					else $spotter_item['aircraft_shadow'] = '';
235
					$aircrafts_shadow[$aircraft_icao] = $spotter_item['aircraft_shadow'];
236
				}
237
			}
238
239
			if (!isset($spotter_item['aircraft_shadow']) || $spotter_item['aircraft_shadow'] == '') {
240
				if ($tracker) {
241
					if (isset($spotter_item['type']) && $spotter_item['type'] == 'Ambulance') {
242
						if ($compress) $output .= '"as": "ambulance.png",';
243
						else $output .= '"aircraft_shadow": "ambulance.png",';
244
					}
245
					elseif (isset($spotter_item['type']) && $spotter_item['type'] == 'Police') {
246
						if ($compress) $output .= '"as": "police.png",';
247
						else $output .= '"aircraft_shadow": "police.png",';
248
					}
249
					elseif (isset($spotter_item['type']) && $spotter_item['type'] == 'Yacht (Sail)') {
250
						if ($compress) $output .= '"as": "ship.png",';
251
						else $output .= '"aircraft_shadow": "ship.png",';
252
					}
253
					elseif (isset($spotter_item['type']) && $spotter_item['type'] == 'Ship (Power Boat)') {
254
						if ($compress) $output .= '"as": "ship.png",';
255
						else $output .= '"aircraft_shadow": "ship.png",';
256
					}
257
					elseif (isset($spotter_item['type']) && $spotter_item['type'] == 'Shuttle') {
258
						if ($compress) $output .= '"as": "ship.png",';
259
						else $output .= '"aircraft_shadow": "ship.png",';
260
					}
261
					elseif (isset($spotter_item['type']) && $spotter_item['type'] == 'Truck') {
262
						if ($compress) $output .= '"as": "truck.png",';
263
						else $output .= '"aircraft_shadow": "truck.png",';
264
					}
265
					elseif (isset($spotter_item['type']) && $spotter_item['type'] == 'Truck (18 Wheeler)') {
266
						if ($compress) $output .= '"as": "truck.png",';
267
						else $output .= '"aircraft_shadow": "truck.png",';
268
					}
269
					elseif (isset($spotter_item['type']) && $spotter_item['type'] == 'Aircraft (small)') {
270
						if ($compress) $output .= '"as": "aircraft.png",';
271
						else $output .= '"aircraft_shadow": "aircraft.png",';
272
					}
273
					elseif (isset($spotter_item['type']) && $spotter_item['type'] == 'Large Aircraft') {
274
						if ($compress) $output .= '"as": "aircraft.png",';
275
						else $output .= '"aircraft_shadow": "aircraft.png",';
276
					}
277
					elseif (isset($spotter_item['type']) && $spotter_item['type'] == 'Helicopter') {
278
						if ($compress) $output .= '"as": "helico.png",';
279
						else $output .= '"aircraft_shadow": "helico.png",';
280
					}
281
					elseif (isset($spotter_item['type']) && $spotter_item['type'] == 'Railroad Engine') {
282
						if ($compress) $output .= '"as": "rail.png",';
283
						else $output .= '"aircraft_shadow": "rail.png",';
284
					}
285
					elseif (isset($spotter_item['type']) && $spotter_item['type'] == 'Firetruck') {
286
						if ($compress) $output .= '"as": "firetruck.png",';
287
						else $output .= '"aircraft_shadow": "firetruck.png",';
288
					}
289
					elseif (isset($spotter_item['type']) && $spotter_item['type'] == 'Bus') {
290
						if ($compress) $output .= '"as": "bus.png",';
291
						else $output .= '"aircraft_shadow": "bus.png",';
292
					}
293
					elseif (isset($spotter_item['type']) && $spotter_item['type'] == 'Phone') {
294
						if ($compress) $output .= '"as": "phone.png",';
295
						else $output .= '"aircraft_shadow": "phone.png",';
296
					}
297
					elseif (isset($spotter_item['type']) && $spotter_item['type'] == 'Jogger') {
298
						if ($compress) $output .= '"as": "jogger.png",';
299
						else $output .= '"aircraft_shadow": "jogger.png",';
300
					}
301
					elseif (isset($spotter_item['type']) && $spotter_item['type'] == 'Bike') {
302
						if ($compress) $output .= '"as": "bike.png",';
303
						else $output .= '"aircraft_shadow": "bike.png",';
304
					}
305
					elseif (isset($spotter_item['type']) && $spotter_item['type'] == 'Motorcycle') {
306
						if ($compress) $output .= '"as": "motorcycle.png",';
307
						else $output .= '"aircraft_shadow": "motorcycle.png",';
308
					}
309
					elseif (isset($spotter_item['type']) && $spotter_item['type'] == 'Balloon') {
310
						if ($compress) $output .= '"as": "balloon.png",';
311
						else $output .= '"aircraft_shadow": "balloon.png",';
312
					}
313
					else {
314
						if ($compress) $output .= '"as": "car.png",';
315
						else $output .= '"aircraft_shadow": "car.png",';
316
					}
317
				}
318
				elseif ($marine) {
319
					if ($compress) $output .= '"as": "ship.png",';
320
					else $output .= '"aircraft_shadow": "ship.png",';
321
				}
322
				else {
323
					if ($compress) $output .= '"as": "default.png",';
324
					else $output .= '"aircraft_shadow": "default.png",';
325
				}
326
			} else {
327
				if ($compress) $output .= '"as": "'.$spotter_item['aircraft_shadow'].'",';
328
				else $output .= '"aircraft_shadow": "'.$spotter_item['aircraft_shadow'].'",';
329
			}
330
331
			if (isset($spotter_item['date_iso_8601'])) {
332
				$output .= '"date_update": "'.date("M j, Y, g:i a T", strtotime($spotter_item['date_iso_8601'])).'",';
333
			}
334
			if (isset($spotter_item['date'])) {
335
				$output .= '"lu": "'.strtotime($spotter_item['date']).'",';
336
			}
337
			if (isset($spotter_item['squawk'])) {
338
				$output .= '"sq": "'.$spotter_item['squawk'].'",';
339
			}
340
			if (isset($spotter_item['squawk_usage'])) {
341
				$output .= '"squawk_usage": "'.$spotter_item['squawk_usage'].'",';
342
			}
343
			if (isset($spotter_item['type'])) {
344
				$output .= '"t": "'.$spotter_item['type'].'",';
345
			} elseif ($marine) {
346
				$output .= '"t": "ship",';
347
			} else {
348
				$output .= '"t": "aircraft",';
349
			}
350
		}
351
	}
352
353
	if ($j > 1) {
354
		if (isset($output_time)) {
355
			$output_time  = substr($output_time, 0, -1);
356
			$output .= '"time": ['.$output_time.']';
357
		}
358
		$output .= '},';
359
		$output .= '"geometry": {';
360
		//$output .= '"type": "MultiPoint",';
361
		$output .= '"type": "LineString",';
362
		$output .= '"coordinates": [';
363
		if (isset($output_history)) {
364
			$output_history  = substr($output_history, 0, -1);
365
			$output .= $output_history;
366
		}
367
		$output .= ']';
368
		$output .= '}';
369
		$output .= '},';
370
	}
371
372
	$output  = substr($output, 0, -1);
373
	$output .= ']';
374
	$output .= ',"initial_sqltime": "'.$sqltime.'",';
375
	$output .= '"totaltime": "'.round(microtime(true)-$begintime,2).'",';
376
	if (isset($begindate)) $output .= '"archive_date": "'.$begindate.'",';
377
	$output .= '"fc": "'.$flightcnt.'"';
378
} else {
379
	$output .= '"features": ';
380
	$output .= '{';
381
	$output .= '"type": "Feature",';
382
	$output .= '"properties": {';
383
	$output .= '"fc": "'.$flightcnt.'"}}';
384
}
385
$output .= '}';
386
print $output;
387
388
?>
389