| @@ -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 | } | 
| @@ -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.':'; | 
| @@ -49,6 +49,9 @@ discard block | ||
| 49 | 49 | return $this->geometryToKML($geometry); | 
| 50 | 50 | } | 
| 51 | 51 | |
| 52 | + /** | |
| 53 | + * @param string $text | |
| 54 | + */ | |
| 52 | 55 |    public function geomFromText($text) {
 | 
| 53 | 56 | |
| 54 | 57 | // Change to lower-case and strip all CDATA | 
| @@ -184,6 +187,9 @@ discard block | ||
| 184 | 187 | return $coordinates; | 
| 185 | 188 | } | 
| 186 | 189 | |
| 190 | + /** | |
| 191 | + * @param Geometry $geom | |
| 192 | + */ | |
| 187 | 193 |    private function geometryToKML($geom) {
 | 
| 188 | 194 | $type = strtolower($geom->getGeomType()); | 
| 189 | 195 |      switch ($type) {
 | 
| @@ -89,8 +89,7 @@ discard block | ||
| 89 | 89 | } | 
| 90 | 90 | } | 
| 91 | 91 | } | 
| 92 | - } | |
| 93 | -    else {
 | |
| 92 | +    } else {
 | |
| 94 | 93 | // The document does not have a placemark, try to create a valid geometry from the root element | 
| 95 | 94 | $node_name = $this->xmlobj->documentElement->nodeName == 'multigeometry' ? 'geometrycollection' : $this->xmlobj->documentElement->nodeName; | 
| 96 | 95 |        if (array_key_exists($node_name, $geom_types)) {
 | 
| @@ -220,7 +219,9 @@ discard block | ||
| 220 | 219 | $str .= '<'.$this->nss.'coordinates>'; | 
| 221 | 220 | $i=0; | 
| 222 | 221 |        foreach ($geom->getComponents() as $comp) {
 | 
| 223 | - if ($i != 0) $str .= ' '; | |
| 222 | +        if ($i != 0) { | |
| 223 | + $str .= ' '; | |
| 224 | + } | |
| 224 | 225 | $str .= $comp->getX() .','. $comp->getY(); | 
| 225 | 226 | $i++; | 
| 226 | 227 | } |