Ysurac /
FlightAirMap
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 | require_once('require/class.Spotter.php'); |
||
| 5 | require_once('require/class.SpotterArchive.php'); |
||
| 6 | $begintime = microtime(true); |
||
| 7 | $Spotter = new Spotter(); |
||
| 8 | $SpotterArchive = new SpotterArchive(); |
||
| 9 | $Common = new Common(); |
||
| 10 | |||
| 11 | if (isset($_GET['download'])) { |
||
| 12 | if ($_GET['download'] == "true") { |
||
| 13 | header('Content-disposition: attachment; filename="flightairmap.json"'); |
||
| 14 | } |
||
| 15 | } |
||
| 16 | header('Content-Type: text/javascript'); |
||
| 17 | |||
| 18 | if (!isset($globalJsonCompress)) $compress = true; |
||
| 19 | else $compress = $globalJsonCompress; |
||
| 20 | |||
| 21 | $from_archive = false; |
||
| 22 | $min = false; |
||
| 23 | $allhistory = false; |
||
| 24 | $filter['source'] = array(); |
||
| 25 | if ((!isset($globalMapVAchoose) || $globalMapVAchoose) && isset($globalVATSIM) && $globalVATSIM && isset($_COOKIE['ShowVATSIM']) && $_COOKIE['ShowVATSIM'] == 'true') $filter['source'] = array_merge($filter['source'],array('vatsimtxt')); |
||
| 26 | if ((!isset($globalMapVAchoose) || $globalMapVAchoose) && isset($globalIVAO) && $globalIVAO && isset($_COOKIE['ShowIVAO']) && $_COOKIE['ShowIVAO'] == 'true') $filter['source'] = array_merge($filter['source'],array('whazzup')); |
||
| 27 | if ((!isset($globalMapVAchoose) || $globalMapVAchoose) && isset($globalphpVMS) && $globalphpVMS && isset($_COOKIE['ShowVMS']) && $_COOKIE['ShowVMS'] == 'true') $filter['source'] = array_merge($filter['source'],array('phpvmacars')); |
||
| 28 | if ((!isset($globalMapchoose) || $globalMapchoose) && isset($globalSBS1) && $globalSBS1 && isset($_COOKIE['ShowSBS1']) && $_COOKIE['ShowSBS1'] == 'true') $filter['source'] = array_merge($filter['source'],array('sbs')); |
||
| 29 | if ((!isset($globalMapchoose) || $globalMapchoose) && isset($globalAPRS) && $globalAPRS && isset($_COOKIE['ShowAPRS']) && $_COOKIE['ShowAPRS'] == 'true') $filter['source'] = array_merge($filter['source'],array('aprs')); |
||
| 30 | if (isset($_COOKIE['Airlines']) && $_COOKIE['Airlines'] != '') $filter['airlines'] = explode(',',$_COOKIE['Airlines']); |
||
| 31 | if (isset($_COOKIE['Sources']) && $_COOKIE['Sources'] != '') $filter['source_aprs'] = explode(',',$_COOKIE['Sources']); |
||
| 32 | if (isset($_COOKIE['airlinestype']) && $_COOKIE['airlinestype'] != 'all') $filter['airlinestype'] = $_COOKIE['airlinestype']; |
||
| 33 | |||
| 34 | if (isset($globalMapPopup) && !$globalMapPopup && !(isset($_COOKIE['flightpopup']) && $_COOKIE['flightpopup'] == 'true')) { |
||
| 35 | $min = true; |
||
| 36 | } |
||
| 37 | |||
| 38 | if (isset($_GET['ident'])) { |
||
| 39 | $ident = filter_input(INPUT_GET,'ident',FILTER_SANITIZE_STRING); |
||
| 40 | $from_archive = true; |
||
| 41 | $spotter_array = $SpotterArchive->getLastArchiveSpotterDataByIdent($ident); |
||
| 42 | $allhistory = true; |
||
| 43 | } elseif (isset($_GET['flightaware_id'])) { |
||
| 44 | $flightaware_id = filter_input(INPUT_GET,'flightaware_id',FILTER_SANITIZE_STRING); |
||
| 45 | $from_archive = true; |
||
| 46 | $spotter_array = $SpotterArchive->getLastArchiveSpotterDataById($flightaware_id); |
||
| 47 | $allhistory = true; |
||
| 48 | } elseif (isset($_GET['archive']) && isset($_GET['begindate']) && isset($_GET['enddate']) && isset($_GET['speed'])) { |
||
| 49 | $from_archive = true; |
||
| 50 | // $begindate = filter_input(INPUT_GET,'begindate',FILTER_VALIDATE_REGEXP,array("options"=>array("regexp"=>'~^\d{4}/\d{2}/\d{2}$~'))); |
||
| 51 | // $enddate = filter_input(INPUT_GET,'enddate',FILTER_VALIDATE_REGEXP,array("options"=>array("regexp"=>'~^\d{4}/\d{2}/\d{2}$~'))); |
||
| 52 | $begindate = filter_input(INPUT_GET,'begindate',FILTER_SANITIZE_NUMBER_INT); |
||
| 53 | $enddate = filter_input(INPUT_GET,'enddate',FILTER_SANITIZE_NUMBER_INT); |
||
| 54 | $archivespeed = filter_input(INPUT_GET,'speed',FILTER_SANITIZE_NUMBER_INT); |
||
| 55 | $begindate = date('Y-m-d H:i:s',$begindate); |
||
| 56 | $enddate = date('Y-m-d H:i:s',$enddate); |
||
| 57 | //$spotter_array = $SpotterArchive->getMinLiveSpotterDataPlayback($begindate,$enddate,$filter); |
||
| 58 | $spotter_array = $SpotterArchive->getMinLiveSpotterData($begindate,$enddate,$filter); |
||
| 59 | } |
||
| 60 | |||
| 61 | if (!empty($spotter_array)) { |
||
| 62 | //$flightcnt = $SpotterArchive->getLiveSpotterCount($begindate,$enddate,$filter); |
||
| 63 | $flightcnt = 0; |
||
| 64 | if ($flightcnt == '') $flightcnt = 0; |
||
| 65 | } else $flightcnt = 0; |
||
| 66 | |||
| 67 | $sqltime = round(microtime(true)-$begintime,2); |
||
| 68 | |||
| 69 | $pfi = ''; |
||
| 70 | //var_dump($spotter_array); |
||
| 71 | $j = 0; |
||
| 72 | |||
| 73 | $output = '{'; |
||
| 74 | $output .= '"type": "FeatureCollection",'; |
||
| 75 | if ($min) $output .= '"minimal": "true",'; |
||
| 76 | else $output .= '"minimal": "false",'; |
||
| 77 | $output .= '"fc": "'.$flightcnt.'",'; |
||
| 78 | $output .= '"sqt": "'.$sqltime.'",'; |
||
| 79 | |||
| 80 | if (!empty($spotter_array) && is_array($spotter_array)) |
||
| 81 | { |
||
| 82 | $output .= '"features": ['; |
||
| 83 | foreach($spotter_array as $spotter_item) |
||
| 84 | { |
||
| 85 | $j++; |
||
| 86 | date_default_timezone_set('UTC'); |
||
| 87 | if ($pfi != $spotter_item['flightaware_id']) { |
||
| 88 | $spotter_history_array = $SpotterArchive->getCoordArchiveSpotterDataById($spotter_item['flightaware_id']); |
||
| 89 | $pfi = $spotter_item['flightaware_id']; |
||
| 90 | } else $spotter_history_array = 0; |
||
| 91 | if (count($spotter_history_array) > 1) { |
||
| 92 | if (isset($spotter_item['image_thumbnail']) && $spotter_item['image_thumbnail'] != "") |
||
| 93 | { |
||
| 94 | $image = $spotter_item['image_thumbnail']; |
||
| 95 | } else { |
||
| 96 | $image = "images/placeholder_thumb.png"; |
||
| 97 | } |
||
| 98 | |||
| 99 | //location of aircraft |
||
| 100 | // print_r($spotter_item); |
||
| 101 | $output .= '{'; |
||
| 102 | $output .= '"type": "Feature",'; |
||
| 103 | //$output .= '"fc": "'.$flightcnt.'",'; |
||
| 104 | //$output .= '"sqt": "'.$sqltime.'",'; |
||
| 105 | $output .= '"properties": {'; |
||
| 106 | if ($compress) $output .= '"fi": "'.$spotter_item['flightaware_id'].'",'; |
||
| 107 | else $output .= '"flightaware_id": "'.$spotter_item['flightaware_id'].'",'; |
||
| 108 | $output .= '"fc": "'.$flightcnt.'",'; |
||
| 109 | $output .= '"sqt": "'.$sqltime.'",'; |
||
| 110 | if (isset($begindate)) $output .= '"archive_date": "'.$begindate.'",'; |
||
| 111 | |||
| 112 | /* |
||
| 113 | if ($min) $output .= '"minimal": "true",'; |
||
| 114 | else $output .= '"minimal": "false",'; |
||
| 115 | */ |
||
| 116 | //$output .= '"fc": "'.$spotter_item['nb'].'",'; |
||
| 117 | if (isset($spotter_item['ident']) && $spotter_item['ident'] != '') { |
||
| 118 | if ($compress) $output .= '"c": "'.$spotter_item['ident'].'",'; |
||
| 119 | else $output .= '"callsign": "'.$spotter_item['ident'].'",'; |
||
| 120 | } else { |
||
| 121 | if ($compress) $output .= '"c": "NA",'; |
||
| 122 | else $output .= '"callsign": "NA",'; |
||
| 123 | } |
||
| 124 | if (isset($spotter_item['registration'])) $output .= '"registration": "'.$spotter_item['registration'].'",'; |
||
| 125 | if (isset($spotter_item['aircraft_name']) && isset($spotter_item['aircraft_type'])) { |
||
| 126 | $output .= '"aircraft_name": "'.$spotter_item['aircraft_name'].' ('.$spotter_item['aircraft_type'].')",'; |
||
| 127 | $output .= '"aircraft_wiki": "http://'.strtolower($globalLanguage).'.wikipedia.org/wiki/'.urlencode(str_replace(' ','_',$spotter_item['aircraft_name'])).'",'; |
||
| 128 | } elseif (isset($spotter_item['aircraft_type'])) { |
||
| 129 | $output .= '"aircraft_name": "NA ('.$spotter_item['aircraft_type'].')",'; |
||
| 130 | } elseif (!$min) { |
||
| 131 | $output .= '"aircraft_name": "NA",'; |
||
| 132 | } |
||
| 133 | if (!$min && isset($spotter_item['aircraft_icao'])) { |
||
| 134 | $output .= '"aircraft_icao": "'.$spotter_item['aircraft_icao'].'",'; |
||
| 135 | } |
||
| 136 | if (!isset($spotter_item['aircraft_shadow'])) { |
||
| 137 | if (!isset($spotter_item['aircraft_icao']) || $spotter_item['aircraft_icao'] == '') $spotter_item['aircraft_shadow'] = ''; |
||
| 138 | else { |
||
| 139 | $aircraft_info = $Spotter->getAllAircraftInfo($spotter_item['aircraft_icao']); |
||
| 140 | if (count($aircraft_info) > 0) $spotter_item['aircraft_shadow'] = $aircraft_info[0]['aircraft_shadow']; |
||
| 141 | else $spotter_item['aircraft_shadow'] = ''; |
||
| 142 | } |
||
| 143 | } |
||
| 144 | if ($spotter_item['aircraft_shadow'] == '') { |
||
| 145 | if ($compress) $output .= '"as": "default.png",'; |
||
| 146 | else $output .= '"aircraft_shadow": "default.png",'; |
||
| 147 | } else { |
||
| 148 | if ($compress) $output .= '"as": "'.$spotter_item['aircraft_shadow'].'",'; |
||
| 149 | else $output .= '"aircraft_shadow": "'.$spotter_item['aircraft_shadow'].'",'; |
||
| 150 | } |
||
| 151 | if (isset($spotter_item['airline_name'])) { |
||
| 152 | $output .= '"airline_name": "'.$spotter_item['airline_name'].'",'; |
||
| 153 | } elseif (!$min) { |
||
| 154 | $output .= '"airline_name": "NA",'; |
||
| 155 | } |
||
| 156 | if (isset($spotter_item['departure_airport'])) { |
||
| 157 | if ($compress) $output .= '"dac": "'.$spotter_item['departure_airport'].'",'; |
||
| 158 | else $output .= '"departure_airport_code": "'.$spotter_item['departure_airport'].'",'; |
||
| 159 | } |
||
| 160 | if (isset($spotter_item['departure_airport_city'])) { |
||
| 161 | $output .= '"departure_airport": "'.$spotter_item['departure_airport_city'].', '.$spotter_item['departure_airport_country'].'",'; |
||
| 162 | } |
||
| 163 | if (isset($spotter_item['departure_airport_time'])) { |
||
| 164 | $output .= '"departure_airport_time": "'.$spotter_item['departure_airport_time'].'",'; |
||
| 165 | } |
||
| 166 | if (isset($spotter_item['arrival_airport_time'])) { |
||
| 167 | $output .= '"arrival_airport_time": "'.$spotter_item['arrival_airport_time'].'",'; |
||
| 168 | } |
||
| 169 | if (isset($spotter_item['arrival_airport'])) { |
||
| 170 | if ($compress) $output .= '"aac": "'.$spotter_item['arrival_airport'].'",'; |
||
| 171 | else $output .= '"arrival_airport_code": "'.$spotter_item['arrival_airport'].'",'; |
||
| 172 | } |
||
| 173 | if (isset($spotter_item['arrival_airport_city'])) { |
||
| 174 | $output .= '"arrival_airport": "'.$spotter_item['arrival_airport_city'].', '.$spotter_item['arrival_airport_country'].'",'; |
||
| 175 | } |
||
| 176 | |||
| 177 | if (isset($spotter_item['date_iso_8601'])) { |
||
| 178 | $output .= '"date_update": "'.date("M j, Y, g:i a T", strtotime($spotter_item['date_iso_8601'])).'",'; |
||
| 179 | } |
||
| 180 | if (isset($spotter_item['date'])) { |
||
| 181 | $output .= '"lu": "'.strtotime($spotter_item['date']).'",'; |
||
| 182 | } |
||
| 183 | if (!$min) { |
||
| 184 | $output .= '"latitude": "'.$spotter_item['latitude'].'",'; |
||
| 185 | $output .= '"longitude": "'.$spotter_item['longitude'].'",'; |
||
| 186 | $output .= '"ground_speed": "'.$spotter_item['ground_speed'].'",'; |
||
| 187 | } |
||
| 188 | |||
| 189 | if ($compress) $output .= '"a": "'.$spotter_item['altitude'].'",'; |
||
| 190 | else $output .= '"altitude": "'.$spotter_item['altitude'].'",'; |
||
| 191 | if ($compress)$output .= '"h": "'.$spotter_item['heading'].'",'; |
||
| 192 | else $output .= '"heading": "'.$spotter_item['heading'].'",'; |
||
| 193 | |||
| 194 | /* |
||
| 195 | if (isset($archivespeed)) $nextcoord = $Common->nextcoord($spotter_item['latitude'],$spotter_item['longitude'],$spotter_item['ground_speed'],$spotter_item['heading'],$archivespeed); |
||
| 196 | else $nextcoord = $Common->nextcoord($spotter_item['latitude'],$spotter_item['longitude'],$spotter_item['ground_speed'],$spotter_item['heading']); |
||
| 197 | //$output .= '"nextlatitude": "'.$nextcoord['latitude'].'",'; |
||
| 198 | //$output .= '"nextlongitude": "'.$nextcoord['longitude'].'",'; |
||
| 199 | $output .= '"nextlatlon": ['.$nextcoord['latitude'].','.$nextcoord['longitude'].'],'; |
||
| 200 | */ |
||
| 201 | |||
| 202 | if (!$min) $output .= '"image": "'.$image.'",'; |
||
| 203 | if (isset($spotter_item['image_copyright']) && $spotter_item['image_copyright'] != '') { |
||
| 204 | $output .= '"image_copyright": "'.str_replace('"',"'",trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'',$spotter_item['image_copyright']))).'",'; |
||
| 205 | } |
||
| 206 | if (isset($spotter_item['image_source_website'])) { |
||
| 207 | $output .= '"image_source_website": "'.urlencode($spotter_item['image_source_website']).'",'; |
||
| 208 | } |
||
| 209 | if (isset($spotter_item['squawk'])) { |
||
| 210 | if ($compress) $output .= '"sq": "'.$spotter_item['squawk'].'",'; |
||
| 211 | else $output .= '"squawk": "'.$spotter_item['squawk'].'",'; |
||
| 212 | } |
||
| 213 | if (isset($spotter_item['squawk_usage'])) { |
||
| 214 | $output .= '"squawk_usage": "'.$spotter_item['squawk_usage'].'",'; |
||
| 215 | } |
||
| 216 | if (isset($spotter_item['pilot_id'])) { |
||
| 217 | $output .= '"pilot_id": "'.$spotter_item['pilot_id'].'",'; |
||
| 218 | } |
||
| 219 | if (isset($spotter_item['pilot_name'])) { |
||
| 220 | $output .= '"pilot_name": "'.$spotter_item['pilot_name'].'",'; |
||
| 221 | } |
||
| 222 | if (isset($spotter_item['waypoints']) && $spotter_item['waypoints'] != '') { |
||
| 223 | $output .= '"waypoints": "'.$spotter_item['waypoints'].'",'; |
||
| 224 | } |
||
| 225 | if (isset($spotter_item['acars'])) { |
||
| 226 | $output .= '"acars": "'.trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"), '<br />',$spotter_item['acars']['message'])).'",'; |
||
| 227 | } |
||
| 228 | //$spotter_history_array = $SpotterArchive->getCoordArchiveSpotterDataById($spotter_item['flightaware_id']); |
||
| 229 | //$spotter_history_array = array(); |
||
| 230 | $output_history = ''; |
||
| 231 | $output_time = ''; |
||
| 232 | $output_timediff = ''; |
||
| 233 | $previousts = 0; |
||
| 234 | $end = false; |
||
| 235 | $k = 0; |
||
| 236 | foreach ($spotter_history_array as $key => $spotter_history) |
||
|
0 ignored issues
–
show
|
|||
| 237 | { |
||
| 238 | if ($end == false) { |
||
|
0 ignored issues
–
show
|
|||
| 239 | $k++; |
||
| 240 | $output_history .= '['.$spotter_history['longitude'].', '.$spotter_history['latitude'].'],'; |
||
| 241 | $output_time .= (strtotime($spotter_history['date'])*1000).','; |
||
| 242 | if ($previousts != 0) $output_timediff .= (strtotime($spotter_history['date'])-$previousts).','; |
||
| 243 | $previousts = strtotime($spotter_history['date']); |
||
| 244 | if ($k > 1 && (strtotime($spotter_history['date'])*1000 > $enddate)) $end = true; |
||
| 245 | } |
||
| 246 | } |
||
| 247 | if (isset($output_time)) { |
||
| 248 | $output_time = substr($output_time, 0, -1); |
||
| 249 | $output .= '"time": ['.$output_time.'],'; |
||
| 250 | } |
||
| 251 | if (isset($output_timediff)) { |
||
| 252 | $output_timediff = substr($output_timediff, 0, -1); |
||
| 253 | $output .= '"timediff": ['.$output_timediff.'],'; |
||
| 254 | } |
||
| 255 | // FIXME : type when not aircraft ? |
||
| 256 | if ($compress) $output .= '"t": "aircraft"'; |
||
| 257 | else $output .= '"type": "aircraft"'; |
||
| 258 | $output .= '},'; |
||
| 259 | $output .= '"geometry": {'; |
||
| 260 | $output .= '"type": "MultiPoint",'; |
||
| 261 | //$output .= '"type": "LineString",'; |
||
| 262 | $output .= '"coordinates": ['; |
||
| 263 | |||
| 264 | if (isset($output_history)) { |
||
| 265 | $output_history = substr($output_history, 0, -1); |
||
| 266 | $output .= $output_history; |
||
| 267 | } |
||
| 268 | $output .= ']'; |
||
| 269 | $output .= '}'; |
||
| 270 | $output .= '},'; |
||
| 271 | } |
||
| 272 | } |
||
| 273 | $output = substr($output, 0, -1); |
||
| 274 | $output .= ']'; |
||
| 275 | $output .= ',"initial_sqltime": "'.$sqltime.'",'; |
||
| 276 | $output .= '"totaltime": "'.round(microtime(true)-$begintime,2).'",'; |
||
| 277 | if (isset($begindate)) $output .= '"archive_date": "'.$begindate.'",'; |
||
| 278 | $output .= '"fc": "'.$flightcnt.'"'; |
||
| 279 | } else { |
||
| 280 | $output .= '"features": '; |
||
| 281 | $output .= '{'; |
||
| 282 | $output .= '"type": "Feature",'; |
||
| 283 | $output .= '"properties": {'; |
||
| 284 | $output .= '"fc": "'.$flightcnt.'"}}'; |
||
| 285 | } |
||
| 286 | $output .= '}'; |
||
| 287 | print $output; |
||
| 288 | |||
| 289 | ?> |
||
| 290 |
There are different options of fixing this problem.
If you want to be on the safe side, you can add an additional type-check:
If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:
Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.