@@ -57,7 +57,7 @@ discard block |
||
57 | 57 | return ($dec); |
58 | 58 | } |
59 | 59 | |
60 | - /* |
|
60 | + /* |
|
61 | 61 | $ais_map64 = array( |
62 | 62 | '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', // 48 |
63 | 63 | ':', ';', '<', '=', '>', '?', '@', 'A', 'B', 'C', |
@@ -97,13 +97,13 @@ discard block |
||
97 | 97 | // ' ' --- '?', // 0x20 - 0x3F |
98 | 98 | // '@' --- '_', // 0x40 - 0x5F |
99 | 99 | $ais_chars = array( |
100 | - '@', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', |
|
101 | - 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', |
|
102 | - 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '[', '\\', ']', |
|
103 | - '^', '_', ' ', '!', '\"', '#', '$', '%', '&', '\'', |
|
104 | - '(', ')', '*', '+', ',', '-', '.', '/', '0', '1', |
|
105 | - '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', |
|
106 | - '<', '=', '>', '?' |
|
100 | + '@', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', |
|
101 | + 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', |
|
102 | + 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '[', '\\', ']', |
|
103 | + '^', '_', ' ', '!', '\"', '#', '$', '%', '&', '\'', |
|
104 | + '(', ')', '*', '+', ',', '-', '.', '/', '0', '1', |
|
105 | + '2', '3', '4', '5', '6', '7', '8', '9', ':', ';', |
|
106 | + '<', '=', '>', '?' |
|
107 | 107 | ); |
108 | 108 | // " |
109 | 109 | $rv = ''; |
@@ -421,8 +421,8 @@ discard block |
||
421 | 421 | } |
422 | 422 | if ($num_seq > 1) { // for multipart messages |
423 | 423 | if ($cmsg_sid != $msg_sid // different msg_sid |
424 | - || $msg_sid == -1 // invalid initial msg_sid |
|
425 | - || ($seq - $pseq) != 1 // not insequence |
|
424 | + || $msg_sid == -1 // invalid initial msg_sid |
|
425 | + || ($seq - $pseq) != 1 // not insequence |
|
426 | 426 | ) { // invalid for multipart message |
427 | 427 | $msg_sid = -1; |
428 | 428 | $cmsg_sid = -1; |
@@ -435,7 +435,7 @@ discard block |
||
435 | 435 | $itu = $itu.$pcs[5]; // get itu message |
436 | 436 | $filler += (int)$pcs[6][0]; // get filler |
437 | 437 | if ($num_seq == 1 // valid single message |
438 | - || $num_seq == $pseq // valid multi-part message |
|
438 | + || $num_seq == $pseq // valid multi-part message |
|
439 | 439 | ) { |
440 | 440 | /* |
441 | 441 | if ($num_seq != 1) { // test |
@@ -520,13 +520,13 @@ discard block |
||
520 | 520 | else $pad = ''; |
521 | 521 | $rv = ''; |
522 | 522 | $ais_chars = array( |
523 | - '@'=>0, 'A'=>1, 'B'=>2, 'C'=>3, 'D'=>4, 'E'=>5, 'F'=>6, 'G'=>7, 'H'=>8, 'I'=>9, |
|
524 | - 'J'=>10, 'K'=>11, 'L'=>12, 'M'=>13, 'N'=>14, 'O'=>15, 'P'=>16, 'Q'=>17, 'R'=>18, 'S'=>19, |
|
525 | - 'T'=>20, 'U'=>21, 'V'=>22, 'W'=>23, 'X'=>24, 'Y'=>25, 'Z'=>26, '['=>27, '\\'=>28, ']'=>29, |
|
526 | - '^'=>30, '_'=>31, ' '=>32, '!'=>33, '\"'=>34, '#'=>35, '$'=>36, '%'=>37, '&'=>38, '\''=>39, |
|
527 | - '('=>40, ')'=>41, '*'=>42, '+'=>43, ','=>44, '-'=>45, '.'=>46, '/'=>47, '0'=>48, '1'=>49, |
|
528 | - '2'=>50, '3'=>51, '4'=>52, '5'=>53, '6'=>54, '7'=>55, '8'=>56, '9'=>57, ':'=>58, ';'=>59, |
|
529 | - '<'=>60, '='=>61, '>'=>62, '?'=>63 |
|
523 | + '@'=>0, 'A'=>1, 'B'=>2, 'C'=>3, 'D'=>4, 'E'=>5, 'F'=>6, 'G'=>7, 'H'=>8, 'I'=>9, |
|
524 | + 'J'=>10, 'K'=>11, 'L'=>12, 'M'=>13, 'N'=>14, 'O'=>15, 'P'=>16, 'Q'=>17, 'R'=>18, 'S'=>19, |
|
525 | + 'T'=>20, 'U'=>21, 'V'=>22, 'W'=>23, 'X'=>24, 'Y'=>25, 'Z'=>26, '['=>27, '\\'=>28, ']'=>29, |
|
526 | + '^'=>30, '_'=>31, ' '=>32, '!'=>33, '\"'=>34, '#'=>35, '$'=>36, '%'=>37, '&'=>38, '\''=>39, |
|
527 | + '('=>40, ')'=>41, '*'=>42, '+'=>43, ','=>44, '-'=>45, '.'=>46, '/'=>47, '0'=>48, '1'=>49, |
|
528 | + '2'=>50, '3'=>51, '4'=>52, '5'=>53, '6'=>54, '7'=>55, '8'=>56, '9'=>57, ':'=>58, ';'=>59, |
|
529 | + '<'=>60, '='=>61, '>'=>62, '?'=>63 |
|
530 | 530 | ); |
531 | 531 | // " |
532 | 532 | $_a = str_split($name); |
@@ -117,31 +117,31 @@ discard block |
||
117 | 117 | |
118 | 118 | private function make_latf($temp) { // unsigned long |
119 | 119 | $flat = 0.0; // float |
120 | - $temp = $temp & 0x07FFFFFF; |
|
121 | - if ($temp & 0x04000000) { |
|
122 | - $temp = $temp ^ 0x07FFFFFF; |
|
120 | + $temp = $temp&0x07FFFFFF; |
|
121 | + if ($temp&0x04000000) { |
|
122 | + $temp = $temp^0x07FFFFFF; |
|
123 | 123 | $temp += 1; |
124 | - $flat = (float)($temp / (60.0 * 10000.0)); |
|
124 | + $flat = (float) ($temp/(60.0*10000.0)); |
|
125 | 125 | $flat *= -1.0; |
126 | - } else $flat = (float)($temp / (60.0 * 10000.0)); |
|
126 | + } else $flat = (float) ($temp/(60.0*10000.0)); |
|
127 | 127 | return $flat; // float |
128 | 128 | } |
129 | 129 | |
130 | 130 | private function make_lonf($temp) { // unsigned long |
131 | 131 | $flon = 0.0; // float |
132 | - $temp = $temp & 0x0FFFFFFF; |
|
133 | - if ($temp & 0x08000000) { |
|
134 | - $temp = $temp ^ 0x0FFFFFFF; |
|
132 | + $temp = $temp&0x0FFFFFFF; |
|
133 | + if ($temp&0x08000000) { |
|
134 | + $temp = $temp^0x0FFFFFFF; |
|
135 | 135 | $temp += 1; |
136 | - $flon = (float)($temp / (60.0 * 10000.0)); |
|
136 | + $flon = (float) ($temp/(60.0*10000.0)); |
|
137 | 137 | $flon *= -1.0; |
138 | - } else $flon = (float)($temp / (60.0 * 10000.0)); |
|
138 | + } else $flon = (float) ($temp/(60.0*10000.0)); |
|
139 | 139 | return $flon; |
140 | 140 | } |
141 | 141 | |
142 | 142 | private function ascii_2_dec($chr) { |
143 | - $dec=ord($chr);//get decimal ascii code |
|
144 | - $hex=dechex($dec);//convert decimal to hex |
|
143 | + $dec = ord($chr); //get decimal ascii code |
|
144 | + $hex = dechex($dec); //convert decimal to hex |
|
145 | 145 | return ($dec); |
146 | 146 | } |
147 | 147 | |
@@ -160,15 +160,15 @@ discard block |
||
160 | 160 | //only process in the following range: 48-87, 96-119 |
161 | 161 | if ($ascii < 48) { } |
162 | 162 | else { |
163 | - if($ascii>119) { } |
|
163 | + if ($ascii > 119) { } |
|
164 | 164 | else { |
165 | - if ($ascii>87 && $ascii<96) ; |
|
165 | + if ($ascii > 87 && $ascii < 96); |
|
166 | 166 | else { |
167 | - $ascii=$ascii+40; |
|
168 | - if ($ascii>128){ |
|
169 | - $ascii=$ascii+32; |
|
167 | + $ascii = $ascii + 40; |
|
168 | + if ($ascii > 128) { |
|
169 | + $ascii = $ascii + 32; |
|
170 | 170 | } else { |
171 | - $ascii=$ascii+40; |
|
171 | + $ascii = $ascii + 40; |
|
172 | 172 | } |
173 | 173 | } |
174 | 174 | } |
@@ -177,7 +177,7 @@ discard block |
||
177 | 177 | } |
178 | 178 | |
179 | 179 | private function dec_2_6bit($dec) { |
180 | - $bin=decbin($dec); |
|
180 | + $bin = decbin($dec); |
|
181 | 181 | return(substr($bin, -6)); |
182 | 182 | } |
183 | 183 | |
@@ -195,11 +195,11 @@ discard block |
||
195 | 195 | ); |
196 | 196 | // " |
197 | 197 | $rv = ''; |
198 | - if ($_size % 6 == 0) { |
|
199 | - $len = $_size / 6; |
|
200 | - for ($i=0; $i<$len; $i++) { |
|
201 | - $offset = $i * 6; |
|
202 | - $rv .= $ais_chars[ bindec(substr($_str,$_start + $offset,6)) ]; |
|
198 | + if ($_size%6 == 0) { |
|
199 | + $len = $_size/6; |
|
200 | + for ($i = 0; $i < $len; $i++) { |
|
201 | + $offset = $i*6; |
|
202 | + $rv .= $ais_chars[bindec(substr($_str, $_start + $offset, 6))]; |
|
203 | 203 | } |
204 | 204 | } |
205 | 205 | return $rv; |
@@ -226,93 +226,93 @@ discard block |
||
226 | 226 | $ro->eta_hour = ''; |
227 | 227 | $ro->eta_minute = ''; |
228 | 228 | $ro->ts = time(); |
229 | - $ro->id = bindec(substr($_aisdata,0,6)); |
|
230 | - $ro->mmsi = bindec(substr($_aisdata,8,30)); |
|
229 | + $ro->id = bindec(substr($_aisdata, 0, 6)); |
|
230 | + $ro->mmsi = bindec(substr($_aisdata, 8, 30)); |
|
231 | 231 | if ($ro->id >= 1 && $ro->id <= 3) { |
232 | - $ro->cog = bindec(substr($_aisdata,116,12))/10; |
|
233 | - $ro->sog = bindec(substr($_aisdata,50,10))/10; |
|
234 | - $ro->lon = $this->make_lonf(bindec(substr($_aisdata,61,28))); |
|
235 | - $ro->lat = $this->make_latf(bindec(substr($_aisdata,89,27))); |
|
232 | + $ro->cog = bindec(substr($_aisdata, 116, 12))/10; |
|
233 | + $ro->sog = bindec(substr($_aisdata, 50, 10))/10; |
|
234 | + $ro->lon = $this->make_lonf(bindec(substr($_aisdata, 61, 28))); |
|
235 | + $ro->lat = $this->make_latf(bindec(substr($_aisdata, 89, 27))); |
|
236 | 236 | $ro->cls = 1; // class A |
237 | 237 | } else if ($ro->id == 4) { |
238 | - $ro->lon = $this->make_lonf(bindec(substr($_aisdata,79,28))); |
|
239 | - $ro->lat = $this->make_latf(bindec(substr($_aisdata,107,27))); |
|
238 | + $ro->lon = $this->make_lonf(bindec(substr($_aisdata, 79, 28))); |
|
239 | + $ro->lat = $this->make_latf(bindec(substr($_aisdata, 107, 27))); |
|
240 | 240 | $ro->cls = 1; // class A |
241 | 241 | } else if ($ro->id == 5) { |
242 | - $ro->imo = bindec(substr($_aisdata,40,30)); |
|
243 | - $ro->callsign = $this->binchar($_aisdata,70,42); |
|
244 | - $ro->name = $this->binchar($_aisdata,112,120); |
|
245 | - $ro->typeid = bindec(substr($_aisdata,232,8)); |
|
242 | + $ro->imo = bindec(substr($_aisdata, 40, 30)); |
|
243 | + $ro->callsign = $this->binchar($_aisdata, 70, 42); |
|
244 | + $ro->name = $this->binchar($_aisdata, 112, 120); |
|
245 | + $ro->typeid = bindec(substr($_aisdata, 232, 8)); |
|
246 | 246 | $ro->type = $this->getShipType($ro->typeid); |
247 | 247 | //$ro->to_bow = bindec(substr($_aisdata,240,9)); |
248 | 248 | //$ro->to_stern = bindec(substr($_aisdata,249,9)); |
249 | 249 | //$ro->to_port = bindec(substr($_aisdata,258,6)); |
250 | 250 | //$ro->to_starboard = bindec(substr($_aisdata,264,6)); |
251 | - $ro->eta_month = bindec(substr($_aisdata,274,4)); |
|
252 | - $ro->eta_day = bindec(substr($_aisdata,278,5)); |
|
253 | - $ro->eta_hour = bindec(substr($_aisdata,283,5)); |
|
254 | - $ro->eta_minute = bindec(substr($_aisdata,288,6)); |
|
251 | + $ro->eta_month = bindec(substr($_aisdata, 274, 4)); |
|
252 | + $ro->eta_day = bindec(substr($_aisdata, 278, 5)); |
|
253 | + $ro->eta_hour = bindec(substr($_aisdata, 283, 5)); |
|
254 | + $ro->eta_minute = bindec(substr($_aisdata, 288, 6)); |
|
255 | 255 | //$ro->draught = bindec(substr($_aisdata,294,8)); |
256 | - $ro->destination = $this->binchar($_aisdata,302,120); |
|
256 | + $ro->destination = $this->binchar($_aisdata, 302, 120); |
|
257 | 257 | $ro->cls = 1; // class A |
258 | 258 | } else if ($ro->id == 9) { |
259 | 259 | // Search and Rescue aircraft position report |
260 | 260 | } else if ($ro->id == 18) { |
261 | - $ro->cog = bindec(substr($_aisdata,112,12))/10; |
|
262 | - $ro->sog = bindec(substr($_aisdata,46,10))/10; |
|
263 | - $ro->lon = $this->make_lonf(bindec(substr($_aisdata,57,28))); |
|
264 | - $ro->lat = $this->make_latf(bindec(substr($_aisdata,85,27))); |
|
265 | - $ro->heading = bindec(substr($_aisdata,124,9)); |
|
261 | + $ro->cog = bindec(substr($_aisdata, 112, 12))/10; |
|
262 | + $ro->sog = bindec(substr($_aisdata, 46, 10))/10; |
|
263 | + $ro->lon = $this->make_lonf(bindec(substr($_aisdata, 57, 28))); |
|
264 | + $ro->lat = $this->make_latf(bindec(substr($_aisdata, 85, 27))); |
|
265 | + $ro->heading = bindec(substr($_aisdata, 124, 9)); |
|
266 | 266 | if ($ro->heading == 511) $ro->heading = ''; |
267 | 267 | $ro->cls = 2; // class B |
268 | 268 | } else if ($ro->id == 19) { |
269 | - $ro->cog = bindec(substr($_aisdata,112,12))/10; |
|
270 | - $ro->sog = bindec(substr($_aisdata,46,10))/10; |
|
271 | - $ro->lon = $this->make_lonf(bindec(substr($_aisdata,61,28))); |
|
272 | - $ro->lat = $this->make_latf(bindec(substr($_aisdata,89,27))); |
|
273 | - $ro->name = $this->binchar($_aisdata,143,120); |
|
269 | + $ro->cog = bindec(substr($_aisdata, 112, 12))/10; |
|
270 | + $ro->sog = bindec(substr($_aisdata, 46, 10))/10; |
|
271 | + $ro->lon = $this->make_lonf(bindec(substr($_aisdata, 61, 28))); |
|
272 | + $ro->lat = $this->make_latf(bindec(substr($_aisdata, 89, 27))); |
|
273 | + $ro->name = $this->binchar($_aisdata, 143, 120); |
|
274 | 274 | $ro->cls = 2; // class B |
275 | - $ro->heading = bindec(substr($_aisdata,124,9)); |
|
275 | + $ro->heading = bindec(substr($_aisdata, 124, 9)); |
|
276 | 276 | if ($ro->heading == 511) $ro->heading = ''; |
277 | - $ro->typeid = bindec(substr($_aisdata,263,8)); |
|
277 | + $ro->typeid = bindec(substr($_aisdata, 263, 8)); |
|
278 | 278 | $ro->type = $this->getShipType($ro->typeid); |
279 | 279 | //$ro->to_bow = bindec(substr($_aisdata,271,9)); |
280 | 280 | //$ro->to_stern = bindec(substr($_aisdata,280,9)); |
281 | 281 | //$ro->to_port = bindec(substr($_aisdata,289,6)); |
282 | 282 | //$ro->to_starboard = bindec(substr($_aisdata,295,6)); |
283 | 283 | } else if ($ro->id == 21) { |
284 | - $ro->lon = $this->make_lonf(bindec(substr($_aisdata,164,28))); |
|
285 | - $ro->lat = $this->make_latf(bindec(substr($_aisdata,192,27))); |
|
286 | - $ro->name = $this->binchar($_aisdata,43,120); |
|
284 | + $ro->lon = $this->make_lonf(bindec(substr($_aisdata, 164, 28))); |
|
285 | + $ro->lat = $this->make_latf(bindec(substr($_aisdata, 192, 27))); |
|
286 | + $ro->name = $this->binchar($_aisdata, 43, 120); |
|
287 | 287 | //$ro->to_bow = bindec(substr($_aisdata,219,9)); |
288 | 288 | //$ro->to_stern = bindec(substr($_aisdata,228,9)); |
289 | 289 | //$ro->to_port = bindec(substr($_aisdata,237,6)); |
290 | 290 | //$ro->to_starboard = bindec(substr($_aisdata,243,6)); |
291 | 291 | $ro->cls = 2; // class B |
292 | 292 | } else if ($ro->id == 24) { |
293 | - $pn = bindec(substr($_aisdata,38,2)); |
|
293 | + $pn = bindec(substr($_aisdata, 38, 2)); |
|
294 | 294 | if ($pn == 0) { |
295 | - $ro->name = $this->binchar($_aisdata,40,120); |
|
295 | + $ro->name = $this->binchar($_aisdata, 40, 120); |
|
296 | 296 | } |
297 | - $ro->typeid = bindec(substr($_aisdata,40,8)); |
|
297 | + $ro->typeid = bindec(substr($_aisdata, 40, 8)); |
|
298 | 298 | $ro->type = $this->getShipType($ro->typeid); |
299 | - $ro->callsign = $this->binchar($_aisdata,90,42); |
|
299 | + $ro->callsign = $this->binchar($_aisdata, 90, 42); |
|
300 | 300 | //$ro->to_bow = bindec(substr($_aisdata,132,9)); |
301 | 301 | //$ro->to_stern = bindec(substr($_aisdata,141,9)); |
302 | 302 | //$ro->to_port = bindec(substr($_aisdata,150,6)); |
303 | 303 | //$ro->to_starboard = bindec(substr($_aisdata,156,6)); |
304 | 304 | $ro->cls = 2; // class B |
305 | 305 | } else if ($ro->id == 27) { |
306 | - $ro->cog = bindec(substr($_aisdata,85,9)); |
|
306 | + $ro->cog = bindec(substr($_aisdata, 85, 9)); |
|
307 | 307 | if ($ro->cog == 511) $ro->cog = 0.0; |
308 | - $ro->sog = bindec(substr($_aisdata,79,6)); |
|
308 | + $ro->sog = bindec(substr($_aisdata, 79, 6)); |
|
309 | 309 | if ($ro->sog == 63) $ro->sog = 0.0; |
310 | - $ro->lon = $this->make_lonf(bindec(substr($_aisdata,44,18))*10); |
|
311 | - $ro->lat = $this->make_latf(bindec(substr($_aisdata,62,17))*10); |
|
310 | + $ro->lon = $this->make_lonf(bindec(substr($_aisdata, 44, 18))*10); |
|
311 | + $ro->lat = $this->make_latf(bindec(substr($_aisdata, 62, 17))*10); |
|
312 | 312 | $ro->cls = 1; // class A |
313 | 313 | |
314 | 314 | } |
315 | - $ro->statusid = bindec(substr($_aisdata,38,4)); |
|
315 | + $ro->statusid = bindec(substr($_aisdata, 38, 4)); |
|
316 | 316 | $ro->status = $this->getStatus($ro->statusid); |
317 | 317 | return $ro; |
318 | 318 | } |
@@ -359,7 +359,7 @@ discard block |
||
359 | 359 | } |
360 | 360 | |
361 | 361 | public function getShipTypeID($type) { |
362 | - $typeid = array_search($type,$this->shiptype); |
|
362 | + $typeid = array_search($type, $this->shiptype); |
|
363 | 363 | if ($typeid !== FALSE) return $typeid; |
364 | 364 | else return ''; |
365 | 365 | } |
@@ -367,14 +367,14 @@ discard block |
||
367 | 367 | public function process_ais_itu($_itu, $_len, $_filler, $aux /*, $ais_ch*/) { |
368 | 368 | global $port; // tcpip port... |
369 | 369 | static $debug_counter = 0; |
370 | - $aisdata168='';//six bit array of ascii characters |
|
370 | + $aisdata168 = ''; //six bit array of ascii characters |
|
371 | 371 | $ais_nmea_array = str_split($_itu); // convert to an array |
372 | 372 | foreach ($ais_nmea_array as $value) { |
373 | 373 | $dec = $this->ascii_2_dec($value); |
374 | 374 | $bit8 = $this->asciidec_2_8bit($dec); |
375 | 375 | $bit6 = $this->dec_2_6bit($bit8); |
376 | 376 | //echo $value ."-" .$bit6 .""; |
377 | - $aisdata168 .=$bit6; |
|
377 | + $aisdata168 .= $bit6; |
|
378 | 378 | } |
379 | 379 | //echo $aisdata168 . "<br/>"; |
380 | 380 | //return $this->decode_ais($aisdata168, $aux); |
@@ -397,24 +397,24 @@ discard block |
||
397 | 397 | // calculate checksum after ! till * |
398 | 398 | // assume 1st ! is valid |
399 | 399 | // find * ensure that it is at correct position |
400 | - $end = strrpos ( $rawdata , '*' ); |
|
400 | + $end = strrpos($rawdata, '*'); |
|
401 | 401 | if ($end === FALSE) return -1; // check for NULLS!!! |
402 | - $cs = substr( $rawdata, $end + 1 ); |
|
403 | - if ( strlen($cs) != 2 ) return -1; // correct cs length |
|
404 | - $dcs = (int)hexdec( $cs ); |
|
405 | - for ( $alias=1; $alias<$end; $alias++) $chksum ^= ord( $rawdata[$alias] ); // perform XOR for NMEA checksum |
|
406 | - if ( $chksum == $dcs ) { // NMEA checksum pass |
|
402 | + $cs = substr($rawdata, $end + 1); |
|
403 | + if (strlen($cs) != 2) return -1; // correct cs length |
|
404 | + $dcs = (int) hexdec($cs); |
|
405 | + for ($alias = 1; $alias < $end; $alias++) $chksum ^= ord($rawdata[$alias]); // perform XOR for NMEA checksum |
|
406 | + if ($chksum == $dcs) { // NMEA checksum pass |
|
407 | 407 | $pcs = explode(',', $rawdata); |
408 | 408 | // !AI??? identifier |
409 | 409 | if (!isset($pcs[1])) { |
410 | 410 | echo "ERROR,INVALID_DATA ".time()." $rawdata\n"; |
411 | 411 | return -1; |
412 | 412 | } |
413 | - $num_seq = (int)$pcs[1]; // number of sequences |
|
414 | - $seq = (int)$pcs[2]; // get sequence |
|
413 | + $num_seq = (int) $pcs[1]; // number of sequences |
|
414 | + $seq = (int) $pcs[2]; // get sequence |
|
415 | 415 | // get msg sequence id |
416 | 416 | if ($pcs[3] == '') $msg_sid = -1; // non-multipart message, set to -1 |
417 | - else $msg_sid = (int)$pcs[3]; // multipart message |
|
417 | + else $msg_sid = (int) $pcs[3]; // multipart message |
|
418 | 418 | $ais_ch = $pcs[4]; // get AIS channel |
419 | 419 | // message sequence checking |
420 | 420 | if ($num_seq < 1 || $num_seq > 9) { |
@@ -447,7 +447,7 @@ discard block |
||
447 | 447 | } |
448 | 448 | } |
449 | 449 | $itu = $itu.$pcs[5]; // get itu message |
450 | - $filler += (int)$pcs[6][0]; // get filler |
|
450 | + $filler += (int) $pcs[6][0]; // get filler |
|
451 | 451 | if ($num_seq == 1 // valid single message |
452 | 452 | || $num_seq == $pseq // valid multi-part message |
453 | 453 | ) { |
@@ -469,13 +469,13 @@ discard block |
||
469 | 469 | $cbuf = $cbuf.$ibuf; |
470 | 470 | $last_pos = 0; |
471 | 471 | $result = new stdClass(); |
472 | - while ( ($start = strpos($cbuf,"VDM",$last_pos)) !== FALSE) { |
|
472 | + while (($start = strpos($cbuf, "VDM", $last_pos)) !== FALSE) { |
|
473 | 473 | //while ( ($start = strpos($cbuf,"!AI",$last_pos)) !== FALSE) { |
474 | 474 | //DEBUG echo $cbuf; |
475 | - if ( ($end = strpos($cbuf,"\r\n", $start)) !== FALSE) { //TBD need to trim? |
|
475 | + if (($end = strpos($cbuf, "\r\n", $start)) !== FALSE) { //TBD need to trim? |
|
476 | 476 | $tst = substr($cbuf, $start - 3, ($end - $start + 3)); |
477 | 477 | //DEBUG echo "[$start $end $tst]\n"; |
478 | - $result = $this->process_ais_raw( $tst, "" ); |
|
478 | + $result = $this->process_ais_raw($tst, ""); |
|
479 | 479 | $last_pos = $end + 1; |
480 | 480 | } else break; |
481 | 481 | } |
@@ -487,41 +487,41 @@ discard block |
||
487 | 487 | // incoming data from serial or IP comms |
488 | 488 | public function process_ais_line($cbuf) { |
489 | 489 | $result = new stdClass(); |
490 | - $start = strpos($cbuf,"VDM"); |
|
490 | + $start = strpos($cbuf, "VDM"); |
|
491 | 491 | $tst = substr($cbuf, $start - 3); |
492 | - $result = $this->process_ais_raw( $tst, "" ); |
|
492 | + $result = $this->process_ais_raw($tst, ""); |
|
493 | 493 | return $result; |
494 | 494 | } |
495 | 495 | |
496 | 496 | /* AIS Encoding |
497 | 497 | */ |
498 | - private function mk_ais_lat( $lat ) { |
|
498 | + private function mk_ais_lat($lat) { |
|
499 | 499 | //$lat = 1.2569; |
500 | - if ($lat<0.0) { |
|
500 | + if ($lat < 0.0) { |
|
501 | 501 | $lat = -$lat; |
502 | - $neg=true; |
|
503 | - } else $neg=false; |
|
502 | + $neg = true; |
|
503 | + } else $neg = false; |
|
504 | 504 | $latd = 0x00000000; |
505 | - $latd = intval ($lat * 600000.0); |
|
506 | - if ($neg==true) { |
|
505 | + $latd = intval($lat*600000.0); |
|
506 | + if ($neg == true) { |
|
507 | 507 | $latd = ~$latd; |
508 | - $latd+=1; |
|
508 | + $latd += 1; |
|
509 | 509 | $latd &= 0x07FFFFFF; |
510 | 510 | } |
511 | 511 | return $latd; |
512 | 512 | } |
513 | 513 | |
514 | - private function mk_ais_lon( $lon ) { |
|
514 | + private function mk_ais_lon($lon) { |
|
515 | 515 | //$lon = 103.851; |
516 | - if ($lon<0.0) { |
|
516 | + if ($lon < 0.0) { |
|
517 | 517 | $lon = -$lon; |
518 | - $neg=true; |
|
519 | - } else $neg=false; |
|
518 | + $neg = true; |
|
519 | + } else $neg = false; |
|
520 | 520 | $lond = 0x00000000; |
521 | - $lond = intval ($lon * 600000.0); |
|
522 | - if ($neg==true) { |
|
521 | + $lond = intval($lon*600000.0); |
|
522 | + if ($neg == true) { |
|
523 | 523 | $lond = ~$lond; |
524 | - $lond+=1; |
|
524 | + $lond += 1; |
|
525 | 525 | $lond &= 0x0FFFFFFF; |
526 | 526 | } |
527 | 527 | return $lond; |
@@ -529,8 +529,8 @@ discard block |
||
529 | 529 | |
530 | 530 | private function char2bin($name, $max_len) { |
531 | 531 | $len = strlen($name); |
532 | - if ($len > $max_len) $name = substr($name,0,$max_len); |
|
533 | - if ($len < $max_len) $pad = str_repeat('0', ($max_len - $len) * 6); |
|
532 | + if ($len > $max_len) $name = substr($name, 0, $max_len); |
|
533 | + if ($len < $max_len) $pad = str_repeat('0', ($max_len - $len)*6); |
|
534 | 534 | else $pad = ''; |
535 | 535 | $rv = ''; |
536 | 536 | $ais_chars = array( |
@@ -547,26 +547,26 @@ discard block |
||
547 | 547 | if ($_a) foreach ($_a as $_1) { |
548 | 548 | if (isset($ais_chars[$_1])) $dec = $ais_chars[$_1]; |
549 | 549 | else $dec = 0; |
550 | - $bin = str_pad(decbin( $dec ), 6, '0', STR_PAD_LEFT); |
|
550 | + $bin = str_pad(decbin($dec), 6, '0', STR_PAD_LEFT); |
|
551 | 551 | $rv .= $bin; |
552 | 552 | //echo "$_1 $dec ($bin)<br/>"; |
553 | 553 | } |
554 | 554 | return $rv.$pad; |
555 | 555 | } |
556 | 556 | |
557 | - private function mk_ais($_enc, $_part=1,$_total=1,$_seq='',$_ch='A') { |
|
557 | + private function mk_ais($_enc, $_part = 1, $_total = 1, $_seq = '', $_ch = 'A') { |
|
558 | 558 | $len_bit = strlen($_enc); |
559 | - $rem6 = $len_bit % 6; |
|
559 | + $rem6 = $len_bit%6; |
|
560 | 560 | $pad6_len = 0; |
561 | 561 | if ($rem6) $pad6_len = 6 - $rem6; |
562 | 562 | //echo $pad6_len.'<br>'; |
563 | 563 | $_enc .= str_repeat("0", $pad6_len); // pad the text... |
564 | - $len_enc = strlen($_enc) / 6; |
|
564 | + $len_enc = strlen($_enc)/6; |
|
565 | 565 | //echo $_enc.' '.$len_enc.'<br/>'; |
566 | 566 | $itu = ''; |
567 | - for ($i=0; $i<$len_enc; $i++) { |
|
568 | - $offset = $i * 6; |
|
569 | - $dec = bindec(substr($_enc,$offset,6)); |
|
567 | + for ($i = 0; $i < $len_enc; $i++) { |
|
568 | + $offset = $i*6; |
|
569 | + $dec = bindec(substr($_enc, $offset, 6)); |
|
570 | 570 | if ($dec < 40) $dec += 48; |
571 | 571 | else $dec += 56; |
572 | 572 | //echo chr($dec)." $dec<br/>"; |
@@ -576,15 +576,15 @@ discard block |
||
576 | 576 | $chksum = 0; |
577 | 577 | $itu = "AIVDM,$_part,$_total,$_seq,$_ch,".$itu.",0"; |
578 | 578 | $len_itu = strlen($itu); |
579 | - for ($i=0; $i<$len_itu; $i++) { |
|
580 | - $chksum ^= ord( $itu[$i] ); |
|
579 | + for ($i = 0; $i < $len_itu; $i++) { |
|
580 | + $chksum ^= ord($itu[$i]); |
|
581 | 581 | } |
582 | - $hex_arr = array('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'); |
|
583 | - $lsb = $chksum & 0x0F; |
|
584 | - if ($lsb >=0 && $lsb <= 15 ) $lsbc = $hex_arr[$lsb]; |
|
582 | + $hex_arr = array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'); |
|
583 | + $lsb = $chksum&0x0F; |
|
584 | + if ($lsb >= 0 && $lsb <= 15) $lsbc = $hex_arr[$lsb]; |
|
585 | 585 | else $lsbc = '0'; |
586 | - $msb = (($chksum & 0xF0) >> 4) & 0x0F; |
|
587 | - if ($msb >=0 && $msb <= 15 ) $msbc = $hex_arr[$msb]; |
|
586 | + $msb = (($chksum&0xF0) >> 4)&0x0F; |
|
587 | + if ($msb >= 0 && $msb <= 15) $msbc = $hex_arr[$msb]; |
|
588 | 588 | else $msbc = '0'; |
589 | 589 | $itu = '!'.$itu."*{$msbc}{$lsbc}\r\n"; |
590 | 590 | return $itu; |
@@ -609,14 +609,14 @@ discard block |
||
609 | 609 | |
610 | 610 | public function mmsitype($mmsi) { |
611 | 611 | if (strlen($mmsi) == 9) { |
612 | - if (substr($mmsi,0,3) == '974') return 'EPIRB (Emergency Position Indicating Radio Beacon) AIS'; |
|
613 | - elseif (substr($mmsi,0,3) == '972') return 'MOB (Man Overboard) device'; |
|
614 | - elseif (substr($mmsi,0,3) == '970') return 'AIS SART (Search and Rescue Transmitter)'; |
|
615 | - elseif (substr($mmsi,0,3) == '111') return 'SAR (Search and Rescue) aircraft'; |
|
616 | - elseif (substr($mmsi,0,2) == '98') return 'Auxiliary craft associated with a parent ship'; |
|
617 | - elseif (substr($mmsi,0,2) == '99') return 'Aids to Navigation'; |
|
618 | - elseif (substr($mmsi,0,2) == '00') return 'Coastal stations'; |
|
619 | - elseif (substr($mmsi,0,1) == '0') return 'Group of ships'; |
|
612 | + if (substr($mmsi, 0, 3) == '974') return 'EPIRB (Emergency Position Indicating Radio Beacon) AIS'; |
|
613 | + elseif (substr($mmsi, 0, 3) == '972') return 'MOB (Man Overboard) device'; |
|
614 | + elseif (substr($mmsi, 0, 3) == '970') return 'AIS SART (Search and Rescue Transmitter)'; |
|
615 | + elseif (substr($mmsi, 0, 3) == '111') return 'SAR (Search and Rescue) aircraft'; |
|
616 | + elseif (substr($mmsi, 0, 2) == '98') return 'Auxiliary craft associated with a parent ship'; |
|
617 | + elseif (substr($mmsi, 0, 2) == '99') return 'Aids to Navigation'; |
|
618 | + elseif (substr($mmsi, 0, 2) == '00') return 'Coastal stations'; |
|
619 | + elseif (substr($mmsi, 0, 1) == '0') return 'Group of ships'; |
|
620 | 620 | else return 'Ship'; |
621 | 621 | } |
622 | 622 | |
@@ -627,19 +627,19 @@ discard block |
||
627 | 627 | global $globalDebug; |
628 | 628 | $result = array(); |
629 | 629 | $data = new stdClass(); |
630 | - $start = strpos($buffer,"VDM"); |
|
630 | + $start = strpos($buffer, "VDM"); |
|
631 | 631 | $tst = substr($buffer, $start - 3); |
632 | - $data = $this->process_ais_raw( $tst, "" ); |
|
632 | + $data = $this->process_ais_raw($tst, ""); |
|
633 | 633 | if (!is_object($data)) { |
634 | 634 | //if ($globalDebug) echo '==== Line format not supported : '.$buffer."\n"; |
635 | 635 | return array(); |
636 | 636 | } |
637 | 637 | if ($data->lon != 0) $result['longitude'] = $data->lon; |
638 | 638 | if ($data->lat != 0) $result['latitude'] = $data->lat; |
639 | - $result['ident'] = trim(str_replace('@','',$data->name)); |
|
639 | + $result['ident'] = trim(str_replace('@', '', $data->name)); |
|
640 | 640 | $result['timestamp'] = $data->ts; |
641 | 641 | $result['mmsi'] = $data->mmsi; |
642 | - if (strlen($result['mmsi']) == 8 && substr($result['mmsi'],0,3) == '669') $result['mmsi'] = '3'.$result['mmsi']; |
|
642 | + if (strlen($result['mmsi']) == 8 && substr($result['mmsi'], 0, 3) == '669') $result['mmsi'] = '3'.$result['mmsi']; |
|
643 | 643 | $result['mmsi_type'] = $this->mmsitype($result['mmsi']); |
644 | 644 | if ($data->sog != -1.0) $result['speed'] = $data->sog; |
645 | 645 | if ($data->heading !== '') $result['heading'] = $data->heading; |
@@ -649,16 +649,16 @@ discard block |
||
649 | 649 | if ($data->type !== '') $result['type'] = $data->type; |
650 | 650 | if ($data->typeid !== '') $result['typeid'] = $data->typeid; |
651 | 651 | if ($data->imo !== '') $result['imo'] = $data->imo; |
652 | - if ($data->callsign !== '') $result['callsign'] = trim(str_replace('@','',$data->callsign)); |
|
652 | + if ($data->callsign !== '') $result['callsign'] = trim(str_replace('@', '', $data->callsign)); |
|
653 | 653 | if (is_numeric($data->eta_month) && $data->eta_month != 0 && is_numeric($data->eta_day) && $data->eta_day != 0 && $data->eta_hour !== '' && $data->eta_minute !== '') { |
654 | - $eta_ts = strtotime(date('Y').'-'.sprintf("%02d",$data->eta_month).'-'.sprintf("%02d",$data->eta_day).' '.sprintf("%02d",$data->eta_hour).':'.sprintf("%02d",$data->eta_minute).':00'); |
|
654 | + $eta_ts = strtotime(date('Y').'-'.sprintf("%02d", $data->eta_month).'-'.sprintf("%02d", $data->eta_day).' '.sprintf("%02d", $data->eta_hour).':'.sprintf("%02d", $data->eta_minute).':00'); |
|
655 | 655 | if ($eta_ts != '') $result['eta_ts'] = $eta_ts; |
656 | 656 | } elseif (is_numeric($data->eta_hour) && is_numeric($data->eta_minute)) { |
657 | - $eta_ts = strtotime(date('Y-m-d').' '.sprintf("%02d",$data->eta_hour).':'.sprintf("%02d",$data->eta_minute).':00'); |
|
657 | + $eta_ts = strtotime(date('Y-m-d').' '.sprintf("%02d", $data->eta_hour).':'.sprintf("%02d", $data->eta_minute).':00'); |
|
658 | 658 | if ($eta_ts != '') $result['eta_ts'] = $eta_ts; |
659 | 659 | } |
660 | 660 | if ($data->destination != '') { |
661 | - $dest = trim(str_replace('@','',$data->destination)); |
|
661 | + $dest = trim(str_replace('@', '', $data->destination)); |
|
662 | 662 | if ($dest != '') $result['destination'] = $dest; |
663 | 663 | } |
664 | 664 | $result['all'] = (array) $data; |
@@ -123,7 +123,9 @@ discard block |
||
123 | 123 | $temp += 1; |
124 | 124 | $flat = (float)($temp / (60.0 * 10000.0)); |
125 | 125 | $flat *= -1.0; |
126 | - } else $flat = (float)($temp / (60.0 * 10000.0)); |
|
126 | + } else { |
|
127 | + $flat = (float)($temp / (60.0 * 10000.0)); |
|
128 | + } |
|
127 | 129 | return $flat; // float |
128 | 130 | } |
129 | 131 | |
@@ -135,7 +137,9 @@ discard block |
||
135 | 137 | $temp += 1; |
136 | 138 | $flon = (float)($temp / (60.0 * 10000.0)); |
137 | 139 | $flon *= -1.0; |
138 | - } else $flon = (float)($temp / (60.0 * 10000.0)); |
|
140 | + } else { |
|
141 | + $flon = (float)($temp / (60.0 * 10000.0)); |
|
142 | + } |
|
139 | 143 | return $flon; |
140 | 144 | } |
141 | 145 | |
@@ -158,10 +162,8 @@ discard block |
||
158 | 162 | */ |
159 | 163 | private function asciidec_2_8bit($ascii) { |
160 | 164 | //only process in the following range: 48-87, 96-119 |
161 | - if ($ascii < 48) { } |
|
162 | - else { |
|
163 | - if($ascii>119) { } |
|
164 | - else { |
|
165 | + if ($ascii < 48) { } else { |
|
166 | + if($ascii>119) { } else { |
|
165 | 167 | if ($ascii>87 && $ascii<96) ; |
166 | 168 | else { |
167 | 169 | $ascii=$ascii+40; |
@@ -263,7 +265,9 @@ discard block |
||
263 | 265 | $ro->lon = $this->make_lonf(bindec(substr($_aisdata,57,28))); |
264 | 266 | $ro->lat = $this->make_latf(bindec(substr($_aisdata,85,27))); |
265 | 267 | $ro->heading = bindec(substr($_aisdata,124,9)); |
266 | - if ($ro->heading == 511) $ro->heading = ''; |
|
268 | + if ($ro->heading == 511) { |
|
269 | + $ro->heading = ''; |
|
270 | + } |
|
267 | 271 | $ro->cls = 2; // class B |
268 | 272 | } else if ($ro->id == 19) { |
269 | 273 | $ro->cog = bindec(substr($_aisdata,112,12))/10; |
@@ -273,7 +277,9 @@ discard block |
||
273 | 277 | $ro->name = $this->binchar($_aisdata,143,120); |
274 | 278 | $ro->cls = 2; // class B |
275 | 279 | $ro->heading = bindec(substr($_aisdata,124,9)); |
276 | - if ($ro->heading == 511) $ro->heading = ''; |
|
280 | + if ($ro->heading == 511) { |
|
281 | + $ro->heading = ''; |
|
282 | + } |
|
277 | 283 | $ro->typeid = bindec(substr($_aisdata,263,8)); |
278 | 284 | $ro->type = $this->getShipType($ro->typeid); |
279 | 285 | //$ro->to_bow = bindec(substr($_aisdata,271,9)); |
@@ -304,9 +310,13 @@ discard block |
||
304 | 310 | $ro->cls = 2; // class B |
305 | 311 | } else if ($ro->id == 27) { |
306 | 312 | $ro->cog = bindec(substr($_aisdata,85,9)); |
307 | - if ($ro->cog == 511) $ro->cog = 0.0; |
|
313 | + if ($ro->cog == 511) { |
|
314 | + $ro->cog = 0.0; |
|
315 | + } |
|
308 | 316 | $ro->sog = bindec(substr($_aisdata,79,6)); |
309 | - if ($ro->sog == 63) $ro->sog = 0.0; |
|
317 | + if ($ro->sog == 63) { |
|
318 | + $ro->sog = 0.0; |
|
319 | + } |
|
310 | 320 | $ro->lon = $this->make_lonf(bindec(substr($_aisdata,44,18))*10); |
311 | 321 | $ro->lat = $this->make_latf(bindec(substr($_aisdata,62,17))*10); |
312 | 322 | $ro->cls = 1; // class A |
@@ -354,14 +364,20 @@ discard block |
||
354 | 364 | } |
355 | 365 | |
356 | 366 | public function getShipType($code) { |
357 | - if (isset($this->shiptype[$code])) return $this->shiptype[$code]; |
|
358 | - else return ''; |
|
367 | + if (isset($this->shiptype[$code])) { |
|
368 | + return $this->shiptype[$code]; |
|
369 | + } else { |
|
370 | + return ''; |
|
371 | + } |
|
359 | 372 | } |
360 | 373 | |
361 | 374 | public function getShipTypeID($type) { |
362 | 375 | $typeid = array_search($type,$this->shiptype); |
363 | - if ($typeid !== FALSE) return $typeid; |
|
364 | - else return ''; |
|
376 | + if ($typeid !== FALSE) { |
|
377 | + return $typeid; |
|
378 | + } else { |
|
379 | + return ''; |
|
380 | + } |
|
365 | 381 | } |
366 | 382 | |
367 | 383 | public function process_ais_itu($_itu, $_len, $_filler, $aux /*, $ais_ch*/) { |
@@ -398,11 +414,20 @@ discard block |
||
398 | 414 | // assume 1st ! is valid |
399 | 415 | // find * ensure that it is at correct position |
400 | 416 | $end = strrpos ( $rawdata , '*' ); |
401 | - if ($end === FALSE) return -1; // check for NULLS!!! |
|
417 | + if ($end === FALSE) { |
|
418 | + return -1; |
|
419 | + } |
|
420 | + // check for NULLS!!! |
|
402 | 421 | $cs = substr( $rawdata, $end + 1 ); |
403 | - if ( strlen($cs) != 2 ) return -1; // correct cs length |
|
422 | + if ( strlen($cs) != 2 ) { |
|
423 | + return -1; |
|
424 | + } |
|
425 | + // correct cs length |
|
404 | 426 | $dcs = (int)hexdec( $cs ); |
405 | - for ( $alias=1; $alias<$end; $alias++) $chksum ^= ord( $rawdata[$alias] ); // perform XOR for NMEA checksum |
|
427 | + for ( $alias=1; $alias<$end; $alias++) { |
|
428 | + $chksum ^= ord( $rawdata[$alias] ); |
|
429 | + } |
|
430 | + // perform XOR for NMEA checksum |
|
406 | 431 | if ( $chksum == $dcs ) { // NMEA checksum pass |
407 | 432 | $pcs = explode(',', $rawdata); |
408 | 433 | // !AI??? identifier |
@@ -413,8 +438,14 @@ discard block |
||
413 | 438 | $num_seq = (int)$pcs[1]; // number of sequences |
414 | 439 | $seq = (int)$pcs[2]; // get sequence |
415 | 440 | // get msg sequence id |
416 | - if ($pcs[3] == '') $msg_sid = -1; // non-multipart message, set to -1 |
|
417 | - else $msg_sid = (int)$pcs[3]; // multipart message |
|
441 | + if ($pcs[3] == '') { |
|
442 | + $msg_sid = -1; |
|
443 | + } |
|
444 | + // non-multipart message, set to -1 |
|
445 | + else { |
|
446 | + $msg_sid = (int)$pcs[3]; |
|
447 | + } |
|
448 | + // multipart message |
|
418 | 449 | $ais_ch = $pcs[4]; // get AIS channel |
419 | 450 | // message sequence checking |
420 | 451 | if ($num_seq < 1 || $num_seq > 9) { |
@@ -477,10 +508,18 @@ discard block |
||
477 | 508 | //DEBUG echo "[$start $end $tst]\n"; |
478 | 509 | $result = $this->process_ais_raw( $tst, "" ); |
479 | 510 | $last_pos = $end + 1; |
480 | - } else break; |
|
511 | + } else { |
|
512 | + break; |
|
513 | + } |
|
514 | + } |
|
515 | + if ($last_pos > 0) { |
|
516 | + $cbuf = substr($cbuf, $last_pos); |
|
481 | 517 | } |
482 | - if ($last_pos > 0) $cbuf = substr($cbuf, $last_pos); // move... |
|
483 | - if (strlen($cbuf) > 1024) $cbuf = ""; // prevent overflow simple mode... |
|
518 | + // move... |
|
519 | + if (strlen($cbuf) > 1024) { |
|
520 | + $cbuf = ""; |
|
521 | + } |
|
522 | + // prevent overflow simple mode... |
|
484 | 523 | return $result; |
485 | 524 | } |
486 | 525 | |
@@ -500,7 +539,9 @@ discard block |
||
500 | 539 | if ($lat<0.0) { |
501 | 540 | $lat = -$lat; |
502 | 541 | $neg=true; |
503 | - } else $neg=false; |
|
542 | + } else { |
|
543 | + $neg=false; |
|
544 | + } |
|
504 | 545 | $latd = 0x00000000; |
505 | 546 | $latd = intval ($lat * 600000.0); |
506 | 547 | if ($neg==true) { |
@@ -516,7 +557,9 @@ discard block |
||
516 | 557 | if ($lon<0.0) { |
517 | 558 | $lon = -$lon; |
518 | 559 | $neg=true; |
519 | - } else $neg=false; |
|
560 | + } else { |
|
561 | + $neg=false; |
|
562 | + } |
|
520 | 563 | $lond = 0x00000000; |
521 | 564 | $lond = intval ($lon * 600000.0); |
522 | 565 | if ($neg==true) { |
@@ -529,9 +572,14 @@ discard block |
||
529 | 572 | |
530 | 573 | private function char2bin($name, $max_len) { |
531 | 574 | $len = strlen($name); |
532 | - if ($len > $max_len) $name = substr($name,0,$max_len); |
|
533 | - if ($len < $max_len) $pad = str_repeat('0', ($max_len - $len) * 6); |
|
534 | - else $pad = ''; |
|
575 | + if ($len > $max_len) { |
|
576 | + $name = substr($name,0,$max_len); |
|
577 | + } |
|
578 | + if ($len < $max_len) { |
|
579 | + $pad = str_repeat('0', ($max_len - $len) * 6); |
|
580 | + } else { |
|
581 | + $pad = ''; |
|
582 | + } |
|
535 | 583 | $rv = ''; |
536 | 584 | $ais_chars = array( |
537 | 585 | '@'=>0, 'A'=>1, 'B'=>2, 'C'=>3, 'D'=>4, 'E'=>5, 'F'=>6, 'G'=>7, 'H'=>8, 'I'=>9, |
@@ -544,9 +592,12 @@ discard block |
||
544 | 592 | ); |
545 | 593 | // " |
546 | 594 | $_a = str_split($name); |
547 | - if ($_a) foreach ($_a as $_1) { |
|
595 | + if ($_a) { |
|
596 | + foreach ($_a as $_1) { |
|
548 | 597 | if (isset($ais_chars[$_1])) $dec = $ais_chars[$_1]; |
549 | - else $dec = 0; |
|
598 | + } else { |
|
599 | + $dec = 0; |
|
600 | + } |
|
550 | 601 | $bin = str_pad(decbin( $dec ), 6, '0', STR_PAD_LEFT); |
551 | 602 | $rv .= $bin; |
552 | 603 | //echo "$_1 $dec ($bin)<br/>"; |
@@ -558,7 +609,9 @@ discard block |
||
558 | 609 | $len_bit = strlen($_enc); |
559 | 610 | $rem6 = $len_bit % 6; |
560 | 611 | $pad6_len = 0; |
561 | - if ($rem6) $pad6_len = 6 - $rem6; |
|
612 | + if ($rem6) { |
|
613 | + $pad6_len = 6 - $rem6; |
|
614 | + } |
|
562 | 615 | //echo $pad6_len.'<br>'; |
563 | 616 | $_enc .= str_repeat("0", $pad6_len); // pad the text... |
564 | 617 | $len_enc = strlen($_enc) / 6; |
@@ -567,8 +620,11 @@ discard block |
||
567 | 620 | for ($i=0; $i<$len_enc; $i++) { |
568 | 621 | $offset = $i * 6; |
569 | 622 | $dec = bindec(substr($_enc,$offset,6)); |
570 | - if ($dec < 40) $dec += 48; |
|
571 | - else $dec += 56; |
|
623 | + if ($dec < 40) { |
|
624 | + $dec += 48; |
|
625 | + } else { |
|
626 | + $dec += 56; |
|
627 | + } |
|
572 | 628 | //echo chr($dec)." $dec<br/>"; |
573 | 629 | $itu .= chr($dec); |
574 | 630 | } |
@@ -581,25 +637,41 @@ discard block |
||
581 | 637 | } |
582 | 638 | $hex_arr = array('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'); |
583 | 639 | $lsb = $chksum & 0x0F; |
584 | - if ($lsb >=0 && $lsb <= 15 ) $lsbc = $hex_arr[$lsb]; |
|
585 | - else $lsbc = '0'; |
|
640 | + if ($lsb >=0 && $lsb <= 15 ) { |
|
641 | + $lsbc = $hex_arr[$lsb]; |
|
642 | + } else { |
|
643 | + $lsbc = '0'; |
|
644 | + } |
|
586 | 645 | $msb = (($chksum & 0xF0) >> 4) & 0x0F; |
587 | - if ($msb >=0 && $msb <= 15 ) $msbc = $hex_arr[$msb]; |
|
588 | - else $msbc = '0'; |
|
646 | + if ($msb >=0 && $msb <= 15 ) { |
|
647 | + $msbc = $hex_arr[$msb]; |
|
648 | + } else { |
|
649 | + $msbc = '0'; |
|
650 | + } |
|
589 | 651 | $itu = '!'.$itu."*{$msbc}{$lsbc}\r\n"; |
590 | 652 | return $itu; |
591 | 653 | } |
592 | 654 | |
593 | 655 | public function parse($buffer) { |
594 | 656 | $data = $this->process_ais_buf($buffer); |
595 | - if (!is_object($data)) return array(); |
|
596 | - if ($data->lon != 0) $result['longitude'] = $data->lon; |
|
597 | - if ($data->lat != 0) $result['latitude'] = $data->lat; |
|
657 | + if (!is_object($data)) { |
|
658 | + return array(); |
|
659 | + } |
|
660 | + if ($data->lon != 0) { |
|
661 | + $result['longitude'] = $data->lon; |
|
662 | + } |
|
663 | + if ($data->lat != 0) { |
|
664 | + $result['latitude'] = $data->lat; |
|
665 | + } |
|
598 | 666 | $result['ident'] = trim($data->name); |
599 | 667 | $result['timestamp'] = $data->ts; |
600 | 668 | $result['mmsi'] = $data->mmsi; |
601 | - if ($data->sog != -1.0) $result['speed'] = $data->sog; |
|
602 | - if ($data->cog != 0) $result['heading'] = $data->cog; |
|
669 | + if ($data->sog != -1.0) { |
|
670 | + $result['speed'] = $data->sog; |
|
671 | + } |
|
672 | + if ($data->cog != 0) { |
|
673 | + $result['heading'] = $data->cog; |
|
674 | + } |
|
603 | 675 | /* |
604 | 676 | $ro->cls = 0; // AIS class undefined, also indicate unparsed msg |
605 | 677 | $ro->id = bindec(substr($_aisdata,0,6)); |
@@ -609,15 +681,25 @@ discard block |
||
609 | 681 | |
610 | 682 | public function mmsitype($mmsi) { |
611 | 683 | if (strlen($mmsi) == 9) { |
612 | - if (substr($mmsi,0,3) == '974') return 'EPIRB (Emergency Position Indicating Radio Beacon) AIS'; |
|
613 | - elseif (substr($mmsi,0,3) == '972') return 'MOB (Man Overboard) device'; |
|
614 | - elseif (substr($mmsi,0,3) == '970') return 'AIS SART (Search and Rescue Transmitter)'; |
|
615 | - elseif (substr($mmsi,0,3) == '111') return 'SAR (Search and Rescue) aircraft'; |
|
616 | - elseif (substr($mmsi,0,2) == '98') return 'Auxiliary craft associated with a parent ship'; |
|
617 | - elseif (substr($mmsi,0,2) == '99') return 'Aids to Navigation'; |
|
618 | - elseif (substr($mmsi,0,2) == '00') return 'Coastal stations'; |
|
619 | - elseif (substr($mmsi,0,1) == '0') return 'Group of ships'; |
|
620 | - else return 'Ship'; |
|
684 | + if (substr($mmsi,0,3) == '974') { |
|
685 | + return 'EPIRB (Emergency Position Indicating Radio Beacon) AIS'; |
|
686 | + } elseif (substr($mmsi,0,3) == '972') { |
|
687 | + return 'MOB (Man Overboard) device'; |
|
688 | + } elseif (substr($mmsi,0,3) == '970') { |
|
689 | + return 'AIS SART (Search and Rescue Transmitter)'; |
|
690 | + } elseif (substr($mmsi,0,3) == '111') { |
|
691 | + return 'SAR (Search and Rescue) aircraft'; |
|
692 | + } elseif (substr($mmsi,0,2) == '98') { |
|
693 | + return 'Auxiliary craft associated with a parent ship'; |
|
694 | + } elseif (substr($mmsi,0,2) == '99') { |
|
695 | + return 'Aids to Navigation'; |
|
696 | + } elseif (substr($mmsi,0,2) == '00') { |
|
697 | + return 'Coastal stations'; |
|
698 | + } elseif (substr($mmsi,0,1) == '0') { |
|
699 | + return 'Group of ships'; |
|
700 | + } else { |
|
701 | + return 'Ship'; |
|
702 | + } |
|
621 | 703 | } |
622 | 704 | |
623 | 705 | |
@@ -634,32 +716,61 @@ discard block |
||
634 | 716 | //if ($globalDebug) echo '==== Line format not supported : '.$buffer."\n"; |
635 | 717 | return array(); |
636 | 718 | } |
637 | - if ($data->lon != 0) $result['longitude'] = $data->lon; |
|
638 | - if ($data->lat != 0) $result['latitude'] = $data->lat; |
|
719 | + if ($data->lon != 0) { |
|
720 | + $result['longitude'] = $data->lon; |
|
721 | + } |
|
722 | + if ($data->lat != 0) { |
|
723 | + $result['latitude'] = $data->lat; |
|
724 | + } |
|
639 | 725 | $result['ident'] = trim(str_replace('@','',$data->name)); |
640 | 726 | $result['timestamp'] = $data->ts; |
641 | 727 | $result['mmsi'] = $data->mmsi; |
642 | - if (strlen($result['mmsi']) == 8 && substr($result['mmsi'],0,3) == '669') $result['mmsi'] = '3'.$result['mmsi']; |
|
728 | + if (strlen($result['mmsi']) == 8 && substr($result['mmsi'],0,3) == '669') { |
|
729 | + $result['mmsi'] = '3'.$result['mmsi']; |
|
730 | + } |
|
643 | 731 | $result['mmsi_type'] = $this->mmsitype($result['mmsi']); |
644 | - if ($data->sog != -1.0) $result['speed'] = $data->sog; |
|
645 | - if ($data->heading !== '') $result['heading'] = $data->heading; |
|
646 | - elseif ($data->cog != 0) $result['heading'] = $data->cog; |
|
647 | - if ($data->status != '') $result['status'] = $data->status; |
|
648 | - if ($data->statusid !== '') $result['statusid'] = $data->statusid; |
|
649 | - if ($data->type !== '') $result['type'] = $data->type; |
|
650 | - if ($data->typeid !== '') $result['typeid'] = $data->typeid; |
|
651 | - if ($data->imo !== '') $result['imo'] = $data->imo; |
|
652 | - if ($data->callsign !== '') $result['callsign'] = trim(str_replace('@','',$data->callsign)); |
|
732 | + if ($data->sog != -1.0) { |
|
733 | + $result['speed'] = $data->sog; |
|
734 | + } |
|
735 | + if ($data->heading !== '') { |
|
736 | + $result['heading'] = $data->heading; |
|
737 | + } elseif ($data->cog != 0) { |
|
738 | + $result['heading'] = $data->cog; |
|
739 | + } |
|
740 | + if ($data->status != '') { |
|
741 | + $result['status'] = $data->status; |
|
742 | + } |
|
743 | + if ($data->statusid !== '') { |
|
744 | + $result['statusid'] = $data->statusid; |
|
745 | + } |
|
746 | + if ($data->type !== '') { |
|
747 | + $result['type'] = $data->type; |
|
748 | + } |
|
749 | + if ($data->typeid !== '') { |
|
750 | + $result['typeid'] = $data->typeid; |
|
751 | + } |
|
752 | + if ($data->imo !== '') { |
|
753 | + $result['imo'] = $data->imo; |
|
754 | + } |
|
755 | + if ($data->callsign !== '') { |
|
756 | + $result['callsign'] = trim(str_replace('@','',$data->callsign)); |
|
757 | + } |
|
653 | 758 | if (is_numeric($data->eta_month) && $data->eta_month != 0 && is_numeric($data->eta_day) && $data->eta_day != 0 && $data->eta_hour !== '' && $data->eta_minute !== '') { |
654 | 759 | $eta_ts = strtotime(date('Y').'-'.sprintf("%02d",$data->eta_month).'-'.sprintf("%02d",$data->eta_day).' '.sprintf("%02d",$data->eta_hour).':'.sprintf("%02d",$data->eta_minute).':00'); |
655 | - if ($eta_ts != '') $result['eta_ts'] = $eta_ts; |
|
760 | + if ($eta_ts != '') { |
|
761 | + $result['eta_ts'] = $eta_ts; |
|
762 | + } |
|
656 | 763 | } elseif (is_numeric($data->eta_hour) && is_numeric($data->eta_minute)) { |
657 | 764 | $eta_ts = strtotime(date('Y-m-d').' '.sprintf("%02d",$data->eta_hour).':'.sprintf("%02d",$data->eta_minute).':00'); |
658 | - if ($eta_ts != '') $result['eta_ts'] = $eta_ts; |
|
765 | + if ($eta_ts != '') { |
|
766 | + $result['eta_ts'] = $eta_ts; |
|
767 | + } |
|
659 | 768 | } |
660 | 769 | if ($data->destination != '') { |
661 | 770 | $dest = trim(str_replace('@','',$data->destination)); |
662 | - if ($dest != '') $result['destination'] = $dest; |
|
771 | + if ($dest != '') { |
|
772 | + $result['destination'] = $dest; |
|
773 | + } |
|
663 | 774 | } |
664 | 775 | $result['all'] = (array) $data; |
665 | 776 | /* |
@@ -156,6 +156,10 @@ discard block |
||
156 | 156 | 't', 'u', 'v', 'w' // 119 |
157 | 157 | ); // char 64 |
158 | 158 | */ |
159 | + |
|
160 | + /** |
|
161 | + * @param integer $ascii |
|
162 | + */ |
|
159 | 163 | private function asciidec_2_8bit($ascii) { |
160 | 164 | //only process in the following range: 48-87, 96-119 |
161 | 165 | if ($ascii < 48) { } |
@@ -181,6 +185,10 @@ discard block |
||
181 | 185 | return(substr($bin, -6)); |
182 | 186 | } |
183 | 187 | |
188 | + /** |
|
189 | + * @param integer $_start |
|
190 | + * @param integer $_size |
|
191 | + */ |
|
184 | 192 | private function binchar($_str, $_start, $_size) { |
185 | 193 | // ' ' --- '?', // 0x20 - 0x3F |
186 | 194 | // '@' --- '_', // 0x40 - 0x5F |
@@ -206,6 +214,10 @@ discard block |
||
206 | 214 | } |
207 | 215 | |
208 | 216 | // function for decoding the AIS Message ITU Payload |
217 | + |
|
218 | + /** |
|
219 | + * @param string $_aisdata |
|
220 | + */ |
|
209 | 221 | private function decode_ais($_aisdata) { |
210 | 222 | $ro = new stdClass(); // return object |
211 | 223 | $ro->cls = 0; // AIS class undefined, also indicate unparsed msg |
@@ -364,6 +376,12 @@ discard block |
||
364 | 376 | else return ''; |
365 | 377 | } |
366 | 378 | |
379 | + /** |
|
380 | + * @param string $_itu |
|
381 | + * @param integer $_len |
|
382 | + * @param integer $_filler |
|
383 | + * @param string $aux |
|
384 | + */ |
|
367 | 385 | public function process_ais_itu($_itu, $_len, $_filler, $aux /*, $ais_ch*/) { |
368 | 386 | global $port; // tcpip port... |
369 | 387 | static $debug_counter = 0; |
@@ -383,6 +401,10 @@ discard block |
||
383 | 401 | |
384 | 402 | // char* - AIS \r terminated string |
385 | 403 | // TCP based streams which send messages in full can use this instead of calling process_ais_buf |
404 | + |
|
405 | + /** |
|
406 | + * @param string $rawdata |
|
407 | + */ |
|
386 | 408 | public function process_ais_raw($rawdata, $aux = '') { // return int |
387 | 409 | static $num_seq; // 1 to 9 |
388 | 410 | static $seq; // 1 to 9 |
@@ -607,6 +629,9 @@ discard block |
||
607 | 629 | return $result; |
608 | 630 | } |
609 | 631 | |
632 | + /** |
|
633 | + * @param string $mmsi |
|
634 | + */ |
|
610 | 635 | public function mmsitype($mmsi) { |
611 | 636 | if (strlen($mmsi) == 9) { |
612 | 637 | if (substr($mmsi,0,3) == '974') return 'EPIRB (Emergency Position Indicating Radio Beacon) AIS'; |
@@ -62,12 +62,12 @@ |
||
62 | 62 | */ |
63 | 63 | //if ($aircraft_type != "NA") |
64 | 64 | //{ |
65 | - print '<div class="info column">'; |
|
66 | - print '<h1>'.$spotter_array[0]['type'].'</h1>'; |
|
67 | - //print '<div><span class="label">'._("Name").'</span>'.$spotter_array[0]['aircraft_name'].'</div>'; |
|
68 | - //print '<div><span class="label">'._("ICAO").'</span>'.$spotter_array[0]['aircraft_type'].'</div>'; |
|
69 | - //if (isset($spotter_array[0]['aircraft_manufacturer'])) print '<div><span class="label">'._("Manufacturer").'</span><a href="'.$globalURL.'/manufacturer/'.strtolower(str_replace(" ", "-", $spotter_array[0]['aircraft_manufacturer'])).'">'.$spotter_array[0]['aircraft_manufacturer'].'</a></div>'; |
|
70 | - print '</div>'; |
|
65 | + print '<div class="info column">'; |
|
66 | + print '<h1>'.$spotter_array[0]['type'].'</h1>'; |
|
67 | + //print '<div><span class="label">'._("Name").'</span>'.$spotter_array[0]['aircraft_name'].'</div>'; |
|
68 | + //print '<div><span class="label">'._("ICAO").'</span>'.$spotter_array[0]['aircraft_type'].'</div>'; |
|
69 | + //if (isset($spotter_array[0]['aircraft_manufacturer'])) print '<div><span class="label">'._("Manufacturer").'</span><a href="'.$globalURL.'/manufacturer/'.strtolower(str_replace(" ", "-", $spotter_array[0]['aircraft_manufacturer'])).'">'.$spotter_array[0]['aircraft_manufacturer'].'</a></div>'; |
|
70 | + print '</div>'; |
|
71 | 71 | //} else { |
72 | 72 | // print '<div class="alert alert-warning">'._("This special aircraft profile shows all flights in where the aircraft type is unknown.").'</div>'; |
73 | 73 | //} |
@@ -5,16 +5,16 @@ discard block |
||
5 | 5 | require_once('require/class.Language.php'); |
6 | 6 | $Marine = new Marine(); |
7 | 7 | $type = 'marine'; |
8 | -if (!isset($_GET['type'])){ |
|
8 | +if (!isset($_GET['type'])) { |
|
9 | 9 | header('Location: '.$globalURL.'/'); |
10 | 10 | } else { |
11 | 11 | //calculuation for the pagination |
12 | - if(!isset($_GET['limit']) || count(explode(",", $_GET['limit'])) < 2) |
|
12 | + if (!isset($_GET['limit']) || count(explode(",", $_GET['limit'])) < 2) |
|
13 | 13 | { |
14 | 14 | $limit_start = 0; |
15 | 15 | $limit_end = 25; |
16 | 16 | $absolute_difference = 25; |
17 | - } else { |
|
17 | + } else { |
|
18 | 18 | $limit_explode = explode(",", $_GET['limit']); |
19 | 19 | $limit_start = $limit_explode[0]; |
20 | 20 | $limit_end = $limit_explode[1]; |
@@ -28,14 +28,14 @@ discard block |
||
28 | 28 | $limit_previous_1 = $limit_start - $absolute_difference; |
29 | 29 | $limit_previous_2 = $limit_end - $absolute_difference; |
30 | 30 | |
31 | - $marine_type = filter_input(INPUT_GET,'type',FILTER_SANITIZE_STRING); |
|
31 | + $marine_type = filter_input(INPUT_GET, 'type', FILTER_SANITIZE_STRING); |
|
32 | 32 | $page_url = $globalURL.'/marine/type/'.$marine_type; |
33 | - $sort = htmlspecialchars(filter_input(INPUT_GET,'sort',FILTER_SANITIZE_STRING)); |
|
34 | - $spotter_array = $Marine->getMarineDataByType($marine_type,$limit_start.",".$absolute_difference, $sort); |
|
33 | + $sort = htmlspecialchars(filter_input(INPUT_GET, 'sort', FILTER_SANITIZE_STRING)); |
|
34 | + $spotter_array = $Marine->getMarineDataByType($marine_type, $limit_start.",".$absolute_difference, $sort); |
|
35 | 35 | |
36 | 36 | if (!empty($spotter_array)) |
37 | 37 | { |
38 | - $title = sprintf(_("Detailed View for %s"),$spotter_array[0]['type']); |
|
38 | + $title = sprintf(_("Detailed View for %s"), $spotter_array[0]['type']); |
|
39 | 39 | require_once('header.php'); |
40 | 40 | |
41 | 41 | /* |
@@ -75,7 +75,7 @@ discard block |
||
75 | 75 | //include('aircraft-sub-menu.php'); |
76 | 76 | |
77 | 77 | print '<div class="table column">'; |
78 | - print '<p>'.sprintf(_("The table below shows the detailed information of all marine of type <strong>%s</strong>."),$spotter_array[0]['type']).'</p>'; |
|
78 | + print '<p>'.sprintf(_("The table below shows the detailed information of all marine of type <strong>%s</strong>."), $spotter_array[0]['type']).'</p>'; |
|
79 | 79 | |
80 | 80 | include('table-output.php'); |
81 | 81 |
@@ -14,7 +14,7 @@ |
||
14 | 14 | $limit_start = 0; |
15 | 15 | $limit_end = 25; |
16 | 16 | $absolute_difference = 25; |
17 | - } else { |
|
17 | + } else { |
|
18 | 18 | $limit_explode = explode(",", $_GET['limit']); |
19 | 19 | $limit_start = $limit_explode[0]; |
20 | 20 | $limit_end = $limit_explode[1]; |
@@ -7,8 +7,8 @@ discard block |
||
7 | 7 | |
8 | 8 | $type = 'marine'; |
9 | 9 | if (!isset($filter_name)) $filter_name = ''; |
10 | -$year = filter_input(INPUT_GET,'year',FILTER_SANITIZE_NUMBER_INT); |
|
11 | -$month = filter_input(INPUT_GET,'month',FILTER_SANITIZE_NUMBER_INT); |
|
10 | +$year = filter_input(INPUT_GET, 'year', FILTER_SANITIZE_NUMBER_INT); |
|
11 | +$month = filter_input(INPUT_GET, 'month', FILTER_SANITIZE_NUMBER_INT); |
|
12 | 12 | |
13 | 13 | require_once('header.php'); |
14 | 14 | |
@@ -20,10 +20,10 @@ discard block |
||
20 | 20 | </div> |
21 | 21 | <p>'._("Below are the <strong>Top 10</strong> most common vessel types.").'</p>'; |
22 | 22 | |
23 | -$type_array = $Marine->countAllMarineTypes(true,0,'',$filter_name,$year,$month); |
|
23 | +$type_array = $Marine->countAllMarineTypes(true, 0, '', $filter_name, $year, $month); |
|
24 | 24 | print '<div id="chart" class="chart" width="100%"></div><script>'; |
25 | 25 | $type_data = ''; |
26 | -foreach($type_array as $type_item) |
|
26 | +foreach ($type_array as $type_item) |
|
27 | 27 | { |
28 | 28 | $type_data .= '["'.$type_item['marine_type'].'",'.$type_item['marine_type_count'].'],'; |
29 | 29 | } |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | print '</thead>'; |
49 | 49 | print '<tbody>'; |
50 | 50 | $i = 1; |
51 | - foreach($type_array as $type_item) |
|
51 | + foreach ($type_array as $type_item) |
|
52 | 52 | { |
53 | 53 | print '<tr>'; |
54 | 54 | print '<td><strong>'.$i.'</strong></td>'; |
@@ -6,7 +6,9 @@ |
||
6 | 6 | $title = _("Statistics").' - '._("Most common Vessel Type"); |
7 | 7 | |
8 | 8 | $type = 'marine'; |
9 | -if (!isset($filter_name)) $filter_name = ''; |
|
9 | +if (!isset($filter_name)) { |
|
10 | + $filter_name = ''; |
|
11 | +} |
|
10 | 12 | $year = filter_input(INPUT_GET,'year',FILTER_SANITIZE_NUMBER_INT); |
11 | 13 | $month = filter_input(INPUT_GET,'month',FILTER_SANITIZE_NUMBER_INT); |
12 | 14 |
@@ -16,8 +16,8 @@ discard block |
||
16 | 16 | require_once(dirname(__FILE__).'/../require/class.Common.php'); |
17 | 17 | if (isset($globalTracker) && $globalTracker) require_once(dirname(__FILE__).'/../require/class.TrackerImport.php'); |
18 | 18 | if (isset($globalMarine) && $globalMarine) { |
19 | - require_once(dirname(__FILE__).'/../require/class.AIS.php'); |
|
20 | - require_once(dirname(__FILE__).'/../require/class.MarineImport.php'); |
|
19 | + require_once(dirname(__FILE__).'/../require/class.AIS.php'); |
|
20 | + require_once(dirname(__FILE__).'/../require/class.MarineImport.php'); |
|
21 | 21 | } |
22 | 22 | |
23 | 23 | if (!isset($globalDebug)) $globalDebug = FALSE; |
@@ -25,46 +25,46 @@ discard block |
||
25 | 25 | // Check if schema is at latest version |
26 | 26 | $Connection = new Connection(); |
27 | 27 | if ($Connection->connectionExists() === false) { |
28 | - echo "Can't connect to your database. Check DB is running, user/password and database logs."; |
|
29 | - exit(); |
|
28 | + echo "Can't connect to your database. Check DB is running, user/password and database logs."; |
|
29 | + exit(); |
|
30 | 30 | } |
31 | 31 | if ($Connection->latest() === false) { |
32 | - echo "You MUST update to latest schema. Run install/index.php"; |
|
33 | - exit(); |
|
32 | + echo "You MUST update to latest schema. Run install/index.php"; |
|
33 | + exit(); |
|
34 | 34 | } |
35 | 35 | if (PHP_SAPI != 'cli') { |
36 | - echo "This script MUST be called from console, not a web browser."; |
|
36 | + echo "This script MUST be called from console, not a web browser."; |
|
37 | 37 | // exit(); |
38 | 38 | } |
39 | 39 | |
40 | 40 | // This is to be compatible with old version of settings.php |
41 | 41 | if (!isset($globalSources)) { |
42 | - if (isset($globalSBS1Hosts)) { |
|
43 | - //$hosts = $globalSBS1Hosts; |
|
44 | - foreach ($globalSBS1Hosts as $host) { |
|
45 | - $globalSources[] = array('host' => $host); |
|
46 | - } |
|
47 | - } else { |
|
48 | - if (!isset($globalSBS1Host)) { |
|
49 | - echo '$globalSources MUST be defined !'; |
|
50 | - die; |
|
42 | + if (isset($globalSBS1Hosts)) { |
|
43 | + //$hosts = $globalSBS1Hosts; |
|
44 | + foreach ($globalSBS1Hosts as $host) { |
|
45 | + $globalSources[] = array('host' => $host); |
|
46 | + } |
|
47 | + } else { |
|
48 | + if (!isset($globalSBS1Host)) { |
|
49 | + echo '$globalSources MUST be defined !'; |
|
50 | + die; |
|
51 | 51 | } |
52 | 52 | //$hosts = array($globalSBS1Host.':'.$globalSBS1Port); |
53 | 53 | $globalSources[] = array('host' => $globalSBS1Host,'port' => $globalSBS1Port); |
54 | - } |
|
54 | + } |
|
55 | 55 | } |
56 | 56 | |
57 | 57 | $options = getopt('s::',array('source::','server','nodaemon','idsource::','aprsserverssid::','aprsserverpass::','aprsserverhost::','aprsserverport::','format::','noaprsserver','enable-aircraft','disable-aircraft','enable-tracker','disable-tracker','enable-marine','disable-marine')); |
58 | 58 | //if (isset($options['s'])) $hosts = array($options['s']); |
59 | 59 | //elseif (isset($options['source'])) $hosts = array($options['source']); |
60 | 60 | if (isset($options['s'])) { |
61 | - $globalSources = array(); |
|
62 | - if (isset($options['format'])) $globalSources[] = array('host' => $options['s'],'format' => $options['format']); |
|
63 | - else $globalSources[] = array('host' => $options['s']); |
|
61 | + $globalSources = array(); |
|
62 | + if (isset($options['format'])) $globalSources[] = array('host' => $options['s'],'format' => $options['format']); |
|
63 | + else $globalSources[] = array('host' => $options['s']); |
|
64 | 64 | } elseif (isset($options['source'])) { |
65 | - $globalSources = array(); |
|
66 | - if (isset($options['format'])) $globalSources[] = array('host' => $options['source'],'format' => $options['format']); |
|
67 | - else $globalSources[] = array('host' => $options['source']); |
|
65 | + $globalSources = array(); |
|
66 | + if (isset($options['format'])) $globalSources[] = array('host' => $options['source'],'format' => $options['format']); |
|
67 | + else $globalSources[] = array('host' => $options['source']); |
|
68 | 68 | } |
69 | 69 | if (isset($options['aprsserverhost'])) { |
70 | 70 | $globalServerAPRS = TRUE; |
@@ -103,8 +103,8 @@ discard block |
||
103 | 103 | if (isset($options['idsource'])) $id_source = $options['idsource']; |
104 | 104 | else $id_source = 1; |
105 | 105 | if (isset($globalServer) && $globalServer) { |
106 | - if ($globalDebug) echo "Using Server Mode\n"; |
|
107 | - $SI=new SpotterServer(); |
|
106 | + if ($globalDebug) echo "Using Server Mode\n"; |
|
107 | + $SI=new SpotterServer(); |
|
108 | 108 | /* |
109 | 109 | require_once(dirname(__FILE__).'/../require/class.APRS.php'); |
110 | 110 | $SI = new adsb2aprs(); |
@@ -114,14 +114,14 @@ discard block |
||
114 | 114 | |
115 | 115 | if (isset($globalTracker) && $globalTracker) require_once(dirname(__FILE__).'/../require/class.TrackerImport.php'); |
116 | 116 | if (isset($globalMarine) && $globalMarine) { |
117 | - require_once(dirname(__FILE__).'/../require/class.AIS.php'); |
|
118 | - require_once(dirname(__FILE__).'/../require/class.MarineImport.php'); |
|
117 | + require_once(dirname(__FILE__).'/../require/class.AIS.php'); |
|
118 | + require_once(dirname(__FILE__).'/../require/class.MarineImport.php'); |
|
119 | 119 | } |
120 | 120 | |
121 | 121 | if (isset($globalTracker) && $globalTracker) $TI = new TrackerImport($Connection->db); |
122 | 122 | if (isset($globalMarine) && $globalMarine) { |
123 | - $AIS = new AIS(); |
|
124 | - $MI = new MarineImport($Connection->db); |
|
123 | + $AIS = new AIS(); |
|
124 | + $MI = new MarineImport($Connection->db); |
|
125 | 125 | } |
126 | 126 | //$APRS=new APRS($Connection->db); |
127 | 127 | $SBS=new SBS(); |
@@ -134,12 +134,12 @@ discard block |
||
134 | 134 | //$servertz = system('date +%Z'); |
135 | 135 | // signal handler - playing nice with sockets and dump1090 |
136 | 136 | if (function_exists('pcntl_fork')) { |
137 | - pcntl_signal(SIGINT, function() { |
|
138 | - global $sockets; |
|
139 | - echo "\n\nctrl-c or kill signal received. Tidying up ... "; |
|
140 | - die("Bye!\n"); |
|
141 | - }); |
|
142 | - pcntl_signal_dispatch(); |
|
137 | + pcntl_signal(SIGINT, function() { |
|
138 | + global $sockets; |
|
139 | + echo "\n\nctrl-c or kill signal received. Tidying up ... "; |
|
140 | + die("Bye!\n"); |
|
141 | + }); |
|
142 | + pcntl_signal_dispatch(); |
|
143 | 143 | } |
144 | 144 | |
145 | 145 | // let's try and connect |
@@ -149,36 +149,36 @@ discard block |
||
149 | 149 | $reset = 0; |
150 | 150 | |
151 | 151 | function connect_all($hosts) { |
152 | - //global $sockets, $formats, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs; |
|
153 | - global $sockets,$httpfeeds, $globalSources, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs, $reset,$context; |
|
154 | - $reset++; |
|
155 | - if ($globalDebug) echo 'Connect to all...'."\n"; |
|
156 | - foreach ($hosts as $id => $value) { |
|
152 | + //global $sockets, $formats, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs; |
|
153 | + global $sockets,$httpfeeds, $globalSources, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs, $reset,$context; |
|
154 | + $reset++; |
|
155 | + if ($globalDebug) echo 'Connect to all...'."\n"; |
|
156 | + foreach ($hosts as $id => $value) { |
|
157 | 157 | $host = $value['host']; |
158 | 158 | $globalSources[$id]['last_exec'] = 0; |
159 | 159 | // Here we check type of source(s) |
160 | 160 | if (filter_var($host,FILTER_VALIDATE_URL) && (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto')) { |
161 | - if (preg_match('/deltadb.txt$/i',$host)) { |
|
162 | - //$formats[$id] = 'deltadbtxt'; |
|
163 | - $globalSources[$id]['format'] = 'deltadbtxt'; |
|
164 | - //$last_exec['deltadbtxt'] = 0; |
|
165 | - if ($globalDebug) echo "Connect to deltadb source (".$host.")...\n"; |
|
166 | - } else if (preg_match('/vatsim-data.txt$/i',$host)) { |
|
167 | - //$formats[$id] = 'vatsimtxt'; |
|
168 | - $globalSources[$id]['format'] = 'vatsimtxt'; |
|
169 | - //$last_exec['vatsimtxt'] = 0; |
|
170 | - if ($globalDebug) echo "Connect to vatsim source (".$host.")...\n"; |
|
171 | - } else if (preg_match('/aircraftlist.json$/i',$host)) { |
|
172 | - //$formats[$id] = 'aircraftlistjson'; |
|
173 | - $globalSources[$id]['format'] = 'aircraftlistjson'; |
|
174 | - //$last_exec['aircraftlistjson'] = 0; |
|
175 | - if ($globalDebug) echo "Connect to aircraftlist.json source (".$host.")...\n"; |
|
176 | - } else if (preg_match('/opensky/i',$host)) { |
|
177 | - //$formats[$id] = 'aircraftlistjson'; |
|
178 | - $globalSources[$id]['format'] = 'opensky'; |
|
179 | - //$last_exec['aircraftlistjson'] = 0; |
|
180 | - if ($globalDebug) echo "Connect to opensky source (".$host.")...\n"; |
|
181 | - /* |
|
161 | + if (preg_match('/deltadb.txt$/i',$host)) { |
|
162 | + //$formats[$id] = 'deltadbtxt'; |
|
163 | + $globalSources[$id]['format'] = 'deltadbtxt'; |
|
164 | + //$last_exec['deltadbtxt'] = 0; |
|
165 | + if ($globalDebug) echo "Connect to deltadb source (".$host.")...\n"; |
|
166 | + } else if (preg_match('/vatsim-data.txt$/i',$host)) { |
|
167 | + //$formats[$id] = 'vatsimtxt'; |
|
168 | + $globalSources[$id]['format'] = 'vatsimtxt'; |
|
169 | + //$last_exec['vatsimtxt'] = 0; |
|
170 | + if ($globalDebug) echo "Connect to vatsim source (".$host.")...\n"; |
|
171 | + } else if (preg_match('/aircraftlist.json$/i',$host)) { |
|
172 | + //$formats[$id] = 'aircraftlistjson'; |
|
173 | + $globalSources[$id]['format'] = 'aircraftlistjson'; |
|
174 | + //$last_exec['aircraftlistjson'] = 0; |
|
175 | + if ($globalDebug) echo "Connect to aircraftlist.json source (".$host.")...\n"; |
|
176 | + } else if (preg_match('/opensky/i',$host)) { |
|
177 | + //$formats[$id] = 'aircraftlistjson'; |
|
178 | + $globalSources[$id]['format'] = 'opensky'; |
|
179 | + //$last_exec['aircraftlistjson'] = 0; |
|
180 | + if ($globalDebug) echo "Connect to opensky source (".$host.")...\n"; |
|
181 | + /* |
|
182 | 182 | // Disabled for now, site change source format |
183 | 183 | } else if (preg_match('/radarvirtuel.com\/list_aircrafts$/i',$host)) { |
184 | 184 | //$formats[$id] = 'radarvirtueljson'; |
@@ -190,125 +190,125 @@ discard block |
||
190 | 190 | exit(0); |
191 | 191 | } |
192 | 192 | */ |
193 | - } else if (preg_match('/planeUpdateFAA.php$/i',$host)) { |
|
194 | - //$formats[$id] = 'planeupdatefaa'; |
|
195 | - $globalSources[$id]['format'] = 'planeupdatefaa'; |
|
196 | - //$last_exec['planeupdatefaa'] = 0; |
|
197 | - if ($globalDebug) echo "Connect to planeUpdateFAA.php source (".$host.")...\n"; |
|
198 | - if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) { |
|
199 | - echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n"; |
|
200 | - exit(0); |
|
201 | - } |
|
202 | - } else if (preg_match('/\/action.php\/acars\/data$/i',$host)) { |
|
203 | - //$formats[$id] = 'phpvmacars'; |
|
204 | - $globalSources[$id]['format'] = 'phpvmacars'; |
|
205 | - //$last_exec['phpvmacars'] = 0; |
|
206 | - if ($globalDebug) echo "Connect to phpvmacars source (".$host.")...\n"; |
|
207 | - } else if (preg_match('/\/api\/v1\/acars\/data$/i',$host)) { |
|
208 | - //$formats[$id] = 'phpvmacars'; |
|
209 | - $globalSources[$id]['format'] = 'vaos'; |
|
210 | - //$last_exec['phpvmacars'] = 0; |
|
211 | - if ($globalDebug) echo "Connect to vaos source (".$host.")...\n"; |
|
212 | - } else if (preg_match('/VAM-json.php$/i',$host)) { |
|
213 | - //$formats[$id] = 'phpvmacars'; |
|
214 | - $globalSources[$id]['format'] = 'vam'; |
|
215 | - if ($globalDebug) echo "Connect to Vam source (".$host.")...\n"; |
|
216 | - } else if (preg_match('/whazzup/i',$host)) { |
|
217 | - //$formats[$id] = 'whazzup'; |
|
218 | - $globalSources[$id]['format'] = 'whazzup'; |
|
219 | - //$last_exec['whazzup'] = 0; |
|
220 | - if ($globalDebug) echo "Connect to whazzup source (".$host.")...\n"; |
|
221 | - } else if (preg_match('/blitzortung/i',$host)) { |
|
222 | - $globalSources[$id]['format'] = 'blitzortung'; |
|
223 | - if ($globalDebug) echo "Connect to blitzortung source (".$host.")...\n"; |
|
224 | - } else if (preg_match('/airwhere/i',$host)) { |
|
225 | - $globalSources[$id]['format'] = 'airwhere'; |
|
226 | - if ($globalDebug) echo "Connect to airwhere source (".$host.")...\n"; |
|
227 | - } else if (preg_match('/recentpireps/i',$host)) { |
|
228 | - //$formats[$id] = 'pirepsjson'; |
|
229 | - $globalSources[$id]['format'] = 'pirepsjson'; |
|
230 | - //$last_exec['pirepsjson'] = 0; |
|
231 | - if ($globalDebug) echo "Connect to pirepsjson source (".$host.")...\n"; |
|
232 | - } else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i',$host)) { |
|
233 | - //$formats[$id] = 'fr24json'; |
|
234 | - $globalSources[$id]['format'] = 'fr24json'; |
|
235 | - //$last_exec['fr24json'] = 0; |
|
236 | - if ($globalDebug) echo "Connect to fr24 source (".$host.")...\n"; |
|
237 | - if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) { |
|
238 | - echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n"; |
|
239 | - exit(0); |
|
240 | - } |
|
241 | - } else if (preg_match(':myshiptracking.com/:i',$host)) { |
|
242 | - //$formats[$id] = 'fr24json'; |
|
243 | - $globalSources[$id]['format'] = 'myshiptracking'; |
|
244 | - //$last_exec['fr24json'] = 0; |
|
245 | - if ($globalDebug) echo "Connect to myshiptracking source (".$host.")...\n"; |
|
246 | - if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) { |
|
247 | - echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n"; |
|
248 | - exit(0); |
|
249 | - } |
|
250 | - //} else if (preg_match('/10001/',$host)) { |
|
251 | - } else if (preg_match('/10001/',$host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) { |
|
252 | - //$formats[$id] = 'tsv'; |
|
253 | - $globalSources[$id]['format'] = 'tsv'; |
|
254 | - if ($globalDebug) echo "Connect to tsv source (".$host.")...\n"; |
|
255 | - } |
|
256 | - } elseif (filter_var($host,FILTER_VALIDATE_URL)) { |
|
257 | - if ($globalSources[$id]['format'] == 'aisnmeahttp') { |
|
258 | - $idf = fopen($globalSources[$id]['host'],'r',false,$context); |
|
259 | - if ($idf !== false) { |
|
260 | - $httpfeeds[$id] = $idf; |
|
261 | - if ($globalDebug) echo "Connected to ".$globalSources[$id]['format']." source (".$host.")...\n"; |
|
262 | - } elseif ($globalDebug) echo "Can't connect to ".$globalSources[$id]['host']."\n"; |
|
263 | - } elseif ($globalDebug) echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n"; |
|
264 | - } elseif (!filter_var($host,FILTER_VALIDATE_URL)) { |
|
265 | - $hostport = explode(':',$host); |
|
266 | - if (isset($hostport[1])) { |
|
193 | + } else if (preg_match('/planeUpdateFAA.php$/i',$host)) { |
|
194 | + //$formats[$id] = 'planeupdatefaa'; |
|
195 | + $globalSources[$id]['format'] = 'planeupdatefaa'; |
|
196 | + //$last_exec['planeupdatefaa'] = 0; |
|
197 | + if ($globalDebug) echo "Connect to planeUpdateFAA.php source (".$host.")...\n"; |
|
198 | + if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) { |
|
199 | + echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n"; |
|
200 | + exit(0); |
|
201 | + } |
|
202 | + } else if (preg_match('/\/action.php\/acars\/data$/i',$host)) { |
|
203 | + //$formats[$id] = 'phpvmacars'; |
|
204 | + $globalSources[$id]['format'] = 'phpvmacars'; |
|
205 | + //$last_exec['phpvmacars'] = 0; |
|
206 | + if ($globalDebug) echo "Connect to phpvmacars source (".$host.")...\n"; |
|
207 | + } else if (preg_match('/\/api\/v1\/acars\/data$/i',$host)) { |
|
208 | + //$formats[$id] = 'phpvmacars'; |
|
209 | + $globalSources[$id]['format'] = 'vaos'; |
|
210 | + //$last_exec['phpvmacars'] = 0; |
|
211 | + if ($globalDebug) echo "Connect to vaos source (".$host.")...\n"; |
|
212 | + } else if (preg_match('/VAM-json.php$/i',$host)) { |
|
213 | + //$formats[$id] = 'phpvmacars'; |
|
214 | + $globalSources[$id]['format'] = 'vam'; |
|
215 | + if ($globalDebug) echo "Connect to Vam source (".$host.")...\n"; |
|
216 | + } else if (preg_match('/whazzup/i',$host)) { |
|
217 | + //$formats[$id] = 'whazzup'; |
|
218 | + $globalSources[$id]['format'] = 'whazzup'; |
|
219 | + //$last_exec['whazzup'] = 0; |
|
220 | + if ($globalDebug) echo "Connect to whazzup source (".$host.")...\n"; |
|
221 | + } else if (preg_match('/blitzortung/i',$host)) { |
|
222 | + $globalSources[$id]['format'] = 'blitzortung'; |
|
223 | + if ($globalDebug) echo "Connect to blitzortung source (".$host.")...\n"; |
|
224 | + } else if (preg_match('/airwhere/i',$host)) { |
|
225 | + $globalSources[$id]['format'] = 'airwhere'; |
|
226 | + if ($globalDebug) echo "Connect to airwhere source (".$host.")...\n"; |
|
227 | + } else if (preg_match('/recentpireps/i',$host)) { |
|
228 | + //$formats[$id] = 'pirepsjson'; |
|
229 | + $globalSources[$id]['format'] = 'pirepsjson'; |
|
230 | + //$last_exec['pirepsjson'] = 0; |
|
231 | + if ($globalDebug) echo "Connect to pirepsjson source (".$host.")...\n"; |
|
232 | + } else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i',$host)) { |
|
233 | + //$formats[$id] = 'fr24json'; |
|
234 | + $globalSources[$id]['format'] = 'fr24json'; |
|
235 | + //$last_exec['fr24json'] = 0; |
|
236 | + if ($globalDebug) echo "Connect to fr24 source (".$host.")...\n"; |
|
237 | + if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) { |
|
238 | + echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n"; |
|
239 | + exit(0); |
|
240 | + } |
|
241 | + } else if (preg_match(':myshiptracking.com/:i',$host)) { |
|
242 | + //$formats[$id] = 'fr24json'; |
|
243 | + $globalSources[$id]['format'] = 'myshiptracking'; |
|
244 | + //$last_exec['fr24json'] = 0; |
|
245 | + if ($globalDebug) echo "Connect to myshiptracking source (".$host.")...\n"; |
|
246 | + if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) { |
|
247 | + echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n"; |
|
248 | + exit(0); |
|
249 | + } |
|
250 | + //} else if (preg_match('/10001/',$host)) { |
|
251 | + } else if (preg_match('/10001/',$host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) { |
|
252 | + //$formats[$id] = 'tsv'; |
|
253 | + $globalSources[$id]['format'] = 'tsv'; |
|
254 | + if ($globalDebug) echo "Connect to tsv source (".$host.")...\n"; |
|
255 | + } |
|
256 | + } elseif (filter_var($host,FILTER_VALIDATE_URL)) { |
|
257 | + if ($globalSources[$id]['format'] == 'aisnmeahttp') { |
|
258 | + $idf = fopen($globalSources[$id]['host'],'r',false,$context); |
|
259 | + if ($idf !== false) { |
|
260 | + $httpfeeds[$id] = $idf; |
|
261 | + if ($globalDebug) echo "Connected to ".$globalSources[$id]['format']." source (".$host.")...\n"; |
|
262 | + } elseif ($globalDebug) echo "Can't connect to ".$globalSources[$id]['host']."\n"; |
|
263 | + } elseif ($globalDebug) echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n"; |
|
264 | + } elseif (!filter_var($host,FILTER_VALIDATE_URL)) { |
|
265 | + $hostport = explode(':',$host); |
|
266 | + if (isset($hostport[1])) { |
|
267 | 267 | $port = $hostport[1]; |
268 | 268 | $hostn = $hostport[0]; |
269 | - } else { |
|
269 | + } else { |
|
270 | 270 | $port = $globalSources[$id]['port']; |
271 | 271 | $hostn = $globalSources[$id]['host']; |
272 | - } |
|
273 | - $Common = new Common(); |
|
274 | - if (!isset($globalSources[$id]['format']) || ($globalSources[$id]['format'] != 'acars' && $globalSources[$id]['format'] != 'flightgearsp')) { |
|
275 | - $s = $Common->create_socket($hostn,$port, $errno, $errstr); |
|
276 | - } else { |
|
277 | - $s = $Common->create_socket_udp($hostn,$port, $errno, $errstr); |
|
278 | - } |
|
279 | - if ($s) { |
|
280 | - $sockets[$id] = $s; |
|
281 | - if (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto') { |
|
282 | - if (preg_match('/aprs/',$hostn) || $port == '10152' || $port == '14580') { |
|
272 | + } |
|
273 | + $Common = new Common(); |
|
274 | + if (!isset($globalSources[$id]['format']) || ($globalSources[$id]['format'] != 'acars' && $globalSources[$id]['format'] != 'flightgearsp')) { |
|
275 | + $s = $Common->create_socket($hostn,$port, $errno, $errstr); |
|
276 | + } else { |
|
277 | + $s = $Common->create_socket_udp($hostn,$port, $errno, $errstr); |
|
278 | + } |
|
279 | + if ($s) { |
|
280 | + $sockets[$id] = $s; |
|
281 | + if (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto') { |
|
282 | + if (preg_match('/aprs/',$hostn) || $port == '10152' || $port == '14580') { |
|
283 | 283 | //$formats[$id] = 'aprs'; |
284 | 284 | $globalSources[$id]['format'] = 'aprs'; |
285 | 285 | //$aprs_connect = 0; |
286 | 286 | //$use_aprs = true; |
287 | - } elseif (preg_match('/pub-vrs/',$hostn) || $port == '32001' || $port == '32005' || $port == '32010' || $port == '32015' || $port == '32030') { |
|
287 | + } elseif (preg_match('/pub-vrs/',$hostn) || $port == '32001' || $port == '32005' || $port == '32010' || $port == '32015' || $port == '32030') { |
|
288 | 288 | $globalSources[$id]['format'] = 'vrstcp'; |
289 | - } elseif ($port == '10001') { |
|
290 | - //$formats[$id] = 'tsv'; |
|
291 | - $globalSources[$id]['format'] = 'tsv'; |
|
292 | - } elseif ($port == '30002') { |
|
293 | - //$formats[$id] = 'raw'; |
|
294 | - $globalSources[$id]['format'] = 'raw'; |
|
295 | - } elseif ($port == '5001') { |
|
296 | - //$formats[$id] = 'raw'; |
|
297 | - $globalSources[$id]['format'] = 'flightgearmp'; |
|
298 | - } elseif ($port == '30005') { |
|
289 | + } elseif ($port == '10001') { |
|
290 | + //$formats[$id] = 'tsv'; |
|
291 | + $globalSources[$id]['format'] = 'tsv'; |
|
292 | + } elseif ($port == '30002') { |
|
293 | + //$formats[$id] = 'raw'; |
|
294 | + $globalSources[$id]['format'] = 'raw'; |
|
295 | + } elseif ($port == '5001') { |
|
296 | + //$formats[$id] = 'raw'; |
|
297 | + $globalSources[$id]['format'] = 'flightgearmp'; |
|
298 | + } elseif ($port == '30005') { |
|
299 | 299 | // Not yet supported |
300 | - //$formats[$id] = 'beast'; |
|
301 | - $globalSources[$id]['format'] = 'beast'; |
|
302 | - //} else $formats[$id] = 'sbs'; |
|
303 | - } else $globalSources[$id]['format'] = 'sbs'; |
|
304 | - //if ($globalDebug) echo 'Connection in progress to '.$host.'('.$formats[$id].')....'."\n"; |
|
300 | + //$formats[$id] = 'beast'; |
|
301 | + $globalSources[$id]['format'] = 'beast'; |
|
302 | + //} else $formats[$id] = 'sbs'; |
|
303 | + } else $globalSources[$id]['format'] = 'sbs'; |
|
304 | + //if ($globalDebug) echo 'Connection in progress to '.$host.'('.$formats[$id].')....'."\n"; |
|
305 | 305 | } |
306 | 306 | if ($globalDebug) echo 'Connection in progress to '.$hostn.':'.$port.' ('.$globalSources[$id]['format'].')....'."\n"; |
307 | - } else { |
|
307 | + } else { |
|
308 | 308 | if ($globalDebug) echo 'Connection failed to '.$hostn.':'.$port.' : '.$errno.' '.$errstr."\n"; |
309 | - } |
|
310 | - } |
|
311 | - } |
|
309 | + } |
|
310 | + } |
|
311 | + } |
|
312 | 312 | } |
313 | 313 | if (!isset($globalMinFetch)) $globalMinFetch = 15; |
314 | 314 | |
@@ -331,9 +331,9 @@ discard block |
||
331 | 331 | //connect_all($globalSources); |
332 | 332 | |
333 | 333 | if (isset($globalProxy) && $globalProxy) { |
334 | - $context = stream_context_create(array('http' => array('timeout' => $timeout,'proxy' => $globalProxy,'request_fulluri' => true))); |
|
334 | + $context = stream_context_create(array('http' => array('timeout' => $timeout,'proxy' => $globalProxy,'request_fulluri' => true))); |
|
335 | 335 | } else { |
336 | - $context = stream_context_create(array('http' => array('timeout' => $timeout))); |
|
336 | + $context = stream_context_create(array('http' => array('timeout' => $timeout))); |
|
337 | 337 | } |
338 | 338 | |
339 | 339 | // APRS Configuration |
@@ -342,21 +342,21 @@ discard block |
||
342 | 342 | die; |
343 | 343 | } |
344 | 344 | foreach ($globalSources as $key => $source) { |
345 | - if (!isset($source['format'])) { |
|
346 | - $globalSources[$key]['format'] = 'auto'; |
|
347 | - } |
|
348 | - if (isset($source['callback']) && $source['callback'] === TRUE) { |
|
349 | - unset($globalSources[$key]); |
|
350 | - } |
|
345 | + if (!isset($source['format'])) { |
|
346 | + $globalSources[$key]['format'] = 'auto'; |
|
347 | + } |
|
348 | + if (isset($source['callback']) && $source['callback'] === TRUE) { |
|
349 | + unset($globalSources[$key]); |
|
350 | + } |
|
351 | 351 | } |
352 | 352 | connect_all($globalSources); |
353 | 353 | foreach ($globalSources as $key => $source) { |
354 | - if (isset($source['format']) && $source['format'] == 'aprs') { |
|
354 | + if (isset($source['format']) && $source['format'] == 'aprs') { |
|
355 | 355 | $aprs_connect = 0; |
356 | 356 | $use_aprs = true; |
357 | 357 | if (isset($source['port']) && $source['port'] == '10152') $aprs_full = true; |
358 | 358 | break; |
359 | - } |
|
359 | + } |
|
360 | 360 | } |
361 | 361 | |
362 | 362 | if ($use_aprs) { |
@@ -397,131 +397,131 @@ discard block |
||
397 | 397 | |
398 | 398 | // Infinite loop if daemon, else work for time defined in $globalCronEnd or only one time. |
399 | 399 | while ($i > 0) { |
400 | - if (!$globalDaemon) $i = $endtime-time(); |
|
401 | - // Delete old ATC |
|
402 | - if ($globalDaemon && ((isset($globalVA) && $globalVA) || (isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) { |
|
400 | + if (!$globalDaemon) $i = $endtime-time(); |
|
401 | + // Delete old ATC |
|
402 | + if ($globalDaemon && ((isset($globalVA) && $globalVA) || (isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) { |
|
403 | 403 | if ($globalDebug) echo 'Delete old ATC...'."\n"; |
404 | - $ATC->deleteOldATC(); |
|
405 | - } |
|
404 | + $ATC->deleteOldATC(); |
|
405 | + } |
|
406 | 406 | |
407 | - if (count($last_exec) == count($globalSources)) { |
|
407 | + if (count($last_exec) == count($globalSources)) { |
|
408 | 408 | $max = $globalMinFetch; |
409 | 409 | foreach ($last_exec as $last) { |
410 | - if ((time() - $last['last']) < $max) $max = time() - $last['last']; |
|
410 | + if ((time() - $last['last']) < $max) $max = time() - $last['last']; |
|
411 | 411 | } |
412 | 412 | if ($max != $globalMinFetch) { |
413 | - if ($globalDebug) echo 'Sleeping...'."\n"; |
|
414 | - sleep($globalMinFetch-$max+2); |
|
413 | + if ($globalDebug) echo 'Sleeping...'."\n"; |
|
414 | + sleep($globalMinFetch-$max+2); |
|
415 | + } |
|
415 | 416 | } |
416 | - } |
|
417 | 417 | |
418 | 418 | |
419 | - //foreach ($formats as $id => $value) { |
|
420 | - foreach ($globalSources as $id => $value) { |
|
419 | + //foreach ($formats as $id => $value) { |
|
420 | + foreach ($globalSources as $id => $value) { |
|
421 | 421 | date_default_timezone_set('UTC'); |
422 | 422 | //if ($globalDebug) echo 'Source host : '.$value['host'].' - Source format: '.$value['format']."\n"; |
423 | 423 | if (!isset($last_exec[$id]['last'])) $last_exec[$id]['last'] = 0; |
424 | 424 | if ($value['format'] == 'deltadbtxt' && |
425 | - ( |
|
425 | + ( |
|
426 | 426 | (isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || |
427 | 427 | (!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch)) |
428 | - ) |
|
428 | + ) |
|
429 | 429 | ) { |
430 | - //$buffer = $Common->getData($hosts[$id]); |
|
431 | - $buffer = $Common->getData($value['host']); |
|
432 | - if ($buffer != '') $reset = 0; |
|
433 | - $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer)); |
|
434 | - $buffer = explode('\n',$buffer); |
|
435 | - foreach ($buffer as $line) { |
|
436 | - if ($line != '' && count($line) > 7) { |
|
437 | - $line = explode(',', $line); |
|
438 | - $data = array(); |
|
439 | - $data['hex'] = $line[1]; // hex |
|
440 | - $data['ident'] = $line[2]; // ident |
|
441 | - if (isset($line[3])) $data['altitude'] = $line[3]; // altitude |
|
442 | - if (isset($line[4])) $data['speed'] = $line[4]; // speed |
|
443 | - if (isset($line[5])) $data['heading'] = $line[5]; // heading |
|
444 | - if (isset($line[6])) $data['latitude'] = $line[6]; // lat |
|
445 | - if (isset($line[7])) $data['longitude'] = $line[7]; // long |
|
446 | - $data['verticalrate'] = ''; // vertical rate |
|
447 | - //if (isset($line[9])) $data['squawk'] = $line[9]; // squawk |
|
448 | - $data['emergency'] = ''; // emergency |
|
449 | - $data['datetime'] = date('Y-m-d H:i:s'); |
|
450 | - $data['format_source'] = 'deltadbtxt'; |
|
451 | - $data['id_source'] = $id_source; |
|
452 | - if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name']; |
|
453 | - if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true; |
|
454 | - if (isset($value['sourcestats'])) $data['sourcestats'] = $value['sourcestats']; |
|
455 | - $SI->add($data); |
|
456 | - unset($data); |
|
457 | - } |
|
458 | - } |
|
459 | - $last_exec[$id]['last'] = time(); |
|
430 | + //$buffer = $Common->getData($hosts[$id]); |
|
431 | + $buffer = $Common->getData($value['host']); |
|
432 | + if ($buffer != '') $reset = 0; |
|
433 | + $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer)); |
|
434 | + $buffer = explode('\n',$buffer); |
|
435 | + foreach ($buffer as $line) { |
|
436 | + if ($line != '' && count($line) > 7) { |
|
437 | + $line = explode(',', $line); |
|
438 | + $data = array(); |
|
439 | + $data['hex'] = $line[1]; // hex |
|
440 | + $data['ident'] = $line[2]; // ident |
|
441 | + if (isset($line[3])) $data['altitude'] = $line[3]; // altitude |
|
442 | + if (isset($line[4])) $data['speed'] = $line[4]; // speed |
|
443 | + if (isset($line[5])) $data['heading'] = $line[5]; // heading |
|
444 | + if (isset($line[6])) $data['latitude'] = $line[6]; // lat |
|
445 | + if (isset($line[7])) $data['longitude'] = $line[7]; // long |
|
446 | + $data['verticalrate'] = ''; // vertical rate |
|
447 | + //if (isset($line[9])) $data['squawk'] = $line[9]; // squawk |
|
448 | + $data['emergency'] = ''; // emergency |
|
449 | + $data['datetime'] = date('Y-m-d H:i:s'); |
|
450 | + $data['format_source'] = 'deltadbtxt'; |
|
451 | + $data['id_source'] = $id_source; |
|
452 | + if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name']; |
|
453 | + if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true; |
|
454 | + if (isset($value['sourcestats'])) $data['sourcestats'] = $value['sourcestats']; |
|
455 | + $SI->add($data); |
|
456 | + unset($data); |
|
457 | + } |
|
458 | + } |
|
459 | + $last_exec[$id]['last'] = time(); |
|
460 | 460 | } elseif ($value['format'] == 'aisnmeatxt' && |
461 | - ( |
|
461 | + ( |
|
462 | 462 | (isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || |
463 | 463 | (!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch*3)) |
464 | - ) |
|
464 | + ) |
|
465 | 465 | ) { |
466 | - date_default_timezone_set('CET'); |
|
467 | - $buffer = $Common->getData(str_replace('{date}',date('Ymd'),$value['host'])); |
|
468 | - date_default_timezone_set('UTC'); |
|
469 | - if ($buffer != '') $reset = 0; |
|
470 | - $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer)); |
|
471 | - $buffer = explode('\n',$buffer); |
|
472 | - foreach ($buffer as $line) { |
|
466 | + date_default_timezone_set('CET'); |
|
467 | + $buffer = $Common->getData(str_replace('{date}',date('Ymd'),$value['host'])); |
|
468 | + date_default_timezone_set('UTC'); |
|
469 | + if ($buffer != '') $reset = 0; |
|
470 | + $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer)); |
|
471 | + $buffer = explode('\n',$buffer); |
|
472 | + foreach ($buffer as $line) { |
|
473 | 473 | if ($line != '') { |
474 | - //echo "'".$line."'\n"; |
|
475 | - $add = false; |
|
476 | - $ais_data = $AIS->parse_line(trim($line)); |
|
477 | - $data = array(); |
|
478 | - if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident']; |
|
479 | - if (isset($ais_data['mmsi'])) $data['mmsi'] = substr($ais_data['mmsi'],-9); |
|
480 | - if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed']; |
|
481 | - if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading']; |
|
482 | - if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude']; |
|
483 | - if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude']; |
|
484 | - if (isset($ais_data['status'])) $data['status'] = $ais_data['status']; |
|
485 | - if (isset($ais_data['statusid'])) $data['status_id'] = $ais_data['statusid']; |
|
486 | - if (isset($ais_data['type'])) $data['type'] = $ais_data['type']; |
|
487 | - if (isset($ais_data['typeid'])) $data['type_id'] = $ais_data['typeid']; |
|
488 | - if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo']; |
|
489 | - if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign']; |
|
490 | - if (isset($ais_data['timestamp'])) { |
|
474 | + //echo "'".$line."'\n"; |
|
475 | + $add = false; |
|
476 | + $ais_data = $AIS->parse_line(trim($line)); |
|
477 | + $data = array(); |
|
478 | + if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident']; |
|
479 | + if (isset($ais_data['mmsi'])) $data['mmsi'] = substr($ais_data['mmsi'],-9); |
|
480 | + if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed']; |
|
481 | + if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading']; |
|
482 | + if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude']; |
|
483 | + if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude']; |
|
484 | + if (isset($ais_data['status'])) $data['status'] = $ais_data['status']; |
|
485 | + if (isset($ais_data['statusid'])) $data['status_id'] = $ais_data['statusid']; |
|
486 | + if (isset($ais_data['type'])) $data['type'] = $ais_data['type']; |
|
487 | + if (isset($ais_data['typeid'])) $data['type_id'] = $ais_data['typeid']; |
|
488 | + if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo']; |
|
489 | + if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign']; |
|
490 | + if (isset($ais_data['timestamp'])) { |
|
491 | 491 | $data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']); |
492 | 492 | if (!isset($last_exec[$id]['timestamp']) || $ais_data['timestamp'] >= $last_exec[$id]['timestamp']) { |
493 | - $last_exec[$id]['timestamp'] = $ais_data['timestamp']; |
|
494 | - $add = true; |
|
493 | + $last_exec[$id]['timestamp'] = $ais_data['timestamp']; |
|
494 | + $add = true; |
|
495 | 495 | } |
496 | - } else { |
|
496 | + } else { |
|
497 | 497 | $data['datetime'] = date('Y-m-d H:i:s'); |
498 | 498 | $add = true; |
499 | - } |
|
500 | - $data['format_source'] = 'aisnmeatxt'; |
|
501 | - $data['id_source'] = $id_source; |
|
502 | - //print_r($data); |
|
503 | - if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true; |
|
504 | - if ($add && isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') $MI->add($data); |
|
505 | - unset($data); |
|
499 | + } |
|
500 | + $data['format_source'] = 'aisnmeatxt'; |
|
501 | + $data['id_source'] = $id_source; |
|
502 | + //print_r($data); |
|
503 | + if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true; |
|
504 | + if ($add && isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') $MI->add($data); |
|
505 | + unset($data); |
|
506 | 506 | } |
507 | - } |
|
508 | - $last_exec[$id]['last'] = time(); |
|
507 | + } |
|
508 | + $last_exec[$id]['last'] = time(); |
|
509 | 509 | } elseif ($value['format'] == 'aisnmeahttp') { |
510 | - $arr = $httpfeeds; |
|
511 | - $w = $e = null; |
|
510 | + $arr = $httpfeeds; |
|
511 | + $w = $e = null; |
|
512 | 512 | |
513 | - if (isset($arr[$id])) { |
|
513 | + if (isset($arr[$id])) { |
|
514 | 514 | $nn = stream_select($arr,$w,$e,$timeout); |
515 | 515 | if ($nn > 0) { |
516 | - foreach ($httpfeeds as $feed) { |
|
516 | + foreach ($httpfeeds as $feed) { |
|
517 | 517 | $buffer = stream_get_line($feed,2000,"\n"); |
518 | 518 | if ($buffer === FALSE) { |
519 | - connect_all($globalSources); |
|
519 | + connect_all($globalSources); |
|
520 | 520 | } |
521 | 521 | $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer)); |
522 | 522 | $buffer = explode('\n',$buffer); |
523 | 523 | foreach ($buffer as $line) { |
524 | - if ($line != '') { |
|
524 | + if ($line != '') { |
|
525 | 525 | $ais_data = $AIS->parse_line(trim($line)); |
526 | 526 | $data = array(); |
527 | 527 | if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident']; |
@@ -539,117 +539,117 @@ discard block |
||
539 | 539 | if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination']; |
540 | 540 | if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']); |
541 | 541 | if (isset($ais_data['timestamp'])) { |
542 | - $data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']); |
|
542 | + $data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']); |
|
543 | 543 | } else { |
544 | - $data['datetime'] = date('Y-m-d H:i:s'); |
|
544 | + $data['datetime'] = date('Y-m-d H:i:s'); |
|
545 | 545 | } |
546 | 546 | $data['format_source'] = 'aisnmeahttp'; |
547 | 547 | $data['id_source'] = $id_source; |
548 | 548 | if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true; |
549 | 549 | if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') $MI->add($data); |
550 | 550 | unset($data); |
551 | - } |
|
551 | + } |
|
552 | + } |
|
552 | 553 | } |
553 | - } |
|
554 | 554 | } else { |
555 | - $format = $value['format']; |
|
556 | - if (isset($tt[$format])) $tt[$format]++; |
|
557 | - else $tt[$format] = 0; |
|
558 | - if ($tt[$format] > 30) { |
|
555 | + $format = $value['format']; |
|
556 | + if (isset($tt[$format])) $tt[$format]++; |
|
557 | + else $tt[$format] = 0; |
|
558 | + if ($tt[$format] > 30) { |
|
559 | 559 | if ($globalDebug) echo 'Reconnect...'."\n"; |
560 | 560 | sleep(2); |
561 | 561 | //$sourceeen[] = $value; |
562 | 562 | //connect_all($sourceeen); |
563 | 563 | //$sourceeen = array(); |
564 | 564 | connect_all($globalSources); |
565 | - } |
|
565 | + } |
|
566 | + } |
|
566 | 567 | } |
567 | - } |
|
568 | 568 | } elseif ($value['format'] == 'myshiptracking' && |
569 | - ( |
|
569 | + ( |
|
570 | 570 | (isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || |
571 | 571 | (!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch*3)) |
572 | - ) |
|
572 | + ) |
|
573 | 573 | ) { |
574 | - $buffer = $Common->getData($value['host'],'get','','','','','20'); |
|
575 | - if ($buffer != '') { |
|
574 | + $buffer = $Common->getData($value['host'],'get','','','','','20'); |
|
575 | + if ($buffer != '') { |
|
576 | 576 | //echo $buffer; |
577 | 577 | $all_data = json_decode($buffer,true); |
578 | 578 | //print_r($all_data); |
579 | 579 | if (isset($all_data[0]['DATA'])) { |
580 | - foreach ($all_data[0]['DATA'] as $line) { |
|
580 | + foreach ($all_data[0]['DATA'] as $line) { |
|
581 | 581 | if ($line != '') { |
582 | - $data = array(); |
|
583 | - $data['ident'] = $line['NAME']; |
|
584 | - $data['mmsi'] = $line['MMSI']; |
|
585 | - if (strlen($data['mmsi']) > 9) { |
|
582 | + $data = array(); |
|
583 | + $data['ident'] = $line['NAME']; |
|
584 | + $data['mmsi'] = $line['MMSI']; |
|
585 | + if (strlen($data['mmsi']) > 9) { |
|
586 | 586 | $data['mmsi'] = substr($data['mmsi'],-9); |
587 | - } |
|
588 | - $data['speed'] = $line['SOG']; |
|
589 | - $data['heading'] = $line['COG']; |
|
590 | - $data['latitude'] = $line['LAT']; |
|
591 | - $data['longitude'] = $line['LNG']; |
|
592 | - // if (isset($ais_data['type'])) $data['type'] = $ais_data['type']; |
|
593 | - //$data['type_id'] = $line['TYPE']; |
|
594 | - $data['imo'] = $line['IMO']; |
|
595 | - if ($line['DEST'] != '') $data['arrival_code'] = $line['DEST']; |
|
596 | - if ($line['ARV'] != '') $data['arrival_time'] = date('Y-m-d H:i:s',strtotime($line['ARV'])); |
|
597 | - $data['datetime'] = date('Y-m-d H:i:s',$line['T']); |
|
598 | - $data['format_source'] = 'myshiptracking'; |
|
599 | - $data['id_source'] = $id_source; |
|
600 | - if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true; |
|
601 | - $MI->add($data); |
|
602 | - unset($data); |
|
587 | + } |
|
588 | + $data['speed'] = $line['SOG']; |
|
589 | + $data['heading'] = $line['COG']; |
|
590 | + $data['latitude'] = $line['LAT']; |
|
591 | + $data['longitude'] = $line['LNG']; |
|
592 | + // if (isset($ais_data['type'])) $data['type'] = $ais_data['type']; |
|
593 | + //$data['type_id'] = $line['TYPE']; |
|
594 | + $data['imo'] = $line['IMO']; |
|
595 | + if ($line['DEST'] != '') $data['arrival_code'] = $line['DEST']; |
|
596 | + if ($line['ARV'] != '') $data['arrival_time'] = date('Y-m-d H:i:s',strtotime($line['ARV'])); |
|
597 | + $data['datetime'] = date('Y-m-d H:i:s',$line['T']); |
|
598 | + $data['format_source'] = 'myshiptracking'; |
|
599 | + $data['id_source'] = $id_source; |
|
600 | + if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true; |
|
601 | + $MI->add($data); |
|
602 | + unset($data); |
|
603 | + } |
|
603 | 604 | } |
604 | - } |
|
605 | 605 | } |
606 | - } |
|
607 | - $last_exec[$id]['last'] = time(); |
|
606 | + } |
|
607 | + $last_exec[$id]['last'] = time(); |
|
608 | 608 | } elseif ($value['format'] == 'boatbeaconapp' && |
609 | - ( |
|
609 | + ( |
|
610 | 610 | (isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || |
611 | 611 | (!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch*3)) |
612 | - ) |
|
612 | + ) |
|
613 | 613 | ) { |
614 | - $buffer = $Common->getData(str_replace('{timestamp}',time(),$value['host'])); |
|
615 | - if ($buffer != '') { |
|
614 | + $buffer = $Common->getData(str_replace('{timestamp}',time(),$value['host'])); |
|
615 | + if ($buffer != '') { |
|
616 | 616 | $all_data = json_decode($buffer,true); |
617 | 617 | if (isset($all_data[0]['mmsi'])) { |
618 | - foreach ($all_data as $line) { |
|
618 | + foreach ($all_data as $line) { |
|
619 | 619 | if ($line != '') { |
620 | - $data = array(); |
|
621 | - $data['ident'] = $line['shipname']; |
|
622 | - $data['callsign'] = $line['callsign']; |
|
623 | - $data['mmsi'] = substr($line['mmsi'],-9); |
|
624 | - $data['speed'] = $line['sog']; |
|
625 | - if ($line['heading'] != '511') $data['heading'] = $line['heading']; |
|
626 | - $data['latitude'] = $line['latitude']; |
|
627 | - $data['longitude'] = $line['longitude']; |
|
628 | - $data['type_id'] = $line['shiptype']; |
|
629 | - $data['arrival_code'] = $line['destination']; |
|
630 | - $data['datetime'] = $line['time']; |
|
631 | - $data['format_source'] = 'boatbeaconapp'; |
|
632 | - $data['id_source'] = $id_source; |
|
633 | - if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true; |
|
634 | - $MI->add($data); |
|
635 | - unset($data); |
|
620 | + $data = array(); |
|
621 | + $data['ident'] = $line['shipname']; |
|
622 | + $data['callsign'] = $line['callsign']; |
|
623 | + $data['mmsi'] = substr($line['mmsi'],-9); |
|
624 | + $data['speed'] = $line['sog']; |
|
625 | + if ($line['heading'] != '511') $data['heading'] = $line['heading']; |
|
626 | + $data['latitude'] = $line['latitude']; |
|
627 | + $data['longitude'] = $line['longitude']; |
|
628 | + $data['type_id'] = $line['shiptype']; |
|
629 | + $data['arrival_code'] = $line['destination']; |
|
630 | + $data['datetime'] = $line['time']; |
|
631 | + $data['format_source'] = 'boatbeaconapp'; |
|
632 | + $data['id_source'] = $id_source; |
|
633 | + if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true; |
|
634 | + $MI->add($data); |
|
635 | + unset($data); |
|
636 | + } |
|
636 | 637 | } |
637 | - } |
|
638 | 638 | } |
639 | 639 | |
640 | - } |
|
641 | - $last_exec[$id]['last'] = time(); |
|
640 | + } |
|
641 | + $last_exec[$id]['last'] = time(); |
|
642 | 642 | } elseif ($value['format'] == 'boatnerd' && |
643 | - ( |
|
643 | + ( |
|
644 | 644 | (isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || |
645 | 645 | (!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch*3)) |
646 | - ) |
|
646 | + ) |
|
647 | 647 | ) { |
648 | - $buffer = $Common->getData($value['host']); |
|
649 | - if ($buffer != '') { |
|
648 | + $buffer = $Common->getData($value['host']); |
|
649 | + if ($buffer != '') { |
|
650 | 650 | $all_data = json_decode($buffer,true); |
651 | 651 | if (isset($all_data['features'][0]['id'])) { |
652 | - foreach ($all_data['features'] as $line) { |
|
652 | + foreach ($all_data['features'] as $line) { |
|
653 | 653 | print_r($line); |
654 | 654 | $data = array(); |
655 | 655 | if (isset($line['properties']['name'])) $data['ident'] = $line['properties']['name']; |
@@ -669,80 +669,80 @@ discard block |
||
669 | 669 | if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true; |
670 | 670 | if ($line['properties']['vesselType'] != 'Navigation Aid') $MI->add($data); |
671 | 671 | unset($data); |
672 | - } |
|
672 | + } |
|
673 | 673 | } |
674 | 674 | |
675 | - } |
|
676 | - $last_exec[$id]['last'] = time(); |
|
675 | + } |
|
676 | + $last_exec[$id]['last'] = time(); |
|
677 | 677 | } elseif ($value['format'] == 'shipplotter' && |
678 | - ( |
|
678 | + ( |
|
679 | 679 | (isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || |
680 | 680 | (!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch*3)) |
681 | - ) |
|
681 | + ) |
|
682 | 682 | ) { |
683 | - echo 'download...'; |
|
684 | - $buffer = $Common->getData($value['host'],'post',$value['post'],'','','','','ShipPlotter'); |
|
685 | - echo 'done !'."\n"; |
|
686 | - // FIXME: Need more work |
|
687 | - if ($buffer != '') $reset = 0; |
|
688 | - $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer)); |
|
689 | - $buffer = explode('\n',$buffer); |
|
690 | - foreach ($buffer as $line) { |
|
683 | + echo 'download...'; |
|
684 | + $buffer = $Common->getData($value['host'],'post',$value['post'],'','','','','ShipPlotter'); |
|
685 | + echo 'done !'."\n"; |
|
686 | + // FIXME: Need more work |
|
687 | + if ($buffer != '') $reset = 0; |
|
688 | + $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer)); |
|
689 | + $buffer = explode('\n',$buffer); |
|
690 | + foreach ($buffer as $line) { |
|
691 | 691 | if ($line != '') { |
692 | - $data = array(); |
|
693 | - echo $line."\n"; |
|
694 | - $data['mmsi'] = (int)substr($line,0,9); |
|
695 | - $data['datetime'] = date('Y-m-d H:i:s',substr($line,10,10)); |
|
696 | - $data['status_id'] = substr($line,21,2); |
|
697 | - $data['type_id'] = substr($line,24,3); |
|
698 | - $data['latitude'] = substr($line,29,9); |
|
699 | - $data['longitude'] = substr($line,41,9); |
|
700 | - $data['speed'] = round(substr($line,51,5)); |
|
701 | - //$data['course'] = substr($line,57,5); |
|
702 | - $data['heading'] = round(substr($line,63,3)); |
|
703 | - //$data['draft'] = substr($line,67,4); |
|
704 | - //$data['length'] = substr($line,72,3); |
|
705 | - //$data['beam'] = substr($line,76,2); |
|
706 | - $data['ident'] = trim(utf8_encode(substr($line,78,20))); |
|
707 | - //$data['callsign'] = trim(substr($line,100,7); |
|
708 | - $data['arrival_code'] = substr($line,108,20); |
|
709 | - //$data['etaDate'] = substr($line,129,5); |
|
710 | - //$data['etaTime'] = substr($line,135,5); |
|
711 | - $data['format_source'] = 'shipplotter'; |
|
712 | - $data['id_source'] = $id_source; |
|
713 | - if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true; |
|
714 | - //print_r($data); |
|
715 | - echo 'Add...'."\n"; |
|
716 | - $MI->add($data); |
|
717 | - unset($data); |
|
692 | + $data = array(); |
|
693 | + echo $line."\n"; |
|
694 | + $data['mmsi'] = (int)substr($line,0,9); |
|
695 | + $data['datetime'] = date('Y-m-d H:i:s',substr($line,10,10)); |
|
696 | + $data['status_id'] = substr($line,21,2); |
|
697 | + $data['type_id'] = substr($line,24,3); |
|
698 | + $data['latitude'] = substr($line,29,9); |
|
699 | + $data['longitude'] = substr($line,41,9); |
|
700 | + $data['speed'] = round(substr($line,51,5)); |
|
701 | + //$data['course'] = substr($line,57,5); |
|
702 | + $data['heading'] = round(substr($line,63,3)); |
|
703 | + //$data['draft'] = substr($line,67,4); |
|
704 | + //$data['length'] = substr($line,72,3); |
|
705 | + //$data['beam'] = substr($line,76,2); |
|
706 | + $data['ident'] = trim(utf8_encode(substr($line,78,20))); |
|
707 | + //$data['callsign'] = trim(substr($line,100,7); |
|
708 | + $data['arrival_code'] = substr($line,108,20); |
|
709 | + //$data['etaDate'] = substr($line,129,5); |
|
710 | + //$data['etaTime'] = substr($line,135,5); |
|
711 | + $data['format_source'] = 'shipplotter'; |
|
712 | + $data['id_source'] = $id_source; |
|
713 | + if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true; |
|
714 | + //print_r($data); |
|
715 | + echo 'Add...'."\n"; |
|
716 | + $MI->add($data); |
|
717 | + unset($data); |
|
718 | 718 | } |
719 | - } |
|
720 | - $last_exec[$id]['last'] = time(); |
|
719 | + } |
|
720 | + $last_exec[$id]['last'] = time(); |
|
721 | 721 | //} elseif (($value == 'whazzup' && (time() - $last_exec['whazzup'] > $globalMinFetch)) || ($value == 'vatsimtxt' && (time() - $last_exec['vatsimtxt'] > $globalMinFetch))) { |
722 | 722 | } elseif ( |
723 | - ( |
|
723 | + ( |
|
724 | 724 | $value['format'] == 'whazzup' && |
725 | 725 | ( |
726 | - (isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || |
|
727 | - (!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch)) |
|
726 | + (isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || |
|
727 | + (!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch)) |
|
728 | 728 | ) |
729 | - ) || ( |
|
729 | + ) || ( |
|
730 | 730 | $value['format'] == 'vatsimtxt' && |
731 | 731 | ( |
732 | - (isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || |
|
733 | - (!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch)) |
|
732 | + (isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || |
|
733 | + (!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch)) |
|
734 | + ) |
|
734 | 735 | ) |
735 | - ) |
|
736 | 736 | ) { |
737 | - //$buffer = $Common->getData($hosts[$id]); |
|
738 | - $buffer = $Common->getData($value['host']); |
|
739 | - $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer)); |
|
740 | - $buffer = explode('\n',$buffer); |
|
741 | - $reset = 0; |
|
742 | - foreach ($buffer as $line) { |
|
743 | - if ($line != '') { |
|
744 | - $line = explode(':', $line); |
|
745 | - if (count($line) > 30 && $line[0] != 'callsign') { |
|
737 | + //$buffer = $Common->getData($hosts[$id]); |
|
738 | + $buffer = $Common->getData($value['host']); |
|
739 | + $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer)); |
|
740 | + $buffer = explode('\n',$buffer); |
|
741 | + $reset = 0; |
|
742 | + foreach ($buffer as $line) { |
|
743 | + if ($line != '') { |
|
744 | + $line = explode(':', $line); |
|
745 | + if (count($line) > 30 && $line[0] != 'callsign') { |
|
746 | 746 | $data = array(); |
747 | 747 | if (isset($line[37]) && $line[37] != '') $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0].'-'.$line[37]; |
748 | 748 | else $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0]; |
@@ -755,37 +755,37 @@ discard block |
||
755 | 755 | if (isset($line[45])) $data['heading'] = $line[45]; // heading |
756 | 756 | elseif (isset($line[38])) $data['heading'] = $line[38]; // heading |
757 | 757 | $data['latitude'] = $line[5]; // lat |
758 | - $data['longitude'] = $line[6]; // long |
|
759 | - $data['verticalrate'] = ''; // vertical rate |
|
760 | - $data['squawk'] = ''; // squawk |
|
761 | - $data['emergency'] = ''; // emergency |
|
762 | - $data['waypoints'] = $line[30]; |
|
758 | + $data['longitude'] = $line[6]; // long |
|
759 | + $data['verticalrate'] = ''; // vertical rate |
|
760 | + $data['squawk'] = ''; // squawk |
|
761 | + $data['emergency'] = ''; // emergency |
|
762 | + $data['waypoints'] = $line[30]; |
|
763 | 763 | $data['datetime'] = date('Y-m-d H:i:s'); |
764 | 764 | //$data['datetime'] = date('Y-m-d H:i:s',strtotime($line[37])); |
765 | 765 | //if (isset($line[37])) $data['last_update'] = $line[37]; |
766 | - $data['departure_airport_icao'] = $line[11]; |
|
767 | - $data['departure_airport_time'] = rtrim(chunk_split($line[22],2,':'),':'); |
|
768 | - $data['arrival_airport_icao'] = $line[13]; |
|
766 | + $data['departure_airport_icao'] = $line[11]; |
|
767 | + $data['departure_airport_time'] = rtrim(chunk_split($line[22],2,':'),':'); |
|
768 | + $data['arrival_airport_icao'] = $line[13]; |
|
769 | 769 | $data['frequency'] = $line[4]; |
770 | 770 | $data['type'] = $line[18]; |
771 | 771 | $data['range'] = $line[19]; |
772 | 772 | if (isset($line[35])) $data['info'] = $line[35]; |
773 | - $data['id_source'] = $id_source; |
|
774 | - //$data['arrival_airport_time'] = ; |
|
775 | - if ($line[9] != '') { |
|
776 | - $aircraft_data = explode('/',$line[9]); |
|
777 | - if (isset($aircraft_data[1])) { |
|
778 | - $data['aircraft_icao'] = $aircraft_data[1]; |
|
779 | - } |
|
780 | - } |
|
781 | - /* |
|
773 | + $data['id_source'] = $id_source; |
|
774 | + //$data['arrival_airport_time'] = ; |
|
775 | + if ($line[9] != '') { |
|
776 | + $aircraft_data = explode('/',$line[9]); |
|
777 | + if (isset($aircraft_data[1])) { |
|
778 | + $data['aircraft_icao'] = $aircraft_data[1]; |
|
779 | + } |
|
780 | + } |
|
781 | + /* |
|
782 | 782 | if ($value == 'whazzup') $data['format_source'] = 'whazzup'; |
783 | 783 | elseif ($value == 'vatsimtxt') $data['format_source'] = 'vatsimtxt'; |
784 | 784 | */ |
785 | - $data['format_source'] = $value['format']; |
|
785 | + $data['format_source'] = $value['format']; |
|
786 | 786 | if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true; |
787 | 787 | if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name']; |
788 | - if ($line[3] == 'PILOT') $SI->add($data); |
|
788 | + if ($line[3] == 'PILOT') $SI->add($data); |
|
789 | 789 | elseif ($line[3] == 'ATC') { |
790 | 790 | //print_r($data); |
791 | 791 | $data['info'] = str_replace('^§','<br />',$data['info']); |
@@ -806,21 +806,21 @@ discard block |
||
806 | 806 | else echo $ATC->add($data['ident'],$data['frequency'],$data['latitude'],$data['longitude'],$data['range'],$data['info'],$data['datetime'],$data['type'],$data['pilot_id'],$data['pilot_name'],$data['format_source'],$data['source_name']); |
807 | 807 | } |
808 | 808 | } |
809 | - unset($data); |
|
810 | - } |
|
811 | - } |
|
812 | - } |
|
813 | - //if ($value == 'whazzup') $last_exec['whazzup'] = time(); |
|
814 | - //elseif ($value == 'vatsimtxt') $last_exec['vatsimtxt'] = time(); |
|
815 | - $last_exec[$id]['last'] = time(); |
|
816 | - } elseif ($value['format'] == 'airwhere' && |
|
817 | - ( |
|
818 | - (isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || |
|
819 | - (!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch)) |
|
820 | - ) |
|
821 | - ) { |
|
822 | - $buffer = $Common->getData('http://www.airwhere.co.uk/pilots.php','get','','','','','20'); |
|
823 | - if ($buffer != '') { |
|
809 | + unset($data); |
|
810 | + } |
|
811 | + } |
|
812 | + } |
|
813 | + //if ($value == 'whazzup') $last_exec['whazzup'] = time(); |
|
814 | + //elseif ($value == 'vatsimtxt') $last_exec['vatsimtxt'] = time(); |
|
815 | + $last_exec[$id]['last'] = time(); |
|
816 | + } elseif ($value['format'] == 'airwhere' && |
|
817 | + ( |
|
818 | + (isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || |
|
819 | + (!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch)) |
|
820 | + ) |
|
821 | + ) { |
|
822 | + $buffer = $Common->getData('http://www.airwhere.co.uk/pilots.php','get','','','','','20'); |
|
823 | + if ($buffer != '') { |
|
824 | 824 | $all_data = simplexml_load_string($buffer); |
825 | 825 | foreach($all_data->children() as $childdata) { |
826 | 826 | $data = array(); |
@@ -842,10 +842,10 @@ discard block |
||
842 | 842 | $SI->add($data); |
843 | 843 | unset($data); |
844 | 844 | } |
845 | - } |
|
846 | - $Source->deleteOldLocationByType('gs'); |
|
847 | - $buffer = $Common->getData('http://www.airwhere.co.uk/gspositions.php','get','','','','','20'); |
|
848 | - if ($buffer != '') { |
|
845 | + } |
|
846 | + $Source->deleteOldLocationByType('gs'); |
|
847 | + $buffer = $Common->getData('http://www.airwhere.co.uk/gspositions.php','get','','','','','20'); |
|
848 | + if ($buffer != '') { |
|
849 | 849 | $all_data = simplexml_load_string($buffer); |
850 | 850 | foreach($all_data->children() as $childdata) { |
851 | 851 | $data = array(); |
@@ -863,8 +863,8 @@ discard block |
||
863 | 863 | } |
864 | 864 | unset($data); |
865 | 865 | } |
866 | - } |
|
867 | - $last_exec[$id]['last'] = time(); |
|
866 | + } |
|
867 | + $last_exec[$id]['last'] = time(); |
|
868 | 868 | /* |
869 | 869 | } if ($value['format'] == 'aircraftlistjson') { |
870 | 870 | print_r($globalSources); |
@@ -872,17 +872,17 @@ discard block |
||
872 | 872 | echo $globalMinFetch; |
873 | 873 | */ |
874 | 874 | } elseif ($value['format'] == 'aircraftlistjson' && |
875 | - ( |
|
875 | + ( |
|
876 | 876 | (isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || |
877 | 877 | (!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch)) |
878 | - ) |
|
878 | + ) |
|
879 | 879 | ) { |
880 | - $buffer = $Common->getData($value['host'],'get','','','','','20'); |
|
881 | - if ($buffer != '') { |
|
882 | - $all_data = json_decode($buffer,true); |
|
880 | + $buffer = $Common->getData($value['host'],'get','','','','','20'); |
|
881 | + if ($buffer != '') { |
|
882 | + $all_data = json_decode($buffer,true); |
|
883 | 883 | if (isset($all_data['acList'])) { |
884 | - $reset = 0; |
|
885 | - foreach ($all_data['acList'] as $line) { |
|
884 | + $reset = 0; |
|
885 | + foreach ($all_data['acList'] as $line) { |
|
886 | 886 | $data = array(); |
887 | 887 | $data['hex'] = $line['Icao']; // hex |
888 | 888 | if (isset($line['Call'])) $data['ident'] = $line['Call']; // ident |
@@ -905,10 +905,10 @@ discard block |
||
905 | 905 | if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true; |
906 | 906 | if (isset($data['latitude'])) $SI->add($data); |
907 | 907 | unset($data); |
908 | - } |
|
908 | + } |
|
909 | 909 | } elseif (is_array($all_data)) { |
910 | - $reset = 0; |
|
911 | - foreach ($all_data as $line) { |
|
910 | + $reset = 0; |
|
911 | + foreach ($all_data as $line) { |
|
912 | 912 | $data = array(); |
913 | 913 | $data['hex'] = $line['hex']; // hex |
914 | 914 | $data['ident'] = $line['flight']; // ident |
@@ -928,218 +928,218 @@ discard block |
||
928 | 928 | if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name']; |
929 | 929 | $SI->add($data); |
930 | 930 | unset($data); |
931 | - } |
|
931 | + } |
|
932 | 932 | } |
933 | - } elseif ($globalDebug) echo 'No data'."\n"; |
|
934 | - //$last_exec['aircraftlistjson'] = time(); |
|
935 | - $last_exec[$id]['last'] = time(); |
|
936 | - //} elseif ($value == 'planeupdatefaa' && (time() - $last_exec['planeupdatefaa'] > $globalMinFetch)) { |
|
937 | - } elseif ($value['format'] == 'planeupdatefaa' && |
|
938 | - ( |
|
939 | - (isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || |
|
940 | - (!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch)) |
|
941 | - ) |
|
942 | - ) { |
|
943 | - $buffer = $Common->getData($value['host']); |
|
944 | - $all_data = json_decode($buffer,true); |
|
945 | - if (isset($all_data['planes'])) { |
|
933 | + } elseif ($globalDebug) echo 'No data'."\n"; |
|
934 | + //$last_exec['aircraftlistjson'] = time(); |
|
935 | + $last_exec[$id]['last'] = time(); |
|
936 | + //} elseif ($value == 'planeupdatefaa' && (time() - $last_exec['planeupdatefaa'] > $globalMinFetch)) { |
|
937 | + } elseif ($value['format'] == 'planeupdatefaa' && |
|
938 | + ( |
|
939 | + (isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || |
|
940 | + (!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch)) |
|
941 | + ) |
|
942 | + ) { |
|
943 | + $buffer = $Common->getData($value['host']); |
|
944 | + $all_data = json_decode($buffer,true); |
|
945 | + if (isset($all_data['planes'])) { |
|
946 | 946 | $reset = 0; |
947 | 947 | foreach ($all_data['planes'] as $key => $line) { |
948 | - $data = array(); |
|
949 | - $data['hex'] = $key; // hex |
|
950 | - $data['ident'] = $line[3]; // ident |
|
951 | - $data['altitude'] = $line[6]; // altitude |
|
952 | - $data['speed'] = $line[8]; // speed |
|
953 | - $data['heading'] = $line[7]; // heading |
|
954 | - $data['latitude'] = $line[4]; // lat |
|
955 | - $data['longitude'] = $line[5]; // long |
|
956 | - //$data['verticalrate'] = $line[]; // verticale rate |
|
957 | - $data['squawk'] = $line[10]; // squawk |
|
958 | - $data['emergency'] = ''; // emergency |
|
959 | - $data['registration'] = $line[2]; |
|
960 | - $data['aircraft_icao'] = $line[0]; |
|
961 | - $deparr = explode('-',$line[1]); |
|
962 | - if (count($deparr) == 2) { |
|
948 | + $data = array(); |
|
949 | + $data['hex'] = $key; // hex |
|
950 | + $data['ident'] = $line[3]; // ident |
|
951 | + $data['altitude'] = $line[6]; // altitude |
|
952 | + $data['speed'] = $line[8]; // speed |
|
953 | + $data['heading'] = $line[7]; // heading |
|
954 | + $data['latitude'] = $line[4]; // lat |
|
955 | + $data['longitude'] = $line[5]; // long |
|
956 | + //$data['verticalrate'] = $line[]; // verticale rate |
|
957 | + $data['squawk'] = $line[10]; // squawk |
|
958 | + $data['emergency'] = ''; // emergency |
|
959 | + $data['registration'] = $line[2]; |
|
960 | + $data['aircraft_icao'] = $line[0]; |
|
961 | + $deparr = explode('-',$line[1]); |
|
962 | + if (count($deparr) == 2) { |
|
963 | 963 | $data['departure_airport_icao'] = $deparr[0]; |
964 | 964 | $data['arrival_airport_icao'] = $deparr[1]; |
965 | - } |
|
966 | - $data['datetime'] = date('Y-m-d H:i:s',$line[9]); |
|
967 | - $data['format_source'] = 'planeupdatefaa'; |
|
968 | - $data['id_source'] = $id_source; |
|
969 | - if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true; |
|
970 | - if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name']; |
|
971 | - $SI->add($data); |
|
972 | - unset($data); |
|
965 | + } |
|
966 | + $data['datetime'] = date('Y-m-d H:i:s',$line[9]); |
|
967 | + $data['format_source'] = 'planeupdatefaa'; |
|
968 | + $data['id_source'] = $id_source; |
|
969 | + if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true; |
|
970 | + if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name']; |
|
971 | + $SI->add($data); |
|
972 | + unset($data); |
|
973 | + } |
|
973 | 974 | } |
974 | - } |
|
975 | - //$last_exec['planeupdatefaa'] = time(); |
|
976 | - $last_exec[$id]['last'] = time(); |
|
975 | + //$last_exec['planeupdatefaa'] = time(); |
|
976 | + $last_exec[$id]['last'] = time(); |
|
977 | 977 | } elseif ($value['format'] == 'opensky' && |
978 | - ( |
|
978 | + ( |
|
979 | 979 | (isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || |
980 | 980 | (!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch)) |
981 | - ) |
|
981 | + ) |
|
982 | 982 | ) { |
983 | - $buffer = $Common->getData($value['host']); |
|
984 | - $all_data = json_decode($buffer,true); |
|
985 | - if (isset($all_data['states'])) { |
|
983 | + $buffer = $Common->getData($value['host']); |
|
984 | + $all_data = json_decode($buffer,true); |
|
985 | + if (isset($all_data['states'])) { |
|
986 | 986 | $reset = 0; |
987 | 987 | foreach ($all_data['states'] as $key => $line) { |
988 | - $data = array(); |
|
989 | - $data['hex'] = $line[0]; // hex |
|
990 | - $data['ident'] = trim($line[1]); // ident |
|
991 | - $data['altitude'] = round($line[7]*3.28084); // altitude |
|
992 | - $data['speed'] = round($line[9]*1.94384); // speed |
|
993 | - $data['heading'] = round($line[10]); // heading |
|
994 | - $data['latitude'] = $line[6]; // lat |
|
995 | - $data['longitude'] = $line[5]; // long |
|
996 | - $data['verticalrate'] = $line[11]; // verticale rate |
|
997 | - //$data['squawk'] = $line[10]; // squawk |
|
998 | - //$data['emergency'] = ''; // emergency |
|
999 | - //$data['registration'] = $line[2]; |
|
1000 | - //$data['aircraft_icao'] = $line[0]; |
|
1001 | - $data['datetime'] = date('Y-m-d H:i:s',$line[3]); |
|
1002 | - $data['format_source'] = 'opensky'; |
|
1003 | - $data['id_source'] = $id_source; |
|
1004 | - if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true; |
|
1005 | - $SI->add($data); |
|
1006 | - unset($data); |
|
988 | + $data = array(); |
|
989 | + $data['hex'] = $line[0]; // hex |
|
990 | + $data['ident'] = trim($line[1]); // ident |
|
991 | + $data['altitude'] = round($line[7]*3.28084); // altitude |
|
992 | + $data['speed'] = round($line[9]*1.94384); // speed |
|
993 | + $data['heading'] = round($line[10]); // heading |
|
994 | + $data['latitude'] = $line[6]; // lat |
|
995 | + $data['longitude'] = $line[5]; // long |
|
996 | + $data['verticalrate'] = $line[11]; // verticale rate |
|
997 | + //$data['squawk'] = $line[10]; // squawk |
|
998 | + //$data['emergency'] = ''; // emergency |
|
999 | + //$data['registration'] = $line[2]; |
|
1000 | + //$data['aircraft_icao'] = $line[0]; |
|
1001 | + $data['datetime'] = date('Y-m-d H:i:s',$line[3]); |
|
1002 | + $data['format_source'] = 'opensky'; |
|
1003 | + $data['id_source'] = $id_source; |
|
1004 | + if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true; |
|
1005 | + $SI->add($data); |
|
1006 | + unset($data); |
|
1007 | + } |
|
1007 | 1008 | } |
1008 | - } |
|
1009 | - //$last_exec['planeupdatefaa'] = time(); |
|
1010 | - $last_exec[$id]['last'] = time(); |
|
1009 | + //$last_exec['planeupdatefaa'] = time(); |
|
1010 | + $last_exec[$id]['last'] = time(); |
|
1011 | 1011 | //} elseif ($value == 'fr24json' && (time() - $last_exec['fr24json'] > $globalMinFetch)) { |
1012 | 1012 | } elseif ($value['format'] == 'fr24json' && |
1013 | - ( |
|
1013 | + ( |
|
1014 | 1014 | (isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || |
1015 | 1015 | (!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch)) |
1016 | - ) |
|
1016 | + ) |
|
1017 | 1017 | ) { |
1018 | - //$buffer = $Common->getData($hosts[$id]); |
|
1019 | - $buffer = $Common->getData($value['host']); |
|
1020 | - $all_data = json_decode($buffer,true); |
|
1021 | - if (!empty($all_data)) $reset = 0; |
|
1022 | - foreach ($all_data as $key => $line) { |
|
1018 | + //$buffer = $Common->getData($hosts[$id]); |
|
1019 | + $buffer = $Common->getData($value['host']); |
|
1020 | + $all_data = json_decode($buffer,true); |
|
1021 | + if (!empty($all_data)) $reset = 0; |
|
1022 | + foreach ($all_data as $key => $line) { |
|
1023 | 1023 | if ($key != 'full_count' && $key != 'version' && $key != 'stats') { |
1024 | - $data = array(); |
|
1025 | - $data['hex'] = $line[0]; |
|
1026 | - $data['ident'] = $line[16]; //$line[13] |
|
1027 | - $data['altitude'] = $line[4]; // altitude |
|
1028 | - $data['speed'] = $line[5]; // speed |
|
1029 | - $data['heading'] = $line[3]; // heading |
|
1030 | - $data['latitude'] = $line[1]; // lat |
|
1031 | - $data['longitude'] = $line[2]; // long |
|
1032 | - $data['verticalrate'] = $line[15]; // verticale rate |
|
1033 | - $data['squawk'] = $line[6]; // squawk |
|
1034 | - $data['aircraft_icao'] = $line[8]; |
|
1035 | - $data['registration'] = $line[9]; |
|
1036 | - $data['departure_airport_iata'] = $line[11]; |
|
1037 | - $data['arrival_airport_iata'] = $line[12]; |
|
1038 | - $data['emergency'] = ''; // emergency |
|
1039 | - $data['datetime'] = date('Y-m-d H:i:s'); //$line[10] |
|
1040 | - $data['format_source'] = 'fr24json'; |
|
1041 | - $data['id_source'] = $id_source; |
|
1042 | - if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true; |
|
1043 | - if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name']; |
|
1044 | - $SI->add($data); |
|
1045 | - unset($data); |
|
1024 | + $data = array(); |
|
1025 | + $data['hex'] = $line[0]; |
|
1026 | + $data['ident'] = $line[16]; //$line[13] |
|
1027 | + $data['altitude'] = $line[4]; // altitude |
|
1028 | + $data['speed'] = $line[5]; // speed |
|
1029 | + $data['heading'] = $line[3]; // heading |
|
1030 | + $data['latitude'] = $line[1]; // lat |
|
1031 | + $data['longitude'] = $line[2]; // long |
|
1032 | + $data['verticalrate'] = $line[15]; // verticale rate |
|
1033 | + $data['squawk'] = $line[6]; // squawk |
|
1034 | + $data['aircraft_icao'] = $line[8]; |
|
1035 | + $data['registration'] = $line[9]; |
|
1036 | + $data['departure_airport_iata'] = $line[11]; |
|
1037 | + $data['arrival_airport_iata'] = $line[12]; |
|
1038 | + $data['emergency'] = ''; // emergency |
|
1039 | + $data['datetime'] = date('Y-m-d H:i:s'); //$line[10] |
|
1040 | + $data['format_source'] = 'fr24json'; |
|
1041 | + $data['id_source'] = $id_source; |
|
1042 | + if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true; |
|
1043 | + if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name']; |
|
1044 | + $SI->add($data); |
|
1045 | + unset($data); |
|
1046 | 1046 | } |
1047 | - } |
|
1048 | - //$last_exec['fr24json'] = time(); |
|
1049 | - $last_exec[$id]['last'] = time(); |
|
1047 | + } |
|
1048 | + //$last_exec['fr24json'] = time(); |
|
1049 | + $last_exec[$id]['last'] = time(); |
|
1050 | 1050 | //} elseif ($value == 'radarvirtueljson' && (time() - $last_exec['radarvirtueljson'] > $globalMinFetch)) { |
1051 | 1051 | } elseif ($value['format'] == 'radarvirtueljson' && |
1052 | - ( |
|
1052 | + ( |
|
1053 | 1053 | (isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || |
1054 | 1054 | (!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch)) |
1055 | - ) |
|
1055 | + ) |
|
1056 | 1056 | ) { |
1057 | - //$buffer = $Common->getData($hosts[$id],'get','','','','','150'); |
|
1058 | - $buffer = $Common->getData($value['host'],'get','','','','','150'); |
|
1059 | - //echo $buffer; |
|
1060 | - $buffer = str_replace(array("\n","\r"),"",$buffer); |
|
1061 | - $buffer = preg_replace('/,"num":(.+)/','}',$buffer); |
|
1062 | - $all_data = json_decode($buffer,true); |
|
1063 | - if (json_last_error() != JSON_ERROR_NONE) { |
|
1057 | + //$buffer = $Common->getData($hosts[$id],'get','','','','','150'); |
|
1058 | + $buffer = $Common->getData($value['host'],'get','','','','','150'); |
|
1059 | + //echo $buffer; |
|
1060 | + $buffer = str_replace(array("\n","\r"),"",$buffer); |
|
1061 | + $buffer = preg_replace('/,"num":(.+)/','}',$buffer); |
|
1062 | + $all_data = json_decode($buffer,true); |
|
1063 | + if (json_last_error() != JSON_ERROR_NONE) { |
|
1064 | 1064 | die(json_last_error_msg()); |
1065 | - } |
|
1066 | - if (isset($all_data['mrkrs'])) { |
|
1065 | + } |
|
1066 | + if (isset($all_data['mrkrs'])) { |
|
1067 | 1067 | $reset = 0; |
1068 | 1068 | foreach ($all_data['mrkrs'] as $key => $line) { |
1069 | - if (isset($line['inf'])) { |
|
1069 | + if (isset($line['inf'])) { |
|
1070 | 1070 | $data = array(); |
1071 | 1071 | $data['hex'] = $line['inf']['ia']; |
1072 | 1072 | if (isset($line['inf']['cs'])) $data['ident'] = $line['inf']['cs']; //$line[13] |
1073 | - $data['altitude'] = round($line['inf']['al']*3.28084); // altitude |
|
1074 | - if (isset($line['inf']['gs'])) $data['speed'] = round($line['inf']['gs']*0.539957); // speed |
|
1075 | - if (isset($line['inf']['tr'])) $data['heading'] = $line['inf']['tr']; // heading |
|
1076 | - $data['latitude'] = $line['pt'][0]; // lat |
|
1077 | - $data['longitude'] = $line['pt'][1]; // long |
|
1078 | - //if (isset($line['inf']['vs'])) $data['verticalrate'] = $line['inf']['vs']; // verticale rate |
|
1079 | - if (isset($line['inf']['sq'])) $data['squawk'] = $line['inf']['sq']; // squawk |
|
1080 | - //$data['aircraft_icao'] = $line[8]; |
|
1081 | - if (isset($line['inf']['rc'])) $data['registration'] = $line['inf']['rc']; |
|
1073 | + $data['altitude'] = round($line['inf']['al']*3.28084); // altitude |
|
1074 | + if (isset($line['inf']['gs'])) $data['speed'] = round($line['inf']['gs']*0.539957); // speed |
|
1075 | + if (isset($line['inf']['tr'])) $data['heading'] = $line['inf']['tr']; // heading |
|
1076 | + $data['latitude'] = $line['pt'][0]; // lat |
|
1077 | + $data['longitude'] = $line['pt'][1]; // long |
|
1078 | + //if (isset($line['inf']['vs'])) $data['verticalrate'] = $line['inf']['vs']; // verticale rate |
|
1079 | + if (isset($line['inf']['sq'])) $data['squawk'] = $line['inf']['sq']; // squawk |
|
1080 | + //$data['aircraft_icao'] = $line[8]; |
|
1081 | + if (isset($line['inf']['rc'])) $data['registration'] = $line['inf']['rc']; |
|
1082 | 1082 | //$data['departure_airport_iata'] = $line[11]; |
1083 | 1083 | //$data['arrival_airport_iata'] = $line[12]; |
1084 | - //$data['emergency'] = ''; // emergency |
|
1084 | + //$data['emergency'] = ''; // emergency |
|
1085 | 1085 | $data['datetime'] = date('Y-m-d H:i:s',$line['inf']['dt']); //$line[10] |
1086 | - $data['format_source'] = 'radarvirtueljson'; |
|
1087 | - $data['id_source'] = $id_source; |
|
1086 | + $data['format_source'] = 'radarvirtueljson'; |
|
1087 | + $data['id_source'] = $id_source; |
|
1088 | 1088 | if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true; |
1089 | 1089 | if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name']; |
1090 | 1090 | $SI->add($data); |
1091 | 1091 | unset($data); |
1092 | - } |
|
1092 | + } |
|
1093 | 1093 | } |
1094 | - } |
|
1095 | - //$last_exec['radarvirtueljson'] = time(); |
|
1096 | - $last_exec[$id]['last'] = time(); |
|
1094 | + } |
|
1095 | + //$last_exec['radarvirtueljson'] = time(); |
|
1096 | + $last_exec[$id]['last'] = time(); |
|
1097 | 1097 | //} elseif ($value == 'pirepsjson' && (time() - $last_exec['pirepsjson'] > $globalMinFetch)) { |
1098 | 1098 | } elseif ($value['format'] == 'pirepsjson' && |
1099 | - ( |
|
1099 | + ( |
|
1100 | 1100 | (isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || |
1101 | 1101 | (!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch)) |
1102 | - ) |
|
1102 | + ) |
|
1103 | 1103 | ) { |
1104 | - //$buffer = $Common->getData($hosts[$id]); |
|
1105 | - $buffer = $Common->getData($value['host'].'?'.time()); |
|
1106 | - $all_data = json_decode(utf8_encode($buffer),true); |
|
1104 | + //$buffer = $Common->getData($hosts[$id]); |
|
1105 | + $buffer = $Common->getData($value['host'].'?'.time()); |
|
1106 | + $all_data = json_decode(utf8_encode($buffer),true); |
|
1107 | 1107 | |
1108 | - if (isset($all_data['pireps'])) { |
|
1108 | + if (isset($all_data['pireps'])) { |
|
1109 | 1109 | $reset = 0; |
1110 | - foreach ($all_data['pireps'] as $line) { |
|
1111 | - $data = array(); |
|
1112 | - $data['id'] = $line['id']; |
|
1113 | - $data['hex'] = substr(str_pad(dechex($line['id']),6,'000000',STR_PAD_LEFT),0,6); |
|
1114 | - $data['ident'] = $line['callsign']; // ident |
|
1115 | - if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; // pilot id |
|
1116 | - if (isset($line['name'])) $data['pilot_name'] = $line['name']; // pilot name |
|
1117 | - if (isset($line['alt'])) $data['altitude'] = $line['alt']; // altitude |
|
1118 | - if (isset($line['gs'])) $data['speed'] = $line['gs']; // speed |
|
1119 | - if (isset($line['heading'])) $data['heading'] = $line['heading']; // heading |
|
1120 | - if (isset($line['route'])) $data['waypoints'] = $line['route']; // route |
|
1121 | - $data['latitude'] = $line['lat']; // lat |
|
1122 | - $data['longitude'] = $line['lon']; // long |
|
1123 | - //$data['verticalrate'] = $line['vrt']; // verticale rate |
|
1124 | - //$data['squawk'] = $line['squawk']; // squawk |
|
1125 | - //$data['emergency'] = ''; // emergency |
|
1126 | - if (isset($line['depicao'])) $data['departure_airport_icao'] = $line['depicao']; |
|
1127 | - if (isset($line['deptime'])) $data['departure_airport_time'] = $line['deptime']; |
|
1128 | - if (isset($line['arricao'])) $data['arrival_airport_icao'] = $line['arricao']; |
|
1129 | - //$data['arrival_airport_time'] = $line['arrtime']; |
|
1130 | - if (isset($line['aircraft'])) $data['aircraft_icao'] = $line['aircraft']; |
|
1131 | - if (isset($line['transponder'])) $data['squawk'] = $line['transponder']; |
|
1132 | - if (isset($line['atis'])) $data['info'] = $line['atis']; |
|
1133 | - else $data['info'] = ''; |
|
1134 | - $data['format_source'] = 'pireps'; |
|
1135 | - $data['id_source'] = $id_source; |
|
1136 | - $data['datetime'] = date('Y-m-d H:i:s'); |
|
1137 | - if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true; |
|
1138 | - if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name']; |
|
1139 | - if ($line['icon'] == 'plane') { |
|
1110 | + foreach ($all_data['pireps'] as $line) { |
|
1111 | + $data = array(); |
|
1112 | + $data['id'] = $line['id']; |
|
1113 | + $data['hex'] = substr(str_pad(dechex($line['id']),6,'000000',STR_PAD_LEFT),0,6); |
|
1114 | + $data['ident'] = $line['callsign']; // ident |
|
1115 | + if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; // pilot id |
|
1116 | + if (isset($line['name'])) $data['pilot_name'] = $line['name']; // pilot name |
|
1117 | + if (isset($line['alt'])) $data['altitude'] = $line['alt']; // altitude |
|
1118 | + if (isset($line['gs'])) $data['speed'] = $line['gs']; // speed |
|
1119 | + if (isset($line['heading'])) $data['heading'] = $line['heading']; // heading |
|
1120 | + if (isset($line['route'])) $data['waypoints'] = $line['route']; // route |
|
1121 | + $data['latitude'] = $line['lat']; // lat |
|
1122 | + $data['longitude'] = $line['lon']; // long |
|
1123 | + //$data['verticalrate'] = $line['vrt']; // verticale rate |
|
1124 | + //$data['squawk'] = $line['squawk']; // squawk |
|
1125 | + //$data['emergency'] = ''; // emergency |
|
1126 | + if (isset($line['depicao'])) $data['departure_airport_icao'] = $line['depicao']; |
|
1127 | + if (isset($line['deptime'])) $data['departure_airport_time'] = $line['deptime']; |
|
1128 | + if (isset($line['arricao'])) $data['arrival_airport_icao'] = $line['arricao']; |
|
1129 | + //$data['arrival_airport_time'] = $line['arrtime']; |
|
1130 | + if (isset($line['aircraft'])) $data['aircraft_icao'] = $line['aircraft']; |
|
1131 | + if (isset($line['transponder'])) $data['squawk'] = $line['transponder']; |
|
1132 | + if (isset($line['atis'])) $data['info'] = $line['atis']; |
|
1133 | + else $data['info'] = ''; |
|
1134 | + $data['format_source'] = 'pireps'; |
|
1135 | + $data['id_source'] = $id_source; |
|
1136 | + $data['datetime'] = date('Y-m-d H:i:s'); |
|
1137 | + if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true; |
|
1138 | + if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name']; |
|
1139 | + if ($line['icon'] == 'plane') { |
|
1140 | 1140 | $SI->add($data); |
1141 | - // print_r($data); |
|
1142 | - } elseif ($line['icon'] == 'ct') { |
|
1141 | + // print_r($data); |
|
1142 | + } elseif ($line['icon'] == 'ct') { |
|
1143 | 1143 | $data['info'] = str_replace('^§','<br />',$data['info']); |
1144 | 1144 | $data['info'] = str_replace('&sect;','',$data['info']); |
1145 | 1145 | $typec = substr($data['ident'],-3); |
@@ -1154,209 +1154,209 @@ discard block |
||
1154 | 1154 | elseif ($typec == 'CTR') $data['type'] = 'Control Radar or Centre'; |
1155 | 1155 | else $data['type'] = 'Observer'; |
1156 | 1156 | if (isset($ATC)) echo $ATC->add($data['ident'],'',$data['latitude'],$data['longitude'],'0',$data['info'],$data['datetime'],$data['type'],$data['pilot_id'],$data['pilot_name'],$data['format_source']); |
1157 | - } |
|
1158 | - unset($data); |
|
1157 | + } |
|
1158 | + unset($data); |
|
1159 | + } |
|
1159 | 1160 | } |
1160 | - } |
|
1161 | - //$last_exec['pirepsjson'] = time(); |
|
1162 | - $last_exec[$id]['last'] = time(); |
|
1161 | + //$last_exec['pirepsjson'] = time(); |
|
1162 | + $last_exec[$id]['last'] = time(); |
|
1163 | 1163 | //} elseif ($value == 'phpvmacars' && (time() - $last_exec['phpvmacars'] > $globalMinFetch)) { |
1164 | 1164 | } elseif ($value['format'] == 'phpvmacars' && |
1165 | - ( |
|
1165 | + ( |
|
1166 | 1166 | (isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || |
1167 | 1167 | (!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch)) |
1168 | - ) |
|
1168 | + ) |
|
1169 | 1169 | ) { |
1170 | - //$buffer = $Common->getData($hosts[$id]); |
|
1171 | - if ($globalDebug) echo 'Get Data...'."\n"; |
|
1172 | - $buffer = $Common->getData($value['host']); |
|
1173 | - $all_data = json_decode($buffer,true); |
|
1174 | - if ($buffer != '' && is_array($all_data)) { |
|
1170 | + //$buffer = $Common->getData($hosts[$id]); |
|
1171 | + if ($globalDebug) echo 'Get Data...'."\n"; |
|
1172 | + $buffer = $Common->getData($value['host']); |
|
1173 | + $all_data = json_decode($buffer,true); |
|
1174 | + if ($buffer != '' && is_array($all_data)) { |
|
1175 | 1175 | $reset = 0; |
1176 | 1176 | foreach ($all_data as $line) { |
1177 | - $data = array(); |
|
1178 | - //$data['id'] = $line['id']; // id not usable |
|
1179 | - if (isset($line['pilotid'])) $data['id'] = $line['pilotid'].$line['flightnum']; |
|
1180 | - $data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex |
|
1181 | - if (isset($line['pilotname'])) $data['pilot_name'] = $line['pilotname']; |
|
1182 | - if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; |
|
1183 | - $data['ident'] = $line['flightnum']; // ident |
|
1184 | - $data['altitude'] = $line['alt']; // altitude |
|
1185 | - $data['speed'] = $line['gs']; // speed |
|
1186 | - $data['heading'] = $line['heading']; // heading |
|
1187 | - $data['latitude'] = $line['lat']; // lat |
|
1188 | - $data['longitude'] = $line['lng']; // long |
|
1189 | - $data['verticalrate'] = ''; // verticale rate |
|
1190 | - $data['squawk'] = ''; // squawk |
|
1191 | - $data['emergency'] = ''; // emergency |
|
1192 | - //$data['datetime'] = $line['lastupdate']; |
|
1193 | - //$data['last_update'] = $line['lastupdate']; |
|
1194 | - if (isset($value['timezone'])) { |
|
1195 | - $datetime = new DateTime($line['lastupdate'],new DateTimeZone($value['timezone'])); |
|
1196 | - $datetime->setTimeZone(new DateTimeZone('UTC')); |
|
1197 | - $data['datetime'] = $datetime->format('Y-m-d H:i:s'); |
|
1198 | - } else $data['datetime'] = date('Y-m-d H:i:s'); |
|
1199 | - $data['departure_airport_icao'] = $line['depicao']; |
|
1200 | - $data['departure_airport_time'] = $line['deptime']; |
|
1201 | - $data['arrival_airport_icao'] = $line['arricao']; |
|
1202 | - $data['arrival_airport_time'] = $line['arrtime']; |
|
1203 | - if (isset($line['registration'])) { |
|
1204 | - $data['registration'] = $line['registration']; |
|
1205 | - //if (isset($line['aircraft'])) $data['id'] = $line['aircraft']; |
|
1206 | - } else $data['registration'] = $line['aircraft']; |
|
1207 | - if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true; |
|
1208 | - if (isset($line['route'])) $data['waypoints'] = $line['route']; // route |
|
1209 | - if (isset($line['aircraftname'])) { |
|
1177 | + $data = array(); |
|
1178 | + //$data['id'] = $line['id']; // id not usable |
|
1179 | + if (isset($line['pilotid'])) $data['id'] = $line['pilotid'].$line['flightnum']; |
|
1180 | + $data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex |
|
1181 | + if (isset($line['pilotname'])) $data['pilot_name'] = $line['pilotname']; |
|
1182 | + if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; |
|
1183 | + $data['ident'] = $line['flightnum']; // ident |
|
1184 | + $data['altitude'] = $line['alt']; // altitude |
|
1185 | + $data['speed'] = $line['gs']; // speed |
|
1186 | + $data['heading'] = $line['heading']; // heading |
|
1187 | + $data['latitude'] = $line['lat']; // lat |
|
1188 | + $data['longitude'] = $line['lng']; // long |
|
1189 | + $data['verticalrate'] = ''; // verticale rate |
|
1190 | + $data['squawk'] = ''; // squawk |
|
1191 | + $data['emergency'] = ''; // emergency |
|
1192 | + //$data['datetime'] = $line['lastupdate']; |
|
1193 | + //$data['last_update'] = $line['lastupdate']; |
|
1194 | + if (isset($value['timezone'])) { |
|
1195 | + $datetime = new DateTime($line['lastupdate'],new DateTimeZone($value['timezone'])); |
|
1196 | + $datetime->setTimeZone(new DateTimeZone('UTC')); |
|
1197 | + $data['datetime'] = $datetime->format('Y-m-d H:i:s'); |
|
1198 | + } else $data['datetime'] = date('Y-m-d H:i:s'); |
|
1199 | + $data['departure_airport_icao'] = $line['depicao']; |
|
1200 | + $data['departure_airport_time'] = $line['deptime']; |
|
1201 | + $data['arrival_airport_icao'] = $line['arricao']; |
|
1202 | + $data['arrival_airport_time'] = $line['arrtime']; |
|
1203 | + if (isset($line['registration'])) { |
|
1204 | + $data['registration'] = $line['registration']; |
|
1205 | + //if (isset($line['aircraft'])) $data['id'] = $line['aircraft']; |
|
1206 | + } else $data['registration'] = $line['aircraft']; |
|
1207 | + if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true; |
|
1208 | + if (isset($line['route'])) $data['waypoints'] = $line['route']; // route |
|
1209 | + if (isset($line['aircraftname'])) { |
|
1210 | 1210 | $line['aircraftname'] = strtoupper($line['aircraftname']); |
1211 | 1211 | $line['aircraftname'] = str_replace('BOEING ','B',$line['aircraftname']); |
1212 | - $aircraft_data = explode('-',$line['aircraftname']); |
|
1213 | - if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) >= 3 && strlen($aircraft_data[0]) <= 4) $data['aircraft_icao'] = $aircraft_data[0]; |
|
1214 | - elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) >= 3 && strlen($aircraft_data[1]) <= 4) $data['aircraft_icao'] = $aircraft_data[1]; |
|
1215 | - else { |
|
1216 | - $aircraft_data = explode(' ',$line['aircraftname']); |
|
1217 | - if (isset($aircraft_data[1])) $data['aircraft_icao'] = str_replace('-','',$aircraft_data[1]); |
|
1218 | - else $data['aircraft_icao'] = str_replace('-','',$line['aircraftname']); |
|
1219 | - } |
|
1220 | - } |
|
1221 | - if (isset($line['route'])) $data['waypoints'] = $line['route']; |
|
1222 | - $data['id_source'] = $id_source; |
|
1223 | - $data['format_source'] = 'phpvmacars'; |
|
1224 | - if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name']; |
|
1225 | - $SI->add($data); |
|
1226 | - unset($data); |
|
1212 | + $aircraft_data = explode('-',$line['aircraftname']); |
|
1213 | + if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) >= 3 && strlen($aircraft_data[0]) <= 4) $data['aircraft_icao'] = $aircraft_data[0]; |
|
1214 | + elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) >= 3 && strlen($aircraft_data[1]) <= 4) $data['aircraft_icao'] = $aircraft_data[1]; |
|
1215 | + else { |
|
1216 | + $aircraft_data = explode(' ',$line['aircraftname']); |
|
1217 | + if (isset($aircraft_data[1])) $data['aircraft_icao'] = str_replace('-','',$aircraft_data[1]); |
|
1218 | + else $data['aircraft_icao'] = str_replace('-','',$line['aircraftname']); |
|
1219 | + } |
|
1220 | + } |
|
1221 | + if (isset($line['route'])) $data['waypoints'] = $line['route']; |
|
1222 | + $data['id_source'] = $id_source; |
|
1223 | + $data['format_source'] = 'phpvmacars'; |
|
1224 | + if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name']; |
|
1225 | + $SI->add($data); |
|
1226 | + unset($data); |
|
1227 | 1227 | } |
1228 | 1228 | if ($globalDebug) echo 'No more data...'."\n"; |
1229 | 1229 | unset($buffer); |
1230 | 1230 | unset($all_data); |
1231 | - } |
|
1232 | - //$last_exec['phpvmacars'] = time(); |
|
1233 | - $last_exec[$id]['last'] = time(); |
|
1231 | + } |
|
1232 | + //$last_exec['phpvmacars'] = time(); |
|
1233 | + $last_exec[$id]['last'] = time(); |
|
1234 | 1234 | } elseif ($value['format'] == 'vaos' && |
1235 | - ( |
|
1235 | + ( |
|
1236 | 1236 | (isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || |
1237 | 1237 | (!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch)) |
1238 | - ) |
|
1238 | + ) |
|
1239 | 1239 | ) { |
1240 | - //$buffer = $Common->getData($hosts[$id]); |
|
1241 | - if ($globalDebug) echo 'Get Data...'."\n"; |
|
1242 | - $buffer = $Common->getData($value['host']); |
|
1243 | - $all_data = json_decode($buffer,true); |
|
1244 | - if ($buffer != '' && is_array($all_data) && isset($all_data['ACARSData'])) { |
|
1240 | + //$buffer = $Common->getData($hosts[$id]); |
|
1241 | + if ($globalDebug) echo 'Get Data...'."\n"; |
|
1242 | + $buffer = $Common->getData($value['host']); |
|
1243 | + $all_data = json_decode($buffer,true); |
|
1244 | + if ($buffer != '' && is_array($all_data) && isset($all_data['ACARSData'])) { |
|
1245 | 1245 | $reset = 0; |
1246 | 1246 | foreach ($all_data['ACARSData'] as $line) { |
1247 | - //print_r($line); |
|
1248 | - $data = array(); |
|
1249 | - //$data['id'] = $line['id']; // id not usable |
|
1250 | - $data['id'] = $line['id']; |
|
1251 | - //$data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex |
|
1252 | - if (isset($line['user']['username'])) $data['pilot_name'] = $line['user']['username']; |
|
1253 | - if (isset($line['user_id'])) $data['pilot_id'] = $line['user_id']; |
|
1254 | - $data['ident'] = str_replace(' ','',$line['bid']['flightnum']); // ident |
|
1255 | - if (is_numeric($data['ident'])) $data['ident'] = $line['bid']['airline']['icao'].$data['ident']; |
|
1256 | - $data['altitude'] = $line['altitude']; // altitude |
|
1257 | - $data['speed'] = $line['groundspeed']; // speed |
|
1258 | - $data['heading'] = $line['heading']; // heading |
|
1259 | - $data['latitude'] = $line['lat']; // lat |
|
1260 | - $data['longitude'] = $line['lon']; // long |
|
1261 | - //$data['verticalrate'] = ''; // verticale rate |
|
1262 | - //$data['squawk'] = ''; // squawk |
|
1263 | - //$data['emergency'] = ''; // emergency |
|
1264 | - if (isset($value['timezone'])) { |
|
1265 | - $datetime = new DateTime($line['updated_at'],new DateTimeZone($value['timezone'])); |
|
1266 | - $datetime->setTimeZone(new DateTimeZone('UTC')); |
|
1267 | - $data['datetime'] = $datetime->format('Y-m-d H:i:s'); |
|
1268 | - } else $data['datetime'] = date('Y-m-d H:i:s'); |
|
1247 | + //print_r($line); |
|
1248 | + $data = array(); |
|
1249 | + //$data['id'] = $line['id']; // id not usable |
|
1250 | + $data['id'] = $line['id']; |
|
1251 | + //$data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex |
|
1252 | + if (isset($line['user']['username'])) $data['pilot_name'] = $line['user']['username']; |
|
1253 | + if (isset($line['user_id'])) $data['pilot_id'] = $line['user_id']; |
|
1254 | + $data['ident'] = str_replace(' ','',$line['bid']['flightnum']); // ident |
|
1255 | + if (is_numeric($data['ident'])) $data['ident'] = $line['bid']['airline']['icao'].$data['ident']; |
|
1256 | + $data['altitude'] = $line['altitude']; // altitude |
|
1257 | + $data['speed'] = $line['groundspeed']; // speed |
|
1258 | + $data['heading'] = $line['heading']; // heading |
|
1259 | + $data['latitude'] = $line['lat']; // lat |
|
1260 | + $data['longitude'] = $line['lon']; // long |
|
1261 | + //$data['verticalrate'] = ''; // verticale rate |
|
1262 | + //$data['squawk'] = ''; // squawk |
|
1263 | + //$data['emergency'] = ''; // emergency |
|
1264 | + if (isset($value['timezone'])) { |
|
1265 | + $datetime = new DateTime($line['updated_at'],new DateTimeZone($value['timezone'])); |
|
1266 | + $datetime->setTimeZone(new DateTimeZone('UTC')); |
|
1267 | + $data['datetime'] = $datetime->format('Y-m-d H:i:s'); |
|
1268 | + } else $data['datetime'] = date('Y-m-d H:i:s'); |
|
1269 | 1269 | |
1270 | - $data['departure_airport_icao'] = $line['bid']['depapt']['icao']; |
|
1271 | - $data['departure_airport_time'] = $line['bid']['deptime']; |
|
1272 | - $data['arrival_airport_icao'] = $line['bid']['arrapt']['icao']; |
|
1273 | - $data['arrival_airport_time'] = $line['bid']['arrtime']; |
|
1274 | - $data['registration'] = $line['bid']['aircraft']['registration']; |
|
1270 | + $data['departure_airport_icao'] = $line['bid']['depapt']['icao']; |
|
1271 | + $data['departure_airport_time'] = $line['bid']['deptime']; |
|
1272 | + $data['arrival_airport_icao'] = $line['bid']['arrapt']['icao']; |
|
1273 | + $data['arrival_airport_time'] = $line['bid']['arrtime']; |
|
1274 | + $data['registration'] = $line['bid']['aircraft']['registration']; |
|
1275 | 1275 | |
1276 | - if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true; |
|
1277 | - if (isset($line['bid']['route']) && $line['bid']['route'] != '') $data['waypoints'] = $line['bid']['route']; // route |
|
1278 | - $data['aircraft_icao'] = $line['bid']['aircraft']['icao']; |
|
1276 | + if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true; |
|
1277 | + if (isset($line['bid']['route']) && $line['bid']['route'] != '') $data['waypoints'] = $line['bid']['route']; // route |
|
1278 | + $data['aircraft_icao'] = $line['bid']['aircraft']['icao']; |
|
1279 | 1279 | |
1280 | - $data['id_source'] = $id_source; |
|
1281 | - $data['format_source'] = 'vaos'; |
|
1282 | - if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name']; |
|
1283 | - $SI->add($data); |
|
1284 | - unset($data); |
|
1280 | + $data['id_source'] = $id_source; |
|
1281 | + $data['format_source'] = 'vaos'; |
|
1282 | + if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name']; |
|
1283 | + $SI->add($data); |
|
1284 | + unset($data); |
|
1285 | 1285 | } |
1286 | 1286 | if ($globalDebug) echo 'No more data...'."\n"; |
1287 | 1287 | unset($buffer); |
1288 | 1288 | unset($all_data); |
1289 | - } |
|
1290 | - //$last_exec['phpvmacars'] = time(); |
|
1291 | - $last_exec[$id]['last'] = time(); |
|
1289 | + } |
|
1290 | + //$last_exec['phpvmacars'] = time(); |
|
1291 | + $last_exec[$id]['last'] = time(); |
|
1292 | 1292 | } elseif ($value['format'] == 'vam' && |
1293 | - ( |
|
1293 | + ( |
|
1294 | 1294 | (isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || |
1295 | 1295 | (!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch)) |
1296 | - ) |
|
1296 | + ) |
|
1297 | 1297 | ) { |
1298 | - //$buffer = $Common->getData($hosts[$id]); |
|
1299 | - if ($globalDebug) echo 'Get Data...'."\n"; |
|
1300 | - $buffer = $Common->getData($value['host']); |
|
1301 | - $all_data = json_decode($buffer,true); |
|
1302 | - if ($buffer != '' && is_array($all_data)) { |
|
1298 | + //$buffer = $Common->getData($hosts[$id]); |
|
1299 | + if ($globalDebug) echo 'Get Data...'."\n"; |
|
1300 | + $buffer = $Common->getData($value['host']); |
|
1301 | + $all_data = json_decode($buffer,true); |
|
1302 | + if ($buffer != '' && is_array($all_data)) { |
|
1303 | 1303 | $reset = 0; |
1304 | 1304 | foreach ($all_data as $line) { |
1305 | - $data = array(); |
|
1306 | - //$data['id'] = $line['id']; // id not usable |
|
1307 | - $data['id'] = trim($line['flight_id']); |
|
1308 | - $data['hex'] = substr(str_pad(bin2hex($line['callsign']),6,'000000',STR_PAD_LEFT),-6); // hex |
|
1309 | - $data['pilot_name'] = $line['pilot_name']; |
|
1310 | - $data['pilot_id'] = $line['pilot_id']; |
|
1311 | - $data['ident'] = trim($line['callsign']); // ident |
|
1312 | - $data['altitude'] = $line['altitude']; // altitude |
|
1313 | - $data['speed'] = $line['gs']; // speed |
|
1314 | - $data['heading'] = $line['heading']; // heading |
|
1315 | - $data['latitude'] = $line['latitude']; // lat |
|
1316 | - $data['longitude'] = $line['longitude']; // long |
|
1317 | - $data['verticalrate'] = ''; // verticale rate |
|
1318 | - $data['squawk'] = ''; // squawk |
|
1319 | - $data['emergency'] = ''; // emergency |
|
1320 | - //$data['datetime'] = $line['lastupdate']; |
|
1321 | - $data['last_update'] = $line['last_update']; |
|
1322 | - $data['datetime'] = date('Y-m-d H:i:s'); |
|
1323 | - $data['departure_airport_icao'] = $line['departure']; |
|
1324 | - //$data['departure_airport_time'] = $line['departure_time']; |
|
1325 | - $data['arrival_airport_icao'] = $line['arrival']; |
|
1326 | - //$data['arrival_airport_time'] = $line['arrival_time']; |
|
1327 | - //$data['registration'] = $line['aircraft']; |
|
1328 | - if (isset($line['route'])) $data['waypoints'] = $line['route']; // route |
|
1329 | - $data['aircraft_icao'] = $line['plane_type']; |
|
1330 | - $data['id_source'] = $id_source; |
|
1331 | - $data['format_source'] = 'vam'; |
|
1332 | - if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true; |
|
1333 | - if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name']; |
|
1334 | - $SI->add($data); |
|
1335 | - unset($data); |
|
1305 | + $data = array(); |
|
1306 | + //$data['id'] = $line['id']; // id not usable |
|
1307 | + $data['id'] = trim($line['flight_id']); |
|
1308 | + $data['hex'] = substr(str_pad(bin2hex($line['callsign']),6,'000000',STR_PAD_LEFT),-6); // hex |
|
1309 | + $data['pilot_name'] = $line['pilot_name']; |
|
1310 | + $data['pilot_id'] = $line['pilot_id']; |
|
1311 | + $data['ident'] = trim($line['callsign']); // ident |
|
1312 | + $data['altitude'] = $line['altitude']; // altitude |
|
1313 | + $data['speed'] = $line['gs']; // speed |
|
1314 | + $data['heading'] = $line['heading']; // heading |
|
1315 | + $data['latitude'] = $line['latitude']; // lat |
|
1316 | + $data['longitude'] = $line['longitude']; // long |
|
1317 | + $data['verticalrate'] = ''; // verticale rate |
|
1318 | + $data['squawk'] = ''; // squawk |
|
1319 | + $data['emergency'] = ''; // emergency |
|
1320 | + //$data['datetime'] = $line['lastupdate']; |
|
1321 | + $data['last_update'] = $line['last_update']; |
|
1322 | + $data['datetime'] = date('Y-m-d H:i:s'); |
|
1323 | + $data['departure_airport_icao'] = $line['departure']; |
|
1324 | + //$data['departure_airport_time'] = $line['departure_time']; |
|
1325 | + $data['arrival_airport_icao'] = $line['arrival']; |
|
1326 | + //$data['arrival_airport_time'] = $line['arrival_time']; |
|
1327 | + //$data['registration'] = $line['aircraft']; |
|
1328 | + if (isset($line['route'])) $data['waypoints'] = $line['route']; // route |
|
1329 | + $data['aircraft_icao'] = $line['plane_type']; |
|
1330 | + $data['id_source'] = $id_source; |
|
1331 | + $data['format_source'] = 'vam'; |
|
1332 | + if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true; |
|
1333 | + if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name']; |
|
1334 | + $SI->add($data); |
|
1335 | + unset($data); |
|
1336 | 1336 | } |
1337 | 1337 | if ($globalDebug) echo 'No more data...'."\n"; |
1338 | 1338 | unset($buffer); |
1339 | 1339 | unset($all_data); |
1340 | - } |
|
1341 | - //$last_exec['phpvmacars'] = time(); |
|
1342 | - $last_exec[$id]['last'] = time(); |
|
1340 | + } |
|
1341 | + //$last_exec['phpvmacars'] = time(); |
|
1342 | + $last_exec[$id]['last'] = time(); |
|
1343 | 1343 | } elseif ($value['format'] == 'blitzortung' && |
1344 | - ( |
|
1344 | + ( |
|
1345 | 1345 | (isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || |
1346 | 1346 | (!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch)) |
1347 | - ) |
|
1347 | + ) |
|
1348 | 1348 | ) { |
1349 | - //$buffer = $Common->getData($hosts[$id]); |
|
1350 | - if ($globalDebug) echo 'Get Data...'."\n"; |
|
1351 | - $buffer = $Common->getData($value['host']); |
|
1352 | - $all_data = json_decode($buffer,true); |
|
1353 | - if ($buffer != '') { |
|
1349 | + //$buffer = $Common->getData($hosts[$id]); |
|
1350 | + if ($globalDebug) echo 'Get Data...'."\n"; |
|
1351 | + $buffer = $Common->getData($value['host']); |
|
1352 | + $all_data = json_decode($buffer,true); |
|
1353 | + if ($buffer != '') { |
|
1354 | 1354 | $Source->deleteLocationBySource('blitzortung'); |
1355 | 1355 | $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer)); |
1356 | 1356 | $buffer = explode('\n',$buffer); |
1357 | 1357 | foreach ($buffer as $buffer_line) { |
1358 | - $line = json_decode($buffer_line,true); |
|
1359 | - if (isset($line['time'])) { |
|
1358 | + $line = json_decode($buffer_line,true); |
|
1359 | + if (isset($line['time'])) { |
|
1360 | 1360 | $data = array(); |
1361 | 1361 | $data['altitude'] = $line['alt']; // altitude |
1362 | 1362 | $data['latitude'] = $line['lat']; // lat |
@@ -1368,96 +1368,96 @@ discard block |
||
1368 | 1368 | if ($globalDebug) echo '☈ Lightning added'."\n"; |
1369 | 1369 | $Source->addLocation('',$data['latitude'],$data['longitude'],0,'','','blitzortung','weather/thunderstorm.png','lightning',$id,0,$data['datetime']); |
1370 | 1370 | unset($data); |
1371 | - } |
|
1371 | + } |
|
1372 | 1372 | } |
1373 | 1373 | if ($globalDebug) echo 'No more data...'."\n"; |
1374 | 1374 | unset($buffer); |
1375 | - } |
|
1376 | - $last_exec[$id]['last'] = time(); |
|
1375 | + } |
|
1376 | + $last_exec[$id]['last'] = time(); |
|
1377 | 1377 | //} elseif ($value == 'sbs' || $value == 'tsv' || $value == 'raw' || $value == 'aprs' || $value == 'beast') { |
1378 | 1378 | } elseif ($value['format'] == 'sbs' || $value['format'] == 'tsv' || $value['format'] == 'raw' || $value['format'] == 'aprs' || $value['format'] == 'famaprs' || $value['format'] == 'beast' || $value['format'] == 'flightgearmp' || $value['format'] == 'flightgearsp' || $value['format'] == 'acars' || $value['format'] == 'acarssbs3' || $value['format'] == 'ais' || $value['format'] == 'vrstcp') { |
1379 | - if (function_exists('pcntl_fork')) pcntl_signal_dispatch(); |
|
1380 | - //$last_exec[$id]['last'] = time(); |
|
1379 | + if (function_exists('pcntl_fork')) pcntl_signal_dispatch(); |
|
1380 | + //$last_exec[$id]['last'] = time(); |
|
1381 | 1381 | |
1382 | - //$read = array( $sockets[$id] ); |
|
1383 | - $read = $sockets; |
|
1384 | - $write = NULL; |
|
1385 | - $e = NULL; |
|
1386 | - $n = socket_select($read, $write, $e, $timeout); |
|
1387 | - if ($e != NULL) var_dump($e); |
|
1388 | - if ($n > 0) { |
|
1382 | + //$read = array( $sockets[$id] ); |
|
1383 | + $read = $sockets; |
|
1384 | + $write = NULL; |
|
1385 | + $e = NULL; |
|
1386 | + $n = socket_select($read, $write, $e, $timeout); |
|
1387 | + if ($e != NULL) var_dump($e); |
|
1388 | + if ($n > 0) { |
|
1389 | 1389 | $reset = 0; |
1390 | 1390 | foreach ($read as $nb => $r) { |
1391 | - //$value = $formats[$nb]; |
|
1392 | - $format = $globalSources[$nb]['format']; |
|
1393 | - if ($format == 'sbs' || $format == 'aprs' || $format == 'famaprs' || $format == 'raw' || $format == 'tsv' || $format == 'acarssbs3') { |
|
1391 | + //$value = $formats[$nb]; |
|
1392 | + $format = $globalSources[$nb]['format']; |
|
1393 | + if ($format == 'sbs' || $format == 'aprs' || $format == 'famaprs' || $format == 'raw' || $format == 'tsv' || $format == 'acarssbs3') { |
|
1394 | 1394 | $buffer = @socket_read($r, 6000,PHP_NORMAL_READ); |
1395 | - } elseif ($format == 'vrstcp') { |
|
1395 | + } elseif ($format == 'vrstcp') { |
|
1396 | 1396 | $buffer = @socket_read($r, 6000); |
1397 | - } else { |
|
1397 | + } else { |
|
1398 | 1398 | $az = socket_recvfrom($r,$buffer,6000,0,$remote_ip,$remote_port); |
1399 | - } |
|
1400 | - //$buffer = socket_read($r, 60000,PHP_NORMAL_READ); |
|
1401 | - //echo $buffer."\n"; |
|
1402 | - // lets play nice and handle signals such as ctrl-c/kill properly |
|
1403 | - //if (function_exists('pcntl_fork')) pcntl_signal_dispatch(); |
|
1404 | - $error = false; |
|
1405 | - //$SI::del(); |
|
1406 | - if ($buffer !== FALSE) { |
|
1399 | + } |
|
1400 | + //$buffer = socket_read($r, 60000,PHP_NORMAL_READ); |
|
1401 | + //echo $buffer."\n"; |
|
1402 | + // lets play nice and handle signals such as ctrl-c/kill properly |
|
1403 | + //if (function_exists('pcntl_fork')) pcntl_signal_dispatch(); |
|
1404 | + $error = false; |
|
1405 | + //$SI::del(); |
|
1406 | + if ($buffer !== FALSE) { |
|
1407 | 1407 | if ($format == 'vrstcp') { |
1408 | - $buffer = explode('},{',$buffer); |
|
1408 | + $buffer = explode('},{',$buffer); |
|
1409 | 1409 | } else $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'',$buffer)); |
1410 | - } |
|
1411 | - // SBS format is CSV format |
|
1412 | - if ($buffer !== FALSE && $buffer !== '') { |
|
1410 | + } |
|
1411 | + // SBS format is CSV format |
|
1412 | + if ($buffer !== FALSE && $buffer !== '') { |
|
1413 | 1413 | $tt[$format] = 0; |
1414 | 1414 | if ($format == 'acarssbs3') { |
1415 | - if ($globalDebug) echo 'ACARS : '.$buffer."\n"; |
|
1416 | - $ACARS->add(trim($buffer)); |
|
1417 | - $ACARS->deleteLiveAcarsData(); |
|
1415 | + if ($globalDebug) echo 'ACARS : '.$buffer."\n"; |
|
1416 | + $ACARS->add(trim($buffer)); |
|
1417 | + $ACARS->deleteLiveAcarsData(); |
|
1418 | 1418 | } elseif ($format == 'raw') { |
1419 | - // AVR format |
|
1420 | - $data = $SBS->parse($buffer); |
|
1421 | - if (is_array($data)) { |
|
1419 | + // AVR format |
|
1420 | + $data = $SBS->parse($buffer); |
|
1421 | + if (is_array($data)) { |
|
1422 | 1422 | $data['datetime'] = date('Y-m-d H:i:s'); |
1423 | 1423 | $data['format_source'] = 'raw'; |
1424 | 1424 | if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name']; |
1425 | 1425 | if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats']; |
1426 | 1426 | if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true; |
1427 | 1427 | if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data); |
1428 | - } |
|
1428 | + } |
|
1429 | 1429 | } elseif ($format == 'ais') { |
1430 | - $ais_data = $AIS->parse_line(trim($buffer)); |
|
1431 | - $data = array(); |
|
1432 | - if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident']; |
|
1433 | - if (isset($ais_data['mmsi'])) $data['mmsi'] = substr($ais_data['mmsi'],-9); |
|
1434 | - if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed']; |
|
1435 | - if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading']; |
|
1436 | - if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude']; |
|
1437 | - if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude']; |
|
1438 | - if (isset($ais_data['status'])) $data['status'] = $ais_data['status']; |
|
1439 | - if (isset($ais_data['statusid'])) $data['status_id'] = $ais_data['statusid']; |
|
1440 | - if (isset($ais_data['type'])) $data['type'] = $ais_data['type']; |
|
1441 | - if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo']; |
|
1442 | - if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign']; |
|
1443 | - if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination']; |
|
1444 | - if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']); |
|
1445 | - if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true; |
|
1446 | - if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name']; |
|
1447 | - if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats']; |
|
1430 | + $ais_data = $AIS->parse_line(trim($buffer)); |
|
1431 | + $data = array(); |
|
1432 | + if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident']; |
|
1433 | + if (isset($ais_data['mmsi'])) $data['mmsi'] = substr($ais_data['mmsi'],-9); |
|
1434 | + if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed']; |
|
1435 | + if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading']; |
|
1436 | + if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude']; |
|
1437 | + if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude']; |
|
1438 | + if (isset($ais_data['status'])) $data['status'] = $ais_data['status']; |
|
1439 | + if (isset($ais_data['statusid'])) $data['status_id'] = $ais_data['statusid']; |
|
1440 | + if (isset($ais_data['type'])) $data['type'] = $ais_data['type']; |
|
1441 | + if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo']; |
|
1442 | + if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign']; |
|
1443 | + if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination']; |
|
1444 | + if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']); |
|
1445 | + if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true; |
|
1446 | + if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name']; |
|
1447 | + if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats']; |
|
1448 | 1448 | |
1449 | - if (isset($ais_data['timestamp'])) { |
|
1449 | + if (isset($ais_data['timestamp'])) { |
|
1450 | 1450 | $data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']); |
1451 | - } else { |
|
1451 | + } else { |
|
1452 | 1452 | $data['datetime'] = date('Y-m-d H:i:s'); |
1453 | - } |
|
1454 | - $data['format_source'] = 'aisnmea'; |
|
1455 | - $data['id_source'] = $id_source; |
|
1456 | - if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') $MI->add($data); |
|
1457 | - unset($data); |
|
1458 | - } elseif ($format == 'flightgearsp') { |
|
1459 | - //echo $buffer."\n"; |
|
1460 | - if (strlen($buffer) > 5) { |
|
1453 | + } |
|
1454 | + $data['format_source'] = 'aisnmea'; |
|
1455 | + $data['id_source'] = $id_source; |
|
1456 | + if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') $MI->add($data); |
|
1457 | + unset($data); |
|
1458 | + } elseif ($format == 'flightgearsp') { |
|
1459 | + //echo $buffer."\n"; |
|
1460 | + if (strlen($buffer) > 5) { |
|
1461 | 1461 | $line = explode(',',$buffer); |
1462 | 1462 | $data = array(); |
1463 | 1463 | //XGPS,2.0947,41.3093,-3047.6953,198.930,0.000,callsign,c172p |
@@ -1474,38 +1474,38 @@ discard block |
||
1474 | 1474 | if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true; |
1475 | 1475 | if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data); |
1476 | 1476 | //$send = @ socket_send( $r , $data_aprs , strlen($data_aprs) , 0 ); |
1477 | - } |
|
1478 | - } elseif ($format == 'acars') { |
|
1479 | - if ($globalDebug) echo 'ACARS : '.$buffer."\n"; |
|
1480 | - $ACARS->add(trim($buffer)); |
|
1481 | - socket_sendto($r, "OK " . $buffer , 100 , 0 , $remote_ip , $remote_port); |
|
1482 | - $ACARS->deleteLiveAcarsData(); |
|
1477 | + } |
|
1478 | + } elseif ($format == 'acars') { |
|
1479 | + if ($globalDebug) echo 'ACARS : '.$buffer."\n"; |
|
1480 | + $ACARS->add(trim($buffer)); |
|
1481 | + socket_sendto($r, "OK " . $buffer , 100 , 0 , $remote_ip , $remote_port); |
|
1482 | + $ACARS->deleteLiveAcarsData(); |
|
1483 | 1483 | } elseif ($format == 'flightgearmp') { |
1484 | - if (substr($buffer,0,1) != '#') { |
|
1484 | + if (substr($buffer,0,1) != '#') { |
|
1485 | 1485 | $data = array(); |
1486 | 1486 | //echo $buffer."\n"; |
1487 | 1487 | $line = explode(' ',$buffer); |
1488 | 1488 | if (count($line) == 11) { |
1489 | - $userserver = explode('@',$line[0]); |
|
1490 | - $data['hex'] = substr(str_pad(bin2hex($line[0]),6,'000000',STR_PAD_LEFT),0,6); // hex |
|
1491 | - $data['ident'] = $userserver[0]; |
|
1492 | - $data['registration'] = $userserver[0]; |
|
1493 | - $data['latitude'] = $line[4]; |
|
1494 | - $data['longitude'] = $line[5]; |
|
1495 | - $data['altitude'] = $line[6]; |
|
1496 | - $data['datetime'] = date('Y-m-d H:i:s'); |
|
1497 | - $aircraft_type = $line[10]; |
|
1498 | - $aircraft_type = preg_split(':/:',$aircraft_type); |
|
1499 | - $data['aircraft_name'] = substr(end($aircraft_type),0,-4); |
|
1500 | - if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true; |
|
1501 | - if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data); |
|
1489 | + $userserver = explode('@',$line[0]); |
|
1490 | + $data['hex'] = substr(str_pad(bin2hex($line[0]),6,'000000',STR_PAD_LEFT),0,6); // hex |
|
1491 | + $data['ident'] = $userserver[0]; |
|
1492 | + $data['registration'] = $userserver[0]; |
|
1493 | + $data['latitude'] = $line[4]; |
|
1494 | + $data['longitude'] = $line[5]; |
|
1495 | + $data['altitude'] = $line[6]; |
|
1496 | + $data['datetime'] = date('Y-m-d H:i:s'); |
|
1497 | + $aircraft_type = $line[10]; |
|
1498 | + $aircraft_type = preg_split(':/:',$aircraft_type); |
|
1499 | + $data['aircraft_name'] = substr(end($aircraft_type),0,-4); |
|
1500 | + if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true; |
|
1501 | + if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data); |
|
1502 | + } |
|
1502 | 1503 | } |
1503 | - } |
|
1504 | 1504 | } elseif ($format == 'beast') { |
1505 | - echo 'Beast Binary format not yet supported. Beast AVR format is supported in alpha state'."\n"; |
|
1506 | - die; |
|
1505 | + echo 'Beast Binary format not yet supported. Beast AVR format is supported in alpha state'."\n"; |
|
1506 | + die; |
|
1507 | 1507 | } elseif ($format == 'vrstcp') { |
1508 | - foreach($buffer as $all_data) { |
|
1508 | + foreach($buffer as $all_data) { |
|
1509 | 1509 | $line = json_decode('{'.$all_data.'}',true); |
1510 | 1510 | $data = array(); |
1511 | 1511 | if (isset($line['Icao'])) $data['hex'] = $line['Icao']; // hex |
@@ -1525,153 +1525,153 @@ discard block |
||
1525 | 1525 | */ |
1526 | 1526 | $data['datetime'] = date('Y-m-d H:i:s'); |
1527 | 1527 | if (isset($line['Type'])) $data['aircraft_icao'] = $line['Type']; |
1528 | - $data['format_source'] = 'vrstcp'; |
|
1528 | + $data['format_source'] = 'vrstcp'; |
|
1529 | 1529 | $data['id_source'] = $id_source; |
1530 | 1530 | if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true; |
1531 | 1531 | if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name']; |
1532 | 1532 | if (isset($data['latitude']) && isset($data['hex'])) $SI->add($data); |
1533 | 1533 | unset($data); |
1534 | - } |
|
1534 | + } |
|
1535 | 1535 | } elseif ($format == 'tsv' || substr($buffer,0,4) == 'clock') { |
1536 | - $line = explode("\t", $buffer); |
|
1537 | - for($k = 0; $k < count($line); $k=$k+2) { |
|
1536 | + $line = explode("\t", $buffer); |
|
1537 | + for($k = 0; $k < count($line); $k=$k+2) { |
|
1538 | 1538 | $key = $line[$k]; |
1539 | - $lined[$key] = $line[$k+1]; |
|
1540 | - } |
|
1541 | - if (count($lined) > 3) { |
|
1542 | - $data['hex'] = $lined['hexid']; |
|
1543 | - //$data['datetime'] = date('Y-m-d H:i:s',strtotime($lined['clock']));; |
|
1544 | - $data['datetime'] = date('Y-m-d H:i:s');; |
|
1545 | - if (isset($lined['ident'])) $data['ident'] = $lined['ident']; |
|
1546 | - if (isset($lined['lat'])) $data['latitude'] = $lined['lat']; |
|
1547 | - if (isset($lined['lon'])) $data['longitude'] = $lined['lon']; |
|
1548 | - if (isset($lined['speed'])) $data['speed'] = $lined['speed']; |
|
1549 | - if (isset($lined['squawk'])) $data['squawk'] = $lined['squawk']; |
|
1550 | - if (isset($lined['alt'])) $data['altitude'] = $lined['alt']; |
|
1551 | - if (isset($lined['heading'])) $data['heading'] = $lined['heading']; |
|
1552 | - $data['id_source'] = $id_source; |
|
1553 | - $data['format_source'] = 'tsv'; |
|
1554 | - if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name']; |
|
1555 | - if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats']; |
|
1539 | + $lined[$key] = $line[$k+1]; |
|
1540 | + } |
|
1541 | + if (count($lined) > 3) { |
|
1542 | + $data['hex'] = $lined['hexid']; |
|
1543 | + //$data['datetime'] = date('Y-m-d H:i:s',strtotime($lined['clock']));; |
|
1544 | + $data['datetime'] = date('Y-m-d H:i:s');; |
|
1545 | + if (isset($lined['ident'])) $data['ident'] = $lined['ident']; |
|
1546 | + if (isset($lined['lat'])) $data['latitude'] = $lined['lat']; |
|
1547 | + if (isset($lined['lon'])) $data['longitude'] = $lined['lon']; |
|
1548 | + if (isset($lined['speed'])) $data['speed'] = $lined['speed']; |
|
1549 | + if (isset($lined['squawk'])) $data['squawk'] = $lined['squawk']; |
|
1550 | + if (isset($lined['alt'])) $data['altitude'] = $lined['alt']; |
|
1551 | + if (isset($lined['heading'])) $data['heading'] = $lined['heading']; |
|
1552 | + $data['id_source'] = $id_source; |
|
1553 | + $data['format_source'] = 'tsv'; |
|
1554 | + if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name']; |
|
1555 | + if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats']; |
|
1556 | 1556 | if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true; |
1557 | - if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data); |
|
1558 | - unset($lined); |
|
1559 | - unset($data); |
|
1560 | - } else $error = true; |
|
1557 | + if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data); |
|
1558 | + unset($lined); |
|
1559 | + unset($data); |
|
1560 | + } else $error = true; |
|
1561 | 1561 | } elseif ($format == 'aprs' && $use_aprs) { |
1562 | - if ($aprs_connect == 0) { |
|
1562 | + if ($aprs_connect == 0) { |
|
1563 | 1563 | $send = @ socket_send( $r , $aprs_login , strlen($aprs_login) , 0 ); |
1564 | 1564 | $aprs_connect = 1; |
1565 | - } |
|
1565 | + } |
|
1566 | 1566 | |
1567 | - if ( $aprs_keep>60 && time() - $aprs_last_tx > $aprs_keep ) { |
|
1567 | + if ( $aprs_keep>60 && time() - $aprs_last_tx > $aprs_keep ) { |
|
1568 | 1568 | $aprs_last_tx = time(); |
1569 | 1569 | $data_aprs = "# Keep alive"; |
1570 | 1570 | $send = @ socket_send( $r , $data_aprs , strlen($data_aprs) , 0 ); |
1571 | - } |
|
1571 | + } |
|
1572 | 1572 | |
1573 | - //echo 'Connect : '.$aprs_connect.' '.$buffer."\n"; |
|
1574 | - //echo 'APRS data : '.$buffer."\n"; |
|
1575 | - $buffer = str_replace('APRS <- ','',$buffer); |
|
1576 | - $buffer = str_replace('APRS -> ','',$buffer); |
|
1577 | - //echo $buffer."\n"; |
|
1578 | - date_default_timezone_set('UTC'); |
|
1579 | - if (substr($buffer,0,1) != '#' && substr($buffer,0,1) != '@' && substr($buffer,0,5) != 'APRS ') { |
|
1573 | + //echo 'Connect : '.$aprs_connect.' '.$buffer."\n"; |
|
1574 | + //echo 'APRS data : '.$buffer."\n"; |
|
1575 | + $buffer = str_replace('APRS <- ','',$buffer); |
|
1576 | + $buffer = str_replace('APRS -> ','',$buffer); |
|
1577 | + //echo $buffer."\n"; |
|
1578 | + date_default_timezone_set('UTC'); |
|
1579 | + if (substr($buffer,0,1) != '#' && substr($buffer,0,1) != '@' && substr($buffer,0,5) != 'APRS ') { |
|
1580 | 1580 | $line = $APRS->parse($buffer); |
1581 | 1581 | //if (is_array($line) && isset($line['address']) && $line['address'] != '' && isset($line['ident'])) { |
1582 | 1582 | if (is_array($line) && isset($line['latitude']) && isset($line['longitude']) && (isset($line['ident']) || isset($line['address']) || isset($line['mmsi']))) { |
1583 | - $aprs_last_tx = time(); |
|
1584 | - $data = array(); |
|
1585 | - //print_r($line); |
|
1586 | - if (isset($line['address'])) $data['hex'] = $line['address']; |
|
1587 | - if (isset($line['mmsi'])) $data['mmsi'] = $line['mmsi']; |
|
1588 | - if (isset($line['imo'])) $data['imo'] = $line['imo']; |
|
1589 | - if (isset($line['squawk'])) $data['squawk'] = $line['squawk']; |
|
1590 | - if (isset($line['arrival_code'])) $data['arrival_code'] = $line['arrival_code']; |
|
1591 | - if (isset($line['arrival_date'])) $data['arrival_date'] = $line['arrival_date']; |
|
1592 | - if (isset($line['typeid'])) $data['type_id'] = $line['typeid']; |
|
1593 | - if (isset($line['statusid'])) $data['status_id'] = $line['statusid']; |
|
1594 | - if (isset($line['timestamp'])) $data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']); |
|
1595 | - else $data['datetime'] = date('Y-m-d H:i:s'); |
|
1596 | - //$data['datetime'] = date('Y-m-d H:i:s'); |
|
1597 | - if (isset($line['ident'])) $data['ident'] = $line['ident']; |
|
1598 | - $data['latitude'] = $line['latitude']; |
|
1599 | - $data['longitude'] = $line['longitude']; |
|
1600 | - //$data['verticalrate'] = $line[16]; |
|
1601 | - if (isset($line['speed'])) $data['speed'] = $line['speed']; |
|
1602 | - //else $data['speed'] = 0; |
|
1603 | - if (isset($line['altitude'])) $data['altitude'] = $line['altitude']; |
|
1604 | - if (isset($line['comment'])) $data['comment'] = $line['comment']; |
|
1605 | - if (isset($line['symbol'])) $data['type'] = $line['symbol']; |
|
1606 | - //if (isset($line['heading'])) $data['heading'] = $line['heading']; |
|
1583 | + $aprs_last_tx = time(); |
|
1584 | + $data = array(); |
|
1585 | + //print_r($line); |
|
1586 | + if (isset($line['address'])) $data['hex'] = $line['address']; |
|
1587 | + if (isset($line['mmsi'])) $data['mmsi'] = $line['mmsi']; |
|
1588 | + if (isset($line['imo'])) $data['imo'] = $line['imo']; |
|
1589 | + if (isset($line['squawk'])) $data['squawk'] = $line['squawk']; |
|
1590 | + if (isset($line['arrival_code'])) $data['arrival_code'] = $line['arrival_code']; |
|
1591 | + if (isset($line['arrival_date'])) $data['arrival_date'] = $line['arrival_date']; |
|
1592 | + if (isset($line['typeid'])) $data['type_id'] = $line['typeid']; |
|
1593 | + if (isset($line['statusid'])) $data['status_id'] = $line['statusid']; |
|
1594 | + if (isset($line['timestamp'])) $data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']); |
|
1595 | + else $data['datetime'] = date('Y-m-d H:i:s'); |
|
1596 | + //$data['datetime'] = date('Y-m-d H:i:s'); |
|
1597 | + if (isset($line['ident'])) $data['ident'] = $line['ident']; |
|
1598 | + $data['latitude'] = $line['latitude']; |
|
1599 | + $data['longitude'] = $line['longitude']; |
|
1600 | + //$data['verticalrate'] = $line[16]; |
|
1601 | + if (isset($line['speed'])) $data['speed'] = $line['speed']; |
|
1602 | + //else $data['speed'] = 0; |
|
1603 | + if (isset($line['altitude'])) $data['altitude'] = $line['altitude']; |
|
1604 | + if (isset($line['comment'])) $data['comment'] = $line['comment']; |
|
1605 | + if (isset($line['symbol'])) $data['type'] = $line['symbol']; |
|
1606 | + //if (isset($line['heading'])) $data['heading'] = $line['heading']; |
|
1607 | 1607 | |
1608 | - if (isset($line['heading']) && isset($line['format_source'])) $data['heading'] = $line['heading']; |
|
1609 | - //else echo 'No heading...'."\n"; |
|
1610 | - //else $data['heading'] = 0; |
|
1611 | - if (isset($line['stealth'])) $data['aircraft_type'] = $line['stealth']; |
|
1612 | - //if (!isset($line['source_type']) && (!isset($globalAPRSarchive) || (isset($globalAPRSarchive) && $globalAPRSarchive === FALSE))) $data['noarchive'] = true; |
|
1613 | - if (isset($globalAPRSarchive) && $globalAPRSarchive === FALSE) $data['noarchive'] = true; |
|
1614 | - elseif (isset($globalAPRSarchive) && $globalAPRSarchive === TRUE) $data['noarchive'] = false; |
|
1615 | - if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true; |
|
1616 | - elseif (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === FALSE) $data['noarchive'] = false; |
|
1617 | - $data['id_source'] = $id_source; |
|
1618 | - if (isset($line['format_source'])) $data['format_source'] = $line['format_source']; |
|
1619 | - else $data['format_source'] = 'aprs'; |
|
1620 | - $data['source_name'] = $line['source']; |
|
1621 | - if (isset($line['source_type'])) $data['source_type'] = $line['source_type']; |
|
1622 | - else $data['source_type'] = 'flarm'; |
|
1623 | - if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats']; |
|
1624 | - $currentdate = date('Y-m-d H:i:s'); |
|
1625 | - $aprsdate = strtotime($data['datetime']); |
|
1626 | - if ($data['source_type'] != 'modes' && $data['source_type'] != 'ais') $data['altitude_relative'] = 'AMSL'; |
|
1627 | - // Accept data if time <= system time + 20s |
|
1628 | - //if (($data['source_type'] == 'modes') || isset($line['stealth']) && ($line['stealth'] == 0 || $line['stealth'] == '') && (strtotime($data['datetime']) <= strtotime($currentdate)+20) && (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude'])))) { |
|
1629 | - if (($data['source_type'] == 'modes') || isset($line['stealth']) && ($line['stealth'] == 0 || $line['stealth'] == '') && (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude'])))) { |
|
1608 | + if (isset($line['heading']) && isset($line['format_source'])) $data['heading'] = $line['heading']; |
|
1609 | + //else echo 'No heading...'."\n"; |
|
1610 | + //else $data['heading'] = 0; |
|
1611 | + if (isset($line['stealth'])) $data['aircraft_type'] = $line['stealth']; |
|
1612 | + //if (!isset($line['source_type']) && (!isset($globalAPRSarchive) || (isset($globalAPRSarchive) && $globalAPRSarchive === FALSE))) $data['noarchive'] = true; |
|
1613 | + if (isset($globalAPRSarchive) && $globalAPRSarchive === FALSE) $data['noarchive'] = true; |
|
1614 | + elseif (isset($globalAPRSarchive) && $globalAPRSarchive === TRUE) $data['noarchive'] = false; |
|
1615 | + if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true; |
|
1616 | + elseif (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === FALSE) $data['noarchive'] = false; |
|
1617 | + $data['id_source'] = $id_source; |
|
1618 | + if (isset($line['format_source'])) $data['format_source'] = $line['format_source']; |
|
1619 | + else $data['format_source'] = 'aprs'; |
|
1620 | + $data['source_name'] = $line['source']; |
|
1621 | + if (isset($line['source_type'])) $data['source_type'] = $line['source_type']; |
|
1622 | + else $data['source_type'] = 'flarm'; |
|
1623 | + if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats']; |
|
1624 | + $currentdate = date('Y-m-d H:i:s'); |
|
1625 | + $aprsdate = strtotime($data['datetime']); |
|
1626 | + if ($data['source_type'] != 'modes' && $data['source_type'] != 'ais') $data['altitude_relative'] = 'AMSL'; |
|
1627 | + // Accept data if time <= system time + 20s |
|
1628 | + //if (($data['source_type'] == 'modes') || isset($line['stealth']) && ($line['stealth'] == 0 || $line['stealth'] == '') && (strtotime($data['datetime']) <= strtotime($currentdate)+20) && (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude'])))) { |
|
1629 | + if (($data['source_type'] == 'modes') || isset($line['stealth']) && ($line['stealth'] == 0 || $line['stealth'] == '') && (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude'])))) { |
|
1630 | 1630 | $send = $SI->add($data); |
1631 | - } elseif ($data['source_type'] == 'ais') { |
|
1631 | + } elseif ($data['source_type'] == 'ais') { |
|
1632 | 1632 | $data['type'] = ''; |
1633 | 1633 | if (isset($globalMarine) && $globalMarine) $send = $MI->add($data); |
1634 | - } elseif (isset($line['stealth'])) { |
|
1634 | + } elseif (isset($line['stealth'])) { |
|
1635 | 1635 | if ($line['stealth'] != 0) echo '-------- '.$data['ident'].' : APRS stealth ON => not adding'."\n"; |
1636 | 1636 | else echo '--------- '.$data['ident'].' : Date APRS : '.$data['datetime'].' - Current date : '.$currentdate.' => not adding future event'."\n"; |
1637 | - } elseif (isset($globalAircraft) && $globalAircraft && isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && ( |
|
1638 | - //$line['symbol'] == 'Balloon' || |
|
1639 | - $line['symbol'] == 'Glider' || |
|
1640 | - $line['symbol'] == 'Aircraft (small)' || $line['symbol'] == 'Helicopter')) { |
|
1641 | - if ($line['symbol'] == 'Ballon') $data['aircraft_icao'] = 'BALL'; |
|
1642 | - if ($line['symbol'] == 'Glider') $data['aircraft_icao'] = 'PARAGLIDER'; |
|
1643 | - $send = $SI->add($data); |
|
1644 | - } elseif (isset($globalMarine) && $globalMarine && isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && ( |
|
1645 | - $line['symbol'] == 'Yacht (Sail)' || |
|
1646 | - $line['symbol'] == 'Ship (Power Boat)')) { |
|
1647 | - $send = $MI->add($data); |
|
1648 | - } elseif (isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && ( |
|
1649 | - $line['symbol'] == 'Car' || |
|
1650 | - $line['symbol'] == 'Ambulance' || |
|
1651 | - $line['symbol'] == 'Van' || |
|
1652 | - $line['symbol'] == 'Truck' || $line['symbol'] == 'Truck (18 Wheeler)' || |
|
1653 | - $line['symbol'] == 'Motorcycle' || |
|
1654 | - $line['symbol'] == 'Tractor' || |
|
1655 | - $line['symbol'] == 'Police' || |
|
1656 | - $line['symbol'] == 'Bike' || |
|
1657 | - $line['symbol'] == 'Jogger' || |
|
1658 | - $line['symbol'] == 'Horse' || |
|
1659 | - $line['symbol'] == 'Bus' || |
|
1660 | - $line['symbol'] == 'Jeep' || |
|
1661 | - $line['symbol'] == 'Recreational Vehicle' || |
|
1662 | - $line['symbol'] == 'Yacht (Sail)' || |
|
1663 | - $line['symbol'] == 'Ship (Power Boat)' || |
|
1664 | - $line['symbol'] == 'Firetruck' || |
|
1665 | - $line['symbol'] == 'Balloon' || $line['symbol'] == 'Glider' || |
|
1666 | - $line['symbol'] == 'Aircraft (small)' || $line['symbol'] == 'Helicopter' || |
|
1667 | - $line['symbol'] == 'SUV' || |
|
1668 | - $line['symbol'] == 'Snowmobile' || |
|
1669 | - $line['symbol'] == 'Mobile Satellite Station')) { |
|
1670 | - //} elseif (isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && isset($line['speed']) && $line['symbol'] != 'Weather Station' && $line['symbol'] != 'House QTH (VHF)' && $line['symbol'] != 'Dot' && $line['symbol'] != 'TCP-IP' && $line['symbol'] != 'xAPRS (UNIX)' && $line['symbol'] != 'Antenna' && $line['symbol'] != 'Cloudy' && $line['symbol'] != 'HF Gateway' && $line['symbol'] != 'Yagi At QTH' && $line['symbol'] != 'Digi' && $line['symbol'] != '8' && $line['symbol'] != 'MacAPRS') { |
|
1637 | + } elseif (isset($globalAircraft) && $globalAircraft && isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && ( |
|
1638 | + //$line['symbol'] == 'Balloon' || |
|
1639 | + $line['symbol'] == 'Glider' || |
|
1640 | + $line['symbol'] == 'Aircraft (small)' || $line['symbol'] == 'Helicopter')) { |
|
1641 | + if ($line['symbol'] == 'Ballon') $data['aircraft_icao'] = 'BALL'; |
|
1642 | + if ($line['symbol'] == 'Glider') $data['aircraft_icao'] = 'PARAGLIDER'; |
|
1643 | + $send = $SI->add($data); |
|
1644 | + } elseif (isset($globalMarine) && $globalMarine && isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && ( |
|
1645 | + $line['symbol'] == 'Yacht (Sail)' || |
|
1646 | + $line['symbol'] == 'Ship (Power Boat)')) { |
|
1647 | + $send = $MI->add($data); |
|
1648 | + } elseif (isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && ( |
|
1649 | + $line['symbol'] == 'Car' || |
|
1650 | + $line['symbol'] == 'Ambulance' || |
|
1651 | + $line['symbol'] == 'Van' || |
|
1652 | + $line['symbol'] == 'Truck' || $line['symbol'] == 'Truck (18 Wheeler)' || |
|
1653 | + $line['symbol'] == 'Motorcycle' || |
|
1654 | + $line['symbol'] == 'Tractor' || |
|
1655 | + $line['symbol'] == 'Police' || |
|
1656 | + $line['symbol'] == 'Bike' || |
|
1657 | + $line['symbol'] == 'Jogger' || |
|
1658 | + $line['symbol'] == 'Horse' || |
|
1659 | + $line['symbol'] == 'Bus' || |
|
1660 | + $line['symbol'] == 'Jeep' || |
|
1661 | + $line['symbol'] == 'Recreational Vehicle' || |
|
1662 | + $line['symbol'] == 'Yacht (Sail)' || |
|
1663 | + $line['symbol'] == 'Ship (Power Boat)' || |
|
1664 | + $line['symbol'] == 'Firetruck' || |
|
1665 | + $line['symbol'] == 'Balloon' || $line['symbol'] == 'Glider' || |
|
1666 | + $line['symbol'] == 'Aircraft (small)' || $line['symbol'] == 'Helicopter' || |
|
1667 | + $line['symbol'] == 'SUV' || |
|
1668 | + $line['symbol'] == 'Snowmobile' || |
|
1669 | + $line['symbol'] == 'Mobile Satellite Station')) { |
|
1670 | + //} elseif (isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && isset($line['speed']) && $line['symbol'] != 'Weather Station' && $line['symbol'] != 'House QTH (VHF)' && $line['symbol'] != 'Dot' && $line['symbol'] != 'TCP-IP' && $line['symbol'] != 'xAPRS (UNIX)' && $line['symbol'] != 'Antenna' && $line['symbol'] != 'Cloudy' && $line['symbol'] != 'HF Gateway' && $line['symbol'] != 'Yagi At QTH' && $line['symbol'] != 'Digi' && $line['symbol'] != '8' && $line['symbol'] != 'MacAPRS') { |
|
1671 | 1671 | // } elseif (isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && $line['symbol'] != 'Weather Station' && $line['symbol'] != 'House QTH (VHF)' && $line['symbol'] != 'Dot' && $line['symbol'] != 'TCP-IP' && $line['symbol'] != 'xAPRS (UNIX)' && $line['symbol'] != 'Antenna' && $line['symbol'] != 'Cloudy' && $line['symbol'] != 'HF Gateway' && $line['symbol'] != 'Yagi At QTH' && $line['symbol'] != 'Digi' && $line['symbol'] != '8' && $line['symbol'] != 'MacAPRS') { |
1672 | 1672 | //echo '!!!!!!!!!!!!!!!! SEND !!!!!!!!!!!!!!!!!!!!'."\n"; |
1673 | 1673 | if (isset($globalTracker) && $globalTracker) $send = $TI->add($data); |
1674 | - } elseif (!isset($line['stealth']) && is_numeric($data['latitude']) && is_numeric($data['longitude']) && isset($data['ident']) && isset($data['altitude'])) { |
|
1674 | + } elseif (!isset($line['stealth']) && is_numeric($data['latitude']) && is_numeric($data['longitude']) && isset($data['ident']) && isset($data['altitude'])) { |
|
1675 | 1675 | if (!isset($data['altitude'])) $data['altitude'] = 0; |
1676 | 1676 | $Source->deleteOldLocationByType('gs'); |
1677 | 1677 | if (count($Source->getLocationInfoByNameType($data['ident'],'gs')) > 0) { |
@@ -1679,7 +1679,7 @@ discard block |
||
1679 | 1679 | } else { |
1680 | 1680 | $Source->addLocation($data['ident'],$data['latitude'],$data['longitude'],$data['altitude'],'','',$data['source_name'],'antenna.png','gs',$id,0,$data['datetime']); |
1681 | 1681 | } |
1682 | - } elseif (isset($line['symbol']) && $line['symbol'] == 'Weather Station') { |
|
1682 | + } elseif (isset($line['symbol']) && $line['symbol'] == 'Weather Station') { |
|
1683 | 1683 | //if ($globalDebug) echo '!! Weather Station not yet supported'."\n"; |
1684 | 1684 | if ($globalDebug) echo '# Weather Station added'."\n"; |
1685 | 1685 | $Source->deleteOldLocationByType('wx'); |
@@ -1689,7 +1689,7 @@ discard block |
||
1689 | 1689 | } else { |
1690 | 1690 | $Source->addLocation($data['ident'],$data['latitude'],$data['longitude'],0,'','',$data['source_name'],'wx.png','wx',$id,0,$data['datetime'],$weather_data); |
1691 | 1691 | } |
1692 | - } elseif (isset($line['symbol']) && ($line['symbol'] == 'Lightning' || $line['symbol'] == 'Thunderstorm')) { |
|
1692 | + } elseif (isset($line['symbol']) && ($line['symbol'] == 'Lightning' || $line['symbol'] == 'Thunderstorm')) { |
|
1693 | 1693 | //if ($globalDebug) echo '!! Weather Station not yet supported'."\n"; |
1694 | 1694 | if ($globalDebug) echo '☈ Lightning added'."\n"; |
1695 | 1695 | $Source->deleteOldLocationByType('lightning'); |
@@ -1698,11 +1698,11 @@ discard block |
||
1698 | 1698 | } else { |
1699 | 1699 | $Source->addLocation($data['ident'],$data['latitude'],$data['longitude'],0,'','',$data['source_name'],'weather/thunderstorm.png','lightning',$id,0,$data['datetime'],$data['comment']); |
1700 | 1700 | } |
1701 | - } elseif ($globalDebug) { |
|
1702 | - echo '/!\ Not added: '.$buffer."\n"; |
|
1703 | - print_r($line); |
|
1704 | - } |
|
1705 | - unset($data); |
|
1701 | + } elseif ($globalDebug) { |
|
1702 | + echo '/!\ Not added: '.$buffer."\n"; |
|
1703 | + print_r($line); |
|
1704 | + } |
|
1705 | + unset($data); |
|
1706 | 1706 | } |
1707 | 1707 | elseif (is_array($line) && isset($line['ident']) && $line['ident'] != '') { |
1708 | 1708 | $Source->updateLocationDescByName($line['ident'],$line['source'],$id,$line['comment']); |
@@ -1721,12 +1721,12 @@ discard block |
||
1721 | 1721 | } elseif (!isset($globalSources[$nb]['last_weather_clean'])) { |
1722 | 1722 | $globalSources[$nb]['last_weather_clean'] = time(); |
1723 | 1723 | } |
1724 | - } |
|
1724 | + } |
|
1725 | 1725 | } else { |
1726 | - $line = explode(',', $buffer); |
|
1727 | - if (count($line) > 20) { |
|
1728 | - $data['hex'] = $line[4]; |
|
1729 | - /* |
|
1726 | + $line = explode(',', $buffer); |
|
1727 | + if (count($line) > 20) { |
|
1728 | + $data['hex'] = $line[4]; |
|
1729 | + /* |
|
1730 | 1730 | $data['datetime'] = $line[6].' '.$line[7]; |
1731 | 1731 | date_default_timezone_set($globalTimezone); |
1732 | 1732 | $datetime = new DateTime($data['datetime']); |
@@ -1734,30 +1734,30 @@ discard block |
||
1734 | 1734 | $data['datetime'] = $datetime->format('Y-m-d H:i:s'); |
1735 | 1735 | date_default_timezone_set('UTC'); |
1736 | 1736 | */ |
1737 | - // Force datetime to current UTC datetime |
|
1738 | - date_default_timezone_set('UTC'); |
|
1739 | - $data['datetime'] = date('Y-m-d H:i:s'); |
|
1740 | - $data['ident'] = trim($line[10]); |
|
1741 | - $data['latitude'] = $line[14]; |
|
1742 | - $data['longitude'] = $line[15]; |
|
1743 | - $data['verticalrate'] = $line[16]; |
|
1744 | - $data['emergency'] = $line[20]; |
|
1745 | - $data['speed'] = $line[12]; |
|
1746 | - $data['squawk'] = $line[17]; |
|
1747 | - $data['altitude'] = $line[11]; |
|
1748 | - $data['heading'] = $line[13]; |
|
1749 | - $data['ground'] = $line[21]; |
|
1750 | - $data['emergency'] = $line[19]; |
|
1751 | - $data['format_source'] = 'sbs'; |
|
1737 | + // Force datetime to current UTC datetime |
|
1738 | + date_default_timezone_set('UTC'); |
|
1739 | + $data['datetime'] = date('Y-m-d H:i:s'); |
|
1740 | + $data['ident'] = trim($line[10]); |
|
1741 | + $data['latitude'] = $line[14]; |
|
1742 | + $data['longitude'] = $line[15]; |
|
1743 | + $data['verticalrate'] = $line[16]; |
|
1744 | + $data['emergency'] = $line[20]; |
|
1745 | + $data['speed'] = $line[12]; |
|
1746 | + $data['squawk'] = $line[17]; |
|
1747 | + $data['altitude'] = $line[11]; |
|
1748 | + $data['heading'] = $line[13]; |
|
1749 | + $data['ground'] = $line[21]; |
|
1750 | + $data['emergency'] = $line[19]; |
|
1751 | + $data['format_source'] = 'sbs'; |
|
1752 | 1752 | if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name']; |
1753 | - if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats']; |
|
1753 | + if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats']; |
|
1754 | 1754 | if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true; |
1755 | - $data['id_source'] = $id_source; |
|
1756 | - if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $send = $SI->add($data); |
|
1757 | - else $error = true; |
|
1758 | - unset($data); |
|
1759 | - } else $error = true; |
|
1760 | - if ($error) { |
|
1755 | + $data['id_source'] = $id_source; |
|
1756 | + if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $send = $SI->add($data); |
|
1757 | + else $error = true; |
|
1758 | + unset($data); |
|
1759 | + } else $error = true; |
|
1760 | + if ($error) { |
|
1761 | 1761 | if (count($line) > 1 && ($line[0] == 'STA' || $line[0] == 'AIR' || $line[0] == 'SEL' || $line[0] == 'ID' || $line[0] == 'CLK')) { |
1762 | 1762 | if ($globalDebug) echo "Not a message. Ignoring... \n"; |
1763 | 1763 | } else { |
@@ -1773,13 +1773,13 @@ discard block |
||
1773 | 1773 | connect_all($sourceer); |
1774 | 1774 | $sourceer = array(); |
1775 | 1775 | } |
1776 | - } |
|
1776 | + } |
|
1777 | 1777 | } |
1778 | 1778 | // Sleep for xxx microseconds |
1779 | 1779 | if (isset($globalSBSSleep)) usleep($globalSBSSleep); |
1780 | - } else { |
|
1780 | + } else { |
|
1781 | 1781 | if ($format == 'flightgearmp') { |
1782 | - if ($globalDebug) echo "Reconnect FlightGear MP..."; |
|
1782 | + if ($globalDebug) echo "Reconnect FlightGear MP..."; |
|
1783 | 1783 | //@socket_close($r); |
1784 | 1784 | sleep($globalMinFetch); |
1785 | 1785 | $sourcefg[$nb] = $globalSources[$nb]; |
@@ -1788,9 +1788,9 @@ discard block |
||
1788 | 1788 | break; |
1789 | 1789 | |
1790 | 1790 | } elseif ($format != 'acars' && $format != 'flightgearsp') { |
1791 | - if (isset($tt[$format])) $tt[$format]++; |
|
1792 | - else $tt[$format] = 0; |
|
1793 | - if ($tt[$format] > 30 || $buffer === FALSE) { |
|
1791 | + if (isset($tt[$format])) $tt[$format]++; |
|
1792 | + else $tt[$format] = 0; |
|
1793 | + if ($tt[$format] > 30 || $buffer === FALSE) { |
|
1794 | 1794 | if ($globalDebug) echo "ERROR : Reconnect ".$format."..."; |
1795 | 1795 | //@socket_close($r); |
1796 | 1796 | sleep(2); |
@@ -1801,24 +1801,24 @@ discard block |
||
1801 | 1801 | //connect_all($globalSources); |
1802 | 1802 | $tt[$format]=0; |
1803 | 1803 | break; |
1804 | - } |
|
1805 | - //else if ($globalDebug) echo "Trying again (".$tt[$format]."x) ".$format."..."; |
|
1804 | + } |
|
1805 | + //else if ($globalDebug) echo "Trying again (".$tt[$format]."x) ".$format."..."; |
|
1806 | + } |
|
1806 | 1807 | } |
1807 | - } |
|
1808 | 1808 | } |
1809 | - } else { |
|
1809 | + } else { |
|
1810 | 1810 | $error = socket_strerror(socket_last_error()); |
1811 | 1811 | if (($error != SOCKET_EINPROGRESS && $error != SOCKET_EALREADY && $error != 'Success') || (time() - $time >= $timeout && $error != 'Success')) { |
1812 | 1812 | if ($globalDebug) echo "ERROR : socket_select give this error ".$error . "\n"; |
1813 | 1813 | if (isset($globalDebug)) echo "Restarting...\n"; |
1814 | 1814 | // Restart the script if possible |
1815 | 1815 | if (is_array($sockets)) { |
1816 | - if ($globalDebug) echo "Shutdown all sockets..."; |
|
1816 | + if ($globalDebug) echo "Shutdown all sockets..."; |
|
1817 | 1817 | |
1818 | - foreach ($sockets as $sock) { |
|
1818 | + foreach ($sockets as $sock) { |
|
1819 | 1819 | @socket_shutdown($sock,2); |
1820 | 1820 | @socket_close($sock); |
1821 | - } |
|
1821 | + } |
|
1822 | 1822 | |
1823 | 1823 | } |
1824 | 1824 | if ($globalDebug) echo "Waiting..."; |
@@ -1833,15 +1833,15 @@ discard block |
||
1833 | 1833 | if ($globalDebug) echo "Restart all connections..."; |
1834 | 1834 | connect_all($globalSources); |
1835 | 1835 | } |
1836 | - } |
|
1836 | + } |
|
1837 | 1837 | } |
1838 | 1838 | if ($globalDaemon === false) { |
1839 | - if ($globalDebug) echo 'Check all...'."\n"; |
|
1840 | - if (isset($SI)) $SI->checkAll(); |
|
1841 | - if (isset($TI)) $TI->checkAll(); |
|
1842 | - if (isset($MI)) $MI->checkAll(); |
|
1839 | + if ($globalDebug) echo 'Check all...'."\n"; |
|
1840 | + if (isset($SI)) $SI->checkAll(); |
|
1841 | + if (isset($TI)) $TI->checkAll(); |
|
1842 | + if (isset($MI)) $MI->checkAll(); |
|
1843 | + } |
|
1843 | 1844 | } |
1844 | - } |
|
1845 | 1845 | } |
1846 | 1846 | |
1847 | 1847 | ?> |
@@ -50,20 +50,20 @@ discard block |
||
50 | 50 | die; |
51 | 51 | } |
52 | 52 | //$hosts = array($globalSBS1Host.':'.$globalSBS1Port); |
53 | - $globalSources[] = array('host' => $globalSBS1Host,'port' => $globalSBS1Port); |
|
53 | + $globalSources[] = array('host' => $globalSBS1Host, 'port' => $globalSBS1Port); |
|
54 | 54 | } |
55 | 55 | } |
56 | 56 | |
57 | -$options = getopt('s::',array('source::','server','nodaemon','idsource::','aprsserverssid::','aprsserverpass::','aprsserverhost::','aprsserverport::','format::','noaprsserver','enable-aircraft','disable-aircraft','enable-tracker','disable-tracker','enable-marine','disable-marine')); |
|
57 | +$options = getopt('s::', array('source::', 'server', 'nodaemon', 'idsource::', 'aprsserverssid::', 'aprsserverpass::', 'aprsserverhost::', 'aprsserverport::', 'format::', 'noaprsserver', 'enable-aircraft', 'disable-aircraft', 'enable-tracker', 'disable-tracker', 'enable-marine', 'disable-marine')); |
|
58 | 58 | //if (isset($options['s'])) $hosts = array($options['s']); |
59 | 59 | //elseif (isset($options['source'])) $hosts = array($options['source']); |
60 | 60 | if (isset($options['s'])) { |
61 | 61 | $globalSources = array(); |
62 | - if (isset($options['format'])) $globalSources[] = array('host' => $options['s'],'format' => $options['format']); |
|
62 | + if (isset($options['format'])) $globalSources[] = array('host' => $options['s'], 'format' => $options['format']); |
|
63 | 63 | else $globalSources[] = array('host' => $options['s']); |
64 | 64 | } elseif (isset($options['source'])) { |
65 | 65 | $globalSources = array(); |
66 | - if (isset($options['format'])) $globalSources[] = array('host' => $options['source'],'format' => $options['format']); |
|
66 | + if (isset($options['format'])) $globalSources[] = array('host' => $options['source'], 'format' => $options['format']); |
|
67 | 67 | else $globalSources[] = array('host' => $options['source']); |
68 | 68 | } |
69 | 69 | if (isset($options['aprsserverhost'])) { |
@@ -104,13 +104,13 @@ discard block |
||
104 | 104 | else $id_source = 1; |
105 | 105 | if (isset($globalServer) && $globalServer) { |
106 | 106 | if ($globalDebug) echo "Using Server Mode\n"; |
107 | - $SI=new SpotterServer(); |
|
107 | + $SI = new SpotterServer(); |
|
108 | 108 | /* |
109 | 109 | require_once(dirname(__FILE__).'/../require/class.APRS.php'); |
110 | 110 | $SI = new adsb2aprs(); |
111 | 111 | $SI->connect(); |
112 | 112 | */ |
113 | -} else $SI=new SpotterImport($Connection->db); |
|
113 | +} else $SI = new SpotterImport($Connection->db); |
|
114 | 114 | |
115 | 115 | if (isset($globalTracker) && $globalTracker) require_once(dirname(__FILE__).'/../require/class.TrackerImport.php'); |
116 | 116 | if (isset($globalMarine) && $globalMarine) { |
@@ -124,17 +124,17 @@ discard block |
||
124 | 124 | $MI = new MarineImport($Connection->db); |
125 | 125 | } |
126 | 126 | //$APRS=new APRS($Connection->db); |
127 | -$SBS=new SBS(); |
|
127 | +$SBS = new SBS(); |
|
128 | 128 | if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
129 | - $ACARS=new ACARS($Connection->db,true); |
|
130 | - $Source=new Source($Connection->db); |
|
129 | + $ACARS = new ACARS($Connection->db, true); |
|
130 | + $Source = new Source($Connection->db); |
|
131 | 131 | } |
132 | -$Common=new Common(); |
|
132 | +$Common = new Common(); |
|
133 | 133 | date_default_timezone_set('UTC'); |
134 | 134 | //$servertz = system('date +%Z'); |
135 | 135 | // signal handler - playing nice with sockets and dump1090 |
136 | 136 | if (function_exists('pcntl_fork')) { |
137 | - pcntl_signal(SIGINT, function() { |
|
137 | + pcntl_signal(SIGINT, function() { |
|
138 | 138 | global $sockets; |
139 | 139 | echo "\n\nctrl-c or kill signal received. Tidying up ... "; |
140 | 140 | die("Bye!\n"); |
@@ -150,30 +150,30 @@ discard block |
||
150 | 150 | |
151 | 151 | function connect_all($hosts) { |
152 | 152 | //global $sockets, $formats, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs; |
153 | - global $sockets,$httpfeeds, $globalSources, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs, $reset,$context; |
|
153 | + global $sockets, $httpfeeds, $globalSources, $globalDebug, $aprs_connect, $last_exec, $globalSourcesRights, $use_aprs, $reset, $context; |
|
154 | 154 | $reset++; |
155 | 155 | if ($globalDebug) echo 'Connect to all...'."\n"; |
156 | 156 | foreach ($hosts as $id => $value) { |
157 | 157 | $host = $value['host']; |
158 | 158 | $globalSources[$id]['last_exec'] = 0; |
159 | 159 | // Here we check type of source(s) |
160 | - if (filter_var($host,FILTER_VALIDATE_URL) && (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto')) { |
|
161 | - if (preg_match('/deltadb.txt$/i',$host)) { |
|
160 | + if (filter_var($host, FILTER_VALIDATE_URL) && (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto')) { |
|
161 | + if (preg_match('/deltadb.txt$/i', $host)) { |
|
162 | 162 | //$formats[$id] = 'deltadbtxt'; |
163 | 163 | $globalSources[$id]['format'] = 'deltadbtxt'; |
164 | 164 | //$last_exec['deltadbtxt'] = 0; |
165 | 165 | if ($globalDebug) echo "Connect to deltadb source (".$host.")...\n"; |
166 | - } else if (preg_match('/vatsim-data.txt$/i',$host)) { |
|
166 | + } else if (preg_match('/vatsim-data.txt$/i', $host)) { |
|
167 | 167 | //$formats[$id] = 'vatsimtxt'; |
168 | 168 | $globalSources[$id]['format'] = 'vatsimtxt'; |
169 | 169 | //$last_exec['vatsimtxt'] = 0; |
170 | 170 | if ($globalDebug) echo "Connect to vatsim source (".$host.")...\n"; |
171 | - } else if (preg_match('/aircraftlist.json$/i',$host)) { |
|
171 | + } else if (preg_match('/aircraftlist.json$/i', $host)) { |
|
172 | 172 | //$formats[$id] = 'aircraftlistjson'; |
173 | 173 | $globalSources[$id]['format'] = 'aircraftlistjson'; |
174 | 174 | //$last_exec['aircraftlistjson'] = 0; |
175 | 175 | if ($globalDebug) echo "Connect to aircraftlist.json source (".$host.")...\n"; |
176 | - } else if (preg_match('/opensky/i',$host)) { |
|
176 | + } else if (preg_match('/opensky/i', $host)) { |
|
177 | 177 | //$formats[$id] = 'aircraftlistjson'; |
178 | 178 | $globalSources[$id]['format'] = 'opensky'; |
179 | 179 | //$last_exec['aircraftlistjson'] = 0; |
@@ -190,7 +190,7 @@ discard block |
||
190 | 190 | exit(0); |
191 | 191 | } |
192 | 192 | */ |
193 | - } else if (preg_match('/planeUpdateFAA.php$/i',$host)) { |
|
193 | + } else if (preg_match('/planeUpdateFAA.php$/i', $host)) { |
|
194 | 194 | //$formats[$id] = 'planeupdatefaa'; |
195 | 195 | $globalSources[$id]['format'] = 'planeupdatefaa'; |
196 | 196 | //$last_exec['planeupdatefaa'] = 0; |
@@ -199,37 +199,37 @@ discard block |
||
199 | 199 | echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n"; |
200 | 200 | exit(0); |
201 | 201 | } |
202 | - } else if (preg_match('/\/action.php\/acars\/data$/i',$host)) { |
|
202 | + } else if (preg_match('/\/action.php\/acars\/data$/i', $host)) { |
|
203 | 203 | //$formats[$id] = 'phpvmacars'; |
204 | 204 | $globalSources[$id]['format'] = 'phpvmacars'; |
205 | 205 | //$last_exec['phpvmacars'] = 0; |
206 | 206 | if ($globalDebug) echo "Connect to phpvmacars source (".$host.")...\n"; |
207 | - } else if (preg_match('/\/api\/v1\/acars\/data$/i',$host)) { |
|
207 | + } else if (preg_match('/\/api\/v1\/acars\/data$/i', $host)) { |
|
208 | 208 | //$formats[$id] = 'phpvmacars'; |
209 | 209 | $globalSources[$id]['format'] = 'vaos'; |
210 | 210 | //$last_exec['phpvmacars'] = 0; |
211 | 211 | if ($globalDebug) echo "Connect to vaos source (".$host.")...\n"; |
212 | - } else if (preg_match('/VAM-json.php$/i',$host)) { |
|
212 | + } else if (preg_match('/VAM-json.php$/i', $host)) { |
|
213 | 213 | //$formats[$id] = 'phpvmacars'; |
214 | 214 | $globalSources[$id]['format'] = 'vam'; |
215 | 215 | if ($globalDebug) echo "Connect to Vam source (".$host.")...\n"; |
216 | - } else if (preg_match('/whazzup/i',$host)) { |
|
216 | + } else if (preg_match('/whazzup/i', $host)) { |
|
217 | 217 | //$formats[$id] = 'whazzup'; |
218 | 218 | $globalSources[$id]['format'] = 'whazzup'; |
219 | 219 | //$last_exec['whazzup'] = 0; |
220 | 220 | if ($globalDebug) echo "Connect to whazzup source (".$host.")...\n"; |
221 | - } else if (preg_match('/blitzortung/i',$host)) { |
|
221 | + } else if (preg_match('/blitzortung/i', $host)) { |
|
222 | 222 | $globalSources[$id]['format'] = 'blitzortung'; |
223 | 223 | if ($globalDebug) echo "Connect to blitzortung source (".$host.")...\n"; |
224 | - } else if (preg_match('/airwhere/i',$host)) { |
|
224 | + } else if (preg_match('/airwhere/i', $host)) { |
|
225 | 225 | $globalSources[$id]['format'] = 'airwhere'; |
226 | 226 | if ($globalDebug) echo "Connect to airwhere source (".$host.")...\n"; |
227 | - } else if (preg_match('/recentpireps/i',$host)) { |
|
227 | + } else if (preg_match('/recentpireps/i', $host)) { |
|
228 | 228 | //$formats[$id] = 'pirepsjson'; |
229 | 229 | $globalSources[$id]['format'] = 'pirepsjson'; |
230 | 230 | //$last_exec['pirepsjson'] = 0; |
231 | 231 | if ($globalDebug) echo "Connect to pirepsjson source (".$host.")...\n"; |
232 | - } else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i',$host)) { |
|
232 | + } else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i', $host)) { |
|
233 | 233 | //$formats[$id] = 'fr24json'; |
234 | 234 | $globalSources[$id]['format'] = 'fr24json'; |
235 | 235 | //$last_exec['fr24json'] = 0; |
@@ -238,7 +238,7 @@ discard block |
||
238 | 238 | echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n"; |
239 | 239 | exit(0); |
240 | 240 | } |
241 | - } else if (preg_match(':myshiptracking.com/:i',$host)) { |
|
241 | + } else if (preg_match(':myshiptracking.com/:i', $host)) { |
|
242 | 242 | //$formats[$id] = 'fr24json'; |
243 | 243 | $globalSources[$id]['format'] = 'myshiptracking'; |
244 | 244 | //$last_exec['fr24json'] = 0; |
@@ -248,21 +248,21 @@ discard block |
||
248 | 248 | exit(0); |
249 | 249 | } |
250 | 250 | //} else if (preg_match('/10001/',$host)) { |
251 | - } else if (preg_match('/10001/',$host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) { |
|
251 | + } else if (preg_match('/10001/', $host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) { |
|
252 | 252 | //$formats[$id] = 'tsv'; |
253 | 253 | $globalSources[$id]['format'] = 'tsv'; |
254 | 254 | if ($globalDebug) echo "Connect to tsv source (".$host.")...\n"; |
255 | 255 | } |
256 | - } elseif (filter_var($host,FILTER_VALIDATE_URL)) { |
|
256 | + } elseif (filter_var($host, FILTER_VALIDATE_URL)) { |
|
257 | 257 | if ($globalSources[$id]['format'] == 'aisnmeahttp') { |
258 | - $idf = fopen($globalSources[$id]['host'],'r',false,$context); |
|
258 | + $idf = fopen($globalSources[$id]['host'], 'r', false, $context); |
|
259 | 259 | if ($idf !== false) { |
260 | 260 | $httpfeeds[$id] = $idf; |
261 | 261 | if ($globalDebug) echo "Connected to ".$globalSources[$id]['format']." source (".$host.")...\n"; |
262 | 262 | } elseif ($globalDebug) echo "Can't connect to ".$globalSources[$id]['host']."\n"; |
263 | 263 | } elseif ($globalDebug) echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n"; |
264 | - } elseif (!filter_var($host,FILTER_VALIDATE_URL)) { |
|
265 | - $hostport = explode(':',$host); |
|
264 | + } elseif (!filter_var($host, FILTER_VALIDATE_URL)) { |
|
265 | + $hostport = explode(':', $host); |
|
266 | 266 | if (isset($hostport[1])) { |
267 | 267 | $port = $hostport[1]; |
268 | 268 | $hostn = $hostport[0]; |
@@ -272,19 +272,19 @@ discard block |
||
272 | 272 | } |
273 | 273 | $Common = new Common(); |
274 | 274 | if (!isset($globalSources[$id]['format']) || ($globalSources[$id]['format'] != 'acars' && $globalSources[$id]['format'] != 'flightgearsp')) { |
275 | - $s = $Common->create_socket($hostn,$port, $errno, $errstr); |
|
275 | + $s = $Common->create_socket($hostn, $port, $errno, $errstr); |
|
276 | 276 | } else { |
277 | - $s = $Common->create_socket_udp($hostn,$port, $errno, $errstr); |
|
277 | + $s = $Common->create_socket_udp($hostn, $port, $errno, $errstr); |
|
278 | 278 | } |
279 | 279 | if ($s) { |
280 | 280 | $sockets[$id] = $s; |
281 | 281 | if (!isset($globalSources[$id]['format']) || strtolower($globalSources[$id]['format']) == 'auto') { |
282 | - if (preg_match('/aprs/',$hostn) || $port == '10152' || $port == '14580') { |
|
282 | + if (preg_match('/aprs/', $hostn) || $port == '10152' || $port == '14580') { |
|
283 | 283 | //$formats[$id] = 'aprs'; |
284 | 284 | $globalSources[$id]['format'] = 'aprs'; |
285 | 285 | //$aprs_connect = 0; |
286 | 286 | //$use_aprs = true; |
287 | - } elseif (preg_match('/pub-vrs/',$hostn) || $port == '32001' || $port == '32005' || $port == '32010' || $port == '32015' || $port == '32030') { |
|
287 | + } elseif (preg_match('/pub-vrs/', $hostn) || $port == '32001' || $port == '32005' || $port == '32010' || $port == '32015' || $port == '32030') { |
|
288 | 288 | $globalSources[$id]['format'] = 'vrstcp'; |
289 | 289 | } elseif ($port == '10001') { |
290 | 290 | //$formats[$id] = 'tsv'; |
@@ -323,7 +323,7 @@ discard block |
||
323 | 323 | else if (isset($globalSBS1TimeOut)) $timeout = $globalSBS1TimeOut; |
324 | 324 | else $timeout = 20; |
325 | 325 | $errno = ''; |
326 | -$errstr=''; |
|
326 | +$errstr = ''; |
|
327 | 327 | |
328 | 328 | if (!isset($globalDaemon)) $globalDaemon = TRUE; |
329 | 329 | /* Initiate connections to all the hosts simultaneously */ |
@@ -331,7 +331,7 @@ discard block |
||
331 | 331 | //connect_all($globalSources); |
332 | 332 | |
333 | 333 | if (isset($globalProxy) && $globalProxy) { |
334 | - $context = stream_context_create(array('http' => array('timeout' => $timeout,'proxy' => $globalProxy,'request_fulluri' => true))); |
|
334 | + $context = stream_context_create(array('http' => array('timeout' => $timeout, 'proxy' => $globalProxy, 'request_fulluri' => true))); |
|
335 | 335 | } else { |
336 | 336 | $context = stream_context_create(array('http' => array('timeout' => $timeout))); |
337 | 337 | } |
@@ -361,16 +361,16 @@ discard block |
||
361 | 361 | |
362 | 362 | if ($use_aprs) { |
363 | 363 | require_once(dirname(__FILE__).'/../require/class.APRS.php'); |
364 | - $APRS=new APRS(); |
|
364 | + $APRS = new APRS(); |
|
365 | 365 | $aprs_connect = 0; |
366 | 366 | $aprs_keep = 120; |
367 | 367 | $aprs_last_tx = time(); |
368 | 368 | if (isset($globalAPRSversion)) $aprs_version = $globalAPRSversion; |
369 | - else $aprs_version = 'FlightAirMap '.str_replace(' ','_',$globalName); |
|
369 | + else $aprs_version = 'FlightAirMap '.str_replace(' ', '_', $globalName); |
|
370 | 370 | if (isset($globalAPRSssid)) $aprs_ssid = $globalAPRSssid; |
371 | - else $aprs_ssid = substr('FAM'.strtoupper(str_replace(' ','_',$globalName)),0,8); |
|
371 | + else $aprs_ssid = substr('FAM'.strtoupper(str_replace(' ', '_', $globalName)), 0, 8); |
|
372 | 372 | if (isset($globalAPRSfilter)) $aprs_filter = $globalAPRSfilter; |
373 | - else $aprs_filter = 'r/'.$globalCenterLatitude.'/'.$globalCenterLongitude.'/250.0'; |
|
373 | + else $aprs_filter = 'r/'.$globalCenterLatitude.'/'.$globalCenterLongitude.'/250.0'; |
|
374 | 374 | if ($aprs_full) $aprs_filter = ''; |
375 | 375 | if (isset($globalAPRSpass)) $aprs_pass = $globalAPRSpass; |
376 | 376 | else $aprs_pass = '-1'; |
@@ -384,12 +384,12 @@ discard block |
||
384 | 384 | sleep(1); |
385 | 385 | if ($globalDebug) echo "SCAN MODE \n\n"; |
386 | 386 | if (!isset($globalCronEnd)) $globalCronEnd = 60; |
387 | -$endtime = time()+$globalCronEnd; |
|
387 | +$endtime = time() + $globalCronEnd; |
|
388 | 388 | $i = 1; |
389 | 389 | $tt = array(); |
390 | 390 | // Delete all ATC |
391 | 391 | if ((isset($globalVA) && $globalVA) || (isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM)) { |
392 | - $ATC=new ATC($Connection->db); |
|
392 | + $ATC = new ATC($Connection->db); |
|
393 | 393 | } |
394 | 394 | if (!$globalDaemon && ((isset($globalVA) && $globalVA) || (isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) { |
395 | 395 | $ATC->deleteAll(); |
@@ -397,7 +397,7 @@ discard block |
||
397 | 397 | |
398 | 398 | // Infinite loop if daemon, else work for time defined in $globalCronEnd or only one time. |
399 | 399 | while ($i > 0) { |
400 | - if (!$globalDaemon) $i = $endtime-time(); |
|
400 | + if (!$globalDaemon) $i = $endtime - time(); |
|
401 | 401 | // Delete old ATC |
402 | 402 | if ($globalDaemon && ((isset($globalVA) && $globalVA) || (isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) { |
403 | 403 | if ($globalDebug) echo 'Delete old ATC...'."\n"; |
@@ -411,7 +411,7 @@ discard block |
||
411 | 411 | } |
412 | 412 | if ($max != $globalMinFetch) { |
413 | 413 | if ($globalDebug) echo 'Sleeping...'."\n"; |
414 | - sleep($globalMinFetch-$max+2); |
|
414 | + sleep($globalMinFetch - $max + 2); |
|
415 | 415 | } |
416 | 416 | } |
417 | 417 | |
@@ -430,8 +430,8 @@ discard block |
||
430 | 430 | //$buffer = $Common->getData($hosts[$id]); |
431 | 431 | $buffer = $Common->getData($value['host']); |
432 | 432 | if ($buffer != '') $reset = 0; |
433 | - $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer)); |
|
434 | - $buffer = explode('\n',$buffer); |
|
433 | + $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer)); |
|
434 | + $buffer = explode('\n', $buffer); |
|
435 | 435 | foreach ($buffer as $line) { |
436 | 436 | if ($line != '' && count($line) > 7) { |
437 | 437 | $line = explode(',', $line); |
@@ -464,11 +464,11 @@ discard block |
||
464 | 464 | ) |
465 | 465 | ) { |
466 | 466 | date_default_timezone_set('CET'); |
467 | - $buffer = $Common->getData(str_replace('{date}',date('Ymd'),$value['host'])); |
|
467 | + $buffer = $Common->getData(str_replace('{date}', date('Ymd'), $value['host'])); |
|
468 | 468 | date_default_timezone_set('UTC'); |
469 | 469 | if ($buffer != '') $reset = 0; |
470 | - $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer)); |
|
471 | - $buffer = explode('\n',$buffer); |
|
470 | + $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer)); |
|
471 | + $buffer = explode('\n', $buffer); |
|
472 | 472 | foreach ($buffer as $line) { |
473 | 473 | if ($line != '') { |
474 | 474 | //echo "'".$line."'\n"; |
@@ -476,7 +476,7 @@ discard block |
||
476 | 476 | $ais_data = $AIS->parse_line(trim($line)); |
477 | 477 | $data = array(); |
478 | 478 | if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident']; |
479 | - if (isset($ais_data['mmsi'])) $data['mmsi'] = substr($ais_data['mmsi'],-9); |
|
479 | + if (isset($ais_data['mmsi'])) $data['mmsi'] = substr($ais_data['mmsi'], -9); |
|
480 | 480 | if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed']; |
481 | 481 | if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading']; |
482 | 482 | if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude']; |
@@ -488,7 +488,7 @@ discard block |
||
488 | 488 | if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo']; |
489 | 489 | if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign']; |
490 | 490 | if (isset($ais_data['timestamp'])) { |
491 | - $data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']); |
|
491 | + $data['datetime'] = date('Y-m-d H:i:s', $ais_data['timestamp']); |
|
492 | 492 | if (!isset($last_exec[$id]['timestamp']) || $ais_data['timestamp'] >= $last_exec[$id]['timestamp']) { |
493 | 493 | $last_exec[$id]['timestamp'] = $ais_data['timestamp']; |
494 | 494 | $add = true; |
@@ -511,21 +511,21 @@ discard block |
||
511 | 511 | $w = $e = null; |
512 | 512 | |
513 | 513 | if (isset($arr[$id])) { |
514 | - $nn = stream_select($arr,$w,$e,$timeout); |
|
514 | + $nn = stream_select($arr, $w, $e, $timeout); |
|
515 | 515 | if ($nn > 0) { |
516 | 516 | foreach ($httpfeeds as $feed) { |
517 | - $buffer = stream_get_line($feed,2000,"\n"); |
|
517 | + $buffer = stream_get_line($feed, 2000, "\n"); |
|
518 | 518 | if ($buffer === FALSE) { |
519 | 519 | connect_all($globalSources); |
520 | 520 | } |
521 | - $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer)); |
|
522 | - $buffer = explode('\n',$buffer); |
|
521 | + $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer)); |
|
522 | + $buffer = explode('\n', $buffer); |
|
523 | 523 | foreach ($buffer as $line) { |
524 | 524 | if ($line != '') { |
525 | 525 | $ais_data = $AIS->parse_line(trim($line)); |
526 | 526 | $data = array(); |
527 | 527 | if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident']; |
528 | - if (isset($ais_data['mmsi'])) $data['mmsi'] = substr($ais_data['mmsi'],-9); |
|
528 | + if (isset($ais_data['mmsi'])) $data['mmsi'] = substr($ais_data['mmsi'], -9); |
|
529 | 529 | if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed']; |
530 | 530 | if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading']; |
531 | 531 | if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude']; |
@@ -537,9 +537,9 @@ discard block |
||
537 | 537 | if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo']; |
538 | 538 | if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign']; |
539 | 539 | if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination']; |
540 | - if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']); |
|
540 | + if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s', $ais_data['eta_ts']); |
|
541 | 541 | if (isset($ais_data['timestamp'])) { |
542 | - $data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']); |
|
542 | + $data['datetime'] = date('Y-m-d H:i:s', $ais_data['timestamp']); |
|
543 | 543 | } else { |
544 | 544 | $data['datetime'] = date('Y-m-d H:i:s'); |
545 | 545 | } |
@@ -571,10 +571,10 @@ discard block |
||
571 | 571 | (!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch*3)) |
572 | 572 | ) |
573 | 573 | ) { |
574 | - $buffer = $Common->getData($value['host'],'get','','','','','20'); |
|
574 | + $buffer = $Common->getData($value['host'], 'get', '', '', '', '', '20'); |
|
575 | 575 | if ($buffer != '') { |
576 | 576 | //echo $buffer; |
577 | - $all_data = json_decode($buffer,true); |
|
577 | + $all_data = json_decode($buffer, true); |
|
578 | 578 | //print_r($all_data); |
579 | 579 | if (isset($all_data[0]['DATA'])) { |
580 | 580 | foreach ($all_data[0]['DATA'] as $line) { |
@@ -583,7 +583,7 @@ discard block |
||
583 | 583 | $data['ident'] = $line['NAME']; |
584 | 584 | $data['mmsi'] = $line['MMSI']; |
585 | 585 | if (strlen($data['mmsi']) > 9) { |
586 | - $data['mmsi'] = substr($data['mmsi'],-9); |
|
586 | + $data['mmsi'] = substr($data['mmsi'], -9); |
|
587 | 587 | } |
588 | 588 | $data['speed'] = $line['SOG']; |
589 | 589 | $data['heading'] = $line['COG']; |
@@ -593,8 +593,8 @@ discard block |
||
593 | 593 | //$data['type_id'] = $line['TYPE']; |
594 | 594 | $data['imo'] = $line['IMO']; |
595 | 595 | if ($line['DEST'] != '') $data['arrival_code'] = $line['DEST']; |
596 | - if ($line['ARV'] != '') $data['arrival_time'] = date('Y-m-d H:i:s',strtotime($line['ARV'])); |
|
597 | - $data['datetime'] = date('Y-m-d H:i:s',$line['T']); |
|
596 | + if ($line['ARV'] != '') $data['arrival_time'] = date('Y-m-d H:i:s', strtotime($line['ARV'])); |
|
597 | + $data['datetime'] = date('Y-m-d H:i:s', $line['T']); |
|
598 | 598 | $data['format_source'] = 'myshiptracking'; |
599 | 599 | $data['id_source'] = $id_source; |
600 | 600 | if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true; |
@@ -611,16 +611,16 @@ discard block |
||
611 | 611 | (!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch*3)) |
612 | 612 | ) |
613 | 613 | ) { |
614 | - $buffer = $Common->getData(str_replace('{timestamp}',time(),$value['host'])); |
|
614 | + $buffer = $Common->getData(str_replace('{timestamp}', time(), $value['host'])); |
|
615 | 615 | if ($buffer != '') { |
616 | - $all_data = json_decode($buffer,true); |
|
616 | + $all_data = json_decode($buffer, true); |
|
617 | 617 | if (isset($all_data[0]['mmsi'])) { |
618 | 618 | foreach ($all_data as $line) { |
619 | 619 | if ($line != '') { |
620 | 620 | $data = array(); |
621 | 621 | $data['ident'] = $line['shipname']; |
622 | 622 | $data['callsign'] = $line['callsign']; |
623 | - $data['mmsi'] = substr($line['mmsi'],-9); |
|
623 | + $data['mmsi'] = substr($line['mmsi'], -9); |
|
624 | 624 | $data['speed'] = $line['sog']; |
625 | 625 | if ($line['heading'] != '511') $data['heading'] = $line['heading']; |
626 | 626 | $data['latitude'] = $line['latitude']; |
@@ -647,14 +647,14 @@ discard block |
||
647 | 647 | ) { |
648 | 648 | $buffer = $Common->getData($value['host']); |
649 | 649 | if ($buffer != '') { |
650 | - $all_data = json_decode($buffer,true); |
|
650 | + $all_data = json_decode($buffer, true); |
|
651 | 651 | if (isset($all_data['features'][0]['id'])) { |
652 | 652 | foreach ($all_data['features'] as $line) { |
653 | 653 | print_r($line); |
654 | 654 | $data = array(); |
655 | 655 | if (isset($line['properties']['name'])) $data['ident'] = $line['properties']['name']; |
656 | 656 | if (isset($line['properties']['callsign'])) $data['callsign'] = $line['properties']['callsign']; |
657 | - if (isset($line['properties']['mmsi'])) $data['mmsi'] = substr($line['properties']['mmsi'],-9); |
|
657 | + if (isset($line['properties']['mmsi'])) $data['mmsi'] = substr($line['properties']['mmsi'], -9); |
|
658 | 658 | if (isset($line['properties']['imo'])) $data['imo'] = $line['properties']['imo']; |
659 | 659 | if (isset($line['properties']['speed'])) $data['speed'] = $line['properties']['speed']; |
660 | 660 | if (isset($line['properties']['heading']) && $line['properties']['heading'] != 0) $data['heading'] = $line['properties']['heading']; |
@@ -681,31 +681,31 @@ discard block |
||
681 | 681 | ) |
682 | 682 | ) { |
683 | 683 | echo 'download...'; |
684 | - $buffer = $Common->getData($value['host'],'post',$value['post'],'','','','','ShipPlotter'); |
|
684 | + $buffer = $Common->getData($value['host'], 'post', $value['post'], '', '', '', '', 'ShipPlotter'); |
|
685 | 685 | echo 'done !'."\n"; |
686 | 686 | // FIXME: Need more work |
687 | 687 | if ($buffer != '') $reset = 0; |
688 | - $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer)); |
|
689 | - $buffer = explode('\n',$buffer); |
|
688 | + $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer)); |
|
689 | + $buffer = explode('\n', $buffer); |
|
690 | 690 | foreach ($buffer as $line) { |
691 | 691 | if ($line != '') { |
692 | 692 | $data = array(); |
693 | 693 | echo $line."\n"; |
694 | - $data['mmsi'] = (int)substr($line,0,9); |
|
695 | - $data['datetime'] = date('Y-m-d H:i:s',substr($line,10,10)); |
|
696 | - $data['status_id'] = substr($line,21,2); |
|
697 | - $data['type_id'] = substr($line,24,3); |
|
698 | - $data['latitude'] = substr($line,29,9); |
|
699 | - $data['longitude'] = substr($line,41,9); |
|
700 | - $data['speed'] = round(substr($line,51,5)); |
|
694 | + $data['mmsi'] = (int) substr($line, 0, 9); |
|
695 | + $data['datetime'] = date('Y-m-d H:i:s', substr($line, 10, 10)); |
|
696 | + $data['status_id'] = substr($line, 21, 2); |
|
697 | + $data['type_id'] = substr($line, 24, 3); |
|
698 | + $data['latitude'] = substr($line, 29, 9); |
|
699 | + $data['longitude'] = substr($line, 41, 9); |
|
700 | + $data['speed'] = round(substr($line, 51, 5)); |
|
701 | 701 | //$data['course'] = substr($line,57,5); |
702 | - $data['heading'] = round(substr($line,63,3)); |
|
702 | + $data['heading'] = round(substr($line, 63, 3)); |
|
703 | 703 | //$data['draft'] = substr($line,67,4); |
704 | 704 | //$data['length'] = substr($line,72,3); |
705 | 705 | //$data['beam'] = substr($line,76,2); |
706 | - $data['ident'] = trim(utf8_encode(substr($line,78,20))); |
|
706 | + $data['ident'] = trim(utf8_encode(substr($line, 78, 20))); |
|
707 | 707 | //$data['callsign'] = trim(substr($line,100,7); |
708 | - $data['arrival_code'] = substr($line,108,20); |
|
708 | + $data['arrival_code'] = substr($line, 108, 20); |
|
709 | 709 | //$data['etaDate'] = substr($line,129,5); |
710 | 710 | //$data['etaTime'] = substr($line,135,5); |
711 | 711 | $data['format_source'] = 'shipplotter'; |
@@ -736,8 +736,8 @@ discard block |
||
736 | 736 | ) { |
737 | 737 | //$buffer = $Common->getData($hosts[$id]); |
738 | 738 | $buffer = $Common->getData($value['host']); |
739 | - $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer)); |
|
740 | - $buffer = explode('\n',$buffer); |
|
739 | + $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer)); |
|
740 | + $buffer = explode('\n', $buffer); |
|
741 | 741 | $reset = 0; |
742 | 742 | foreach ($buffer as $line) { |
743 | 743 | if ($line != '') { |
@@ -748,7 +748,7 @@ discard block |
||
748 | 748 | else $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0]; |
749 | 749 | $data['pilot_id'] = $line[1]; |
750 | 750 | $data['pilot_name'] = $line[2]; |
751 | - $data['hex'] = str_pad(dechex($Common->str2int($line[1])),6,'000000',STR_PAD_LEFT); |
|
751 | + $data['hex'] = str_pad(dechex($Common->str2int($line[1])), 6, '000000', STR_PAD_LEFT); |
|
752 | 752 | $data['ident'] = $line[0]; // ident |
753 | 753 | if ($line[7] != '' && $line[7] != 0) $data['altitude'] = $line[7]; // altitude |
754 | 754 | $data['speed'] = $line[8]; // speed |
@@ -764,7 +764,7 @@ discard block |
||
764 | 764 | //$data['datetime'] = date('Y-m-d H:i:s',strtotime($line[37])); |
765 | 765 | //if (isset($line[37])) $data['last_update'] = $line[37]; |
766 | 766 | $data['departure_airport_icao'] = $line[11]; |
767 | - $data['departure_airport_time'] = rtrim(chunk_split($line[22],2,':'),':'); |
|
767 | + $data['departure_airport_time'] = rtrim(chunk_split($line[22], 2, ':'), ':'); |
|
768 | 768 | $data['arrival_airport_icao'] = $line[13]; |
769 | 769 | $data['frequency'] = $line[4]; |
770 | 770 | $data['type'] = $line[18]; |
@@ -773,7 +773,7 @@ discard block |
||
773 | 773 | $data['id_source'] = $id_source; |
774 | 774 | //$data['arrival_airport_time'] = ; |
775 | 775 | if ($line[9] != '') { |
776 | - $aircraft_data = explode('/',$line[9]); |
|
776 | + $aircraft_data = explode('/', $line[9]); |
|
777 | 777 | if (isset($aircraft_data[1])) { |
778 | 778 | $data['aircraft_icao'] = $aircraft_data[1]; |
779 | 779 | } |
@@ -788,9 +788,9 @@ discard block |
||
788 | 788 | if ($line[3] == 'PILOT') $SI->add($data); |
789 | 789 | elseif ($line[3] == 'ATC') { |
790 | 790 | //print_r($data); |
791 | - $data['info'] = str_replace('^§','<br />',$data['info']); |
|
792 | - $data['info'] = str_replace('&sect;','',$data['info']); |
|
793 | - $typec = substr($data['ident'],-3); |
|
791 | + $data['info'] = str_replace('^§', '<br />', $data['info']); |
|
792 | + $data['info'] = str_replace('&sect;', '', $data['info']); |
|
793 | + $typec = substr($data['ident'], -3); |
|
794 | 794 | if ($typec == 'APP') $data['type'] = 'Approach'; |
795 | 795 | elseif ($typec == 'TWR') $data['type'] = 'Tower'; |
796 | 796 | elseif ($typec == 'OBS') $data['type'] = 'Observer'; |
@@ -802,8 +802,8 @@ discard block |
||
802 | 802 | elseif ($data['type'] == '') $data['type'] = 'Observer'; |
803 | 803 | if (!isset($data['source_name'])) $data['source_name'] = ''; |
804 | 804 | if (isset($ATC)) { |
805 | - if (count($ATC->getByIdent($data['ident'],$data['format_source'])) > 0) echo $ATC->update($data['ident'],$data['frequency'],$data['latitude'],$data['longitude'],$data['range'],$data['info'],$data['datetime'],$data['type'],$data['pilot_id'],$data['pilot_name'],$data['format_source'],$data['source_name']); |
|
806 | - else echo $ATC->add($data['ident'],$data['frequency'],$data['latitude'],$data['longitude'],$data['range'],$data['info'],$data['datetime'],$data['type'],$data['pilot_id'],$data['pilot_name'],$data['format_source'],$data['source_name']); |
|
805 | + if (count($ATC->getByIdent($data['ident'], $data['format_source'])) > 0) echo $ATC->update($data['ident'], $data['frequency'], $data['latitude'], $data['longitude'], $data['range'], $data['info'], $data['datetime'], $data['type'], $data['pilot_id'], $data['pilot_name'], $data['format_source'], $data['source_name']); |
|
806 | + else echo $ATC->add($data['ident'], $data['frequency'], $data['latitude'], $data['longitude'], $data['range'], $data['info'], $data['datetime'], $data['type'], $data['pilot_id'], $data['pilot_name'], $data['format_source'], $data['source_name']); |
|
807 | 807 | } |
808 | 808 | } |
809 | 809 | unset($data); |
@@ -819,24 +819,24 @@ discard block |
||
819 | 819 | (!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch)) |
820 | 820 | ) |
821 | 821 | ) { |
822 | - $buffer = $Common->getData('http://www.airwhere.co.uk/pilots.php','get','','','','','20'); |
|
822 | + $buffer = $Common->getData('http://www.airwhere.co.uk/pilots.php', 'get', '', '', '', '', '20'); |
|
823 | 823 | if ($buffer != '') { |
824 | 824 | $all_data = simplexml_load_string($buffer); |
825 | - foreach($all_data->children() as $childdata) { |
|
825 | + foreach ($all_data->children() as $childdata) { |
|
826 | 826 | $data = array(); |
827 | 827 | $line = $childdata; |
828 | 828 | //$data['hex'] = str_pad(dechex((int)$line['pktPilotID']),6,'000000',STR_PAD_LEFT); |
829 | - $data['id'] = date('Ymd').(int)$line['pktPilotID']; |
|
830 | - $data['datetime'] = date('Y-m-d H:i:s',strtotime((string)$line['entryTime'].' BST')); |
|
831 | - $data['latitude'] = (float)$line['pktLatitude']; |
|
832 | - $data['longitude'] = (float)$line['pktLongitude']; |
|
833 | - if ((float)$line['pktTrack'] != 0) $data['heading'] = (float)$line['pktTrack']; |
|
834 | - if ((int)$line['pktSpeed'] != 0) $data['speed'] = (int)$line['pktSpeed']; |
|
835 | - $data['altitude'] = round((int)$line['pktAltitude']*3.28084); |
|
829 | + $data['id'] = date('Ymd').(int) $line['pktPilotID']; |
|
830 | + $data['datetime'] = date('Y-m-d H:i:s', strtotime((string) $line['entryTime'].' BST')); |
|
831 | + $data['latitude'] = (float) $line['pktLatitude']; |
|
832 | + $data['longitude'] = (float) $line['pktLongitude']; |
|
833 | + if ((float) $line['pktTrack'] != 0) $data['heading'] = (float) $line['pktTrack']; |
|
834 | + if ((int) $line['pktSpeed'] != 0) $data['speed'] = (int) $line['pktSpeed']; |
|
835 | + $data['altitude'] = round((int) $line['pktAltitude']*3.28084); |
|
836 | 836 | $data['altitude_relative'] = 'AMSL'; |
837 | - $data['pilot_id'] = (int)$line['pktPilotID']; |
|
837 | + $data['pilot_id'] = (int) $line['pktPilotID']; |
|
838 | 838 | $data['aircraft_icao'] = 'PARAGLIDER'; |
839 | - $pilot_data = explode(',',$Common->getData('http://www.airwhere.co.uk/pilotdetails.php?pilot='.$data['pilot_id'])); |
|
839 | + $pilot_data = explode(',', $Common->getData('http://www.airwhere.co.uk/pilotdetails.php?pilot='.$data['pilot_id'])); |
|
840 | 840 | if (isset($pilot_data[4])) $data['pilot_name'] = $pilot_data[4]; |
841 | 841 | $data['format_source'] = $value['format']; |
842 | 842 | $SI->add($data); |
@@ -844,22 +844,22 @@ discard block |
||
844 | 844 | } |
845 | 845 | } |
846 | 846 | $Source->deleteOldLocationByType('gs'); |
847 | - $buffer = $Common->getData('http://www.airwhere.co.uk/gspositions.php','get','','','','','20'); |
|
847 | + $buffer = $Common->getData('http://www.airwhere.co.uk/gspositions.php', 'get', '', '', '', '', '20'); |
|
848 | 848 | if ($buffer != '') { |
849 | 849 | $all_data = simplexml_load_string($buffer); |
850 | - foreach($all_data->children() as $childdata) { |
|
850 | + foreach ($all_data->children() as $childdata) { |
|
851 | 851 | $data = array(); |
852 | 852 | $line = $childdata; |
853 | - $data['id'] = (int)$line['gsID']; |
|
854 | - $data['latitude'] = (float)$line['gsLatitude']; |
|
855 | - $data['longitude'] = (float)$line['gsLongitude']; |
|
856 | - $data['altitude'] = round((int)$line['gsHeight']*3.28084); |
|
853 | + $data['id'] = (int) $line['gsID']; |
|
854 | + $data['latitude'] = (float) $line['gsLatitude']; |
|
855 | + $data['longitude'] = (float) $line['gsLongitude']; |
|
856 | + $data['altitude'] = round((int) $line['gsHeight']*3.28084); |
|
857 | 857 | $data['altitude_relative'] = 'AMSL'; |
858 | - $data['datetime'] = date('Y-m-d H:i:s',strtotime((string)$line['gsLastUpdate'].' BST')); |
|
858 | + $data['datetime'] = date('Y-m-d H:i:s', strtotime((string) $line['gsLastUpdate'].' BST')); |
|
859 | 859 | if (count($Source->getLocationInfoByLocationID($data['id'])) > 0) { |
860 | - $Source->updateLocationByLocationID('',$data['latitude'],$data['longitude'],$data['altitude'],'','','airwhere','antenna.png','gs',$id,$data['id'],$data['datetime']); |
|
860 | + $Source->updateLocationByLocationID('', $data['latitude'], $data['longitude'], $data['altitude'], '', '', 'airwhere', 'antenna.png', 'gs', $id, $data['id'], $data['datetime']); |
|
861 | 861 | } else { |
862 | - $Source->addLocation('',$data['latitude'],$data['longitude'],$data['altitude'],'','','airwhere','antenna.png','gs',$id,$data['id'],$data['datetime']); |
|
862 | + $Source->addLocation('', $data['latitude'], $data['longitude'], $data['altitude'], '', '', 'airwhere', 'antenna.png', 'gs', $id, $data['id'], $data['datetime']); |
|
863 | 863 | } |
864 | 864 | unset($data); |
865 | 865 | } |
@@ -877,9 +877,9 @@ discard block |
||
877 | 877 | (!isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalMinFetch)) |
878 | 878 | ) |
879 | 879 | ) { |
880 | - $buffer = $Common->getData($value['host'],'get','','','','','20'); |
|
880 | + $buffer = $Common->getData($value['host'], 'get', '', '', '', '', '20'); |
|
881 | 881 | if ($buffer != '') { |
882 | - $all_data = json_decode($buffer,true); |
|
882 | + $all_data = json_decode($buffer, true); |
|
883 | 883 | if (isset($all_data['acList'])) { |
884 | 884 | $reset = 0; |
885 | 885 | foreach ($all_data['acList'] as $line) { |
@@ -895,7 +895,7 @@ discard block |
||
895 | 895 | if (isset($line['Sqk'])) $data['squawk'] = $line['Sqk']; // squawk |
896 | 896 | $data['emergency'] = ''; // emergency |
897 | 897 | if (isset($line['Reg'])) $data['registration'] = $line['Reg']; |
898 | - if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s',round($line['PosTime']/1000)); |
|
898 | + if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s', round($line['PosTime']/1000)); |
|
899 | 899 | else $data['datetime'] = date('Y-m-d H:i:s'); |
900 | 900 | //$data['datetime'] = date('Y-m-d H:i:s'); |
901 | 901 | if (isset($line['Type'])) $data['aircraft_icao'] = $line['Type']; |
@@ -920,7 +920,7 @@ discard block |
||
920 | 920 | $data['verticalrate'] = $line['vrt']; // verticale rate |
921 | 921 | $data['squawk'] = $line['squawk']; // squawk |
922 | 922 | $data['emergency'] = ''; // emergency |
923 | - if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s',round($line['PosTime']/1000)); |
|
923 | + if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s', round($line['PosTime']/1000)); |
|
924 | 924 | else $data['datetime'] = date('Y-m-d H:i:s'); |
925 | 925 | $data['format_source'] = 'aircraftlistjson'; |
926 | 926 | $data['id_source'] = $id_source; |
@@ -941,7 +941,7 @@ discard block |
||
941 | 941 | ) |
942 | 942 | ) { |
943 | 943 | $buffer = $Common->getData($value['host']); |
944 | - $all_data = json_decode($buffer,true); |
|
944 | + $all_data = json_decode($buffer, true); |
|
945 | 945 | if (isset($all_data['planes'])) { |
946 | 946 | $reset = 0; |
947 | 947 | foreach ($all_data['planes'] as $key => $line) { |
@@ -958,12 +958,12 @@ discard block |
||
958 | 958 | $data['emergency'] = ''; // emergency |
959 | 959 | $data['registration'] = $line[2]; |
960 | 960 | $data['aircraft_icao'] = $line[0]; |
961 | - $deparr = explode('-',$line[1]); |
|
961 | + $deparr = explode('-', $line[1]); |
|
962 | 962 | if (count($deparr) == 2) { |
963 | 963 | $data['departure_airport_icao'] = $deparr[0]; |
964 | 964 | $data['arrival_airport_icao'] = $deparr[1]; |
965 | 965 | } |
966 | - $data['datetime'] = date('Y-m-d H:i:s',$line[9]); |
|
966 | + $data['datetime'] = date('Y-m-d H:i:s', $line[9]); |
|
967 | 967 | $data['format_source'] = 'planeupdatefaa'; |
968 | 968 | $data['id_source'] = $id_source; |
969 | 969 | if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true; |
@@ -981,7 +981,7 @@ discard block |
||
981 | 981 | ) |
982 | 982 | ) { |
983 | 983 | $buffer = $Common->getData($value['host']); |
984 | - $all_data = json_decode($buffer,true); |
|
984 | + $all_data = json_decode($buffer, true); |
|
985 | 985 | if (isset($all_data['states'])) { |
986 | 986 | $reset = 0; |
987 | 987 | foreach ($all_data['states'] as $key => $line) { |
@@ -998,7 +998,7 @@ discard block |
||
998 | 998 | //$data['emergency'] = ''; // emergency |
999 | 999 | //$data['registration'] = $line[2]; |
1000 | 1000 | //$data['aircraft_icao'] = $line[0]; |
1001 | - $data['datetime'] = date('Y-m-d H:i:s',$line[3]); |
|
1001 | + $data['datetime'] = date('Y-m-d H:i:s', $line[3]); |
|
1002 | 1002 | $data['format_source'] = 'opensky'; |
1003 | 1003 | $data['id_source'] = $id_source; |
1004 | 1004 | if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true; |
@@ -1017,7 +1017,7 @@ discard block |
||
1017 | 1017 | ) { |
1018 | 1018 | //$buffer = $Common->getData($hosts[$id]); |
1019 | 1019 | $buffer = $Common->getData($value['host']); |
1020 | - $all_data = json_decode($buffer,true); |
|
1020 | + $all_data = json_decode($buffer, true); |
|
1021 | 1021 | if (!empty($all_data)) $reset = 0; |
1022 | 1022 | foreach ($all_data as $key => $line) { |
1023 | 1023 | if ($key != 'full_count' && $key != 'version' && $key != 'stats') { |
@@ -1055,11 +1055,11 @@ discard block |
||
1055 | 1055 | ) |
1056 | 1056 | ) { |
1057 | 1057 | //$buffer = $Common->getData($hosts[$id],'get','','','','','150'); |
1058 | - $buffer = $Common->getData($value['host'],'get','','','','','150'); |
|
1058 | + $buffer = $Common->getData($value['host'], 'get', '', '', '', '', '150'); |
|
1059 | 1059 | //echo $buffer; |
1060 | - $buffer = str_replace(array("\n","\r"),"",$buffer); |
|
1061 | - $buffer = preg_replace('/,"num":(.+)/','}',$buffer); |
|
1062 | - $all_data = json_decode($buffer,true); |
|
1060 | + $buffer = str_replace(array("\n", "\r"), "", $buffer); |
|
1061 | + $buffer = preg_replace('/,"num":(.+)/', '}', $buffer); |
|
1062 | + $all_data = json_decode($buffer, true); |
|
1063 | 1063 | if (json_last_error() != JSON_ERROR_NONE) { |
1064 | 1064 | die(json_last_error_msg()); |
1065 | 1065 | } |
@@ -1082,7 +1082,7 @@ discard block |
||
1082 | 1082 | //$data['departure_airport_iata'] = $line[11]; |
1083 | 1083 | //$data['arrival_airport_iata'] = $line[12]; |
1084 | 1084 | //$data['emergency'] = ''; // emergency |
1085 | - $data['datetime'] = date('Y-m-d H:i:s',$line['inf']['dt']); //$line[10] |
|
1085 | + $data['datetime'] = date('Y-m-d H:i:s', $line['inf']['dt']); //$line[10] |
|
1086 | 1086 | $data['format_source'] = 'radarvirtueljson'; |
1087 | 1087 | $data['id_source'] = $id_source; |
1088 | 1088 | if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true; |
@@ -1103,14 +1103,14 @@ discard block |
||
1103 | 1103 | ) { |
1104 | 1104 | //$buffer = $Common->getData($hosts[$id]); |
1105 | 1105 | $buffer = $Common->getData($value['host'].'?'.time()); |
1106 | - $all_data = json_decode(utf8_encode($buffer),true); |
|
1106 | + $all_data = json_decode(utf8_encode($buffer), true); |
|
1107 | 1107 | |
1108 | 1108 | if (isset($all_data['pireps'])) { |
1109 | 1109 | $reset = 0; |
1110 | 1110 | foreach ($all_data['pireps'] as $line) { |
1111 | 1111 | $data = array(); |
1112 | 1112 | $data['id'] = $line['id']; |
1113 | - $data['hex'] = substr(str_pad(dechex($line['id']),6,'000000',STR_PAD_LEFT),0,6); |
|
1113 | + $data['hex'] = substr(str_pad(dechex($line['id']), 6, '000000', STR_PAD_LEFT), 0, 6); |
|
1114 | 1114 | $data['ident'] = $line['callsign']; // ident |
1115 | 1115 | if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; // pilot id |
1116 | 1116 | if (isset($line['name'])) $data['pilot_name'] = $line['name']; // pilot name |
@@ -1140,9 +1140,9 @@ discard block |
||
1140 | 1140 | $SI->add($data); |
1141 | 1141 | // print_r($data); |
1142 | 1142 | } elseif ($line['icon'] == 'ct') { |
1143 | - $data['info'] = str_replace('^§','<br />',$data['info']); |
|
1144 | - $data['info'] = str_replace('&sect;','',$data['info']); |
|
1145 | - $typec = substr($data['ident'],-3); |
|
1143 | + $data['info'] = str_replace('^§', '<br />', $data['info']); |
|
1144 | + $data['info'] = str_replace('&sect;', '', $data['info']); |
|
1145 | + $typec = substr($data['ident'], -3); |
|
1146 | 1146 | $data['type'] = ''; |
1147 | 1147 | if ($typec == 'APP') $data['type'] = 'Approach'; |
1148 | 1148 | elseif ($typec == 'TWR') $data['type'] = 'Tower'; |
@@ -1153,7 +1153,7 @@ discard block |
||
1153 | 1153 | elseif ($typec == 'FSS') $data['type'] = 'Flight Service Station'; |
1154 | 1154 | elseif ($typec == 'CTR') $data['type'] = 'Control Radar or Centre'; |
1155 | 1155 | else $data['type'] = 'Observer'; |
1156 | - if (isset($ATC)) echo $ATC->add($data['ident'],'',$data['latitude'],$data['longitude'],'0',$data['info'],$data['datetime'],$data['type'],$data['pilot_id'],$data['pilot_name'],$data['format_source']); |
|
1156 | + if (isset($ATC)) echo $ATC->add($data['ident'], '', $data['latitude'], $data['longitude'], '0', $data['info'], $data['datetime'], $data['type'], $data['pilot_id'], $data['pilot_name'], $data['format_source']); |
|
1157 | 1157 | } |
1158 | 1158 | unset($data); |
1159 | 1159 | } |
@@ -1170,14 +1170,14 @@ discard block |
||
1170 | 1170 | //$buffer = $Common->getData($hosts[$id]); |
1171 | 1171 | if ($globalDebug) echo 'Get Data...'."\n"; |
1172 | 1172 | $buffer = $Common->getData($value['host']); |
1173 | - $all_data = json_decode($buffer,true); |
|
1173 | + $all_data = json_decode($buffer, true); |
|
1174 | 1174 | if ($buffer != '' && is_array($all_data)) { |
1175 | 1175 | $reset = 0; |
1176 | 1176 | foreach ($all_data as $line) { |
1177 | 1177 | $data = array(); |
1178 | 1178 | //$data['id'] = $line['id']; // id not usable |
1179 | 1179 | if (isset($line['pilotid'])) $data['id'] = $line['pilotid'].$line['flightnum']; |
1180 | - $data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex |
|
1180 | + $data['hex'] = substr(str_pad(bin2hex($line['flightnum']), 6, '000000', STR_PAD_LEFT), -6); // hex |
|
1181 | 1181 | if (isset($line['pilotname'])) $data['pilot_name'] = $line['pilotname']; |
1182 | 1182 | if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; |
1183 | 1183 | $data['ident'] = $line['flightnum']; // ident |
@@ -1192,7 +1192,7 @@ discard block |
||
1192 | 1192 | //$data['datetime'] = $line['lastupdate']; |
1193 | 1193 | //$data['last_update'] = $line['lastupdate']; |
1194 | 1194 | if (isset($value['timezone'])) { |
1195 | - $datetime = new DateTime($line['lastupdate'],new DateTimeZone($value['timezone'])); |
|
1195 | + $datetime = new DateTime($line['lastupdate'], new DateTimeZone($value['timezone'])); |
|
1196 | 1196 | $datetime->setTimeZone(new DateTimeZone('UTC')); |
1197 | 1197 | $data['datetime'] = $datetime->format('Y-m-d H:i:s'); |
1198 | 1198 | } else $data['datetime'] = date('Y-m-d H:i:s'); |
@@ -1208,14 +1208,14 @@ discard block |
||
1208 | 1208 | if (isset($line['route'])) $data['waypoints'] = $line['route']; // route |
1209 | 1209 | if (isset($line['aircraftname'])) { |
1210 | 1210 | $line['aircraftname'] = strtoupper($line['aircraftname']); |
1211 | - $line['aircraftname'] = str_replace('BOEING ','B',$line['aircraftname']); |
|
1212 | - $aircraft_data = explode('-',$line['aircraftname']); |
|
1211 | + $line['aircraftname'] = str_replace('BOEING ', 'B', $line['aircraftname']); |
|
1212 | + $aircraft_data = explode('-', $line['aircraftname']); |
|
1213 | 1213 | if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) >= 3 && strlen($aircraft_data[0]) <= 4) $data['aircraft_icao'] = $aircraft_data[0]; |
1214 | 1214 | elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) >= 3 && strlen($aircraft_data[1]) <= 4) $data['aircraft_icao'] = $aircraft_data[1]; |
1215 | 1215 | else { |
1216 | - $aircraft_data = explode(' ',$line['aircraftname']); |
|
1217 | - if (isset($aircraft_data[1])) $data['aircraft_icao'] = str_replace('-','',$aircraft_data[1]); |
|
1218 | - else $data['aircraft_icao'] = str_replace('-','',$line['aircraftname']); |
|
1216 | + $aircraft_data = explode(' ', $line['aircraftname']); |
|
1217 | + if (isset($aircraft_data[1])) $data['aircraft_icao'] = str_replace('-', '', $aircraft_data[1]); |
|
1218 | + else $data['aircraft_icao'] = str_replace('-', '', $line['aircraftname']); |
|
1219 | 1219 | } |
1220 | 1220 | } |
1221 | 1221 | if (isset($line['route'])) $data['waypoints'] = $line['route']; |
@@ -1240,7 +1240,7 @@ discard block |
||
1240 | 1240 | //$buffer = $Common->getData($hosts[$id]); |
1241 | 1241 | if ($globalDebug) echo 'Get Data...'."\n"; |
1242 | 1242 | $buffer = $Common->getData($value['host']); |
1243 | - $all_data = json_decode($buffer,true); |
|
1243 | + $all_data = json_decode($buffer, true); |
|
1244 | 1244 | if ($buffer != '' && is_array($all_data) && isset($all_data['ACARSData'])) { |
1245 | 1245 | $reset = 0; |
1246 | 1246 | foreach ($all_data['ACARSData'] as $line) { |
@@ -1251,7 +1251,7 @@ discard block |
||
1251 | 1251 | //$data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex |
1252 | 1252 | if (isset($line['user']['username'])) $data['pilot_name'] = $line['user']['username']; |
1253 | 1253 | if (isset($line['user_id'])) $data['pilot_id'] = $line['user_id']; |
1254 | - $data['ident'] = str_replace(' ','',$line['bid']['flightnum']); // ident |
|
1254 | + $data['ident'] = str_replace(' ', '', $line['bid']['flightnum']); // ident |
|
1255 | 1255 | if (is_numeric($data['ident'])) $data['ident'] = $line['bid']['airline']['icao'].$data['ident']; |
1256 | 1256 | $data['altitude'] = $line['altitude']; // altitude |
1257 | 1257 | $data['speed'] = $line['groundspeed']; // speed |
@@ -1262,7 +1262,7 @@ discard block |
||
1262 | 1262 | //$data['squawk'] = ''; // squawk |
1263 | 1263 | //$data['emergency'] = ''; // emergency |
1264 | 1264 | if (isset($value['timezone'])) { |
1265 | - $datetime = new DateTime($line['updated_at'],new DateTimeZone($value['timezone'])); |
|
1265 | + $datetime = new DateTime($line['updated_at'], new DateTimeZone($value['timezone'])); |
|
1266 | 1266 | $datetime->setTimeZone(new DateTimeZone('UTC')); |
1267 | 1267 | $data['datetime'] = $datetime->format('Y-m-d H:i:s'); |
1268 | 1268 | } else $data['datetime'] = date('Y-m-d H:i:s'); |
@@ -1298,14 +1298,14 @@ discard block |
||
1298 | 1298 | //$buffer = $Common->getData($hosts[$id]); |
1299 | 1299 | if ($globalDebug) echo 'Get Data...'."\n"; |
1300 | 1300 | $buffer = $Common->getData($value['host']); |
1301 | - $all_data = json_decode($buffer,true); |
|
1301 | + $all_data = json_decode($buffer, true); |
|
1302 | 1302 | if ($buffer != '' && is_array($all_data)) { |
1303 | 1303 | $reset = 0; |
1304 | 1304 | foreach ($all_data as $line) { |
1305 | 1305 | $data = array(); |
1306 | 1306 | //$data['id'] = $line['id']; // id not usable |
1307 | 1307 | $data['id'] = trim($line['flight_id']); |
1308 | - $data['hex'] = substr(str_pad(bin2hex($line['callsign']),6,'000000',STR_PAD_LEFT),-6); // hex |
|
1308 | + $data['hex'] = substr(str_pad(bin2hex($line['callsign']), 6, '000000', STR_PAD_LEFT), -6); // hex |
|
1309 | 1309 | $data['pilot_name'] = $line['pilot_name']; |
1310 | 1310 | $data['pilot_id'] = $line['pilot_id']; |
1311 | 1311 | $data['ident'] = trim($line['callsign']); // ident |
@@ -1349,24 +1349,24 @@ discard block |
||
1349 | 1349 | //$buffer = $Common->getData($hosts[$id]); |
1350 | 1350 | if ($globalDebug) echo 'Get Data...'."\n"; |
1351 | 1351 | $buffer = $Common->getData($value['host']); |
1352 | - $all_data = json_decode($buffer,true); |
|
1352 | + $all_data = json_decode($buffer, true); |
|
1353 | 1353 | if ($buffer != '') { |
1354 | 1354 | $Source->deleteLocationBySource('blitzortung'); |
1355 | - $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer)); |
|
1356 | - $buffer = explode('\n',$buffer); |
|
1355 | + $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '\n', $buffer)); |
|
1356 | + $buffer = explode('\n', $buffer); |
|
1357 | 1357 | foreach ($buffer as $buffer_line) { |
1358 | - $line = json_decode($buffer_line,true); |
|
1358 | + $line = json_decode($buffer_line, true); |
|
1359 | 1359 | if (isset($line['time'])) { |
1360 | 1360 | $data = array(); |
1361 | 1361 | $data['altitude'] = $line['alt']; // altitude |
1362 | 1362 | $data['latitude'] = $line['lat']; // lat |
1363 | 1363 | $data['longitude'] = $line['lon']; // long |
1364 | - $data['datetime'] = date('Y-m-d H:i:s',substr($line['time'],0,10)); |
|
1364 | + $data['datetime'] = date('Y-m-d H:i:s', substr($line['time'], 0, 10)); |
|
1365 | 1365 | $data['id_source'] = $id_source; |
1366 | 1366 | $data['format_source'] = 'blitzortung'; |
1367 | 1367 | $SI->add($data); |
1368 | 1368 | if ($globalDebug) echo '☈ Lightning added'."\n"; |
1369 | - $Source->addLocation('',$data['latitude'],$data['longitude'],0,'','','blitzortung','weather/thunderstorm.png','lightning',$id,0,$data['datetime']); |
|
1369 | + $Source->addLocation('', $data['latitude'], $data['longitude'], 0, '', '', 'blitzortung', 'weather/thunderstorm.png', 'lightning', $id, 0, $data['datetime']); |
|
1370 | 1370 | unset($data); |
1371 | 1371 | } |
1372 | 1372 | } |
@@ -1391,11 +1391,11 @@ discard block |
||
1391 | 1391 | //$value = $formats[$nb]; |
1392 | 1392 | $format = $globalSources[$nb]['format']; |
1393 | 1393 | if ($format == 'sbs' || $format == 'aprs' || $format == 'famaprs' || $format == 'raw' || $format == 'tsv' || $format == 'acarssbs3') { |
1394 | - $buffer = @socket_read($r, 6000,PHP_NORMAL_READ); |
|
1394 | + $buffer = @socket_read($r, 6000, PHP_NORMAL_READ); |
|
1395 | 1395 | } elseif ($format == 'vrstcp') { |
1396 | 1396 | $buffer = @socket_read($r, 6000); |
1397 | 1397 | } else { |
1398 | - $az = socket_recvfrom($r,$buffer,6000,0,$remote_ip,$remote_port); |
|
1398 | + $az = socket_recvfrom($r, $buffer, 6000, 0, $remote_ip, $remote_port); |
|
1399 | 1399 | } |
1400 | 1400 | //$buffer = socket_read($r, 60000,PHP_NORMAL_READ); |
1401 | 1401 | //echo $buffer."\n"; |
@@ -1405,8 +1405,8 @@ discard block |
||
1405 | 1405 | //$SI::del(); |
1406 | 1406 | if ($buffer !== FALSE) { |
1407 | 1407 | if ($format == 'vrstcp') { |
1408 | - $buffer = explode('},{',$buffer); |
|
1409 | - } else $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'',$buffer)); |
|
1408 | + $buffer = explode('},{', $buffer); |
|
1409 | + } else $buffer = trim(str_replace(array("\r\n", "\r", "\n", "\\r", "\\n", "\\r\\n"), '', $buffer)); |
|
1410 | 1410 | } |
1411 | 1411 | // SBS format is CSV format |
1412 | 1412 | if ($buffer !== FALSE && $buffer !== '') { |
@@ -1430,7 +1430,7 @@ discard block |
||
1430 | 1430 | $ais_data = $AIS->parse_line(trim($buffer)); |
1431 | 1431 | $data = array(); |
1432 | 1432 | if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident']; |
1433 | - if (isset($ais_data['mmsi'])) $data['mmsi'] = substr($ais_data['mmsi'],-9); |
|
1433 | + if (isset($ais_data['mmsi'])) $data['mmsi'] = substr($ais_data['mmsi'], -9); |
|
1434 | 1434 | if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed']; |
1435 | 1435 | if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading']; |
1436 | 1436 | if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude']; |
@@ -1441,13 +1441,13 @@ discard block |
||
1441 | 1441 | if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo']; |
1442 | 1442 | if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign']; |
1443 | 1443 | if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination']; |
1444 | - if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']); |
|
1444 | + if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s', $ais_data['eta_ts']); |
|
1445 | 1445 | if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true; |
1446 | 1446 | if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name']; |
1447 | 1447 | if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats']; |
1448 | 1448 | |
1449 | 1449 | if (isset($ais_data['timestamp'])) { |
1450 | - $data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']); |
|
1450 | + $data['datetime'] = date('Y-m-d H:i:s', $ais_data['timestamp']); |
|
1451 | 1451 | } else { |
1452 | 1452 | $data['datetime'] = date('Y-m-d H:i:s'); |
1453 | 1453 | } |
@@ -1458,10 +1458,10 @@ discard block |
||
1458 | 1458 | } elseif ($format == 'flightgearsp') { |
1459 | 1459 | //echo $buffer."\n"; |
1460 | 1460 | if (strlen($buffer) > 5) { |
1461 | - $line = explode(',',$buffer); |
|
1461 | + $line = explode(',', $buffer); |
|
1462 | 1462 | $data = array(); |
1463 | 1463 | //XGPS,2.0947,41.3093,-3047.6953,198.930,0.000,callsign,c172p |
1464 | - $data['hex'] = substr(str_pad(bin2hex($line[6].$line[7]),6,'000000',STR_PAD_LEFT),0,6); |
|
1464 | + $data['hex'] = substr(str_pad(bin2hex($line[6].$line[7]), 6, '000000', STR_PAD_LEFT), 0, 6); |
|
1465 | 1465 | $data['ident'] = $line[6]; |
1466 | 1466 | $data['aircraft_name'] = $line[7]; |
1467 | 1467 | $data['longitude'] = $line[1]; |
@@ -1478,16 +1478,16 @@ discard block |
||
1478 | 1478 | } elseif ($format == 'acars') { |
1479 | 1479 | if ($globalDebug) echo 'ACARS : '.$buffer."\n"; |
1480 | 1480 | $ACARS->add(trim($buffer)); |
1481 | - socket_sendto($r, "OK " . $buffer , 100 , 0 , $remote_ip , $remote_port); |
|
1481 | + socket_sendto($r, "OK ".$buffer, 100, 0, $remote_ip, $remote_port); |
|
1482 | 1482 | $ACARS->deleteLiveAcarsData(); |
1483 | 1483 | } elseif ($format == 'flightgearmp') { |
1484 | - if (substr($buffer,0,1) != '#') { |
|
1484 | + if (substr($buffer, 0, 1) != '#') { |
|
1485 | 1485 | $data = array(); |
1486 | 1486 | //echo $buffer."\n"; |
1487 | - $line = explode(' ',$buffer); |
|
1487 | + $line = explode(' ', $buffer); |
|
1488 | 1488 | if (count($line) == 11) { |
1489 | - $userserver = explode('@',$line[0]); |
|
1490 | - $data['hex'] = substr(str_pad(bin2hex($line[0]),6,'000000',STR_PAD_LEFT),0,6); // hex |
|
1489 | + $userserver = explode('@', $line[0]); |
|
1490 | + $data['hex'] = substr(str_pad(bin2hex($line[0]), 6, '000000', STR_PAD_LEFT), 0, 6); // hex |
|
1491 | 1491 | $data['ident'] = $userserver[0]; |
1492 | 1492 | $data['registration'] = $userserver[0]; |
1493 | 1493 | $data['latitude'] = $line[4]; |
@@ -1495,8 +1495,8 @@ discard block |
||
1495 | 1495 | $data['altitude'] = $line[6]; |
1496 | 1496 | $data['datetime'] = date('Y-m-d H:i:s'); |
1497 | 1497 | $aircraft_type = $line[10]; |
1498 | - $aircraft_type = preg_split(':/:',$aircraft_type); |
|
1499 | - $data['aircraft_name'] = substr(end($aircraft_type),0,-4); |
|
1498 | + $aircraft_type = preg_split(':/:', $aircraft_type); |
|
1499 | + $data['aircraft_name'] = substr(end($aircraft_type), 0, -4); |
|
1500 | 1500 | if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true; |
1501 | 1501 | if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data); |
1502 | 1502 | } |
@@ -1505,8 +1505,8 @@ discard block |
||
1505 | 1505 | echo 'Beast Binary format not yet supported. Beast AVR format is supported in alpha state'."\n"; |
1506 | 1506 | die; |
1507 | 1507 | } elseif ($format == 'vrstcp') { |
1508 | - foreach($buffer as $all_data) { |
|
1509 | - $line = json_decode('{'.$all_data.'}',true); |
|
1508 | + foreach ($buffer as $all_data) { |
|
1509 | + $line = json_decode('{'.$all_data.'}', true); |
|
1510 | 1510 | $data = array(); |
1511 | 1511 | if (isset($line['Icao'])) $data['hex'] = $line['Icao']; // hex |
1512 | 1512 | if (isset($line['Call'])) $data['ident'] = $line['Call']; // ident |
@@ -1532,16 +1532,16 @@ discard block |
||
1532 | 1532 | if (isset($data['latitude']) && isset($data['hex'])) $SI->add($data); |
1533 | 1533 | unset($data); |
1534 | 1534 | } |
1535 | - } elseif ($format == 'tsv' || substr($buffer,0,4) == 'clock') { |
|
1535 | + } elseif ($format == 'tsv' || substr($buffer, 0, 4) == 'clock') { |
|
1536 | 1536 | $line = explode("\t", $buffer); |
1537 | - for($k = 0; $k < count($line); $k=$k+2) { |
|
1537 | + for ($k = 0; $k < count($line); $k = $k + 2) { |
|
1538 | 1538 | $key = $line[$k]; |
1539 | - $lined[$key] = $line[$k+1]; |
|
1539 | + $lined[$key] = $line[$k + 1]; |
|
1540 | 1540 | } |
1541 | 1541 | if (count($lined) > 3) { |
1542 | 1542 | $data['hex'] = $lined['hexid']; |
1543 | 1543 | //$data['datetime'] = date('Y-m-d H:i:s',strtotime($lined['clock']));; |
1544 | - $data['datetime'] = date('Y-m-d H:i:s');; |
|
1544 | + $data['datetime'] = date('Y-m-d H:i:s'); ; |
|
1545 | 1545 | if (isset($lined['ident'])) $data['ident'] = $lined['ident']; |
1546 | 1546 | if (isset($lined['lat'])) $data['latitude'] = $lined['lat']; |
1547 | 1547 | if (isset($lined['lon'])) $data['longitude'] = $lined['lon']; |
@@ -1560,23 +1560,23 @@ discard block |
||
1560 | 1560 | } else $error = true; |
1561 | 1561 | } elseif ($format == 'aprs' && $use_aprs) { |
1562 | 1562 | if ($aprs_connect == 0) { |
1563 | - $send = @ socket_send( $r , $aprs_login , strlen($aprs_login) , 0 ); |
|
1563 | + $send = @ socket_send($r, $aprs_login, strlen($aprs_login), 0); |
|
1564 | 1564 | $aprs_connect = 1; |
1565 | 1565 | } |
1566 | 1566 | |
1567 | - if ( $aprs_keep>60 && time() - $aprs_last_tx > $aprs_keep ) { |
|
1567 | + if ($aprs_keep > 60 && time() - $aprs_last_tx > $aprs_keep) { |
|
1568 | 1568 | $aprs_last_tx = time(); |
1569 | 1569 | $data_aprs = "# Keep alive"; |
1570 | - $send = @ socket_send( $r , $data_aprs , strlen($data_aprs) , 0 ); |
|
1570 | + $send = @ socket_send($r, $data_aprs, strlen($data_aprs), 0); |
|
1571 | 1571 | } |
1572 | 1572 | |
1573 | 1573 | //echo 'Connect : '.$aprs_connect.' '.$buffer."\n"; |
1574 | 1574 | //echo 'APRS data : '.$buffer."\n"; |
1575 | - $buffer = str_replace('APRS <- ','',$buffer); |
|
1576 | - $buffer = str_replace('APRS -> ','',$buffer); |
|
1575 | + $buffer = str_replace('APRS <- ', '', $buffer); |
|
1576 | + $buffer = str_replace('APRS -> ', '', $buffer); |
|
1577 | 1577 | //echo $buffer."\n"; |
1578 | 1578 | date_default_timezone_set('UTC'); |
1579 | - if (substr($buffer,0,1) != '#' && substr($buffer,0,1) != '@' && substr($buffer,0,5) != 'APRS ') { |
|
1579 | + if (substr($buffer, 0, 1) != '#' && substr($buffer, 0, 1) != '@' && substr($buffer, 0, 5) != 'APRS ') { |
|
1580 | 1580 | $line = $APRS->parse($buffer); |
1581 | 1581 | //if (is_array($line) && isset($line['address']) && $line['address'] != '' && isset($line['ident'])) { |
1582 | 1582 | if (is_array($line) && isset($line['latitude']) && isset($line['longitude']) && (isset($line['ident']) || isset($line['address']) || isset($line['mmsi']))) { |
@@ -1591,7 +1591,7 @@ discard block |
||
1591 | 1591 | if (isset($line['arrival_date'])) $data['arrival_date'] = $line['arrival_date']; |
1592 | 1592 | if (isset($line['typeid'])) $data['type_id'] = $line['typeid']; |
1593 | 1593 | if (isset($line['statusid'])) $data['status_id'] = $line['statusid']; |
1594 | - if (isset($line['timestamp'])) $data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']); |
|
1594 | + if (isset($line['timestamp'])) $data['datetime'] = date('Y-m-d H:i:s', $line['timestamp']); |
|
1595 | 1595 | else $data['datetime'] = date('Y-m-d H:i:s'); |
1596 | 1596 | //$data['datetime'] = date('Y-m-d H:i:s'); |
1597 | 1597 | if (isset($line['ident'])) $data['ident'] = $line['ident']; |
@@ -1674,29 +1674,29 @@ discard block |
||
1674 | 1674 | } elseif (!isset($line['stealth']) && is_numeric($data['latitude']) && is_numeric($data['longitude']) && isset($data['ident']) && isset($data['altitude'])) { |
1675 | 1675 | if (!isset($data['altitude'])) $data['altitude'] = 0; |
1676 | 1676 | $Source->deleteOldLocationByType('gs'); |
1677 | - if (count($Source->getLocationInfoByNameType($data['ident'],'gs')) > 0) { |
|
1678 | - $Source->updateLocation($data['ident'],$data['latitude'],$data['longitude'],$data['altitude'],'','',$data['source_name'],'antenna.png','gs',$id,0,$data['datetime']); |
|
1677 | + if (count($Source->getLocationInfoByNameType($data['ident'], 'gs')) > 0) { |
|
1678 | + $Source->updateLocation($data['ident'], $data['latitude'], $data['longitude'], $data['altitude'], '', '', $data['source_name'], 'antenna.png', 'gs', $id, 0, $data['datetime']); |
|
1679 | 1679 | } else { |
1680 | - $Source->addLocation($data['ident'],$data['latitude'],$data['longitude'],$data['altitude'],'','',$data['source_name'],'antenna.png','gs',$id,0,$data['datetime']); |
|
1680 | + $Source->addLocation($data['ident'], $data['latitude'], $data['longitude'], $data['altitude'], '', '', $data['source_name'], 'antenna.png', 'gs', $id, 0, $data['datetime']); |
|
1681 | 1681 | } |
1682 | 1682 | } elseif (isset($line['symbol']) && $line['symbol'] == 'Weather Station') { |
1683 | 1683 | //if ($globalDebug) echo '!! Weather Station not yet supported'."\n"; |
1684 | 1684 | if ($globalDebug) echo '# Weather Station added'."\n"; |
1685 | 1685 | $Source->deleteOldLocationByType('wx'); |
1686 | 1686 | $weather_data = json_encode($line); |
1687 | - if (count($Source->getLocationInfoByNameType($data['ident'],'wx')) > 0) { |
|
1688 | - $Source->updateLocation($data['ident'],$data['latitude'],$data['longitude'],0,'','',$data['source_name'],'wx.png','wx',$id,0,$data['datetime'],$weather_data); |
|
1687 | + if (count($Source->getLocationInfoByNameType($data['ident'], 'wx')) > 0) { |
|
1688 | + $Source->updateLocation($data['ident'], $data['latitude'], $data['longitude'], 0, '', '', $data['source_name'], 'wx.png', 'wx', $id, 0, $data['datetime'], $weather_data); |
|
1689 | 1689 | } else { |
1690 | - $Source->addLocation($data['ident'],$data['latitude'],$data['longitude'],0,'','',$data['source_name'],'wx.png','wx',$id,0,$data['datetime'],$weather_data); |
|
1690 | + $Source->addLocation($data['ident'], $data['latitude'], $data['longitude'], 0, '', '', $data['source_name'], 'wx.png', 'wx', $id, 0, $data['datetime'], $weather_data); |
|
1691 | 1691 | } |
1692 | 1692 | } elseif (isset($line['symbol']) && ($line['symbol'] == 'Lightning' || $line['symbol'] == 'Thunderstorm')) { |
1693 | 1693 | //if ($globalDebug) echo '!! Weather Station not yet supported'."\n"; |
1694 | 1694 | if ($globalDebug) echo '☈ Lightning added'."\n"; |
1695 | 1695 | $Source->deleteOldLocationByType('lightning'); |
1696 | - if (count($Source->getLocationInfoByNameType($data['ident'],'lightning')) > 0) { |
|
1697 | - $Source->updateLocation($data['ident'],$data['latitude'],$data['longitude'],0,'','',$data['source_name'],'weather/thunderstorm.png','lightning',$id,0,$data['datetime'],$data['comment']); |
|
1696 | + if (count($Source->getLocationInfoByNameType($data['ident'], 'lightning')) > 0) { |
|
1697 | + $Source->updateLocation($data['ident'], $data['latitude'], $data['longitude'], 0, '', '', $data['source_name'], 'weather/thunderstorm.png', 'lightning', $id, 0, $data['datetime'], $data['comment']); |
|
1698 | 1698 | } else { |
1699 | - $Source->addLocation($data['ident'],$data['latitude'],$data['longitude'],0,'','',$data['source_name'],'weather/thunderstorm.png','lightning',$id,0,$data['datetime'],$data['comment']); |
|
1699 | + $Source->addLocation($data['ident'], $data['latitude'], $data['longitude'], 0, '', '', $data['source_name'], 'weather/thunderstorm.png', 'lightning', $id, 0, $data['datetime'], $data['comment']); |
|
1700 | 1700 | } |
1701 | 1701 | } elseif ($globalDebug) { |
1702 | 1702 | echo '/!\ Not added: '.$buffer."\n"; |
@@ -1705,7 +1705,7 @@ discard block |
||
1705 | 1705 | unset($data); |
1706 | 1706 | } |
1707 | 1707 | elseif (is_array($line) && isset($line['ident']) && $line['ident'] != '') { |
1708 | - $Source->updateLocationDescByName($line['ident'],$line['source'],$id,$line['comment']); |
|
1708 | + $Source->updateLocationDescByName($line['ident'], $line['source'], $id, $line['comment']); |
|
1709 | 1709 | } |
1710 | 1710 | /* |
1711 | 1711 | elseif (is_array($line) && $globalDebug && isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && ($line['symbol'] == 'Car' || $line['symbol'] == 'Ambulance' || $line['symbol'] == 'Van' || $line['symbol'] == 'Truck' || $line['symbol'] == 'Truck (18 Wheeler)' || $line['symbol'] == 'Motorcycle')) { |
@@ -1714,7 +1714,7 @@ discard block |
||
1714 | 1714 | */ |
1715 | 1715 | //elseif ($line == false && $globalDebug) echo 'Ignored ('.$buffer.")\n"; |
1716 | 1716 | elseif ($line == true && $globalDebug) echo '!! Failed : '.$buffer."!!\n"; |
1717 | - if (isset($globalSources[$nb]['last_weather_clean']) && time()-$globalSources[$nb]['last_weather_clean'] > 60*5) { |
|
1717 | + if (isset($globalSources[$nb]['last_weather_clean']) && time() - $globalSources[$nb]['last_weather_clean'] > 60*5) { |
|
1718 | 1718 | $Source->deleteOldLocationByType('lightning'); |
1719 | 1719 | $Source->deleteOldLocationByType('wx'); |
1720 | 1720 | $globalSources[$nb]['last_weather_clean'] = time(); |
@@ -1799,7 +1799,7 @@ discard block |
||
1799 | 1799 | connect_all($sourceee); |
1800 | 1800 | $sourceee = array(); |
1801 | 1801 | //connect_all($globalSources); |
1802 | - $tt[$format]=0; |
|
1802 | + $tt[$format] = 0; |
|
1803 | 1803 | break; |
1804 | 1804 | } |
1805 | 1805 | //else if ($globalDebug) echo "Trying again (".$tt[$format]."x) ".$format."..."; |
@@ -1809,14 +1809,14 @@ discard block |
||
1809 | 1809 | } else { |
1810 | 1810 | $error = socket_strerror(socket_last_error()); |
1811 | 1811 | if (($error != SOCKET_EINPROGRESS && $error != SOCKET_EALREADY && $error != 'Success') || (time() - $time >= $timeout && $error != 'Success')) { |
1812 | - if ($globalDebug) echo "ERROR : socket_select give this error ".$error . "\n"; |
|
1812 | + if ($globalDebug) echo "ERROR : socket_select give this error ".$error."\n"; |
|
1813 | 1813 | if (isset($globalDebug)) echo "Restarting...\n"; |
1814 | 1814 | // Restart the script if possible |
1815 | 1815 | if (is_array($sockets)) { |
1816 | 1816 | if ($globalDebug) echo "Shutdown all sockets..."; |
1817 | 1817 | |
1818 | 1818 | foreach ($sockets as $sock) { |
1819 | - @socket_shutdown($sock,2); |
|
1819 | + @socket_shutdown($sock, 2); |
|
1820 | 1820 | @socket_close($sock); |
1821 | 1821 | } |
1822 | 1822 |
@@ -14,13 +14,17 @@ discard block |
||
14 | 14 | require_once(dirname(__FILE__).'/../require/class.Source.php'); |
15 | 15 | require_once(dirname(__FILE__).'/../require/class.Connection.php'); |
16 | 16 | require_once(dirname(__FILE__).'/../require/class.Common.php'); |
17 | -if (isset($globalTracker) && $globalTracker) require_once(dirname(__FILE__).'/../require/class.TrackerImport.php'); |
|
17 | +if (isset($globalTracker) && $globalTracker) { |
|
18 | + require_once(dirname(__FILE__).'/../require/class.TrackerImport.php'); |
|
19 | +} |
|
18 | 20 | if (isset($globalMarine) && $globalMarine) { |
19 | 21 | require_once(dirname(__FILE__).'/../require/class.AIS.php'); |
20 | 22 | require_once(dirname(__FILE__).'/../require/class.MarineImport.php'); |
21 | 23 | } |
22 | 24 | |
23 | -if (!isset($globalDebug)) $globalDebug = FALSE; |
|
25 | +if (!isset($globalDebug)) { |
|
26 | + $globalDebug = FALSE; |
|
27 | +} |
|
24 | 28 | |
25 | 29 | // Check if schema is at latest version |
26 | 30 | $Connection = new Connection(); |
@@ -59,66 +63,107 @@ discard block |
||
59 | 63 | //elseif (isset($options['source'])) $hosts = array($options['source']); |
60 | 64 | if (isset($options['s'])) { |
61 | 65 | $globalSources = array(); |
62 | - if (isset($options['format'])) $globalSources[] = array('host' => $options['s'],'format' => $options['format']); |
|
63 | - else $globalSources[] = array('host' => $options['s']); |
|
64 | -} elseif (isset($options['source'])) { |
|
66 | + if (isset($options['format'])) { |
|
67 | + $globalSources[] = array('host' => $options['s'],'format' => $options['format']); |
|
68 | + } else { |
|
69 | + $globalSources[] = array('host' => $options['s']); |
|
70 | + } |
|
71 | + } elseif (isset($options['source'])) { |
|
65 | 72 | $globalSources = array(); |
66 | - if (isset($options['format'])) $globalSources[] = array('host' => $options['source'],'format' => $options['format']); |
|
67 | - else $globalSources[] = array('host' => $options['source']); |
|
68 | -} |
|
73 | + if (isset($options['format'])) { |
|
74 | + $globalSources[] = array('host' => $options['source'],'format' => $options['format']); |
|
75 | + } else { |
|
76 | + $globalSources[] = array('host' => $options['source']); |
|
77 | + } |
|
78 | + } |
|
69 | 79 | if (isset($options['aprsserverhost'])) { |
70 | 80 | $globalServerAPRS = TRUE; |
71 | 81 | $globalServerAPRShost = $options['aprsserverhost']; |
72 | 82 | } |
73 | -if (isset($options['aprsserverport'])) $globalServerAPRSport = $options['aprsserverport']; |
|
74 | -if (isset($options['aprsserverssid'])) $globalServerAPRSssid = $options['aprsserverssid']; |
|
75 | -if (isset($options['aprsserverpass'])) $globalServerAPRSpass = $options['aprsserverpass']; |
|
76 | -if (isset($options['noaprsserver'])) $globalServerAPRS = FALSE; |
|
83 | +if (isset($options['aprsserverport'])) { |
|
84 | + $globalServerAPRSport = $options['aprsserverport']; |
|
85 | +} |
|
86 | +if (isset($options['aprsserverssid'])) { |
|
87 | + $globalServerAPRSssid = $options['aprsserverssid']; |
|
88 | +} |
|
89 | +if (isset($options['aprsserverpass'])) { |
|
90 | + $globalServerAPRSpass = $options['aprsserverpass']; |
|
91 | +} |
|
92 | +if (isset($options['noaprsserver'])) { |
|
93 | + $globalServerAPRS = FALSE; |
|
94 | +} |
|
77 | 95 | if (isset($options['enable-aircraft'])) { |
78 | - if ($globalDebug) echo 'Enable Aircraft mode'."\n"; |
|
96 | + if ($globalDebug) { |
|
97 | + echo 'Enable Aircraft mode'."\n"; |
|
98 | + } |
|
79 | 99 | $globalAircraft = TRUE; |
80 | 100 | } |
81 | 101 | if (isset($options['disable-aircraft'])) { |
82 | - if ($globalDebug) echo 'Disable Aircraft mode'."\n"; |
|
102 | + if ($globalDebug) { |
|
103 | + echo 'Disable Aircraft mode'."\n"; |
|
104 | + } |
|
83 | 105 | $globalAircraft = FALSE; |
84 | 106 | } |
85 | 107 | if (isset($options['enable-tracker'])) { |
86 | - if ($globalDebug) echo 'Enable Tracker mode'."\n"; |
|
108 | + if ($globalDebug) { |
|
109 | + echo 'Enable Tracker mode'."\n"; |
|
110 | + } |
|
87 | 111 | $globalTracker = TRUE; |
88 | 112 | } |
89 | 113 | if (isset($options['disable-tracker'])) { |
90 | - if ($globalDebug) echo 'Disable Tracker mode'."\n"; |
|
114 | + if ($globalDebug) { |
|
115 | + echo 'Disable Tracker mode'."\n"; |
|
116 | + } |
|
91 | 117 | $globalTracker = FALSE; |
92 | 118 | } |
93 | 119 | if (isset($options['enable-marine'])) { |
94 | - if ($globalDebug) echo 'Enable Marine mode'."\n"; |
|
120 | + if ($globalDebug) { |
|
121 | + echo 'Enable Marine mode'."\n"; |
|
122 | + } |
|
95 | 123 | $globalMarine = TRUE; |
96 | 124 | } |
97 | 125 | if (isset($options['disable-marine'])) { |
98 | - if ($globalDebug) echo 'Disable Marine mode'."\n"; |
|
126 | + if ($globalDebug) { |
|
127 | + echo 'Disable Marine mode'."\n"; |
|
128 | + } |
|
99 | 129 | $globalMarine = FALSE; |
100 | 130 | } |
101 | -if (isset($options['nodaemon'])) $globalDaemon = FALSE; |
|
102 | -if (isset($options['server'])) $globalServer = TRUE; |
|
103 | -if (isset($options['idsource'])) $id_source = $options['idsource']; |
|
104 | -else $id_source = 1; |
|
131 | +if (isset($options['nodaemon'])) { |
|
132 | + $globalDaemon = FALSE; |
|
133 | +} |
|
134 | +if (isset($options['server'])) { |
|
135 | + $globalServer = TRUE; |
|
136 | +} |
|
137 | +if (isset($options['idsource'])) { |
|
138 | + $id_source = $options['idsource']; |
|
139 | +} else { |
|
140 | + $id_source = 1; |
|
141 | +} |
|
105 | 142 | if (isset($globalServer) && $globalServer) { |
106 | - if ($globalDebug) echo "Using Server Mode\n"; |
|
143 | + if ($globalDebug) { |
|
144 | + echo "Using Server Mode\n"; |
|
145 | + } |
|
107 | 146 | $SI=new SpotterServer(); |
108 | 147 | /* |
109 | 148 | require_once(dirname(__FILE__).'/../require/class.APRS.php'); |
110 | 149 | $SI = new adsb2aprs(); |
111 | 150 | $SI->connect(); |
112 | 151 | */ |
113 | -} else $SI=new SpotterImport($Connection->db); |
|
152 | +} else { |
|
153 | + $SI=new SpotterImport($Connection->db); |
|
154 | +} |
|
114 | 155 | |
115 | -if (isset($globalTracker) && $globalTracker) require_once(dirname(__FILE__).'/../require/class.TrackerImport.php'); |
|
156 | +if (isset($globalTracker) && $globalTracker) { |
|
157 | + require_once(dirname(__FILE__).'/../require/class.TrackerImport.php'); |
|
158 | +} |
|
116 | 159 | if (isset($globalMarine) && $globalMarine) { |
117 | 160 | require_once(dirname(__FILE__).'/../require/class.AIS.php'); |
118 | 161 | require_once(dirname(__FILE__).'/../require/class.MarineImport.php'); |
119 | 162 | } |
120 | 163 | |
121 | -if (isset($globalTracker) && $globalTracker) $TI = new TrackerImport($Connection->db); |
|
164 | +if (isset($globalTracker) && $globalTracker) { |
|
165 | + $TI = new TrackerImport($Connection->db); |
|
166 | +} |
|
122 | 167 | if (isset($globalMarine) && $globalMarine) { |
123 | 168 | $AIS = new AIS(); |
124 | 169 | $MI = new MarineImport($Connection->db); |
@@ -143,7 +188,9 @@ discard block |
||
143 | 188 | } |
144 | 189 | |
145 | 190 | // let's try and connect |
146 | -if ($globalDebug) echo "Connecting...\n"; |
|
191 | +if ($globalDebug) { |
|
192 | + echo "Connecting...\n"; |
|
193 | +} |
|
147 | 194 | $use_aprs = false; |
148 | 195 | $aprs_full = false; |
149 | 196 | $reset = 0; |
@@ -152,7 +199,9 @@ discard block |
||
152 | 199 | //global $sockets, $formats, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs; |
153 | 200 | global $sockets,$httpfeeds, $globalSources, $globalDebug,$aprs_connect,$last_exec, $globalSourcesRights, $use_aprs, $reset,$context; |
154 | 201 | $reset++; |
155 | - if ($globalDebug) echo 'Connect to all...'."\n"; |
|
202 | + if ($globalDebug) { |
|
203 | + echo 'Connect to all...'."\n"; |
|
204 | + } |
|
156 | 205 | foreach ($hosts as $id => $value) { |
157 | 206 | $host = $value['host']; |
158 | 207 | $globalSources[$id]['last_exec'] = 0; |
@@ -162,22 +211,30 @@ discard block |
||
162 | 211 | //$formats[$id] = 'deltadbtxt'; |
163 | 212 | $globalSources[$id]['format'] = 'deltadbtxt'; |
164 | 213 | //$last_exec['deltadbtxt'] = 0; |
165 | - if ($globalDebug) echo "Connect to deltadb source (".$host.")...\n"; |
|
214 | + if ($globalDebug) { |
|
215 | + echo "Connect to deltadb source (".$host.")...\n"; |
|
216 | + } |
|
166 | 217 | } else if (preg_match('/vatsim-data.txt$/i',$host)) { |
167 | 218 | //$formats[$id] = 'vatsimtxt'; |
168 | 219 | $globalSources[$id]['format'] = 'vatsimtxt'; |
169 | 220 | //$last_exec['vatsimtxt'] = 0; |
170 | - if ($globalDebug) echo "Connect to vatsim source (".$host.")...\n"; |
|
221 | + if ($globalDebug) { |
|
222 | + echo "Connect to vatsim source (".$host.")...\n"; |
|
223 | + } |
|
171 | 224 | } else if (preg_match('/aircraftlist.json$/i',$host)) { |
172 | 225 | //$formats[$id] = 'aircraftlistjson'; |
173 | 226 | $globalSources[$id]['format'] = 'aircraftlistjson'; |
174 | 227 | //$last_exec['aircraftlistjson'] = 0; |
175 | - if ($globalDebug) echo "Connect to aircraftlist.json source (".$host.")...\n"; |
|
228 | + if ($globalDebug) { |
|
229 | + echo "Connect to aircraftlist.json source (".$host.")...\n"; |
|
230 | + } |
|
176 | 231 | } else if (preg_match('/opensky/i',$host)) { |
177 | 232 | //$formats[$id] = 'aircraftlistjson'; |
178 | 233 | $globalSources[$id]['format'] = 'opensky'; |
179 | 234 | //$last_exec['aircraftlistjson'] = 0; |
180 | - if ($globalDebug) echo "Connect to opensky source (".$host.")...\n"; |
|
235 | + if ($globalDebug) { |
|
236 | + echo "Connect to opensky source (".$host.")...\n"; |
|
237 | + } |
|
181 | 238 | /* |
182 | 239 | // Disabled for now, site change source format |
183 | 240 | } else if (preg_match('/radarvirtuel.com\/list_aircrafts$/i',$host)) { |
@@ -194,7 +251,9 @@ discard block |
||
194 | 251 | //$formats[$id] = 'planeupdatefaa'; |
195 | 252 | $globalSources[$id]['format'] = 'planeupdatefaa'; |
196 | 253 | //$last_exec['planeupdatefaa'] = 0; |
197 | - if ($globalDebug) echo "Connect to planeUpdateFAA.php source (".$host.")...\n"; |
|
254 | + if ($globalDebug) { |
|
255 | + echo "Connect to planeUpdateFAA.php source (".$host.")...\n"; |
|
256 | + } |
|
198 | 257 | if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) { |
199 | 258 | echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n"; |
200 | 259 | exit(0); |
@@ -203,37 +262,53 @@ discard block |
||
203 | 262 | //$formats[$id] = 'phpvmacars'; |
204 | 263 | $globalSources[$id]['format'] = 'phpvmacars'; |
205 | 264 | //$last_exec['phpvmacars'] = 0; |
206 | - if ($globalDebug) echo "Connect to phpvmacars source (".$host.")...\n"; |
|
265 | + if ($globalDebug) { |
|
266 | + echo "Connect to phpvmacars source (".$host.")...\n"; |
|
267 | + } |
|
207 | 268 | } else if (preg_match('/\/api\/v1\/acars\/data$/i',$host)) { |
208 | 269 | //$formats[$id] = 'phpvmacars'; |
209 | 270 | $globalSources[$id]['format'] = 'vaos'; |
210 | 271 | //$last_exec['phpvmacars'] = 0; |
211 | - if ($globalDebug) echo "Connect to vaos source (".$host.")...\n"; |
|
272 | + if ($globalDebug) { |
|
273 | + echo "Connect to vaos source (".$host.")...\n"; |
|
274 | + } |
|
212 | 275 | } else if (preg_match('/VAM-json.php$/i',$host)) { |
213 | 276 | //$formats[$id] = 'phpvmacars'; |
214 | 277 | $globalSources[$id]['format'] = 'vam'; |
215 | - if ($globalDebug) echo "Connect to Vam source (".$host.")...\n"; |
|
278 | + if ($globalDebug) { |
|
279 | + echo "Connect to Vam source (".$host.")...\n"; |
|
280 | + } |
|
216 | 281 | } else if (preg_match('/whazzup/i',$host)) { |
217 | 282 | //$formats[$id] = 'whazzup'; |
218 | 283 | $globalSources[$id]['format'] = 'whazzup'; |
219 | 284 | //$last_exec['whazzup'] = 0; |
220 | - if ($globalDebug) echo "Connect to whazzup source (".$host.")...\n"; |
|
285 | + if ($globalDebug) { |
|
286 | + echo "Connect to whazzup source (".$host.")...\n"; |
|
287 | + } |
|
221 | 288 | } else if (preg_match('/blitzortung/i',$host)) { |
222 | 289 | $globalSources[$id]['format'] = 'blitzortung'; |
223 | - if ($globalDebug) echo "Connect to blitzortung source (".$host.")...\n"; |
|
290 | + if ($globalDebug) { |
|
291 | + echo "Connect to blitzortung source (".$host.")...\n"; |
|
292 | + } |
|
224 | 293 | } else if (preg_match('/airwhere/i',$host)) { |
225 | 294 | $globalSources[$id]['format'] = 'airwhere'; |
226 | - if ($globalDebug) echo "Connect to airwhere source (".$host.")...\n"; |
|
295 | + if ($globalDebug) { |
|
296 | + echo "Connect to airwhere source (".$host.")...\n"; |
|
297 | + } |
|
227 | 298 | } else if (preg_match('/recentpireps/i',$host)) { |
228 | 299 | //$formats[$id] = 'pirepsjson'; |
229 | 300 | $globalSources[$id]['format'] = 'pirepsjson'; |
230 | 301 | //$last_exec['pirepsjson'] = 0; |
231 | - if ($globalDebug) echo "Connect to pirepsjson source (".$host.")...\n"; |
|
302 | + if ($globalDebug) { |
|
303 | + echo "Connect to pirepsjson source (".$host.")...\n"; |
|
304 | + } |
|
232 | 305 | } else if (preg_match(':data.fr24.com/zones/fcgi/feed.js:i',$host)) { |
233 | 306 | //$formats[$id] = 'fr24json'; |
234 | 307 | $globalSources[$id]['format'] = 'fr24json'; |
235 | 308 | //$last_exec['fr24json'] = 0; |
236 | - if ($globalDebug) echo "Connect to fr24 source (".$host.")...\n"; |
|
309 | + if ($globalDebug) { |
|
310 | + echo "Connect to fr24 source (".$host.")...\n"; |
|
311 | + } |
|
237 | 312 | if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) { |
238 | 313 | echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n"; |
239 | 314 | exit(0); |
@@ -242,7 +317,9 @@ discard block |
||
242 | 317 | //$formats[$id] = 'fr24json'; |
243 | 318 | $globalSources[$id]['format'] = 'myshiptracking'; |
244 | 319 | //$last_exec['fr24json'] = 0; |
245 | - if ($globalDebug) echo "Connect to myshiptracking source (".$host.")...\n"; |
|
320 | + if ($globalDebug) { |
|
321 | + echo "Connect to myshiptracking source (".$host.")...\n"; |
|
322 | + } |
|
246 | 323 | if (!isset($globalSourcesRights) || (isset($globalSourcesRights) && !$globalSourcesRights)) { |
247 | 324 | echo '!!! You MUST set $globalSourcesRights = TRUE in settings.php if you have the right to use this feed !!!'."\n"; |
248 | 325 | exit(0); |
@@ -251,16 +328,24 @@ discard block |
||
251 | 328 | } else if (preg_match('/10001/',$host) || (isset($globalSources[$id]['port']) && $globalSources[$id]['port'] == '10001')) { |
252 | 329 | //$formats[$id] = 'tsv'; |
253 | 330 | $globalSources[$id]['format'] = 'tsv'; |
254 | - if ($globalDebug) echo "Connect to tsv source (".$host.")...\n"; |
|
331 | + if ($globalDebug) { |
|
332 | + echo "Connect to tsv source (".$host.")...\n"; |
|
333 | + } |
|
255 | 334 | } |
256 | 335 | } elseif (filter_var($host,FILTER_VALIDATE_URL)) { |
257 | 336 | if ($globalSources[$id]['format'] == 'aisnmeahttp') { |
258 | 337 | $idf = fopen($globalSources[$id]['host'],'r',false,$context); |
259 | 338 | if ($idf !== false) { |
260 | 339 | $httpfeeds[$id] = $idf; |
261 | - if ($globalDebug) echo "Connected to ".$globalSources[$id]['format']." source (".$host.")...\n"; |
|
262 | - } elseif ($globalDebug) echo "Can't connect to ".$globalSources[$id]['host']."\n"; |
|
263 | - } elseif ($globalDebug) echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n"; |
|
340 | + if ($globalDebug) { |
|
341 | + echo "Connected to ".$globalSources[$id]['format']." source (".$host.")...\n"; |
|
342 | + } |
|
343 | + } elseif ($globalDebug) { |
|
344 | + echo "Can't connect to ".$globalSources[$id]['host']."\n"; |
|
345 | + } |
|
346 | + } elseif ($globalDebug) { |
|
347 | + echo "Connect to ".$globalSources[$id]['format']." source (".$host.")...\n"; |
|
348 | + } |
|
264 | 349 | } elseif (!filter_var($host,FILTER_VALIDATE_URL)) { |
265 | 350 | $hostport = explode(':',$host); |
266 | 351 | if (isset($hostport[1])) { |
@@ -300,17 +385,25 @@ discard block |
||
300 | 385 | //$formats[$id] = 'beast'; |
301 | 386 | $globalSources[$id]['format'] = 'beast'; |
302 | 387 | //} else $formats[$id] = 'sbs'; |
303 | - } else $globalSources[$id]['format'] = 'sbs'; |
|
388 | + } else { |
|
389 | + $globalSources[$id]['format'] = 'sbs'; |
|
390 | + } |
|
304 | 391 | //if ($globalDebug) echo 'Connection in progress to '.$host.'('.$formats[$id].')....'."\n"; |
305 | 392 | } |
306 | - if ($globalDebug) echo 'Connection in progress to '.$hostn.':'.$port.' ('.$globalSources[$id]['format'].')....'."\n"; |
|
393 | + if ($globalDebug) { |
|
394 | + echo 'Connection in progress to '.$hostn.':'.$port.' ('.$globalSources[$id]['format'].')....'."\n"; |
|
395 | + } |
|
307 | 396 | } else { |
308 | - if ($globalDebug) echo 'Connection failed to '.$hostn.':'.$port.' : '.$errno.' '.$errstr."\n"; |
|
397 | + if ($globalDebug) { |
|
398 | + echo 'Connection failed to '.$hostn.':'.$port.' : '.$errno.' '.$errstr."\n"; |
|
399 | + } |
|
309 | 400 | } |
310 | 401 | } |
311 | 402 | } |
312 | 403 | } |
313 | -if (!isset($globalMinFetch)) $globalMinFetch = 15; |
|
404 | +if (!isset($globalMinFetch)) { |
|
405 | + $globalMinFetch = 15; |
|
406 | +} |
|
314 | 407 | |
315 | 408 | // Initialize all |
316 | 409 | $status = array(); |
@@ -319,13 +412,19 @@ discard block |
||
319 | 412 | $formats = array(); |
320 | 413 | $last_exec = array(); |
321 | 414 | $time = time(); |
322 | -if (isset($globalSourcesTimeout)) $timeout = $globalSourcesTimeOut; |
|
323 | -else if (isset($globalSBS1TimeOut)) $timeout = $globalSBS1TimeOut; |
|
324 | -else $timeout = 20; |
|
415 | +if (isset($globalSourcesTimeout)) { |
|
416 | + $timeout = $globalSourcesTimeOut; |
|
417 | +} else if (isset($globalSBS1TimeOut)) { |
|
418 | + $timeout = $globalSBS1TimeOut; |
|
419 | +} else { |
|
420 | + $timeout = 20; |
|
421 | +} |
|
325 | 422 | $errno = ''; |
326 | 423 | $errstr=''; |
327 | 424 | |
328 | -if (!isset($globalDaemon)) $globalDaemon = TRUE; |
|
425 | +if (!isset($globalDaemon)) { |
|
426 | + $globalDaemon = TRUE; |
|
427 | +} |
|
329 | 428 | /* Initiate connections to all the hosts simultaneously */ |
330 | 429 | //connect_all($hosts); |
331 | 430 | //connect_all($globalSources); |
@@ -354,7 +453,9 @@ discard block |
||
354 | 453 | if (isset($source['format']) && $source['format'] == 'aprs') { |
355 | 454 | $aprs_connect = 0; |
356 | 455 | $use_aprs = true; |
357 | - if (isset($source['port']) && $source['port'] == '10152') $aprs_full = true; |
|
456 | + if (isset($source['port']) && $source['port'] == '10152') { |
|
457 | + $aprs_full = true; |
|
458 | + } |
|
358 | 459 | break; |
359 | 460 | } |
360 | 461 | } |
@@ -365,25 +466,46 @@ discard block |
||
365 | 466 | $aprs_connect = 0; |
366 | 467 | $aprs_keep = 120; |
367 | 468 | $aprs_last_tx = time(); |
368 | - if (isset($globalAPRSversion)) $aprs_version = $globalAPRSversion; |
|
369 | - else $aprs_version = 'FlightAirMap '.str_replace(' ','_',$globalName); |
|
370 | - if (isset($globalAPRSssid)) $aprs_ssid = $globalAPRSssid; |
|
371 | - else $aprs_ssid = substr('FAM'.strtoupper(str_replace(' ','_',$globalName)),0,8); |
|
372 | - if (isset($globalAPRSfilter)) $aprs_filter = $globalAPRSfilter; |
|
373 | - else $aprs_filter = 'r/'.$globalCenterLatitude.'/'.$globalCenterLongitude.'/250.0'; |
|
374 | - if ($aprs_full) $aprs_filter = ''; |
|
375 | - if (isset($globalAPRSpass)) $aprs_pass = $globalAPRSpass; |
|
376 | - else $aprs_pass = '-1'; |
|
469 | + if (isset($globalAPRSversion)) { |
|
470 | + $aprs_version = $globalAPRSversion; |
|
471 | + } else { |
|
472 | + $aprs_version = 'FlightAirMap '.str_replace(' ','_',$globalName); |
|
473 | + } |
|
474 | + if (isset($globalAPRSssid)) { |
|
475 | + $aprs_ssid = $globalAPRSssid; |
|
476 | + } else { |
|
477 | + $aprs_ssid = substr('FAM'.strtoupper(str_replace(' ','_',$globalName)),0,8); |
|
478 | + } |
|
479 | + if (isset($globalAPRSfilter)) { |
|
480 | + $aprs_filter = $globalAPRSfilter; |
|
481 | + } else { |
|
482 | + $aprs_filter = 'r/'.$globalCenterLatitude.'/'.$globalCenterLongitude.'/250.0'; |
|
483 | + } |
|
484 | + if ($aprs_full) { |
|
485 | + $aprs_filter = ''; |
|
486 | + } |
|
487 | + if (isset($globalAPRSpass)) { |
|
488 | + $aprs_pass = $globalAPRSpass; |
|
489 | + } else { |
|
490 | + $aprs_pass = '-1'; |
|
491 | + } |
|
377 | 492 | |
378 | - if ($aprs_filter != '') $aprs_login = "user {$aprs_ssid} pass {$aprs_pass} vers {$aprs_version} filter {$aprs_filter}\n"; |
|
379 | - else $aprs_login = "user {$aprs_ssid} pass {$aprs_pass} vers {$aprs_version}\n"; |
|
380 | -} |
|
493 | + if ($aprs_filter != '') { |
|
494 | + $aprs_login = "user {$aprs_ssid} pass {$aprs_pass} vers {$aprs_version} filter {$aprs_filter}\n"; |
|
495 | + } else { |
|
496 | + $aprs_login = "user {$aprs_ssid} pass {$aprs_pass} vers {$aprs_version}\n"; |
|
497 | + } |
|
498 | + } |
|
381 | 499 | |
382 | 500 | // connected - lets do some work |
383 | 501 | //if ($globalDebug) echo "Connected!\n"; |
384 | 502 | sleep(1); |
385 | -if ($globalDebug) echo "SCAN MODE \n\n"; |
|
386 | -if (!isset($globalCronEnd)) $globalCronEnd = 60; |
|
503 | +if ($globalDebug) { |
|
504 | + echo "SCAN MODE \n\n"; |
|
505 | +} |
|
506 | +if (!isset($globalCronEnd)) { |
|
507 | + $globalCronEnd = 60; |
|
508 | +} |
|
387 | 509 | $endtime = time()+$globalCronEnd; |
388 | 510 | $i = 1; |
389 | 511 | $tt = array(); |
@@ -397,20 +519,28 @@ discard block |
||
397 | 519 | |
398 | 520 | // Infinite loop if daemon, else work for time defined in $globalCronEnd or only one time. |
399 | 521 | while ($i > 0) { |
400 | - if (!$globalDaemon) $i = $endtime-time(); |
|
522 | + if (!$globalDaemon) { |
|
523 | + $i = $endtime-time(); |
|
524 | + } |
|
401 | 525 | // Delete old ATC |
402 | 526 | if ($globalDaemon && ((isset($globalVA) && $globalVA) || (isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM))) { |
403 | - if ($globalDebug) echo 'Delete old ATC...'."\n"; |
|
527 | + if ($globalDebug) { |
|
528 | + echo 'Delete old ATC...'."\n"; |
|
529 | + } |
|
404 | 530 | $ATC->deleteOldATC(); |
405 | 531 | } |
406 | 532 | |
407 | 533 | if (count($last_exec) == count($globalSources)) { |
408 | 534 | $max = $globalMinFetch; |
409 | 535 | foreach ($last_exec as $last) { |
410 | - if ((time() - $last['last']) < $max) $max = time() - $last['last']; |
|
536 | + if ((time() - $last['last']) < $max) { |
|
537 | + $max = time() - $last['last']; |
|
538 | + } |
|
411 | 539 | } |
412 | 540 | if ($max != $globalMinFetch) { |
413 | - if ($globalDebug) echo 'Sleeping...'."\n"; |
|
541 | + if ($globalDebug) { |
|
542 | + echo 'Sleeping...'."\n"; |
|
543 | + } |
|
414 | 544 | sleep($globalMinFetch-$max+2); |
415 | 545 | } |
416 | 546 | } |
@@ -420,7 +550,9 @@ discard block |
||
420 | 550 | foreach ($globalSources as $id => $value) { |
421 | 551 | date_default_timezone_set('UTC'); |
422 | 552 | //if ($globalDebug) echo 'Source host : '.$value['host'].' - Source format: '.$value['format']."\n"; |
423 | - if (!isset($last_exec[$id]['last'])) $last_exec[$id]['last'] = 0; |
|
553 | + if (!isset($last_exec[$id]['last'])) { |
|
554 | + $last_exec[$id]['last'] = 0; |
|
555 | + } |
|
424 | 556 | if ($value['format'] == 'deltadbtxt' && |
425 | 557 | ( |
426 | 558 | (isset($globalSources[$id]['minfetch']) && (time() - $last_exec[$id]['last'] > $globalSources[$id]['minfetch'])) || |
@@ -429,7 +561,9 @@ discard block |
||
429 | 561 | ) { |
430 | 562 | //$buffer = $Common->getData($hosts[$id]); |
431 | 563 | $buffer = $Common->getData($value['host']); |
432 | - if ($buffer != '') $reset = 0; |
|
564 | + if ($buffer != '') { |
|
565 | + $reset = 0; |
|
566 | + } |
|
433 | 567 | $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer)); |
434 | 568 | $buffer = explode('\n',$buffer); |
435 | 569 | foreach ($buffer as $line) { |
@@ -438,20 +572,41 @@ discard block |
||
438 | 572 | $data = array(); |
439 | 573 | $data['hex'] = $line[1]; // hex |
440 | 574 | $data['ident'] = $line[2]; // ident |
441 | - if (isset($line[3])) $data['altitude'] = $line[3]; // altitude |
|
442 | - if (isset($line[4])) $data['speed'] = $line[4]; // speed |
|
443 | - if (isset($line[5])) $data['heading'] = $line[5]; // heading |
|
444 | - if (isset($line[6])) $data['latitude'] = $line[6]; // lat |
|
445 | - if (isset($line[7])) $data['longitude'] = $line[7]; // long |
|
575 | + if (isset($line[3])) { |
|
576 | + $data['altitude'] = $line[3]; |
|
577 | + } |
|
578 | + // altitude |
|
579 | + if (isset($line[4])) { |
|
580 | + $data['speed'] = $line[4]; |
|
581 | + } |
|
582 | + // speed |
|
583 | + if (isset($line[5])) { |
|
584 | + $data['heading'] = $line[5]; |
|
585 | + } |
|
586 | + // heading |
|
587 | + if (isset($line[6])) { |
|
588 | + $data['latitude'] = $line[6]; |
|
589 | + } |
|
590 | + // lat |
|
591 | + if (isset($line[7])) { |
|
592 | + $data['longitude'] = $line[7]; |
|
593 | + } |
|
594 | + // long |
|
446 | 595 | $data['verticalrate'] = ''; // vertical rate |
447 | 596 | //if (isset($line[9])) $data['squawk'] = $line[9]; // squawk |
448 | 597 | $data['emergency'] = ''; // emergency |
449 | 598 | $data['datetime'] = date('Y-m-d H:i:s'); |
450 | 599 | $data['format_source'] = 'deltadbtxt'; |
451 | 600 | $data['id_source'] = $id_source; |
452 | - if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name']; |
|
453 | - if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true; |
|
454 | - if (isset($value['sourcestats'])) $data['sourcestats'] = $value['sourcestats']; |
|
601 | + if (isset($value['name']) && $value['name'] != '') { |
|
602 | + $data['source_name'] = $value['name']; |
|
603 | + } |
|
604 | + if (isset($value['noarchive']) && $value['noarchive'] === TRUE) { |
|
605 | + $data['noarchive'] = true; |
|
606 | + } |
|
607 | + if (isset($value['sourcestats'])) { |
|
608 | + $data['sourcestats'] = $value['sourcestats']; |
|
609 | + } |
|
455 | 610 | $SI->add($data); |
456 | 611 | unset($data); |
457 | 612 | } |
@@ -466,7 +621,9 @@ discard block |
||
466 | 621 | date_default_timezone_set('CET'); |
467 | 622 | $buffer = $Common->getData(str_replace('{date}',date('Ymd'),$value['host'])); |
468 | 623 | date_default_timezone_set('UTC'); |
469 | - if ($buffer != '') $reset = 0; |
|
624 | + if ($buffer != '') { |
|
625 | + $reset = 0; |
|
626 | + } |
|
470 | 627 | $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer)); |
471 | 628 | $buffer = explode('\n',$buffer); |
472 | 629 | foreach ($buffer as $line) { |
@@ -475,18 +632,42 @@ discard block |
||
475 | 632 | $add = false; |
476 | 633 | $ais_data = $AIS->parse_line(trim($line)); |
477 | 634 | $data = array(); |
478 | - if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident']; |
|
479 | - if (isset($ais_data['mmsi'])) $data['mmsi'] = substr($ais_data['mmsi'],-9); |
|
480 | - if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed']; |
|
481 | - if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading']; |
|
482 | - if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude']; |
|
483 | - if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude']; |
|
484 | - if (isset($ais_data['status'])) $data['status'] = $ais_data['status']; |
|
485 | - if (isset($ais_data['statusid'])) $data['status_id'] = $ais_data['statusid']; |
|
486 | - if (isset($ais_data['type'])) $data['type'] = $ais_data['type']; |
|
487 | - if (isset($ais_data['typeid'])) $data['type_id'] = $ais_data['typeid']; |
|
488 | - if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo']; |
|
489 | - if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign']; |
|
635 | + if (isset($ais_data['ident'])) { |
|
636 | + $data['ident'] = $ais_data['ident']; |
|
637 | + } |
|
638 | + if (isset($ais_data['mmsi'])) { |
|
639 | + $data['mmsi'] = substr($ais_data['mmsi'],-9); |
|
640 | + } |
|
641 | + if (isset($ais_data['speed'])) { |
|
642 | + $data['speed'] = $ais_data['speed']; |
|
643 | + } |
|
644 | + if (isset($ais_data['heading'])) { |
|
645 | + $data['heading'] = $ais_data['heading']; |
|
646 | + } |
|
647 | + if (isset($ais_data['latitude'])) { |
|
648 | + $data['latitude'] = $ais_data['latitude']; |
|
649 | + } |
|
650 | + if (isset($ais_data['longitude'])) { |
|
651 | + $data['longitude'] = $ais_data['longitude']; |
|
652 | + } |
|
653 | + if (isset($ais_data['status'])) { |
|
654 | + $data['status'] = $ais_data['status']; |
|
655 | + } |
|
656 | + if (isset($ais_data['statusid'])) { |
|
657 | + $data['status_id'] = $ais_data['statusid']; |
|
658 | + } |
|
659 | + if (isset($ais_data['type'])) { |
|
660 | + $data['type'] = $ais_data['type']; |
|
661 | + } |
|
662 | + if (isset($ais_data['typeid'])) { |
|
663 | + $data['type_id'] = $ais_data['typeid']; |
|
664 | + } |
|
665 | + if (isset($ais_data['imo'])) { |
|
666 | + $data['imo'] = $ais_data['imo']; |
|
667 | + } |
|
668 | + if (isset($ais_data['callsign'])) { |
|
669 | + $data['callsign'] = $ais_data['callsign']; |
|
670 | + } |
|
490 | 671 | if (isset($ais_data['timestamp'])) { |
491 | 672 | $data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']); |
492 | 673 | if (!isset($last_exec[$id]['timestamp']) || $ais_data['timestamp'] >= $last_exec[$id]['timestamp']) { |
@@ -500,8 +681,12 @@ discard block |
||
500 | 681 | $data['format_source'] = 'aisnmeatxt'; |
501 | 682 | $data['id_source'] = $id_source; |
502 | 683 | //print_r($data); |
503 | - if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true; |
|
504 | - if ($add && isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') $MI->add($data); |
|
684 | + if (isset($value['noarchive']) && $value['noarchive'] === TRUE) { |
|
685 | + $data['noarchive'] = true; |
|
686 | + } |
|
687 | + if ($add && isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') { |
|
688 | + $MI->add($data); |
|
689 | + } |
|
505 | 690 | unset($data); |
506 | 691 | } |
507 | 692 | } |
@@ -524,20 +709,48 @@ discard block |
||
524 | 709 | if ($line != '') { |
525 | 710 | $ais_data = $AIS->parse_line(trim($line)); |
526 | 711 | $data = array(); |
527 | - if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident']; |
|
528 | - if (isset($ais_data['mmsi'])) $data['mmsi'] = substr($ais_data['mmsi'],-9); |
|
529 | - if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed']; |
|
530 | - if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading']; |
|
531 | - if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude']; |
|
532 | - if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude']; |
|
533 | - if (isset($ais_data['status'])) $data['status'] = $ais_data['status']; |
|
534 | - if (isset($ais_data['statusid'])) $data['status_id'] = $ais_data['statusid']; |
|
535 | - if (isset($ais_data['type'])) $data['type'] = $ais_data['type']; |
|
536 | - if (isset($ais_data['typeid'])) $data['type_id'] = $ais_data['typeid']; |
|
537 | - if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo']; |
|
538 | - if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign']; |
|
539 | - if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination']; |
|
540 | - if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']); |
|
712 | + if (isset($ais_data['ident'])) { |
|
713 | + $data['ident'] = $ais_data['ident']; |
|
714 | + } |
|
715 | + if (isset($ais_data['mmsi'])) { |
|
716 | + $data['mmsi'] = substr($ais_data['mmsi'],-9); |
|
717 | + } |
|
718 | + if (isset($ais_data['speed'])) { |
|
719 | + $data['speed'] = $ais_data['speed']; |
|
720 | + } |
|
721 | + if (isset($ais_data['heading'])) { |
|
722 | + $data['heading'] = $ais_data['heading']; |
|
723 | + } |
|
724 | + if (isset($ais_data['latitude'])) { |
|
725 | + $data['latitude'] = $ais_data['latitude']; |
|
726 | + } |
|
727 | + if (isset($ais_data['longitude'])) { |
|
728 | + $data['longitude'] = $ais_data['longitude']; |
|
729 | + } |
|
730 | + if (isset($ais_data['status'])) { |
|
731 | + $data['status'] = $ais_data['status']; |
|
732 | + } |
|
733 | + if (isset($ais_data['statusid'])) { |
|
734 | + $data['status_id'] = $ais_data['statusid']; |
|
735 | + } |
|
736 | + if (isset($ais_data['type'])) { |
|
737 | + $data['type'] = $ais_data['type']; |
|
738 | + } |
|
739 | + if (isset($ais_data['typeid'])) { |
|
740 | + $data['type_id'] = $ais_data['typeid']; |
|
741 | + } |
|
742 | + if (isset($ais_data['imo'])) { |
|
743 | + $data['imo'] = $ais_data['imo']; |
|
744 | + } |
|
745 | + if (isset($ais_data['callsign'])) { |
|
746 | + $data['callsign'] = $ais_data['callsign']; |
|
747 | + } |
|
748 | + if (isset($ais_data['destination'])) { |
|
749 | + $data['arrival_code'] = $ais_data['destination']; |
|
750 | + } |
|
751 | + if (isset($ais_data['eta_ts'])) { |
|
752 | + $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']); |
|
753 | + } |
|
541 | 754 | if (isset($ais_data['timestamp'])) { |
542 | 755 | $data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']); |
543 | 756 | } else { |
@@ -545,18 +758,27 @@ discard block |
||
545 | 758 | } |
546 | 759 | $data['format_source'] = 'aisnmeahttp'; |
547 | 760 | $data['id_source'] = $id_source; |
548 | - if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true; |
|
549 | - if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') $MI->add($data); |
|
761 | + if (isset($value['noarchive']) && $value['noarchive'] === TRUE) { |
|
762 | + $data['noarchive'] = true; |
|
763 | + } |
|
764 | + if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') { |
|
765 | + $MI->add($data); |
|
766 | + } |
|
550 | 767 | unset($data); |
551 | 768 | } |
552 | 769 | } |
553 | 770 | } |
554 | 771 | } else { |
555 | 772 | $format = $value['format']; |
556 | - if (isset($tt[$format])) $tt[$format]++; |
|
557 | - else $tt[$format] = 0; |
|
773 | + if (isset($tt[$format])) { |
|
774 | + $tt[$format]++; |
|
775 | + } else { |
|
776 | + $tt[$format] = 0; |
|
777 | + } |
|
558 | 778 | if ($tt[$format] > 30) { |
559 | - if ($globalDebug) echo 'Reconnect...'."\n"; |
|
779 | + if ($globalDebug) { |
|
780 | + echo 'Reconnect...'."\n"; |
|
781 | + } |
|
560 | 782 | sleep(2); |
561 | 783 | //$sourceeen[] = $value; |
562 | 784 | //connect_all($sourceeen); |
@@ -592,12 +814,18 @@ discard block |
||
592 | 814 | // if (isset($ais_data['type'])) $data['type'] = $ais_data['type']; |
593 | 815 | //$data['type_id'] = $line['TYPE']; |
594 | 816 | $data['imo'] = $line['IMO']; |
595 | - if ($line['DEST'] != '') $data['arrival_code'] = $line['DEST']; |
|
596 | - if ($line['ARV'] != '') $data['arrival_time'] = date('Y-m-d H:i:s',strtotime($line['ARV'])); |
|
817 | + if ($line['DEST'] != '') { |
|
818 | + $data['arrival_code'] = $line['DEST']; |
|
819 | + } |
|
820 | + if ($line['ARV'] != '') { |
|
821 | + $data['arrival_time'] = date('Y-m-d H:i:s',strtotime($line['ARV'])); |
|
822 | + } |
|
597 | 823 | $data['datetime'] = date('Y-m-d H:i:s',$line['T']); |
598 | 824 | $data['format_source'] = 'myshiptracking'; |
599 | 825 | $data['id_source'] = $id_source; |
600 | - if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true; |
|
826 | + if (isset($value['noarchive']) && $value['noarchive'] === TRUE) { |
|
827 | + $data['noarchive'] = true; |
|
828 | + } |
|
601 | 829 | $MI->add($data); |
602 | 830 | unset($data); |
603 | 831 | } |
@@ -622,7 +850,9 @@ discard block |
||
622 | 850 | $data['callsign'] = $line['callsign']; |
623 | 851 | $data['mmsi'] = substr($line['mmsi'],-9); |
624 | 852 | $data['speed'] = $line['sog']; |
625 | - if ($line['heading'] != '511') $data['heading'] = $line['heading']; |
|
853 | + if ($line['heading'] != '511') { |
|
854 | + $data['heading'] = $line['heading']; |
|
855 | + } |
|
626 | 856 | $data['latitude'] = $line['latitude']; |
627 | 857 | $data['longitude'] = $line['longitude']; |
628 | 858 | $data['type_id'] = $line['shiptype']; |
@@ -630,7 +860,9 @@ discard block |
||
630 | 860 | $data['datetime'] = $line['time']; |
631 | 861 | $data['format_source'] = 'boatbeaconapp'; |
632 | 862 | $data['id_source'] = $id_source; |
633 | - if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true; |
|
863 | + if (isset($value['noarchive']) && $value['noarchive'] === TRUE) { |
|
864 | + $data['noarchive'] = true; |
|
865 | + } |
|
634 | 866 | $MI->add($data); |
635 | 867 | unset($data); |
636 | 868 | } |
@@ -652,22 +884,44 @@ discard block |
||
652 | 884 | foreach ($all_data['features'] as $line) { |
653 | 885 | print_r($line); |
654 | 886 | $data = array(); |
655 | - if (isset($line['properties']['name'])) $data['ident'] = $line['properties']['name']; |
|
656 | - if (isset($line['properties']['callsign'])) $data['callsign'] = $line['properties']['callsign']; |
|
657 | - if (isset($line['properties']['mmsi'])) $data['mmsi'] = substr($line['properties']['mmsi'],-9); |
|
658 | - if (isset($line['properties']['imo'])) $data['imo'] = $line['properties']['imo']; |
|
659 | - if (isset($line['properties']['speed'])) $data['speed'] = $line['properties']['speed']; |
|
660 | - if (isset($line['properties']['heading']) && $line['properties']['heading'] != 0) $data['heading'] = $line['properties']['heading']; |
|
887 | + if (isset($line['properties']['name'])) { |
|
888 | + $data['ident'] = $line['properties']['name']; |
|
889 | + } |
|
890 | + if (isset($line['properties']['callsign'])) { |
|
891 | + $data['callsign'] = $line['properties']['callsign']; |
|
892 | + } |
|
893 | + if (isset($line['properties']['mmsi'])) { |
|
894 | + $data['mmsi'] = substr($line['properties']['mmsi'],-9); |
|
895 | + } |
|
896 | + if (isset($line['properties']['imo'])) { |
|
897 | + $data['imo'] = $line['properties']['imo']; |
|
898 | + } |
|
899 | + if (isset($line['properties']['speed'])) { |
|
900 | + $data['speed'] = $line['properties']['speed']; |
|
901 | + } |
|
902 | + if (isset($line['properties']['heading']) && $line['properties']['heading'] != 0) { |
|
903 | + $data['heading'] = $line['properties']['heading']; |
|
904 | + } |
|
661 | 905 | $data['latitude'] = $line['geometry']['coordinates'][1]; |
662 | 906 | $data['longitude'] = $line['geometry']['coordinates'][0]; |
663 | - if (isset($line['properties']['vesselType'])) $data['type'] = $line['properties']['vesselType']; |
|
664 | - if (isset($line['properties']['destination'])) $data['arrival_code'] = $line['properties']['destination']; |
|
665 | - if (isset($line['properties']['eta']) && $line['properties']['eta'] != '') $data['arrival_date'] = $line['properties']['eta']; |
|
907 | + if (isset($line['properties']['vesselType'])) { |
|
908 | + $data['type'] = $line['properties']['vesselType']; |
|
909 | + } |
|
910 | + if (isset($line['properties']['destination'])) { |
|
911 | + $data['arrival_code'] = $line['properties']['destination']; |
|
912 | + } |
|
913 | + if (isset($line['properties']['eta']) && $line['properties']['eta'] != '') { |
|
914 | + $data['arrival_date'] = $line['properties']['eta']; |
|
915 | + } |
|
666 | 916 | $data['format_source'] = 'boatnerd'; |
667 | 917 | $data['id_source'] = $id_source; |
668 | 918 | $data['datetime'] = date('Y-m-d H:i:s'); |
669 | - if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true; |
|
670 | - if ($line['properties']['vesselType'] != 'Navigation Aid') $MI->add($data); |
|
919 | + if (isset($value['noarchive']) && $value['noarchive'] === TRUE) { |
|
920 | + $data['noarchive'] = true; |
|
921 | + } |
|
922 | + if ($line['properties']['vesselType'] != 'Navigation Aid') { |
|
923 | + $MI->add($data); |
|
924 | + } |
|
671 | 925 | unset($data); |
672 | 926 | } |
673 | 927 | } |
@@ -684,7 +938,9 @@ discard block |
||
684 | 938 | $buffer = $Common->getData($value['host'],'post',$value['post'],'','','','','ShipPlotter'); |
685 | 939 | echo 'done !'."\n"; |
686 | 940 | // FIXME: Need more work |
687 | - if ($buffer != '') $reset = 0; |
|
941 | + if ($buffer != '') { |
|
942 | + $reset = 0; |
|
943 | + } |
|
688 | 944 | $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'\n',$buffer)); |
689 | 945 | $buffer = explode('\n',$buffer); |
690 | 946 | foreach ($buffer as $line) { |
@@ -710,7 +966,9 @@ discard block |
||
710 | 966 | //$data['etaTime'] = substr($line,135,5); |
711 | 967 | $data['format_source'] = 'shipplotter'; |
712 | 968 | $data['id_source'] = $id_source; |
713 | - if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true; |
|
969 | + if (isset($value['noarchive']) && $value['noarchive'] === TRUE) { |
|
970 | + $data['noarchive'] = true; |
|
971 | + } |
|
714 | 972 | //print_r($data); |
715 | 973 | echo 'Add...'."\n"; |
716 | 974 | $MI->add($data); |
@@ -744,16 +1002,28 @@ discard block |
||
744 | 1002 | $line = explode(':', $line); |
745 | 1003 | if (count($line) > 30 && $line[0] != 'callsign') { |
746 | 1004 | $data = array(); |
747 | - if (isset($line[37]) && $line[37] != '') $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0].'-'.$line[37]; |
|
748 | - else $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0]; |
|
1005 | + if (isset($line[37]) && $line[37] != '') { |
|
1006 | + $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0].'-'.$line[37]; |
|
1007 | + } else { |
|
1008 | + $data['id'] = $value['format'].'-'.$line[1].'-'.$line[0]; |
|
1009 | + } |
|
749 | 1010 | $data['pilot_id'] = $line[1]; |
750 | 1011 | $data['pilot_name'] = $line[2]; |
751 | 1012 | $data['hex'] = str_pad(dechex($Common->str2int($line[1])),6,'000000',STR_PAD_LEFT); |
752 | 1013 | $data['ident'] = $line[0]; // ident |
753 | - if ($line[7] != '' && $line[7] != 0) $data['altitude'] = $line[7]; // altitude |
|
1014 | + if ($line[7] != '' && $line[7] != 0) { |
|
1015 | + $data['altitude'] = $line[7]; |
|
1016 | + } |
|
1017 | + // altitude |
|
754 | 1018 | $data['speed'] = $line[8]; // speed |
755 | - if (isset($line[45])) $data['heading'] = $line[45]; // heading |
|
756 | - elseif (isset($line[38])) $data['heading'] = $line[38]; // heading |
|
1019 | + if (isset($line[45])) { |
|
1020 | + $data['heading'] = $line[45]; |
|
1021 | + } |
|
1022 | + // heading |
|
1023 | + elseif (isset($line[38])) { |
|
1024 | + $data['heading'] = $line[38]; |
|
1025 | + } |
|
1026 | + // heading |
|
757 | 1027 | $data['latitude'] = $line[5]; // lat |
758 | 1028 | $data['longitude'] = $line[6]; // long |
759 | 1029 | $data['verticalrate'] = ''; // vertical rate |
@@ -769,7 +1039,9 @@ discard block |
||
769 | 1039 | $data['frequency'] = $line[4]; |
770 | 1040 | $data['type'] = $line[18]; |
771 | 1041 | $data['range'] = $line[19]; |
772 | - if (isset($line[35])) $data['info'] = $line[35]; |
|
1042 | + if (isset($line[35])) { |
|
1043 | + $data['info'] = $line[35]; |
|
1044 | + } |
|
773 | 1045 | $data['id_source'] = $id_source; |
774 | 1046 | //$data['arrival_airport_time'] = ; |
775 | 1047 | if ($line[9] != '') { |
@@ -783,27 +1055,47 @@ discard block |
||
783 | 1055 | elseif ($value == 'vatsimtxt') $data['format_source'] = 'vatsimtxt'; |
784 | 1056 | */ |
785 | 1057 | $data['format_source'] = $value['format']; |
786 | - if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true; |
|
787 | - if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name']; |
|
788 | - if ($line[3] == 'PILOT') $SI->add($data); |
|
789 | - elseif ($line[3] == 'ATC') { |
|
1058 | + if (isset($value['noarchive']) && $value['noarchive'] === TRUE) { |
|
1059 | + $data['noarchive'] = true; |
|
1060 | + } |
|
1061 | + if (isset($value['name']) && $value['name'] != '') { |
|
1062 | + $data['source_name'] = $value['name']; |
|
1063 | + } |
|
1064 | + if ($line[3] == 'PILOT') { |
|
1065 | + $SI->add($data); |
|
1066 | + } elseif ($line[3] == 'ATC') { |
|
790 | 1067 | //print_r($data); |
791 | 1068 | $data['info'] = str_replace('^§','<br />',$data['info']); |
792 | 1069 | $data['info'] = str_replace('&sect;','',$data['info']); |
793 | 1070 | $typec = substr($data['ident'],-3); |
794 | - if ($typec == 'APP') $data['type'] = 'Approach'; |
|
795 | - elseif ($typec == 'TWR') $data['type'] = 'Tower'; |
|
796 | - elseif ($typec == 'OBS') $data['type'] = 'Observer'; |
|
797 | - elseif ($typec == 'GND') $data['type'] = 'Ground'; |
|
798 | - elseif ($typec == 'DEL') $data['type'] = 'Delivery'; |
|
799 | - elseif ($typec == 'DEP') $data['type'] = 'Departure'; |
|
800 | - elseif ($typec == 'FSS') $data['type'] = 'Flight Service Station'; |
|
801 | - elseif ($typec == 'CTR') $data['type'] = 'Control Radar or Centre'; |
|
802 | - elseif ($data['type'] == '') $data['type'] = 'Observer'; |
|
803 | - if (!isset($data['source_name'])) $data['source_name'] = ''; |
|
1071 | + if ($typec == 'APP') { |
|
1072 | + $data['type'] = 'Approach'; |
|
1073 | + } elseif ($typec == 'TWR') { |
|
1074 | + $data['type'] = 'Tower'; |
|
1075 | + } elseif ($typec == 'OBS') { |
|
1076 | + $data['type'] = 'Observer'; |
|
1077 | + } elseif ($typec == 'GND') { |
|
1078 | + $data['type'] = 'Ground'; |
|
1079 | + } elseif ($typec == 'DEL') { |
|
1080 | + $data['type'] = 'Delivery'; |
|
1081 | + } elseif ($typec == 'DEP') { |
|
1082 | + $data['type'] = 'Departure'; |
|
1083 | + } elseif ($typec == 'FSS') { |
|
1084 | + $data['type'] = 'Flight Service Station'; |
|
1085 | + } elseif ($typec == 'CTR') { |
|
1086 | + $data['type'] = 'Control Radar or Centre'; |
|
1087 | + } elseif ($data['type'] == '') { |
|
1088 | + $data['type'] = 'Observer'; |
|
1089 | + } |
|
1090 | + if (!isset($data['source_name'])) { |
|
1091 | + $data['source_name'] = ''; |
|
1092 | + } |
|
804 | 1093 | if (isset($ATC)) { |
805 | - if (count($ATC->getByIdent($data['ident'],$data['format_source'])) > 0) echo $ATC->update($data['ident'],$data['frequency'],$data['latitude'],$data['longitude'],$data['range'],$data['info'],$data['datetime'],$data['type'],$data['pilot_id'],$data['pilot_name'],$data['format_source'],$data['source_name']); |
|
806 | - else echo $ATC->add($data['ident'],$data['frequency'],$data['latitude'],$data['longitude'],$data['range'],$data['info'],$data['datetime'],$data['type'],$data['pilot_id'],$data['pilot_name'],$data['format_source'],$data['source_name']); |
|
1094 | + if (count($ATC->getByIdent($data['ident'],$data['format_source'])) > 0) { |
|
1095 | + echo $ATC->update($data['ident'],$data['frequency'],$data['latitude'],$data['longitude'],$data['range'],$data['info'],$data['datetime'],$data['type'],$data['pilot_id'],$data['pilot_name'],$data['format_source'],$data['source_name']); |
|
1096 | + } else { |
|
1097 | + echo $ATC->add($data['ident'],$data['frequency'],$data['latitude'],$data['longitude'],$data['range'],$data['info'],$data['datetime'],$data['type'],$data['pilot_id'],$data['pilot_name'],$data['format_source'],$data['source_name']); |
|
1098 | + } |
|
807 | 1099 | } |
808 | 1100 | } |
809 | 1101 | unset($data); |
@@ -830,14 +1122,20 @@ discard block |
||
830 | 1122 | $data['datetime'] = date('Y-m-d H:i:s',strtotime((string)$line['entryTime'].' BST')); |
831 | 1123 | $data['latitude'] = (float)$line['pktLatitude']; |
832 | 1124 | $data['longitude'] = (float)$line['pktLongitude']; |
833 | - if ((float)$line['pktTrack'] != 0) $data['heading'] = (float)$line['pktTrack']; |
|
834 | - if ((int)$line['pktSpeed'] != 0) $data['speed'] = (int)$line['pktSpeed']; |
|
1125 | + if ((float)$line['pktTrack'] != 0) { |
|
1126 | + $data['heading'] = (float)$line['pktTrack']; |
|
1127 | + } |
|
1128 | + if ((int)$line['pktSpeed'] != 0) { |
|
1129 | + $data['speed'] = (int)$line['pktSpeed']; |
|
1130 | + } |
|
835 | 1131 | $data['altitude'] = round((int)$line['pktAltitude']*3.28084); |
836 | 1132 | $data['altitude_relative'] = 'AMSL'; |
837 | 1133 | $data['pilot_id'] = (int)$line['pktPilotID']; |
838 | 1134 | $data['aircraft_icao'] = 'PARAGLIDER'; |
839 | 1135 | $pilot_data = explode(',',$Common->getData('http://www.airwhere.co.uk/pilotdetails.php?pilot='.$data['pilot_id'])); |
840 | - if (isset($pilot_data[4])) $data['pilot_name'] = $pilot_data[4]; |
|
1136 | + if (isset($pilot_data[4])) { |
|
1137 | + $data['pilot_name'] = $pilot_data[4]; |
|
1138 | + } |
|
841 | 1139 | $data['format_source'] = $value['format']; |
842 | 1140 | $SI->add($data); |
843 | 1141 | unset($data); |
@@ -885,25 +1183,59 @@ discard block |
||
885 | 1183 | foreach ($all_data['acList'] as $line) { |
886 | 1184 | $data = array(); |
887 | 1185 | $data['hex'] = $line['Icao']; // hex |
888 | - if (isset($line['Call'])) $data['ident'] = $line['Call']; // ident |
|
889 | - if (isset($line['Alt'])) $data['altitude'] = $line['Alt']; // altitude |
|
890 | - if (isset($line['Spd'])) $data['speed'] = $line['Spd']; // speed |
|
891 | - if (isset($line['Trak'])) $data['heading'] = $line['Trak']; // heading |
|
892 | - if (isset($line['Lat'])) $data['latitude'] = $line['Lat']; // lat |
|
893 | - if (isset($line['Long'])) $data['longitude'] = $line['Long']; // long |
|
1186 | + if (isset($line['Call'])) { |
|
1187 | + $data['ident'] = $line['Call']; |
|
1188 | + } |
|
1189 | + // ident |
|
1190 | + if (isset($line['Alt'])) { |
|
1191 | + $data['altitude'] = $line['Alt']; |
|
1192 | + } |
|
1193 | + // altitude |
|
1194 | + if (isset($line['Spd'])) { |
|
1195 | + $data['speed'] = $line['Spd']; |
|
1196 | + } |
|
1197 | + // speed |
|
1198 | + if (isset($line['Trak'])) { |
|
1199 | + $data['heading'] = $line['Trak']; |
|
1200 | + } |
|
1201 | + // heading |
|
1202 | + if (isset($line['Lat'])) { |
|
1203 | + $data['latitude'] = $line['Lat']; |
|
1204 | + } |
|
1205 | + // lat |
|
1206 | + if (isset($line['Long'])) { |
|
1207 | + $data['longitude'] = $line['Long']; |
|
1208 | + } |
|
1209 | + // long |
|
894 | 1210 | //$data['verticalrate'] = $line['']; // verticale rate |
895 | - if (isset($line['Sqk'])) $data['squawk'] = $line['Sqk']; // squawk |
|
1211 | + if (isset($line['Sqk'])) { |
|
1212 | + $data['squawk'] = $line['Sqk']; |
|
1213 | + } |
|
1214 | + // squawk |
|
896 | 1215 | $data['emergency'] = ''; // emergency |
897 | - if (isset($line['Reg'])) $data['registration'] = $line['Reg']; |
|
898 | - if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s',round($line['PosTime']/1000)); |
|
899 | - else $data['datetime'] = date('Y-m-d H:i:s'); |
|
1216 | + if (isset($line['Reg'])) { |
|
1217 | + $data['registration'] = $line['Reg']; |
|
1218 | + } |
|
1219 | + if (isset($line['PosTime'])) { |
|
1220 | + $data['datetime'] = date('Y-m-d H:i:s',round($line['PosTime']/1000)); |
|
1221 | + } else { |
|
1222 | + $data['datetime'] = date('Y-m-d H:i:s'); |
|
1223 | + } |
|
900 | 1224 | //$data['datetime'] = date('Y-m-d H:i:s'); |
901 | - if (isset($line['Type'])) $data['aircraft_icao'] = $line['Type']; |
|
1225 | + if (isset($line['Type'])) { |
|
1226 | + $data['aircraft_icao'] = $line['Type']; |
|
1227 | + } |
|
902 | 1228 | $data['format_source'] = 'aircraftlistjson'; |
903 | 1229 | $data['id_source'] = $id_source; |
904 | - if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name']; |
|
905 | - if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true; |
|
906 | - if (isset($data['latitude'])) $SI->add($data); |
|
1230 | + if (isset($value['name']) && $value['name'] != '') { |
|
1231 | + $data['source_name'] = $value['name']; |
|
1232 | + } |
|
1233 | + if (isset($value['noarchive']) && $value['noarchive'] === TRUE) { |
|
1234 | + $data['noarchive'] = true; |
|
1235 | + } |
|
1236 | + if (isset($data['latitude'])) { |
|
1237 | + $SI->add($data); |
|
1238 | + } |
|
907 | 1239 | unset($data); |
908 | 1240 | } |
909 | 1241 | } elseif (is_array($all_data)) { |
@@ -920,17 +1252,26 @@ discard block |
||
920 | 1252 | $data['verticalrate'] = $line['vrt']; // verticale rate |
921 | 1253 | $data['squawk'] = $line['squawk']; // squawk |
922 | 1254 | $data['emergency'] = ''; // emergency |
923 | - if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s',round($line['PosTime']/1000)); |
|
924 | - else $data['datetime'] = date('Y-m-d H:i:s'); |
|
1255 | + if (isset($line['PosTime'])) { |
|
1256 | + $data['datetime'] = date('Y-m-d H:i:s',round($line['PosTime']/1000)); |
|
1257 | + } else { |
|
1258 | + $data['datetime'] = date('Y-m-d H:i:s'); |
|
1259 | + } |
|
925 | 1260 | $data['format_source'] = 'aircraftlistjson'; |
926 | 1261 | $data['id_source'] = $id_source; |
927 | - if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true; |
|
928 | - if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name']; |
|
1262 | + if (isset($value['noarchive']) && $value['noarchive'] === TRUE) { |
|
1263 | + $data['noarchive'] = true; |
|
1264 | + } |
|
1265 | + if (isset($value['name']) && $value['name'] != '') { |
|
1266 | + $data['source_name'] = $value['name']; |
|
1267 | + } |
|
929 | 1268 | $SI->add($data); |
930 | 1269 | unset($data); |
931 | 1270 | } |
932 | 1271 | } |
933 | - } elseif ($globalDebug) echo 'No data'."\n"; |
|
1272 | + } elseif ($globalDebug) { |
|
1273 | + echo 'No data'."\n"; |
|
1274 | + } |
|
934 | 1275 | //$last_exec['aircraftlistjson'] = time(); |
935 | 1276 | $last_exec[$id]['last'] = time(); |
936 | 1277 | //} elseif ($value == 'planeupdatefaa' && (time() - $last_exec['planeupdatefaa'] > $globalMinFetch)) { |
@@ -966,8 +1307,12 @@ discard block |
||
966 | 1307 | $data['datetime'] = date('Y-m-d H:i:s',$line[9]); |
967 | 1308 | $data['format_source'] = 'planeupdatefaa'; |
968 | 1309 | $data['id_source'] = $id_source; |
969 | - if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true; |
|
970 | - if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name']; |
|
1310 | + if (isset($value['noarchive']) && $value['noarchive'] === TRUE) { |
|
1311 | + $data['noarchive'] = true; |
|
1312 | + } |
|
1313 | + if (isset($value['name']) && $value['name'] != '') { |
|
1314 | + $data['source_name'] = $value['name']; |
|
1315 | + } |
|
971 | 1316 | $SI->add($data); |
972 | 1317 | unset($data); |
973 | 1318 | } |
@@ -1001,7 +1346,9 @@ discard block |
||
1001 | 1346 | $data['datetime'] = date('Y-m-d H:i:s',$line[3]); |
1002 | 1347 | $data['format_source'] = 'opensky'; |
1003 | 1348 | $data['id_source'] = $id_source; |
1004 | - if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true; |
|
1349 | + if (isset($value['noarchive']) && $value['noarchive'] === TRUE) { |
|
1350 | + $data['noarchive'] = true; |
|
1351 | + } |
|
1005 | 1352 | $SI->add($data); |
1006 | 1353 | unset($data); |
1007 | 1354 | } |
@@ -1018,7 +1365,9 @@ discard block |
||
1018 | 1365 | //$buffer = $Common->getData($hosts[$id]); |
1019 | 1366 | $buffer = $Common->getData($value['host']); |
1020 | 1367 | $all_data = json_decode($buffer,true); |
1021 | - if (!empty($all_data)) $reset = 0; |
|
1368 | + if (!empty($all_data)) { |
|
1369 | + $reset = 0; |
|
1370 | + } |
|
1022 | 1371 | foreach ($all_data as $key => $line) { |
1023 | 1372 | if ($key != 'full_count' && $key != 'version' && $key != 'stats') { |
1024 | 1373 | $data = array(); |
@@ -1039,8 +1388,12 @@ discard block |
||
1039 | 1388 | $data['datetime'] = date('Y-m-d H:i:s'); //$line[10] |
1040 | 1389 | $data['format_source'] = 'fr24json'; |
1041 | 1390 | $data['id_source'] = $id_source; |
1042 | - if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true; |
|
1043 | - if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name']; |
|
1391 | + if (isset($value['noarchive']) && $value['noarchive'] === TRUE) { |
|
1392 | + $data['noarchive'] = true; |
|
1393 | + } |
|
1394 | + if (isset($value['name']) && $value['name'] != '') { |
|
1395 | + $data['source_name'] = $value['name']; |
|
1396 | + } |
|
1044 | 1397 | $SI->add($data); |
1045 | 1398 | unset($data); |
1046 | 1399 | } |
@@ -1069,24 +1422,42 @@ discard block |
||
1069 | 1422 | if (isset($line['inf'])) { |
1070 | 1423 | $data = array(); |
1071 | 1424 | $data['hex'] = $line['inf']['ia']; |
1072 | - if (isset($line['inf']['cs'])) $data['ident'] = $line['inf']['cs']; //$line[13] |
|
1425 | + if (isset($line['inf']['cs'])) { |
|
1426 | + $data['ident'] = $line['inf']['cs']; |
|
1427 | + } |
|
1428 | + //$line[13] |
|
1073 | 1429 | $data['altitude'] = round($line['inf']['al']*3.28084); // altitude |
1074 | - if (isset($line['inf']['gs'])) $data['speed'] = round($line['inf']['gs']*0.539957); // speed |
|
1075 | - if (isset($line['inf']['tr'])) $data['heading'] = $line['inf']['tr']; // heading |
|
1430 | + if (isset($line['inf']['gs'])) { |
|
1431 | + $data['speed'] = round($line['inf']['gs']*0.539957); |
|
1432 | + } |
|
1433 | + // speed |
|
1434 | + if (isset($line['inf']['tr'])) { |
|
1435 | + $data['heading'] = $line['inf']['tr']; |
|
1436 | + } |
|
1437 | + // heading |
|
1076 | 1438 | $data['latitude'] = $line['pt'][0]; // lat |
1077 | 1439 | $data['longitude'] = $line['pt'][1]; // long |
1078 | 1440 | //if (isset($line['inf']['vs'])) $data['verticalrate'] = $line['inf']['vs']; // verticale rate |
1079 | - if (isset($line['inf']['sq'])) $data['squawk'] = $line['inf']['sq']; // squawk |
|
1441 | + if (isset($line['inf']['sq'])) { |
|
1442 | + $data['squawk'] = $line['inf']['sq']; |
|
1443 | + } |
|
1444 | + // squawk |
|
1080 | 1445 | //$data['aircraft_icao'] = $line[8]; |
1081 | - if (isset($line['inf']['rc'])) $data['registration'] = $line['inf']['rc']; |
|
1446 | + if (isset($line['inf']['rc'])) { |
|
1447 | + $data['registration'] = $line['inf']['rc']; |
|
1448 | + } |
|
1082 | 1449 | //$data['departure_airport_iata'] = $line[11]; |
1083 | 1450 | //$data['arrival_airport_iata'] = $line[12]; |
1084 | 1451 | //$data['emergency'] = ''; // emergency |
1085 | 1452 | $data['datetime'] = date('Y-m-d H:i:s',$line['inf']['dt']); //$line[10] |
1086 | 1453 | $data['format_source'] = 'radarvirtueljson'; |
1087 | 1454 | $data['id_source'] = $id_source; |
1088 | - if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true; |
|
1089 | - if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name']; |
|
1455 | + if (isset($value['noarchive']) && $value['noarchive'] === TRUE) { |
|
1456 | + $data['noarchive'] = true; |
|
1457 | + } |
|
1458 | + if (isset($value['name']) && $value['name'] != '') { |
|
1459 | + $data['source_name'] = $value['name']; |
|
1460 | + } |
|
1090 | 1461 | $SI->add($data); |
1091 | 1462 | unset($data); |
1092 | 1463 | } |
@@ -1112,30 +1483,65 @@ discard block |
||
1112 | 1483 | $data['id'] = $line['id']; |
1113 | 1484 | $data['hex'] = substr(str_pad(dechex($line['id']),6,'000000',STR_PAD_LEFT),0,6); |
1114 | 1485 | $data['ident'] = $line['callsign']; // ident |
1115 | - if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; // pilot id |
|
1116 | - if (isset($line['name'])) $data['pilot_name'] = $line['name']; // pilot name |
|
1117 | - if (isset($line['alt'])) $data['altitude'] = $line['alt']; // altitude |
|
1118 | - if (isset($line['gs'])) $data['speed'] = $line['gs']; // speed |
|
1119 | - if (isset($line['heading'])) $data['heading'] = $line['heading']; // heading |
|
1120 | - if (isset($line['route'])) $data['waypoints'] = $line['route']; // route |
|
1486 | + if (isset($line['pilotid'])) { |
|
1487 | + $data['pilot_id'] = $line['pilotid']; |
|
1488 | + } |
|
1489 | + // pilot id |
|
1490 | + if (isset($line['name'])) { |
|
1491 | + $data['pilot_name'] = $line['name']; |
|
1492 | + } |
|
1493 | + // pilot name |
|
1494 | + if (isset($line['alt'])) { |
|
1495 | + $data['altitude'] = $line['alt']; |
|
1496 | + } |
|
1497 | + // altitude |
|
1498 | + if (isset($line['gs'])) { |
|
1499 | + $data['speed'] = $line['gs']; |
|
1500 | + } |
|
1501 | + // speed |
|
1502 | + if (isset($line['heading'])) { |
|
1503 | + $data['heading'] = $line['heading']; |
|
1504 | + } |
|
1505 | + // heading |
|
1506 | + if (isset($line['route'])) { |
|
1507 | + $data['waypoints'] = $line['route']; |
|
1508 | + } |
|
1509 | + // route |
|
1121 | 1510 | $data['latitude'] = $line['lat']; // lat |
1122 | 1511 | $data['longitude'] = $line['lon']; // long |
1123 | 1512 | //$data['verticalrate'] = $line['vrt']; // verticale rate |
1124 | 1513 | //$data['squawk'] = $line['squawk']; // squawk |
1125 | 1514 | //$data['emergency'] = ''; // emergency |
1126 | - if (isset($line['depicao'])) $data['departure_airport_icao'] = $line['depicao']; |
|
1127 | - if (isset($line['deptime'])) $data['departure_airport_time'] = $line['deptime']; |
|
1128 | - if (isset($line['arricao'])) $data['arrival_airport_icao'] = $line['arricao']; |
|
1515 | + if (isset($line['depicao'])) { |
|
1516 | + $data['departure_airport_icao'] = $line['depicao']; |
|
1517 | + } |
|
1518 | + if (isset($line['deptime'])) { |
|
1519 | + $data['departure_airport_time'] = $line['deptime']; |
|
1520 | + } |
|
1521 | + if (isset($line['arricao'])) { |
|
1522 | + $data['arrival_airport_icao'] = $line['arricao']; |
|
1523 | + } |
|
1129 | 1524 | //$data['arrival_airport_time'] = $line['arrtime']; |
1130 | - if (isset($line['aircraft'])) $data['aircraft_icao'] = $line['aircraft']; |
|
1131 | - if (isset($line['transponder'])) $data['squawk'] = $line['transponder']; |
|
1132 | - if (isset($line['atis'])) $data['info'] = $line['atis']; |
|
1133 | - else $data['info'] = ''; |
|
1525 | + if (isset($line['aircraft'])) { |
|
1526 | + $data['aircraft_icao'] = $line['aircraft']; |
|
1527 | + } |
|
1528 | + if (isset($line['transponder'])) { |
|
1529 | + $data['squawk'] = $line['transponder']; |
|
1530 | + } |
|
1531 | + if (isset($line['atis'])) { |
|
1532 | + $data['info'] = $line['atis']; |
|
1533 | + } else { |
|
1534 | + $data['info'] = ''; |
|
1535 | + } |
|
1134 | 1536 | $data['format_source'] = 'pireps'; |
1135 | 1537 | $data['id_source'] = $id_source; |
1136 | 1538 | $data['datetime'] = date('Y-m-d H:i:s'); |
1137 | - if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true; |
|
1138 | - if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name']; |
|
1539 | + if (isset($value['noarchive']) && $value['noarchive'] === TRUE) { |
|
1540 | + $data['noarchive'] = true; |
|
1541 | + } |
|
1542 | + if (isset($value['name']) && $value['name'] != '') { |
|
1543 | + $data['source_name'] = $value['name']; |
|
1544 | + } |
|
1139 | 1545 | if ($line['icon'] == 'plane') { |
1140 | 1546 | $SI->add($data); |
1141 | 1547 | // print_r($data); |
@@ -1144,16 +1550,28 @@ discard block |
||
1144 | 1550 | $data['info'] = str_replace('&sect;','',$data['info']); |
1145 | 1551 | $typec = substr($data['ident'],-3); |
1146 | 1552 | $data['type'] = ''; |
1147 | - if ($typec == 'APP') $data['type'] = 'Approach'; |
|
1148 | - elseif ($typec == 'TWR') $data['type'] = 'Tower'; |
|
1149 | - elseif ($typec == 'OBS') $data['type'] = 'Observer'; |
|
1150 | - elseif ($typec == 'GND') $data['type'] = 'Ground'; |
|
1151 | - elseif ($typec == 'DEL') $data['type'] = 'Delivery'; |
|
1152 | - elseif ($typec == 'DEP') $data['type'] = 'Departure'; |
|
1153 | - elseif ($typec == 'FSS') $data['type'] = 'Flight Service Station'; |
|
1154 | - elseif ($typec == 'CTR') $data['type'] = 'Control Radar or Centre'; |
|
1155 | - else $data['type'] = 'Observer'; |
|
1156 | - if (isset($ATC)) echo $ATC->add($data['ident'],'',$data['latitude'],$data['longitude'],'0',$data['info'],$data['datetime'],$data['type'],$data['pilot_id'],$data['pilot_name'],$data['format_source']); |
|
1553 | + if ($typec == 'APP') { |
|
1554 | + $data['type'] = 'Approach'; |
|
1555 | + } elseif ($typec == 'TWR') { |
|
1556 | + $data['type'] = 'Tower'; |
|
1557 | + } elseif ($typec == 'OBS') { |
|
1558 | + $data['type'] = 'Observer'; |
|
1559 | + } elseif ($typec == 'GND') { |
|
1560 | + $data['type'] = 'Ground'; |
|
1561 | + } elseif ($typec == 'DEL') { |
|
1562 | + $data['type'] = 'Delivery'; |
|
1563 | + } elseif ($typec == 'DEP') { |
|
1564 | + $data['type'] = 'Departure'; |
|
1565 | + } elseif ($typec == 'FSS') { |
|
1566 | + $data['type'] = 'Flight Service Station'; |
|
1567 | + } elseif ($typec == 'CTR') { |
|
1568 | + $data['type'] = 'Control Radar or Centre'; |
|
1569 | + } else { |
|
1570 | + $data['type'] = 'Observer'; |
|
1571 | + } |
|
1572 | + if (isset($ATC)) { |
|
1573 | + echo $ATC->add($data['ident'],'',$data['latitude'],$data['longitude'],'0',$data['info'],$data['datetime'],$data['type'],$data['pilot_id'],$data['pilot_name'],$data['format_source']); |
|
1574 | + } |
|
1157 | 1575 | } |
1158 | 1576 | unset($data); |
1159 | 1577 | } |
@@ -1168,7 +1586,9 @@ discard block |
||
1168 | 1586 | ) |
1169 | 1587 | ) { |
1170 | 1588 | //$buffer = $Common->getData($hosts[$id]); |
1171 | - if ($globalDebug) echo 'Get Data...'."\n"; |
|
1589 | + if ($globalDebug) { |
|
1590 | + echo 'Get Data...'."\n"; |
|
1591 | + } |
|
1172 | 1592 | $buffer = $Common->getData($value['host']); |
1173 | 1593 | $all_data = json_decode($buffer,true); |
1174 | 1594 | if ($buffer != '' && is_array($all_data)) { |
@@ -1176,10 +1596,16 @@ discard block |
||
1176 | 1596 | foreach ($all_data as $line) { |
1177 | 1597 | $data = array(); |
1178 | 1598 | //$data['id'] = $line['id']; // id not usable |
1179 | - if (isset($line['pilotid'])) $data['id'] = $line['pilotid'].$line['flightnum']; |
|
1599 | + if (isset($line['pilotid'])) { |
|
1600 | + $data['id'] = $line['pilotid'].$line['flightnum']; |
|
1601 | + } |
|
1180 | 1602 | $data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex |
1181 | - if (isset($line['pilotname'])) $data['pilot_name'] = $line['pilotname']; |
|
1182 | - if (isset($line['pilotid'])) $data['pilot_id'] = $line['pilotid']; |
|
1603 | + if (isset($line['pilotname'])) { |
|
1604 | + $data['pilot_name'] = $line['pilotname']; |
|
1605 | + } |
|
1606 | + if (isset($line['pilotid'])) { |
|
1607 | + $data['pilot_id'] = $line['pilotid']; |
|
1608 | + } |
|
1183 | 1609 | $data['ident'] = $line['flightnum']; // ident |
1184 | 1610 | $data['altitude'] = $line['alt']; // altitude |
1185 | 1611 | $data['speed'] = $line['gs']; // speed |
@@ -1195,7 +1621,9 @@ discard block |
||
1195 | 1621 | $datetime = new DateTime($line['lastupdate'],new DateTimeZone($value['timezone'])); |
1196 | 1622 | $datetime->setTimeZone(new DateTimeZone('UTC')); |
1197 | 1623 | $data['datetime'] = $datetime->format('Y-m-d H:i:s'); |
1198 | - } else $data['datetime'] = date('Y-m-d H:i:s'); |
|
1624 | + } else { |
|
1625 | + $data['datetime'] = date('Y-m-d H:i:s'); |
|
1626 | + } |
|
1199 | 1627 | $data['departure_airport_icao'] = $line['depicao']; |
1200 | 1628 | $data['departure_airport_time'] = $line['deptime']; |
1201 | 1629 | $data['arrival_airport_icao'] = $line['arricao']; |
@@ -1203,29 +1631,47 @@ discard block |
||
1203 | 1631 | if (isset($line['registration'])) { |
1204 | 1632 | $data['registration'] = $line['registration']; |
1205 | 1633 | //if (isset($line['aircraft'])) $data['id'] = $line['aircraft']; |
1206 | - } else $data['registration'] = $line['aircraft']; |
|
1207 | - if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true; |
|
1208 | - if (isset($line['route'])) $data['waypoints'] = $line['route']; // route |
|
1634 | + } else { |
|
1635 | + $data['registration'] = $line['aircraft']; |
|
1636 | + } |
|
1637 | + if (isset($value['noarchive']) && $value['noarchive'] === TRUE) { |
|
1638 | + $data['noarchive'] = true; |
|
1639 | + } |
|
1640 | + if (isset($line['route'])) { |
|
1641 | + $data['waypoints'] = $line['route']; |
|
1642 | + } |
|
1643 | + // route |
|
1209 | 1644 | if (isset($line['aircraftname'])) { |
1210 | 1645 | $line['aircraftname'] = strtoupper($line['aircraftname']); |
1211 | 1646 | $line['aircraftname'] = str_replace('BOEING ','B',$line['aircraftname']); |
1212 | 1647 | $aircraft_data = explode('-',$line['aircraftname']); |
1213 | - if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) >= 3 && strlen($aircraft_data[0]) <= 4) $data['aircraft_icao'] = $aircraft_data[0]; |
|
1214 | - elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) >= 3 && strlen($aircraft_data[1]) <= 4) $data['aircraft_icao'] = $aircraft_data[1]; |
|
1215 | - else { |
|
1648 | + if (isset($aircraft_data[1]) && strlen($aircraft_data[0]) >= 3 && strlen($aircraft_data[0]) <= 4) { |
|
1649 | + $data['aircraft_icao'] = $aircraft_data[0]; |
|
1650 | + } elseif (isset($aircraft_data[1]) && strlen($aircraft_data[1]) >= 3 && strlen($aircraft_data[1]) <= 4) { |
|
1651 | + $data['aircraft_icao'] = $aircraft_data[1]; |
|
1652 | + } else { |
|
1216 | 1653 | $aircraft_data = explode(' ',$line['aircraftname']); |
1217 | - if (isset($aircraft_data[1])) $data['aircraft_icao'] = str_replace('-','',$aircraft_data[1]); |
|
1218 | - else $data['aircraft_icao'] = str_replace('-','',$line['aircraftname']); |
|
1654 | + if (isset($aircraft_data[1])) { |
|
1655 | + $data['aircraft_icao'] = str_replace('-','',$aircraft_data[1]); |
|
1656 | + } else { |
|
1657 | + $data['aircraft_icao'] = str_replace('-','',$line['aircraftname']); |
|
1658 | + } |
|
1219 | 1659 | } |
1220 | 1660 | } |
1221 | - if (isset($line['route'])) $data['waypoints'] = $line['route']; |
|
1661 | + if (isset($line['route'])) { |
|
1662 | + $data['waypoints'] = $line['route']; |
|
1663 | + } |
|
1222 | 1664 | $data['id_source'] = $id_source; |
1223 | 1665 | $data['format_source'] = 'phpvmacars'; |
1224 | - if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name']; |
|
1666 | + if (isset($value['name']) && $value['name'] != '') { |
|
1667 | + $data['source_name'] = $value['name']; |
|
1668 | + } |
|
1225 | 1669 | $SI->add($data); |
1226 | 1670 | unset($data); |
1227 | 1671 | } |
1228 | - if ($globalDebug) echo 'No more data...'."\n"; |
|
1672 | + if ($globalDebug) { |
|
1673 | + echo 'No more data...'."\n"; |
|
1674 | + } |
|
1229 | 1675 | unset($buffer); |
1230 | 1676 | unset($all_data); |
1231 | 1677 | } |
@@ -1238,7 +1684,9 @@ discard block |
||
1238 | 1684 | ) |
1239 | 1685 | ) { |
1240 | 1686 | //$buffer = $Common->getData($hosts[$id]); |
1241 | - if ($globalDebug) echo 'Get Data...'."\n"; |
|
1687 | + if ($globalDebug) { |
|
1688 | + echo 'Get Data...'."\n"; |
|
1689 | + } |
|
1242 | 1690 | $buffer = $Common->getData($value['host']); |
1243 | 1691 | $all_data = json_decode($buffer,true); |
1244 | 1692 | if ($buffer != '' && is_array($all_data) && isset($all_data['ACARSData'])) { |
@@ -1249,10 +1697,16 @@ discard block |
||
1249 | 1697 | //$data['id'] = $line['id']; // id not usable |
1250 | 1698 | $data['id'] = $line['id']; |
1251 | 1699 | //$data['hex'] = substr(str_pad(bin2hex($line['flightnum']),6,'000000',STR_PAD_LEFT),-6); // hex |
1252 | - if (isset($line['user']['username'])) $data['pilot_name'] = $line['user']['username']; |
|
1253 | - if (isset($line['user_id'])) $data['pilot_id'] = $line['user_id']; |
|
1700 | + if (isset($line['user']['username'])) { |
|
1701 | + $data['pilot_name'] = $line['user']['username']; |
|
1702 | + } |
|
1703 | + if (isset($line['user_id'])) { |
|
1704 | + $data['pilot_id'] = $line['user_id']; |
|
1705 | + } |
|
1254 | 1706 | $data['ident'] = str_replace(' ','',$line['bid']['flightnum']); // ident |
1255 | - if (is_numeric($data['ident'])) $data['ident'] = $line['bid']['airline']['icao'].$data['ident']; |
|
1707 | + if (is_numeric($data['ident'])) { |
|
1708 | + $data['ident'] = $line['bid']['airline']['icao'].$data['ident']; |
|
1709 | + } |
|
1256 | 1710 | $data['altitude'] = $line['altitude']; // altitude |
1257 | 1711 | $data['speed'] = $line['groundspeed']; // speed |
1258 | 1712 | $data['heading'] = $line['heading']; // heading |
@@ -1265,7 +1719,9 @@ discard block |
||
1265 | 1719 | $datetime = new DateTime($line['updated_at'],new DateTimeZone($value['timezone'])); |
1266 | 1720 | $datetime->setTimeZone(new DateTimeZone('UTC')); |
1267 | 1721 | $data['datetime'] = $datetime->format('Y-m-d H:i:s'); |
1268 | - } else $data['datetime'] = date('Y-m-d H:i:s'); |
|
1722 | + } else { |
|
1723 | + $data['datetime'] = date('Y-m-d H:i:s'); |
|
1724 | + } |
|
1269 | 1725 | |
1270 | 1726 | $data['departure_airport_icao'] = $line['bid']['depapt']['icao']; |
1271 | 1727 | $data['departure_airport_time'] = $line['bid']['deptime']; |
@@ -1273,17 +1729,26 @@ discard block |
||
1273 | 1729 | $data['arrival_airport_time'] = $line['bid']['arrtime']; |
1274 | 1730 | $data['registration'] = $line['bid']['aircraft']['registration']; |
1275 | 1731 | |
1276 | - if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true; |
|
1277 | - if (isset($line['bid']['route']) && $line['bid']['route'] != '') $data['waypoints'] = $line['bid']['route']; // route |
|
1732 | + if (isset($value['noarchive']) && $value['noarchive'] === TRUE) { |
|
1733 | + $data['noarchive'] = true; |
|
1734 | + } |
|
1735 | + if (isset($line['bid']['route']) && $line['bid']['route'] != '') { |
|
1736 | + $data['waypoints'] = $line['bid']['route']; |
|
1737 | + } |
|
1738 | + // route |
|
1278 | 1739 | $data['aircraft_icao'] = $line['bid']['aircraft']['icao']; |
1279 | 1740 | |
1280 | 1741 | $data['id_source'] = $id_source; |
1281 | 1742 | $data['format_source'] = 'vaos'; |
1282 | - if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name']; |
|
1743 | + if (isset($value['name']) && $value['name'] != '') { |
|
1744 | + $data['source_name'] = $value['name']; |
|
1745 | + } |
|
1283 | 1746 | $SI->add($data); |
1284 | 1747 | unset($data); |
1285 | 1748 | } |
1286 | - if ($globalDebug) echo 'No more data...'."\n"; |
|
1749 | + if ($globalDebug) { |
|
1750 | + echo 'No more data...'."\n"; |
|
1751 | + } |
|
1287 | 1752 | unset($buffer); |
1288 | 1753 | unset($all_data); |
1289 | 1754 | } |
@@ -1296,7 +1761,9 @@ discard block |
||
1296 | 1761 | ) |
1297 | 1762 | ) { |
1298 | 1763 | //$buffer = $Common->getData($hosts[$id]); |
1299 | - if ($globalDebug) echo 'Get Data...'."\n"; |
|
1764 | + if ($globalDebug) { |
|
1765 | + echo 'Get Data...'."\n"; |
|
1766 | + } |
|
1300 | 1767 | $buffer = $Common->getData($value['host']); |
1301 | 1768 | $all_data = json_decode($buffer,true); |
1302 | 1769 | if ($buffer != '' && is_array($all_data)) { |
@@ -1325,16 +1792,25 @@ discard block |
||
1325 | 1792 | $data['arrival_airport_icao'] = $line['arrival']; |
1326 | 1793 | //$data['arrival_airport_time'] = $line['arrival_time']; |
1327 | 1794 | //$data['registration'] = $line['aircraft']; |
1328 | - if (isset($line['route'])) $data['waypoints'] = $line['route']; // route |
|
1795 | + if (isset($line['route'])) { |
|
1796 | + $data['waypoints'] = $line['route']; |
|
1797 | + } |
|
1798 | + // route |
|
1329 | 1799 | $data['aircraft_icao'] = $line['plane_type']; |
1330 | 1800 | $data['id_source'] = $id_source; |
1331 | 1801 | $data['format_source'] = 'vam'; |
1332 | - if (isset($value['noarchive']) && $value['noarchive'] === TRUE) $data['noarchive'] = true; |
|
1333 | - if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name']; |
|
1802 | + if (isset($value['noarchive']) && $value['noarchive'] === TRUE) { |
|
1803 | + $data['noarchive'] = true; |
|
1804 | + } |
|
1805 | + if (isset($value['name']) && $value['name'] != '') { |
|
1806 | + $data['source_name'] = $value['name']; |
|
1807 | + } |
|
1334 | 1808 | $SI->add($data); |
1335 | 1809 | unset($data); |
1336 | 1810 | } |
1337 | - if ($globalDebug) echo 'No more data...'."\n"; |
|
1811 | + if ($globalDebug) { |
|
1812 | + echo 'No more data...'."\n"; |
|
1813 | + } |
|
1338 | 1814 | unset($buffer); |
1339 | 1815 | unset($all_data); |
1340 | 1816 | } |
@@ -1347,7 +1823,9 @@ discard block |
||
1347 | 1823 | ) |
1348 | 1824 | ) { |
1349 | 1825 | //$buffer = $Common->getData($hosts[$id]); |
1350 | - if ($globalDebug) echo 'Get Data...'."\n"; |
|
1826 | + if ($globalDebug) { |
|
1827 | + echo 'Get Data...'."\n"; |
|
1828 | + } |
|
1351 | 1829 | $buffer = $Common->getData($value['host']); |
1352 | 1830 | $all_data = json_decode($buffer,true); |
1353 | 1831 | if ($buffer != '') { |
@@ -1365,18 +1843,24 @@ discard block |
||
1365 | 1843 | $data['id_source'] = $id_source; |
1366 | 1844 | $data['format_source'] = 'blitzortung'; |
1367 | 1845 | $SI->add($data); |
1368 | - if ($globalDebug) echo '☈ Lightning added'."\n"; |
|
1846 | + if ($globalDebug) { |
|
1847 | + echo '☈ Lightning added'."\n"; |
|
1848 | + } |
|
1369 | 1849 | $Source->addLocation('',$data['latitude'],$data['longitude'],0,'','','blitzortung','weather/thunderstorm.png','lightning',$id,0,$data['datetime']); |
1370 | 1850 | unset($data); |
1371 | 1851 | } |
1372 | 1852 | } |
1373 | - if ($globalDebug) echo 'No more data...'."\n"; |
|
1853 | + if ($globalDebug) { |
|
1854 | + echo 'No more data...'."\n"; |
|
1855 | + } |
|
1374 | 1856 | unset($buffer); |
1375 | 1857 | } |
1376 | 1858 | $last_exec[$id]['last'] = time(); |
1377 | 1859 | //} elseif ($value == 'sbs' || $value == 'tsv' || $value == 'raw' || $value == 'aprs' || $value == 'beast') { |
1378 | 1860 | } elseif ($value['format'] == 'sbs' || $value['format'] == 'tsv' || $value['format'] == 'raw' || $value['format'] == 'aprs' || $value['format'] == 'famaprs' || $value['format'] == 'beast' || $value['format'] == 'flightgearmp' || $value['format'] == 'flightgearsp' || $value['format'] == 'acars' || $value['format'] == 'acarssbs3' || $value['format'] == 'ais' || $value['format'] == 'vrstcp') { |
1379 | - if (function_exists('pcntl_fork')) pcntl_signal_dispatch(); |
|
1861 | + if (function_exists('pcntl_fork')) { |
|
1862 | + pcntl_signal_dispatch(); |
|
1863 | + } |
|
1380 | 1864 | //$last_exec[$id]['last'] = time(); |
1381 | 1865 | |
1382 | 1866 | //$read = array( $sockets[$id] ); |
@@ -1384,7 +1868,9 @@ discard block |
||
1384 | 1868 | $write = NULL; |
1385 | 1869 | $e = NULL; |
1386 | 1870 | $n = socket_select($read, $write, $e, $timeout); |
1387 | - if ($e != NULL) var_dump($e); |
|
1871 | + if ($e != NULL) { |
|
1872 | + var_dump($e); |
|
1873 | + } |
|
1388 | 1874 | if ($n > 0) { |
1389 | 1875 | $reset = 0; |
1390 | 1876 | foreach ($read as $nb => $r) { |
@@ -1406,13 +1892,17 @@ discard block |
||
1406 | 1892 | if ($buffer !== FALSE) { |
1407 | 1893 | if ($format == 'vrstcp') { |
1408 | 1894 | $buffer = explode('},{',$buffer); |
1409 | - } else $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'',$buffer)); |
|
1895 | + } else { |
|
1896 | + $buffer=trim(str_replace(array("\r\n","\r","\n","\\r","\\n","\\r\\n"),'',$buffer)); |
|
1897 | + } |
|
1410 | 1898 | } |
1411 | 1899 | // SBS format is CSV format |
1412 | 1900 | if ($buffer !== FALSE && $buffer !== '') { |
1413 | 1901 | $tt[$format] = 0; |
1414 | 1902 | if ($format == 'acarssbs3') { |
1415 | - if ($globalDebug) echo 'ACARS : '.$buffer."\n"; |
|
1903 | + if ($globalDebug) { |
|
1904 | + echo 'ACARS : '.$buffer."\n"; |
|
1905 | + } |
|
1416 | 1906 | $ACARS->add(trim($buffer)); |
1417 | 1907 | $ACARS->deleteLiveAcarsData(); |
1418 | 1908 | } elseif ($format == 'raw') { |
@@ -1421,30 +1911,70 @@ discard block |
||
1421 | 1911 | if (is_array($data)) { |
1422 | 1912 | $data['datetime'] = date('Y-m-d H:i:s'); |
1423 | 1913 | $data['format_source'] = 'raw'; |
1424 | - if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name']; |
|
1425 | - if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats']; |
|
1426 | - if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true; |
|
1427 | - if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data); |
|
1914 | + if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') { |
|
1915 | + $data['source_name'] = $globalSources[$nb]['name']; |
|
1916 | + } |
|
1917 | + if (isset($globalSources[$nb]['sourcestats'])) { |
|
1918 | + $data['sourcestats'] = $globalSources[$nb]['sourcestats']; |
|
1919 | + } |
|
1920 | + if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) { |
|
1921 | + $data['noarchive'] = true; |
|
1922 | + } |
|
1923 | + if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) { |
|
1924 | + $SI->add($data); |
|
1925 | + } |
|
1428 | 1926 | } |
1429 | 1927 | } elseif ($format == 'ais') { |
1430 | 1928 | $ais_data = $AIS->parse_line(trim($buffer)); |
1431 | 1929 | $data = array(); |
1432 | - if (isset($ais_data['ident'])) $data['ident'] = $ais_data['ident']; |
|
1433 | - if (isset($ais_data['mmsi'])) $data['mmsi'] = substr($ais_data['mmsi'],-9); |
|
1434 | - if (isset($ais_data['speed'])) $data['speed'] = $ais_data['speed']; |
|
1435 | - if (isset($ais_data['heading'])) $data['heading'] = $ais_data['heading']; |
|
1436 | - if (isset($ais_data['latitude'])) $data['latitude'] = $ais_data['latitude']; |
|
1437 | - if (isset($ais_data['longitude'])) $data['longitude'] = $ais_data['longitude']; |
|
1438 | - if (isset($ais_data['status'])) $data['status'] = $ais_data['status']; |
|
1439 | - if (isset($ais_data['statusid'])) $data['status_id'] = $ais_data['statusid']; |
|
1440 | - if (isset($ais_data['type'])) $data['type'] = $ais_data['type']; |
|
1441 | - if (isset($ais_data['imo'])) $data['imo'] = $ais_data['imo']; |
|
1442 | - if (isset($ais_data['callsign'])) $data['callsign'] = $ais_data['callsign']; |
|
1443 | - if (isset($ais_data['destination'])) $data['arrival_code'] = $ais_data['destination']; |
|
1444 | - if (isset($ais_data['eta_ts'])) $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']); |
|
1445 | - if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true; |
|
1446 | - if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name']; |
|
1447 | - if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats']; |
|
1930 | + if (isset($ais_data['ident'])) { |
|
1931 | + $data['ident'] = $ais_data['ident']; |
|
1932 | + } |
|
1933 | + if (isset($ais_data['mmsi'])) { |
|
1934 | + $data['mmsi'] = substr($ais_data['mmsi'],-9); |
|
1935 | + } |
|
1936 | + if (isset($ais_data['speed'])) { |
|
1937 | + $data['speed'] = $ais_data['speed']; |
|
1938 | + } |
|
1939 | + if (isset($ais_data['heading'])) { |
|
1940 | + $data['heading'] = $ais_data['heading']; |
|
1941 | + } |
|
1942 | + if (isset($ais_data['latitude'])) { |
|
1943 | + $data['latitude'] = $ais_data['latitude']; |
|
1944 | + } |
|
1945 | + if (isset($ais_data['longitude'])) { |
|
1946 | + $data['longitude'] = $ais_data['longitude']; |
|
1947 | + } |
|
1948 | + if (isset($ais_data['status'])) { |
|
1949 | + $data['status'] = $ais_data['status']; |
|
1950 | + } |
|
1951 | + if (isset($ais_data['statusid'])) { |
|
1952 | + $data['status_id'] = $ais_data['statusid']; |
|
1953 | + } |
|
1954 | + if (isset($ais_data['type'])) { |
|
1955 | + $data['type'] = $ais_data['type']; |
|
1956 | + } |
|
1957 | + if (isset($ais_data['imo'])) { |
|
1958 | + $data['imo'] = $ais_data['imo']; |
|
1959 | + } |
|
1960 | + if (isset($ais_data['callsign'])) { |
|
1961 | + $data['callsign'] = $ais_data['callsign']; |
|
1962 | + } |
|
1963 | + if (isset($ais_data['destination'])) { |
|
1964 | + $data['arrival_code'] = $ais_data['destination']; |
|
1965 | + } |
|
1966 | + if (isset($ais_data['eta_ts'])) { |
|
1967 | + $data['arrival_date'] = date('Y-m-d H:i:s',$ais_data['eta_ts']); |
|
1968 | + } |
|
1969 | + if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) { |
|
1970 | + $data['noarchive'] = true; |
|
1971 | + } |
|
1972 | + if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') { |
|
1973 | + $data['source_name'] = $globalSources[$nb]['name']; |
|
1974 | + } |
|
1975 | + if (isset($globalSources[$nb]['sourcestats'])) { |
|
1976 | + $data['sourcestats'] = $globalSources[$nb]['sourcestats']; |
|
1977 | + } |
|
1448 | 1978 | |
1449 | 1979 | if (isset($ais_data['timestamp'])) { |
1450 | 1980 | $data['datetime'] = date('Y-m-d H:i:s',$ais_data['timestamp']); |
@@ -1453,7 +1983,9 @@ discard block |
||
1453 | 1983 | } |
1454 | 1984 | $data['format_source'] = 'aisnmea'; |
1455 | 1985 | $data['id_source'] = $id_source; |
1456 | - if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') $MI->add($data); |
|
1986 | + if (isset($ais_data['mmsi_type']) && $ais_data['mmsi_type'] == 'Ship') { |
|
1987 | + $MI->add($data); |
|
1988 | + } |
|
1457 | 1989 | unset($data); |
1458 | 1990 | } elseif ($format == 'flightgearsp') { |
1459 | 1991 | //echo $buffer."\n"; |
@@ -1471,12 +2003,18 @@ discard block |
||
1471 | 2003 | $data['speed'] = round($line[5]*1.94384); |
1472 | 2004 | $data['datetime'] = date('Y-m-d H:i:s'); |
1473 | 2005 | $data['format_source'] = 'flightgearsp'; |
1474 | - if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true; |
|
1475 | - if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data); |
|
2006 | + if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) { |
|
2007 | + $data['noarchive'] = true; |
|
2008 | + } |
|
2009 | + if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) { |
|
2010 | + $SI->add($data); |
|
2011 | + } |
|
1476 | 2012 | //$send = @ socket_send( $r , $data_aprs , strlen($data_aprs) , 0 ); |
1477 | 2013 | } |
1478 | 2014 | } elseif ($format == 'acars') { |
1479 | - if ($globalDebug) echo 'ACARS : '.$buffer."\n"; |
|
2015 | + if ($globalDebug) { |
|
2016 | + echo 'ACARS : '.$buffer."\n"; |
|
2017 | + } |
|
1480 | 2018 | $ACARS->add(trim($buffer)); |
1481 | 2019 | socket_sendto($r, "OK " . $buffer , 100 , 0 , $remote_ip , $remote_port); |
1482 | 2020 | $ACARS->deleteLiveAcarsData(); |
@@ -1497,8 +2035,12 @@ discard block |
||
1497 | 2035 | $aircraft_type = $line[10]; |
1498 | 2036 | $aircraft_type = preg_split(':/:',$aircraft_type); |
1499 | 2037 | $data['aircraft_name'] = substr(end($aircraft_type),0,-4); |
1500 | - if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true; |
|
1501 | - if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data); |
|
2038 | + if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) { |
|
2039 | + $data['noarchive'] = true; |
|
2040 | + } |
|
2041 | + if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) { |
|
2042 | + $SI->add($data); |
|
2043 | + } |
|
1502 | 2044 | } |
1503 | 2045 | } |
1504 | 2046 | } elseif ($format == 'beast') { |
@@ -1508,28 +2050,62 @@ discard block |
||
1508 | 2050 | foreach($buffer as $all_data) { |
1509 | 2051 | $line = json_decode('{'.$all_data.'}',true); |
1510 | 2052 | $data = array(); |
1511 | - if (isset($line['Icao'])) $data['hex'] = $line['Icao']; // hex |
|
1512 | - if (isset($line['Call'])) $data['ident'] = $line['Call']; // ident |
|
1513 | - if (isset($line['Alt'])) $data['altitude'] = $line['Alt']; // altitude |
|
1514 | - if (isset($line['Spd'])) $data['speed'] = $line['Spd']; // speed |
|
1515 | - if (isset($line['Trak'])) $data['heading'] = $line['Trak']; // heading |
|
1516 | - if (isset($line['Lat'])) $data['latitude'] = $line['Lat']; // lat |
|
1517 | - if (isset($line['Long'])) $data['longitude'] = $line['Long']; // long |
|
2053 | + if (isset($line['Icao'])) { |
|
2054 | + $data['hex'] = $line['Icao']; |
|
2055 | + } |
|
2056 | + // hex |
|
2057 | + if (isset($line['Call'])) { |
|
2058 | + $data['ident'] = $line['Call']; |
|
2059 | + } |
|
2060 | + // ident |
|
2061 | + if (isset($line['Alt'])) { |
|
2062 | + $data['altitude'] = $line['Alt']; |
|
2063 | + } |
|
2064 | + // altitude |
|
2065 | + if (isset($line['Spd'])) { |
|
2066 | + $data['speed'] = $line['Spd']; |
|
2067 | + } |
|
2068 | + // speed |
|
2069 | + if (isset($line['Trak'])) { |
|
2070 | + $data['heading'] = $line['Trak']; |
|
2071 | + } |
|
2072 | + // heading |
|
2073 | + if (isset($line['Lat'])) { |
|
2074 | + $data['latitude'] = $line['Lat']; |
|
2075 | + } |
|
2076 | + // lat |
|
2077 | + if (isset($line['Long'])) { |
|
2078 | + $data['longitude'] = $line['Long']; |
|
2079 | + } |
|
2080 | + // long |
|
1518 | 2081 | //$data['verticalrate'] = $line['']; // verticale rate |
1519 | - if (isset($line['Sqk'])) $data['squawk'] = $line['Sqk']; // squawk |
|
2082 | + if (isset($line['Sqk'])) { |
|
2083 | + $data['squawk'] = $line['Sqk']; |
|
2084 | + } |
|
2085 | + // squawk |
|
1520 | 2086 | $data['emergency'] = ''; // emergency |
1521 | - if (isset($line['Reg'])) $data['registration'] = $line['Reg']; |
|
2087 | + if (isset($line['Reg'])) { |
|
2088 | + $data['registration'] = $line['Reg']; |
|
2089 | + } |
|
1522 | 2090 | /* |
1523 | 2091 | if (isset($line['PosTime'])) $data['datetime'] = date('Y-m-d H:i:s',$line['PosTime']/1000); |
1524 | 2092 | else $data['datetime'] = date('Y-m-d H:i:s'); |
1525 | 2093 | */ |
1526 | 2094 | $data['datetime'] = date('Y-m-d H:i:s'); |
1527 | - if (isset($line['Type'])) $data['aircraft_icao'] = $line['Type']; |
|
2095 | + if (isset($line['Type'])) { |
|
2096 | + $data['aircraft_icao'] = $line['Type']; |
|
2097 | + } |
|
1528 | 2098 | $data['format_source'] = 'vrstcp'; |
1529 | 2099 | $data['id_source'] = $id_source; |
1530 | - if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true; |
|
1531 | - if (isset($value['name']) && $value['name'] != '') $data['source_name'] = $value['name']; |
|
1532 | - if (isset($data['latitude']) && isset($data['hex'])) $SI->add($data); |
|
2100 | + if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) { |
|
2101 | + $data['noarchive'] = true; |
|
2102 | + } |
|
2103 | + if (isset($value['name']) && $value['name'] != '') { |
|
2104 | + $data['source_name'] = $value['name']; |
|
2105 | + } |
|
2106 | + if (isset($data['latitude']) && isset($data['hex'])) { |
|
2107 | + $SI->add($data); |
|
2108 | + } |
|
1533 | 2109 | unset($data); |
1534 | 2110 | } |
1535 | 2111 | } elseif ($format == 'tsv' || substr($buffer,0,4) == 'clock') { |
@@ -1542,22 +2118,46 @@ discard block |
||
1542 | 2118 | $data['hex'] = $lined['hexid']; |
1543 | 2119 | //$data['datetime'] = date('Y-m-d H:i:s',strtotime($lined['clock']));; |
1544 | 2120 | $data['datetime'] = date('Y-m-d H:i:s');; |
1545 | - if (isset($lined['ident'])) $data['ident'] = $lined['ident']; |
|
1546 | - if (isset($lined['lat'])) $data['latitude'] = $lined['lat']; |
|
1547 | - if (isset($lined['lon'])) $data['longitude'] = $lined['lon']; |
|
1548 | - if (isset($lined['speed'])) $data['speed'] = $lined['speed']; |
|
1549 | - if (isset($lined['squawk'])) $data['squawk'] = $lined['squawk']; |
|
1550 | - if (isset($lined['alt'])) $data['altitude'] = $lined['alt']; |
|
1551 | - if (isset($lined['heading'])) $data['heading'] = $lined['heading']; |
|
2121 | + if (isset($lined['ident'])) { |
|
2122 | + $data['ident'] = $lined['ident']; |
|
2123 | + } |
|
2124 | + if (isset($lined['lat'])) { |
|
2125 | + $data['latitude'] = $lined['lat']; |
|
2126 | + } |
|
2127 | + if (isset($lined['lon'])) { |
|
2128 | + $data['longitude'] = $lined['lon']; |
|
2129 | + } |
|
2130 | + if (isset($lined['speed'])) { |
|
2131 | + $data['speed'] = $lined['speed']; |
|
2132 | + } |
|
2133 | + if (isset($lined['squawk'])) { |
|
2134 | + $data['squawk'] = $lined['squawk']; |
|
2135 | + } |
|
2136 | + if (isset($lined['alt'])) { |
|
2137 | + $data['altitude'] = $lined['alt']; |
|
2138 | + } |
|
2139 | + if (isset($lined['heading'])) { |
|
2140 | + $data['heading'] = $lined['heading']; |
|
2141 | + } |
|
1552 | 2142 | $data['id_source'] = $id_source; |
1553 | 2143 | $data['format_source'] = 'tsv'; |
1554 | - if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name']; |
|
1555 | - if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats']; |
|
1556 | - if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true; |
|
1557 | - if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $SI->add($data); |
|
2144 | + if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') { |
|
2145 | + $data['source_name'] = $globalSources[$nb]['name']; |
|
2146 | + } |
|
2147 | + if (isset($globalSources[$nb]['sourcestats'])) { |
|
2148 | + $data['sourcestats'] = $globalSources[$nb]['sourcestats']; |
|
2149 | + } |
|
2150 | + if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) { |
|
2151 | + $data['noarchive'] = true; |
|
2152 | + } |
|
2153 | + if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) { |
|
2154 | + $SI->add($data); |
|
2155 | + } |
|
1558 | 2156 | unset($lined); |
1559 | 2157 | unset($data); |
1560 | - } else $error = true; |
|
2158 | + } else { |
|
2159 | + $error = true; |
|
2160 | + } |
|
1561 | 2161 | } elseif ($format == 'aprs' && $use_aprs) { |
1562 | 2162 | if ($aprs_connect == 0) { |
1563 | 2163 | $send = @ socket_send( $r , $aprs_login , strlen($aprs_login) , 0 ); |
@@ -1583,63 +2183,121 @@ discard block |
||
1583 | 2183 | $aprs_last_tx = time(); |
1584 | 2184 | $data = array(); |
1585 | 2185 | //print_r($line); |
1586 | - if (isset($line['address'])) $data['hex'] = $line['address']; |
|
1587 | - if (isset($line['mmsi'])) $data['mmsi'] = $line['mmsi']; |
|
1588 | - if (isset($line['imo'])) $data['imo'] = $line['imo']; |
|
1589 | - if (isset($line['squawk'])) $data['squawk'] = $line['squawk']; |
|
1590 | - if (isset($line['arrival_code'])) $data['arrival_code'] = $line['arrival_code']; |
|
1591 | - if (isset($line['arrival_date'])) $data['arrival_date'] = $line['arrival_date']; |
|
1592 | - if (isset($line['typeid'])) $data['type_id'] = $line['typeid']; |
|
1593 | - if (isset($line['statusid'])) $data['status_id'] = $line['statusid']; |
|
1594 | - if (isset($line['timestamp'])) $data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']); |
|
1595 | - else $data['datetime'] = date('Y-m-d H:i:s'); |
|
2186 | + if (isset($line['address'])) { |
|
2187 | + $data['hex'] = $line['address']; |
|
2188 | + } |
|
2189 | + if (isset($line['mmsi'])) { |
|
2190 | + $data['mmsi'] = $line['mmsi']; |
|
2191 | + } |
|
2192 | + if (isset($line['imo'])) { |
|
2193 | + $data['imo'] = $line['imo']; |
|
2194 | + } |
|
2195 | + if (isset($line['squawk'])) { |
|
2196 | + $data['squawk'] = $line['squawk']; |
|
2197 | + } |
|
2198 | + if (isset($line['arrival_code'])) { |
|
2199 | + $data['arrival_code'] = $line['arrival_code']; |
|
2200 | + } |
|
2201 | + if (isset($line['arrival_date'])) { |
|
2202 | + $data['arrival_date'] = $line['arrival_date']; |
|
2203 | + } |
|
2204 | + if (isset($line['typeid'])) { |
|
2205 | + $data['type_id'] = $line['typeid']; |
|
2206 | + } |
|
2207 | + if (isset($line['statusid'])) { |
|
2208 | + $data['status_id'] = $line['statusid']; |
|
2209 | + } |
|
2210 | + if (isset($line['timestamp'])) { |
|
2211 | + $data['datetime'] = date('Y-m-d H:i:s',$line['timestamp']); |
|
2212 | + } else { |
|
2213 | + $data['datetime'] = date('Y-m-d H:i:s'); |
|
2214 | + } |
|
1596 | 2215 | //$data['datetime'] = date('Y-m-d H:i:s'); |
1597 | - if (isset($line['ident'])) $data['ident'] = $line['ident']; |
|
2216 | + if (isset($line['ident'])) { |
|
2217 | + $data['ident'] = $line['ident']; |
|
2218 | + } |
|
1598 | 2219 | $data['latitude'] = $line['latitude']; |
1599 | 2220 | $data['longitude'] = $line['longitude']; |
1600 | 2221 | //$data['verticalrate'] = $line[16]; |
1601 | - if (isset($line['speed'])) $data['speed'] = $line['speed']; |
|
2222 | + if (isset($line['speed'])) { |
|
2223 | + $data['speed'] = $line['speed']; |
|
2224 | + } |
|
1602 | 2225 | //else $data['speed'] = 0; |
1603 | - if (isset($line['altitude'])) $data['altitude'] = $line['altitude']; |
|
1604 | - if (isset($line['comment'])) $data['comment'] = $line['comment']; |
|
1605 | - if (isset($line['symbol'])) $data['type'] = $line['symbol']; |
|
2226 | + if (isset($line['altitude'])) { |
|
2227 | + $data['altitude'] = $line['altitude']; |
|
2228 | + } |
|
2229 | + if (isset($line['comment'])) { |
|
2230 | + $data['comment'] = $line['comment']; |
|
2231 | + } |
|
2232 | + if (isset($line['symbol'])) { |
|
2233 | + $data['type'] = $line['symbol']; |
|
2234 | + } |
|
1606 | 2235 | //if (isset($line['heading'])) $data['heading'] = $line['heading']; |
1607 | 2236 | |
1608 | - if (isset($line['heading']) && isset($line['format_source'])) $data['heading'] = $line['heading']; |
|
2237 | + if (isset($line['heading']) && isset($line['format_source'])) { |
|
2238 | + $data['heading'] = $line['heading']; |
|
2239 | + } |
|
1609 | 2240 | //else echo 'No heading...'."\n"; |
1610 | 2241 | //else $data['heading'] = 0; |
1611 | - if (isset($line['stealth'])) $data['aircraft_type'] = $line['stealth']; |
|
2242 | + if (isset($line['stealth'])) { |
|
2243 | + $data['aircraft_type'] = $line['stealth']; |
|
2244 | + } |
|
1612 | 2245 | //if (!isset($line['source_type']) && (!isset($globalAPRSarchive) || (isset($globalAPRSarchive) && $globalAPRSarchive === FALSE))) $data['noarchive'] = true; |
1613 | - if (isset($globalAPRSarchive) && $globalAPRSarchive === FALSE) $data['noarchive'] = true; |
|
1614 | - elseif (isset($globalAPRSarchive) && $globalAPRSarchive === TRUE) $data['noarchive'] = false; |
|
1615 | - if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true; |
|
1616 | - elseif (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === FALSE) $data['noarchive'] = false; |
|
2246 | + if (isset($globalAPRSarchive) && $globalAPRSarchive === FALSE) { |
|
2247 | + $data['noarchive'] = true; |
|
2248 | + } elseif (isset($globalAPRSarchive) && $globalAPRSarchive === TRUE) { |
|
2249 | + $data['noarchive'] = false; |
|
2250 | + } |
|
2251 | + if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) { |
|
2252 | + $data['noarchive'] = true; |
|
2253 | + } elseif (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === FALSE) { |
|
2254 | + $data['noarchive'] = false; |
|
2255 | + } |
|
1617 | 2256 | $data['id_source'] = $id_source; |
1618 | - if (isset($line['format_source'])) $data['format_source'] = $line['format_source']; |
|
1619 | - else $data['format_source'] = 'aprs'; |
|
2257 | + if (isset($line['format_source'])) { |
|
2258 | + $data['format_source'] = $line['format_source']; |
|
2259 | + } else { |
|
2260 | + $data['format_source'] = 'aprs'; |
|
2261 | + } |
|
1620 | 2262 | $data['source_name'] = $line['source']; |
1621 | - if (isset($line['source_type'])) $data['source_type'] = $line['source_type']; |
|
1622 | - else $data['source_type'] = 'flarm'; |
|
1623 | - if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats']; |
|
2263 | + if (isset($line['source_type'])) { |
|
2264 | + $data['source_type'] = $line['source_type']; |
|
2265 | + } else { |
|
2266 | + $data['source_type'] = 'flarm'; |
|
2267 | + } |
|
2268 | + if (isset($globalSources[$nb]['sourcestats'])) { |
|
2269 | + $data['sourcestats'] = $globalSources[$nb]['sourcestats']; |
|
2270 | + } |
|
1624 | 2271 | $currentdate = date('Y-m-d H:i:s'); |
1625 | 2272 | $aprsdate = strtotime($data['datetime']); |
1626 | - if ($data['source_type'] != 'modes' && $data['source_type'] != 'ais') $data['altitude_relative'] = 'AMSL'; |
|
2273 | + if ($data['source_type'] != 'modes' && $data['source_type'] != 'ais') { |
|
2274 | + $data['altitude_relative'] = 'AMSL'; |
|
2275 | + } |
|
1627 | 2276 | // Accept data if time <= system time + 20s |
1628 | 2277 | //if (($data['source_type'] == 'modes') || isset($line['stealth']) && ($line['stealth'] == 0 || $line['stealth'] == '') && (strtotime($data['datetime']) <= strtotime($currentdate)+20) && (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude'])))) { |
1629 | 2278 | if (($data['source_type'] == 'modes') || isset($line['stealth']) && ($line['stealth'] == 0 || $line['stealth'] == '') && (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude'])))) { |
1630 | 2279 | $send = $SI->add($data); |
1631 | 2280 | } elseif ($data['source_type'] == 'ais') { |
1632 | 2281 | $data['type'] = ''; |
1633 | - if (isset($globalMarine) && $globalMarine) $send = $MI->add($data); |
|
2282 | + if (isset($globalMarine) && $globalMarine) { |
|
2283 | + $send = $MI->add($data); |
|
2284 | + } |
|
1634 | 2285 | } elseif (isset($line['stealth'])) { |
1635 | - if ($line['stealth'] != 0) echo '-------- '.$data['ident'].' : APRS stealth ON => not adding'."\n"; |
|
1636 | - else echo '--------- '.$data['ident'].' : Date APRS : '.$data['datetime'].' - Current date : '.$currentdate.' => not adding future event'."\n"; |
|
2286 | + if ($line['stealth'] != 0) { |
|
2287 | + echo '-------- '.$data['ident'].' : APRS stealth ON => not adding'."\n"; |
|
2288 | + } else { |
|
2289 | + echo '--------- '.$data['ident'].' : Date APRS : '.$data['datetime'].' - Current date : '.$currentdate.' => not adding future event'."\n"; |
|
2290 | + } |
|
1637 | 2291 | } elseif (isset($globalAircraft) && $globalAircraft && isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && ( |
1638 | 2292 | //$line['symbol'] == 'Balloon' || |
1639 | 2293 | $line['symbol'] == 'Glider' || |
1640 | 2294 | $line['symbol'] == 'Aircraft (small)' || $line['symbol'] == 'Helicopter')) { |
1641 | - if ($line['symbol'] == 'Ballon') $data['aircraft_icao'] = 'BALL'; |
|
1642 | - if ($line['symbol'] == 'Glider') $data['aircraft_icao'] = 'PARAGLIDER'; |
|
2295 | + if ($line['symbol'] == 'Ballon') { |
|
2296 | + $data['aircraft_icao'] = 'BALL'; |
|
2297 | + } |
|
2298 | + if ($line['symbol'] == 'Glider') { |
|
2299 | + $data['aircraft_icao'] = 'PARAGLIDER'; |
|
2300 | + } |
|
1643 | 2301 | $send = $SI->add($data); |
1644 | 2302 | } elseif (isset($globalMarine) && $globalMarine && isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && ( |
1645 | 2303 | $line['symbol'] == 'Yacht (Sail)' || |
@@ -1670,9 +2328,13 @@ discard block |
||
1670 | 2328 | //} elseif (isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && isset($line['speed']) && $line['symbol'] != 'Weather Station' && $line['symbol'] != 'House QTH (VHF)' && $line['symbol'] != 'Dot' && $line['symbol'] != 'TCP-IP' && $line['symbol'] != 'xAPRS (UNIX)' && $line['symbol'] != 'Antenna' && $line['symbol'] != 'Cloudy' && $line['symbol'] != 'HF Gateway' && $line['symbol'] != 'Yagi At QTH' && $line['symbol'] != 'Digi' && $line['symbol'] != '8' && $line['symbol'] != 'MacAPRS') { |
1671 | 2329 | // } elseif (isset($line['symbol']) && isset($line['latitude']) && isset($line['longitude']) && $line['symbol'] != 'Weather Station' && $line['symbol'] != 'House QTH (VHF)' && $line['symbol'] != 'Dot' && $line['symbol'] != 'TCP-IP' && $line['symbol'] != 'xAPRS (UNIX)' && $line['symbol'] != 'Antenna' && $line['symbol'] != 'Cloudy' && $line['symbol'] != 'HF Gateway' && $line['symbol'] != 'Yagi At QTH' && $line['symbol'] != 'Digi' && $line['symbol'] != '8' && $line['symbol'] != 'MacAPRS') { |
1672 | 2330 | //echo '!!!!!!!!!!!!!!!! SEND !!!!!!!!!!!!!!!!!!!!'."\n"; |
1673 | - if (isset($globalTracker) && $globalTracker) $send = $TI->add($data); |
|
2331 | + if (isset($globalTracker) && $globalTracker) { |
|
2332 | + $send = $TI->add($data); |
|
2333 | + } |
|
1674 | 2334 | } elseif (!isset($line['stealth']) && is_numeric($data['latitude']) && is_numeric($data['longitude']) && isset($data['ident']) && isset($data['altitude'])) { |
1675 | - if (!isset($data['altitude'])) $data['altitude'] = 0; |
|
2335 | + if (!isset($data['altitude'])) { |
|
2336 | + $data['altitude'] = 0; |
|
2337 | + } |
|
1676 | 2338 | $Source->deleteOldLocationByType('gs'); |
1677 | 2339 | if (count($Source->getLocationInfoByNameType($data['ident'],'gs')) > 0) { |
1678 | 2340 | $Source->updateLocation($data['ident'],$data['latitude'],$data['longitude'],$data['altitude'],'','',$data['source_name'],'antenna.png','gs',$id,0,$data['datetime']); |
@@ -1681,7 +2343,9 @@ discard block |
||
1681 | 2343 | } |
1682 | 2344 | } elseif (isset($line['symbol']) && $line['symbol'] == 'Weather Station') { |
1683 | 2345 | //if ($globalDebug) echo '!! Weather Station not yet supported'."\n"; |
1684 | - if ($globalDebug) echo '# Weather Station added'."\n"; |
|
2346 | + if ($globalDebug) { |
|
2347 | + echo '# Weather Station added'."\n"; |
|
2348 | + } |
|
1685 | 2349 | $Source->deleteOldLocationByType('wx'); |
1686 | 2350 | $weather_data = json_encode($line); |
1687 | 2351 | if (count($Source->getLocationInfoByNameType($data['ident'],'wx')) > 0) { |
@@ -1691,7 +2355,9 @@ discard block |
||
1691 | 2355 | } |
1692 | 2356 | } elseif (isset($line['symbol']) && ($line['symbol'] == 'Lightning' || $line['symbol'] == 'Thunderstorm')) { |
1693 | 2357 | //if ($globalDebug) echo '!! Weather Station not yet supported'."\n"; |
1694 | - if ($globalDebug) echo '☈ Lightning added'."\n"; |
|
2358 | + if ($globalDebug) { |
|
2359 | + echo '☈ Lightning added'."\n"; |
|
2360 | + } |
|
1695 | 2361 | $Source->deleteOldLocationByType('lightning'); |
1696 | 2362 | if (count($Source->getLocationInfoByNameType($data['ident'],'lightning')) > 0) { |
1697 | 2363 | $Source->updateLocation($data['ident'],$data['latitude'],$data['longitude'],0,'','',$data['source_name'],'weather/thunderstorm.png','lightning',$id,0,$data['datetime'],$data['comment']); |
@@ -1703,8 +2369,7 @@ discard block |
||
1703 | 2369 | print_r($line); |
1704 | 2370 | } |
1705 | 2371 | unset($data); |
1706 | - } |
|
1707 | - elseif (is_array($line) && isset($line['ident']) && $line['ident'] != '') { |
|
2372 | + } elseif (is_array($line) && isset($line['ident']) && $line['ident'] != '') { |
|
1708 | 2373 | $Source->updateLocationDescByName($line['ident'],$line['source'],$id,$line['comment']); |
1709 | 2374 | } |
1710 | 2375 | /* |
@@ -1713,7 +2378,9 @@ discard block |
||
1713 | 2378 | } |
1714 | 2379 | */ |
1715 | 2380 | //elseif ($line == false && $globalDebug) echo 'Ignored ('.$buffer.")\n"; |
1716 | - elseif ($line == true && $globalDebug) echo '!! Failed : '.$buffer."!!\n"; |
|
2381 | + elseif ($line == true && $globalDebug) { |
|
2382 | + echo '!! Failed : '.$buffer."!!\n"; |
|
2383 | + } |
|
1717 | 2384 | if (isset($globalSources[$nb]['last_weather_clean']) && time()-$globalSources[$nb]['last_weather_clean'] > 60*5) { |
1718 | 2385 | $Source->deleteOldLocationByType('lightning'); |
1719 | 2386 | $Source->deleteOldLocationByType('wx'); |
@@ -1749,26 +2416,45 @@ discard block |
||
1749 | 2416 | $data['ground'] = $line[21]; |
1750 | 2417 | $data['emergency'] = $line[19]; |
1751 | 2418 | $data['format_source'] = 'sbs'; |
1752 | - if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') $data['source_name'] = $globalSources[$nb]['name']; |
|
1753 | - if (isset($globalSources[$nb]['sourcestats'])) $data['sourcestats'] = $globalSources[$nb]['sourcestats']; |
|
1754 | - if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) $data['noarchive'] = true; |
|
2419 | + if (isset($globalSources[$nb]['name']) && $globalSources[$nb]['name'] != '') { |
|
2420 | + $data['source_name'] = $globalSources[$nb]['name']; |
|
2421 | + } |
|
2422 | + if (isset($globalSources[$nb]['sourcestats'])) { |
|
2423 | + $data['sourcestats'] = $globalSources[$nb]['sourcestats']; |
|
2424 | + } |
|
2425 | + if (isset($globalSources[$nb]['noarchive']) && $globalSources[$nb]['noarchive'] === TRUE) { |
|
2426 | + $data['noarchive'] = true; |
|
2427 | + } |
|
1755 | 2428 | $data['id_source'] = $id_source; |
1756 | - if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) $send = $SI->add($data); |
|
1757 | - else $error = true; |
|
2429 | + if (($data['latitude'] == '' && $data['longitude'] == '') || (is_numeric($data['latitude']) && is_numeric($data['longitude']))) { |
|
2430 | + $send = $SI->add($data); |
|
2431 | + } else { |
|
2432 | + $error = true; |
|
2433 | + } |
|
1758 | 2434 | unset($data); |
1759 | - } else $error = true; |
|
2435 | + } else { |
|
2436 | + $error = true; |
|
2437 | + } |
|
1760 | 2438 | if ($error) { |
1761 | 2439 | if (count($line) > 1 && ($line[0] == 'STA' || $line[0] == 'AIR' || $line[0] == 'SEL' || $line[0] == 'ID' || $line[0] == 'CLK')) { |
1762 | - if ($globalDebug) echo "Not a message. Ignoring... \n"; |
|
2440 | + if ($globalDebug) { |
|
2441 | + echo "Not a message. Ignoring... \n"; |
|
2442 | + } |
|
1763 | 2443 | } else { |
1764 | - if ($globalDebug) echo "Wrong line format. Ignoring... \n"; |
|
2444 | + if ($globalDebug) { |
|
2445 | + echo "Wrong line format. Ignoring... \n"; |
|
2446 | + } |
|
1765 | 2447 | if ($globalDebug) { |
1766 | 2448 | echo $buffer; |
1767 | 2449 | //print_r($line); |
1768 | 2450 | } |
1769 | 2451 | //socket_close($r); |
1770 | - if ($globalDebug) echo "Reconnect after an error...\n"; |
|
1771 | - if ($format == 'aprs') $aprs_connect = 0; |
|
2452 | + if ($globalDebug) { |
|
2453 | + echo "Reconnect after an error...\n"; |
|
2454 | + } |
|
2455 | + if ($format == 'aprs') { |
|
2456 | + $aprs_connect = 0; |
|
2457 | + } |
|
1772 | 2458 | $sourceer[$nb] = $globalSources[$nb]; |
1773 | 2459 | connect_all($sourceer); |
1774 | 2460 | $sourceer = array(); |
@@ -1776,10 +2462,14 @@ discard block |
||
1776 | 2462 | } |
1777 | 2463 | } |
1778 | 2464 | // Sleep for xxx microseconds |
1779 | - if (isset($globalSBSSleep)) usleep($globalSBSSleep); |
|
2465 | + if (isset($globalSBSSleep)) { |
|
2466 | + usleep($globalSBSSleep); |
|
2467 | + } |
|
1780 | 2468 | } else { |
1781 | 2469 | if ($format == 'flightgearmp') { |
1782 | - if ($globalDebug) echo "Reconnect FlightGear MP..."; |
|
2470 | + if ($globalDebug) { |
|
2471 | + echo "Reconnect FlightGear MP..."; |
|
2472 | + } |
|
1783 | 2473 | //@socket_close($r); |
1784 | 2474 | sleep($globalMinFetch); |
1785 | 2475 | $sourcefg[$nb] = $globalSources[$nb]; |
@@ -1788,10 +2478,15 @@ discard block |
||
1788 | 2478 | break; |
1789 | 2479 | |
1790 | 2480 | } elseif ($format != 'acars' && $format != 'flightgearsp') { |
1791 | - if (isset($tt[$format])) $tt[$format]++; |
|
1792 | - else $tt[$format] = 0; |
|
2481 | + if (isset($tt[$format])) { |
|
2482 | + $tt[$format]++; |
|
2483 | + } else { |
|
2484 | + $tt[$format] = 0; |
|
2485 | + } |
|
1793 | 2486 | if ($tt[$format] > 30 || $buffer === FALSE) { |
1794 | - if ($globalDebug) echo "ERROR : Reconnect ".$format."..."; |
|
2487 | + if ($globalDebug) { |
|
2488 | + echo "ERROR : Reconnect ".$format."..."; |
|
2489 | + } |
|
1795 | 2490 | //@socket_close($r); |
1796 | 2491 | sleep(2); |
1797 | 2492 | $aprs_connect = 0; |
@@ -1809,11 +2504,17 @@ discard block |
||
1809 | 2504 | } else { |
1810 | 2505 | $error = socket_strerror(socket_last_error()); |
1811 | 2506 | if (($error != SOCKET_EINPROGRESS && $error != SOCKET_EALREADY && $error != 'Success') || (time() - $time >= $timeout && $error != 'Success')) { |
1812 | - if ($globalDebug) echo "ERROR : socket_select give this error ".$error . "\n"; |
|
1813 | - if (isset($globalDebug)) echo "Restarting...\n"; |
|
2507 | + if ($globalDebug) { |
|
2508 | + echo "ERROR : socket_select give this error ".$error . "\n"; |
|
2509 | + } |
|
2510 | + if (isset($globalDebug)) { |
|
2511 | + echo "Restarting...\n"; |
|
2512 | + } |
|
1814 | 2513 | // Restart the script if possible |
1815 | 2514 | if (is_array($sockets)) { |
1816 | - if ($globalDebug) echo "Shutdown all sockets..."; |
|
2515 | + if ($globalDebug) { |
|
2516 | + echo "Shutdown all sockets..."; |
|
2517 | + } |
|
1817 | 2518 | |
1818 | 2519 | foreach ($sockets as $sock) { |
1819 | 2520 | @socket_shutdown($sock,2); |
@@ -1821,25 +2522,45 @@ discard block |
||
1821 | 2522 | } |
1822 | 2523 | |
1823 | 2524 | } |
1824 | - if ($globalDebug) echo "Waiting..."; |
|
2525 | + if ($globalDebug) { |
|
2526 | + echo "Waiting..."; |
|
2527 | + } |
|
1825 | 2528 | sleep(2); |
1826 | 2529 | $time = time(); |
1827 | 2530 | //connect_all($hosts); |
1828 | 2531 | $aprs_connect = 0; |
1829 | - if ($reset%5 == 0) sleep(20); |
|
1830 | - if ($reset%10 == 0) sleep(100); |
|
1831 | - if ($reset%20 == 0) sleep(200); |
|
1832 | - if ($reset > 100) exit('Too many attempts...'); |
|
1833 | - if ($globalDebug) echo "Restart all connections..."; |
|
2532 | + if ($reset%5 == 0) { |
|
2533 | + sleep(20); |
|
2534 | + } |
|
2535 | + if ($reset%10 == 0) { |
|
2536 | + sleep(100); |
|
2537 | + } |
|
2538 | + if ($reset%20 == 0) { |
|
2539 | + sleep(200); |
|
2540 | + } |
|
2541 | + if ($reset > 100) { |
|
2542 | + exit('Too many attempts...'); |
|
2543 | + } |
|
2544 | + if ($globalDebug) { |
|
2545 | + echo "Restart all connections..."; |
|
2546 | + } |
|
1834 | 2547 | connect_all($globalSources); |
1835 | 2548 | } |
1836 | 2549 | } |
1837 | 2550 | } |
1838 | 2551 | if ($globalDaemon === false) { |
1839 | - if ($globalDebug) echo 'Check all...'."\n"; |
|
1840 | - if (isset($SI)) $SI->checkAll(); |
|
1841 | - if (isset($TI)) $TI->checkAll(); |
|
1842 | - if (isset($MI)) $MI->checkAll(); |
|
2552 | + if ($globalDebug) { |
|
2553 | + echo 'Check all...'."\n"; |
|
2554 | + } |
|
2555 | + if (isset($SI)) { |
|
2556 | + $SI->checkAll(); |
|
2557 | + } |
|
2558 | + if (isset($TI)) { |
|
2559 | + $TI->checkAll(); |
|
2560 | + } |
|
2561 | + if (isset($MI)) { |
|
2562 | + $MI->checkAll(); |
|
2563 | + } |
|
1843 | 2564 | } |
1844 | 2565 | } |
1845 | 2566 | } |
@@ -9,25 +9,25 @@ discard block |
||
9 | 9 | require_once(dirname(__FILE__).'/class.Stats.php'); |
10 | 10 | require_once(dirname(__FILE__).'/class.Source.php'); |
11 | 11 | if (isset($globalServerAPRS) && $globalServerAPRS) { |
12 | - require_once(dirname(__FILE__).'/class.APRS.php'); |
|
12 | + require_once(dirname(__FILE__).'/class.APRS.php'); |
|
13 | 13 | } |
14 | 14 | |
15 | 15 | class MarineImport { |
16 | - private $all_tracked = array(); |
|
17 | - private $last_delete_hourly = 0; |
|
18 | - private $last_delete = 0; |
|
19 | - private $stats = array(); |
|
20 | - private $tmd = 0; |
|
21 | - private $source_location = array(); |
|
22 | - public $db = null; |
|
23 | - public $nb = 0; |
|
16 | + private $all_tracked = array(); |
|
17 | + private $last_delete_hourly = 0; |
|
18 | + private $last_delete = 0; |
|
19 | + private $stats = array(); |
|
20 | + private $tmd = 0; |
|
21 | + private $source_location = array(); |
|
22 | + public $db = null; |
|
23 | + public $nb = 0; |
|
24 | 24 | |
25 | - public function __construct($dbc = null) { |
|
25 | + public function __construct($dbc = null) { |
|
26 | 26 | global $globalBeta, $globalServerAPRS, $APRSMarine, $globalNoDB; |
27 | 27 | if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
28 | - $Connection = new Connection($dbc); |
|
29 | - $this->db = $Connection->db(); |
|
30 | - date_default_timezone_set('UTC'); |
|
28 | + $Connection = new Connection($dbc); |
|
29 | + $this->db = $Connection->db(); |
|
30 | + date_default_timezone_set('UTC'); |
|
31 | 31 | } |
32 | 32 | // Get previous source stats |
33 | 33 | /* |
@@ -46,57 +46,57 @@ discard block |
||
46 | 46 | } |
47 | 47 | */ |
48 | 48 | if (isset($globalServerAPRS) && $globalServerAPRS) { |
49 | - $APRSMarine = new APRSMarine(); |
|
50 | - //$APRSSpotter->connect(); |
|
49 | + $APRSMarine = new APRSMarine(); |
|
50 | + //$APRSSpotter->connect(); |
|
51 | + } |
|
51 | 52 | } |
52 | - } |
|
53 | 53 | |
54 | - public function checkAll() { |
|
54 | + public function checkAll() { |
|
55 | 55 | global $globalDebug, $globalNoDB; |
56 | 56 | if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
57 | - if ($globalDebug) echo "Update last seen tracked data...\n"; |
|
58 | - foreach ($this->all_tracked as $key => $flight) { |
|
57 | + if ($globalDebug) echo "Update last seen tracked data...\n"; |
|
58 | + foreach ($this->all_tracked as $key => $flight) { |
|
59 | 59 | if (isset($this->all_tracked[$key]['id'])) { |
60 | - //echo $this->all_tracked[$key]['id'].' - '.$this->all_tracked[$key]['latitude'].' '.$this->all_tracked[$key]['longitude']."\n"; |
|
61 | - $Marine = new Marine($this->db); |
|
62 | - $Marine->updateLatestMarineData($this->all_tracked[$key]['id'],$this->all_tracked[$key]['ident'],$this->all_tracked[$key]['latitude'],$this->all_tracked[$key]['longitude'],$this->all_tracked[$key]['speed'],$this->all_tracked[$key]['datetime']); |
|
60 | + //echo $this->all_tracked[$key]['id'].' - '.$this->all_tracked[$key]['latitude'].' '.$this->all_tracked[$key]['longitude']."\n"; |
|
61 | + $Marine = new Marine($this->db); |
|
62 | + $Marine->updateLatestMarineData($this->all_tracked[$key]['id'],$this->all_tracked[$key]['ident'],$this->all_tracked[$key]['latitude'],$this->all_tracked[$key]['longitude'],$this->all_tracked[$key]['speed'],$this->all_tracked[$key]['datetime']); |
|
63 | + } |
|
63 | 64 | } |
64 | - } |
|
65 | 65 | } |
66 | - } |
|
66 | + } |
|
67 | 67 | |
68 | - public function del() { |
|
68 | + public function del() { |
|
69 | 69 | global $globalDebug, $globalNoDB, $globalNoImport; |
70 | 70 | // Delete old infos |
71 | 71 | if ($globalDebug) echo 'Delete old values and update latest data...'."\n"; |
72 | 72 | foreach ($this->all_tracked as $key => $flight) { |
73 | - if (isset($flight['lastupdate'])) { |
|
74 | - if ($flight['lastupdate'] < (time()-3000)) { |
|
75 | - if ((!isset($globalNoImport) || $globalNoImport !== TRUE) && (!isset($globalNoDB) || $globalNoDB !== TRUE)) { |
|
76 | - if (isset($this->all_tracked[$key]['id'])) { |
|
77 | - if ($globalDebug) echo "--- Delete old values with id ".$this->all_tracked[$key]['id']."\n"; |
|
78 | - /* |
|
73 | + if (isset($flight['lastupdate'])) { |
|
74 | + if ($flight['lastupdate'] < (time()-3000)) { |
|
75 | + if ((!isset($globalNoImport) || $globalNoImport !== TRUE) && (!isset($globalNoDB) || $globalNoDB !== TRUE)) { |
|
76 | + if (isset($this->all_tracked[$key]['id'])) { |
|
77 | + if ($globalDebug) echo "--- Delete old values with id ".$this->all_tracked[$key]['id']."\n"; |
|
78 | + /* |
|
79 | 79 | $MarineLive = new MarineLive(); |
80 | 80 | $MarineLive->deleteLiveMarineDataById($this->all_tracked[$key]['id']); |
81 | 81 | $MarineLive->db = null; |
82 | 82 | */ |
83 | - //$real_arrival = $this->arrival($key); |
|
84 | - $Marine = new Marine($this->db); |
|
85 | - if ($this->all_tracked[$key]['latitude'] != '' && $this->all_tracked[$key]['longitude'] != '') { |
|
83 | + //$real_arrival = $this->arrival($key); |
|
84 | + $Marine = new Marine($this->db); |
|
85 | + if ($this->all_tracked[$key]['latitude'] != '' && $this->all_tracked[$key]['longitude'] != '') { |
|
86 | 86 | $result = $Marine->updateLatestMarineData($this->all_tracked[$key]['id'],$this->all_tracked[$key]['ident'],$this->all_tracked[$key]['latitude'],$this->all_tracked[$key]['longitude'],$this->all_tracked[$key]['speed'],$this->all_tracked[$key]['datetime']); |
87 | 87 | if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n"; |
88 | - } |
|
89 | - // Put in archive |
|
88 | + } |
|
89 | + // Put in archive |
|
90 | 90 | // $Marine->db = null; |
91 | 91 | } |
92 | - } |
|
93 | - unset($this->all_tracked[$key]); |
|
94 | - } |
|
95 | - } |
|
96 | - } |
|
97 | - } |
|
92 | + } |
|
93 | + unset($this->all_tracked[$key]); |
|
94 | + } |
|
95 | + } |
|
96 | + } |
|
97 | + } |
|
98 | 98 | |
99 | - public function add($line) { |
|
99 | + public function add($line) { |
|
100 | 100 | global $globalFork, $globalDistanceIgnore, $globalDaemon, $globalDebug, $globalCoordMinChange, $globalDebugTimeElapsed, $globalCenterLatitude, $globalCenterLongitude, $globalBeta, $globalSourcesupdate, $globalAllTracked, $globalNoImport, $globalNoDB, $globalServerAPRS,$APRSMarine; |
101 | 101 | if (!isset($globalCoordMinChange) || $globalCoordMinChange == '') $globalCoordMinChange = '0.02'; |
102 | 102 | date_default_timezone_set('UTC'); |
@@ -105,104 +105,104 @@ discard block |
||
105 | 105 | |
106 | 106 | // SBS format is CSV format |
107 | 107 | if(is_array($line) && isset($line['mmsi'])) { |
108 | - //print_r($line); |
|
109 | - if (isset($line['mmsi'])) { |
|
108 | + //print_r($line); |
|
109 | + if (isset($line['mmsi'])) { |
|
110 | 110 | |
111 | 111 | |
112 | 112 | // Increment message number |
113 | 113 | if (isset($line['sourcestats']) && $line['sourcestats'] == TRUE) { |
114 | - $current_date = date('Y-m-d'); |
|
115 | - if (isset($line['source_name'])) $source = $line['source_name']; |
|
116 | - else $source = ''; |
|
117 | - if ($source == '' || $line['format_source'] == 'aprs') $source = $line['format_source']; |
|
118 | - if (!isset($this->stats[$current_date][$source]['msg'])) { |
|
119 | - $this->stats[$current_date][$source]['msg']['date'] = time(); |
|
120 | - $this->stats[$current_date][$source]['msg']['nb'] = 1; |
|
121 | - } else $this->stats[$current_date][$source]['msg']['nb'] += 1; |
|
114 | + $current_date = date('Y-m-d'); |
|
115 | + if (isset($line['source_name'])) $source = $line['source_name']; |
|
116 | + else $source = ''; |
|
117 | + if ($source == '' || $line['format_source'] == 'aprs') $source = $line['format_source']; |
|
118 | + if (!isset($this->stats[$current_date][$source]['msg'])) { |
|
119 | + $this->stats[$current_date][$source]['msg']['date'] = time(); |
|
120 | + $this->stats[$current_date][$source]['msg']['nb'] = 1; |
|
121 | + } else $this->stats[$current_date][$source]['msg']['nb'] += 1; |
|
122 | 122 | } |
123 | 123 | |
124 | 124 | |
125 | 125 | $Common = new Common(); |
126 | 126 | $AIS = new AIS(); |
127 | - if (!isset($line['id'])) $id = trim($line['mmsi']); |
|
128 | - else $id = trim($line['id']); |
|
127 | + if (!isset($line['id'])) $id = trim($line['mmsi']); |
|
128 | + else $id = trim($line['id']); |
|
129 | 129 | |
130 | 130 | if (!isset($this->all_tracked[$id])) { |
131 | - $this->all_tracked[$id] = array(); |
|
132 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('addedMarine' => 0)); |
|
133 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('ident' => '','latitude' => '', 'longitude' => '', 'speed' => '0', 'heading' => '', 'format_source' => '','source_name' => '','comment'=> '','type' => '','typeid' => '','noarchive' => false,'putinarchive' => true,'over_country' => '','mmsi' => '','status' => '','status_id' => '','imo' => '','callsign' => '','arrival_code' => '','arrival_date' => '','mmsi_type' => '')); |
|
134 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('lastupdate' => time())); |
|
135 | - if (!isset($line['id'])) { |
|
131 | + $this->all_tracked[$id] = array(); |
|
132 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('addedMarine' => 0)); |
|
133 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('ident' => '','latitude' => '', 'longitude' => '', 'speed' => '0', 'heading' => '', 'format_source' => '','source_name' => '','comment'=> '','type' => '','typeid' => '','noarchive' => false,'putinarchive' => true,'over_country' => '','mmsi' => '','status' => '','status_id' => '','imo' => '','callsign' => '','arrival_code' => '','arrival_date' => '','mmsi_type' => '')); |
|
134 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('lastupdate' => time())); |
|
135 | + if (!isset($line['id'])) { |
|
136 | 136 | if (!isset($globalDaemon)) $globalDaemon = TRUE; |
137 | 137 | $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $id.'-'.date('YmdHi'))); |
138 | - } else $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $line['id'])); |
|
139 | - if ($globalAllTracked !== FALSE) $dataFound = true; |
|
138 | + } else $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $line['id'])); |
|
139 | + if ($globalAllTracked !== FALSE) $dataFound = true; |
|
140 | 140 | } |
141 | 141 | |
142 | 142 | if (isset($line['mmsi']) && $line['mmsi'] != '' && $line['mmsi'] != $this->all_tracked[$id]['mmsi']) { |
143 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('mmsi' => $line['mmsi'])); |
|
144 | - if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
|
143 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('mmsi' => $line['mmsi'])); |
|
144 | + if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
|
145 | 145 | $Marine = new Marine($this->db); |
146 | 146 | $identity = $Marine->getIdentity($line['mmsi']); |
147 | 147 | if (!empty($identity)) { |
148 | - $this->all_tracked[$id]['ident'] = $identity['ship_name']; |
|
149 | - $this->all_tracked[$id]['type'] = $identity['type']; |
|
150 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('typeid' => $AIS->getShipTypeID($identity['type']))); |
|
148 | + $this->all_tracked[$id]['ident'] = $identity['ship_name']; |
|
149 | + $this->all_tracked[$id]['type'] = $identity['type']; |
|
150 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('typeid' => $AIS->getShipTypeID($identity['type']))); |
|
151 | 151 | } |
152 | 152 | //print_r($identity); |
153 | 153 | unset($Marine); |
154 | 154 | //$dataFound = true; |
155 | - } |
|
155 | + } |
|
156 | 156 | } |
157 | 157 | if (isset($line['type_id'])) { |
158 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('type' => $AIS->getShipType($line['type_id']))); |
|
159 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('typeid' => $line['type_id'])); |
|
158 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('type' => $AIS->getShipType($line['type_id']))); |
|
159 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('typeid' => $line['type_id'])); |
|
160 | 160 | } |
161 | 161 | if (isset($line['type']) && $line['type'] != '' && $this->all_tracked[$id]['type'] == '') { |
162 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('type' => $line['type'])); |
|
163 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('typeid' => $AIS->getShipTypeID($line['type']))); |
|
162 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('type' => $line['type'])); |
|
163 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('typeid' => $AIS->getShipTypeID($line['type']))); |
|
164 | 164 | } |
165 | 165 | if (isset($line['status']) && $line['status'] != '') { |
166 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('status' => $line['status'])); |
|
166 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('status' => $line['status'])); |
|
167 | 167 | } |
168 | 168 | if (isset($line['status_id']) && (!isset($this->all_tracked[$id]['status_id']) || $this->all_tracked[$id]['status_id'] != $line['status_id'])) { |
169 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('status_id' => $line['status_id'])); |
|
170 | - if ($this->all_tracked[$id]['addedMarine'] == 1) { |
|
169 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('status_id' => $line['status_id'])); |
|
170 | + if ($this->all_tracked[$id]['addedMarine'] == 1) { |
|
171 | 171 | if (!isset($globalNoImport) || $globalNoImport !== TRUE) { |
172 | - if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
|
172 | + if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
|
173 | 173 | $Marine = new Marine($this->db); |
174 | 174 | $Marine->updateStatusMarineData($this->all_tracked[$id]['id'],$this->all_tracked[$id]['status_id'],$this->all_tracked[$id]['status']); |
175 | 175 | unset($Marine); |
176 | - } |
|
176 | + } |
|
177 | + } |
|
177 | 178 | } |
178 | - } |
|
179 | 179 | } |
180 | 180 | |
181 | 181 | |
182 | 182 | if (isset($line['mmsi_type']) && $line['mmsi_type'] != '') { |
183 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('mmsi_type' => $line['mmsi_type'])); |
|
183 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('mmsi_type' => $line['mmsi_type'])); |
|
184 | 184 | } |
185 | 185 | if (isset($line['imo']) && $line['imo'] != '') { |
186 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('imo' => $line['imo'])); |
|
186 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('imo' => $line['imo'])); |
|
187 | 187 | } |
188 | 188 | if (isset($line['callsign']) && $line['callsign'] != '') { |
189 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('callsign' => $line['callsign'])); |
|
189 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('callsign' => $line['callsign'])); |
|
190 | 190 | } |
191 | 191 | if (isset($line['arrival_code']) && $line['arrival_code'] != '') { |
192 | - if (!isset($this->all_tracked[$id]['arrival_code'])) { |
|
192 | + if (!isset($this->all_tracked[$id]['arrival_code'])) { |
|
193 | 193 | $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('arrival_code' => $line['arrival_code'])); |
194 | 194 | if ($globalDebug) echo $this->all_tracked[$id]['id'].' => New arrival: '.$line['arrival_code']."\n"; |
195 | 195 | if ($this->all_tracked[$id]['addedMarine'] != 0) { |
196 | - if (!isset($globalNoImport) || $globalNoImport !== TRUE) { |
|
196 | + if (!isset($globalNoImport) || $globalNoImport !== TRUE) { |
|
197 | 197 | if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
198 | - $Marine = new Marine($this->db); |
|
199 | - $fromsource = NULL; |
|
200 | - $Marine->updateArrivalPortNameMarineData($this->all_tracked[$id]['id'],$this->all_tracked[$id]['arrival_code'],$fromsource); |
|
201 | - $Marine->db = null; |
|
198 | + $Marine = new Marine($this->db); |
|
199 | + $fromsource = NULL; |
|
200 | + $Marine->updateArrivalPortNameMarineData($this->all_tracked[$id]['id'],$this->all_tracked[$id]['arrival_code'],$fromsource); |
|
201 | + $Marine->db = null; |
|
202 | + } |
|
202 | 203 | } |
203 | - } |
|
204 | 204 | } |
205 | - } elseif ($this->all_tracked[$id]['arrival_code'] != $line['arrival_code']) { |
|
205 | + } elseif ($this->all_tracked[$id]['arrival_code'] != $line['arrival_code']) { |
|
206 | 206 | $this->all_tracked[$id]['arrival_code'] = $line['arrival_code']; |
207 | 207 | if ($globalDebug) echo $this->all_tracked[$id]['id'].' => New arrival: '.$line['arrival_code']."\n"; |
208 | 208 | if (!isset($line['id'])) { |
@@ -210,26 +210,26 @@ discard block |
||
210 | 210 | $this->all_tracked[$id]['forcenew'] = 1; |
211 | 211 | $this->all_tracked[$id]['addedMarine'] = 0; |
212 | 212 | } |
213 | - } |
|
213 | + } |
|
214 | 214 | } |
215 | 215 | if (isset($line['arrival_date']) && $line['arrival_date'] != '') { |
216 | - if (strtotime($line['arrival_date']) > time()) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('arrival_date' => $line['arrival_date'])); |
|
216 | + if (strtotime($line['arrival_date']) > time()) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('arrival_date' => $line['arrival_date'])); |
|
217 | 217 | } |
218 | 218 | |
219 | 219 | //if (isset($line['ident']) && $line['ident'] != '' && $line['ident'] != '????????' && $line['ident'] != '00000000' && ($this->all_tracked[$id]['ident'] != trim($line['ident'])) && preg_match('/^[a-zA-Z0-9-]+$/', $line['ident'])) { |
220 | 220 | if (isset($line['ident']) && $line['ident'] != '' && $line['ident'] != '????????' && $line['ident'] != '00000000' && ($this->all_tracked[$id]['ident'] != trim($line['ident']))) { |
221 | - if (!isset($globalNoImport) || $globalNoImport !== TRUE) { |
|
221 | + if (!isset($globalNoImport) || $globalNoImport !== TRUE) { |
|
222 | 222 | if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
223 | - $timeelapsed = microtime(true); |
|
224 | - $Marine = new Marine($this->db); |
|
225 | - $Marine->addIdentity($this->all_tracked[$id]['mmsi'],$this->all_tracked[$id]['imo'],$this->all_tracked[$id]['ident'],$this->all_tracked[$id]['callsign'],$this->all_tracked[$id]['type']); |
|
226 | - $Marine->db = null; |
|
223 | + $timeelapsed = microtime(true); |
|
224 | + $Marine = new Marine($this->db); |
|
225 | + $Marine->addIdentity($this->all_tracked[$id]['mmsi'],$this->all_tracked[$id]['imo'],$this->all_tracked[$id]['ident'],$this->all_tracked[$id]['callsign'],$this->all_tracked[$id]['type']); |
|
226 | + $Marine->db = null; |
|
227 | + } |
|
227 | 228 | } |
228 | - } |
|
229 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('ident' => trim($line['ident']))); |
|
230 | - if ($this->all_tracked[$id]['addedMarine'] == 1) { |
|
229 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('ident' => trim($line['ident']))); |
|
230 | + if ($this->all_tracked[$id]['addedMarine'] == 1) { |
|
231 | 231 | if (!isset($globalNoImport) || $globalNoImport !== TRUE) { |
232 | - if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
|
232 | + if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
|
233 | 233 | $timeelapsed = microtime(true); |
234 | 234 | $Marine = new Marine($this->db); |
235 | 235 | $fromsource = NULL; |
@@ -237,20 +237,20 @@ discard block |
||
237 | 237 | if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n"; |
238 | 238 | $Marine->db = null; |
239 | 239 | if ($globalDebugTimeElapsed) echo 'Time elapsed for update identspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
240 | - } |
|
240 | + } |
|
241 | + } |
|
241 | 242 | } |
242 | - } |
|
243 | - if (!isset($this->all_tracked[$id]['id'])) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $this->all_tracked[$id]['ident'])); |
|
243 | + if (!isset($this->all_tracked[$id]['id'])) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $this->all_tracked[$id]['ident'])); |
|
244 | 244 | } |
245 | 245 | |
246 | 246 | if (isset($line['datetime']) && strtotime($line['datetime']) > time()-30*60 && strtotime($line['datetime']) < time()+20*60) { |
247 | - if (!isset($this->all_tracked[$id]['datetime']) || strtotime($line['datetime']) > strtotime($this->all_tracked[$id]['datetime'])) { |
|
247 | + if (!isset($this->all_tracked[$id]['datetime']) || strtotime($line['datetime']) > strtotime($this->all_tracked[$id]['datetime'])) { |
|
248 | 248 | $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('datetime' => $line['datetime'])); |
249 | - } else { |
|
249 | + } else { |
|
250 | 250 | if (strtotime($line['datetime']) == strtotime($this->all_tracked[$id]['datetime']) && $globalDebug) echo "!!! Date is the same as previous data for ".$this->all_tracked[$id]['mmsi']."\n"; |
251 | 251 | elseif (strtotime($line['datetime']) > strtotime($this->all_tracked[$id]['datetime']) && $globalDebug) echo "!!! Date previous latest data (".$line['datetime']." > ".$this->all_tracked[$id]['datetime'].") !!! for ".$this->all_tracked[$id]['hex']." - format : ".$line['format_source']."\n"; |
252 | 252 | return ''; |
253 | - } |
|
253 | + } |
|
254 | 254 | } elseif (isset($line['datetime']) && strtotime($line['datetime']) <= time()-30*60) { |
255 | 255 | if ($globalDebug) echo "!!! Date is too old ".$this->all_tracked[$id]['mmsi']." - format : ".$line['format_source']."!!!\n"; |
256 | 256 | return ''; |
@@ -267,24 +267,24 @@ discard block |
||
267 | 267 | |
268 | 268 | |
269 | 269 | if (isset($line['speed'])) { |
270 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed' => round($line['speed']))); |
|
271 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed_fromsrc' => true)); |
|
270 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed' => round($line['speed']))); |
|
271 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed_fromsrc' => true)); |
|
272 | 272 | } else if (!isset($this->all_tracked[$id]['speed_fromsrc']) && isset($this->all_tracked[$id]['time_last_coord']) && $this->all_tracked[$id]['time_last_coord'] != time() && isset($line['latitude']) && isset($line['longitude'])) { |
273 | - $distance = $Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m'); |
|
274 | - if ($distance > 1000 && $distance < 10000) { |
|
273 | + $distance = $Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m'); |
|
274 | + if ($distance > 1000 && $distance < 10000) { |
|
275 | 275 | $speed = $distance/(time() - $this->all_tracked[$id]['time_last_coord']); |
276 | 276 | $speed = $speed*3.6; |
277 | 277 | if ($speed < 1000) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed' => round($speed))); |
278 | 278 | if ($globalDebug) echo "ø Calculated Speed for ".$this->all_tracked[$id]['hex']." : ".$speed." - distance : ".$distance."\n"; |
279 | - } |
|
279 | + } |
|
280 | 280 | } |
281 | 281 | |
282 | - if (isset($line['latitude']) && isset($line['longitude']) && $line['latitude'] != '' && $line['longitude'] != '' && is_numeric($line['latitude']) && is_numeric($line['longitude'])) { |
|
283 | - if (isset($this->all_tracked[$id]['time_last_coord'])) $timediff = round(time()-$this->all_tracked[$id]['time_last_coord']); |
|
284 | - else unset($timediff); |
|
285 | - if ($this->tmd > 5 || !isset($timediff) || $timediff > 2000 || ($timediff > 30 && isset($this->all_tracked[$id]['latitude']) && isset($this->all_tracked[$id]['longitude']) && $Common->withinThreshold($timediff,$Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m')))) { |
|
282 | + if (isset($line['latitude']) && isset($line['longitude']) && $line['latitude'] != '' && $line['longitude'] != '' && is_numeric($line['latitude']) && is_numeric($line['longitude'])) { |
|
283 | + if (isset($this->all_tracked[$id]['time_last_coord'])) $timediff = round(time()-$this->all_tracked[$id]['time_last_coord']); |
|
284 | + else unset($timediff); |
|
285 | + if ($this->tmd > 5 || !isset($timediff) || $timediff > 2000 || ($timediff > 30 && isset($this->all_tracked[$id]['latitude']) && isset($this->all_tracked[$id]['longitude']) && $Common->withinThreshold($timediff,$Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m')))) { |
|
286 | 286 | if (isset($this->all_tracked[$id]['archive_latitude']) && isset($this->all_tracked[$id]['archive_longitude']) && isset($this->all_tracked[$id]['livedb_latitude']) && isset($this->all_tracked[$id]['livedb_longitude'])) { |
287 | - if (!$Common->checkLine($this->all_tracked[$id]['archive_latitude'],$this->all_tracked[$id]['archive_longitude'],$this->all_tracked[$id]['livedb_latitude'],$this->all_tracked[$id]['livedb_longitude'],$line['latitude'],$line['longitude'])) { |
|
287 | + if (!$Common->checkLine($this->all_tracked[$id]['archive_latitude'],$this->all_tracked[$id]['archive_longitude'],$this->all_tracked[$id]['livedb_latitude'],$this->all_tracked[$id]['livedb_longitude'],$line['latitude'],$line['longitude'])) { |
|
288 | 288 | $this->all_tracked[$id]['archive_latitude'] = $line['latitude']; |
289 | 289 | $this->all_tracked[$id]['archive_longitude'] = $line['longitude']; |
290 | 290 | $this->all_tracked[$id]['putinarchive'] = true; |
@@ -292,195 +292,195 @@ discard block |
||
292 | 292 | if ($globalDebug) echo "\n".' ------- Check Country for '.$this->all_tracked[$id]['ident'].' with latitude : '.$line['latitude'].' and longitude : '.$line['longitude'].'.... '; |
293 | 293 | $timeelapsed = microtime(true); |
294 | 294 | if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
295 | - $Marine = new Marine($this->db); |
|
296 | - $all_country = $Marine->getCountryFromLatitudeLongitude($line['latitude'],$line['longitude']); |
|
297 | - if (!empty($all_country)) $this->all_tracked[$id]['over_country'] = $all_country['iso2']; |
|
298 | - $Marine->db = null; |
|
299 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
295 | + $Marine = new Marine($this->db); |
|
296 | + $all_country = $Marine->getCountryFromLatitudeLongitude($line['latitude'],$line['longitude']); |
|
297 | + if (!empty($all_country)) $this->all_tracked[$id]['over_country'] = $all_country['iso2']; |
|
298 | + $Marine->db = null; |
|
299 | + if ($globalDebugTimeElapsed) echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
300 | 300 | } |
301 | 301 | $this->tmd = 0; |
302 | 302 | if ($globalDebug) echo 'FOUND : '.$this->all_tracked[$id]['over_country'].' ---------------'."\n"; |
303 | - } |
|
303 | + } |
|
304 | 304 | } |
305 | 305 | |
306 | 306 | if (isset($line['latitude']) && $line['latitude'] != '' && $line['latitude'] != 0 && $line['latitude'] < 91 && $line['latitude'] > -90) { |
307 | 307 | if (!isset($this->all_tracked[$id]['archive_latitude'])) $this->all_tracked[$id]['archive_latitude'] = $line['latitude']; |
308 | 308 | if (!isset($this->all_tracked[$id]['livedb_latitude']) || abs($this->all_tracked[$id]['livedb_latitude']-$line['latitude']) > $globalCoordMinChange || $this->all_tracked[$id]['format_source'] == 'aprs') { |
309 | - $this->all_tracked[$id]['livedb_latitude'] = $line['latitude']; |
|
310 | - $dataFound = true; |
|
311 | - $this->all_tracked[$id]['time_last_coord'] = time(); |
|
309 | + $this->all_tracked[$id]['livedb_latitude'] = $line['latitude']; |
|
310 | + $dataFound = true; |
|
311 | + $this->all_tracked[$id]['time_last_coord'] = time(); |
|
312 | 312 | } |
313 | 313 | $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('latitude' => $line['latitude'])); |
314 | 314 | } |
315 | 315 | if (isset($line['longitude']) && $line['longitude'] != '' && $line['longitude'] != 0 && $line['longitude'] < 360 && $line['longitude'] > -180) { |
316 | - if ($line['longitude'] > 180) $line['longitude'] = $line['longitude'] - 360; |
|
316 | + if ($line['longitude'] > 180) $line['longitude'] = $line['longitude'] - 360; |
|
317 | 317 | if (!isset($this->all_tracked[$id]['archive_longitude'])) $this->all_tracked[$id]['archive_longitude'] = $line['longitude']; |
318 | 318 | if (!isset($this->all_tracked[$id]['livedb_longitude']) || abs($this->all_tracked[$id]['livedb_longitude']-$line['longitude']) > $globalCoordMinChange || $this->all_tracked[$id]['format_source'] == 'aprs') { |
319 | - $this->all_tracked[$id]['livedb_longitude'] = $line['longitude']; |
|
320 | - $dataFound = true; |
|
321 | - $this->all_tracked[$id]['time_last_coord'] = time(); |
|
319 | + $this->all_tracked[$id]['livedb_longitude'] = $line['longitude']; |
|
320 | + $dataFound = true; |
|
321 | + $this->all_tracked[$id]['time_last_coord'] = time(); |
|
322 | 322 | } |
323 | 323 | $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('longitude' => $line['longitude'])); |
324 | 324 | } |
325 | 325 | |
326 | - } else if ($globalDebug && $timediff > 20) { |
|
326 | + } else if ($globalDebug && $timediff > 20) { |
|
327 | 327 | $this->tmd = $this->tmd + 1; |
328 | 328 | echo '!!! Too much distance in short time... for '.$this->all_tracked[$id]['ident']."\n"; |
329 | 329 | echo 'Time : '.$timediff.'s - Distance : '.$Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m')."m -"; |
330 | 330 | echo 'Speed : '.(($Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m')/$timediff)*3.6)." km/h - "; |
331 | 331 | echo 'Lat : '.$line['latitude'].' - long : '.$line['longitude'].' - prev lat : '.$this->all_tracked[$id]['latitude'].' - prev long : '.$this->all_tracked[$id]['longitude']." \n"; |
332 | - } |
|
332 | + } |
|
333 | 333 | } |
334 | 334 | if (isset($line['last_update']) && $line['last_update'] != '') { |
335 | - if (isset($this->all_tracked[$id]['last_update']) && $this->all_tracked[$id]['last_update'] != $line['last_update']) $dataFound = true; |
|
336 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('last_update' => $line['last_update'])); |
|
335 | + if (isset($this->all_tracked[$id]['last_update']) && $this->all_tracked[$id]['last_update'] != $line['last_update']) $dataFound = true; |
|
336 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('last_update' => $line['last_update'])); |
|
337 | 337 | } |
338 | 338 | if (isset($line['format_source']) && $line['format_source'] != '') { |
339 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('format_source' => $line['format_source'])); |
|
339 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('format_source' => $line['format_source'])); |
|
340 | 340 | } |
341 | 341 | if (isset($line['source_name']) && $line['source_name'] != '') { |
342 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('source_name' => $line['source_name'])); |
|
342 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('source_name' => $line['source_name'])); |
|
343 | 343 | } |
344 | 344 | if (isset($line['noarchive']) && $line['noarchive'] === true) { |
345 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('noarchive' => true)); |
|
345 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('noarchive' => true)); |
|
346 | 346 | } |
347 | 347 | |
348 | 348 | if (isset($line['heading']) && $line['heading'] != '') { |
349 | - if (is_int($this->all_tracked[$id]['heading']) && abs($this->all_tracked[$id]['heading']-round($line['heading'])) > 10) $this->all_tracked[$id]['putinarchive'] = true; |
|
350 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading' => round($line['heading']))); |
|
351 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading_fromsrc' => true)); |
|
352 | - //$dataFound = true; |
|
349 | + if (is_int($this->all_tracked[$id]['heading']) && abs($this->all_tracked[$id]['heading']-round($line['heading'])) > 10) $this->all_tracked[$id]['putinarchive'] = true; |
|
350 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading' => round($line['heading']))); |
|
351 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading_fromsrc' => true)); |
|
352 | + //$dataFound = true; |
|
353 | 353 | } elseif (!isset($this->all_tracked[$id]['heading_fromsrc']) && isset($this->all_tracked[$id]['archive_latitude']) && $this->all_tracked[$id]['archive_latitude'] != $this->all_tracked[$id]['latitude'] && isset($this->all_tracked[$id]['archive_longitude']) && $this->all_tracked[$id]['archive_longitude'] != $this->all_tracked[$id]['longitude']) { |
354 | - $heading = $Common->getHeading($this->all_tracked[$id]['archive_latitude'],$this->all_tracked[$id]['archive_longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude']); |
|
355 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading' => round($heading))); |
|
356 | - if (abs($this->all_tracked[$id]['heading']-round($heading)) > 10) $this->all_tracked[$id]['putinarchive'] = true; |
|
357 | - if ($globalDebug) echo "ø Calculated Heading for ".$this->all_tracked[$id]['ident']." : ".$heading."\n"; |
|
354 | + $heading = $Common->getHeading($this->all_tracked[$id]['archive_latitude'],$this->all_tracked[$id]['archive_longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude']); |
|
355 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading' => round($heading))); |
|
356 | + if (abs($this->all_tracked[$id]['heading']-round($heading)) > 10) $this->all_tracked[$id]['putinarchive'] = true; |
|
357 | + if ($globalDebug) echo "ø Calculated Heading for ".$this->all_tracked[$id]['ident']." : ".$heading."\n"; |
|
358 | 358 | } |
359 | 359 | //if (isset($globalSourcesupdate) && $globalSourcesupdate != '' && isset($this->all_tracked[$id]['lastupdate']) && time()-$this->all_tracked[$id]['lastupdate'] < $globalSourcesupdate) $dataFound = false; |
360 | 360 | |
361 | 361 | |
362 | 362 | |
363 | 363 | if ($dataFound === true && isset($this->all_tracked[$id]['mmsi'])) { |
364 | - $this->all_tracked[$id]['lastupdate'] = time(); |
|
365 | - if ($this->all_tracked[$id]['addedMarine'] == 0) { |
|
366 | - if (!isset($globalDistanceIgnore['latitude']) || $this->all_tracked[$id]['longitude'] == '' || $this->all_tracked[$id]['latitude'] == '' || (isset($globalDistanceIgnore['latitude']) && $Common->distance($this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude']) < $globalDistanceIgnore['distance'])) { |
|
367 | - if (!isset($this->all_tracked[$id]['forcenew']) || $this->all_tracked[$id]['forcenew'] == 0) { |
|
364 | + $this->all_tracked[$id]['lastupdate'] = time(); |
|
365 | + if ($this->all_tracked[$id]['addedMarine'] == 0) { |
|
366 | + if (!isset($globalDistanceIgnore['latitude']) || $this->all_tracked[$id]['longitude'] == '' || $this->all_tracked[$id]['latitude'] == '' || (isset($globalDistanceIgnore['latitude']) && $Common->distance($this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude']) < $globalDistanceIgnore['distance'])) { |
|
367 | + if (!isset($this->all_tracked[$id]['forcenew']) || $this->all_tracked[$id]['forcenew'] == 0) { |
|
368 | 368 | if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
369 | - if ($globalDebug) echo "Check if vessel is already in DB..."; |
|
370 | - $timeelapsed = microtime(true); |
|
371 | - $MarineLive = new MarineLive($this->db); |
|
372 | - if (isset($line['id'])) { |
|
369 | + if ($globalDebug) echo "Check if vessel is already in DB..."; |
|
370 | + $timeelapsed = microtime(true); |
|
371 | + $MarineLive = new MarineLive($this->db); |
|
372 | + if (isset($line['id'])) { |
|
373 | 373 | $recent_ident = $MarineLive->checkIdRecent($line['id']); |
374 | 374 | if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
375 | - } elseif (isset($this->all_tracked[$id]['mmsi']) && $this->all_tracked[$id]['mmsi'] != '') { |
|
375 | + } elseif (isset($this->all_tracked[$id]['mmsi']) && $this->all_tracked[$id]['mmsi'] != '') { |
|
376 | 376 | $recent_ident = $MarineLive->checkMMSIRecent($this->all_tracked[$id]['mmsi']); |
377 | 377 | if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
378 | - } elseif (isset($this->all_tracked[$id]['ident']) && $this->all_tracked[$id]['ident'] != '') { |
|
378 | + } elseif (isset($this->all_tracked[$id]['ident']) && $this->all_tracked[$id]['ident'] != '') { |
|
379 | 379 | $recent_ident = $MarineLive->checkIdentRecent($this->all_tracked[$id]['ident']); |
380 | 380 | if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
381 | - } else $recent_ident = ''; |
|
382 | - $MarineLive->db=null; |
|
383 | - if ($globalDebug && $recent_ident == '') echo " Not in DB.\n"; |
|
384 | - elseif ($globalDebug && $recent_ident != '') echo " Already in DB.\n"; |
|
381 | + } else $recent_ident = ''; |
|
382 | + $MarineLive->db=null; |
|
383 | + if ($globalDebug && $recent_ident == '') echo " Not in DB.\n"; |
|
384 | + elseif ($globalDebug && $recent_ident != '') echo " Already in DB.\n"; |
|
385 | 385 | } else $recent_ident = ''; |
386 | - } else { |
|
386 | + } else { |
|
387 | 387 | $recent_ident = ''; |
388 | 388 | $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('forcenew' => 0)); |
389 | - } |
|
390 | - //if there was no vessel with the same callsign within the last hour and go post it into the archive |
|
391 | - if($recent_ident == "" && $this->all_tracked[$id]['latitude'] != '' && $this->all_tracked[$id]['longitude'] != '') |
|
392 | - { |
|
389 | + } |
|
390 | + //if there was no vessel with the same callsign within the last hour and go post it into the archive |
|
391 | + if($recent_ident == "" && $this->all_tracked[$id]['latitude'] != '' && $this->all_tracked[$id]['longitude'] != '') |
|
392 | + { |
|
393 | 393 | if ($globalDebug) echo "\o/ Add ".$this->all_tracked[$id]['mmsi']." in archive DB : "; |
394 | 394 | //adds the spotter data for the archive |
395 | - $highlight = ''; |
|
396 | - if (!isset($this->all_tracked[$id]['id'])) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $this->all_tracked[$id]['mmsi'].'-'.date('YmdHi'))); |
|
397 | - if (!isset($globalNoImport) || $globalNoImport !== TRUE) { |
|
395 | + $highlight = ''; |
|
396 | + if (!isset($this->all_tracked[$id]['id'])) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $this->all_tracked[$id]['mmsi'].'-'.date('YmdHi'))); |
|
397 | + if (!isset($globalNoImport) || $globalNoImport !== TRUE) { |
|
398 | 398 | if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
399 | - $timeelapsed = microtime(true); |
|
400 | - $Marine = new Marine($this->db); |
|
401 | - $result = $Marine->addMarineData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['ident'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], $this->all_tracked[$id]['heading'], $this->all_tracked[$id]['speed'], $this->all_tracked[$id]['datetime'], $this->all_tracked[$id]['mmsi'], $this->all_tracked[$id]['type'],$this->all_tracked[$id]['typeid'],$this->all_tracked[$id]['imo'],$this->all_tracked[$id]['callsign'],$this->all_tracked[$id]['arrival_code'],$this->all_tracked[$id]['arrival_date'], $this->all_tracked[$id]['status'], $this->all_tracked[$id]['status_id'],$this->all_tracked[$id]['format_source'],$this->all_tracked[$id]['source_name']); |
|
402 | - $Marine->db = null; |
|
403 | - if ($globalDebug && isset($result)) echo $result."\n"; |
|
404 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
399 | + $timeelapsed = microtime(true); |
|
400 | + $Marine = new Marine($this->db); |
|
401 | + $result = $Marine->addMarineData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['ident'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], $this->all_tracked[$id]['heading'], $this->all_tracked[$id]['speed'], $this->all_tracked[$id]['datetime'], $this->all_tracked[$id]['mmsi'], $this->all_tracked[$id]['type'],$this->all_tracked[$id]['typeid'],$this->all_tracked[$id]['imo'],$this->all_tracked[$id]['callsign'],$this->all_tracked[$id]['arrival_code'],$this->all_tracked[$id]['arrival_date'], $this->all_tracked[$id]['status'], $this->all_tracked[$id]['status_id'],$this->all_tracked[$id]['format_source'],$this->all_tracked[$id]['source_name']); |
|
402 | + $Marine->db = null; |
|
403 | + if ($globalDebug && isset($result)) echo $result."\n"; |
|
404 | + if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
405 | + } |
|
405 | 406 | } |
406 | - } |
|
407 | - if (isset($line['sourcestats']) && $line['sourcestats'] == TRUE && $this->all_tracked[$id]['latitude'] != '' && $this->all_tracked[$id]['longitude'] != '') { |
|
407 | + if (isset($line['sourcestats']) && $line['sourcestats'] == TRUE && $this->all_tracked[$id]['latitude'] != '' && $this->all_tracked[$id]['longitude'] != '') { |
|
408 | 408 | // Add source stat in DB |
409 | 409 | $Stats = new Stats($this->db); |
410 | 410 | if (!empty($this->stats)) { |
411 | - if ($globalDebug) echo 'Add source stats : '; |
|
412 | - foreach($this->stats as $date => $data) { |
|
411 | + if ($globalDebug) echo 'Add source stats : '; |
|
412 | + foreach($this->stats as $date => $data) { |
|
413 | 413 | foreach($data as $source => $sourced) { |
414 | - //print_r($sourced); |
|
415 | - if (isset($sourced['polar'])) echo $Stats->addStatSource(json_encode($sourced['polar']),$source,'polar_marine',$date); |
|
416 | - if (isset($sourced['hist'])) echo $Stats->addStatSource(json_encode($sourced['hist']),$source,'hist_marine',$date); |
|
417 | - if (isset($sourced['msg'])) { |
|
418 | - if (time() - $sourced['msg']['date'] > 10) { |
|
419 | - $nbmsg = round($sourced['msg']['nb']/(time() - $sourced['msg']['date'])); |
|
420 | - echo $Stats->addStatSource($nbmsg,$source,'msg_marine',$date); |
|
421 | - unset($this->stats[$date][$source]['msg']); |
|
422 | - } |
|
423 | - } |
|
424 | - } |
|
425 | - if ($date != date('Y-m-d')) { |
|
426 | - unset($this->stats[$date]); |
|
427 | - } |
|
428 | - } |
|
429 | - if ($globalDebug) echo 'Done'."\n"; |
|
414 | + //print_r($sourced); |
|
415 | + if (isset($sourced['polar'])) echo $Stats->addStatSource(json_encode($sourced['polar']),$source,'polar_marine',$date); |
|
416 | + if (isset($sourced['hist'])) echo $Stats->addStatSource(json_encode($sourced['hist']),$source,'hist_marine',$date); |
|
417 | + if (isset($sourced['msg'])) { |
|
418 | + if (time() - $sourced['msg']['date'] > 10) { |
|
419 | + $nbmsg = round($sourced['msg']['nb']/(time() - $sourced['msg']['date'])); |
|
420 | + echo $Stats->addStatSource($nbmsg,$source,'msg_marine',$date); |
|
421 | + unset($this->stats[$date][$source]['msg']); |
|
422 | + } |
|
423 | + } |
|
424 | + } |
|
425 | + if ($date != date('Y-m-d')) { |
|
426 | + unset($this->stats[$date]); |
|
427 | + } |
|
428 | + } |
|
429 | + if ($globalDebug) echo 'Done'."\n"; |
|
430 | 430 | } |
431 | 431 | $Stats->db = null; |
432 | - } |
|
432 | + } |
|
433 | 433 | |
434 | - $this->del(); |
|
434 | + $this->del(); |
|
435 | 435 | //$ignoreImport = false; |
436 | 436 | $this->all_tracked[$id]['addedMarine'] = 1; |
437 | 437 | //print_r($this->all_tracked[$id]); |
438 | 438 | if ($this->last_delete == 0 || time() - $this->last_delete > 1800) { |
439 | - if ($globalDebug) echo "---- Deleting Live Marine data older than 9 hours..."; |
|
440 | - //MarineLive->deleteLiveMarineDataNotUpdated(); |
|
441 | - if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
|
439 | + if ($globalDebug) echo "---- Deleting Live Marine data older than 9 hours..."; |
|
440 | + //MarineLive->deleteLiveMarineDataNotUpdated(); |
|
441 | + if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
|
442 | 442 | $MarineLive = new MarineLive($this->db); |
443 | 443 | $MarineLive->deleteLiveMarineData(); |
444 | 444 | $MarineLive->db=null; |
445 | 445 | if ($globalDebug) echo " Done\n"; |
446 | - } |
|
447 | - $this->last_delete = time(); |
|
446 | + } |
|
447 | + $this->last_delete = time(); |
|
448 | 448 | } |
449 | - } elseif ($recent_ident != '') { |
|
449 | + } elseif ($recent_ident != '') { |
|
450 | 450 | $this->all_tracked[$id]['id'] = $recent_ident; |
451 | 451 | $this->all_tracked[$id]['addedMarine'] = 1; |
452 | 452 | if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
453 | - if (isset($globalDaemon) && !$globalDaemon) { |
|
453 | + if (isset($globalDaemon) && !$globalDaemon) { |
|
454 | 454 | $Marine = new Marine($this->db); |
455 | 455 | $Marine->updateLatestMarineData($this->all_tracked[$id]['id'],$this->all_tracked[$id]['ident'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],$this->all_tracked[$id]['speed'],$this->all_tracked[$id]['datetime']); |
456 | 456 | $Marine->db = null; |
457 | - } |
|
457 | + } |
|
458 | 458 | } |
459 | 459 | |
460 | - } |
|
460 | + } |
|
461 | 461 | } |
462 | - } |
|
463 | - //adds the spotter LIVE data |
|
464 | - if ($globalDebug) { |
|
462 | + } |
|
463 | + //adds the spotter LIVE data |
|
464 | + if ($globalDebug) { |
|
465 | 465 | echo 'DATA : ident : '.$this->all_tracked[$id]['ident'].' - type : '.$this->all_tracked[$id]['type'].' - Latitude : '.$this->all_tracked[$id]['latitude'].' - Longitude : '.$this->all_tracked[$id]['longitude'].' - Heading : '.$this->all_tracked[$id]['heading'].' - Speed : '.$this->all_tracked[$id]['speed']."\n"; |
466 | - } |
|
467 | - $ignoreImport = false; |
|
466 | + } |
|
467 | + $ignoreImport = false; |
|
468 | 468 | |
469 | - if (!$ignoreImport) { |
|
469 | + if (!$ignoreImport) { |
|
470 | 470 | if (!isset($globalDistanceIgnore['latitude']) || (isset($globalDistanceIgnore['latitude']) && $Common->distance($this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude']) < $globalDistanceIgnore['distance'])) { |
471 | 471 | if ($globalDebug) echo "\o/ Add ".$this->all_tracked[$id]['ident']." from ".$this->all_tracked[$id]['format_source']." in Live DB : "; |
472 | 472 | if (!isset($globalNoImport) || $globalNoImport !== TRUE) { |
473 | - if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
|
473 | + if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
|
474 | 474 | $timeelapsed = microtime(true); |
475 | 475 | $MarineLive = new MarineLive($this->db); |
476 | 476 | $result = $MarineLive->addLiveMarineData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['ident'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], $this->all_tracked[$id]['heading'], $this->all_tracked[$id]['speed'],$this->all_tracked[$id]['datetime'], $this->all_tracked[$id]['putinarchive'],$this->all_tracked[$id]['mmsi'],$this->all_tracked[$id]['type'],$this->all_tracked[$id]['typeid'],$this->all_tracked[$id]['imo'],$this->all_tracked[$id]['callsign'],$this->all_tracked[$id]['arrival_code'],$this->all_tracked[$id]['arrival_date'],$this->all_tracked[$id]['status'],$this->all_tracked[$id]['status_id'],$this->all_tracked[$id]['noarchive'],$this->all_tracked[$id]['format_source'],$this->all_tracked[$id]['source_name'],$this->all_tracked[$id]['over_country']); |
477 | 477 | $MarineLive->db = null; |
478 | 478 | if ($globalDebug) echo $result."\n"; |
479 | 479 | if ($globalDebugTimeElapsed) echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
480 | - } |
|
480 | + } |
|
481 | 481 | } |
482 | 482 | if (isset($globalServerAPRS) && $globalServerAPRS && $this->all_tracked[$id]['putinarchive']) { |
483 | - $APRSMarine->addLiveMarineData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['ident'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], $this->all_tracked[$id]['heading'], $this->all_tracked[$id]['speed'],$this->all_tracked[$id]['datetime'], $this->all_tracked[$id]['putinarchive'],$this->all_tracked[$id]['mmsi'],$this->all_tracked[$id]['type'],$this->all_tracked[$id]['typeid'],$this->all_tracked[$id]['imo'],$this->all_tracked[$id]['callsign'],$this->all_tracked[$id]['arrival_code'],$this->all_tracked[$id]['arrival_date'],$this->all_tracked[$id]['status'],$this->all_tracked[$id]['status_id'],$this->all_tracked[$id]['noarchive'],$this->all_tracked[$id]['format_source'],$this->all_tracked[$id]['source_name'],$this->all_tracked[$id]['over_country']); |
|
483 | + $APRSMarine->addLiveMarineData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['ident'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], $this->all_tracked[$id]['heading'], $this->all_tracked[$id]['speed'],$this->all_tracked[$id]['datetime'], $this->all_tracked[$id]['putinarchive'],$this->all_tracked[$id]['mmsi'],$this->all_tracked[$id]['type'],$this->all_tracked[$id]['typeid'],$this->all_tracked[$id]['imo'],$this->all_tracked[$id]['callsign'],$this->all_tracked[$id]['arrival_code'],$this->all_tracked[$id]['arrival_date'],$this->all_tracked[$id]['status'],$this->all_tracked[$id]['status_id'],$this->all_tracked[$id]['noarchive'],$this->all_tracked[$id]['format_source'],$this->all_tracked[$id]['source_name'],$this->all_tracked[$id]['over_country']); |
|
484 | 484 | } |
485 | 485 | $this->all_tracked[$id]['putinarchive'] = false; |
486 | 486 | |
@@ -512,7 +512,7 @@ discard block |
||
512 | 512 | if ($stats_heading == 16) $stats_heading = 0; |
513 | 513 | if (!isset($this->stats[$current_date][$source]['polar'][1])) { |
514 | 514 | for ($i=0;$i<=15;$i++) { |
515 | - $this->stats[$current_date][$source]['polar'][$i] = 0; |
|
515 | + $this->stats[$current_date][$source]['polar'][$i] = 0; |
|
516 | 516 | } |
517 | 517 | $this->stats[$current_date][$source]['polar'][$stats_heading] = $stats_distance; |
518 | 518 | } else { |
@@ -525,11 +525,11 @@ discard block |
||
525 | 525 | //var_dump($this->stats); |
526 | 526 | if (!isset($this->stats[$current_date][$source]['hist'][$distance])) { |
527 | 527 | if (isset($this->stats[$current_date][$source]['hist'][0])) { |
528 | - end($this->stats[$current_date][$source]['hist']); |
|
529 | - $mini = key($this->stats[$current_date][$source]['hist'])+10; |
|
528 | + end($this->stats[$current_date][$source]['hist']); |
|
529 | + $mini = key($this->stats[$current_date][$source]['hist'])+10; |
|
530 | 530 | } else $mini = 0; |
531 | 531 | for ($i=$mini;$i<=$distance;$i+=10) { |
532 | - $this->stats[$current_date][$source]['hist'][$i] = 0; |
|
532 | + $this->stats[$current_date][$source]['hist'][$i] = 0; |
|
533 | 533 | } |
534 | 534 | $this->stats[$current_date][$source]['hist'][$distance] = 1; |
535 | 535 | } else { |
@@ -545,24 +545,24 @@ discard block |
||
545 | 545 | |
546 | 546 | |
547 | 547 | if ($this->last_delete_hourly == 0 || time() - $this->last_delete_hourly > 900) { |
548 | - if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
|
548 | + if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
|
549 | 549 | if ($globalDebug) echo "---- Deleting Live Marine data Not updated since 2 hour..."; |
550 | 550 | $MarineLive = new MarineLive($this->db); |
551 | 551 | $MarineLive->deleteLiveMarineDataNotUpdated(); |
552 | 552 | $MarineLive->db = null; |
553 | 553 | //MarineLive->deleteLiveMarineData(); |
554 | 554 | if ($globalDebug) echo " Done\n"; |
555 | - } |
|
556 | - $this->last_delete_hourly = time(); |
|
555 | + } |
|
556 | + $this->last_delete_hourly = time(); |
|
557 | 557 | } |
558 | 558 | |
559 | - } |
|
560 | - //$ignoreImport = false; |
|
559 | + } |
|
560 | + //$ignoreImport = false; |
|
561 | 561 | } |
562 | 562 | //if (function_exists('pcntl_fork') && $globalFork) pcntl_signal(SIGCHLD, SIG_IGN); |
563 | 563 | if ($send) return $this->all_tracked[$id]; |
564 | - } |
|
564 | + } |
|
565 | + } |
|
565 | 566 | } |
566 | - } |
|
567 | 567 | } |
568 | 568 | ?> |
@@ -59,7 +59,7 @@ discard block |
||
59 | 59 | if (isset($this->all_tracked[$key]['id'])) { |
60 | 60 | //echo $this->all_tracked[$key]['id'].' - '.$this->all_tracked[$key]['latitude'].' '.$this->all_tracked[$key]['longitude']."\n"; |
61 | 61 | $Marine = new Marine($this->db); |
62 | - $Marine->updateLatestMarineData($this->all_tracked[$key]['id'],$this->all_tracked[$key]['ident'],$this->all_tracked[$key]['latitude'],$this->all_tracked[$key]['longitude'],$this->all_tracked[$key]['speed'],$this->all_tracked[$key]['datetime']); |
|
62 | + $Marine->updateLatestMarineData($this->all_tracked[$key]['id'], $this->all_tracked[$key]['ident'], $this->all_tracked[$key]['latitude'], $this->all_tracked[$key]['longitude'], $this->all_tracked[$key]['speed'], $this->all_tracked[$key]['datetime']); |
|
63 | 63 | } |
64 | 64 | } |
65 | 65 | } |
@@ -71,7 +71,7 @@ discard block |
||
71 | 71 | if ($globalDebug) echo 'Delete old values and update latest data...'."\n"; |
72 | 72 | foreach ($this->all_tracked as $key => $flight) { |
73 | 73 | if (isset($flight['lastupdate'])) { |
74 | - if ($flight['lastupdate'] < (time()-3000)) { |
|
74 | + if ($flight['lastupdate'] < (time() - 3000)) { |
|
75 | 75 | if ((!isset($globalNoImport) || $globalNoImport !== TRUE) && (!isset($globalNoDB) || $globalNoDB !== TRUE)) { |
76 | 76 | if (isset($this->all_tracked[$key]['id'])) { |
77 | 77 | if ($globalDebug) echo "--- Delete old values with id ".$this->all_tracked[$key]['id']."\n"; |
@@ -83,7 +83,7 @@ discard block |
||
83 | 83 | //$real_arrival = $this->arrival($key); |
84 | 84 | $Marine = new Marine($this->db); |
85 | 85 | if ($this->all_tracked[$key]['latitude'] != '' && $this->all_tracked[$key]['longitude'] != '') { |
86 | - $result = $Marine->updateLatestMarineData($this->all_tracked[$key]['id'],$this->all_tracked[$key]['ident'],$this->all_tracked[$key]['latitude'],$this->all_tracked[$key]['longitude'],$this->all_tracked[$key]['speed'],$this->all_tracked[$key]['datetime']); |
|
86 | + $result = $Marine->updateLatestMarineData($this->all_tracked[$key]['id'], $this->all_tracked[$key]['ident'], $this->all_tracked[$key]['latitude'], $this->all_tracked[$key]['longitude'], $this->all_tracked[$key]['speed'], $this->all_tracked[$key]['datetime']); |
|
87 | 87 | if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n"; |
88 | 88 | } |
89 | 89 | // Put in archive |
@@ -97,14 +97,14 @@ discard block |
||
97 | 97 | } |
98 | 98 | |
99 | 99 | public function add($line) { |
100 | - global $globalFork, $globalDistanceIgnore, $globalDaemon, $globalDebug, $globalCoordMinChange, $globalDebugTimeElapsed, $globalCenterLatitude, $globalCenterLongitude, $globalBeta, $globalSourcesupdate, $globalAllTracked, $globalNoImport, $globalNoDB, $globalServerAPRS,$APRSMarine; |
|
100 | + global $globalFork, $globalDistanceIgnore, $globalDaemon, $globalDebug, $globalCoordMinChange, $globalDebugTimeElapsed, $globalCenterLatitude, $globalCenterLongitude, $globalBeta, $globalSourcesupdate, $globalAllTracked, $globalNoImport, $globalNoDB, $globalServerAPRS, $APRSMarine; |
|
101 | 101 | if (!isset($globalCoordMinChange) || $globalCoordMinChange == '') $globalCoordMinChange = '0.02'; |
102 | 102 | date_default_timezone_set('UTC'); |
103 | 103 | $dataFound = false; |
104 | 104 | $send = false; |
105 | 105 | |
106 | 106 | // SBS format is CSV format |
107 | - if(is_array($line) && isset($line['mmsi'])) { |
|
107 | + if (is_array($line) && isset($line['mmsi'])) { |
|
108 | 108 | //print_r($line); |
109 | 109 | if (isset($line['mmsi'])) { |
110 | 110 | |
@@ -129,25 +129,25 @@ discard block |
||
129 | 129 | |
130 | 130 | if (!isset($this->all_tracked[$id])) { |
131 | 131 | $this->all_tracked[$id] = array(); |
132 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('addedMarine' => 0)); |
|
133 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('ident' => '','latitude' => '', 'longitude' => '', 'speed' => '0', 'heading' => '', 'format_source' => '','source_name' => '','comment'=> '','type' => '','typeid' => '','noarchive' => false,'putinarchive' => true,'over_country' => '','mmsi' => '','status' => '','status_id' => '','imo' => '','callsign' => '','arrival_code' => '','arrival_date' => '','mmsi_type' => '')); |
|
134 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('lastupdate' => time())); |
|
132 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('addedMarine' => 0)); |
|
133 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('ident' => '', 'latitude' => '', 'longitude' => '', 'speed' => '0', 'heading' => '', 'format_source' => '', 'source_name' => '', 'comment'=> '', 'type' => '', 'typeid' => '', 'noarchive' => false, 'putinarchive' => true, 'over_country' => '', 'mmsi' => '', 'status' => '', 'status_id' => '', 'imo' => '', 'callsign' => '', 'arrival_code' => '', 'arrival_date' => '', 'mmsi_type' => '')); |
|
134 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('lastupdate' => time())); |
|
135 | 135 | if (!isset($line['id'])) { |
136 | 136 | if (!isset($globalDaemon)) $globalDaemon = TRUE; |
137 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $id.'-'.date('YmdHi'))); |
|
138 | - } else $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $line['id'])); |
|
137 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('id' => $id.'-'.date('YmdHi'))); |
|
138 | + } else $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('id' => $line['id'])); |
|
139 | 139 | if ($globalAllTracked !== FALSE) $dataFound = true; |
140 | 140 | } |
141 | 141 | |
142 | 142 | if (isset($line['mmsi']) && $line['mmsi'] != '' && $line['mmsi'] != $this->all_tracked[$id]['mmsi']) { |
143 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('mmsi' => $line['mmsi'])); |
|
143 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('mmsi' => $line['mmsi'])); |
|
144 | 144 | if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
145 | 145 | $Marine = new Marine($this->db); |
146 | 146 | $identity = $Marine->getIdentity($line['mmsi']); |
147 | 147 | if (!empty($identity)) { |
148 | 148 | $this->all_tracked[$id]['ident'] = $identity['ship_name']; |
149 | 149 | $this->all_tracked[$id]['type'] = $identity['type']; |
150 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('typeid' => $AIS->getShipTypeID($identity['type']))); |
|
150 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('typeid' => $AIS->getShipTypeID($identity['type']))); |
|
151 | 151 | } |
152 | 152 | //print_r($identity); |
153 | 153 | unset($Marine); |
@@ -155,23 +155,23 @@ discard block |
||
155 | 155 | } |
156 | 156 | } |
157 | 157 | if (isset($line['type_id'])) { |
158 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('type' => $AIS->getShipType($line['type_id']))); |
|
159 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('typeid' => $line['type_id'])); |
|
158 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('type' => $AIS->getShipType($line['type_id']))); |
|
159 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('typeid' => $line['type_id'])); |
|
160 | 160 | } |
161 | 161 | if (isset($line['type']) && $line['type'] != '' && $this->all_tracked[$id]['type'] == '') { |
162 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('type' => $line['type'])); |
|
163 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('typeid' => $AIS->getShipTypeID($line['type']))); |
|
162 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('type' => $line['type'])); |
|
163 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('typeid' => $AIS->getShipTypeID($line['type']))); |
|
164 | 164 | } |
165 | 165 | if (isset($line['status']) && $line['status'] != '') { |
166 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('status' => $line['status'])); |
|
166 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('status' => $line['status'])); |
|
167 | 167 | } |
168 | 168 | if (isset($line['status_id']) && (!isset($this->all_tracked[$id]['status_id']) || $this->all_tracked[$id]['status_id'] != $line['status_id'])) { |
169 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('status_id' => $line['status_id'])); |
|
169 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('status_id' => $line['status_id'])); |
|
170 | 170 | if ($this->all_tracked[$id]['addedMarine'] == 1) { |
171 | 171 | if (!isset($globalNoImport) || $globalNoImport !== TRUE) { |
172 | 172 | if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
173 | 173 | $Marine = new Marine($this->db); |
174 | - $Marine->updateStatusMarineData($this->all_tracked[$id]['id'],$this->all_tracked[$id]['status_id'],$this->all_tracked[$id]['status']); |
|
174 | + $Marine->updateStatusMarineData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['status_id'], $this->all_tracked[$id]['status']); |
|
175 | 175 | unset($Marine); |
176 | 176 | } |
177 | 177 | } |
@@ -180,24 +180,24 @@ discard block |
||
180 | 180 | |
181 | 181 | |
182 | 182 | if (isset($line['mmsi_type']) && $line['mmsi_type'] != '') { |
183 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('mmsi_type' => $line['mmsi_type'])); |
|
183 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('mmsi_type' => $line['mmsi_type'])); |
|
184 | 184 | } |
185 | 185 | if (isset($line['imo']) && $line['imo'] != '') { |
186 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('imo' => $line['imo'])); |
|
186 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('imo' => $line['imo'])); |
|
187 | 187 | } |
188 | 188 | if (isset($line['callsign']) && $line['callsign'] != '') { |
189 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('callsign' => $line['callsign'])); |
|
189 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('callsign' => $line['callsign'])); |
|
190 | 190 | } |
191 | 191 | if (isset($line['arrival_code']) && $line['arrival_code'] != '') { |
192 | 192 | if (!isset($this->all_tracked[$id]['arrival_code'])) { |
193 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('arrival_code' => $line['arrival_code'])); |
|
193 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('arrival_code' => $line['arrival_code'])); |
|
194 | 194 | if ($globalDebug) echo $this->all_tracked[$id]['id'].' => New arrival: '.$line['arrival_code']."\n"; |
195 | 195 | if ($this->all_tracked[$id]['addedMarine'] != 0) { |
196 | 196 | if (!isset($globalNoImport) || $globalNoImport !== TRUE) { |
197 | 197 | if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
198 | 198 | $Marine = new Marine($this->db); |
199 | 199 | $fromsource = NULL; |
200 | - $Marine->updateArrivalPortNameMarineData($this->all_tracked[$id]['id'],$this->all_tracked[$id]['arrival_code'],$fromsource); |
|
200 | + $Marine->updateArrivalPortNameMarineData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['arrival_code'], $fromsource); |
|
201 | 201 | $Marine->db = null; |
202 | 202 | } |
203 | 203 | } |
@@ -213,7 +213,7 @@ discard block |
||
213 | 213 | } |
214 | 214 | } |
215 | 215 | if (isset($line['arrival_date']) && $line['arrival_date'] != '') { |
216 | - if (strtotime($line['arrival_date']) > time()) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('arrival_date' => $line['arrival_date'])); |
|
216 | + if (strtotime($line['arrival_date']) > time()) $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('arrival_date' => $line['arrival_date'])); |
|
217 | 217 | } |
218 | 218 | |
219 | 219 | //if (isset($line['ident']) && $line['ident'] != '' && $line['ident'] != '????????' && $line['ident'] != '00000000' && ($this->all_tracked[$id]['ident'] != trim($line['ident'])) && preg_match('/^[a-zA-Z0-9-]+$/', $line['ident'])) { |
@@ -222,44 +222,44 @@ discard block |
||
222 | 222 | if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
223 | 223 | $timeelapsed = microtime(true); |
224 | 224 | $Marine = new Marine($this->db); |
225 | - $Marine->addIdentity($this->all_tracked[$id]['mmsi'],$this->all_tracked[$id]['imo'],$this->all_tracked[$id]['ident'],$this->all_tracked[$id]['callsign'],$this->all_tracked[$id]['type']); |
|
225 | + $Marine->addIdentity($this->all_tracked[$id]['mmsi'], $this->all_tracked[$id]['imo'], $this->all_tracked[$id]['ident'], $this->all_tracked[$id]['callsign'], $this->all_tracked[$id]['type']); |
|
226 | 226 | $Marine->db = null; |
227 | 227 | } |
228 | 228 | } |
229 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('ident' => trim($line['ident']))); |
|
229 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('ident' => trim($line['ident']))); |
|
230 | 230 | if ($this->all_tracked[$id]['addedMarine'] == 1) { |
231 | 231 | if (!isset($globalNoImport) || $globalNoImport !== TRUE) { |
232 | 232 | if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
233 | 233 | $timeelapsed = microtime(true); |
234 | 234 | $Marine = new Marine($this->db); |
235 | 235 | $fromsource = NULL; |
236 | - $result = $Marine->updateIdentMarineData($this->all_tracked[$id]['id'],$this->all_tracked[$id]['ident'],$fromsource); |
|
236 | + $result = $Marine->updateIdentMarineData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['ident'], $fromsource); |
|
237 | 237 | if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n"; |
238 | 238 | $Marine->db = null; |
239 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update identspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
239 | + if ($globalDebugTimeElapsed) echo 'Time elapsed for update identspotterdata : '.round(microtime(true) - $timeelapsed, 2).'s'."\n"; |
|
240 | 240 | } |
241 | 241 | } |
242 | 242 | } |
243 | - if (!isset($this->all_tracked[$id]['id'])) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $this->all_tracked[$id]['ident'])); |
|
243 | + if (!isset($this->all_tracked[$id]['id'])) $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('id' => $this->all_tracked[$id]['ident'])); |
|
244 | 244 | } |
245 | 245 | |
246 | - if (isset($line['datetime']) && strtotime($line['datetime']) > time()-30*60 && strtotime($line['datetime']) < time()+20*60) { |
|
246 | + if (isset($line['datetime']) && strtotime($line['datetime']) > time() - 30*60 && strtotime($line['datetime']) < time() + 20*60) { |
|
247 | 247 | if (!isset($this->all_tracked[$id]['datetime']) || strtotime($line['datetime']) > strtotime($this->all_tracked[$id]['datetime'])) { |
248 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('datetime' => $line['datetime'])); |
|
248 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('datetime' => $line['datetime'])); |
|
249 | 249 | } else { |
250 | 250 | if (strtotime($line['datetime']) == strtotime($this->all_tracked[$id]['datetime']) && $globalDebug) echo "!!! Date is the same as previous data for ".$this->all_tracked[$id]['mmsi']."\n"; |
251 | 251 | elseif (strtotime($line['datetime']) > strtotime($this->all_tracked[$id]['datetime']) && $globalDebug) echo "!!! Date previous latest data (".$line['datetime']." > ".$this->all_tracked[$id]['datetime'].") !!! for ".$this->all_tracked[$id]['hex']." - format : ".$line['format_source']."\n"; |
252 | 252 | return ''; |
253 | 253 | } |
254 | - } elseif (isset($line['datetime']) && strtotime($line['datetime']) <= time()-30*60) { |
|
254 | + } elseif (isset($line['datetime']) && strtotime($line['datetime']) <= time() - 30*60) { |
|
255 | 255 | if ($globalDebug) echo "!!! Date is too old ".$this->all_tracked[$id]['mmsi']." - format : ".$line['format_source']."!!!\n"; |
256 | 256 | return ''; |
257 | - } elseif (isset($line['datetime']) && strtotime($line['datetime']) >= time()+20*60) { |
|
257 | + } elseif (isset($line['datetime']) && strtotime($line['datetime']) >= time() + 20*60) { |
|
258 | 258 | if ($globalDebug) echo "!!! Date is in the future ".$this->all_tracked[$id]['mmsi']." - format : ".$line['format_source']."!!!\n"; |
259 | 259 | return ''; |
260 | 260 | } elseif (!isset($line['datetime'])) { |
261 | 261 | date_default_timezone_set('UTC'); |
262 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('datetime' => date('Y-m-d H:i:s'))); |
|
262 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('datetime' => date('Y-m-d H:i:s'))); |
|
263 | 263 | } else { |
264 | 264 | if ($globalDebug) echo "!!! Unknow date error ".$this->all_tracked[$id]['mmsi']." date: ".$line['datetime']." - format : ".$line['format_source']."!!!\n"; |
265 | 265 | return ''; |
@@ -267,24 +267,24 @@ discard block |
||
267 | 267 | |
268 | 268 | |
269 | 269 | if (isset($line['speed'])) { |
270 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed' => round($line['speed']))); |
|
271 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed_fromsrc' => true)); |
|
270 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('speed' => round($line['speed']))); |
|
271 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('speed_fromsrc' => true)); |
|
272 | 272 | } else if (!isset($this->all_tracked[$id]['speed_fromsrc']) && isset($this->all_tracked[$id]['time_last_coord']) && $this->all_tracked[$id]['time_last_coord'] != time() && isset($line['latitude']) && isset($line['longitude'])) { |
273 | - $distance = $Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m'); |
|
273 | + $distance = $Common->distance($line['latitude'], $line['longitude'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], 'm'); |
|
274 | 274 | if ($distance > 1000 && $distance < 10000) { |
275 | 275 | $speed = $distance/(time() - $this->all_tracked[$id]['time_last_coord']); |
276 | 276 | $speed = $speed*3.6; |
277 | - if ($speed < 1000) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed' => round($speed))); |
|
277 | + if ($speed < 1000) $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('speed' => round($speed))); |
|
278 | 278 | if ($globalDebug) echo "ø Calculated Speed for ".$this->all_tracked[$id]['hex']." : ".$speed." - distance : ".$distance."\n"; |
279 | 279 | } |
280 | 280 | } |
281 | 281 | |
282 | 282 | if (isset($line['latitude']) && isset($line['longitude']) && $line['latitude'] != '' && $line['longitude'] != '' && is_numeric($line['latitude']) && is_numeric($line['longitude'])) { |
283 | - if (isset($this->all_tracked[$id]['time_last_coord'])) $timediff = round(time()-$this->all_tracked[$id]['time_last_coord']); |
|
283 | + if (isset($this->all_tracked[$id]['time_last_coord'])) $timediff = round(time() - $this->all_tracked[$id]['time_last_coord']); |
|
284 | 284 | else unset($timediff); |
285 | - if ($this->tmd > 5 || !isset($timediff) || $timediff > 2000 || ($timediff > 30 && isset($this->all_tracked[$id]['latitude']) && isset($this->all_tracked[$id]['longitude']) && $Common->withinThreshold($timediff,$Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m')))) { |
|
285 | + if ($this->tmd > 5 || !isset($timediff) || $timediff > 2000 || ($timediff > 30 && isset($this->all_tracked[$id]['latitude']) && isset($this->all_tracked[$id]['longitude']) && $Common->withinThreshold($timediff, $Common->distance($line['latitude'], $line['longitude'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], 'm')))) { |
|
286 | 286 | if (isset($this->all_tracked[$id]['archive_latitude']) && isset($this->all_tracked[$id]['archive_longitude']) && isset($this->all_tracked[$id]['livedb_latitude']) && isset($this->all_tracked[$id]['livedb_longitude'])) { |
287 | - if (!$Common->checkLine($this->all_tracked[$id]['archive_latitude'],$this->all_tracked[$id]['archive_longitude'],$this->all_tracked[$id]['livedb_latitude'],$this->all_tracked[$id]['livedb_longitude'],$line['latitude'],$line['longitude'])) { |
|
287 | + if (!$Common->checkLine($this->all_tracked[$id]['archive_latitude'], $this->all_tracked[$id]['archive_longitude'], $this->all_tracked[$id]['livedb_latitude'], $this->all_tracked[$id]['livedb_longitude'], $line['latitude'], $line['longitude'])) { |
|
288 | 288 | $this->all_tracked[$id]['archive_latitude'] = $line['latitude']; |
289 | 289 | $this->all_tracked[$id]['archive_longitude'] = $line['longitude']; |
290 | 290 | $this->all_tracked[$id]['putinarchive'] = true; |
@@ -293,10 +293,10 @@ discard block |
||
293 | 293 | $timeelapsed = microtime(true); |
294 | 294 | if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
295 | 295 | $Marine = new Marine($this->db); |
296 | - $all_country = $Marine->getCountryFromLatitudeLongitude($line['latitude'],$line['longitude']); |
|
296 | + $all_country = $Marine->getCountryFromLatitudeLongitude($line['latitude'], $line['longitude']); |
|
297 | 297 | if (!empty($all_country)) $this->all_tracked[$id]['over_country'] = $all_country['iso2']; |
298 | 298 | $Marine->db = null; |
299 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
299 | + if ($globalDebugTimeElapsed) echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true) - $timeelapsed, 2).'s'."\n"; |
|
300 | 300 | } |
301 | 301 | $this->tmd = 0; |
302 | 302 | if ($globalDebug) echo 'FOUND : '.$this->all_tracked[$id]['over_country'].' ---------------'."\n"; |
@@ -305,55 +305,55 @@ discard block |
||
305 | 305 | |
306 | 306 | if (isset($line['latitude']) && $line['latitude'] != '' && $line['latitude'] != 0 && $line['latitude'] < 91 && $line['latitude'] > -90) { |
307 | 307 | if (!isset($this->all_tracked[$id]['archive_latitude'])) $this->all_tracked[$id]['archive_latitude'] = $line['latitude']; |
308 | - if (!isset($this->all_tracked[$id]['livedb_latitude']) || abs($this->all_tracked[$id]['livedb_latitude']-$line['latitude']) > $globalCoordMinChange || $this->all_tracked[$id]['format_source'] == 'aprs') { |
|
308 | + if (!isset($this->all_tracked[$id]['livedb_latitude']) || abs($this->all_tracked[$id]['livedb_latitude'] - $line['latitude']) > $globalCoordMinChange || $this->all_tracked[$id]['format_source'] == 'aprs') { |
|
309 | 309 | $this->all_tracked[$id]['livedb_latitude'] = $line['latitude']; |
310 | 310 | $dataFound = true; |
311 | 311 | $this->all_tracked[$id]['time_last_coord'] = time(); |
312 | 312 | } |
313 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('latitude' => $line['latitude'])); |
|
313 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('latitude' => $line['latitude'])); |
|
314 | 314 | } |
315 | 315 | if (isset($line['longitude']) && $line['longitude'] != '' && $line['longitude'] != 0 && $line['longitude'] < 360 && $line['longitude'] > -180) { |
316 | 316 | if ($line['longitude'] > 180) $line['longitude'] = $line['longitude'] - 360; |
317 | 317 | if (!isset($this->all_tracked[$id]['archive_longitude'])) $this->all_tracked[$id]['archive_longitude'] = $line['longitude']; |
318 | - if (!isset($this->all_tracked[$id]['livedb_longitude']) || abs($this->all_tracked[$id]['livedb_longitude']-$line['longitude']) > $globalCoordMinChange || $this->all_tracked[$id]['format_source'] == 'aprs') { |
|
318 | + if (!isset($this->all_tracked[$id]['livedb_longitude']) || abs($this->all_tracked[$id]['livedb_longitude'] - $line['longitude']) > $globalCoordMinChange || $this->all_tracked[$id]['format_source'] == 'aprs') { |
|
319 | 319 | $this->all_tracked[$id]['livedb_longitude'] = $line['longitude']; |
320 | 320 | $dataFound = true; |
321 | 321 | $this->all_tracked[$id]['time_last_coord'] = time(); |
322 | 322 | } |
323 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('longitude' => $line['longitude'])); |
|
323 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('longitude' => $line['longitude'])); |
|
324 | 324 | } |
325 | 325 | |
326 | 326 | } else if ($globalDebug && $timediff > 20) { |
327 | 327 | $this->tmd = $this->tmd + 1; |
328 | 328 | echo '!!! Too much distance in short time... for '.$this->all_tracked[$id]['ident']."\n"; |
329 | - echo 'Time : '.$timediff.'s - Distance : '.$Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m')."m -"; |
|
330 | - echo 'Speed : '.(($Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m')/$timediff)*3.6)." km/h - "; |
|
329 | + echo 'Time : '.$timediff.'s - Distance : '.$Common->distance($line['latitude'], $line['longitude'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], 'm')."m -"; |
|
330 | + echo 'Speed : '.(($Common->distance($line['latitude'], $line['longitude'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], 'm')/$timediff)*3.6)." km/h - "; |
|
331 | 331 | echo 'Lat : '.$line['latitude'].' - long : '.$line['longitude'].' - prev lat : '.$this->all_tracked[$id]['latitude'].' - prev long : '.$this->all_tracked[$id]['longitude']." \n"; |
332 | 332 | } |
333 | 333 | } |
334 | 334 | if (isset($line['last_update']) && $line['last_update'] != '') { |
335 | 335 | if (isset($this->all_tracked[$id]['last_update']) && $this->all_tracked[$id]['last_update'] != $line['last_update']) $dataFound = true; |
336 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('last_update' => $line['last_update'])); |
|
336 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('last_update' => $line['last_update'])); |
|
337 | 337 | } |
338 | 338 | if (isset($line['format_source']) && $line['format_source'] != '') { |
339 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('format_source' => $line['format_source'])); |
|
339 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('format_source' => $line['format_source'])); |
|
340 | 340 | } |
341 | 341 | if (isset($line['source_name']) && $line['source_name'] != '') { |
342 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('source_name' => $line['source_name'])); |
|
342 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('source_name' => $line['source_name'])); |
|
343 | 343 | } |
344 | 344 | if (isset($line['noarchive']) && $line['noarchive'] === true) { |
345 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('noarchive' => true)); |
|
345 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('noarchive' => true)); |
|
346 | 346 | } |
347 | 347 | |
348 | 348 | if (isset($line['heading']) && $line['heading'] != '') { |
349 | - if (is_int($this->all_tracked[$id]['heading']) && abs($this->all_tracked[$id]['heading']-round($line['heading'])) > 10) $this->all_tracked[$id]['putinarchive'] = true; |
|
350 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading' => round($line['heading']))); |
|
351 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading_fromsrc' => true)); |
|
349 | + if (is_int($this->all_tracked[$id]['heading']) && abs($this->all_tracked[$id]['heading'] - round($line['heading'])) > 10) $this->all_tracked[$id]['putinarchive'] = true; |
|
350 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('heading' => round($line['heading']))); |
|
351 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('heading_fromsrc' => true)); |
|
352 | 352 | //$dataFound = true; |
353 | 353 | } elseif (!isset($this->all_tracked[$id]['heading_fromsrc']) && isset($this->all_tracked[$id]['archive_latitude']) && $this->all_tracked[$id]['archive_latitude'] != $this->all_tracked[$id]['latitude'] && isset($this->all_tracked[$id]['archive_longitude']) && $this->all_tracked[$id]['archive_longitude'] != $this->all_tracked[$id]['longitude']) { |
354 | - $heading = $Common->getHeading($this->all_tracked[$id]['archive_latitude'],$this->all_tracked[$id]['archive_longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude']); |
|
355 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading' => round($heading))); |
|
356 | - if (abs($this->all_tracked[$id]['heading']-round($heading)) > 10) $this->all_tracked[$id]['putinarchive'] = true; |
|
354 | + $heading = $Common->getHeading($this->all_tracked[$id]['archive_latitude'], $this->all_tracked[$id]['archive_longitude'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude']); |
|
355 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('heading' => round($heading))); |
|
356 | + if (abs($this->all_tracked[$id]['heading'] - round($heading)) > 10) $this->all_tracked[$id]['putinarchive'] = true; |
|
357 | 357 | if ($globalDebug) echo "ø Calculated Heading for ".$this->all_tracked[$id]['ident']." : ".$heading."\n"; |
358 | 358 | } |
359 | 359 | //if (isset($globalSourcesupdate) && $globalSourcesupdate != '' && isset($this->all_tracked[$id]['lastupdate']) && time()-$this->all_tracked[$id]['lastupdate'] < $globalSourcesupdate) $dataFound = false; |
@@ -363,7 +363,7 @@ discard block |
||
363 | 363 | if ($dataFound === true && isset($this->all_tracked[$id]['mmsi'])) { |
364 | 364 | $this->all_tracked[$id]['lastupdate'] = time(); |
365 | 365 | if ($this->all_tracked[$id]['addedMarine'] == 0) { |
366 | - if (!isset($globalDistanceIgnore['latitude']) || $this->all_tracked[$id]['longitude'] == '' || $this->all_tracked[$id]['latitude'] == '' || (isset($globalDistanceIgnore['latitude']) && $Common->distance($this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude']) < $globalDistanceIgnore['distance'])) { |
|
366 | + if (!isset($globalDistanceIgnore['latitude']) || $this->all_tracked[$id]['longitude'] == '' || $this->all_tracked[$id]['latitude'] == '' || (isset($globalDistanceIgnore['latitude']) && $Common->distance($this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], $globalDistanceIgnore['latitude'], $globalDistanceIgnore['longitude']) < $globalDistanceIgnore['distance'])) { |
|
367 | 367 | if (!isset($this->all_tracked[$id]['forcenew']) || $this->all_tracked[$id]['forcenew'] == 0) { |
368 | 368 | if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
369 | 369 | if ($globalDebug) echo "Check if vessel is already in DB..."; |
@@ -371,37 +371,37 @@ discard block |
||
371 | 371 | $MarineLive = new MarineLive($this->db); |
372 | 372 | if (isset($line['id'])) { |
373 | 373 | $recent_ident = $MarineLive->checkIdRecent($line['id']); |
374 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
374 | + if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true) - $timeelapsed, 2).'s'."\n"; |
|
375 | 375 | } elseif (isset($this->all_tracked[$id]['mmsi']) && $this->all_tracked[$id]['mmsi'] != '') { |
376 | 376 | $recent_ident = $MarineLive->checkMMSIRecent($this->all_tracked[$id]['mmsi']); |
377 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
377 | + if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true) - $timeelapsed, 2).'s'."\n"; |
|
378 | 378 | } elseif (isset($this->all_tracked[$id]['ident']) && $this->all_tracked[$id]['ident'] != '') { |
379 | 379 | $recent_ident = $MarineLive->checkIdentRecent($this->all_tracked[$id]['ident']); |
380 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
380 | + if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true) - $timeelapsed, 2).'s'."\n"; |
|
381 | 381 | } else $recent_ident = ''; |
382 | - $MarineLive->db=null; |
|
382 | + $MarineLive->db = null; |
|
383 | 383 | if ($globalDebug && $recent_ident == '') echo " Not in DB.\n"; |
384 | 384 | elseif ($globalDebug && $recent_ident != '') echo " Already in DB.\n"; |
385 | 385 | } else $recent_ident = ''; |
386 | 386 | } else { |
387 | 387 | $recent_ident = ''; |
388 | - $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('forcenew' => 0)); |
|
388 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('forcenew' => 0)); |
|
389 | 389 | } |
390 | 390 | //if there was no vessel with the same callsign within the last hour and go post it into the archive |
391 | - if($recent_ident == "" && $this->all_tracked[$id]['latitude'] != '' && $this->all_tracked[$id]['longitude'] != '') |
|
391 | + if ($recent_ident == "" && $this->all_tracked[$id]['latitude'] != '' && $this->all_tracked[$id]['longitude'] != '') |
|
392 | 392 | { |
393 | 393 | if ($globalDebug) echo "\o/ Add ".$this->all_tracked[$id]['mmsi']." in archive DB : "; |
394 | 394 | //adds the spotter data for the archive |
395 | 395 | $highlight = ''; |
396 | - if (!isset($this->all_tracked[$id]['id'])) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $this->all_tracked[$id]['mmsi'].'-'.date('YmdHi'))); |
|
396 | + if (!isset($this->all_tracked[$id]['id'])) $this->all_tracked[$id] = array_merge($this->all_tracked[$id], array('id' => $this->all_tracked[$id]['mmsi'].'-'.date('YmdHi'))); |
|
397 | 397 | if (!isset($globalNoImport) || $globalNoImport !== TRUE) { |
398 | 398 | if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
399 | 399 | $timeelapsed = microtime(true); |
400 | 400 | $Marine = new Marine($this->db); |
401 | - $result = $Marine->addMarineData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['ident'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], $this->all_tracked[$id]['heading'], $this->all_tracked[$id]['speed'], $this->all_tracked[$id]['datetime'], $this->all_tracked[$id]['mmsi'], $this->all_tracked[$id]['type'],$this->all_tracked[$id]['typeid'],$this->all_tracked[$id]['imo'],$this->all_tracked[$id]['callsign'],$this->all_tracked[$id]['arrival_code'],$this->all_tracked[$id]['arrival_date'], $this->all_tracked[$id]['status'], $this->all_tracked[$id]['status_id'],$this->all_tracked[$id]['format_source'],$this->all_tracked[$id]['source_name']); |
|
401 | + $result = $Marine->addMarineData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['ident'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], $this->all_tracked[$id]['heading'], $this->all_tracked[$id]['speed'], $this->all_tracked[$id]['datetime'], $this->all_tracked[$id]['mmsi'], $this->all_tracked[$id]['type'], $this->all_tracked[$id]['typeid'], $this->all_tracked[$id]['imo'], $this->all_tracked[$id]['callsign'], $this->all_tracked[$id]['arrival_code'], $this->all_tracked[$id]['arrival_date'], $this->all_tracked[$id]['status'], $this->all_tracked[$id]['status_id'], $this->all_tracked[$id]['format_source'], $this->all_tracked[$id]['source_name']); |
|
402 | 402 | $Marine->db = null; |
403 | 403 | if ($globalDebug && isset($result)) echo $result."\n"; |
404 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
404 | + if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true) - $timeelapsed, 2).'s'."\n"; |
|
405 | 405 | } |
406 | 406 | } |
407 | 407 | if (isset($line['sourcestats']) && $line['sourcestats'] == TRUE && $this->all_tracked[$id]['latitude'] != '' && $this->all_tracked[$id]['longitude'] != '') { |
@@ -409,15 +409,15 @@ discard block |
||
409 | 409 | $Stats = new Stats($this->db); |
410 | 410 | if (!empty($this->stats)) { |
411 | 411 | if ($globalDebug) echo 'Add source stats : '; |
412 | - foreach($this->stats as $date => $data) { |
|
413 | - foreach($data as $source => $sourced) { |
|
412 | + foreach ($this->stats as $date => $data) { |
|
413 | + foreach ($data as $source => $sourced) { |
|
414 | 414 | //print_r($sourced); |
415 | - if (isset($sourced['polar'])) echo $Stats->addStatSource(json_encode($sourced['polar']),$source,'polar_marine',$date); |
|
416 | - if (isset($sourced['hist'])) echo $Stats->addStatSource(json_encode($sourced['hist']),$source,'hist_marine',$date); |
|
415 | + if (isset($sourced['polar'])) echo $Stats->addStatSource(json_encode($sourced['polar']), $source, 'polar_marine', $date); |
|
416 | + if (isset($sourced['hist'])) echo $Stats->addStatSource(json_encode($sourced['hist']), $source, 'hist_marine', $date); |
|
417 | 417 | if (isset($sourced['msg'])) { |
418 | 418 | if (time() - $sourced['msg']['date'] > 10) { |
419 | 419 | $nbmsg = round($sourced['msg']['nb']/(time() - $sourced['msg']['date'])); |
420 | - echo $Stats->addStatSource($nbmsg,$source,'msg_marine',$date); |
|
420 | + echo $Stats->addStatSource($nbmsg, $source, 'msg_marine', $date); |
|
421 | 421 | unset($this->stats[$date][$source]['msg']); |
422 | 422 | } |
423 | 423 | } |
@@ -441,7 +441,7 @@ discard block |
||
441 | 441 | if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
442 | 442 | $MarineLive = new MarineLive($this->db); |
443 | 443 | $MarineLive->deleteLiveMarineData(); |
444 | - $MarineLive->db=null; |
|
444 | + $MarineLive->db = null; |
|
445 | 445 | if ($globalDebug) echo " Done\n"; |
446 | 446 | } |
447 | 447 | $this->last_delete = time(); |
@@ -452,7 +452,7 @@ discard block |
||
452 | 452 | if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
453 | 453 | if (isset($globalDaemon) && !$globalDaemon) { |
454 | 454 | $Marine = new Marine($this->db); |
455 | - $Marine->updateLatestMarineData($this->all_tracked[$id]['id'],$this->all_tracked[$id]['ident'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],$this->all_tracked[$id]['speed'],$this->all_tracked[$id]['datetime']); |
|
455 | + $Marine->updateLatestMarineData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['ident'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], $this->all_tracked[$id]['speed'], $this->all_tracked[$id]['datetime']); |
|
456 | 456 | $Marine->db = null; |
457 | 457 | } |
458 | 458 | } |
@@ -467,20 +467,20 @@ discard block |
||
467 | 467 | $ignoreImport = false; |
468 | 468 | |
469 | 469 | if (!$ignoreImport) { |
470 | - if (!isset($globalDistanceIgnore['latitude']) || (isset($globalDistanceIgnore['latitude']) && $Common->distance($this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude']) < $globalDistanceIgnore['distance'])) { |
|
470 | + if (!isset($globalDistanceIgnore['latitude']) || (isset($globalDistanceIgnore['latitude']) && $Common->distance($this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], $globalDistanceIgnore['latitude'], $globalDistanceIgnore['longitude']) < $globalDistanceIgnore['distance'])) { |
|
471 | 471 | if ($globalDebug) echo "\o/ Add ".$this->all_tracked[$id]['ident']." from ".$this->all_tracked[$id]['format_source']." in Live DB : "; |
472 | 472 | if (!isset($globalNoImport) || $globalNoImport !== TRUE) { |
473 | 473 | if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
474 | 474 | $timeelapsed = microtime(true); |
475 | 475 | $MarineLive = new MarineLive($this->db); |
476 | - $result = $MarineLive->addLiveMarineData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['ident'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], $this->all_tracked[$id]['heading'], $this->all_tracked[$id]['speed'],$this->all_tracked[$id]['datetime'], $this->all_tracked[$id]['putinarchive'],$this->all_tracked[$id]['mmsi'],$this->all_tracked[$id]['type'],$this->all_tracked[$id]['typeid'],$this->all_tracked[$id]['imo'],$this->all_tracked[$id]['callsign'],$this->all_tracked[$id]['arrival_code'],$this->all_tracked[$id]['arrival_date'],$this->all_tracked[$id]['status'],$this->all_tracked[$id]['status_id'],$this->all_tracked[$id]['noarchive'],$this->all_tracked[$id]['format_source'],$this->all_tracked[$id]['source_name'],$this->all_tracked[$id]['over_country']); |
|
476 | + $result = $MarineLive->addLiveMarineData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['ident'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], $this->all_tracked[$id]['heading'], $this->all_tracked[$id]['speed'], $this->all_tracked[$id]['datetime'], $this->all_tracked[$id]['putinarchive'], $this->all_tracked[$id]['mmsi'], $this->all_tracked[$id]['type'], $this->all_tracked[$id]['typeid'], $this->all_tracked[$id]['imo'], $this->all_tracked[$id]['callsign'], $this->all_tracked[$id]['arrival_code'], $this->all_tracked[$id]['arrival_date'], $this->all_tracked[$id]['status'], $this->all_tracked[$id]['status_id'], $this->all_tracked[$id]['noarchive'], $this->all_tracked[$id]['format_source'], $this->all_tracked[$id]['source_name'], $this->all_tracked[$id]['over_country']); |
|
477 | 477 | $MarineLive->db = null; |
478 | 478 | if ($globalDebug) echo $result."\n"; |
479 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
479 | + if ($globalDebugTimeElapsed) echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true) - $timeelapsed, 2).'s'."\n"; |
|
480 | 480 | } |
481 | 481 | } |
482 | 482 | if (isset($globalServerAPRS) && $globalServerAPRS && $this->all_tracked[$id]['putinarchive']) { |
483 | - $APRSMarine->addLiveMarineData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['ident'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], $this->all_tracked[$id]['heading'], $this->all_tracked[$id]['speed'],$this->all_tracked[$id]['datetime'], $this->all_tracked[$id]['putinarchive'],$this->all_tracked[$id]['mmsi'],$this->all_tracked[$id]['type'],$this->all_tracked[$id]['typeid'],$this->all_tracked[$id]['imo'],$this->all_tracked[$id]['callsign'],$this->all_tracked[$id]['arrival_code'],$this->all_tracked[$id]['arrival_date'],$this->all_tracked[$id]['status'],$this->all_tracked[$id]['status_id'],$this->all_tracked[$id]['noarchive'],$this->all_tracked[$id]['format_source'],$this->all_tracked[$id]['source_name'],$this->all_tracked[$id]['over_country']); |
|
483 | + $APRSMarine->addLiveMarineData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['ident'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], $this->all_tracked[$id]['heading'], $this->all_tracked[$id]['speed'], $this->all_tracked[$id]['datetime'], $this->all_tracked[$id]['putinarchive'], $this->all_tracked[$id]['mmsi'], $this->all_tracked[$id]['type'], $this->all_tracked[$id]['typeid'], $this->all_tracked[$id]['imo'], $this->all_tracked[$id]['callsign'], $this->all_tracked[$id]['arrival_code'], $this->all_tracked[$id]['arrival_date'], $this->all_tracked[$id]['status'], $this->all_tracked[$id]['status_id'], $this->all_tracked[$id]['noarchive'], $this->all_tracked[$id]['format_source'], $this->all_tracked[$id]['source_name'], $this->all_tracked[$id]['over_country']); |
|
484 | 484 | } |
485 | 485 | $this->all_tracked[$id]['putinarchive'] = false; |
486 | 486 | |
@@ -499,19 +499,19 @@ discard block |
||
499 | 499 | $latitude = $globalCenterLatitude; |
500 | 500 | $longitude = $globalCenterLongitude; |
501 | 501 | } |
502 | - $this->source_location[$source] = array('latitude' => $latitude,'longitude' => $longitude); |
|
502 | + $this->source_location[$source] = array('latitude' => $latitude, 'longitude' => $longitude); |
|
503 | 503 | } else { |
504 | 504 | $latitude = $this->source_location[$source]['latitude']; |
505 | 505 | $longitude = $this->source_location[$source]['longitude']; |
506 | 506 | } |
507 | - $stats_heading = $Common->getHeading($latitude,$longitude,$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude']); |
|
507 | + $stats_heading = $Common->getHeading($latitude, $longitude, $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude']); |
|
508 | 508 | //$stats_heading = $stats_heading%22.5; |
509 | 509 | $stats_heading = round($stats_heading/22.5); |
510 | - $stats_distance = $Common->distance($latitude,$longitude,$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude']); |
|
510 | + $stats_distance = $Common->distance($latitude, $longitude, $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude']); |
|
511 | 511 | $current_date = date('Y-m-d'); |
512 | 512 | if ($stats_heading == 16) $stats_heading = 0; |
513 | 513 | if (!isset($this->stats[$current_date][$source]['polar'][1])) { |
514 | - for ($i=0;$i<=15;$i++) { |
|
514 | + for ($i = 0; $i <= 15; $i++) { |
|
515 | 515 | $this->stats[$current_date][$source]['polar'][$i] = 0; |
516 | 516 | } |
517 | 517 | $this->stats[$current_date][$source]['polar'][$stats_heading] = $stats_distance; |
@@ -526,9 +526,9 @@ discard block |
||
526 | 526 | if (!isset($this->stats[$current_date][$source]['hist'][$distance])) { |
527 | 527 | if (isset($this->stats[$current_date][$source]['hist'][0])) { |
528 | 528 | end($this->stats[$current_date][$source]['hist']); |
529 | - $mini = key($this->stats[$current_date][$source]['hist'])+10; |
|
529 | + $mini = key($this->stats[$current_date][$source]['hist']) + 10; |
|
530 | 530 | } else $mini = 0; |
531 | - for ($i=$mini;$i<=$distance;$i+=10) { |
|
531 | + for ($i = $mini; $i <= $distance; $i += 10) { |
|
532 | 532 | $this->stats[$current_date][$source]['hist'][$i] = 0; |
533 | 533 | } |
534 | 534 | $this->stats[$current_date][$source]['hist'][$distance] = 1; |
@@ -540,7 +540,7 @@ discard block |
||
540 | 540 | |
541 | 541 | $this->all_tracked[$id]['lastupdate'] = time(); |
542 | 542 | if ($this->all_tracked[$id]['putinarchive']) $send = true; |
543 | - } elseif (isset($this->all_tracked[$id]['latitude']) && isset($globalDistanceIgnore['latitude']) && $globalDebug) echo "!! Too far -> Distance : ".$Common->distance($this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude'])."\n"; |
|
543 | + } elseif (isset($this->all_tracked[$id]['latitude']) && isset($globalDistanceIgnore['latitude']) && $globalDebug) echo "!! Too far -> Distance : ".$Common->distance($this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], $globalDistanceIgnore['latitude'], $globalDistanceIgnore['longitude'])."\n"; |
|
544 | 544 | //$this->del(); |
545 | 545 | |
546 | 546 |
@@ -54,7 +54,9 @@ discard block |
||
54 | 54 | public function checkAll() { |
55 | 55 | global $globalDebug, $globalNoDB; |
56 | 56 | if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
57 | - if ($globalDebug) echo "Update last seen tracked data...\n"; |
|
57 | + if ($globalDebug) { |
|
58 | + echo "Update last seen tracked data...\n"; |
|
59 | + } |
|
58 | 60 | foreach ($this->all_tracked as $key => $flight) { |
59 | 61 | if (isset($this->all_tracked[$key]['id'])) { |
60 | 62 | //echo $this->all_tracked[$key]['id'].' - '.$this->all_tracked[$key]['latitude'].' '.$this->all_tracked[$key]['longitude']."\n"; |
@@ -68,13 +70,17 @@ discard block |
||
68 | 70 | public function del() { |
69 | 71 | global $globalDebug, $globalNoDB, $globalNoImport; |
70 | 72 | // Delete old infos |
71 | - if ($globalDebug) echo 'Delete old values and update latest data...'."\n"; |
|
73 | + if ($globalDebug) { |
|
74 | + echo 'Delete old values and update latest data...'."\n"; |
|
75 | + } |
|
72 | 76 | foreach ($this->all_tracked as $key => $flight) { |
73 | 77 | if (isset($flight['lastupdate'])) { |
74 | 78 | if ($flight['lastupdate'] < (time()-3000)) { |
75 | 79 | if ((!isset($globalNoImport) || $globalNoImport !== TRUE) && (!isset($globalNoDB) || $globalNoDB !== TRUE)) { |
76 | 80 | if (isset($this->all_tracked[$key]['id'])) { |
77 | - if ($globalDebug) echo "--- Delete old values with id ".$this->all_tracked[$key]['id']."\n"; |
|
81 | + if ($globalDebug) { |
|
82 | + echo "--- Delete old values with id ".$this->all_tracked[$key]['id']."\n"; |
|
83 | + } |
|
78 | 84 | /* |
79 | 85 | $MarineLive = new MarineLive(); |
80 | 86 | $MarineLive->deleteLiveMarineDataById($this->all_tracked[$key]['id']); |
@@ -84,7 +90,9 @@ discard block |
||
84 | 90 | $Marine = new Marine($this->db); |
85 | 91 | if ($this->all_tracked[$key]['latitude'] != '' && $this->all_tracked[$key]['longitude'] != '') { |
86 | 92 | $result = $Marine->updateLatestMarineData($this->all_tracked[$key]['id'],$this->all_tracked[$key]['ident'],$this->all_tracked[$key]['latitude'],$this->all_tracked[$key]['longitude'],$this->all_tracked[$key]['speed'],$this->all_tracked[$key]['datetime']); |
87 | - if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n"; |
|
93 | + if ($globalDebug && $result != 'success') { |
|
94 | + echo '!!! ERROR : '.$result."\n"; |
|
95 | + } |
|
88 | 96 | } |
89 | 97 | // Put in archive |
90 | 98 | // $Marine->db = null; |
@@ -98,7 +106,9 @@ discard block |
||
98 | 106 | |
99 | 107 | public function add($line) { |
100 | 108 | global $globalFork, $globalDistanceIgnore, $globalDaemon, $globalDebug, $globalCoordMinChange, $globalDebugTimeElapsed, $globalCenterLatitude, $globalCenterLongitude, $globalBeta, $globalSourcesupdate, $globalAllTracked, $globalNoImport, $globalNoDB, $globalServerAPRS,$APRSMarine; |
101 | - if (!isset($globalCoordMinChange) || $globalCoordMinChange == '') $globalCoordMinChange = '0.02'; |
|
109 | + if (!isset($globalCoordMinChange) || $globalCoordMinChange == '') { |
|
110 | + $globalCoordMinChange = '0.02'; |
|
111 | + } |
|
102 | 112 | date_default_timezone_set('UTC'); |
103 | 113 | $dataFound = false; |
104 | 114 | $send = false; |
@@ -112,20 +122,30 @@ discard block |
||
112 | 122 | // Increment message number |
113 | 123 | if (isset($line['sourcestats']) && $line['sourcestats'] == TRUE) { |
114 | 124 | $current_date = date('Y-m-d'); |
115 | - if (isset($line['source_name'])) $source = $line['source_name']; |
|
116 | - else $source = ''; |
|
117 | - if ($source == '' || $line['format_source'] == 'aprs') $source = $line['format_source']; |
|
125 | + if (isset($line['source_name'])) { |
|
126 | + $source = $line['source_name']; |
|
127 | + } else { |
|
128 | + $source = ''; |
|
129 | + } |
|
130 | + if ($source == '' || $line['format_source'] == 'aprs') { |
|
131 | + $source = $line['format_source']; |
|
132 | + } |
|
118 | 133 | if (!isset($this->stats[$current_date][$source]['msg'])) { |
119 | 134 | $this->stats[$current_date][$source]['msg']['date'] = time(); |
120 | 135 | $this->stats[$current_date][$source]['msg']['nb'] = 1; |
121 | - } else $this->stats[$current_date][$source]['msg']['nb'] += 1; |
|
136 | + } else { |
|
137 | + $this->stats[$current_date][$source]['msg']['nb'] += 1; |
|
138 | + } |
|
122 | 139 | } |
123 | 140 | |
124 | 141 | |
125 | 142 | $Common = new Common(); |
126 | 143 | $AIS = new AIS(); |
127 | - if (!isset($line['id'])) $id = trim($line['mmsi']); |
|
128 | - else $id = trim($line['id']); |
|
144 | + if (!isset($line['id'])) { |
|
145 | + $id = trim($line['mmsi']); |
|
146 | + } else { |
|
147 | + $id = trim($line['id']); |
|
148 | + } |
|
129 | 149 | |
130 | 150 | if (!isset($this->all_tracked[$id])) { |
131 | 151 | $this->all_tracked[$id] = array(); |
@@ -133,10 +153,16 @@ discard block |
||
133 | 153 | $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('ident' => '','latitude' => '', 'longitude' => '', 'speed' => '0', 'heading' => '', 'format_source' => '','source_name' => '','comment'=> '','type' => '','typeid' => '','noarchive' => false,'putinarchive' => true,'over_country' => '','mmsi' => '','status' => '','status_id' => '','imo' => '','callsign' => '','arrival_code' => '','arrival_date' => '','mmsi_type' => '')); |
134 | 154 | $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('lastupdate' => time())); |
135 | 155 | if (!isset($line['id'])) { |
136 | - if (!isset($globalDaemon)) $globalDaemon = TRUE; |
|
156 | + if (!isset($globalDaemon)) { |
|
157 | + $globalDaemon = TRUE; |
|
158 | + } |
|
137 | 159 | $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $id.'-'.date('YmdHi'))); |
138 | - } else $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $line['id'])); |
|
139 | - if ($globalAllTracked !== FALSE) $dataFound = true; |
|
160 | + } else { |
|
161 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $line['id'])); |
|
162 | + } |
|
163 | + if ($globalAllTracked !== FALSE) { |
|
164 | + $dataFound = true; |
|
165 | + } |
|
140 | 166 | } |
141 | 167 | |
142 | 168 | if (isset($line['mmsi']) && $line['mmsi'] != '' && $line['mmsi'] != $this->all_tracked[$id]['mmsi']) { |
@@ -191,7 +217,9 @@ discard block |
||
191 | 217 | if (isset($line['arrival_code']) && $line['arrival_code'] != '') { |
192 | 218 | if (!isset($this->all_tracked[$id]['arrival_code'])) { |
193 | 219 | $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('arrival_code' => $line['arrival_code'])); |
194 | - if ($globalDebug) echo $this->all_tracked[$id]['id'].' => New arrival: '.$line['arrival_code']."\n"; |
|
220 | + if ($globalDebug) { |
|
221 | + echo $this->all_tracked[$id]['id'].' => New arrival: '.$line['arrival_code']."\n"; |
|
222 | + } |
|
195 | 223 | if ($this->all_tracked[$id]['addedMarine'] != 0) { |
196 | 224 | if (!isset($globalNoImport) || $globalNoImport !== TRUE) { |
197 | 225 | if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
@@ -204,7 +232,9 @@ discard block |
||
204 | 232 | } |
205 | 233 | } elseif ($this->all_tracked[$id]['arrival_code'] != $line['arrival_code']) { |
206 | 234 | $this->all_tracked[$id]['arrival_code'] = $line['arrival_code']; |
207 | - if ($globalDebug) echo $this->all_tracked[$id]['id'].' => New arrival: '.$line['arrival_code']."\n"; |
|
235 | + if ($globalDebug) { |
|
236 | + echo $this->all_tracked[$id]['id'].' => New arrival: '.$line['arrival_code']."\n"; |
|
237 | + } |
|
208 | 238 | if (!isset($line['id'])) { |
209 | 239 | $this->all_tracked[$id]['id'] = $id.'-'.date('YmdHi'); |
210 | 240 | $this->all_tracked[$id]['forcenew'] = 1; |
@@ -213,7 +243,9 @@ discard block |
||
213 | 243 | } |
214 | 244 | } |
215 | 245 | if (isset($line['arrival_date']) && $line['arrival_date'] != '') { |
216 | - if (strtotime($line['arrival_date']) > time()) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('arrival_date' => $line['arrival_date'])); |
|
246 | + if (strtotime($line['arrival_date']) > time()) { |
|
247 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('arrival_date' => $line['arrival_date'])); |
|
248 | + } |
|
217 | 249 | } |
218 | 250 | |
219 | 251 | //if (isset($line['ident']) && $line['ident'] != '' && $line['ident'] != '????????' && $line['ident'] != '00000000' && ($this->all_tracked[$id]['ident'] != trim($line['ident'])) && preg_match('/^[a-zA-Z0-9-]+$/', $line['ident'])) { |
@@ -234,34 +266,49 @@ discard block |
||
234 | 266 | $Marine = new Marine($this->db); |
235 | 267 | $fromsource = NULL; |
236 | 268 | $result = $Marine->updateIdentMarineData($this->all_tracked[$id]['id'],$this->all_tracked[$id]['ident'],$fromsource); |
237 | - if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n"; |
|
269 | + if ($globalDebug && $result != 'success') { |
|
270 | + echo '!!! ERROR : '.$result."\n"; |
|
271 | + } |
|
238 | 272 | $Marine->db = null; |
239 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update identspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
273 | + if ($globalDebugTimeElapsed) { |
|
274 | + echo 'Time elapsed for update identspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
275 | + } |
|
240 | 276 | } |
241 | 277 | } |
242 | 278 | } |
243 | - if (!isset($this->all_tracked[$id]['id'])) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $this->all_tracked[$id]['ident'])); |
|
279 | + if (!isset($this->all_tracked[$id]['id'])) { |
|
280 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $this->all_tracked[$id]['ident'])); |
|
281 | + } |
|
244 | 282 | } |
245 | 283 | |
246 | 284 | if (isset($line['datetime']) && strtotime($line['datetime']) > time()-30*60 && strtotime($line['datetime']) < time()+20*60) { |
247 | 285 | if (!isset($this->all_tracked[$id]['datetime']) || strtotime($line['datetime']) > strtotime($this->all_tracked[$id]['datetime'])) { |
248 | 286 | $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('datetime' => $line['datetime'])); |
249 | 287 | } else { |
250 | - if (strtotime($line['datetime']) == strtotime($this->all_tracked[$id]['datetime']) && $globalDebug) echo "!!! Date is the same as previous data for ".$this->all_tracked[$id]['mmsi']."\n"; |
|
251 | - elseif (strtotime($line['datetime']) > strtotime($this->all_tracked[$id]['datetime']) && $globalDebug) echo "!!! Date previous latest data (".$line['datetime']." > ".$this->all_tracked[$id]['datetime'].") !!! for ".$this->all_tracked[$id]['hex']." - format : ".$line['format_source']."\n"; |
|
288 | + if (strtotime($line['datetime']) == strtotime($this->all_tracked[$id]['datetime']) && $globalDebug) { |
|
289 | + echo "!!! Date is the same as previous data for ".$this->all_tracked[$id]['mmsi']."\n"; |
|
290 | + } elseif (strtotime($line['datetime']) > strtotime($this->all_tracked[$id]['datetime']) && $globalDebug) { |
|
291 | + echo "!!! Date previous latest data (".$line['datetime']." > ".$this->all_tracked[$id]['datetime'].") !!! for ".$this->all_tracked[$id]['hex']." - format : ".$line['format_source']."\n"; |
|
292 | + } |
|
252 | 293 | return ''; |
253 | 294 | } |
254 | 295 | } elseif (isset($line['datetime']) && strtotime($line['datetime']) <= time()-30*60) { |
255 | - if ($globalDebug) echo "!!! Date is too old ".$this->all_tracked[$id]['mmsi']." - format : ".$line['format_source']."!!!\n"; |
|
296 | + if ($globalDebug) { |
|
297 | + echo "!!! Date is too old ".$this->all_tracked[$id]['mmsi']." - format : ".$line['format_source']."!!!\n"; |
|
298 | + } |
|
256 | 299 | return ''; |
257 | 300 | } elseif (isset($line['datetime']) && strtotime($line['datetime']) >= time()+20*60) { |
258 | - if ($globalDebug) echo "!!! Date is in the future ".$this->all_tracked[$id]['mmsi']." - format : ".$line['format_source']."!!!\n"; |
|
301 | + if ($globalDebug) { |
|
302 | + echo "!!! Date is in the future ".$this->all_tracked[$id]['mmsi']." - format : ".$line['format_source']."!!!\n"; |
|
303 | + } |
|
259 | 304 | return ''; |
260 | 305 | } elseif (!isset($line['datetime'])) { |
261 | 306 | date_default_timezone_set('UTC'); |
262 | 307 | $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('datetime' => date('Y-m-d H:i:s'))); |
263 | 308 | } else { |
264 | - if ($globalDebug) echo "!!! Unknow date error ".$this->all_tracked[$id]['mmsi']." date: ".$line['datetime']." - format : ".$line['format_source']."!!!\n"; |
|
309 | + if ($globalDebug) { |
|
310 | + echo "!!! Unknow date error ".$this->all_tracked[$id]['mmsi']." date: ".$line['datetime']." - format : ".$line['format_source']."!!!\n"; |
|
311 | + } |
|
265 | 312 | return ''; |
266 | 313 | } |
267 | 314 | |
@@ -274,14 +321,21 @@ discard block |
||
274 | 321 | if ($distance > 1000 && $distance < 10000) { |
275 | 322 | $speed = $distance/(time() - $this->all_tracked[$id]['time_last_coord']); |
276 | 323 | $speed = $speed*3.6; |
277 | - if ($speed < 1000) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed' => round($speed))); |
|
278 | - if ($globalDebug) echo "ø Calculated Speed for ".$this->all_tracked[$id]['hex']." : ".$speed." - distance : ".$distance."\n"; |
|
324 | + if ($speed < 1000) { |
|
325 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('speed' => round($speed))); |
|
326 | + } |
|
327 | + if ($globalDebug) { |
|
328 | + echo "ø Calculated Speed for ".$this->all_tracked[$id]['hex']." : ".$speed." - distance : ".$distance."\n"; |
|
329 | + } |
|
279 | 330 | } |
280 | 331 | } |
281 | 332 | |
282 | 333 | if (isset($line['latitude']) && isset($line['longitude']) && $line['latitude'] != '' && $line['longitude'] != '' && is_numeric($line['latitude']) && is_numeric($line['longitude'])) { |
283 | - if (isset($this->all_tracked[$id]['time_last_coord'])) $timediff = round(time()-$this->all_tracked[$id]['time_last_coord']); |
|
284 | - else unset($timediff); |
|
334 | + if (isset($this->all_tracked[$id]['time_last_coord'])) { |
|
335 | + $timediff = round(time()-$this->all_tracked[$id]['time_last_coord']); |
|
336 | + } else { |
|
337 | + unset($timediff); |
|
338 | + } |
|
285 | 339 | if ($this->tmd > 5 || !isset($timediff) || $timediff > 2000 || ($timediff > 30 && isset($this->all_tracked[$id]['latitude']) && isset($this->all_tracked[$id]['longitude']) && $Common->withinThreshold($timediff,$Common->distance($line['latitude'],$line['longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],'m')))) { |
286 | 340 | if (isset($this->all_tracked[$id]['archive_latitude']) && isset($this->all_tracked[$id]['archive_longitude']) && isset($this->all_tracked[$id]['livedb_latitude']) && isset($this->all_tracked[$id]['livedb_longitude'])) { |
287 | 341 | if (!$Common->checkLine($this->all_tracked[$id]['archive_latitude'],$this->all_tracked[$id]['archive_longitude'],$this->all_tracked[$id]['livedb_latitude'],$this->all_tracked[$id]['livedb_longitude'],$line['latitude'],$line['longitude'])) { |
@@ -289,22 +343,32 @@ discard block |
||
289 | 343 | $this->all_tracked[$id]['archive_longitude'] = $line['longitude']; |
290 | 344 | $this->all_tracked[$id]['putinarchive'] = true; |
291 | 345 | |
292 | - if ($globalDebug) echo "\n".' ------- Check Country for '.$this->all_tracked[$id]['ident'].' with latitude : '.$line['latitude'].' and longitude : '.$line['longitude'].'.... '; |
|
346 | + if ($globalDebug) { |
|
347 | + echo "\n".' ------- Check Country for '.$this->all_tracked[$id]['ident'].' with latitude : '.$line['latitude'].' and longitude : '.$line['longitude'].'.... '; |
|
348 | + } |
|
293 | 349 | $timeelapsed = microtime(true); |
294 | 350 | if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
295 | 351 | $Marine = new Marine($this->db); |
296 | 352 | $all_country = $Marine->getCountryFromLatitudeLongitude($line['latitude'],$line['longitude']); |
297 | - if (!empty($all_country)) $this->all_tracked[$id]['over_country'] = $all_country['iso2']; |
|
353 | + if (!empty($all_country)) { |
|
354 | + $this->all_tracked[$id]['over_country'] = $all_country['iso2']; |
|
355 | + } |
|
298 | 356 | $Marine->db = null; |
299 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
357 | + if ($globalDebugTimeElapsed) { |
|
358 | + echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
359 | + } |
|
300 | 360 | } |
301 | 361 | $this->tmd = 0; |
302 | - if ($globalDebug) echo 'FOUND : '.$this->all_tracked[$id]['over_country'].' ---------------'."\n"; |
|
362 | + if ($globalDebug) { |
|
363 | + echo 'FOUND : '.$this->all_tracked[$id]['over_country'].' ---------------'."\n"; |
|
364 | + } |
|
303 | 365 | } |
304 | 366 | } |
305 | 367 | |
306 | 368 | if (isset($line['latitude']) && $line['latitude'] != '' && $line['latitude'] != 0 && $line['latitude'] < 91 && $line['latitude'] > -90) { |
307 | - if (!isset($this->all_tracked[$id]['archive_latitude'])) $this->all_tracked[$id]['archive_latitude'] = $line['latitude']; |
|
369 | + if (!isset($this->all_tracked[$id]['archive_latitude'])) { |
|
370 | + $this->all_tracked[$id]['archive_latitude'] = $line['latitude']; |
|
371 | + } |
|
308 | 372 | if (!isset($this->all_tracked[$id]['livedb_latitude']) || abs($this->all_tracked[$id]['livedb_latitude']-$line['latitude']) > $globalCoordMinChange || $this->all_tracked[$id]['format_source'] == 'aprs') { |
309 | 373 | $this->all_tracked[$id]['livedb_latitude'] = $line['latitude']; |
310 | 374 | $dataFound = true; |
@@ -313,8 +377,12 @@ discard block |
||
313 | 377 | $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('latitude' => $line['latitude'])); |
314 | 378 | } |
315 | 379 | if (isset($line['longitude']) && $line['longitude'] != '' && $line['longitude'] != 0 && $line['longitude'] < 360 && $line['longitude'] > -180) { |
316 | - if ($line['longitude'] > 180) $line['longitude'] = $line['longitude'] - 360; |
|
317 | - if (!isset($this->all_tracked[$id]['archive_longitude'])) $this->all_tracked[$id]['archive_longitude'] = $line['longitude']; |
|
380 | + if ($line['longitude'] > 180) { |
|
381 | + $line['longitude'] = $line['longitude'] - 360; |
|
382 | + } |
|
383 | + if (!isset($this->all_tracked[$id]['archive_longitude'])) { |
|
384 | + $this->all_tracked[$id]['archive_longitude'] = $line['longitude']; |
|
385 | + } |
|
318 | 386 | if (!isset($this->all_tracked[$id]['livedb_longitude']) || abs($this->all_tracked[$id]['livedb_longitude']-$line['longitude']) > $globalCoordMinChange || $this->all_tracked[$id]['format_source'] == 'aprs') { |
319 | 387 | $this->all_tracked[$id]['livedb_longitude'] = $line['longitude']; |
320 | 388 | $dataFound = true; |
@@ -332,7 +400,9 @@ discard block |
||
332 | 400 | } |
333 | 401 | } |
334 | 402 | if (isset($line['last_update']) && $line['last_update'] != '') { |
335 | - if (isset($this->all_tracked[$id]['last_update']) && $this->all_tracked[$id]['last_update'] != $line['last_update']) $dataFound = true; |
|
403 | + if (isset($this->all_tracked[$id]['last_update']) && $this->all_tracked[$id]['last_update'] != $line['last_update']) { |
|
404 | + $dataFound = true; |
|
405 | + } |
|
336 | 406 | $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('last_update' => $line['last_update'])); |
337 | 407 | } |
338 | 408 | if (isset($line['format_source']) && $line['format_source'] != '') { |
@@ -346,15 +416,21 @@ discard block |
||
346 | 416 | } |
347 | 417 | |
348 | 418 | if (isset($line['heading']) && $line['heading'] != '') { |
349 | - if (is_int($this->all_tracked[$id]['heading']) && abs($this->all_tracked[$id]['heading']-round($line['heading'])) > 10) $this->all_tracked[$id]['putinarchive'] = true; |
|
419 | + if (is_int($this->all_tracked[$id]['heading']) && abs($this->all_tracked[$id]['heading']-round($line['heading'])) > 10) { |
|
420 | + $this->all_tracked[$id]['putinarchive'] = true; |
|
421 | + } |
|
350 | 422 | $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading' => round($line['heading']))); |
351 | 423 | $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading_fromsrc' => true)); |
352 | 424 | //$dataFound = true; |
353 | 425 | } elseif (!isset($this->all_tracked[$id]['heading_fromsrc']) && isset($this->all_tracked[$id]['archive_latitude']) && $this->all_tracked[$id]['archive_latitude'] != $this->all_tracked[$id]['latitude'] && isset($this->all_tracked[$id]['archive_longitude']) && $this->all_tracked[$id]['archive_longitude'] != $this->all_tracked[$id]['longitude']) { |
354 | 426 | $heading = $Common->getHeading($this->all_tracked[$id]['archive_latitude'],$this->all_tracked[$id]['archive_longitude'],$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude']); |
355 | 427 | $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('heading' => round($heading))); |
356 | - if (abs($this->all_tracked[$id]['heading']-round($heading)) > 10) $this->all_tracked[$id]['putinarchive'] = true; |
|
357 | - if ($globalDebug) echo "ø Calculated Heading for ".$this->all_tracked[$id]['ident']." : ".$heading."\n"; |
|
428 | + if (abs($this->all_tracked[$id]['heading']-round($heading)) > 10) { |
|
429 | + $this->all_tracked[$id]['putinarchive'] = true; |
|
430 | + } |
|
431 | + if ($globalDebug) { |
|
432 | + echo "ø Calculated Heading for ".$this->all_tracked[$id]['ident']." : ".$heading."\n"; |
|
433 | + } |
|
358 | 434 | } |
359 | 435 | //if (isset($globalSourcesupdate) && $globalSourcesupdate != '' && isset($this->all_tracked[$id]['lastupdate']) && time()-$this->all_tracked[$id]['lastupdate'] < $globalSourcesupdate) $dataFound = false; |
360 | 436 | |
@@ -366,23 +442,38 @@ discard block |
||
366 | 442 | if (!isset($globalDistanceIgnore['latitude']) || $this->all_tracked[$id]['longitude'] == '' || $this->all_tracked[$id]['latitude'] == '' || (isset($globalDistanceIgnore['latitude']) && $Common->distance($this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude']) < $globalDistanceIgnore['distance'])) { |
367 | 443 | if (!isset($this->all_tracked[$id]['forcenew']) || $this->all_tracked[$id]['forcenew'] == 0) { |
368 | 444 | if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
369 | - if ($globalDebug) echo "Check if vessel is already in DB..."; |
|
445 | + if ($globalDebug) { |
|
446 | + echo "Check if vessel is already in DB..."; |
|
447 | + } |
|
370 | 448 | $timeelapsed = microtime(true); |
371 | 449 | $MarineLive = new MarineLive($this->db); |
372 | 450 | if (isset($line['id'])) { |
373 | 451 | $recent_ident = $MarineLive->checkIdRecent($line['id']); |
374 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
452 | + if ($globalDebugTimeElapsed) { |
|
453 | + echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
454 | + } |
|
375 | 455 | } elseif (isset($this->all_tracked[$id]['mmsi']) && $this->all_tracked[$id]['mmsi'] != '') { |
376 | 456 | $recent_ident = $MarineLive->checkMMSIRecent($this->all_tracked[$id]['mmsi']); |
377 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
457 | + if ($globalDebugTimeElapsed) { |
|
458 | + echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
459 | + } |
|
378 | 460 | } elseif (isset($this->all_tracked[$id]['ident']) && $this->all_tracked[$id]['ident'] != '') { |
379 | 461 | $recent_ident = $MarineLive->checkIdentRecent($this->all_tracked[$id]['ident']); |
380 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
381 | - } else $recent_ident = ''; |
|
462 | + if ($globalDebugTimeElapsed) { |
|
463 | + echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
464 | + } |
|
465 | + } else { |
|
466 | + $recent_ident = ''; |
|
467 | + } |
|
382 | 468 | $MarineLive->db=null; |
383 | - if ($globalDebug && $recent_ident == '') echo " Not in DB.\n"; |
|
384 | - elseif ($globalDebug && $recent_ident != '') echo " Already in DB.\n"; |
|
385 | - } else $recent_ident = ''; |
|
469 | + if ($globalDebug && $recent_ident == '') { |
|
470 | + echo " Not in DB.\n"; |
|
471 | + } elseif ($globalDebug && $recent_ident != '') { |
|
472 | + echo " Already in DB.\n"; |
|
473 | + } |
|
474 | + } else { |
|
475 | + $recent_ident = ''; |
|
476 | + } |
|
386 | 477 | } else { |
387 | 478 | $recent_ident = ''; |
388 | 479 | $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('forcenew' => 0)); |
@@ -390,30 +481,44 @@ discard block |
||
390 | 481 | //if there was no vessel with the same callsign within the last hour and go post it into the archive |
391 | 482 | if($recent_ident == "" && $this->all_tracked[$id]['latitude'] != '' && $this->all_tracked[$id]['longitude'] != '') |
392 | 483 | { |
393 | - if ($globalDebug) echo "\o/ Add ".$this->all_tracked[$id]['mmsi']." in archive DB : "; |
|
484 | + if ($globalDebug) { |
|
485 | + echo "\o/ Add ".$this->all_tracked[$id]['mmsi']." in archive DB : "; |
|
486 | + } |
|
394 | 487 | //adds the spotter data for the archive |
395 | 488 | $highlight = ''; |
396 | - if (!isset($this->all_tracked[$id]['id'])) $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $this->all_tracked[$id]['mmsi'].'-'.date('YmdHi'))); |
|
489 | + if (!isset($this->all_tracked[$id]['id'])) { |
|
490 | + $this->all_tracked[$id] = array_merge($this->all_tracked[$id],array('id' => $this->all_tracked[$id]['mmsi'].'-'.date('YmdHi'))); |
|
491 | + } |
|
397 | 492 | if (!isset($globalNoImport) || $globalNoImport !== TRUE) { |
398 | 493 | if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
399 | 494 | $timeelapsed = microtime(true); |
400 | 495 | $Marine = new Marine($this->db); |
401 | 496 | $result = $Marine->addMarineData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['ident'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], $this->all_tracked[$id]['heading'], $this->all_tracked[$id]['speed'], $this->all_tracked[$id]['datetime'], $this->all_tracked[$id]['mmsi'], $this->all_tracked[$id]['type'],$this->all_tracked[$id]['typeid'],$this->all_tracked[$id]['imo'],$this->all_tracked[$id]['callsign'],$this->all_tracked[$id]['arrival_code'],$this->all_tracked[$id]['arrival_date'], $this->all_tracked[$id]['status'], $this->all_tracked[$id]['status_id'],$this->all_tracked[$id]['format_source'],$this->all_tracked[$id]['source_name']); |
402 | 497 | $Marine->db = null; |
403 | - if ($globalDebug && isset($result)) echo $result."\n"; |
|
404 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
498 | + if ($globalDebug && isset($result)) { |
|
499 | + echo $result."\n"; |
|
500 | + } |
|
501 | + if ($globalDebugTimeElapsed) { |
|
502 | + echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
503 | + } |
|
405 | 504 | } |
406 | 505 | } |
407 | 506 | if (isset($line['sourcestats']) && $line['sourcestats'] == TRUE && $this->all_tracked[$id]['latitude'] != '' && $this->all_tracked[$id]['longitude'] != '') { |
408 | 507 | // Add source stat in DB |
409 | 508 | $Stats = new Stats($this->db); |
410 | 509 | if (!empty($this->stats)) { |
411 | - if ($globalDebug) echo 'Add source stats : '; |
|
510 | + if ($globalDebug) { |
|
511 | + echo 'Add source stats : '; |
|
512 | + } |
|
412 | 513 | foreach($this->stats as $date => $data) { |
413 | 514 | foreach($data as $source => $sourced) { |
414 | 515 | //print_r($sourced); |
415 | - if (isset($sourced['polar'])) echo $Stats->addStatSource(json_encode($sourced['polar']),$source,'polar_marine',$date); |
|
416 | - if (isset($sourced['hist'])) echo $Stats->addStatSource(json_encode($sourced['hist']),$source,'hist_marine',$date); |
|
516 | + if (isset($sourced['polar'])) { |
|
517 | + echo $Stats->addStatSource(json_encode($sourced['polar']),$source,'polar_marine',$date); |
|
518 | + } |
|
519 | + if (isset($sourced['hist'])) { |
|
520 | + echo $Stats->addStatSource(json_encode($sourced['hist']),$source,'hist_marine',$date); |
|
521 | + } |
|
417 | 522 | if (isset($sourced['msg'])) { |
418 | 523 | if (time() - $sourced['msg']['date'] > 10) { |
419 | 524 | $nbmsg = round($sourced['msg']['nb']/(time() - $sourced['msg']['date'])); |
@@ -426,7 +531,9 @@ discard block |
||
426 | 531 | unset($this->stats[$date]); |
427 | 532 | } |
428 | 533 | } |
429 | - if ($globalDebug) echo 'Done'."\n"; |
|
534 | + if ($globalDebug) { |
|
535 | + echo 'Done'."\n"; |
|
536 | + } |
|
430 | 537 | } |
431 | 538 | $Stats->db = null; |
432 | 539 | } |
@@ -436,13 +543,17 @@ discard block |
||
436 | 543 | $this->all_tracked[$id]['addedMarine'] = 1; |
437 | 544 | //print_r($this->all_tracked[$id]); |
438 | 545 | if ($this->last_delete == 0 || time() - $this->last_delete > 1800) { |
439 | - if ($globalDebug) echo "---- Deleting Live Marine data older than 9 hours..."; |
|
546 | + if ($globalDebug) { |
|
547 | + echo "---- Deleting Live Marine data older than 9 hours..."; |
|
548 | + } |
|
440 | 549 | //MarineLive->deleteLiveMarineDataNotUpdated(); |
441 | 550 | if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
442 | 551 | $MarineLive = new MarineLive($this->db); |
443 | 552 | $MarineLive->deleteLiveMarineData(); |
444 | 553 | $MarineLive->db=null; |
445 | - if ($globalDebug) echo " Done\n"; |
|
554 | + if ($globalDebug) { |
|
555 | + echo " Done\n"; |
|
556 | + } |
|
446 | 557 | } |
447 | 558 | $this->last_delete = time(); |
448 | 559 | } |
@@ -468,15 +579,21 @@ discard block |
||
468 | 579 | |
469 | 580 | if (!$ignoreImport) { |
470 | 581 | if (!isset($globalDistanceIgnore['latitude']) || (isset($globalDistanceIgnore['latitude']) && $Common->distance($this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude']) < $globalDistanceIgnore['distance'])) { |
471 | - if ($globalDebug) echo "\o/ Add ".$this->all_tracked[$id]['ident']." from ".$this->all_tracked[$id]['format_source']." in Live DB : "; |
|
582 | + if ($globalDebug) { |
|
583 | + echo "\o/ Add ".$this->all_tracked[$id]['ident']." from ".$this->all_tracked[$id]['format_source']." in Live DB : "; |
|
584 | + } |
|
472 | 585 | if (!isset($globalNoImport) || $globalNoImport !== TRUE) { |
473 | 586 | if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
474 | 587 | $timeelapsed = microtime(true); |
475 | 588 | $MarineLive = new MarineLive($this->db); |
476 | 589 | $result = $MarineLive->addLiveMarineData($this->all_tracked[$id]['id'], $this->all_tracked[$id]['ident'], $this->all_tracked[$id]['latitude'], $this->all_tracked[$id]['longitude'], $this->all_tracked[$id]['heading'], $this->all_tracked[$id]['speed'],$this->all_tracked[$id]['datetime'], $this->all_tracked[$id]['putinarchive'],$this->all_tracked[$id]['mmsi'],$this->all_tracked[$id]['type'],$this->all_tracked[$id]['typeid'],$this->all_tracked[$id]['imo'],$this->all_tracked[$id]['callsign'],$this->all_tracked[$id]['arrival_code'],$this->all_tracked[$id]['arrival_date'],$this->all_tracked[$id]['status'],$this->all_tracked[$id]['status_id'],$this->all_tracked[$id]['noarchive'],$this->all_tracked[$id]['format_source'],$this->all_tracked[$id]['source_name'],$this->all_tracked[$id]['over_country']); |
477 | 590 | $MarineLive->db = null; |
478 | - if ($globalDebug) echo $result."\n"; |
|
479 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
591 | + if ($globalDebug) { |
|
592 | + echo $result."\n"; |
|
593 | + } |
|
594 | + if ($globalDebugTimeElapsed) { |
|
595 | + echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
596 | + } |
|
480 | 597 | } |
481 | 598 | } |
482 | 599 | if (isset($globalServerAPRS) && $globalServerAPRS && $this->all_tracked[$id]['putinarchive']) { |
@@ -488,7 +605,9 @@ discard block |
||
488 | 605 | |
489 | 606 | if (isset($line['sourcestats']) && $line['sourcestats'] == TRUE && $line['format_source'] != 'aprs' && $this->all_tracked[$id]['latitude'] != '' && $this->all_tracked[$id]['longitude'] != '') { |
490 | 607 | $source = $this->all_tracked[$id]['source_name']; |
491 | - if ($source == '') $source = $this->all_tracked[$id]['format_source']; |
|
608 | + if ($source == '') { |
|
609 | + $source = $this->all_tracked[$id]['format_source']; |
|
610 | + } |
|
492 | 611 | if (!isset($this->source_location[$source])) { |
493 | 612 | $Location = new Source($this->db); |
494 | 613 | $coord = $Location->getLocationInfobySourceName($source); |
@@ -509,7 +628,9 @@ discard block |
||
509 | 628 | $stats_heading = round($stats_heading/22.5); |
510 | 629 | $stats_distance = $Common->distance($latitude,$longitude,$this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude']); |
511 | 630 | $current_date = date('Y-m-d'); |
512 | - if ($stats_heading == 16) $stats_heading = 0; |
|
631 | + if ($stats_heading == 16) { |
|
632 | + $stats_heading = 0; |
|
633 | + } |
|
513 | 634 | if (!isset($this->stats[$current_date][$source]['polar'][1])) { |
514 | 635 | for ($i=0;$i<=15;$i++) { |
515 | 636 | $this->stats[$current_date][$source]['polar'][$i] = 0; |
@@ -527,7 +648,9 @@ discard block |
||
527 | 648 | if (isset($this->stats[$current_date][$source]['hist'][0])) { |
528 | 649 | end($this->stats[$current_date][$source]['hist']); |
529 | 650 | $mini = key($this->stats[$current_date][$source]['hist'])+10; |
530 | - } else $mini = 0; |
|
651 | + } else { |
|
652 | + $mini = 0; |
|
653 | + } |
|
531 | 654 | for ($i=$mini;$i<=$distance;$i+=10) { |
532 | 655 | $this->stats[$current_date][$source]['hist'][$i] = 0; |
533 | 656 | } |
@@ -539,19 +662,27 @@ discard block |
||
539 | 662 | |
540 | 663 | |
541 | 664 | $this->all_tracked[$id]['lastupdate'] = time(); |
542 | - if ($this->all_tracked[$id]['putinarchive']) $send = true; |
|
543 | - } elseif (isset($this->all_tracked[$id]['latitude']) && isset($globalDistanceIgnore['latitude']) && $globalDebug) echo "!! Too far -> Distance : ".$Common->distance($this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude'])."\n"; |
|
665 | + if ($this->all_tracked[$id]['putinarchive']) { |
|
666 | + $send = true; |
|
667 | + } |
|
668 | + } elseif (isset($this->all_tracked[$id]['latitude']) && isset($globalDistanceIgnore['latitude']) && $globalDebug) { |
|
669 | + echo "!! Too far -> Distance : ".$Common->distance($this->all_tracked[$id]['latitude'],$this->all_tracked[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude'])."\n"; |
|
670 | + } |
|
544 | 671 | //$this->del(); |
545 | 672 | |
546 | 673 | |
547 | 674 | if ($this->last_delete_hourly == 0 || time() - $this->last_delete_hourly > 900) { |
548 | 675 | if (!isset($globalNoDB) || $globalNoDB !== TRUE) { |
549 | - if ($globalDebug) echo "---- Deleting Live Marine data Not updated since 2 hour..."; |
|
676 | + if ($globalDebug) { |
|
677 | + echo "---- Deleting Live Marine data Not updated since 2 hour..."; |
|
678 | + } |
|
550 | 679 | $MarineLive = new MarineLive($this->db); |
551 | 680 | $MarineLive->deleteLiveMarineDataNotUpdated(); |
552 | 681 | $MarineLive->db = null; |
553 | 682 | //MarineLive->deleteLiveMarineData(); |
554 | - if ($globalDebug) echo " Done\n"; |
|
683 | + if ($globalDebug) { |
|
684 | + echo " Done\n"; |
|
685 | + } |
|
555 | 686 | } |
556 | 687 | $this->last_delete_hourly = time(); |
557 | 688 | } |
@@ -560,7 +691,9 @@ discard block |
||
560 | 691 | //$ignoreImport = false; |
561 | 692 | } |
562 | 693 | //if (function_exists('pcntl_fork') && $globalFork) pcntl_signal(SIGCHLD, SIG_IGN); |
563 | - if ($send) return $this->all_tracked[$id]; |
|
694 | + if ($send) { |
|
695 | + return $this->all_tracked[$id]; |
|
696 | + } |
|
564 | 697 | } |
565 | 698 | } |
566 | 699 | } |