@@ -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(); |
@@ -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; |
@@ -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) | |
@@ -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 | } |
@@ -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 | { |
@@ -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 | } |
@@ -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); |
@@ -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 | } |
@@ -56,7 +65,9 @@ discard block |
||
56 | 65 | $sth->closeCursor(); |
57 | 66 | if (count($row) > 0) { |
58 | 67 | return $row['operator_correct']; |
59 | - } else return $ident; |
|
68 | + } else { |
|
69 | + return $ident; |
|
70 | + } |
|
60 | 71 | } |
61 | 72 | |
62 | 73 | public function addOperator($ident,$correct_ident,$source) { |
@@ -85,7 +96,9 @@ discard block |
||
85 | 96 | global $globalTranslationSources, $globalTranslationFetch; |
86 | 97 | //if (!isset($globalTranslationSources)) $globalTranslationSources = array('planefinder'); |
87 | 98 | $globalTranslationSources = array(); |
88 | - if (!isset($globalTranslationFetch)) $globalTranslationFetch = TRUE; |
|
99 | + if (!isset($globalTranslationFetch)) { |
|
100 | + $globalTranslationFetch = TRUE; |
|
101 | + } |
|
89 | 102 | //echo "Check Translation for ".$ident."..."; |
90 | 103 | $correct = $this->getOperator($ident); |
91 | 104 | if ($correct != '' && $correct != $ident) { |
@@ -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 |
@@ -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 |
@@ -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(); |
@@ -120,8 +120,7 @@ discard block |
||
120 | 120 | public function write(Geometry $geometry, $return_array = FALSE) { |
121 | 121 | if ($return_array) { |
122 | 122 | return $this->getArray($geometry); |
123 | - } |
|
124 | - else { |
|
123 | + } else { |
|
125 | 124 | return json_encode($this->getArray($geometry)); |
126 | 125 | } |
127 | 126 | } |
@@ -139,11 +138,12 @@ discard block |
||
139 | 138 | 'type'=> 'GeometryCollection', |
140 | 139 | 'geometries'=> $component_array, |
141 | 140 | ); |
142 | - } |
|
143 | - else return array( |
|
141 | + } else { |
|
142 | + return array( |
|
144 | 143 | 'type'=> $geometry->getGeomType(), |
145 | 144 | 'coordinates'=> $geometry->asArray(), |
146 | 145 | ); |
146 | + } |
|
147 | 147 | } |
148 | 148 | } |
149 | 149 |
@@ -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); |
@@ -87,8 +87,7 @@ discard block |
||
87 | 87 | if (!($key % 2)) { |
88 | 88 | // It's a latitude |
89 | 89 | $lat = $item; |
90 | - } |
|
91 | - else { |
|
90 | + } else { |
|
92 | 91 | // It's a longitude |
93 | 92 | $lon = $item; |
94 | 93 | $coords[] = new Point($lon, $lat); |
@@ -125,8 +124,7 @@ discard block |
||
125 | 124 | $points = $this->getPointsFromCoords(trim($poly->firstChild->nodeValue)); |
126 | 125 | $exterior_ring = new LineString($points); |
127 | 126 | $polygons[] = new Polygon(array($exterior_ring)); |
128 | - } |
|
129 | - else { |
|
127 | + } else { |
|
130 | 128 | // It's an EMPTY polygon |
131 | 129 | $polygons[] = new Polygon(); |
132 | 130 | } |
@@ -196,7 +194,9 @@ discard block |
||
196 | 194 | $output = '<'.$this->nss.'line>'; |
197 | 195 | foreach ($geom->getComponents() as $k => $point) { |
198 | 196 | $output .= $point->getY().' '.$point->getX(); |
199 | - if ($k < ($geom->numGeometries() -1)) $output .= ' '; |
|
197 | + if ($k < ($geom->numGeometries() -1)) { |
|
198 | + $output .= ' '; |
|
199 | + } |
|
200 | 200 | } |
201 | 201 | $output .= '</'.$this->nss.'line>'; |
202 | 202 | return $output; |
@@ -207,7 +207,9 @@ 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)) { |
|
211 | + $output .= ' '; |
|
212 | + } |
|
211 | 213 | } |
212 | 214 | $output .= '</'.$this->nss.'polygon>'; |
213 | 215 | 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); |
@@ -34,7 +34,9 @@ |
||
34 | 34 | * @return string The GPX string representation of the input geometries |
35 | 35 | */ |
36 | 36 | public function write(Geometry $geometry, $namespace = FALSE) { |
37 | - if ($geometry->isEmpty()) return NULL; |
|
37 | + if ($geometry->isEmpty()) { |
|
38 | + return NULL; |
|
39 | + } |
|
38 | 40 | if ($namespace) { |
39 | 41 | $this->namespace = $namespace; |
40 | 42 | $this->nss = $namespace.':'; |