@@ -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 | } |
@@ -133,10 +145,16 @@ discard block |
||
133 | 145 | * @return Array array of the tables in HTML page |
134 | 146 | */ |
135 | 147 | public function table2array($data) { |
136 | - if (!is_string($data)) return array(); |
|
137 | - if ($data == '') return array(); |
|
148 | + if (!is_string($data)) { |
|
149 | + return array(); |
|
150 | + } |
|
151 | + if ($data == '') { |
|
152 | + return array(); |
|
153 | + } |
|
138 | 154 | $html = str_get_html($data); |
139 | - if ($html === false) return array(); |
|
155 | + if ($html === false) { |
|
156 | + return array(); |
|
157 | + } |
|
140 | 158 | $tabledata=array(); |
141 | 159 | foreach($html->find('tr') as $element) |
142 | 160 | { |
@@ -171,7 +189,9 @@ discard block |
||
171 | 189 | */ |
172 | 190 | public function text2array($data) { |
173 | 191 | $html = str_get_html($data); |
174 | - if ($html === false) return array(); |
|
192 | + if ($html === false) { |
|
193 | + return array(); |
|
194 | + } |
|
175 | 195 | $tabledata=array(); |
176 | 196 | foreach($html->find('p') as $element) |
177 | 197 | { |
@@ -192,7 +212,9 @@ discard block |
||
192 | 212 | * @return Float Distance in $unit |
193 | 213 | */ |
194 | 214 | public function distance($lat, $lon, $latc, $lonc, $unit = 'km') { |
195 | - if ($lat == $latc && $lon == $lonc) return 0; |
|
215 | + if ($lat == $latc && $lon == $lonc) { |
|
216 | + return 0; |
|
217 | + } |
|
196 | 218 | $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; |
197 | 219 | if ($unit == "km") { |
198 | 220 | return round($dist * 1.609344); |
@@ -216,10 +238,16 @@ discard block |
||
216 | 238 | public function withinThreshold ($timeDifference, $distance) { |
217 | 239 | $x = abs($timeDifference); |
218 | 240 | $d = abs($distance); |
219 | - if ($x == 0 || $d == 0) return true; |
|
241 | + if ($x == 0 || $d == 0) { |
|
242 | + return true; |
|
243 | + } |
|
220 | 244 | // may be due to Internet jitter; distance is realistic |
221 | - if ($x < 0.7 && $d < 2000) return true; |
|
222 | - else return $d/$x < 1500*0.27778; // 1500 km/h max |
|
245 | + if ($x < 0.7 && $d < 2000) { |
|
246 | + return true; |
|
247 | + } else { |
|
248 | + return $d/$x < 1500*0.27778; |
|
249 | + } |
|
250 | + // 1500 km/h max |
|
223 | 251 | } |
224 | 252 | |
225 | 253 | |
@@ -247,11 +275,17 @@ discard block |
||
247 | 275 | |
248 | 276 | public function convertDM($coord,$latlong) { |
249 | 277 | if ($latlong == 'latitude') { |
250 | - if ($coord < 0) $NSEW = 'S'; |
|
251 | - else $NSEW = 'N'; |
|
278 | + if ($coord < 0) { |
|
279 | + $NSEW = 'S'; |
|
280 | + } else { |
|
281 | + $NSEW = 'N'; |
|
282 | + } |
|
252 | 283 | } elseif ($latlong == 'longitude') { |
253 | - if ($coord < 0) $NSEW = 'W'; |
|
254 | - else $NSEW = 'E'; |
|
284 | + if ($coord < 0) { |
|
285 | + $NSEW = 'W'; |
|
286 | + } else { |
|
287 | + $NSEW = 'E'; |
|
288 | + } |
|
255 | 289 | } |
256 | 290 | $coord = abs($coord); |
257 | 291 | $deg = floor($coord); |
@@ -294,7 +328,9 @@ discard block |
||
294 | 328 | public function hex2str($hex) { |
295 | 329 | $str = ''; |
296 | 330 | $hexln = strlen($hex); |
297 | - for($i=0;$i<$hexln;$i+=2) $str .= chr(hexdec(substr($hex,$i,2))); |
|
331 | + for($i=0;$i<$hexln;$i+=2) { |
|
332 | + $str .= chr(hexdec(substr($hex,$i,2))); |
|
333 | + } |
|
298 | 334 | return $str; |
299 | 335 | } |
300 | 336 | |
@@ -331,8 +367,11 @@ discard block |
||
331 | 367 | $b = $lat2 - $lat1; |
332 | 368 | $c = -($a*$lat1+$b*$lon1); |
333 | 369 | $d = $a*$lat3+$b*$lon3+$c; |
334 | - if ($d > -$approx && $d < $approx) return true; |
|
335 | - else return false; |
|
370 | + if ($d > -$approx && $d < $approx) { |
|
371 | + return true; |
|
372 | + } else { |
|
373 | + return false; |
|
374 | + } |
|
336 | 375 | } |
337 | 376 | |
338 | 377 | public function array_merge_noappend() { |
@@ -391,7 +430,9 @@ discard block |
||
391 | 430 | return $result; |
392 | 431 | } |
393 | 432 | $handle = @opendir('./locale'); |
394 | - if ($handle === false) return $result; |
|
433 | + if ($handle === false) { |
|
434 | + return $result; |
|
435 | + } |
|
395 | 436 | while (false !== ($file = readdir($handle))) { |
396 | 437 | $path = './locale'.'/'.$file.'/LC_MESSAGES/fam.mo'; |
397 | 438 | if ($file != "." && $file != ".." && @file_exists($path)) { |
@@ -458,8 +499,9 @@ discard block |
||
458 | 499 | $error = false; |
459 | 500 | if ($fp_out = gzopen($dest, $mode)) { |
460 | 501 | if ($fp_in = fopen($source,'rb')) { |
461 | - while (!feof($fp_in)) |
|
462 | - gzwrite($fp_out, fread($fp_in, 1024 * 512)); |
|
502 | + while (!feof($fp_in)) { |
|
503 | + gzwrite($fp_out, fread($fp_in, 1024 * 512)); |
|
504 | + } |
|
463 | 505 | fclose($fp_in); |
464 | 506 | } else { |
465 | 507 | $error = true; |
@@ -468,14 +510,17 @@ discard block |
||
468 | 510 | } else { |
469 | 511 | $error = true; |
470 | 512 | } |
471 | - if ($error) |
|
472 | - return false; |
|
473 | - else |
|
474 | - return $dest; |
|
513 | + if ($error) { |
|
514 | + return false; |
|
515 | + } else { |
|
516 | + return $dest; |
|
517 | + } |
|
475 | 518 | } |
476 | 519 | |
477 | 520 | public function remove_accents($string) { |
478 | - if ( !preg_match('/[\x80-\xff]/', $string) ) return $string; |
|
521 | + if ( !preg_match('/[\x80-\xff]/', $string) ) { |
|
522 | + return $string; |
|
523 | + } |
|
479 | 524 | $chars = array( |
480 | 525 | // Decompositions for Latin-1 Supplement |
481 | 526 | chr(195).chr(128) => 'A', chr(195).chr(129) => 'A', |
@@ -599,7 +644,9 @@ discard block |
||
599 | 644 | $ip = gethostbyname($host); |
600 | 645 | $s = socket_create(AF_INET, SOCK_STREAM, 0); |
601 | 646 | $r = @socket_connect($s, $ip, $port); |
602 | - if (!socket_set_nonblock($s)) echo "Unable to set nonblock on socket\n"; |
|
647 | + if (!socket_set_nonblock($s)) { |
|
648 | + echo "Unable to set nonblock on socket\n"; |
|
649 | + } |
|
603 | 650 | if ($r || socket_last_error() == 114 || socket_last_error() == 115) { |
604 | 651 | return $s; |
605 | 652 | } |