@@ -3,6 +3,10 @@ |
||
3 | 3 | require_once(dirname(__FILE__).'/../require/class.Connection.php'); |
4 | 4 | |
5 | 5 | class create_db { |
6 | + |
|
7 | + /** |
|
8 | + * @param string $filename |
|
9 | + */ |
|
6 | 10 | public static function import_file($filename) { |
7 | 11 | $filename = filter_var($filename,FILTER_SANITIZE_STRING); |
8 | 12 | $Connection = new Connection(); |
@@ -29,9 +29,9 @@ discard block |
||
29 | 29 | } |
30 | 30 | fclose($handle); |
31 | 31 | } |
32 | - //Connection::$db->commit(); |
|
33 | - $Connection->db = null; |
|
34 | - return ''; |
|
32 | + //Connection::$db->commit(); |
|
33 | + $Connection->db = null; |
|
34 | + return ''; |
|
35 | 35 | } |
36 | 36 | |
37 | 37 | public static function import_all_db($directory) { |
@@ -40,7 +40,7 @@ discard block |
||
40 | 40 | //foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($directory)) as $filename) |
41 | 41 | while(false !== ($filename = readdir($dh))) |
42 | 42 | { |
43 | - if (preg_match('/\.sql$/',$filename)) $error .= create_db::import_file($directory.$filename); |
|
43 | + if (preg_match('/\.sql$/',$filename)) $error .= create_db::import_file($directory.$filename); |
|
44 | 44 | } |
45 | 45 | return $error; |
46 | 46 | } |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | $host = filter_var($host,FILTER_SANITIZE_STRING); |
56 | 56 | // Dirty hack |
57 | 57 | if ($host != 'localhost' && $host != '127.0.0.1') { |
58 | - $grantright = $_SERVER['SERVER_ADDR']; |
|
58 | + $grantright = $_SERVER['SERVER_ADDR']; |
|
59 | 59 | } else $grantright = 'localhost'; |
60 | 60 | try { |
61 | 61 | $dbh = new PDO($db_type.':host='.$host,$root,$root_pass); |
@@ -13,6 +13,9 @@ discard block |
||
13 | 13 | function sparql_connect( $endpoint ) { return new sparql_connection( $endpoint ); } |
14 | 14 | |
15 | 15 | function sparql_ns( $short, $long, $db = null ) { return _sparql_a_connection( $db )->ns( $short, $long ); } |
16 | +/** |
|
17 | + * @param string $sparql |
|
18 | + */ |
|
16 | 19 | function sparql_query( $sparql, $db = null ) { return _sparql_a_connection( $db )->query( $sparql ); } |
17 | 20 | function sparql_errno( $db = null ) { return _sparql_a_connection( $db )->errno(); } |
18 | 21 | function sparql_error( $db = null ) { return _sparql_a_connection( $db )->error(); } |
@@ -84,6 +87,9 @@ discard block |
||
84 | 87 | $this->params = $params; |
85 | 88 | } |
86 | 89 | |
90 | + /** |
|
91 | + * @param integer $timeout |
|
92 | + */ |
|
87 | 93 | function query( $query, $timeout=null ) |
88 | 94 | { |
89 | 95 | $prefixes = ""; |
@@ -324,6 +330,10 @@ discard block |
||
324 | 330 | var $fields; |
325 | 331 | var $db; |
326 | 332 | var $i = 0; |
333 | + |
|
334 | + /** |
|
335 | + * @param sparql_connection $db |
|
336 | + */ |
|
327 | 337 | function __construct( $db, $rows, $fields ) |
328 | 338 | { |
329 | 339 | $this->rows = $rows; |
@@ -1,5 +1,10 @@ |
||
1 | 1 | <?php |
2 | 2 | class aprs { |
3 | + |
|
4 | + /** |
|
5 | + * @param integer $n |
|
6 | + * @param integer $s |
|
7 | + */ |
|
3 | 8 | private function urshift($n, $s) { |
4 | 9 | return ($n >= 0) ? ($n >> $s) : |
5 | 10 | (($n & 0x7fffffff) >> $s) | |
@@ -1,12 +1,12 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | class aprs { |
3 | - private function urshift($n, $s) { |
|
3 | + private function urshift($n, $s) { |
|
4 | 4 | return ($n >= 0) ? ($n >> $s) : |
5 | - (($n & 0x7fffffff) >> $s) | |
|
6 | - (0x40000000 >> ($s - 1)); |
|
7 | - } |
|
5 | + (($n & 0x7fffffff) >> $s) | |
|
6 | + (0x40000000 >> ($s - 1)); |
|
7 | + } |
|
8 | 8 | |
9 | - public function parse($input) { |
|
9 | + public function parse($input) { |
|
10 | 10 | global $globalDebug; |
11 | 11 | $debug = false; |
12 | 12 | $result = array(); |
@@ -18,8 +18,8 @@ discard block |
||
18 | 18 | |
19 | 19 | /* Check that end was found and body has at least one byte. */ |
20 | 20 | if ($splitpos == 0 || $splitpos + 1 == $input_len || $splitpos === FALSE) { |
21 | - if ($globalDebug) echo '!!! APRS invalid : '.$input."\n"; |
|
22 | - return false; |
|
21 | + if ($globalDebug) echo '!!! APRS invalid : '.$input."\n"; |
|
22 | + return false; |
|
23 | 23 | } |
24 | 24 | |
25 | 25 | /* Save header and body. */ |
@@ -32,22 +32,22 @@ discard block |
||
32 | 32 | /* Parse source, target and path. */ |
33 | 33 | //FLRDF0A52>APRS,qAS,LSTB |
34 | 34 | if (preg_match('/^([A-Z0-9\\-]{1,9})>(.*)$/',$header,$matches)) { |
35 | - $ident = $matches[1]; |
|
36 | - $all_elements = $matches[2]; |
|
37 | - if ($debug) echo 'ident : '.$ident."\n"; |
|
38 | - $result['ident'] = $ident; |
|
35 | + $ident = $matches[1]; |
|
36 | + $all_elements = $matches[2]; |
|
37 | + if ($debug) echo 'ident : '.$ident."\n"; |
|
38 | + $result['ident'] = $ident; |
|
39 | 39 | } else return false; |
40 | 40 | $elements = explode(',',$all_elements); |
41 | 41 | $source = end($elements); |
42 | 42 | $result['source'] = $source; |
43 | 43 | foreach ($elements as $element) { |
44 | - if (preg_match('/^([a-zA-Z0-9-]{1,9})([*]?)$/',$element)) { |
|
45 | - //echo "ok"; |
|
46 | - if ($element == 'TCPIP*') return false; |
|
47 | - } elseif (!preg_match('/^([0-9A-F]{32})$/',$element)) { |
|
44 | + if (preg_match('/^([a-zA-Z0-9-]{1,9})([*]?)$/',$element)) { |
|
45 | + //echo "ok"; |
|
46 | + if ($element == 'TCPIP*') return false; |
|
47 | + } elseif (!preg_match('/^([0-9A-F]{32})$/',$element)) { |
|
48 | 48 | return false; |
49 | - } |
|
50 | - /* |
|
49 | + } |
|
50 | + /* |
|
51 | 51 | } elseif (preg_match('/^([0-9A-F]{32})$/',$element)) { |
52 | 52 | //echo "ok"; |
53 | 53 | } else { |
@@ -58,23 +58,23 @@ discard block |
||
58 | 58 | // Check for Timestamp |
59 | 59 | $body_parse = substr($body,1); |
60 | 60 | if (preg_match('/^([0-9]{2})([0-9]{2})([0-9]{2})([zh\\/])/',$body_parse,$matches)) { |
61 | - $timestamp = $matches[0]; |
|
62 | - if ($matches[4] == 'h') { |
|
61 | + $timestamp = $matches[0]; |
|
62 | + if ($matches[4] == 'h') { |
|
63 | 63 | $timestamp = strtotime($matches[1].':'.$matches[2].':'.$matches[3]); |
64 | 64 | //echo 'timestamp : '.$timestamp.' - now : '.time()."\n"; |
65 | 65 | /* |
66 | 66 | if (time() + 3900 < $timestamp) $timestamp -= 86400; |
67 | 67 | elseif (time() - 82500 > $timestamp) $timestamp += 86400; |
68 | 68 | */ |
69 | - } elseif ($matches[4] == 'z' || $matches[4] == '/') { |
|
69 | + } elseif ($matches[4] == 'z' || $matches[4] == '/') { |
|
70 | 70 | // This work or not ? |
71 | 71 | $timestamp = strtotime($matches[1].' '.$matches[2].':'.$matches[3]); |
72 | - } |
|
73 | - $body_parse = substr($body_parse,7); |
|
74 | - $result['timestamp'] = $timestamp; |
|
72 | + } |
|
73 | + $body_parse = substr($body_parse,7); |
|
74 | + $result['timestamp'] = $timestamp; |
|
75 | 75 | } |
76 | 76 | if (strlen($body_parse) > 19) { |
77 | - if (preg_match('/^([0-9]{2})([0-7 ][0-9 ]\\.[0-9 ]{2})([NnSs])(.)([0-9]{3})([0-7 ][0-9 ]\\.[0-9 ]{2})([EeWw])(.)/',$body_parse,$matches)) { |
|
77 | + if (preg_match('/^([0-9]{2})([0-7 ][0-9 ]\\.[0-9 ]{2})([NnSs])(.)([0-9]{3})([0-7 ][0-9 ]\\.[0-9 ]{2})([EeWw])(.)/',$body_parse,$matches)) { |
|
78 | 78 | // 4658.70N/00707.78Ez |
79 | 79 | //print_r(str_split($body_parse)); |
80 | 80 | |
@@ -91,7 +91,7 @@ discard block |
||
91 | 91 | $lon = intval($lon_deg); |
92 | 92 | if ($lat > 89 || $lon > 179) return false; |
93 | 93 | |
94 | - /* |
|
94 | + /* |
|
95 | 95 | $tmp_5b = str_replace('.','',$lat_min); |
96 | 96 | if (preg_match('/^([0-9]{0,4})( {0,4})$/',$tmp_5b,$matches)) { |
97 | 97 | print_r($matches); |
@@ -103,64 +103,64 @@ discard block |
||
103 | 103 | if ($wind == 'W') $longitude = 0-$longitude; |
104 | 104 | $result['latitude'] = $latitude; |
105 | 105 | $result['longitude'] = $longitude; |
106 | - } |
|
107 | - if ($body_len > 19) { |
|
106 | + } |
|
107 | + if ($body_len > 19) { |
|
108 | 108 | $body_split = str_split($body_parse); |
109 | 109 | $symbol_code = $body_split[18]; |
110 | 110 | if ($symbol_code != '_') { |
111 | - $body_parse = substr($body_parse,19); |
|
112 | - $body_parse_len = strlen($body_parse); |
|
113 | - if ($body_parse_len >= 7) { |
|
111 | + $body_parse = substr($body_parse,19); |
|
112 | + $body_parse_len = strlen($body_parse); |
|
113 | + if ($body_parse_len >= 7) { |
|
114 | 114 | |
115 | - if (preg_match('/^([0-9\\. ]{3})\\/([0-9\\. ]{3})/',$body_parse)) { |
|
116 | - $course = substr($body_parse,0,3); |
|
117 | - $tmp_s = intval($course); |
|
118 | - if ($tmp_s >= 1 && $tmp_s <= 360) $result['course'] = intval($course); |
|
119 | - $speed = substr($body_parse,4,3); |
|
120 | - $result['speed'] = round($speed*1.852); |
|
121 | - $body_parse = substr($body_parse,7); |
|
122 | - } |
|
123 | - // Check PHGR, PHG, RNG |
|
124 | - } |
|
125 | - /* |
|
115 | + if (preg_match('/^([0-9\\. ]{3})\\/([0-9\\. ]{3})/',$body_parse)) { |
|
116 | + $course = substr($body_parse,0,3); |
|
117 | + $tmp_s = intval($course); |
|
118 | + if ($tmp_s >= 1 && $tmp_s <= 360) $result['course'] = intval($course); |
|
119 | + $speed = substr($body_parse,4,3); |
|
120 | + $result['speed'] = round($speed*1.852); |
|
121 | + $body_parse = substr($body_parse,7); |
|
122 | + } |
|
123 | + // Check PHGR, PHG, RNG |
|
124 | + } |
|
125 | + /* |
|
126 | 126 | else if ($body_parse_len > 0) { |
127 | 127 | $rest = $body_parse; |
128 | 128 | } |
129 | 129 | */ |
130 | - if (strlen($body_parse) > 0) { |
|
131 | - if (preg_match('/\\/A=(-[0-9]{5}|[0-9]{6})/',$body_parse,$matches)) { |
|
132 | - $altitude = intval($matches[1]); |
|
133 | - //$result['altitude'] = round($altitude*0.3048); |
|
134 | - $result['altitude'] = $altitude; |
|
135 | - $body_parse = substr($body_parse,strlen($matches[0])+1); |
|
136 | - } |
|
137 | - } |
|
130 | + if (strlen($body_parse) > 0) { |
|
131 | + if (preg_match('/\\/A=(-[0-9]{5}|[0-9]{6})/',$body_parse,$matches)) { |
|
132 | + $altitude = intval($matches[1]); |
|
133 | + //$result['altitude'] = round($altitude*0.3048); |
|
134 | + $result['altitude'] = $altitude; |
|
135 | + $body_parse = substr($body_parse,strlen($matches[0])+1); |
|
136 | + } |
|
137 | + } |
|
138 | 138 | |
139 | - // Telemetry |
|
140 | - /* |
|
139 | + // Telemetry |
|
140 | + /* |
|
141 | 141 | if (preg_match('/^([0-9]+),(-?)([0-9]{1,6}|[0-9]+\\.[0-9]+|\\.[0-9]+)?,(-?)([0-9]{1,6}|[0-9]+\\.[0-9]+|\\.[0-9]+)?,(-?)([0-9]{1,6}|[0-9]+\\.[0-9]+|\\.[0-9]+)?,(-?)([0-9]{1,6}|[0-9]+\\.[0-9]+|\\.[0-9]+)?,(-?)([0-9]{1,6}|[0-9]+\\.[0-9]+|\\.[0-9]+)?,([01]{0,8})/',$body_parse,$matches)) { |
142 | 142 | // Nothing yet... |
143 | 143 | } |
144 | 144 | */ |
145 | - // DAO |
|
146 | - if (preg_match('/^!([0-9A-Z]{3})/',$body_parse,$matches)) { |
|
147 | - $dao = $matches[1]; |
|
148 | - if (preg_match('/^([A-Z])([0-9]{2})/',$dao)) { |
|
145 | + // DAO |
|
146 | + if (preg_match('/^!([0-9A-Z]{3})/',$body_parse,$matches)) { |
|
147 | + $dao = $matches[1]; |
|
148 | + if (preg_match('/^([A-Z])([0-9]{2})/',$dao)) { |
|
149 | 149 | $dao_split = str_split($dao); |
150 | - $lat_off = (($dao_split[1])-48.0)*0.001/60.0; |
|
151 | - $lon_off = (($dao_split[2])-48.0)*0.001/60.0; |
|
150 | + $lat_off = (($dao_split[1])-48.0)*0.001/60.0; |
|
151 | + $lon_off = (($dao_split[2])-48.0)*0.001/60.0; |
|
152 | 152 | |
153 | 153 | if ($result['latitude'] < 0) $result['latitude'] -= $lat_off; |
154 | 154 | else $result['latitude'] += $lat_off; |
155 | 155 | if ($result['longitude'] < 0) $result['longitude'] -= $lon_off; |
156 | 156 | else $result['longitude'] += $lon_off; |
157 | - } |
|
158 | - $body_parse = substr($body_parse,6); |
|
159 | - } |
|
157 | + } |
|
158 | + $body_parse = substr($body_parse,6); |
|
159 | + } |
|
160 | 160 | |
161 | - // OGN comment |
|
161 | + // OGN comment |
|
162 | 162 | // echo "Before OGN : ".$body_parse."\n"; |
163 | - if (preg_match('/^id([0-9A-F]{8}) ([+-])([0-9]{3,4})fpm ([+-])([0-9.]{3,4})rot (.*)$/',$body_parse,$matches)) { |
|
163 | + if (preg_match('/^id([0-9A-F]{8}) ([+-])([0-9]{3,4})fpm ([+-])([0-9.]{3,4})rot (.*)$/',$body_parse,$matches)) { |
|
164 | 164 | $id = $matches[1]; |
165 | 165 | //$mode = substr($id,0,2); |
166 | 166 | $address = substr($id,2); |
@@ -190,49 +190,49 @@ discard block |
||
190 | 190 | $stealth = (intval(substr($id,0,2), 16) & 0b10000000) != 0; |
191 | 191 | $result['stealth'] = $stealth; |
192 | 192 | $result['address'] = $address; |
193 | - } |
|
193 | + } |
|
194 | 194 | |
195 | - //Comment |
|
196 | - $result['comment'] = $body_parse; |
|
195 | + //Comment |
|
196 | + $result['comment'] = $body_parse; |
|
197 | 197 | } else { |
198 | - // parse weather |
|
199 | - $body_parse = substr($body_parse,19); |
|
200 | - //$body_parse_len = strlen($body_parse); |
|
198 | + // parse weather |
|
199 | + $body_parse = substr($body_parse,19); |
|
200 | + //$body_parse_len = strlen($body_parse); |
|
201 | 201 | |
202 | - if (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})g([0-9 \\.]+)t(-{0,1}[0-9 \\.]+)/',$body_parse,$matches)) { |
|
202 | + if (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})g([0-9 \\.]+)t(-{0,1}[0-9 \\.]+)/',$body_parse,$matches)) { |
|
203 | 203 | $result['wind_dir'] = $matches[1]; |
204 | 204 | $result['wind_speed'] = round($matches[2]*1.60934,1); |
205 | 205 | $result['wind_gust'] = round($matches[3]*1.60934,1); |
206 | 206 | $result['temp'] = round(5/9*(($matches[4])-32),1); |
207 | - $body_parse = substr($body_parse,strlen($matches[0])+1); |
|
208 | - } elseif (preg_match('/^_{0,1}c([0-9 \\.\\-]{3})s([0-9 \\.]{3})g([0-9 \\.]+)t(-{0,1}[0-9 \\.]+)/',$body_parse,$matches)) { |
|
207 | + $body_parse = substr($body_parse,strlen($matches[0])+1); |
|
208 | + } elseif (preg_match('/^_{0,1}c([0-9 \\.\\-]{3})s([0-9 \\.]{3})g([0-9 \\.]+)t(-{0,1}[0-9 \\.]+)/',$body_parse,$matches)) { |
|
209 | 209 | $result['wind_dir'] = $matches[1]; |
210 | 210 | $result['wind_speed'] = round($matches[2]*1.60934,1); |
211 | 211 | $result['wind_gust'] = round($matches[3]*1.60934,1); |
212 | 212 | $result['temp'] = round(5/9*(($matches[4])-32),1); |
213 | - $body_parse = substr($body_parse,strlen($matches[0])+1); |
|
214 | - } elseif (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})t(-{0,1}[0-9 \\.]+)/',$body_parse,$matches)) { |
|
213 | + $body_parse = substr($body_parse,strlen($matches[0])+1); |
|
214 | + } elseif (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})t(-{0,1}[0-9 \\.]+)/',$body_parse,$matches)) { |
|
215 | 215 | $result['wind_dir'] = $matches[1]; |
216 | 216 | $result['wind_speed'] = round($matches[2]*1.60934,1); |
217 | 217 | $result['wind_gust'] = round($matches[3]*1.60934,1); |
218 | - $body_parse = substr($body_parse,strlen($matches[0])+1); |
|
219 | - } elseif (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})g([0-9 \\.]+)/',$body_parse,$matches)) { |
|
218 | + $body_parse = substr($body_parse,strlen($matches[0])+1); |
|
219 | + } elseif (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})g([0-9 \\.]+)/',$body_parse,$matches)) { |
|
220 | 220 | $result['wind_dir'] = $matches[1]; |
221 | 221 | $result['wind_speed'] = round($matches[2]*1.60934,1); |
222 | 222 | $result['wind_gust'] = round($matches[3]*1.60934,1); |
223 | - $body_parse = substr($body_parse,strlen($matches[0])+1); |
|
224 | - } |
|
225 | - if (!isset($result['temp']) && strlen($body_parse) > 0 && preg_match('/^g([0-9]+)t(-?[0-9 \\.]{1,3})/',$body_parse,$matches)) { |
|
223 | + $body_parse = substr($body_parse,strlen($matches[0])+1); |
|
224 | + } |
|
225 | + if (!isset($result['temp']) && strlen($body_parse) > 0 && preg_match('/^g([0-9]+)t(-?[0-9 \\.]{1,3})/',$body_parse,$matches)) { |
|
226 | 226 | $result['temp'] = round(5/9*(($matches[1])-32),1); |
227 | - } |
|
227 | + } |
|
228 | + } |
|
228 | 229 | } |
229 | - } |
|
230 | 230 | } |
231 | 231 | if (isset($result['latitude'])) $result['latitude'] = round($result['latitude'],4); |
232 | 232 | if (isset($result['longitude'])) $result['longitude'] = round($result['longitude'],4); |
233 | 233 | //print_r($result); |
234 | 234 | return $result; |
235 | - } |
|
235 | + } |
|
236 | 236 | } |
237 | 237 | /* |
238 | 238 | $aprs = new aprs(); |
@@ -77,7 +77,7 @@ |
||
77 | 77 | /** |
78 | 78 | * Returns list of available locales |
79 | 79 | * |
80 | - * @return array |
|
80 | + * @return string[] |
|
81 | 81 | */ |
82 | 82 | public function listLocaleDir() |
83 | 83 | { |
@@ -1,9 +1,9 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | if (!function_exists("gettext")) { |
4 | - function _($text) { |
|
5 | - return $text; |
|
6 | - } |
|
4 | + function _($text) { |
|
5 | + return $text; |
|
6 | + } |
|
7 | 7 | } else { |
8 | 8 | if (isset($_COOKIE['language']) && $_COOKIE['language'] != 'en_GB' && (isset($globalTranslate) && $globalTranslate)) { |
9 | 9 | $Language = new Language(); |
@@ -75,9 +75,9 @@ discard block |
||
75 | 75 | ); |
76 | 76 | |
77 | 77 | /** |
78 | - * Returns list of available locales |
|
79 | - * |
|
80 | - * @return array |
|
78 | + * Returns list of available locales |
|
79 | + * |
|
80 | + * @return array |
|
81 | 81 | */ |
82 | 82 | public function listLocaleDir() |
83 | 83 | { |
@@ -103,9 +103,9 @@ discard block |
||
103 | 103 | } |
104 | 104 | |
105 | 105 | /** |
106 | - * Returns list of available languages |
|
107 | - * |
|
108 | - * @return array |
|
106 | + * Returns list of available languages |
|
107 | + * |
|
108 | + * @return array |
|
109 | 109 | */ |
110 | 110 | public function getLanguages() |
111 | 111 | { |
@@ -178,6 +178,10 @@ discard block |
||
178 | 178 | return 1; |
179 | 179 | } |
180 | 180 | |
181 | + /** |
|
182 | + * @param double $lat |
|
183 | + * @param integer $isodd |
|
184 | + */ |
|
181 | 185 | function cprN($lat,$isodd) { |
182 | 186 | $nl = $this->cprNL($lat) - $isodd; |
183 | 187 | if ($nl > 1) return $nl; |
@@ -185,6 +189,10 @@ discard block |
||
185 | 189 | } |
186 | 190 | |
187 | 191 | |
192 | + /** |
|
193 | + * @param string $msg |
|
194 | + * @param string $bin |
|
195 | + */ |
|
188 | 196 | function parityCheck($msg, $bin) { |
189 | 197 | $modes_checksum_table = array( |
190 | 198 | 0x3935ea, 0x1c9af5, 0xf1b77e, 0x78dbbf, 0xc397db, 0x9e31e9, 0xb0e2f0, 0x587178, |
@@ -1,8 +1,8 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | class SBS { |
3 | - static $latlon = array(); |
|
3 | + static $latlon = array(); |
|
4 | 4 | |
5 | - public function parse($buffer) { |
|
5 | + public function parse($buffer) { |
|
6 | 6 | // Not yet finished, no CRC checks |
7 | 7 | //echo $buffer."\n"; |
8 | 8 | $data = array(); |
@@ -13,47 +13,47 @@ discard block |
||
13 | 13 | $bin = gmp_strval( gmp_init($hex,16), 2); |
14 | 14 | //if (strlen($hex) == 28 && $this->parityCheck($hex,$bin)) { |
15 | 15 | if (strlen($hex) == 28) { |
16 | - $df = intval(substr($bin,0,5),2); |
|
17 | - //$ca = intval(substr($bin,5,3),2); |
|
18 | - // Only support DF17 for now |
|
19 | - //if ($df == 17 || ($df == 18 && ($ca == 0 || $ca == 1 || $ca == 6))) { |
|
20 | - if (($df == 17 || $df == 18) && ($this->parityCheck($hex,$bin) || $typehex == '@')) { |
|
16 | + $df = intval(substr($bin,0,5),2); |
|
17 | + //$ca = intval(substr($bin,5,3),2); |
|
18 | + // Only support DF17 for now |
|
19 | + //if ($df == 17 || ($df == 18 && ($ca == 0 || $ca == 1 || $ca == 6))) { |
|
20 | + if (($df == 17 || $df == 18) && ($this->parityCheck($hex,$bin) || $typehex == '@')) { |
|
21 | 21 | $icao = substr($hex,2,6); |
22 | 22 | $data['hex'] = $icao; |
23 | 23 | $tc = intval(substr($bin,32,5),2); |
24 | 24 | if ($tc >= 1 && $tc <= 4) { |
25 | - //callsign |
|
26 | - $csbin = substr($bin,40,56); |
|
27 | - $charset = str_split('#ABCDEFGHIJKLMNOPQRSTUVWXYZ#####_###############0123456789######'); |
|
28 | - $cs = ''; |
|
29 | - $cs .= $charset[intval(substr($csbin,0,6),2)]; |
|
30 | - $cs .= $charset[intval(substr($csbin,6,6),2)]; |
|
31 | - $cs .= $charset[intval(substr($csbin,12,6),2)]; |
|
32 | - $cs .= $charset[intval(substr($csbin,18,6),2)]; |
|
33 | - $cs .= $charset[intval(substr($csbin,24,6),2)]; |
|
34 | - $cs .= $charset[intval(substr($csbin,30,6),2)]; |
|
35 | - $cs .= $charset[intval(substr($csbin,36,6),2)]; |
|
36 | - $cs .= $charset[intval(substr($csbin,42,6),2)]; |
|
37 | - $cs = str_replace('_','',$cs); |
|
38 | - $cs = str_replace('#','',$cs); |
|
39 | - $callsign = $cs; |
|
40 | - $data['ident'] = $callsign; |
|
25 | + //callsign |
|
26 | + $csbin = substr($bin,40,56); |
|
27 | + $charset = str_split('#ABCDEFGHIJKLMNOPQRSTUVWXYZ#####_###############0123456789######'); |
|
28 | + $cs = ''; |
|
29 | + $cs .= $charset[intval(substr($csbin,0,6),2)]; |
|
30 | + $cs .= $charset[intval(substr($csbin,6,6),2)]; |
|
31 | + $cs .= $charset[intval(substr($csbin,12,6),2)]; |
|
32 | + $cs .= $charset[intval(substr($csbin,18,6),2)]; |
|
33 | + $cs .= $charset[intval(substr($csbin,24,6),2)]; |
|
34 | + $cs .= $charset[intval(substr($csbin,30,6),2)]; |
|
35 | + $cs .= $charset[intval(substr($csbin,36,6),2)]; |
|
36 | + $cs .= $charset[intval(substr($csbin,42,6),2)]; |
|
37 | + $cs = str_replace('_','',$cs); |
|
38 | + $cs = str_replace('#','',$cs); |
|
39 | + $callsign = $cs; |
|
40 | + $data['ident'] = $callsign; |
|
41 | 41 | } elseif ($tc >= 9 && $tc <= 18) { |
42 | - // Check Q-bit |
|
43 | - $q = substr($bin,47,1); |
|
44 | - if ($q) { |
|
42 | + // Check Q-bit |
|
43 | + $q = substr($bin,47,1); |
|
44 | + if ($q) { |
|
45 | 45 | $n = intval(substr($bin,40,7).substr($bin,48,4),2); |
46 | 46 | $alt = $n*25-1000; |
47 | 47 | $data['altitude'] = $alt; |
48 | - } |
|
49 | - // Check odd/even flag |
|
50 | - $oe = substr($bin,53,1); |
|
51 | - //if ($oe) => odd else even |
|
52 | - // 131072 is 2^17 since CPR latitude and longitude are encoded in 17 bits. |
|
53 | - $cprlat = intval(substr($bin,54,17),2)/131072.0; |
|
54 | - $cprlon = intval(substr($bin,71,17),2)/131072.0; |
|
55 | - if ($oe == 0) $this::$latlon[$icao] = array('latitude' => $cprlat,'longitude' => $cprlon,'created' => time()); |
|
56 | - elseif (isset($this::$latlon[$icao]) && (time() - $this::$latlon[$icao]['created']) < 10) { |
|
48 | + } |
|
49 | + // Check odd/even flag |
|
50 | + $oe = substr($bin,53,1); |
|
51 | + //if ($oe) => odd else even |
|
52 | + // 131072 is 2^17 since CPR latitude and longitude are encoded in 17 bits. |
|
53 | + $cprlat = intval(substr($bin,54,17),2)/131072.0; |
|
54 | + $cprlon = intval(substr($bin,71,17),2)/131072.0; |
|
55 | + if ($oe == 0) $this::$latlon[$icao] = array('latitude' => $cprlat,'longitude' => $cprlon,'created' => time()); |
|
56 | + elseif (isset($this::$latlon[$icao]) && (time() - $this::$latlon[$icao]['created']) < 10) { |
|
57 | 57 | $cprlat_odd = $cprlat; |
58 | 58 | $cprlon_odd = $cprlon; |
59 | 59 | $cprlat_even = $this::$latlon[$icao]['latitude']; |
@@ -66,53 +66,53 @@ discard block |
||
66 | 66 | if ($lat_odd >= 270) $lat_odd = $lat_odd - 360; |
67 | 67 | // check latitude zone |
68 | 68 | if ($this->cprNL($lat_even) == $this->cprNL($lat_odd)) { |
69 | - if ($this::$latlon[$icao]['created'] > time()) { |
|
69 | + if ($this::$latlon[$icao]['created'] > time()) { |
|
70 | 70 | $ni = $this->cprN($lat_even,0); |
71 | 71 | $m = floor($cprlon_even*($this->cprNL($lat_even)-1) - $cprlon_odd * $this->cprNL($lat_even)+0.5); |
72 | 72 | $lon = (360.0/$ni)*($m%$ni+$cprlon_even); |
73 | 73 | $lat = $lat_even; |
74 | 74 | if ($lon > 180) $lon = $lon -360; |
75 | 75 | if ($lat > -91 && $lat < 91 && $lon > -181 && $lon < 181) { |
76 | - //if ($globalDebug) echo 'cs : '.$cs.' - hex : '.$hex.' - lat : '.$lat.' - lon : '.$lon; |
|
77 | - $data['latitude'] = $lat; |
|
78 | - $data['longitude'] = $lon; |
|
76 | + //if ($globalDebug) echo 'cs : '.$cs.' - hex : '.$hex.' - lat : '.$lat.' - lon : '.$lon; |
|
77 | + $data['latitude'] = $lat; |
|
78 | + $data['longitude'] = $lon; |
|
79 | 79 | } |
80 | - } else { |
|
80 | + } else { |
|
81 | 81 | $ni = $this->cprN($lat_odd,1); |
82 | 82 | $m = floor($cprlon_even*($this->cprNL($lat_odd)-1) - $cprlon_odd * $this->cprNL($lat_odd)+0.5); |
83 | 83 | $lon = (360.0/$ni)*($m%$ni+$cprlon_odd); |
84 | 84 | $lat = $lat_odd; |
85 | 85 | if ($lon > 180) $lon = $lon -360; |
86 | 86 | if ($lat > -91 && $lat < 91 && $lon > -181 && $lon < 181) { |
87 | - //if ($globalDebug) echo 'icao : '.$icao.' - hex : '.$hex.' - lat : '.$lat.' - lon : '.$lon.' second'."\n"; |
|
88 | - $data['latitude'] = $lat; |
|
89 | - $data['longitude'] = $lon; |
|
87 | + //if ($globalDebug) echo 'icao : '.$icao.' - hex : '.$hex.' - lat : '.$lat.' - lon : '.$lon.' second'."\n"; |
|
88 | + $data['latitude'] = $lat; |
|
89 | + $data['longitude'] = $lon; |
|
90 | + } |
|
90 | 91 | } |
91 | - } |
|
92 | 92 | } else echo "Not cprNL"; |
93 | 93 | unset($this::$latlon[$icao]); |
94 | - } |
|
94 | + } |
|
95 | 95 | } elseif ($tc == 19) { |
96 | - // speed & heading |
|
97 | - $v_ew_dir = intval(substr($bin,45,1)); |
|
98 | - $v_ew = intval(substr($bin,46,10),2); |
|
99 | - $v_ns_dir = intval(substr($bin,56,1)); |
|
100 | - $v_ns = intval(substr($bin,57,10),2); |
|
101 | - if ($v_ew_dir) $v_ew = -1*$v_ew; |
|
102 | - if ($v_ns_dir) $v_ns = -1*$v_ns; |
|
103 | - $speed = sqrt($v_ns*$v_ns+$v_ew*$v_ew); |
|
104 | - $heading = atan2($v_ew,$v_ns)*360.0/(2*pi()); |
|
105 | - if ($heading <0) $heading = $heading+360; |
|
106 | - $data['speed'] = $speed; |
|
107 | - $data['heading'] = $heading; |
|
96 | + // speed & heading |
|
97 | + $v_ew_dir = intval(substr($bin,45,1)); |
|
98 | + $v_ew = intval(substr($bin,46,10),2); |
|
99 | + $v_ns_dir = intval(substr($bin,56,1)); |
|
100 | + $v_ns = intval(substr($bin,57,10),2); |
|
101 | + if ($v_ew_dir) $v_ew = -1*$v_ew; |
|
102 | + if ($v_ns_dir) $v_ns = -1*$v_ns; |
|
103 | + $speed = sqrt($v_ns*$v_ns+$v_ew*$v_ew); |
|
104 | + $heading = atan2($v_ew,$v_ns)*360.0/(2*pi()); |
|
105 | + if ($heading <0) $heading = $heading+360; |
|
106 | + $data['speed'] = $speed; |
|
107 | + $data['heading'] = $heading; |
|
108 | + } |
|
108 | 109 | } |
109 | - } |
|
110 | - if (isset($data)) { |
|
110 | + if (isset($data)) { |
|
111 | 111 | //print_r($data); |
112 | 112 | return $data; |
113 | - } |
|
114 | - } |
|
115 | - } |
|
113 | + } |
|
114 | + } |
|
115 | + } |
|
116 | 116 | |
117 | 117 | |
118 | 118 | public function cprNL($lat) { |
@@ -177,16 +177,16 @@ discard block |
||
177 | 177 | if ($lat < 86.53536998) return 3; |
178 | 178 | if ($lat < 87.00000000) return 2; |
179 | 179 | return 1; |
180 | - } |
|
180 | + } |
|
181 | 181 | |
182 | - public function cprN($lat,$isodd) { |
|
182 | + public function cprN($lat,$isodd) { |
|
183 | 183 | $nl = $this->cprNL($lat) - $isodd; |
184 | 184 | if ($nl > 1) return $nl; |
185 | 185 | else return 1; |
186 | - } |
|
186 | + } |
|
187 | 187 | |
188 | 188 | |
189 | - function parityCheck($msg, $bin) { |
|
189 | + function parityCheck($msg, $bin) { |
|
190 | 190 | $modes_checksum_table = array( |
191 | 191 | 0x3935ea, 0x1c9af5, 0xf1b77e, 0x78dbbf, 0xc397db, 0x9e31e9, 0xb0e2f0, 0x587178, |
192 | 192 | 0x2c38bc, 0x161c5e, 0x0b0e2f, 0xfa7d13, 0x82c48d, 0xbe9842, 0x5f4c21, 0xd05c14, |
@@ -208,13 +208,13 @@ discard block |
||
208 | 208 | $checksum = intval(substr($msg,22,6),16); |
209 | 209 | |
210 | 210 | for ($j = 0; $j < strlen($bin); $j++) { |
211 | - if ($bin[$j]) $crc = $crc^intval($modes_checksum_table[$j],0); |
|
211 | + if ($bin[$j]) $crc = $crc^intval($modes_checksum_table[$j],0); |
|
212 | 212 | } |
213 | 213 | if ($crc == $checksum) return true; |
214 | 214 | else { |
215 | - //echo "**** CRC ERROR ****\n"; |
|
216 | - return false; |
|
215 | + //echo "**** CRC ERROR ****\n"; |
|
216 | + return false; |
|
217 | + } |
|
217 | 218 | } |
218 | - } |
|
219 | 219 | } |
220 | 220 | ?> |
@@ -40,6 +40,10 @@ |
||
40 | 40 | } |
41 | 41 | } |
42 | 42 | |
43 | + /** |
|
44 | + * @param string $id |
|
45 | + * @param string $ident |
|
46 | + */ |
|
43 | 47 | function get_Schedule($id,$ident) { |
44 | 48 | global $globalDebug, $globalFork, $globalSchedulesFetch; |
45 | 49 | // Get schedule here, so it's done only one time |
@@ -9,16 +9,16 @@ discard block |
||
9 | 9 | require_once(dirname(__FILE__).'/class.Source.php'); |
10 | 10 | |
11 | 11 | class SpotterImport { |
12 | - private $all_flights = array(); |
|
13 | - private $last_delete_hourly = 0; |
|
14 | - private $last_delete = 0; |
|
15 | - private $stats = array(); |
|
16 | - private $tmd = 0; |
|
17 | - private $source_location = array(); |
|
18 | - public $db = null; |
|
19 | - public $nb = 0; |
|
20 | - |
|
21 | - public function __construct($dbc = null) { |
|
12 | + private $all_flights = array(); |
|
13 | + private $last_delete_hourly = 0; |
|
14 | + private $last_delete = 0; |
|
15 | + private $stats = array(); |
|
16 | + private $tmd = 0; |
|
17 | + private $source_location = array(); |
|
18 | + public $db = null; |
|
19 | + public $nb = 0; |
|
20 | + |
|
21 | + public function __construct($dbc = null) { |
|
22 | 22 | global $globalBeta; |
23 | 23 | $Connection = new Connection($dbc); |
24 | 24 | $this->db = $Connection->db(); |
@@ -29,18 +29,18 @@ discard block |
||
29 | 29 | $currentdate = date('Y-m-d'); |
30 | 30 | $sourcestat = $Stats->getStatsSource($currentdate); |
31 | 31 | if (!empty($sourcestat)) { |
32 | - foreach($sourcestat as $srcst) { |
|
33 | - $type = $srcst['stats_type']; |
|
32 | + foreach($sourcestat as $srcst) { |
|
33 | + $type = $srcst['stats_type']; |
|
34 | 34 | if ($type == 'polar' || $type == 'hist') { |
35 | - $source = $srcst['source_name']; |
|
36 | - $data = $srcst['source_data']; |
|
37 | - $this->stats[$currentdate][$source][$type] = json_decode($data,true); |
|
38 | - } |
|
39 | - } |
|
35 | + $source = $srcst['source_name']; |
|
36 | + $data = $srcst['source_data']; |
|
37 | + $this->stats[$currentdate][$source][$type] = json_decode($data,true); |
|
38 | + } |
|
39 | + } |
|
40 | + } |
|
40 | 41 | } |
41 | - } |
|
42 | 42 | |
43 | - public function get_Schedule($id,$ident) { |
|
43 | + public function get_Schedule($id,$ident) { |
|
44 | 44 | global $globalDebug, $globalFork, $globalSchedulesFetch; |
45 | 45 | // Get schedule here, so it's done only one time |
46 | 46 | |
@@ -60,42 +60,42 @@ discard block |
||
60 | 60 | $operator = $Spotter->getOperator($ident); |
61 | 61 | $scheduleexist = false; |
62 | 62 | if ($Schedule->checkSchedule($operator) == 0) { |
63 | - $operator = $Translation->checkTranslation($ident); |
|
64 | - if ($Schedule->checkSchedule($operator) == 0) { |
|
63 | + $operator = $Translation->checkTranslation($ident); |
|
64 | + if ($Schedule->checkSchedule($operator) == 0) { |
|
65 | 65 | $schedule = $Schedule->fetchSchedule($operator); |
66 | 66 | if (count($schedule) > 0 && isset($schedule['DepartureTime']) && isset($schedule['ArrivalTime'])) { |
67 | - if ($globalDebug) echo "-> Schedule info for ".$operator." (".$ident.")\n"; |
|
68 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport_time' => $schedule['DepartureTime'])); |
|
69 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('arrival_airport_time' => $schedule['ArrivalTime'])); |
|
70 | - // Should also check if route schedule = route from DB |
|
71 | - if ($schedule['DepartureAirportIATA'] != '') { |
|
67 | + if ($globalDebug) echo "-> Schedule info for ".$operator." (".$ident.")\n"; |
|
68 | + $this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport_time' => $schedule['DepartureTime'])); |
|
69 | + $this->all_flights[$id] = array_merge($this->all_flights[$id],array('arrival_airport_time' => $schedule['ArrivalTime'])); |
|
70 | + // Should also check if route schedule = route from DB |
|
71 | + if ($schedule['DepartureAirportIATA'] != '') { |
|
72 | 72 | if ($this->all_flights[$id]['departure_airport'] != $Spotter->getAirportIcao($schedule['DepartureAirportIATA'])) { |
73 | - $airport_icao = $Spotter->getAirportIcao($schedule['DepartureAirportIATA']); |
|
74 | - if (trim($airport_icao) != '') { |
|
73 | + $airport_icao = $Spotter->getAirportIcao($schedule['DepartureAirportIATA']); |
|
74 | + if (trim($airport_icao) != '') { |
|
75 | 75 | $this->all_flights[$id]['departure_airport'] = $airport_icao; |
76 | 76 | if ($globalDebug) echo "-> Change departure airport to ".$airport_icao." for ".$ident."\n"; |
77 | - } |
|
77 | + } |
|
78 | + } |
|
78 | 79 | } |
79 | - } |
|
80 | - if ($schedule['ArrivalAirportIATA'] != '') { |
|
80 | + if ($schedule['ArrivalAirportIATA'] != '') { |
|
81 | 81 | if ($this->all_flights[$id]['arrival_airport'] != $Spotter->getAirportIcao($schedule['ArrivalAirportIATA'])) { |
82 | - $airport_icao = $Spotter->getAirportIcao($schedule['ArrivalAirportIATA']); |
|
83 | - if (trim($airport_icao) != '') { |
|
82 | + $airport_icao = $Spotter->getAirportIcao($schedule['ArrivalAirportIATA']); |
|
83 | + if (trim($airport_icao) != '') { |
|
84 | 84 | $this->all_flights[$id]['arrival_airport'] = $airport_icao; |
85 | 85 | if ($globalDebug) echo "-> Change arrival airport to ".$airport_icao." for ".$ident."\n"; |
86 | - } |
|
86 | + } |
|
87 | + } |
|
87 | 88 | } |
88 | - } |
|
89 | - $Schedule->addSchedule($operator,$this->all_flights[$id]['departure_airport'],$this->all_flights[$id]['departure_airport_time'],$this->all_flights[$id]['arrival_airport'],$this->all_flights[$id]['arrival_airport_time'],$schedule['Source']); |
|
89 | + $Schedule->addSchedule($operator,$this->all_flights[$id]['departure_airport'],$this->all_flights[$id]['departure_airport_time'],$this->all_flights[$id]['arrival_airport'],$this->all_flights[$id]['arrival_airport_time'],$schedule['Source']); |
|
90 | 90 | } |
91 | - } else $scheduleexist = true; |
|
91 | + } else $scheduleexist = true; |
|
92 | 92 | } else $scheduleexist = true; |
93 | 93 | // close connection, at least one way will work ? |
94 | - if ($scheduleexist) { |
|
94 | + if ($scheduleexist) { |
|
95 | 95 | if ($globalDebug) echo "-> get arrival/departure airport info for ".$ident."\n"; |
96 | - $sch = $Schedule->getSchedule($operator); |
|
96 | + $sch = $Schedule->getSchedule($operator); |
|
97 | 97 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('arrival_airport' => $sch['arrival_airport_icao'],'departure_airport' => $sch['departure_airport_icao'],'departure_airport_time' => $sch['departure_airport_time'],'arrival_airport_time' => $sch['arrival_airport_time'])); |
98 | - } |
|
98 | + } |
|
99 | 99 | $Spotter->db = null; |
100 | 100 | $Schedule->db = null; |
101 | 101 | $Translation->db = null; |
@@ -110,92 +110,92 @@ discard block |
||
110 | 110 | } |
111 | 111 | */ |
112 | 112 | } |
113 | - } |
|
113 | + } |
|
114 | 114 | |
115 | - public function checkAll() { |
|
115 | + public function checkAll() { |
|
116 | 116 | global $globalDebug; |
117 | 117 | if ($globalDebug) echo "Update last seen flights data...\n"; |
118 | 118 | foreach ($this->all_flights as $key => $flight) { |
119 | - if (isset($this->all_flights[$key]['id'])) { |
|
119 | + if (isset($this->all_flights[$key]['id'])) { |
|
120 | 120 | //echo $this->all_flights[$key]['id'].' - '.$this->all_flights[$key]['latitude'].' '.$this->all_flights[$key]['longitude']."\n"; |
121 | - $Spotter = new Spotter($this->db); |
|
122 | - $real_arrival = $this->arrival($key); |
|
123 | - $Spotter->updateLatestSpotterData($this->all_flights[$key]['id'],$this->all_flights[$key]['ident'],$this->all_flights[$key]['latitude'],$this->all_flights[$key]['longitude'],$this->all_flights[$key]['altitude'],$this->all_flights[$key]['ground'],$this->all_flights[$key]['speed'],$this->all_flights[$key]['datetime'],$real_arrival['airport_icao'],$real_arrival['airport_time']); |
|
124 | - } |
|
121 | + $Spotter = new Spotter($this->db); |
|
122 | + $real_arrival = $this->arrival($key); |
|
123 | + $Spotter->updateLatestSpotterData($this->all_flights[$key]['id'],$this->all_flights[$key]['ident'],$this->all_flights[$key]['latitude'],$this->all_flights[$key]['longitude'],$this->all_flights[$key]['altitude'],$this->all_flights[$key]['ground'],$this->all_flights[$key]['speed'],$this->all_flights[$key]['datetime'],$real_arrival['airport_icao'],$real_arrival['airport_time']); |
|
124 | + } |
|
125 | + } |
|
125 | 126 | } |
126 | - } |
|
127 | 127 | |
128 | - public function arrival($key) { |
|
128 | + public function arrival($key) { |
|
129 | 129 | global $globalClosestMinDist, $globalDebug; |
130 | 130 | if ($globalDebug) echo 'Update arrival...'."\n"; |
131 | 131 | $Spotter = new Spotter($this->db); |
132 | - $airport_icao = ''; |
|
133 | - $airport_time = ''; |
|
134 | - if (!isset($globalClosestMinDist) || $globalClosestMinDist == '') $globalClosestMinDist = 50; |
|
132 | + $airport_icao = ''; |
|
133 | + $airport_time = ''; |
|
134 | + if (!isset($globalClosestMinDist) || $globalClosestMinDist == '') $globalClosestMinDist = 50; |
|
135 | 135 | if ($this->all_flights[$key]['latitude'] != '' && $this->all_flights[$key]['longitude'] != '') { |
136 | - $closestAirports = $Spotter->closestAirports($this->all_flights[$key]['latitude'],$this->all_flights[$key]['longitude'],$globalClosestMinDist); |
|
137 | - if (isset($closestAirports[0])) { |
|
138 | - if (isset($this->all_flights[$key]['arrival_airport']) && $this->all_flights[$key]['arrival_airport'] == $closestAirports[0]['icao']) { |
|
139 | - $airport_icao = $closestAirports[0]['icao']; |
|
140 | - $airport_time = $this->all_flights[$key]['datetime']; |
|
141 | - if ($globalDebug) echo "---++ Find arrival airport. airport_icao : ".$airport_icao."\n"; |
|
142 | - } elseif (count($closestAirports > 1) && isset($this->all_flights[$key]['arrival_airport']) && $this->all_flights[$key]['arrival_airport'] != '') { |
|
143 | - foreach ($closestAirports as $airport) { |
|
144 | - if ($this->all_flights[$key]['arrival_airport'] == $airport['icao']) { |
|
145 | - $airport_icao = $airport['icao']; |
|
146 | - $airport_time = $this->all_flights[$key]['datetime']; |
|
147 | - if ($globalDebug) echo "---++ Find arrival airport. airport_icao : ".$airport_icao."\n"; |
|
148 | - break; |
|
149 | - } |
|
150 | - } |
|
151 | - } elseif ($this->all_flights[$key]['altitude'] == 0 || ($this->all_flights[$key]['altitude_real'] != '' && ($closestAirports[0]['altitude'] < $this->all_flights[$key]['altitude_real'] && $this->all_flights[$key]['altitude_real'] < $closestAirports[0]['altitude']+5000))) { |
|
152 | - $airport_icao = $closestAirports[0]['icao']; |
|
153 | - $airport_time = $this->all_flights[$key]['datetime']; |
|
154 | - } else { |
|
155 | - if ($globalDebug) echo "----- Can't find arrival airport. Airport altitude : ".$closestAirports[0]['altitude'].' - flight altitude : '.$this->all_flights[$key]['altitude_real']."\n"; |
|
156 | - } |
|
157 | - } else { |
|
158 | - if ($globalDebug) echo "----- No Airport near last coord. Latitude : ".$this->all_flights[$key]['latitude'].' - Longitude : '.$this->all_flights[$key]['longitude'].' - MinDist : '.$globalClosestMinDist."\n"; |
|
159 | - } |
|
160 | - |
|
161 | - } else { |
|
162 | - if ($globalDebug) echo "---- No latitude or longitude. Ident : ".$this->all_flights[$key]['ident']."\n"; |
|
163 | - } |
|
164 | - return array('airport_icao' => $airport_icao,'airport_time' => $airport_time); |
|
165 | - } |
|
166 | - |
|
167 | - |
|
168 | - |
|
169 | - public function del() { |
|
136 | + $closestAirports = $Spotter->closestAirports($this->all_flights[$key]['latitude'],$this->all_flights[$key]['longitude'],$globalClosestMinDist); |
|
137 | + if (isset($closestAirports[0])) { |
|
138 | + if (isset($this->all_flights[$key]['arrival_airport']) && $this->all_flights[$key]['arrival_airport'] == $closestAirports[0]['icao']) { |
|
139 | + $airport_icao = $closestAirports[0]['icao']; |
|
140 | + $airport_time = $this->all_flights[$key]['datetime']; |
|
141 | + if ($globalDebug) echo "---++ Find arrival airport. airport_icao : ".$airport_icao."\n"; |
|
142 | + } elseif (count($closestAirports > 1) && isset($this->all_flights[$key]['arrival_airport']) && $this->all_flights[$key]['arrival_airport'] != '') { |
|
143 | + foreach ($closestAirports as $airport) { |
|
144 | + if ($this->all_flights[$key]['arrival_airport'] == $airport['icao']) { |
|
145 | + $airport_icao = $airport['icao']; |
|
146 | + $airport_time = $this->all_flights[$key]['datetime']; |
|
147 | + if ($globalDebug) echo "---++ Find arrival airport. airport_icao : ".$airport_icao."\n"; |
|
148 | + break; |
|
149 | + } |
|
150 | + } |
|
151 | + } elseif ($this->all_flights[$key]['altitude'] == 0 || ($this->all_flights[$key]['altitude_real'] != '' && ($closestAirports[0]['altitude'] < $this->all_flights[$key]['altitude_real'] && $this->all_flights[$key]['altitude_real'] < $closestAirports[0]['altitude']+5000))) { |
|
152 | + $airport_icao = $closestAirports[0]['icao']; |
|
153 | + $airport_time = $this->all_flights[$key]['datetime']; |
|
154 | + } else { |
|
155 | + if ($globalDebug) echo "----- Can't find arrival airport. Airport altitude : ".$closestAirports[0]['altitude'].' - flight altitude : '.$this->all_flights[$key]['altitude_real']."\n"; |
|
156 | + } |
|
157 | + } else { |
|
158 | + if ($globalDebug) echo "----- No Airport near last coord. Latitude : ".$this->all_flights[$key]['latitude'].' - Longitude : '.$this->all_flights[$key]['longitude'].' - MinDist : '.$globalClosestMinDist."\n"; |
|
159 | + } |
|
160 | + |
|
161 | + } else { |
|
162 | + if ($globalDebug) echo "---- No latitude or longitude. Ident : ".$this->all_flights[$key]['ident']."\n"; |
|
163 | + } |
|
164 | + return array('airport_icao' => $airport_icao,'airport_time' => $airport_time); |
|
165 | + } |
|
166 | + |
|
167 | + |
|
168 | + |
|
169 | + public function del() { |
|
170 | 170 | global $globalDebug; |
171 | 171 | // Delete old infos |
172 | 172 | if ($globalDebug) echo 'Delete old values and update latest data...'."\n"; |
173 | 173 | foreach ($this->all_flights as $key => $flight) { |
174 | - if (isset($flight['lastupdate'])) { |
|
175 | - if ($flight['lastupdate'] < (time()-3000)) { |
|
176 | - if (isset($this->all_flights[$key]['id'])) { |
|
177 | - if ($globalDebug) echo "--- Delete old values with id ".$this->all_flights[$key]['id']."\n"; |
|
174 | + if (isset($flight['lastupdate'])) { |
|
175 | + if ($flight['lastupdate'] < (time()-3000)) { |
|
176 | + if (isset($this->all_flights[$key]['id'])) { |
|
177 | + if ($globalDebug) echo "--- Delete old values with id ".$this->all_flights[$key]['id']."\n"; |
|
178 | 178 | /* |
179 | 179 | $SpotterLive = new SpotterLive(); |
180 | 180 | $SpotterLive->deleteLiveSpotterDataById($this->all_flights[$key]['id']); |
181 | 181 | $SpotterLive->db = null; |
182 | 182 | */ |
183 | - $real_arrival = $this->arrival($key); |
|
184 | - $Spotter = new Spotter($this->db); |
|
185 | - if ($this->all_flights[$key]['latitude'] != '' && $this->all_flights[$key]['longitude'] != '') { |
|
183 | + $real_arrival = $this->arrival($key); |
|
184 | + $Spotter = new Spotter($this->db); |
|
185 | + if ($this->all_flights[$key]['latitude'] != '' && $this->all_flights[$key]['longitude'] != '') { |
|
186 | 186 | $result = $Spotter->updateLatestSpotterData($this->all_flights[$key]['id'],$this->all_flights[$key]['ident'],$this->all_flights[$key]['latitude'],$this->all_flights[$key]['longitude'],$this->all_flights[$key]['altitude'],$this->all_flights[$key]['ground'],$this->all_flights[$key]['speed'],$this->all_flights[$key]['datetime'],$real_arrival['airport_icao'],$real_arrival['airport_time']); |
187 | 187 | if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n"; |
188 | 188 | } |
189 | 189 | // Put in archive |
190 | 190 | // $Spotter->db = null; |
191 | - } |
|
192 | - unset($this->all_flights[$key]); |
|
193 | - } |
|
194 | - } |
|
195 | - } |
|
196 | - } |
|
197 | - |
|
198 | - public function add($line) { |
|
191 | + } |
|
192 | + unset($this->all_flights[$key]); |
|
193 | + } |
|
194 | + } |
|
195 | + } |
|
196 | + } |
|
197 | + |
|
198 | + public function add($line) { |
|
199 | 199 | global $globalPilotIdAccept, $globalAirportAccept, $globalAirlineAccept, $globalAirlineIgnore, $globalAirportIgnore, $globalFork, $globalDistanceIgnore, $globalDaemon, $globalSBS1update, $globalDebug, $globalIVAO, $globalVATSIM, $globalphpVMS, $globalCoordMinChange, $globalDebugTimeElapsed, $globalCenterLatitude, $globalCenterLongitude, $globalBeta, $globalSourcesupdate, $globalAirlinesSource, $globalVAM, $globalAllFlights; |
200 | 200 | //if (!isset($globalDebugTimeElapsed) || $globalDebugTimeElapsed == '') $globalDebugTimeElapsed = FALSE; |
201 | 201 | if (!isset($globalCoordMinChange) || $globalCoordMinChange == '') $globalCoordMinChange = '0.02'; |
@@ -220,18 +220,18 @@ discard block |
||
220 | 220 | |
221 | 221 | // SBS format is CSV format |
222 | 222 | if(is_array($line) && isset($line['hex'])) { |
223 | - //print_r($line); |
|
224 | - if ($line['hex'] != '' && $line['hex'] != '00000' && $line['hex'] != '000000' && $line['hex'] != '111111' && ctype_xdigit($line['hex']) && strlen($line['hex']) === 6) { |
|
223 | + //print_r($line); |
|
224 | + if ($line['hex'] != '' && $line['hex'] != '00000' && $line['hex'] != '000000' && $line['hex'] != '111111' && ctype_xdigit($line['hex']) && strlen($line['hex']) === 6) { |
|
225 | 225 | |
226 | 226 | // Increment message number |
227 | 227 | if (isset($line['sourcestats']) && $line['sourcestats'] == TRUE) { |
228 | - $current_date = date('Y-m-d'); |
|
229 | - $source = $line['source_name']; |
|
230 | - if ($source == '' || $line['format_source'] == 'aprs') $source = $line['format_source']; |
|
231 | - if (!isset($this->stats[$current_date][$source]['msg'])) { |
|
232 | - $this->stats[$current_date][$source]['msg']['date'] = time(); |
|
233 | - $this->stats[$current_date][$source]['msg']['nb'] = 1; |
|
234 | - } else $this->stats[$current_date][$source]['msg']['nb'] += 1; |
|
228 | + $current_date = date('Y-m-d'); |
|
229 | + $source = $line['source_name']; |
|
230 | + if ($source == '' || $line['format_source'] == 'aprs') $source = $line['format_source']; |
|
231 | + if (!isset($this->stats[$current_date][$source]['msg'])) { |
|
232 | + $this->stats[$current_date][$source]['msg']['date'] = time(); |
|
233 | + $this->stats[$current_date][$source]['msg']['nb'] = 1; |
|
234 | + } else $this->stats[$current_date][$source]['msg']['nb'] += 1; |
|
235 | 235 | } |
236 | 236 | |
237 | 237 | /* |
@@ -247,17 +247,17 @@ discard block |
||
247 | 247 | //$this->db = $dbc; |
248 | 248 | |
249 | 249 | $hex = trim($line['hex']); |
250 | - if (!isset($line['id'])) $id = trim($line['hex']); |
|
251 | - else $id = trim($line['id']); |
|
250 | + if (!isset($line['id'])) $id = trim($line['hex']); |
|
251 | + else $id = trim($line['id']); |
|
252 | 252 | |
253 | 253 | //print_r($this->all_flights); |
254 | 254 | if (!isset($this->all_flights[$id]['hex']) && ctype_xdigit($hex)) { |
255 | - $this->all_flights[$id] = array('hex' => $hex); |
|
256 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0)); |
|
257 | - //if (isset($line['datetime']) && preg_match('/^(\d{4}(?:\-\d{2}){2} \d{2}(?:\:\d{2}){2})$/',$line['datetime'])) { |
|
255 | + $this->all_flights[$id] = array('hex' => $hex); |
|
256 | + $this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0)); |
|
257 | + //if (isset($line['datetime']) && preg_match('/^(\d{4}(?:\-\d{2}){2} \d{2}(?:\:\d{2}){2})$/',$line['datetime'])) { |
|
258 | 258 | //$this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => $line['datetime'])); |
259 | - //} else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => date('Y-m-d H:i:s'))); |
|
260 | - if (!isset($line['aircraft_name']) && (!isset($line['aircraft_icao']) || $line['aircraft_icao'] == '????')) { |
|
259 | + //} else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => date('Y-m-d H:i:s'))); |
|
260 | + if (!isset($line['aircraft_name']) && (!isset($line['aircraft_icao']) || $line['aircraft_icao'] == '????')) { |
|
261 | 261 | |
262 | 262 | $timeelapsed = microtime(true); |
263 | 263 | $Spotter = new Spotter($this->db); |
@@ -266,38 +266,38 @@ discard block |
||
266 | 266 | if ($globalDebugTimeElapsed) echo 'Time elapsed for update getallaircrattype : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
267 | 267 | |
268 | 268 | if ($aircraft_icao == '' && isset($line['aircraft_type'])) { |
269 | - if ($line['aircraft_type'] == 'PARA_GLIDER') $aircraft_icao = 'GLID'; |
|
270 | - elseif ($line['aircraft_type'] == 'HELICOPTER_ROTORCRAFT') $aircraft_icao = 'UHEL'; |
|
271 | - elseif ($line['aircraft_type'] == 'TOW_PLANE') $aircraft_icao = 'TOWPLANE'; |
|
272 | - elseif ($line['aircraft_type'] == 'POWERED_AIRCRAFT') $aircraft_icao = 'POWAIRC'; |
|
269 | + if ($line['aircraft_type'] == 'PARA_GLIDER') $aircraft_icao = 'GLID'; |
|
270 | + elseif ($line['aircraft_type'] == 'HELICOPTER_ROTORCRAFT') $aircraft_icao = 'UHEL'; |
|
271 | + elseif ($line['aircraft_type'] == 'TOW_PLANE') $aircraft_icao = 'TOWPLANE'; |
|
272 | + elseif ($line['aircraft_type'] == 'POWERED_AIRCRAFT') $aircraft_icao = 'POWAIRC'; |
|
273 | 273 | } |
274 | 274 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao)); |
275 | - } else if (isset($line['aircraft_name'])) { |
|
275 | + } else if (isset($line['aircraft_name'])) { |
|
276 | 276 | // Get aircraft ICAO from aircraft name |
277 | 277 | $Spotter = new Spotter($this->db); |
278 | 278 | $aircraft_icao = $Spotter->getAircraftIcao($line['aircraft_name']); |
279 | 279 | $Spotter->db = null; |
280 | 280 | if ($aircraft_icao != '') $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao)); |
281 | 281 | else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => 'NA')); |
282 | - } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $line['aircraft_icao'])); |
|
283 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ident' => '','departure_airport' => '', 'arrival_airport' => '','latitude' => '', 'longitude' => '', 'speed' => '', 'altitude' => '','altitude_real' => '', 'heading' => '','departure_airport_time' => '','arrival_airport_time' => '','squawk' => '','route_stop' => '','registration' => '','pilot_id' => '','pilot_name' => '','waypoints' => '','ground' => '0', 'format_source' => '','source_name' => '','over_country' => '','verticalrate' => '','noarchive' => false,'putinarchive' => true)); |
|
284 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('lastupdate' => time())); |
|
285 | - if (!isset($line['id'])) { |
|
282 | + } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $line['aircraft_icao'])); |
|
283 | + $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ident' => '','departure_airport' => '', 'arrival_airport' => '','latitude' => '', 'longitude' => '', 'speed' => '', 'altitude' => '','altitude_real' => '', 'heading' => '','departure_airport_time' => '','arrival_airport_time' => '','squawk' => '','route_stop' => '','registration' => '','pilot_id' => '','pilot_name' => '','waypoints' => '','ground' => '0', 'format_source' => '','source_name' => '','over_country' => '','verticalrate' => '','noarchive' => false,'putinarchive' => true)); |
|
284 | + $this->all_flights[$id] = array_merge($this->all_flights[$id],array('lastupdate' => time())); |
|
285 | + if (!isset($line['id'])) { |
|
286 | 286 | if (!isset($globalDaemon)) $globalDaemon = TRUE; |
287 | 287 | // if (isset($line['format_source']) && ($line['format_source'] == 'sbs' || $line['format_source'] == 'tsv' || $line['format_source'] == 'raw') && $globalDaemon) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident'].'-'.date('YmdGi'))); |
288 | 288 | // if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs') && $globalDaemon) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdHi'))); |
289 | 289 | if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'radarvirtueljson')) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdHi'))); |
290 | - //else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident'])); |
|
291 | - } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id'])); |
|
290 | + //else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident'])); |
|
291 | + } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id'])); |
|
292 | 292 | |
293 | - if ($globalDebug) echo "*********** New aircraft hex : ".$hex." ***********\n"; |
|
294 | - if ($globalAllFlights !== FALSE) $dataFound = true; |
|
293 | + if ($globalDebug) echo "*********** New aircraft hex : ".$hex." ***********\n"; |
|
294 | + if ($globalAllFlights !== FALSE) $dataFound = true; |
|
295 | 295 | } |
296 | 296 | |
297 | 297 | if (isset($line['datetime']) && preg_match('/^(\d{4}(?:\-\d{2}){2} \d{2}(?:\:\d{2}){2})$/',$line['datetime'])) { |
298 | - if (!isset($this->all_flights[$id]['datetime']) || strtotime($line['datetime']) >= strtotime($this->all_flights[$id]['datetime'])) { |
|
298 | + if (!isset($this->all_flights[$id]['datetime']) || strtotime($line['datetime']) >= strtotime($this->all_flights[$id]['datetime'])) { |
|
299 | 299 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => $line['datetime'])); |
300 | - } else { |
|
300 | + } else { |
|
301 | 301 | if (strtotime($line['datetime']) == strtotime($this->all_flights[$id]['datetime']) && $globalDebug) echo "!!! Date is the same as previous data for ".$this->all_flights[$id]['hex']." - format : ".$line['format_source']."\n"; |
302 | 302 | elseif (strtotime($line['datetime']) > strtotime($this->all_flights[$id]['datetime']) && $globalDebug) echo "!!! Date previous latest data (".$line['datetime']." > ".$this->all_flights[$id]['datetime'].") !!! for ".$this->all_flights[$id]['hex']." - format : ".$line['format_source']."\n"; |
303 | 303 | /* |
@@ -306,38 +306,38 @@ discard block |
||
306 | 306 | print_r($line); |
307 | 307 | */ |
308 | 308 | return ''; |
309 | - } |
|
309 | + } |
|
310 | 310 | } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => date('Y-m-d H:i:s'))); |
311 | 311 | |
312 | 312 | if (isset($line['registration']) && $line['registration'] != '' && $line['registration'] != 'z.NO-REG') { |
313 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('registration' => $line['registration'])); |
|
313 | + $this->all_flights[$id] = array_merge($this->all_flights[$id],array('registration' => $line['registration'])); |
|
314 | 314 | } |
315 | 315 | if (isset($line['waypoints']) && $line['waypoints'] != '') { |
316 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('waypoints' => $line['waypoints'])); |
|
316 | + $this->all_flights[$id] = array_merge($this->all_flights[$id],array('waypoints' => $line['waypoints'])); |
|
317 | 317 | } |
318 | 318 | if (isset($line['pilot_id']) && $line['pilot_id'] != '') { |
319 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('pilot_id' => $line['pilot_id'])); |
|
319 | + $this->all_flights[$id] = array_merge($this->all_flights[$id],array('pilot_id' => $line['pilot_id'])); |
|
320 | 320 | } |
321 | 321 | if (isset($line['pilot_name']) && $line['pilot_name'] != '') { |
322 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('pilot_name' => $line['pilot_name'])); |
|
322 | + $this->all_flights[$id] = array_merge($this->all_flights[$id],array('pilot_name' => $line['pilot_name'])); |
|
323 | 323 | } |
324 | 324 | |
325 | 325 | if (isset($line['ident']) && $line['ident'] != '' && $line['ident'] != '????????' && $line['ident'] != '00000000' && ($this->all_flights[$id]['ident'] != trim($line['ident'])) && preg_match('/^[a-zA-Z0-9]+$/', $line['ident'])) { |
326 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ident' => trim($line['ident']))); |
|
327 | - if ($this->all_flights[$id]['addedSpotter'] == 1) { |
|
326 | + $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ident' => trim($line['ident']))); |
|
327 | + if ($this->all_flights[$id]['addedSpotter'] == 1) { |
|
328 | 328 | $timeelapsed = microtime(true); |
329 | - $Spotter = new Spotter($this->db); |
|
330 | - $fromsource = NULL; |
|
331 | - if (isset($globalAirlinesSource) && $globalAirlinesSource != '') $fromsource = $globalAirlinesSource; |
|
332 | - elseif (isset($line['format_source']) && $line['format_source'] == 'vatsimtxt') $fromsource = 'vatsim'; |
|
329 | + $Spotter = new Spotter($this->db); |
|
330 | + $fromsource = NULL; |
|
331 | + if (isset($globalAirlinesSource) && $globalAirlinesSource != '') $fromsource = $globalAirlinesSource; |
|
332 | + elseif (isset($line['format_source']) && $line['format_source'] == 'vatsimtxt') $fromsource = 'vatsim'; |
|
333 | 333 | elseif (isset($line['format_source']) && $line['format_source'] == 'whazzup') $fromsource = 'ivao'; |
334 | 334 | elseif (isset($globalVATSIM) && $globalVATSIM) $fromsource = 'vatsim'; |
335 | 335 | elseif (isset($globalIVAO) && $globalIVAO) $fromsource = 'ivao'; |
336 | - $result = $Spotter->updateIdentSpotterData($this->all_flights[$id]['id'],$this->all_flights[$id]['ident'],$fromsource); |
|
336 | + $result = $Spotter->updateIdentSpotterData($this->all_flights[$id]['id'],$this->all_flights[$id]['ident'],$fromsource); |
|
337 | 337 | if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n"; |
338 | 338 | $Spotter->db = null; |
339 | 339 | if ($globalDebugTimeElapsed) echo 'Time elapsed for update identspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
340 | - } |
|
340 | + } |
|
341 | 341 | |
342 | 342 | /* |
343 | 343 | if (!isset($line['id'])) { |
@@ -347,26 +347,26 @@ discard block |
||
347 | 347 | else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident'])); |
348 | 348 | } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id'])); |
349 | 349 | */ |
350 | - if (!isset($this->all_flights[$id]['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident'])); |
|
350 | + if (!isset($this->all_flights[$id]['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident'])); |
|
351 | 351 | |
352 | - //$putinarchive = true; |
|
353 | - if (isset($line['departure_airport_time']) && $line['departure_airport_time'] != 0) { |
|
352 | + //$putinarchive = true; |
|
353 | + if (isset($line['departure_airport_time']) && $line['departure_airport_time'] != 0) { |
|
354 | 354 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport_time' => $line['departure_airport_time'])); |
355 | - } |
|
356 | - if (isset($line['arrival_airport_time']) && $line['arrival_airport_time'] != 0) { |
|
355 | + } |
|
356 | + if (isset($line['arrival_airport_time']) && $line['arrival_airport_time'] != 0) { |
|
357 | 357 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('arrival_airport_time' => $line['arrival_airport_time'])); |
358 | - } |
|
359 | - if (isset($line['departure_airport_icao']) && isset($line['arrival_airport_icao'])) { |
|
360 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport' => $line['departure_airport_icao'],'arrival_airport' => $line['arrival_airport_icao'],'route_stop' => '')); |
|
361 | - } elseif (isset($line['departure_airport_iata']) && isset($line['arrival_airport_iata'])) { |
|
358 | + } |
|
359 | + if (isset($line['departure_airport_icao']) && isset($line['arrival_airport_icao'])) { |
|
360 | + $this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport' => $line['departure_airport_icao'],'arrival_airport' => $line['arrival_airport_icao'],'route_stop' => '')); |
|
361 | + } elseif (isset($line['departure_airport_iata']) && isset($line['arrival_airport_iata'])) { |
|
362 | 362 | $timeelapsed = microtime(true); |
363 | 363 | $Spotter = new Spotter($this->db); |
364 | 364 | $line['departure_airport_icao'] = $Spotter->getAirportIcao($line['departure_airport_iata']); |
365 | 365 | $line['arrival_airport_icao'] = $Spotter->getAirportIcao($line['arrival_airport_iata']); |
366 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport' => $line['departure_airport_icao'],'arrival_airport' => $line['arrival_airport_icao'],'route_stop' => '')); |
|
366 | + $this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport' => $line['departure_airport_icao'],'arrival_airport' => $line['arrival_airport_icao'],'route_stop' => '')); |
|
367 | 367 | if ($globalDebugTimeElapsed) echo 'Time elapsed for update getAirportICAO : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
368 | 368 | |
369 | - } elseif (!isset($line['format_source']) || $line['format_source'] != 'aprs') { |
|
369 | + } elseif (!isset($line['format_source']) || $line['format_source'] != 'aprs') { |
|
370 | 370 | $timeelapsed = microtime(true); |
371 | 371 | $Spotter = new Spotter($this->db); |
372 | 372 | $route = $Spotter->getRouteInfo(trim($line['ident'])); |
@@ -380,43 +380,43 @@ discard block |
||
380 | 380 | if ($globalDebugTimeElapsed) echo 'Time elapsed for update getrouteinfo : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
381 | 381 | |
382 | 382 | if (isset($route['fromairport_icao']) && isset($route['toairport_icao'])) { |
383 | - //if ($route['FromAirport_ICAO'] != $route['ToAirport_ICAO']) { |
|
384 | - if ($route['fromairport_icao'] != $route['toairport_icao']) { |
|
383 | + //if ($route['FromAirport_ICAO'] != $route['ToAirport_ICAO']) { |
|
384 | + if ($route['fromairport_icao'] != $route['toairport_icao']) { |
|
385 | 385 | // $this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport' => $route['FromAirport_ICAO'],'arrival_airport' => $route['ToAirport_ICAO'],'route_stop' => $route['RouteStop'])); |
386 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport' => $route['fromairport_icao'],'arrival_airport' => $route['toairport_icao'],'route_stop' => $route['routestop'])); |
|
387 | - } |
|
386 | + $this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport' => $route['fromairport_icao'],'arrival_airport' => $route['toairport_icao'],'route_stop' => $route['routestop'])); |
|
387 | + } |
|
388 | 388 | } |
389 | 389 | if (!isset($globalFork)) $globalFork = TRUE; |
390 | 390 | if (!$globalIVAO && !$globalVATSIM && !$globalphpVMS && !$globalVAM && (!isset($line['format_source']) || $line['format_source'] != 'aprs')) { |
391 | 391 | if (!isset($this->all_flights[$id]['schedule_check']) || $this->all_flights[$id]['schedule_check'] === false) $this->get_Schedule($id,trim($line['ident'])); |
392 | 392 | } |
393 | - } |
|
393 | + } |
|
394 | 394 | } |
395 | 395 | |
396 | 396 | if (isset($line['speed']) && $line['speed'] != '') { |
397 | 397 | // $this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed' => $line[12])); |
398 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed' => round($line['speed']))); |
|
399 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed_fromsrc' => true)); |
|
400 | - //$dataFound = true; |
|
398 | + $this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed' => round($line['speed']))); |
|
399 | + $this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed_fromsrc' => true)); |
|
400 | + //$dataFound = true; |
|
401 | 401 | } else if (!isset($this->all_flights[$id]['speed_fromsrc']) && isset($this->all_flights[$id]['time_last_coord']) && $this->all_flights[$id]['time_last_coord'] != time() && isset($line['latitude']) && isset($line['longitude'])) { |
402 | - $distance = $Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m'); |
|
403 | - if ($distance > 1000 && $distance < 10000) { |
|
404 | - // use datetime |
|
402 | + $distance = $Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m'); |
|
403 | + if ($distance > 1000 && $distance < 10000) { |
|
404 | + // use datetime |
|
405 | 405 | $speed = $distance/(time() - $this->all_flights[$id]['time_last_coord']); |
406 | 406 | $speed = $speed*3.6; |
407 | 407 | if ($speed < 1000) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed' => round($speed))); |
408 | 408 | if ($globalDebug) echo "ø Calculated Speed for ".$this->all_flights[$id]['hex']." : ".$speed." - distance : ".$distance."\n"; |
409 | - } |
|
409 | + } |
|
410 | 410 | } |
411 | 411 | |
412 | 412 | |
413 | 413 | |
414 | - if (isset($line['latitude']) && isset($line['longitude']) && $line['latitude'] != '' && $line['longitude'] != '' && is_numeric($line['latitude']) && is_numeric($line['longitude'])) { |
|
415 | - if (isset($this->all_flights[$id]['time_last_coord'])) $timediff = round(time()-$this->all_flights[$id]['time_last_coord']); |
|
416 | - else unset($timediff); |
|
417 | - if ($this->tmd > 5 || (isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM) || (isset($globalphpVMS) && $globalphpVMS) || (isset($globalVAM) && $globalVAM) || !isset($timediff) || $timediff > 800 || ($timediff > 10 && isset($this->all_flights[$id]['latitude']) && isset($this->all_flights[$id]['longitude']) && $Common->withinThreshold($timediff,$Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m')))) { |
|
414 | + if (isset($line['latitude']) && isset($line['longitude']) && $line['latitude'] != '' && $line['longitude'] != '' && is_numeric($line['latitude']) && is_numeric($line['longitude'])) { |
|
415 | + if (isset($this->all_flights[$id]['time_last_coord'])) $timediff = round(time()-$this->all_flights[$id]['time_last_coord']); |
|
416 | + else unset($timediff); |
|
417 | + if ($this->tmd > 5 || (isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM) || (isset($globalphpVMS) && $globalphpVMS) || (isset($globalVAM) && $globalVAM) || !isset($timediff) || $timediff > 800 || ($timediff > 10 && isset($this->all_flights[$id]['latitude']) && isset($this->all_flights[$id]['longitude']) && $Common->withinThreshold($timediff,$Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m')))) { |
|
418 | 418 | if (isset($this->all_flights[$id]['archive_latitude']) && isset($this->all_flights[$id]['archive_longitude']) && isset($this->all_flights[$id]['livedb_latitude']) && isset($this->all_flights[$id]['livedb_longitude'])) { |
419 | - if (!$Common->checkLine($this->all_flights[$id]['archive_latitude'],$this->all_flights[$id]['archive_longitude'],$this->all_flights[$id]['livedb_latitude'],$this->all_flights[$id]['livedb_longitude'],$line['latitude'],$line['longitude'])) { |
|
419 | + if (!$Common->checkLine($this->all_flights[$id]['archive_latitude'],$this->all_flights[$id]['archive_longitude'],$this->all_flights[$id]['livedb_latitude'],$this->all_flights[$id]['livedb_longitude'],$line['latitude'],$line['longitude'])) { |
|
420 | 420 | $this->all_flights[$id]['archive_latitude'] = $line['latitude']; |
421 | 421 | $this->all_flights[$id]['archive_longitude'] = $line['longitude']; |
422 | 422 | $this->all_flights[$id]['putinarchive'] = true; |
@@ -430,16 +430,16 @@ discard block |
||
430 | 430 | if ($globalDebugTimeElapsed) echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
431 | 431 | $this->tmd = 0; |
432 | 432 | if ($globalDebug) echo 'FOUND : '.$this->all_flights[$id]['over_country'].' ---------------'."\n"; |
433 | - } |
|
433 | + } |
|
434 | 434 | } |
435 | 435 | |
436 | 436 | if (isset($line['latitude']) && $line['latitude'] != '' && $line['latitude'] != 0 && $line['latitude'] < 91 && $line['latitude'] > -90) { |
437 | - //if (!isset($this->all_flights[$id]['latitude']) || $this->all_flights[$id]['latitude'] == '' || abs($this->all_flights[$id]['latitude']-$line['latitude']) < 3 || $line['format_source'] != 'sbs' || time() - $this->all_flights[$id]['lastupdate'] > 30) { |
|
437 | + //if (!isset($this->all_flights[$id]['latitude']) || $this->all_flights[$id]['latitude'] == '' || abs($this->all_flights[$id]['latitude']-$line['latitude']) < 3 || $line['format_source'] != 'sbs' || time() - $this->all_flights[$id]['lastupdate'] > 30) { |
|
438 | 438 | if (!isset($this->all_flights[$id]['archive_latitude'])) $this->all_flights[$id]['archive_latitude'] = $line['latitude']; |
439 | 439 | if (!isset($this->all_flights[$id]['livedb_latitude']) || abs($this->all_flights[$id]['livedb_latitude']-$line['latitude']) > $globalCoordMinChange || $this->all_flights[$id]['format_source'] == 'aprs') { |
440 | - $this->all_flights[$id]['livedb_latitude'] = $line['latitude']; |
|
441 | - $dataFound = true; |
|
442 | - $this->all_flights[$id]['time_last_coord'] = time(); |
|
440 | + $this->all_flights[$id]['livedb_latitude'] = $line['latitude']; |
|
441 | + $dataFound = true; |
|
442 | + $this->all_flights[$id]['time_last_coord'] = time(); |
|
443 | 443 | } |
444 | 444 | // elseif ($globalDebug) echo '!*!*! Ignore data, too close to previous one'."\n"; |
445 | 445 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('latitude' => $line['latitude'])); |
@@ -450,20 +450,20 @@ discard block |
||
450 | 450 | //$putinarchive = true; |
451 | 451 | } |
452 | 452 | */ |
453 | - /* |
|
453 | + /* |
|
454 | 454 | } elseif (isset($this->all_flights[$id]['latitude'])) { |
455 | 455 | if ($globalDebug) echo '!!! Strange latitude value - diff : '.abs($this->all_flights[$id]['latitude']-$line['latitude']).'- previous lat : '.$this->all_flights[$id]['latitude'].'- new lat : '.$line['latitude']."\n"; |
456 | 456 | } |
457 | 457 | */ |
458 | 458 | } |
459 | 459 | if (isset($line['longitude']) && $line['longitude'] != '' && $line['longitude'] != 0 && $line['longitude'] < 360 && $line['longitude'] > -180) { |
460 | - if ($line['longitude'] > 180) $line['longitude'] = $line['longitude'] - 360; |
|
461 | - //if (!isset($this->all_flights[$id]['longitude']) || $this->all_flights[$id]['longitude'] == '' || abs($this->all_flights[$id]['longitude']-$line['longitude']) < 2 || $line['format_source'] != 'sbs' || time() - $this->all_flights[$id]['lastupdate'] > 30) { |
|
460 | + if ($line['longitude'] > 180) $line['longitude'] = $line['longitude'] - 360; |
|
461 | + //if (!isset($this->all_flights[$id]['longitude']) || $this->all_flights[$id]['longitude'] == '' || abs($this->all_flights[$id]['longitude']-$line['longitude']) < 2 || $line['format_source'] != 'sbs' || time() - $this->all_flights[$id]['lastupdate'] > 30) { |
|
462 | 462 | if (!isset($this->all_flights[$id]['archive_longitude'])) $this->all_flights[$id]['archive_longitude'] = $line['longitude']; |
463 | 463 | if (!isset($this->all_flights[$id]['livedb_longitude']) || abs($this->all_flights[$id]['livedb_longitude']-$line['longitude']) > $globalCoordMinChange || $this->all_flights[$id]['format_source'] == 'aprs') { |
464 | - $this->all_flights[$id]['livedb_longitude'] = $line['longitude']; |
|
465 | - $dataFound = true; |
|
466 | - $this->all_flights[$id]['time_last_coord'] = time(); |
|
464 | + $this->all_flights[$id]['livedb_longitude'] = $line['longitude']; |
|
465 | + $dataFound = true; |
|
466 | + $this->all_flights[$id]['time_last_coord'] = time(); |
|
467 | 467 | } |
468 | 468 | // elseif ($globalDebug) echo '!*!*! Ignore data, too close to previous one'."\n"; |
469 | 469 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('longitude' => $line['longitude'])); |
@@ -481,53 +481,53 @@ discard block |
||
481 | 481 | */ |
482 | 482 | } |
483 | 483 | |
484 | - } else if ($globalDebug && $timediff > 20) { |
|
484 | + } else if ($globalDebug && $timediff > 20) { |
|
485 | 485 | $this->tmd = $this->tmd + 1; |
486 | 486 | echo '!!! Too much distance in short time... for '.$this->all_flights[$id]['ident']."\n"; |
487 | 487 | echo 'Time : '.$timediff.'s - Distance : '.$Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m')."m -"; |
488 | 488 | echo 'Speed : '.(($Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m')/$timediff)*3.6)." km/h - "; |
489 | 489 | echo 'Lat : '.$line['latitude'].' - long : '.$line['longitude'].' - prev lat : '.$this->all_flights[$id]['latitude'].' - prev long : '.$this->all_flights[$id]['longitude']." \n"; |
490 | - } |
|
490 | + } |
|
491 | 491 | } |
492 | 492 | if (isset($line['last_update']) && $line['last_update'] != '') { |
493 | - if (isset($this->all_flights[$id]['last_update']) && $this->all_flights[$id]['last_update'] != $line['last_update']) $dataFound = true; |
|
494 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('last_update' => $line['last_update'])); |
|
493 | + if (isset($this->all_flights[$id]['last_update']) && $this->all_flights[$id]['last_update'] != $line['last_update']) $dataFound = true; |
|
494 | + $this->all_flights[$id] = array_merge($this->all_flights[$id],array('last_update' => $line['last_update'])); |
|
495 | 495 | } |
496 | 496 | if (isset($line['verticalrate']) && $line['verticalrate'] != '') { |
497 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('verticalrate' => $line['verticalrate'])); |
|
498 | - //$dataFound = true; |
|
497 | + $this->all_flights[$id] = array_merge($this->all_flights[$id],array('verticalrate' => $line['verticalrate'])); |
|
498 | + //$dataFound = true; |
|
499 | 499 | } |
500 | 500 | if (isset($line['format_source']) && $line['format_source'] != '') { |
501 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('format_source' => $line['format_source'])); |
|
501 | + $this->all_flights[$id] = array_merge($this->all_flights[$id],array('format_source' => $line['format_source'])); |
|
502 | 502 | } |
503 | 503 | if (isset($line['source_name']) && $line['source_name'] != '') { |
504 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('source_name' => $line['source_name'])); |
|
504 | + $this->all_flights[$id] = array_merge($this->all_flights[$id],array('source_name' => $line['source_name'])); |
|
505 | 505 | } |
506 | 506 | if (isset($line['emergency']) && $line['emergency'] != '') { |
507 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('emergency' => $line['emergency'])); |
|
508 | - //$dataFound = true; |
|
507 | + $this->all_flights[$id] = array_merge($this->all_flights[$id],array('emergency' => $line['emergency'])); |
|
508 | + //$dataFound = true; |
|
509 | 509 | } |
510 | 510 | if (isset($line['ground']) && $line['ground'] != '') { |
511 | - if (isset($this->all_flights[$id]['ground']) && $this->all_flights[$id]['ground'] == 1 && $line['ground'] == 0) { |
|
511 | + if (isset($this->all_flights[$id]['ground']) && $this->all_flights[$id]['ground'] == 1 && $line['ground'] == 0) { |
|
512 | 512 | // Here we force archive of flight because after ground it's a new one (or should be) |
513 | 513 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0)); |
514 | 514 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('forcenew' => 1)); |
515 | 515 | if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw') && $globalDaemon) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdGi'))); |
516 | - elseif (isset($line['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id'])); |
|
516 | + elseif (isset($line['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id'])); |
|
517 | 517 | elseif (isset($this->all_flights[$id]['ident'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident'])); |
518 | - } |
|
519 | - if ($line['ground'] != 1) $line['ground'] = 0; |
|
520 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ground' => $line['ground'])); |
|
521 | - //$dataFound = true; |
|
518 | + } |
|
519 | + if ($line['ground'] != 1) $line['ground'] = 0; |
|
520 | + $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ground' => $line['ground'])); |
|
521 | + //$dataFound = true; |
|
522 | 522 | } |
523 | 523 | if (isset($line['squawk']) && $line['squawk'] != '') { |
524 | - if (isset($this->all_flights[$id]['squawk']) && $this->all_flights[$id]['squawk'] != '7500' && $this->all_flights[$id]['squawk'] != '7600' && $this->all_flights[$id]['squawk'] != '7700' && isset($this->all_flights[$id]['id'])) { |
|
525 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk'])); |
|
526 | - $highlight = ''; |
|
527 | - if ($this->all_flights[$id]['squawk'] == '7500') $highlight = 'Squawk 7500 : Hijack at '.date('Y-m-d G:i').' UTC'; |
|
528 | - if ($this->all_flights[$id]['squawk'] == '7600') $highlight = 'Squawk 7600 : Lost Comm (radio failure) at '.date('Y-m-d G:i').' UTC'; |
|
529 | - if ($this->all_flights[$id]['squawk'] == '7700') $highlight = 'Squawk 7700 : Emergency at '.date('Y-m-d G:i').' UTC'; |
|
530 | - if ($highlight != '') { |
|
524 | + if (isset($this->all_flights[$id]['squawk']) && $this->all_flights[$id]['squawk'] != '7500' && $this->all_flights[$id]['squawk'] != '7600' && $this->all_flights[$id]['squawk'] != '7700' && isset($this->all_flights[$id]['id'])) { |
|
525 | + $this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk'])); |
|
526 | + $highlight = ''; |
|
527 | + if ($this->all_flights[$id]['squawk'] == '7500') $highlight = 'Squawk 7500 : Hijack at '.date('Y-m-d G:i').' UTC'; |
|
528 | + if ($this->all_flights[$id]['squawk'] == '7600') $highlight = 'Squawk 7600 : Lost Comm (radio failure) at '.date('Y-m-d G:i').' UTC'; |
|
529 | + if ($this->all_flights[$id]['squawk'] == '7700') $highlight = 'Squawk 7700 : Emergency at '.date('Y-m-d G:i').' UTC'; |
|
530 | + if ($highlight != '') { |
|
531 | 531 | $timeelapsed = microtime(true); |
532 | 532 | $Spotter = new Spotter($this->db); |
533 | 533 | $Spotter->setHighlightFlight($this->all_flights[$id]['id'],$highlight); |
@@ -537,38 +537,38 @@ discard block |
||
537 | 537 | $this->all_flights[$id]['putinarchive'] = true; |
538 | 538 | //$putinarchive = true; |
539 | 539 | //$highlight = ''; |
540 | - } |
|
540 | + } |
|
541 | 541 | |
542 | - } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk'])); |
|
543 | - //$dataFound = true; |
|
542 | + } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk'])); |
|
543 | + //$dataFound = true; |
|
544 | 544 | } |
545 | 545 | |
546 | 546 | if (isset($line['altitude']) && $line['altitude'] != '') { |
547 | - //if (!isset($this->all_flights[$id]['altitude']) || $this->all_flights[$id]['altitude'] == '' || ($this->all_flights[$id]['altitude'] > 0 && $line['altitude'] != 0)) { |
|
547 | + //if (!isset($this->all_flights[$id]['altitude']) || $this->all_flights[$id]['altitude'] == '' || ($this->all_flights[$id]['altitude'] > 0 && $line['altitude'] != 0)) { |
|
548 | 548 | if (is_int($this->all_flights[$id]['altitude']) && abs(round($line['altitude']/100)-$this->all_flights[$id]['altitude']) > 2) $this->all_flights[$id]['putinarchive'] = true; |
549 | 549 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('altitude' => round($line['altitude']/100))); |
550 | 550 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('altitude_real' => $line['altitude'])); |
551 | 551 | //$dataFound = true; |
552 | - //} elseif ($globalDebug) echo "!!! Strange altitude data... not added.\n"; |
|
552 | + //} elseif ($globalDebug) echo "!!! Strange altitude data... not added.\n"; |
|
553 | 553 | } |
554 | 554 | |
555 | 555 | if (isset($line['noarchive']) && $line['noarchive'] === true) { |
556 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('noarchive' => true)); |
|
556 | + $this->all_flights[$id] = array_merge($this->all_flights[$id],array('noarchive' => true)); |
|
557 | 557 | } |
558 | 558 | |
559 | 559 | if (isset($line['heading']) && $line['heading'] != '') { |
560 | - if (is_int($this->all_flights[$id]['heading']) && abs($this->all_flights[$id]['heading']-round($line['heading'])) > 2) $this->all_flights[$id]['putinarchive'] = true; |
|
561 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => round($line['heading']))); |
|
562 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading_fromsrc' => true)); |
|
563 | - //$dataFound = true; |
|
560 | + if (is_int($this->all_flights[$id]['heading']) && abs($this->all_flights[$id]['heading']-round($line['heading'])) > 2) $this->all_flights[$id]['putinarchive'] = true; |
|
561 | + $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => round($line['heading']))); |
|
562 | + $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading_fromsrc' => true)); |
|
563 | + //$dataFound = true; |
|
564 | 564 | } elseif (!isset($this->all_flights[$id]['heading_fromsrc']) && isset($this->all_flights[$id]['archive_latitude']) && $this->all_flights[$id]['archive_latitude'] != $this->all_flights[$id]['latitude'] && isset($this->all_flights[$id]['archive_longitude']) && $this->all_flights[$id]['archive_longitude'] != $this->all_flights[$id]['longitude']) { |
565 | - $heading = $Common->getHeading($this->all_flights[$id]['archive_latitude'],$this->all_flights[$id]['archive_longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude']); |
|
566 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => round($heading))); |
|
567 | - if (abs($this->all_flights[$id]['heading']-round($heading)) > 2) $this->all_flights[$id]['putinarchive'] = true; |
|
568 | - if ($globalDebug) echo "ø Calculated Heading for ".$this->all_flights[$id]['hex']." : ".$heading."\n"; |
|
565 | + $heading = $Common->getHeading($this->all_flights[$id]['archive_latitude'],$this->all_flights[$id]['archive_longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude']); |
|
566 | + $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => round($heading))); |
|
567 | + if (abs($this->all_flights[$id]['heading']-round($heading)) > 2) $this->all_flights[$id]['putinarchive'] = true; |
|
568 | + if ($globalDebug) echo "ø Calculated Heading for ".$this->all_flights[$id]['hex']." : ".$heading."\n"; |
|
569 | 569 | } elseif (isset($this->all_flights[$id]['format_source']) && $this->all_flights[$id]['format_source'] == 'ACARS') { |
570 | - // If not enough messages and ACARS set heading to 0 |
|
571 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => 0)); |
|
570 | + // If not enough messages and ACARS set heading to 0 |
|
571 | + $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => 0)); |
|
572 | 572 | } |
573 | 573 | if (isset($globalSourcesupdate) && $globalSourcesupdate != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalSourcesupdate) $dataFound = false; |
574 | 574 | elseif (isset($globalSBS1update) && $globalSBS1update != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalSBS1update) $dataFound = false; |
@@ -579,119 +579,119 @@ discard block |
||
579 | 579 | //if ($dataFound == true && isset($this->all_flights[$id]['hex']) && $this->all_flights[$id]['ident'] != '' && $this->all_flights[$id]['latitude'] != '' && $this->all_flights[$id]['longitude'] != '') { |
580 | 580 | //if ($dataFound === true && isset($this->all_flights[$id]['hex']) && $this->all_flights[$id]['heading'] != '' && $this->all_flights[$id]['latitude'] != '' && $this->all_flights[$id]['longitude'] != '') { |
581 | 581 | if ($dataFound === true && isset($this->all_flights[$id]['hex'])) { |
582 | - $this->all_flights[$id]['lastupdate'] = time(); |
|
583 | - if ($this->all_flights[$id]['addedSpotter'] == 0) { |
|
584 | - if (!isset($globalDistanceIgnore['latitude']) || $this->all_flights[$id]['longitude'] == '' || $this->all_flights[$id]['latitude'] == '' || (isset($globalDistanceIgnore['latitude']) && $Common->distance($this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude']) < $globalDistanceIgnore['distance'])) { |
|
585 | - //print_r($this->all_flights); |
|
586 | - //echo $this->all_flights[$id]['id'].' - '.$this->all_flights[$id]['addedSpotter']."\n"; |
|
587 | - //$last_hour_ident = Spotter->getIdentFromLastHour($this->all_flights[$id]['ident']); |
|
588 | - if (!isset($this->all_flights[$id]['forcenew']) || $this->all_flights[$id]['forcenew'] == 0) { |
|
582 | + $this->all_flights[$id]['lastupdate'] = time(); |
|
583 | + if ($this->all_flights[$id]['addedSpotter'] == 0) { |
|
584 | + if (!isset($globalDistanceIgnore['latitude']) || $this->all_flights[$id]['longitude'] == '' || $this->all_flights[$id]['latitude'] == '' || (isset($globalDistanceIgnore['latitude']) && $Common->distance($this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude']) < $globalDistanceIgnore['distance'])) { |
|
585 | + //print_r($this->all_flights); |
|
586 | + //echo $this->all_flights[$id]['id'].' - '.$this->all_flights[$id]['addedSpotter']."\n"; |
|
587 | + //$last_hour_ident = Spotter->getIdentFromLastHour($this->all_flights[$id]['ident']); |
|
588 | + if (!isset($this->all_flights[$id]['forcenew']) || $this->all_flights[$id]['forcenew'] == 0) { |
|
589 | 589 | if ($globalDebug) echo "Check if aircraft is already in DB..."; |
590 | 590 | $timeelapsed = microtime(true); |
591 | 591 | $SpotterLive = new SpotterLive($this->db); |
592 | 592 | if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt' || $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson' || $line['format_source'] === 'radarvirtueljson')) { |
593 | - $recent_ident = $SpotterLive->checkModeSRecent($this->all_flights[$id]['hex']); |
|
594 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkModeSRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
593 | + $recent_ident = $SpotterLive->checkModeSRecent($this->all_flights[$id]['hex']); |
|
594 | + if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkModeSRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
595 | 595 | } elseif (isset($line['id'])) { |
596 | - $recent_ident = $SpotterLive->checkIdRecent($line['id']); |
|
597 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
596 | + $recent_ident = $SpotterLive->checkIdRecent($line['id']); |
|
597 | + if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
598 | 598 | } elseif (isset($this->all_flights[$id]['ident']) && $this->all_flights[$id]['ident'] != '') { |
599 | - $recent_ident = $SpotterLive->checkIdentRecent($this->all_flights[$id]['ident']); |
|
600 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
599 | + $recent_ident = $SpotterLive->checkIdentRecent($this->all_flights[$id]['ident']); |
|
600 | + if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
601 | 601 | } else $recent_ident = ''; |
602 | 602 | $SpotterLive->db=null; |
603 | 603 | |
604 | 604 | if ($globalDebug && $recent_ident == '') echo " Not in DB.\n"; |
605 | 605 | elseif ($globalDebug && $recent_ident != '') echo " Already in DB.\n"; |
606 | - } else { |
|
606 | + } else { |
|
607 | 607 | $recent_ident = ''; |
608 | 608 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('forcenew' => 0)); |
609 | - } |
|
610 | - //if there was no aircraft with the same callsign within the last hour and go post it into the archive |
|
611 | - if($recent_ident == "") |
|
612 | - { |
|
609 | + } |
|
610 | + //if there was no aircraft with the same callsign within the last hour and go post it into the archive |
|
611 | + if($recent_ident == "") |
|
612 | + { |
|
613 | 613 | if ($globalDebug) echo "\o/ Add ".$this->all_flights[$id]['ident']." in archive DB : "; |
614 | 614 | if ($this->all_flights[$id]['departure_airport'] == "") { $this->all_flights[$id]['departure_airport'] = "NA"; } |
615 | 615 | if ($this->all_flights[$id]['arrival_airport'] == "") { $this->all_flights[$id]['arrival_airport'] = "NA"; } |
616 | 616 | //adds the spotter data for the archive |
617 | 617 | $ignoreImport = false; |
618 | 618 | foreach($globalAirportIgnore as $airportIgnore) { |
619 | - if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) { |
|
619 | + if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) { |
|
620 | 620 | $ignoreImport = true; |
621 | - } |
|
621 | + } |
|
622 | 622 | } |
623 | 623 | if (count($globalAirportAccept) > 0) { |
624 | - $ignoreImport = true; |
|
625 | - foreach($globalAirportIgnore as $airportIgnore) { |
|
624 | + $ignoreImport = true; |
|
625 | + foreach($globalAirportIgnore as $airportIgnore) { |
|
626 | 626 | if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) { |
627 | - $ignoreImport = false; |
|
627 | + $ignoreImport = false; |
|
628 | + } |
|
628 | 629 | } |
629 | - } |
|
630 | 630 | } |
631 | 631 | if (isset($globalAirlineIgnore) && is_array($globalAirlineIgnore)) { |
632 | - foreach($globalAirlineIgnore as $airlineIgnore) { |
|
632 | + foreach($globalAirlineIgnore as $airlineIgnore) { |
|
633 | 633 | if ((is_numeric(substr(substr($this->all_flights[$id]['ident'],0,4),-1,1)) && substr($this->all_flights[$id]['ident'],0,3) == $airlineIgnore) || (is_numeric(substr(substr($this->all_flights[$id]['ident'],0,3),-1,1)) && substr($this->all_flights[$id]['ident'],0,2) == $airlineIgnore)) { |
634 | - $ignoreImport = true; |
|
634 | + $ignoreImport = true; |
|
635 | + } |
|
635 | 636 | } |
636 | - } |
|
637 | 637 | } |
638 | 638 | if (isset($globalAirlineAccept) && count($globalAirlineAccept) > 0) { |
639 | - $ignoreImport = true; |
|
640 | - foreach($globalAirlineAccept as $airlineAccept) { |
|
639 | + $ignoreImport = true; |
|
640 | + foreach($globalAirlineAccept as $airlineAccept) { |
|
641 | 641 | if ((is_numeric(substr(substr($this->all_flights[$id]['ident'],0,4),-1,1)) && substr($this->all_flights[$id]['ident'],0,3) == $airlineAccept) || (is_numeric(substr(substr($this->all_flights[$id]['ident'],0,3),-1,1)) && substr($this->all_flights[$id]['ident'],0,2) == $airlineAccept)) { |
642 | - $ignoreImport = false; |
|
642 | + $ignoreImport = false; |
|
643 | + } |
|
643 | 644 | } |
644 | - } |
|
645 | 645 | } |
646 | 646 | if (isset($globalPilotIdAccept) && count($globalPilotIdAccept) > 0) { |
647 | - $ignoreImport = true; |
|
648 | - foreach($globalPilotIdAccept as $pilotIdAccept) { |
|
647 | + $ignoreImport = true; |
|
648 | + foreach($globalPilotIdAccept as $pilotIdAccept) { |
|
649 | 649 | if ($this->all_flights[$id]['pilot_id'] == $pilotIdAccept) { |
650 | - $ignoreImport = false; |
|
650 | + $ignoreImport = false; |
|
651 | + } |
|
651 | 652 | } |
652 | - } |
|
653 | 653 | } |
654 | 654 | |
655 | 655 | if (!$ignoreImport) { |
656 | - $highlight = ''; |
|
657 | - if ($this->all_flights[$id]['squawk'] == '7500') $highlight = 'Squawk 7500 : Hijack'; |
|
658 | - if ($this->all_flights[$id]['squawk'] == '7600') $highlight = 'Squawk 7600 : Lost Comm (radio failure)'; |
|
659 | - if ($this->all_flights[$id]['squawk'] == '7700') $highlight = 'Squawk 7700 : Emergency'; |
|
660 | - if (!isset($this->all_flights[$id]['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdHi'))); |
|
661 | - $timeelapsed = microtime(true); |
|
662 | - $Spotter = new Spotter($this->db); |
|
663 | - $result = $Spotter->addSpotterData($this->all_flights[$id]['id'], $this->all_flights[$id]['ident'], $this->all_flights[$id]['aircraft_icao'], $this->all_flights[$id]['departure_airport'], $this->all_flights[$id]['arrival_airport'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], $this->all_flights[$id]['waypoints'], $this->all_flights[$id]['altitude'], $this->all_flights[$id]['heading'], $this->all_flights[$id]['speed'], $this->all_flights[$id]['datetime'], $this->all_flights[$id]['departure_airport_time'], $this->all_flights[$id]['arrival_airport_time'],$this->all_flights[$id]['squawk'],$this->all_flights[$id]['route_stop'],$highlight,$this->all_flights[$id]['hex'],$this->all_flights[$id]['registration'],$this->all_flights[$id]['pilot_id'],$this->all_flights[$id]['pilot_name'],$this->all_flights[$id]['verticalrate'],$this->all_flights[$id]['ground'],$this->all_flights[$id]['format_source'],$this->all_flights[$id]['source_name']); |
|
664 | - $Spotter->db = null; |
|
665 | - if ($globalDebug && isset($result)) echo $result."\n"; |
|
666 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
656 | + $highlight = ''; |
|
657 | + if ($this->all_flights[$id]['squawk'] == '7500') $highlight = 'Squawk 7500 : Hijack'; |
|
658 | + if ($this->all_flights[$id]['squawk'] == '7600') $highlight = 'Squawk 7600 : Lost Comm (radio failure)'; |
|
659 | + if ($this->all_flights[$id]['squawk'] == '7700') $highlight = 'Squawk 7700 : Emergency'; |
|
660 | + if (!isset($this->all_flights[$id]['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdHi'))); |
|
661 | + $timeelapsed = microtime(true); |
|
662 | + $Spotter = new Spotter($this->db); |
|
663 | + $result = $Spotter->addSpotterData($this->all_flights[$id]['id'], $this->all_flights[$id]['ident'], $this->all_flights[$id]['aircraft_icao'], $this->all_flights[$id]['departure_airport'], $this->all_flights[$id]['arrival_airport'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], $this->all_flights[$id]['waypoints'], $this->all_flights[$id]['altitude'], $this->all_flights[$id]['heading'], $this->all_flights[$id]['speed'], $this->all_flights[$id]['datetime'], $this->all_flights[$id]['departure_airport_time'], $this->all_flights[$id]['arrival_airport_time'],$this->all_flights[$id]['squawk'],$this->all_flights[$id]['route_stop'],$highlight,$this->all_flights[$id]['hex'],$this->all_flights[$id]['registration'],$this->all_flights[$id]['pilot_id'],$this->all_flights[$id]['pilot_name'],$this->all_flights[$id]['verticalrate'],$this->all_flights[$id]['ground'],$this->all_flights[$id]['format_source'],$this->all_flights[$id]['source_name']); |
|
664 | + $Spotter->db = null; |
|
665 | + if ($globalDebug && isset($result)) echo $result."\n"; |
|
666 | + if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
667 | 667 | |
668 | - // Add source stat in DB |
|
669 | - $Stats = new Stats($this->db); |
|
670 | - if (!empty($this->stats)) { |
|
668 | + // Add source stat in DB |
|
669 | + $Stats = new Stats($this->db); |
|
670 | + if (!empty($this->stats)) { |
|
671 | 671 | if ($globalDebug) echo 'Add source stats : '; |
672 | - foreach($this->stats as $date => $data) { |
|
673 | - foreach($data as $source => $sourced) { |
|
674 | - //print_r($sourced); |
|
675 | - if (isset($sourced['polar'])) echo $Stats->addStatSource(json_encode($sourced['polar']),$source,'polar',$date); |
|
676 | - if (isset($sourced['hist'])) echo $Stats->addStatSource(json_encode($sourced['hist']),$source,'hist',$date); |
|
677 | - if (isset($sourced['msg'])) { |
|
678 | - if (time() - $sourced['msg']['date'] > 10) { |
|
679 | - $nbmsg = round($sourced['msg']['nb']/(time() - $sourced['msg']['date'])); |
|
680 | - echo $Stats->addStatSource($nbmsg,$source,'msg',$date); |
|
681 | - unset($this->stats[$date][$source]['msg']); |
|
682 | - } |
|
683 | - } |
|
684 | - } |
|
685 | - if ($date != date('Y-m-d')) { |
|
686 | - unset($this->stats[$date]); |
|
687 | - } |
|
688 | - } |
|
689 | - if ($globalDebug) echo 'Done'."\n"; |
|
690 | - |
|
691 | - } |
|
692 | - $Stats->db = null; |
|
672 | + foreach($this->stats as $date => $data) { |
|
673 | + foreach($data as $source => $sourced) { |
|
674 | + //print_r($sourced); |
|
675 | + if (isset($sourced['polar'])) echo $Stats->addStatSource(json_encode($sourced['polar']),$source,'polar',$date); |
|
676 | + if (isset($sourced['hist'])) echo $Stats->addStatSource(json_encode($sourced['hist']),$source,'hist',$date); |
|
677 | + if (isset($sourced['msg'])) { |
|
678 | + if (time() - $sourced['msg']['date'] > 10) { |
|
679 | + $nbmsg = round($sourced['msg']['nb']/(time() - $sourced['msg']['date'])); |
|
680 | + echo $Stats->addStatSource($nbmsg,$source,'msg',$date); |
|
681 | + unset($this->stats[$date][$source]['msg']); |
|
682 | + } |
|
683 | + } |
|
684 | + } |
|
685 | + if ($date != date('Y-m-d')) { |
|
686 | + unset($this->stats[$date]); |
|
687 | + } |
|
688 | + } |
|
689 | + if ($globalDebug) echo 'Done'."\n"; |
|
690 | + |
|
691 | + } |
|
692 | + $Stats->db = null; |
|
693 | 693 | |
694 | - $this->del(); |
|
694 | + $this->del(); |
|
695 | 695 | } elseif ($globalDebug) echo 'Ignore data'."\n"; |
696 | 696 | //$ignoreImport = false; |
697 | 697 | $this->all_flights[$id]['addedSpotter'] = 1; |
@@ -709,18 +709,18 @@ discard block |
||
709 | 709 | */ |
710 | 710 | //SpotterLive->deleteLiveSpotterDataByIdent($this->all_flights[$id]['ident']); |
711 | 711 | if ($this->last_delete == 0 || time() - $this->last_delete > 1800) { |
712 | - if ($globalDebug) echo "---- Deleting Live Spotter data older than 9 hours..."; |
|
713 | - //SpotterLive->deleteLiveSpotterDataNotUpdated(); |
|
714 | - $SpotterLive = new SpotterLive($this->db); |
|
715 | - $SpotterLive->deleteLiveSpotterData(); |
|
716 | - $SpotterLive->db=null; |
|
717 | - if ($globalDebug) echo " Done\n"; |
|
718 | - $this->last_delete = time(); |
|
712 | + if ($globalDebug) echo "---- Deleting Live Spotter data older than 9 hours..."; |
|
713 | + //SpotterLive->deleteLiveSpotterDataNotUpdated(); |
|
714 | + $SpotterLive = new SpotterLive($this->db); |
|
715 | + $SpotterLive->deleteLiveSpotterData(); |
|
716 | + $SpotterLive->db=null; |
|
717 | + if ($globalDebug) echo " Done\n"; |
|
718 | + $this->last_delete = time(); |
|
719 | 719 | } |
720 | - } else { |
|
720 | + } else { |
|
721 | 721 | if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt'|| $line['format_source'] === 'planeupdatefaa' || $line['format_source'] === 'aprs' || $line['format_source'] === 'aircraftlistjson')) { |
722 | - $this->all_flights[$id]['id'] = $recent_ident; |
|
723 | - $this->all_flights[$id]['addedSpotter'] = 1; |
|
722 | + $this->all_flights[$id]['id'] = $recent_ident; |
|
723 | + $this->all_flights[$id]['addedSpotter'] = 1; |
|
724 | 724 | } |
725 | 725 | if (isset($globalDaemon) && !$globalDaemon) { |
726 | 726 | $Spotter = new Spotter($this->db); |
@@ -728,14 +728,14 @@ discard block |
||
728 | 728 | $Spotter->db = null; |
729 | 729 | } |
730 | 730 | |
731 | - } |
|
731 | + } |
|
732 | + } |
|
732 | 733 | } |
733 | - } |
|
734 | - //adds the spotter LIVE data |
|
735 | - //SpotterLive->addLiveSpotterData($flightaware_id, $ident, $aircraft_type, $departure_airport, $arrival_airport, $latitude, $longitude, $waypoints, $altitude, $heading, $groundspeed); |
|
736 | - //echo "\nAdd in Live !! \n"; |
|
737 | - //echo "{$line[8]} {$line[7]} - MODES:{$line[4]} CALLSIGN:{$line[10]} ALT:{$line[11]} VEL:{$line[12]} HDG:{$line[13]} LAT:{$line[14]} LON:{$line[15]} VR:{$line[16]} SQUAWK:{$line[17]}\n"; |
|
738 | - if ($globalDebug) { |
|
734 | + //adds the spotter LIVE data |
|
735 | + //SpotterLive->addLiveSpotterData($flightaware_id, $ident, $aircraft_type, $departure_airport, $arrival_airport, $latitude, $longitude, $waypoints, $altitude, $heading, $groundspeed); |
|
736 | + //echo "\nAdd in Live !! \n"; |
|
737 | + //echo "{$line[8]} {$line[7]} - MODES:{$line[4]} CALLSIGN:{$line[10]} ALT:{$line[11]} VEL:{$line[12]} HDG:{$line[13]} LAT:{$line[14]} LON:{$line[15]} VR:{$line[16]} SQUAWK:{$line[17]}\n"; |
|
738 | + if ($globalDebug) { |
|
739 | 739 | if ((isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM) || (isset($globalphpVMS) && $globalphpVMS) || (isset($globalVAM) && $globalVAM)) { |
740 | 740 | if (isset($this->all_flights[$id]['source_name'])) echo 'DATA : hex : '.$this->all_flights[$id]['hex'].' - ident : '.$this->all_flights[$id]['ident'].' - ICAO : '.$this->all_flights[$id]['aircraft_icao'].' - Departure Airport : '.$this->all_flights[$id]['departure_airport'].' - Arrival Airport : '.$this->all_flights[$id]['arrival_airport'].' - Latitude : '.$this->all_flights[$id]['latitude'].' - Longitude : '.$this->all_flights[$id]['longitude'].' - waypoints : '.$this->all_flights[$id]['waypoints'].' - Altitude : '.$this->all_flights[$id]['altitude'].' - Heading : '.$this->all_flights[$id]['heading'].' - Speed : '.$this->all_flights[$id]['speed'].' - Departure Airport Time : '.$this->all_flights[$id]['departure_airport_time'].' - Arrival Airport time : '.$this->all_flights[$id]['arrival_airport_time'].' - Pilot : '.$this->all_flights[$id]['pilot_name'].' - Source name : '.$this->all_flights[$id]['source_name']."\n"; |
741 | 741 | else echo 'DATA : hex : '.$this->all_flights[$id]['hex'].' - ident : '.$this->all_flights[$id]['ident'].' - ICAO : '.$this->all_flights[$id]['aircraft_icao'].' - Departure Airport : '.$this->all_flights[$id]['departure_airport'].' - Arrival Airport : '.$this->all_flights[$id]['arrival_airport'].' - Latitude : '.$this->all_flights[$id]['latitude'].' - Longitude : '.$this->all_flights[$id]['longitude'].' - waypoints : '.$this->all_flights[$id]['waypoints'].' - Altitude : '.$this->all_flights[$id]['altitude'].' - Heading : '.$this->all_flights[$id]['heading'].' - Speed : '.$this->all_flights[$id]['speed'].' - Departure Airport Time : '.$this->all_flights[$id]['departure_airport_time'].' - Arrival Airport time : '.$this->all_flights[$id]['arrival_airport_time'].' - Pilot : '.$this->all_flights[$id]['pilot_name']."\n"; |
@@ -743,49 +743,49 @@ discard block |
||
743 | 743 | if (isset($this->all_flights[$id]['source_name'])) echo 'DATA : hex : '.$this->all_flights[$id]['hex'].' - ident : '.$this->all_flights[$id]['ident'].' - ICAO : '.$this->all_flights[$id]['aircraft_icao'].' - Departure Airport : '.$this->all_flights[$id]['departure_airport'].' - Arrival Airport : '.$this->all_flights[$id]['arrival_airport'].' - Latitude : '.$this->all_flights[$id]['latitude'].' - Longitude : '.$this->all_flights[$id]['longitude'].' - waypoints : '.$this->all_flights[$id]['waypoints'].' - Altitude : '.$this->all_flights[$id]['altitude'].' - Heading : '.$this->all_flights[$id]['heading'].' - Speed : '.$this->all_flights[$id]['speed'].' - Departure Airport Time : '.$this->all_flights[$id]['departure_airport_time'].' - Arrival Airport time : '.$this->all_flights[$id]['arrival_airport_time'].' - Source Name : '.$this->all_flights[$id]['source_name']."\n"; |
744 | 744 | else echo 'DATA : hex : '.$this->all_flights[$id]['hex'].' - ident : '.$this->all_flights[$id]['ident'].' - ICAO : '.$this->all_flights[$id]['aircraft_icao'].' - Departure Airport : '.$this->all_flights[$id]['departure_airport'].' - Arrival Airport : '.$this->all_flights[$id]['arrival_airport'].' - Latitude : '.$this->all_flights[$id]['latitude'].' - Longitude : '.$this->all_flights[$id]['longitude'].' - waypoints : '.$this->all_flights[$id]['waypoints'].' - Altitude : '.$this->all_flights[$id]['altitude'].' - Heading : '.$this->all_flights[$id]['heading'].' - Speed : '.$this->all_flights[$id]['speed'].' - Departure Airport Time : '.$this->all_flights[$id]['departure_airport_time'].' - Arrival Airport time : '.$this->all_flights[$id]['arrival_airport_time']."\n"; |
745 | 745 | } |
746 | - } |
|
747 | - $ignoreImport = false; |
|
748 | - if ($this->all_flights[$id]['departure_airport'] == "") { $this->all_flights[$id]['departure_airport'] = "NA"; } |
|
749 | - if ($this->all_flights[$id]['arrival_airport'] == "") { $this->all_flights[$id]['arrival_airport'] = "NA"; } |
|
746 | + } |
|
747 | + $ignoreImport = false; |
|
748 | + if ($this->all_flights[$id]['departure_airport'] == "") { $this->all_flights[$id]['departure_airport'] = "NA"; } |
|
749 | + if ($this->all_flights[$id]['arrival_airport'] == "") { $this->all_flights[$id]['arrival_airport'] = "NA"; } |
|
750 | 750 | |
751 | - foreach($globalAirportIgnore as $airportIgnore) { |
|
752 | - if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) { |
|
753 | - $ignoreImport = true; |
|
751 | + foreach($globalAirportIgnore as $airportIgnore) { |
|
752 | + if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) { |
|
753 | + $ignoreImport = true; |
|
754 | + } |
|
754 | 755 | } |
755 | - } |
|
756 | - if (count($globalAirportAccept) > 0) { |
|
757 | - $ignoreImport = true; |
|
758 | - foreach($globalAirportIgnore as $airportIgnore) { |
|
759 | - if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) { |
|
756 | + if (count($globalAirportAccept) > 0) { |
|
757 | + $ignoreImport = true; |
|
758 | + foreach($globalAirportIgnore as $airportIgnore) { |
|
759 | + if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) { |
|
760 | 760 | $ignoreImport = false; |
761 | - } |
|
761 | + } |
|
762 | 762 | } |
763 | - } |
|
764 | - if (isset($globalAirlineIgnore) && is_array($globalAirlineIgnore)) { |
|
763 | + } |
|
764 | + if (isset($globalAirlineIgnore) && is_array($globalAirlineIgnore)) { |
|
765 | 765 | foreach($globalAirlineIgnore as $airlineIgnore) { |
766 | - if ((is_numeric(substr(substr($this->all_flights[$id]['ident'],0,4),-1,1)) && substr($this->all_flights[$id]['ident'],0,3) == $airlineIgnore) || (is_numeric(substr(substr($this->all_flights[$id]['ident'],0,3),-1,1)) && substr($this->all_flights[$id]['ident'],0,2) == $airlineIgnore)) { |
|
766 | + if ((is_numeric(substr(substr($this->all_flights[$id]['ident'],0,4),-1,1)) && substr($this->all_flights[$id]['ident'],0,3) == $airlineIgnore) || (is_numeric(substr(substr($this->all_flights[$id]['ident'],0,3),-1,1)) && substr($this->all_flights[$id]['ident'],0,2) == $airlineIgnore)) { |
|
767 | 767 | $ignoreImport = true; |
768 | - } |
|
768 | + } |
|
769 | 769 | } |
770 | - } |
|
771 | - if (isset($globalAirlineAccept) && count($globalAirlineAccept) > 0) { |
|
770 | + } |
|
771 | + if (isset($globalAirlineAccept) && count($globalAirlineAccept) > 0) { |
|
772 | 772 | $ignoreImport = true; |
773 | 773 | foreach($globalAirlineAccept as $airlineAccept) { |
774 | - if ((is_numeric(substr(substr($this->all_flights[$id]['ident'],0,4),-1,1)) && substr($this->all_flights[$id]['ident'],0,3) == $airlineAccept) || (is_numeric(substr(substr($this->all_flights[$id]['ident'],0,3),-1,1)) && substr($this->all_flights[$id]['ident'],0,2) == $airlineAccept)) { |
|
774 | + if ((is_numeric(substr(substr($this->all_flights[$id]['ident'],0,4),-1,1)) && substr($this->all_flights[$id]['ident'],0,3) == $airlineAccept) || (is_numeric(substr(substr($this->all_flights[$id]['ident'],0,3),-1,1)) && substr($this->all_flights[$id]['ident'],0,2) == $airlineAccept)) { |
|
775 | 775 | $ignoreImport = false; |
776 | - } |
|
776 | + } |
|
777 | 777 | } |
778 | - } |
|
779 | - if (isset($globalPilotIdAccept) && count($globalPilotIdAccept) > 0) { |
|
778 | + } |
|
779 | + if (isset($globalPilotIdAccept) && count($globalPilotIdAccept) > 0) { |
|
780 | 780 | $ignoreImport = true; |
781 | 781 | foreach($globalPilotIdAccept as $pilotIdAccept) { |
782 | - if ($this->all_flights[$id]['pilot_id'] == $pilotIdAccept) { |
|
783 | - $ignoreImport = false; |
|
784 | - } |
|
782 | + if ($this->all_flights[$id]['pilot_id'] == $pilotIdAccept) { |
|
783 | + $ignoreImport = false; |
|
784 | + } |
|
785 | + } |
|
785 | 786 | } |
786 | - } |
|
787 | 787 | |
788 | - if (!$ignoreImport) { |
|
788 | + if (!$ignoreImport) { |
|
789 | 789 | if (!isset($globalDistanceIgnore['latitude']) || (isset($globalDistanceIgnore['latitude']) && $Common->distance($this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude']) < $globalDistanceIgnore['distance'])) { |
790 | 790 | if ($globalDebug) echo "\o/ Add ".$this->all_flights[$id]['ident']." from ".$this->all_flights[$id]['format_source']." in Live DB : "; |
791 | 791 | $timeelapsed = microtime(true); |
@@ -823,7 +823,7 @@ discard block |
||
823 | 823 | if ($stats_heading == 16) $stats_heading = 0; |
824 | 824 | if (!isset($this->stats[$current_date][$source]['polar'][1])) { |
825 | 825 | for ($i=0;$i<=15;$i++) { |
826 | - $this->stats[$current_date][$source]['polar'][$i] = 0; |
|
826 | + $this->stats[$current_date][$source]['polar'][$i] = 0; |
|
827 | 827 | } |
828 | 828 | $this->stats[$current_date][$source]['polar'][$stats_heading] = $stats_distance; |
829 | 829 | } else { |
@@ -836,11 +836,11 @@ discard block |
||
836 | 836 | //var_dump($this->stats); |
837 | 837 | if (!isset($this->stats[$current_date][$source]['hist'][$distance])) { |
838 | 838 | if (isset($this->stats[$current_date][$source]['hist'][0])) { |
839 | - end($this->stats[$current_date][$source]['hist']); |
|
840 | - $mini = key($this->stats[$current_date][$source]['hist'])+10; |
|
839 | + end($this->stats[$current_date][$source]['hist']); |
|
840 | + $mini = key($this->stats[$current_date][$source]['hist'])+10; |
|
841 | 841 | } else $mini = 0; |
842 | 842 | for ($i=$mini;$i<=$distance;$i+=10) { |
843 | - $this->stats[$current_date][$source]['hist'][$i] = 0; |
|
843 | + $this->stats[$current_date][$source]['hist'][$i] = 0; |
|
844 | 844 | } |
845 | 845 | $this->stats[$current_date][$source]['hist'][$distance] = 1; |
846 | 846 | } else { |
@@ -857,22 +857,22 @@ discard block |
||
857 | 857 | |
858 | 858 | |
859 | 859 | if ($this->last_delete_hourly == 0 || time() - $this->last_delete_hourly > 900) { |
860 | - if ($globalDebug) echo "---- Deleting Live Spotter data Not updated since 2 hour..."; |
|
861 | - $SpotterLive = new SpotterLive($this->db); |
|
862 | - $SpotterLive->deleteLiveSpotterDataNotUpdated(); |
|
863 | - $SpotterLive->db = null; |
|
864 | - //SpotterLive->deleteLiveSpotterData(); |
|
865 | - if ($globalDebug) echo " Done\n"; |
|
866 | - $this->last_delete_hourly = time(); |
|
860 | + if ($globalDebug) echo "---- Deleting Live Spotter data Not updated since 2 hour..."; |
|
861 | + $SpotterLive = new SpotterLive($this->db); |
|
862 | + $SpotterLive->deleteLiveSpotterDataNotUpdated(); |
|
863 | + $SpotterLive->db = null; |
|
864 | + //SpotterLive->deleteLiveSpotterData(); |
|
865 | + if ($globalDebug) echo " Done\n"; |
|
866 | + $this->last_delete_hourly = time(); |
|
867 | 867 | } |
868 | 868 | |
869 | - } |
|
870 | - //$ignoreImport = false; |
|
869 | + } |
|
870 | + //$ignoreImport = false; |
|
871 | 871 | } |
872 | 872 | //if (function_exists('pcntl_fork') && $globalFork) pcntl_signal(SIGCHLD, SIG_IGN); |
873 | 873 | if ($send) return $this->all_flights[$id]; |
874 | - } |
|
874 | + } |
|
875 | + } |
|
875 | 876 | } |
876 | - } |
|
877 | 877 | } |
878 | 878 | ?> |
@@ -58,6 +58,10 @@ discard block |
||
58 | 58 | } else return $ident; |
59 | 59 | } |
60 | 60 | |
61 | + /** |
|
62 | + * @param string $correct_ident |
|
63 | + * @param string $source |
|
64 | + */ |
|
61 | 65 | public function addOperator($ident,$correct_ident,$source) { |
62 | 66 | $query = "INSERT INTO translation (Operator,Operator_correct,Source) VALUES (:ident,:correct_ident,:source)"; |
63 | 67 | $query_values = array(':ident' => $ident,':correct_ident' => $correct_ident, ':source' => $source); |
@@ -69,6 +73,10 @@ discard block |
||
69 | 73 | } |
70 | 74 | } |
71 | 75 | |
76 | + /** |
|
77 | + * @param string $correct_ident |
|
78 | + * @param string $source |
|
79 | + */ |
|
72 | 80 | public function updateOperator($ident,$correct_ident,$source) { |
73 | 81 | $query = "UPDATE translation SET Operator_correct = :correct_ident,Source = :source WHERE Operator = :ident"; |
74 | 82 | $query_values = array(':ident' => $ident,':correct_ident' => $correct_ident, ':source' => $source); |
@@ -7,91 +7,91 @@ discard block |
||
7 | 7 | |
8 | 8 | |
9 | 9 | class Translation { |
10 | - public $db; |
|
11 | - public function __construct($dbc = null) { |
|
12 | - $Connection = new Connection($dbc); |
|
13 | - $this->db = $Connection->db(); |
|
14 | - } |
|
10 | + public $db; |
|
11 | + public function __construct($dbc = null) { |
|
12 | + $Connection = new Connection($dbc); |
|
13 | + $this->db = $Connection->db(); |
|
14 | + } |
|
15 | 15 | |
16 | - /** |
|
17 | - * Change IATA to ICAO value for ident |
|
18 | - * |
|
19 | - * @param String $ident ident |
|
20 | - * @return String the icao |
|
21 | - */ |
|
22 | - public function ident2icao($ident) { |
|
16 | + /** |
|
17 | + * Change IATA to ICAO value for ident |
|
18 | + * |
|
19 | + * @param String $ident ident |
|
20 | + * @return String the icao |
|
21 | + */ |
|
22 | + public function ident2icao($ident) { |
|
23 | 23 | $Spotter = new Spotter(); |
24 | 24 | if (!is_numeric(substr($ident, 0, 3))) |
25 | - { |
|
26 | - if (is_numeric(substr(substr($ident, 0, 3), -1, 1))) { |
|
27 | - $airline_icao = substr($ident, 0, 2); |
|
28 | - } elseif (is_numeric(substr(substr($ident, 0, 4), -1, 1))) { |
|
29 | - //$airline_icao = substr($ident, 0, 3); |
|
30 | - return $ident; |
|
31 | - } else return $ident; |
|
32 | - } else return $ident; |
|
33 | - if ($airline_icao == 'AF') { |
|
34 | - if (filter_var(substr($ident,2),FILTER_VALIDATE_INT,array("flags"=>FILTER_FLAG_ALLOW_OCTAL))) $icao = $ident; |
|
35 | - else $icao = 'AFR'.ltrim(substr($ident,2),'0'); |
|
36 | - } else { |
|
37 | - $identicao = $Spotter->getAllAirlineInfo($airline_icao); |
|
38 | - if (isset($identicao[0])) { |
|
39 | - $icao = $identicao[0]['icao'].ltrim(substr($ident,2),'0'); |
|
40 | - } else $icao = $ident; |
|
41 | - } |
|
42 | - return $icao; |
|
43 | - } |
|
25 | + { |
|
26 | + if (is_numeric(substr(substr($ident, 0, 3), -1, 1))) { |
|
27 | + $airline_icao = substr($ident, 0, 2); |
|
28 | + } elseif (is_numeric(substr(substr($ident, 0, 4), -1, 1))) { |
|
29 | + //$airline_icao = substr($ident, 0, 3); |
|
30 | + return $ident; |
|
31 | + } else return $ident; |
|
32 | + } else return $ident; |
|
33 | + if ($airline_icao == 'AF') { |
|
34 | + if (filter_var(substr($ident,2),FILTER_VALIDATE_INT,array("flags"=>FILTER_FLAG_ALLOW_OCTAL))) $icao = $ident; |
|
35 | + else $icao = 'AFR'.ltrim(substr($ident,2),'0'); |
|
36 | + } else { |
|
37 | + $identicao = $Spotter->getAllAirlineInfo($airline_icao); |
|
38 | + if (isset($identicao[0])) { |
|
39 | + $icao = $identicao[0]['icao'].ltrim(substr($ident,2),'0'); |
|
40 | + } else $icao = $ident; |
|
41 | + } |
|
42 | + return $icao; |
|
43 | + } |
|
44 | 44 | |
45 | 45 | |
46 | - public function getOperator($ident) { |
|
47 | - $query = "SELECT * FROM translation WHERE Operator = :ident LIMIT 1"; |
|
48 | - $query_values = array(':ident' => $ident); |
|
49 | - try { |
|
50 | - $sth = $this->db->prepare($query); |
|
51 | - $sth->execute($query_values); |
|
52 | - } catch(PDOException $e) { |
|
53 | - return "error : ".$e->getMessage(); |
|
54 | - } |
|
55 | - $row = $sth->fetch(PDO::FETCH_ASSOC); |
|
56 | - $sth->closeCursor(); |
|
57 | - if (count($row) > 0) { |
|
58 | - return $row['operator_correct']; |
|
59 | - } else return $ident; |
|
60 | - } |
|
46 | + public function getOperator($ident) { |
|
47 | + $query = "SELECT * FROM translation WHERE Operator = :ident LIMIT 1"; |
|
48 | + $query_values = array(':ident' => $ident); |
|
49 | + try { |
|
50 | + $sth = $this->db->prepare($query); |
|
51 | + $sth->execute($query_values); |
|
52 | + } catch(PDOException $e) { |
|
53 | + return "error : ".$e->getMessage(); |
|
54 | + } |
|
55 | + $row = $sth->fetch(PDO::FETCH_ASSOC); |
|
56 | + $sth->closeCursor(); |
|
57 | + if (count($row) > 0) { |
|
58 | + return $row['operator_correct']; |
|
59 | + } else return $ident; |
|
60 | + } |
|
61 | 61 | |
62 | - public function addOperator($ident,$correct_ident,$source) { |
|
63 | - $query = "INSERT INTO translation (Operator,Operator_correct,Source) VALUES (:ident,:correct_ident,:source)"; |
|
64 | - $query_values = array(':ident' => $ident,':correct_ident' => $correct_ident, ':source' => $source); |
|
65 | - try { |
|
66 | - $sth = $this->db->prepare($query); |
|
67 | - $sth->execute($query_values); |
|
68 | - } catch(PDOException $e) { |
|
69 | - return "error : ".$e->getMessage(); |
|
70 | - } |
|
71 | - } |
|
62 | + public function addOperator($ident,$correct_ident,$source) { |
|
63 | + $query = "INSERT INTO translation (Operator,Operator_correct,Source) VALUES (:ident,:correct_ident,:source)"; |
|
64 | + $query_values = array(':ident' => $ident,':correct_ident' => $correct_ident, ':source' => $source); |
|
65 | + try { |
|
66 | + $sth = $this->db->prepare($query); |
|
67 | + $sth->execute($query_values); |
|
68 | + } catch(PDOException $e) { |
|
69 | + return "error : ".$e->getMessage(); |
|
70 | + } |
|
71 | + } |
|
72 | 72 | |
73 | - public function updateOperator($ident,$correct_ident,$source) { |
|
74 | - $query = "UPDATE translation SET Operator_correct = :correct_ident,Source = :source WHERE Operator = :ident"; |
|
75 | - $query_values = array(':ident' => $ident,':correct_ident' => $correct_ident, ':source' => $source); |
|
76 | - try { |
|
77 | - $sth = $this->db->prepare($query); |
|
78 | - $sth->execute($query_values); |
|
79 | - } catch(PDOException $e) { |
|
80 | - return "error : ".$e->getMessage(); |
|
81 | - } |
|
82 | - } |
|
73 | + public function updateOperator($ident,$correct_ident,$source) { |
|
74 | + $query = "UPDATE translation SET Operator_correct = :correct_ident,Source = :source WHERE Operator = :ident"; |
|
75 | + $query_values = array(':ident' => $ident,':correct_ident' => $correct_ident, ':source' => $source); |
|
76 | + try { |
|
77 | + $sth = $this->db->prepare($query); |
|
78 | + $sth->execute($query_values); |
|
79 | + } catch(PDOException $e) { |
|
80 | + return "error : ".$e->getMessage(); |
|
81 | + } |
|
82 | + } |
|
83 | 83 | |
84 | - public function checkTranslation($ident,$web = false) { |
|
85 | - global $globalTranslationSources, $globalTranslationFetch; |
|
86 | - //if (!isset($globalTranslationSources)) $globalTranslationSources = array('planefinder'); |
|
87 | - $globalTranslationSources = array(); |
|
88 | - if (!isset($globalTranslationFetch)) $globalTranslationFetch = TRUE; |
|
89 | - //echo "Check Translation for ".$ident."..."; |
|
90 | - $correct = $this->getOperator($ident); |
|
91 | - if ($correct != '' && $correct != $ident) { |
|
92 | - //echo "Found in DB !\n"; |
|
93 | - return $correct; |
|
94 | - } /* |
|
84 | + public function checkTranslation($ident,$web = false) { |
|
85 | + global $globalTranslationSources, $globalTranslationFetch; |
|
86 | + //if (!isset($globalTranslationSources)) $globalTranslationSources = array('planefinder'); |
|
87 | + $globalTranslationSources = array(); |
|
88 | + if (!isset($globalTranslationFetch)) $globalTranslationFetch = TRUE; |
|
89 | + //echo "Check Translation for ".$ident."..."; |
|
90 | + $correct = $this->getOperator($ident); |
|
91 | + if ($correct != '' && $correct != $ident) { |
|
92 | + //echo "Found in DB !\n"; |
|
93 | + return $correct; |
|
94 | + } /* |
|
95 | 95 | elseif ($web && $globalTranslationFetch) { |
96 | 96 | if (! is_numeric(substr($ident,-4))) { |
97 | 97 | if (count($globalTranslationSources) > 0) { |
@@ -108,8 +108,8 @@ discard block |
||
108 | 108 | } |
109 | 109 | } |
110 | 110 | */ |
111 | - return $this->ident2icao($ident); |
|
112 | - } |
|
111 | + return $this->ident2icao($ident); |
|
112 | + } |
|
113 | 113 | |
114 | 114 | /* |
115 | 115 | function fromPlanefinder($icao) { |
@@ -118,6 +118,9 @@ discard block |
||
118 | 118 | ); |
119 | 119 | } |
120 | 120 | |
121 | + /** |
|
122 | + * @param boolean $force |
|
123 | + */ |
|
121 | 124 | static function geosInstalled($force = NULL) { |
122 | 125 | static $geos_installed = NULL; |
123 | 126 | if ($force !== NULL) $geos_installed = $force; |
@@ -222,6 +225,10 @@ discard block |
||
222 | 225 | |
223 | 226 | // Detect a format given a value. This function is meant to be SPEEDY. |
224 | 227 | // It could make a mistake in XML detection if you are mixing or using namespaces in weird ways (ie, KML inside an RSS feed) |
228 | + |
|
229 | + /** |
|
230 | + * @return string |
|
231 | + */ |
|
225 | 232 | static function detectFormat(&$input) { |
226 | 233 | $mem = fopen('php://memory', 'r+'); |
227 | 234 | fwrite($mem, $input, 11); // Write 11 bytes - we can detect the vast majority of formats in the first 11 bytes |
@@ -35,110 +35,110 @@ discard block |
||
35 | 35 | { |
36 | 36 | |
37 | 37 | static function version() { |
38 | - return '1.1'; |
|
38 | + return '1.1'; |
|
39 | 39 | } |
40 | 40 | |
41 | 41 | // geoPHP::load($data, $type, $other_args); |
42 | 42 | // if $data is an array, all passed in values will be combined into a single geometry |
43 | 43 | static function load() { |
44 | - $args = func_get_args(); |
|
44 | + $args = func_get_args(); |
|
45 | 45 | |
46 | - $data = array_shift($args); |
|
47 | - $type = array_shift($args); |
|
46 | + $data = array_shift($args); |
|
47 | + $type = array_shift($args); |
|
48 | 48 | |
49 | - $type_map = geoPHP::getAdapterMap(); |
|
49 | + $type_map = geoPHP::getAdapterMap(); |
|
50 | 50 | |
51 | - // Auto-detect type if needed |
|
52 | - if (!$type) { |
|
53 | - // If the user is trying to load a Geometry from a Geometry... Just pass it back |
|
54 | - if (is_object($data)) { |
|
55 | - if ($data instanceOf Geometry) return $data; |
|
56 | - } |
|
51 | + // Auto-detect type if needed |
|
52 | + if (!$type) { |
|
53 | + // If the user is trying to load a Geometry from a Geometry... Just pass it back |
|
54 | + if (is_object($data)) { |
|
55 | + if ($data instanceOf Geometry) return $data; |
|
56 | + } |
|
57 | 57 | |
58 | - $detected = geoPHP::detectFormat($data); |
|
59 | - if (!$detected) { |
|
60 | - return FALSE; |
|
61 | - } |
|
58 | + $detected = geoPHP::detectFormat($data); |
|
59 | + if (!$detected) { |
|
60 | + return FALSE; |
|
61 | + } |
|
62 | 62 | |
63 | - $format = explode(':', $detected); |
|
64 | - $type = array_shift($format); |
|
65 | - $args = $format; |
|
66 | - } |
|
67 | - |
|
68 | - $processor_type = $type_map[$type]; |
|
69 | - |
|
70 | - if (!$processor_type) { |
|
71 | - throw new exception('geoPHP could not find an adapter of type '.htmlentities($type)); |
|
72 | - exit; |
|
73 | - } |
|
74 | - |
|
75 | - $processor = new $processor_type(); |
|
76 | - |
|
77 | - // Data is not an array, just pass it normally |
|
78 | - if (!is_array($data)) { |
|
79 | - $result = call_user_func_array(array($processor, "read"), array_merge(array($data), $args)); |
|
80 | - } |
|
81 | - // Data is an array, combine all passed in items into a single geomtetry |
|
82 | - else { |
|
83 | - $geoms = array(); |
|
84 | - foreach ($data as $item) { |
|
85 | - $geoms[] = call_user_func_array(array($processor, "read"), array_merge(array($item), $args)); |
|
86 | - } |
|
87 | - $result = geoPHP::geometryReduce($geoms); |
|
88 | - } |
|
89 | - |
|
90 | - return $result; |
|
63 | + $format = explode(':', $detected); |
|
64 | + $type = array_shift($format); |
|
65 | + $args = $format; |
|
66 | + } |
|
67 | + |
|
68 | + $processor_type = $type_map[$type]; |
|
69 | + |
|
70 | + if (!$processor_type) { |
|
71 | + throw new exception('geoPHP could not find an adapter of type '.htmlentities($type)); |
|
72 | + exit; |
|
73 | + } |
|
74 | + |
|
75 | + $processor = new $processor_type(); |
|
76 | + |
|
77 | + // Data is not an array, just pass it normally |
|
78 | + if (!is_array($data)) { |
|
79 | + $result = call_user_func_array(array($processor, "read"), array_merge(array($data), $args)); |
|
80 | + } |
|
81 | + // Data is an array, combine all passed in items into a single geomtetry |
|
82 | + else { |
|
83 | + $geoms = array(); |
|
84 | + foreach ($data as $item) { |
|
85 | + $geoms[] = call_user_func_array(array($processor, "read"), array_merge(array($item), $args)); |
|
86 | + } |
|
87 | + $result = geoPHP::geometryReduce($geoms); |
|
88 | + } |
|
89 | + |
|
90 | + return $result; |
|
91 | 91 | } |
92 | 92 | |
93 | 93 | static function getAdapterMap() { |
94 | - return array ( |
|
95 | - 'wkt' => 'WKT', |
|
96 | - 'ewkt' => 'EWKT', |
|
97 | - 'wkb' => 'WKB', |
|
98 | - 'ewkb' => 'EWKB', |
|
99 | - 'json' => 'GeoJSON', |
|
100 | - 'geojson' => 'GeoJSON', |
|
101 | - 'kml' => 'KML', |
|
102 | - 'gpx' => 'GPX', |
|
103 | - 'georss' => 'GeoRSS', |
|
104 | - 'google_geocode' => 'GoogleGeocode', |
|
105 | - 'geohash' => 'GeoHash', |
|
106 | - ); |
|
94 | + return array ( |
|
95 | + 'wkt' => 'WKT', |
|
96 | + 'ewkt' => 'EWKT', |
|
97 | + 'wkb' => 'WKB', |
|
98 | + 'ewkb' => 'EWKB', |
|
99 | + 'json' => 'GeoJSON', |
|
100 | + 'geojson' => 'GeoJSON', |
|
101 | + 'kml' => 'KML', |
|
102 | + 'gpx' => 'GPX', |
|
103 | + 'georss' => 'GeoRSS', |
|
104 | + 'google_geocode' => 'GoogleGeocode', |
|
105 | + 'geohash' => 'GeoHash', |
|
106 | + ); |
|
107 | 107 | } |
108 | 108 | |
109 | 109 | static function geometryList() { |
110 | - return array( |
|
111 | - 'point' => 'Point', |
|
112 | - 'linestring' => 'LineString', |
|
113 | - 'polygon' => 'Polygon', |
|
114 | - 'multipoint' => 'MultiPoint', |
|
115 | - 'multilinestring' => 'MultiLineString', |
|
116 | - 'multipolygon' => 'MultiPolygon', |
|
117 | - 'geometrycollection' => 'GeometryCollection', |
|
118 | - ); |
|
110 | + return array( |
|
111 | + 'point' => 'Point', |
|
112 | + 'linestring' => 'LineString', |
|
113 | + 'polygon' => 'Polygon', |
|
114 | + 'multipoint' => 'MultiPoint', |
|
115 | + 'multilinestring' => 'MultiLineString', |
|
116 | + 'multipolygon' => 'MultiPolygon', |
|
117 | + 'geometrycollection' => 'GeometryCollection', |
|
118 | + ); |
|
119 | 119 | } |
120 | 120 | |
121 | 121 | static function geosInstalled($force = NULL) { |
122 | - static $geos_installed = NULL; |
|
123 | - if ($force !== NULL) $geos_installed = $force; |
|
124 | - if ($geos_installed !== NULL) { |
|
125 | - return $geos_installed; |
|
126 | - } |
|
127 | - $geos_installed = class_exists('GEOSGeometry'); |
|
128 | - return $geos_installed; |
|
122 | + static $geos_installed = NULL; |
|
123 | + if ($force !== NULL) $geos_installed = $force; |
|
124 | + if ($geos_installed !== NULL) { |
|
125 | + return $geos_installed; |
|
126 | + } |
|
127 | + $geos_installed = class_exists('GEOSGeometry'); |
|
128 | + return $geos_installed; |
|
129 | 129 | } |
130 | 130 | |
131 | 131 | static function geosToGeometry($geos) { |
132 | - if (!geoPHP::geosInstalled()) { |
|
133 | - return NULL; |
|
134 | - } |
|
135 | - $wkb_writer = new GEOSWKBWriter(); |
|
136 | - $wkb = $wkb_writer->writeHEX($geos); |
|
137 | - $geometry = geoPHP::load($wkb, 'wkb', TRUE); |
|
138 | - if ($geometry) { |
|
139 | - $geometry->setGeos($geos); |
|
140 | - return $geometry; |
|
141 | - } |
|
132 | + if (!geoPHP::geosInstalled()) { |
|
133 | + return NULL; |
|
134 | + } |
|
135 | + $wkb_writer = new GEOSWKBWriter(); |
|
136 | + $wkb = $wkb_writer->writeHEX($geos); |
|
137 | + $geometry = geoPHP::load($wkb, 'wkb', TRUE); |
|
138 | + if ($geometry) { |
|
139 | + $geometry->setGeos($geos); |
|
140 | + return $geometry; |
|
141 | + } |
|
142 | 142 | } |
143 | 143 | |
144 | 144 | // Reduce a geometry, or an array of geometries, into their 'lowest' available common geometry. |
@@ -146,155 +146,155 @@ discard block |
||
146 | 146 | // A multi-point containing a single point will return a point. |
147 | 147 | // An array of geometries can be passed and they will be compiled into a single geometry |
148 | 148 | static function geometryReduce($geometry) { |
149 | - // If it's an array of one, then just parse the one |
|
150 | - if (is_array($geometry)) { |
|
151 | - if (empty($geometry)) return FALSE; |
|
152 | - if (count($geometry) == 1) return geoPHP::geometryReduce(array_shift($geometry)); |
|
153 | - } |
|
154 | - |
|
155 | - // If the geometry cannot even theoretically be reduced more, then pass it back |
|
156 | - if (gettype($geometry) == 'object') { |
|
157 | - $passbacks = array('Point','LineString','Polygon'); |
|
158 | - if (in_array($geometry->geometryType(),$passbacks)) { |
|
159 | - return $geometry; |
|
160 | - } |
|
161 | - } |
|
162 | - |
|
163 | - // If it is a mutlti-geometry, check to see if it just has one member |
|
164 | - // If it does, then pass the member, if not, then just pass back the geometry |
|
165 | - if (gettype($geometry) == 'object') { |
|
166 | - $simple_collections = array('MultiPoint','MultiLineString','MultiPolygon'); |
|
167 | - if (in_array(get_class($geometry),$passbacks)) { |
|
168 | - $components = $geometry->getComponents(); |
|
169 | - if (count($components) == 1) { |
|
170 | - return $components[0]; |
|
171 | - } |
|
172 | - else { |
|
173 | - return $geometry; |
|
174 | - } |
|
175 | - } |
|
176 | - } |
|
177 | - |
|
178 | - // So now we either have an array of geometries, a GeometryCollection, or an array of GeometryCollections |
|
179 | - if (!is_array($geometry)) { |
|
180 | - $geometry = array($geometry); |
|
181 | - } |
|
182 | - |
|
183 | - $geometries = array(); |
|
184 | - $geom_types = array(); |
|
185 | - |
|
186 | - $collections = array('MultiPoint','MultiLineString','MultiPolygon','GeometryCollection'); |
|
187 | - |
|
188 | - foreach ($geometry as $item) { |
|
189 | - if ($item) { |
|
190 | - if (in_array(get_class($item), $collections)) { |
|
191 | - foreach ($item->getComponents() as $component) { |
|
192 | - $geometries[] = $component; |
|
193 | - $geom_types[] = $component->geometryType(); |
|
194 | - } |
|
195 | - } |
|
196 | - else { |
|
197 | - $geometries[] = $item; |
|
198 | - $geom_types[] = $item->geometryType(); |
|
199 | - } |
|
200 | - } |
|
201 | - } |
|
202 | - |
|
203 | - $geom_types = array_unique($geom_types); |
|
149 | + // If it's an array of one, then just parse the one |
|
150 | + if (is_array($geometry)) { |
|
151 | + if (empty($geometry)) return FALSE; |
|
152 | + if (count($geometry) == 1) return geoPHP::geometryReduce(array_shift($geometry)); |
|
153 | + } |
|
154 | + |
|
155 | + // If the geometry cannot even theoretically be reduced more, then pass it back |
|
156 | + if (gettype($geometry) == 'object') { |
|
157 | + $passbacks = array('Point','LineString','Polygon'); |
|
158 | + if (in_array($geometry->geometryType(),$passbacks)) { |
|
159 | + return $geometry; |
|
160 | + } |
|
161 | + } |
|
162 | + |
|
163 | + // If it is a mutlti-geometry, check to see if it just has one member |
|
164 | + // If it does, then pass the member, if not, then just pass back the geometry |
|
165 | + if (gettype($geometry) == 'object') { |
|
166 | + $simple_collections = array('MultiPoint','MultiLineString','MultiPolygon'); |
|
167 | + if (in_array(get_class($geometry),$passbacks)) { |
|
168 | + $components = $geometry->getComponents(); |
|
169 | + if (count($components) == 1) { |
|
170 | + return $components[0]; |
|
171 | + } |
|
172 | + else { |
|
173 | + return $geometry; |
|
174 | + } |
|
175 | + } |
|
176 | + } |
|
177 | + |
|
178 | + // So now we either have an array of geometries, a GeometryCollection, or an array of GeometryCollections |
|
179 | + if (!is_array($geometry)) { |
|
180 | + $geometry = array($geometry); |
|
181 | + } |
|
182 | + |
|
183 | + $geometries = array(); |
|
184 | + $geom_types = array(); |
|
185 | + |
|
186 | + $collections = array('MultiPoint','MultiLineString','MultiPolygon','GeometryCollection'); |
|
187 | + |
|
188 | + foreach ($geometry as $item) { |
|
189 | + if ($item) { |
|
190 | + if (in_array(get_class($item), $collections)) { |
|
191 | + foreach ($item->getComponents() as $component) { |
|
192 | + $geometries[] = $component; |
|
193 | + $geom_types[] = $component->geometryType(); |
|
194 | + } |
|
195 | + } |
|
196 | + else { |
|
197 | + $geometries[] = $item; |
|
198 | + $geom_types[] = $item->geometryType(); |
|
199 | + } |
|
200 | + } |
|
201 | + } |
|
202 | + |
|
203 | + $geom_types = array_unique($geom_types); |
|
204 | 204 | |
205 | - if (empty($geom_types)) { |
|
206 | - return FALSE; |
|
207 | - } |
|
208 | - |
|
209 | - if (count($geom_types) == 1) { |
|
210 | - if (count($geometries) == 1) { |
|
211 | - return $geometries[0]; |
|
212 | - } |
|
213 | - else { |
|
214 | - $class = 'Multi'.$geom_types[0]; |
|
215 | - return new $class($geometries); |
|
216 | - } |
|
217 | - } |
|
218 | - else { |
|
219 | - return new GeometryCollection($geometries); |
|
220 | - } |
|
205 | + if (empty($geom_types)) { |
|
206 | + return FALSE; |
|
207 | + } |
|
208 | + |
|
209 | + if (count($geom_types) == 1) { |
|
210 | + if (count($geometries) == 1) { |
|
211 | + return $geometries[0]; |
|
212 | + } |
|
213 | + else { |
|
214 | + $class = 'Multi'.$geom_types[0]; |
|
215 | + return new $class($geometries); |
|
216 | + } |
|
217 | + } |
|
218 | + else { |
|
219 | + return new GeometryCollection($geometries); |
|
220 | + } |
|
221 | 221 | } |
222 | 222 | |
223 | 223 | // Detect a format given a value. This function is meant to be SPEEDY. |
224 | 224 | // It could make a mistake in XML detection if you are mixing or using namespaces in weird ways (ie, KML inside an RSS feed) |
225 | 225 | static function detectFormat(&$input) { |
226 | - $mem = fopen('php://memory', 'r+'); |
|
227 | - fwrite($mem, $input, 11); // Write 11 bytes - we can detect the vast majority of formats in the first 11 bytes |
|
228 | - fseek($mem, 0); |
|
229 | - |
|
230 | - $bytes = unpack("c*", fread($mem, 11)); |
|
231 | - |
|
232 | - // If bytes is empty, then we were passed empty input |
|
233 | - if (empty($bytes)) return FALSE; |
|
234 | - |
|
235 | - // First char is a tab, space or carriage-return. trim it and try again |
|
236 | - if ($bytes[1] == 9 || $bytes[1] == 10 || $bytes[1] == 32) { |
|
237 | - return geoPHP::detectFormat(ltrim($input)); |
|
238 | - } |
|
239 | - |
|
240 | - // Detect WKB or EWKB -- first byte is 1 (little endian indicator) |
|
241 | - if ($bytes[1] == 1) { |
|
242 | - // If SRID byte is TRUE (1), it's EWKB |
|
243 | - if ($bytes[5]) return 'ewkb'; |
|
244 | - else return 'wkb'; |
|
245 | - } |
|
246 | - |
|
247 | - // Detect HEX encoded WKB or EWKB (PostGIS format) -- first byte is 48, second byte is 49 (hex '01' => first-byte = 1) |
|
248 | - if ($bytes[1] == 48 && $bytes[2] == 49) { |
|
249 | - // The shortest possible WKB string (LINESTRING EMPTY) is 18 hex-chars (9 encoded bytes) long |
|
250 | - // This differentiates it from a geohash, which is always shorter than 18 characters. |
|
251 | - if (strlen($input) >= 18) { |
|
252 | - //@@TODO: Differentiate between EWKB and WKB -- check hex-char 10 or 11 (SRID bool indicator at encoded byte 5) |
|
253 | - return 'ewkb:1'; |
|
254 | - } |
|
255 | - } |
|
256 | - |
|
257 | - // Detect GeoJSON - first char starts with { |
|
258 | - if ($bytes[1] == 123) { |
|
259 | - return 'json'; |
|
260 | - } |
|
261 | - |
|
262 | - // Detect EWKT - first char is S |
|
263 | - if ($bytes[1] == 83) { |
|
264 | - return 'ewkt'; |
|
265 | - } |
|
266 | - |
|
267 | - // Detect WKT - first char starts with P (80), L (76), M (77), or G (71) |
|
268 | - $wkt_chars = array(80, 76, 77, 71); |
|
269 | - if (in_array($bytes[1], $wkt_chars)) { |
|
270 | - return 'wkt'; |
|
271 | - } |
|
272 | - |
|
273 | - // Detect XML -- first char is < |
|
274 | - if ($bytes[1] == 60) { |
|
275 | - // grab the first 256 characters |
|
276 | - $string = substr($input, 0, 256); |
|
277 | - if (strpos($string, '<kml') !== FALSE) return 'kml'; |
|
278 | - if (strpos($string, '<coordinate') !== FALSE) return 'kml'; |
|
279 | - if (strpos($string, '<gpx') !== FALSE) return 'gpx'; |
|
280 | - if (strpos($string, '<georss') !== FALSE) return 'georss'; |
|
281 | - if (strpos($string, '<rss') !== FALSE) return 'georss'; |
|
282 | - if (strpos($string, '<feed') !== FALSE) return 'georss'; |
|
283 | - } |
|
284 | - |
|
285 | - // We need an 8 byte string for geohash and unpacked WKB / WKT |
|
286 | - fseek($mem, 0); |
|
287 | - $string = trim(fread($mem, 8)); |
|
288 | - |
|
289 | - // Detect geohash - geohash ONLY contains lowercase chars and numerics |
|
290 | - preg_match('/[a-z0-9]+/', $string, $matches); |
|
291 | - if ($matches[0] == $string) { |
|
292 | - return 'geohash'; |
|
293 | - } |
|
294 | - |
|
295 | - // What do you get when you cross an elephant with a rhino? |
|
296 | - // http://youtu.be/RCBn5J83Poc |
|
297 | - return FALSE; |
|
226 | + $mem = fopen('php://memory', 'r+'); |
|
227 | + fwrite($mem, $input, 11); // Write 11 bytes - we can detect the vast majority of formats in the first 11 bytes |
|
228 | + fseek($mem, 0); |
|
229 | + |
|
230 | + $bytes = unpack("c*", fread($mem, 11)); |
|
231 | + |
|
232 | + // If bytes is empty, then we were passed empty input |
|
233 | + if (empty($bytes)) return FALSE; |
|
234 | + |
|
235 | + // First char is a tab, space or carriage-return. trim it and try again |
|
236 | + if ($bytes[1] == 9 || $bytes[1] == 10 || $bytes[1] == 32) { |
|
237 | + return geoPHP::detectFormat(ltrim($input)); |
|
238 | + } |
|
239 | + |
|
240 | + // Detect WKB or EWKB -- first byte is 1 (little endian indicator) |
|
241 | + if ($bytes[1] == 1) { |
|
242 | + // If SRID byte is TRUE (1), it's EWKB |
|
243 | + if ($bytes[5]) return 'ewkb'; |
|
244 | + else return 'wkb'; |
|
245 | + } |
|
246 | + |
|
247 | + // Detect HEX encoded WKB or EWKB (PostGIS format) -- first byte is 48, second byte is 49 (hex '01' => first-byte = 1) |
|
248 | + if ($bytes[1] == 48 && $bytes[2] == 49) { |
|
249 | + // The shortest possible WKB string (LINESTRING EMPTY) is 18 hex-chars (9 encoded bytes) long |
|
250 | + // This differentiates it from a geohash, which is always shorter than 18 characters. |
|
251 | + if (strlen($input) >= 18) { |
|
252 | + //@@TODO: Differentiate between EWKB and WKB -- check hex-char 10 or 11 (SRID bool indicator at encoded byte 5) |
|
253 | + return 'ewkb:1'; |
|
254 | + } |
|
255 | + } |
|
256 | + |
|
257 | + // Detect GeoJSON - first char starts with { |
|
258 | + if ($bytes[1] == 123) { |
|
259 | + return 'json'; |
|
260 | + } |
|
261 | + |
|
262 | + // Detect EWKT - first char is S |
|
263 | + if ($bytes[1] == 83) { |
|
264 | + return 'ewkt'; |
|
265 | + } |
|
266 | + |
|
267 | + // Detect WKT - first char starts with P (80), L (76), M (77), or G (71) |
|
268 | + $wkt_chars = array(80, 76, 77, 71); |
|
269 | + if (in_array($bytes[1], $wkt_chars)) { |
|
270 | + return 'wkt'; |
|
271 | + } |
|
272 | + |
|
273 | + // Detect XML -- first char is < |
|
274 | + if ($bytes[1] == 60) { |
|
275 | + // grab the first 256 characters |
|
276 | + $string = substr($input, 0, 256); |
|
277 | + if (strpos($string, '<kml') !== FALSE) return 'kml'; |
|
278 | + if (strpos($string, '<coordinate') !== FALSE) return 'kml'; |
|
279 | + if (strpos($string, '<gpx') !== FALSE) return 'gpx'; |
|
280 | + if (strpos($string, '<georss') !== FALSE) return 'georss'; |
|
281 | + if (strpos($string, '<rss') !== FALSE) return 'georss'; |
|
282 | + if (strpos($string, '<feed') !== FALSE) return 'georss'; |
|
283 | + } |
|
284 | + |
|
285 | + // We need an 8 byte string for geohash and unpacked WKB / WKT |
|
286 | + fseek($mem, 0); |
|
287 | + $string = trim(fread($mem, 8)); |
|
288 | + |
|
289 | + // Detect geohash - geohash ONLY contains lowercase chars and numerics |
|
290 | + preg_match('/[a-z0-9]+/', $string, $matches); |
|
291 | + if ($matches[0] == $string) { |
|
292 | + return 'geohash'; |
|
293 | + } |
|
294 | + |
|
295 | + // What do you get when you cross an elephant with a rhino? |
|
296 | + // http://youtu.be/RCBn5J83Poc |
|
297 | + return FALSE; |
|
298 | 298 | } |
299 | 299 | |
300 | 300 | } |
@@ -113,7 +113,6 @@ discard block |
||
113 | 113 | * Serializes an object into a geojson string |
114 | 114 | * |
115 | 115 | * |
116 | - * @param Geometry $obj The object to serialize |
|
117 | 116 | * |
118 | 117 | * @return string The GeoJSON string |
119 | 118 | */ |
@@ -126,6 +125,9 @@ discard block |
||
126 | 125 | } |
127 | 126 | } |
128 | 127 | |
128 | + /** |
|
129 | + * @param Geometry $geometry |
|
130 | + */ |
|
129 | 131 | public function getArray($geometry) { |
130 | 132 | if ($geometry->getGeomType() == 'GeometryCollection') { |
131 | 133 | $component_array = array(); |
@@ -16,97 +16,97 @@ discard block |
||
16 | 16 | * @return object Geometry |
17 | 17 | */ |
18 | 18 | public function read($input) { |
19 | - if (is_string($input)) { |
|
20 | - $input = json_decode($input); |
|
21 | - } |
|
22 | - if (!is_object($input)) { |
|
23 | - throw new Exception('Invalid JSON'); |
|
24 | - } |
|
25 | - if (!is_string($input->type)) { |
|
26 | - throw new Exception('Invalid JSON'); |
|
27 | - } |
|
28 | - |
|
29 | - // Check to see if it's a FeatureCollection |
|
30 | - if ($input->type == 'FeatureCollection') { |
|
31 | - $geoms = array(); |
|
32 | - foreach ($input->features as $feature) { |
|
33 | - $geoms[] = $this->read($feature); |
|
34 | - } |
|
35 | - return geoPHP::geometryReduce($geoms); |
|
36 | - } |
|
37 | - |
|
38 | - // Check to see if it's a Feature |
|
39 | - if ($input->type == 'Feature') { |
|
40 | - return $this->read($input->geometry); |
|
41 | - } |
|
42 | - |
|
43 | - // It's a geometry - process it |
|
44 | - return $this->objToGeom($input); |
|
19 | + if (is_string($input)) { |
|
20 | + $input = json_decode($input); |
|
21 | + } |
|
22 | + if (!is_object($input)) { |
|
23 | + throw new Exception('Invalid JSON'); |
|
24 | + } |
|
25 | + if (!is_string($input->type)) { |
|
26 | + throw new Exception('Invalid JSON'); |
|
27 | + } |
|
28 | + |
|
29 | + // Check to see if it's a FeatureCollection |
|
30 | + if ($input->type == 'FeatureCollection') { |
|
31 | + $geoms = array(); |
|
32 | + foreach ($input->features as $feature) { |
|
33 | + $geoms[] = $this->read($feature); |
|
34 | + } |
|
35 | + return geoPHP::geometryReduce($geoms); |
|
36 | + } |
|
37 | + |
|
38 | + // Check to see if it's a Feature |
|
39 | + if ($input->type == 'Feature') { |
|
40 | + return $this->read($input->geometry); |
|
41 | + } |
|
42 | + |
|
43 | + // It's a geometry - process it |
|
44 | + return $this->objToGeom($input); |
|
45 | 45 | } |
46 | 46 | |
47 | 47 | private function objToGeom($obj) { |
48 | - $type = $obj->type; |
|
48 | + $type = $obj->type; |
|
49 | 49 | |
50 | - if ($type == 'GeometryCollection') { |
|
51 | - return $this->objToGeometryCollection($obj); |
|
52 | - } |
|
53 | - $method = 'arrayTo' . $type; |
|
54 | - return $this->$method($obj->coordinates); |
|
50 | + if ($type == 'GeometryCollection') { |
|
51 | + return $this->objToGeometryCollection($obj); |
|
52 | + } |
|
53 | + $method = 'arrayTo' . $type; |
|
54 | + return $this->$method($obj->coordinates); |
|
55 | 55 | } |
56 | 56 | |
57 | 57 | private function arrayToPoint($array) { |
58 | - return new Point($array[0], $array[1]); |
|
58 | + return new Point($array[0], $array[1]); |
|
59 | 59 | } |
60 | 60 | |
61 | 61 | private function arrayToLineString($array) { |
62 | - $points = array(); |
|
63 | - foreach ($array as $comp_array) { |
|
64 | - $points[] = $this->arrayToPoint($comp_array); |
|
65 | - } |
|
66 | - return new LineString($points); |
|
62 | + $points = array(); |
|
63 | + foreach ($array as $comp_array) { |
|
64 | + $points[] = $this->arrayToPoint($comp_array); |
|
65 | + } |
|
66 | + return new LineString($points); |
|
67 | 67 | } |
68 | 68 | |
69 | 69 | private function arrayToPolygon($array) { |
70 | - $lines = array(); |
|
71 | - foreach ($array as $comp_array) { |
|
72 | - $lines[] = $this->arrayToLineString($comp_array); |
|
73 | - } |
|
74 | - return new Polygon($lines); |
|
70 | + $lines = array(); |
|
71 | + foreach ($array as $comp_array) { |
|
72 | + $lines[] = $this->arrayToLineString($comp_array); |
|
73 | + } |
|
74 | + return new Polygon($lines); |
|
75 | 75 | } |
76 | 76 | |
77 | 77 | private function arrayToMultiPoint($array) { |
78 | - $points = array(); |
|
79 | - foreach ($array as $comp_array) { |
|
80 | - $points[] = $this->arrayToPoint($comp_array); |
|
81 | - } |
|
82 | - return new MultiPoint($points); |
|
78 | + $points = array(); |
|
79 | + foreach ($array as $comp_array) { |
|
80 | + $points[] = $this->arrayToPoint($comp_array); |
|
81 | + } |
|
82 | + return new MultiPoint($points); |
|
83 | 83 | } |
84 | 84 | |
85 | 85 | private function arrayToMultiLineString($array) { |
86 | - $lines = array(); |
|
87 | - foreach ($array as $comp_array) { |
|
88 | - $lines[] = $this->arrayToLineString($comp_array); |
|
89 | - } |
|
90 | - return new MultiLineString($lines); |
|
86 | + $lines = array(); |
|
87 | + foreach ($array as $comp_array) { |
|
88 | + $lines[] = $this->arrayToLineString($comp_array); |
|
89 | + } |
|
90 | + return new MultiLineString($lines); |
|
91 | 91 | } |
92 | 92 | |
93 | 93 | private function arrayToMultiPolygon($array) { |
94 | - $polys = array(); |
|
95 | - foreach ($array as $comp_array) { |
|
96 | - $polys[] = $this->arrayToPolygon($comp_array); |
|
97 | - } |
|
98 | - return new MultiPolygon($polys); |
|
94 | + $polys = array(); |
|
95 | + foreach ($array as $comp_array) { |
|
96 | + $polys[] = $this->arrayToPolygon($comp_array); |
|
97 | + } |
|
98 | + return new MultiPolygon($polys); |
|
99 | 99 | } |
100 | 100 | |
101 | 101 | private function objToGeometryCollection($obj) { |
102 | - $geoms = array(); |
|
103 | - if (empty($obj->geometries)) { |
|
104 | - throw new Exception('Invalid GeoJSON: GeometryCollection with no component geometries'); |
|
105 | - } |
|
106 | - foreach ($obj->geometries as $comp_object) { |
|
107 | - $geoms[] = $this->objToGeom($comp_object); |
|
108 | - } |
|
109 | - return new GeometryCollection($geoms); |
|
102 | + $geoms = array(); |
|
103 | + if (empty($obj->geometries)) { |
|
104 | + throw new Exception('Invalid GeoJSON: GeometryCollection with no component geometries'); |
|
105 | + } |
|
106 | + foreach ($obj->geometries as $comp_object) { |
|
107 | + $geoms[] = $this->objToGeom($comp_object); |
|
108 | + } |
|
109 | + return new GeometryCollection($geoms); |
|
110 | 110 | } |
111 | 111 | |
112 | 112 | /** |
@@ -118,32 +118,32 @@ discard block |
||
118 | 118 | * @return string The GeoJSON string |
119 | 119 | */ |
120 | 120 | public function write(Geometry $geometry, $return_array = FALSE) { |
121 | - if ($return_array) { |
|
122 | - return $this->getArray($geometry); |
|
123 | - } |
|
124 | - else { |
|
125 | - return json_encode($this->getArray($geometry)); |
|
126 | - } |
|
121 | + if ($return_array) { |
|
122 | + return $this->getArray($geometry); |
|
123 | + } |
|
124 | + else { |
|
125 | + return json_encode($this->getArray($geometry)); |
|
126 | + } |
|
127 | 127 | } |
128 | 128 | |
129 | 129 | public function getArray($geometry) { |
130 | - if ($geometry->getGeomType() == 'GeometryCollection') { |
|
131 | - $component_array = array(); |
|
132 | - foreach ($geometry->components as $component) { |
|
133 | - $component_array[] = array( |
|
134 | - 'type' => $component->geometryType(), |
|
135 | - 'coordinates' => $component->asArray(), |
|
136 | - ); |
|
137 | - } |
|
138 | - return array( |
|
139 | - 'type'=> 'GeometryCollection', |
|
140 | - 'geometries'=> $component_array, |
|
141 | - ); |
|
142 | - } |
|
143 | - else return array( |
|
144 | - 'type'=> $geometry->getGeomType(), |
|
145 | - 'coordinates'=> $geometry->asArray(), |
|
146 | - ); |
|
130 | + if ($geometry->getGeomType() == 'GeometryCollection') { |
|
131 | + $component_array = array(); |
|
132 | + foreach ($geometry->components as $component) { |
|
133 | + $component_array[] = array( |
|
134 | + 'type' => $component->geometryType(), |
|
135 | + 'coordinates' => $component->asArray(), |
|
136 | + ); |
|
137 | + } |
|
138 | + return array( |
|
139 | + 'type'=> 'GeometryCollection', |
|
140 | + 'geometries'=> $component_array, |
|
141 | + ); |
|
142 | + } |
|
143 | + else return array( |
|
144 | + 'type'=> $geometry->getGeomType(), |
|
145 | + 'coordinates'=> $geometry->asArray(), |
|
146 | + ); |
|
147 | 147 | } |
148 | 148 | } |
149 | 149 |