@@ -36,7 +36,9 @@ discard block |
||
| 36 | 36 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
| 37 | 37 | curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); |
| 38 | 38 | curl_setopt($ch, CURLINFO_HEADER_OUT, true); |
| 39 | - if ($getheaders) curl_setopt($ch, CURLOPT_HEADER, 1); |
|
| 39 | + if ($getheaders) { |
|
| 40 | + curl_setopt($ch, CURLOPT_HEADER, 1); |
|
| 41 | + } |
|
| 40 | 42 | curl_setopt($ch,CURLOPT_ENCODING , "gzip"); |
| 41 | 43 | //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'); |
| 42 | 44 | // curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (X11; Linux x86_64; rv:42.0) Gecko/20100101 Firefox/42.0'); |
@@ -45,8 +47,11 @@ discard block |
||
| 45 | 47 | } else { |
| 46 | 48 | curl_setopt($ch, CURLOPT_USERAGENT, $useragent); |
| 47 | 49 | } |
| 48 | - if ($timeout == '') curl_setopt($ch, CURLOPT_TIMEOUT, 10); |
|
| 49 | - else curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); |
|
| 50 | + if ($timeout == '') { |
|
| 51 | + curl_setopt($ch, CURLOPT_TIMEOUT, 10); |
|
| 52 | + } else { |
|
| 53 | + curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); |
|
| 54 | + } |
|
| 50 | 55 | //curl_setopt($ch, CURLOPT_HEADERFUNCTION, array('Common',"curlResponseHeaderCallback")); |
| 51 | 56 | if ($type == 'post') { |
| 52 | 57 | curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); |
@@ -59,7 +64,9 @@ discard block |
||
| 59 | 64 | } else { |
| 60 | 65 | curl_setopt($ch, CURLOPT_POSTFIELDS, $data); |
| 61 | 66 | } |
| 62 | - } elseif ($type != 'get' && $type != '') curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $type); |
|
| 67 | + } elseif ($type != 'get' && $type != '') { |
|
| 68 | + curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $type); |
|
| 69 | + } |
|
| 63 | 70 | if ($headers != '') { |
| 64 | 71 | curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); |
| 65 | 72 | } |
@@ -104,8 +111,9 @@ discard block |
||
| 104 | 111 | private function curlResponseHeaderCallback($ch, $headerLine) { |
| 105 | 112 | global $curl_cookies; |
| 106 | 113 | $curl_cookies = array(); |
| 107 | - if (preg_match('/^Set-Cookie:\s*([^;]*)/mi', $headerLine, $cookie) == 1) |
|
| 108 | - $curl_cookies[] = $cookie; |
|
| 114 | + if (preg_match('/^Set-Cookie:\s*([^;]*)/mi', $headerLine, $cookie) == 1) { |
|
| 115 | + $curl_cookies[] = $cookie; |
|
| 116 | + } |
|
| 109 | 117 | return strlen($headerLine); // Needed by curl |
| 110 | 118 | } |
| 111 | 119 | |
@@ -118,7 +126,9 @@ discard block |
||
| 118 | 126 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
| 119 | 127 | curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); |
| 120 | 128 | curl_setopt($ch, CURLOPT_COOKIEFILE, ''); |
| 121 | - if ($referer != '') curl_setopt($ch, CURLOPT_REFERER, $referer); |
|
| 129 | + if ($referer != '') { |
|
| 130 | + curl_setopt($ch, CURLOPT_REFERER, $referer); |
|
| 131 | + } |
|
| 122 | 132 | if (isset($globalForceIPv4) && $globalForceIPv4) { |
| 123 | 133 | if (defined('CURLOPT_IPRESOLVE') && defined('CURL_IPRESOLVE_V4')){ |
| 124 | 134 | curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4); |
@@ -133,7 +143,9 @@ discard block |
||
| 133 | 143 | 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'); |
| 134 | 144 | curl_setopt($ch, CURLOPT_FILE, $fp); |
| 135 | 145 | curl_exec($ch); |
| 136 | - if (curl_errno($ch) && $globalDebug) echo 'Download error: '.curl_error($ch); |
|
| 146 | + if (curl_errno($ch) && $globalDebug) { |
|
| 147 | + echo 'Download error: '.curl_error($ch); |
|
| 148 | + } |
|
| 137 | 149 | curl_close($ch); |
| 138 | 150 | fclose($fp); |
| 139 | 151 | } |
@@ -141,12 +153,16 @@ discard block |
||
| 141 | 153 | public static function gunzip($in_file,$out_file_name = '') { |
| 142 | 154 | //echo $in_file.' -> '.$out_file_name."\n"; |
| 143 | 155 | $buffer_size = 4096; // read 4kb at a time |
| 144 | - if ($out_file_name == '') $out_file_name = str_replace('.gz', '', $in_file); |
|
| 156 | + if ($out_file_name == '') { |
|
| 157 | + $out_file_name = str_replace('.gz', '', $in_file); |
|
| 158 | + } |
|
| 145 | 159 | if ($in_file != '' && file_exists($in_file)) { |
| 146 | 160 | // PHP version of Ubuntu use gzopen64 instead of gzopen |
| 147 | - if (function_exists('gzopen')) $file = gzopen($in_file,'rb'); |
|
| 148 | - elseif (function_exists('gzopen64')) $file = gzopen64($in_file,'rb'); |
|
| 149 | - else { |
|
| 161 | + if (function_exists('gzopen')) { |
|
| 162 | + $file = gzopen($in_file,'rb'); |
|
| 163 | + } elseif (function_exists('gzopen64')) { |
|
| 164 | + $file = gzopen64($in_file,'rb'); |
|
| 165 | + } else { |
|
| 150 | 166 | echo 'gzopen not available'; |
| 151 | 167 | die; |
| 152 | 168 | } |
@@ -162,11 +178,14 @@ discard block |
||
| 162 | 178 | public static function bunzip2($in_file,$out_file_name = '') { |
| 163 | 179 | //echo $in_file.' -> '.$out_file_name."\n"; |
| 164 | 180 | $buffer_size = 4096; // read 4kb at a time |
| 165 | - if ($out_file_name == '') $out_file_name = str_replace('.bz2', '', $in_file); |
|
| 181 | + if ($out_file_name == '') { |
|
| 182 | + $out_file_name = str_replace('.bz2', '', $in_file); |
|
| 183 | + } |
|
| 166 | 184 | if ($in_file != '' && file_exists($in_file)) { |
| 167 | 185 | // PHP version of Ubuntu use gzopen64 instead of gzopen |
| 168 | - if (function_exists('bzopen')) $file = bzopen($in_file,'rb'); |
|
| 169 | - else { |
|
| 186 | + if (function_exists('bzopen')) { |
|
| 187 | + $file = bzopen($in_file,'rb'); |
|
| 188 | + } else { |
|
| 170 | 189 | echo 'bzopen not available'; |
| 171 | 190 | die; |
| 172 | 191 | } |
@@ -185,10 +204,16 @@ discard block |
||
| 185 | 204 | * @return array array of the tables in HTML page |
| 186 | 205 | */ |
| 187 | 206 | public function table2array($data) { |
| 188 | - if (!is_string($data)) return array(); |
|
| 189 | - if ($data == '') return array(); |
|
| 207 | + if (!is_string($data)) { |
|
| 208 | + return array(); |
|
| 209 | + } |
|
| 210 | + if ($data == '') { |
|
| 211 | + return array(); |
|
| 212 | + } |
|
| 190 | 213 | $html = str_get_html($data); |
| 191 | - if ($html === false) return array(); |
|
| 214 | + if ($html === false) { |
|
| 215 | + return array(); |
|
| 216 | + } |
|
| 192 | 217 | $tabledata=array(); |
| 193 | 218 | foreach($html->find('tr') as $element) |
| 194 | 219 | { |
@@ -223,7 +248,9 @@ discard block |
||
| 223 | 248 | */ |
| 224 | 249 | public function text2array($data) { |
| 225 | 250 | $html = str_get_html($data); |
| 226 | - if ($html === false) return array(); |
|
| 251 | + if ($html === false) { |
|
| 252 | + return array(); |
|
| 253 | + } |
|
| 227 | 254 | $tabledata=array(); |
| 228 | 255 | foreach($html->find('p') as $element) |
| 229 | 256 | { |
@@ -244,7 +271,9 @@ discard block |
||
| 244 | 271 | * @return Float Distance in $unit |
| 245 | 272 | */ |
| 246 | 273 | public function distance($lat, $lon, $latc, $lonc, $unit = 'km') { |
| 247 | - if ($lat == $latc && $lon == $lonc) return 0; |
|
| 274 | + if ($lat == $latc && $lon == $lonc) { |
|
| 275 | + return 0; |
|
| 276 | + } |
|
| 248 | 277 | $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; |
| 249 | 278 | if ($unit == "km") { |
| 250 | 279 | return round($dist * 1.609344); |
@@ -290,7 +319,9 @@ discard block |
||
| 290 | 319 | $dX = $latc - $lat; |
| 291 | 320 | $dY = $lonc - $lon; |
| 292 | 321 | $azimuth = rad2deg(atan2($dY,$dX)); |
| 293 | - if ($azimuth < 0) return $azimuth+360; |
|
| 322 | + if ($azimuth < 0) { |
|
| 323 | + return $azimuth+360; |
|
| 324 | + } |
|
| 294 | 325 | return $azimuth; |
| 295 | 326 | } |
| 296 | 327 | |
@@ -304,10 +335,16 @@ discard block |
||
| 304 | 335 | public function withinThreshold ($timeDifference, $distance) { |
| 305 | 336 | $x = abs($timeDifference); |
| 306 | 337 | $d = abs($distance); |
| 307 | - if ($x == 0 || $d == 0) return true; |
|
| 338 | + if ($x == 0 || $d == 0) { |
|
| 339 | + return true; |
|
| 340 | + } |
|
| 308 | 341 | // may be due to Internet jitter; distance is realistic |
| 309 | - if ($x < 0.7 && $d < 2000) return true; |
|
| 310 | - else return $d/$x < 1500*0.27778; // 1500 km/h max |
|
| 342 | + if ($x < 0.7 && $d < 2000) { |
|
| 343 | + return true; |
|
| 344 | + } else { |
|
| 345 | + return $d/$x < 1500*0.27778; |
|
| 346 | + } |
|
| 347 | + // 1500 km/h max |
|
| 311 | 348 | } |
| 312 | 349 | |
| 313 | 350 | |
@@ -359,11 +396,17 @@ discard block |
||
| 359 | 396 | |
| 360 | 397 | public function convertDM($coord,$latlong) { |
| 361 | 398 | if ($latlong == 'latitude') { |
| 362 | - if ($coord < 0) $NSEW = 'S'; |
|
| 363 | - else $NSEW = 'N'; |
|
| 399 | + if ($coord < 0) { |
|
| 400 | + $NSEW = 'S'; |
|
| 401 | + } else { |
|
| 402 | + $NSEW = 'N'; |
|
| 403 | + } |
|
| 364 | 404 | } else { |
| 365 | - if ($coord < 0) $NSEW = 'W'; |
|
| 366 | - else $NSEW = 'E'; |
|
| 405 | + if ($coord < 0) { |
|
| 406 | + $NSEW = 'W'; |
|
| 407 | + } else { |
|
| 408 | + $NSEW = 'E'; |
|
| 409 | + } |
|
| 367 | 410 | } |
| 368 | 411 | $coord = abs($coord); |
| 369 | 412 | $deg = floor($coord); |
@@ -373,11 +416,17 @@ discard block |
||
| 373 | 416 | } |
| 374 | 417 | public function convertDMS($coord,$latlong) { |
| 375 | 418 | if ($latlong == 'latitude') { |
| 376 | - if ($coord < 0) $NSEW = 'S'; |
|
| 377 | - else $NSEW = 'N'; |
|
| 419 | + if ($coord < 0) { |
|
| 420 | + $NSEW = 'S'; |
|
| 421 | + } else { |
|
| 422 | + $NSEW = 'N'; |
|
| 423 | + } |
|
| 378 | 424 | } else { |
| 379 | - if ($coord < 0) $NSEW = 'W'; |
|
| 380 | - else $NSEW = 'E'; |
|
| 425 | + if ($coord < 0) { |
|
| 426 | + $NSEW = 'W'; |
|
| 427 | + } else { |
|
| 428 | + $NSEW = 'E'; |
|
| 429 | + } |
|
| 381 | 430 | } |
| 382 | 431 | $coord = abs($coord); |
| 383 | 432 | $deg = floor($coord); |
@@ -421,7 +470,9 @@ discard block |
||
| 421 | 470 | public function hex2str($hex) { |
| 422 | 471 | $str = ''; |
| 423 | 472 | $hexln = strlen($hex); |
| 424 | - for($i=0;$i<$hexln;$i+=2) $str .= chr(hexdec(substr($hex,$i,2))); |
|
| 473 | + for($i=0;$i<$hexln;$i+=2) { |
|
| 474 | + $str .= chr(hexdec(substr($hex,$i,2))); |
|
| 475 | + } |
|
| 425 | 476 | return $str; |
| 426 | 477 | } |
| 427 | 478 | |
@@ -458,8 +509,11 @@ discard block |
||
| 458 | 509 | $b = $lat2 - $lat1; |
| 459 | 510 | $c = -($a*$lat1+$b*$lon1); |
| 460 | 511 | $d = $a*$lat3+$b*$lon3+$c; |
| 461 | - if ($d > -$approx && $d < $approx) return true; |
|
| 462 | - else return false; |
|
| 512 | + if ($d > -$approx && $d < $approx) { |
|
| 513 | + return true; |
|
| 514 | + } else { |
|
| 515 | + return false; |
|
| 516 | + } |
|
| 463 | 517 | } |
| 464 | 518 | |
| 465 | 519 | public function array_merge_noappend() { |
@@ -518,7 +572,9 @@ discard block |
||
| 518 | 572 | return $result; |
| 519 | 573 | } |
| 520 | 574 | $handle = @opendir('./locale'); |
| 521 | - if ($handle === false) return $result; |
|
| 575 | + if ($handle === false) { |
|
| 576 | + return $result; |
|
| 577 | + } |
|
| 522 | 578 | while (false !== ($file = readdir($handle))) { |
| 523 | 579 | $path = './locale'.'/'.$file.'/LC_MESSAGES/fam.mo'; |
| 524 | 580 | if ($file != "." && $file != ".." && @file_exists($path)) { |
@@ -589,8 +645,9 @@ discard block |
||
| 589 | 645 | $error = false; |
| 590 | 646 | if ($fp_out = gzopen($dest, $mode)) { |
| 591 | 647 | if ($fp_in = fopen($source,'rb')) { |
| 592 | - while (!feof($fp_in)) |
|
| 593 | - gzwrite($fp_out, fread($fp_in, 1024 * 512)); |
|
| 648 | + while (!feof($fp_in)) { |
|
| 649 | + gzwrite($fp_out, fread($fp_in, 1024 * 512)); |
|
| 650 | + } |
|
| 594 | 651 | fclose($fp_in); |
| 595 | 652 | } else { |
| 596 | 653 | $error = true; |
@@ -599,14 +656,17 @@ discard block |
||
| 599 | 656 | } else { |
| 600 | 657 | $error = true; |
| 601 | 658 | } |
| 602 | - if ($error) |
|
| 603 | - return false; |
|
| 604 | - else |
|
| 605 | - return $dest; |
|
| 659 | + if ($error) { |
|
| 660 | + return false; |
|
| 661 | + } else { |
|
| 662 | + return $dest; |
|
| 663 | + } |
|
| 606 | 664 | } |
| 607 | 665 | |
| 608 | 666 | public function remove_accents($string) { |
| 609 | - if ( !preg_match('/[\x80-\xff]/', $string) ) return $string; |
|
| 667 | + if ( !preg_match('/[\x80-\xff]/', $string) ) { |
|
| 668 | + return $string; |
|
| 669 | + } |
|
| 610 | 670 | $chars = array( |
| 611 | 671 | // Decompositions for Latin-1 Supplement |
| 612 | 672 | chr(195).chr(128) => 'A', chr(195).chr(129) => 'A', |
@@ -732,7 +792,9 @@ discard block |
||
| 732 | 792 | $s = socket_create(AF_INET, SOCK_STREAM, 0); |
| 733 | 793 | socket_set_option($s, SOL_SOCKET, SO_SNDTIMEO, array('sec' => $globalSourcesTimeOut, 'usec' => 0)); |
| 734 | 794 | $r = @socket_connect($s, $ip, $port); |
| 735 | - if (!socket_set_nonblock($s)) echo "Unable to set nonblock on socket\n"; |
|
| 795 | + if (!socket_set_nonblock($s)) { |
|
| 796 | + echo "Unable to set nonblock on socket\n"; |
|
| 797 | + } |
|
| 736 | 798 | if ($r || socket_last_error() == 114 || socket_last_error() == 115) { |
| 737 | 799 | return $s; |
| 738 | 800 | } |
@@ -779,18 +841,22 @@ discard block |
||
| 779 | 841 | //NOTE: use a trailing slash for folders!!! |
| 780 | 842 | //see http://bugs.php.net/bug.php?id=27609 |
| 781 | 843 | //see http://bugs.php.net/bug.php?id=30931 |
| 782 | - if ($path{strlen($path)-1}=='/') // recursively return a temporary file path |
|
| 844 | + if ($path{strlen($path)-1}=='/') { |
|
| 845 | + // recursively return a temporary file path |
|
| 783 | 846 | return $this->is__writable($path.uniqid(mt_rand()).'.tmp'); |
| 784 | - else if (is_dir($path)) |
|
| 785 | - return $this->is__writable($path.'/'.uniqid(mt_rand()).'.tmp'); |
|
| 847 | + } else if (is_dir($path)) { |
|
| 848 | + return $this->is__writable($path.'/'.uniqid(mt_rand()).'.tmp'); |
|
| 849 | + } |
|
| 786 | 850 | // check tmp file for read/write capabilities |
| 787 | 851 | $rm = file_exists($path); |
| 788 | 852 | $f = @fopen($path, 'a'); |
| 789 | - if ($f===false) |
|
| 790 | - return false; |
|
| 853 | + if ($f===false) { |
|
| 854 | + return false; |
|
| 855 | + } |
|
| 791 | 856 | fclose($f); |
| 792 | - if (!$rm) |
|
| 793 | - unlink($path); |
|
| 857 | + if (!$rm) { |
|
| 858 | + unlink($path); |
|
| 859 | + } |
|
| 794 | 860 | return true; |
| 795 | 861 | } |
| 796 | 862 | |
@@ -806,7 +872,9 @@ discard block |
||
| 806 | 872 | * @return Array Coordinate of the route |
| 807 | 873 | */ |
| 808 | 874 | public function greatcircle($begin_lat,$begin_lon,$end_lat,$end_lon,$nbpts = 20, $offset = 10) { |
| 809 | - if ($nbpts <= 2) return array(array($begin_lon,$begin_lat),array($end_lon,$end_lat)); |
|
| 875 | + if ($nbpts <= 2) { |
|
| 876 | + return array(array($begin_lon,$begin_lat),array($end_lon,$end_lat)); |
|
| 877 | + } |
|
| 810 | 878 | $sx = deg2rad($begin_lon); |
| 811 | 879 | $sy = deg2rad($begin_lat); |
| 812 | 880 | $ex = deg2rad($end_lon); |
@@ -815,7 +883,9 @@ discard block |
||
| 815 | 883 | $h = $sy - $ey; |
| 816 | 884 | $z = pow(sin($h/2.0),2) + cos($sy)*cos($ey)*pow(sin($w/2.0),2); |
| 817 | 885 | $g = 2.0*asin(sqrt($z)); |
| 818 | - if ($g == M_PI || is_nan($g)) return array(array($begin_lon,$begin_lat),array($end_lon,$end_lat)); |
|
| 886 | + if ($g == M_PI || is_nan($g)) { |
|
| 887 | + return array(array($begin_lon,$begin_lat),array($end_lon,$end_lat)); |
|
| 888 | + } |
|
| 819 | 889 | $first_pass = array(); |
| 820 | 890 | $delta = 1.0/($nbpts-1); |
| 821 | 891 | for ($i =0; $i < $nbpts; ++$i) { |