@@ -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(); |
@@ -4,24 +4,24 @@ discard block |
||
4 | 4 | |
5 | 5 | class create_db { |
6 | 6 | public static function import_file($filename) { |
7 | - $filename = filter_var($filename,FILTER_SANITIZE_STRING); |
|
7 | + $filename = filter_var($filename, FILTER_SANITIZE_STRING); |
|
8 | 8 | $Connection = new Connection(); |
9 | 9 | //Connection::$db->beginTransaction(); |
10 | 10 | $templine = ''; |
11 | - $handle = @fopen($filename,"r"); |
|
11 | + $handle = @fopen($filename, "r"); |
|
12 | 12 | if ($handle) { |
13 | 13 | //$lines = file($filename); |
14 | 14 | //foreach ($lines as $line) |
15 | - while (($line = fgets($handle,4096)) !== false) |
|
15 | + while (($line = fgets($handle, 4096)) !== false) |
|
16 | 16 | { |
17 | - if (substr($line,0,2) == '--' || $line == '') continue; |
|
17 | + if (substr($line, 0, 2) == '--' || $line == '') continue; |
|
18 | 18 | $templine .= $line; |
19 | - if (substr(trim($line), -1,1) == ';') |
|
19 | + if (substr(trim($line), -1, 1) == ';') |
|
20 | 20 | { |
21 | 21 | try { |
22 | 22 | $sth = $Connection->db->prepare($templine); |
23 | 23 | $sth->execute(); |
24 | - } catch(PDOException $e) { |
|
24 | + } catch (PDOException $e) { |
|
25 | 25 | return "error (import ".$filename.") : ".$e->getMessage()."\n"; |
26 | 26 | } |
27 | 27 | $templine = ''; |
@@ -38,27 +38,27 @@ discard block |
||
38 | 38 | $error = ''; |
39 | 39 | $dh = opendir($directory); |
40 | 40 | //foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($directory)) as $filename) |
41 | - while(false !== ($filename = readdir($dh))) |
|
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 | } |
47 | 47 | |
48 | - public static function create_database($root,$root_pass,$user,$pass,$db,$db_type,$host) { |
|
49 | - $root = filter_var($root,FILTER_SANITIZE_STRING); |
|
50 | - $root_pass = filter_var($root_pass,FILTER_SANITIZE_STRING); |
|
51 | - $user = filter_var($user,FILTER_SANITIZE_STRING); |
|
52 | - $password = filter_var($pass,FILTER_SANITIZE_STRING); |
|
53 | - $db = filter_var($db,FILTER_SANITIZE_STRING); |
|
54 | - $db_type = filter_var($db_type,FILTER_SANITIZE_STRING); |
|
55 | - $host = filter_var($host,FILTER_SANITIZE_STRING); |
|
48 | + public static function create_database($root, $root_pass, $user, $pass, $db, $db_type, $host) { |
|
49 | + $root = filter_var($root, FILTER_SANITIZE_STRING); |
|
50 | + $root_pass = filter_var($root_pass, FILTER_SANITIZE_STRING); |
|
51 | + $user = filter_var($user, FILTER_SANITIZE_STRING); |
|
52 | + $password = filter_var($pass, FILTER_SANITIZE_STRING); |
|
53 | + $db = filter_var($db, FILTER_SANITIZE_STRING); |
|
54 | + $db_type = filter_var($db_type, FILTER_SANITIZE_STRING); |
|
55 | + $host = filter_var($host, FILTER_SANITIZE_STRING); |
|
56 | 56 | // Dirty hack |
57 | 57 | if ($host != 'localhost' && $host != '127.0.0.1') { |
58 | 58 | $grantright = $_SERVER['SERVER_ADDR']; |
59 | 59 | } else $grantright = 'localhost'; |
60 | 60 | try { |
61 | - $dbh = new PDO($db_type.':host='.$host,$root,$root_pass); |
|
61 | + $dbh = new PDO($db_type.':host='.$host, $root, $root_pass); |
|
62 | 62 | $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); |
63 | 63 | if ($db_type == 'mysql') { |
64 | 64 | $dbh->exec('CREATE DATABASE IF NOT EXISTS `'.$db.'`;GRANT ALL ON `'.$db."`.* TO '".$user."'@'".$grantright."' IDENTIFIED BY '".$password."';FLUSH PRIVILEGES;"); |
@@ -68,7 +68,7 @@ discard block |
||
68 | 68 | $dbh->exec("CREATE USER ".$user." WITH PASSWORD '".$password."'; |
69 | 69 | GRANT ALL PRIVILEGES ON DATABASE ".$db." TO ".$user.";"); |
70 | 70 | } |
71 | - } catch(PDOException $e) { |
|
71 | + } catch (PDOException $e) { |
|
72 | 72 | $dbh = null; |
73 | 73 | return "error : ".$e->getMessage(); |
74 | 74 | } |
@@ -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; |
@@ -10,37 +10,37 @@ discard block |
||
10 | 10 | |
11 | 11 | # to document: CGIParams |
12 | 12 | |
13 | -function sparql_connect( $endpoint ) { return new sparql_connection( $endpoint ); } |
|
13 | +function sparql_connect($endpoint) { return new sparql_connection($endpoint); } |
|
14 | 14 | |
15 | -function sparql_ns( $short, $long, $db = null ) { return _sparql_a_connection( $db )->ns( $short, $long ); } |
|
16 | -function sparql_query( $sparql, $db = null ) { return _sparql_a_connection( $db )->query( $sparql ); } |
|
17 | -function sparql_errno( $db = null ) { return _sparql_a_connection( $db )->errno(); } |
|
18 | -function sparql_error( $db = null ) { return _sparql_a_connection( $db )->error(); } |
|
15 | +function sparql_ns($short, $long, $db = null) { return _sparql_a_connection($db)->ns($short, $long); } |
|
16 | +function sparql_query($sparql, $db = null) { return _sparql_a_connection($db)->query($sparql); } |
|
17 | +function sparql_errno($db = null) { return _sparql_a_connection($db)->errno(); } |
|
18 | +function sparql_error($db = null) { return _sparql_a_connection($db)->error(); } |
|
19 | 19 | |
20 | -function sparql_fetch_array( $result ) { return $result->fetch_array(); } |
|
21 | -function sparql_num_rows( $result ) { return $result->num_rows(); } |
|
22 | -function sparql_field_array( $result ) { return $result->field_array(); } |
|
23 | -function sparql_field_name( $result, $i ) { return $result->field_name( $i ); } |
|
20 | +function sparql_fetch_array($result) { return $result->fetch_array(); } |
|
21 | +function sparql_num_rows($result) { return $result->num_rows(); } |
|
22 | +function sparql_field_array($result) { return $result->field_array(); } |
|
23 | +function sparql_field_name($result, $i) { return $result->field_name($i); } |
|
24 | 24 | |
25 | -function sparql_fetch_all( $result ) { return $result->fetch_all(); } |
|
25 | +function sparql_fetch_all($result) { return $result->fetch_all(); } |
|
26 | 26 | |
27 | -function sparql_get( $endpoint, $sparql ) |
|
27 | +function sparql_get($endpoint, $sparql) |
|
28 | 28 | { |
29 | - $db = sparql_connect( $endpoint ); |
|
30 | - if( !$db ) { return; } |
|
31 | - $result = $db->query( $sparql ); |
|
32 | - if( !$result ) { return; } |
|
29 | + $db = sparql_connect($endpoint); |
|
30 | + if (!$db) { return; } |
|
31 | + $result = $db->query($sparql); |
|
32 | + if (!$result) { return; } |
|
33 | 33 | return $result->fetch_all(); |
34 | 34 | } |
35 | 35 | |
36 | -function _sparql_a_connection( $db ) |
|
36 | +function _sparql_a_connection($db) |
|
37 | 37 | { |
38 | 38 | global $sparql_last_connection; |
39 | - if( !isset( $db ) ) |
|
39 | + if (!isset($db)) |
|
40 | 40 | { |
41 | - if( !isset( $sparql_last_connection ) ) |
|
41 | + if (!isset($sparql_last_connection)) |
|
42 | 42 | { |
43 | - print( "No currect SPARQL connection (connection) in play!" ); |
|
43 | + print("No currect SPARQL connection (connection) in play!"); |
|
44 | 44 | return; |
45 | 45 | } |
46 | 46 | $db = $sparql_last_connection; |
@@ -62,14 +62,14 @@ discard block |
||
62 | 62 | var $params = null; |
63 | 63 | # capabilities are either true, false or null if not yet tested. |
64 | 64 | |
65 | - function __construct( $endpoint ) |
|
65 | + function __construct($endpoint) |
|
66 | 66 | { |
67 | 67 | $this->endpoint = $endpoint; |
68 | 68 | global $sparql_last_connection; |
69 | 69 | $sparql_last_connection = $this; |
70 | 70 | } |
71 | 71 | |
72 | - function ns( $short, $long ) |
|
72 | + function ns($short, $long) |
|
73 | 73 | { |
74 | 74 | $this->ns[$short] = $long; |
75 | 75 | } |
@@ -77,77 +77,77 @@ discard block |
||
77 | 77 | function errno() { return $this->errno; } |
78 | 78 | function error() { return $this->error; } |
79 | 79 | |
80 | - function cgiParams( $params = null ) |
|
80 | + function cgiParams($params = null) |
|
81 | 81 | { |
82 | - if( $params === null ) { return $this->params; } |
|
83 | - if( $params === "" ) { $this->params = null; return; } |
|
82 | + if ($params === null) { return $this->params; } |
|
83 | + if ($params === "") { $this->params = null; return; } |
|
84 | 84 | $this->params = $params; |
85 | 85 | } |
86 | 86 | |
87 | - function query( $query, $timeout=null ) |
|
87 | + function query($query, $timeout = null) |
|
88 | 88 | { |
89 | 89 | $prefixes = ""; |
90 | - foreach( $this->ns as $k=>$v ) |
|
90 | + foreach ($this->ns as $k=>$v) |
|
91 | 91 | { |
92 | 92 | $prefixes .= "PREFIX $k: <$v>\n"; |
93 | 93 | } |
94 | - $output = $this->dispatchQuery( $prefixes.$query, $timeout ); |
|
95 | - if( $this->errno ) { return; } |
|
94 | + $output = $this->dispatchQuery($prefixes.$query, $timeout); |
|
95 | + if ($this->errno) { return; } |
|
96 | 96 | $parser = new xx_xml($output, 'contents'); |
97 | - if( $parser->error() ) |
|
97 | + if ($parser->error()) |
|
98 | 98 | { |
99 | 99 | $this->errno = -1; # to not clash with CURLOPT return; } |
100 | 100 | $this->error = $parser->error(); |
101 | 101 | return; |
102 | 102 | } |
103 | - return new sparql_result( $this, $parser->rows, $parser->fields ); |
|
103 | + return new sparql_result($this, $parser->rows, $parser->fields); |
|
104 | 104 | } |
105 | 105 | |
106 | - function alive( $timeout=3 ) |
|
106 | + function alive($timeout = 3) |
|
107 | 107 | { |
108 | - $result = $this->query( "SELECT * WHERE { ?s ?p ?o } LIMIT 1", $timeout ); |
|
108 | + $result = $this->query("SELECT * WHERE { ?s ?p ?o } LIMIT 1", $timeout); |
|
109 | 109 | |
110 | - if( $this->errno ) { return false; } |
|
110 | + if ($this->errno) { return false; } |
|
111 | 111 | |
112 | 112 | return true; |
113 | 113 | } |
114 | 114 | |
115 | - function dispatchQuery( $sparql, $timeout=null ) |
|
115 | + function dispatchQuery($sparql, $timeout = null) |
|
116 | 116 | { |
117 | - $url = $this->endpoint."?query=".urlencode( $sparql ); |
|
118 | - if( $this->params !== null ) |
|
117 | + $url = $this->endpoint."?query=".urlencode($sparql); |
|
118 | + if ($this->params !== null) |
|
119 | 119 | { |
120 | 120 | $url .= "&".$this->params; |
121 | 121 | } |
122 | - if( $this->debug ) { print "<div class='debug'><a href='".htmlspecialchars($url)."'>".htmlspecialchars($prefixes.$query)."</a></div>\n"; } |
|
122 | + if ($this->debug) { print "<div class='debug'><a href='".htmlspecialchars($url)."'>".htmlspecialchars($prefixes.$query)."</a></div>\n"; } |
|
123 | 123 | $this->errno = null; |
124 | 124 | $this->error = null; |
125 | 125 | $ch = curl_init($url); |
126 | 126 | #curl_setopt($ch, CURLOPT_HEADER, 1); |
127 | - if( $timeout !== null ) |
|
127 | + if ($timeout !== null) |
|
128 | 128 | { |
129 | - curl_setopt($ch, CURLOPT_TIMEOUT, $timeout ); |
|
129 | + curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); |
|
130 | 130 | } |
131 | 131 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); |
132 | - curl_setopt($ch, CURLOPT_HTTPHEADER,array ( |
|
132 | + curl_setopt($ch, CURLOPT_HTTPHEADER, array( |
|
133 | 133 | "Accept: application/sparql-results+xml" |
134 | 134 | )); |
135 | 135 | |
136 | 136 | $output = curl_exec($ch); |
137 | 137 | $info = curl_getinfo($ch); |
138 | - if(curl_errno($ch)) |
|
138 | + if (curl_errno($ch)) |
|
139 | 139 | { |
140 | - $this->errno = curl_errno( $ch ); |
|
141 | - $this->error = 'Curl error: ' . curl_error($ch); |
|
140 | + $this->errno = curl_errno($ch); |
|
141 | + $this->error = 'Curl error: '.curl_error($ch); |
|
142 | 142 | return; |
143 | 143 | } |
144 | - if( $output === '' ) |
|
144 | + if ($output === '') |
|
145 | 145 | { |
146 | 146 | $this->errno = "-1"; |
147 | 147 | $this->error = 'URL returned no data'; |
148 | 148 | return; |
149 | 149 | } |
150 | - if( $info['http_code'] != 200) |
|
150 | + if ($info['http_code'] != 200) |
|
151 | 151 | { |
152 | 152 | $this->errno = $info['http_code']; |
153 | 153 | $this->error = 'Bad response, '.$info['http_code'].': '.$output; |
@@ -179,13 +179,13 @@ discard block |
||
179 | 179 | |
180 | 180 | var $caps_cache; |
181 | 181 | var $caps_anysubject; |
182 | - function capabilityCache( $filename, $dba_type='db4' ) |
|
182 | + function capabilityCache($filename, $dba_type = 'db4') |
|
183 | 183 | { |
184 | - $this->caps_cache = dba_open($filename, "c", $dba_type ); |
|
184 | + $this->caps_cache = dba_open($filename, "c", $dba_type); |
|
185 | 185 | } |
186 | 186 | function capabilityCodes() |
187 | 187 | { |
188 | - return array_keys( $this->caps_desc ); |
|
188 | + return array_keys($this->caps_desc); |
|
189 | 189 | } |
190 | 190 | function capabilityDescription($code) |
191 | 191 | { |
@@ -194,19 +194,19 @@ discard block |
||
194 | 194 | |
195 | 195 | # return true if the endpoint supports a capability |
196 | 196 | # nb. returns false if connecion isn't authoriased to use the feature, eg LOAD |
197 | - function supports( $code ) |
|
197 | + function supports($code) |
|
198 | 198 | { |
199 | - if( isset( $this->caps[$code] ) ) { return $this->caps[$code]; } |
|
199 | + if (isset($this->caps[$code])) { return $this->caps[$code]; } |
|
200 | 200 | $was_cached = false; |
201 | - if( isset( $this->caps_cache ) ) |
|
201 | + if (isset($this->caps_cache)) |
|
202 | 202 | { |
203 | 203 | $CACHE_TIMEOUT_SECONDS = 7*24*60*60; |
204 | 204 | $db_key = $this->endpoint.";".$code; |
205 | - $db_val = dba_fetch( $db_key, $this->caps_cache ); |
|
206 | - if( $db_val !== false ) |
|
205 | + $db_val = dba_fetch($db_key, $this->caps_cache); |
|
206 | + if ($db_val !== false) |
|
207 | 207 | { |
208 | - list( $result, $when ) = preg_split( '/;/', $db_val ); |
|
209 | - if( $when + $CACHE_TIMEOUT_SECONDS > time() ) |
|
208 | + list($result, $when) = preg_split('/;/', $db_val); |
|
209 | + if ($when + $CACHE_TIMEOUT_SECONDS > time()) |
|
210 | 210 | { |
211 | 211 | return $result; |
212 | 212 | } |
@@ -215,26 +215,26 @@ discard block |
||
215 | 215 | } |
216 | 216 | $r = null; |
217 | 217 | |
218 | - if( $code == "select" ) { $r = $this->test_select(); } |
|
219 | - elseif( $code == "constant_as" ) { $r = $this->test_constant_as(); } |
|
220 | - elseif( $code == "math_as" ) { $r = $this->test_math_as(); } |
|
221 | - elseif( $code == "count" ) { $r = $this->test_count(); } |
|
222 | - elseif( $code == "max" ) { $r = $this->test_max(); } |
|
223 | - elseif( $code == "load" ) { $r = $this->test_load(); } |
|
224 | - elseif( $code == "sample" ) { $r = $this->test_sample(); } |
|
218 | + if ($code == "select") { $r = $this->test_select(); } |
|
219 | + elseif ($code == "constant_as") { $r = $this->test_constant_as(); } |
|
220 | + elseif ($code == "math_as") { $r = $this->test_math_as(); } |
|
221 | + elseif ($code == "count") { $r = $this->test_count(); } |
|
222 | + elseif ($code == "max") { $r = $this->test_max(); } |
|
223 | + elseif ($code == "load") { $r = $this->test_load(); } |
|
224 | + elseif ($code == "sample") { $r = $this->test_sample(); } |
|
225 | 225 | else { print "<p>Unknown capability code: '$code'</p>"; return false; } |
226 | 226 | $this->caps[$code] = $r; |
227 | - if( isset( $this->caps_cache ) ) |
|
227 | + if (isset($this->caps_cache)) |
|
228 | 228 | { |
229 | 229 | $db_key = $this->endpoint.";".$code; |
230 | 230 | $db_val = $r.";".time(); |
231 | - if( $was_cached ) |
|
231 | + if ($was_cached) |
|
232 | 232 | { |
233 | - dba_replace( $db_key, $db_val, $this->caps_cache ); |
|
233 | + dba_replace($db_key, $db_val, $this->caps_cache); |
|
234 | 234 | } |
235 | 235 | else |
236 | 236 | { |
237 | - dba_insert( $db_key, $db_val, $this->caps_cache ); |
|
237 | + dba_insert($db_key, $db_val, $this->caps_cache); |
|
238 | 238 | } |
239 | 239 | } |
240 | 240 | return $r; |
@@ -242,11 +242,11 @@ discard block |
||
242 | 242 | |
243 | 243 | function anySubject() |
244 | 244 | { |
245 | - if( !isset( $this->caps_anysubject ) ) |
|
245 | + if (!isset($this->caps_anysubject)) |
|
246 | 246 | { |
247 | 247 | $results = $this->query( |
248 | 248 | "SELECT * WHERE { ?s ?p ?o } LIMIT 1" ); |
249 | - if( sizeof($results)) |
|
249 | + if (sizeof($results)) |
|
250 | 250 | { |
251 | 251 | $row = $results->fetch_array(); |
252 | 252 | $this->caps_anysubject = $row["s"]; |
@@ -260,7 +260,7 @@ discard block |
||
260 | 260 | { |
261 | 261 | $output = $this->dispatchQuery( |
262 | 262 | "SELECT ?s ?p ?o WHERE { ?s ?p ?o } LIMIT 1" ); |
263 | - return !isset( $this->errno ); |
|
263 | + return !isset($this->errno); |
|
264 | 264 | } |
265 | 265 | |
266 | 266 | # return true if the endpoint supports AS |
@@ -268,7 +268,7 @@ discard block |
||
268 | 268 | { |
269 | 269 | $output = $this->dispatchQuery( |
270 | 270 | "SELECT (1+2 AS ?bar) WHERE { ?s ?p ?o } LIMIT 1" ); |
271 | - return !isset( $this->errno ); |
|
271 | + return !isset($this->errno); |
|
272 | 272 | } |
273 | 273 | |
274 | 274 | # return true if the endpoint supports AS |
@@ -276,7 +276,7 @@ discard block |
||
276 | 276 | { |
277 | 277 | $output = $this->dispatchQuery( |
278 | 278 | "SELECT (\"foo\" AS ?bar) WHERE { ?s ?p ?o } LIMIT 1" ); |
279 | - return !isset( $this->errno ); |
|
279 | + return !isset($this->errno); |
|
280 | 280 | } |
281 | 281 | |
282 | 282 | # return true if the endpoint supports SELECT (COUNT(?x) as ?n) ... GROUP BY |
@@ -284,35 +284,35 @@ discard block |
||
284 | 284 | { |
285 | 285 | # assumes at least one rdf:type predicate |
286 | 286 | $s = $this->anySubject(); |
287 | - if( !isset($s) ) { return false; } |
|
287 | + if (!isset($s)) { return false; } |
|
288 | 288 | $output = $this->dispatchQuery( |
289 | 289 | "SELECT (COUNT(?p) AS ?n) ?o WHERE { <$s> ?p ?o } GROUP BY ?o" ); |
290 | - return !isset( $this->errno ); |
|
290 | + return !isset($this->errno); |
|
291 | 291 | } |
292 | 292 | |
293 | 293 | function test_max() |
294 | 294 | { |
295 | 295 | $s = $this->anySubject(); |
296 | - if( !isset($s) ) { return false; } |
|
296 | + if (!isset($s)) { return false; } |
|
297 | 297 | $output = $this->dispatchQuery( |
298 | 298 | "SELECT (MAX(?p) AS ?max) ?o WHERE { <$s> ?p ?o } GROUP BY ?o" ); |
299 | - return !isset( $this->errno ); |
|
299 | + return !isset($this->errno); |
|
300 | 300 | } |
301 | 301 | |
302 | 302 | function test_sample() |
303 | 303 | { |
304 | 304 | $s = $this->anySubject(); |
305 | - if( !isset($s) ) { return false; } |
|
305 | + if (!isset($s)) { return false; } |
|
306 | 306 | $output = $this->dispatchQuery( |
307 | 307 | "SELECT (SAMPLE(?p) AS ?sam) ?o WHERE { <$s> ?p ?o } GROUP BY ?o" ); |
308 | - return !isset( $this->errno ); |
|
308 | + return !isset($this->errno); |
|
309 | 309 | } |
310 | 310 | |
311 | 311 | function test_load() |
312 | 312 | { |
313 | 313 | $output = $this->dispatchQuery( |
314 | 314 | "LOAD <http://graphite.ecs.soton.ac.uk/sparqllib/examples/loadtest.rdf>" ); |
315 | - return !isset( $this->errno ); |
|
315 | + return !isset($this->errno); |
|
316 | 316 | } |
317 | 317 | |
318 | 318 | |
@@ -324,7 +324,7 @@ discard block |
||
324 | 324 | var $fields; |
325 | 325 | var $db; |
326 | 326 | var $i = 0; |
327 | - function __construct( $db, $rows, $fields ) |
|
327 | + function __construct($db, $rows, $fields) |
|
328 | 328 | { |
329 | 329 | $this->rows = $rows; |
330 | 330 | $this->fields = $fields; |
@@ -333,17 +333,17 @@ discard block |
||
333 | 333 | |
334 | 334 | function fetch_array() |
335 | 335 | { |
336 | - if( !@$this->rows[$this->i] ) { return; } |
|
336 | + if (!@$this->rows[$this->i]) { return; } |
|
337 | 337 | $r = array(); |
338 | - foreach( $this->rows[$this->i++] as $k=>$v ) |
|
338 | + foreach ($this->rows[$this->i++] as $k=>$v) |
|
339 | 339 | { |
340 | 340 | $r[$k] = $v["value"]; |
341 | 341 | $r["$k.type"] = $v["type"]; |
342 | - if( isset( $v["language"] ) ) |
|
342 | + if (isset($v["language"])) |
|
343 | 343 | { |
344 | 344 | $r["$k.language"] = $v["language"]; |
345 | 345 | } |
346 | - if( isset( $v["datatype"] ) ) |
|
346 | + if (isset($v["datatype"])) |
|
347 | 347 | { |
348 | 348 | $r["$k.datatype"] = $v["datatype"]; |
349 | 349 | } |
@@ -355,16 +355,16 @@ discard block |
||
355 | 355 | { |
356 | 356 | $r = new sparql_results(); |
357 | 357 | $r->fields = $this->fields; |
358 | - foreach( $this->rows as $i=>$row ) |
|
358 | + foreach ($this->rows as $i=>$row) |
|
359 | 359 | { |
360 | - $r []= $this->fetch_array(); |
|
360 | + $r [] = $this->fetch_array(); |
|
361 | 361 | } |
362 | 362 | return $r; |
363 | 363 | } |
364 | 364 | |
365 | 365 | function num_rows() |
366 | 366 | { |
367 | - return sizeof( $this->rows ); |
|
367 | + return sizeof($this->rows); |
|
368 | 368 | } |
369 | 369 | |
370 | 370 | function field_array() |
@@ -400,7 +400,7 @@ discard block |
||
400 | 400 | var $type; |
401 | 401 | |
402 | 402 | // function with the default parameter value |
403 | - function xx_xml($url='http://www.opocot.com', $type='url') { |
|
403 | + function xx_xml($url = 'http://www.opocot.com', $type = 'url') { |
|
404 | 404 | $this->type = $type; |
405 | 405 | $this->url = $url; |
406 | 406 | $this->parse(); |
@@ -414,7 +414,7 @@ discard block |
||
414 | 414 | $this->rows = array(); |
415 | 415 | $this->fields = array(); |
416 | 416 | $data = ''; |
417 | - $this->parser = xml_parser_create ("UTF-8"); |
|
417 | + $this->parser = xml_parser_create("UTF-8"); |
|
418 | 418 | xml_set_object($this->parser, $this); |
419 | 419 | xml_set_element_handler($this->parser, 'startXML', 'endXML'); |
420 | 420 | xml_set_character_data_handler($this->parser, 'charXML'); |
@@ -439,9 +439,9 @@ discard block |
||
439 | 439 | } else if ($this->type == 'contents') { |
440 | 440 | // Now we can pass the contents, maybe if you want |
441 | 441 | // to use CURL, SOCK or other method. |
442 | - $lines = explode("\n",$this->url); |
|
442 | + $lines = explode("\n", $this->url); |
|
443 | 443 | foreach ($lines as $val) { |
444 | - $data = $val . "\n"; |
|
444 | + $data = $val."\n"; |
|
445 | 445 | if (!xml_parse($this->parser, $data)) { |
446 | 446 | $this->error = $data."\n".sprintf('XML error at line %d column %d', |
447 | 447 | xml_get_current_line_number($this->parser), |
@@ -450,7 +450,7 @@ discard block |
||
450 | 450 | } |
451 | 451 | } |
452 | 452 | } |
453 | - if( !$this->looks_legit ) |
|
453 | + if (!$this->looks_legit) |
|
454 | 454 | { |
455 | 455 | $this->error = "Didn't even see a sparql element, is this really an endpoint?"; |
456 | 456 | } |
@@ -458,53 +458,53 @@ discard block |
||
458 | 458 | |
459 | 459 | function startXML($parser, $name, $attr) |
460 | 460 | { |
461 | - if( $name == "sparql" ) { $this->looks_legit = true; } |
|
462 | - if( $name == "result" ) |
|
461 | + if ($name == "sparql") { $this->looks_legit = true; } |
|
462 | + if ($name == "result") |
|
463 | 463 | { |
464 | 464 | $this->result = array(); |
465 | 465 | } |
466 | - if( $name == "binding" ) |
|
466 | + if ($name == "binding") |
|
467 | 467 | { |
468 | 468 | $this->part = $attr["name"]; |
469 | 469 | } |
470 | - if( $name == "uri" || $name == "bnode" ) |
|
470 | + if ($name == "uri" || $name == "bnode") |
|
471 | 471 | { |
472 | 472 | $this->part_type = $name; |
473 | 473 | $this->chars = ""; |
474 | 474 | } |
475 | - if( $name == "literal" ) |
|
475 | + if ($name == "literal") |
|
476 | 476 | { |
477 | 477 | $this->part_type = "literal"; |
478 | - if( isset( $attr["datatype"] ) ) |
|
478 | + if (isset($attr["datatype"])) |
|
479 | 479 | { |
480 | 480 | $this->part_datatype = $attr["datatype"]; |
481 | 481 | } |
482 | - if( isset( $attr["xml:lang"] ) ) |
|
482 | + if (isset($attr["xml:lang"])) |
|
483 | 483 | { |
484 | 484 | $this->part_lang = $attr["xml:lang"]; |
485 | 485 | } |
486 | 486 | $this->chars = ""; |
487 | 487 | } |
488 | - if( $name == "variable" ) |
|
488 | + if ($name == "variable") |
|
489 | 489 | { |
490 | 490 | $this->fields[] = $attr["name"]; |
491 | 491 | } |
492 | 492 | } |
493 | 493 | |
494 | - function endXML($parser, $name) { |
|
495 | - if( $name == "result" ) |
|
494 | + function endXML($parser, $name) { |
|
495 | + if ($name == "result") |
|
496 | 496 | { |
497 | 497 | $this->rows[] = $this->result; |
498 | 498 | $this->result = array(); |
499 | 499 | } |
500 | - if( $name == "uri" || $name == "bnode" || $name == "literal" ) |
|
500 | + if ($name == "uri" || $name == "bnode" || $name == "literal") |
|
501 | 501 | { |
502 | - $this->result[$this->part] = array( "type"=>$name, "value"=>$this->chars ); |
|
503 | - if( isset( $this->part_lang ) ) |
|
502 | + $this->result[$this->part] = array("type"=>$name, "value"=>$this->chars); |
|
503 | + if (isset($this->part_lang)) |
|
504 | 504 | { |
505 | 505 | $this->result[$this->part]["lang"] = $this->part_lang; |
506 | 506 | } |
507 | - if( isset( $this->part_datatype ) ) |
|
507 | + if (isset($this->part_datatype)) |
|
508 | 508 | { |
509 | 509 | $this->result[$this->part]["datatype"] = $this->part_datatype; |
510 | 510 | } |
@@ -513,7 +513,7 @@ discard block |
||
513 | 513 | } |
514 | 514 | } |
515 | 515 | |
516 | - function charXML($parser, $data) { |
|
516 | + function charXML($parser, $data) { |
|
517 | 517 | @$this->chars .= $data; |
518 | 518 | } |
519 | 519 | |
@@ -527,28 +527,28 @@ discard block |
||
527 | 527 | function render_table() |
528 | 528 | { |
529 | 529 | $html = "<table class='sparql-results'><tr>"; |
530 | - foreach( $this->fields as $i=>$field ) |
|
530 | + foreach ($this->fields as $i=>$field) |
|
531 | 531 | { |
532 | 532 | $html .= "<th>?$field</th>"; |
533 | 533 | } |
534 | 534 | $html .= "</tr>"; |
535 | - foreach( $this as $row ) |
|
535 | + foreach ($this as $row) |
|
536 | 536 | { |
537 | - $html.="<tr>"; |
|
538 | - foreach( $row as $cell ) |
|
537 | + $html .= "<tr>"; |
|
538 | + foreach ($row as $cell) |
|
539 | 539 | { |
540 | - $html .= "<td>".htmlspecialchars( $cell )."</td>"; |
|
540 | + $html .= "<td>".htmlspecialchars($cell)."</td>"; |
|
541 | 541 | } |
542 | - $html.="</tr>"; |
|
542 | + $html .= "</tr>"; |
|
543 | 543 | } |
544 | - $html.="</table> |
|
544 | + $html .= "</table> |
|
545 | 545 | <style> |
546 | 546 | table.sparql-results { border-collapse: collapse; } |
547 | 547 | table.sparql-results tr td { border: solid 1px #000 ; padding:4px;vertical-align:top} |
548 | 548 | table.sparql-results tr th { border: solid 1px #000 ; padding:4px;vertical-align:top ; background-color:#eee;} |
549 | 549 | </style> |
550 | 550 | "; |
551 | - return $html;exit; |
|
551 | + return $html; exit; |
|
552 | 552 | } |
553 | 553 | |
554 | 554 | } |
@@ -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,8 +1,7 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | class aprs { |
3 | 3 | private function urshift($n, $s) { |
4 | - return ($n >= 0) ? ($n >> $s) : |
|
5 | - (($n & 0x7fffffff) >> $s) | |
|
4 | + return ($n >= 0) ? ($n >> $s) : (($n&0x7fffffff) >> $s)| |
|
6 | 5 | (0x40000000 >> ($s - 1)); |
7 | 6 | } |
8 | 7 | |
@@ -14,7 +13,7 @@ discard block |
||
14 | 13 | //$split_input = str_split($input); |
15 | 14 | |
16 | 15 | /* Find the end of header checking for NULL bytes while doing it. */ |
17 | - $splitpos = strpos($input,':'); |
|
16 | + $splitpos = strpos($input, ':'); |
|
18 | 17 | |
19 | 18 | /* Check that end was found and body has at least one byte. */ |
20 | 19 | if ($splitpos == 0 || $splitpos + 1 == $input_len || $splitpos === FALSE) { |
@@ -23,28 +22,28 @@ discard block |
||
23 | 22 | } |
24 | 23 | |
25 | 24 | /* Save header and body. */ |
26 | - $body = substr($input,$splitpos+1,$input_len); |
|
25 | + $body = substr($input, $splitpos + 1, $input_len); |
|
27 | 26 | $body_len = strlen($body); |
28 | - $header = substr($input,0,$splitpos); |
|
27 | + $header = substr($input, 0, $splitpos); |
|
29 | 28 | //$header_len = strlen($header); |
30 | 29 | if ($debug) echo 'header : '.$header."\n"; |
31 | 30 | |
32 | 31 | /* Parse source, target and path. */ |
33 | 32 | //FLRDF0A52>APRS,qAS,LSTB |
34 | - if (preg_match('/^([A-Z0-9\\-]{1,9})>(.*)$/',$header,$matches)) { |
|
33 | + if (preg_match('/^([A-Z0-9\\-]{1,9})>(.*)$/', $header, $matches)) { |
|
35 | 34 | $ident = $matches[1]; |
36 | 35 | $all_elements = $matches[2]; |
37 | 36 | if ($debug) echo 'ident : '.$ident."\n"; |
38 | 37 | $result['ident'] = $ident; |
39 | 38 | } else return false; |
40 | - $elements = explode(',',$all_elements); |
|
39 | + $elements = explode(',', $all_elements); |
|
41 | 40 | $source = end($elements); |
42 | 41 | $result['source'] = $source; |
43 | 42 | foreach ($elements as $element) { |
44 | - if (preg_match('/^([a-zA-Z0-9-]{1,9})([*]?)$/',$element)) { |
|
43 | + if (preg_match('/^([a-zA-Z0-9-]{1,9})([*]?)$/', $element)) { |
|
45 | 44 | //echo "ok"; |
46 | 45 | if ($element == 'TCPIP*') return false; |
47 | - } elseif (!preg_match('/^([0-9A-F]{32})$/',$element)) { |
|
46 | + } elseif (!preg_match('/^([0-9A-F]{32})$/', $element)) { |
|
48 | 47 | return false; |
49 | 48 | } |
50 | 49 | /* |
@@ -56,8 +55,8 @@ discard block |
||
56 | 55 | */ |
57 | 56 | } |
58 | 57 | // Check for Timestamp |
59 | - $body_parse = substr($body,1); |
|
60 | - if (preg_match('/^([0-9]{2})([0-9]{2})([0-9]{2})([zh\\/])/',$body_parse,$matches)) { |
|
58 | + $body_parse = substr($body, 1); |
|
59 | + if (preg_match('/^([0-9]{2})([0-9]{2})([0-9]{2})([zh\\/])/', $body_parse, $matches)) { |
|
61 | 60 | $timestamp = $matches[0]; |
62 | 61 | if ($matches[4] == 'h') { |
63 | 62 | $timestamp = strtotime($matches[1].':'.$matches[2].':'.$matches[3]); |
@@ -70,11 +69,11 @@ discard block |
||
70 | 69 | // This work or not ? |
71 | 70 | $timestamp = strtotime($matches[1].' '.$matches[2].':'.$matches[3]); |
72 | 71 | } |
73 | - $body_parse = substr($body_parse,7); |
|
72 | + $body_parse = substr($body_parse, 7); |
|
74 | 73 | $result['timestamp'] = $timestamp; |
75 | 74 | } |
76 | 75 | 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)) { |
|
76 | + 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 | 77 | // 4658.70N/00707.78Ez |
79 | 78 | //print_r(str_split($body_parse)); |
80 | 79 | |
@@ -99,8 +98,8 @@ discard block |
||
99 | 98 | */ |
100 | 99 | $latitude = $lat + floatval($lat_min)/60; |
101 | 100 | $longitude = $lon + floatval($lon_min)/60; |
102 | - if ($sind == 'S') $latitude = 0-$latitude; |
|
103 | - if ($wind == 'W') $longitude = 0-$longitude; |
|
101 | + if ($sind == 'S') $latitude = 0 - $latitude; |
|
102 | + if ($wind == 'W') $longitude = 0 - $longitude; |
|
104 | 103 | $result['latitude'] = $latitude; |
105 | 104 | $result['longitude'] = $longitude; |
106 | 105 | } |
@@ -108,17 +107,17 @@ discard block |
||
108 | 107 | $body_split = str_split($body_parse); |
109 | 108 | $symbol_code = $body_split[18]; |
110 | 109 | if ($symbol_code != '_') { |
111 | - $body_parse = substr($body_parse,19); |
|
110 | + $body_parse = substr($body_parse, 19); |
|
112 | 111 | $body_parse_len = strlen($body_parse); |
113 | 112 | if ($body_parse_len >= 7) { |
114 | 113 | |
115 | - if (preg_match('/^([0-9\\. ]{3})\\/([0-9\\. ]{3})/',$body_parse)) { |
|
116 | - $course = substr($body_parse,0,3); |
|
114 | + if (preg_match('/^([0-9\\. ]{3})\\/([0-9\\. ]{3})/', $body_parse)) { |
|
115 | + $course = substr($body_parse, 0, 3); |
|
117 | 116 | $tmp_s = intval($course); |
118 | 117 | if ($tmp_s >= 1 && $tmp_s <= 360) $result['course'] = intval($course); |
119 | - $speed = substr($body_parse,4,3); |
|
118 | + $speed = substr($body_parse, 4, 3); |
|
120 | 119 | $result['speed'] = round($speed*1.852); |
121 | - $body_parse = substr($body_parse,7); |
|
120 | + $body_parse = substr($body_parse, 7); |
|
122 | 121 | } |
123 | 122 | // Check PHGR, PHG, RNG |
124 | 123 | } |
@@ -128,10 +127,10 @@ discard block |
||
128 | 127 | } |
129 | 128 | */ |
130 | 129 | if (strlen($body_parse) > 0) { |
131 | - if (preg_match('/\\/A=(-[0-9]{5}|[0-9]{6})/',$body_parse,$matches)) { |
|
130 | + if (preg_match('/\\/A=(-[0-9]{5}|[0-9]{6})/', $body_parse, $matches)) { |
|
132 | 131 | $altitude = intval($matches[1]); |
133 | 132 | $result['altitude'] = round($altitude*0.3048); |
134 | - $body_parse = substr($body_parse,strlen($matches[0])+1); |
|
133 | + $body_parse = substr($body_parse, strlen($matches[0]) + 1); |
|
135 | 134 | } |
136 | 135 | } |
137 | 136 | |
@@ -142,34 +141,34 @@ discard block |
||
142 | 141 | } |
143 | 142 | */ |
144 | 143 | // DAO |
145 | - if (preg_match('/^!([0-9A-Z]{3})/',$body_parse,$matches)) { |
|
144 | + if (preg_match('/^!([0-9A-Z]{3})/', $body_parse, $matches)) { |
|
146 | 145 | $dao = $matches[1]; |
147 | - if (preg_match('/^([A-Z])([0-9]{2})/',$dao)) { |
|
146 | + if (preg_match('/^([A-Z])([0-9]{2})/', $dao)) { |
|
148 | 147 | $dao_split = str_split($dao); |
149 | - $lat_off = (($dao_split[1])-48.0)*0.001/60.0; |
|
150 | - $lon_off = (($dao_split[2])-48.0)*0.001/60.0; |
|
148 | + $lat_off = (($dao_split[1]) - 48.0)*0.001/60.0; |
|
149 | + $lon_off = (($dao_split[2]) - 48.0)*0.001/60.0; |
|
151 | 150 | |
152 | 151 | if ($result['latitude'] < 0) $result['latitude'] -= $lat_off; |
153 | 152 | else $result['latitude'] += $lat_off; |
154 | 153 | if ($result['longitude'] < 0) $result['longitude'] -= $lon_off; |
155 | 154 | else $result['longitude'] += $lon_off; |
156 | 155 | } |
157 | - $body_parse = substr($body_parse,6); |
|
156 | + $body_parse = substr($body_parse, 6); |
|
158 | 157 | } |
159 | 158 | |
160 | 159 | // OGN comment |
161 | 160 | // echo "Before OGN : ".$body_parse."\n"; |
162 | - if (preg_match('/^id([0-9A-F]{8}) ([+-])([0-9]{3,4})fpm ([+-])([0-9.]{3,4})rot (.*)$/',$body_parse,$matches)) { |
|
161 | + if (preg_match('/^id([0-9A-F]{8}) ([+-])([0-9]{3,4})fpm ([+-])([0-9.]{3,4})rot (.*)$/', $body_parse, $matches)) { |
|
163 | 162 | $id = $matches[1]; |
164 | 163 | //$mode = substr($id,0,2); |
165 | - $address = substr($id,2); |
|
164 | + $address = substr($id, 2); |
|
166 | 165 | //print_r($matches); |
167 | - $addressType = (intval(substr($id,0,2),16))&3; |
|
166 | + $addressType = (intval(substr($id, 0, 2), 16))&3; |
|
168 | 167 | if ($addressType == 0) $result['addresstype'] = "RANDOM"; |
169 | 168 | elseif ($addressType == 1) $result['addresstype'] = "ICAO"; |
170 | 169 | elseif ($addressType == 2) $result['addresstype'] = "FLARM"; |
171 | 170 | elseif ($addressType == 3) $result['addresstype'] = "OGN"; |
172 | - $aircraftType = $this->urshift(((intval(substr($id,0,2),16)) & 0b1111100),2); |
|
171 | + $aircraftType = $this->urshift(((intval(substr($id, 0, 2), 16))&0b1111100), 2); |
|
173 | 172 | $result['aircrafttype_code'] = $aircraftType; |
174 | 173 | if ($aircraftType == 0) $result['aircrafttype'] = "UNKNOWN"; |
175 | 174 | elseif ($aircraftType == 1) $result['aircrafttype'] = "GLIDER"; |
@@ -186,7 +185,7 @@ discard block |
||
186 | 185 | elseif ($aircraftType == 12) $result['aircrafttype'] = "AIRSHIP"; |
187 | 186 | elseif ($aircraftType == 13) $result['aircrafttype'] = "UAV"; |
188 | 187 | elseif ($aircraftType == 15) $result['aircrafttype'] = "STATIC_OBJECT"; |
189 | - $stealth = (intval(substr($id,0,2), 16) & 0b10000000) != 0; |
|
188 | + $stealth = (intval(substr($id, 0, 2), 16)&0b10000000) != 0; |
|
190 | 189 | $result['stealth'] = $stealth; |
191 | 190 | $result['address'] = $address; |
192 | 191 | } |
@@ -195,40 +194,40 @@ discard block |
||
195 | 194 | $result['comment'] = $body_parse; |
196 | 195 | } else { |
197 | 196 | // parse weather |
198 | - $body_parse = substr($body_parse,19); |
|
197 | + $body_parse = substr($body_parse, 19); |
|
199 | 198 | //$body_parse_len = strlen($body_parse); |
200 | 199 | |
201 | - if (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})g([0-9 \\.]+)t(-{0,1}[0-9 \\.]+)/',$body_parse,$matches)) { |
|
200 | + if (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})g([0-9 \\.]+)t(-{0,1}[0-9 \\.]+)/', $body_parse, $matches)) { |
|
202 | 201 | $result['wind_dir'] = $matches[1]; |
203 | - $result['wind_speed'] = round($matches[2]*1.60934,1); |
|
204 | - $result['wind_gust'] = round($matches[3]*1.60934,1); |
|
205 | - $result['temp'] = round(5/9*(($matches[4])-32),1); |
|
206 | - $body_parse = substr($body_parse,strlen($matches[0])+1); |
|
207 | - } elseif (preg_match('/^_{0,1}c([0-9 \\.\\-]{3})s([0-9 \\.]{3})g([0-9 \\.]+)t(-{0,1}[0-9 \\.]+)/',$body_parse,$matches)) { |
|
202 | + $result['wind_speed'] = round($matches[2]*1.60934, 1); |
|
203 | + $result['wind_gust'] = round($matches[3]*1.60934, 1); |
|
204 | + $result['temp'] = round(5/9*(($matches[4]) - 32), 1); |
|
205 | + $body_parse = substr($body_parse, strlen($matches[0]) + 1); |
|
206 | + } elseif (preg_match('/^_{0,1}c([0-9 \\.\\-]{3})s([0-9 \\.]{3})g([0-9 \\.]+)t(-{0,1}[0-9 \\.]+)/', $body_parse, $matches)) { |
|
208 | 207 | $result['wind_dir'] = $matches[1]; |
209 | - $result['wind_speed'] = round($matches[2]*1.60934,1); |
|
210 | - $result['wind_gust'] = round($matches[3]*1.60934,1); |
|
211 | - $result['temp'] = round(5/9*(($matches[4])-32),1); |
|
212 | - $body_parse = substr($body_parse,strlen($matches[0])+1); |
|
213 | - } elseif (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})t(-{0,1}[0-9 \\.]+)/',$body_parse,$matches)) { |
|
208 | + $result['wind_speed'] = round($matches[2]*1.60934, 1); |
|
209 | + $result['wind_gust'] = round($matches[3]*1.60934, 1); |
|
210 | + $result['temp'] = round(5/9*(($matches[4]) - 32), 1); |
|
211 | + $body_parse = substr($body_parse, strlen($matches[0]) + 1); |
|
212 | + } elseif (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})t(-{0,1}[0-9 \\.]+)/', $body_parse, $matches)) { |
|
214 | 213 | $result['wind_dir'] = $matches[1]; |
215 | - $result['wind_speed'] = round($matches[2]*1.60934,1); |
|
216 | - $result['wind_gust'] = round($matches[3]*1.60934,1); |
|
217 | - $body_parse = substr($body_parse,strlen($matches[0])+1); |
|
218 | - } elseif (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})g([0-9 \\.]+)/',$body_parse,$matches)) { |
|
214 | + $result['wind_speed'] = round($matches[2]*1.60934, 1); |
|
215 | + $result['wind_gust'] = round($matches[3]*1.60934, 1); |
|
216 | + $body_parse = substr($body_parse, strlen($matches[0]) + 1); |
|
217 | + } elseif (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})g([0-9 \\.]+)/', $body_parse, $matches)) { |
|
219 | 218 | $result['wind_dir'] = $matches[1]; |
220 | - $result['wind_speed'] = round($matches[2]*1.60934,1); |
|
221 | - $result['wind_gust'] = round($matches[3]*1.60934,1); |
|
222 | - $body_parse = substr($body_parse,strlen($matches[0])+1); |
|
219 | + $result['wind_speed'] = round($matches[2]*1.60934, 1); |
|
220 | + $result['wind_gust'] = round($matches[3]*1.60934, 1); |
|
221 | + $body_parse = substr($body_parse, strlen($matches[0]) + 1); |
|
223 | 222 | } |
224 | - if (!isset($result['temp']) && strlen($body_parse) > 0 && preg_match('/^g([0-9]+)t(-?[0-9 \\.]{1,3})/',$body_parse,$matches)) { |
|
225 | - $result['temp'] = round(5/9*(($matches[1])-32),1); |
|
223 | + if (!isset($result['temp']) && strlen($body_parse) > 0 && preg_match('/^g([0-9]+)t(-?[0-9 \\.]{1,3})/', $body_parse, $matches)) { |
|
224 | + $result['temp'] = round(5/9*(($matches[1]) - 32), 1); |
|
226 | 225 | } |
227 | 226 | } |
228 | 227 | } |
229 | 228 | } |
230 | - if (isset($result['latitude'])) $result['latitude'] = round($result['latitude'],4); |
|
231 | - if (isset($result['longitude'])) $result['longitude'] = round($result['longitude'],4); |
|
229 | + if (isset($result['latitude'])) $result['latitude'] = round($result['latitude'], 4); |
|
230 | + if (isset($result['longitude'])) $result['longitude'] = round($result['longitude'], 4); |
|
232 | 231 | //print_r($result); |
233 | 232 | return $result; |
234 | 233 | } |
@@ -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 | { |
@@ -24,54 +24,54 @@ discard block |
||
24 | 24 | } |
25 | 25 | |
26 | 26 | class Language { |
27 | - public $all_languages = array('ar_SA' => array('العَرَبِيَّةُ', 'ar', 'arabic'), |
|
28 | - 'bg_BG' => array('Български', 'bg', 'bulgarian'), |
|
29 | - 'id_ID' => array('Bahasa Indonesia', 'id', 'indonesian'), |
|
30 | - 'ms_MY' => array('Bahasa Melayu', 'ms', 'malay'), |
|
31 | - 'ca_ES' => array('Català', 'ca', 'catalan'), // ca_CA |
|
32 | - 'cs_CZ' => array('Čeština', 'cs', 'czech'), |
|
33 | - 'de_DE' => array('Deutsch', 'de', 'german'), |
|
34 | - 'da_DK' => array('Dansk', 'da', 'danish') , // dk_DK |
|
35 | - 'et_EE' => array('Eesti', 'et', 'estonian'), // ee_ET |
|
36 | - 'en_GB' => array('English', 'en', 'english'), |
|
37 | - 'en_US' => array('English (US)', 'en', 'english'), |
|
38 | - 'es_AR' => array('Español (Argentina)', 'es', 'spanish'), |
|
39 | - 'es_CO' => array('Español (Colombia)', 'es', 'spanish'), |
|
40 | - 'es_ES' => array('Español (España)', 'es', 'spanish'), |
|
41 | - 'es_419' => array('Español (América Latina)', 'es', 'spanish'), |
|
42 | - 'es_MX' => array('Español (Mexico)', 'es', 'spanish'), |
|
43 | - 'es_VE' => array('Español (Venezuela)', 'es', 'spanish'), |
|
44 | - 'eu_ES' => array('Euskara', 'en', 'basque'), |
|
45 | - 'fr_FR' => array('Français', 'fr', 'french'), |
|
46 | - 'gl_ES' => array('Galego', 'gl', 'galician'), |
|
47 | - 'el_GR' => array('Ελληνικά', 'el', 'greek'), // el_EL |
|
48 | - 'he_IL' => array('עברית', 'he', 'hebrew'), // he_HE |
|
49 | - 'hr_HR' => array('Hrvatski', 'hr', 'croatian'), |
|
50 | - 'hu_HU' => array('Magyar', 'hu', 'hungarian'), |
|
51 | - 'it_IT' => array('Italiano', 'it', 'italian'), |
|
52 | - 'lv_LV' => array('Latviešu', 'lv', 'latvian'), |
|
53 | - 'lt_LT' => array('Lietuvių', 'lt', 'lithuanian'), |
|
54 | - 'nl_NL' => array('Nederlands', 'nl', 'dutch'), |
|
55 | - 'nb_NO' => array('Norsk (Bokmål)', 'nb', 'norwegian'), // no_NB |
|
56 | - 'nn_NO' => array('Norsk (Nynorsk)', 'nn', 'norwegian'), // no_NN |
|
57 | - 'fa_IR' => array('فارسی', 'fa', 'persian'), |
|
58 | - 'pl_PL' => array('Polski', 'pl', 'polish'), |
|
59 | - 'pt_PT' => array('Português', 'pt', 'portuguese'), |
|
60 | - 'pt_BR' => array('Português do Brasil', 'pt', 'brazilian portuguese'), |
|
61 | - 'ro_RO' => array('Română', 'en', 'romanian'), |
|
62 | - 'ru_RU' => array('Pусский', 'ru', 'russian'), |
|
63 | - 'sk_SK' => array('Slovenčina', 'sk', 'slovak'), |
|
64 | - 'sl_SI' => array('Slovenščina', 'sl', 'slovenian slovene'), |
|
65 | - 'sr_RS' => array('Srpski', 'sr', 'serbian'), |
|
66 | - 'fi_FI' => array('Suomi', 'fi', 'finish'), |
|
67 | - 'sv_SE' => array('Svenska', 'sv', 'swedish'), |
|
68 | - 'vi_VN' => array('Tiếng Việt', 'vi', 'vietnamese'), |
|
69 | - 'th_TH' => array('ภาษาไทย', 'th', 'thai'), |
|
70 | - 'tr_TR' => array('Türkçe', 'tr', 'turkish'), |
|
71 | - 'uk_UA' => array('Українська', 'en', 'ukrainian'), // ua_UA |
|
72 | - 'ja_JP' => array('日本語', 'ja', 'japanese'), |
|
73 | - 'zh_CN' => array('简体中文', 'zh', 'chinese'), |
|
74 | - 'zh_TW' => array('繁體中文', 'zh', 'chinese') |
|
27 | + public $all_languages = array('ar_SA' => array('العَرَبِيَّةُ', 'ar', 'arabic'), |
|
28 | + 'bg_BG' => array('Български', 'bg', 'bulgarian'), |
|
29 | + 'id_ID' => array('Bahasa Indonesia', 'id', 'indonesian'), |
|
30 | + 'ms_MY' => array('Bahasa Melayu', 'ms', 'malay'), |
|
31 | + 'ca_ES' => array('Català', 'ca', 'catalan'), // ca_CA |
|
32 | + 'cs_CZ' => array('Čeština', 'cs', 'czech'), |
|
33 | + 'de_DE' => array('Deutsch', 'de', 'german'), |
|
34 | + 'da_DK' => array('Dansk', 'da', 'danish'), // dk_DK |
|
35 | + 'et_EE' => array('Eesti', 'et', 'estonian'), // ee_ET |
|
36 | + 'en_GB' => array('English', 'en', 'english'), |
|
37 | + 'en_US' => array('English (US)', 'en', 'english'), |
|
38 | + 'es_AR' => array('Español (Argentina)', 'es', 'spanish'), |
|
39 | + 'es_CO' => array('Español (Colombia)', 'es', 'spanish'), |
|
40 | + 'es_ES' => array('Español (España)', 'es', 'spanish'), |
|
41 | + 'es_419' => array('Español (América Latina)', 'es', 'spanish'), |
|
42 | + 'es_MX' => array('Español (Mexico)', 'es', 'spanish'), |
|
43 | + 'es_VE' => array('Español (Venezuela)', 'es', 'spanish'), |
|
44 | + 'eu_ES' => array('Euskara', 'en', 'basque'), |
|
45 | + 'fr_FR' => array('Français', 'fr', 'french'), |
|
46 | + 'gl_ES' => array('Galego', 'gl', 'galician'), |
|
47 | + 'el_GR' => array('Ελληνικά', 'el', 'greek'), // el_EL |
|
48 | + 'he_IL' => array('עברית', 'he', 'hebrew'), // he_HE |
|
49 | + 'hr_HR' => array('Hrvatski', 'hr', 'croatian'), |
|
50 | + 'hu_HU' => array('Magyar', 'hu', 'hungarian'), |
|
51 | + 'it_IT' => array('Italiano', 'it', 'italian'), |
|
52 | + 'lv_LV' => array('Latviešu', 'lv', 'latvian'), |
|
53 | + 'lt_LT' => array('Lietuvių', 'lt', 'lithuanian'), |
|
54 | + 'nl_NL' => array('Nederlands', 'nl', 'dutch'), |
|
55 | + 'nb_NO' => array('Norsk (Bokmål)', 'nb', 'norwegian'), // no_NB |
|
56 | + 'nn_NO' => array('Norsk (Nynorsk)', 'nn', 'norwegian'), // no_NN |
|
57 | + 'fa_IR' => array('فارسی', 'fa', 'persian'), |
|
58 | + 'pl_PL' => array('Polski', 'pl', 'polish'), |
|
59 | + 'pt_PT' => array('Português', 'pt', 'portuguese'), |
|
60 | + 'pt_BR' => array('Português do Brasil', 'pt', 'brazilian portuguese'), |
|
61 | + 'ro_RO' => array('Română', 'en', 'romanian'), |
|
62 | + 'ru_RU' => array('Pусский', 'ru', 'russian'), |
|
63 | + 'sk_SK' => array('Slovenčina', 'sk', 'slovak'), |
|
64 | + 'sl_SI' => array('Slovenščina', 'sl', 'slovenian slovene'), |
|
65 | + 'sr_RS' => array('Srpski', 'sr', 'serbian'), |
|
66 | + 'fi_FI' => array('Suomi', 'fi', 'finish'), |
|
67 | + 'sv_SE' => array('Svenska', 'sv', 'swedish'), |
|
68 | + 'vi_VN' => array('Tiếng Việt', 'vi', 'vietnamese'), |
|
69 | + 'th_TH' => array('ภาษาไทย', 'th', 'thai'), |
|
70 | + 'tr_TR' => array('Türkçe', 'tr', 'turkish'), |
|
71 | + 'uk_UA' => array('Українська', 'en', 'ukrainian'), // ua_UA |
|
72 | + 'ja_JP' => array('日本語', 'ja', 'japanese'), |
|
73 | + 'zh_CN' => array('简体中文', 'zh', 'chinese'), |
|
74 | + 'zh_TW' => array('繁體中文', 'zh', 'chinese') |
|
75 | 75 | ); |
76 | 76 | |
77 | 77 | /** |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | |
100 | 100 | public function getLocale($locale) |
101 | 101 | { |
102 | - return array($locale,$this->all_languages[$locale][1],$this->all_languages[$locale][2],$locale.'.utf8',$locale.'.UTF8'); |
|
102 | + return array($locale, $this->all_languages[$locale][1], $this->all_languages[$locale][2], $locale.'.utf8', $locale.'.UTF8'); |
|
103 | 103 | } |
104 | 104 | |
105 | 105 | /** |
@@ -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, |
@@ -6,83 +6,83 @@ discard block |
||
6 | 6 | // Not yet finished, no CRC checks |
7 | 7 | //echo $buffer."\n"; |
8 | 8 | $data = array(); |
9 | - $typehex = substr($buffer,0,1); |
|
10 | - if ($typehex == '*' || $typehex == ':') $hex = substr($buffer,1,-1); |
|
11 | - elseif ($typehex == '@' || $typehex == '%') $hex = substr($buffer,13,-13); |
|
12 | - else $hex = substr($buffer,1,-1); |
|
13 | - $bin = gmp_strval( gmp_init($hex,16), 2); |
|
9 | + $typehex = substr($buffer, 0, 1); |
|
10 | + if ($typehex == '*' || $typehex == ':') $hex = substr($buffer, 1, -1); |
|
11 | + elseif ($typehex == '@' || $typehex == '%') $hex = substr($buffer, 13, -13); |
|
12 | + else $hex = substr($buffer, 1, -1); |
|
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); |
|
16 | + $df = intval(substr($bin, 0, 5), 2); |
|
17 | 17 | //$ca = intval(substr($bin,5,3),2); |
18 | 18 | // Only support DF17 for now |
19 | 19 | //if ($df == 17 || ($df == 18 && ($ca == 0 || $ca == 1 || $ca == 6))) { |
20 | - if (($df == 17 || $df == 18) && ($this->parityCheck($hex,$bin) || $typehex == '@')) { |
|
21 | - $icao = substr($hex,2,6); |
|
20 | + if (($df == 17 || $df == 18) && ($this->parityCheck($hex, $bin) || $typehex == '@')) { |
|
21 | + $icao = substr($hex, 2, 6); |
|
22 | 22 | $data['hex'] = $icao; |
23 | - $tc = intval(substr($bin,32,5),2); |
|
23 | + $tc = intval(substr($bin, 32, 5), 2); |
|
24 | 24 | if ($tc >= 1 && $tc <= 4) { |
25 | 25 | //callsign |
26 | - $csbin = substr($bin,40,56); |
|
26 | + $csbin = substr($bin, 40, 56); |
|
27 | 27 | $charset = str_split('#ABCDEFGHIJKLMNOPQRSTUVWXYZ#####_###############0123456789######'); |
28 | 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); |
|
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 | 39 | $callsign = $cs; |
40 | 40 | $data['ident'] = $callsign; |
41 | 41 | } elseif ($tc >= 9 && $tc <= 18) { |
42 | 42 | // Check Q-bit |
43 | - $q = substr($bin,47,1); |
|
43 | + $q = substr($bin, 47, 1); |
|
44 | 44 | if ($q) { |
45 | - $n = intval(substr($bin,40,7).substr($bin,48,4),2); |
|
46 | - $alt = $n*25-1000; |
|
45 | + $n = intval(substr($bin, 40, 7).substr($bin, 48, 4), 2); |
|
46 | + $alt = $n*25 - 1000; |
|
47 | 47 | $data['altitude'] = $alt; |
48 | 48 | } |
49 | 49 | // Check odd/even flag |
50 | - $oe = substr($bin,53,1); |
|
50 | + $oe = substr($bin, 53, 1); |
|
51 | 51 | //if ($oe) => odd else even |
52 | 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()); |
|
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 | 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']; |
60 | 60 | $cprlon_even = $this::$latlon[$icao]['longitude']; |
61 | 61 | |
62 | - $j = 59*$cprlat_even-60*$cprlat_odd+0.5; |
|
63 | - $lat_even = (360.0/60)*($j%60+$cprlat_even); |
|
64 | - $lat_odd = (360.0/59)*($j%59+$cprlat_odd); |
|
62 | + $j = 59*$cprlat_even - 60*$cprlat_odd + 0.5; |
|
63 | + $lat_even = (360.0/60)*($j%60 + $cprlat_even); |
|
64 | + $lat_odd = (360.0/59)*($j%59 + $cprlat_odd); |
|
65 | 65 | if ($lat_even >= 270) $lat_even = $lat_even - 360; |
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 | 69 | if ($this::$latlon[$icao]['created'] > time()) { |
70 | - $ni = $this->cprN($lat_even,0); |
|
71 | - $m = floor($cprlon_even*($this->cprNL($lat_even)-1) - $cprlon_odd * $this->cprNL($lat_even)+0.5); |
|
72 | - $lon = (360.0/$ni)*($m%$ni+$cprlon_even); |
|
70 | + $ni = $this->cprN($lat_even, 0); |
|
71 | + $m = floor($cprlon_even*($this->cprNL($lat_even) - 1) - $cprlon_odd*$this->cprNL($lat_even) + 0.5); |
|
72 | + $lon = (360.0/$ni)*($m%$ni + $cprlon_even); |
|
73 | 73 | $lat = $lat_even; |
74 | - if ($lon > 180) $lon = $lon -360; |
|
74 | + if ($lon > 180) $lon = $lon - 360; |
|
75 | 75 | if ($lat > -91 && $lat < 91 && $lon > -181 && $lon < 181) { |
76 | 76 | //if ($globalDebug) echo 'cs : '.$cs.' - hex : '.$hex.' - lat : '.$lat.' - lon : '.$lon; |
77 | 77 | $data['latitude'] = $lat; |
78 | 78 | $data['longitude'] = $lon; |
79 | 79 | } |
80 | 80 | } else { |
81 | - $ni = $this->cprN($lat_odd,1); |
|
82 | - $m = floor($cprlon_even*($this->cprNL($lat_odd)-1) - $cprlon_odd * $this->cprNL($lat_odd)+0.5); |
|
83 | - $lon = (360.0/$ni)*($m%$ni+$cprlon_odd); |
|
81 | + $ni = $this->cprN($lat_odd, 1); |
|
82 | + $m = floor($cprlon_even*($this->cprNL($lat_odd) - 1) - $cprlon_odd*$this->cprNL($lat_odd) + 0.5); |
|
83 | + $lon = (360.0/$ni)*($m%$ni + $cprlon_odd); |
|
84 | 84 | $lat = $lat_odd; |
85 | - if ($lon > 180) $lon = $lon -360; |
|
85 | + if ($lon > 180) $lon = $lon - 360; |
|
86 | 86 | if ($lat > -91 && $lat < 91 && $lon > -181 && $lon < 181) { |
87 | 87 | //if ($globalDebug) echo 'icao : '.$icao.' - hex : '.$hex.' - lat : '.$lat.' - lon : '.$lon.' second'."\n"; |
88 | 88 | $data['latitude'] = $lat; |
@@ -94,15 +94,15 @@ discard block |
||
94 | 94 | } |
95 | 95 | } elseif ($tc == 19) { |
96 | 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); |
|
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 | 101 | if ($v_ew_dir) $v_ew = -1*$v_ew; |
102 | 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; |
|
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 | 106 | $data['speed'] = $speed; |
107 | 107 | $data['heading'] = $heading; |
108 | 108 | } |
@@ -117,7 +117,7 @@ discard block |
||
117 | 117 | |
118 | 118 | public function cprNL($lat) { |
119 | 119 | //Lookup table to convert the latitude to index. |
120 | - if ($lat < 0) $lat = -$lat; // Table is simmetric about the equator. |
|
120 | + if ($lat < 0) $lat = -$lat; // Table is simmetric about the equator. |
|
121 | 121 | if ($lat < 10.47047130) return 59; |
122 | 122 | if ($lat < 14.82817437) return 58; |
123 | 123 | if ($lat < 18.18626357) return 57; |
@@ -179,7 +179,7 @@ discard block |
||
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; |
@@ -205,10 +205,10 @@ discard block |
||
205 | 205 | ); |
206 | 206 | |
207 | 207 | $crc = 0; |
208 | - $checksum = intval(substr($msg,22,6),16); |
|
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 { |
@@ -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 |
@@ -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) { |
|
32 | + foreach ($sourcestat as $srcst) { |
|
33 | 33 | $type = $srcst['stats_type']; |
34 | 34 | if ($type == 'polar' || $type == 'hist') { |
35 | 35 | $source = $srcst['source_name']; |
36 | 36 | $data = $srcst['source_data']; |
37 | - $this->stats[$currentdate][$source][$type] = json_decode($data,true); |
|
37 | + $this->stats[$currentdate][$source][$type] = json_decode($data, true); |
|
38 | 38 | } |
39 | 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 | |
@@ -65,8 +65,8 @@ discard block |
||
65 | 65 | $schedule = $Schedule->fetchSchedule($operator); |
66 | 66 | if (count($schedule) > 0 && isset($schedule['DepartureTime']) && isset($schedule['ArrivalTime'])) { |
67 | 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'])); |
|
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 | 70 | // Should also check if route schedule = route from DB |
71 | 71 | if ($schedule['DepartureAirportIATA'] != '') { |
72 | 72 | if ($this->all_flights[$id]['departure_airport'] != $Spotter->getAirportIcao($schedule['DepartureAirportIATA'])) { |
@@ -86,7 +86,7 @@ discard block |
||
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 | 91 | } else $scheduleexist = true; |
92 | 92 | } else $scheduleexist = true; |
@@ -94,7 +94,7 @@ discard block |
||
94 | 94 | if ($scheduleexist) { |
95 | 95 | if ($globalDebug) echo "-> get arrival/departure airport info for ".$ident."\n"; |
96 | 96 | $sch = $Schedule->getSchedule($operator); |
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'])); |
|
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; |
@@ -120,7 +120,7 @@ discard block |
||
120 | 120 | //echo $this->all_flights[$key]['id'].' - '.$this->all_flights[$key]['latitude'].' '.$this->all_flights[$key]['longitude']."\n"; |
121 | 121 | $Spotter = new Spotter($this->db); |
122 | 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']); |
|
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 | 124 | } |
125 | 125 | } |
126 | 126 | } |
@@ -133,7 +133,7 @@ discard block |
||
133 | 133 | $airport_time = ''; |
134 | 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); |
|
136 | + $closestAirports = $Spotter->closestAirports($this->all_flights[$key]['latitude'], $this->all_flights[$key]['longitude'], $globalClosestMinDist); |
|
137 | 137 | if (isset($closestAirports[0])) { |
138 | 138 | if (isset($this->all_flights[$key]['arrival_airport']) && $this->all_flights[$key]['arrival_airport'] == $closestAirports[0]['icao']) { |
139 | 139 | $airport_icao = $closestAirports[0]['icao']; |
@@ -148,7 +148,7 @@ discard block |
||
148 | 148 | break; |
149 | 149 | } |
150 | 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))) { |
|
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 | 152 | $airport_icao = $closestAirports[0]['icao']; |
153 | 153 | $airport_time = $this->all_flights[$key]['datetime']; |
154 | 154 | } else { |
@@ -161,7 +161,7 @@ discard block |
||
161 | 161 | } else { |
162 | 162 | if ($globalDebug) echo "---- No latitude or longitude. Ident : ".$this->all_flights[$key]['ident']."\n"; |
163 | 163 | } |
164 | - return array('airport_icao' => $airport_icao,'airport_time' => $airport_time); |
|
164 | + return array('airport_icao' => $airport_icao, 'airport_time' => $airport_time); |
|
165 | 165 | } |
166 | 166 | |
167 | 167 | |
@@ -172,7 +172,7 @@ discard block |
||
172 | 172 | if ($globalDebug) echo 'Delete old values and update latest data...'."\n"; |
173 | 173 | foreach ($this->all_flights as $key => $flight) { |
174 | 174 | if (isset($flight['lastupdate'])) { |
175 | - if ($flight['lastupdate'] < (time()-3000)) { |
|
175 | + if ($flight['lastupdate'] < (time() - 3000)) { |
|
176 | 176 | if (isset($this->all_flights[$key]['id'])) { |
177 | 177 | if ($globalDebug) echo "--- Delete old values with id ".$this->all_flights[$key]['id']."\n"; |
178 | 178 | /* |
@@ -183,7 +183,7 @@ discard block |
||
183 | 183 | $real_arrival = $this->arrival($key); |
184 | 184 | $Spotter = new Spotter($this->db); |
185 | 185 | if ($this->all_flights[$key]['latitude'] != '' && $this->all_flights[$key]['longitude'] != '') { |
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']); |
|
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 |
@@ -219,7 +219,7 @@ discard block |
||
219 | 219 | $send = false; |
220 | 220 | |
221 | 221 | // SBS format is CSV format |
222 | - if(is_array($line) && isset($line['hex'])) { |
|
222 | + if (is_array($line) && isset($line['hex'])) { |
|
223 | 223 | //print_r($line); |
224 | 224 | if ($line['hex'] != '' && $line['hex'] != '00000' && $line['hex'] != '000000' && $line['hex'] != '111111' && ctype_xdigit($line['hex']) && strlen($line['hex']) === 6) { |
225 | 225 | |
@@ -253,7 +253,7 @@ discard block |
||
253 | 253 | //print_r($this->all_flights); |
254 | 254 | if (!isset($this->all_flights[$id]['hex']) && ctype_xdigit($hex)) { |
255 | 255 | $this->all_flights[$id] = array('hex' => $hex); |
256 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0)); |
|
256 | + $this->all_flights[$id] = array_merge($this->all_flights[$id], array('addedSpotter' => 0)); |
|
257 | 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 | 259 | //} else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => date('Y-m-d H:i:s'))); |
@@ -263,7 +263,7 @@ discard block |
||
263 | 263 | $Spotter = new Spotter($this->db); |
264 | 264 | $aircraft_icao = $Spotter->getAllAircraftType($hex); |
265 | 265 | $Spotter->db = null; |
266 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update getallaircrattype : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
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 | 269 | if ($line['aircraft_type'] == 'PARA_GLIDER') $aircraft_icao = 'GLID'; |
@@ -271,32 +271,32 @@ discard block |
||
271 | 271 | elseif ($line['aircraft_type'] == 'TOW_PLANE') $aircraft_icao = 'TOWPLANE'; |
272 | 272 | elseif ($line['aircraft_type'] == 'POWERED_AIRCRAFT') $aircraft_icao = 'POWAIRC'; |
273 | 273 | } |
274 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao)); |
|
274 | + $this->all_flights[$id] = array_merge($this->all_flights[$id], array('aircraft_icao' => $aircraft_icao)); |
|
275 | 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 | - if ($aircraft_icao != '') $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao)); |
|
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())); |
|
280 | + if ($aircraft_icao != '') $this->all_flights[$id] = array_merge($this->all_flights[$id], array('aircraft_icao' => $aircraft_icao)); |
|
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 | 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 | - 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'))); |
|
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 | 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'])); |
|
291 | + } else $this->all_flights[$id] = array_merge($this->all_flights[$id], array('id' => $line['id'])); |
|
292 | 292 | |
293 | 293 | if ($globalDebug) echo "*********** New aircraft hex : ".$hex." ***********\n"; |
294 | 294 | if ($globalAllFlights !== FALSE) $dataFound = true; |
295 | 295 | } |
296 | 296 | |
297 | - if (isset($line['datetime']) && preg_match('/^(\d{4}(?:\-\d{2}){2} \d{2}(?:\:\d{2}){2})$/',$line['datetime'])) { |
|
297 | + if (isset($line['datetime']) && preg_match('/^(\d{4}(?:\-\d{2}){2} \d{2}(?:\:\d{2}){2})$/', $line['datetime'])) { |
|
298 | 298 | if (!isset($this->all_flights[$id]['datetime']) || strtotime($line['datetime']) >= strtotime($this->all_flights[$id]['datetime'])) { |
299 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => $line['datetime'])); |
|
299 | + $this->all_flights[$id] = array_merge($this->all_flights[$id], array('datetime' => $line['datetime'])); |
|
300 | 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"; |
@@ -307,23 +307,23 @@ discard block |
||
307 | 307 | */ |
308 | 308 | return ''; |
309 | 309 | } |
310 | - } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => date('Y-m-d H:i:s'))); |
|
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']))); |
|
326 | + $this->all_flights[$id] = array_merge($this->all_flights[$id], array('ident' => trim($line['ident']))); |
|
327 | 327 | if ($this->all_flights[$id]['addedSpotter'] == 1) { |
328 | 328 | $timeelapsed = microtime(true); |
329 | 329 | $Spotter = new Spotter($this->db); |
@@ -333,10 +333,10 @@ discard block |
||
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 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update identspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
339 | + if ($globalDebugTimeElapsed) echo 'Time elapsed for update identspotterdata : '.round(microtime(true) - $timeelapsed, 2).'s'."\n"; |
|
340 | 340 | } |
341 | 341 | |
342 | 342 | /* |
@@ -347,24 +347,24 @@ 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 | 352 | //$putinarchive = true; |
353 | 353 | if (isset($line['departure_airport_time']) && $line['departure_airport_time'] != 0) { |
354 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport_time' => $line['departure_airport_time'])); |
|
354 | + $this->all_flights[$id] = array_merge($this->all_flights[$id], array('departure_airport_time' => $line['departure_airport_time'])); |
|
355 | 355 | } |
356 | 356 | if (isset($line['arrival_airport_time']) && $line['arrival_airport_time'] != 0) { |
357 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('arrival_airport_time' => $line['arrival_airport_time'])); |
|
357 | + $this->all_flights[$id] = array_merge($this->all_flights[$id], array('arrival_airport_time' => $line['arrival_airport_time'])); |
|
358 | 358 | } |
359 | 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' => '')); |
|
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 | 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' => '')); |
|
367 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update getAirportICAO : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
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 | + if ($globalDebugTimeElapsed) echo 'Time elapsed for update getAirportICAO : '.round(microtime(true) - $timeelapsed, 2).'s'."\n"; |
|
368 | 368 | |
369 | 369 | } elseif (!isset($line['format_source']) || $line['format_source'] != 'aprs') { |
370 | 370 | $timeelapsed = microtime(true); |
@@ -377,34 +377,34 @@ discard block |
||
377 | 377 | $Translation->db = null; |
378 | 378 | } |
379 | 379 | $Spotter->db = null; |
380 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update getrouteinfo : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
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 | 383 | //if ($route['FromAirport_ICAO'] != $route['ToAirport_ICAO']) { |
384 | 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'])); |
|
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 | 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 | - if (!isset($this->all_flights[$id]['schedule_check']) || $this->all_flights[$id]['schedule_check'] === false) $this->get_Schedule($id,trim($line['ident'])); |
|
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)); |
|
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 | 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'); |
|
402 | + $distance = $Common->distance($line['latitude'], $line['longitude'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], 'm'); |
|
403 | 403 | if ($distance > 1000 && $distance < 10000) { |
404 | 404 | // use datetime |
405 | 405 | $speed = $distance/(time() - $this->all_flights[$id]['time_last_coord']); |
406 | 406 | $speed = $speed*3.6; |
407 | - if ($speed < 1000) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed' => round($speed))); |
|
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 | } |
@@ -412,11 +412,11 @@ discard block |
||
412 | 412 | |
413 | 413 | |
414 | 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']); |
|
415 | + if (isset($this->all_flights[$id]['time_last_coord'])) $timediff = round(time() - $this->all_flights[$id]['time_last_coord']); |
|
416 | 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')))) { |
|
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; |
@@ -424,10 +424,10 @@ discard block |
||
424 | 424 | if ($globalDebug) echo "\n".' ------- Check Country for '.$this->all_flights[$id]['ident'].' with latitude : '.$line['latitude'].' and longitude : '.$line['longitude'].'.... '; |
425 | 425 | $timeelapsed = microtime(true); |
426 | 426 | $Spotter = new Spotter($this->db); |
427 | - $all_country = $Spotter->getCountryFromLatitudeLongitude($line['latitude'],$line['longitude']); |
|
427 | + $all_country = $Spotter->getCountryFromLatitudeLongitude($line['latitude'], $line['longitude']); |
|
428 | 428 | if (!empty($all_country)) $this->all_flights[$id]['over_country'] = $all_country['iso2']; |
429 | 429 | $Spotter->db = null; |
430 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
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 | } |
@@ -436,13 +436,13 @@ discard block |
||
436 | 436 | if (isset($line['latitude']) && $line['latitude'] != '' && $line['latitude'] != 0 && $line['latitude'] < 91 && $line['latitude'] > -90) { |
437 | 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 | - 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') { |
|
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 | 440 | $this->all_flights[$id]['livedb_latitude'] = $line['latitude']; |
441 | 441 | $dataFound = true; |
442 | 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 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('latitude' => $line['latitude'])); |
|
445 | + $this->all_flights[$id] = array_merge($this->all_flights[$id], array('latitude' => $line['latitude'])); |
|
446 | 446 | /* |
447 | 447 | if (abs($this->all_flights[$id]['archive_latitude']-$this->all_flights[$id]['latitude']) > 0.3) { |
448 | 448 | $this->all_flights[$id]['archive_latitude'] = $line['latitude']; |
@@ -460,13 +460,13 @@ discard block |
||
460 | 460 | if ($line['longitude'] > 180) $line['longitude'] = $line['longitude'] - 360; |
461 | 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 | - 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') { |
|
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 | 464 | $this->all_flights[$id]['livedb_longitude'] = $line['longitude']; |
465 | 465 | $dataFound = true; |
466 | 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 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('longitude' => $line['longitude'])); |
|
469 | + $this->all_flights[$id] = array_merge($this->all_flights[$id], array('longitude' => $line['longitude'])); |
|
470 | 470 | /* |
471 | 471 | if (abs($this->all_flights[$id]['archive_longitude']-$this->all_flights[$id]['longitude']) > 0.3) { |
472 | 472 | $this->all_flights[$id]['archive_longitude'] = $line['longitude']; |
@@ -484,45 +484,45 @@ discard block |
||
484 | 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 | - echo 'Time : '.$timediff.'s - Distance : '.$Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m')."m -"; |
|
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 - "; |
|
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 | + 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 | 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'])); |
|
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'])); |
|
497 | + $this->all_flights[$id] = array_merge($this->all_flights[$id], array('verticalrate' => $line['verticalrate'])); |
|
498 | 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'])); |
|
507 | + $this->all_flights[$id] = array_merge($this->all_flights[$id], array('emergency' => $line['emergency'])); |
|
508 | 508 | //$dataFound = true; |
509 | 509 | } |
510 | 510 | if (isset($line['ground']) && $line['ground'] != '') { |
511 | 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 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0)); |
|
514 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('forcenew' => 1)); |
|
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'])); |
|
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'])); |
|
513 | + $this->all_flights[$id] = array_merge($this->all_flights[$id], array('addedSpotter' => 0)); |
|
514 | + $this->all_flights[$id] = array_merge($this->all_flights[$id], array('forcenew' => 1)); |
|
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'])); |
|
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 | 518 | } |
519 | 519 | if ($line['ground'] != 1) $line['ground'] = 0; |
520 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ground' => $line['ground'])); |
|
520 | + $this->all_flights[$id] = array_merge($this->all_flights[$id], array('ground' => $line['ground'])); |
|
521 | 521 | //$dataFound = true; |
522 | 522 | } |
523 | 523 | if (isset($line['squawk']) && $line['squawk'] != '') { |
524 | 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'])); |
|
525 | + $this->all_flights[$id] = array_merge($this->all_flights[$id], array('squawk' => $line['squawk'])); |
|
526 | 526 | $highlight = ''; |
527 | 527 | if ($this->all_flights[$id]['squawk'] == '7500') $highlight = 'Squawk 7500 : Hijack at '.date('Y-m-d G:i').' UTC'; |
528 | 528 | if ($this->all_flights[$id]['squawk'] == '7600') $highlight = 'Squawk 7600 : Lost Comm (radio failure) at '.date('Y-m-d G:i').' UTC'; |
@@ -530,48 +530,48 @@ discard block |
||
530 | 530 | if ($highlight != '') { |
531 | 531 | $timeelapsed = microtime(true); |
532 | 532 | $Spotter = new Spotter($this->db); |
533 | - $Spotter->setHighlightFlight($this->all_flights[$id]['id'],$highlight); |
|
533 | + $Spotter->setHighlightFlight($this->all_flights[$id]['id'], $highlight); |
|
534 | 534 | $Spotter->db = null; |
535 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update sethighlightflight : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
535 | + if ($globalDebugTimeElapsed) echo 'Time elapsed for update sethighlightflight : '.round(microtime(true) - $timeelapsed, 2).'s'."\n"; |
|
536 | 536 | |
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'])); |
|
542 | + } else $this->all_flights[$id] = array_merge($this->all_flights[$id], array('squawk' => $line['squawk'])); |
|
543 | 543 | //$dataFound = true; |
544 | 544 | } |
545 | 545 | |
546 | 546 | if (isset($line['altitude']) && $line['altitude'] != '') { |
547 | 547 | //if (!isset($this->all_flights[$id]['altitude']) || $this->all_flights[$id]['altitude'] == '' || ($this->all_flights[$id]['altitude'] > 0 && $line['altitude'] != 0)) { |
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 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('altitude' => round($line['altitude']/100))); |
|
550 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('altitude_real' => $line['altitude'])); |
|
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 | + $this->all_flights[$id] = array_merge($this->all_flights[$id], array('altitude' => round($line['altitude']/100))); |
|
550 | + $this->all_flights[$id] = array_merge($this->all_flights[$id], array('altitude_real' => $line['altitude'])); |
|
551 | 551 | //$dataFound = true; |
552 | 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)); |
|
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 | 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; |
|
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 | 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 | 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)); |
|
571 | + $this->all_flights[$id] = array_merge($this->all_flights[$id], array('heading' => 0)); |
|
572 | 572 | } |
573 | - if (isset($globalSourcesupdate) && $globalSourcesupdate != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalSourcesupdate) $dataFound = false; |
|
574 | - elseif (isset($globalSBS1update) && $globalSBS1update != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalSBS1update) $dataFound = false; |
|
573 | + if (isset($globalSourcesupdate) && $globalSourcesupdate != '' && isset($this->all_flights[$id]['lastupdate']) && time() - $this->all_flights[$id]['lastupdate'] < $globalSourcesupdate) $dataFound = false; |
|
574 | + elseif (isset($globalSBS1update) && $globalSBS1update != '' && isset($this->all_flights[$id]['lastupdate']) && time() - $this->all_flights[$id]['lastupdate'] < $globalSBS1update) $dataFound = false; |
|
575 | 575 | |
576 | 576 | // print_r($this->all_flights[$id]); |
577 | 577 | //gets the callsign from the last hour |
@@ -581,7 +581,7 @@ discard block |
||
581 | 581 | if ($dataFound === true && isset($this->all_flights[$id]['hex'])) { |
582 | 582 | $this->all_flights[$id]['lastupdate'] = time(); |
583 | 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'])) { |
|
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 | 585 | //print_r($this->all_flights); |
586 | 586 | //echo $this->all_flights[$id]['id'].' - '.$this->all_flights[$id]['addedSpotter']."\n"; |
587 | 587 | //$last_hour_ident = Spotter->getIdentFromLastHour($this->all_flights[$id]['ident']); |
@@ -591,61 +591,61 @@ discard block |
||
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 | 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"; |
|
594 | + if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkModeSRecent : '.round(microtime(true) - $timeelapsed, 2).'s'."\n"; |
|
595 | 595 | } elseif (isset($line['id'])) { |
596 | 596 | $recent_ident = $SpotterLive->checkIdRecent($line['id']); |
597 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
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 | 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"; |
|
600 | + if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true) - $timeelapsed, 2).'s'."\n"; |
|
601 | 601 | } else $recent_ident = ''; |
602 | - $SpotterLive->db=null; |
|
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 | 606 | } else { |
607 | 607 | $recent_ident = ''; |
608 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('forcenew' => 0)); |
|
608 | + $this->all_flights[$id] = array_merge($this->all_flights[$id], array('forcenew' => 0)); |
|
609 | 609 | } |
610 | 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 == "") |
|
611 | + if ($recent_ident == "") |
|
612 | 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 | - foreach($globalAirportIgnore as $airportIgnore) { |
|
618 | + foreach ($globalAirportIgnore as $airportIgnore) { |
|
619 | 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 | 624 | $ignoreImport = true; |
625 | - foreach($globalAirportIgnore as $airportIgnore) { |
|
625 | + foreach ($globalAirportIgnore as $airportIgnore) { |
|
626 | 626 | if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) { |
627 | 627 | $ignoreImport = false; |
628 | 628 | } |
629 | 629 | } |
630 | 630 | } |
631 | 631 | if (isset($globalAirlineIgnore) && is_array($globalAirlineIgnore)) { |
632 | - foreach($globalAirlineIgnore as $airlineIgnore) { |
|
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)) { |
|
632 | + foreach ($globalAirlineIgnore as $airlineIgnore) { |
|
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 | 634 | $ignoreImport = true; |
635 | 635 | } |
636 | 636 | } |
637 | 637 | } |
638 | 638 | if (isset($globalAirlineAccept) && count($globalAirlineAccept) > 0) { |
639 | 639 | $ignoreImport = true; |
640 | - foreach($globalAirlineAccept as $airlineAccept) { |
|
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)) { |
|
640 | + foreach ($globalAirlineAccept as $airlineAccept) { |
|
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 | 642 | $ignoreImport = false; |
643 | 643 | } |
644 | 644 | } |
645 | 645 | } |
646 | 646 | if (isset($globalPilotIdAccept) && count($globalPilotIdAccept) > 0) { |
647 | 647 | $ignoreImport = true; |
648 | - foreach($globalPilotIdAccept as $pilotIdAccept) { |
|
648 | + foreach ($globalPilotIdAccept as $pilotIdAccept) { |
|
649 | 649 | if ($this->all_flights[$id]['pilot_id'] == $pilotIdAccept) { |
650 | 650 | $ignoreImport = false; |
651 | 651 | } |
@@ -657,27 +657,27 @@ discard block |
||
657 | 657 | if ($this->all_flights[$id]['squawk'] == '7500') $highlight = 'Squawk 7500 : Hijack'; |
658 | 658 | if ($this->all_flights[$id]['squawk'] == '7600') $highlight = 'Squawk 7600 : Lost Comm (radio failure)'; |
659 | 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'))); |
|
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 | 661 | $timeelapsed = microtime(true); |
662 | 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']); |
|
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 | 664 | $Spotter->db = null; |
665 | 665 | if ($globalDebug && isset($result)) echo $result."\n"; |
666 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
666 | + if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true) - $timeelapsed, 2).'s'."\n"; |
|
667 | 667 | |
668 | 668 | // Add source stat in DB |
669 | 669 | $Stats = new Stats($this->db); |
670 | 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) { |
|
672 | + foreach ($this->stats as $date => $data) { |
|
673 | + foreach ($data as $source => $sourced) { |
|
674 | 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); |
|
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 | 677 | if (isset($sourced['msg'])) { |
678 | 678 | if (time() - $sourced['msg']['date'] > 10) { |
679 | 679 | $nbmsg = round($sourced['msg']['nb']/(time() - $sourced['msg']['date'])); |
680 | - echo $Stats->addStatSource($nbmsg,$source,'msg',$date); |
|
680 | + echo $Stats->addStatSource($nbmsg, $source, 'msg', $date); |
|
681 | 681 | unset($this->stats[$date][$source]['msg']); |
682 | 682 | } |
683 | 683 | } |
@@ -713,18 +713,18 @@ discard block |
||
713 | 713 | //SpotterLive->deleteLiveSpotterDataNotUpdated(); |
714 | 714 | $SpotterLive = new SpotterLive($this->db); |
715 | 715 | $SpotterLive->deleteLiveSpotterData(); |
716 | - $SpotterLive->db=null; |
|
716 | + $SpotterLive->db = null; |
|
717 | 717 | if ($globalDebug) echo " Done\n"; |
718 | 718 | $this->last_delete = time(); |
719 | 719 | } |
720 | 720 | } else { |
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')) { |
|
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 | 722 | $this->all_flights[$id]['id'] = $recent_ident; |
723 | 723 | $this->all_flights[$id]['addedSpotter'] = 1; |
724 | 724 | } |
725 | 725 | if (isset($globalDaemon) && !$globalDaemon) { |
726 | 726 | $Spotter = new Spotter($this->db); |
727 | - $Spotter->updateLatestSpotterData($this->all_flights[$id]['id'],$this->all_flights[$id]['ident'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$this->all_flights[$id]['altitude'],$this->all_flights[$id]['ground'],$this->all_flights[$id]['speed'],$this->all_flights[$id]['datetime'],$this->all_flights[$id]['arrival_airport'],$this->all_flights[$id]['arrival_airport_time']); |
|
727 | + $Spotter->updateLatestSpotterData($this->all_flights[$id]['id'], $this->all_flights[$id]['ident'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], $this->all_flights[$id]['altitude'], $this->all_flights[$id]['ground'], $this->all_flights[$id]['speed'], $this->all_flights[$id]['datetime'], $this->all_flights[$id]['arrival_airport'], $this->all_flights[$id]['arrival_airport_time']); |
|
728 | 728 | $Spotter->db = null; |
729 | 729 | } |
730 | 730 | |
@@ -748,37 +748,37 @@ discard block |
||
748 | 748 | if ($this->all_flights[$id]['departure_airport'] == "") { $this->all_flights[$id]['departure_airport'] = "NA"; } |
749 | 749 | if ($this->all_flights[$id]['arrival_airport'] == "") { $this->all_flights[$id]['arrival_airport'] = "NA"; } |
750 | 750 | |
751 | - foreach($globalAirportIgnore as $airportIgnore) { |
|
751 | + foreach ($globalAirportIgnore as $airportIgnore) { |
|
752 | 752 | if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) { |
753 | 753 | $ignoreImport = true; |
754 | 754 | } |
755 | 755 | } |
756 | 756 | if (count($globalAirportAccept) > 0) { |
757 | 757 | $ignoreImport = true; |
758 | - foreach($globalAirportIgnore as $airportIgnore) { |
|
758 | + foreach ($globalAirportIgnore as $airportIgnore) { |
|
759 | 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 | 763 | } |
764 | 764 | if (isset($globalAirlineIgnore) && is_array($globalAirlineIgnore)) { |
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)) { |
|
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)) { |
|
767 | 767 | $ignoreImport = true; |
768 | 768 | } |
769 | 769 | } |
770 | 770 | } |
771 | 771 | if (isset($globalAirlineAccept) && count($globalAirlineAccept) > 0) { |
772 | 772 | $ignoreImport = true; |
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)) { |
|
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)) { |
|
775 | 775 | $ignoreImport = false; |
776 | 776 | } |
777 | 777 | } |
778 | 778 | } |
779 | 779 | if (isset($globalPilotIdAccept) && count($globalPilotIdAccept) > 0) { |
780 | 780 | $ignoreImport = true; |
781 | - foreach($globalPilotIdAccept as $pilotIdAccept) { |
|
781 | + foreach ($globalPilotIdAccept as $pilotIdAccept) { |
|
782 | 782 | if ($this->all_flights[$id]['pilot_id'] == $pilotIdAccept) { |
783 | 783 | $ignoreImport = false; |
784 | 784 | } |
@@ -786,13 +786,13 @@ discard block |
||
786 | 786 | } |
787 | 787 | |
788 | 788 | if (!$ignoreImport) { |
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'])) { |
|
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); |
792 | 792 | $SpotterLive = new SpotterLive($this->db); |
793 | - $result = $SpotterLive->addLiveSpotterData($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'],$this->all_flights[$id]['hex'],$this->all_flights[$id]['putinarchive'],$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]['noarchive'], $this->all_flights[$id]['ground'],$this->all_flights[$id]['format_source'],$this->all_flights[$id]['source_name'],$this->all_flights[$id]['over_country']); |
|
793 | + $result = $SpotterLive->addLiveSpotterData($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'], $this->all_flights[$id]['hex'], $this->all_flights[$id]['putinarchive'], $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]['noarchive'], $this->all_flights[$id]['ground'], $this->all_flights[$id]['format_source'], $this->all_flights[$id]['source_name'], $this->all_flights[$id]['over_country']); |
|
794 | 794 | $SpotterLive->db = null; |
795 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
795 | + if ($globalDebugTimeElapsed) echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true) - $timeelapsed, 2).'s'."\n"; |
|
796 | 796 | |
797 | 797 | // Put statistics in $this->stats variable |
798 | 798 | //if ($line['format_source'] != 'aprs') { |
@@ -810,19 +810,19 @@ discard block |
||
810 | 810 | $latitude = $globalCenterLatitude; |
811 | 811 | $longitude = $globalCenterLongitude; |
812 | 812 | } |
813 | - $this->source_location[$source] = array('latitude' => $latitude,'longitude' => $longitude); |
|
813 | + $this->source_location[$source] = array('latitude' => $latitude, 'longitude' => $longitude); |
|
814 | 814 | } else { |
815 | 815 | $latitude = $this->source_location[$source]['latitude']; |
816 | 816 | $longitude = $this->source_location[$source]['longitude']; |
817 | 817 | } |
818 | - $stats_heading = $Common->getHeading($latitude,$longitude,$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude']); |
|
818 | + $stats_heading = $Common->getHeading($latitude, $longitude, $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude']); |
|
819 | 819 | //$stats_heading = $stats_heading%22.5; |
820 | 820 | $stats_heading = round($stats_heading/22.5); |
821 | - $stats_distance = $Common->distance($latitude,$longitude,$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude']); |
|
821 | + $stats_distance = $Common->distance($latitude, $longitude, $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude']); |
|
822 | 822 | $current_date = date('Y-m-d'); |
823 | 823 | if ($stats_heading == 16) $stats_heading = 0; |
824 | 824 | if (!isset($this->stats[$current_date][$source]['polar'][1])) { |
825 | - for ($i=0;$i<=15;$i++) { |
|
825 | + for ($i = 0; $i <= 15; $i++) { |
|
826 | 826 | $this->stats[$current_date][$source]['polar'][$i] = 0; |
827 | 827 | } |
828 | 828 | $this->stats[$current_date][$source]['polar'][$stats_heading] = $stats_distance; |
@@ -837,9 +837,9 @@ discard block |
||
837 | 837 | if (!isset($this->stats[$current_date][$source]['hist'][$distance])) { |
838 | 838 | if (isset($this->stats[$current_date][$source]['hist'][0])) { |
839 | 839 | end($this->stats[$current_date][$source]['hist']); |
840 | - $mini = key($this->stats[$current_date][$source]['hist'])+10; |
|
840 | + $mini = key($this->stats[$current_date][$source]['hist']) + 10; |
|
841 | 841 | } else $mini = 0; |
842 | - for ($i=$mini;$i<=$distance;$i+=10) { |
|
842 | + for ($i = $mini; $i <= $distance; $i += 10) { |
|
843 | 843 | $this->stats[$current_date][$source]['hist'][$i] = 0; |
844 | 844 | } |
845 | 845 | $this->stats[$current_date][$source]['hist'][$distance] = 1; |
@@ -852,7 +852,7 @@ discard block |
||
852 | 852 | if ($this->all_flights[$id]['putinarchive']) $send = true; |
853 | 853 | //if ($globalDebug) echo "Distance : ".Common->distance($this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude'])."\n"; |
854 | 854 | if ($globalDebug) echo $result."\n"; |
855 | - } elseif (isset($this->all_flights[$id]['latitude']) && isset($globalDistanceIgnore['latitude']) && $globalDebug) echo "!! Too far -> Distance : ".$Common->distance($this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude'])."\n"; |
|
855 | + } elseif (isset($this->all_flights[$id]['latitude']) && isset($globalDistanceIgnore['latitude']) && $globalDebug) echo "!! Too far -> Distance : ".$Common->distance($this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], $globalDistanceIgnore['latitude'], $globalDistanceIgnore['longitude'])."\n"; |
|
856 | 856 | //$this->del(); |
857 | 857 | |
858 | 858 |
@@ -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); |
@@ -31,12 +31,12 @@ discard block |
||
31 | 31 | } else return $ident; |
32 | 32 | } else return $ident; |
33 | 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'); |
|
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 | 36 | } else { |
37 | 37 | $identicao = $Spotter->getAllAirlineInfo($airline_icao); |
38 | 38 | if (isset($identicao[0])) { |
39 | - $icao = $identicao[0]['icao'].ltrim(substr($ident,2),'0'); |
|
39 | + $icao = $identicao[0]['icao'].ltrim(substr($ident, 2), '0'); |
|
40 | 40 | } else $icao = $ident; |
41 | 41 | } |
42 | 42 | return $icao; |
@@ -49,7 +49,7 @@ discard block |
||
49 | 49 | try { |
50 | 50 | $sth = $this->db->prepare($query); |
51 | 51 | $sth->execute($query_values); |
52 | - } catch(PDOException $e) { |
|
52 | + } catch (PDOException $e) { |
|
53 | 53 | return "error : ".$e->getMessage(); |
54 | 54 | } |
55 | 55 | $row = $sth->fetch(PDO::FETCH_ASSOC); |
@@ -58,29 +58,29 @@ discard block |
||
58 | 58 | } else return $ident; |
59 | 59 | } |
60 | 60 | |
61 | - public function addOperator($ident,$correct_ident,$source) { |
|
61 | + public function addOperator($ident, $correct_ident, $source) { |
|
62 | 62 | $query = "INSERT INTO translation (Operator,Operator_correct,Source) VALUES (:ident,:correct_ident,:source)"; |
63 | - $query_values = array(':ident' => $ident,':correct_ident' => $correct_ident, ':source' => $source); |
|
63 | + $query_values = array(':ident' => $ident, ':correct_ident' => $correct_ident, ':source' => $source); |
|
64 | 64 | try { |
65 | 65 | $sth = $this->db->prepare($query); |
66 | 66 | $sth->execute($query_values); |
67 | - } catch(PDOException $e) { |
|
67 | + } catch (PDOException $e) { |
|
68 | 68 | return "error : ".$e->getMessage(); |
69 | 69 | } |
70 | 70 | } |
71 | 71 | |
72 | - public function updateOperator($ident,$correct_ident,$source) { |
|
72 | + public function updateOperator($ident, $correct_ident, $source) { |
|
73 | 73 | $query = "UPDATE translation SET Operator_correct = :correct_ident,Source = :source WHERE Operator = :ident"; |
74 | - $query_values = array(':ident' => $ident,':correct_ident' => $correct_ident, ':source' => $source); |
|
74 | + $query_values = array(':ident' => $ident, ':correct_ident' => $correct_ident, ':source' => $source); |
|
75 | 75 | try { |
76 | 76 | $sth = $this->db->prepare($query); |
77 | 77 | $sth->execute($query_values); |
78 | - } catch(PDOException $e) { |
|
78 | + } catch (PDOException $e) { |
|
79 | 79 | return "error : ".$e->getMessage(); |
80 | 80 | } |
81 | 81 | } |
82 | 82 | |
83 | - public function checkTranslation($ident,$web = false) { |
|
83 | + public function checkTranslation($ident, $web = false) { |
|
84 | 84 | global $globalTranslationSources, $globalTranslationFetch; |
85 | 85 | //if (!isset($globalTranslationSources)) $globalTranslationSources = array('planefinder'); |
86 | 86 | $globalTranslationSources = array(); |
@@ -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 |
@@ -91,7 +91,7 @@ discard block |
||
91 | 91 | } |
92 | 92 | |
93 | 93 | static function getAdapterMap() { |
94 | - return array ( |
|
94 | + return array( |
|
95 | 95 | 'wkt' => 'WKT', |
96 | 96 | 'ewkt' => 'EWKT', |
97 | 97 | 'wkb' => 'WKB', |
@@ -154,8 +154,8 @@ discard block |
||
154 | 154 | |
155 | 155 | // If the geometry cannot even theoretically be reduced more, then pass it back |
156 | 156 | if (gettype($geometry) == 'object') { |
157 | - $passbacks = array('Point','LineString','Polygon'); |
|
158 | - if (in_array($geometry->geometryType(),$passbacks)) { |
|
157 | + $passbacks = array('Point', 'LineString', 'Polygon'); |
|
158 | + if (in_array($geometry->geometryType(), $passbacks)) { |
|
159 | 159 | return $geometry; |
160 | 160 | } |
161 | 161 | } |
@@ -163,8 +163,8 @@ discard block |
||
163 | 163 | // If it is a mutlti-geometry, check to see if it just has one member |
164 | 164 | // If it does, then pass the member, if not, then just pass back the geometry |
165 | 165 | if (gettype($geometry) == 'object') { |
166 | - $simple_collections = array('MultiPoint','MultiLineString','MultiPolygon'); |
|
167 | - if (in_array(get_class($geometry),$passbacks)) { |
|
166 | + $simple_collections = array('MultiPoint', 'MultiLineString', 'MultiPolygon'); |
|
167 | + if (in_array(get_class($geometry), $passbacks)) { |
|
168 | 168 | $components = $geometry->getComponents(); |
169 | 169 | if (count($components) == 1) { |
170 | 170 | return $components[0]; |
@@ -183,7 +183,7 @@ discard block |
||
183 | 183 | $geometries = array(); |
184 | 184 | $geom_types = array(); |
185 | 185 | |
186 | - $collections = array('MultiPoint','MultiLineString','MultiPolygon','GeometryCollection'); |
|
186 | + $collections = array('MultiPoint', 'MultiLineString', 'MultiPolygon', 'GeometryCollection'); |
|
187 | 187 | |
188 | 188 | foreach ($geometry as $item) { |
189 | 189 | if ($item) { |
@@ -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(); |
@@ -50,7 +50,7 @@ |
||
50 | 50 | if ($type == 'GeometryCollection') { |
51 | 51 | return $this->objToGeometryCollection($obj); |
52 | 52 | } |
53 | - $method = 'arrayTo' . $type; |
|
53 | + $method = 'arrayTo'.$type; |
|
54 | 54 | return $this->$method($obj->coordinates); |
55 | 55 | } |
56 | 56 |