@@ -20,7 +20,9 @@ |
||
| 20 | 20 | public $c3s = [[18, -36, -122, 0, 120, 135, 0, 0, -84, -31], [-18, 36, -2, 0, -120, 51, 0, 0, 84, -31], [36, -165, -27, 93, 147, -9, 0, -93, 18, 0], [210, 45, -111, -93, -57, -192, 0, 93, 12, 93], [162, 141, -75, -93, -129, -180, 0, 93, -12, 93], [-36, -21, 27, 93, 39, 9, 0, -93, -18, 0], [0, 0, 62, 0, 0, 31, 0, 0, 0, -31], [0, 0, 124, 0, 0, 62, 0, 0, 0, -62], [0, 0, 124, 0, 0, 62, 0, 0, 0, -62], [0, 0, 62, 0, 0, 31, 0, 0, 0, -31], [-18, 36, -64, 0, 66, 51, 0, 0, -102, 31], [18, -36, 2, 0, -66, -51, 0, 0, 102, 31]]; |
| 21 | 21 | |
| 22 | 22 | function __construct($name='egm2008-1.pgm') { |
| 23 | - if ($name == '') $name = dirname(__FILE__).'/install/tmp/egm2008-1.pgm'; |
|
| 23 | + if ($name == '') { |
|
| 24 | + $name = dirname(__FILE__).'/install/tmp/egm2008-1.pgm'; |
|
| 25 | + } |
|
| 24 | 26 | $this->offset = null; |
| 25 | 27 | $this->scale = null; |
| 26 | 28 | |
@@ -37,8 +37,11 @@ discard block |
||
| 37 | 37 | } else { |
| 38 | 38 | curl_setopt($ch, CURLOPT_USERAGENT, $useragent); |
| 39 | 39 | } |
| 40 | - if ($timeout == '') curl_setopt($ch, CURLOPT_TIMEOUT, 10); |
|
| 41 | - else curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); |
|
| 40 | + if ($timeout == '') { |
|
| 41 | + curl_setopt($ch, CURLOPT_TIMEOUT, 10); |
|
| 42 | + } else { |
|
| 43 | + curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); |
|
| 44 | + } |
|
| 42 | 45 | curl_setopt($ch, CURLOPT_HEADERFUNCTION, array('Common',"curlResponseHeaderCallback")); |
| 43 | 46 | if ($type == 'post') { |
| 44 | 47 | curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); |
@@ -85,8 +88,9 @@ discard block |
||
| 85 | 88 | private function curlResponseHeaderCallback($ch, $headerLine) { |
| 86 | 89 | //global $cookies; |
| 87 | 90 | $cookies = array(); |
| 88 | - if (preg_match('/^Set-Cookie:\s*([^;]*)/mi', $headerLine, $cookie) == 1) |
|
| 89 | - $cookies[] = $cookie; |
|
| 91 | + if (preg_match('/^Set-Cookie:\s*([^;]*)/mi', $headerLine, $cookie) == 1) { |
|
| 92 | + $cookies[] = $cookie; |
|
| 93 | + } |
|
| 90 | 94 | return strlen($headerLine); // Needed by curl |
| 91 | 95 | } |
| 92 | 96 | |
@@ -97,11 +101,15 @@ discard block |
||
| 97 | 101 | curl_setopt($ch, CURLOPT_URL, $url); |
| 98 | 102 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); |
| 99 | 103 | curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); |
| 100 | - if ($referer != '') curl_setopt($ch, CURLOPT_REFERER, $referer); |
|
| 104 | + if ($referer != '') { |
|
| 105 | + curl_setopt($ch, CURLOPT_REFERER, $referer); |
|
| 106 | + } |
|
| 101 | 107 | curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.2) Gecko/20090729 Firefox/3.5.2 GTB5'); |
| 102 | 108 | curl_setopt($ch, CURLOPT_FILE, $fp); |
| 103 | 109 | curl_exec($ch); |
| 104 | - if (curl_errno($ch) && $globalDebug) echo 'Download error: '.curl_error($ch); |
|
| 110 | + if (curl_errno($ch) && $globalDebug) { |
|
| 111 | + echo 'Download error: '.curl_error($ch); |
|
| 112 | + } |
|
| 105 | 113 | curl_close($ch); |
| 106 | 114 | fclose($fp); |
| 107 | 115 | } |
@@ -109,12 +117,16 @@ discard block |
||
| 109 | 117 | public static function gunzip($in_file,$out_file_name = '') { |
| 110 | 118 | //echo $in_file.' -> '.$out_file_name."\n"; |
| 111 | 119 | $buffer_size = 4096; // read 4kb at a time |
| 112 | - if ($out_file_name == '') $out_file_name = str_replace('.gz', '', $in_file); |
|
| 120 | + if ($out_file_name == '') { |
|
| 121 | + $out_file_name = str_replace('.gz', '', $in_file); |
|
| 122 | + } |
|
| 113 | 123 | if ($in_file != '' && file_exists($in_file)) { |
| 114 | 124 | // PHP version of Ubuntu use gzopen64 instead of gzopen |
| 115 | - if (function_exists('gzopen')) $file = gzopen($in_file,'rb'); |
|
| 116 | - elseif (function_exists('gzopen64')) $file = gzopen64($in_file,'rb'); |
|
| 117 | - else { |
|
| 125 | + if (function_exists('gzopen')) { |
|
| 126 | + $file = gzopen($in_file,'rb'); |
|
| 127 | + } elseif (function_exists('gzopen64')) { |
|
| 128 | + $file = gzopen64($in_file,'rb'); |
|
| 129 | + } else { |
|
| 118 | 130 | echo 'gzopen not available'; |
| 119 | 131 | die; |
| 120 | 132 | } |
@@ -130,11 +142,14 @@ discard block |
||
| 130 | 142 | public static function bunzip2($in_file,$out_file_name = '') { |
| 131 | 143 | //echo $in_file.' -> '.$out_file_name."\n"; |
| 132 | 144 | $buffer_size = 4096; // read 4kb at a time |
| 133 | - if ($out_file_name == '') $out_file_name = str_replace('.bz2', '', $in_file); |
|
| 145 | + if ($out_file_name == '') { |
|
| 146 | + $out_file_name = str_replace('.bz2', '', $in_file); |
|
| 147 | + } |
|
| 134 | 148 | if ($in_file != '' && file_exists($in_file)) { |
| 135 | 149 | // PHP version of Ubuntu use gzopen64 instead of gzopen |
| 136 | - if (function_exists('bzopen')) $file = bzopen($in_file,'rb'); |
|
| 137 | - else { |
|
| 150 | + if (function_exists('bzopen')) { |
|
| 151 | + $file = bzopen($in_file,'rb'); |
|
| 152 | + } else { |
|
| 138 | 153 | echo 'bzopen not available'; |
| 139 | 154 | die; |
| 140 | 155 | } |
@@ -153,10 +168,16 @@ discard block |
||
| 153 | 168 | * @return Array array of the tables in HTML page |
| 154 | 169 | */ |
| 155 | 170 | public function table2array($data) { |
| 156 | - if (!is_string($data)) return array(); |
|
| 157 | - if ($data == '') return array(); |
|
| 171 | + if (!is_string($data)) { |
|
| 172 | + return array(); |
|
| 173 | + } |
|
| 174 | + if ($data == '') { |
|
| 175 | + return array(); |
|
| 176 | + } |
|
| 158 | 177 | $html = str_get_html($data); |
| 159 | - if ($html === false) return array(); |
|
| 178 | + if ($html === false) { |
|
| 179 | + return array(); |
|
| 180 | + } |
|
| 160 | 181 | $tabledata=array(); |
| 161 | 182 | foreach($html->find('tr') as $element) |
| 162 | 183 | { |
@@ -191,7 +212,9 @@ discard block |
||
| 191 | 212 | */ |
| 192 | 213 | public function text2array($data) { |
| 193 | 214 | $html = str_get_html($data); |
| 194 | - if ($html === false) return array(); |
|
| 215 | + if ($html === false) { |
|
| 216 | + return array(); |
|
| 217 | + } |
|
| 195 | 218 | $tabledata=array(); |
| 196 | 219 | foreach($html->find('p') as $element) |
| 197 | 220 | { |
@@ -212,7 +235,9 @@ discard block |
||
| 212 | 235 | * @return Float Distance in $unit |
| 213 | 236 | */ |
| 214 | 237 | public function distance($lat, $lon, $latc, $lonc, $unit = 'km') { |
| 215 | - if ($lat == $latc && $lon == $lonc) return 0; |
|
| 238 | + if ($lat == $latc && $lon == $lonc) { |
|
| 239 | + return 0; |
|
| 240 | + } |
|
| 216 | 241 | $dist = rad2deg(acos(sin(deg2rad(floatval($lat)))*sin(deg2rad(floatval($latc)))+ cos(deg2rad(floatval($lat)))*cos(deg2rad(floatval($latc)))*cos(deg2rad(floatval($lon)-floatval($lonc)))))*60*1.1515; |
| 217 | 242 | if ($unit == "km") { |
| 218 | 243 | return round($dist * 1.609344); |
@@ -236,10 +261,16 @@ discard block |
||
| 236 | 261 | public function withinThreshold ($timeDifference, $distance) { |
| 237 | 262 | $x = abs($timeDifference); |
| 238 | 263 | $d = abs($distance); |
| 239 | - if ($x == 0 || $d == 0) return true; |
|
| 264 | + if ($x == 0 || $d == 0) { |
|
| 265 | + return true; |
|
| 266 | + } |
|
| 240 | 267 | // may be due to Internet jitter; distance is realistic |
| 241 | - if ($x < 0.7 && $d < 2000) return true; |
|
| 242 | - else return $d/$x < 1500*0.27778; // 1500 km/h max |
|
| 268 | + if ($x < 0.7 && $d < 2000) { |
|
| 269 | + return true; |
|
| 270 | + } else { |
|
| 271 | + return $d/$x < 1500*0.27778; |
|
| 272 | + } |
|
| 273 | + // 1500 km/h max |
|
| 243 | 274 | } |
| 244 | 275 | |
| 245 | 276 | |
@@ -267,11 +298,17 @@ discard block |
||
| 267 | 298 | |
| 268 | 299 | public function convertDM($coord,$latlong) { |
| 269 | 300 | if ($latlong == 'latitude') { |
| 270 | - if ($coord < 0) $NSEW = 'S'; |
|
| 271 | - else $NSEW = 'N'; |
|
| 301 | + if ($coord < 0) { |
|
| 302 | + $NSEW = 'S'; |
|
| 303 | + } else { |
|
| 304 | + $NSEW = 'N'; |
|
| 305 | + } |
|
| 272 | 306 | } elseif ($latlong == 'longitude') { |
| 273 | - if ($coord < 0) $NSEW = 'W'; |
|
| 274 | - else $NSEW = 'E'; |
|
| 307 | + if ($coord < 0) { |
|
| 308 | + $NSEW = 'W'; |
|
| 309 | + } else { |
|
| 310 | + $NSEW = 'E'; |
|
| 311 | + } |
|
| 275 | 312 | } |
| 276 | 313 | $coord = abs($coord); |
| 277 | 314 | $deg = floor($coord); |
@@ -314,7 +351,9 @@ discard block |
||
| 314 | 351 | public function hex2str($hex) { |
| 315 | 352 | $str = ''; |
| 316 | 353 | $hexln = strlen($hex); |
| 317 | - for($i=0;$i<$hexln;$i+=2) $str .= chr(hexdec(substr($hex,$i,2))); |
|
| 354 | + for($i=0;$i<$hexln;$i+=2) { |
|
| 355 | + $str .= chr(hexdec(substr($hex,$i,2))); |
|
| 356 | + } |
|
| 318 | 357 | return $str; |
| 319 | 358 | } |
| 320 | 359 | |
@@ -351,8 +390,11 @@ discard block |
||
| 351 | 390 | $b = $lat2 - $lat1; |
| 352 | 391 | $c = -($a*$lat1+$b*$lon1); |
| 353 | 392 | $d = $a*$lat3+$b*$lon3+$c; |
| 354 | - if ($d > -$approx && $d < $approx) return true; |
|
| 355 | - else return false; |
|
| 393 | + if ($d > -$approx && $d < $approx) { |
|
| 394 | + return true; |
|
| 395 | + } else { |
|
| 396 | + return false; |
|
| 397 | + } |
|
| 356 | 398 | } |
| 357 | 399 | |
| 358 | 400 | public function array_merge_noappend() { |
@@ -411,7 +453,9 @@ discard block |
||
| 411 | 453 | return $result; |
| 412 | 454 | } |
| 413 | 455 | $handle = @opendir('./locale'); |
| 414 | - if ($handle === false) return $result; |
|
| 456 | + if ($handle === false) { |
|
| 457 | + return $result; |
|
| 458 | + } |
|
| 415 | 459 | while (false !== ($file = readdir($handle))) { |
| 416 | 460 | $path = './locale'.'/'.$file.'/LC_MESSAGES/fam.mo'; |
| 417 | 461 | if ($file != "." && $file != ".." && @file_exists($path)) { |
@@ -478,8 +522,9 @@ discard block |
||
| 478 | 522 | $error = false; |
| 479 | 523 | if ($fp_out = gzopen($dest, $mode)) { |
| 480 | 524 | if ($fp_in = fopen($source,'rb')) { |
| 481 | - while (!feof($fp_in)) |
|
| 482 | - gzwrite($fp_out, fread($fp_in, 1024 * 512)); |
|
| 525 | + while (!feof($fp_in)) { |
|
| 526 | + gzwrite($fp_out, fread($fp_in, 1024 * 512)); |
|
| 527 | + } |
|
| 483 | 528 | fclose($fp_in); |
| 484 | 529 | } else { |
| 485 | 530 | $error = true; |
@@ -488,14 +533,17 @@ discard block |
||
| 488 | 533 | } else { |
| 489 | 534 | $error = true; |
| 490 | 535 | } |
| 491 | - if ($error) |
|
| 492 | - return false; |
|
| 493 | - else |
|
| 494 | - return $dest; |
|
| 536 | + if ($error) { |
|
| 537 | + return false; |
|
| 538 | + } else { |
|
| 539 | + return $dest; |
|
| 540 | + } |
|
| 495 | 541 | } |
| 496 | 542 | |
| 497 | 543 | public function remove_accents($string) { |
| 498 | - if ( !preg_match('/[\x80-\xff]/', $string) ) return $string; |
|
| 544 | + if ( !preg_match('/[\x80-\xff]/', $string) ) { |
|
| 545 | + return $string; |
|
| 546 | + } |
|
| 499 | 547 | $chars = array( |
| 500 | 548 | // Decompositions for Latin-1 Supplement |
| 501 | 549 | chr(195).chr(128) => 'A', chr(195).chr(129) => 'A', |
@@ -619,7 +667,9 @@ discard block |
||
| 619 | 667 | $ip = gethostbyname($host); |
| 620 | 668 | $s = socket_create(AF_INET, SOCK_STREAM, 0); |
| 621 | 669 | $r = @socket_connect($s, $ip, $port); |
| 622 | - if (!socket_set_nonblock($s)) echo "Unable to set nonblock on socket\n"; |
|
| 670 | + if (!socket_set_nonblock($s)) { |
|
| 671 | + echo "Unable to set nonblock on socket\n"; |
|
| 672 | + } |
|
| 623 | 673 | if ($r || socket_last_error() == 114 || socket_last_error() == 115) { |
| 624 | 674 | return $s; |
| 625 | 675 | } |