Completed
Push — master ( b184e5...56e07e )
by Yannick
27:11
created

live-geojson.php (3 issues)

Severity

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
$tracker = false;
5
$marine = false;
6
$usecoord = false;
7
if (isset($_GET['tracker'])) {
8
    $tracker = true;
9
}
10
if (isset($_GET['marine'])) {
11
    $marine = true;
12
}
13
if ($tracker) {
14
    require_once('require/class.Tracker.php');
15
    require_once('require/class.TrackerLive.php');
16
    require_once('require/class.TrackerArchive.php');
17
} elseif ($marine) {
18
    require_once('require/class.Marine.php');
19
    require_once('require/class.MarineLive.php');
20
    require_once('require/class.MarineArchive.php');
21
} else {
22
    require_once('require/class.Spotter.php');
23
    require_once('require/class.SpotterLive.php');
24
    require_once('require/class.SpotterArchive.php');
25
}
26
27
$begintime = microtime(true);
28
if ($tracker) {
29
	$TrackerLive = new TrackerLive();
30
	$Tracker = new Tracker();
31
	$TrackerArchive = new TrackerArchive();
32
} elseif ($marine) {
33
	$MarineLive = new MarineLive();
34
	$Marine = new Marine();
35
	$MarineArchive = new MarineArchive();
36
} else {
37
	$SpotterLive = new SpotterLive();
38
	$Spotter = new Spotter();
39
	$SpotterArchive = new SpotterArchive();
40
}
41
$Common = new Common();
42
43
if (isset($_GET['download'])) {
44
    if ($_GET['download'] == "true")
45
    {
46
	header('Content-disposition: attachment; filename="flightairmap.json"');
47
    }
48
}
49
header('Content-Type: text/javascript');
50
51
if (!isset($globalJsonCompress)) $compress = true;
52
else $compress = $globalJsonCompress;
53
54
$from_archive = false;
55
$min = true;
56
$allhistory = false;
57
$filter['source'] = array();
58
if ((!isset($globalMapVAchoose) || $globalMapVAchoose) && isset($globalVATSIM) && $globalVATSIM && isset($_COOKIE['filter_ShowVATSIM']) && $_COOKIE['filter_ShowVATSIM'] == 'true') $filter['source'] = array_merge($filter['source'],array('vatsimtxt'));
59
if ((!isset($globalMapVAchoose) || $globalMapVAchoose) && isset($globalIVAO) && $globalIVAO && isset($_COOKIE['filter_ShowIVAO']) && $_COOKIE['filter_ShowIVAO'] == 'true') $filter['source'] = array_merge($filter['source'],array('whazzup'));
60
if ((!isset($globalMapVAchoose) || $globalMapVAchoose) && isset($globalphpVMS) && $globalphpVMS && isset($_COOKIE['filter_ShowVMS']) && $_COOKIE['filter_ShowVMS'] == 'true') $filter['source'] = array_merge($filter['source'],array('phpvmacars'));
61
if ((!isset($globalMapchoose) || $globalMapchoose) && isset($globalSBS1) && $globalSBS1 && isset($_COOKIE['filter_ShowSBS1']) && $_COOKIE['filter_ShowSBS1'] == 'true') $filter['source'] = array_merge($filter['source'],array('sbs','famaprs'));
62
if ((!isset($globalMapchoose) || $globalMapchoose) && isset($globalAPRS) && $globalAPRS && isset($_COOKIE['filter_ShowAPRS']) && $_COOKIE['filter_ShowAPRS'] == 'true') $filter['source'] = array_merge($filter['source'],array('aprs'));
63
if (isset($_COOKIE['filter_ident']) && $_COOKIE['filter_ident'] != '') $filter['ident'] = filter_var($_COOKIE['filter_ident'],FILTER_SANITIZE_STRING);
64
if (isset($_COOKIE['filter_Airlines']) && $_COOKIE['filter_Airlines'] != '') $filter['airlines'] = filter_var_array(explode(',',$_COOKIE['filter_Airlines']),FILTER_SANITIZE_STRING);
65
if (isset($_COOKIE['filter_Sources']) && $_COOKIE['filter_Sources'] != '') $filter['source_aprs'] = filter_var_array(explode(',',$_COOKIE['filter_Sources']),FILTER_SANITIZE_STRING);
66
if (isset($_COOKIE['filter_airlinestype']) && $_COOKIE['filter_airlinestype'] != 'all') $filter['airlinestype'] = filter_var($_COOKIE['filter_airlinestype'],FILTER_SANITIZE_STRING);
67
if (isset($_COOKIE['filter_alliance']) && $_COOKIE['filter_alliance'] != 'all') $filter['alliance'] = filter_var($_COOKIE['filter_alliance'],FILTER_SANITIZE_STRING);
68
69
if (isset($globalMapPopup) && !$globalMapPopup && !(isset($_COOKIE['flightpopup']) && $_COOKIE['flightpopup'] == 'true')) {
70
	$min = true;
71
} else $min = false;
72
73
if (isset($_GET['ident'])) {
74
	$ident = urldecode(filter_input(INPUT_GET,'ident',FILTER_SANITIZE_STRING));
75
	if ($tracker) {
76
		$spotter_array = $TrackerLive->getLastLiveTrackerDataByIdent($ident);
77
	} elseif ($marine) {
78
		$spotter_array = $MarineLive->getLastLiveMarineDataByIdent($ident);
79
	} else {
80
		$spotter_array = $SpotterLive->getLastLiveSpotterDataByIdent($ident);
81
		if (empty($spotter_array)) {
82
			$from_archive = true;
83
			$spotter_array = $SpotterArchive->getLastArchiveSpotterDataByIdent($ident);
84
		}
85
	}
86
	$allhistory = true;
87
} elseif (isset($_GET['flightaware_id'])) {
88
	$flightaware_id = filter_input(INPUT_GET,'flightaware_id',FILTER_SANITIZE_STRING);
89
	$spotter_array = $SpotterLive->getLastLiveSpotterDataById($flightaware_id);
90
	if (empty($spotter_array)) {
91
		$from_archive = true;
92
		$spotter_array = $SpotterArchive->getLastArchiveSpotterDataById($flightaware_id);
93
	}
94
	$allhistory = true;
95
} elseif (isset($_GET['famtrack_id'])) {
96
	$famtrack_id = urldecode(filter_input(INPUT_GET,'famtrack_id',FILTER_SANITIZE_STRING));
97
	$spotter_array = $TrackerLive->getLastLiveTrackerDataById($famtrack_id);
98
	$allhistory = true;
99
} elseif (isset($_GET['fammarine_id'])) {
100
	$fammarine_id = urldecode(filter_input(INPUT_GET,'fammarine_id',FILTER_SANITIZE_STRING));
101
	$spotter_array = $MarineLive->getLastLiveMarineDataById($fammarine_id);
102
	$allhistory = true;
103
} elseif (isset($globalMapUseBbox) && $globalMapUseBbox && isset($_GET['coord']) && (!isset($globalMapPopup) || $globalMapPopup || (isset($_COOKIE['flightpopup']) && $_COOKIE['flightpopup'] == 'true'))) {
104
//} elseif (isset($_GET['coord'])) {
105
	$usecoord = true;
106
	$coord = explode(',',$_GET['coord']);
107
	if ($tracker) {
108
		$spotter_array = $TrackerLive->getLiveTrackerDatabyCoord($coord,$filter);
109
	} elseif ($marine) {
110
		$spotter_array = $MarineLive->getLiveMarineDatabyCoord($coord,$filter);
111
	} else {
112
		$spotter_array = $SpotterLive->getLiveSpotterDatabyCoord($coord,$filter);
113
	}
114
} elseif (isset($globalMapUseBbox) && $globalMapUseBbox && isset($_GET['coord']) && $min) {
115
	$usecoord = true;
116
	$coord = explode(',',$_GET['coord']);
117
	if ($tracker) {
118
		$spotter_array = $TrackerLive->getMinLiveTrackerDatabyCoord($coord,$filter);
119
	} elseif ($marine) {
120
		$spotter_array = $MarineLive->getMinLiveMarineDatabyCoord($coord,$filter);
121
	} else {
122
		$spotter_array = $SpotterLive->getMinLiveSpotterDatabyCoord($coord,$filter);
123
	}
124
} elseif (isset($_GET['archive']) && isset($_GET['begindate']) && isset($_GET['enddate']) && isset($_GET['speed']) && !isset($_GET['tracker']) && !isset($_GET['marine'])) {
125
	$from_archive = true;
126
//	$begindate = filter_input(INPUT_GET,'begindate',FILTER_VALIDATE_REGEXP,array("options"=>array("regexp"=>'~^\d{4}/\d{2}/\d{2}$~')));
127
//	$enddate = filter_input(INPUT_GET,'enddate',FILTER_VALIDATE_REGEXP,array("options"=>array("regexp"=>'~^\d{4}/\d{2}/\d{2}$~')));
128
	$begindate = filter_input(INPUT_GET,'begindate',FILTER_SANITIZE_NUMBER_INT);
129
	$enddate = filter_input(INPUT_GET,'enddate',FILTER_SANITIZE_NUMBER_INT);
130
	$archivespeed = filter_input(INPUT_GET,'speed',FILTER_SANITIZE_NUMBER_INT);
131
	$begindate = date('Y-m-d H:i:s',$begindate);
132
	$enddate = date('Y-m-d H:i:s',$enddate);
133
	$spotter_array = $SpotterArchive->getMinLiveSpotterData($begindate,$enddate,$filter);
134
} elseif ($min) {
135
	if ($tracker) {
136
		$spotter_array = $TrackerLive->getMinLiveTrackerData($filter);
137
	} elseif ($marine) {
138
		$spotter_array = $MarineLive->getMinLiveMarineData($filter);
139
	} else {
140
		$spotter_array = $SpotterLive->getMinLiveSpotterData($filter);
141
	}
142
#	$min = true;
143
} else {
144
	if ($tracker) {
145
		$spotter_array = $TrackerLive->getLiveTrackerData('','',$filter);
146
	} elseif ($marine) {
147
		$spotter_array = $marineLive->getLiveMarineData('','',$filter);
148
	} else {
149
		$spotter_array = $SpotterLive->getLiveSpotterData('','',$filter);
150
	}
151
}
152
153
if ($usecoord) {
154
	if (isset($_GET['archive'])) {
155
		$flightcnt = $SpotterArchive->getLiveSpotterCount($begindate,$enddate,$filter);
156
	} else {
157
		if ($tracker) {
158
			$flightcnt = $TrackerLive->getLiveTrackerCount($filter);
159
		} elseif ($marine) {
160
			$flightcnt = $MarineLive->getLiveMarineCount($filter);
161
		} else {
162
			$flightcnt = $SpotterLive->getLiveSpotterCount($filter);
163
		}
164
	}
165
	if ($flightcnt == '') $flightcnt = 0;
166
} else $flightcnt = 0;
167
168
$sqltime = round(microtime(true)-$begintime,2);
169
170
$currenttime = filter_input(INPUT_GET,'currenttime',FILTER_SANITIZE_NUMBER_INT);
171
if ($currenttime != '') $currenttime = round($currenttime/1000);
172
173
if ((!isset($_COOKIE['flightestimation']) && isset($globalMapEstimation) && $globalMapEstimation == FALSE) || (isset($_COOKIE['flightestimation']) && $_COOKIE['flightestimation'] == 'false')) $usenextlatlon = false;
174
else $usenextlatlon = true;
175
if ($usenextlatlon === false) $currenttime = '';
176
$j = 0;
177
$prev_flightaware_id = '';
178
$aircrafts_shadow = array();
179
$output = '{';
180
	$output .= '"type": "FeatureCollection",';
181
		if ($min) $output .= '"minimal": "true",';
182
		else $output .= '"minimal": "false",';
183
		//$output .= '"fc": "'.$flightcnt.'",';
184
		$output .= '"sqt": "'.$sqltime.'",';
185
186
		if (!empty($spotter_array) && is_array($spotter_array))
187
		{
188
			$output .= '"features": [';
189
			foreach($spotter_array as $spotter_item)
190
			{
191
				$j++;
192
				date_default_timezone_set('UTC');
193
194
				if (isset($spotter_item['image_thumbnail']) && $spotter_item['image_thumbnail'] != "")
195
				{
196
					$image = $spotter_item['image_thumbnail'];
197
				} else {
198
					$image = "images/placeholder_thumb.png";
199
				}
200
201
/*
202
				if ($prev_flightaware_id != $spotter_item['flightaware_id']) {
203
				    if ($prev_flightaware_id != '') {
204
						$output .= ']';
205
						$output .= '}';
206
						$output .= '},';
207
				    }
208
				$prev_flightaware_id = $spotter_item['flightaware_id'];
209
*/
210
211
				//location of aircraft
212
//				print_r($spotter_item);
213
				$output .= '{';
214
					$output .= '"type": "Feature",';
215
						//$output .= '"fc": "'.$flightcnt.'",';
216
						//$output .= '"sqt": "'.$sqltime.'",';
217
						if (isset($spotter_item['flightaware_id'])) {
218
							$output .= '"id": "'.$spotter_item['flightaware_id'].'",';
219
						} elseif (isset($spotter_item['famtrackid'])) {
220
							$output .= '"id": "'.$spotter_item['famtrackid'].'",';
221
						} elseif (isset($spotter_item['fammarine_id'])) {
222
							$output .= '"id": "'.$spotter_item['fammarine_id'].'",';
223
						}
224
						$output .= '"properties": {';
225
						if (isset($spotter_item['flightaware_id'])) {
226
							if ($compress) $output .= '"fi": "'.$spotter_item['flightaware_id'].'",';
227
							else $output .= '"flightaware_id": "'.$spotter_item['flightaware_id'].'",';
228
						} elseif (isset($spotter_item['famtrackid'])) {
229
							if ($compress) $output .= '"fti": "'.$spotter_item['famtrackid'].'",';
230
							else $output .= '"famtrackid": "'.$spotter_item['famtrackid'].'",';
231
						} elseif (isset($spotter_item['fammarine_id'])) {
232
							if ($compress) $output .= '"fmi": "'.$spotter_item['fammarine_id'].'",';
233
							else $output .= '"fammarineid": "'.$spotter_item['fammarine_id'].'",';
234
						}
235
							$output .= '"fc": "'.$flightcnt.'",';
236
							$output .= '"sqt": "'.$sqltime.'",';
237
							if (isset($begindate)) $output .= '"archive_date": "'.$begindate.'",';
238
239
/*
240
							if ($min) $output .= '"minimal": "true",';
241
							else $output .= '"minimal": "false",';
242
*/
243
							//$output .= '"fc": "'.$spotter_item['nb'].'",';
244
						if (isset($spotter_item['ident']) && $spotter_item['ident'] != '') {
245
							if ($compress) $output .= '"c": "'.str_replace('\\','',$spotter_item['ident']).'",';
246
							else $output .= '"callsign": "'.str_replace('\\','',$spotter_item['ident']).'",';
247
							//"
248
						} else {
249
							if ($compress) $output .= '"c": "NA",';
250
							else $output .= '"callsign": "NA",';
251
						}
252
						if (isset($spotter_item['registration'])) $output .= '"registration": "'.$spotter_item['registration'].'",';
253
						if (isset($spotter_item['aircraft_name']) && isset($spotter_item['aircraft_type'])) {
254
							$output .= '"aircraft_name": "'.$spotter_item['aircraft_name'].' ('.$spotter_item['aircraft_type'].')",';
255
							$output .= '"aircraft_wiki": "http://'.strtolower($globalLanguage).'.wikipedia.org/wiki/'.urlencode(str_replace(' ','_',$spotter_item['aircraft_name'])).'",';
256
						} elseif (isset($spotter_item['aircraft_type'])) {
257
							$output .= '"aircraft_name": "NA ('.$spotter_item['aircraft_type'].')",';
258
						} elseif (!$min) {
259
							$output .= '"aircraft_name": "NA",';
260
						}
261
						if (!$min && isset($spotter_item['aircraft_icao'])) {
262
							$output .= '"aircraft_icao": "'.$spotter_item['aircraft_icao'].'",';
263
						}
264
						if (!isset($spotter_item['aircraft_shadow']) && !$tracker) {
265
							if (!isset($spotter_item['aircraft_icao']) || $spotter_item['aircraft_icao'] == '') $spotter_item['aircraft_shadow'] = '';
266
							else {
267
								$aircraft_icao = $spotter_item['aircraft_icao'];
268
								if (isset($aircrafts_shadow[$aircraft_icao])) $spotter_item['aircraft_shadow'] = $aircrafts_shadow[$aircraft_icao];
269
								else {
270
									$aircraft_info = $Spotter->getAllAircraftInfo($spotter_item['aircraft_icao']);
271
									if (count($aircraft_info) > 0) $spotter_item['aircraft_shadow'] = $aircraft_info[0]['aircraft_shadow'];
272
									elseif (isset($spotter_item['format_source']) && $spotter_item['format_source'] == 'aprs') $spotter_item['aircraft_shadow'] = 'PA18.png';
273
									elseif ($aircraft_icao == 'PARAGLIDER') $spotter_item['aircraft_shadow'] = 'PARAGLIDER.png';
274
									else $spotter_item['aircraft_shadow'] = '';
275
									$aircrafts_shadow[$aircraft_icao] = $spotter_item['aircraft_shadow'];
276
								}
277
							}
278
						}
279
						if (!isset($spotter_item['aircraft_shadow']) || $spotter_item['aircraft_shadow'] == '') {
280
							if ($tracker) {
281
								if (isset($spotter_item['type']) && $spotter_item['type'] == 'Ambulance') {
282
									if ($compress) $output .= '"as": "ambulance.png",';
283
									else $output .= '"aircraft_shadow": "ambulance.png",';
284
								} elseif (isset($spotter_item['type']) && $spotter_item['type'] == 'Police') {
285
									if ($compress) $output .= '"as": "police.png",';
286
									else $output .= '"aircraft_shadow": "police.png",';
287
								} elseif (isset($spotter_item['type']) && $spotter_item['type'] == 'Yacht (Sail)') {
288
									if ($compress) $output .= '"as": "ship.png",';
289
									else $output .= '"aircraft_shadow": "ship.png",';
290
								} elseif (isset($spotter_item['type']) && $spotter_item['type'] == 'Ship (Power Boat)') {
291
									if ($compress) $output .= '"as": "ship.png",';
292
									else $output .= '"aircraft_shadow": "ship.png",';
293
								} elseif (isset($spotter_item['type']) && $spotter_item['type'] == 'Shuttle') {
294
									if ($compress) $output .= '"as": "ship.png",';
295
									else $output .= '"aircraft_shadow": "ship.png",';
296
								} elseif (isset($spotter_item['type']) && $spotter_item['type'] == 'Truck') {
297
									if ($compress) $output .= '"as": "truck.png",';
298
									else $output .= '"aircraft_shadow": "truck.png",';
299
								} elseif (isset($spotter_item['type']) && $spotter_item['type'] == 'Truck (18 Wheeler)') {
300
									if ($compress) $output .= '"as": "truck.png",';
301
									else $output .= '"aircraft_shadow": "truck.png",';
302
								} elseif (isset($spotter_item['type']) && $spotter_item['type'] == 'Aircraft (small)') {
303
									if ($compress) $output .= '"as": "aircraft.png",';
304
									else $output .= '"aircraft_shadow": "aircraft.png",';
305
								} elseif (isset($spotter_item['type']) && $spotter_item['type'] == 'Large Aircraft') {
306
									if ($compress) $output .= '"as": "aircraft.png",';
307
									else $output .= '"aircraft_shadow": "aircraft.png",';
308
								} elseif (isset($spotter_item['type']) && $spotter_item['type'] == 'Helicopter') {
309
									if ($compress) $output .= '"as": "helico.png",';
310
									else $output .= '"aircraft_shadow": "helico.png",';
311
								} elseif (isset($spotter_item['type']) && $spotter_item['type'] == 'Railroad Engine') {
312
									if ($compress) $output .= '"as": "rail.png",';
313
									else $output .= '"aircraft_shadow": "rail.png",';
314
								} elseif (isset($spotter_item['type']) && $spotter_item['type'] == 'Firetruck') {
315
									if ($compress) $output .= '"as": "firetruck.png",';
316
									else $output .= '"aircraft_shadow": "firetruck.png",';
317
								} elseif (isset($spotter_item['type']) && $spotter_item['type'] == 'Bus') {
318
									if ($compress) $output .= '"as": "bus.png",';
319
									else $output .= '"aircraft_shadow": "bus.png",';
320
								} elseif (isset($spotter_item['type']) && $spotter_item['type'] == 'Phone') {
321
									if ($compress) $output .= '"as": "phone.png",';
322
									else $output .= '"aircraft_shadow": "phone.png",';
323
								} elseif (isset($spotter_item['type']) && $spotter_item['type'] == 'Jogger') {
324
									if ($compress) $output .= '"as": "jogger.png",';
325
									else $output .= '"aircraft_shadow": "jogger.png",';
326
								} elseif (isset($spotter_item['type']) && $spotter_item['type'] == 'Bike') {
327
									if ($compress) $output .= '"as": "bike.png",';
328
									else $output .= '"aircraft_shadow": "bike.png",';
329
								} elseif (isset($spotter_item['type']) && $spotter_item['type'] == 'Motorcycle') {
330
									if ($compress) $output .= '"as": "motorcycle.png",';
331
									else $output .= '"aircraft_shadow": "motorcycle.png",';
332
								} elseif (isset($spotter_item['type']) && $spotter_item['type'] == 'Balloon') {
333
									if ($compress) $output .= '"as": "balloon.png",';
334
									else $output .= '"aircraft_shadow": "balloon.png",';
335
								} else {
336
									if ($compress) $output .= '"as": "car.png",';
337
									else $output .= '"aircraft_shadow": "car.png",';
338
								}
339
							} elseif ($marine) {
340
								if ($compress) $output .= '"as": "ship.png",';
341
								else $output .= '"aircraft_shadow": "ship.png",';
342
							} else {
343
								if ($compress) $output .= '"as": "default.png",';
344
								else $output .= '"aircraft_shadow": "default.png",';
345
							}
346
						} else {
347
							if ($compress) $output .= '"as": "'.$spotter_item['aircraft_shadow'].'",';
348
							else $output .= '"aircraft_shadow": "'.$spotter_item['aircraft_shadow'].'",';
349
						}
350
						if (isset($spotter_item['airline_name'])) {
351
							$output .= '"airline_name": "'.$spotter_item['airline_name'].'",';
352
						} elseif (!$min) {
353
							$output .= '"airline_name": "NA",';
354
						}
355
						if (isset($spotter_item['departure_airport'])) {
356
							if ($compress) $output .= '"dac": "'.$spotter_item['departure_airport'].'",';
357
							else $output .= '"departure_airport_code": "'.$spotter_item['departure_airport'].'",';
358
						}
359
						if (isset($spotter_item['departure_airport_city'])) {
360
							$output .= '"departure_airport": "'.$spotter_item['departure_airport_city'].', '.$spotter_item['departure_airport_country'].'",';
361
						}
362
						if (isset($spotter_item['departure_airport_time'])) {
363
							$output .= '"departure_airport_time": "'.$spotter_item['departure_airport_time'].'",';
364
						}
365
						if (isset($spotter_item['arrival_airport_time'])) {
366
							$output .= '"arrival_airport_time": "'.$spotter_item['arrival_airport_time'].'",';
367
						}
368
						if (isset($spotter_item['arrival_airport'])) {
369
							if ($compress) $output .= '"aac": "'.$spotter_item['arrival_airport'].'",';
370
							else $output .= '"arrival_airport_code": "'.$spotter_item['arrival_airport'].'",';
371
						}
372
						if (isset($spotter_item['arrival_airport_city'])) {
373
							$output .= '"arrival_airport": "'.$spotter_item['arrival_airport_city'].', '.$spotter_item['arrival_airport_country'].'",';
374
						}
375
						
376
						if (isset($spotter_item['date_iso_8601'])) {
377
							$output .= '"date_update": "'.date("M j, Y, g:i a T", strtotime($spotter_item['date_iso_8601'])).'",';
378
						}
379
						if (isset($spotter_item['date'])) {
380
							$output .= '"lu": "'.strtotime($spotter_item['date']).'",';
381
						}
382
						if (!$min) {
383
							$output .= '"latitude": "'.$spotter_item['latitude'].'",';
384
							$output .= '"longitude": "'.$spotter_item['longitude'].'",';
385
							$output .= '"ground_speed": "'.$spotter_item['ground_speed'].'",';
386
						}
387
						
388
						if (isset($spotter_item['altitude'])) {
389
							if ($compress) $output .= '"a": "'.$spotter_item['altitude'].'",';
390
							else $output .= '"altitude": "'.$spotter_item['altitude'].'",';
391
						}
392
						if ($compress)$output .= '"h": "'.$spotter_item['heading'].'",';
393
						else $output .= '"heading": "'.$spotter_item['heading'].'",';
394
						
395
						if ($currenttime != '') {
396
							if (strtotime($spotter_item['date']) < $currenttime) {
397
								if (isset($archivespeed)) {
398
									$nextcoord = $Common->nextcoord($spotter_item['latitude'],$spotter_item['longitude'],$spotter_item['ground_speed'],$spotter_item['heading'],$archivespeed,$currenttime-strtotime($spotter_item['date'])+$globalMapRefresh);
0 ignored issues
show
The call to Common::nextcoord() has too many arguments starting with $currenttime - strtotime...']) + $globalMapRefresh.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
399
									$output .= '"nextlatlon": ['.$nextcoord['latitude'].','.$nextcoord['longitude'].'],';
400
								} elseif ($usenextlatlon) {
401
									$nextcoord = $Common->nextcoord($spotter_item['latitude'],$spotter_item['longitude'],$spotter_item['ground_speed'],$spotter_item['heading'],1,$currenttime-strtotime($spotter_item['date'])+$globalMapRefresh);
0 ignored issues
show
The call to Common::nextcoord() has too many arguments starting with $currenttime - strtotime...']) + $globalMapRefresh.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
402
									$output .= '"nextlatlon": ['.$nextcoord['latitude'].','.$nextcoord['longitude'].'],';
403
								}
404
							}
405
						} else {
406
							if (isset($archivespeed)) {
407
								$nextcoord = $Common->nextcoord($spotter_item['latitude'],$spotter_item['longitude'],$spotter_item['ground_speed'],$spotter_item['heading'],$archivespeed);
408
								$output .= '"nextlatlon": ['.$nextcoord['latitude'].','.$nextcoord['longitude'].'],';
409
							} elseif ($usenextlatlon) {
410
								$nextcoord = $Common->nextcoord($spotter_item['latitude'],$spotter_item['longitude'],$spotter_item['ground_speed'],$spotter_item['heading']);
411
								$output .= '"nextlatlon": ['.$nextcoord['latitude'].','.$nextcoord['longitude'].'],';
412
							}
413
						}
414
415
						if (!$min) $output .= '"image": "'.$image.'",';
416
						if (isset($spotter_item['image_copyright']) && $spotter_item['image_copyright'] != '') {
417
							$output .= '"image_copyright": "'.str_replace('"',"'",trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'',$spotter_item['image_copyright']))).'",';
418
						}
419
						if (isset($spotter_item['image_source_website'])) {
420
							$output .= '"image_source_website": "'.urlencode($spotter_item['image_source_website']).'",';
421
						}
422
						if (isset($spotter_item['squawk'])) {
423
							if ($compress) $output .= '"sq": "'.$spotter_item['squawk'].'",';
424
							else $output .= '"squawk": "'.$spotter_item['squawk'].'",';
425
						}
426
						if (isset($spotter_item['squawk_usage'])) {
427
							$output .= '"squawk_usage": "'.$spotter_item['squawk_usage'].'",';
428
						}
429
						if (isset($spotter_item['pilot_id'])) {
430
							$output .= '"pilot_id": "'.$spotter_item['pilot_id'].'",';
431
						}
432
						if (isset($spotter_item['pilot_name'])) {
433
							$output .= '"pilot_name": "'.$spotter_item['pilot_name'].'",';
434
						}
435
						if (isset($spotter_item['waypoints']) && $spotter_item['waypoints'] != '') {
436
							$output .= '"waypoints": "'.$spotter_item['waypoints'].'",';
437
						}
438
						if (isset($spotter_item['acars'])) {
439
							$output .= '"acars": "'.trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"), '<br />',$spotter_item['acars']['message'])).'",';
440
						}
441
						// type when not aircraft ?
442
						if (isset($spotter_item['type'])) {
443
							if ($compress) $output .= '"t": "'.$spotter_item['type'].'"';
444
							else $output .= '"type": "'.$spotter_item['type'].'"';
445
						} elseif ($marine) {
446
							if ($compress) $output .= '"t": "ship"';
447
							else $output .= '"type": "ship"';
448
						} else {
449
							if ($compress) $output .= '"t": "aircraft"';
450
							else $output .= '"type": "aircraft"';
451
						}
452
						$output .= '},';
453
						$output .= '"geometry": {';
454
							$output .= '"type": "Point",';
455
								$output .= '"coordinates": [';
456
								if ($currenttime != '') {
457
									if (strtotime($spotter_item['date']) < $currenttime) {
458
										if (!isset($archivespeed)) $archivespeed = 1;
459
										$nextcoord = $Common->nextcoord($spotter_item['latitude'],$spotter_item['longitude'],$spotter_item['ground_speed'],$spotter_item['heading'],$archivespeed,$currenttime-strtotime($spotter_item['date']));
0 ignored issues
show
The call to Common::nextcoord() has too many arguments starting with $currenttime - strtotime($spotter_item['date']).

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
460
										$output .= $nextcoord['longitude'].','.$nextcoord['latitude'];
461
									} else {
462
										$output .= $spotter_item['longitude'].', ';
463
										$output .= $spotter_item['latitude'];
464
									}
465
								} else {
466
										$output .= $spotter_item['longitude'].', ';
467
										$output .= $spotter_item['latitude'];
468
								}
469
										/*
470
										.', ';
471
										$output .= $spotter_item['altitude']*30.48;
472
										$output .= ', '.strtotime($spotter_item['date']);
473
										*/
474
								$output .= ']';
475
							$output .= '}';
476
				$output .= '},';
477
					
478
			/*	} else {
479
								$output .= ', ';
480
								$output .= $spotter_item['longitude'].', ';
481
								$output .= $spotter_item['latitude'].', ';
482
								$output .= $spotter_item['altitude']*30.48;
483
								$output .= ', '.strtotime($spotter_item['date']);
484
485
				}
486
*/                
487
488
/*                
489
                //previous location history of aircraft
490
                $output .= '{';
491
					$output .= '"type": "Feature",';
492
                        $output .= '"properties": {';
493
							$output .= '"callsign": "'.$spotter_item['ident'].'",';
494
							$output .= '"type": "history"';
495
						$output .= '},';
496
						$output .= '"geometry": {';
497
							$output .= '"type": "LineString",';
498
								$output .= '"coordinates": [';
499
                                    //$spotter_history_array = SpotterLive::getAllLiveSpotterDataByIdent($spotter_item['ident']);
500
                                    if ($from_archive) {
501
					    $spotter_history_array = SpotterArchive::getAllArchiveSpotterDataById($spotter_item['flightaware_id']);
502
                                    } else {
503
					    $spotter_history_array = SpotterLive::getAllLiveSpotterDataById($spotter_item['flightaware_id']);
504
                                    }
505
										$d = false;
506
										$neg = false;
507
									$history_output = '';
508
									foreach ($spotter_history_array as $key => $spotter_history)
509
									{
510
										if (abs($spotter_history['longitude']-$spotter_item['longitude']) > 200 || $d==true) {
511
											if ($d == false) $d = true;
512
									        } else {
513
											$history_output .= '[';
514
											$history_output .=  $spotter_history['longitude'].', ';
515
											$history_output .=  $spotter_history['latitude'].',';
516
											$history_output .=  $spotter_history['altitude'];
517
											$history_output .= '],';
518
519
										}
520
									}
521
									if ($history_output != '') $output .= substr($history_output, 0, -1);
522
								$output .= ']';
523
							$output .= '}';
524
				$output .= '},';
525
                
526
			}
527
*/
528
				$history = filter_input(INPUT_GET,'history',FILTER_SANITIZE_STRING);
529
				if ($history == '' && isset($_COOKIE['history'])) $history = $_COOKIE['history'];
530
				
531
				if (
532
				    (isset($_COOKIE['flightpath']) && $_COOKIE['flightpath'] == 'true') 
533
				    || ((isset($globalMapHistory) && $globalMapHistory) || $allhistory)
534
				//    || (isset($history) && $history != '' && $history != 'NA' && ($history == $spotter_item['ident'] || $history == $spotter_item['flightaware_id']))
535
				//    || (isset($history) && $history != '' && $history != 'NA' && $history == $spotter_item['ident'])
536
				    || (isset($history) && $history != '' && $history != 'NA' && isset($spotter_item['flightaware_id']) && str_replace('-','',$history) == str_replace('-','',$spotter_item['flightaware_id']))
537
				    || (isset($history) && $history == '' && isset($spotter_item['flightaware_id']) && isset($_GET['flightaware_id']) && $_GET['flightaware_id'] == $spotter_item['flightaware_id'])
538
				    || (isset($history) && $history != '' && $history != 'NA' && isset($spotter_item['fammarine_id']) && str_replace('-','',$history) == str_replace('-','',$spotter_item['fammarine_id']))
539
				    || (isset($history) && $history == '' && isset($spotter_item['flightaware_id']) && isset($_GET['fammarine_id']) && $_GET['fammarine_id'] == $spotter_item['fammarine_id'])
540
				    || (isset($history) && $history != '' && $history != 'NA' && isset($spotter_item['famtrackid']) && str_replace('-','',$history) == str_replace('-','',$spotter_item['famtrackid']))
541
				    || (isset($history) && $history == '' && isset($spotter_item['flightaware_id']) && isset($_GET['famtrackid']) && $_GET['famtrackid'] == $spotter_item['famtrackid'])
542
				    ) {
543
					if ($tracker) {
544
						if ($from_archive || $globalArchive) {
545
							$spotter_history_array = $TrackerArchive->getAllArchiveTrackerDataById($spotter_item['famtrackid']);
546
						} else {
547
							$spotter_history_array = $TrackerLive->getAllLiveTrackerDataById($spotter_item['famtrackid']);
548
						}
549
					} elseif ($marine) {
550
						if ($from_archive || $globalArchive) {
551
							$spotter_history_array = $MarineArchive->getAllArchiveMarineDataById($spotter_item['fammarine_id']);
552
						} else {
553
							$spotter_history_array = $MarineLive->getAllLiveMarineDataById($spotter_item['fammarine_id']);
554
						}
555
					} else {
556
						if ($from_archive || $globalArchive) {
557
							$spotter_history_array = $SpotterArchive->getAllArchiveSpotterDataById($spotter_item['flightaware_id']);
558
						} else {
559
							$spotter_history_array = $SpotterLive->getAllLiveSpotterDataById($spotter_item['flightaware_id']);
560
						}
561
					}
562
					$d = false;
563
					foreach ($spotter_history_array as $key => $spotter_history)
564
					{
565
						if (isset($spotter_history['altitude'])) {
566
							$alt = round($spotter_history['altitude']/10)*10;
567
							if (!isset($prev_alt) || $prev_alt != $alt) {
568
								if (isset($prev_alt)) {
569
									$output_history .= '['.$spotter_history['longitude'].', '.$spotter_history['latitude'].', '.$spotter_history['altitude'].']';
570
									$output_history .= ']}},';
571
									$output .= $output_history;
572
								}
573
								if ($compress) $output_history = '{"type": "Feature","properties": {"c": "'.$spotter_item['ident'].'","t": "history","a": "'.$alt.'"},"geometry": {"type": "LineString","coordinates": [';
574
								else $output_history = '{"type": "Feature","properties": {"callsign": "'.$spotter_item['ident'].'","type": "history","altitude": "'.$alt.'"},"geometry": {"type": "LineString","coordinates": [';
575
							}
576
							$output_history .= '[';
577
							$output_history .=  $spotter_history['longitude'].', ';
578
							$output_history .=  $spotter_history['latitude'].', ';
579
							$output_history .=  $spotter_history['altitude']*30.48;
580
							$output_history .= '],';
581
							/*
582
							if ($from_archive === false) {
583
								$output_history .= '[';
584
								$output_history .=  $spotter_item['longitude'].', ';
585
								$output_history .=  $spotter_item['latitude'].', ';
586
								$output_history .=  $spotter_item['altitude']*30.48;
587
								$output_history .= '],';
588
							}
589
							*/
590
							$prev_alt = $alt;
591
						} else {
592
							if ($d == false) {
593
								if ($compress) $output_history = '{"type": "Feature","properties": {"c": "'.$spotter_item['ident'].'","t": "history"},"geometry": {"type": "LineString","coordinates": [';
594
								else $output_history = '{"type": "Feature","properties": {"callsign": "'.$spotter_item['ident'].'","type": "history"},"geometry": {"type": "LineString","coordinates": [';
595
							} else $d = true;
596
							$output_history .= '[';
597
							$output_history .=  $spotter_history['longitude'].', ';
598
							$output_history .=  $spotter_history['latitude'];
599
							$output_history .= '],';
600
							/*
601
							if ($from_archive === false) {
602
								$output_history .= '[';
603
								$output_history .=  $spotter_item['longitude'].', ';
604
								$output_history .=  $spotter_item['latitude'];
605
								$output_history .= '],';
606
							}
607
							*/
608
						}
609
					}
610
					if (isset($output_history)) {
611
					
612
						if ($from_archive === false) {
613
							$output_historyd = '[';
614
							$output_historyd .=  $spotter_item['longitude'].', ';
615
							$output_historyd .=  $spotter_item['latitude'];
616
							if (isset($spotter_history['altitude'])) $output_historyd .=  ','.$spotter_item['altitude']*30.48;
617
							$output_historyd .= '],';
618
							//$output_history = $output_historyd.$output_history;
619
							$output_history = $output_history.$output_historyd;
620
						}
621
						
622
						$output_history  = substr($output_history, 0, -1);
623
						$output_history .= ']}},';
624
						$output .= $output_history;
625
						unset($prev_alt);
626
						unset($output_history);
627
					}
628
				}
629
				
630
				if (((isset($history) && $history != '' && $history != 'NA' && isset($spotter_item['flightaware_id']) && str_replace('-','',$history) == str_replace('-','',$spotter_item['flightaware_id']))
631
				    || (isset($history) && $history == '' && isset($spotter_item['flightaware_id']) && isset($_GET['flightaware_id']) && $_GET['flightaware_id'] == $spotter_item['flightaware_id']))
632
				     && (isset($spotter_item['departure_airport']) 
633
				        && $spotter_item['departure_airport'] != 'NA' 
634
				        && isset($spotter_item['arrival_airport']) 
635
				        && $spotter_item['arrival_airport'] != 'NA' 
636
				        && ((isset($_COOKIE['MapRoute']) && $_COOKIE['MapRoute'] == "true") 
637
				    	    || (!isset($_COOKIE['MapRoute']) && isset($globalMapRoute) && $globalMapRoute)))) {
638
				    if ($compress) $output_air = '{"type": "Feature","properties": {"c": "'.$spotter_item['ident'].'","t": "route"},"geometry": {"type": "LineString","coordinates": [';
639
				    else $output_air = '{"type": "Feature","properties": {"callsign": "'.$spotter_item['ident'].'","type": "route"},"geometry": {"type": "LineString","coordinates": [';
640
				    if (isset($spotter_item['departure_airport_latitude'])) {
641
					$output_air .= '['.$spotter_item['departure_airport_longitude'].','.$spotter_item['departure_airport_latitude'].'],';
642
				    } elseif (isset($spotter_item['departure_airport']) && $spotter_item['departure_airport'] != 'NA') {
643
					$dairport = $Spotter->getAllAirportInfo($spotter_item['departure_airport']);
644
					if (isset($dairport[0]['latitude'])) {
645
					    $output_air .= '['.$dairport[0]['longitude'].','.$dairport[0]['latitude'].'],';
646
					}
647
				    }
648
				    if (isset($spotter_item['arrival_airport_latitude'])) {
649
					$output_air .= '['.$spotter_item['arrival_airport_longitude'].','.$spotter_item['arrival_airport_latitude'].'],';
650
				    } elseif (isset($spotter_item['arrival_airport']) && $spotter_item['arrival_airport'] != 'NA') {
651
					$aairport = $Spotter->getAllAirportInfo($spotter_item['arrival_airport']);
652
					if (isset($aairport[0]['latitude'])) {
653
					    $output_air .= '['.$aairport[0]['longitude'].','.$aairport[0]['latitude'].'],';
654
					}
655
				    }
656
				    $output_air  = substr($output_air, 0, -1);
657
				    $output_air .= ']}},';
658
				    $output .= $output_air;
659
				    unset($output_air);
660
				}
661
662
				//if (isset($history) && $history != '' && $history == $spotter_item['ident'] && isset($spotter_item['departure_airport']) && $spotter_item['departure_airport'] != 'NA' && isset($spotter_item['arrival_airport']) && $spotter_item['arrival_airport'] != 'NA' && ((isset($_COOKIE['MapRoute']) && $_COOKIE['MapRoute'] == "true") || (!isset($_COOKIE['MapRoute']) && (!isset($globalMapRoute) || (isset($globalMapRoute) && $globalMapRoute))))) {
663
				//if (isset($history) && $history != '' && $history == $spotter_item['ident'] && isset($spotter_item['arrival_airport']) && $spotter_item['arrival_airport'] != 'NA' && ((isset($_COOKIE['MapRoute']) && $_COOKIE['MapRoute'] == "true") || (!isset($_COOKIE['MapRoute']) && (!isset($globalMapRoute) || (isset($globalMapRoute) && $globalMapRoute))))) {
664
				if (((isset($history) && $history != '' && $history != 'NA' && isset($spotter_item['flightaware_id']) && str_replace('-','',$history) == str_replace('-','',$spotter_item['flightaware_id']))
665
				    || (isset($history) && $history == '' && isset($spotter_item['flightaware_id']) && isset($_GET['flightaware_id']) && $_GET['flightaware_id'] == $spotter_item['flightaware_id']))
666
				     && (isset($spotter_item['arrival_airport']) 
667
				        && $spotter_item['arrival_airport'] != 'NA' 
668
				        && ((isset($_COOKIE['MapRemainingRoute']) && $_COOKIE['MapRemainingRoute'] == "true") 
669
				    	    || (!isset($_COOKIE['MapRemainaingRoute']) && (!isset($globalMapRemainingRoute) 
670
				    	    || (isset($globalMapRemainingRoute) && $globalMapRemainingRoute)))))) {
671
				    $havedata = false;
672
				    if ($compress) $output_dest = '{"type": "Feature","properties": {"c": "'.$spotter_item['ident'].'","t": "routedest"},"geometry": {"type": "LineString","coordinates": [';
673
				    else $output_dest = '{"type": "Feature","properties": {"callsign": "'.$spotter_item['ident'].'","type": "routedest"},"geometry": {"type": "LineString","coordinates": [';
674
				    $output_dest .= '['.$spotter_item['longitude'].','.$spotter_item['latitude'].'],';
675
676
				    if (isset($spotter_item['arrival_airport_latitude'])) {
677
					$output_dest .= '['.$spotter_item['arrival_airport_longitude'].','.$spotter_item['arrival_airport_latitude'].']';
678
					$havedata = true;
679
				    } elseif (isset($spotter_item['arrival_airport']) && $spotter_item['arrival_airport'] != 'NA') {
680
					$aairport = $Spotter->getAllAirportInfo($spotter_item['arrival_airport']);
681
					if (isset($aairport[0]['latitude'])) {
682
					    $output_dest .= '['.$aairport[0]['longitude'].','.$aairport[0]['latitude'].']';
683
					    $havedata = true;
684
					}
685
				    }
686
				    //$output_dest  = substr($output_dest, 0, -1);
687
				    $output_dest .= ']}},';
688
				    if ($havedata) $output .= $output_dest;
689
				    unset($output_dest);
690
				}
691
			}
692
			$output  = substr($output, 0, -1);
693
			$output .= ']';
694
			$output .= ',"initial_sqltime": "'.$sqltime.'",';
695
			$output .= '"totaltime": "'.round(microtime(true)-$begintime,2).'",';
696
			if (isset($begindate)) $output .= '"archive_date": "'.$begindate.'",';
697
			$output .= '"fc": "'.$j.'"';
698
		} else {
699
			$output .= '"features": ';
700
			$output .= '[{';
701
			$output .= '"type": "Feature",';
702
			$output .= '"properties": {';
703
			$output .= '"fc": "'.$flightcnt.'",';
704
			$output .= '"empty": "true"}';
705
			$output .= ',"geometry": {"type": "Point","coordinates": [0, 0]}';
706
			$output .= '}]';
707
		}
708
		
709
$output .= '}';
710
711
print $output;
712
713
?>
714