| @@ -3,6 +3,10 @@ | ||
| 3 | 3 | require_once(dirname(__FILE__).'/../require/class.Connection.php'); | 
| 4 | 4 | |
| 5 | 5 |  class create_db { | 
| 6 | + | |
| 7 | + /** | |
| 8 | + * @param string $filename | |
| 9 | + */ | |
| 6 | 10 |  	public static function import_file($filename) { | 
| 7 | 11 | $filename = filter_var($filename,FILTER_SANITIZE_STRING); | 
| 8 | 12 | $Connection = new Connection(); | 
| @@ -4,24 +4,24 @@ discard block | ||
| 4 | 4 | |
| 5 | 5 |  class create_db { | 
| 6 | 6 |  	public static function import_file($filename) { | 
| 7 | - $filename = filter_var($filename,FILTER_SANITIZE_STRING); | |
| 7 | + $filename = filter_var($filename, FILTER_SANITIZE_STRING); | |
| 8 | 8 | $Connection = new Connection(); | 
| 9 | 9 | //Connection::$db->beginTransaction(); | 
| 10 | 10 | $templine = ''; | 
| 11 | - $handle = @fopen($filename,"r"); | |
| 11 | + $handle = @fopen($filename, "r"); | |
| 12 | 12 |  		if ($handle) { | 
| 13 | 13 | //$lines = file($filename); | 
| 14 | 14 | //foreach ($lines as $line) | 
| 15 | - while (($line = fgets($handle,4096)) !== false) | |
| 15 | + while (($line = fgets($handle, 4096)) !== false) | |
| 16 | 16 |  			{ | 
| 17 | - if (substr($line,0,2) == '--' || $line == '') continue; | |
| 17 | + if (substr($line, 0, 2) == '--' || $line == '') continue; | |
| 18 | 18 | $templine .= $line; | 
| 19 | - if (substr(trim($line), -1,1) == ';') | |
| 19 | + if (substr(trim($line), -1, 1) == ';') | |
| 20 | 20 |  				{ | 
| 21 | 21 |  					try { | 
| 22 | 22 | $sth = $Connection->db->prepare($templine); | 
| 23 | 23 | $sth->execute(); | 
| 24 | -					} catch(PDOException $e) { | |
| 24 | +					} catch (PDOException $e) { | |
| 25 | 25 | return "error (import ".$filename.") : ".$e->getMessage()."\n"; | 
| 26 | 26 | } | 
| 27 | 27 | $templine = ''; | 
| @@ -38,27 +38,27 @@ discard block | ||
| 38 | 38 | $error = ''; | 
| 39 | 39 | $dh = opendir($directory); | 
| 40 | 40 | //foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($directory)) as $filename) | 
| 41 | - while(false !== ($filename = readdir($dh))) | |
| 41 | + while (false !== ($filename = readdir($dh))) | |
| 42 | 42 |  		{ | 
| 43 | -		    if (preg_match('/\.sql$/',$filename)) $error .= create_db::import_file($directory.$filename); | |
| 43 | +		    if (preg_match('/\.sql$/', $filename)) $error .= create_db::import_file($directory.$filename); | |
| 44 | 44 | } | 
| 45 | 45 | return $error; | 
| 46 | 46 | } | 
| 47 | 47 | |
| 48 | -	public static function create_database($root,$root_pass,$user,$pass,$db,$db_type,$host) { | |
| 49 | - $root = filter_var($root,FILTER_SANITIZE_STRING); | |
| 50 | - $root_pass = filter_var($root_pass,FILTER_SANITIZE_STRING); | |
| 51 | - $user = filter_var($user,FILTER_SANITIZE_STRING); | |
| 52 | - $password = filter_var($pass,FILTER_SANITIZE_STRING); | |
| 53 | - $db = filter_var($db,FILTER_SANITIZE_STRING); | |
| 54 | - $db_type = filter_var($db_type,FILTER_SANITIZE_STRING); | |
| 55 | - $host = filter_var($host,FILTER_SANITIZE_STRING); | |
| 48 | +	public static function create_database($root, $root_pass, $user, $pass, $db, $db_type, $host) { | |
| 49 | + $root = filter_var($root, FILTER_SANITIZE_STRING); | |
| 50 | + $root_pass = filter_var($root_pass, FILTER_SANITIZE_STRING); | |
| 51 | + $user = filter_var($user, FILTER_SANITIZE_STRING); | |
| 52 | + $password = filter_var($pass, FILTER_SANITIZE_STRING); | |
| 53 | + $db = filter_var($db, FILTER_SANITIZE_STRING); | |
| 54 | + $db_type = filter_var($db_type, FILTER_SANITIZE_STRING); | |
| 55 | + $host = filter_var($host, FILTER_SANITIZE_STRING); | |
| 56 | 56 | // Dirty hack | 
| 57 | 57 |  		if ($host != 'localhost' && $host != '127.0.0.1') { | 
| 58 | 58 | $grantright = $_SERVER['SERVER_ADDR']; | 
| 59 | 59 | } else $grantright = 'localhost'; | 
| 60 | 60 |  		try { | 
| 61 | - $dbh = new PDO($db_type.':host='.$host,$root,$root_pass); | |
| 61 | + $dbh = new PDO($db_type.':host='.$host, $root, $root_pass); | |
| 62 | 62 | $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); | 
| 63 | 63 |  			if ($db_type == 'mysql') { | 
| 64 | 64 |  				$dbh->exec('CREATE DATABASE IF NOT EXISTS `'.$db.'`;GRANT ALL ON `'.$db."`.* TO '".$user."'@'".$grantright."' IDENTIFIED BY '".$password."';FLUSH PRIVILEGES;"); | 
| @@ -68,7 +68,7 @@ discard block | ||
| 68 | 68 |  				$dbh->exec("CREATE USER ".$user." WITH PASSWORD '".$password."'; | 
| 69 | 69 | GRANT ALL PRIVILEGES ON DATABASE ".$db." TO ".$user.";"); | 
| 70 | 70 | } | 
| 71 | -		} catch(PDOException $e) { | |
| 71 | +		} catch (PDOException $e) { | |
| 72 | 72 | $dbh = null; | 
| 73 | 73 | return "error : ".$e->getMessage(); | 
| 74 | 74 | } | 
| @@ -13,6 +13,9 @@ discard block | ||
| 13 | 13 |  function sparql_connect( $endpoint ) { return new sparql_connection( $endpoint ); } | 
| 14 | 14 | |
| 15 | 15 |  function sparql_ns( $short, $long, $db = null ) { return _sparql_a_connection( $db )->ns( $short, $long ); } | 
| 16 | +/** | |
| 17 | + * @param string $sparql | |
| 18 | + */ | |
| 16 | 19 |  function sparql_query( $sparql, $db = null ) { return _sparql_a_connection( $db )->query( $sparql ); } | 
| 17 | 20 |  function sparql_errno( $db = null ) { return _sparql_a_connection( $db )->errno(); } | 
| 18 | 21 |  function sparql_error( $db = null ) { return _sparql_a_connection( $db )->error(); } | 
| @@ -84,6 +87,9 @@ discard block | ||
| 84 | 87 | $this->params = $params; | 
| 85 | 88 | } | 
| 86 | 89 | |
| 90 | + /** | |
| 91 | + * @param integer $timeout | |
| 92 | + */ | |
| 87 | 93 | function query( $query, $timeout=null ) | 
| 88 | 94 |  	{	 | 
| 89 | 95 | $prefixes = ""; | 
| @@ -324,6 +330,10 @@ discard block | ||
| 324 | 330 | var $fields; | 
| 325 | 331 | var $db; | 
| 326 | 332 | var $i = 0; | 
| 333 | + | |
| 334 | + /** | |
| 335 | + * @param sparql_connection $db | |
| 336 | + */ | |
| 327 | 337 | function __construct( $db, $rows, $fields ) | 
| 328 | 338 |  	{ | 
| 329 | 339 | $this->rows = $rows; | 
| @@ -10,37 +10,37 @@ discard block | ||
| 10 | 10 | |
| 11 | 11 | # to document: CGIParams | 
| 12 | 12 | |
| 13 | -function sparql_connect( $endpoint ) { return new sparql_connection( $endpoint ); } | |
| 13 | +function sparql_connect($endpoint) { return new sparql_connection($endpoint); } | |
| 14 | 14 | |
| 15 | -function sparql_ns( $short, $long, $db = null ) { return _sparql_a_connection( $db )->ns( $short, $long ); } | |
| 16 | -function sparql_query( $sparql, $db = null ) { return _sparql_a_connection( $db )->query( $sparql ); } | |
| 17 | -function sparql_errno( $db = null ) { return _sparql_a_connection( $db )->errno(); } | |
| 18 | -function sparql_error( $db = null ) { return _sparql_a_connection( $db )->error(); } | |
| 15 | +function sparql_ns($short, $long, $db = null) { return _sparql_a_connection($db)->ns($short, $long); } | |
| 16 | +function sparql_query($sparql, $db = null) { return _sparql_a_connection($db)->query($sparql); } | |
| 17 | +function sparql_errno($db = null) { return _sparql_a_connection($db)->errno(); } | |
| 18 | +function sparql_error($db = null) { return _sparql_a_connection($db)->error(); } | |
| 19 | 19 | |
| 20 | -function sparql_fetch_array( $result ) { return $result->fetch_array(); } | |
| 21 | -function sparql_num_rows( $result ) { return $result->num_rows(); } | |
| 22 | -function sparql_field_array( $result ) { return $result->field_array(); } | |
| 23 | -function sparql_field_name( $result, $i ) { return $result->field_name( $i ); } | |
| 20 | +function sparql_fetch_array($result) { return $result->fetch_array(); } | |
| 21 | +function sparql_num_rows($result) { return $result->num_rows(); } | |
| 22 | +function sparql_field_array($result) { return $result->field_array(); } | |
| 23 | +function sparql_field_name($result, $i) { return $result->field_name($i); } | |
| 24 | 24 | |
| 25 | -function sparql_fetch_all( $result ) { return $result->fetch_all(); } | |
| 25 | +function sparql_fetch_all($result) { return $result->fetch_all(); } | |
| 26 | 26 | |
| 27 | -function sparql_get( $endpoint, $sparql ) | |
| 27 | +function sparql_get($endpoint, $sparql) | |
| 28 | 28 |  {  | 
| 29 | - $db = sparql_connect( $endpoint ); | |
| 30 | -	if( !$db ) { return; } | |
| 31 | - $result = $db->query( $sparql ); | |
| 32 | -	if( !$result ) { return; } | |
| 29 | + $db = sparql_connect($endpoint); | |
| 30 | +	if (!$db) { return; } | |
| 31 | + $result = $db->query($sparql); | |
| 32 | +	if (!$result) { return; } | |
| 33 | 33 | return $result->fetch_all(); | 
| 34 | 34 | } | 
| 35 | 35 | |
| 36 | -function _sparql_a_connection( $db ) | |
| 36 | +function _sparql_a_connection($db) | |
| 37 | 37 |  { | 
| 38 | 38 | global $sparql_last_connection; | 
| 39 | - if( !isset( $db ) ) | |
| 39 | + if (!isset($db)) | |
| 40 | 40 |  	{ | 
| 41 | - if( !isset( $sparql_last_connection ) ) | |
| 41 | + if (!isset($sparql_last_connection)) | |
| 42 | 42 |  		{ | 
| 43 | - print( "No currect SPARQL connection (connection) in play!" ); | |
| 43 | +			print("No currect SPARQL connection (connection) in play!"); | |
| 44 | 44 | return; | 
| 45 | 45 | } | 
| 46 | 46 | $db = $sparql_last_connection; | 
| @@ -62,14 +62,14 @@ discard block | ||
| 62 | 62 | var $params = null; | 
| 63 | 63 | # capabilities are either true, false or null if not yet tested. | 
| 64 | 64 | |
| 65 | - function __construct( $endpoint ) | |
| 65 | + function __construct($endpoint) | |
| 66 | 66 |  	{ | 
| 67 | 67 | $this->endpoint = $endpoint; | 
| 68 | 68 | global $sparql_last_connection; | 
| 69 | 69 | $sparql_last_connection = $this; | 
| 70 | 70 | } | 
| 71 | 71 | |
| 72 | - function ns( $short, $long ) | |
| 72 | + function ns($short, $long) | |
| 73 | 73 |  	{ | 
| 74 | 74 | $this->ns[$short] = $long; | 
| 75 | 75 | } | 
| @@ -77,77 +77,77 @@ discard block | ||
| 77 | 77 |  	function errno() { return $this->errno; } | 
| 78 | 78 |  	function error() { return $this->error; } | 
| 79 | 79 | |
| 80 | - function cgiParams( $params = null ) | |
| 80 | + function cgiParams($params = null) | |
| 81 | 81 |  	{ | 
| 82 | -		if( $params === null ) { return $this->params; } | |
| 83 | -		if( $params === "" ) { $this->params = null; return; } | |
| 82 | +		if ($params === null) { return $this->params; } | |
| 83 | +		if ($params === "") { $this->params = null; return; } | |
| 84 | 84 | $this->params = $params; | 
| 85 | 85 | } | 
| 86 | 86 | |
| 87 | - function query( $query, $timeout=null ) | |
| 87 | + function query($query, $timeout = null) | |
| 88 | 88 |  	{	 | 
| 89 | 89 | $prefixes = ""; | 
| 90 | - foreach( $this->ns as $k=>$v ) | |
| 90 | + foreach ($this->ns as $k=>$v) | |
| 91 | 91 |  		{ | 
| 92 | 92 | $prefixes .= "PREFIX $k: <$v>\n"; | 
| 93 | 93 | } | 
| 94 | - $output = $this->dispatchQuery( $prefixes.$query, $timeout ); | |
| 95 | -		if( $this->errno ) { return; } | |
| 94 | + $output = $this->dispatchQuery($prefixes.$query, $timeout); | |
| 95 | +		if ($this->errno) { return; } | |
| 96 | 96 | $parser = new xx_xml($output, 'contents'); | 
| 97 | - if( $parser->error() ) | |
| 97 | + if ($parser->error()) | |
| 98 | 98 |  		{  | 
| 99 | 99 | $this->errno = -1; # to not clash with CURLOPT return; } | 
| 100 | 100 | $this->error = $parser->error(); | 
| 101 | 101 | return; | 
| 102 | 102 | } | 
| 103 | - return new sparql_result( $this, $parser->rows, $parser->fields ); | |
| 103 | + return new sparql_result($this, $parser->rows, $parser->fields); | |
| 104 | 104 | } | 
| 105 | 105 | |
| 106 | - function alive( $timeout=3 ) | |
| 106 | + function alive($timeout = 3) | |
| 107 | 107 |  	{ | 
| 108 | -		$result = $this->query( "SELECT * WHERE { ?s ?p ?o } LIMIT 1", $timeout ); | |
| 108 | +		$result = $this->query("SELECT * WHERE { ?s ?p ?o } LIMIT 1", $timeout); | |
| 109 | 109 | |
| 110 | -		if( $this->errno ) { return false; } | |
| 110 | +		if ($this->errno) { return false; } | |
| 111 | 111 | |
| 112 | 112 | return true; | 
| 113 | 113 | } | 
| 114 | 114 | |
| 115 | - function dispatchQuery( $sparql, $timeout=null ) | |
| 115 | + function dispatchQuery($sparql, $timeout = null) | |
| 116 | 116 |  	{ | 
| 117 | - $url = $this->endpoint."?query=".urlencode( $sparql ); | |
| 118 | - if( $this->params !== null ) | |
| 117 | + $url = $this->endpoint."?query=".urlencode($sparql); | |
| 118 | + if ($this->params !== null) | |
| 119 | 119 |  		{ | 
| 120 | 120 | $url .= "&".$this->params; | 
| 121 | 121 | } | 
| 122 | -		if( $this->debug ) { print "<div class='debug'><a href='".htmlspecialchars($url)."'>".htmlspecialchars($prefixes.$query)."</a></div>\n"; } | |
| 122 | +		if ($this->debug) { print "<div class='debug'><a href='".htmlspecialchars($url)."'>".htmlspecialchars($prefixes.$query)."</a></div>\n"; } | |
| 123 | 123 | $this->errno = null; | 
| 124 | 124 | $this->error = null; | 
| 125 | 125 | $ch = curl_init($url); | 
| 126 | 126 | #curl_setopt($ch, CURLOPT_HEADER, 1); | 
| 127 | - if( $timeout !== null ) | |
| 127 | + if ($timeout !== null) | |
| 128 | 128 |  		{ | 
| 129 | - curl_setopt($ch, CURLOPT_TIMEOUT, $timeout ); | |
| 129 | + curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); | |
| 130 | 130 | } | 
| 131 | 131 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); | 
| 132 | - curl_setopt($ch, CURLOPT_HTTPHEADER,array ( | |
| 132 | + curl_setopt($ch, CURLOPT_HTTPHEADER, array( | |
| 133 | 133 | "Accept: application/sparql-results+xml" | 
| 134 | 134 | )); | 
| 135 | 135 | |
| 136 | 136 | $output = curl_exec($ch); | 
| 137 | 137 | $info = curl_getinfo($ch); | 
| 138 | - if(curl_errno($ch)) | |
| 138 | + if (curl_errno($ch)) | |
| 139 | 139 |  		{ | 
| 140 | - $this->errno = curl_errno( $ch ); | |
| 141 | - $this->error = 'Curl error: ' . curl_error($ch); | |
| 140 | + $this->errno = curl_errno($ch); | |
| 141 | + $this->error = 'Curl error: '.curl_error($ch); | |
| 142 | 142 | return; | 
| 143 | 143 | } | 
| 144 | - if( $output === '' ) | |
| 144 | + if ($output === '') | |
| 145 | 145 |  		{ | 
| 146 | 146 | $this->errno = "-1"; | 
| 147 | 147 | $this->error = 'URL returned no data'; | 
| 148 | 148 | return; | 
| 149 | 149 | } | 
| 150 | - if( $info['http_code'] != 200) | |
| 150 | + if ($info['http_code'] != 200) | |
| 151 | 151 |  		{ | 
| 152 | 152 | $this->errno = $info['http_code']; | 
| 153 | 153 | $this->error = 'Bad response, '.$info['http_code'].': '.$output; | 
| @@ -179,13 +179,13 @@ discard block | ||
| 179 | 179 | |
| 180 | 180 | var $caps_cache; | 
| 181 | 181 | var $caps_anysubject; | 
| 182 | - function capabilityCache( $filename, $dba_type='db4' ) | |
| 182 | + function capabilityCache($filename, $dba_type = 'db4') | |
| 183 | 183 |  	{ | 
| 184 | - $this->caps_cache = dba_open($filename, "c", $dba_type ); | |
| 184 | + $this->caps_cache = dba_open($filename, "c", $dba_type); | |
| 185 | 185 | } | 
| 186 | 186 | function capabilityCodes() | 
| 187 | 187 |  	{ | 
| 188 | - return array_keys( $this->caps_desc ); | |
| 188 | + return array_keys($this->caps_desc); | |
| 189 | 189 | } | 
| 190 | 190 | function capabilityDescription($code) | 
| 191 | 191 |  	{ | 
| @@ -194,19 +194,19 @@ discard block | ||
| 194 | 194 | |
| 195 | 195 | # return true if the endpoint supports a capability | 
| 196 | 196 | # nb. returns false if connecion isn't authoriased to use the feature, eg LOAD | 
| 197 | - function supports( $code ) | |
| 197 | + function supports($code) | |
| 198 | 198 |  	{ | 
| 199 | -		if( isset( $this->caps[$code] ) ) { return $this->caps[$code]; } | |
| 199 | +		if (isset($this->caps[$code])) { return $this->caps[$code]; } | |
| 200 | 200 | $was_cached = false; | 
| 201 | - if( isset( $this->caps_cache ) ) | |
| 201 | + if (isset($this->caps_cache)) | |
| 202 | 202 |  		{ | 
| 203 | 203 | $CACHE_TIMEOUT_SECONDS = 7*24*60*60; | 
| 204 | 204 | $db_key = $this->endpoint.";".$code; | 
| 205 | - $db_val = dba_fetch( $db_key, $this->caps_cache ); | |
| 206 | - if( $db_val !== false ) | |
| 205 | + $db_val = dba_fetch($db_key, $this->caps_cache); | |
| 206 | + if ($db_val !== false) | |
| 207 | 207 |  			{ | 
| 208 | - list( $result, $when ) = preg_split( '/;/', $db_val ); | |
| 209 | - if( $when + $CACHE_TIMEOUT_SECONDS > time() ) | |
| 208 | +				list($result, $when) = preg_split('/;/', $db_val); | |
| 209 | + if ($when + $CACHE_TIMEOUT_SECONDS > time()) | |
| 210 | 210 |  				{ | 
| 211 | 211 | return $result; | 
| 212 | 212 | } | 
| @@ -215,26 +215,26 @@ discard block | ||
| 215 | 215 | } | 
| 216 | 216 | $r = null; | 
| 217 | 217 | |
| 218 | -		if( $code == "select" ) { $r = $this->test_select(); } | |
| 219 | -		elseif( $code == "constant_as" ) { $r = $this->test_constant_as(); } | |
| 220 | -		elseif( $code == "math_as" ) { $r = $this->test_math_as(); } | |
| 221 | -		elseif( $code == "count" ) { $r = $this->test_count(); } | |
| 222 | -		elseif( $code == "max" ) { $r = $this->test_max(); } | |
| 223 | -		elseif( $code == "load" ) { $r = $this->test_load(); } | |
| 224 | -		elseif( $code == "sample" ) { $r = $this->test_sample(); } | |
| 218 | +		if ($code == "select") { $r = $this->test_select(); } | |
| 219 | +		elseif ($code == "constant_as") { $r = $this->test_constant_as(); } | |
| 220 | +		elseif ($code == "math_as") { $r = $this->test_math_as(); } | |
| 221 | +		elseif ($code == "count") { $r = $this->test_count(); } | |
| 222 | +		elseif ($code == "max") { $r = $this->test_max(); } | |
| 223 | +		elseif ($code == "load") { $r = $this->test_load(); } | |
| 224 | +		elseif ($code == "sample") { $r = $this->test_sample(); } | |
| 225 | 225 |  		else { print "<p>Unknown capability code: '$code'</p>"; return false; } | 
| 226 | 226 | $this->caps[$code] = $r; | 
| 227 | - if( isset( $this->caps_cache ) ) | |
| 227 | + if (isset($this->caps_cache)) | |
| 228 | 228 |  		{ | 
| 229 | 229 | $db_key = $this->endpoint.";".$code; | 
| 230 | 230 | $db_val = $r.";".time(); | 
| 231 | - if( $was_cached ) | |
| 231 | + if ($was_cached) | |
| 232 | 232 |  			{ | 
| 233 | - dba_replace( $db_key, $db_val, $this->caps_cache ); | |
| 233 | + dba_replace($db_key, $db_val, $this->caps_cache); | |
| 234 | 234 | } | 
| 235 | 235 | else | 
| 236 | 236 |  			{ | 
| 237 | - dba_insert( $db_key, $db_val, $this->caps_cache ); | |
| 237 | + dba_insert($db_key, $db_val, $this->caps_cache); | |
| 238 | 238 | } | 
| 239 | 239 | } | 
| 240 | 240 | return $r; | 
| @@ -242,11 +242,11 @@ discard block | ||
| 242 | 242 | |
| 243 | 243 | function anySubject() | 
| 244 | 244 |  	{ | 
| 245 | - if( !isset( $this->caps_anysubject ) ) | |
| 245 | + if (!isset($this->caps_anysubject)) | |
| 246 | 246 |  		{ | 
| 247 | 247 | $results = $this->query( | 
| 248 | 248 |  			  "SELECT * WHERE { ?s ?p ?o } LIMIT 1" ); | 
| 249 | - if( sizeof($results)) | |
| 249 | + if (sizeof($results)) | |
| 250 | 250 |  			{ | 
| 251 | 251 | $row = $results->fetch_array(); | 
| 252 | 252 | $this->caps_anysubject = $row["s"]; | 
| @@ -260,7 +260,7 @@ discard block | ||
| 260 | 260 |  	{ | 
| 261 | 261 | $output = $this->dispatchQuery( | 
| 262 | 262 |  		  "SELECT ?s ?p ?o WHERE { ?s ?p ?o } LIMIT 1" ); | 
| 263 | - return !isset( $this->errno ); | |
| 263 | + return !isset($this->errno); | |
| 264 | 264 | } | 
| 265 | 265 | |
| 266 | 266 | # return true if the endpoint supports AS | 
| @@ -268,7 +268,7 @@ discard block | ||
| 268 | 268 |  	{ | 
| 269 | 269 | $output = $this->dispatchQuery( | 
| 270 | 270 |  		  "SELECT (1+2 AS ?bar) WHERE { ?s ?p ?o } LIMIT 1" ); | 
| 271 | - return !isset( $this->errno ); | |
| 271 | + return !isset($this->errno); | |
| 272 | 272 | } | 
| 273 | 273 | |
| 274 | 274 | # return true if the endpoint supports AS | 
| @@ -276,7 +276,7 @@ discard block | ||
| 276 | 276 |  	{ | 
| 277 | 277 | $output = $this->dispatchQuery( | 
| 278 | 278 |  		  "SELECT (\"foo\" AS ?bar) WHERE { ?s ?p ?o } LIMIT 1" ); | 
| 279 | - return !isset( $this->errno ); | |
| 279 | + return !isset($this->errno); | |
| 280 | 280 | } | 
| 281 | 281 | |
| 282 | 282 | # return true if the endpoint supports SELECT (COUNT(?x) as ?n) ... GROUP BY | 
| @@ -284,35 +284,35 @@ discard block | ||
| 284 | 284 |  	{ | 
| 285 | 285 | # assumes at least one rdf:type predicate | 
| 286 | 286 | $s = $this->anySubject(); | 
| 287 | -		if( !isset($s) ) { return false; } | |
| 287 | +		if (!isset($s)) { return false; } | |
| 288 | 288 | $output = $this->dispatchQuery( | 
| 289 | 289 |  		  "SELECT (COUNT(?p) AS ?n) ?o WHERE { <$s> ?p ?o } GROUP BY ?o" ); | 
| 290 | - return !isset( $this->errno ); | |
| 290 | + return !isset($this->errno); | |
| 291 | 291 | } | 
| 292 | 292 | |
| 293 | 293 | function test_max() | 
| 294 | 294 |  	{ | 
| 295 | 295 | $s = $this->anySubject(); | 
| 296 | -		if( !isset($s) ) { return false; } | |
| 296 | +		if (!isset($s)) { return false; } | |
| 297 | 297 | $output = $this->dispatchQuery( | 
| 298 | 298 |  		  "SELECT (MAX(?p) AS ?max) ?o WHERE { <$s> ?p ?o } GROUP BY ?o" ); | 
| 299 | - return !isset( $this->errno ); | |
| 299 | + return !isset($this->errno); | |
| 300 | 300 | } | 
| 301 | 301 | |
| 302 | 302 | function test_sample() | 
| 303 | 303 |  	{ | 
| 304 | 304 | $s = $this->anySubject(); | 
| 305 | -		if( !isset($s) ) { return false; } | |
| 305 | +		if (!isset($s)) { return false; } | |
| 306 | 306 | $output = $this->dispatchQuery( | 
| 307 | 307 |  		  "SELECT (SAMPLE(?p) AS ?sam) ?o WHERE { <$s> ?p ?o } GROUP BY ?o" ); | 
| 308 | - return !isset( $this->errno ); | |
| 308 | + return !isset($this->errno); | |
| 309 | 309 | } | 
| 310 | 310 | |
| 311 | 311 | function test_load() | 
| 312 | 312 |  	{ | 
| 313 | 313 | $output = $this->dispatchQuery( | 
| 314 | 314 | "LOAD <http://graphite.ecs.soton.ac.uk/sparqllib/examples/loadtest.rdf>" ); | 
| 315 | - return !isset( $this->errno ); | |
| 315 | + return !isset($this->errno); | |
| 316 | 316 | } | 
| 317 | 317 | |
| 318 | 318 | |
| @@ -324,7 +324,7 @@ discard block | ||
| 324 | 324 | var $fields; | 
| 325 | 325 | var $db; | 
| 326 | 326 | var $i = 0; | 
| 327 | - function __construct( $db, $rows, $fields ) | |
| 327 | + function __construct($db, $rows, $fields) | |
| 328 | 328 |  	{ | 
| 329 | 329 | $this->rows = $rows; | 
| 330 | 330 | $this->fields = $fields; | 
| @@ -333,17 +333,17 @@ discard block | ||
| 333 | 333 | |
| 334 | 334 | function fetch_array() | 
| 335 | 335 |  	{ | 
| 336 | -		if( !@$this->rows[$this->i] ) { return; } | |
| 336 | +		if (!@$this->rows[$this->i]) { return; } | |
| 337 | 337 | $r = array(); | 
| 338 | - foreach( $this->rows[$this->i++] as $k=>$v ) | |
| 338 | + foreach ($this->rows[$this->i++] as $k=>$v) | |
| 339 | 339 |  		{ | 
| 340 | 340 | $r[$k] = $v["value"]; | 
| 341 | 341 | $r["$k.type"] = $v["type"]; | 
| 342 | - if( isset( $v["language"] ) ) | |
| 342 | + if (isset($v["language"])) | |
| 343 | 343 |  			{ | 
| 344 | 344 | $r["$k.language"] = $v["language"]; | 
| 345 | 345 | } | 
| 346 | - if( isset( $v["datatype"] ) ) | |
| 346 | + if (isset($v["datatype"])) | |
| 347 | 347 |  			{ | 
| 348 | 348 | $r["$k.datatype"] = $v["datatype"]; | 
| 349 | 349 | } | 
| @@ -355,16 +355,16 @@ discard block | ||
| 355 | 355 |  	{ | 
| 356 | 356 | $r = new sparql_results(); | 
| 357 | 357 | $r->fields = $this->fields; | 
| 358 | - foreach( $this->rows as $i=>$row ) | |
| 358 | + foreach ($this->rows as $i=>$row) | |
| 359 | 359 |  		{ | 
| 360 | - $r []= $this->fetch_array(); | |
| 360 | + $r [] = $this->fetch_array(); | |
| 361 | 361 | } | 
| 362 | 362 | return $r; | 
| 363 | 363 | } | 
| 364 | 364 | |
| 365 | 365 | function num_rows() | 
| 366 | 366 |  	{ | 
| 367 | - return sizeof( $this->rows ); | |
| 367 | + return sizeof($this->rows); | |
| 368 | 368 | } | 
| 369 | 369 | |
| 370 | 370 | function field_array() | 
| @@ -400,7 +400,7 @@ discard block | ||
| 400 | 400 | var $type; | 
| 401 | 401 | |
| 402 | 402 | // function with the default parameter value | 
| 403 | -	function xx_xml($url='http://www.opocot.com', $type='url') { | |
| 403 | +	function xx_xml($url = 'http://www.opocot.com', $type = 'url') { | |
| 404 | 404 | $this->type = $type; | 
| 405 | 405 | $this->url = $url; | 
| 406 | 406 | $this->parse(); | 
| @@ -414,7 +414,7 @@ discard block | ||
| 414 | 414 | $this->rows = array(); | 
| 415 | 415 | $this->fields = array(); | 
| 416 | 416 | $data = ''; | 
| 417 | -		$this->parser = xml_parser_create ("UTF-8"); | |
| 417 | +		$this->parser = xml_parser_create("UTF-8"); | |
| 418 | 418 | xml_set_object($this->parser, $this); | 
| 419 | 419 | xml_set_element_handler($this->parser, 'startXML', 'endXML'); | 
| 420 | 420 | xml_set_character_data_handler($this->parser, 'charXML'); | 
| @@ -439,9 +439,9 @@ discard block | ||
| 439 | 439 |  	 	} else if ($this->type == 'contents') { | 
| 440 | 440 | // Now we can pass the contents, maybe if you want | 
| 441 | 441 | // to use CURL, SOCK or other method. | 
| 442 | -			$lines = explode("\n",$this->url); | |
| 442 | +			$lines = explode("\n", $this->url); | |
| 443 | 443 |  			foreach ($lines as $val) { | 
| 444 | - $data = $val . "\n"; | |
| 444 | + $data = $val."\n"; | |
| 445 | 445 |  				if (!xml_parse($this->parser, $data)) { | 
| 446 | 446 |  					$this->error = $data."\n".sprintf('XML error at line %d column %d', | 
| 447 | 447 | xml_get_current_line_number($this->parser), | 
| @@ -450,7 +450,7 @@ discard block | ||
| 450 | 450 | } | 
| 451 | 451 | } | 
| 452 | 452 | } | 
| 453 | - if( !$this->looks_legit ) | |
| 453 | + if (!$this->looks_legit) | |
| 454 | 454 |  		{ | 
| 455 | 455 | $this->error = "Didn't even see a sparql element, is this really an endpoint?"; | 
| 456 | 456 | } | 
| @@ -458,53 +458,53 @@ discard block | ||
| 458 | 458 | |
| 459 | 459 | function startXML($parser, $name, $attr) | 
| 460 | 460 |  	{ | 
| 461 | -		if( $name == "sparql" ) { $this->looks_legit = true; } | |
| 462 | - if( $name == "result" ) | |
| 461 | +		if ($name == "sparql") { $this->looks_legit = true; } | |
| 462 | + if ($name == "result") | |
| 463 | 463 |  		{ | 
| 464 | 464 | $this->result = array(); | 
| 465 | 465 | } | 
| 466 | - if( $name == "binding" ) | |
| 466 | + if ($name == "binding") | |
| 467 | 467 |  		{ | 
| 468 | 468 | $this->part = $attr["name"]; | 
| 469 | 469 | } | 
| 470 | - if( $name == "uri" || $name == "bnode" ) | |
| 470 | + if ($name == "uri" || $name == "bnode") | |
| 471 | 471 |  		{ | 
| 472 | 472 | $this->part_type = $name; | 
| 473 | 473 | $this->chars = ""; | 
| 474 | 474 | } | 
| 475 | - if( $name == "literal" ) | |
| 475 | + if ($name == "literal") | |
| 476 | 476 |  		{ | 
| 477 | 477 | $this->part_type = "literal"; | 
| 478 | - if( isset( $attr["datatype"] ) ) | |
| 478 | + if (isset($attr["datatype"])) | |
| 479 | 479 |  			{ | 
| 480 | 480 | $this->part_datatype = $attr["datatype"]; | 
| 481 | 481 | } | 
| 482 | - if( isset( $attr["xml:lang"] ) ) | |
| 482 | + if (isset($attr["xml:lang"])) | |
| 483 | 483 |  			{ | 
| 484 | 484 | $this->part_lang = $attr["xml:lang"]; | 
| 485 | 485 | } | 
| 486 | 486 | $this->chars = ""; | 
| 487 | 487 | } | 
| 488 | - if( $name == "variable" ) | |
| 488 | + if ($name == "variable") | |
| 489 | 489 |  		{ | 
| 490 | 490 | $this->fields[] = $attr["name"]; | 
| 491 | 491 | } | 
| 492 | 492 | } | 
| 493 | 493 | |
| 494 | -	function endXML($parser, $name)	{ | |
| 495 | - if( $name == "result" ) | |
| 494 | +	function endXML($parser, $name) { | |
| 495 | + if ($name == "result") | |
| 496 | 496 |  		{ | 
| 497 | 497 | $this->rows[] = $this->result; | 
| 498 | 498 | $this->result = array(); | 
| 499 | 499 | } | 
| 500 | - if( $name == "uri" || $name == "bnode" || $name == "literal" ) | |
| 500 | + if ($name == "uri" || $name == "bnode" || $name == "literal") | |
| 501 | 501 |  		{ | 
| 502 | - $this->result[$this->part] = array( "type"=>$name, "value"=>$this->chars ); | |
| 503 | - if( isset( $this->part_lang ) ) | |
| 502 | +			$this->result[$this->part] = array("type"=>$name, "value"=>$this->chars); | |
| 503 | + if (isset($this->part_lang)) | |
| 504 | 504 |  			{ | 
| 505 | 505 | $this->result[$this->part]["lang"] = $this->part_lang; | 
| 506 | 506 | } | 
| 507 | - if( isset( $this->part_datatype ) ) | |
| 507 | + if (isset($this->part_datatype)) | |
| 508 | 508 |  			{ | 
| 509 | 509 | $this->result[$this->part]["datatype"] = $this->part_datatype; | 
| 510 | 510 | } | 
| @@ -513,7 +513,7 @@ discard block | ||
| 513 | 513 | } | 
| 514 | 514 | } | 
| 515 | 515 | |
| 516 | -	function charXML($parser, $data)	{ | |
| 516 | +	function charXML($parser, $data) { | |
| 517 | 517 | @$this->chars .= $data; | 
| 518 | 518 | } | 
| 519 | 519 | |
| @@ -527,28 +527,28 @@ discard block | ||
| 527 | 527 | function render_table() | 
| 528 | 528 |  	{ | 
| 529 | 529 | $html = "<table class='sparql-results'><tr>"; | 
| 530 | - foreach( $this->fields as $i=>$field ) | |
| 530 | + foreach ($this->fields as $i=>$field) | |
| 531 | 531 |  		{ | 
| 532 | 532 | $html .= "<th>?$field</th>"; | 
| 533 | 533 | } | 
| 534 | 534 | $html .= "</tr>"; | 
| 535 | - foreach( $this as $row ) | |
| 535 | + foreach ($this as $row) | |
| 536 | 536 |  		{ | 
| 537 | - $html.="<tr>"; | |
| 538 | - foreach( $row as $cell ) | |
| 537 | + $html .= "<tr>"; | |
| 538 | + foreach ($row as $cell) | |
| 539 | 539 |  			{ | 
| 540 | - $html .= "<td>".htmlspecialchars( $cell )."</td>"; | |
| 540 | + $html .= "<td>".htmlspecialchars($cell)."</td>"; | |
| 541 | 541 | } | 
| 542 | - $html.="</tr>"; | |
| 542 | + $html .= "</tr>"; | |
| 543 | 543 | } | 
| 544 | - $html.="</table> | |
| 544 | + $html .= "</table> | |
| 545 | 545 | <style> | 
| 546 | 546 |  table.sparql-results { border-collapse: collapse; } | 
| 547 | 547 |  table.sparql-results tr td { border: solid 1px #000 ; padding:4px;vertical-align:top} | 
| 548 | 548 |  table.sparql-results tr th { border: solid 1px #000 ; padding:4px;vertical-align:top ; background-color:#eee;} | 
| 549 | 549 | </style> | 
| 550 | 550 | "; | 
| 551 | - return $html;exit; | |
| 551 | + return $html; exit; | |
| 552 | 552 | } | 
| 553 | 553 | |
| 554 | 554 | } | 
| @@ -1,5 +1,10 @@ | ||
| 1 | 1 | <?php | 
| 2 | 2 |  class aprs { | 
| 3 | + | |
| 4 | + /** | |
| 5 | + * @param integer $n | |
| 6 | + * @param integer $s | |
| 7 | + */ | |
| 3 | 8 |      private function urshift($n, $s) { | 
| 4 | 9 | return ($n >= 0) ? ($n >> $s) : | 
| 5 | 10 | (($n & 0x7fffffff) >> $s) | | 
| @@ -1,8 +1,7 @@ discard block | ||
| 1 | 1 | <?php | 
| 2 | 2 |  class aprs { | 
| 3 | 3 |      private function urshift($n, $s) { | 
| 4 | - return ($n >= 0) ? ($n >> $s) : | |
| 5 | - (($n & 0x7fffffff) >> $s) | | |
| 4 | + return ($n >= 0) ? ($n >> $s) : (($n&0x7fffffff) >> $s)| | |
| 6 | 5 | (0x40000000 >> ($s - 1)); | 
| 7 | 6 | } | 
| 8 | 7 | |
| @@ -14,7 +13,7 @@ discard block | ||
| 14 | 13 | //$split_input = str_split($input); | 
| 15 | 14 | |
| 16 | 15 | /* Find the end of header checking for NULL bytes while doing it. */ | 
| 17 | - $splitpos = strpos($input,':'); | |
| 16 | + $splitpos = strpos($input, ':'); | |
| 18 | 17 | |
| 19 | 18 | /* Check that end was found and body has at least one byte. */ | 
| 20 | 19 |  	if ($splitpos == 0 || $splitpos + 1 == $input_len || $splitpos === FALSE) { | 
| @@ -23,28 +22,28 @@ discard block | ||
| 23 | 22 | } | 
| 24 | 23 | |
| 25 | 24 | /* Save header and body. */ | 
| 26 | - $body = substr($input,$splitpos+1,$input_len); | |
| 25 | + $body = substr($input, $splitpos + 1, $input_len); | |
| 27 | 26 | $body_len = strlen($body); | 
| 28 | - $header = substr($input,0,$splitpos); | |
| 27 | + $header = substr($input, 0, $splitpos); | |
| 29 | 28 | //$header_len = strlen($header); | 
| 30 | 29 | if ($debug) echo 'header : '.$header."\n"; | 
| 31 | 30 | |
| 32 | 31 | /* Parse source, target and path. */ | 
| 33 | 32 | //FLRDF0A52>APRS,qAS,LSTB | 
| 34 | -	if (preg_match('/^([A-Z0-9\\-]{1,9})>(.*)$/',$header,$matches)) { | |
| 33 | +	if (preg_match('/^([A-Z0-9\\-]{1,9})>(.*)$/', $header, $matches)) { | |
| 35 | 34 | $ident = $matches[1]; | 
| 36 | 35 | $all_elements = $matches[2]; | 
| 37 | 36 | if ($debug) echo 'ident : '.$ident."\n"; | 
| 38 | 37 | $result['ident'] = $ident; | 
| 39 | 38 | } else return false; | 
| 40 | -	$elements = explode(',',$all_elements); | |
| 39 | +	$elements = explode(',', $all_elements); | |
| 41 | 40 | $source = end($elements); | 
| 42 | 41 | $result['source'] = $source; | 
| 43 | 42 |  	foreach ($elements as $element) { | 
| 44 | -	    if (preg_match('/^([a-zA-Z0-9-]{1,9})([*]?)$/',$element)) { | |
| 43 | +	    if (preg_match('/^([a-zA-Z0-9-]{1,9})([*]?)$/', $element)) { | |
| 45 | 44 | //echo "ok"; | 
| 46 | 45 | if ($element == 'TCPIP*') return false; | 
| 47 | -	    } elseif (!preg_match('/^([0-9A-F]{32})$/',$element)) { | |
| 46 | +	    } elseif (!preg_match('/^([0-9A-F]{32})$/', $element)) { | |
| 48 | 47 | return false; | 
| 49 | 48 | } | 
| 50 | 49 | /* | 
| @@ -56,8 +55,8 @@ discard block | ||
| 56 | 55 | */ | 
| 57 | 56 | } | 
| 58 | 57 | // Check for Timestamp | 
| 59 | - $body_parse = substr($body,1); | |
| 60 | -	if (preg_match('/^([0-9]{2})([0-9]{2})([0-9]{2})([zh\\/])/',$body_parse,$matches)) { | |
| 58 | + $body_parse = substr($body, 1); | |
| 59 | +	if (preg_match('/^([0-9]{2})([0-9]{2})([0-9]{2})([zh\\/])/', $body_parse, $matches)) { | |
| 61 | 60 | $timestamp = $matches[0]; | 
| 62 | 61 |  	    if ($matches[4] == 'h') { | 
| 63 | 62 | $timestamp = strtotime($matches[1].':'.$matches[2].':'.$matches[3]); | 
| @@ -70,11 +69,11 @@ discard block | ||
| 70 | 69 | // This work or not ? | 
| 71 | 70 | $timestamp = strtotime($matches[1].' '.$matches[2].':'.$matches[3]); | 
| 72 | 71 | } | 
| 73 | - $body_parse = substr($body_parse,7); | |
| 72 | + $body_parse = substr($body_parse, 7); | |
| 74 | 73 | $result['timestamp'] = $timestamp; | 
| 75 | 74 | } | 
| 76 | 75 |  	if (strlen($body_parse) > 19) { | 
| 77 | -	    if (preg_match('/^([0-9]{2})([0-7 ][0-9 ]\\.[0-9 ]{2})([NnSs])(.)([0-9]{3})([0-7 ][0-9 ]\\.[0-9 ]{2})([EeWw])(.)/',$body_parse,$matches)) { | |
| 76 | +	    if (preg_match('/^([0-9]{2})([0-7 ][0-9 ]\\.[0-9 ]{2})([NnSs])(.)([0-9]{3})([0-7 ][0-9 ]\\.[0-9 ]{2})([EeWw])(.)/', $body_parse, $matches)) { | |
| 78 | 77 | // 4658.70N/00707.78Ez | 
| 79 | 78 | //print_r(str_split($body_parse)); | 
| 80 | 79 | |
| @@ -99,8 +98,8 @@ discard block | ||
| 99 | 98 | */ | 
| 100 | 99 | $latitude = $lat + floatval($lat_min)/60; | 
| 101 | 100 | $longitude = $lon + floatval($lon_min)/60; | 
| 102 | - if ($sind == 'S') $latitude = 0-$latitude; | |
| 103 | - if ($wind == 'W') $longitude = 0-$longitude; | |
| 101 | + if ($sind == 'S') $latitude = 0 - $latitude; | |
| 102 | + if ($wind == 'W') $longitude = 0 - $longitude; | |
| 104 | 103 | $result['latitude'] = $latitude; | 
| 105 | 104 | $result['longitude'] = $longitude; | 
| 106 | 105 | } | 
| @@ -108,17 +107,17 @@ discard block | ||
| 108 | 107 | $body_split = str_split($body_parse); | 
| 109 | 108 | $symbol_code = $body_split[18]; | 
| 110 | 109 |  		if ($symbol_code != '_') { | 
| 111 | - $body_parse = substr($body_parse,19); | |
| 110 | + $body_parse = substr($body_parse, 19); | |
| 112 | 111 | $body_parse_len = strlen($body_parse); | 
| 113 | 112 |  		    if ($body_parse_len >= 7) { | 
| 114 | 113 | |
| 115 | -		        if (preg_match('/^([0-9\\. ]{3})\\/([0-9\\. ]{3})/',$body_parse)) { | |
| 116 | - $course = substr($body_parse,0,3); | |
| 114 | +		        if (preg_match('/^([0-9\\. ]{3})\\/([0-9\\. ]{3})/', $body_parse)) { | |
| 115 | + $course = substr($body_parse, 0, 3); | |
| 117 | 116 | $tmp_s = intval($course); | 
| 118 | 117 | if ($tmp_s >= 1 && $tmp_s <= 360) $result['course'] = intval($course); | 
| 119 | - $speed = substr($body_parse,4,3); | |
| 118 | + $speed = substr($body_parse, 4, 3); | |
| 120 | 119 | $result['speed'] = round($speed*1.852); | 
| 121 | - $body_parse = substr($body_parse,7); | |
| 120 | + $body_parse = substr($body_parse, 7); | |
| 122 | 121 | } | 
| 123 | 122 | // Check PHGR, PHG, RNG | 
| 124 | 123 | } | 
| @@ -128,11 +127,11 @@ 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 | 133 | $result['altitude'] = $altitude; | 
| 135 | - $body_parse = substr($body_parse,strlen($matches[0])+1); | |
| 134 | + $body_parse = substr($body_parse, strlen($matches[0]) + 1); | |
| 136 | 135 | } | 
| 137 | 136 | } | 
| 138 | 137 | |
| @@ -143,34 +142,34 @@ discard block | ||
| 143 | 142 | } | 
| 144 | 143 | */ | 
| 145 | 144 | // DAO | 
| 146 | -		    if (preg_match('/^!([0-9A-Z]{3})/',$body_parse,$matches)) { | |
| 145 | +		    if (preg_match('/^!([0-9A-Z]{3})/', $body_parse, $matches)) { | |
| 147 | 146 | $dao = $matches[1]; | 
| 148 | -			    if (preg_match('/^([A-Z])([0-9]{2})/',$dao)) { | |
| 147 | +			    if (preg_match('/^([A-Z])([0-9]{2})/', $dao)) { | |
| 149 | 148 | $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; | |
| 149 | + $lat_off = (($dao_split[1]) - 48.0)*0.001/60.0; | |
| 150 | + $lon_off = (($dao_split[2]) - 48.0)*0.001/60.0; | |
| 152 | 151 | |
| 153 | 152 | if ($result['latitude'] < 0) $result['latitude'] -= $lat_off; | 
| 154 | 153 | else $result['latitude'] += $lat_off; | 
| 155 | 154 | if ($result['longitude'] < 0) $result['longitude'] -= $lon_off; | 
| 156 | 155 | else $result['longitude'] += $lon_off; | 
| 157 | 156 | } | 
| 158 | - $body_parse = substr($body_parse,6); | |
| 157 | + $body_parse = substr($body_parse, 6); | |
| 159 | 158 | } | 
| 160 | 159 | |
| 161 | 160 | // OGN comment | 
| 162 | 161 | // 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)) { | |
| 162 | +		    if (preg_match('/^id([0-9A-F]{8}) ([+-])([0-9]{3,4})fpm ([+-])([0-9.]{3,4})rot (.*)$/', $body_parse, $matches)) { | |
| 164 | 163 | $id = $matches[1]; | 
| 165 | 164 | //$mode = substr($id,0,2); | 
| 166 | - $address = substr($id,2); | |
| 165 | + $address = substr($id, 2); | |
| 167 | 166 | //print_r($matches); | 
| 168 | - $addressType = (intval(substr($id,0,2),16))&3; | |
| 167 | + $addressType = (intval(substr($id, 0, 2), 16))&3; | |
| 169 | 168 | if ($addressType == 0) $result['addresstype'] = "RANDOM"; | 
| 170 | 169 | elseif ($addressType == 1) $result['addresstype'] = "ICAO"; | 
| 171 | 170 | elseif ($addressType == 2) $result['addresstype'] = "FLARM"; | 
| 172 | 171 | elseif ($addressType == 3) $result['addresstype'] = "OGN"; | 
| 173 | - $aircraftType = $this->urshift(((intval(substr($id,0,2),16)) & 0b1111100),2); | |
| 172 | + $aircraftType = $this->urshift(((intval(substr($id, 0, 2), 16))&0b1111100), 2); | |
| 174 | 173 | $result['aircrafttype_code'] = $aircraftType; | 
| 175 | 174 | if ($aircraftType == 0) $result['aircrafttype'] = "UNKNOWN"; | 
| 176 | 175 | elseif ($aircraftType == 1) $result['aircrafttype'] = "GLIDER"; | 
| @@ -187,7 +186,7 @@ discard block | ||
| 187 | 186 | elseif ($aircraftType == 12) $result['aircrafttype'] = "AIRSHIP"; | 
| 188 | 187 | elseif ($aircraftType == 13) $result['aircrafttype'] = "UAV"; | 
| 189 | 188 | elseif ($aircraftType == 15) $result['aircrafttype'] = "STATIC_OBJECT"; | 
| 190 | - $stealth = (intval(substr($id,0,2), 16) & 0b10000000) != 0; | |
| 189 | + $stealth = (intval(substr($id, 0, 2), 16)&0b10000000) != 0; | |
| 191 | 190 | $result['stealth'] = $stealth; | 
| 192 | 191 | $result['address'] = $address; | 
| 193 | 192 | } | 
| @@ -196,40 +195,40 @@ discard block | ||
| 196 | 195 | $result['comment'] = $body_parse; | 
| 197 | 196 |  		} else { | 
| 198 | 197 | // parse weather | 
| 199 | - $body_parse = substr($body_parse,19); | |
| 198 | + $body_parse = substr($body_parse, 19); | |
| 200 | 199 | //$body_parse_len = strlen($body_parse); | 
| 201 | 200 | |
| 202 | -		    if (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})g([0-9 \\.]+)t(-{0,1}[0-9 \\.]+)/',$body_parse,$matches)) { | |
| 201 | +		    if (preg_match('/^_{0,1}([0-9 \\.\\-]{3})\\/([0-9 \\.]{3})g([0-9 \\.]+)t(-{0,1}[0-9 \\.]+)/', $body_parse, $matches)) { | |
| 203 | 202 | $result['wind_dir'] = $matches[1]; | 
| 204 | - $result['wind_speed'] = round($matches[2]*1.60934,1); | |
| 205 | - $result['wind_gust'] = round($matches[3]*1.60934,1); | |
| 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)) { | |
| 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)) { | |
| 209 | 208 | $result['wind_dir'] = $matches[1]; | 
| 210 | - $result['wind_speed'] = round($matches[2]*1.60934,1); | |
| 211 | - $result['wind_gust'] = round($matches[3]*1.60934,1); | |
| 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)) { | |
| 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)) { | |
| 215 | 214 | $result['wind_dir'] = $matches[1]; | 
| 216 | - $result['wind_speed'] = round($matches[2]*1.60934,1); | |
| 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)) { | |
| 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)) { | |
| 220 | 219 | $result['wind_dir'] = $matches[1]; | 
| 221 | - $result['wind_speed'] = round($matches[2]*1.60934,1); | |
| 222 | - $result['wind_gust'] = round($matches[3]*1.60934,1); | |
| 223 | - $body_parse = substr($body_parse,strlen($matches[0])+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); | |
| 224 | 223 | } | 
| 225 | -		    if (!isset($result['temp']) && strlen($body_parse) > 0 && preg_match('/^g([0-9]+)t(-?[0-9 \\.]{1,3})/',$body_parse,$matches)) { | |
| 226 | - $result['temp'] = round(5/9*(($matches[1])-32),1); | |
| 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); | |
| 227 | 226 | } | 
| 228 | 227 | } | 
| 229 | 228 | } | 
| 230 | 229 | } | 
| 231 | - if (isset($result['latitude'])) $result['latitude'] = round($result['latitude'],4); | |
| 232 | - if (isset($result['longitude'])) $result['longitude'] = round($result['longitude'],4); | |
| 230 | + if (isset($result['latitude'])) $result['latitude'] = round($result['latitude'], 4); | |
| 231 | + if (isset($result['longitude'])) $result['longitude'] = round($result['longitude'], 4); | |
| 233 | 232 | //print_r($result); | 
| 234 | 233 | return $result; | 
| 235 | 234 | } | 
| @@ -77,7 +77,7 @@ | ||
| 77 | 77 | /** | 
| 78 | 78 | * Returns list of available locales | 
| 79 | 79 | * | 
| 80 | - * @return array | |
| 80 | + * @return string[] | |
| 81 | 81 | */ | 
| 82 | 82 | public function listLocaleDir() | 
| 83 | 83 |  	{ | 
| @@ -24,54 +24,54 @@ discard block | ||
| 24 | 24 | } | 
| 25 | 25 | |
| 26 | 26 |  class Language { | 
| 27 | -	public $all_languages = array('ar_SA' => array('العَرَبِيَّةُ',	'ar',	'arabic'), | |
| 28 | -				'bg_BG' => array('Български',		'bg',	'bulgarian'), | |
| 29 | -				'id_ID' => array('Bahasa Indonesia',	'id',	'indonesian'), | |
| 30 | -				'ms_MY' => array('Bahasa Melayu',	'ms',	'malay'), | |
| 31 | -				'ca_ES' => array('Català',		'ca',	'catalan'), // ca_CA | |
| 32 | -				'cs_CZ' => array('Čeština',		'cs',	'czech'), | |
| 33 | -				'de_DE' => array('Deutsch',		'de',	'german'), | |
| 34 | -				'da_DK' => array('Dansk',		'da',	'danish')     , // dk_DK | |
| 35 | -				'et_EE' => array('Eesti',		'et',	'estonian'), // ee_ET | |
| 36 | -				'en_GB' => array('English',		'en',	'english'), | |
| 37 | -				'en_US' => array('English (US)',	'en',	'english'), | |
| 38 | -				'es_AR' => array('Español (Argentina)',	'es',	'spanish'), | |
| 39 | -				'es_CO' => array('Español (Colombia)',	'es',	'spanish'), | |
| 40 | -				'es_ES' => array('Español (España)',	'es',	'spanish'), | |
| 41 | -				'es_419' => array('Español (América Latina)',	'es',	'spanish'), | |
| 42 | -				'es_MX' => array('Español (Mexico)',	'es',	'spanish'), | |
| 43 | -				'es_VE' => array('Español (Venezuela)',	'es',	'spanish'), | |
| 44 | -				'eu_ES' => array('Euskara',		'en',	'basque'), | |
| 45 | -				'fr_FR' => array('Français',		'fr',	'french'), | |
| 46 | -				'gl_ES' => array('Galego',		'gl',	'galician'), | |
| 47 | -				'el_GR' => array('Ελληνικά',		'el',	'greek'), // el_EL | |
| 48 | -				'he_IL' => array('עברית',		'he',	'hebrew'), // he_HE | |
| 49 | -				'hr_HR' => array('Hrvatski',		'hr',	'croatian'), | |
| 50 | -				'hu_HU' => array('Magyar',		'hu',	'hungarian'), | |
| 51 | -				'it_IT' => array('Italiano',		'it',	'italian'), | |
| 52 | -				'lv_LV' => array('Latviešu',		'lv',	'latvian'), | |
| 53 | -				'lt_LT' => array('Lietuvių',		'lt',	'lithuanian'), | |
| 54 | -				'nl_NL' => array('Nederlands',		'nl',	'dutch'), | |
| 55 | -				'nb_NO' => array('Norsk (Bokmål)',	'nb',	'norwegian'), // no_NB | |
| 56 | -				'nn_NO' => array('Norsk (Nynorsk)',	'nn',	'norwegian'), // no_NN | |
| 57 | -				'fa_IR' => array('فارسی',		'fa',	'persian'), | |
| 58 | -				'pl_PL' => array('Polski',		'pl',	'polish'), | |
| 59 | -				'pt_PT' => array('Português',		'pt',	'portuguese'), | |
| 60 | -				'pt_BR' => array('Português do Brasil',	'pt',	'brazilian portuguese'), | |
| 61 | -				'ro_RO' => array('Română',		'en',	'romanian'), | |
| 62 | -				'ru_RU' => array('Pусский',		'ru',	'russian'), | |
| 63 | -				'sk_SK' => array('Slovenčina',		'sk',	'slovak'), | |
| 64 | -				'sl_SI' => array('Slovenščina',		'sl',	'slovenian slovene'), | |
| 65 | -				'sr_RS' => array('Srpski',		'sr',	'serbian'), | |
| 66 | -				'fi_FI' => array('Suomi',		'fi',	'finish'), | |
| 67 | -				'sv_SE' => array('Svenska',		'sv',	'swedish'), | |
| 68 | -				'vi_VN' => array('Tiếng Việt',		'vi',	'vietnamese'), | |
| 69 | -				'th_TH' => array('ภาษาไทย',		'th',	'thai'), | |
| 70 | -				'tr_TR' => array('Türkçe',		'tr',	'turkish'), | |
| 71 | -				'uk_UA' => array('Українська',		'en',	'ukrainian'), // ua_UA | |
| 72 | -				'ja_JP' => array('日本語',		'ja',	'japanese'), | |
| 73 | -				'zh_CN' => array('简体中文',		'zh',	'chinese'), | |
| 74 | -				'zh_TW' => array('繁體中文',		'zh',	'chinese') | |
| 27 | +	public $all_languages = array('ar_SA' => array('العَرَبِيَّةُ', 'ar', 'arabic'), | |
| 28 | +				'bg_BG' => array('Български', 'bg', 'bulgarian'), | |
| 29 | +				'id_ID' => array('Bahasa Indonesia', 'id', 'indonesian'), | |
| 30 | +				'ms_MY' => array('Bahasa Melayu', 'ms', 'malay'), | |
| 31 | +				'ca_ES' => array('Català', 'ca', 'catalan'), // ca_CA | |
| 32 | +				'cs_CZ' => array('Čeština', 'cs', 'czech'), | |
| 33 | +				'de_DE' => array('Deutsch', 'de', 'german'), | |
| 34 | +				'da_DK' => array('Dansk', 'da', 'danish'), // dk_DK | |
| 35 | +				'et_EE' => array('Eesti', 'et', 'estonian'), // ee_ET | |
| 36 | +				'en_GB' => array('English', 'en', 'english'), | |
| 37 | +				'en_US' => array('English (US)', 'en', 'english'), | |
| 38 | +				'es_AR' => array('Español (Argentina)', 'es', 'spanish'), | |
| 39 | +				'es_CO' => array('Español (Colombia)', 'es', 'spanish'), | |
| 40 | +				'es_ES' => array('Español (España)', 'es', 'spanish'), | |
| 41 | +				'es_419' => array('Español (América Latina)', 'es', 'spanish'), | |
| 42 | +				'es_MX' => array('Español (Mexico)', 'es', 'spanish'), | |
| 43 | +				'es_VE' => array('Español (Venezuela)', 'es', 'spanish'), | |
| 44 | +				'eu_ES' => array('Euskara', 'en', 'basque'), | |
| 45 | +				'fr_FR' => array('Français', 'fr', 'french'), | |
| 46 | +				'gl_ES' => array('Galego', 'gl', 'galician'), | |
| 47 | +				'el_GR' => array('Ελληνικά', 'el', 'greek'), // el_EL | |
| 48 | +				'he_IL' => array('עברית', 'he', 'hebrew'), // he_HE | |
| 49 | +				'hr_HR' => array('Hrvatski', 'hr', 'croatian'), | |
| 50 | +				'hu_HU' => array('Magyar', 'hu', 'hungarian'), | |
| 51 | +				'it_IT' => array('Italiano', 'it', 'italian'), | |
| 52 | +				'lv_LV' => array('Latviešu', 'lv', 'latvian'), | |
| 53 | +				'lt_LT' => array('Lietuvių', 'lt', 'lithuanian'), | |
| 54 | +				'nl_NL' => array('Nederlands', 'nl', 'dutch'), | |
| 55 | +				'nb_NO' => array('Norsk (Bokmål)', 'nb', 'norwegian'), // no_NB | |
| 56 | +				'nn_NO' => array('Norsk (Nynorsk)', 'nn', 'norwegian'), // no_NN | |
| 57 | +				'fa_IR' => array('فارسی', 'fa', 'persian'), | |
| 58 | +				'pl_PL' => array('Polski', 'pl', 'polish'), | |
| 59 | +				'pt_PT' => array('Português', 'pt', 'portuguese'), | |
| 60 | +				'pt_BR' => array('Português do Brasil', 'pt', 'brazilian portuguese'), | |
| 61 | +				'ro_RO' => array('Română', 'en', 'romanian'), | |
| 62 | +				'ru_RU' => array('Pусский', 'ru', 'russian'), | |
| 63 | +				'sk_SK' => array('Slovenčina', 'sk', 'slovak'), | |
| 64 | +				'sl_SI' => array('Slovenščina', 'sl', 'slovenian slovene'), | |
| 65 | +				'sr_RS' => array('Srpski', 'sr', 'serbian'), | |
| 66 | +				'fi_FI' => array('Suomi', 'fi', 'finish'), | |
| 67 | +				'sv_SE' => array('Svenska', 'sv', 'swedish'), | |
| 68 | +				'vi_VN' => array('Tiếng Việt', 'vi', 'vietnamese'), | |
| 69 | +				'th_TH' => array('ภาษาไทย', 'th', 'thai'), | |
| 70 | +				'tr_TR' => array('Türkçe', 'tr', 'turkish'), | |
| 71 | +				'uk_UA' => array('Українська', 'en', 'ukrainian'), // ua_UA | |
| 72 | +				'ja_JP' => array('日本語', 'ja', 'japanese'), | |
| 73 | +				'zh_CN' => array('简体中文', 'zh', 'chinese'), | |
| 74 | +				'zh_TW' => array('繁體中文', 'zh', 'chinese') | |
| 75 | 75 | ); | 
| 76 | 76 | |
| 77 | 77 | /** | 
| @@ -99,7 +99,7 @@ discard block | ||
| 99 | 99 | |
| 100 | 100 | public function getLocale($locale) | 
| 101 | 101 |  	{ | 
| 102 | - return array($locale,$this->all_languages[$locale][1],$this->all_languages[$locale][2],$locale.'.utf8',$locale.'.UTF8'); | |
| 102 | + return array($locale, $this->all_languages[$locale][1], $this->all_languages[$locale][2], $locale.'.utf8', $locale.'.UTF8'); | |
| 103 | 103 | } | 
| 104 | 104 | |
| 105 | 105 | /** | 
| @@ -58,6 +58,10 @@ discard block | ||
| 58 | 58 | } else return $ident; | 
| 59 | 59 | } | 
| 60 | 60 | |
| 61 | + /** | |
| 62 | + * @param string $correct_ident | |
| 63 | + * @param string $source | |
| 64 | + */ | |
| 61 | 65 |         public function addOperator($ident,$correct_ident,$source) { | 
| 62 | 66 | $query = "INSERT INTO translation (Operator,Operator_correct,Source) VALUES (:ident,:correct_ident,:source)"; | 
| 63 | 67 |                  $query_values = array(':ident' => $ident,':correct_ident' => $correct_ident, ':source' => $source); | 
| @@ -69,6 +73,10 @@ discard block | ||
| 69 | 73 | } | 
| 70 | 74 | } | 
| 71 | 75 | |
| 76 | + /** | |
| 77 | + * @param string $correct_ident | |
| 78 | + * @param string $source | |
| 79 | + */ | |
| 72 | 80 |         public function updateOperator($ident,$correct_ident,$source) { | 
| 73 | 81 | $query = "UPDATE translation SET Operator_correct = :correct_ident,Source = :source WHERE Operator = :ident"; | 
| 74 | 82 |                  $query_values = array(':ident' => $ident,':correct_ident' => $correct_ident, ':source' => $source); | 
| @@ -31,12 +31,12 @@ discard block | ||
| 31 | 31 | } else return $ident; | 
| 32 | 32 | } else return $ident; | 
| 33 | 33 |          if ($airline_icao == 'AF') { | 
| 34 | -            if (filter_var(substr($ident,2),FILTER_VALIDATE_INT,array("flags"=>FILTER_FLAG_ALLOW_OCTAL))) $icao = $ident; | |
| 35 | - else $icao = 'AFR'.ltrim(substr($ident,2),'0'); | |
| 34 | +            if (filter_var(substr($ident, 2), FILTER_VALIDATE_INT, array("flags"=>FILTER_FLAG_ALLOW_OCTAL))) $icao = $ident; | |
| 35 | + else $icao = 'AFR'.ltrim(substr($ident, 2), '0'); | |
| 36 | 36 |          } else { | 
| 37 | 37 | $identicao = $Spotter->getAllAirlineInfo($airline_icao); | 
| 38 | 38 |              if (isset($identicao[0])) { | 
| 39 | - $icao = $identicao[0]['icao'].ltrim(substr($ident,2),'0'); | |
| 39 | + $icao = $identicao[0]['icao'].ltrim(substr($ident, 2), '0'); | |
| 40 | 40 | } else $icao = $ident; | 
| 41 | 41 | } | 
| 42 | 42 | return $icao; | 
| @@ -49,7 +49,7 @@ discard block | ||
| 49 | 49 |                   try { | 
| 50 | 50 | $sth = $this->db->prepare($query); | 
| 51 | 51 | $sth->execute($query_values); | 
| 52 | -                } catch(PDOException $e) { | |
| 52 | +                } catch (PDOException $e) { | |
| 53 | 53 | return "error : ".$e->getMessage(); | 
| 54 | 54 | } | 
| 55 | 55 | $row = $sth->fetch(PDO::FETCH_ASSOC); | 
| @@ -58,29 +58,29 @@ discard block | ||
| 58 | 58 | } else return $ident; | 
| 59 | 59 | } | 
| 60 | 60 | |
| 61 | -       public function addOperator($ident,$correct_ident,$source) { | |
| 61 | +       public function addOperator($ident, $correct_ident, $source) { | |
| 62 | 62 | $query = "INSERT INTO translation (Operator,Operator_correct,Source) VALUES (:ident,:correct_ident,:source)"; | 
| 63 | -                $query_values = array(':ident' => $ident,':correct_ident' => $correct_ident, ':source' => $source); | |
| 63 | +                $query_values = array(':ident' => $ident, ':correct_ident' => $correct_ident, ':source' => $source); | |
| 64 | 64 |                   try { | 
| 65 | 65 | $sth = $this->db->prepare($query); | 
| 66 | 66 | $sth->execute($query_values); | 
| 67 | -                } catch(PDOException $e) { | |
| 67 | +                } catch (PDOException $e) { | |
| 68 | 68 | return "error : ".$e->getMessage(); | 
| 69 | 69 | } | 
| 70 | 70 | } | 
| 71 | 71 | |
| 72 | -       public function updateOperator($ident,$correct_ident,$source) { | |
| 72 | +       public function updateOperator($ident, $correct_ident, $source) { | |
| 73 | 73 | $query = "UPDATE translation SET Operator_correct = :correct_ident,Source = :source WHERE Operator = :ident"; | 
| 74 | -                $query_values = array(':ident' => $ident,':correct_ident' => $correct_ident, ':source' => $source); | |
| 74 | +                $query_values = array(':ident' => $ident, ':correct_ident' => $correct_ident, ':source' => $source); | |
| 75 | 75 |                   try { | 
| 76 | 76 | $sth = $this->db->prepare($query); | 
| 77 | 77 | $sth->execute($query_values); | 
| 78 | -                } catch(PDOException $e) { | |
| 78 | +                } catch (PDOException $e) { | |
| 79 | 79 | return "error : ".$e->getMessage(); | 
| 80 | 80 | } | 
| 81 | 81 | } | 
| 82 | 82 | |
| 83 | -        public function checkTranslation($ident,$web = false) { | |
| 83 | +        public function checkTranslation($ident, $web = false) { | |
| 84 | 84 | global $globalTranslationSources, $globalTranslationFetch; | 
| 85 | 85 |      	    //if (!isset($globalTranslationSources)) $globalTranslationSources = array('planefinder'); | 
| 86 | 86 | $globalTranslationSources = array(); | 
| @@ -118,6 +118,9 @@ discard block | ||
| 118 | 118 | ); | 
| 119 | 119 | } | 
| 120 | 120 | |
| 121 | + /** | |
| 122 | + * @param boolean $force | |
| 123 | + */ | |
| 121 | 124 |    static function geosInstalled($force = NULL) {
 | 
| 122 | 125 | static $geos_installed = NULL; | 
| 123 | 126 | if ($force !== NULL) $geos_installed = $force; | 
| @@ -222,6 +225,10 @@ discard block | ||
| 222 | 225 | |
| 223 | 226 | // Detect a format given a value. This function is meant to be SPEEDY. | 
| 224 | 227 | // It could make a mistake in XML detection if you are mixing or using namespaces in weird ways (ie, KML inside an RSS feed) | 
| 228 | + | |
| 229 | + /** | |
| 230 | + * @return string | |
| 231 | + */ | |
| 225 | 232 |    static function detectFormat(&$input) {
 | 
| 226 | 233 |      $mem = fopen('php://memory', 'r+');
 | 
| 227 | 234 | fwrite($mem, $input, 11); // Write 11 bytes - we can detect the vast majority of formats in the first 11 bytes | 
| @@ -91,7 +91,7 @@ discard block | ||
| 91 | 91 | } | 
| 92 | 92 | |
| 93 | 93 |    static function getAdapterMap() {
 | 
| 94 | - return array ( | |
| 94 | + return array( | |
| 95 | 95 | 'wkt' => 'WKT', | 
| 96 | 96 | 'ewkt' => 'EWKT', | 
| 97 | 97 | 'wkb' => 'WKB', | 
| @@ -154,8 +154,8 @@ discard block | ||
| 154 | 154 | |
| 155 | 155 | // If the geometry cannot even theoretically be reduced more, then pass it back | 
| 156 | 156 |      if (gettype($geometry) == 'object') {
 | 
| 157 | -      $passbacks = array('Point','LineString','Polygon');
 | |
| 158 | -      if (in_array($geometry->geometryType(),$passbacks)) {
 | |
| 157 | +      $passbacks = array('Point', 'LineString', 'Polygon');
 | |
| 158 | +      if (in_array($geometry->geometryType(), $passbacks)) {
 | |
| 159 | 159 | return $geometry; | 
| 160 | 160 | } | 
| 161 | 161 | } | 
| @@ -163,8 +163,8 @@ discard block | ||
| 163 | 163 | // If it is a mutlti-geometry, check to see if it just has one member | 
| 164 | 164 | // If it does, then pass the member, if not, then just pass back the geometry | 
| 165 | 165 |      if (gettype($geometry) == 'object') {
 | 
| 166 | -      $simple_collections = array('MultiPoint','MultiLineString','MultiPolygon');
 | |
| 167 | -      if (in_array(get_class($geometry),$passbacks)) {
 | |
| 166 | +      $simple_collections = array('MultiPoint', 'MultiLineString', 'MultiPolygon');
 | |
| 167 | +      if (in_array(get_class($geometry), $passbacks)) {
 | |
| 168 | 168 | $components = $geometry->getComponents(); | 
| 169 | 169 |          if (count($components) == 1) {
 | 
| 170 | 170 | return $components[0]; | 
| @@ -183,7 +183,7 @@ discard block | ||
| 183 | 183 | $geometries = array(); | 
| 184 | 184 | $geom_types = array(); | 
| 185 | 185 | |
| 186 | -    $collections = array('MultiPoint','MultiLineString','MultiPolygon','GeometryCollection');
 | |
| 186 | +    $collections = array('MultiPoint', 'MultiLineString', 'MultiPolygon', 'GeometryCollection');
 | |
| 187 | 187 | |
| 188 | 188 |      foreach ($geometry as $item) {
 | 
| 189 | 189 |        if ($item) {
 | 
| @@ -113,7 +113,6 @@ discard block | ||
| 113 | 113 | * Serializes an object into a geojson string | 
| 114 | 114 | * | 
| 115 | 115 | * | 
| 116 | - * @param Geometry $obj The object to serialize | |
| 117 | 116 | * | 
| 118 | 117 | * @return string The GeoJSON string | 
| 119 | 118 | */ | 
| @@ -126,6 +125,9 @@ discard block | ||
| 126 | 125 | } | 
| 127 | 126 | } | 
| 128 | 127 | |
| 128 | + /** | |
| 129 | + * @param Geometry $geometry | |
| 130 | + */ | |
| 129 | 131 |    public function getArray($geometry) { | 
| 130 | 132 |      if ($geometry->getGeomType() == 'GeometryCollection') { | 
| 131 | 133 | $component_array = array(); | 
| @@ -50,7 +50,7 @@ | ||
| 50 | 50 |      if ($type == 'GeometryCollection') { | 
| 51 | 51 | return $this->objToGeometryCollection($obj); | 
| 52 | 52 | } | 
| 53 | - $method = 'arrayTo' . $type; | |
| 53 | + $method = 'arrayTo'.$type; | |
| 54 | 54 | return $this->$method($obj->coordinates); | 
| 55 | 55 | } | 
| 56 | 56 | |
| @@ -18,8 +18,6 @@ discard block | ||
| 18 | 18 | /** | 
| 19 | 19 | * Read GeoRSS string into geometry objects | 
| 20 | 20 | * | 
| 21 | - * @param string $georss - an XML feed containing geoRSS | |
| 22 | - * | |
| 23 | 21 | * @return Geometry|GeometryCollection | 
| 24 | 22 | */ | 
| 25 | 23 |    public function read($gpx) {
 | 
| @@ -80,6 +78,9 @@ discard block | ||
| 80 | 78 | return geoPHP::geometryReduce($geometries); | 
| 81 | 79 | } | 
| 82 | 80 | |
| 81 | + /** | |
| 82 | + * @param string $string | |
| 83 | + */ | |
| 83 | 84 |    protected function getPointsFromCoords($string) {
 | 
| 84 | 85 | $coords = array(); | 
| 85 | 86 |      $latlon = explode(' ',$string);
 | 
| @@ -44,21 +44,21 @@ discard block | ||
| 44 | 44 |    public function geomFromText($text) {
 | 
| 45 | 45 | // Change to lower-case, strip all CDATA, and de-namespace | 
| 46 | 46 | $text = strtolower($text); | 
| 47 | -    $text = preg_replace('/<!\[cdata\[(.*?)\]\]>/s','',$text);
 | |
| 47 | +    $text = preg_replace('/<!\[cdata\[(.*?)\]\]>/s', '', $text);
 | |
| 48 | 48 | |
| 49 | 49 | // Load into DOMDOcument | 
| 50 | 50 | $xmlobj = new DOMDocument(); | 
| 51 | 51 | @$xmlobj->loadXML($text); | 
| 52 | 52 |      if ($xmlobj === false) {
 | 
| 53 | -      throw new Exception("Invalid GeoRSS: ". $text);
 | |
| 53 | +      throw new Exception("Invalid GeoRSS: ".$text);
 | |
| 54 | 54 | } | 
| 55 | 55 | |
| 56 | 56 | $this->xmlobj = $xmlobj; | 
| 57 | 57 |      try {
 | 
| 58 | 58 | $geom = $this->geomFromXML(); | 
| 59 | -    } catch(InvalidText $e) {
 | |
| 60 | -        throw new Exception("Cannot Read Geometry From GeoRSS: ". $text);
 | |
| 61 | -    } catch(Exception $e) {
 | |
| 59 | +    } catch (InvalidText $e) {
 | |
| 60 | +        throw new Exception("Cannot Read Geometry From GeoRSS: ".$text);
 | |
| 61 | +    } catch (Exception $e) {
 | |
| 62 | 62 | throw $e; | 
| 63 | 63 | } | 
| 64 | 64 | |
| @@ -82,9 +82,9 @@ discard block | ||
| 82 | 82 | |
| 83 | 83 |    protected function getPointsFromCoords($string) {
 | 
| 84 | 84 | $coords = array(); | 
| 85 | -    $latlon = explode(' ',$string);
 | |
| 85 | +    $latlon = explode(' ', $string);
 | |
| 86 | 86 |      foreach ($latlon as $key => $item) {
 | 
| 87 | -      if (!($key % 2)) {
 | |
| 87 | +      if (!($key%2)) {
 | |
| 88 | 88 | // It's a latitude | 
| 89 | 89 | $lat = $item; | 
| 90 | 90 | } | 
| @@ -139,7 +139,7 @@ discard block | ||
| 139 | 139 | $polygons = array(); | 
| 140 | 140 |      $box_elements = $this->xmlobj->getElementsByTagName('box');
 | 
| 141 | 141 |      foreach ($box_elements as $box) {
 | 
| 142 | -      $parts = explode(' ',trim($box->firstChild->nodeValue));
 | |
| 142 | +      $parts = explode(' ', trim($box->firstChild->nodeValue));
 | |
| 143 | 143 | $components = array( | 
| 144 | 144 | new Point($parts[3], $parts[2]), | 
| 145 | 145 | new Point($parts[3], $parts[0]), | 
| @@ -159,7 +159,7 @@ discard block | ||
| 159 | 159 | $points = array(); | 
| 160 | 160 |      $circle_elements = $this->xmlobj->getElementsByTagName('circle');
 | 
| 161 | 161 |      foreach ($circle_elements as $circle) {
 | 
| 162 | -      $parts = explode(' ',trim($circle->firstChild->nodeValue));
 | |
| 162 | +      $parts = explode(' ', trim($circle->firstChild->nodeValue));
 | |
| 163 | 163 | $points[] = new Point($parts[1], $parts[0]); | 
| 164 | 164 | } | 
| 165 | 165 | return $points; | 
| @@ -196,7 +196,7 @@ discard block | ||
| 196 | 196 | $output = '<'.$this->nss.'line>'; | 
| 197 | 197 |      foreach ($geom->getComponents() as $k => $point) {
 | 
| 198 | 198 | $output .= $point->getY().' '.$point->getX(); | 
| 199 | - if ($k < ($geom->numGeometries() -1)) $output .= ' '; | |
| 199 | + if ($k < ($geom->numGeometries() - 1)) $output .= ' '; | |
| 200 | 200 | } | 
| 201 | 201 | $output .= '</'.$this->nss.'line>'; | 
| 202 | 202 | return $output; | 
| @@ -207,7 +207,7 @@ discard block | ||
| 207 | 207 | $exterior_ring = $geom->exteriorRing(); | 
| 208 | 208 |      foreach ($exterior_ring->getComponents() as $k => $point) {
 | 
| 209 | 209 | $output .= $point->getY().' '.$point->getX(); | 
| 210 | - if ($k < ($exterior_ring->numGeometries() -1)) $output .= ' '; | |
| 210 | + if ($k < ($exterior_ring->numGeometries() - 1)) $output .= ' '; | |
| 211 | 211 | } | 
| 212 | 212 | $output .= '</'.$this->nss.'polygon>'; | 
| 213 | 213 | return $output; | 
| @@ -42,6 +42,9 @@ | ||
| 42 | 42 | return '<'.$this->nss.'gpx creator="geoPHP" version="1.0">'.$this->geometryToGPX($geometry).'</'.$this->nss.'gpx>'; | 
| 43 | 43 | } | 
| 44 | 44 | |
| 45 | + /** | |
| 46 | + * @param string $text | |
| 47 | + */ | |
| 45 | 48 |    public function geomFromText($text) {
 | 
| 46 | 49 | // Change to lower-case and strip all CDATA | 
| 47 | 50 | $text = strtolower($text); | 
| @@ -45,21 +45,21 @@ discard block | ||
| 45 | 45 |    public function geomFromText($text) {
 | 
| 46 | 46 | // Change to lower-case and strip all CDATA | 
| 47 | 47 | $text = strtolower($text); | 
| 48 | -    $text = preg_replace('/<!\[cdata\[(.*?)\]\]>/s','',$text);
 | |
| 48 | +    $text = preg_replace('/<!\[cdata\[(.*?)\]\]>/s', '', $text);
 | |
| 49 | 49 | |
| 50 | 50 | // Load into DOMDocument | 
| 51 | 51 | $xmlobj = new DOMDocument(); | 
| 52 | 52 | @$xmlobj->loadXML($text); | 
| 53 | 53 |      if ($xmlobj === false) {
 | 
| 54 | -      throw new Exception("Invalid GPX: ". $text);
 | |
| 54 | +      throw new Exception("Invalid GPX: ".$text);
 | |
| 55 | 55 | } | 
| 56 | 56 | |
| 57 | 57 | $this->xmlobj = $xmlobj; | 
| 58 | 58 |      try {
 | 
| 59 | 59 | $geom = $this->geomFromXML(); | 
| 60 | -    } catch(InvalidText $e) {
 | |
| 61 | -        throw new Exception("Cannot Read Geometry From GPX: ". $text);
 | |
| 62 | -    } catch(Exception $e) {
 | |
| 60 | +    } catch (InvalidText $e) {
 | |
| 61 | +        throw new Exception("Cannot Read Geometry From GPX: ".$text);
 | |
| 62 | +    } catch (Exception $e) {
 | |
| 63 | 63 | throw $e; | 
| 64 | 64 | } | 
| 65 | 65 | |
| @@ -112,7 +112,7 @@ discard block | ||
| 112 | 112 | $components[] = new Point($lon, $lat); | 
| 113 | 113 | } | 
| 114 | 114 | } | 
| 115 | -      if ($components) {$lines[] = new LineString($components);}
 | |
| 115 | +      if ($components) {$lines[] = new LineString($components); }
 | |
| 116 | 116 | } | 
| 117 | 117 | return $lines; | 
| 118 | 118 | } |