@@ -3,6 +3,10 @@ |
||
| 3 | 3 | require_once(dirname(__FILE__).'/../require/class.Connection.php'); |
| 4 | 4 | |
| 5 | 5 | class create_db { |
| 6 | + |
|
| 7 | + /** |
|
| 8 | + * @param string $filename |
|
| 9 | + */ |
|
| 6 | 10 | public static function import_file($filename) { |
| 7 | 11 | $filename = filter_var($filename,FILTER_SANITIZE_STRING); |
| 8 | 12 | $Connection = new Connection(); |
@@ -29,9 +29,9 @@ discard block |
||
| 29 | 29 | } |
| 30 | 30 | fclose($handle); |
| 31 | 31 | } |
| 32 | - //Connection::$db->commit(); |
|
| 33 | - $Connection->db = null; |
|
| 34 | - return ''; |
|
| 32 | + //Connection::$db->commit(); |
|
| 33 | + $Connection->db = null; |
|
| 34 | + return ''; |
|
| 35 | 35 | } |
| 36 | 36 | |
| 37 | 37 | public static function import_all_db($directory) { |
@@ -40,7 +40,7 @@ discard block |
||
| 40 | 40 | //foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($directory)) as $filename) |
| 41 | 41 | while(false !== ($filename = readdir($dh))) |
| 42 | 42 | { |
| 43 | - if (preg_match('/\.sql$/',$filename)) $error .= create_db::import_file($directory.$filename); |
|
| 43 | + if (preg_match('/\.sql$/',$filename)) $error .= create_db::import_file($directory.$filename); |
|
| 44 | 44 | } |
| 45 | 45 | return $error; |
| 46 | 46 | } |
@@ -55,7 +55,7 @@ discard block |
||
| 55 | 55 | $host = filter_var($host,FILTER_SANITIZE_STRING); |
| 56 | 56 | // Dirty hack |
| 57 | 57 | if ($host != 'localhost' && $host != '127.0.0.1') { |
| 58 | - $grantright = $_SERVER['SERVER_ADDR']; |
|
| 58 | + $grantright = $_SERVER['SERVER_ADDR']; |
|
| 59 | 59 | } else $grantright = 'localhost'; |
| 60 | 60 | try { |
| 61 | 61 | $dbh = new PDO($db_type.':host='.$host,$root,$root_pass); |
@@ -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 | } |
@@ -14,7 +14,9 @@ discard block |
||
| 14 | 14 | //foreach ($lines as $line) |
| 15 | 15 | while (($line = fgets($handle,4096)) !== false) |
| 16 | 16 | { |
| 17 | - if (substr($line,0,2) == '--' || $line == '') continue; |
|
| 17 | + if (substr($line,0,2) == '--' || $line == '') { |
|
| 18 | + continue; |
|
| 19 | + } |
|
| 18 | 20 | $templine .= $line; |
| 19 | 21 | if (substr(trim($line), -1,1) == ';') |
| 20 | 22 | { |
@@ -40,7 +42,9 @@ discard block |
||
| 40 | 42 | //foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($directory)) as $filename) |
| 41 | 43 | while(false !== ($filename = readdir($dh))) |
| 42 | 44 | { |
| 43 | - if (preg_match('/\.sql$/',$filename)) $error .= create_db::import_file($directory.$filename); |
|
| 45 | + if (preg_match('/\.sql$/',$filename)) { |
|
| 46 | + $error .= create_db::import_file($directory.$filename); |
|
| 47 | + } |
|
| 44 | 48 | } |
| 45 | 49 | return $error; |
| 46 | 50 | } |
@@ -56,13 +60,17 @@ discard block |
||
| 56 | 60 | // Dirty hack |
| 57 | 61 | if ($host != 'localhost' && $host != '127.0.0.1') { |
| 58 | 62 | $grantright = $_SERVER['SERVER_ADDR']; |
| 59 | - } else $grantright = 'localhost'; |
|
| 63 | + } else { |
|
| 64 | + $grantright = 'localhost'; |
|
| 65 | + } |
|
| 60 | 66 | try { |
| 61 | 67 | $dbh = new PDO($db_type.':host='.$host,$root,$root_pass); |
| 62 | 68 | $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); |
| 63 | 69 | if ($db_type == 'mysql') { |
| 64 | 70 | $dbh->exec('CREATE DATABASE IF NOT EXISTS `'.$db.'`;GRANT ALL ON `'.$db."`.* TO '".$user."'@'".$grantright."' IDENTIFIED BY '".$password."';FLUSH PRIVILEGES;"); |
| 65 | - if ($grantright == 'localhost') $dbh->exec('GRANT ALL ON `'.$db."`.* TO '".$user."'@'127.0.0.1' IDENTIFIED BY '".$password."';FLUSH PRIVILEGES;"); |
|
| 71 | + if ($grantright == 'localhost') { |
|
| 72 | + $dbh->exec('GRANT ALL ON `'.$db."`.* TO '".$user."'@'127.0.0.1' IDENTIFIED BY '".$password."';FLUSH PRIVILEGES;"); |
|
| 73 | + } |
|
| 66 | 74 | } else if ($db_type == 'pgsql') { |
| 67 | 75 | $dbh->exec("CREATE DATABASE ".$db.";"); |
| 68 | 76 | $dbh->exec("CREATE USER ".$user." WITH PASSWORD '".$password."'; |
@@ -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 | } |
@@ -215,14 +215,7 @@ 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(); } |
|
| 225 | - else { print "<p>Unknown capability code: '$code'</p>"; return false; } |
|
| 218 | + if( $code == "select" ) { $r = $this->test_select(); } elseif( $code == "constant_as" ) { $r = $this->test_constant_as(); } elseif( $code == "math_as" ) { $r = $this->test_math_as(); } elseif( $code == "count" ) { $r = $this->test_count(); } elseif( $code == "max" ) { $r = $this->test_max(); } elseif( $code == "load" ) { $r = $this->test_load(); } elseif( $code == "sample" ) { $r = $this->test_sample(); } else { print "<p>Unknown capability code: '$code'</p>"; return false; } |
|
| 226 | 219 | $this->caps[$code] = $r; |
| 227 | 220 | if( isset( $this->caps_cache ) ) |
| 228 | 221 | { |
@@ -231,8 +224,7 @@ discard block |
||
| 231 | 224 | if( $was_cached ) |
| 232 | 225 | { |
| 233 | 226 | dba_replace( $db_key, $db_val, $this->caps_cache ); |
| 234 | - } |
|
| 235 | - else |
|
| 227 | + } else |
|
| 236 | 228 | { |
| 237 | 229 | dba_insert( $db_key, $db_val, $this->caps_cache ); |
| 238 | 230 | } |
@@ -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 | } |
@@ -18,7 +18,9 @@ discard block |
||
| 18 | 18 | |
| 19 | 19 | /* Check that end was found and body has at least one byte. */ |
| 20 | 20 | if ($splitpos == 0 || $splitpos + 1 == $input_len || $splitpos === FALSE) { |
| 21 | - if ($globalDebug) echo '!!! APRS invalid : '.$input."\n"; |
|
| 21 | + if ($globalDebug) { |
|
| 22 | + echo '!!! APRS invalid : '.$input."\n"; |
|
| 23 | + } |
|
| 22 | 24 | return false; |
| 23 | 25 | } |
| 24 | 26 | |
@@ -27,23 +29,31 @@ discard block |
||
| 27 | 29 | $body_len = strlen($body); |
| 28 | 30 | $header = substr($input,0,$splitpos); |
| 29 | 31 | //$header_len = strlen($header); |
| 30 | - if ($debug) echo 'header : '.$header."\n"; |
|
| 32 | + if ($debug) { |
|
| 33 | + echo 'header : '.$header."\n"; |
|
| 34 | + } |
|
| 31 | 35 | |
| 32 | 36 | /* Parse source, target and path. */ |
| 33 | 37 | //FLRDF0A52>APRS,qAS,LSTB |
| 34 | 38 | if (preg_match('/^([A-Z0-9\\-]{1,9})>(.*)$/',$header,$matches)) { |
| 35 | 39 | $ident = $matches[1]; |
| 36 | 40 | $all_elements = $matches[2]; |
| 37 | - if ($debug) echo 'ident : '.$ident."\n"; |
|
| 41 | + if ($debug) { |
|
| 42 | + echo 'ident : '.$ident."\n"; |
|
| 43 | + } |
|
| 38 | 44 | $result['ident'] = $ident; |
| 39 | - } else return false; |
|
| 45 | + } else { |
|
| 46 | + return false; |
|
| 47 | + } |
|
| 40 | 48 | $elements = explode(',',$all_elements); |
| 41 | 49 | $source = end($elements); |
| 42 | 50 | $result['source'] = $source; |
| 43 | 51 | foreach ($elements as $element) { |
| 44 | 52 | if (preg_match('/^([a-zA-Z0-9-]{1,9})([*]?)$/',$element)) { |
| 45 | 53 | //echo "ok"; |
| 46 | - if ($element == 'TCPIP*') return false; |
|
| 54 | + if ($element == 'TCPIP*') { |
|
| 55 | + return false; |
|
| 56 | + } |
|
| 47 | 57 | } elseif (!preg_match('/^([0-9A-F]{32})$/',$element)) { |
| 48 | 58 | return false; |
| 49 | 59 | } |
@@ -89,7 +99,9 @@ discard block |
||
| 89 | 99 | //$symbol_table = $matches[4]; |
| 90 | 100 | $lat = intval($lat_deg); |
| 91 | 101 | $lon = intval($lon_deg); |
| 92 | - if ($lat > 89 || $lon > 179) return false; |
|
| 102 | + if ($lat > 89 || $lon > 179) { |
|
| 103 | + return false; |
|
| 104 | + } |
|
| 93 | 105 | |
| 94 | 106 | /* |
| 95 | 107 | $tmp_5b = str_replace('.','',$lat_min); |
@@ -99,8 +111,12 @@ discard block |
||
| 99 | 111 | */ |
| 100 | 112 | $latitude = $lat + floatval($lat_min)/60; |
| 101 | 113 | $longitude = $lon + floatval($lon_min)/60; |
| 102 | - if ($sind == 'S') $latitude = 0-$latitude; |
|
| 103 | - if ($wind == 'W') $longitude = 0-$longitude; |
|
| 114 | + if ($sind == 'S') { |
|
| 115 | + $latitude = 0-$latitude; |
|
| 116 | + } |
|
| 117 | + if ($wind == 'W') { |
|
| 118 | + $longitude = 0-$longitude; |
|
| 119 | + } |
|
| 104 | 120 | $result['latitude'] = $latitude; |
| 105 | 121 | $result['longitude'] = $longitude; |
| 106 | 122 | } |
@@ -115,7 +131,9 @@ discard block |
||
| 115 | 131 | if (preg_match('/^([0-9\\. ]{3})\\/([0-9\\. ]{3})/',$body_parse)) { |
| 116 | 132 | $course = substr($body_parse,0,3); |
| 117 | 133 | $tmp_s = intval($course); |
| 118 | - if ($tmp_s >= 1 && $tmp_s <= 360) $result['course'] = intval($course); |
|
| 134 | + if ($tmp_s >= 1 && $tmp_s <= 360) { |
|
| 135 | + $result['course'] = intval($course); |
|
| 136 | + } |
|
| 119 | 137 | $speed = substr($body_parse,4,3); |
| 120 | 138 | $result['speed'] = round($speed*1.852); |
| 121 | 139 | $body_parse = substr($body_parse,7); |
@@ -149,10 +167,16 @@ discard block |
||
| 149 | 167 | $lat_off = (($dao_split[1])-48.0)*0.001/60.0; |
| 150 | 168 | $lon_off = (($dao_split[2])-48.0)*0.001/60.0; |
| 151 | 169 | |
| 152 | - if ($result['latitude'] < 0) $result['latitude'] -= $lat_off; |
|
| 153 | - else $result['latitude'] += $lat_off; |
|
| 154 | - if ($result['longitude'] < 0) $result['longitude'] -= $lon_off; |
|
| 155 | - else $result['longitude'] += $lon_off; |
|
| 170 | + if ($result['latitude'] < 0) { |
|
| 171 | + $result['latitude'] -= $lat_off; |
|
| 172 | + } else { |
|
| 173 | + $result['latitude'] += $lat_off; |
|
| 174 | + } |
|
| 175 | + if ($result['longitude'] < 0) { |
|
| 176 | + $result['longitude'] -= $lon_off; |
|
| 177 | + } else { |
|
| 178 | + $result['longitude'] += $lon_off; |
|
| 179 | + } |
|
| 156 | 180 | } |
| 157 | 181 | $body_parse = substr($body_parse,6); |
| 158 | 182 | } |
@@ -165,27 +189,48 @@ discard block |
||
| 165 | 189 | $address = substr($id,2); |
| 166 | 190 | //print_r($matches); |
| 167 | 191 | $addressType = (intval(substr($id,0,2),16))&3; |
| 168 | - if ($addressType == 0) $result['addresstype'] = "RANDOM"; |
|
| 169 | - elseif ($addressType == 1) $result['addresstype'] = "ICAO"; |
|
| 170 | - elseif ($addressType == 2) $result['addresstype'] = "FLARM"; |
|
| 171 | - elseif ($addressType == 3) $result['addresstype'] = "OGN"; |
|
| 192 | + if ($addressType == 0) { |
|
| 193 | + $result['addresstype'] = "RANDOM"; |
|
| 194 | + } elseif ($addressType == 1) { |
|
| 195 | + $result['addresstype'] = "ICAO"; |
|
| 196 | + } elseif ($addressType == 2) { |
|
| 197 | + $result['addresstype'] = "FLARM"; |
|
| 198 | + } elseif ($addressType == 3) { |
|
| 199 | + $result['addresstype'] = "OGN"; |
|
| 200 | + } |
|
| 172 | 201 | $aircraftType = $this->urshift(((intval(substr($id,0,2),16)) & 0b1111100),2); |
| 173 | 202 | $result['aircrafttype_code'] = $aircraftType; |
| 174 | - if ($aircraftType == 0) $result['aircrafttype'] = "UNKNOWN"; |
|
| 175 | - elseif ($aircraftType == 1) $result['aircrafttype'] = "GLIDER"; |
|
| 176 | - elseif ($aircraftType == 2) $result['aircrafttype'] = "TOW_PLANE"; |
|
| 177 | - elseif ($aircraftType == 3) $result['aircrafttype'] = "HELICOPTER_ROTORCRAFT"; |
|
| 178 | - elseif ($aircraftType == 4) $result['aircrafttype'] = "PARACHUTE"; |
|
| 179 | - elseif ($aircraftType == 5) $result['aircrafttype'] = "DROP_PLANE"; |
|
| 180 | - elseif ($aircraftType == 6) $result['aircrafttype'] = "HANG_GLIDER"; |
|
| 181 | - elseif ($aircraftType == 7) $result['aircrafttype'] = "PARA_GLIDER"; |
|
| 182 | - elseif ($aircraftType == 8) $result['aircrafttype'] = "POWERED_AIRCRAFT"; |
|
| 183 | - elseif ($aircraftType == 9) $result['aircrafttype'] = "JET_AIRCRAFT"; |
|
| 184 | - elseif ($aircraftType == 10) $result['aircrafttype'] = "UFO"; |
|
| 185 | - elseif ($aircraftType == 11) $result['aircrafttype'] = "BALLOON"; |
|
| 186 | - elseif ($aircraftType == 12) $result['aircrafttype'] = "AIRSHIP"; |
|
| 187 | - elseif ($aircraftType == 13) $result['aircrafttype'] = "UAV"; |
|
| 188 | - elseif ($aircraftType == 15) $result['aircrafttype'] = "STATIC_OBJECT"; |
|
| 203 | + if ($aircraftType == 0) { |
|
| 204 | + $result['aircrafttype'] = "UNKNOWN"; |
|
| 205 | + } elseif ($aircraftType == 1) { |
|
| 206 | + $result['aircrafttype'] = "GLIDER"; |
|
| 207 | + } elseif ($aircraftType == 2) { |
|
| 208 | + $result['aircrafttype'] = "TOW_PLANE"; |
|
| 209 | + } elseif ($aircraftType == 3) { |
|
| 210 | + $result['aircrafttype'] = "HELICOPTER_ROTORCRAFT"; |
|
| 211 | + } elseif ($aircraftType == 4) { |
|
| 212 | + $result['aircrafttype'] = "PARACHUTE"; |
|
| 213 | + } elseif ($aircraftType == 5) { |
|
| 214 | + $result['aircrafttype'] = "DROP_PLANE"; |
|
| 215 | + } elseif ($aircraftType == 6) { |
|
| 216 | + $result['aircrafttype'] = "HANG_GLIDER"; |
|
| 217 | + } elseif ($aircraftType == 7) { |
|
| 218 | + $result['aircrafttype'] = "PARA_GLIDER"; |
|
| 219 | + } elseif ($aircraftType == 8) { |
|
| 220 | + $result['aircrafttype'] = "POWERED_AIRCRAFT"; |
|
| 221 | + } elseif ($aircraftType == 9) { |
|
| 222 | + $result['aircrafttype'] = "JET_AIRCRAFT"; |
|
| 223 | + } elseif ($aircraftType == 10) { |
|
| 224 | + $result['aircrafttype'] = "UFO"; |
|
| 225 | + } elseif ($aircraftType == 11) { |
|
| 226 | + $result['aircrafttype'] = "BALLOON"; |
|
| 227 | + } elseif ($aircraftType == 12) { |
|
| 228 | + $result['aircrafttype'] = "AIRSHIP"; |
|
| 229 | + } elseif ($aircraftType == 13) { |
|
| 230 | + $result['aircrafttype'] = "UAV"; |
|
| 231 | + } elseif ($aircraftType == 15) { |
|
| 232 | + $result['aircrafttype'] = "STATIC_OBJECT"; |
|
| 233 | + } |
|
| 189 | 234 | $stealth = (intval(substr($id,0,2), 16) & 0b10000000) != 0; |
| 190 | 235 | $result['stealth'] = $stealth; |
| 191 | 236 | $result['address'] = $address; |
@@ -227,8 +272,12 @@ discard block |
||
| 227 | 272 | } |
| 228 | 273 | } |
| 229 | 274 | } |
| 230 | - if (isset($result['latitude'])) $result['latitude'] = round($result['latitude'],4); |
|
| 231 | - if (isset($result['longitude'])) $result['longitude'] = round($result['longitude'],4); |
|
| 275 | + if (isset($result['latitude'])) { |
|
| 276 | + $result['latitude'] = round($result['latitude'],4); |
|
| 277 | + } |
|
| 278 | + if (isset($result['longitude'])) { |
|
| 279 | + $result['longitude'] = round($result['longitude'],4); |
|
| 280 | + } |
|
| 232 | 281 | //print_r($result); |
| 233 | 282 | return $result; |
| 234 | 283 | } |
@@ -1,12 +1,12 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | class aprs { |
| 3 | - private function urshift($n, $s) { |
|
| 3 | + private function urshift($n, $s) { |
|
| 4 | 4 | return ($n >= 0) ? ($n >> $s) : |
| 5 | - (($n & 0x7fffffff) >> $s) | |
|
| 6 | - (0x40000000 >> ($s - 1)); |
|
| 7 | - } |
|
| 5 | + (($n & 0x7fffffff) >> $s) | |
|
| 6 | + (0x40000000 >> ($s - 1)); |
|
| 7 | + } |
|
| 8 | 8 | |
| 9 | - public function parse($input) { |
|
| 9 | + public function parse($input) { |
|
| 10 | 10 | global $globalDebug; |
| 11 | 11 | $debug = false; |
| 12 | 12 | $result = array(); |
@@ -18,8 +18,8 @@ discard block |
||
| 18 | 18 | |
| 19 | 19 | /* Check that end was found and body has at least one byte. */ |
| 20 | 20 | if ($splitpos == 0 || $splitpos + 1 == $input_len || $splitpos === FALSE) { |
| 21 | - if ($globalDebug) echo '!!! APRS invalid : '.$input."\n"; |
|
| 22 | - return false; |
|
| 21 | + if ($globalDebug) echo '!!! APRS invalid : '.$input."\n"; |
|
| 22 | + return false; |
|
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | /* Save header and body. */ |
@@ -32,22 +32,22 @@ discard block |
||
| 32 | 32 | /* Parse source, target and path. */ |
| 33 | 33 | //FLRDF0A52>APRS,qAS,LSTB |
| 34 | 34 | if (preg_match('/^([A-Z0-9\\-]{1,9})>(.*)$/',$header,$matches)) { |
| 35 | - $ident = $matches[1]; |
|
| 36 | - $all_elements = $matches[2]; |
|
| 37 | - if ($debug) echo 'ident : '.$ident."\n"; |
|
| 38 | - $result['ident'] = $ident; |
|
| 35 | + $ident = $matches[1]; |
|
| 36 | + $all_elements = $matches[2]; |
|
| 37 | + if ($debug) echo 'ident : '.$ident."\n"; |
|
| 38 | + $result['ident'] = $ident; |
|
| 39 | 39 | } else return false; |
| 40 | 40 | $elements = explode(',',$all_elements); |
| 41 | 41 | $source = end($elements); |
| 42 | 42 | $result['source'] = $source; |
| 43 | 43 | foreach ($elements as $element) { |
| 44 | - if (preg_match('/^([a-zA-Z0-9-]{1,9})([*]?)$/',$element)) { |
|
| 45 | - //echo "ok"; |
|
| 46 | - if ($element == 'TCPIP*') return false; |
|
| 47 | - } elseif (!preg_match('/^([0-9A-F]{32})$/',$element)) { |
|
| 44 | + if (preg_match('/^([a-zA-Z0-9-]{1,9})([*]?)$/',$element)) { |
|
| 45 | + //echo "ok"; |
|
| 46 | + if ($element == 'TCPIP*') return false; |
|
| 47 | + } elseif (!preg_match('/^([0-9A-F]{32})$/',$element)) { |
|
| 48 | 48 | return false; |
| 49 | - } |
|
| 50 | - /* |
|
| 49 | + } |
|
| 50 | + /* |
|
| 51 | 51 | } elseif (preg_match('/^([0-9A-F]{32})$/',$element)) { |
| 52 | 52 | //echo "ok"; |
| 53 | 53 | } else { |
@@ -58,23 +58,23 @@ discard block |
||
| 58 | 58 | // Check for Timestamp |
| 59 | 59 | $body_parse = substr($body,1); |
| 60 | 60 | if (preg_match('/^([0-9]{2})([0-9]{2})([0-9]{2})([zh\\/])/',$body_parse,$matches)) { |
| 61 | - $timestamp = $matches[0]; |
|
| 62 | - if ($matches[4] == 'h') { |
|
| 61 | + $timestamp = $matches[0]; |
|
| 62 | + if ($matches[4] == 'h') { |
|
| 63 | 63 | $timestamp = strtotime($matches[1].':'.$matches[2].':'.$matches[3]); |
| 64 | 64 | //echo 'timestamp : '.$timestamp.' - now : '.time()."\n"; |
| 65 | 65 | /* |
| 66 | 66 | if (time() + 3900 < $timestamp) $timestamp -= 86400; |
| 67 | 67 | elseif (time() - 82500 > $timestamp) $timestamp += 86400; |
| 68 | 68 | */ |
| 69 | - } elseif ($matches[4] == 'z' || $matches[4] == '/') { |
|
| 69 | + } elseif ($matches[4] == 'z' || $matches[4] == '/') { |
|
| 70 | 70 | // This work or not ? |
| 71 | 71 | $timestamp = strtotime($matches[1].' '.$matches[2].':'.$matches[3]); |
| 72 | - } |
|
| 73 | - $body_parse = substr($body_parse,7); |
|
| 74 | - $result['timestamp'] = $timestamp; |
|
| 72 | + } |
|
| 73 | + $body_parse = substr($body_parse,7); |
|
| 74 | + $result['timestamp'] = $timestamp; |
|
| 75 | 75 | } |
| 76 | 76 | if (strlen($body_parse) > 19) { |
| 77 | - if (preg_match('/^([0-9]{2})([0-7 ][0-9 ]\\.[0-9 ]{2})([NnSs])(.)([0-9]{3})([0-7 ][0-9 ]\\.[0-9 ]{2})([EeWw])(.)/',$body_parse,$matches)) { |
|
| 77 | + if (preg_match('/^([0-9]{2})([0-7 ][0-9 ]\\.[0-9 ]{2})([NnSs])(.)([0-9]{3})([0-7 ][0-9 ]\\.[0-9 ]{2})([EeWw])(.)/',$body_parse,$matches)) { |
|
| 78 | 78 | // 4658.70N/00707.78Ez |
| 79 | 79 | //print_r(str_split($body_parse)); |
| 80 | 80 | |
@@ -91,7 +91,7 @@ discard block |
||
| 91 | 91 | $lon = intval($lon_deg); |
| 92 | 92 | if ($lat > 89 || $lon > 179) return false; |
| 93 | 93 | |
| 94 | - /* |
|
| 94 | + /* |
|
| 95 | 95 | $tmp_5b = str_replace('.','',$lat_min); |
| 96 | 96 | if (preg_match('/^([0-9]{0,4})( {0,4})$/',$tmp_5b,$matches)) { |
| 97 | 97 | print_r($matches); |
@@ -103,64 +103,64 @@ discard block |
||
| 103 | 103 | if ($wind == 'W') $longitude = 0-$longitude; |
| 104 | 104 | $result['latitude'] = $latitude; |
| 105 | 105 | $result['longitude'] = $longitude; |
| 106 | - } |
|
| 107 | - if ($body_len > 19) { |
|
| 106 | + } |
|
| 107 | + if ($body_len > 19) { |
|
| 108 | 108 | $body_split = str_split($body_parse); |
| 109 | 109 | $symbol_code = $body_split[18]; |
| 110 | 110 | if ($symbol_code != '_') { |
| 111 | - $body_parse = substr($body_parse,19); |
|
| 112 | - $body_parse_len = strlen($body_parse); |
|
| 113 | - if ($body_parse_len >= 7) { |
|
| 111 | + $body_parse = substr($body_parse,19); |
|
| 112 | + $body_parse_len = strlen($body_parse); |
|
| 113 | + if ($body_parse_len >= 7) { |
|
| 114 | 114 | |
| 115 | - if (preg_match('/^([0-9\\. ]{3})\\/([0-9\\. ]{3})/',$body_parse)) { |
|
| 116 | - $course = substr($body_parse,0,3); |
|
| 117 | - $tmp_s = intval($course); |
|
| 118 | - if ($tmp_s >= 1 && $tmp_s <= 360) $result['course'] = intval($course); |
|
| 119 | - $speed = substr($body_parse,4,3); |
|
| 120 | - $result['speed'] = round($speed*1.852); |
|
| 121 | - $body_parse = substr($body_parse,7); |
|
| 122 | - } |
|
| 123 | - // Check PHGR, PHG, RNG |
|
| 124 | - } |
|
| 125 | - /* |
|
| 115 | + if (preg_match('/^([0-9\\. ]{3})\\/([0-9\\. ]{3})/',$body_parse)) { |
|
| 116 | + $course = substr($body_parse,0,3); |
|
| 117 | + $tmp_s = intval($course); |
|
| 118 | + if ($tmp_s >= 1 && $tmp_s <= 360) $result['course'] = intval($course); |
|
| 119 | + $speed = substr($body_parse,4,3); |
|
| 120 | + $result['speed'] = round($speed*1.852); |
|
| 121 | + $body_parse = substr($body_parse,7); |
|
| 122 | + } |
|
| 123 | + // Check PHGR, PHG, RNG |
|
| 124 | + } |
|
| 125 | + /* |
|
| 126 | 126 | else if ($body_parse_len > 0) { |
| 127 | 127 | $rest = $body_parse; |
| 128 | 128 | } |
| 129 | 129 | */ |
| 130 | - if (strlen($body_parse) > 0) { |
|
| 131 | - if (preg_match('/\\/A=(-[0-9]{5}|[0-9]{6})/',$body_parse,$matches)) { |
|
| 132 | - $altitude = intval($matches[1]); |
|
| 133 | - //$result['altitude'] = round($altitude*0.3048); |
|
| 134 | - $result['altitude'] = $altitude; |
|
| 135 | - $body_parse = substr($body_parse,strlen($matches[0])+1); |
|
| 136 | - } |
|
| 137 | - } |
|
| 130 | + if (strlen($body_parse) > 0) { |
|
| 131 | + if (preg_match('/\\/A=(-[0-9]{5}|[0-9]{6})/',$body_parse,$matches)) { |
|
| 132 | + $altitude = intval($matches[1]); |
|
| 133 | + //$result['altitude'] = round($altitude*0.3048); |
|
| 134 | + $result['altitude'] = $altitude; |
|
| 135 | + $body_parse = substr($body_parse,strlen($matches[0])+1); |
|
| 136 | + } |
|
| 137 | + } |
|
| 138 | 138 | |
| 139 | - // Telemetry |
|
| 140 | - /* |
|
| 139 | + // Telemetry |
|
| 140 | + /* |
|
| 141 | 141 | if (preg_match('/^([0-9]+),(-?)([0-9]{1,6}|[0-9]+\\.[0-9]+|\\.[0-9]+)?,(-?)([0-9]{1,6}|[0-9]+\\.[0-9]+|\\.[0-9]+)?,(-?)([0-9]{1,6}|[0-9]+\\.[0-9]+|\\.[0-9]+)?,(-?)([0-9]{1,6}|[0-9]+\\.[0-9]+|\\.[0-9]+)?,(-?)([0-9]{1,6}|[0-9]+\\.[0-9]+|\\.[0-9]+)?,([01]{0,8})/',$body_parse,$matches)) { |
| 142 | 142 | // Nothing yet... |
| 143 | 143 | } |
| 144 | 144 | */ |
| 145 | - // DAO |
|
| 146 | - if (preg_match('/^!([0-9A-Z]{3})/',$body_parse,$matches)) { |
|
| 147 | - $dao = $matches[1]; |
|
| 148 | - if (preg_match('/^([A-Z])([0-9]{2})/',$dao)) { |
|
| 145 | + // DAO |
|
| 146 | + if (preg_match('/^!([0-9A-Z]{3})/',$body_parse,$matches)) { |
|
| 147 | + $dao = $matches[1]; |
|
| 148 | + if (preg_match('/^([A-Z])([0-9]{2})/',$dao)) { |
|
| 149 | 149 | $dao_split = str_split($dao); |
| 150 | - $lat_off = (($dao_split[1])-48.0)*0.001/60.0; |
|
| 151 | - $lon_off = (($dao_split[2])-48.0)*0.001/60.0; |
|
| 150 | + $lat_off = (($dao_split[1])-48.0)*0.001/60.0; |
|
| 151 | + $lon_off = (($dao_split[2])-48.0)*0.001/60.0; |
|
| 152 | 152 | |
| 153 | 153 | if ($result['latitude'] < 0) $result['latitude'] -= $lat_off; |
| 154 | 154 | else $result['latitude'] += $lat_off; |
| 155 | 155 | if ($result['longitude'] < 0) $result['longitude'] -= $lon_off; |
| 156 | 156 | else $result['longitude'] += $lon_off; |
| 157 | - } |
|
| 158 | - $body_parse = substr($body_parse,6); |
|
| 159 | - } |
|
| 157 | + } |
|
| 158 | + $body_parse = substr($body_parse,6); |
|
| 159 | + } |
|
| 160 | 160 | |
| 161 | - // OGN comment |
|
| 161 | + // OGN comment |
|
| 162 | 162 | // echo "Before OGN : ".$body_parse."\n"; |
| 163 | - if (preg_match('/^id([0-9A-F]{8}) ([+-])([0-9]{3,4})fpm ([+-])([0-9.]{3,4})rot (.*)$/',$body_parse,$matches)) { |
|
| 163 | + if (preg_match('/^id([0-9A-F]{8}) ([+-])([0-9]{3,4})fpm ([+-])([0-9.]{3,4})rot (.*)$/',$body_parse,$matches)) { |
|
| 164 | 164 | $id = $matches[1]; |
| 165 | 165 | //$mode = substr($id,0,2); |
| 166 | 166 | $address = substr($id,2); |
@@ -190,49 +190,49 @@ discard block |
||
| 190 | 190 | $stealth = (intval(substr($id,0,2), 16) & 0b10000000) != 0; |
| 191 | 191 | $result['stealth'] = $stealth; |
| 192 | 192 | $result['address'] = $address; |
| 193 | - } |
|
| 193 | + } |
|
| 194 | 194 | |
| 195 | - //Comment |
|
| 196 | - $result['comment'] = $body_parse; |
|
| 195 | + //Comment |
|
| 196 | + $result['comment'] = $body_parse; |
|
| 197 | 197 | } else { |
| 198 | - // parse weather |
|
| 199 | - $body_parse = substr($body_parse,19); |
|
| 200 | - //$body_parse_len = strlen($body_parse); |
|
| 198 | + // parse weather |
|
| 199 | + $body_parse = substr($body_parse,19); |
|
| 200 | + //$body_parse_len = strlen($body_parse); |
|
| 201 | 201 | |
| 202 | - if (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})g([0-9 \\.]+)t(-{0,1}[0-9 \\.]+)/',$body_parse,$matches)) { |
|
| 202 | + if (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})g([0-9 \\.]+)t(-{0,1}[0-9 \\.]+)/',$body_parse,$matches)) { |
|
| 203 | 203 | $result['wind_dir'] = $matches[1]; |
| 204 | 204 | $result['wind_speed'] = round($matches[2]*1.60934,1); |
| 205 | 205 | $result['wind_gust'] = round($matches[3]*1.60934,1); |
| 206 | 206 | $result['temp'] = round(5/9*(($matches[4])-32),1); |
| 207 | - $body_parse = substr($body_parse,strlen($matches[0])+1); |
|
| 208 | - } elseif (preg_match('/^_{0,1}c([0-9 \\.\\-]{3})s([0-9 \\.]{3})g([0-9 \\.]+)t(-{0,1}[0-9 \\.]+)/',$body_parse,$matches)) { |
|
| 207 | + $body_parse = substr($body_parse,strlen($matches[0])+1); |
|
| 208 | + } elseif (preg_match('/^_{0,1}c([0-9 \\.\\-]{3})s([0-9 \\.]{3})g([0-9 \\.]+)t(-{0,1}[0-9 \\.]+)/',$body_parse,$matches)) { |
|
| 209 | 209 | $result['wind_dir'] = $matches[1]; |
| 210 | 210 | $result['wind_speed'] = round($matches[2]*1.60934,1); |
| 211 | 211 | $result['wind_gust'] = round($matches[3]*1.60934,1); |
| 212 | 212 | $result['temp'] = round(5/9*(($matches[4])-32),1); |
| 213 | - $body_parse = substr($body_parse,strlen($matches[0])+1); |
|
| 214 | - } elseif (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})t(-{0,1}[0-9 \\.]+)/',$body_parse,$matches)) { |
|
| 213 | + $body_parse = substr($body_parse,strlen($matches[0])+1); |
|
| 214 | + } elseif (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})t(-{0,1}[0-9 \\.]+)/',$body_parse,$matches)) { |
|
| 215 | 215 | $result['wind_dir'] = $matches[1]; |
| 216 | 216 | $result['wind_speed'] = round($matches[2]*1.60934,1); |
| 217 | 217 | $result['wind_gust'] = round($matches[3]*1.60934,1); |
| 218 | - $body_parse = substr($body_parse,strlen($matches[0])+1); |
|
| 219 | - } elseif (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})g([0-9 \\.]+)/',$body_parse,$matches)) { |
|
| 218 | + $body_parse = substr($body_parse,strlen($matches[0])+1); |
|
| 219 | + } elseif (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})g([0-9 \\.]+)/',$body_parse,$matches)) { |
|
| 220 | 220 | $result['wind_dir'] = $matches[1]; |
| 221 | 221 | $result['wind_speed'] = round($matches[2]*1.60934,1); |
| 222 | 222 | $result['wind_gust'] = round($matches[3]*1.60934,1); |
| 223 | - $body_parse = substr($body_parse,strlen($matches[0])+1); |
|
| 224 | - } |
|
| 225 | - if (!isset($result['temp']) && strlen($body_parse) > 0 && preg_match('/^g([0-9]+)t(-?[0-9 \\.]{1,3})/',$body_parse,$matches)) { |
|
| 223 | + $body_parse = substr($body_parse,strlen($matches[0])+1); |
|
| 224 | + } |
|
| 225 | + if (!isset($result['temp']) && strlen($body_parse) > 0 && preg_match('/^g([0-9]+)t(-?[0-9 \\.]{1,3})/',$body_parse,$matches)) { |
|
| 226 | 226 | $result['temp'] = round(5/9*(($matches[1])-32),1); |
| 227 | - } |
|
| 227 | + } |
|
| 228 | + } |
|
| 228 | 229 | } |
| 229 | - } |
|
| 230 | 230 | } |
| 231 | 231 | if (isset($result['latitude'])) $result['latitude'] = round($result['latitude'],4); |
| 232 | 232 | if (isset($result['longitude'])) $result['longitude'] = round($result['longitude'],4); |
| 233 | 233 | //print_r($result); |
| 234 | 234 | return $result; |
| 235 | - } |
|
| 235 | + } |
|
| 236 | 236 | } |
| 237 | 237 | /* |
| 238 | 238 | $aprs = new aprs(); |
@@ -160,7 +160,7 @@ discard block |
||
| 160 | 160 | * Check is distance realistic |
| 161 | 161 | * @param int $timeDifference the time between the reception of both messages |
| 162 | 162 | * @param float $distance distance covered |
| 163 | - * @return whether distance is realistic |
|
| 163 | + * @return boolean distance is realistic |
|
| 164 | 164 | */ |
| 165 | 165 | public function withinThreshold ($timeDifference, $distance) { |
| 166 | 166 | $x = abs($timeDifference); |
@@ -183,6 +183,9 @@ discard block |
||
| 183 | 183 | } |
| 184 | 184 | |
| 185 | 185 | |
| 186 | + /** |
|
| 187 | + * @param string $latlong |
|
| 188 | + */ |
|
| 186 | 189 | public function convertDec($dms,$latlong) { |
| 187 | 190 | if ($latlong == 'latitude') { |
| 188 | 191 | $deg = substr($dms, 0, 2); |
@@ -274,7 +277,7 @@ discard block |
||
| 274 | 277 | /** |
| 275 | 278 | * Returns list of available locales |
| 276 | 279 | * |
| 277 | - * @return array |
|
| 280 | + * @return string[] |
|
| 278 | 281 | */ |
| 279 | 282 | public function listLocaleDir() |
| 280 | 283 | { |
@@ -27,8 +27,11 @@ discard block |
||
| 27 | 27 | } else { |
| 28 | 28 | curl_setopt($ch, CURLOPT_USERAGENT, $useragent); |
| 29 | 29 | } |
| 30 | - if ($timeout == '') curl_setopt($ch, CURLOPT_TIMEOUT, 10); |
|
| 31 | - else curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); |
|
| 30 | + if ($timeout == '') { |
|
| 31 | + curl_setopt($ch, CURLOPT_TIMEOUT, 10); |
|
| 32 | + } else { |
|
| 33 | + curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); |
|
| 34 | + } |
|
| 32 | 35 | curl_setopt($ch, CURLOPT_HEADERFUNCTION, array('Common',"curlResponseHeaderCallback")); |
| 33 | 36 | if ($type == 'post') { |
| 34 | 37 | curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); |
@@ -73,8 +76,9 @@ discard block |
||
| 73 | 76 | |
| 74 | 77 | private function curlResponseHeaderCallback($ch, $headerLine) { |
| 75 | 78 | global $cookies; |
| 76 | - if (preg_match('/^Set-Cookie:\s*([^;]*)/mi', $headerLine, $cookie) == 1) |
|
| 77 | - $cookies[] = $cookie; |
|
| 79 | + if (preg_match('/^Set-Cookie:\s*([^;]*)/mi', $headerLine, $cookie) == 1) { |
|
| 80 | + $cookies[] = $cookie; |
|
| 81 | + } |
|
| 78 | 82 | return strlen($headerLine); // Needed by curl |
| 79 | 83 | } |
| 80 | 84 | |
@@ -84,10 +88,16 @@ discard block |
||
| 84 | 88 | * @return Array array of the tables in HTML page |
| 85 | 89 | */ |
| 86 | 90 | public function table2array($data) { |
| 87 | - if (!is_string($data)) return array(); |
|
| 88 | - if ($data == '') return array(); |
|
| 91 | + if (!is_string($data)) { |
|
| 92 | + return array(); |
|
| 93 | + } |
|
| 94 | + if ($data == '') { |
|
| 95 | + return array(); |
|
| 96 | + } |
|
| 89 | 97 | $html = str_get_html($data); |
| 90 | - if ($html === false) return array(); |
|
| 98 | + if ($html === false) { |
|
| 99 | + return array(); |
|
| 100 | + } |
|
| 91 | 101 | $tabledata=array(); |
| 92 | 102 | foreach($html->find('tr') as $element) |
| 93 | 103 | { |
@@ -122,7 +132,9 @@ discard block |
||
| 122 | 132 | */ |
| 123 | 133 | public function text2array($data) { |
| 124 | 134 | $html = str_get_html($data); |
| 125 | - if ($html === false) return array(); |
|
| 135 | + if ($html === false) { |
|
| 136 | + return array(); |
|
| 137 | + } |
|
| 126 | 138 | $tabledata=array(); |
| 127 | 139 | foreach($html->find('p') as $element) |
| 128 | 140 | { |
@@ -143,7 +155,9 @@ discard block |
||
| 143 | 155 | * @return Float Distance in $unit |
| 144 | 156 | */ |
| 145 | 157 | public function distance($lat, $lon, $latc, $lonc, $unit = 'km') { |
| 146 | - if ($lat == $latc && $lon == $lonc) return 0; |
|
| 158 | + if ($lat == $latc && $lon == $lonc) { |
|
| 159 | + return 0; |
|
| 160 | + } |
|
| 147 | 161 | $dist = rad2deg(acos(sin(deg2rad(floatval($lat)))*sin(deg2rad(floatval($latc)))+ cos(deg2rad(floatval($lat)))*cos(deg2rad(floatval($latc)))*cos(deg2rad(floatval($lon)-floatval($lonc)))))*60*1.1515; |
| 148 | 162 | if ($unit == "km") { |
| 149 | 163 | return round($dist * 1.609344); |
@@ -167,10 +181,16 @@ discard block |
||
| 167 | 181 | public function withinThreshold ($timeDifference, $distance) { |
| 168 | 182 | $x = abs($timeDifference); |
| 169 | 183 | $d = abs($distance); |
| 170 | - if ($x == 0 || $d == 0) return true; |
|
| 184 | + if ($x == 0 || $d == 0) { |
|
| 185 | + return true; |
|
| 186 | + } |
|
| 171 | 187 | // may be due to Internet jitter; distance is realistic |
| 172 | - if ($x < 0.7 && $d < 2000) return true; |
|
| 173 | - else return $d/$x < 1500*0.27778; // 1500 km/h max |
|
| 188 | + if ($x < 0.7 && $d < 2000) { |
|
| 189 | + return true; |
|
| 190 | + } else { |
|
| 191 | + return $d/$x < 1500*0.27778; |
|
| 192 | + } |
|
| 193 | + // 1500 km/h max |
|
| 174 | 194 | } |
| 175 | 195 | |
| 176 | 196 | |
@@ -230,7 +250,9 @@ discard block |
||
| 230 | 250 | public function hex2str($hex) { |
| 231 | 251 | $str = ''; |
| 232 | 252 | $hexln = strlen($hex); |
| 233 | - for($i=0;$i<$hexln;$i+=2) $str .= chr(hexdec(substr($hex,$i,2))); |
|
| 253 | + for($i=0;$i<$hexln;$i+=2) { |
|
| 254 | + $str .= chr(hexdec(substr($hex,$i,2))); |
|
| 255 | + } |
|
| 234 | 256 | return $str; |
| 235 | 257 | } |
| 236 | 258 | |
@@ -258,8 +280,11 @@ discard block |
||
| 258 | 280 | $b = $lat2 - $lat1; |
| 259 | 281 | $c = -($a*$lat1+$b*$lon1); |
| 260 | 282 | $d = $a*$lat3+$b*$lon3+$c; |
| 261 | - if ($d > -$approx && $d < $approx) return true; |
|
| 262 | - else return false; |
|
| 283 | + if ($d > -$approx && $d < $approx) { |
|
| 284 | + return true; |
|
| 285 | + } else { |
|
| 286 | + return false; |
|
| 287 | + } |
|
| 263 | 288 | } |
| 264 | 289 | |
| 265 | 290 | public function array_merge_noappend() { |
@@ -285,7 +310,9 @@ discard block |
||
| 285 | 310 | return $result; |
| 286 | 311 | } |
| 287 | 312 | $handle = @opendir('./locale'); |
| 288 | - if ($handle === false) return $result; |
|
| 313 | + if ($handle === false) { |
|
| 314 | + return $result; |
|
| 315 | + } |
|
| 289 | 316 | while (false !== ($file = readdir($handle))) { |
| 290 | 317 | $path = './locale'.'/'.$file.'/LC_MESSAGES/fam.mo'; |
| 291 | 318 | if ($file != "." && $file != ".." && @file_exists($path)) { |
@@ -6,13 +6,13 @@ discard block |
||
| 6 | 6 | //protected $cookies = array(); |
| 7 | 7 | |
| 8 | 8 | /** |
| 9 | - * Get data from form result |
|
| 10 | - * @param String $url form URL |
|
| 11 | - * @param String $type type of submit form method (get or post) |
|
| 12 | - * @param String|Array $data values form post method |
|
| 13 | - * @param Array $headers header to submit with the form |
|
| 14 | - * @return String the result |
|
| 15 | - */ |
|
| 9 | + * Get data from form result |
|
| 10 | + * @param String $url form URL |
|
| 11 | + * @param String $type type of submit form method (get or post) |
|
| 12 | + * @param String|Array $data values form post method |
|
| 13 | + * @param Array $headers header to submit with the form |
|
| 14 | + * @return String the result |
|
| 15 | + */ |
|
| 16 | 16 | public function getData($url, $type = 'get', $data = '', $headers = '',$cookie = '',$referer = '',$timeout = '',$useragent = '') { |
| 17 | 17 | $ch = curl_init(); |
| 18 | 18 | curl_setopt($ch, CURLOPT_URL, $url); |
@@ -67,7 +67,7 @@ discard block |
||
| 67 | 67 | return $this->getData($url,'get',$data,$headers,$clearanceCookie,$referer,$timeout,$useragent); |
| 68 | 68 | } |
| 69 | 69 | } else { |
| 70 | - return $result; |
|
| 70 | + return $result; |
|
| 71 | 71 | } |
| 72 | 72 | } |
| 73 | 73 | |
@@ -80,10 +80,10 @@ discard block |
||
| 80 | 80 | } |
| 81 | 81 | |
| 82 | 82 | /** |
| 83 | - * Convert a HTML table to an array |
|
| 84 | - * @param String $data HTML page |
|
| 85 | - * @return Array array of the tables in HTML page |
|
| 86 | - */ |
|
| 83 | + * Convert a HTML table to an array |
|
| 84 | + * @param String $data HTML page |
|
| 85 | + * @return Array array of the tables in HTML page |
|
| 86 | + */ |
|
| 87 | 87 | public function table2array($data) { |
| 88 | 88 | if (!is_string($data)) return array(); |
| 89 | 89 | if ($data == '') return array(); |
@@ -117,10 +117,10 @@ discard block |
||
| 117 | 117 | } |
| 118 | 118 | |
| 119 | 119 | /** |
| 120 | - * Convert <p> part of a HTML page to an array |
|
| 121 | - * @param String $data HTML page |
|
| 122 | - * @return Array array of the <p> in HTML page |
|
| 123 | - */ |
|
| 120 | + * Convert <p> part of a HTML page to an array |
|
| 121 | + * @param String $data HTML page |
|
| 122 | + * @return Array array of the <p> in HTML page |
|
| 123 | + */ |
|
| 124 | 124 | public function text2array($data) { |
| 125 | 125 | $html = str_get_html($data); |
| 126 | 126 | if ($html === false) return array(); |
@@ -135,14 +135,14 @@ discard block |
||
| 135 | 135 | } |
| 136 | 136 | |
| 137 | 137 | /** |
| 138 | - * Give distance between 2 coordonnates |
|
| 139 | - * @param Float $lat latitude of first point |
|
| 140 | - * @param Float $lon longitude of first point |
|
| 141 | - * @param Float $latc latitude of second point |
|
| 142 | - * @param Float $lonc longitude of second point |
|
| 143 | - * @param String $unit km else no unit used |
|
| 144 | - * @return Float Distance in $unit |
|
| 145 | - */ |
|
| 138 | + * Give distance between 2 coordonnates |
|
| 139 | + * @param Float $lat latitude of first point |
|
| 140 | + * @param Float $lon longitude of first point |
|
| 141 | + * @param Float $latc latitude of second point |
|
| 142 | + * @param Float $lonc longitude of second point |
|
| 143 | + * @param String $unit km else no unit used |
|
| 144 | + * @return Float Distance in $unit |
|
| 145 | + */ |
|
| 146 | 146 | public function distance($lat, $lon, $latc, $lonc, $unit = 'km') { |
| 147 | 147 | if ($lat == $latc && $lon == $lonc) return 0; |
| 148 | 148 | $dist = rad2deg(acos(sin(deg2rad(floatval($lat)))*sin(deg2rad(floatval($latc)))+ cos(deg2rad(floatval($lat)))*cos(deg2rad(floatval($latc)))*cos(deg2rad(floatval($lon)-floatval($lonc)))))*60*1.1515; |
@@ -160,11 +160,11 @@ discard block |
||
| 160 | 160 | } |
| 161 | 161 | |
| 162 | 162 | /** |
| 163 | - * Check is distance realistic |
|
| 164 | - * @param int $timeDifference the time between the reception of both messages |
|
| 165 | - * @param float $distance distance covered |
|
| 166 | - * @return whether distance is realistic |
|
| 167 | - */ |
|
| 163 | + * Check is distance realistic |
|
| 164 | + * @param int $timeDifference the time between the reception of both messages |
|
| 165 | + * @param float $distance distance covered |
|
| 166 | + * @return whether distance is realistic |
|
| 167 | + */ |
|
| 168 | 168 | public function withinThreshold ($timeDifference, $distance) { |
| 169 | 169 | $x = abs($timeDifference); |
| 170 | 170 | $d = abs($distance); |
@@ -182,7 +182,7 @@ discard block |
||
| 182 | 182 | } |
| 183 | 183 | |
| 184 | 184 | public function isInteger($input){ |
| 185 | - return(ctype_digit(strval($input))); |
|
| 185 | + return(ctype_digit(strval($input))); |
|
| 186 | 186 | } |
| 187 | 187 | |
| 188 | 188 | |
@@ -198,11 +198,11 @@ discard block |
||
| 198 | 198 | } |
| 199 | 199 | |
| 200 | 200 | /** |
| 201 | - * Copy folder contents |
|
| 202 | - * @param string $source Source path |
|
| 203 | - * @param string $dest Destination path |
|
| 204 | - * @return bool Returns true on success, false on failure |
|
| 205 | - */ |
|
| 201 | + * Copy folder contents |
|
| 202 | + * @param string $source Source path |
|
| 203 | + * @param string $dest Destination path |
|
| 204 | + * @return bool Returns true on success, false on failure |
|
| 205 | + */ |
|
| 206 | 206 | public function xcopy($source, $dest) |
| 207 | 207 | { |
| 208 | 208 | $files = glob($source.'*.*'); |
@@ -214,20 +214,20 @@ discard block |
||
| 214 | 214 | } |
| 215 | 215 | |
| 216 | 216 | /** |
| 217 | - * Check if an url exist |
|
| 218 | - * @param String $url url to check |
|
| 219 | - * @return bool Return true on succes false on failure |
|
| 220 | - */ |
|
| 217 | + * Check if an url exist |
|
| 218 | + * @param String $url url to check |
|
| 219 | + * @return bool Return true on succes false on failure |
|
| 220 | + */ |
|
| 221 | 221 | public function urlexist($url){ |
| 222 | 222 | $headers=get_headers($url); |
| 223 | 223 | return stripos($headers[0],"200 OK")?true:false; |
| 224 | 224 | } |
| 225 | 225 | |
| 226 | 226 | /** |
| 227 | - * Convert hexa to string |
|
| 228 | - * @param String $hex data in hexa |
|
| 229 | - * @return String Return result |
|
| 230 | - */ |
|
| 227 | + * Convert hexa to string |
|
| 228 | + * @param String $hex data in hexa |
|
| 229 | + * @return String Return result |
|
| 230 | + */ |
|
| 231 | 231 | public function hex2str($hex) { |
| 232 | 232 | $str = ''; |
| 233 | 233 | $hexln = strlen($hex); |
@@ -275,9 +275,9 @@ discard block |
||
| 275 | 275 | } |
| 276 | 276 | |
| 277 | 277 | /** |
| 278 | - * Returns list of available locales |
|
| 279 | - * |
|
| 280 | - * @return array |
|
| 278 | + * Returns list of available locales |
|
| 279 | + * |
|
| 280 | + * @return array |
|
| 281 | 281 | */ |
| 282 | 282 | public function listLocaleDir() |
| 283 | 283 | { |
@@ -13,13 +13,13 @@ discard block |
||
| 13 | 13 | * @param Array $headers header to submit with the form |
| 14 | 14 | * @return String the result |
| 15 | 15 | */ |
| 16 | - public function getData($url, $type = 'get', $data = '', $headers = '',$cookie = '',$referer = '',$timeout = '',$useragent = '') { |
|
| 16 | + public function getData($url, $type = 'get', $data = '', $headers = '', $cookie = '', $referer = '', $timeout = '', $useragent = '') { |
|
| 17 | 17 | $ch = curl_init(); |
| 18 | 18 | curl_setopt($ch, CURLOPT_URL, $url); |
| 19 | 19 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
| 20 | 20 | curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); |
| 21 | 21 | curl_setopt($ch, CURLINFO_HEADER_OUT, true); |
| 22 | - curl_setopt($ch,CURLOPT_ENCODING , "gzip"); |
|
| 22 | + curl_setopt($ch, CURLOPT_ENCODING, "gzip"); |
|
| 23 | 23 | //curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.2) Gecko/20090729 Firefox/3.5.2 GTB5'); |
| 24 | 24 | // curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (X11; Linux x86_64; rv:42.0) Gecko/20100101 Firefox/42.0'); |
| 25 | 25 | if ($useragent == '') { |
@@ -29,13 +29,13 @@ discard block |
||
| 29 | 29 | } |
| 30 | 30 | if ($timeout == '') curl_setopt($ch, CURLOPT_TIMEOUT, 10); |
| 31 | 31 | else curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); |
| 32 | - curl_setopt($ch, CURLOPT_HEADERFUNCTION, array('Common',"curlResponseHeaderCallback")); |
|
| 32 | + curl_setopt($ch, CURLOPT_HEADERFUNCTION, array('Common', "curlResponseHeaderCallback")); |
|
| 33 | 33 | if ($type == 'post') { |
| 34 | 34 | curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); |
| 35 | 35 | if (is_array($data)) { |
| 36 | 36 | curl_setopt($ch, CURLOPT_POST, count($data)); |
| 37 | 37 | $data_string = ''; |
| 38 | - foreach($data as $key=>$value) { $data_string .= $key.'='.$value.'&'; } |
|
| 38 | + foreach ($data as $key=>$value) { $data_string .= $key.'='.$value.'&'; } |
|
| 39 | 39 | rtrim($data_string, '&'); |
| 40 | 40 | curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string); |
| 41 | 41 | } else { |
@@ -47,7 +47,7 @@ discard block |
||
| 47 | 47 | } |
| 48 | 48 | if ($cookie != '') { |
| 49 | 49 | if (is_array($cookie)) { |
| 50 | - curl_setopt($ch, CURLOPT_COOKIE, implode($cookie,';')); |
|
| 50 | + curl_setopt($ch, CURLOPT_COOKIE, implode($cookie, ';')); |
|
| 51 | 51 | } else { |
| 52 | 52 | curl_setopt($ch, CURLOPT_COOKIE, $cookie); |
| 53 | 53 | } |
@@ -58,13 +58,13 @@ discard block |
||
| 58 | 58 | $result = curl_exec($ch); |
| 59 | 59 | $info = curl_getinfo($ch); |
| 60 | 60 | curl_close($ch); |
| 61 | - if ($info['http_code'] == '503' && strstr($result,'DDoS protection by CloudFlare')) { |
|
| 61 | + if ($info['http_code'] == '503' && strstr($result, 'DDoS protection by CloudFlare')) { |
|
| 62 | 62 | echo "Cloudflare Detected\n"; |
| 63 | 63 | require_once(dirname(__FILE__).'/libs/cloudflare-bypass/libraries/cloudflareClass.php'); |
| 64 | 64 | $useragent = UAgent::random(); |
| 65 | 65 | cloudflare::useUserAgent($useragent); |
| 66 | 66 | if ($clearanceCookie = cloudflare::bypass($url)) { |
| 67 | - return $this->getData($url,'get',$data,$headers,$clearanceCookie,$referer,$timeout,$useragent); |
|
| 67 | + return $this->getData($url, 'get', $data, $headers, $clearanceCookie, $referer, $timeout, $useragent); |
|
| 68 | 68 | } |
| 69 | 69 | } else { |
| 70 | 70 | return $result; |
@@ -89,27 +89,27 @@ discard block |
||
| 89 | 89 | if ($data == '') return array(); |
| 90 | 90 | $html = str_get_html($data); |
| 91 | 91 | if ($html === false) return array(); |
| 92 | - $tabledata=array(); |
|
| 93 | - foreach($html->find('tr') as $element) |
|
| 92 | + $tabledata = array(); |
|
| 93 | + foreach ($html->find('tr') as $element) |
|
| 94 | 94 | { |
| 95 | 95 | $td = array(); |
| 96 | - foreach( $element->find('th') as $row) |
|
| 96 | + foreach ($element->find('th') as $row) |
|
| 97 | 97 | { |
| 98 | 98 | $td [] = trim($row->plaintext); |
| 99 | 99 | } |
| 100 | - $td=array_filter($td); |
|
| 100 | + $td = array_filter($td); |
|
| 101 | 101 | $tabledata[] = $td; |
| 102 | 102 | |
| 103 | 103 | $td = array(); |
| 104 | 104 | $tdi = array(); |
| 105 | - foreach( $element->find('td') as $row) |
|
| 105 | + foreach ($element->find('td') as $row) |
|
| 106 | 106 | { |
| 107 | 107 | $td [] = trim($row->plaintext); |
| 108 | 108 | $tdi [] = trim($row->innertext); |
| 109 | 109 | } |
| 110 | - $td=array_filter($td); |
|
| 111 | - $tdi=array_filter($tdi); |
|
| 112 | - $tabledata[]=array_merge($td,$tdi); |
|
| 110 | + $td = array_filter($td); |
|
| 111 | + $tdi = array_filter($tdi); |
|
| 112 | + $tabledata[] = array_merge($td, $tdi); |
|
| 113 | 113 | } |
| 114 | 114 | $html->clear(); |
| 115 | 115 | unset($html); |
@@ -124,8 +124,8 @@ discard block |
||
| 124 | 124 | public function text2array($data) { |
| 125 | 125 | $html = str_get_html($data); |
| 126 | 126 | if ($html === false) return array(); |
| 127 | - $tabledata=array(); |
|
| 128 | - foreach($html->find('p') as $element) |
|
| 127 | + $tabledata = array(); |
|
| 128 | + foreach ($html->find('p') as $element) |
|
| 129 | 129 | { |
| 130 | 130 | $tabledata [] = trim($element->plaintext); |
| 131 | 131 | } |
@@ -145,11 +145,11 @@ discard block |
||
| 145 | 145 | */ |
| 146 | 146 | public function distance($lat, $lon, $latc, $lonc, $unit = 'km') { |
| 147 | 147 | if ($lat == $latc && $lon == $lonc) return 0; |
| 148 | - $dist = rad2deg(acos(sin(deg2rad(floatval($lat)))*sin(deg2rad(floatval($latc)))+ cos(deg2rad(floatval($lat)))*cos(deg2rad(floatval($latc)))*cos(deg2rad(floatval($lon)-floatval($lonc)))))*60*1.1515; |
|
| 148 | + $dist = rad2deg(acos(sin(deg2rad(floatval($lat)))*sin(deg2rad(floatval($latc))) + cos(deg2rad(floatval($lat)))*cos(deg2rad(floatval($latc)))*cos(deg2rad(floatval($lon) - floatval($lonc)))))*60*1.1515; |
|
| 149 | 149 | if ($unit == "km") { |
| 150 | - return round($dist * 1.609344); |
|
| 150 | + return round($dist*1.609344); |
|
| 151 | 151 | } elseif ($unit == "m") { |
| 152 | - return round($dist * 1.609344 * 1000); |
|
| 152 | + return round($dist*1.609344*1000); |
|
| 153 | 153 | } elseif ($unit == "mile" || $unit == "mi") { |
| 154 | 154 | return round($dist); |
| 155 | 155 | } elseif ($unit == "nm") { |
@@ -165,7 +165,7 @@ discard block |
||
| 165 | 165 | * @param float $distance distance covered |
| 166 | 166 | * @return whether distance is realistic |
| 167 | 167 | */ |
| 168 | - public function withinThreshold ($timeDifference, $distance) { |
|
| 168 | + public function withinThreshold($timeDifference, $distance) { |
|
| 169 | 169 | $x = abs($timeDifference); |
| 170 | 170 | $d = abs($distance); |
| 171 | 171 | if ($x == 0 || $d == 0) return true; |
@@ -181,12 +181,12 @@ discard block |
||
| 181 | 181 | return ($array !== array_values($array)); |
| 182 | 182 | } |
| 183 | 183 | |
| 184 | - public function isInteger($input){ |
|
| 184 | + public function isInteger($input) { |
|
| 185 | 185 | return(ctype_digit(strval($input))); |
| 186 | 186 | } |
| 187 | 187 | |
| 188 | 188 | |
| 189 | - public function convertDec($dms,$latlong) { |
|
| 189 | + public function convertDec($dms, $latlong) { |
|
| 190 | 190 | if ($latlong == 'latitude') { |
| 191 | 191 | $deg = substr($dms, 0, 2); |
| 192 | 192 | $min = substr($dms, 2, 4); |
@@ -194,7 +194,7 @@ discard block |
||
| 194 | 194 | $deg = substr($dms, 0, 3); |
| 195 | 195 | $min = substr($dms, 3, 5); |
| 196 | 196 | } |
| 197 | - return $deg+(($min*60)/3600); |
|
| 197 | + return $deg + (($min*60)/3600); |
|
| 198 | 198 | } |
| 199 | 199 | |
| 200 | 200 | /** |
@@ -206,8 +206,8 @@ discard block |
||
| 206 | 206 | public function xcopy($source, $dest) |
| 207 | 207 | { |
| 208 | 208 | $files = glob($source.'*.*'); |
| 209 | - foreach($files as $file){ |
|
| 210 | - $file_to_go = str_replace($source,$dest,$file); |
|
| 209 | + foreach ($files as $file) { |
|
| 210 | + $file_to_go = str_replace($source, $dest, $file); |
|
| 211 | 211 | copy($file, $file_to_go); |
| 212 | 212 | } |
| 213 | 213 | return true; |
@@ -218,9 +218,9 @@ discard block |
||
| 218 | 218 | * @param String $url url to check |
| 219 | 219 | * @return bool Return true on succes false on failure |
| 220 | 220 | */ |
| 221 | - public function urlexist($url){ |
|
| 222 | - $headers=get_headers($url); |
|
| 223 | - return stripos($headers[0],"200 OK")?true:false; |
|
| 221 | + public function urlexist($url) { |
|
| 222 | + $headers = get_headers($url); |
|
| 223 | + return stripos($headers[0], "200 OK") ? true : false; |
|
| 224 | 224 | } |
| 225 | 225 | |
| 226 | 226 | /** |
@@ -231,7 +231,7 @@ discard block |
||
| 231 | 231 | public function hex2str($hex) { |
| 232 | 232 | $str = ''; |
| 233 | 233 | $hexln = strlen($hex); |
| 234 | - for($i=0;$i<$hexln;$i+=2) $str .= chr(hexdec(substr($hex,$i,2))); |
|
| 234 | + for ($i = 0; $i < $hexln; $i += 2) $str .= chr(hexdec(substr($hex, $i, 2))); |
|
| 235 | 235 | return $str; |
| 236 | 236 | } |
| 237 | 237 | |
@@ -240,33 +240,33 @@ discard block |
||
| 240 | 240 | //difference in longitudinal coordinates |
| 241 | 241 | $dLon = deg2rad($lon2) - deg2rad($lon1); |
| 242 | 242 | //difference in the phi of latitudinal coordinates |
| 243 | - $dPhi = log(tan(deg2rad($lat2) / 2 + pi() / 4) / tan(deg2rad($lat1) / 2 + pi() / 4)); |
|
| 243 | + $dPhi = log(tan(deg2rad($lat2)/2 + pi()/4)/tan(deg2rad($lat1)/2 + pi()/4)); |
|
| 244 | 244 | //we need to recalculate $dLon if it is greater than pi |
| 245 | - if(abs($dLon) > pi()) { |
|
| 246 | - if($dLon > 0) { |
|
| 247 | - $dLon = (2 * pi() - $dLon) * -1; |
|
| 245 | + if (abs($dLon) > pi()) { |
|
| 246 | + if ($dLon > 0) { |
|
| 247 | + $dLon = (2*pi() - $dLon)*-1; |
|
| 248 | 248 | } else { |
| 249 | - $dLon = 2 * pi() + $dLon; |
|
| 249 | + $dLon = 2*pi() + $dLon; |
|
| 250 | 250 | } |
| 251 | 251 | } |
| 252 | 252 | //return the angle, normalized |
| 253 | - return (rad2deg(atan2($dLon, $dPhi)) + 360) % 360; |
|
| 253 | + return (rad2deg(atan2($dLon, $dPhi)) + 360)%360; |
|
| 254 | 254 | } |
| 255 | 255 | |
| 256 | - public function checkLine($lat1,$lon1,$lat2,$lon2,$lat3,$lon3,$approx = 0.1) { |
|
| 256 | + public function checkLine($lat1, $lon1, $lat2, $lon2, $lat3, $lon3, $approx = 0.1) { |
|
| 257 | 257 | //$a = ($lon2-$lon1)*$lat3+($lat2-$lat1)*$lon3+($lat1*$lon2+$lat2*$lon1); |
| 258 | - $a = -($lon2-$lon1); |
|
| 258 | + $a = -($lon2 - $lon1); |
|
| 259 | 259 | $b = $lat2 - $lat1; |
| 260 | - $c = -($a*$lat1+$b*$lon1); |
|
| 261 | - $d = $a*$lat3+$b*$lon3+$c; |
|
| 260 | + $c = -($a*$lat1 + $b*$lon1); |
|
| 261 | + $d = $a*$lat3 + $b*$lon3 + $c; |
|
| 262 | 262 | if ($d > -$approx && $d < $approx) return true; |
| 263 | 263 | else return false; |
| 264 | 264 | } |
| 265 | 265 | |
| 266 | 266 | public function array_merge_noappend() { |
| 267 | 267 | $output = array(); |
| 268 | - foreach(func_get_args() as $array) { |
|
| 269 | - foreach($array as $key => $value) { |
|
| 268 | + foreach (func_get_args() as $array) { |
|
| 269 | + foreach ($array as $key => $value) { |
|
| 270 | 270 | $output[$key] = isset($output[$key]) ? |
| 271 | 271 | array_merge($output[$key], $value) : $value; |
| 272 | 272 | } |
@@ -297,34 +297,34 @@ discard block |
||
| 297 | 297 | return $result; |
| 298 | 298 | } |
| 299 | 299 | |
| 300 | - public function nextcoord($latitude, $longitude, $speed, $heading, $archivespeed = 1){ |
|
| 300 | + public function nextcoord($latitude, $longitude, $speed, $heading, $archivespeed = 1) { |
|
| 301 | 301 | global $globalMapRefresh; |
| 302 | 302 | $distance = ($speed*0.514444*$globalMapRefresh*$archivespeed)/1000; |
| 303 | 303 | $r = 6378; |
| 304 | 304 | $latitude = deg2rad($latitude); |
| 305 | 305 | $longitude = deg2rad($longitude); |
| 306 | 306 | $bearing = deg2rad($heading); |
| 307 | - $latitude2 = asin( (sin($latitude) * cos($distance/$r)) + (cos($latitude) * sin($distance/$r) * cos($bearing)) ); |
|
| 308 | - $longitude2 = $longitude + atan2( sin($bearing)*sin($distance/$r)*cos($latitude), cos($distance/$r)-(sin($latitude)*sin($latitude2)) ); |
|
| 309 | - return array('latitude' => number_format(rad2deg($latitude2),5,'.',''),'longitude' => number_format(rad2deg($longitude2),5,'.','')); |
|
| 307 | + $latitude2 = asin((sin($latitude)*cos($distance/$r)) + (cos($latitude)*sin($distance/$r)*cos($bearing))); |
|
| 308 | + $longitude2 = $longitude + atan2(sin($bearing)*sin($distance/$r)*cos($latitude), cos($distance/$r) - (sin($latitude)*sin($latitude2))); |
|
| 309 | + return array('latitude' => number_format(rad2deg($latitude2), 5, '.', ''), 'longitude' => number_format(rad2deg($longitude2), 5, '.', '')); |
|
| 310 | 310 | } |
| 311 | 311 | |
| 312 | - public function getCoordfromDistanceBearing($latitude,$longitude,$bearing,$distance) { |
|
| 312 | + public function getCoordfromDistanceBearing($latitude, $longitude, $bearing, $distance) { |
|
| 313 | 313 | // distance in meter |
| 314 | 314 | $R = 6378.14; |
| 315 | - $latitude1 = $latitude * (M_PI/180); |
|
| 316 | - $longitude1 = $longitude * (M_PI/180); |
|
| 317 | - $brng = $bearing * (M_PI/180); |
|
| 315 | + $latitude1 = $latitude*(M_PI/180); |
|
| 316 | + $longitude1 = $longitude*(M_PI/180); |
|
| 317 | + $brng = $bearing*(M_PI/180); |
|
| 318 | 318 | $d = $distance; |
| 319 | 319 | |
| 320 | 320 | $latitude2 = asin(sin($latitude1)*cos($d/$R) + cos($latitude1)*sin($d/$R)*cos($brng)); |
| 321 | - $longitude2 = $longitude1 + atan2(sin($brng)*sin($d/$R)*cos($latitude1),cos($d/$R)-sin($latitude1)*sin($latitude2)); |
|
| 321 | + $longitude2 = $longitude1 + atan2(sin($brng)*sin($d/$R)*cos($latitude1), cos($d/$R) - sin($latitude1)*sin($latitude2)); |
|
| 322 | 322 | |
| 323 | - $latitude2 = $latitude2 * (180/M_PI); |
|
| 324 | - $longitude2 = $longitude2 * (180/M_PI); |
|
| 323 | + $latitude2 = $latitude2*(180/M_PI); |
|
| 324 | + $longitude2 = $longitude2*(180/M_PI); |
|
| 325 | 325 | |
| 326 | - $flat = round ($latitude2,6); |
|
| 327 | - $flong = round ($longitude2,6); |
|
| 326 | + $flat = round($latitude2, 6); |
|
| 327 | + $flong = round($longitude2, 6); |
|
| 328 | 328 | /* |
| 329 | 329 | $dx = $distance*cos($bearing); |
| 330 | 330 | $dy = $distance*sin($bearing); |
@@ -333,7 +333,7 @@ discard block |
||
| 333 | 333 | $flong = $longitude + $dlong; |
| 334 | 334 | $flat = $latitude + $dlat; |
| 335 | 335 | */ |
| 336 | - return array('latitude' => $flat,'longitude' => $flong); |
|
| 336 | + return array('latitude' => $flat, 'longitude' => $flong); |
|
| 337 | 337 | } |
| 338 | 338 | } |
| 339 | 339 | ?> |
| 340 | 340 | \ No newline at end of file |
@@ -77,7 +77,7 @@ |
||
| 77 | 77 | /** |
| 78 | 78 | * Returns list of available locales |
| 79 | 79 | * |
| 80 | - * @return array |
|
| 80 | + * @return string[] |
|
| 81 | 81 | */ |
| 82 | 82 | public function listLocaleDir() |
| 83 | 83 | { |
@@ -1,9 +1,9 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | if (!function_exists("gettext")) { |
| 4 | - function _($text) { |
|
| 5 | - return $text; |
|
| 6 | - } |
|
| 4 | + function _($text) { |
|
| 5 | + return $text; |
|
| 6 | + } |
|
| 7 | 7 | } else { |
| 8 | 8 | if (isset($_COOKIE['language']) && $_COOKIE['language'] != 'en_GB' && (isset($globalTranslate) && $globalTranslate)) { |
| 9 | 9 | $Language = new Language(); |
@@ -75,9 +75,9 @@ discard block |
||
| 75 | 75 | ); |
| 76 | 76 | |
| 77 | 77 | /** |
| 78 | - * Returns list of available locales |
|
| 79 | - * |
|
| 80 | - * @return array |
|
| 78 | + * Returns list of available locales |
|
| 79 | + * |
|
| 80 | + * @return array |
|
| 81 | 81 | */ |
| 82 | 82 | public function listLocaleDir() |
| 83 | 83 | { |
@@ -103,9 +103,9 @@ discard block |
||
| 103 | 103 | } |
| 104 | 104 | |
| 105 | 105 | /** |
| 106 | - * Returns list of available languages |
|
| 107 | - * |
|
| 108 | - * @return array |
|
| 106 | + * Returns list of available languages |
|
| 107 | + * |
|
| 108 | + * @return array |
|
| 109 | 109 | */ |
| 110 | 110 | public function getLanguages() |
| 111 | 111 | { |
@@ -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 | /** |
@@ -86,7 +86,9 @@ discard block |
||
| 86 | 86 | return $result; |
| 87 | 87 | } |
| 88 | 88 | $handle = @opendir('./locale'); |
| 89 | - if ($handle === false) return $result; |
|
| 89 | + if ($handle === false) { |
|
| 90 | + return $result; |
|
| 91 | + } |
|
| 90 | 92 | while (false !== ($file = readdir($handle))) { |
| 91 | 93 | $path = './locale'.'/'.$file.'/LC_MESSAGES/fam.mo'; |
| 92 | 94 | if ($file != "." && $file != ".." && @file_exists($path)) { |
@@ -112,7 +114,9 @@ discard block |
||
| 112 | 114 | $available = $this->listLocaleDir(); |
| 113 | 115 | $allAvailableLanguages = array(); |
| 114 | 116 | foreach ($available as $lang) { |
| 115 | - if (isset($this->all_languages[$lang])) $allAvailableLanguages[$lang] = $this->all_languages[$lang]; |
|
| 117 | + if (isset($this->all_languages[$lang])) { |
|
| 118 | + $allAvailableLanguages[$lang] = $this->all_languages[$lang]; |
|
| 119 | + } |
|
| 116 | 120 | } |
| 117 | 121 | return $allAvailableLanguages; |
| 118 | 122 | } |
@@ -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,9 +6,13 @@ discard block |
||
| 6 | 6 | // Not yet finished, no CRC checks |
| 7 | 7 | //echo $buffer."\n"; |
| 8 | 8 | $typehex = substr($buffer,0,1); |
| 9 | - if ($typehex == '*' || $typehex == ':') $hex = substr($buffer,1,-1); |
|
| 10 | - elseif ($typehex == '@' || $typehex == '%') $hex = substr($buffer,13,-13); |
|
| 11 | - else $hex = substr($buffer,1,-1); |
|
| 9 | + if ($typehex == '*' || $typehex == ':') { |
|
| 10 | + $hex = substr($buffer,1,-1); |
|
| 11 | + } elseif ($typehex == '@' || $typehex == '%') { |
|
| 12 | + $hex = substr($buffer,13,-13); |
|
| 13 | + } else { |
|
| 14 | + $hex = substr($buffer,1,-1); |
|
| 15 | + } |
|
| 12 | 16 | $bin = gmp_strval( gmp_init($hex,16), 2); |
| 13 | 17 | //if (strlen($hex) == 28 && $this->parityCheck($hex,$bin)) { |
| 14 | 18 | if (strlen($hex) == 28) { |
@@ -51,8 +55,9 @@ discard block |
||
| 51 | 55 | // 131072 is 2^17 since CPR latitude and longitude are encoded in 17 bits. |
| 52 | 56 | $cprlat = intval(substr($bin,54,17),2)/131072.0; |
| 53 | 57 | $cprlon = intval(substr($bin,71,17),2)/131072.0; |
| 54 | - if ($oe == 0) $this::$latlon[$icao] = array('latitude' => $cprlat,'longitude' => $cprlon,'created' => time()); |
|
| 55 | - elseif (isset($this::$latlon[$icao]) && (time() - $this::$latlon[$icao]['created']) < 10) { |
|
| 58 | + if ($oe == 0) { |
|
| 59 | + $this::$latlon[$icao] = array('latitude' => $cprlat,'longitude' => $cprlon,'created' => time()); |
|
| 60 | + } elseif (isset($this::$latlon[$icao]) && (time() - $this::$latlon[$icao]['created']) < 10) { |
|
| 56 | 61 | $cprlat_odd = $cprlat; |
| 57 | 62 | $cprlon_odd = $cprlon; |
| 58 | 63 | $cprlat_even = $this::$latlon[$icao]['latitude']; |
@@ -61,8 +66,12 @@ discard block |
||
| 61 | 66 | $j = 59*$cprlat_even-60*$cprlat_odd+0.5; |
| 62 | 67 | $lat_even = (360.0/60)*($j%60+$cprlat_even); |
| 63 | 68 | $lat_odd = (360.0/59)*($j%59+$cprlat_odd); |
| 64 | - if ($lat_even >= 270) $lat_even = $lat_even - 360; |
|
| 65 | - if ($lat_odd >= 270) $lat_odd = $lat_odd - 360; |
|
| 69 | + if ($lat_even >= 270) { |
|
| 70 | + $lat_even = $lat_even - 360; |
|
| 71 | + } |
|
| 72 | + if ($lat_odd >= 270) { |
|
| 73 | + $lat_odd = $lat_odd - 360; |
|
| 74 | + } |
|
| 66 | 75 | // check latitude zone |
| 67 | 76 | if ($this->cprNL($lat_even) == $this->cprNL($lat_odd)) { |
| 68 | 77 | if ($this::$latlon[$icao]['created'] > time()) { |
@@ -70,7 +79,9 @@ discard block |
||
| 70 | 79 | $m = floor($cprlon_even*($this->cprNL($lat_even)-1) - $cprlon_odd * $this->cprNL($lat_even)+0.5); |
| 71 | 80 | $lon = (360.0/$ni)*($m%$ni+$cprlon_even); |
| 72 | 81 | $lat = $lat_even; |
| 73 | - if ($lon > 180) $lon = $lon -360; |
|
| 82 | + if ($lon > 180) { |
|
| 83 | + $lon = $lon -360; |
|
| 84 | + } |
|
| 74 | 85 | if ($lat > -91 && $lat < 91 && $lon > -181 && $lon < 181) { |
| 75 | 86 | //if ($globalDebug) echo 'cs : '.$cs.' - hex : '.$hex.' - lat : '.$lat.' - lon : '.$lon; |
| 76 | 87 | $data['latitude'] = $lat; |
@@ -81,14 +92,18 @@ discard block |
||
| 81 | 92 | $m = floor($cprlon_even*($this->cprNL($lat_odd)-1) - $cprlon_odd * $this->cprNL($lat_odd)+0.5); |
| 82 | 93 | $lon = (360.0/$ni)*($m%$ni+$cprlon_odd); |
| 83 | 94 | $lat = $lat_odd; |
| 84 | - if ($lon > 180) $lon = $lon -360; |
|
| 95 | + if ($lon > 180) { |
|
| 96 | + $lon = $lon -360; |
|
| 97 | + } |
|
| 85 | 98 | if ($lat > -91 && $lat < 91 && $lon > -181 && $lon < 181) { |
| 86 | 99 | //if ($globalDebug) echo 'icao : '.$icao.' - hex : '.$hex.' - lat : '.$lat.' - lon : '.$lon.' second'."\n"; |
| 87 | 100 | $data['latitude'] = $lat; |
| 88 | 101 | $data['longitude'] = $lon; |
| 89 | 102 | } |
| 90 | 103 | } |
| 91 | - } else echo "Not cprNL"; |
|
| 104 | + } else { |
|
| 105 | + echo "Not cprNL"; |
|
| 106 | + } |
|
| 92 | 107 | unset($this::$latlon[$icao]); |
| 93 | 108 | } |
| 94 | 109 | } elseif ($tc == 19) { |
@@ -97,11 +112,17 @@ discard block |
||
| 97 | 112 | $v_ew = intval(substr($bin,46,10),2); |
| 98 | 113 | $v_ns_dir = intval(substr($bin,56,1)); |
| 99 | 114 | $v_ns = intval(substr($bin,57,10),2); |
| 100 | - if ($v_ew_dir) $v_ew = -1*$v_ew; |
|
| 101 | - if ($v_ns_dir) $v_ns = -1*$v_ns; |
|
| 115 | + if ($v_ew_dir) { |
|
| 116 | + $v_ew = -1*$v_ew; |
|
| 117 | + } |
|
| 118 | + if ($v_ns_dir) { |
|
| 119 | + $v_ns = -1*$v_ns; |
|
| 120 | + } |
|
| 102 | 121 | $speed = sqrt($v_ns*$v_ns+$v_ew*$v_ew); |
| 103 | 122 | $heading = atan2($v_ew,$v_ns)*360.0/(2*pi()); |
| 104 | - if ($heading <0) $heading = $heading+360; |
|
| 123 | + if ($heading <0) { |
|
| 124 | + $heading = $heading+360; |
|
| 125 | + } |
|
| 105 | 126 | $data['speed'] = $speed; |
| 106 | 127 | $data['heading'] = $heading; |
| 107 | 128 | } |
@@ -116,72 +137,194 @@ discard block |
||
| 116 | 137 | |
| 117 | 138 | function cprNL($lat) { |
| 118 | 139 | //Lookup table to convert the latitude to index. |
| 119 | - if ($lat < 0) $lat = -$lat; // Table is simmetric about the equator. |
|
| 120 | - if ($lat < 10.47047130) return 59; |
|
| 121 | - if ($lat < 14.82817437) return 58; |
|
| 122 | - if ($lat < 18.18626357) return 57; |
|
| 123 | - if ($lat < 21.02939493) return 56; |
|
| 124 | - if ($lat < 23.54504487) return 55; |
|
| 125 | - if ($lat < 25.82924707) return 54; |
|
| 126 | - if ($lat < 27.93898710) return 53; |
|
| 127 | - if ($lat < 29.91135686) return 52; |
|
| 128 | - if ($lat < 31.77209708) return 51; |
|
| 129 | - if ($lat < 33.53993436) return 50; |
|
| 130 | - if ($lat < 35.22899598) return 49; |
|
| 131 | - if ($lat < 36.85025108) return 48; |
|
| 132 | - if ($lat < 38.41241892) return 47; |
|
| 133 | - if ($lat < 39.92256684) return 46; |
|
| 134 | - if ($lat < 41.38651832) return 45; |
|
| 135 | - if ($lat < 42.80914012) return 44; |
|
| 136 | - if ($lat < 44.19454951) return 43; |
|
| 137 | - if ($lat < 45.54626723) return 42; |
|
| 138 | - if ($lat < 46.86733252) return 41; |
|
| 139 | - if ($lat < 48.16039128) return 40; |
|
| 140 | - if ($lat < 49.42776439) return 39; |
|
| 141 | - if ($lat < 50.67150166) return 38; |
|
| 142 | - if ($lat < 51.89342469) return 37; |
|
| 143 | - if ($lat < 53.09516153) return 36; |
|
| 144 | - if ($lat < 54.27817472) return 35; |
|
| 145 | - if ($lat < 55.44378444) return 34; |
|
| 146 | - if ($lat < 56.59318756) return 33; |
|
| 147 | - if ($lat < 57.72747354) return 32; |
|
| 148 | - if ($lat < 58.84763776) return 31; |
|
| 149 | - if ($lat < 59.95459277) return 30; |
|
| 150 | - if ($lat < 61.04917774) return 29; |
|
| 151 | - if ($lat < 62.13216659) return 28; |
|
| 152 | - if ($lat < 63.20427479) return 27; |
|
| 153 | - if ($lat < 64.26616523) return 26; |
|
| 154 | - if ($lat < 65.31845310) return 25; |
|
| 155 | - if ($lat < 66.36171008) return 24; |
|
| 156 | - if ($lat < 67.39646774) return 23; |
|
| 157 | - if ($lat < 68.42322022) return 22; |
|
| 158 | - if ($lat < 69.44242631) return 21; |
|
| 159 | - if ($lat < 70.45451075) return 20; |
|
| 160 | - if ($lat < 71.45986473) return 19; |
|
| 161 | - if ($lat < 72.45884545) return 18; |
|
| 162 | - if ($lat < 73.45177442) return 17; |
|
| 163 | - if ($lat < 74.43893416) return 16; |
|
| 164 | - if ($lat < 75.42056257) return 15; |
|
| 165 | - if ($lat < 76.39684391) return 14; |
|
| 166 | - if ($lat < 77.36789461) return 13; |
|
| 167 | - if ($lat < 78.33374083) return 12; |
|
| 168 | - if ($lat < 79.29428225) return 11; |
|
| 169 | - if ($lat < 80.24923213) return 10; |
|
| 170 | - if ($lat < 81.19801349) return 9; |
|
| 171 | - if ($lat < 82.13956981) return 8; |
|
| 172 | - if ($lat < 83.07199445) return 7; |
|
| 173 | - if ($lat < 83.99173563) return 6; |
|
| 174 | - if ($lat < 84.89166191) return 5; |
|
| 175 | - if ($lat < 85.75541621) return 4; |
|
| 176 | - if ($lat < 86.53536998) return 3; |
|
| 177 | - if ($lat < 87.00000000) return 2; |
|
| 140 | + if ($lat < 0) { |
|
| 141 | + $lat = -$lat; |
|
| 142 | + } |
|
| 143 | + // Table is simmetric about the equator. |
|
| 144 | + if ($lat < 10.47047130) { |
|
| 145 | + return 59; |
|
| 146 | + } |
|
| 147 | + if ($lat < 14.82817437) { |
|
| 148 | + return 58; |
|
| 149 | + } |
|
| 150 | + if ($lat < 18.18626357) { |
|
| 151 | + return 57; |
|
| 152 | + } |
|
| 153 | + if ($lat < 21.02939493) { |
|
| 154 | + return 56; |
|
| 155 | + } |
|
| 156 | + if ($lat < 23.54504487) { |
|
| 157 | + return 55; |
|
| 158 | + } |
|
| 159 | + if ($lat < 25.82924707) { |
|
| 160 | + return 54; |
|
| 161 | + } |
|
| 162 | + if ($lat < 27.93898710) { |
|
| 163 | + return 53; |
|
| 164 | + } |
|
| 165 | + if ($lat < 29.91135686) { |
|
| 166 | + return 52; |
|
| 167 | + } |
|
| 168 | + if ($lat < 31.77209708) { |
|
| 169 | + return 51; |
|
| 170 | + } |
|
| 171 | + if ($lat < 33.53993436) { |
|
| 172 | + return 50; |
|
| 173 | + } |
|
| 174 | + if ($lat < 35.22899598) { |
|
| 175 | + return 49; |
|
| 176 | + } |
|
| 177 | + if ($lat < 36.85025108) { |
|
| 178 | + return 48; |
|
| 179 | + } |
|
| 180 | + if ($lat < 38.41241892) { |
|
| 181 | + return 47; |
|
| 182 | + } |
|
| 183 | + if ($lat < 39.92256684) { |
|
| 184 | + return 46; |
|
| 185 | + } |
|
| 186 | + if ($lat < 41.38651832) { |
|
| 187 | + return 45; |
|
| 188 | + } |
|
| 189 | + if ($lat < 42.80914012) { |
|
| 190 | + return 44; |
|
| 191 | + } |
|
| 192 | + if ($lat < 44.19454951) { |
|
| 193 | + return 43; |
|
| 194 | + } |
|
| 195 | + if ($lat < 45.54626723) { |
|
| 196 | + return 42; |
|
| 197 | + } |
|
| 198 | + if ($lat < 46.86733252) { |
|
| 199 | + return 41; |
|
| 200 | + } |
|
| 201 | + if ($lat < 48.16039128) { |
|
| 202 | + return 40; |
|
| 203 | + } |
|
| 204 | + if ($lat < 49.42776439) { |
|
| 205 | + return 39; |
|
| 206 | + } |
|
| 207 | + if ($lat < 50.67150166) { |
|
| 208 | + return 38; |
|
| 209 | + } |
|
| 210 | + if ($lat < 51.89342469) { |
|
| 211 | + return 37; |
|
| 212 | + } |
|
| 213 | + if ($lat < 53.09516153) { |
|
| 214 | + return 36; |
|
| 215 | + } |
|
| 216 | + if ($lat < 54.27817472) { |
|
| 217 | + return 35; |
|
| 218 | + } |
|
| 219 | + if ($lat < 55.44378444) { |
|
| 220 | + return 34; |
|
| 221 | + } |
|
| 222 | + if ($lat < 56.59318756) { |
|
| 223 | + return 33; |
|
| 224 | + } |
|
| 225 | + if ($lat < 57.72747354) { |
|
| 226 | + return 32; |
|
| 227 | + } |
|
| 228 | + if ($lat < 58.84763776) { |
|
| 229 | + return 31; |
|
| 230 | + } |
|
| 231 | + if ($lat < 59.95459277) { |
|
| 232 | + return 30; |
|
| 233 | + } |
|
| 234 | + if ($lat < 61.04917774) { |
|
| 235 | + return 29; |
|
| 236 | + } |
|
| 237 | + if ($lat < 62.13216659) { |
|
| 238 | + return 28; |
|
| 239 | + } |
|
| 240 | + if ($lat < 63.20427479) { |
|
| 241 | + return 27; |
|
| 242 | + } |
|
| 243 | + if ($lat < 64.26616523) { |
|
| 244 | + return 26; |
|
| 245 | + } |
|
| 246 | + if ($lat < 65.31845310) { |
|
| 247 | + return 25; |
|
| 248 | + } |
|
| 249 | + if ($lat < 66.36171008) { |
|
| 250 | + return 24; |
|
| 251 | + } |
|
| 252 | + if ($lat < 67.39646774) { |
|
| 253 | + return 23; |
|
| 254 | + } |
|
| 255 | + if ($lat < 68.42322022) { |
|
| 256 | + return 22; |
|
| 257 | + } |
|
| 258 | + if ($lat < 69.44242631) { |
|
| 259 | + return 21; |
|
| 260 | + } |
|
| 261 | + if ($lat < 70.45451075) { |
|
| 262 | + return 20; |
|
| 263 | + } |
|
| 264 | + if ($lat < 71.45986473) { |
|
| 265 | + return 19; |
|
| 266 | + } |
|
| 267 | + if ($lat < 72.45884545) { |
|
| 268 | + return 18; |
|
| 269 | + } |
|
| 270 | + if ($lat < 73.45177442) { |
|
| 271 | + return 17; |
|
| 272 | + } |
|
| 273 | + if ($lat < 74.43893416) { |
|
| 274 | + return 16; |
|
| 275 | + } |
|
| 276 | + if ($lat < 75.42056257) { |
|
| 277 | + return 15; |
|
| 278 | + } |
|
| 279 | + if ($lat < 76.39684391) { |
|
| 280 | + return 14; |
|
| 281 | + } |
|
| 282 | + if ($lat < 77.36789461) { |
|
| 283 | + return 13; |
|
| 284 | + } |
|
| 285 | + if ($lat < 78.33374083) { |
|
| 286 | + return 12; |
|
| 287 | + } |
|
| 288 | + if ($lat < 79.29428225) { |
|
| 289 | + return 11; |
|
| 290 | + } |
|
| 291 | + if ($lat < 80.24923213) { |
|
| 292 | + return 10; |
|
| 293 | + } |
|
| 294 | + if ($lat < 81.19801349) { |
|
| 295 | + return 9; |
|
| 296 | + } |
|
| 297 | + if ($lat < 82.13956981) { |
|
| 298 | + return 8; |
|
| 299 | + } |
|
| 300 | + if ($lat < 83.07199445) { |
|
| 301 | + return 7; |
|
| 302 | + } |
|
| 303 | + if ($lat < 83.99173563) { |
|
| 304 | + return 6; |
|
| 305 | + } |
|
| 306 | + if ($lat < 84.89166191) { |
|
| 307 | + return 5; |
|
| 308 | + } |
|
| 309 | + if ($lat < 85.75541621) { |
|
| 310 | + return 4; |
|
| 311 | + } |
|
| 312 | + if ($lat < 86.53536998) { |
|
| 313 | + return 3; |
|
| 314 | + } |
|
| 315 | + if ($lat < 87.00000000) { |
|
| 316 | + return 2; |
|
| 317 | + } |
|
| 178 | 318 | return 1; |
| 179 | 319 | } |
| 180 | 320 | |
| 181 | 321 | function cprN($lat,$isodd) { |
| 182 | 322 | $nl = $this->cprNL($lat) - $isodd; |
| 183 | - if ($nl > 1) return $nl; |
|
| 184 | - else return 1; |
|
| 323 | + if ($nl > 1) { |
|
| 324 | + return $nl; |
|
| 325 | + } else { |
|
| 326 | + return 1; |
|
| 327 | + } |
|
| 185 | 328 | } |
| 186 | 329 | |
| 187 | 330 | |
@@ -207,10 +350,13 @@ discard block |
||
| 207 | 350 | $checksum = intval(substr($msg,22,6),16); |
| 208 | 351 | |
| 209 | 352 | for ($j = 0; $j < strlen($bin); $j++) { |
| 210 | - if ($bin[$j]) $crc = $crc^intval($modes_checksum_table[$j],0); |
|
| 353 | + if ($bin[$j]) { |
|
| 354 | + $crc = $crc^intval($modes_checksum_table[$j],0); |
|
| 355 | + } |
|
| 211 | 356 | } |
| 212 | - if ($crc == $checksum) return true; |
|
| 213 | - else { |
|
| 357 | + if ($crc == $checksum) { |
|
| 358 | + return true; |
|
| 359 | + } else { |
|
| 214 | 360 | //echo "**** CRC ERROR ****\n"; |
| 215 | 361 | return false; |
| 216 | 362 | } |
@@ -1,8 +1,8 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | class SBS { |
| 3 | - static $latlon = array(); |
|
| 3 | + static $latlon = array(); |
|
| 4 | 4 | |
| 5 | - public function parse($buffer) { |
|
| 5 | + public function parse($buffer) { |
|
| 6 | 6 | // Not yet finished, no CRC checks |
| 7 | 7 | //echo $buffer."\n"; |
| 8 | 8 | $data = array(); |
@@ -13,47 +13,47 @@ discard block |
||
| 13 | 13 | $bin = gmp_strval( gmp_init($hex,16), 2); |
| 14 | 14 | //if (strlen($hex) == 28 && $this->parityCheck($hex,$bin)) { |
| 15 | 15 | if (strlen($hex) == 28) { |
| 16 | - $df = intval(substr($bin,0,5),2); |
|
| 17 | - //$ca = intval(substr($bin,5,3),2); |
|
| 18 | - // Only support DF17 for now |
|
| 19 | - //if ($df == 17 || ($df == 18 && ($ca == 0 || $ca == 1 || $ca == 6))) { |
|
| 20 | - if (($df == 17 || $df == 18) && ($this->parityCheck($hex,$bin) || $typehex == '@')) { |
|
| 16 | + $df = intval(substr($bin,0,5),2); |
|
| 17 | + //$ca = intval(substr($bin,5,3),2); |
|
| 18 | + // Only support DF17 for now |
|
| 19 | + //if ($df == 17 || ($df == 18 && ($ca == 0 || $ca == 1 || $ca == 6))) { |
|
| 20 | + if (($df == 17 || $df == 18) && ($this->parityCheck($hex,$bin) || $typehex == '@')) { |
|
| 21 | 21 | $icao = substr($hex,2,6); |
| 22 | 22 | $data['hex'] = $icao; |
| 23 | 23 | $tc = intval(substr($bin,32,5),2); |
| 24 | 24 | if ($tc >= 1 && $tc <= 4) { |
| 25 | - //callsign |
|
| 26 | - $csbin = substr($bin,40,56); |
|
| 27 | - $charset = str_split('#ABCDEFGHIJKLMNOPQRSTUVWXYZ#####_###############0123456789######'); |
|
| 28 | - $cs = ''; |
|
| 29 | - $cs .= $charset[intval(substr($csbin,0,6),2)]; |
|
| 30 | - $cs .= $charset[intval(substr($csbin,6,6),2)]; |
|
| 31 | - $cs .= $charset[intval(substr($csbin,12,6),2)]; |
|
| 32 | - $cs .= $charset[intval(substr($csbin,18,6),2)]; |
|
| 33 | - $cs .= $charset[intval(substr($csbin,24,6),2)]; |
|
| 34 | - $cs .= $charset[intval(substr($csbin,30,6),2)]; |
|
| 35 | - $cs .= $charset[intval(substr($csbin,36,6),2)]; |
|
| 36 | - $cs .= $charset[intval(substr($csbin,42,6),2)]; |
|
| 37 | - $cs = str_replace('_','',$cs); |
|
| 38 | - $cs = str_replace('#','',$cs); |
|
| 39 | - $callsign = $cs; |
|
| 40 | - $data['ident'] = $callsign; |
|
| 25 | + //callsign |
|
| 26 | + $csbin = substr($bin,40,56); |
|
| 27 | + $charset = str_split('#ABCDEFGHIJKLMNOPQRSTUVWXYZ#####_###############0123456789######'); |
|
| 28 | + $cs = ''; |
|
| 29 | + $cs .= $charset[intval(substr($csbin,0,6),2)]; |
|
| 30 | + $cs .= $charset[intval(substr($csbin,6,6),2)]; |
|
| 31 | + $cs .= $charset[intval(substr($csbin,12,6),2)]; |
|
| 32 | + $cs .= $charset[intval(substr($csbin,18,6),2)]; |
|
| 33 | + $cs .= $charset[intval(substr($csbin,24,6),2)]; |
|
| 34 | + $cs .= $charset[intval(substr($csbin,30,6),2)]; |
|
| 35 | + $cs .= $charset[intval(substr($csbin,36,6),2)]; |
|
| 36 | + $cs .= $charset[intval(substr($csbin,42,6),2)]; |
|
| 37 | + $cs = str_replace('_','',$cs); |
|
| 38 | + $cs = str_replace('#','',$cs); |
|
| 39 | + $callsign = $cs; |
|
| 40 | + $data['ident'] = $callsign; |
|
| 41 | 41 | } elseif ($tc >= 9 && $tc <= 18) { |
| 42 | - // Check Q-bit |
|
| 43 | - $q = substr($bin,47,1); |
|
| 44 | - if ($q) { |
|
| 42 | + // Check Q-bit |
|
| 43 | + $q = substr($bin,47,1); |
|
| 44 | + if ($q) { |
|
| 45 | 45 | $n = intval(substr($bin,40,7).substr($bin,48,4),2); |
| 46 | 46 | $alt = $n*25-1000; |
| 47 | 47 | $data['altitude'] = $alt; |
| 48 | - } |
|
| 49 | - // Check odd/even flag |
|
| 50 | - $oe = substr($bin,53,1); |
|
| 51 | - //if ($oe) => odd else even |
|
| 52 | - // 131072 is 2^17 since CPR latitude and longitude are encoded in 17 bits. |
|
| 53 | - $cprlat = intval(substr($bin,54,17),2)/131072.0; |
|
| 54 | - $cprlon = intval(substr($bin,71,17),2)/131072.0; |
|
| 55 | - if ($oe == 0) $this::$latlon[$icao] = array('latitude' => $cprlat,'longitude' => $cprlon,'created' => time()); |
|
| 56 | - elseif (isset($this::$latlon[$icao]) && (time() - $this::$latlon[$icao]['created']) < 10) { |
|
| 48 | + } |
|
| 49 | + // Check odd/even flag |
|
| 50 | + $oe = substr($bin,53,1); |
|
| 51 | + //if ($oe) => odd else even |
|
| 52 | + // 131072 is 2^17 since CPR latitude and longitude are encoded in 17 bits. |
|
| 53 | + $cprlat = intval(substr($bin,54,17),2)/131072.0; |
|
| 54 | + $cprlon = intval(substr($bin,71,17),2)/131072.0; |
|
| 55 | + if ($oe == 0) $this::$latlon[$icao] = array('latitude' => $cprlat,'longitude' => $cprlon,'created' => time()); |
|
| 56 | + elseif (isset($this::$latlon[$icao]) && (time() - $this::$latlon[$icao]['created']) < 10) { |
|
| 57 | 57 | $cprlat_odd = $cprlat; |
| 58 | 58 | $cprlon_odd = $cprlon; |
| 59 | 59 | $cprlat_even = $this::$latlon[$icao]['latitude']; |
@@ -66,53 +66,53 @@ discard block |
||
| 66 | 66 | if ($lat_odd >= 270) $lat_odd = $lat_odd - 360; |
| 67 | 67 | // check latitude zone |
| 68 | 68 | if ($this->cprNL($lat_even) == $this->cprNL($lat_odd)) { |
| 69 | - if ($this::$latlon[$icao]['created'] > time()) { |
|
| 69 | + if ($this::$latlon[$icao]['created'] > time()) { |
|
| 70 | 70 | $ni = $this->cprN($lat_even,0); |
| 71 | 71 | $m = floor($cprlon_even*($this->cprNL($lat_even)-1) - $cprlon_odd * $this->cprNL($lat_even)+0.5); |
| 72 | 72 | $lon = (360.0/$ni)*($m%$ni+$cprlon_even); |
| 73 | 73 | $lat = $lat_even; |
| 74 | 74 | if ($lon > 180) $lon = $lon -360; |
| 75 | 75 | if ($lat > -91 && $lat < 91 && $lon > -181 && $lon < 181) { |
| 76 | - //if ($globalDebug) echo 'cs : '.$cs.' - hex : '.$hex.' - lat : '.$lat.' - lon : '.$lon; |
|
| 77 | - $data['latitude'] = $lat; |
|
| 78 | - $data['longitude'] = $lon; |
|
| 76 | + //if ($globalDebug) echo 'cs : '.$cs.' - hex : '.$hex.' - lat : '.$lat.' - lon : '.$lon; |
|
| 77 | + $data['latitude'] = $lat; |
|
| 78 | + $data['longitude'] = $lon; |
|
| 79 | 79 | } |
| 80 | - } else { |
|
| 80 | + } else { |
|
| 81 | 81 | $ni = $this->cprN($lat_odd,1); |
| 82 | 82 | $m = floor($cprlon_even*($this->cprNL($lat_odd)-1) - $cprlon_odd * $this->cprNL($lat_odd)+0.5); |
| 83 | 83 | $lon = (360.0/$ni)*($m%$ni+$cprlon_odd); |
| 84 | 84 | $lat = $lat_odd; |
| 85 | 85 | if ($lon > 180) $lon = $lon -360; |
| 86 | 86 | if ($lat > -91 && $lat < 91 && $lon > -181 && $lon < 181) { |
| 87 | - //if ($globalDebug) echo 'icao : '.$icao.' - hex : '.$hex.' - lat : '.$lat.' - lon : '.$lon.' second'."\n"; |
|
| 88 | - $data['latitude'] = $lat; |
|
| 89 | - $data['longitude'] = $lon; |
|
| 87 | + //if ($globalDebug) echo 'icao : '.$icao.' - hex : '.$hex.' - lat : '.$lat.' - lon : '.$lon.' second'."\n"; |
|
| 88 | + $data['latitude'] = $lat; |
|
| 89 | + $data['longitude'] = $lon; |
|
| 90 | + } |
|
| 90 | 91 | } |
| 91 | - } |
|
| 92 | 92 | } else echo "Not cprNL"; |
| 93 | 93 | unset($this::$latlon[$icao]); |
| 94 | - } |
|
| 94 | + } |
|
| 95 | 95 | } elseif ($tc == 19) { |
| 96 | - // speed & heading |
|
| 97 | - $v_ew_dir = intval(substr($bin,45,1)); |
|
| 98 | - $v_ew = intval(substr($bin,46,10),2); |
|
| 99 | - $v_ns_dir = intval(substr($bin,56,1)); |
|
| 100 | - $v_ns = intval(substr($bin,57,10),2); |
|
| 101 | - if ($v_ew_dir) $v_ew = -1*$v_ew; |
|
| 102 | - if ($v_ns_dir) $v_ns = -1*$v_ns; |
|
| 103 | - $speed = sqrt($v_ns*$v_ns+$v_ew*$v_ew); |
|
| 104 | - $heading = atan2($v_ew,$v_ns)*360.0/(2*pi()); |
|
| 105 | - if ($heading <0) $heading = $heading+360; |
|
| 106 | - $data['speed'] = $speed; |
|
| 107 | - $data['heading'] = $heading; |
|
| 96 | + // speed & heading |
|
| 97 | + $v_ew_dir = intval(substr($bin,45,1)); |
|
| 98 | + $v_ew = intval(substr($bin,46,10),2); |
|
| 99 | + $v_ns_dir = intval(substr($bin,56,1)); |
|
| 100 | + $v_ns = intval(substr($bin,57,10),2); |
|
| 101 | + if ($v_ew_dir) $v_ew = -1*$v_ew; |
|
| 102 | + if ($v_ns_dir) $v_ns = -1*$v_ns; |
|
| 103 | + $speed = sqrt($v_ns*$v_ns+$v_ew*$v_ew); |
|
| 104 | + $heading = atan2($v_ew,$v_ns)*360.0/(2*pi()); |
|
| 105 | + if ($heading <0) $heading = $heading+360; |
|
| 106 | + $data['speed'] = $speed; |
|
| 107 | + $data['heading'] = $heading; |
|
| 108 | + } |
|
| 108 | 109 | } |
| 109 | - } |
|
| 110 | - if (isset($data)) { |
|
| 110 | + if (isset($data)) { |
|
| 111 | 111 | //print_r($data); |
| 112 | 112 | return $data; |
| 113 | - } |
|
| 114 | - } |
|
| 115 | - } |
|
| 113 | + } |
|
| 114 | + } |
|
| 115 | + } |
|
| 116 | 116 | |
| 117 | 117 | |
| 118 | 118 | public function cprNL($lat) { |
@@ -177,16 +177,16 @@ discard block |
||
| 177 | 177 | if ($lat < 86.53536998) return 3; |
| 178 | 178 | if ($lat < 87.00000000) return 2; |
| 179 | 179 | return 1; |
| 180 | - } |
|
| 180 | + } |
|
| 181 | 181 | |
| 182 | - public function cprN($lat,$isodd) { |
|
| 182 | + public function cprN($lat,$isodd) { |
|
| 183 | 183 | $nl = $this->cprNL($lat) - $isodd; |
| 184 | 184 | if ($nl > 1) return $nl; |
| 185 | 185 | else return 1; |
| 186 | - } |
|
| 186 | + } |
|
| 187 | 187 | |
| 188 | 188 | |
| 189 | - function parityCheck($msg, $bin) { |
|
| 189 | + function parityCheck($msg, $bin) { |
|
| 190 | 190 | $modes_checksum_table = array( |
| 191 | 191 | 0x3935ea, 0x1c9af5, 0xf1b77e, 0x78dbbf, 0xc397db, 0x9e31e9, 0xb0e2f0, 0x587178, |
| 192 | 192 | 0x2c38bc, 0x161c5e, 0x0b0e2f, 0xfa7d13, 0x82c48d, 0xbe9842, 0x5f4c21, 0xd05c14, |
@@ -208,13 +208,13 @@ discard block |
||
| 208 | 208 | $checksum = intval(substr($msg,22,6),16); |
| 209 | 209 | |
| 210 | 210 | for ($j = 0; $j < strlen($bin); $j++) { |
| 211 | - if ($bin[$j]) $crc = $crc^intval($modes_checksum_table[$j],0); |
|
| 211 | + if ($bin[$j]) $crc = $crc^intval($modes_checksum_table[$j],0); |
|
| 212 | 212 | } |
| 213 | 213 | if ($crc == $checksum) return true; |
| 214 | 214 | else { |
| 215 | - //echo "**** CRC ERROR ****\n"; |
|
| 216 | - return false; |
|
| 215 | + //echo "**** CRC ERROR ****\n"; |
|
| 216 | + return false; |
|
| 217 | + } |
|
| 217 | 218 | } |
| 218 | - } |
|
| 219 | 219 | } |
| 220 | 220 | ?> |
@@ -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 |
@@ -9,16 +9,16 @@ discard block |
||
| 9 | 9 | require_once(dirname(__FILE__).'/class.Source.php'); |
| 10 | 10 | |
| 11 | 11 | class SpotterImport { |
| 12 | - private $all_flights = array(); |
|
| 13 | - private $last_delete_hourly = 0; |
|
| 14 | - private $last_delete = 0; |
|
| 15 | - private $stats = array(); |
|
| 16 | - private $tmd = 0; |
|
| 17 | - private $source_location = array(); |
|
| 18 | - public $db = null; |
|
| 19 | - public $nb = 0; |
|
| 20 | - |
|
| 21 | - public function __construct($dbc = null) { |
|
| 12 | + private $all_flights = array(); |
|
| 13 | + private $last_delete_hourly = 0; |
|
| 14 | + private $last_delete = 0; |
|
| 15 | + private $stats = array(); |
|
| 16 | + private $tmd = 0; |
|
| 17 | + private $source_location = array(); |
|
| 18 | + public $db = null; |
|
| 19 | + public $nb = 0; |
|
| 20 | + |
|
| 21 | + public function __construct($dbc = null) { |
|
| 22 | 22 | global $globalBeta; |
| 23 | 23 | $Connection = new Connection($dbc); |
| 24 | 24 | $this->db = $Connection->db(); |
@@ -29,18 +29,18 @@ discard block |
||
| 29 | 29 | $currentdate = date('Y-m-d'); |
| 30 | 30 | $sourcestat = $Stats->getStatsSource($currentdate); |
| 31 | 31 | if (!empty($sourcestat)) { |
| 32 | - foreach($sourcestat as $srcst) { |
|
| 33 | - $type = $srcst['stats_type']; |
|
| 32 | + foreach($sourcestat as $srcst) { |
|
| 33 | + $type = $srcst['stats_type']; |
|
| 34 | 34 | if ($type == 'polar' || $type == 'hist') { |
| 35 | - $source = $srcst['source_name']; |
|
| 36 | - $data = $srcst['source_data']; |
|
| 37 | - $this->stats[$currentdate][$source][$type] = json_decode($data,true); |
|
| 38 | - } |
|
| 39 | - } |
|
| 35 | + $source = $srcst['source_name']; |
|
| 36 | + $data = $srcst['source_data']; |
|
| 37 | + $this->stats[$currentdate][$source][$type] = json_decode($data,true); |
|
| 38 | + } |
|
| 39 | + } |
|
| 40 | + } |
|
| 40 | 41 | } |
| 41 | - } |
|
| 42 | 42 | |
| 43 | - public function get_Schedule($id,$ident) { |
|
| 43 | + public function get_Schedule($id,$ident) { |
|
| 44 | 44 | global $globalDebug, $globalFork, $globalSchedulesFetch; |
| 45 | 45 | // Get schedule here, so it's done only one time |
| 46 | 46 | |
@@ -59,35 +59,35 @@ discard block |
||
| 59 | 59 | $Translation = new Translation($dbc); |
| 60 | 60 | $operator = $Spotter->getOperator($ident); |
| 61 | 61 | if ($Schedule->checkSchedule($operator) == 0) { |
| 62 | - $operator = $Translation->checkTranslation($ident); |
|
| 63 | - if ($Schedule->checkSchedule($operator) == 0) { |
|
| 62 | + $operator = $Translation->checkTranslation($ident); |
|
| 63 | + if ($Schedule->checkSchedule($operator) == 0) { |
|
| 64 | 64 | $schedule = $Schedule->fetchSchedule($operator); |
| 65 | 65 | if (count($schedule) > 0 && isset($schedule['DepartureTime']) && isset($schedule['ArrivalTime'])) { |
| 66 | - if ($globalDebug) echo "-> Schedule info for ".$operator." (".$ident.")\n"; |
|
| 67 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport_time' => $schedule['DepartureTime'])); |
|
| 68 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('arrival_airport_time' => $schedule['ArrivalTime'])); |
|
| 69 | - // Should also check if route schedule = route from DB |
|
| 70 | - if ($schedule['DepartureAirportIATA'] != '') { |
|
| 66 | + if ($globalDebug) echo "-> Schedule info for ".$operator." (".$ident.")\n"; |
|
| 67 | + $this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport_time' => $schedule['DepartureTime'])); |
|
| 68 | + $this->all_flights[$id] = array_merge($this->all_flights[$id],array('arrival_airport_time' => $schedule['ArrivalTime'])); |
|
| 69 | + // Should also check if route schedule = route from DB |
|
| 70 | + if ($schedule['DepartureAirportIATA'] != '') { |
|
| 71 | 71 | if ($this->all_flights[$id]['departure_airport'] != $Spotter->getAirportIcao($schedule['DepartureAirportIATA'])) { |
| 72 | - $airport_icao = $Spotter->getAirportIcao($schedule['DepartureAirportIATA']); |
|
| 73 | - if ($airport_icao != '') { |
|
| 72 | + $airport_icao = $Spotter->getAirportIcao($schedule['DepartureAirportIATA']); |
|
| 73 | + if ($airport_icao != '') { |
|
| 74 | 74 | $this->all_flights[$id]['departure_airport'] = $airport_icao; |
| 75 | 75 | if ($globalDebug) echo "-> Change departure airport to ".$airport_icao." for ".$ident."\n"; |
| 76 | - } |
|
| 76 | + } |
|
| 77 | + } |
|
| 77 | 78 | } |
| 78 | - } |
|
| 79 | - if ($schedule['ArrivalAirportIATA'] != '') { |
|
| 79 | + if ($schedule['ArrivalAirportIATA'] != '') { |
|
| 80 | 80 | if ($this->all_flights[$id]['arrival_airport'] != $Spotter->getAirportIcao($schedule['ArrivalAirportIATA'])) { |
| 81 | - $airport_icao = $Spotter->getAirportIcao($schedule['ArrivalAirportIATA']); |
|
| 82 | - if ($airport_icao != '') { |
|
| 81 | + $airport_icao = $Spotter->getAirportIcao($schedule['ArrivalAirportIATA']); |
|
| 82 | + if ($airport_icao != '') { |
|
| 83 | 83 | $this->all_flights[$id]['arrival_airport'] = $airport_icao; |
| 84 | 84 | if ($globalDebug) echo "-> Change arrival airport to ".$airport_icao." for ".$ident."\n"; |
| 85 | - } |
|
| 85 | + } |
|
| 86 | + } |
|
| 86 | 87 | } |
| 87 | - } |
|
| 88 | - $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']); |
|
| 88 | + $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 | + } |
|
| 89 | 90 | } |
| 90 | - } |
|
| 91 | 91 | } |
| 92 | 92 | // close connection, at least one way will work ? |
| 93 | 93 | |
@@ -105,92 +105,92 @@ discard block |
||
| 105 | 105 | } |
| 106 | 106 | */ |
| 107 | 107 | } |
| 108 | - } |
|
| 108 | + } |
|
| 109 | 109 | |
| 110 | - public function checkAll() { |
|
| 110 | + public function checkAll() { |
|
| 111 | 111 | global $globalDebug; |
| 112 | 112 | if ($globalDebug) echo "Update last seen flights data...\n"; |
| 113 | 113 | foreach ($this->all_flights as $key => $flight) { |
| 114 | - if (isset($this->all_flights[$key]['id'])) { |
|
| 114 | + if (isset($this->all_flights[$key]['id'])) { |
|
| 115 | 115 | //echo $this->all_flights[$key]['id'].' - '.$this->all_flights[$key]['latitude'].' '.$this->all_flights[$key]['longitude']."\n"; |
| 116 | - $Spotter = new Spotter($this->db); |
|
| 117 | - $real_arrival = $this->arrival($key); |
|
| 118 | - $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']); |
|
| 119 | - } |
|
| 116 | + $Spotter = new Spotter($this->db); |
|
| 117 | + $real_arrival = $this->arrival($key); |
|
| 118 | + $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']); |
|
| 119 | + } |
|
| 120 | + } |
|
| 120 | 121 | } |
| 121 | - } |
|
| 122 | 122 | |
| 123 | - public function arrival($key) { |
|
| 123 | + public function arrival($key) { |
|
| 124 | 124 | global $globalClosestMinDist, $globalDebug; |
| 125 | 125 | if ($globalDebug) echo 'Update arrival...'."\n"; |
| 126 | 126 | $Spotter = new Spotter($this->db); |
| 127 | - $airport_icao = ''; |
|
| 128 | - $airport_time = ''; |
|
| 129 | - if (!isset($globalClosestMinDist) || $globalClosestMinDist == '') $globalClosestMinDist = 50; |
|
| 127 | + $airport_icao = ''; |
|
| 128 | + $airport_time = ''; |
|
| 129 | + if (!isset($globalClosestMinDist) || $globalClosestMinDist == '') $globalClosestMinDist = 50; |
|
| 130 | 130 | if ($this->all_flights[$key]['latitude'] != '' && $this->all_flights[$key]['longitude'] != '') { |
| 131 | - $closestAirports = $Spotter->closestAirports($this->all_flights[$key]['latitude'],$this->all_flights[$key]['longitude'],$globalClosestMinDist); |
|
| 132 | - if (isset($closestAirports[0])) { |
|
| 133 | - if (isset($this->all_flights[$key]['arrival_airport']) && $this->all_flights[$key]['arrival_airport'] == $closestAirports[0]['icao']) { |
|
| 134 | - $airport_icao = $closestAirports[0]['icao']; |
|
| 135 | - $airport_time = $this->all_flights[$key]['datetime']; |
|
| 136 | - if ($globalDebug) echo "---++ Find arrival airport. airport_icao : ".$airport_icao."\n"; |
|
| 137 | - } elseif (count($closestAirports > 1) && isset($this->all_flights[$key]['arrival_airport']) && $this->all_flights[$key]['arrival_airport'] != '') { |
|
| 138 | - foreach ($closestAirports as $airport) { |
|
| 139 | - if ($this->all_flights[$key]['arrival_airport'] == $airport['icao']) { |
|
| 140 | - $airport_icao = $airport['icao']; |
|
| 141 | - $airport_time = $this->all_flights[$key]['datetime']; |
|
| 142 | - if ($globalDebug) echo "---++ Find arrival airport. airport_icao : ".$airport_icao."\n"; |
|
| 143 | - break; |
|
| 144 | - } |
|
| 145 | - } |
|
| 146 | - } 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))) { |
|
| 147 | - $airport_icao = $closestAirports[0]['icao']; |
|
| 148 | - $airport_time = $this->all_flights[$key]['datetime']; |
|
| 149 | - } else { |
|
| 150 | - if ($globalDebug) echo "----- Can't find arrival airport. Airport altitude : ".$closestAirports[0]['altitude'].' - flight altitude : '.$this->all_flights[$key]['altitude_real']."\n"; |
|
| 151 | - } |
|
| 152 | - } else { |
|
| 153 | - if ($globalDebug) echo "----- No Airport near last coord. Latitude : ".$this->all_flights[$key]['latitude'].' - Longitude : '.$this->all_flights[$key]['longitude'].' - MinDist : '.$globalClosestMinDist."\n"; |
|
| 154 | - } |
|
| 155 | - |
|
| 156 | - } else { |
|
| 157 | - if ($globalDebug) echo "---- No latitude or longitude. Ident : ".$this->all_flights[$key]['ident']."\n"; |
|
| 158 | - } |
|
| 159 | - return array('airport_icao' => $airport_icao,'airport_time' => $airport_time); |
|
| 160 | - } |
|
| 161 | - |
|
| 162 | - |
|
| 163 | - |
|
| 164 | - public function del() { |
|
| 131 | + $closestAirports = $Spotter->closestAirports($this->all_flights[$key]['latitude'],$this->all_flights[$key]['longitude'],$globalClosestMinDist); |
|
| 132 | + if (isset($closestAirports[0])) { |
|
| 133 | + if (isset($this->all_flights[$key]['arrival_airport']) && $this->all_flights[$key]['arrival_airport'] == $closestAirports[0]['icao']) { |
|
| 134 | + $airport_icao = $closestAirports[0]['icao']; |
|
| 135 | + $airport_time = $this->all_flights[$key]['datetime']; |
|
| 136 | + if ($globalDebug) echo "---++ Find arrival airport. airport_icao : ".$airport_icao."\n"; |
|
| 137 | + } elseif (count($closestAirports > 1) && isset($this->all_flights[$key]['arrival_airport']) && $this->all_flights[$key]['arrival_airport'] != '') { |
|
| 138 | + foreach ($closestAirports as $airport) { |
|
| 139 | + if ($this->all_flights[$key]['arrival_airport'] == $airport['icao']) { |
|
| 140 | + $airport_icao = $airport['icao']; |
|
| 141 | + $airport_time = $this->all_flights[$key]['datetime']; |
|
| 142 | + if ($globalDebug) echo "---++ Find arrival airport. airport_icao : ".$airport_icao."\n"; |
|
| 143 | + break; |
|
| 144 | + } |
|
| 145 | + } |
|
| 146 | + } 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))) { |
|
| 147 | + $airport_icao = $closestAirports[0]['icao']; |
|
| 148 | + $airport_time = $this->all_flights[$key]['datetime']; |
|
| 149 | + } else { |
|
| 150 | + if ($globalDebug) echo "----- Can't find arrival airport. Airport altitude : ".$closestAirports[0]['altitude'].' - flight altitude : '.$this->all_flights[$key]['altitude_real']."\n"; |
|
| 151 | + } |
|
| 152 | + } else { |
|
| 153 | + if ($globalDebug) echo "----- No Airport near last coord. Latitude : ".$this->all_flights[$key]['latitude'].' - Longitude : '.$this->all_flights[$key]['longitude'].' - MinDist : '.$globalClosestMinDist."\n"; |
|
| 154 | + } |
|
| 155 | + |
|
| 156 | + } else { |
|
| 157 | + if ($globalDebug) echo "---- No latitude or longitude. Ident : ".$this->all_flights[$key]['ident']."\n"; |
|
| 158 | + } |
|
| 159 | + return array('airport_icao' => $airport_icao,'airport_time' => $airport_time); |
|
| 160 | + } |
|
| 161 | + |
|
| 162 | + |
|
| 163 | + |
|
| 164 | + public function del() { |
|
| 165 | 165 | global $globalDebug; |
| 166 | 166 | // Delete old infos |
| 167 | 167 | if ($globalDebug) echo 'Delete old values and update latest data...'."\n"; |
| 168 | 168 | foreach ($this->all_flights as $key => $flight) { |
| 169 | - if (isset($flight['lastupdate'])) { |
|
| 170 | - if ($flight['lastupdate'] < (time()-3000)) { |
|
| 171 | - if (isset($this->all_flights[$key]['id'])) { |
|
| 172 | - if ($globalDebug) echo "--- Delete old values with id ".$this->all_flights[$key]['id']."\n"; |
|
| 169 | + if (isset($flight['lastupdate'])) { |
|
| 170 | + if ($flight['lastupdate'] < (time()-3000)) { |
|
| 171 | + if (isset($this->all_flights[$key]['id'])) { |
|
| 172 | + if ($globalDebug) echo "--- Delete old values with id ".$this->all_flights[$key]['id']."\n"; |
|
| 173 | 173 | /* |
| 174 | 174 | $SpotterLive = new SpotterLive(); |
| 175 | 175 | $SpotterLive->deleteLiveSpotterDataById($this->all_flights[$key]['id']); |
| 176 | 176 | $SpotterLive->db = null; |
| 177 | 177 | */ |
| 178 | - $real_arrival = $this->arrival($key); |
|
| 179 | - $Spotter = new Spotter($this->db); |
|
| 180 | - if ($this->all_flights[$key]['latitude'] != '' && $this->all_flights[$key]['longitude'] != '') { |
|
| 178 | + $real_arrival = $this->arrival($key); |
|
| 179 | + $Spotter = new Spotter($this->db); |
|
| 180 | + if ($this->all_flights[$key]['latitude'] != '' && $this->all_flights[$key]['longitude'] != '') { |
|
| 181 | 181 | $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']); |
| 182 | 182 | if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n"; |
| 183 | 183 | } |
| 184 | 184 | // Put in archive |
| 185 | 185 | // $Spotter->db = null; |
| 186 | - } |
|
| 187 | - unset($this->all_flights[$key]); |
|
| 188 | - } |
|
| 189 | - } |
|
| 190 | - } |
|
| 191 | - } |
|
| 192 | - |
|
| 193 | - public function add($line) { |
|
| 186 | + } |
|
| 187 | + unset($this->all_flights[$key]); |
|
| 188 | + } |
|
| 189 | + } |
|
| 190 | + } |
|
| 191 | + } |
|
| 192 | + |
|
| 193 | + public function add($line) { |
|
| 194 | 194 | global $globalPilotIdAccept, $globalAirportAccept, $globalAirlineAccept, $globalAirlineIgnore, $globalAirportIgnore, $globalFork, $globalDistanceIgnore, $globalDaemon, $globalSBS1update, $globalDebug, $globalIVAO, $globalVATSIM, $globalphpVMS, $globalCoordMinChange, $globalDebugTimeElapsed, $globalCenterLatitude, $globalCenterLongitude, $globalBeta, $globalSourcesupdate, $globalAirlinesSource, $globalVAM, $globalAllFlights; |
| 195 | 195 | //if (!isset($globalDebugTimeElapsed) || $globalDebugTimeElapsed == '') $globalDebugTimeElapsed = FALSE; |
| 196 | 196 | if (!isset($globalCoordMinChange) || $globalCoordMinChange == '') $globalCoordMinChange = '0.02'; |
@@ -215,18 +215,18 @@ discard block |
||
| 215 | 215 | |
| 216 | 216 | // SBS format is CSV format |
| 217 | 217 | if(is_array($line) && isset($line['hex'])) { |
| 218 | - //print_r($line); |
|
| 219 | - if ($line['hex'] != '' && $line['hex'] != '00000' && $line['hex'] != '000000' && $line['hex'] != '111111' && ctype_xdigit($line['hex']) && strlen($line['hex']) === 6) { |
|
| 218 | + //print_r($line); |
|
| 219 | + if ($line['hex'] != '' && $line['hex'] != '00000' && $line['hex'] != '000000' && $line['hex'] != '111111' && ctype_xdigit($line['hex']) && strlen($line['hex']) === 6) { |
|
| 220 | 220 | |
| 221 | 221 | // Increment message number |
| 222 | 222 | if (isset($line['sourcestats']) && $line['sourcestats'] == TRUE) { |
| 223 | - $current_date = date('Y-m-d'); |
|
| 224 | - $source = $line['source_name']; |
|
| 225 | - if ($source == '' || $line['format_source'] == 'aprs') $source = $line['format_source']; |
|
| 226 | - if (!isset($this->stats[$current_date][$source]['msg'])) { |
|
| 227 | - $this->stats[$current_date][$source]['msg']['date'] = time(); |
|
| 228 | - $this->stats[$current_date][$source]['msg']['nb'] = 1; |
|
| 229 | - } else $this->stats[$current_date][$source]['msg']['nb'] += 1; |
|
| 223 | + $current_date = date('Y-m-d'); |
|
| 224 | + $source = $line['source_name']; |
|
| 225 | + if ($source == '' || $line['format_source'] == 'aprs') $source = $line['format_source']; |
|
| 226 | + if (!isset($this->stats[$current_date][$source]['msg'])) { |
|
| 227 | + $this->stats[$current_date][$source]['msg']['date'] = time(); |
|
| 228 | + $this->stats[$current_date][$source]['msg']['nb'] = 1; |
|
| 229 | + } else $this->stats[$current_date][$source]['msg']['nb'] += 1; |
|
| 230 | 230 | } |
| 231 | 231 | |
| 232 | 232 | /* |
@@ -242,17 +242,17 @@ discard block |
||
| 242 | 242 | //$this->db = $dbc; |
| 243 | 243 | |
| 244 | 244 | $hex = trim($line['hex']); |
| 245 | - if (!isset($line['id'])) $id = trim($line['hex']); |
|
| 246 | - else $id = trim($line['id']); |
|
| 245 | + if (!isset($line['id'])) $id = trim($line['hex']); |
|
| 246 | + else $id = trim($line['id']); |
|
| 247 | 247 | |
| 248 | 248 | //print_r($this->all_flights); |
| 249 | 249 | if (!isset($this->all_flights[$id]['hex']) && ctype_xdigit($hex)) { |
| 250 | - $this->all_flights[$id] = array('hex' => $hex); |
|
| 251 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0)); |
|
| 252 | - //if (isset($line['datetime']) && preg_match('/^(\d{4}(?:\-\d{2}){2} \d{2}(?:\:\d{2}){2})$/',$line['datetime'])) { |
|
| 250 | + $this->all_flights[$id] = array('hex' => $hex); |
|
| 251 | + $this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0)); |
|
| 252 | + //if (isset($line['datetime']) && preg_match('/^(\d{4}(?:\-\d{2}){2} \d{2}(?:\:\d{2}){2})$/',$line['datetime'])) { |
|
| 253 | 253 | //$this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => $line['datetime'])); |
| 254 | - //} else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => date('Y-m-d H:i:s'))); |
|
| 255 | - if (!isset($line['aircraft_name']) && (!isset($line['aircraft_icao']) || $line['aircraft_icao'] == '????')) { |
|
| 254 | + //} else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => date('Y-m-d H:i:s'))); |
|
| 255 | + if (!isset($line['aircraft_name']) && (!isset($line['aircraft_icao']) || $line['aircraft_icao'] == '????')) { |
|
| 256 | 256 | |
| 257 | 257 | $timeelapsed = microtime(true); |
| 258 | 258 | $Spotter = new Spotter($this->db); |
@@ -261,38 +261,38 @@ discard block |
||
| 261 | 261 | if ($globalDebugTimeElapsed) echo 'Time elapsed for update getallaircrattype : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
| 262 | 262 | |
| 263 | 263 | if ($aircraft_icao == '' && isset($line['aircraft_type'])) { |
| 264 | - if ($line['aircraft_type'] == 'PARA_GLIDER') $aircraft_icao = 'GLID'; |
|
| 265 | - elseif ($line['aircraft_type'] == 'HELICOPTER_ROTORCRAFT') $aircraft_icao = 'UHEL'; |
|
| 266 | - elseif ($line['aircraft_type'] == 'TOW_PLANE') $aircraft_icao = 'TOWPLANE'; |
|
| 267 | - elseif ($line['aircraft_type'] == 'POWERED_AIRCRAFT') $aircraft_icao = 'POWAIRC'; |
|
| 264 | + if ($line['aircraft_type'] == 'PARA_GLIDER') $aircraft_icao = 'GLID'; |
|
| 265 | + elseif ($line['aircraft_type'] == 'HELICOPTER_ROTORCRAFT') $aircraft_icao = 'UHEL'; |
|
| 266 | + elseif ($line['aircraft_type'] == 'TOW_PLANE') $aircraft_icao = 'TOWPLANE'; |
|
| 267 | + elseif ($line['aircraft_type'] == 'POWERED_AIRCRAFT') $aircraft_icao = 'POWAIRC'; |
|
| 268 | 268 | } |
| 269 | 269 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao)); |
| 270 | - } else if (isset($line['aircraft_name'])) { |
|
| 270 | + } else if (isset($line['aircraft_name'])) { |
|
| 271 | 271 | // Get aircraft ICAO from aircraft name |
| 272 | 272 | $Spotter = new Spotter($this->db); |
| 273 | 273 | $aircraft_icao = $Spotter->getAircraftIcao($line['aircraft_name']); |
| 274 | 274 | $Spotter->db = null; |
| 275 | 275 | if ($aircraft_icao != '') $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao)); |
| 276 | 276 | else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => 'NA')); |
| 277 | - } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $line['aircraft_icao'])); |
|
| 278 | - $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)); |
|
| 279 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('lastupdate' => time())); |
|
| 280 | - if (!isset($line['id'])) { |
|
| 277 | + } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $line['aircraft_icao'])); |
|
| 278 | + $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)); |
|
| 279 | + $this->all_flights[$id] = array_merge($this->all_flights[$id],array('lastupdate' => time())); |
|
| 280 | + if (!isset($line['id'])) { |
|
| 281 | 281 | if (!isset($globalDaemon)) $globalDaemon = TRUE; |
| 282 | 282 | // 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'))); |
| 283 | 283 | // 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'))); |
| 284 | 284 | 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'))); |
| 285 | - //else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident'])); |
|
| 286 | - } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id'])); |
|
| 285 | + //else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident'])); |
|
| 286 | + } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id'])); |
|
| 287 | 287 | |
| 288 | - if ($globalDebug) echo "*********** New aircraft hex : ".$hex." ***********\n"; |
|
| 289 | - if ($globalAllFlights !== FALSE) $dataFound = true; |
|
| 288 | + if ($globalDebug) echo "*********** New aircraft hex : ".$hex." ***********\n"; |
|
| 289 | + if ($globalAllFlights !== FALSE) $dataFound = true; |
|
| 290 | 290 | } |
| 291 | 291 | |
| 292 | 292 | if (isset($line['datetime']) && preg_match('/^(\d{4}(?:\-\d{2}){2} \d{2}(?:\:\d{2}){2})$/',$line['datetime'])) { |
| 293 | - if (!isset($this->all_flights[$id]['datetime']) || strtotime($line['datetime']) >= strtotime($this->all_flights[$id]['datetime'])) { |
|
| 293 | + if (!isset($this->all_flights[$id]['datetime']) || strtotime($line['datetime']) >= strtotime($this->all_flights[$id]['datetime'])) { |
|
| 294 | 294 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => $line['datetime'])); |
| 295 | - } else { |
|
| 295 | + } else { |
|
| 296 | 296 | 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"; |
| 297 | 297 | 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"; |
| 298 | 298 | /* |
@@ -301,38 +301,38 @@ discard block |
||
| 301 | 301 | print_r($line); |
| 302 | 302 | */ |
| 303 | 303 | return ''; |
| 304 | - } |
|
| 304 | + } |
|
| 305 | 305 | } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => date('Y-m-d H:i:s'))); |
| 306 | 306 | |
| 307 | 307 | if (isset($line['registration']) && $line['registration'] != '' && $line['registration'] != 'z.NO-REG') { |
| 308 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('registration' => $line['registration'])); |
|
| 308 | + $this->all_flights[$id] = array_merge($this->all_flights[$id],array('registration' => $line['registration'])); |
|
| 309 | 309 | } |
| 310 | 310 | if (isset($line['waypoints']) && $line['waypoints'] != '') { |
| 311 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('waypoints' => $line['waypoints'])); |
|
| 311 | + $this->all_flights[$id] = array_merge($this->all_flights[$id],array('waypoints' => $line['waypoints'])); |
|
| 312 | 312 | } |
| 313 | 313 | if (isset($line['pilot_id']) && $line['pilot_id'] != '') { |
| 314 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('pilot_id' => $line['pilot_id'])); |
|
| 314 | + $this->all_flights[$id] = array_merge($this->all_flights[$id],array('pilot_id' => $line['pilot_id'])); |
|
| 315 | 315 | } |
| 316 | 316 | if (isset($line['pilot_name']) && $line['pilot_name'] != '') { |
| 317 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('pilot_name' => $line['pilot_name'])); |
|
| 317 | + $this->all_flights[$id] = array_merge($this->all_flights[$id],array('pilot_name' => $line['pilot_name'])); |
|
| 318 | 318 | } |
| 319 | 319 | |
| 320 | 320 | 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'])) { |
| 321 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ident' => trim($line['ident']))); |
|
| 322 | - if ($this->all_flights[$id]['addedSpotter'] == 1) { |
|
| 321 | + $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ident' => trim($line['ident']))); |
|
| 322 | + if ($this->all_flights[$id]['addedSpotter'] == 1) { |
|
| 323 | 323 | $timeelapsed = microtime(true); |
| 324 | - $Spotter = new Spotter($this->db); |
|
| 325 | - $fromsource = NULL; |
|
| 326 | - if (isset($globalAirlinesSource) && $globalAirlinesSource != '') $fromsource = $globalAirlinesSource; |
|
| 327 | - elseif (isset($line['format_source']) && $line['format_source'] == 'vatsimtxt') $fromsource = 'vatsim'; |
|
| 324 | + $Spotter = new Spotter($this->db); |
|
| 325 | + $fromsource = NULL; |
|
| 326 | + if (isset($globalAirlinesSource) && $globalAirlinesSource != '') $fromsource = $globalAirlinesSource; |
|
| 327 | + elseif (isset($line['format_source']) && $line['format_source'] == 'vatsimtxt') $fromsource = 'vatsim'; |
|
| 328 | 328 | elseif (isset($line['format_source']) && $line['format_source'] == 'whazzup') $fromsource = 'ivao'; |
| 329 | 329 | elseif (isset($globalVATSIM) && $globalVATSIM) $fromsource = 'vatsim'; |
| 330 | 330 | elseif (isset($globalIVAO) && $globalIVAO) $fromsource = 'ivao'; |
| 331 | - $result = $Spotter->updateIdentSpotterData($this->all_flights[$id]['id'],$this->all_flights[$id]['ident'],$fromsource); |
|
| 331 | + $result = $Spotter->updateIdentSpotterData($this->all_flights[$id]['id'],$this->all_flights[$id]['ident'],$fromsource); |
|
| 332 | 332 | if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n"; |
| 333 | 333 | $Spotter->db = null; |
| 334 | 334 | if ($globalDebugTimeElapsed) echo 'Time elapsed for update identspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
| 335 | - } |
|
| 335 | + } |
|
| 336 | 336 | |
| 337 | 337 | /* |
| 338 | 338 | if (!isset($line['id'])) { |
@@ -342,26 +342,26 @@ discard block |
||
| 342 | 342 | else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident'])); |
| 343 | 343 | } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id'])); |
| 344 | 344 | */ |
| 345 | - 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'])); |
|
| 345 | + 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'])); |
|
| 346 | 346 | |
| 347 | - //$putinarchive = true; |
|
| 348 | - if (isset($line['departure_airport_time']) && $line['departure_airport_time'] != 0) { |
|
| 347 | + //$putinarchive = true; |
|
| 348 | + if (isset($line['departure_airport_time']) && $line['departure_airport_time'] != 0) { |
|
| 349 | 349 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport_time' => $line['departure_airport_time'])); |
| 350 | - } |
|
| 351 | - if (isset($line['arrival_airport_time']) && $line['arrival_airport_time'] != 0) { |
|
| 350 | + } |
|
| 351 | + if (isset($line['arrival_airport_time']) && $line['arrival_airport_time'] != 0) { |
|
| 352 | 352 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('arrival_airport_time' => $line['arrival_airport_time'])); |
| 353 | - } |
|
| 354 | - if (isset($line['departure_airport_icao']) && isset($line['arrival_airport_icao'])) { |
|
| 355 | - $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' => '')); |
|
| 356 | - } elseif (isset($line['departure_airport_iata']) && isset($line['arrival_airport_iata'])) { |
|
| 353 | + } |
|
| 354 | + if (isset($line['departure_airport_icao']) && isset($line['arrival_airport_icao'])) { |
|
| 355 | + $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' => '')); |
|
| 356 | + } elseif (isset($line['departure_airport_iata']) && isset($line['arrival_airport_iata'])) { |
|
| 357 | 357 | $timeelapsed = microtime(true); |
| 358 | 358 | $Spotter = new Spotter($this->db); |
| 359 | 359 | $line['departure_airport_icao'] = $Spotter->getAirportIcao($line['departure_airport_iata']); |
| 360 | 360 | $line['arrival_airport_icao'] = $Spotter->getAirportIcao($line['arrival_airport_iata']); |
| 361 | - $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 | + $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' => '')); |
|
| 362 | 362 | if ($globalDebugTimeElapsed) echo 'Time elapsed for update getAirportICAO : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
| 363 | 363 | |
| 364 | - } elseif (!isset($line['format_source']) || $line['format_source'] != 'aprs') { |
|
| 364 | + } elseif (!isset($line['format_source']) || $line['format_source'] != 'aprs') { |
|
| 365 | 365 | $timeelapsed = microtime(true); |
| 366 | 366 | $Spotter = new Spotter($this->db); |
| 367 | 367 | $route = $Spotter->getRouteInfo(trim($line['ident'])); |
@@ -375,43 +375,43 @@ discard block |
||
| 375 | 375 | if ($globalDebugTimeElapsed) echo 'Time elapsed for update getrouteinfo : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
| 376 | 376 | |
| 377 | 377 | if (isset($route['fromairport_icao']) && isset($route['toairport_icao'])) { |
| 378 | - //if ($route['FromAirport_ICAO'] != $route['ToAirport_ICAO']) { |
|
| 379 | - if ($route['fromairport_icao'] != $route['toairport_icao']) { |
|
| 378 | + //if ($route['FromAirport_ICAO'] != $route['ToAirport_ICAO']) { |
|
| 379 | + if ($route['fromairport_icao'] != $route['toairport_icao']) { |
|
| 380 | 380 | // $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'])); |
| 381 | - $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'])); |
|
| 382 | - } |
|
| 381 | + $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'])); |
|
| 382 | + } |
|
| 383 | 383 | } |
| 384 | 384 | if (!isset($globalFork)) $globalFork = TRUE; |
| 385 | 385 | if (!$globalIVAO && !$globalVATSIM && !$globalphpVMS && !$globalVAM && (!isset($line['format_source']) || $line['format_source'] != 'aprs')) { |
| 386 | 386 | if (!isset($this->all_flights[$id]['schedule_check']) || $this->all_flights[$id]['schedule_check'] === false) $this->get_Schedule($id,trim($line['ident'])); |
| 387 | 387 | } |
| 388 | - } |
|
| 388 | + } |
|
| 389 | 389 | } |
| 390 | 390 | |
| 391 | 391 | if (isset($line['speed']) && $line['speed'] != '') { |
| 392 | 392 | // $this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed' => $line[12])); |
| 393 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed' => round($line['speed']))); |
|
| 394 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed_fromsrc' => true)); |
|
| 395 | - //$dataFound = true; |
|
| 393 | + $this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed' => round($line['speed']))); |
|
| 394 | + $this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed_fromsrc' => true)); |
|
| 395 | + //$dataFound = true; |
|
| 396 | 396 | } 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'])) { |
| 397 | - $distance = $Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m'); |
|
| 398 | - if ($distance > 1000 && $distance < 10000) { |
|
| 399 | - // use datetime |
|
| 397 | + $distance = $Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m'); |
|
| 398 | + if ($distance > 1000 && $distance < 10000) { |
|
| 399 | + // use datetime |
|
| 400 | 400 | $speed = $distance/(time() - $this->all_flights[$id]['time_last_coord']); |
| 401 | 401 | $speed = $speed*3.6; |
| 402 | 402 | if ($speed < 1000) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed' => round($speed))); |
| 403 | 403 | if ($globalDebug) echo "ø Calculated Speed for ".$this->all_flights[$id]['hex']." : ".$speed." - distance : ".$distance."\n"; |
| 404 | - } |
|
| 404 | + } |
|
| 405 | 405 | } |
| 406 | 406 | |
| 407 | 407 | |
| 408 | 408 | |
| 409 | - if (isset($line['latitude']) && isset($line['longitude']) && $line['latitude'] != '' && $line['longitude'] != '' && is_numeric($line['latitude']) && is_numeric($line['longitude'])) { |
|
| 410 | - if (isset($this->all_flights[$id]['time_last_coord'])) $timediff = round(time()-$this->all_flights[$id]['time_last_coord']); |
|
| 411 | - else unset($timediff); |
|
| 412 | - 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')))) { |
|
| 409 | + if (isset($line['latitude']) && isset($line['longitude']) && $line['latitude'] != '' && $line['longitude'] != '' && is_numeric($line['latitude']) && is_numeric($line['longitude'])) { |
|
| 410 | + if (isset($this->all_flights[$id]['time_last_coord'])) $timediff = round(time()-$this->all_flights[$id]['time_last_coord']); |
|
| 411 | + else unset($timediff); |
|
| 412 | + 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')))) { |
|
| 413 | 413 | 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'])) { |
| 414 | - 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'])) { |
|
| 414 | + 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'])) { |
|
| 415 | 415 | $this->all_flights[$id]['archive_latitude'] = $line['latitude']; |
| 416 | 416 | $this->all_flights[$id]['archive_longitude'] = $line['longitude']; |
| 417 | 417 | $this->all_flights[$id]['putinarchive'] = true; |
@@ -425,16 +425,16 @@ discard block |
||
| 425 | 425 | if ($globalDebugTimeElapsed) echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
| 426 | 426 | $this->tmd = 0; |
| 427 | 427 | if ($globalDebug) echo 'FOUND : '.$this->all_flights[$id]['over_country'].' ---------------'."\n"; |
| 428 | - } |
|
| 428 | + } |
|
| 429 | 429 | } |
| 430 | 430 | |
| 431 | 431 | if (isset($line['latitude']) && $line['latitude'] != '' && $line['latitude'] != 0 && $line['latitude'] < 91 && $line['latitude'] > -90) { |
| 432 | - //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) { |
|
| 432 | + //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) { |
|
| 433 | 433 | if (!isset($this->all_flights[$id]['archive_latitude'])) $this->all_flights[$id]['archive_latitude'] = $line['latitude']; |
| 434 | 434 | 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') { |
| 435 | - $this->all_flights[$id]['livedb_latitude'] = $line['latitude']; |
|
| 436 | - $dataFound = true; |
|
| 437 | - $this->all_flights[$id]['time_last_coord'] = time(); |
|
| 435 | + $this->all_flights[$id]['livedb_latitude'] = $line['latitude']; |
|
| 436 | + $dataFound = true; |
|
| 437 | + $this->all_flights[$id]['time_last_coord'] = time(); |
|
| 438 | 438 | } |
| 439 | 439 | // elseif ($globalDebug) echo '!*!*! Ignore data, too close to previous one'."\n"; |
| 440 | 440 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('latitude' => $line['latitude'])); |
@@ -445,20 +445,20 @@ discard block |
||
| 445 | 445 | //$putinarchive = true; |
| 446 | 446 | } |
| 447 | 447 | */ |
| 448 | - /* |
|
| 448 | + /* |
|
| 449 | 449 | } elseif (isset($this->all_flights[$id]['latitude'])) { |
| 450 | 450 | if ($globalDebug) echo '!!! Strange latitude value - diff : '.abs($this->all_flights[$id]['latitude']-$line['latitude']).'- previous lat : '.$this->all_flights[$id]['latitude'].'- new lat : '.$line['latitude']."\n"; |
| 451 | 451 | } |
| 452 | 452 | */ |
| 453 | 453 | } |
| 454 | 454 | if (isset($line['longitude']) && $line['longitude'] != '' && $line['longitude'] != 0 && $line['longitude'] < 360 && $line['longitude'] > -180) { |
| 455 | - if ($line['longitude'] > 180) $line['longitude'] = $line['longitude'] - 360; |
|
| 456 | - //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) { |
|
| 455 | + if ($line['longitude'] > 180) $line['longitude'] = $line['longitude'] - 360; |
|
| 456 | + //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) { |
|
| 457 | 457 | if (!isset($this->all_flights[$id]['archive_longitude'])) $this->all_flights[$id]['archive_longitude'] = $line['longitude']; |
| 458 | 458 | 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') { |
| 459 | - $this->all_flights[$id]['livedb_longitude'] = $line['longitude']; |
|
| 460 | - $dataFound = true; |
|
| 461 | - $this->all_flights[$id]['time_last_coord'] = time(); |
|
| 459 | + $this->all_flights[$id]['livedb_longitude'] = $line['longitude']; |
|
| 460 | + $dataFound = true; |
|
| 461 | + $this->all_flights[$id]['time_last_coord'] = time(); |
|
| 462 | 462 | } |
| 463 | 463 | // elseif ($globalDebug) echo '!*!*! Ignore data, too close to previous one'."\n"; |
| 464 | 464 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('longitude' => $line['longitude'])); |
@@ -476,53 +476,53 @@ discard block |
||
| 476 | 476 | */ |
| 477 | 477 | } |
| 478 | 478 | |
| 479 | - } else if ($globalDebug && $timediff > 20) { |
|
| 479 | + } else if ($globalDebug && $timediff > 20) { |
|
| 480 | 480 | $this->tmd = $this->tmd + 1; |
| 481 | 481 | echo '!!! Too much distance in short time... for '.$this->all_flights[$id]['ident']."\n"; |
| 482 | 482 | echo 'Time : '.$timediff.'s - Distance : '.$Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m')."m -"; |
| 483 | 483 | echo 'Speed : '.(($Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m')/$timediff)*3.6)." km/h - "; |
| 484 | 484 | echo 'Lat : '.$line['latitude'].' - long : '.$line['longitude'].' - prev lat : '.$this->all_flights[$id]['latitude'].' - prev long : '.$this->all_flights[$id]['longitude']." \n"; |
| 485 | - } |
|
| 485 | + } |
|
| 486 | 486 | } |
| 487 | 487 | if (isset($line['last_update']) && $line['last_update'] != '') { |
| 488 | - if (isset($this->all_flights[$id]['last_update']) && $this->all_flights[$id]['last_update'] != $line['last_update']) $dataFound = true; |
|
| 489 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('last_update' => $line['last_update'])); |
|
| 488 | + if (isset($this->all_flights[$id]['last_update']) && $this->all_flights[$id]['last_update'] != $line['last_update']) $dataFound = true; |
|
| 489 | + $this->all_flights[$id] = array_merge($this->all_flights[$id],array('last_update' => $line['last_update'])); |
|
| 490 | 490 | } |
| 491 | 491 | if (isset($line['verticalrate']) && $line['verticalrate'] != '') { |
| 492 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('verticalrate' => $line['verticalrate'])); |
|
| 493 | - //$dataFound = true; |
|
| 492 | + $this->all_flights[$id] = array_merge($this->all_flights[$id],array('verticalrate' => $line['verticalrate'])); |
|
| 493 | + //$dataFound = true; |
|
| 494 | 494 | } |
| 495 | 495 | if (isset($line['format_source']) && $line['format_source'] != '') { |
| 496 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('format_source' => $line['format_source'])); |
|
| 496 | + $this->all_flights[$id] = array_merge($this->all_flights[$id],array('format_source' => $line['format_source'])); |
|
| 497 | 497 | } |
| 498 | 498 | if (isset($line['source_name']) && $line['source_name'] != '') { |
| 499 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('source_name' => $line['source_name'])); |
|
| 499 | + $this->all_flights[$id] = array_merge($this->all_flights[$id],array('source_name' => $line['source_name'])); |
|
| 500 | 500 | } |
| 501 | 501 | if (isset($line['emergency']) && $line['emergency'] != '') { |
| 502 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('emergency' => $line['emergency'])); |
|
| 503 | - //$dataFound = true; |
|
| 502 | + $this->all_flights[$id] = array_merge($this->all_flights[$id],array('emergency' => $line['emergency'])); |
|
| 503 | + //$dataFound = true; |
|
| 504 | 504 | } |
| 505 | 505 | if (isset($line['ground']) && $line['ground'] != '') { |
| 506 | - if (isset($this->all_flights[$id]['ground']) && $this->all_flights[$id]['ground'] == 1 && $line['ground'] == 0) { |
|
| 506 | + if (isset($this->all_flights[$id]['ground']) && $this->all_flights[$id]['ground'] == 1 && $line['ground'] == 0) { |
|
| 507 | 507 | // Here we force archive of flight because after ground it's a new one (or should be) |
| 508 | 508 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0)); |
| 509 | 509 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('forcenew' => 1)); |
| 510 | 510 | 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'))); |
| 511 | - elseif (isset($line['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id'])); |
|
| 511 | + elseif (isset($line['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id'])); |
|
| 512 | 512 | 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 | - } |
|
| 514 | - if ($line['ground'] != 1) $line['ground'] = 0; |
|
| 515 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ground' => $line['ground'])); |
|
| 516 | - //$dataFound = true; |
|
| 513 | + } |
|
| 514 | + if ($line['ground'] != 1) $line['ground'] = 0; |
|
| 515 | + $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ground' => $line['ground'])); |
|
| 516 | + //$dataFound = true; |
|
| 517 | 517 | } |
| 518 | 518 | if (isset($line['squawk']) && $line['squawk'] != '') { |
| 519 | - 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'])) { |
|
| 520 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk'])); |
|
| 521 | - $highlight = ''; |
|
| 522 | - if ($this->all_flights[$id]['squawk'] == '7500') $highlight = 'Squawk 7500 : Hijack at '.date('Y-m-d G:i').' UTC'; |
|
| 523 | - if ($this->all_flights[$id]['squawk'] == '7600') $highlight = 'Squawk 7600 : Lost Comm (radio failure) at '.date('Y-m-d G:i').' UTC'; |
|
| 524 | - if ($this->all_flights[$id]['squawk'] == '7700') $highlight = 'Squawk 7700 : Emergency at '.date('Y-m-d G:i').' UTC'; |
|
| 525 | - if ($highlight != '') { |
|
| 519 | + 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'])) { |
|
| 520 | + $this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk'])); |
|
| 521 | + $highlight = ''; |
|
| 522 | + if ($this->all_flights[$id]['squawk'] == '7500') $highlight = 'Squawk 7500 : Hijack at '.date('Y-m-d G:i').' UTC'; |
|
| 523 | + if ($this->all_flights[$id]['squawk'] == '7600') $highlight = 'Squawk 7600 : Lost Comm (radio failure) at '.date('Y-m-d G:i').' UTC'; |
|
| 524 | + if ($this->all_flights[$id]['squawk'] == '7700') $highlight = 'Squawk 7700 : Emergency at '.date('Y-m-d G:i').' UTC'; |
|
| 525 | + if ($highlight != '') { |
|
| 526 | 526 | $timeelapsed = microtime(true); |
| 527 | 527 | $Spotter = new Spotter($this->db); |
| 528 | 528 | $Spotter->setHighlightFlight($this->all_flights[$id]['id'],$highlight); |
@@ -532,38 +532,38 @@ discard block |
||
| 532 | 532 | $this->all_flights[$id]['putinarchive'] = true; |
| 533 | 533 | //$putinarchive = true; |
| 534 | 534 | //$highlight = ''; |
| 535 | - } |
|
| 535 | + } |
|
| 536 | 536 | |
| 537 | - } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk'])); |
|
| 538 | - //$dataFound = true; |
|
| 537 | + } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk'])); |
|
| 538 | + //$dataFound = true; |
|
| 539 | 539 | } |
| 540 | 540 | |
| 541 | 541 | if (isset($line['altitude']) && $line['altitude'] != '') { |
| 542 | - //if (!isset($this->all_flights[$id]['altitude']) || $this->all_flights[$id]['altitude'] == '' || ($this->all_flights[$id]['altitude'] > 0 && $line['altitude'] != 0)) { |
|
| 542 | + //if (!isset($this->all_flights[$id]['altitude']) || $this->all_flights[$id]['altitude'] == '' || ($this->all_flights[$id]['altitude'] > 0 && $line['altitude'] != 0)) { |
|
| 543 | 543 | 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; |
| 544 | 544 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('altitude' => round($line['altitude']/100))); |
| 545 | 545 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('altitude_real' => $line['altitude'])); |
| 546 | 546 | //$dataFound = true; |
| 547 | - //} elseif ($globalDebug) echo "!!! Strange altitude data... not added.\n"; |
|
| 547 | + //} elseif ($globalDebug) echo "!!! Strange altitude data... not added.\n"; |
|
| 548 | 548 | } |
| 549 | 549 | |
| 550 | 550 | if (isset($line['noarchive']) && $line['noarchive'] === true) { |
| 551 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('noarchive' => true)); |
|
| 551 | + $this->all_flights[$id] = array_merge($this->all_flights[$id],array('noarchive' => true)); |
|
| 552 | 552 | } |
| 553 | 553 | |
| 554 | 554 | if (isset($line['heading']) && $line['heading'] != '') { |
| 555 | - if (is_int($this->all_flights[$id]['heading']) && abs($this->all_flights[$id]['heading']-round($line['heading'])) > 2) $this->all_flights[$id]['putinarchive'] = true; |
|
| 556 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => round($line['heading']))); |
|
| 557 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading_fromsrc' => true)); |
|
| 558 | - //$dataFound = true; |
|
| 555 | + if (is_int($this->all_flights[$id]['heading']) && abs($this->all_flights[$id]['heading']-round($line['heading'])) > 2) $this->all_flights[$id]['putinarchive'] = true; |
|
| 556 | + $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => round($line['heading']))); |
|
| 557 | + $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading_fromsrc' => true)); |
|
| 558 | + //$dataFound = true; |
|
| 559 | 559 | } 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']) { |
| 560 | - $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']); |
|
| 561 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => round($heading))); |
|
| 562 | - if (abs($this->all_flights[$id]['heading']-round($heading)) > 2) $this->all_flights[$id]['putinarchive'] = true; |
|
| 563 | - if ($globalDebug) echo "ø Calculated Heading for ".$this->all_flights[$id]['hex']." : ".$heading."\n"; |
|
| 560 | + $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']); |
|
| 561 | + $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => round($heading))); |
|
| 562 | + if (abs($this->all_flights[$id]['heading']-round($heading)) > 2) $this->all_flights[$id]['putinarchive'] = true; |
|
| 563 | + if ($globalDebug) echo "ø Calculated Heading for ".$this->all_flights[$id]['hex']." : ".$heading."\n"; |
|
| 564 | 564 | } elseif (isset($this->all_flights[$id]['format_source']) && $this->all_flights[$id]['format_source'] == 'ACARS') { |
| 565 | - // If not enough messages and ACARS set heading to 0 |
|
| 566 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => 0)); |
|
| 565 | + // If not enough messages and ACARS set heading to 0 |
|
| 566 | + $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => 0)); |
|
| 567 | 567 | } |
| 568 | 568 | if (isset($globalSourcesupdate) && $globalSourcesupdate != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalSourcesupdate) $dataFound = false; |
| 569 | 569 | elseif (isset($globalSBS1update) && $globalSBS1update != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalSBS1update) $dataFound = false; |
@@ -574,119 +574,119 @@ discard block |
||
| 574 | 574 | //if ($dataFound == true && isset($this->all_flights[$id]['hex']) && $this->all_flights[$id]['ident'] != '' && $this->all_flights[$id]['latitude'] != '' && $this->all_flights[$id]['longitude'] != '') { |
| 575 | 575 | //if ($dataFound === true && isset($this->all_flights[$id]['hex']) && $this->all_flights[$id]['heading'] != '' && $this->all_flights[$id]['latitude'] != '' && $this->all_flights[$id]['longitude'] != '') { |
| 576 | 576 | if ($dataFound === true && isset($this->all_flights[$id]['hex'])) { |
| 577 | - $this->all_flights[$id]['lastupdate'] = time(); |
|
| 578 | - if ($this->all_flights[$id]['addedSpotter'] == 0) { |
|
| 579 | - 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'])) { |
|
| 580 | - //print_r($this->all_flights); |
|
| 581 | - //echo $this->all_flights[$id]['id'].' - '.$this->all_flights[$id]['addedSpotter']."\n"; |
|
| 582 | - //$last_hour_ident = Spotter->getIdentFromLastHour($this->all_flights[$id]['ident']); |
|
| 583 | - if (!isset($this->all_flights[$id]['forcenew']) || $this->all_flights[$id]['forcenew'] == 0) { |
|
| 577 | + $this->all_flights[$id]['lastupdate'] = time(); |
|
| 578 | + if ($this->all_flights[$id]['addedSpotter'] == 0) { |
|
| 579 | + 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'])) { |
|
| 580 | + //print_r($this->all_flights); |
|
| 581 | + //echo $this->all_flights[$id]['id'].' - '.$this->all_flights[$id]['addedSpotter']."\n"; |
|
| 582 | + //$last_hour_ident = Spotter->getIdentFromLastHour($this->all_flights[$id]['ident']); |
|
| 583 | + if (!isset($this->all_flights[$id]['forcenew']) || $this->all_flights[$id]['forcenew'] == 0) { |
|
| 584 | 584 | if ($globalDebug) echo "Check if aircraft is already in DB..."; |
| 585 | 585 | $timeelapsed = microtime(true); |
| 586 | 586 | $SpotterLive = new SpotterLive($this->db); |
| 587 | 587 | 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')) { |
| 588 | - $recent_ident = $SpotterLive->checkModeSRecent($this->all_flights[$id]['hex']); |
|
| 589 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkModeSRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
| 588 | + $recent_ident = $SpotterLive->checkModeSRecent($this->all_flights[$id]['hex']); |
|
| 589 | + if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkModeSRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
| 590 | 590 | } elseif (isset($line['id'])) { |
| 591 | - $recent_ident = $SpotterLive->checkIdRecent($line['id']); |
|
| 592 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
| 591 | + $recent_ident = $SpotterLive->checkIdRecent($line['id']); |
|
| 592 | + if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
| 593 | 593 | } elseif (isset($this->all_flights[$id]['ident']) && $this->all_flights[$id]['ident'] != '') { |
| 594 | - $recent_ident = $SpotterLive->checkIdentRecent($this->all_flights[$id]['ident']); |
|
| 595 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
| 594 | + $recent_ident = $SpotterLive->checkIdentRecent($this->all_flights[$id]['ident']); |
|
| 595 | + if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
| 596 | 596 | } else $recent_ident = ''; |
| 597 | 597 | $SpotterLive->db=null; |
| 598 | 598 | |
| 599 | 599 | if ($globalDebug && $recent_ident == '') echo " Not in DB.\n"; |
| 600 | 600 | elseif ($globalDebug && $recent_ident != '') echo " Already in DB.\n"; |
| 601 | - } else { |
|
| 601 | + } else { |
|
| 602 | 602 | $recent_ident = ''; |
| 603 | 603 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('forcenew' => 0)); |
| 604 | - } |
|
| 605 | - //if there was no aircraft with the same callsign within the last hour and go post it into the archive |
|
| 606 | - if($recent_ident == "") |
|
| 607 | - { |
|
| 604 | + } |
|
| 605 | + //if there was no aircraft with the same callsign within the last hour and go post it into the archive |
|
| 606 | + if($recent_ident == "") |
|
| 607 | + { |
|
| 608 | 608 | if ($globalDebug) echo "\o/ Add ".$this->all_flights[$id]['ident']." in archive DB : "; |
| 609 | 609 | if ($this->all_flights[$id]['departure_airport'] == "") { $this->all_flights[$id]['departure_airport'] = "NA"; } |
| 610 | 610 | if ($this->all_flights[$id]['arrival_airport'] == "") { $this->all_flights[$id]['arrival_airport'] = "NA"; } |
| 611 | 611 | //adds the spotter data for the archive |
| 612 | 612 | $ignoreImport = false; |
| 613 | 613 | foreach($globalAirportIgnore as $airportIgnore) { |
| 614 | - if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) { |
|
| 614 | + if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) { |
|
| 615 | 615 | $ignoreImport = true; |
| 616 | - } |
|
| 616 | + } |
|
| 617 | 617 | } |
| 618 | 618 | if (count($globalAirportAccept) > 0) { |
| 619 | - $ignoreImport = true; |
|
| 620 | - foreach($globalAirportIgnore as $airportIgnore) { |
|
| 619 | + $ignoreImport = true; |
|
| 620 | + foreach($globalAirportIgnore as $airportIgnore) { |
|
| 621 | 621 | if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) { |
| 622 | - $ignoreImport = false; |
|
| 622 | + $ignoreImport = false; |
|
| 623 | + } |
|
| 623 | 624 | } |
| 624 | - } |
|
| 625 | 625 | } |
| 626 | 626 | if (isset($globalAirlineIgnore) && is_array($globalAirlineIgnore)) { |
| 627 | - foreach($globalAirlineIgnore as $airlineIgnore) { |
|
| 627 | + foreach($globalAirlineIgnore as $airlineIgnore) { |
|
| 628 | 628 | 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)) { |
| 629 | - $ignoreImport = true; |
|
| 629 | + $ignoreImport = true; |
|
| 630 | + } |
|
| 630 | 631 | } |
| 631 | - } |
|
| 632 | 632 | } |
| 633 | 633 | if (isset($globalAirlineAccept) && count($globalAirlineAccept) > 0) { |
| 634 | - $ignoreImport = true; |
|
| 635 | - foreach($globalAirlineAccept as $airlineAccept) { |
|
| 634 | + $ignoreImport = true; |
|
| 635 | + foreach($globalAirlineAccept as $airlineAccept) { |
|
| 636 | 636 | 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)) { |
| 637 | - $ignoreImport = false; |
|
| 637 | + $ignoreImport = false; |
|
| 638 | + } |
|
| 638 | 639 | } |
| 639 | - } |
|
| 640 | 640 | } |
| 641 | 641 | if (isset($globalPilotIdAccept) && count($globalPilotIdAccept) > 0) { |
| 642 | - $ignoreImport = true; |
|
| 643 | - foreach($globalPilotIdAccept as $pilotIdAccept) { |
|
| 642 | + $ignoreImport = true; |
|
| 643 | + foreach($globalPilotIdAccept as $pilotIdAccept) { |
|
| 644 | 644 | if ($this->all_flights[$id]['pilot_id'] == $pilotIdAccept) { |
| 645 | - $ignoreImport = false; |
|
| 645 | + $ignoreImport = false; |
|
| 646 | + } |
|
| 646 | 647 | } |
| 647 | - } |
|
| 648 | 648 | } |
| 649 | 649 | |
| 650 | 650 | if (!$ignoreImport) { |
| 651 | - $highlight = ''; |
|
| 652 | - if ($this->all_flights[$id]['squawk'] == '7500') $highlight = 'Squawk 7500 : Hijack'; |
|
| 653 | - if ($this->all_flights[$id]['squawk'] == '7600') $highlight = 'Squawk 7600 : Lost Comm (radio failure)'; |
|
| 654 | - if ($this->all_flights[$id]['squawk'] == '7700') $highlight = 'Squawk 7700 : Emergency'; |
|
| 655 | - 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'))); |
|
| 656 | - $timeelapsed = microtime(true); |
|
| 657 | - $Spotter = new Spotter($this->db); |
|
| 658 | - $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']); |
|
| 659 | - $Spotter->db = null; |
|
| 660 | - if ($globalDebug && isset($result)) echo $result."\n"; |
|
| 661 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
| 651 | + $highlight = ''; |
|
| 652 | + if ($this->all_flights[$id]['squawk'] == '7500') $highlight = 'Squawk 7500 : Hijack'; |
|
| 653 | + if ($this->all_flights[$id]['squawk'] == '7600') $highlight = 'Squawk 7600 : Lost Comm (radio failure)'; |
|
| 654 | + if ($this->all_flights[$id]['squawk'] == '7700') $highlight = 'Squawk 7700 : Emergency'; |
|
| 655 | + 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'))); |
|
| 656 | + $timeelapsed = microtime(true); |
|
| 657 | + $Spotter = new Spotter($this->db); |
|
| 658 | + $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']); |
|
| 659 | + $Spotter->db = null; |
|
| 660 | + if ($globalDebug && isset($result)) echo $result."\n"; |
|
| 661 | + if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
| 662 | 662 | |
| 663 | - // Add source stat in DB |
|
| 664 | - $Stats = new Stats($this->db); |
|
| 665 | - if (!empty($this->stats)) { |
|
| 663 | + // Add source stat in DB |
|
| 664 | + $Stats = new Stats($this->db); |
|
| 665 | + if (!empty($this->stats)) { |
|
| 666 | 666 | if ($globalDebug) echo 'Add source stats : '; |
| 667 | - foreach($this->stats as $date => $data) { |
|
| 668 | - foreach($data as $source => $sourced) { |
|
| 669 | - //print_r($sourced); |
|
| 670 | - if (isset($sourced['polar'])) echo $Stats->addStatSource(json_encode($sourced['polar']),$source,'polar',$date); |
|
| 671 | - if (isset($sourced['hist'])) echo $Stats->addStatSource(json_encode($sourced['hist']),$source,'hist',$date); |
|
| 672 | - if (isset($sourced['msg'])) { |
|
| 673 | - if (time() - $sourced['msg']['date'] > 10) { |
|
| 674 | - $nbmsg = round($sourced['msg']['nb']/(time() - $sourced['msg']['date'])); |
|
| 675 | - echo $Stats->addStatSource($nbmsg,$source,'msg',$date); |
|
| 676 | - unset($this->stats[$date][$source]['msg']); |
|
| 677 | - } |
|
| 678 | - } |
|
| 679 | - } |
|
| 680 | - if ($date != date('Y-m-d')) { |
|
| 681 | - unset($this->stats[$date]); |
|
| 682 | - } |
|
| 683 | - } |
|
| 684 | - if ($globalDebug) echo 'Done'."\n"; |
|
| 685 | - |
|
| 686 | - } |
|
| 687 | - $Stats->db = null; |
|
| 667 | + foreach($this->stats as $date => $data) { |
|
| 668 | + foreach($data as $source => $sourced) { |
|
| 669 | + //print_r($sourced); |
|
| 670 | + if (isset($sourced['polar'])) echo $Stats->addStatSource(json_encode($sourced['polar']),$source,'polar',$date); |
|
| 671 | + if (isset($sourced['hist'])) echo $Stats->addStatSource(json_encode($sourced['hist']),$source,'hist',$date); |
|
| 672 | + if (isset($sourced['msg'])) { |
|
| 673 | + if (time() - $sourced['msg']['date'] > 10) { |
|
| 674 | + $nbmsg = round($sourced['msg']['nb']/(time() - $sourced['msg']['date'])); |
|
| 675 | + echo $Stats->addStatSource($nbmsg,$source,'msg',$date); |
|
| 676 | + unset($this->stats[$date][$source]['msg']); |
|
| 677 | + } |
|
| 678 | + } |
|
| 679 | + } |
|
| 680 | + if ($date != date('Y-m-d')) { |
|
| 681 | + unset($this->stats[$date]); |
|
| 682 | + } |
|
| 683 | + } |
|
| 684 | + if ($globalDebug) echo 'Done'."\n"; |
|
| 685 | + |
|
| 686 | + } |
|
| 687 | + $Stats->db = null; |
|
| 688 | 688 | |
| 689 | - $this->del(); |
|
| 689 | + $this->del(); |
|
| 690 | 690 | } elseif ($globalDebug) echo 'Ignore data'."\n"; |
| 691 | 691 | //$ignoreImport = false; |
| 692 | 692 | $this->all_flights[$id]['addedSpotter'] = 1; |
@@ -704,18 +704,18 @@ discard block |
||
| 704 | 704 | */ |
| 705 | 705 | //SpotterLive->deleteLiveSpotterDataByIdent($this->all_flights[$id]['ident']); |
| 706 | 706 | if ($this->last_delete == 0 || time() - $this->last_delete > 1800) { |
| 707 | - if ($globalDebug) echo "---- Deleting Live Spotter data older than 9 hours..."; |
|
| 708 | - //SpotterLive->deleteLiveSpotterDataNotUpdated(); |
|
| 709 | - $SpotterLive = new SpotterLive($this->db); |
|
| 710 | - $SpotterLive->deleteLiveSpotterData(); |
|
| 711 | - $SpotterLive->db=null; |
|
| 712 | - if ($globalDebug) echo " Done\n"; |
|
| 713 | - $this->last_delete = time(); |
|
| 707 | + if ($globalDebug) echo "---- Deleting Live Spotter data older than 9 hours..."; |
|
| 708 | + //SpotterLive->deleteLiveSpotterDataNotUpdated(); |
|
| 709 | + $SpotterLive = new SpotterLive($this->db); |
|
| 710 | + $SpotterLive->deleteLiveSpotterData(); |
|
| 711 | + $SpotterLive->db=null; |
|
| 712 | + if ($globalDebug) echo " Done\n"; |
|
| 713 | + $this->last_delete = time(); |
|
| 714 | 714 | } |
| 715 | - } else { |
|
| 715 | + } else { |
|
| 716 | 716 | 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')) { |
| 717 | - $this->all_flights[$id]['id'] = $recent_ident; |
|
| 718 | - $this->all_flights[$id]['addedSpotter'] = 1; |
|
| 717 | + $this->all_flights[$id]['id'] = $recent_ident; |
|
| 718 | + $this->all_flights[$id]['addedSpotter'] = 1; |
|
| 719 | 719 | } |
| 720 | 720 | if (isset($globalDaemon) && !$globalDaemon) { |
| 721 | 721 | $Spotter = new Spotter($this->db); |
@@ -723,14 +723,14 @@ discard block |
||
| 723 | 723 | $Spotter->db = null; |
| 724 | 724 | } |
| 725 | 725 | |
| 726 | - } |
|
| 726 | + } |
|
| 727 | + } |
|
| 727 | 728 | } |
| 728 | - } |
|
| 729 | - //adds the spotter LIVE data |
|
| 730 | - //SpotterLive->addLiveSpotterData($flightaware_id, $ident, $aircraft_type, $departure_airport, $arrival_airport, $latitude, $longitude, $waypoints, $altitude, $heading, $groundspeed); |
|
| 731 | - //echo "\nAdd in Live !! \n"; |
|
| 732 | - //echo "{$line[8]} {$line[7]} - MODES:{$line[4]} CALLSIGN:{$line[10]} ALT:{$line[11]} VEL:{$line[12]} HDG:{$line[13]} LAT:{$line[14]} LON:{$line[15]} VR:{$line[16]} SQUAWK:{$line[17]}\n"; |
|
| 733 | - if ($globalDebug) { |
|
| 729 | + //adds the spotter LIVE data |
|
| 730 | + //SpotterLive->addLiveSpotterData($flightaware_id, $ident, $aircraft_type, $departure_airport, $arrival_airport, $latitude, $longitude, $waypoints, $altitude, $heading, $groundspeed); |
|
| 731 | + //echo "\nAdd in Live !! \n"; |
|
| 732 | + //echo "{$line[8]} {$line[7]} - MODES:{$line[4]} CALLSIGN:{$line[10]} ALT:{$line[11]} VEL:{$line[12]} HDG:{$line[13]} LAT:{$line[14]} LON:{$line[15]} VR:{$line[16]} SQUAWK:{$line[17]}\n"; |
|
| 733 | + if ($globalDebug) { |
|
| 734 | 734 | if ((isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM) || (isset($globalphpVMS) && $globalphpVMS) || (isset($globalVAM) && $globalVAM)) { |
| 735 | 735 | if (isset($this->all_flights[$id]['source_name'])) echo 'DATA : hex : '.$this->all_flights[$id]['hex'].' - ident : '.$this->all_flights[$id]['ident'].' - ICAO : '.$this->all_flights[$id]['aircraft_icao'].' - Departure Airport : '.$this->all_flights[$id]['departure_airport'].' - Arrival Airport : '.$this->all_flights[$id]['arrival_airport'].' - Latitude : '.$this->all_flights[$id]['latitude'].' - Longitude : '.$this->all_flights[$id]['longitude'].' - waypoints : '.$this->all_flights[$id]['waypoints'].' - Altitude : '.$this->all_flights[$id]['altitude'].' - Heading : '.$this->all_flights[$id]['heading'].' - Speed : '.$this->all_flights[$id]['speed'].' - Departure Airport Time : '.$this->all_flights[$id]['departure_airport_time'].' - Arrival Airport time : '.$this->all_flights[$id]['arrival_airport_time'].' - Pilot : '.$this->all_flights[$id]['pilot_name'].' - Source name : '.$this->all_flights[$id]['source_name']."\n"; |
| 736 | 736 | else echo 'DATA : hex : '.$this->all_flights[$id]['hex'].' - ident : '.$this->all_flights[$id]['ident'].' - ICAO : '.$this->all_flights[$id]['aircraft_icao'].' - Departure Airport : '.$this->all_flights[$id]['departure_airport'].' - Arrival Airport : '.$this->all_flights[$id]['arrival_airport'].' - Latitude : '.$this->all_flights[$id]['latitude'].' - Longitude : '.$this->all_flights[$id]['longitude'].' - waypoints : '.$this->all_flights[$id]['waypoints'].' - Altitude : '.$this->all_flights[$id]['altitude'].' - Heading : '.$this->all_flights[$id]['heading'].' - Speed : '.$this->all_flights[$id]['speed'].' - Departure Airport Time : '.$this->all_flights[$id]['departure_airport_time'].' - Arrival Airport time : '.$this->all_flights[$id]['arrival_airport_time'].' - Pilot : '.$this->all_flights[$id]['pilot_name']."\n"; |
@@ -738,49 +738,49 @@ discard block |
||
| 738 | 738 | if (isset($this->all_flights[$id]['source_name'])) echo 'DATA : hex : '.$this->all_flights[$id]['hex'].' - ident : '.$this->all_flights[$id]['ident'].' - ICAO : '.$this->all_flights[$id]['aircraft_icao'].' - Departure Airport : '.$this->all_flights[$id]['departure_airport'].' - Arrival Airport : '.$this->all_flights[$id]['arrival_airport'].' - Latitude : '.$this->all_flights[$id]['latitude'].' - Longitude : '.$this->all_flights[$id]['longitude'].' - waypoints : '.$this->all_flights[$id]['waypoints'].' - Altitude : '.$this->all_flights[$id]['altitude'].' - Heading : '.$this->all_flights[$id]['heading'].' - Speed : '.$this->all_flights[$id]['speed'].' - Departure Airport Time : '.$this->all_flights[$id]['departure_airport_time'].' - Arrival Airport time : '.$this->all_flights[$id]['arrival_airport_time'].' - Source Name : '.$this->all_flights[$id]['source_name']."\n"; |
| 739 | 739 | else echo 'DATA : hex : '.$this->all_flights[$id]['hex'].' - ident : '.$this->all_flights[$id]['ident'].' - ICAO : '.$this->all_flights[$id]['aircraft_icao'].' - Departure Airport : '.$this->all_flights[$id]['departure_airport'].' - Arrival Airport : '.$this->all_flights[$id]['arrival_airport'].' - Latitude : '.$this->all_flights[$id]['latitude'].' - Longitude : '.$this->all_flights[$id]['longitude'].' - waypoints : '.$this->all_flights[$id]['waypoints'].' - Altitude : '.$this->all_flights[$id]['altitude'].' - Heading : '.$this->all_flights[$id]['heading'].' - Speed : '.$this->all_flights[$id]['speed'].' - Departure Airport Time : '.$this->all_flights[$id]['departure_airport_time'].' - Arrival Airport time : '.$this->all_flights[$id]['arrival_airport_time']."\n"; |
| 740 | 740 | } |
| 741 | - } |
|
| 742 | - $ignoreImport = false; |
|
| 743 | - if ($this->all_flights[$id]['departure_airport'] == "") { $this->all_flights[$id]['departure_airport'] = "NA"; } |
|
| 744 | - if ($this->all_flights[$id]['arrival_airport'] == "") { $this->all_flights[$id]['arrival_airport'] = "NA"; } |
|
| 741 | + } |
|
| 742 | + $ignoreImport = false; |
|
| 743 | + if ($this->all_flights[$id]['departure_airport'] == "") { $this->all_flights[$id]['departure_airport'] = "NA"; } |
|
| 744 | + if ($this->all_flights[$id]['arrival_airport'] == "") { $this->all_flights[$id]['arrival_airport'] = "NA"; } |
|
| 745 | 745 | |
| 746 | - foreach($globalAirportIgnore as $airportIgnore) { |
|
| 747 | - if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) { |
|
| 748 | - $ignoreImport = true; |
|
| 746 | + foreach($globalAirportIgnore as $airportIgnore) { |
|
| 747 | + if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) { |
|
| 748 | + $ignoreImport = true; |
|
| 749 | + } |
|
| 749 | 750 | } |
| 750 | - } |
|
| 751 | - if (count($globalAirportAccept) > 0) { |
|
| 752 | - $ignoreImport = true; |
|
| 753 | - foreach($globalAirportIgnore as $airportIgnore) { |
|
| 754 | - if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) { |
|
| 751 | + if (count($globalAirportAccept) > 0) { |
|
| 752 | + $ignoreImport = true; |
|
| 753 | + foreach($globalAirportIgnore as $airportIgnore) { |
|
| 754 | + if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) { |
|
| 755 | 755 | $ignoreImport = false; |
| 756 | - } |
|
| 756 | + } |
|
| 757 | 757 | } |
| 758 | - } |
|
| 759 | - if (isset($globalAirlineIgnore) && is_array($globalAirlineIgnore)) { |
|
| 758 | + } |
|
| 759 | + if (isset($globalAirlineIgnore) && is_array($globalAirlineIgnore)) { |
|
| 760 | 760 | foreach($globalAirlineIgnore as $airlineIgnore) { |
| 761 | - 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)) { |
|
| 761 | + 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)) { |
|
| 762 | 762 | $ignoreImport = true; |
| 763 | - } |
|
| 763 | + } |
|
| 764 | 764 | } |
| 765 | - } |
|
| 766 | - if (isset($globalAirlineAccept) && count($globalAirlineAccept) > 0) { |
|
| 765 | + } |
|
| 766 | + if (isset($globalAirlineAccept) && count($globalAirlineAccept) > 0) { |
|
| 767 | 767 | $ignoreImport = true; |
| 768 | 768 | foreach($globalAirlineAccept as $airlineAccept) { |
| 769 | - 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)) { |
|
| 769 | + 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)) { |
|
| 770 | 770 | $ignoreImport = false; |
| 771 | - } |
|
| 771 | + } |
|
| 772 | 772 | } |
| 773 | - } |
|
| 774 | - if (isset($globalPilotIdAccept) && count($globalPilotIdAccept) > 0) { |
|
| 773 | + } |
|
| 774 | + if (isset($globalPilotIdAccept) && count($globalPilotIdAccept) > 0) { |
|
| 775 | 775 | $ignoreImport = true; |
| 776 | 776 | foreach($globalPilotIdAccept as $pilotIdAccept) { |
| 777 | - if ($this->all_flights[$id]['pilot_id'] == $pilotIdAccept) { |
|
| 778 | - $ignoreImport = false; |
|
| 779 | - } |
|
| 777 | + if ($this->all_flights[$id]['pilot_id'] == $pilotIdAccept) { |
|
| 778 | + $ignoreImport = false; |
|
| 779 | + } |
|
| 780 | + } |
|
| 780 | 781 | } |
| 781 | - } |
|
| 782 | 782 | |
| 783 | - if (!$ignoreImport) { |
|
| 783 | + if (!$ignoreImport) { |
|
| 784 | 784 | 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'])) { |
| 785 | 785 | if ($globalDebug) echo "\o/ Add ".$this->all_flights[$id]['ident']." from ".$this->all_flights[$id]['format_source']." in Live DB : "; |
| 786 | 786 | $timeelapsed = microtime(true); |
@@ -818,7 +818,7 @@ discard block |
||
| 818 | 818 | if ($stats_heading == 16) $stats_heading = 0; |
| 819 | 819 | if (!isset($this->stats[$current_date][$source]['polar'][1])) { |
| 820 | 820 | for ($i=0;$i<=15;$i++) { |
| 821 | - $this->stats[$current_date][$source]['polar'][$i] = 0; |
|
| 821 | + $this->stats[$current_date][$source]['polar'][$i] = 0; |
|
| 822 | 822 | } |
| 823 | 823 | $this->stats[$current_date][$source]['polar'][$stats_heading] = $stats_distance; |
| 824 | 824 | } else { |
@@ -831,11 +831,11 @@ discard block |
||
| 831 | 831 | //var_dump($this->stats); |
| 832 | 832 | if (!isset($this->stats[$current_date][$source]['hist'][$distance])) { |
| 833 | 833 | if (isset($this->stats[$current_date][$source]['hist'][0])) { |
| 834 | - end($this->stats[$current_date][$source]['hist']); |
|
| 835 | - $mini = key($this->stats[$current_date][$source]['hist'])+10; |
|
| 834 | + end($this->stats[$current_date][$source]['hist']); |
|
| 835 | + $mini = key($this->stats[$current_date][$source]['hist'])+10; |
|
| 836 | 836 | } else $mini = 0; |
| 837 | 837 | for ($i=$mini;$i<=$distance;$i+=10) { |
| 838 | - $this->stats[$current_date][$source]['hist'][$i] = 0; |
|
| 838 | + $this->stats[$current_date][$source]['hist'][$i] = 0; |
|
| 839 | 839 | } |
| 840 | 840 | $this->stats[$current_date][$source]['hist'][$distance] = 1; |
| 841 | 841 | } else { |
@@ -852,22 +852,22 @@ discard block |
||
| 852 | 852 | |
| 853 | 853 | |
| 854 | 854 | if ($this->last_delete_hourly == 0 || time() - $this->last_delete_hourly > 900) { |
| 855 | - if ($globalDebug) echo "---- Deleting Live Spotter data Not updated since 2 hour..."; |
|
| 856 | - $SpotterLive = new SpotterLive($this->db); |
|
| 857 | - $SpotterLive->deleteLiveSpotterDataNotUpdated(); |
|
| 858 | - $SpotterLive->db = null; |
|
| 859 | - //SpotterLive->deleteLiveSpotterData(); |
|
| 860 | - if ($globalDebug) echo " Done\n"; |
|
| 861 | - $this->last_delete_hourly = time(); |
|
| 855 | + if ($globalDebug) echo "---- Deleting Live Spotter data Not updated since 2 hour..."; |
|
| 856 | + $SpotterLive = new SpotterLive($this->db); |
|
| 857 | + $SpotterLive->deleteLiveSpotterDataNotUpdated(); |
|
| 858 | + $SpotterLive->db = null; |
|
| 859 | + //SpotterLive->deleteLiveSpotterData(); |
|
| 860 | + if ($globalDebug) echo " Done\n"; |
|
| 861 | + $this->last_delete_hourly = time(); |
|
| 862 | 862 | } |
| 863 | 863 | |
| 864 | - } |
|
| 865 | - //$ignoreImport = false; |
|
| 864 | + } |
|
| 865 | + //$ignoreImport = false; |
|
| 866 | 866 | } |
| 867 | 867 | //if (function_exists('pcntl_fork') && $globalFork) pcntl_signal(SIGCHLD, SIG_IGN); |
| 868 | 868 | if ($send) return $this->all_flights[$id]; |
| 869 | - } |
|
| 869 | + } |
|
| 870 | + } |
|
| 870 | 871 | } |
| 871 | - } |
|
| 872 | 872 | } |
| 873 | 873 | ?> |
@@ -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 | |
@@ -64,8 +64,8 @@ discard block |
||
| 64 | 64 | $schedule = $Schedule->fetchSchedule($operator); |
| 65 | 65 | if (count($schedule) > 0 && isset($schedule['DepartureTime']) && isset($schedule['ArrivalTime'])) { |
| 66 | 66 | if ($globalDebug) echo "-> Schedule info for ".$operator." (".$ident.")\n"; |
| 67 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport_time' => $schedule['DepartureTime'])); |
|
| 68 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('arrival_airport_time' => $schedule['ArrivalTime'])); |
|
| 67 | + $this->all_flights[$id] = array_merge($this->all_flights[$id], array('departure_airport_time' => $schedule['DepartureTime'])); |
|
| 68 | + $this->all_flights[$id] = array_merge($this->all_flights[$id], array('arrival_airport_time' => $schedule['ArrivalTime'])); |
|
| 69 | 69 | // Should also check if route schedule = route from DB |
| 70 | 70 | if ($schedule['DepartureAirportIATA'] != '') { |
| 71 | 71 | if ($this->all_flights[$id]['departure_airport'] != $Spotter->getAirportIcao($schedule['DepartureAirportIATA'])) { |
@@ -85,7 +85,7 @@ discard block |
||
| 85 | 85 | } |
| 86 | 86 | } |
| 87 | 87 | } |
| 88 | - $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']); |
|
| 88 | + $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 | 89 | } |
| 90 | 90 | } |
| 91 | 91 | } |
@@ -115,7 +115,7 @@ discard block |
||
| 115 | 115 | //echo $this->all_flights[$key]['id'].' - '.$this->all_flights[$key]['latitude'].' '.$this->all_flights[$key]['longitude']."\n"; |
| 116 | 116 | $Spotter = new Spotter($this->db); |
| 117 | 117 | $real_arrival = $this->arrival($key); |
| 118 | - $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']); |
|
| 118 | + $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']); |
|
| 119 | 119 | } |
| 120 | 120 | } |
| 121 | 121 | } |
@@ -128,7 +128,7 @@ discard block |
||
| 128 | 128 | $airport_time = ''; |
| 129 | 129 | if (!isset($globalClosestMinDist) || $globalClosestMinDist == '') $globalClosestMinDist = 50; |
| 130 | 130 | if ($this->all_flights[$key]['latitude'] != '' && $this->all_flights[$key]['longitude'] != '') { |
| 131 | - $closestAirports = $Spotter->closestAirports($this->all_flights[$key]['latitude'],$this->all_flights[$key]['longitude'],$globalClosestMinDist); |
|
| 131 | + $closestAirports = $Spotter->closestAirports($this->all_flights[$key]['latitude'], $this->all_flights[$key]['longitude'], $globalClosestMinDist); |
|
| 132 | 132 | if (isset($closestAirports[0])) { |
| 133 | 133 | if (isset($this->all_flights[$key]['arrival_airport']) && $this->all_flights[$key]['arrival_airport'] == $closestAirports[0]['icao']) { |
| 134 | 134 | $airport_icao = $closestAirports[0]['icao']; |
@@ -143,7 +143,7 @@ discard block |
||
| 143 | 143 | break; |
| 144 | 144 | } |
| 145 | 145 | } |
| 146 | - } 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))) { |
|
| 146 | + } 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))) { |
|
| 147 | 147 | $airport_icao = $closestAirports[0]['icao']; |
| 148 | 148 | $airport_time = $this->all_flights[$key]['datetime']; |
| 149 | 149 | } else { |
@@ -156,7 +156,7 @@ discard block |
||
| 156 | 156 | } else { |
| 157 | 157 | if ($globalDebug) echo "---- No latitude or longitude. Ident : ".$this->all_flights[$key]['ident']."\n"; |
| 158 | 158 | } |
| 159 | - return array('airport_icao' => $airport_icao,'airport_time' => $airport_time); |
|
| 159 | + return array('airport_icao' => $airport_icao, 'airport_time' => $airport_time); |
|
| 160 | 160 | } |
| 161 | 161 | |
| 162 | 162 | |
@@ -167,7 +167,7 @@ discard block |
||
| 167 | 167 | if ($globalDebug) echo 'Delete old values and update latest data...'."\n"; |
| 168 | 168 | foreach ($this->all_flights as $key => $flight) { |
| 169 | 169 | if (isset($flight['lastupdate'])) { |
| 170 | - if ($flight['lastupdate'] < (time()-3000)) { |
|
| 170 | + if ($flight['lastupdate'] < (time() - 3000)) { |
|
| 171 | 171 | if (isset($this->all_flights[$key]['id'])) { |
| 172 | 172 | if ($globalDebug) echo "--- Delete old values with id ".$this->all_flights[$key]['id']."\n"; |
| 173 | 173 | /* |
@@ -178,7 +178,7 @@ discard block |
||
| 178 | 178 | $real_arrival = $this->arrival($key); |
| 179 | 179 | $Spotter = new Spotter($this->db); |
| 180 | 180 | if ($this->all_flights[$key]['latitude'] != '' && $this->all_flights[$key]['longitude'] != '') { |
| 181 | - $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']); |
|
| 181 | + $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']); |
|
| 182 | 182 | if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n"; |
| 183 | 183 | } |
| 184 | 184 | // Put in archive |
@@ -214,7 +214,7 @@ discard block |
||
| 214 | 214 | $send = false; |
| 215 | 215 | |
| 216 | 216 | // SBS format is CSV format |
| 217 | - if(is_array($line) && isset($line['hex'])) { |
|
| 217 | + if (is_array($line) && isset($line['hex'])) { |
|
| 218 | 218 | //print_r($line); |
| 219 | 219 | if ($line['hex'] != '' && $line['hex'] != '00000' && $line['hex'] != '000000' && $line['hex'] != '111111' && ctype_xdigit($line['hex']) && strlen($line['hex']) === 6) { |
| 220 | 220 | |
@@ -248,7 +248,7 @@ discard block |
||
| 248 | 248 | //print_r($this->all_flights); |
| 249 | 249 | if (!isset($this->all_flights[$id]['hex']) && ctype_xdigit($hex)) { |
| 250 | 250 | $this->all_flights[$id] = array('hex' => $hex); |
| 251 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0)); |
|
| 251 | + $this->all_flights[$id] = array_merge($this->all_flights[$id], array('addedSpotter' => 0)); |
|
| 252 | 252 | //if (isset($line['datetime']) && preg_match('/^(\d{4}(?:\-\d{2}){2} \d{2}(?:\:\d{2}){2})$/',$line['datetime'])) { |
| 253 | 253 | //$this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => $line['datetime'])); |
| 254 | 254 | //} else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => date('Y-m-d H:i:s'))); |
@@ -258,7 +258,7 @@ discard block |
||
| 258 | 258 | $Spotter = new Spotter($this->db); |
| 259 | 259 | $aircraft_icao = $Spotter->getAllAircraftType($hex); |
| 260 | 260 | $Spotter->db = null; |
| 261 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update getallaircrattype : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
| 261 | + if ($globalDebugTimeElapsed) echo 'Time elapsed for update getallaircrattype : '.round(microtime(true) - $timeelapsed, 2).'s'."\n"; |
|
| 262 | 262 | |
| 263 | 263 | if ($aircraft_icao == '' && isset($line['aircraft_type'])) { |
| 264 | 264 | if ($line['aircraft_type'] == 'PARA_GLIDER') $aircraft_icao = 'GLID'; |
@@ -266,32 +266,32 @@ discard block |
||
| 266 | 266 | elseif ($line['aircraft_type'] == 'TOW_PLANE') $aircraft_icao = 'TOWPLANE'; |
| 267 | 267 | elseif ($line['aircraft_type'] == 'POWERED_AIRCRAFT') $aircraft_icao = 'POWAIRC'; |
| 268 | 268 | } |
| 269 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao)); |
|
| 269 | + $this->all_flights[$id] = array_merge($this->all_flights[$id], array('aircraft_icao' => $aircraft_icao)); |
|
| 270 | 270 | } else if (isset($line['aircraft_name'])) { |
| 271 | 271 | // Get aircraft ICAO from aircraft name |
| 272 | 272 | $Spotter = new Spotter($this->db); |
| 273 | 273 | $aircraft_icao = $Spotter->getAircraftIcao($line['aircraft_name']); |
| 274 | 274 | $Spotter->db = null; |
| 275 | - if ($aircraft_icao != '') $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao)); |
|
| 276 | - else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => 'NA')); |
|
| 277 | - } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $line['aircraft_icao'])); |
|
| 278 | - $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)); |
|
| 279 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('lastupdate' => time())); |
|
| 275 | + if ($aircraft_icao != '') $this->all_flights[$id] = array_merge($this->all_flights[$id], array('aircraft_icao' => $aircraft_icao)); |
|
| 276 | + else $this->all_flights[$id] = array_merge($this->all_flights[$id], array('aircraft_icao' => 'NA')); |
|
| 277 | + } else $this->all_flights[$id] = array_merge($this->all_flights[$id], array('aircraft_icao' => $line['aircraft_icao'])); |
|
| 278 | + $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)); |
|
| 279 | + $this->all_flights[$id] = array_merge($this->all_flights[$id], array('lastupdate' => time())); |
|
| 280 | 280 | if (!isset($line['id'])) { |
| 281 | 281 | if (!isset($globalDaemon)) $globalDaemon = TRUE; |
| 282 | 282 | // 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'))); |
| 283 | 283 | // 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'))); |
| 284 | - 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'))); |
|
| 284 | + 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'))); |
|
| 285 | 285 | //else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident'])); |
| 286 | - } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id'])); |
|
| 286 | + } else $this->all_flights[$id] = array_merge($this->all_flights[$id], array('id' => $line['id'])); |
|
| 287 | 287 | |
| 288 | 288 | if ($globalDebug) echo "*********** New aircraft hex : ".$hex." ***********\n"; |
| 289 | 289 | if ($globalAllFlights !== FALSE) $dataFound = true; |
| 290 | 290 | } |
| 291 | 291 | |
| 292 | - if (isset($line['datetime']) && preg_match('/^(\d{4}(?:\-\d{2}){2} \d{2}(?:\:\d{2}){2})$/',$line['datetime'])) { |
|
| 292 | + if (isset($line['datetime']) && preg_match('/^(\d{4}(?:\-\d{2}){2} \d{2}(?:\:\d{2}){2})$/', $line['datetime'])) { |
|
| 293 | 293 | if (!isset($this->all_flights[$id]['datetime']) || strtotime($line['datetime']) >= strtotime($this->all_flights[$id]['datetime'])) { |
| 294 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => $line['datetime'])); |
|
| 294 | + $this->all_flights[$id] = array_merge($this->all_flights[$id], array('datetime' => $line['datetime'])); |
|
| 295 | 295 | } else { |
| 296 | 296 | 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"; |
| 297 | 297 | 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"; |
@@ -302,23 +302,23 @@ discard block |
||
| 302 | 302 | */ |
| 303 | 303 | return ''; |
| 304 | 304 | } |
| 305 | - } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => date('Y-m-d H:i:s'))); |
|
| 305 | + } else $this->all_flights[$id] = array_merge($this->all_flights[$id], array('datetime' => date('Y-m-d H:i:s'))); |
|
| 306 | 306 | |
| 307 | 307 | if (isset($line['registration']) && $line['registration'] != '' && $line['registration'] != 'z.NO-REG') { |
| 308 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('registration' => $line['registration'])); |
|
| 308 | + $this->all_flights[$id] = array_merge($this->all_flights[$id], array('registration' => $line['registration'])); |
|
| 309 | 309 | } |
| 310 | 310 | if (isset($line['waypoints']) && $line['waypoints'] != '') { |
| 311 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('waypoints' => $line['waypoints'])); |
|
| 311 | + $this->all_flights[$id] = array_merge($this->all_flights[$id], array('waypoints' => $line['waypoints'])); |
|
| 312 | 312 | } |
| 313 | 313 | if (isset($line['pilot_id']) && $line['pilot_id'] != '') { |
| 314 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('pilot_id' => $line['pilot_id'])); |
|
| 314 | + $this->all_flights[$id] = array_merge($this->all_flights[$id], array('pilot_id' => $line['pilot_id'])); |
|
| 315 | 315 | } |
| 316 | 316 | if (isset($line['pilot_name']) && $line['pilot_name'] != '') { |
| 317 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('pilot_name' => $line['pilot_name'])); |
|
| 317 | + $this->all_flights[$id] = array_merge($this->all_flights[$id], array('pilot_name' => $line['pilot_name'])); |
|
| 318 | 318 | } |
| 319 | 319 | |
| 320 | 320 | 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'])) { |
| 321 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ident' => trim($line['ident']))); |
|
| 321 | + $this->all_flights[$id] = array_merge($this->all_flights[$id], array('ident' => trim($line['ident']))); |
|
| 322 | 322 | if ($this->all_flights[$id]['addedSpotter'] == 1) { |
| 323 | 323 | $timeelapsed = microtime(true); |
| 324 | 324 | $Spotter = new Spotter($this->db); |
@@ -328,10 +328,10 @@ discard block |
||
| 328 | 328 | elseif (isset($line['format_source']) && $line['format_source'] == 'whazzup') $fromsource = 'ivao'; |
| 329 | 329 | elseif (isset($globalVATSIM) && $globalVATSIM) $fromsource = 'vatsim'; |
| 330 | 330 | elseif (isset($globalIVAO) && $globalIVAO) $fromsource = 'ivao'; |
| 331 | - $result = $Spotter->updateIdentSpotterData($this->all_flights[$id]['id'],$this->all_flights[$id]['ident'],$fromsource); |
|
| 331 | + $result = $Spotter->updateIdentSpotterData($this->all_flights[$id]['id'], $this->all_flights[$id]['ident'], $fromsource); |
|
| 332 | 332 | if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n"; |
| 333 | 333 | $Spotter->db = null; |
| 334 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update identspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
| 334 | + if ($globalDebugTimeElapsed) echo 'Time elapsed for update identspotterdata : '.round(microtime(true) - $timeelapsed, 2).'s'."\n"; |
|
| 335 | 335 | } |
| 336 | 336 | |
| 337 | 337 | /* |
@@ -342,24 +342,24 @@ discard block |
||
| 342 | 342 | else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident'])); |
| 343 | 343 | } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id'])); |
| 344 | 344 | */ |
| 345 | - 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'])); |
|
| 345 | + 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'])); |
|
| 346 | 346 | |
| 347 | 347 | //$putinarchive = true; |
| 348 | 348 | if (isset($line['departure_airport_time']) && $line['departure_airport_time'] != 0) { |
| 349 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport_time' => $line['departure_airport_time'])); |
|
| 349 | + $this->all_flights[$id] = array_merge($this->all_flights[$id], array('departure_airport_time' => $line['departure_airport_time'])); |
|
| 350 | 350 | } |
| 351 | 351 | if (isset($line['arrival_airport_time']) && $line['arrival_airport_time'] != 0) { |
| 352 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('arrival_airport_time' => $line['arrival_airport_time'])); |
|
| 352 | + $this->all_flights[$id] = array_merge($this->all_flights[$id], array('arrival_airport_time' => $line['arrival_airport_time'])); |
|
| 353 | 353 | } |
| 354 | 354 | if (isset($line['departure_airport_icao']) && isset($line['arrival_airport_icao'])) { |
| 355 | - $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' => '')); |
|
| 355 | + $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' => '')); |
|
| 356 | 356 | } elseif (isset($line['departure_airport_iata']) && isset($line['arrival_airport_iata'])) { |
| 357 | 357 | $timeelapsed = microtime(true); |
| 358 | 358 | $Spotter = new Spotter($this->db); |
| 359 | 359 | $line['departure_airport_icao'] = $Spotter->getAirportIcao($line['departure_airport_iata']); |
| 360 | 360 | $line['arrival_airport_icao'] = $Spotter->getAirportIcao($line['arrival_airport_iata']); |
| 361 | - $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' => '')); |
|
| 362 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update getAirportICAO : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
| 361 | + $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' => '')); |
|
| 362 | + if ($globalDebugTimeElapsed) echo 'Time elapsed for update getAirportICAO : '.round(microtime(true) - $timeelapsed, 2).'s'."\n"; |
|
| 363 | 363 | |
| 364 | 364 | } elseif (!isset($line['format_source']) || $line['format_source'] != 'aprs') { |
| 365 | 365 | $timeelapsed = microtime(true); |
@@ -372,34 +372,34 @@ discard block |
||
| 372 | 372 | $Translation->db = null; |
| 373 | 373 | } |
| 374 | 374 | $Spotter->db = null; |
| 375 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update getrouteinfo : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
| 375 | + if ($globalDebugTimeElapsed) echo 'Time elapsed for update getrouteinfo : '.round(microtime(true) - $timeelapsed, 2).'s'."\n"; |
|
| 376 | 376 | |
| 377 | 377 | if (isset($route['fromairport_icao']) && isset($route['toairport_icao'])) { |
| 378 | 378 | //if ($route['FromAirport_ICAO'] != $route['ToAirport_ICAO']) { |
| 379 | 379 | if ($route['fromairport_icao'] != $route['toairport_icao']) { |
| 380 | 380 | // $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'])); |
| 381 | - $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'])); |
|
| 381 | + $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'])); |
|
| 382 | 382 | } |
| 383 | 383 | } |
| 384 | 384 | if (!isset($globalFork)) $globalFork = TRUE; |
| 385 | 385 | if (!$globalIVAO && !$globalVATSIM && !$globalphpVMS && !$globalVAM && (!isset($line['format_source']) || $line['format_source'] != 'aprs')) { |
| 386 | - if (!isset($this->all_flights[$id]['schedule_check']) || $this->all_flights[$id]['schedule_check'] === false) $this->get_Schedule($id,trim($line['ident'])); |
|
| 386 | + if (!isset($this->all_flights[$id]['schedule_check']) || $this->all_flights[$id]['schedule_check'] === false) $this->get_Schedule($id, trim($line['ident'])); |
|
| 387 | 387 | } |
| 388 | 388 | } |
| 389 | 389 | } |
| 390 | 390 | |
| 391 | 391 | if (isset($line['speed']) && $line['speed'] != '') { |
| 392 | 392 | // $this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed' => $line[12])); |
| 393 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed' => round($line['speed']))); |
|
| 394 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed_fromsrc' => true)); |
|
| 393 | + $this->all_flights[$id] = array_merge($this->all_flights[$id], array('speed' => round($line['speed']))); |
|
| 394 | + $this->all_flights[$id] = array_merge($this->all_flights[$id], array('speed_fromsrc' => true)); |
|
| 395 | 395 | //$dataFound = true; |
| 396 | 396 | } 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'])) { |
| 397 | - $distance = $Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m'); |
|
| 397 | + $distance = $Common->distance($line['latitude'], $line['longitude'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], 'm'); |
|
| 398 | 398 | if ($distance > 1000 && $distance < 10000) { |
| 399 | 399 | // use datetime |
| 400 | 400 | $speed = $distance/(time() - $this->all_flights[$id]['time_last_coord']); |
| 401 | 401 | $speed = $speed*3.6; |
| 402 | - if ($speed < 1000) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed' => round($speed))); |
|
| 402 | + if ($speed < 1000) $this->all_flights[$id] = array_merge($this->all_flights[$id], array('speed' => round($speed))); |
|
| 403 | 403 | if ($globalDebug) echo "ø Calculated Speed for ".$this->all_flights[$id]['hex']." : ".$speed." - distance : ".$distance."\n"; |
| 404 | 404 | } |
| 405 | 405 | } |
@@ -407,11 +407,11 @@ discard block |
||
| 407 | 407 | |
| 408 | 408 | |
| 409 | 409 | if (isset($line['latitude']) && isset($line['longitude']) && $line['latitude'] != '' && $line['longitude'] != '' && is_numeric($line['latitude']) && is_numeric($line['longitude'])) { |
| 410 | - if (isset($this->all_flights[$id]['time_last_coord'])) $timediff = round(time()-$this->all_flights[$id]['time_last_coord']); |
|
| 410 | + if (isset($this->all_flights[$id]['time_last_coord'])) $timediff = round(time() - $this->all_flights[$id]['time_last_coord']); |
|
| 411 | 411 | else unset($timediff); |
| 412 | - 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')))) { |
|
| 412 | + 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')))) { |
|
| 413 | 413 | 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'])) { |
| 414 | - 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'])) { |
|
| 414 | + 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'])) { |
|
| 415 | 415 | $this->all_flights[$id]['archive_latitude'] = $line['latitude']; |
| 416 | 416 | $this->all_flights[$id]['archive_longitude'] = $line['longitude']; |
| 417 | 417 | $this->all_flights[$id]['putinarchive'] = true; |
@@ -419,10 +419,10 @@ discard block |
||
| 419 | 419 | if ($globalDebug) echo "\n".' ------- Check Country.... '; |
| 420 | 420 | $timeelapsed = microtime(true); |
| 421 | 421 | $Spotter = new Spotter($this->db); |
| 422 | - $all_country = $Spotter->getCountryFromLatitudeLongitude($line['latitude'],$line['longitude']); |
|
| 422 | + $all_country = $Spotter->getCountryFromLatitudeLongitude($line['latitude'], $line['longitude']); |
|
| 423 | 423 | if (!empty($all_country)) $this->all_flights[$id]['over_country'] = $all_country['iso2']; |
| 424 | 424 | $Spotter->db = null; |
| 425 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
| 425 | + if ($globalDebugTimeElapsed) echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true) - $timeelapsed, 2).'s'."\n"; |
|
| 426 | 426 | $this->tmd = 0; |
| 427 | 427 | if ($globalDebug) echo 'FOUND : '.$this->all_flights[$id]['over_country'].' ---------------'."\n"; |
| 428 | 428 | } |
@@ -431,13 +431,13 @@ discard block |
||
| 431 | 431 | if (isset($line['latitude']) && $line['latitude'] != '' && $line['latitude'] != 0 && $line['latitude'] < 91 && $line['latitude'] > -90) { |
| 432 | 432 | //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) { |
| 433 | 433 | if (!isset($this->all_flights[$id]['archive_latitude'])) $this->all_flights[$id]['archive_latitude'] = $line['latitude']; |
| 434 | - 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') { |
|
| 434 | + 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') { |
|
| 435 | 435 | $this->all_flights[$id]['livedb_latitude'] = $line['latitude']; |
| 436 | 436 | $dataFound = true; |
| 437 | 437 | $this->all_flights[$id]['time_last_coord'] = time(); |
| 438 | 438 | } |
| 439 | 439 | // elseif ($globalDebug) echo '!*!*! Ignore data, too close to previous one'."\n"; |
| 440 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('latitude' => $line['latitude'])); |
|
| 440 | + $this->all_flights[$id] = array_merge($this->all_flights[$id], array('latitude' => $line['latitude'])); |
|
| 441 | 441 | /* |
| 442 | 442 | if (abs($this->all_flights[$id]['archive_latitude']-$this->all_flights[$id]['latitude']) > 0.3) { |
| 443 | 443 | $this->all_flights[$id]['archive_latitude'] = $line['latitude']; |
@@ -455,13 +455,13 @@ discard block |
||
| 455 | 455 | if ($line['longitude'] > 180) $line['longitude'] = $line['longitude'] - 360; |
| 456 | 456 | //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) { |
| 457 | 457 | if (!isset($this->all_flights[$id]['archive_longitude'])) $this->all_flights[$id]['archive_longitude'] = $line['longitude']; |
| 458 | - 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') { |
|
| 458 | + 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') { |
|
| 459 | 459 | $this->all_flights[$id]['livedb_longitude'] = $line['longitude']; |
| 460 | 460 | $dataFound = true; |
| 461 | 461 | $this->all_flights[$id]['time_last_coord'] = time(); |
| 462 | 462 | } |
| 463 | 463 | // elseif ($globalDebug) echo '!*!*! Ignore data, too close to previous one'."\n"; |
| 464 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('longitude' => $line['longitude'])); |
|
| 464 | + $this->all_flights[$id] = array_merge($this->all_flights[$id], array('longitude' => $line['longitude'])); |
|
| 465 | 465 | /* |
| 466 | 466 | if (abs($this->all_flights[$id]['archive_longitude']-$this->all_flights[$id]['longitude']) > 0.3) { |
| 467 | 467 | $this->all_flights[$id]['archive_longitude'] = $line['longitude']; |
@@ -479,45 +479,45 @@ discard block |
||
| 479 | 479 | } else if ($globalDebug && $timediff > 20) { |
| 480 | 480 | $this->tmd = $this->tmd + 1; |
| 481 | 481 | echo '!!! Too much distance in short time... for '.$this->all_flights[$id]['ident']."\n"; |
| 482 | - echo 'Time : '.$timediff.'s - Distance : '.$Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m')."m -"; |
|
| 483 | - echo 'Speed : '.(($Common->distance($line['latitude'],$line['longitude'],$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],'m')/$timediff)*3.6)." km/h - "; |
|
| 482 | + echo 'Time : '.$timediff.'s - Distance : '.$Common->distance($line['latitude'], $line['longitude'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], 'm')."m -"; |
|
| 483 | + echo 'Speed : '.(($Common->distance($line['latitude'], $line['longitude'], $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude'], 'm')/$timediff)*3.6)." km/h - "; |
|
| 484 | 484 | echo 'Lat : '.$line['latitude'].' - long : '.$line['longitude'].' - prev lat : '.$this->all_flights[$id]['latitude'].' - prev long : '.$this->all_flights[$id]['longitude']." \n"; |
| 485 | 485 | } |
| 486 | 486 | } |
| 487 | 487 | if (isset($line['last_update']) && $line['last_update'] != '') { |
| 488 | 488 | if (isset($this->all_flights[$id]['last_update']) && $this->all_flights[$id]['last_update'] != $line['last_update']) $dataFound = true; |
| 489 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('last_update' => $line['last_update'])); |
|
| 489 | + $this->all_flights[$id] = array_merge($this->all_flights[$id], array('last_update' => $line['last_update'])); |
|
| 490 | 490 | } |
| 491 | 491 | if (isset($line['verticalrate']) && $line['verticalrate'] != '') { |
| 492 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('verticalrate' => $line['verticalrate'])); |
|
| 492 | + $this->all_flights[$id] = array_merge($this->all_flights[$id], array('verticalrate' => $line['verticalrate'])); |
|
| 493 | 493 | //$dataFound = true; |
| 494 | 494 | } |
| 495 | 495 | if (isset($line['format_source']) && $line['format_source'] != '') { |
| 496 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('format_source' => $line['format_source'])); |
|
| 496 | + $this->all_flights[$id] = array_merge($this->all_flights[$id], array('format_source' => $line['format_source'])); |
|
| 497 | 497 | } |
| 498 | 498 | if (isset($line['source_name']) && $line['source_name'] != '') { |
| 499 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('source_name' => $line['source_name'])); |
|
| 499 | + $this->all_flights[$id] = array_merge($this->all_flights[$id], array('source_name' => $line['source_name'])); |
|
| 500 | 500 | } |
| 501 | 501 | if (isset($line['emergency']) && $line['emergency'] != '') { |
| 502 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('emergency' => $line['emergency'])); |
|
| 502 | + $this->all_flights[$id] = array_merge($this->all_flights[$id], array('emergency' => $line['emergency'])); |
|
| 503 | 503 | //$dataFound = true; |
| 504 | 504 | } |
| 505 | 505 | if (isset($line['ground']) && $line['ground'] != '') { |
| 506 | 506 | if (isset($this->all_flights[$id]['ground']) && $this->all_flights[$id]['ground'] == 1 && $line['ground'] == 0) { |
| 507 | 507 | // Here we force archive of flight because after ground it's a new one (or should be) |
| 508 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0)); |
|
| 509 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('forcenew' => 1)); |
|
| 510 | - 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'))); |
|
| 511 | - elseif (isset($line['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id'])); |
|
| 512 | - 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'])); |
|
| 508 | + $this->all_flights[$id] = array_merge($this->all_flights[$id], array('addedSpotter' => 0)); |
|
| 509 | + $this->all_flights[$id] = array_merge($this->all_flights[$id], array('forcenew' => 1)); |
|
| 510 | + 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'))); |
|
| 511 | + elseif (isset($line['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id], array('id' => $line['id'])); |
|
| 512 | + 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 | 513 | } |
| 514 | 514 | if ($line['ground'] != 1) $line['ground'] = 0; |
| 515 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ground' => $line['ground'])); |
|
| 515 | + $this->all_flights[$id] = array_merge($this->all_flights[$id], array('ground' => $line['ground'])); |
|
| 516 | 516 | //$dataFound = true; |
| 517 | 517 | } |
| 518 | 518 | if (isset($line['squawk']) && $line['squawk'] != '') { |
| 519 | 519 | 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'])) { |
| 520 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk'])); |
|
| 520 | + $this->all_flights[$id] = array_merge($this->all_flights[$id], array('squawk' => $line['squawk'])); |
|
| 521 | 521 | $highlight = ''; |
| 522 | 522 | if ($this->all_flights[$id]['squawk'] == '7500') $highlight = 'Squawk 7500 : Hijack at '.date('Y-m-d G:i').' UTC'; |
| 523 | 523 | if ($this->all_flights[$id]['squawk'] == '7600') $highlight = 'Squawk 7600 : Lost Comm (radio failure) at '.date('Y-m-d G:i').' UTC'; |
@@ -525,48 +525,48 @@ discard block |
||
| 525 | 525 | if ($highlight != '') { |
| 526 | 526 | $timeelapsed = microtime(true); |
| 527 | 527 | $Spotter = new Spotter($this->db); |
| 528 | - $Spotter->setHighlightFlight($this->all_flights[$id]['id'],$highlight); |
|
| 528 | + $Spotter->setHighlightFlight($this->all_flights[$id]['id'], $highlight); |
|
| 529 | 529 | $Spotter->db = null; |
| 530 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update sethighlightflight : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
| 530 | + if ($globalDebugTimeElapsed) echo 'Time elapsed for update sethighlightflight : '.round(microtime(true) - $timeelapsed, 2).'s'."\n"; |
|
| 531 | 531 | |
| 532 | 532 | $this->all_flights[$id]['putinarchive'] = true; |
| 533 | 533 | //$putinarchive = true; |
| 534 | 534 | //$highlight = ''; |
| 535 | 535 | } |
| 536 | 536 | |
| 537 | - } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk'])); |
|
| 537 | + } else $this->all_flights[$id] = array_merge($this->all_flights[$id], array('squawk' => $line['squawk'])); |
|
| 538 | 538 | //$dataFound = true; |
| 539 | 539 | } |
| 540 | 540 | |
| 541 | 541 | if (isset($line['altitude']) && $line['altitude'] != '') { |
| 542 | 542 | //if (!isset($this->all_flights[$id]['altitude']) || $this->all_flights[$id]['altitude'] == '' || ($this->all_flights[$id]['altitude'] > 0 && $line['altitude'] != 0)) { |
| 543 | - 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; |
|
| 544 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('altitude' => round($line['altitude']/100))); |
|
| 545 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('altitude_real' => $line['altitude'])); |
|
| 543 | + 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; |
|
| 544 | + $this->all_flights[$id] = array_merge($this->all_flights[$id], array('altitude' => round($line['altitude']/100))); |
|
| 545 | + $this->all_flights[$id] = array_merge($this->all_flights[$id], array('altitude_real' => $line['altitude'])); |
|
| 546 | 546 | //$dataFound = true; |
| 547 | 547 | //} elseif ($globalDebug) echo "!!! Strange altitude data... not added.\n"; |
| 548 | 548 | } |
| 549 | 549 | |
| 550 | 550 | if (isset($line['noarchive']) && $line['noarchive'] === true) { |
| 551 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('noarchive' => true)); |
|
| 551 | + $this->all_flights[$id] = array_merge($this->all_flights[$id], array('noarchive' => true)); |
|
| 552 | 552 | } |
| 553 | 553 | |
| 554 | 554 | if (isset($line['heading']) && $line['heading'] != '') { |
| 555 | - if (is_int($this->all_flights[$id]['heading']) && abs($this->all_flights[$id]['heading']-round($line['heading'])) > 2) $this->all_flights[$id]['putinarchive'] = true; |
|
| 556 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => round($line['heading']))); |
|
| 557 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading_fromsrc' => true)); |
|
| 555 | + if (is_int($this->all_flights[$id]['heading']) && abs($this->all_flights[$id]['heading'] - round($line['heading'])) > 2) $this->all_flights[$id]['putinarchive'] = true; |
|
| 556 | + $this->all_flights[$id] = array_merge($this->all_flights[$id], array('heading' => round($line['heading']))); |
|
| 557 | + $this->all_flights[$id] = array_merge($this->all_flights[$id], array('heading_fromsrc' => true)); |
|
| 558 | 558 | //$dataFound = true; |
| 559 | 559 | } 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']) { |
| 560 | - $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']); |
|
| 561 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => round($heading))); |
|
| 562 | - if (abs($this->all_flights[$id]['heading']-round($heading)) > 2) $this->all_flights[$id]['putinarchive'] = true; |
|
| 560 | + $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']); |
|
| 561 | + $this->all_flights[$id] = array_merge($this->all_flights[$id], array('heading' => round($heading))); |
|
| 562 | + if (abs($this->all_flights[$id]['heading'] - round($heading)) > 2) $this->all_flights[$id]['putinarchive'] = true; |
|
| 563 | 563 | if ($globalDebug) echo "ø Calculated Heading for ".$this->all_flights[$id]['hex']." : ".$heading."\n"; |
| 564 | 564 | } elseif (isset($this->all_flights[$id]['format_source']) && $this->all_flights[$id]['format_source'] == 'ACARS') { |
| 565 | 565 | // If not enough messages and ACARS set heading to 0 |
| 566 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => 0)); |
|
| 566 | + $this->all_flights[$id] = array_merge($this->all_flights[$id], array('heading' => 0)); |
|
| 567 | 567 | } |
| 568 | - if (isset($globalSourcesupdate) && $globalSourcesupdate != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalSourcesupdate) $dataFound = false; |
|
| 569 | - elseif (isset($globalSBS1update) && $globalSBS1update != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalSBS1update) $dataFound = false; |
|
| 568 | + if (isset($globalSourcesupdate) && $globalSourcesupdate != '' && isset($this->all_flights[$id]['lastupdate']) && time() - $this->all_flights[$id]['lastupdate'] < $globalSourcesupdate) $dataFound = false; |
|
| 569 | + elseif (isset($globalSBS1update) && $globalSBS1update != '' && isset($this->all_flights[$id]['lastupdate']) && time() - $this->all_flights[$id]['lastupdate'] < $globalSBS1update) $dataFound = false; |
|
| 570 | 570 | |
| 571 | 571 | // print_r($this->all_flights[$id]); |
| 572 | 572 | //gets the callsign from the last hour |
@@ -576,7 +576,7 @@ discard block |
||
| 576 | 576 | if ($dataFound === true && isset($this->all_flights[$id]['hex'])) { |
| 577 | 577 | $this->all_flights[$id]['lastupdate'] = time(); |
| 578 | 578 | if ($this->all_flights[$id]['addedSpotter'] == 0) { |
| 579 | - 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'])) { |
|
| 579 | + 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'])) { |
|
| 580 | 580 | //print_r($this->all_flights); |
| 581 | 581 | //echo $this->all_flights[$id]['id'].' - '.$this->all_flights[$id]['addedSpotter']."\n"; |
| 582 | 582 | //$last_hour_ident = Spotter->getIdentFromLastHour($this->all_flights[$id]['ident']); |
@@ -586,61 +586,61 @@ discard block |
||
| 586 | 586 | $SpotterLive = new SpotterLive($this->db); |
| 587 | 587 | 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')) { |
| 588 | 588 | $recent_ident = $SpotterLive->checkModeSRecent($this->all_flights[$id]['hex']); |
| 589 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkModeSRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
| 589 | + if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkModeSRecent : '.round(microtime(true) - $timeelapsed, 2).'s'."\n"; |
|
| 590 | 590 | } elseif (isset($line['id'])) { |
| 591 | 591 | $recent_ident = $SpotterLive->checkIdRecent($line['id']); |
| 592 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
| 592 | + if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true) - $timeelapsed, 2).'s'."\n"; |
|
| 593 | 593 | } elseif (isset($this->all_flights[$id]['ident']) && $this->all_flights[$id]['ident'] != '') { |
| 594 | 594 | $recent_ident = $SpotterLive->checkIdentRecent($this->all_flights[$id]['ident']); |
| 595 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
| 595 | + if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true) - $timeelapsed, 2).'s'."\n"; |
|
| 596 | 596 | } else $recent_ident = ''; |
| 597 | - $SpotterLive->db=null; |
|
| 597 | + $SpotterLive->db = null; |
|
| 598 | 598 | |
| 599 | 599 | if ($globalDebug && $recent_ident == '') echo " Not in DB.\n"; |
| 600 | 600 | elseif ($globalDebug && $recent_ident != '') echo " Already in DB.\n"; |
| 601 | 601 | } else { |
| 602 | 602 | $recent_ident = ''; |
| 603 | - $this->all_flights[$id] = array_merge($this->all_flights[$id],array('forcenew' => 0)); |
|
| 603 | + $this->all_flights[$id] = array_merge($this->all_flights[$id], array('forcenew' => 0)); |
|
| 604 | 604 | } |
| 605 | 605 | //if there was no aircraft with the same callsign within the last hour and go post it into the archive |
| 606 | - if($recent_ident == "") |
|
| 606 | + if ($recent_ident == "") |
|
| 607 | 607 | { |
| 608 | 608 | if ($globalDebug) echo "\o/ Add ".$this->all_flights[$id]['ident']." in archive DB : "; |
| 609 | 609 | if ($this->all_flights[$id]['departure_airport'] == "") { $this->all_flights[$id]['departure_airport'] = "NA"; } |
| 610 | 610 | if ($this->all_flights[$id]['arrival_airport'] == "") { $this->all_flights[$id]['arrival_airport'] = "NA"; } |
| 611 | 611 | //adds the spotter data for the archive |
| 612 | 612 | $ignoreImport = false; |
| 613 | - foreach($globalAirportIgnore as $airportIgnore) { |
|
| 613 | + foreach ($globalAirportIgnore as $airportIgnore) { |
|
| 614 | 614 | if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) { |
| 615 | 615 | $ignoreImport = true; |
| 616 | 616 | } |
| 617 | 617 | } |
| 618 | 618 | if (count($globalAirportAccept) > 0) { |
| 619 | 619 | $ignoreImport = true; |
| 620 | - foreach($globalAirportIgnore as $airportIgnore) { |
|
| 620 | + foreach ($globalAirportIgnore as $airportIgnore) { |
|
| 621 | 621 | if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) { |
| 622 | 622 | $ignoreImport = false; |
| 623 | 623 | } |
| 624 | 624 | } |
| 625 | 625 | } |
| 626 | 626 | if (isset($globalAirlineIgnore) && is_array($globalAirlineIgnore)) { |
| 627 | - foreach($globalAirlineIgnore as $airlineIgnore) { |
|
| 628 | - 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)) { |
|
| 627 | + foreach ($globalAirlineIgnore as $airlineIgnore) { |
|
| 628 | + 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)) { |
|
| 629 | 629 | $ignoreImport = true; |
| 630 | 630 | } |
| 631 | 631 | } |
| 632 | 632 | } |
| 633 | 633 | if (isset($globalAirlineAccept) && count($globalAirlineAccept) > 0) { |
| 634 | 634 | $ignoreImport = true; |
| 635 | - foreach($globalAirlineAccept as $airlineAccept) { |
|
| 636 | - 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)) { |
|
| 635 | + foreach ($globalAirlineAccept as $airlineAccept) { |
|
| 636 | + 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)) { |
|
| 637 | 637 | $ignoreImport = false; |
| 638 | 638 | } |
| 639 | 639 | } |
| 640 | 640 | } |
| 641 | 641 | if (isset($globalPilotIdAccept) && count($globalPilotIdAccept) > 0) { |
| 642 | 642 | $ignoreImport = true; |
| 643 | - foreach($globalPilotIdAccept as $pilotIdAccept) { |
|
| 643 | + foreach ($globalPilotIdAccept as $pilotIdAccept) { |
|
| 644 | 644 | if ($this->all_flights[$id]['pilot_id'] == $pilotIdAccept) { |
| 645 | 645 | $ignoreImport = false; |
| 646 | 646 | } |
@@ -652,27 +652,27 @@ discard block |
||
| 652 | 652 | if ($this->all_flights[$id]['squawk'] == '7500') $highlight = 'Squawk 7500 : Hijack'; |
| 653 | 653 | if ($this->all_flights[$id]['squawk'] == '7600') $highlight = 'Squawk 7600 : Lost Comm (radio failure)'; |
| 654 | 654 | if ($this->all_flights[$id]['squawk'] == '7700') $highlight = 'Squawk 7700 : Emergency'; |
| 655 | - 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'))); |
|
| 655 | + 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'))); |
|
| 656 | 656 | $timeelapsed = microtime(true); |
| 657 | 657 | $Spotter = new Spotter($this->db); |
| 658 | - $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']); |
|
| 658 | + $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']); |
|
| 659 | 659 | $Spotter->db = null; |
| 660 | 660 | if ($globalDebug && isset($result)) echo $result."\n"; |
| 661 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
| 661 | + if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true) - $timeelapsed, 2).'s'."\n"; |
|
| 662 | 662 | |
| 663 | 663 | // Add source stat in DB |
| 664 | 664 | $Stats = new Stats($this->db); |
| 665 | 665 | if (!empty($this->stats)) { |
| 666 | 666 | if ($globalDebug) echo 'Add source stats : '; |
| 667 | - foreach($this->stats as $date => $data) { |
|
| 668 | - foreach($data as $source => $sourced) { |
|
| 667 | + foreach ($this->stats as $date => $data) { |
|
| 668 | + foreach ($data as $source => $sourced) { |
|
| 669 | 669 | //print_r($sourced); |
| 670 | - if (isset($sourced['polar'])) echo $Stats->addStatSource(json_encode($sourced['polar']),$source,'polar',$date); |
|
| 671 | - if (isset($sourced['hist'])) echo $Stats->addStatSource(json_encode($sourced['hist']),$source,'hist',$date); |
|
| 670 | + if (isset($sourced['polar'])) echo $Stats->addStatSource(json_encode($sourced['polar']), $source, 'polar', $date); |
|
| 671 | + if (isset($sourced['hist'])) echo $Stats->addStatSource(json_encode($sourced['hist']), $source, 'hist', $date); |
|
| 672 | 672 | if (isset($sourced['msg'])) { |
| 673 | 673 | if (time() - $sourced['msg']['date'] > 10) { |
| 674 | 674 | $nbmsg = round($sourced['msg']['nb']/(time() - $sourced['msg']['date'])); |
| 675 | - echo $Stats->addStatSource($nbmsg,$source,'msg',$date); |
|
| 675 | + echo $Stats->addStatSource($nbmsg, $source, 'msg', $date); |
|
| 676 | 676 | unset($this->stats[$date][$source]['msg']); |
| 677 | 677 | } |
| 678 | 678 | } |
@@ -708,18 +708,18 @@ discard block |
||
| 708 | 708 | //SpotterLive->deleteLiveSpotterDataNotUpdated(); |
| 709 | 709 | $SpotterLive = new SpotterLive($this->db); |
| 710 | 710 | $SpotterLive->deleteLiveSpotterData(); |
| 711 | - $SpotterLive->db=null; |
|
| 711 | + $SpotterLive->db = null; |
|
| 712 | 712 | if ($globalDebug) echo " Done\n"; |
| 713 | 713 | $this->last_delete = time(); |
| 714 | 714 | } |
| 715 | 715 | } else { |
| 716 | - 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')) { |
|
| 716 | + 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')) { |
|
| 717 | 717 | $this->all_flights[$id]['id'] = $recent_ident; |
| 718 | 718 | $this->all_flights[$id]['addedSpotter'] = 1; |
| 719 | 719 | } |
| 720 | 720 | if (isset($globalDaemon) && !$globalDaemon) { |
| 721 | 721 | $Spotter = new Spotter($this->db); |
| 722 | - $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']); |
|
| 722 | + $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']); |
|
| 723 | 723 | $Spotter->db = null; |
| 724 | 724 | } |
| 725 | 725 | |
@@ -743,37 +743,37 @@ discard block |
||
| 743 | 743 | if ($this->all_flights[$id]['departure_airport'] == "") { $this->all_flights[$id]['departure_airport'] = "NA"; } |
| 744 | 744 | if ($this->all_flights[$id]['arrival_airport'] == "") { $this->all_flights[$id]['arrival_airport'] = "NA"; } |
| 745 | 745 | |
| 746 | - foreach($globalAirportIgnore as $airportIgnore) { |
|
| 746 | + foreach ($globalAirportIgnore as $airportIgnore) { |
|
| 747 | 747 | if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) { |
| 748 | 748 | $ignoreImport = true; |
| 749 | 749 | } |
| 750 | 750 | } |
| 751 | 751 | if (count($globalAirportAccept) > 0) { |
| 752 | 752 | $ignoreImport = true; |
| 753 | - foreach($globalAirportIgnore as $airportIgnore) { |
|
| 753 | + foreach ($globalAirportIgnore as $airportIgnore) { |
|
| 754 | 754 | if (($this->all_flights[$id]['departure_airport'] == $airportIgnore) || ($this->all_flights[$id]['arrival_airport'] == $airportIgnore)) { |
| 755 | 755 | $ignoreImport = false; |
| 756 | 756 | } |
| 757 | 757 | } |
| 758 | 758 | } |
| 759 | 759 | if (isset($globalAirlineIgnore) && is_array($globalAirlineIgnore)) { |
| 760 | - foreach($globalAirlineIgnore as $airlineIgnore) { |
|
| 761 | - 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)) { |
|
| 760 | + foreach ($globalAirlineIgnore as $airlineIgnore) { |
|
| 761 | + 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)) { |
|
| 762 | 762 | $ignoreImport = true; |
| 763 | 763 | } |
| 764 | 764 | } |
| 765 | 765 | } |
| 766 | 766 | if (isset($globalAirlineAccept) && count($globalAirlineAccept) > 0) { |
| 767 | 767 | $ignoreImport = true; |
| 768 | - foreach($globalAirlineAccept as $airlineAccept) { |
|
| 769 | - 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)) { |
|
| 768 | + foreach ($globalAirlineAccept as $airlineAccept) { |
|
| 769 | + 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)) { |
|
| 770 | 770 | $ignoreImport = false; |
| 771 | 771 | } |
| 772 | 772 | } |
| 773 | 773 | } |
| 774 | 774 | if (isset($globalPilotIdAccept) && count($globalPilotIdAccept) > 0) { |
| 775 | 775 | $ignoreImport = true; |
| 776 | - foreach($globalPilotIdAccept as $pilotIdAccept) { |
|
| 776 | + foreach ($globalPilotIdAccept as $pilotIdAccept) { |
|
| 777 | 777 | if ($this->all_flights[$id]['pilot_id'] == $pilotIdAccept) { |
| 778 | 778 | $ignoreImport = false; |
| 779 | 779 | } |
@@ -781,13 +781,13 @@ discard block |
||
| 781 | 781 | } |
| 782 | 782 | |
| 783 | 783 | if (!$ignoreImport) { |
| 784 | - 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'])) { |
|
| 784 | + 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'])) { |
|
| 785 | 785 | if ($globalDebug) echo "\o/ Add ".$this->all_flights[$id]['ident']." from ".$this->all_flights[$id]['format_source']." in Live DB : "; |
| 786 | 786 | $timeelapsed = microtime(true); |
| 787 | 787 | $SpotterLive = new SpotterLive($this->db); |
| 788 | - $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']); |
|
| 788 | + $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']); |
|
| 789 | 789 | $SpotterLive->db = null; |
| 790 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
| 790 | + if ($globalDebugTimeElapsed) echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true) - $timeelapsed, 2).'s'."\n"; |
|
| 791 | 791 | |
| 792 | 792 | // Put statistics in $this->stats variable |
| 793 | 793 | //if ($line['format_source'] != 'aprs') { |
@@ -805,19 +805,19 @@ discard block |
||
| 805 | 805 | $latitude = $globalCenterLatitude; |
| 806 | 806 | $longitude = $globalCenterLongitude; |
| 807 | 807 | } |
| 808 | - $this->source_location[$source] = array('latitude' => $latitude,'longitude' => $longitude); |
|
| 808 | + $this->source_location[$source] = array('latitude' => $latitude, 'longitude' => $longitude); |
|
| 809 | 809 | } else { |
| 810 | 810 | $latitude = $this->source_location[$source]['latitude']; |
| 811 | 811 | $longitude = $this->source_location[$source]['longitude']; |
| 812 | 812 | } |
| 813 | - $stats_heading = $Common->getHeading($latitude,$longitude,$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude']); |
|
| 813 | + $stats_heading = $Common->getHeading($latitude, $longitude, $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude']); |
|
| 814 | 814 | //$stats_heading = $stats_heading%22.5; |
| 815 | 815 | $stats_heading = round($stats_heading/22.5); |
| 816 | - $stats_distance = $Common->distance($latitude,$longitude,$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude']); |
|
| 816 | + $stats_distance = $Common->distance($latitude, $longitude, $this->all_flights[$id]['latitude'], $this->all_flights[$id]['longitude']); |
|
| 817 | 817 | $current_date = date('Y-m-d'); |
| 818 | 818 | if ($stats_heading == 16) $stats_heading = 0; |
| 819 | 819 | if (!isset($this->stats[$current_date][$source]['polar'][1])) { |
| 820 | - for ($i=0;$i<=15;$i++) { |
|
| 820 | + for ($i = 0; $i <= 15; $i++) { |
|
| 821 | 821 | $this->stats[$current_date][$source]['polar'][$i] = 0; |
| 822 | 822 | } |
| 823 | 823 | $this->stats[$current_date][$source]['polar'][$stats_heading] = $stats_distance; |
@@ -832,9 +832,9 @@ discard block |
||
| 832 | 832 | if (!isset($this->stats[$current_date][$source]['hist'][$distance])) { |
| 833 | 833 | if (isset($this->stats[$current_date][$source]['hist'][0])) { |
| 834 | 834 | end($this->stats[$current_date][$source]['hist']); |
| 835 | - $mini = key($this->stats[$current_date][$source]['hist'])+10; |
|
| 835 | + $mini = key($this->stats[$current_date][$source]['hist']) + 10; |
|
| 836 | 836 | } else $mini = 0; |
| 837 | - for ($i=$mini;$i<=$distance;$i+=10) { |
|
| 837 | + for ($i = $mini; $i <= $distance; $i += 10) { |
|
| 838 | 838 | $this->stats[$current_date][$source]['hist'][$i] = 0; |
| 839 | 839 | } |
| 840 | 840 | $this->stats[$current_date][$source]['hist'][$distance] = 1; |
@@ -847,7 +847,7 @@ discard block |
||
| 847 | 847 | if ($this->all_flights[$id]['putinarchive']) $send = true; |
| 848 | 848 | //if ($globalDebug) echo "Distance : ".Common->distance($this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude'])."\n"; |
| 849 | 849 | if ($globalDebug) echo $result."\n"; |
| 850 | - } 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"; |
|
| 850 | + } 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"; |
|
| 851 | 851 | //$this->del(); |
| 852 | 852 | |
| 853 | 853 | |
@@ -53,7 +53,9 @@ discard block |
||
| 53 | 53 | $dbc = $this->db; |
| 54 | 54 | $this->all_flights[$id]['schedule_check'] = true; |
| 55 | 55 | if ($globalSchedulesFetch) { |
| 56 | - if ($globalDebug) echo 'Getting schedule info...'."\n"; |
|
| 56 | + if ($globalDebug) { |
|
| 57 | + echo 'Getting schedule info...'."\n"; |
|
| 58 | + } |
|
| 57 | 59 | $Spotter = new Spotter($dbc); |
| 58 | 60 | $Schedule = new Schedule($dbc); |
| 59 | 61 | $Translation = new Translation($dbc); |
@@ -63,7 +65,9 @@ discard block |
||
| 63 | 65 | if ($Schedule->checkSchedule($operator) == 0) { |
| 64 | 66 | $schedule = $Schedule->fetchSchedule($operator); |
| 65 | 67 | if (count($schedule) > 0 && isset($schedule['DepartureTime']) && isset($schedule['ArrivalTime'])) { |
| 66 | - if ($globalDebug) echo "-> Schedule info for ".$operator." (".$ident.")\n"; |
|
| 68 | + if ($globalDebug) { |
|
| 69 | + echo "-> Schedule info for ".$operator." (".$ident.")\n"; |
|
| 70 | + } |
|
| 67 | 71 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('departure_airport_time' => $schedule['DepartureTime'])); |
| 68 | 72 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('arrival_airport_time' => $schedule['ArrivalTime'])); |
| 69 | 73 | // Should also check if route schedule = route from DB |
@@ -72,7 +76,9 @@ discard block |
||
| 72 | 76 | $airport_icao = $Spotter->getAirportIcao($schedule['DepartureAirportIATA']); |
| 73 | 77 | if ($airport_icao != '') { |
| 74 | 78 | $this->all_flights[$id]['departure_airport'] = $airport_icao; |
| 75 | - if ($globalDebug) echo "-> Change departure airport to ".$airport_icao." for ".$ident."\n"; |
|
| 79 | + if ($globalDebug) { |
|
| 80 | + echo "-> Change departure airport to ".$airport_icao." for ".$ident."\n"; |
|
| 81 | + } |
|
| 76 | 82 | } |
| 77 | 83 | } |
| 78 | 84 | } |
@@ -81,7 +87,9 @@ discard block |
||
| 81 | 87 | $airport_icao = $Spotter->getAirportIcao($schedule['ArrivalAirportIATA']); |
| 82 | 88 | if ($airport_icao != '') { |
| 83 | 89 | $this->all_flights[$id]['arrival_airport'] = $airport_icao; |
| 84 | - if ($globalDebug) echo "-> Change arrival airport to ".$airport_icao." for ".$ident."\n"; |
|
| 90 | + if ($globalDebug) { |
|
| 91 | + echo "-> Change arrival airport to ".$airport_icao." for ".$ident."\n"; |
|
| 92 | + } |
|
| 85 | 93 | } |
| 86 | 94 | } |
| 87 | 95 | } |
@@ -109,7 +117,9 @@ discard block |
||
| 109 | 117 | |
| 110 | 118 | public function checkAll() { |
| 111 | 119 | global $globalDebug; |
| 112 | - if ($globalDebug) echo "Update last seen flights data...\n"; |
|
| 120 | + if ($globalDebug) { |
|
| 121 | + echo "Update last seen flights data...\n"; |
|
| 122 | + } |
|
| 113 | 123 | foreach ($this->all_flights as $key => $flight) { |
| 114 | 124 | if (isset($this->all_flights[$key]['id'])) { |
| 115 | 125 | //echo $this->all_flights[$key]['id'].' - '.$this->all_flights[$key]['latitude'].' '.$this->all_flights[$key]['longitude']."\n"; |
@@ -122,24 +132,32 @@ discard block |
||
| 122 | 132 | |
| 123 | 133 | public function arrival($key) { |
| 124 | 134 | global $globalClosestMinDist, $globalDebug; |
| 125 | - if ($globalDebug) echo 'Update arrival...'."\n"; |
|
| 135 | + if ($globalDebug) { |
|
| 136 | + echo 'Update arrival...'."\n"; |
|
| 137 | + } |
|
| 126 | 138 | $Spotter = new Spotter($this->db); |
| 127 | 139 | $airport_icao = ''; |
| 128 | 140 | $airport_time = ''; |
| 129 | - if (!isset($globalClosestMinDist) || $globalClosestMinDist == '') $globalClosestMinDist = 50; |
|
| 141 | + if (!isset($globalClosestMinDist) || $globalClosestMinDist == '') { |
|
| 142 | + $globalClosestMinDist = 50; |
|
| 143 | + } |
|
| 130 | 144 | if ($this->all_flights[$key]['latitude'] != '' && $this->all_flights[$key]['longitude'] != '') { |
| 131 | 145 | $closestAirports = $Spotter->closestAirports($this->all_flights[$key]['latitude'],$this->all_flights[$key]['longitude'],$globalClosestMinDist); |
| 132 | 146 | if (isset($closestAirports[0])) { |
| 133 | 147 | if (isset($this->all_flights[$key]['arrival_airport']) && $this->all_flights[$key]['arrival_airport'] == $closestAirports[0]['icao']) { |
| 134 | 148 | $airport_icao = $closestAirports[0]['icao']; |
| 135 | 149 | $airport_time = $this->all_flights[$key]['datetime']; |
| 136 | - if ($globalDebug) echo "---++ Find arrival airport. airport_icao : ".$airport_icao."\n"; |
|
| 150 | + if ($globalDebug) { |
|
| 151 | + echo "---++ Find arrival airport. airport_icao : ".$airport_icao."\n"; |
|
| 152 | + } |
|
| 137 | 153 | } elseif (count($closestAirports > 1) && isset($this->all_flights[$key]['arrival_airport']) && $this->all_flights[$key]['arrival_airport'] != '') { |
| 138 | 154 | foreach ($closestAirports as $airport) { |
| 139 | 155 | if ($this->all_flights[$key]['arrival_airport'] == $airport['icao']) { |
| 140 | 156 | $airport_icao = $airport['icao']; |
| 141 | 157 | $airport_time = $this->all_flights[$key]['datetime']; |
| 142 | - if ($globalDebug) echo "---++ Find arrival airport. airport_icao : ".$airport_icao."\n"; |
|
| 158 | + if ($globalDebug) { |
|
| 159 | + echo "---++ Find arrival airport. airport_icao : ".$airport_icao."\n"; |
|
| 160 | + } |
|
| 143 | 161 | break; |
| 144 | 162 | } |
| 145 | 163 | } |
@@ -147,14 +165,20 @@ discard block |
||
| 147 | 165 | $airport_icao = $closestAirports[0]['icao']; |
| 148 | 166 | $airport_time = $this->all_flights[$key]['datetime']; |
| 149 | 167 | } else { |
| 150 | - if ($globalDebug) echo "----- Can't find arrival airport. Airport altitude : ".$closestAirports[0]['altitude'].' - flight altitude : '.$this->all_flights[$key]['altitude_real']."\n"; |
|
| 168 | + if ($globalDebug) { |
|
| 169 | + echo "----- Can't find arrival airport. Airport altitude : ".$closestAirports[0]['altitude'].' - flight altitude : '.$this->all_flights[$key]['altitude_real']."\n"; |
|
| 170 | + } |
|
| 151 | 171 | } |
| 152 | 172 | } else { |
| 153 | - if ($globalDebug) echo "----- No Airport near last coord. Latitude : ".$this->all_flights[$key]['latitude'].' - Longitude : '.$this->all_flights[$key]['longitude'].' - MinDist : '.$globalClosestMinDist."\n"; |
|
| 173 | + if ($globalDebug) { |
|
| 174 | + echo "----- No Airport near last coord. Latitude : ".$this->all_flights[$key]['latitude'].' - Longitude : '.$this->all_flights[$key]['longitude'].' - MinDist : '.$globalClosestMinDist."\n"; |
|
| 175 | + } |
|
| 154 | 176 | } |
| 155 | 177 | |
| 156 | 178 | } else { |
| 157 | - if ($globalDebug) echo "---- No latitude or longitude. Ident : ".$this->all_flights[$key]['ident']."\n"; |
|
| 179 | + if ($globalDebug) { |
|
| 180 | + echo "---- No latitude or longitude. Ident : ".$this->all_flights[$key]['ident']."\n"; |
|
| 181 | + } |
|
| 158 | 182 | } |
| 159 | 183 | return array('airport_icao' => $airport_icao,'airport_time' => $airport_time); |
| 160 | 184 | } |
@@ -164,12 +188,16 @@ discard block |
||
| 164 | 188 | public function del() { |
| 165 | 189 | global $globalDebug; |
| 166 | 190 | // Delete old infos |
| 167 | - if ($globalDebug) echo 'Delete old values and update latest data...'."\n"; |
|
| 191 | + if ($globalDebug) { |
|
| 192 | + echo 'Delete old values and update latest data...'."\n"; |
|
| 193 | + } |
|
| 168 | 194 | foreach ($this->all_flights as $key => $flight) { |
| 169 | 195 | if (isset($flight['lastupdate'])) { |
| 170 | 196 | if ($flight['lastupdate'] < (time()-3000)) { |
| 171 | 197 | if (isset($this->all_flights[$key]['id'])) { |
| 172 | - if ($globalDebug) echo "--- Delete old values with id ".$this->all_flights[$key]['id']."\n"; |
|
| 198 | + if ($globalDebug) { |
|
| 199 | + echo "--- Delete old values with id ".$this->all_flights[$key]['id']."\n"; |
|
| 200 | + } |
|
| 173 | 201 | /* |
| 174 | 202 | $SpotterLive = new SpotterLive(); |
| 175 | 203 | $SpotterLive->deleteLiveSpotterDataById($this->all_flights[$key]['id']); |
@@ -179,7 +207,9 @@ discard block |
||
| 179 | 207 | $Spotter = new Spotter($this->db); |
| 180 | 208 | if ($this->all_flights[$key]['latitude'] != '' && $this->all_flights[$key]['longitude'] != '') { |
| 181 | 209 | $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']); |
| 182 | - if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n"; |
|
| 210 | + if ($globalDebug && $result != 'success') { |
|
| 211 | + echo '!!! ERROR : '.$result."\n"; |
|
| 212 | + } |
|
| 183 | 213 | } |
| 184 | 214 | // Put in archive |
| 185 | 215 | // $Spotter->db = null; |
@@ -193,8 +223,10 @@ discard block |
||
| 193 | 223 | public function add($line) { |
| 194 | 224 | global $globalPilotIdAccept, $globalAirportAccept, $globalAirlineAccept, $globalAirlineIgnore, $globalAirportIgnore, $globalFork, $globalDistanceIgnore, $globalDaemon, $globalSBS1update, $globalDebug, $globalIVAO, $globalVATSIM, $globalphpVMS, $globalCoordMinChange, $globalDebugTimeElapsed, $globalCenterLatitude, $globalCenterLongitude, $globalBeta, $globalSourcesupdate, $globalAirlinesSource, $globalVAM, $globalAllFlights; |
| 195 | 225 | //if (!isset($globalDebugTimeElapsed) || $globalDebugTimeElapsed == '') $globalDebugTimeElapsed = FALSE; |
| 196 | - if (!isset($globalCoordMinChange) || $globalCoordMinChange == '') $globalCoordMinChange = '0.02'; |
|
| 197 | -/* |
|
| 226 | + if (!isset($globalCoordMinChange) || $globalCoordMinChange == '') { |
|
| 227 | + $globalCoordMinChange = '0.02'; |
|
| 228 | + } |
|
| 229 | + /* |
|
| 198 | 230 | $Spotter = new Spotter(); |
| 199 | 231 | $dbc = $Spotter->db; |
| 200 | 232 | $SpotterLive = new SpotterLive($dbc); |
@@ -222,11 +254,15 @@ discard block |
||
| 222 | 254 | if (isset($line['sourcestats']) && $line['sourcestats'] == TRUE) { |
| 223 | 255 | $current_date = date('Y-m-d'); |
| 224 | 256 | $source = $line['source_name']; |
| 225 | - if ($source == '' || $line['format_source'] == 'aprs') $source = $line['format_source']; |
|
| 257 | + if ($source == '' || $line['format_source'] == 'aprs') { |
|
| 258 | + $source = $line['format_source']; |
|
| 259 | + } |
|
| 226 | 260 | if (!isset($this->stats[$current_date][$source]['msg'])) { |
| 227 | 261 | $this->stats[$current_date][$source]['msg']['date'] = time(); |
| 228 | 262 | $this->stats[$current_date][$source]['msg']['nb'] = 1; |
| 229 | - } else $this->stats[$current_date][$source]['msg']['nb'] += 1; |
|
| 263 | + } else { |
|
| 264 | + $this->stats[$current_date][$source]['msg']['nb'] += 1; |
|
| 265 | + } |
|
| 230 | 266 | } |
| 231 | 267 | |
| 232 | 268 | /* |
@@ -242,8 +278,11 @@ discard block |
||
| 242 | 278 | //$this->db = $dbc; |
| 243 | 279 | |
| 244 | 280 | $hex = trim($line['hex']); |
| 245 | - if (!isset($line['id'])) $id = trim($line['hex']); |
|
| 246 | - else $id = trim($line['id']); |
|
| 281 | + if (!isset($line['id'])) { |
|
| 282 | + $id = trim($line['hex']); |
|
| 283 | + } else { |
|
| 284 | + $id = trim($line['id']); |
|
| 285 | + } |
|
| 247 | 286 | |
| 248 | 287 | //print_r($this->all_flights); |
| 249 | 288 | if (!isset($this->all_flights[$id]['hex']) && ctype_xdigit($hex)) { |
@@ -258,13 +297,20 @@ discard block |
||
| 258 | 297 | $Spotter = new Spotter($this->db); |
| 259 | 298 | $aircraft_icao = $Spotter->getAllAircraftType($hex); |
| 260 | 299 | $Spotter->db = null; |
| 261 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update getallaircrattype : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
| 300 | + if ($globalDebugTimeElapsed) { |
|
| 301 | + echo 'Time elapsed for update getallaircrattype : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
| 302 | + } |
|
| 262 | 303 | |
| 263 | 304 | if ($aircraft_icao == '' && isset($line['aircraft_type'])) { |
| 264 | - if ($line['aircraft_type'] == 'PARA_GLIDER') $aircraft_icao = 'GLID'; |
|
| 265 | - elseif ($line['aircraft_type'] == 'HELICOPTER_ROTORCRAFT') $aircraft_icao = 'UHEL'; |
|
| 266 | - elseif ($line['aircraft_type'] == 'TOW_PLANE') $aircraft_icao = 'TOWPLANE'; |
|
| 267 | - elseif ($line['aircraft_type'] == 'POWERED_AIRCRAFT') $aircraft_icao = 'POWAIRC'; |
|
| 305 | + if ($line['aircraft_type'] == 'PARA_GLIDER') { |
|
| 306 | + $aircraft_icao = 'GLID'; |
|
| 307 | + } elseif ($line['aircraft_type'] == 'HELICOPTER_ROTORCRAFT') { |
|
| 308 | + $aircraft_icao = 'UHEL'; |
|
| 309 | + } elseif ($line['aircraft_type'] == 'TOW_PLANE') { |
|
| 310 | + $aircraft_icao = 'TOWPLANE'; |
|
| 311 | + } elseif ($line['aircraft_type'] == 'POWERED_AIRCRAFT') { |
|
| 312 | + $aircraft_icao = 'POWAIRC'; |
|
| 313 | + } |
|
| 268 | 314 | } |
| 269 | 315 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao)); |
| 270 | 316 | } else if (isset($line['aircraft_name'])) { |
@@ -272,29 +318,47 @@ discard block |
||
| 272 | 318 | $Spotter = new Spotter($this->db); |
| 273 | 319 | $aircraft_icao = $Spotter->getAircraftIcao($line['aircraft_name']); |
| 274 | 320 | $Spotter->db = null; |
| 275 | - if ($aircraft_icao != '') $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao)); |
|
| 276 | - else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => 'NA')); |
|
| 277 | - } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $line['aircraft_icao'])); |
|
| 321 | + if ($aircraft_icao != '') { |
|
| 322 | + $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $aircraft_icao)); |
|
| 323 | + } else { |
|
| 324 | + $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => 'NA')); |
|
| 325 | + } |
|
| 326 | + } else { |
|
| 327 | + $this->all_flights[$id] = array_merge($this->all_flights[$id],array('aircraft_icao' => $line['aircraft_icao'])); |
|
| 328 | + } |
|
| 278 | 329 | $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)); |
| 279 | 330 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('lastupdate' => time())); |
| 280 | 331 | if (!isset($line['id'])) { |
| 281 | - if (!isset($globalDaemon)) $globalDaemon = TRUE; |
|
| 282 | -// 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'))); |
|
| 332 | + if (!isset($globalDaemon)) { |
|
| 333 | + $globalDaemon = TRUE; |
|
| 334 | + } |
|
| 335 | + // 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'))); |
|
| 283 | 336 | // 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'))); |
| 284 | - 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'))); |
|
| 337 | + 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')) { |
|
| 338 | + $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdHi'))); |
|
| 339 | + } |
|
| 285 | 340 | //else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident'])); |
| 286 | - } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id'])); |
|
| 341 | + } else { |
|
| 342 | + $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id'])); |
|
| 343 | + } |
|
| 287 | 344 | |
| 288 | - if ($globalDebug) echo "*********** New aircraft hex : ".$hex." ***********\n"; |
|
| 289 | - if ($globalAllFlights !== FALSE) $dataFound = true; |
|
| 345 | + if ($globalDebug) { |
|
| 346 | + echo "*********** New aircraft hex : ".$hex." ***********\n"; |
|
| 347 | + } |
|
| 348 | + if ($globalAllFlights !== FALSE) { |
|
| 349 | + $dataFound = true; |
|
| 350 | + } |
|
| 290 | 351 | } |
| 291 | 352 | |
| 292 | 353 | if (isset($line['datetime']) && preg_match('/^(\d{4}(?:\-\d{2}){2} \d{2}(?:\:\d{2}){2})$/',$line['datetime'])) { |
| 293 | 354 | if (!isset($this->all_flights[$id]['datetime']) || strtotime($line['datetime']) >= strtotime($this->all_flights[$id]['datetime'])) { |
| 294 | 355 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => $line['datetime'])); |
| 295 | 356 | } else { |
| 296 | - 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"; |
|
| 297 | - 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"; |
|
| 357 | + if (strtotime($line['datetime']) == strtotime($this->all_flights[$id]['datetime']) && $globalDebug) { |
|
| 358 | + echo "!!! Date is the same as previous data for ".$this->all_flights[$id]['hex']." - format : ".$line['format_source']."\n"; |
|
| 359 | + } elseif (strtotime($line['datetime']) > strtotime($this->all_flights[$id]['datetime']) && $globalDebug) { |
|
| 360 | + echo "!!! Date previous latest data (".$line['datetime']." > ".$this->all_flights[$id]['datetime'].") !!! for ".$this->all_flights[$id]['hex']." - format : ".$line['format_source']."\n"; |
|
| 361 | + } |
|
| 298 | 362 | /* |
| 299 | 363 | echo strtotime($line['datetime']).' > '.strtotime($this->all_flights[$id]['datetime']); |
| 300 | 364 | print_r($this->all_flights[$id]); |
@@ -302,7 +366,9 @@ discard block |
||
| 302 | 366 | */ |
| 303 | 367 | return ''; |
| 304 | 368 | } |
| 305 | - } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => date('Y-m-d H:i:s'))); |
|
| 369 | + } else { |
|
| 370 | + $this->all_flights[$id] = array_merge($this->all_flights[$id],array('datetime' => date('Y-m-d H:i:s'))); |
|
| 371 | + } |
|
| 306 | 372 | |
| 307 | 373 | if (isset($line['registration']) && $line['registration'] != '' && $line['registration'] != 'z.NO-REG') { |
| 308 | 374 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('registration' => $line['registration'])); |
@@ -323,15 +389,25 @@ discard block |
||
| 323 | 389 | $timeelapsed = microtime(true); |
| 324 | 390 | $Spotter = new Spotter($this->db); |
| 325 | 391 | $fromsource = NULL; |
| 326 | - if (isset($globalAirlinesSource) && $globalAirlinesSource != '') $fromsource = $globalAirlinesSource; |
|
| 327 | - elseif (isset($line['format_source']) && $line['format_source'] == 'vatsimtxt') $fromsource = 'vatsim'; |
|
| 328 | - elseif (isset($line['format_source']) && $line['format_source'] == 'whazzup') $fromsource = 'ivao'; |
|
| 329 | - elseif (isset($globalVATSIM) && $globalVATSIM) $fromsource = 'vatsim'; |
|
| 330 | - elseif (isset($globalIVAO) && $globalIVAO) $fromsource = 'ivao'; |
|
| 392 | + if (isset($globalAirlinesSource) && $globalAirlinesSource != '') { |
|
| 393 | + $fromsource = $globalAirlinesSource; |
|
| 394 | + } elseif (isset($line['format_source']) && $line['format_source'] == 'vatsimtxt') { |
|
| 395 | + $fromsource = 'vatsim'; |
|
| 396 | + } elseif (isset($line['format_source']) && $line['format_source'] == 'whazzup') { |
|
| 397 | + $fromsource = 'ivao'; |
|
| 398 | + } elseif (isset($globalVATSIM) && $globalVATSIM) { |
|
| 399 | + $fromsource = 'vatsim'; |
|
| 400 | + } elseif (isset($globalIVAO) && $globalIVAO) { |
|
| 401 | + $fromsource = 'ivao'; |
|
| 402 | + } |
|
| 331 | 403 | $result = $Spotter->updateIdentSpotterData($this->all_flights[$id]['id'],$this->all_flights[$id]['ident'],$fromsource); |
| 332 | - if ($globalDebug && $result != 'success') echo '!!! ERROR : '.$result."\n"; |
|
| 404 | + if ($globalDebug && $result != 'success') { |
|
| 405 | + echo '!!! ERROR : '.$result."\n"; |
|
| 406 | + } |
|
| 333 | 407 | $Spotter->db = null; |
| 334 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update identspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
| 408 | + if ($globalDebugTimeElapsed) { |
|
| 409 | + echo 'Time elapsed for update identspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
| 410 | + } |
|
| 335 | 411 | } |
| 336 | 412 | |
| 337 | 413 | /* |
@@ -342,7 +418,9 @@ discard block |
||
| 342 | 418 | else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident'])); |
| 343 | 419 | } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id'])); |
| 344 | 420 | */ |
| 345 | - 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'])); |
|
| 421 | + if (!isset($this->all_flights[$id]['id'])) { |
|
| 422 | + $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident'])); |
|
| 423 | + } |
|
| 346 | 424 | |
| 347 | 425 | //$putinarchive = true; |
| 348 | 426 | if (isset($line['departure_airport_time']) && $line['departure_airport_time'] != 0) { |
@@ -359,7 +437,9 @@ discard block |
||
| 359 | 437 | $line['departure_airport_icao'] = $Spotter->getAirportIcao($line['departure_airport_iata']); |
| 360 | 438 | $line['arrival_airport_icao'] = $Spotter->getAirportIcao($line['arrival_airport_iata']); |
| 361 | 439 | $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' => '')); |
| 362 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update getAirportICAO : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
| 440 | + if ($globalDebugTimeElapsed) { |
|
| 441 | + echo 'Time elapsed for update getAirportICAO : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
| 442 | + } |
|
| 363 | 443 | |
| 364 | 444 | } elseif (!isset($line['format_source']) || $line['format_source'] != 'aprs') { |
| 365 | 445 | $timeelapsed = microtime(true); |
@@ -372,7 +452,9 @@ discard block |
||
| 372 | 452 | $Translation->db = null; |
| 373 | 453 | } |
| 374 | 454 | $Spotter->db = null; |
| 375 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update getrouteinfo : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
| 455 | + if ($globalDebugTimeElapsed) { |
|
| 456 | + echo 'Time elapsed for update getrouteinfo : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
| 457 | + } |
|
| 376 | 458 | |
| 377 | 459 | if (isset($route['fromairport_icao']) && isset($route['toairport_icao'])) { |
| 378 | 460 | //if ($route['FromAirport_ICAO'] != $route['ToAirport_ICAO']) { |
@@ -381,9 +463,13 @@ discard block |
||
| 381 | 463 | $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'])); |
| 382 | 464 | } |
| 383 | 465 | } |
| 384 | - if (!isset($globalFork)) $globalFork = TRUE; |
|
| 466 | + if (!isset($globalFork)) { |
|
| 467 | + $globalFork = TRUE; |
|
| 468 | + } |
|
| 385 | 469 | if (!$globalIVAO && !$globalVATSIM && !$globalphpVMS && !$globalVAM && (!isset($line['format_source']) || $line['format_source'] != 'aprs')) { |
| 386 | - if (!isset($this->all_flights[$id]['schedule_check']) || $this->all_flights[$id]['schedule_check'] === false) $this->get_Schedule($id,trim($line['ident'])); |
|
| 470 | + if (!isset($this->all_flights[$id]['schedule_check']) || $this->all_flights[$id]['schedule_check'] === false) { |
|
| 471 | + $this->get_Schedule($id,trim($line['ident'])); |
|
| 472 | + } |
|
| 387 | 473 | } |
| 388 | 474 | } |
| 389 | 475 | } |
@@ -399,16 +485,23 @@ discard block |
||
| 399 | 485 | // use datetime |
| 400 | 486 | $speed = $distance/(time() - $this->all_flights[$id]['time_last_coord']); |
| 401 | 487 | $speed = $speed*3.6; |
| 402 | - if ($speed < 1000) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed' => round($speed))); |
|
| 403 | - if ($globalDebug) echo "ø Calculated Speed for ".$this->all_flights[$id]['hex']." : ".$speed." - distance : ".$distance."\n"; |
|
| 488 | + if ($speed < 1000) { |
|
| 489 | + $this->all_flights[$id] = array_merge($this->all_flights[$id],array('speed' => round($speed))); |
|
| 490 | + } |
|
| 491 | + if ($globalDebug) { |
|
| 492 | + echo "ø Calculated Speed for ".$this->all_flights[$id]['hex']." : ".$speed." - distance : ".$distance."\n"; |
|
| 493 | + } |
|
| 404 | 494 | } |
| 405 | 495 | } |
| 406 | 496 | |
| 407 | 497 | |
| 408 | 498 | |
| 409 | 499 | if (isset($line['latitude']) && isset($line['longitude']) && $line['latitude'] != '' && $line['longitude'] != '' && is_numeric($line['latitude']) && is_numeric($line['longitude'])) { |
| 410 | - if (isset($this->all_flights[$id]['time_last_coord'])) $timediff = round(time()-$this->all_flights[$id]['time_last_coord']); |
|
| 411 | - else unset($timediff); |
|
| 500 | + if (isset($this->all_flights[$id]['time_last_coord'])) { |
|
| 501 | + $timediff = round(time()-$this->all_flights[$id]['time_last_coord']); |
|
| 502 | + } else { |
|
| 503 | + unset($timediff); |
|
| 504 | + } |
|
| 412 | 505 | 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')))) { |
| 413 | 506 | 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'])) { |
| 414 | 507 | 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'])) { |
@@ -416,21 +509,31 @@ discard block |
||
| 416 | 509 | $this->all_flights[$id]['archive_longitude'] = $line['longitude']; |
| 417 | 510 | $this->all_flights[$id]['putinarchive'] = true; |
| 418 | 511 | |
| 419 | - if ($globalDebug) echo "\n".' ------- Check Country.... '; |
|
| 512 | + if ($globalDebug) { |
|
| 513 | + echo "\n".' ------- Check Country.... '; |
|
| 514 | + } |
|
| 420 | 515 | $timeelapsed = microtime(true); |
| 421 | 516 | $Spotter = new Spotter($this->db); |
| 422 | 517 | $all_country = $Spotter->getCountryFromLatitudeLongitude($line['latitude'],$line['longitude']); |
| 423 | - if (!empty($all_country)) $this->all_flights[$id]['over_country'] = $all_country['iso2']; |
|
| 518 | + if (!empty($all_country)) { |
|
| 519 | + $this->all_flights[$id]['over_country'] = $all_country['iso2']; |
|
| 520 | + } |
|
| 424 | 521 | $Spotter->db = null; |
| 425 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
| 522 | + if ($globalDebugTimeElapsed) { |
|
| 523 | + echo 'Time elapsed for update getCountryFromlatitudeLongitude : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
| 524 | + } |
|
| 426 | 525 | $this->tmd = 0; |
| 427 | - if ($globalDebug) echo 'FOUND : '.$this->all_flights[$id]['over_country'].' ---------------'."\n"; |
|
| 526 | + if ($globalDebug) { |
|
| 527 | + echo 'FOUND : '.$this->all_flights[$id]['over_country'].' ---------------'."\n"; |
|
| 528 | + } |
|
| 428 | 529 | } |
| 429 | 530 | } |
| 430 | 531 | |
| 431 | 532 | if (isset($line['latitude']) && $line['latitude'] != '' && $line['latitude'] != 0 && $line['latitude'] < 91 && $line['latitude'] > -90) { |
| 432 | 533 | //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) { |
| 433 | - if (!isset($this->all_flights[$id]['archive_latitude'])) $this->all_flights[$id]['archive_latitude'] = $line['latitude']; |
|
| 534 | + if (!isset($this->all_flights[$id]['archive_latitude'])) { |
|
| 535 | + $this->all_flights[$id]['archive_latitude'] = $line['latitude']; |
|
| 536 | + } |
|
| 434 | 537 | 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') { |
| 435 | 538 | $this->all_flights[$id]['livedb_latitude'] = $line['latitude']; |
| 436 | 539 | $dataFound = true; |
@@ -452,9 +555,13 @@ discard block |
||
| 452 | 555 | */ |
| 453 | 556 | } |
| 454 | 557 | if (isset($line['longitude']) && $line['longitude'] != '' && $line['longitude'] != 0 && $line['longitude'] < 360 && $line['longitude'] > -180) { |
| 455 | - if ($line['longitude'] > 180) $line['longitude'] = $line['longitude'] - 360; |
|
| 558 | + if ($line['longitude'] > 180) { |
|
| 559 | + $line['longitude'] = $line['longitude'] - 360; |
|
| 560 | + } |
|
| 456 | 561 | //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) { |
| 457 | - if (!isset($this->all_flights[$id]['archive_longitude'])) $this->all_flights[$id]['archive_longitude'] = $line['longitude']; |
|
| 562 | + if (!isset($this->all_flights[$id]['archive_longitude'])) { |
|
| 563 | + $this->all_flights[$id]['archive_longitude'] = $line['longitude']; |
|
| 564 | + } |
|
| 458 | 565 | 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') { |
| 459 | 566 | $this->all_flights[$id]['livedb_longitude'] = $line['longitude']; |
| 460 | 567 | $dataFound = true; |
@@ -485,7 +592,9 @@ discard block |
||
| 485 | 592 | } |
| 486 | 593 | } |
| 487 | 594 | if (isset($line['last_update']) && $line['last_update'] != '') { |
| 488 | - if (isset($this->all_flights[$id]['last_update']) && $this->all_flights[$id]['last_update'] != $line['last_update']) $dataFound = true; |
|
| 595 | + if (isset($this->all_flights[$id]['last_update']) && $this->all_flights[$id]['last_update'] != $line['last_update']) { |
|
| 596 | + $dataFound = true; |
|
| 597 | + } |
|
| 489 | 598 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('last_update' => $line['last_update'])); |
| 490 | 599 | } |
| 491 | 600 | if (isset($line['verticalrate']) && $line['verticalrate'] != '') { |
@@ -507,11 +616,17 @@ discard block |
||
| 507 | 616 | // Here we force archive of flight because after ground it's a new one (or should be) |
| 508 | 617 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('addedSpotter' => 0)); |
| 509 | 618 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('forcenew' => 1)); |
| 510 | - 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'))); |
|
| 511 | - elseif (isset($line['id'])) $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id'])); |
|
| 512 | - 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'])); |
|
| 619 | + if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw') && $globalDaemon) { |
|
| 620 | + $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdGi'))); |
|
| 621 | + } elseif (isset($line['id'])) { |
|
| 622 | + $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $line['id'])); |
|
| 623 | + } elseif (isset($this->all_flights[$id]['ident'])) { |
|
| 624 | + $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.$this->all_flights[$id]['ident'])); |
|
| 625 | + } |
|
| 626 | + } |
|
| 627 | + if ($line['ground'] != 1) { |
|
| 628 | + $line['ground'] = 0; |
|
| 513 | 629 | } |
| 514 | - if ($line['ground'] != 1) $line['ground'] = 0; |
|
| 515 | 630 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('ground' => $line['ground'])); |
| 516 | 631 | //$dataFound = true; |
| 517 | 632 | } |
@@ -519,28 +634,40 @@ discard block |
||
| 519 | 634 | 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'])) { |
| 520 | 635 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk'])); |
| 521 | 636 | $highlight = ''; |
| 522 | - if ($this->all_flights[$id]['squawk'] == '7500') $highlight = 'Squawk 7500 : Hijack at '.date('Y-m-d G:i').' UTC'; |
|
| 523 | - if ($this->all_flights[$id]['squawk'] == '7600') $highlight = 'Squawk 7600 : Lost Comm (radio failure) at '.date('Y-m-d G:i').' UTC'; |
|
| 524 | - if ($this->all_flights[$id]['squawk'] == '7700') $highlight = 'Squawk 7700 : Emergency at '.date('Y-m-d G:i').' UTC'; |
|
| 637 | + if ($this->all_flights[$id]['squawk'] == '7500') { |
|
| 638 | + $highlight = 'Squawk 7500 : Hijack at '.date('Y-m-d G:i').' UTC'; |
|
| 639 | + } |
|
| 640 | + if ($this->all_flights[$id]['squawk'] == '7600') { |
|
| 641 | + $highlight = 'Squawk 7600 : Lost Comm (radio failure) at '.date('Y-m-d G:i').' UTC'; |
|
| 642 | + } |
|
| 643 | + if ($this->all_flights[$id]['squawk'] == '7700') { |
|
| 644 | + $highlight = 'Squawk 7700 : Emergency at '.date('Y-m-d G:i').' UTC'; |
|
| 645 | + } |
|
| 525 | 646 | if ($highlight != '') { |
| 526 | 647 | $timeelapsed = microtime(true); |
| 527 | 648 | $Spotter = new Spotter($this->db); |
| 528 | 649 | $Spotter->setHighlightFlight($this->all_flights[$id]['id'],$highlight); |
| 529 | 650 | $Spotter->db = null; |
| 530 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update sethighlightflight : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
| 651 | + if ($globalDebugTimeElapsed) { |
|
| 652 | + echo 'Time elapsed for update sethighlightflight : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
| 653 | + } |
|
| 531 | 654 | |
| 532 | 655 | $this->all_flights[$id]['putinarchive'] = true; |
| 533 | 656 | //$putinarchive = true; |
| 534 | 657 | //$highlight = ''; |
| 535 | 658 | } |
| 536 | 659 | |
| 537 | - } else $this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk'])); |
|
| 660 | + } else { |
|
| 661 | + $this->all_flights[$id] = array_merge($this->all_flights[$id],array('squawk' => $line['squawk'])); |
|
| 662 | + } |
|
| 538 | 663 | //$dataFound = true; |
| 539 | 664 | } |
| 540 | 665 | |
| 541 | 666 | if (isset($line['altitude']) && $line['altitude'] != '') { |
| 542 | 667 | //if (!isset($this->all_flights[$id]['altitude']) || $this->all_flights[$id]['altitude'] == '' || ($this->all_flights[$id]['altitude'] > 0 && $line['altitude'] != 0)) { |
| 543 | - 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; |
|
| 668 | + if (is_int($this->all_flights[$id]['altitude']) && abs(round($line['altitude']/100)-$this->all_flights[$id]['altitude']) > 2) { |
|
| 669 | + $this->all_flights[$id]['putinarchive'] = true; |
|
| 670 | + } |
|
| 544 | 671 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('altitude' => round($line['altitude']/100))); |
| 545 | 672 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('altitude_real' => $line['altitude'])); |
| 546 | 673 | //$dataFound = true; |
@@ -552,21 +679,30 @@ discard block |
||
| 552 | 679 | } |
| 553 | 680 | |
| 554 | 681 | if (isset($line['heading']) && $line['heading'] != '') { |
| 555 | - if (is_int($this->all_flights[$id]['heading']) && abs($this->all_flights[$id]['heading']-round($line['heading'])) > 2) $this->all_flights[$id]['putinarchive'] = true; |
|
| 682 | + if (is_int($this->all_flights[$id]['heading']) && abs($this->all_flights[$id]['heading']-round($line['heading'])) > 2) { |
|
| 683 | + $this->all_flights[$id]['putinarchive'] = true; |
|
| 684 | + } |
|
| 556 | 685 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => round($line['heading']))); |
| 557 | 686 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading_fromsrc' => true)); |
| 558 | 687 | //$dataFound = true; |
| 559 | 688 | } 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']) { |
| 560 | 689 | $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']); |
| 561 | 690 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => round($heading))); |
| 562 | - if (abs($this->all_flights[$id]['heading']-round($heading)) > 2) $this->all_flights[$id]['putinarchive'] = true; |
|
| 563 | - if ($globalDebug) echo "ø Calculated Heading for ".$this->all_flights[$id]['hex']." : ".$heading."\n"; |
|
| 691 | + if (abs($this->all_flights[$id]['heading']-round($heading)) > 2) { |
|
| 692 | + $this->all_flights[$id]['putinarchive'] = true; |
|
| 693 | + } |
|
| 694 | + if ($globalDebug) { |
|
| 695 | + echo "ø Calculated Heading for ".$this->all_flights[$id]['hex']." : ".$heading."\n"; |
|
| 696 | + } |
|
| 564 | 697 | } elseif (isset($this->all_flights[$id]['format_source']) && $this->all_flights[$id]['format_source'] == 'ACARS') { |
| 565 | 698 | // If not enough messages and ACARS set heading to 0 |
| 566 | 699 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('heading' => 0)); |
| 567 | 700 | } |
| 568 | - if (isset($globalSourcesupdate) && $globalSourcesupdate != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalSourcesupdate) $dataFound = false; |
|
| 569 | - elseif (isset($globalSBS1update) && $globalSBS1update != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalSBS1update) $dataFound = false; |
|
| 701 | + if (isset($globalSourcesupdate) && $globalSourcesupdate != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalSourcesupdate) { |
|
| 702 | + $dataFound = false; |
|
| 703 | + } elseif (isset($globalSBS1update) && $globalSBS1update != '' && isset($this->all_flights[$id]['lastupdate']) && time()-$this->all_flights[$id]['lastupdate'] < $globalSBS1update) { |
|
| 704 | + $dataFound = false; |
|
| 705 | + } |
|
| 570 | 706 | |
| 571 | 707 | // print_r($this->all_flights[$id]); |
| 572 | 708 | //gets the callsign from the last hour |
@@ -581,23 +717,36 @@ discard block |
||
| 581 | 717 | //echo $this->all_flights[$id]['id'].' - '.$this->all_flights[$id]['addedSpotter']."\n"; |
| 582 | 718 | //$last_hour_ident = Spotter->getIdentFromLastHour($this->all_flights[$id]['ident']); |
| 583 | 719 | if (!isset($this->all_flights[$id]['forcenew']) || $this->all_flights[$id]['forcenew'] == 0) { |
| 584 | - if ($globalDebug) echo "Check if aircraft is already in DB..."; |
|
| 720 | + if ($globalDebug) { |
|
| 721 | + echo "Check if aircraft is already in DB..."; |
|
| 722 | + } |
|
| 585 | 723 | $timeelapsed = microtime(true); |
| 586 | 724 | $SpotterLive = new SpotterLive($this->db); |
| 587 | 725 | 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')) { |
| 588 | 726 | $recent_ident = $SpotterLive->checkModeSRecent($this->all_flights[$id]['hex']); |
| 589 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkModeSRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
| 727 | + if ($globalDebugTimeElapsed) { |
|
| 728 | + echo 'Time elapsed for update checkModeSRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
| 729 | + } |
|
| 590 | 730 | } elseif (isset($line['id'])) { |
| 591 | 731 | $recent_ident = $SpotterLive->checkIdRecent($line['id']); |
| 592 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
| 732 | + if ($globalDebugTimeElapsed) { |
|
| 733 | + echo 'Time elapsed for update checkIdRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
| 734 | + } |
|
| 593 | 735 | } elseif (isset($this->all_flights[$id]['ident']) && $this->all_flights[$id]['ident'] != '') { |
| 594 | 736 | $recent_ident = $SpotterLive->checkIdentRecent($this->all_flights[$id]['ident']); |
| 595 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
| 596 | - } else $recent_ident = ''; |
|
| 737 | + if ($globalDebugTimeElapsed) { |
|
| 738 | + echo 'Time elapsed for update checkIdentRecent : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
| 739 | + } |
|
| 740 | + } else { |
|
| 741 | + $recent_ident = ''; |
|
| 742 | + } |
|
| 597 | 743 | $SpotterLive->db=null; |
| 598 | 744 | |
| 599 | - if ($globalDebug && $recent_ident == '') echo " Not in DB.\n"; |
|
| 600 | - elseif ($globalDebug && $recent_ident != '') echo " Already in DB.\n"; |
|
| 745 | + if ($globalDebug && $recent_ident == '') { |
|
| 746 | + echo " Not in DB.\n"; |
|
| 747 | + } elseif ($globalDebug && $recent_ident != '') { |
|
| 748 | + echo " Already in DB.\n"; |
|
| 749 | + } |
|
| 601 | 750 | } else { |
| 602 | 751 | $recent_ident = ''; |
| 603 | 752 | $this->all_flights[$id] = array_merge($this->all_flights[$id],array('forcenew' => 0)); |
@@ -605,7 +754,9 @@ discard block |
||
| 605 | 754 | //if there was no aircraft with the same callsign within the last hour and go post it into the archive |
| 606 | 755 | if($recent_ident == "") |
| 607 | 756 | { |
| 608 | - if ($globalDebug) echo "\o/ Add ".$this->all_flights[$id]['ident']." in archive DB : "; |
|
| 757 | + if ($globalDebug) { |
|
| 758 | + echo "\o/ Add ".$this->all_flights[$id]['ident']." in archive DB : "; |
|
| 759 | + } |
|
| 609 | 760 | if ($this->all_flights[$id]['departure_airport'] == "") { $this->all_flights[$id]['departure_airport'] = "NA"; } |
| 610 | 761 | if ($this->all_flights[$id]['arrival_airport'] == "") { $this->all_flights[$id]['arrival_airport'] = "NA"; } |
| 611 | 762 | //adds the spotter data for the archive |
@@ -649,26 +800,44 @@ discard block |
||
| 649 | 800 | |
| 650 | 801 | if (!$ignoreImport) { |
| 651 | 802 | $highlight = ''; |
| 652 | - if ($this->all_flights[$id]['squawk'] == '7500') $highlight = 'Squawk 7500 : Hijack'; |
|
| 653 | - if ($this->all_flights[$id]['squawk'] == '7600') $highlight = 'Squawk 7600 : Lost Comm (radio failure)'; |
|
| 654 | - if ($this->all_flights[$id]['squawk'] == '7700') $highlight = 'Squawk 7700 : Emergency'; |
|
| 655 | - 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'))); |
|
| 803 | + if ($this->all_flights[$id]['squawk'] == '7500') { |
|
| 804 | + $highlight = 'Squawk 7500 : Hijack'; |
|
| 805 | + } |
|
| 806 | + if ($this->all_flights[$id]['squawk'] == '7600') { |
|
| 807 | + $highlight = 'Squawk 7600 : Lost Comm (radio failure)'; |
|
| 808 | + } |
|
| 809 | + if ($this->all_flights[$id]['squawk'] == '7700') { |
|
| 810 | + $highlight = 'Squawk 7700 : Emergency'; |
|
| 811 | + } |
|
| 812 | + if (!isset($this->all_flights[$id]['id'])) { |
|
| 813 | + $this->all_flights[$id] = array_merge($this->all_flights[$id],array('id' => $this->all_flights[$id]['hex'].'-'.date('YmdHi'))); |
|
| 814 | + } |
|
| 656 | 815 | $timeelapsed = microtime(true); |
| 657 | 816 | $Spotter = new Spotter($this->db); |
| 658 | 817 | $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']); |
| 659 | 818 | $Spotter->db = null; |
| 660 | - if ($globalDebug && isset($result)) echo $result."\n"; |
|
| 661 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
| 819 | + if ($globalDebug && isset($result)) { |
|
| 820 | + echo $result."\n"; |
|
| 821 | + } |
|
| 822 | + if ($globalDebugTimeElapsed) { |
|
| 823 | + echo 'Time elapsed for update addspotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
| 824 | + } |
|
| 662 | 825 | |
| 663 | 826 | // Add source stat in DB |
| 664 | 827 | $Stats = new Stats($this->db); |
| 665 | 828 | if (!empty($this->stats)) { |
| 666 | - if ($globalDebug) echo 'Add source stats : '; |
|
| 829 | + if ($globalDebug) { |
|
| 830 | + echo 'Add source stats : '; |
|
| 831 | + } |
|
| 667 | 832 | foreach($this->stats as $date => $data) { |
| 668 | 833 | foreach($data as $source => $sourced) { |
| 669 | 834 | //print_r($sourced); |
| 670 | - if (isset($sourced['polar'])) echo $Stats->addStatSource(json_encode($sourced['polar']),$source,'polar',$date); |
|
| 671 | - if (isset($sourced['hist'])) echo $Stats->addStatSource(json_encode($sourced['hist']),$source,'hist',$date); |
|
| 835 | + if (isset($sourced['polar'])) { |
|
| 836 | + echo $Stats->addStatSource(json_encode($sourced['polar']),$source,'polar',$date); |
|
| 837 | + } |
|
| 838 | + if (isset($sourced['hist'])) { |
|
| 839 | + echo $Stats->addStatSource(json_encode($sourced['hist']),$source,'hist',$date); |
|
| 840 | + } |
|
| 672 | 841 | if (isset($sourced['msg'])) { |
| 673 | 842 | if (time() - $sourced['msg']['date'] > 10) { |
| 674 | 843 | $nbmsg = round($sourced['msg']['nb']/(time() - $sourced['msg']['date'])); |
@@ -681,13 +850,17 @@ discard block |
||
| 681 | 850 | unset($this->stats[$date]); |
| 682 | 851 | } |
| 683 | 852 | } |
| 684 | - if ($globalDebug) echo 'Done'."\n"; |
|
| 853 | + if ($globalDebug) { |
|
| 854 | + echo 'Done'."\n"; |
|
| 855 | + } |
|
| 685 | 856 | |
| 686 | 857 | } |
| 687 | 858 | $Stats->db = null; |
| 688 | 859 | |
| 689 | 860 | $this->del(); |
| 690 | - } elseif ($globalDebug) echo 'Ignore data'."\n"; |
|
| 861 | + } elseif ($globalDebug) { |
|
| 862 | + echo 'Ignore data'."\n"; |
|
| 863 | + } |
|
| 691 | 864 | //$ignoreImport = false; |
| 692 | 865 | $this->all_flights[$id]['addedSpotter'] = 1; |
| 693 | 866 | //print_r($this->all_flights[$id]); |
@@ -704,12 +877,16 @@ discard block |
||
| 704 | 877 | */ |
| 705 | 878 | //SpotterLive->deleteLiveSpotterDataByIdent($this->all_flights[$id]['ident']); |
| 706 | 879 | if ($this->last_delete == 0 || time() - $this->last_delete > 1800) { |
| 707 | - if ($globalDebug) echo "---- Deleting Live Spotter data older than 9 hours..."; |
|
| 880 | + if ($globalDebug) { |
|
| 881 | + echo "---- Deleting Live Spotter data older than 9 hours..."; |
|
| 882 | + } |
|
| 708 | 883 | //SpotterLive->deleteLiveSpotterDataNotUpdated(); |
| 709 | 884 | $SpotterLive = new SpotterLive($this->db); |
| 710 | 885 | $SpotterLive->deleteLiveSpotterData(); |
| 711 | 886 | $SpotterLive->db=null; |
| 712 | - if ($globalDebug) echo " Done\n"; |
|
| 887 | + if ($globalDebug) { |
|
| 888 | + echo " Done\n"; |
|
| 889 | + } |
|
| 713 | 890 | $this->last_delete = time(); |
| 714 | 891 | } |
| 715 | 892 | } else { |
@@ -732,11 +909,17 @@ discard block |
||
| 732 | 909 | //echo "{$line[8]} {$line[7]} - MODES:{$line[4]} CALLSIGN:{$line[10]} ALT:{$line[11]} VEL:{$line[12]} HDG:{$line[13]} LAT:{$line[14]} LON:{$line[15]} VR:{$line[16]} SQUAWK:{$line[17]}\n"; |
| 733 | 910 | if ($globalDebug) { |
| 734 | 911 | if ((isset($globalIVAO) && $globalIVAO) || (isset($globalVATSIM) && $globalVATSIM) || (isset($globalphpVMS) && $globalphpVMS) || (isset($globalVAM) && $globalVAM)) { |
| 735 | - if (isset($this->all_flights[$id]['source_name'])) echo 'DATA : hex : '.$this->all_flights[$id]['hex'].' - ident : '.$this->all_flights[$id]['ident'].' - ICAO : '.$this->all_flights[$id]['aircraft_icao'].' - Departure Airport : '.$this->all_flights[$id]['departure_airport'].' - Arrival Airport : '.$this->all_flights[$id]['arrival_airport'].' - Latitude : '.$this->all_flights[$id]['latitude'].' - Longitude : '.$this->all_flights[$id]['longitude'].' - waypoints : '.$this->all_flights[$id]['waypoints'].' - Altitude : '.$this->all_flights[$id]['altitude'].' - Heading : '.$this->all_flights[$id]['heading'].' - Speed : '.$this->all_flights[$id]['speed'].' - Departure Airport Time : '.$this->all_flights[$id]['departure_airport_time'].' - Arrival Airport time : '.$this->all_flights[$id]['arrival_airport_time'].' - Pilot : '.$this->all_flights[$id]['pilot_name'].' - Source name : '.$this->all_flights[$id]['source_name']."\n"; |
|
| 736 | - else echo 'DATA : hex : '.$this->all_flights[$id]['hex'].' - ident : '.$this->all_flights[$id]['ident'].' - ICAO : '.$this->all_flights[$id]['aircraft_icao'].' - Departure Airport : '.$this->all_flights[$id]['departure_airport'].' - Arrival Airport : '.$this->all_flights[$id]['arrival_airport'].' - Latitude : '.$this->all_flights[$id]['latitude'].' - Longitude : '.$this->all_flights[$id]['longitude'].' - waypoints : '.$this->all_flights[$id]['waypoints'].' - Altitude : '.$this->all_flights[$id]['altitude'].' - Heading : '.$this->all_flights[$id]['heading'].' - Speed : '.$this->all_flights[$id]['speed'].' - Departure Airport Time : '.$this->all_flights[$id]['departure_airport_time'].' - Arrival Airport time : '.$this->all_flights[$id]['arrival_airport_time'].' - Pilot : '.$this->all_flights[$id]['pilot_name']."\n"; |
|
| 912 | + if (isset($this->all_flights[$id]['source_name'])) { |
|
| 913 | + echo 'DATA : hex : '.$this->all_flights[$id]['hex'].' - ident : '.$this->all_flights[$id]['ident'].' - ICAO : '.$this->all_flights[$id]['aircraft_icao'].' - Departure Airport : '.$this->all_flights[$id]['departure_airport'].' - Arrival Airport : '.$this->all_flights[$id]['arrival_airport'].' - Latitude : '.$this->all_flights[$id]['latitude'].' - Longitude : '.$this->all_flights[$id]['longitude'].' - waypoints : '.$this->all_flights[$id]['waypoints'].' - Altitude : '.$this->all_flights[$id]['altitude'].' - Heading : '.$this->all_flights[$id]['heading'].' - Speed : '.$this->all_flights[$id]['speed'].' - Departure Airport Time : '.$this->all_flights[$id]['departure_airport_time'].' - Arrival Airport time : '.$this->all_flights[$id]['arrival_airport_time'].' - Pilot : '.$this->all_flights[$id]['pilot_name'].' - Source name : '.$this->all_flights[$id]['source_name']."\n"; |
|
| 914 | + } else { |
|
| 915 | + echo 'DATA : hex : '.$this->all_flights[$id]['hex'].' - ident : '.$this->all_flights[$id]['ident'].' - ICAO : '.$this->all_flights[$id]['aircraft_icao'].' - Departure Airport : '.$this->all_flights[$id]['departure_airport'].' - Arrival Airport : '.$this->all_flights[$id]['arrival_airport'].' - Latitude : '.$this->all_flights[$id]['latitude'].' - Longitude : '.$this->all_flights[$id]['longitude'].' - waypoints : '.$this->all_flights[$id]['waypoints'].' - Altitude : '.$this->all_flights[$id]['altitude'].' - Heading : '.$this->all_flights[$id]['heading'].' - Speed : '.$this->all_flights[$id]['speed'].' - Departure Airport Time : '.$this->all_flights[$id]['departure_airport_time'].' - Arrival Airport time : '.$this->all_flights[$id]['arrival_airport_time'].' - Pilot : '.$this->all_flights[$id]['pilot_name']."\n"; |
|
| 916 | + } |
|
| 737 | 917 | } else { |
| 738 | - if (isset($this->all_flights[$id]['source_name'])) echo 'DATA : hex : '.$this->all_flights[$id]['hex'].' - ident : '.$this->all_flights[$id]['ident'].' - ICAO : '.$this->all_flights[$id]['aircraft_icao'].' - Departure Airport : '.$this->all_flights[$id]['departure_airport'].' - Arrival Airport : '.$this->all_flights[$id]['arrival_airport'].' - Latitude : '.$this->all_flights[$id]['latitude'].' - Longitude : '.$this->all_flights[$id]['longitude'].' - waypoints : '.$this->all_flights[$id]['waypoints'].' - Altitude : '.$this->all_flights[$id]['altitude'].' - Heading : '.$this->all_flights[$id]['heading'].' - Speed : '.$this->all_flights[$id]['speed'].' - Departure Airport Time : '.$this->all_flights[$id]['departure_airport_time'].' - Arrival Airport time : '.$this->all_flights[$id]['arrival_airport_time'].' - Source Name : '.$this->all_flights[$id]['source_name']."\n"; |
|
| 739 | - else echo 'DATA : hex : '.$this->all_flights[$id]['hex'].' - ident : '.$this->all_flights[$id]['ident'].' - ICAO : '.$this->all_flights[$id]['aircraft_icao'].' - Departure Airport : '.$this->all_flights[$id]['departure_airport'].' - Arrival Airport : '.$this->all_flights[$id]['arrival_airport'].' - Latitude : '.$this->all_flights[$id]['latitude'].' - Longitude : '.$this->all_flights[$id]['longitude'].' - waypoints : '.$this->all_flights[$id]['waypoints'].' - Altitude : '.$this->all_flights[$id]['altitude'].' - Heading : '.$this->all_flights[$id]['heading'].' - Speed : '.$this->all_flights[$id]['speed'].' - Departure Airport Time : '.$this->all_flights[$id]['departure_airport_time'].' - Arrival Airport time : '.$this->all_flights[$id]['arrival_airport_time']."\n"; |
|
| 918 | + if (isset($this->all_flights[$id]['source_name'])) { |
|
| 919 | + echo 'DATA : hex : '.$this->all_flights[$id]['hex'].' - ident : '.$this->all_flights[$id]['ident'].' - ICAO : '.$this->all_flights[$id]['aircraft_icao'].' - Departure Airport : '.$this->all_flights[$id]['departure_airport'].' - Arrival Airport : '.$this->all_flights[$id]['arrival_airport'].' - Latitude : '.$this->all_flights[$id]['latitude'].' - Longitude : '.$this->all_flights[$id]['longitude'].' - waypoints : '.$this->all_flights[$id]['waypoints'].' - Altitude : '.$this->all_flights[$id]['altitude'].' - Heading : '.$this->all_flights[$id]['heading'].' - Speed : '.$this->all_flights[$id]['speed'].' - Departure Airport Time : '.$this->all_flights[$id]['departure_airport_time'].' - Arrival Airport time : '.$this->all_flights[$id]['arrival_airport_time'].' - Source Name : '.$this->all_flights[$id]['source_name']."\n"; |
|
| 920 | + } else { |
|
| 921 | + echo 'DATA : hex : '.$this->all_flights[$id]['hex'].' - ident : '.$this->all_flights[$id]['ident'].' - ICAO : '.$this->all_flights[$id]['aircraft_icao'].' - Departure Airport : '.$this->all_flights[$id]['departure_airport'].' - Arrival Airport : '.$this->all_flights[$id]['arrival_airport'].' - Latitude : '.$this->all_flights[$id]['latitude'].' - Longitude : '.$this->all_flights[$id]['longitude'].' - waypoints : '.$this->all_flights[$id]['waypoints'].' - Altitude : '.$this->all_flights[$id]['altitude'].' - Heading : '.$this->all_flights[$id]['heading'].' - Speed : '.$this->all_flights[$id]['speed'].' - Departure Airport Time : '.$this->all_flights[$id]['departure_airport_time'].' - Arrival Airport time : '.$this->all_flights[$id]['arrival_airport_time']."\n"; |
|
| 922 | + } |
|
| 740 | 923 | } |
| 741 | 924 | } |
| 742 | 925 | $ignoreImport = false; |
@@ -782,19 +965,25 @@ discard block |
||
| 782 | 965 | |
| 783 | 966 | if (!$ignoreImport) { |
| 784 | 967 | 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'])) { |
| 785 | - if ($globalDebug) echo "\o/ Add ".$this->all_flights[$id]['ident']." from ".$this->all_flights[$id]['format_source']." in Live DB : "; |
|
| 968 | + if ($globalDebug) { |
|
| 969 | + echo "\o/ Add ".$this->all_flights[$id]['ident']." from ".$this->all_flights[$id]['format_source']." in Live DB : "; |
|
| 970 | + } |
|
| 786 | 971 | $timeelapsed = microtime(true); |
| 787 | 972 | $SpotterLive = new SpotterLive($this->db); |
| 788 | 973 | $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']); |
| 789 | 974 | $SpotterLive->db = null; |
| 790 | - if ($globalDebugTimeElapsed) echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
| 975 | + if ($globalDebugTimeElapsed) { |
|
| 976 | + echo 'Time elapsed for update addlivespotterdata : '.round(microtime(true)-$timeelapsed,2).'s'."\n"; |
|
| 977 | + } |
|
| 791 | 978 | |
| 792 | 979 | // Put statistics in $this->stats variable |
| 793 | 980 | //if ($line['format_source'] != 'aprs') { |
| 794 | 981 | //if (isset($line['format_source']) && ($line['format_source'] === 'sbs' || $line['format_source'] === 'tsv' || $line['format_source'] === 'raw' || $line['format_source'] === 'deltadbtxt')) { |
| 795 | 982 | if (isset($line['sourcestats']) && $line['sourcestats'] == TRUE && $line['format_source'] != 'aprs' && $this->all_flights[$id]['latitude'] != '' && $this->all_flights[$id]['longitude'] != '') { |
| 796 | 983 | $source = $this->all_flights[$id]['source_name']; |
| 797 | - if ($source == '') $source = $this->all_flights[$id]['format_source']; |
|
| 984 | + if ($source == '') { |
|
| 985 | + $source = $this->all_flights[$id]['format_source']; |
|
| 986 | + } |
|
| 798 | 987 | if (!isset($this->source_location[$source])) { |
| 799 | 988 | $Location = new Source(); |
| 800 | 989 | $coord = $Location->getLocationInfobySourceName($source); |
@@ -815,7 +1004,9 @@ discard block |
||
| 815 | 1004 | $stats_heading = round($stats_heading/22.5); |
| 816 | 1005 | $stats_distance = $Common->distance($latitude,$longitude,$this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude']); |
| 817 | 1006 | $current_date = date('Y-m-d'); |
| 818 | - if ($stats_heading == 16) $stats_heading = 0; |
|
| 1007 | + if ($stats_heading == 16) { |
|
| 1008 | + $stats_heading = 0; |
|
| 1009 | + } |
|
| 819 | 1010 | if (!isset($this->stats[$current_date][$source]['polar'][1])) { |
| 820 | 1011 | for ($i=0;$i<=15;$i++) { |
| 821 | 1012 | $this->stats[$current_date][$source]['polar'][$i] = 0; |
@@ -833,7 +1024,9 @@ discard block |
||
| 833 | 1024 | if (isset($this->stats[$current_date][$source]['hist'][0])) { |
| 834 | 1025 | end($this->stats[$current_date][$source]['hist']); |
| 835 | 1026 | $mini = key($this->stats[$current_date][$source]['hist'])+10; |
| 836 | - } else $mini = 0; |
|
| 1027 | + } else { |
|
| 1028 | + $mini = 0; |
|
| 1029 | + } |
|
| 837 | 1030 | for ($i=$mini;$i<=$distance;$i+=10) { |
| 838 | 1031 | $this->stats[$current_date][$source]['hist'][$i] = 0; |
| 839 | 1032 | } |
@@ -844,20 +1037,30 @@ discard block |
||
| 844 | 1037 | } |
| 845 | 1038 | |
| 846 | 1039 | $this->all_flights[$id]['lastupdate'] = time(); |
| 847 | - if ($this->all_flights[$id]['putinarchive']) $send = true; |
|
| 1040 | + if ($this->all_flights[$id]['putinarchive']) { |
|
| 1041 | + $send = true; |
|
| 1042 | + } |
|
| 848 | 1043 | //if ($globalDebug) echo "Distance : ".Common->distance($this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude'])."\n"; |
| 849 | - if ($globalDebug) echo $result."\n"; |
|
| 850 | - } 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"; |
|
| 1044 | + if ($globalDebug) { |
|
| 1045 | + echo $result."\n"; |
|
| 1046 | + } |
|
| 1047 | + } elseif (isset($this->all_flights[$id]['latitude']) && isset($globalDistanceIgnore['latitude']) && $globalDebug) { |
|
| 1048 | + echo "!! Too far -> Distance : ".$Common->distance($this->all_flights[$id]['latitude'],$this->all_flights[$id]['longitude'],$globalDistanceIgnore['latitude'],$globalDistanceIgnore['longitude'])."\n"; |
|
| 1049 | + } |
|
| 851 | 1050 | //$this->del(); |
| 852 | 1051 | |
| 853 | 1052 | |
| 854 | 1053 | if ($this->last_delete_hourly == 0 || time() - $this->last_delete_hourly > 900) { |
| 855 | - if ($globalDebug) echo "---- Deleting Live Spotter data Not updated since 2 hour..."; |
|
| 1054 | + if ($globalDebug) { |
|
| 1055 | + echo "---- Deleting Live Spotter data Not updated since 2 hour..."; |
|
| 1056 | + } |
|
| 856 | 1057 | $SpotterLive = new SpotterLive($this->db); |
| 857 | 1058 | $SpotterLive->deleteLiveSpotterDataNotUpdated(); |
| 858 | 1059 | $SpotterLive->db = null; |
| 859 | 1060 | //SpotterLive->deleteLiveSpotterData(); |
| 860 | - if ($globalDebug) echo " Done\n"; |
|
| 1061 | + if ($globalDebug) { |
|
| 1062 | + echo " Done\n"; |
|
| 1063 | + } |
|
| 861 | 1064 | $this->last_delete_hourly = time(); |
| 862 | 1065 | } |
| 863 | 1066 | |
@@ -865,7 +1068,9 @@ discard block |
||
| 865 | 1068 | //$ignoreImport = false; |
| 866 | 1069 | } |
| 867 | 1070 | //if (function_exists('pcntl_fork') && $globalFork) pcntl_signal(SIGCHLD, SIG_IGN); |
| 868 | - if ($send) return $this->all_flights[$id]; |
|
| 1071 | + if ($send) { |
|
| 1072 | + return $this->all_flights[$id]; |
|
| 1073 | + } |
|
| 869 | 1074 | } |
| 870 | 1075 | } |
| 871 | 1076 | } |
@@ -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(); |
@@ -28,16 +28,25 @@ discard block |
||
| 28 | 28 | } elseif (is_numeric(substr(substr($ident, 0, 4), -1, 1))) { |
| 29 | 29 | //$airline_icao = substr($ident, 0, 3); |
| 30 | 30 | return $ident; |
| 31 | - } else return $ident; |
|
| 32 | - } else return $ident; |
|
| 31 | + } else { |
|
| 32 | + return $ident; |
|
| 33 | + } |
|
| 34 | + } else { |
|
| 35 | + return $ident; |
|
| 36 | + } |
|
| 33 | 37 | 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'); |
|
| 38 | + if (filter_var(substr($ident,2),FILTER_VALIDATE_INT,array("flags"=>FILTER_FLAG_ALLOW_OCTAL))) { |
|
| 39 | + $icao = $ident; |
|
| 40 | + } else { |
|
| 41 | + $icao = 'AFR'.ltrim(substr($ident,2),'0'); |
|
| 42 | + } |
|
| 36 | 43 | } else { |
| 37 | 44 | $identicao = $Spotter->getAllAirlineInfo($airline_icao); |
| 38 | 45 | if (isset($identicao[0])) { |
| 39 | 46 | $icao = $identicao[0]['icao'].ltrim(substr($ident,2),'0'); |
| 40 | - } else $icao = $ident; |
|
| 47 | + } else { |
|
| 48 | + $icao = $ident; |
|
| 49 | + } |
|
| 41 | 50 | } |
| 42 | 51 | return $icao; |
| 43 | 52 | } |
@@ -55,7 +64,9 @@ discard block |
||
| 55 | 64 | $row = $sth->fetch(PDO::FETCH_ASSOC); |
| 56 | 65 | if (count($row) > 0) { |
| 57 | 66 | return $row['operator_correct']; |
| 58 | - } else return $ident; |
|
| 67 | + } else { |
|
| 68 | + return $ident; |
|
| 69 | + } |
|
| 59 | 70 | } |
| 60 | 71 | |
| 61 | 72 | public function addOperator($ident,$correct_ident,$source) { |
@@ -84,7 +95,9 @@ discard block |
||
| 84 | 95 | global $globalTranslationSources, $globalTranslationFetch; |
| 85 | 96 | //if (!isset($globalTranslationSources)) $globalTranslationSources = array('planefinder'); |
| 86 | 97 | $globalTranslationSources = array(); |
| 87 | - if (!isset($globalTranslationFetch)) $globalTranslationFetch = TRUE; |
|
| 98 | + if (!isset($globalTranslationFetch)) { |
|
| 99 | + $globalTranslationFetch = TRUE; |
|
| 100 | + } |
|
| 88 | 101 | //echo "Check Translation for ".$ident."..."; |
| 89 | 102 | $correct = $this->getOperator($ident); |
| 90 | 103 | if ($correct != '' && $correct != $ident) { |
@@ -7,91 +7,91 @@ discard block |
||
| 7 | 7 | |
| 8 | 8 | |
| 9 | 9 | class Translation { |
| 10 | - public $db; |
|
| 11 | - public function __construct($dbc = null) { |
|
| 12 | - $Connection = new Connection($dbc); |
|
| 13 | - $this->db = $Connection->db(); |
|
| 14 | - } |
|
| 10 | + public $db; |
|
| 11 | + public function __construct($dbc = null) { |
|
| 12 | + $Connection = new Connection($dbc); |
|
| 13 | + $this->db = $Connection->db(); |
|
| 14 | + } |
|
| 15 | 15 | |
| 16 | - /** |
|
| 17 | - * Change IATA to ICAO value for ident |
|
| 18 | - * |
|
| 19 | - * @param String $ident ident |
|
| 20 | - * @return String the icao |
|
| 21 | - */ |
|
| 22 | - public function ident2icao($ident) { |
|
| 16 | + /** |
|
| 17 | + * Change IATA to ICAO value for ident |
|
| 18 | + * |
|
| 19 | + * @param String $ident ident |
|
| 20 | + * @return String the icao |
|
| 21 | + */ |
|
| 22 | + public function ident2icao($ident) { |
|
| 23 | 23 | $Spotter = new Spotter(); |
| 24 | 24 | if (!is_numeric(substr($ident, 0, 3))) |
| 25 | - { |
|
| 26 | - if (is_numeric(substr(substr($ident, 0, 3), -1, 1))) { |
|
| 27 | - $airline_icao = substr($ident, 0, 2); |
|
| 28 | - } elseif (is_numeric(substr(substr($ident, 0, 4), -1, 1))) { |
|
| 29 | - //$airline_icao = substr($ident, 0, 3); |
|
| 30 | - return $ident; |
|
| 31 | - } else return $ident; |
|
| 32 | - } else return $ident; |
|
| 33 | - if ($airline_icao == 'AF') { |
|
| 34 | - if (filter_var(substr($ident,2),FILTER_VALIDATE_INT,array("flags"=>FILTER_FLAG_ALLOW_OCTAL))) $icao = $ident; |
|
| 35 | - else $icao = 'AFR'.ltrim(substr($ident,2),'0'); |
|
| 36 | - } else { |
|
| 37 | - $identicao = $Spotter->getAllAirlineInfo($airline_icao); |
|
| 38 | - if (isset($identicao[0])) { |
|
| 39 | - $icao = $identicao[0]['icao'].ltrim(substr($ident,2),'0'); |
|
| 40 | - } else $icao = $ident; |
|
| 41 | - } |
|
| 42 | - return $icao; |
|
| 43 | - } |
|
| 25 | + { |
|
| 26 | + if (is_numeric(substr(substr($ident, 0, 3), -1, 1))) { |
|
| 27 | + $airline_icao = substr($ident, 0, 2); |
|
| 28 | + } elseif (is_numeric(substr(substr($ident, 0, 4), -1, 1))) { |
|
| 29 | + //$airline_icao = substr($ident, 0, 3); |
|
| 30 | + return $ident; |
|
| 31 | + } else return $ident; |
|
| 32 | + } else return $ident; |
|
| 33 | + if ($airline_icao == 'AF') { |
|
| 34 | + if (filter_var(substr($ident,2),FILTER_VALIDATE_INT,array("flags"=>FILTER_FLAG_ALLOW_OCTAL))) $icao = $ident; |
|
| 35 | + else $icao = 'AFR'.ltrim(substr($ident,2),'0'); |
|
| 36 | + } else { |
|
| 37 | + $identicao = $Spotter->getAllAirlineInfo($airline_icao); |
|
| 38 | + if (isset($identicao[0])) { |
|
| 39 | + $icao = $identicao[0]['icao'].ltrim(substr($ident,2),'0'); |
|
| 40 | + } else $icao = $ident; |
|
| 41 | + } |
|
| 42 | + return $icao; |
|
| 43 | + } |
|
| 44 | 44 | |
| 45 | 45 | |
| 46 | - public function getOperator($ident) { |
|
| 47 | - $query = "SELECT * FROM translation WHERE Operator = :ident LIMIT 1"; |
|
| 48 | - $query_values = array(':ident' => $ident); |
|
| 49 | - try { |
|
| 50 | - $sth = $this->db->prepare($query); |
|
| 51 | - $sth->execute($query_values); |
|
| 52 | - } catch(PDOException $e) { |
|
| 53 | - return "error : ".$e->getMessage(); |
|
| 54 | - } |
|
| 55 | - $row = $sth->fetch(PDO::FETCH_ASSOC); |
|
| 56 | - $sth->closeCursor(); |
|
| 57 | - if (count($row) > 0) { |
|
| 58 | - return $row['operator_correct']; |
|
| 59 | - } else return $ident; |
|
| 60 | - } |
|
| 46 | + public function getOperator($ident) { |
|
| 47 | + $query = "SELECT * FROM translation WHERE Operator = :ident LIMIT 1"; |
|
| 48 | + $query_values = array(':ident' => $ident); |
|
| 49 | + try { |
|
| 50 | + $sth = $this->db->prepare($query); |
|
| 51 | + $sth->execute($query_values); |
|
| 52 | + } catch(PDOException $e) { |
|
| 53 | + return "error : ".$e->getMessage(); |
|
| 54 | + } |
|
| 55 | + $row = $sth->fetch(PDO::FETCH_ASSOC); |
|
| 56 | + $sth->closeCursor(); |
|
| 57 | + if (count($row) > 0) { |
|
| 58 | + return $row['operator_correct']; |
|
| 59 | + } else return $ident; |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | - public function addOperator($ident,$correct_ident,$source) { |
|
| 63 | - $query = "INSERT INTO translation (Operator,Operator_correct,Source) VALUES (:ident,:correct_ident,:source)"; |
|
| 64 | - $query_values = array(':ident' => $ident,':correct_ident' => $correct_ident, ':source' => $source); |
|
| 65 | - try { |
|
| 66 | - $sth = $this->db->prepare($query); |
|
| 67 | - $sth->execute($query_values); |
|
| 68 | - } catch(PDOException $e) { |
|
| 69 | - return "error : ".$e->getMessage(); |
|
| 70 | - } |
|
| 71 | - } |
|
| 62 | + public function addOperator($ident,$correct_ident,$source) { |
|
| 63 | + $query = "INSERT INTO translation (Operator,Operator_correct,Source) VALUES (:ident,:correct_ident,:source)"; |
|
| 64 | + $query_values = array(':ident' => $ident,':correct_ident' => $correct_ident, ':source' => $source); |
|
| 65 | + try { |
|
| 66 | + $sth = $this->db->prepare($query); |
|
| 67 | + $sth->execute($query_values); |
|
| 68 | + } catch(PDOException $e) { |
|
| 69 | + return "error : ".$e->getMessage(); |
|
| 70 | + } |
|
| 71 | + } |
|
| 72 | 72 | |
| 73 | - public function updateOperator($ident,$correct_ident,$source) { |
|
| 74 | - $query = "UPDATE translation SET Operator_correct = :correct_ident,Source = :source WHERE Operator = :ident"; |
|
| 75 | - $query_values = array(':ident' => $ident,':correct_ident' => $correct_ident, ':source' => $source); |
|
| 76 | - try { |
|
| 77 | - $sth = $this->db->prepare($query); |
|
| 78 | - $sth->execute($query_values); |
|
| 79 | - } catch(PDOException $e) { |
|
| 80 | - return "error : ".$e->getMessage(); |
|
| 81 | - } |
|
| 82 | - } |
|
| 73 | + public function updateOperator($ident,$correct_ident,$source) { |
|
| 74 | + $query = "UPDATE translation SET Operator_correct = :correct_ident,Source = :source WHERE Operator = :ident"; |
|
| 75 | + $query_values = array(':ident' => $ident,':correct_ident' => $correct_ident, ':source' => $source); |
|
| 76 | + try { |
|
| 77 | + $sth = $this->db->prepare($query); |
|
| 78 | + $sth->execute($query_values); |
|
| 79 | + } catch(PDOException $e) { |
|
| 80 | + return "error : ".$e->getMessage(); |
|
| 81 | + } |
|
| 82 | + } |
|
| 83 | 83 | |
| 84 | - public function checkTranslation($ident,$web = false) { |
|
| 85 | - global $globalTranslationSources, $globalTranslationFetch; |
|
| 86 | - //if (!isset($globalTranslationSources)) $globalTranslationSources = array('planefinder'); |
|
| 87 | - $globalTranslationSources = array(); |
|
| 88 | - if (!isset($globalTranslationFetch)) $globalTranslationFetch = TRUE; |
|
| 89 | - //echo "Check Translation for ".$ident."..."; |
|
| 90 | - $correct = $this->getOperator($ident); |
|
| 91 | - if ($correct != '' && $correct != $ident) { |
|
| 92 | - //echo "Found in DB !\n"; |
|
| 93 | - return $correct; |
|
| 94 | - } /* |
|
| 84 | + public function checkTranslation($ident,$web = false) { |
|
| 85 | + global $globalTranslationSources, $globalTranslationFetch; |
|
| 86 | + //if (!isset($globalTranslationSources)) $globalTranslationSources = array('planefinder'); |
|
| 87 | + $globalTranslationSources = array(); |
|
| 88 | + if (!isset($globalTranslationFetch)) $globalTranslationFetch = TRUE; |
|
| 89 | + //echo "Check Translation for ".$ident."..."; |
|
| 90 | + $correct = $this->getOperator($ident); |
|
| 91 | + if ($correct != '' && $correct != $ident) { |
|
| 92 | + //echo "Found in DB !\n"; |
|
| 93 | + return $correct; |
|
| 94 | + } /* |
|
| 95 | 95 | elseif ($web && $globalTranslationFetch) { |
| 96 | 96 | if (! is_numeric(substr($ident,-4))) { |
| 97 | 97 | if (count($globalTranslationSources) > 0) { |
@@ -108,8 +108,8 @@ discard block |
||
| 108 | 108 | } |
| 109 | 109 | } |
| 110 | 110 | */ |
| 111 | - return $this->ident2icao($ident); |
|
| 112 | - } |
|
| 111 | + return $this->ident2icao($ident); |
|
| 112 | + } |
|
| 113 | 113 | |
| 114 | 114 | /* |
| 115 | 115 | function fromPlanefinder($icao) { |
@@ -118,6 +118,9 @@ discard block |
||
| 118 | 118 | ); |
| 119 | 119 | } |
| 120 | 120 | |
| 121 | + /** |
|
| 122 | + * @param boolean $force |
|
| 123 | + */ |
|
| 121 | 124 | static function geosInstalled($force = NULL) {
|
| 122 | 125 | static $geos_installed = NULL; |
| 123 | 126 | if ($force !== NULL) $geos_installed = $force; |
@@ -222,6 +225,10 @@ discard block |
||
| 222 | 225 | |
| 223 | 226 | // Detect a format given a value. This function is meant to be SPEEDY. |
| 224 | 227 | // It could make a mistake in XML detection if you are mixing or using namespaces in weird ways (ie, KML inside an RSS feed) |
| 228 | + |
|
| 229 | + /** |
|
| 230 | + * @return string |
|
| 231 | + */ |
|
| 225 | 232 | static function detectFormat(&$input) {
|
| 226 | 233 | $mem = fopen('php://memory', 'r+');
|
| 227 | 234 | fwrite($mem, $input, 11); // Write 11 bytes - we can detect the vast majority of formats in the first 11 bytes |
@@ -35,110 +35,110 @@ discard block |
||
| 35 | 35 | {
|
| 36 | 36 | |
| 37 | 37 | static function version() {
|
| 38 | - return '1.1'; |
|
| 38 | + return '1.1'; |
|
| 39 | 39 | } |
| 40 | 40 | |
| 41 | 41 | // geoPHP::load($data, $type, $other_args); |
| 42 | 42 | // if $data is an array, all passed in values will be combined into a single geometry |
| 43 | 43 | static function load() {
|
| 44 | - $args = func_get_args(); |
|
| 44 | + $args = func_get_args(); |
|
| 45 | 45 | |
| 46 | - $data = array_shift($args); |
|
| 47 | - $type = array_shift($args); |
|
| 46 | + $data = array_shift($args); |
|
| 47 | + $type = array_shift($args); |
|
| 48 | 48 | |
| 49 | - $type_map = geoPHP::getAdapterMap(); |
|
| 49 | + $type_map = geoPHP::getAdapterMap(); |
|
| 50 | 50 | |
| 51 | - // Auto-detect type if needed |
|
| 52 | - if (!$type) {
|
|
| 53 | - // If the user is trying to load a Geometry from a Geometry... Just pass it back |
|
| 54 | - if (is_object($data)) {
|
|
| 55 | - if ($data instanceOf Geometry) return $data; |
|
| 56 | - } |
|
| 51 | + // Auto-detect type if needed |
|
| 52 | + if (!$type) {
|
|
| 53 | + // If the user is trying to load a Geometry from a Geometry... Just pass it back |
|
| 54 | + if (is_object($data)) {
|
|
| 55 | + if ($data instanceOf Geometry) return $data; |
|
| 56 | + } |
|
| 57 | 57 | |
| 58 | - $detected = geoPHP::detectFormat($data); |
|
| 59 | - if (!$detected) {
|
|
| 60 | - return FALSE; |
|
| 61 | - } |
|
| 58 | + $detected = geoPHP::detectFormat($data); |
|
| 59 | + if (!$detected) {
|
|
| 60 | + return FALSE; |
|
| 61 | + } |
|
| 62 | 62 | |
| 63 | - $format = explode(':', $detected);
|
|
| 64 | - $type = array_shift($format); |
|
| 65 | - $args = $format; |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - $processor_type = $type_map[$type]; |
|
| 69 | - |
|
| 70 | - if (!$processor_type) {
|
|
| 71 | - throw new exception('geoPHP could not find an adapter of type '.htmlentities($type));
|
|
| 72 | - exit; |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - $processor = new $processor_type(); |
|
| 76 | - |
|
| 77 | - // Data is not an array, just pass it normally |
|
| 78 | - if (!is_array($data)) {
|
|
| 79 | - $result = call_user_func_array(array($processor, "read"), array_merge(array($data), $args)); |
|
| 80 | - } |
|
| 81 | - // Data is an array, combine all passed in items into a single geomtetry |
|
| 82 | - else {
|
|
| 83 | - $geoms = array(); |
|
| 84 | - foreach ($data as $item) {
|
|
| 85 | - $geoms[] = call_user_func_array(array($processor, "read"), array_merge(array($item), $args)); |
|
| 86 | - } |
|
| 87 | - $result = geoPHP::geometryReduce($geoms); |
|
| 88 | - } |
|
| 89 | - |
|
| 90 | - return $result; |
|
| 63 | + $format = explode(':', $detected);
|
|
| 64 | + $type = array_shift($format); |
|
| 65 | + $args = $format; |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + $processor_type = $type_map[$type]; |
|
| 69 | + |
|
| 70 | + if (!$processor_type) {
|
|
| 71 | + throw new exception('geoPHP could not find an adapter of type '.htmlentities($type));
|
|
| 72 | + exit; |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + $processor = new $processor_type(); |
|
| 76 | + |
|
| 77 | + // Data is not an array, just pass it normally |
|
| 78 | + if (!is_array($data)) {
|
|
| 79 | + $result = call_user_func_array(array($processor, "read"), array_merge(array($data), $args)); |
|
| 80 | + } |
|
| 81 | + // Data is an array, combine all passed in items into a single geomtetry |
|
| 82 | + else {
|
|
| 83 | + $geoms = array(); |
|
| 84 | + foreach ($data as $item) {
|
|
| 85 | + $geoms[] = call_user_func_array(array($processor, "read"), array_merge(array($item), $args)); |
|
| 86 | + } |
|
| 87 | + $result = geoPHP::geometryReduce($geoms); |
|
| 88 | + } |
|
| 89 | + |
|
| 90 | + return $result; |
|
| 91 | 91 | } |
| 92 | 92 | |
| 93 | 93 | static function getAdapterMap() {
|
| 94 | - return array ( |
|
| 95 | - 'wkt' => 'WKT', |
|
| 96 | - 'ewkt' => 'EWKT', |
|
| 97 | - 'wkb' => 'WKB', |
|
| 98 | - 'ewkb' => 'EWKB', |
|
| 99 | - 'json' => 'GeoJSON', |
|
| 100 | - 'geojson' => 'GeoJSON', |
|
| 101 | - 'kml' => 'KML', |
|
| 102 | - 'gpx' => 'GPX', |
|
| 103 | - 'georss' => 'GeoRSS', |
|
| 104 | - 'google_geocode' => 'GoogleGeocode', |
|
| 105 | - 'geohash' => 'GeoHash', |
|
| 106 | - ); |
|
| 94 | + return array ( |
|
| 95 | + 'wkt' => 'WKT', |
|
| 96 | + 'ewkt' => 'EWKT', |
|
| 97 | + 'wkb' => 'WKB', |
|
| 98 | + 'ewkb' => 'EWKB', |
|
| 99 | + 'json' => 'GeoJSON', |
|
| 100 | + 'geojson' => 'GeoJSON', |
|
| 101 | + 'kml' => 'KML', |
|
| 102 | + 'gpx' => 'GPX', |
|
| 103 | + 'georss' => 'GeoRSS', |
|
| 104 | + 'google_geocode' => 'GoogleGeocode', |
|
| 105 | + 'geohash' => 'GeoHash', |
|
| 106 | + ); |
|
| 107 | 107 | } |
| 108 | 108 | |
| 109 | 109 | static function geometryList() {
|
| 110 | - return array( |
|
| 111 | - 'point' => 'Point', |
|
| 112 | - 'linestring' => 'LineString', |
|
| 113 | - 'polygon' => 'Polygon', |
|
| 114 | - 'multipoint' => 'MultiPoint', |
|
| 115 | - 'multilinestring' => 'MultiLineString', |
|
| 116 | - 'multipolygon' => 'MultiPolygon', |
|
| 117 | - 'geometrycollection' => 'GeometryCollection', |
|
| 118 | - ); |
|
| 110 | + return array( |
|
| 111 | + 'point' => 'Point', |
|
| 112 | + 'linestring' => 'LineString', |
|
| 113 | + 'polygon' => 'Polygon', |
|
| 114 | + 'multipoint' => 'MultiPoint', |
|
| 115 | + 'multilinestring' => 'MultiLineString', |
|
| 116 | + 'multipolygon' => 'MultiPolygon', |
|
| 117 | + 'geometrycollection' => 'GeometryCollection', |
|
| 118 | + ); |
|
| 119 | 119 | } |
| 120 | 120 | |
| 121 | 121 | static function geosInstalled($force = NULL) {
|
| 122 | - static $geos_installed = NULL; |
|
| 123 | - if ($force !== NULL) $geos_installed = $force; |
|
| 124 | - if ($geos_installed !== NULL) {
|
|
| 125 | - return $geos_installed; |
|
| 126 | - } |
|
| 127 | - $geos_installed = class_exists('GEOSGeometry');
|
|
| 128 | - return $geos_installed; |
|
| 122 | + static $geos_installed = NULL; |
|
| 123 | + if ($force !== NULL) $geos_installed = $force; |
|
| 124 | + if ($geos_installed !== NULL) {
|
|
| 125 | + return $geos_installed; |
|
| 126 | + } |
|
| 127 | + $geos_installed = class_exists('GEOSGeometry');
|
|
| 128 | + return $geos_installed; |
|
| 129 | 129 | } |
| 130 | 130 | |
| 131 | 131 | static function geosToGeometry($geos) {
|
| 132 | - if (!geoPHP::geosInstalled()) {
|
|
| 133 | - return NULL; |
|
| 134 | - } |
|
| 135 | - $wkb_writer = new GEOSWKBWriter(); |
|
| 136 | - $wkb = $wkb_writer->writeHEX($geos); |
|
| 137 | - $geometry = geoPHP::load($wkb, 'wkb', TRUE); |
|
| 138 | - if ($geometry) {
|
|
| 139 | - $geometry->setGeos($geos); |
|
| 140 | - return $geometry; |
|
| 141 | - } |
|
| 132 | + if (!geoPHP::geosInstalled()) {
|
|
| 133 | + return NULL; |
|
| 134 | + } |
|
| 135 | + $wkb_writer = new GEOSWKBWriter(); |
|
| 136 | + $wkb = $wkb_writer->writeHEX($geos); |
|
| 137 | + $geometry = geoPHP::load($wkb, 'wkb', TRUE); |
|
| 138 | + if ($geometry) {
|
|
| 139 | + $geometry->setGeos($geos); |
|
| 140 | + return $geometry; |
|
| 141 | + } |
|
| 142 | 142 | } |
| 143 | 143 | |
| 144 | 144 | // Reduce a geometry, or an array of geometries, into their 'lowest' available common geometry. |
@@ -146,155 +146,155 @@ discard block |
||
| 146 | 146 | // A multi-point containing a single point will return a point. |
| 147 | 147 | // An array of geometries can be passed and they will be compiled into a single geometry |
| 148 | 148 | static function geometryReduce($geometry) {
|
| 149 | - // If it's an array of one, then just parse the one |
|
| 150 | - if (is_array($geometry)) {
|
|
| 151 | - if (empty($geometry)) return FALSE; |
|
| 152 | - if (count($geometry) == 1) return geoPHP::geometryReduce(array_shift($geometry)); |
|
| 153 | - } |
|
| 154 | - |
|
| 155 | - // If the geometry cannot even theoretically be reduced more, then pass it back |
|
| 156 | - if (gettype($geometry) == 'object') {
|
|
| 157 | - $passbacks = array('Point','LineString','Polygon');
|
|
| 158 | - if (in_array($geometry->geometryType(),$passbacks)) {
|
|
| 159 | - return $geometry; |
|
| 160 | - } |
|
| 161 | - } |
|
| 162 | - |
|
| 163 | - // If it is a mutlti-geometry, check to see if it just has one member |
|
| 164 | - // If it does, then pass the member, if not, then just pass back the geometry |
|
| 165 | - if (gettype($geometry) == 'object') {
|
|
| 166 | - $simple_collections = array('MultiPoint','MultiLineString','MultiPolygon');
|
|
| 167 | - if (in_array(get_class($geometry),$passbacks)) {
|
|
| 168 | - $components = $geometry->getComponents(); |
|
| 169 | - if (count($components) == 1) {
|
|
| 170 | - return $components[0]; |
|
| 171 | - } |
|
| 172 | - else {
|
|
| 173 | - return $geometry; |
|
| 174 | - } |
|
| 175 | - } |
|
| 176 | - } |
|
| 177 | - |
|
| 178 | - // So now we either have an array of geometries, a GeometryCollection, or an array of GeometryCollections |
|
| 179 | - if (!is_array($geometry)) {
|
|
| 180 | - $geometry = array($geometry); |
|
| 181 | - } |
|
| 182 | - |
|
| 183 | - $geometries = array(); |
|
| 184 | - $geom_types = array(); |
|
| 185 | - |
|
| 186 | - $collections = array('MultiPoint','MultiLineString','MultiPolygon','GeometryCollection');
|
|
| 187 | - |
|
| 188 | - foreach ($geometry as $item) {
|
|
| 189 | - if ($item) {
|
|
| 190 | - if (in_array(get_class($item), $collections)) {
|
|
| 191 | - foreach ($item->getComponents() as $component) {
|
|
| 192 | - $geometries[] = $component; |
|
| 193 | - $geom_types[] = $component->geometryType(); |
|
| 194 | - } |
|
| 195 | - } |
|
| 196 | - else {
|
|
| 197 | - $geometries[] = $item; |
|
| 198 | - $geom_types[] = $item->geometryType(); |
|
| 199 | - } |
|
| 200 | - } |
|
| 201 | - } |
|
| 202 | - |
|
| 203 | - $geom_types = array_unique($geom_types); |
|
| 149 | + // If it's an array of one, then just parse the one |
|
| 150 | + if (is_array($geometry)) {
|
|
| 151 | + if (empty($geometry)) return FALSE; |
|
| 152 | + if (count($geometry) == 1) return geoPHP::geometryReduce(array_shift($geometry)); |
|
| 153 | + } |
|
| 154 | + |
|
| 155 | + // If the geometry cannot even theoretically be reduced more, then pass it back |
|
| 156 | + if (gettype($geometry) == 'object') {
|
|
| 157 | + $passbacks = array('Point','LineString','Polygon');
|
|
| 158 | + if (in_array($geometry->geometryType(),$passbacks)) {
|
|
| 159 | + return $geometry; |
|
| 160 | + } |
|
| 161 | + } |
|
| 162 | + |
|
| 163 | + // If it is a mutlti-geometry, check to see if it just has one member |
|
| 164 | + // If it does, then pass the member, if not, then just pass back the geometry |
|
| 165 | + if (gettype($geometry) == 'object') {
|
|
| 166 | + $simple_collections = array('MultiPoint','MultiLineString','MultiPolygon');
|
|
| 167 | + if (in_array(get_class($geometry),$passbacks)) {
|
|
| 168 | + $components = $geometry->getComponents(); |
|
| 169 | + if (count($components) == 1) {
|
|
| 170 | + return $components[0]; |
|
| 171 | + } |
|
| 172 | + else {
|
|
| 173 | + return $geometry; |
|
| 174 | + } |
|
| 175 | + } |
|
| 176 | + } |
|
| 177 | + |
|
| 178 | + // So now we either have an array of geometries, a GeometryCollection, or an array of GeometryCollections |
|
| 179 | + if (!is_array($geometry)) {
|
|
| 180 | + $geometry = array($geometry); |
|
| 181 | + } |
|
| 182 | + |
|
| 183 | + $geometries = array(); |
|
| 184 | + $geom_types = array(); |
|
| 185 | + |
|
| 186 | + $collections = array('MultiPoint','MultiLineString','MultiPolygon','GeometryCollection');
|
|
| 187 | + |
|
| 188 | + foreach ($geometry as $item) {
|
|
| 189 | + if ($item) {
|
|
| 190 | + if (in_array(get_class($item), $collections)) {
|
|
| 191 | + foreach ($item->getComponents() as $component) {
|
|
| 192 | + $geometries[] = $component; |
|
| 193 | + $geom_types[] = $component->geometryType(); |
|
| 194 | + } |
|
| 195 | + } |
|
| 196 | + else {
|
|
| 197 | + $geometries[] = $item; |
|
| 198 | + $geom_types[] = $item->geometryType(); |
|
| 199 | + } |
|
| 200 | + } |
|
| 201 | + } |
|
| 202 | + |
|
| 203 | + $geom_types = array_unique($geom_types); |
|
| 204 | 204 | |
| 205 | - if (empty($geom_types)) {
|
|
| 206 | - return FALSE; |
|
| 207 | - } |
|
| 208 | - |
|
| 209 | - if (count($geom_types) == 1) {
|
|
| 210 | - if (count($geometries) == 1) {
|
|
| 211 | - return $geometries[0]; |
|
| 212 | - } |
|
| 213 | - else {
|
|
| 214 | - $class = 'Multi'.$geom_types[0]; |
|
| 215 | - return new $class($geometries); |
|
| 216 | - } |
|
| 217 | - } |
|
| 218 | - else {
|
|
| 219 | - return new GeometryCollection($geometries); |
|
| 220 | - } |
|
| 205 | + if (empty($geom_types)) {
|
|
| 206 | + return FALSE; |
|
| 207 | + } |
|
| 208 | + |
|
| 209 | + if (count($geom_types) == 1) {
|
|
| 210 | + if (count($geometries) == 1) {
|
|
| 211 | + return $geometries[0]; |
|
| 212 | + } |
|
| 213 | + else {
|
|
| 214 | + $class = 'Multi'.$geom_types[0]; |
|
| 215 | + return new $class($geometries); |
|
| 216 | + } |
|
| 217 | + } |
|
| 218 | + else {
|
|
| 219 | + return new GeometryCollection($geometries); |
|
| 220 | + } |
|
| 221 | 221 | } |
| 222 | 222 | |
| 223 | 223 | // Detect a format given a value. This function is meant to be SPEEDY. |
| 224 | 224 | // It could make a mistake in XML detection if you are mixing or using namespaces in weird ways (ie, KML inside an RSS feed) |
| 225 | 225 | static function detectFormat(&$input) {
|
| 226 | - $mem = fopen('php://memory', 'r+');
|
|
| 227 | - fwrite($mem, $input, 11); // Write 11 bytes - we can detect the vast majority of formats in the first 11 bytes |
|
| 228 | - fseek($mem, 0); |
|
| 229 | - |
|
| 230 | - $bytes = unpack("c*", fread($mem, 11));
|
|
| 231 | - |
|
| 232 | - // If bytes is empty, then we were passed empty input |
|
| 233 | - if (empty($bytes)) return FALSE; |
|
| 234 | - |
|
| 235 | - // First char is a tab, space or carriage-return. trim it and try again |
|
| 236 | - if ($bytes[1] == 9 || $bytes[1] == 10 || $bytes[1] == 32) {
|
|
| 237 | - return geoPHP::detectFormat(ltrim($input)); |
|
| 238 | - } |
|
| 239 | - |
|
| 240 | - // Detect WKB or EWKB -- first byte is 1 (little endian indicator) |
|
| 241 | - if ($bytes[1] == 1) {
|
|
| 242 | - // If SRID byte is TRUE (1), it's EWKB |
|
| 243 | - if ($bytes[5]) return 'ewkb'; |
|
| 244 | - else return 'wkb'; |
|
| 245 | - } |
|
| 246 | - |
|
| 247 | - // Detect HEX encoded WKB or EWKB (PostGIS format) -- first byte is 48, second byte is 49 (hex '01' => first-byte = 1) |
|
| 248 | - if ($bytes[1] == 48 && $bytes[2] == 49) {
|
|
| 249 | - // The shortest possible WKB string (LINESTRING EMPTY) is 18 hex-chars (9 encoded bytes) long |
|
| 250 | - // This differentiates it from a geohash, which is always shorter than 18 characters. |
|
| 251 | - if (strlen($input) >= 18) {
|
|
| 252 | - //@@TODO: Differentiate between EWKB and WKB -- check hex-char 10 or 11 (SRID bool indicator at encoded byte 5) |
|
| 253 | - return 'ewkb:1'; |
|
| 254 | - } |
|
| 255 | - } |
|
| 256 | - |
|
| 257 | - // Detect GeoJSON - first char starts with {
|
|
| 258 | - if ($bytes[1] == 123) {
|
|
| 259 | - return 'json'; |
|
| 260 | - } |
|
| 261 | - |
|
| 262 | - // Detect EWKT - first char is S |
|
| 263 | - if ($bytes[1] == 83) {
|
|
| 264 | - return 'ewkt'; |
|
| 265 | - } |
|
| 266 | - |
|
| 267 | - // Detect WKT - first char starts with P (80), L (76), M (77), or G (71) |
|
| 268 | - $wkt_chars = array(80, 76, 77, 71); |
|
| 269 | - if (in_array($bytes[1], $wkt_chars)) {
|
|
| 270 | - return 'wkt'; |
|
| 271 | - } |
|
| 272 | - |
|
| 273 | - // Detect XML -- first char is < |
|
| 274 | - if ($bytes[1] == 60) {
|
|
| 275 | - // grab the first 256 characters |
|
| 276 | - $string = substr($input, 0, 256); |
|
| 277 | - if (strpos($string, '<kml') !== FALSE) return 'kml'; |
|
| 278 | - if (strpos($string, '<coordinate') !== FALSE) return 'kml'; |
|
| 279 | - if (strpos($string, '<gpx') !== FALSE) return 'gpx'; |
|
| 280 | - if (strpos($string, '<georss') !== FALSE) return 'georss'; |
|
| 281 | - if (strpos($string, '<rss') !== FALSE) return 'georss'; |
|
| 282 | - if (strpos($string, '<feed') !== FALSE) return 'georss'; |
|
| 283 | - } |
|
| 284 | - |
|
| 285 | - // We need an 8 byte string for geohash and unpacked WKB / WKT |
|
| 286 | - fseek($mem, 0); |
|
| 287 | - $string = trim(fread($mem, 8)); |
|
| 288 | - |
|
| 289 | - // Detect geohash - geohash ONLY contains lowercase chars and numerics |
|
| 290 | - preg_match('/[a-z0-9]+/', $string, $matches);
|
|
| 291 | - if ($matches[0] == $string) {
|
|
| 292 | - return 'geohash'; |
|
| 293 | - } |
|
| 294 | - |
|
| 295 | - // What do you get when you cross an elephant with a rhino? |
|
| 296 | - // http://youtu.be/RCBn5J83Poc |
|
| 297 | - return FALSE; |
|
| 226 | + $mem = fopen('php://memory', 'r+');
|
|
| 227 | + fwrite($mem, $input, 11); // Write 11 bytes - we can detect the vast majority of formats in the first 11 bytes |
|
| 228 | + fseek($mem, 0); |
|
| 229 | + |
|
| 230 | + $bytes = unpack("c*", fread($mem, 11));
|
|
| 231 | + |
|
| 232 | + // If bytes is empty, then we were passed empty input |
|
| 233 | + if (empty($bytes)) return FALSE; |
|
| 234 | + |
|
| 235 | + // First char is a tab, space or carriage-return. trim it and try again |
|
| 236 | + if ($bytes[1] == 9 || $bytes[1] == 10 || $bytes[1] == 32) {
|
|
| 237 | + return geoPHP::detectFormat(ltrim($input)); |
|
| 238 | + } |
|
| 239 | + |
|
| 240 | + // Detect WKB or EWKB -- first byte is 1 (little endian indicator) |
|
| 241 | + if ($bytes[1] == 1) {
|
|
| 242 | + // If SRID byte is TRUE (1), it's EWKB |
|
| 243 | + if ($bytes[5]) return 'ewkb'; |
|
| 244 | + else return 'wkb'; |
|
| 245 | + } |
|
| 246 | + |
|
| 247 | + // Detect HEX encoded WKB or EWKB (PostGIS format) -- first byte is 48, second byte is 49 (hex '01' => first-byte = 1) |
|
| 248 | + if ($bytes[1] == 48 && $bytes[2] == 49) {
|
|
| 249 | + // The shortest possible WKB string (LINESTRING EMPTY) is 18 hex-chars (9 encoded bytes) long |
|
| 250 | + // This differentiates it from a geohash, which is always shorter than 18 characters. |
|
| 251 | + if (strlen($input) >= 18) {
|
|
| 252 | + //@@TODO: Differentiate between EWKB and WKB -- check hex-char 10 or 11 (SRID bool indicator at encoded byte 5) |
|
| 253 | + return 'ewkb:1'; |
|
| 254 | + } |
|
| 255 | + } |
|
| 256 | + |
|
| 257 | + // Detect GeoJSON - first char starts with {
|
|
| 258 | + if ($bytes[1] == 123) {
|
|
| 259 | + return 'json'; |
|
| 260 | + } |
|
| 261 | + |
|
| 262 | + // Detect EWKT - first char is S |
|
| 263 | + if ($bytes[1] == 83) {
|
|
| 264 | + return 'ewkt'; |
|
| 265 | + } |
|
| 266 | + |
|
| 267 | + // Detect WKT - first char starts with P (80), L (76), M (77), or G (71) |
|
| 268 | + $wkt_chars = array(80, 76, 77, 71); |
|
| 269 | + if (in_array($bytes[1], $wkt_chars)) {
|
|
| 270 | + return 'wkt'; |
|
| 271 | + } |
|
| 272 | + |
|
| 273 | + // Detect XML -- first char is < |
|
| 274 | + if ($bytes[1] == 60) {
|
|
| 275 | + // grab the first 256 characters |
|
| 276 | + $string = substr($input, 0, 256); |
|
| 277 | + if (strpos($string, '<kml') !== FALSE) return 'kml'; |
|
| 278 | + if (strpos($string, '<coordinate') !== FALSE) return 'kml'; |
|
| 279 | + if (strpos($string, '<gpx') !== FALSE) return 'gpx'; |
|
| 280 | + if (strpos($string, '<georss') !== FALSE) return 'georss'; |
|
| 281 | + if (strpos($string, '<rss') !== FALSE) return 'georss'; |
|
| 282 | + if (strpos($string, '<feed') !== FALSE) return 'georss'; |
|
| 283 | + } |
|
| 284 | + |
|
| 285 | + // We need an 8 byte string for geohash and unpacked WKB / WKT |
|
| 286 | + fseek($mem, 0); |
|
| 287 | + $string = trim(fread($mem, 8)); |
|
| 288 | + |
|
| 289 | + // Detect geohash - geohash ONLY contains lowercase chars and numerics |
|
| 290 | + preg_match('/[a-z0-9]+/', $string, $matches);
|
|
| 291 | + if ($matches[0] == $string) {
|
|
| 292 | + return 'geohash'; |
|
| 293 | + } |
|
| 294 | + |
|
| 295 | + // What do you get when you cross an elephant with a rhino? |
|
| 296 | + // http://youtu.be/RCBn5J83Poc |
|
| 297 | + return FALSE; |
|
| 298 | 298 | } |
| 299 | 299 | |
| 300 | 300 | } |
@@ -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) {
|
@@ -52,7 +52,9 @@ discard block |
||
| 52 | 52 | if (!$type) {
|
| 53 | 53 | // If the user is trying to load a Geometry from a Geometry... Just pass it back |
| 54 | 54 | if (is_object($data)) {
|
| 55 | - if ($data instanceOf Geometry) return $data; |
|
| 55 | + if ($data instanceOf Geometry) { |
|
| 56 | + return $data; |
|
| 57 | + } |
|
| 56 | 58 | } |
| 57 | 59 | |
| 58 | 60 | $detected = geoPHP::detectFormat($data); |
@@ -120,7 +122,9 @@ discard block |
||
| 120 | 122 | |
| 121 | 123 | static function geosInstalled($force = NULL) {
|
| 122 | 124 | static $geos_installed = NULL; |
| 123 | - if ($force !== NULL) $geos_installed = $force; |
|
| 125 | + if ($force !== NULL) { |
|
| 126 | + $geos_installed = $force; |
|
| 127 | + } |
|
| 124 | 128 | if ($geos_installed !== NULL) {
|
| 125 | 129 | return $geos_installed; |
| 126 | 130 | } |
@@ -148,8 +152,12 @@ discard block |
||
| 148 | 152 | static function geometryReduce($geometry) {
|
| 149 | 153 | // If it's an array of one, then just parse the one |
| 150 | 154 | if (is_array($geometry)) {
|
| 151 | - if (empty($geometry)) return FALSE; |
|
| 152 | - if (count($geometry) == 1) return geoPHP::geometryReduce(array_shift($geometry)); |
|
| 155 | + if (empty($geometry)) { |
|
| 156 | + return FALSE; |
|
| 157 | + } |
|
| 158 | + if (count($geometry) == 1) { |
|
| 159 | + return geoPHP::geometryReduce(array_shift($geometry)); |
|
| 160 | + } |
|
| 153 | 161 | } |
| 154 | 162 | |
| 155 | 163 | // If the geometry cannot even theoretically be reduced more, then pass it back |
@@ -168,8 +176,7 @@ discard block |
||
| 168 | 176 | $components = $geometry->getComponents(); |
| 169 | 177 | if (count($components) == 1) {
|
| 170 | 178 | return $components[0]; |
| 171 | - } |
|
| 172 | - else {
|
|
| 179 | + } else {
|
|
| 173 | 180 | return $geometry; |
| 174 | 181 | } |
| 175 | 182 | } |
@@ -192,8 +199,7 @@ discard block |
||
| 192 | 199 | $geometries[] = $component; |
| 193 | 200 | $geom_types[] = $component->geometryType(); |
| 194 | 201 | } |
| 195 | - } |
|
| 196 | - else {
|
|
| 202 | + } else {
|
|
| 197 | 203 | $geometries[] = $item; |
| 198 | 204 | $geom_types[] = $item->geometryType(); |
| 199 | 205 | } |
@@ -209,13 +215,11 @@ discard block |
||
| 209 | 215 | if (count($geom_types) == 1) {
|
| 210 | 216 | if (count($geometries) == 1) {
|
| 211 | 217 | return $geometries[0]; |
| 212 | - } |
|
| 213 | - else {
|
|
| 218 | + } else {
|
|
| 214 | 219 | $class = 'Multi'.$geom_types[0]; |
| 215 | 220 | return new $class($geometries); |
| 216 | 221 | } |
| 217 | - } |
|
| 218 | - else {
|
|
| 222 | + } else {
|
|
| 219 | 223 | return new GeometryCollection($geometries); |
| 220 | 224 | } |
| 221 | 225 | } |
@@ -230,7 +234,9 @@ discard block |
||
| 230 | 234 | $bytes = unpack("c*", fread($mem, 11));
|
| 231 | 235 | |
| 232 | 236 | // If bytes is empty, then we were passed empty input |
| 233 | - if (empty($bytes)) return FALSE; |
|
| 237 | + if (empty($bytes)) { |
|
| 238 | + return FALSE; |
|
| 239 | + } |
|
| 234 | 240 | |
| 235 | 241 | // First char is a tab, space or carriage-return. trim it and try again |
| 236 | 242 | if ($bytes[1] == 9 || $bytes[1] == 10 || $bytes[1] == 32) {
|
@@ -240,8 +246,11 @@ discard block |
||
| 240 | 246 | // Detect WKB or EWKB -- first byte is 1 (little endian indicator) |
| 241 | 247 | if ($bytes[1] == 1) {
|
| 242 | 248 | // If SRID byte is TRUE (1), it's EWKB |
| 243 | - if ($bytes[5]) return 'ewkb'; |
|
| 244 | - else return 'wkb'; |
|
| 249 | + if ($bytes[5]) { |
|
| 250 | + return 'ewkb'; |
|
| 251 | + } else { |
|
| 252 | + return 'wkb'; |
|
| 253 | + } |
|
| 245 | 254 | } |
| 246 | 255 | |
| 247 | 256 | // Detect HEX encoded WKB or EWKB (PostGIS format) -- first byte is 48, second byte is 49 (hex '01' => first-byte = 1) |
@@ -274,12 +283,24 @@ discard block |
||
| 274 | 283 | if ($bytes[1] == 60) {
|
| 275 | 284 | // grab the first 256 characters |
| 276 | 285 | $string = substr($input, 0, 256); |
| 277 | - if (strpos($string, '<kml') !== FALSE) return 'kml'; |
|
| 278 | - if (strpos($string, '<coordinate') !== FALSE) return 'kml'; |
|
| 279 | - if (strpos($string, '<gpx') !== FALSE) return 'gpx'; |
|
| 280 | - if (strpos($string, '<georss') !== FALSE) return 'georss'; |
|
| 281 | - if (strpos($string, '<rss') !== FALSE) return 'georss'; |
|
| 282 | - if (strpos($string, '<feed') !== FALSE) return 'georss'; |
|
| 286 | + if (strpos($string, '<kml') !== FALSE) { |
|
| 287 | + return 'kml'; |
|
| 288 | + } |
|
| 289 | + if (strpos($string, '<coordinate') !== FALSE) { |
|
| 290 | + return 'kml'; |
|
| 291 | + } |
|
| 292 | + if (strpos($string, '<gpx') !== FALSE) { |
|
| 293 | + return 'gpx'; |
|
| 294 | + } |
|
| 295 | + if (strpos($string, '<georss') !== FALSE) { |
|
| 296 | + return 'georss'; |
|
| 297 | + } |
|
| 298 | + if (strpos($string, '<rss') !== FALSE) { |
|
| 299 | + return 'georss'; |
|
| 300 | + } |
|
| 301 | + if (strpos($string, '<feed') !== FALSE) { |
|
| 302 | + return 'georss'; |
|
| 303 | + } |
|
| 283 | 304 | } |
| 284 | 305 | |
| 285 | 306 | // We need an 8 byte string for geohash and unpacked WKB / WKT |