Completed
Push — master ( f7956b...8c6c54 )
by Yannick
43:22 queued 14:24
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
require_once('require/class.Connection.php');
3
require_once('require/class.Common.php');
4
5
if (isset($globalProtect) && $globalProtect) {
6
	@session_start();
7
	if (!isset($_SESSION['protect']) || !isset($_SERVER['HTTP_REFERER'])) {
8
		echo 'You must access this page using the right way.';
9
		die();
10
	}
11
}
12
13
$tracker = false;
14
$marine = false;
15
16
if (isset($_GET['tracker'])) {
17
	$tracker = true;
18
}
19
if (isset($_GET['marine'])) {
20
	$marine = true;
21
}
22
if ($tracker) {
23
	require_once('require/class.Tracker.php');
24
	require_once('require/class.TrackerArchive.php');
25
}
26
elseif ($marine) {
27
	require_once('require/class.Marine.php');
28
	require_once('require/class.MarineArchive.php');
29
}
30
else {
31
	require_once('require/class.Spotter.php');
32
	require_once('require/class.SpotterArchive.php');
33
}
34
$begintime = microtime(true);
35
if ($tracker) {
36
	$Tracker = new Tracker();
37
	$TrackerArchive = new TrackerArchive();
38
}
39
elseif ($marine) {
40
	$Marine = new Marine();
41
	$MarineArchive = new MarineArchive();
42
}
43
else {
44
	$Spotter = new Spotter();
45
	$SpotterArchive = new SpotterArchive();
46
}
47
$Common = new Common();
48
49
if (isset($_GET['download'])) {
50
	if ($_GET['download'] == "true") {
51
		header('Content-disposition: attachment; filename="flightairmap-archive.json"');
52
	}
53
}
54
header('Content-Type: text/javascript');
55
56
if (!isset($globalJsonCompress)) $compress = true;
57
else $compress = $globalJsonCompress;
58
59
$from_archive = false;
60
$min = false;
61
$allhistory = false;
62
$filter['source'] = array();
63
if ((!isset($globalMapVAchoose) || $globalMapVAchoose) && isset($globalVATSIM) && $globalVATSIM && isset($_COOKIE['filter_ShowVATSIM']) && $_COOKIE['filter_ShowVATSIM'] == 'true') $filter['source'] = array_merge($filter['source'],array('vatsimtxt'));
64
if ((!isset($globalMapVAchoose) || $globalMapVAchoose) && isset($globalIVAO) && $globalIVAO && isset($_COOKIE['filter_ShowIVAO']) && $_COOKIE['filter_ShowIVAO'] == 'true') $filter['source'] = array_merge($filter['source'],array('whazzup'));
65
if ((!isset($globalMapVAchoose) || $globalMapVAchoose) && isset($globalphpVMS) && $globalphpVMS && isset($_COOKIE['filter_ShowVMS']) && $_COOKIE['filter_ShowVMS'] == 'true') $filter['source'] = array_merge($filter['source'],array('phpvmacars'));
66
if ((!isset($globalMapchoose) || $globalMapchoose) && isset($globalSBS1) && $globalSBS1 && isset($_COOKIE['filter_ShowSBS1']) && $_COOKIE['filter_ShowSBS1'] == 'true') $filter['source'] = array_merge($filter['source'],array('sbs','famaprs'));
67
if ((!isset($globalMapchoose) || $globalMapchoose) && isset($globalAPRS) && $globalAPRS && isset($_COOKIE['filter_ShowAPRS']) && $_COOKIE['filter_ShowAPRS'] == 'true') $filter['source'] = array_merge($filter['source'],array('aprs'));
68
if (isset($_COOKIE['filter_ident']) && $_COOKIE['filter_ident'] != '') $filter['ident'] = filter_var($_COOKIE['filter_ident'],FILTER_SANITIZE_STRING);
69
if (isset($_COOKIE['filter_mmsi']) && $_COOKIE['filter_mmsi'] != '') $filter['mmsi'] = filter_var($_COOKIE['filter_mmsi'],FILTER_SANITIZE_STRING);
70
if (isset($_COOKIE['filter_Airlines']) && $_COOKIE['filter_Airlines'] != '') $filter['airlines'] = filter_var_array(explode(',',$_COOKIE['filter_Airlines']),FILTER_SANITIZE_STRING);
71
if (isset($_COOKIE['filter_Sources']) && $_COOKIE['filter_Sources'] != '') $filter['source_aprs'] = filter_var_array(explode(',',$_COOKIE['filter_Sources']),FILTER_SANITIZE_STRING);
72
if (isset($_COOKIE['filter_airlinestype']) && $_COOKIE['filter_airlinestype'] != 'all') $filter['airlinestype'] = filter_var($_COOKIE['filter_airlinestype'],FILTER_SANITIZE_STRING);
73
if (isset($_COOKIE['filter_alliance']) && $_COOKIE['filter_alliance'] != 'all') $filter['alliance'] = filter_var($_COOKIE['filter_alliance'],FILTER_SANITIZE_STRING);
74
75
if (isset($globalMapPopup) && !$globalMapPopup && !(isset($_COOKIE['flightpopup']) && $_COOKIE['flightpopup'] == 'true')) {
76
	$min = true;
77
} else $min = false;
78
79
if (isset($_GET['ident'])) {
80
	$ident = filter_input(INPUT_GET,'ident',FILTER_SANITIZE_STRING);
81
	$from_archive = true;
82
	if ($tracker) {
83
		$spotter_array = $TrackerArchive->getLastArchiveTrackerDataByIdent($ident);
84
	}
85
	elseif ($marine) {
86
		$spotter_array = $MarineArchive->getLastArchiveMarineDataByIdent($ident);
87
	}
88
	else {
89
		$spotter_array = $SpotterArchive->getLastArchiveSpotterDataByIdent($ident);
90
	}
91
	$allhistory = true;
92
}
93
elseif (isset($_GET['flightaware_id'])) {
94
	$flightaware_id = filter_input(INPUT_GET,'flightaware_id',FILTER_SANITIZE_STRING);
95
	$from_archive = true;
96
	if ($tracker) {
97
		$spotter_array = $TrackerArchive->getLastArchiveTrackerDataById($flightaware_id);
98
	}
99
	elseif ($marine) {
100
		$spotter_array = $MarineArchive->getLastArchiveMarineDataById($flightaware_id);
101
	}
102
	else {
103
		$spotter_array = $SpotterArchive->getLastArchiveSpotterDataById($flightaware_id);
104
	}
105
	$allhistory = true;
106
}
107
elseif (isset($_GET['archive']) && isset($_GET['begindate']) && isset($_GET['enddate']) && isset($_GET['speed'])) {
108
	$from_archive = true;
109
	$begindate = filter_input(INPUT_GET,'begindate',FILTER_SANITIZE_NUMBER_INT);
110
	if (isset($globalAircraftMaxUpdate)) $begindate = $begindate - $globalAircraftMaxUpdate;
111
	else $begindate = $begindate - 3000;
112
	$enddate = filter_input(INPUT_GET,'enddate',FILTER_SANITIZE_NUMBER_INT);
113
	$archivespeed = filter_input(INPUT_GET,'speed',FILTER_SANITIZE_NUMBER_INT);
114
	if ($begindate != '' && $enddate != '') {
115
		$begindate = date('Y-m-d H:i:s',$begindate);
116
		$enddate = date('Y-m-d H:i:s',$enddate);
117
		//$spotter_array = $SpotterArchive->getMinLiveSpotterDataPlayback($begindate,$enddate,$filter);
118
		if ($tracker) {
119
			$spotter_array = $TrackerArchive->getMinLiveTrackerData($begindate,$enddate,$filter);
120
		}
121
		elseif ($marine) {
122
			$spotter_array = $MarineArchive->getMinLiveMarineData($begindate,$enddate,$filter);
123
		}
124
		else {
125
			$spotter_array = $SpotterArchive->getMinLiveSpotterData($begindate,$enddate,$filter);
126
		}
127
	}
128
}
129
130
if (!empty($spotter_array)) {
131
	//$flightcnt = $SpotterArchive->getLiveSpotterCount($begindate,$enddate,$filter);
132
	$flightcnt = 0;
133
	if ($flightcnt == '') $flightcnt = 0;
134
} else $flightcnt = 0;
135
136
$sqltime = round(microtime(true)-$begintime,2);
137
138
$pfi = '';
139
//var_dump($spotter_array);
140
$j = 0;
141
$aircrafts_shadow = array();
142
$output = '{';
143
$output .= '"type": "FeatureCollection",';
144
if ($min) $output .= '"minimal": "true",';
145
else $output .= '"minimal": "false",';
146
$output .= '"fc": "'.$flightcnt.'",';
147
$output .= '"sqt": "'.$sqltime.'",';
148
$begin = true;
149
if (!empty($spotter_array) && is_array($spotter_array)) {
150
	$output .= '"features": [';
151
	foreach($spotter_array as $spotter_item) {
152
		$j++;
153
		date_default_timezone_set('UTC');
154
		if ($tracker) {
155
			if ($pfi != $spotter_item['famtrackid']) {
156
				$pfi = $spotter_item['famtrackid'];
157
				$begin = true;
158
			} else $spotter_history_array = 0;
159
		}
160
		elseif ($marine) {
161
			if ($pfi != $spotter_item['fammarine_d']) {
162
				$pfi = $spotter_item['fammarine_id'];
163
				$begin = true;
164
			} else $spotter_history_array = 0;
165
		}
166
		else {
167
			if ($pfi != $spotter_item['flightaware_id']) {
168
				$pfi = $spotter_item['flightaware_id'];
169
				$begin = true;
170
			}
171
		}
172
		if ($begin) {
173
			if ($j > 1) {
174
				if (isset($output_time)) {
175
					$output_time  = substr($output_time, 0, -1);
176
					$output .= '"time": ['.$output_time.']';
177
				}
178
				$output .= '},';
179
				$output .= '"geometry": {';
180
				//$output .= '"type": "MultiPoint",';
181
				$output .= '"type": "LineString",';
182
				$output .= '"coordinates": [';
183
				if (isset($output_history)) {
184
					$output_history  = substr($output_history, 0, -1);
185
					$output .= $output_history;
186
				}
187
				$output .= ']}},';
188
			}
189
			$pfi = $spotter_item['flightaware_id'];
190
			$output_history = '';
191
			$output_time = '';
192
			$output_timediff = '';
193
			$previousts = 0;
194
			$end = false;
195
			$k = 0;
196
		}
197
198
		if ($end == false) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
199
			$k++;
200
			$output_history .= '['.$spotter_item['longitude'].', '.$spotter_item['latitude'].'],';
201
			$output_time .= (strtotime($spotter_item['date'])*1000).',';
202
			$previousts = strtotime($spotter_item['date']);
203
			if ($k > 1 && (strtotime($spotter_item['date'])*1000 > $enddate)) $end = true;
204
		}
205
206
		if ($begin) {
207
			$begin = false;
208
			//location of aircraft
209
			$output .= '{';
210
			$output .= '"type": "Feature",';
211
			$output .= '"properties": {';
212
			$output .= '"fi": "'.$pfi.'",';
213
			if (isset($begindate)) $output .= '"archive_date": "'.$begindate.'",';
214
			if (isset($spotter_item['ident']) && $spotter_item['ident'] != '') {
215
				$output .= '"c": "'.$spotter_item['ident'].'",';
216
			} else {
217
				$output .= '"c": "NA",';
218
			}
219
			if (!isset($spotter_item['aircraft_shadow']) && !$tracker && !$marine) {
220
				if (!isset($spotter_item['aircraft_icao']) || $spotter_item['aircraft_icao'] == '') $spotter_item['aircraft_shadow'] = '';
221
				else {
222
					$aircraft_icao = $spotter_item['aircraft_icao'];
223
					$aircraft_info = $Spotter->getAllAircraftInfo($spotter_item['aircraft_icao']);
224
					if (count($aircraft_info) > 0) $spotter_item['aircraft_shadow'] = $aircraft_info[0]['aircraft_shadow'];
225
					elseif (isset($spotter_item['format_source']) && $spotter_item['format_source'] == 'aprs') $spotter_item['aircraft_shadow'] = 'PA18.png';
226
					elseif ($aircraft_icao == 'PARAGLIDER') $spotter_item['aircraft_shadow'] = 'PARAGLIDER.png';
227
					else $spotter_item['aircraft_shadow'] = '';
228
					$aircrafts_shadow[$aircraft_icao] = $spotter_item['aircraft_shadow'];
229
				}
230
			}
231
232
			if (!isset($spotter_item['aircraft_shadow']) || $spotter_item['aircraft_shadow'] == '') {
233
				if ($tracker) {
234
					if (isset($spotter_item['type']) && $spotter_item['type'] == 'Ambulance') {
235
						if ($compress) $output .= '"as": "ambulance.png",';
236
						else $output .= '"aircraft_shadow": "ambulance.png",';
237
					}
238
					elseif (isset($spotter_item['type']) && $spotter_item['type'] == 'Police') {
239
						if ($compress) $output .= '"as": "police.png",';
240
						else $output .= '"aircraft_shadow": "police.png",';
241
					}
242
					elseif (isset($spotter_item['type']) && $spotter_item['type'] == 'Yacht (Sail)') {
243
						if ($compress) $output .= '"as": "ship.png",';
244
						else $output .= '"aircraft_shadow": "ship.png",';
245
					}
246
					elseif (isset($spotter_item['type']) && $spotter_item['type'] == 'Ship (Power Boat)') {
247
						if ($compress) $output .= '"as": "ship.png",';
248
						else $output .= '"aircraft_shadow": "ship.png",';
249
					}
250
					elseif (isset($spotter_item['type']) && $spotter_item['type'] == 'Shuttle') {
251
						if ($compress) $output .= '"as": "ship.png",';
252
						else $output .= '"aircraft_shadow": "ship.png",';
253
					}
254
					elseif (isset($spotter_item['type']) && $spotter_item['type'] == 'Truck') {
255
						if ($compress) $output .= '"as": "truck.png",';
256
						else $output .= '"aircraft_shadow": "truck.png",';
257
					}
258
					elseif (isset($spotter_item['type']) && $spotter_item['type'] == 'Truck (18 Wheeler)') {
259
						if ($compress) $output .= '"as": "truck.png",';
260
						else $output .= '"aircraft_shadow": "truck.png",';
261
					}
262
					elseif (isset($spotter_item['type']) && $spotter_item['type'] == 'Aircraft (small)') {
263
						if ($compress) $output .= '"as": "aircraft.png",';
264
						else $output .= '"aircraft_shadow": "aircraft.png",';
265
					}
266
					elseif (isset($spotter_item['type']) && $spotter_item['type'] == 'Large Aircraft') {
267
						if ($compress) $output .= '"as": "aircraft.png",';
268
						else $output .= '"aircraft_shadow": "aircraft.png",';
269
					}
270
					elseif (isset($spotter_item['type']) && $spotter_item['type'] == 'Helicopter') {
271
						if ($compress) $output .= '"as": "helico.png",';
272
						else $output .= '"aircraft_shadow": "helico.png",';
273
					}
274
					elseif (isset($spotter_item['type']) && $spotter_item['type'] == 'Railroad Engine') {
275
						if ($compress) $output .= '"as": "rail.png",';
276
						else $output .= '"aircraft_shadow": "rail.png",';
277
					}
278
					elseif (isset($spotter_item['type']) && $spotter_item['type'] == 'Firetruck') {
279
						if ($compress) $output .= '"as": "firetruck.png",';
280
						else $output .= '"aircraft_shadow": "firetruck.png",';
281
					}
282
					elseif (isset($spotter_item['type']) && $spotter_item['type'] == 'Bus') {
283
						if ($compress) $output .= '"as": "bus.png",';
284
						else $output .= '"aircraft_shadow": "bus.png",';
285
					}
286
					elseif (isset($spotter_item['type']) && $spotter_item['type'] == 'Phone') {
287
						if ($compress) $output .= '"as": "phone.png",';
288
						else $output .= '"aircraft_shadow": "phone.png",';
289
					}
290
					elseif (isset($spotter_item['type']) && $spotter_item['type'] == 'Jogger') {
291
						if ($compress) $output .= '"as": "jogger.png",';
292
						else $output .= '"aircraft_shadow": "jogger.png",';
293
					}
294
					elseif (isset($spotter_item['type']) && $spotter_item['type'] == 'Bike') {
295
						if ($compress) $output .= '"as": "bike.png",';
296
						else $output .= '"aircraft_shadow": "bike.png",';
297
					}
298
					elseif (isset($spotter_item['type']) && $spotter_item['type'] == 'Motorcycle') {
299
						if ($compress) $output .= '"as": "motorcycle.png",';
300
						else $output .= '"aircraft_shadow": "motorcycle.png",';
301
					}
302
					elseif (isset($spotter_item['type']) && $spotter_item['type'] == 'Balloon') {
303
						if ($compress) $output .= '"as": "balloon.png",';
304
						else $output .= '"aircraft_shadow": "balloon.png",';
305
					}
306
					else {
307
						if ($compress) $output .= '"as": "car.png",';
308
						else $output .= '"aircraft_shadow": "car.png",';
309
					}
310
				}
311
				elseif ($marine) {
312
					if ($compress) $output .= '"as": "ship.png",';
313
					else $output .= '"aircraft_shadow": "ship.png",';
314
				}
315
				else {
316
					if ($compress) $output .= '"as": "default.png",';
317
					else $output .= '"aircraft_shadow": "default.png",';
318
				}
319
			} else {
320
				if ($compress) $output .= '"as": "'.$spotter_item['aircraft_shadow'].'",';
321
				else $output .= '"aircraft_shadow": "'.$spotter_item['aircraft_shadow'].'",';
322
			}
323
324
			if (isset($spotter_item['date_iso_8601'])) {
325
				$output .= '"date_update": "'.date("M j, Y, g:i a T", strtotime($spotter_item['date_iso_8601'])).'",';
326
			}
327
			if (isset($spotter_item['date'])) {
328
				$output .= '"lu": "'.strtotime($spotter_item['date']).'",';
329
			}
330
			if (isset($spotter_item['squawk'])) {
331
				$output .= '"sq": "'.$spotter_item['squawk'].'",';
332
			}
333
			if (isset($spotter_item['squawk_usage'])) {
334
				$output .= '"squawk_usage": "'.$spotter_item['squawk_usage'].'",';
335
			}
336
			if (isset($spotter_item['type'])) {
337
				$output .= '"t": "'.$spotter_item['type'].'",';
338
			} elseif ($marine) {
339
				$output .= '"t": "ship",';
340
			} else {
341
				$output .= '"t": "aircraft",';
342
			}
343
		}
344
	}
345
346
	if ($j > 1) {
347
		if (isset($output_time)) {
348
			$output_time  = substr($output_time, 0, -1);
349
			$output .= '"time": ['.$output_time.']';
350
		}
351
		$output .= '},';
352
		$output .= '"geometry": {';
353
		//$output .= '"type": "MultiPoint",';
354
		$output .= '"type": "LineString",';
355
		$output .= '"coordinates": [';
356
		if (isset($output_history)) {
357
			$output_history  = substr($output_history, 0, -1);
358
			$output .= $output_history;
359
		}
360
		$output .= ']';
361
		$output .= '}';
362
		$output .= '},';
363
	}
364
365
	$output  = substr($output, 0, -1);
366
	$output .= ']';
367
	$output .= ',"initial_sqltime": "'.$sqltime.'",';
368
	$output .= '"totaltime": "'.round(microtime(true)-$begintime,2).'",';
369
	if (isset($begindate)) $output .= '"archive_date": "'.$begindate.'",';
370
	$output .= '"fc": "'.$flightcnt.'"';
371
} else {
372
	$output .= '"features": ';
373
	$output .= '{';
374
	$output .= '"type": "Feature",';
375
	$output .= '"properties": {';
376
	$output .= '"fc": "'.$flightcnt.'"}}';
377
}
378
$output .= '}';
379
print $output;
380
381
?>
382