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