Completed
Push — master ( e2a702...676958 )
by Yannick
44:36 queued 16:19
created

archive-geojson.php (2 issues)

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
	if ($begindate != '' && $enddate != '') {
118
		$begindate = date('Y-m-d H:i:s',$begindate);
119
		$enddate = date('Y-m-d H:i:s',$enddate);
120
		//$spotter_array = $SpotterArchive->getMinLiveSpotterDataPlayback($begindate,$enddate,$filter);
121
		if ($tracker) {
122
			$spotter_array = $TrackerArchive->getMinLiveTrackerData($begindate,$enddate,$filter);
123
		}
124
		elseif ($marine) {
125
			$spotter_array = $MarineArchive->getMinLiveMarineData($begindate,$enddate,$filter);
126
		}
127
		else {
128
			$spotter_array = $SpotterArchive->getMinLiveSpotterData($begindate,$enddate,$filter);
129
		}
130
	}
131
}
132
133
if (!empty($spotter_array)) {
134
	//$flightcnt = $SpotterArchive->getLiveSpotterCount($begindate,$enddate,$filter);
135
	$flightcnt = 0;
136
	if ($flightcnt == '') $flightcnt = 0;
137
} else $flightcnt = 0;
138
139
$sqltime = round(microtime(true)-$begintime,2);
140
141
$pfi = '';
142
//var_dump($spotter_array);
143
$j = 0;
144
$aircrafts_shadow = array();
145
$output = '{';
146
$output .= '"type": "FeatureCollection",';
147
if ($min) $output .= '"minimal": "true",';
148
else $output .= '"minimal": "false",';
149
$output .= '"fc": "'.$flightcnt.'",';
150
$output .= '"sqt": "'.$sqltime.'",';
151
$begin = true;
152
if (!empty($spotter_array) && is_array($spotter_array)) {
153
	$output .= '"features": [';
154
	foreach($spotter_array as $spotter_item) {
155
		$j++;
156
		date_default_timezone_set('UTC');
157
		if ($tracker) {
158
			if ($pfi != $spotter_item['famtrackid']) {
159
				$pfi = $spotter_item['famtrackid'];
160
				$begin = true;
161
			} else $spotter_history_array = 0;
162
		}
163
		elseif ($marine) {
164
			if ($pfi != $spotter_item['fammarine_d']) {
165
				$pfi = $spotter_item['fammarine_id'];
166
				$begin = true;
167
			} else $spotter_history_array = 0;
168
		}
169
		else {
170
			if ($pfi != $spotter_item['flightaware_id']) {
171
				$pfi = $spotter_item['flightaware_id'];
172
				$begin = true;
173
			}
174
		}
175
		if ($begin) {
176
			if ($j > 1) {
177
				if (isset($output_time)) {
178
					$output_time  = substr($output_time, 0, -1);
179
					$output .= '"time": ['.$output_time.']';
180
				}
181
				$output .= '},';
182
				$output .= '"geometry": {';
183
				//$output .= '"type": "MultiPoint",';
184
				$output .= '"type": "LineString",';
185
				$output .= '"coordinates": [';
186
				if (isset($output_history)) {
187
					$output_history  = substr($output_history, 0, -1);
188
					$output .= $output_history;
189
				}
190
				$output .= ']}},';
191
			}
192
			$pfi = $spotter_item['flightaware_id'];
193
			$output_history = '';
194
			$output_time = '';
195
			$output_timediff = '';
196
			$previousts = 0;
197
			$end = false;
198
			$k = 0;
199
		}
200
201
		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...
202
			$k++;
203
			$output_history .= '['.$spotter_item['longitude'].', '.$spotter_item['latitude'].'],';
204
			$output_time .= (strtotime($spotter_item['date'])*1000).',';
205
			$previousts = strtotime($spotter_item['date']);
206
			if ($k > 1 && (strtotime($spotter_item['date'])*1000 > $enddate)) $end = true;
207
		}
208
209
		if ($begin) {
210
			$begin = false;
211
			//location of aircraft
212
			$output .= '{';
213
			$output .= '"type": "Feature",';
214
			$output .= '"properties": {';
215
			$output .= '"fi": "'.$pfi.'",';
216
			if (isset($begindate)) $output .= '"archive_date": "'.$begindate.'",';
217
			if (isset($spotter_item['ident']) && $spotter_item['ident'] != '') {
218
				$output .= '"c": "'.$spotter_item['ident'].'",';
219
			} else {
220
				$output .= '"c": "NA",';
221
			}
222
			if (!isset($spotter_item['aircraft_shadow']) && !$tracker && !$marine) {
223
				if (!isset($spotter_item['aircraft_icao']) || $spotter_item['aircraft_icao'] == '') $spotter_item['aircraft_shadow'] = '';
224
				else {
225
					$aircraft_icao = $spotter_item['aircraft_icao'];
226
					$aircraft_info = $Spotter->getAllAircraftInfo($spotter_item['aircraft_icao']);
227
					if (count($aircraft_info) > 0) $spotter_item['aircraft_shadow'] = $aircraft_info[0]['aircraft_shadow'];
228
					elseif (isset($spotter_item['format_source']) && $spotter_item['format_source'] == 'aprs') $spotter_item['aircraft_shadow'] = 'PA18.png';
229
					elseif ($aircraft_icao == 'PARAGLIDER') $spotter_item['aircraft_shadow'] = 'PARAGLIDER.png';
230
					else $spotter_item['aircraft_shadow'] = '';
231
					$aircrafts_shadow[$aircraft_icao] = $spotter_item['aircraft_shadow'];
232
				}
233
			}
234
235
			if (!isset($spotter_item['aircraft_shadow']) || $spotter_item['aircraft_shadow'] == '') {
236
				if ($tracker) {
237
					if (isset($spotter_item['type']) && $spotter_item['type'] == 'Ambulance') {
238
						if ($compress) $output .= '"as": "ambulance.png",';
239
						else $output .= '"aircraft_shadow": "ambulance.png",';
240
					}
241
					elseif (isset($spotter_item['type']) && $spotter_item['type'] == 'Police') {
242
						if ($compress) $output .= '"as": "police.png",';
243
						else $output .= '"aircraft_shadow": "police.png",';
244
					}
245
					elseif (isset($spotter_item['type']) && $spotter_item['type'] == 'Yacht (Sail)') {
246
						if ($compress) $output .= '"as": "ship.png",';
247
						else $output .= '"aircraft_shadow": "ship.png",';
248
					}
249
					elseif (isset($spotter_item['type']) && $spotter_item['type'] == 'Ship (Power Boat)') {
250
						if ($compress) $output .= '"as": "ship.png",';
251
						else $output .= '"aircraft_shadow": "ship.png",';
252
					}
253
					elseif (isset($spotter_item['type']) && $spotter_item['type'] == 'Shuttle') {
254
						if ($compress) $output .= '"as": "ship.png",';
255
						else $output .= '"aircraft_shadow": "ship.png",';
256
					}
257
					elseif (isset($spotter_item['type']) && $spotter_item['type'] == 'Truck') {
258
						if ($compress) $output .= '"as": "truck.png",';
259
						else $output .= '"aircraft_shadow": "truck.png",';
260
					}
261
					elseif (isset($spotter_item['type']) && $spotter_item['type'] == 'Truck (18 Wheeler)') {
262
						if ($compress) $output .= '"as": "truck.png",';
263
						else $output .= '"aircraft_shadow": "truck.png",';
264
					}
265
					elseif (isset($spotter_item['type']) && $spotter_item['type'] == 'Aircraft (small)') {
266
						if ($compress) $output .= '"as": "aircraft.png",';
267
						else $output .= '"aircraft_shadow": "aircraft.png",';
268
					}
269
					elseif (isset($spotter_item['type']) && $spotter_item['type'] == 'Large Aircraft') {
270
						if ($compress) $output .= '"as": "aircraft.png",';
271
						else $output .= '"aircraft_shadow": "aircraft.png",';
272
					}
273
					elseif (isset($spotter_item['type']) && $spotter_item['type'] == 'Helicopter') {
274
						if ($compress) $output .= '"as": "helico.png",';
275
						else $output .= '"aircraft_shadow": "helico.png",';
276
					}
277
					elseif (isset($spotter_item['type']) && $spotter_item['type'] == 'Railroad Engine') {
278
						if ($compress) $output .= '"as": "rail.png",';
279
						else $output .= '"aircraft_shadow": "rail.png",';
280
					}
281
					elseif (isset($spotter_item['type']) && $spotter_item['type'] == 'Firetruck') {
282
						if ($compress) $output .= '"as": "firetruck.png",';
283
						else $output .= '"aircraft_shadow": "firetruck.png",';
284
					}
285
					elseif (isset($spotter_item['type']) && $spotter_item['type'] == 'Bus') {
286
						if ($compress) $output .= '"as": "bus.png",';
287
						else $output .= '"aircraft_shadow": "bus.png",';
288
					}
289
					elseif (isset($spotter_item['type']) && $spotter_item['type'] == 'Phone') {
290
						if ($compress) $output .= '"as": "phone.png",';
291
						else $output .= '"aircraft_shadow": "phone.png",';
292
					}
293
					elseif (isset($spotter_item['type']) && $spotter_item['type'] == 'Jogger') {
294
						if ($compress) $output .= '"as": "jogger.png",';
295
						else $output .= '"aircraft_shadow": "jogger.png",';
296
					}
297
					elseif (isset($spotter_item['type']) && $spotter_item['type'] == 'Bike') {
298
						if ($compress) $output .= '"as": "bike.png",';
299
						else $output .= '"aircraft_shadow": "bike.png",';
300
					}
301
					elseif (isset($spotter_item['type']) && $spotter_item['type'] == 'Motorcycle') {
302
						if ($compress) $output .= '"as": "motorcycle.png",';
303
						else $output .= '"aircraft_shadow": "motorcycle.png",';
304
					}
305
					elseif (isset($spotter_item['type']) && $spotter_item['type'] == 'Balloon') {
306
						if ($compress) $output .= '"as": "balloon.png",';
307
						else $output .= '"aircraft_shadow": "balloon.png",';
308
					}
309
					else {
310
						if ($compress) $output .= '"as": "car.png",';
311
						else $output .= '"aircraft_shadow": "car.png",';
312
					}
313
				}
314
				elseif ($marine) {
315
					if ($compress) $output .= '"as": "ship.png",';
316
					else $output .= '"aircraft_shadow": "ship.png",';
317
				}
318
				else {
319
					if ($compress) $output .= '"as": "default.png",';
320
					else $output .= '"aircraft_shadow": "default.png",';
321
				}
322
			} else {
323
				if ($compress) $output .= '"as": "'.$spotter_item['aircraft_shadow'].'",';
324
				else $output .= '"aircraft_shadow": "'.$spotter_item['aircraft_shadow'].'",';
325
			}
326
327
			if (isset($spotter_item['date_iso_8601'])) {
328
				$output .= '"date_update": "'.date("M j, Y, g:i a T", strtotime($spotter_item['date_iso_8601'])).'",';
329
			}
330
			if (isset($spotter_item['date'])) {
331
				$output .= '"lu": "'.strtotime($spotter_item['date']).'",';
332
			}
333
			if (isset($spotter_item['squawk'])) {
334
				$output .= '"sq": "'.$spotter_item['squawk'].'",';
335
			}
336
			if (isset($spotter_item['squawk_usage'])) {
337
				$output .= '"squawk_usage": "'.$spotter_item['squawk_usage'].'",';
338
			}
339
			if (isset($spotter_item['type'])) {
340
				$output .= '"t": "'.$spotter_item['type'].'",';
341
			} elseif ($marine) {
342
				$output .= '"t": "ship",';
343
			} else {
344
				$output .= '"t": "aircraft",';
345
			}
346
		}
347
	}
348
349
	if ($j > 1) {
350
		if (isset($output_time)) {
351
			$output_time  = substr($output_time, 0, -1);
352
			$output .= '"time": ['.$output_time.']';
353
		}
354
		$output .= '},';
355
		$output .= '"geometry": {';
356
		//$output .= '"type": "MultiPoint",';
357
		$output .= '"type": "LineString",';
358
		$output .= '"coordinates": [';
359
		if (isset($output_history)) {
360
			$output_history  = substr($output_history, 0, -1);
361
			$output .= $output_history;
362
		}
363
		$output .= ']';
364
		$output .= '}';
365
		$output .= '},';
366
	}
367
368
	$output  = substr($output, 0, -1);
369
	$output .= ']';
370
	$output .= ',"initial_sqltime": "'.$sqltime.'",';
371
	$output .= '"totaltime": "'.round(microtime(true)-$begintime,2).'",';
372
	if (isset($begindate)) $output .= '"archive_date": "'.$begindate.'",';
373
	$output .= '"fc": "'.$flightcnt.'"';
374
} else {
375
	$output .= '"features": ';
376
	$output .= '{';
377
	$output .= '"type": "Feature",';
378
	$output .= '"properties": {';
379
	$output .= '"fc": "'.$flightcnt.'"}}';
380
}
381
$output .= '}';
382
print $output;
383
384
?>
385