Completed
Push — master ( 862b39...57932c )
by Yannick
08:32
created
require/class.Common.php 3 patches
Doc Comments   +15 added lines, -2 removed lines patch added patch discarded remove patch
@@ -90,6 +90,10 @@  discard block
 block discarded – undo
90 90
 		return strlen($headerLine); // Needed by curl
91 91
 	}
92 92
 
93
+	/**
94
+	 * @param string $url
95
+	 * @param string $file
96
+	 */
93 97
 	public static function download($url, $file, $referer = '') {
94 98
 		global $globalDebug;
95 99
 		$fp = fopen($file, 'w');
@@ -106,6 +110,9 @@  discard block
 block discarded – undo
106 110
 		fclose($fp);
107 111
 	}
108 112
 
113
+	/**
114
+	 * @param string $in_file
115
+	 */
109 116
 	public static function gunzip($in_file,$out_file_name = '') {
110 117
 		//echo $in_file.' -> '.$out_file_name."\n";
111 118
 		$buffer_size = 4096; // read 4kb at a time
@@ -211,7 +218,7 @@  discard block
 block discarded – undo
211 218
 	* Check is distance realistic
212 219
 	* @param int $timeDifference the time between the reception of both messages
213 220
 	* @param float $distance distance covered
214
-	* @return whether distance is realistic
221
+	* @return boolean distance is realistic
215 222
 	*/
216 223
 	public function withinThreshold ($timeDifference, $distance) {
217 224
 		$x = abs($timeDifference);
@@ -234,6 +241,9 @@  discard block
 block discarded – undo
234 241
 	}
235 242
 
236 243
 
244
+	/**
245
+	 * @param string $latlong
246
+	 */
237 247
 	public function convertDec($dms,$latlong) {
238 248
 		if ($latlong == 'latitude') {
239 249
 			$deg = substr($dms, 0, 2);
@@ -245,6 +255,9 @@  discard block
 block discarded – undo
245 255
 		return $deg+(($min*60)/3600);
246 256
 	}
247 257
 	
258
+	/**
259
+	 * @param string $latlong
260
+	 */
248 261
 	public function convertDM($coord,$latlong) {
249 262
 		if ($latlong == 'latitude') {
250 263
 			if ($coord < 0) $NSEW = 'S';
@@ -382,7 +395,7 @@  discard block
 block discarded – undo
382 395
 	/**
383 396
 	* Returns list of available locales
384 397
 	*
385
-	* @return array
398
+	* @return string[]
386 399
 	 */
387 400
 	public function listLocaleDir()
388 401
 	{
Please login to merge, or discard this patch.
Spacing   +80 added lines, -80 removed lines patch added patch discarded remove patch
@@ -14,12 +14,12 @@  discard block
 block discarded – undo
14 14
 	* @param Array $headers header to submit with the form
15 15
 	* @return String the result
16 16
 	*/
17
-	public function getData($url, $type = 'get', $data = '', $headers = '',$cookie = '',$referer = '',$timeout = '',$useragent = '') {
17
+	public function getData($url, $type = 'get', $data = '', $headers = '', $cookie = '', $referer = '', $timeout = '', $useragent = '') {
18 18
 		global $globalProxy, $globalForceIPv4;
19 19
 		$ch = curl_init();
20 20
 		curl_setopt($ch, CURLOPT_URL, $url);
21 21
 		if (isset($globalForceIPv4) && $globalForceIPv4) {
22
-			if (defined('CURLOPT_IPRESOLVE') && defined('CURL_IPRESOLVE_V4')){
22
+			if (defined('CURLOPT_IPRESOLVE') && defined('CURL_IPRESOLVE_V4')) {
23 23
 				curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
24 24
 			}
25 25
 		}
@@ -29,7 +29,7 @@  discard block
 block discarded – undo
29 29
 		curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
30 30
 		curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
31 31
 		curl_setopt($ch, CURLINFO_HEADER_OUT, true); 
32
-		curl_setopt($ch,CURLOPT_ENCODING , "gzip");
32
+		curl_setopt($ch, CURLOPT_ENCODING, "gzip");
33 33
 		//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');
34 34
 //		curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (X11; Linux x86_64; rv:42.0) Gecko/20100101 Firefox/42.0');
35 35
 		if ($useragent == '') {
@@ -39,13 +39,13 @@  discard block
 block discarded – undo
39 39
 		}
40 40
 		if ($timeout == '') curl_setopt($ch, CURLOPT_TIMEOUT, 10); 
41 41
 		else curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); 
42
-		curl_setopt($ch, CURLOPT_HEADERFUNCTION, array('Common',"curlResponseHeaderCallback"));
42
+		curl_setopt($ch, CURLOPT_HEADERFUNCTION, array('Common', "curlResponseHeaderCallback"));
43 43
 		if ($type == 'post') {
44 44
 			curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
45 45
 			if (is_array($data)) {
46 46
 				curl_setopt($ch, CURLOPT_POST, count($data));
47 47
 				$data_string = '';
48
-				foreach($data as $key=>$value) { $data_string .= $key.'='.$value.'&'; }
48
+				foreach ($data as $key=>$value) { $data_string .= $key.'='.$value.'&'; }
49 49
 				rtrim($data_string, '&');
50 50
 				curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
51 51
 			} else {
@@ -57,7 +57,7 @@  discard block
 block discarded – undo
57 57
 		}
58 58
 		if ($cookie != '') {
59 59
 			if (is_array($cookie)) {
60
-				curl_setopt($ch, CURLOPT_COOKIE, implode($cookie,';'));
60
+				curl_setopt($ch, CURLOPT_COOKIE, implode($cookie, ';'));
61 61
 			} else {
62 62
 				curl_setopt($ch, CURLOPT_COOKIE, $cookie);
63 63
 			}
@@ -69,13 +69,13 @@  discard block
 block discarded – undo
69 69
 		$info = curl_getinfo($ch);
70 70
 		//var_dump($info);
71 71
 		curl_close($ch);
72
-		if ($info['http_code'] == '503' && strstr($result,'DDoS protection by CloudFlare')) {
72
+		if ($info['http_code'] == '503' && strstr($result, 'DDoS protection by CloudFlare')) {
73 73
 			echo "Cloudflare Detected\n";
74 74
 			require_once(dirname(__FILE__).'/libs/cloudflare-bypass/libraries/cloudflareClass.php');
75 75
 			$useragent = UAgent::random();
76 76
 			cloudflare::useUserAgent($useragent);
77 77
 			if ($clearanceCookie = cloudflare::bypass($url)) {
78
-				return $this->getData($url,'get',$data,$headers,$clearanceCookie,$referer,$timeout,$useragent);
78
+				return $this->getData($url, 'get', $data, $headers, $clearanceCookie, $referer, $timeout, $useragent);
79 79
 			}
80 80
 		} else {
81 81
 			return $result;
@@ -106,20 +106,20 @@  discard block
 block discarded – undo
106 106
 		fclose($fp);
107 107
 	}
108 108
 
109
-	public static function gunzip($in_file,$out_file_name = '') {
109
+	public static function gunzip($in_file, $out_file_name = '') {
110 110
 		//echo $in_file.' -> '.$out_file_name."\n";
111 111
 		$buffer_size = 4096; // read 4kb at a time
112 112
 		if ($out_file_name == '') $out_file_name = str_replace('.gz', '', $in_file); 
113 113
 		if ($in_file != '' && file_exists($in_file)) {
114 114
 			// 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');
115
+			if (function_exists('gzopen')) $file = gzopen($in_file, 'rb');
116
+			elseif (function_exists('gzopen64')) $file = gzopen64($in_file, 'rb');
117 117
 			else {
118 118
 				echo 'gzopen not available';
119 119
 				die;
120 120
 			}
121 121
 			$out_file = fopen($out_file_name, 'wb'); 
122
-			while(!gzeof($file)) {
122
+			while (!gzeof($file)) {
123 123
 				fwrite($out_file, gzread($file, $buffer_size));
124 124
 			}  
125 125
 			fclose($out_file);
@@ -137,27 +137,27 @@  discard block
 block discarded – undo
137 137
 		if ($data == '') return array();
138 138
 		$html = str_get_html($data);
139 139
 		if ($html === false) return array();
140
-		$tabledata=array();
141
-		foreach($html->find('tr') as $element)
140
+		$tabledata = array();
141
+		foreach ($html->find('tr') as $element)
142 142
 		{
143 143
 			$td = array();
144
-			foreach( $element->find('th') as $row)
144
+			foreach ($element->find('th') as $row)
145 145
 			{
146 146
 				$td [] = trim($row->plaintext);
147 147
 			}
148
-			$td=array_filter($td);
148
+			$td = array_filter($td);
149 149
 			$tabledata[] = $td;
150 150
 
151 151
 			$td = array();
152 152
 			$tdi = array();
153
-			foreach( $element->find('td') as $row)
153
+			foreach ($element->find('td') as $row)
154 154
 			{
155 155
 				$td [] = trim($row->plaintext);
156 156
 				$tdi [] = trim($row->innertext);
157 157
 			}
158
-			$td=array_filter($td);
159
-			$tdi=array_filter($tdi);
160
-			$tabledata[]=array_merge($td,$tdi);
158
+			$td = array_filter($td);
159
+			$tdi = array_filter($tdi);
160
+			$tabledata[] = array_merge($td, $tdi);
161 161
 		}
162 162
 		$html->clear();
163 163
 		unset($html);
@@ -172,8 +172,8 @@  discard block
 block discarded – undo
172 172
 	public function text2array($data) {
173 173
 		$html = str_get_html($data);
174 174
 		if ($html === false) return array();
175
-		$tabledata=array();
176
-		foreach($html->find('p') as $element)
175
+		$tabledata = array();
176
+		foreach ($html->find('p') as $element)
177 177
 		{
178 178
 			$tabledata [] = trim($element->plaintext);
179 179
 		}
@@ -193,11 +193,11 @@  discard block
 block discarded – undo
193 193
 	*/
194 194
 	public function distance($lat, $lon, $latc, $lonc, $unit = 'km') {
195 195
 		if ($lat == $latc && $lon == $lonc) return 0;
196
-		$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;
196
+		$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 197
 		if ($unit == "km") {
198
-			return round($dist * 1.609344);
198
+			return round($dist*1.609344);
199 199
 		} elseif ($unit == "m") {
200
-			return round($dist * 1.609344 * 1000);
200
+			return round($dist*1.609344*1000);
201 201
 		} elseif ($unit == "mile" || $unit == "mi") {
202 202
 			return round($dist);
203 203
 		} elseif ($unit == "nm") {
@@ -213,7 +213,7 @@  discard block
 block discarded – undo
213 213
 	* @param float $distance distance covered
214 214
 	* @return whether distance is realistic
215 215
 	*/
216
-	public function withinThreshold ($timeDifference, $distance) {
216
+	public function withinThreshold($timeDifference, $distance) {
217 217
 		$x = abs($timeDifference);
218 218
 		$d = abs($distance);
219 219
 		if ($x == 0 || $d == 0) return true;
@@ -229,12 +229,12 @@  discard block
 block discarded – undo
229 229
 		return ($array !== array_values($array));
230 230
 	}
231 231
 
232
-	public function isInteger($input){
232
+	public function isInteger($input) {
233 233
 	    return(ctype_digit(strval($input)));
234 234
 	}
235 235
 
236 236
 
237
-	public function convertDec($dms,$latlong) {
237
+	public function convertDec($dms, $latlong) {
238 238
 		if ($latlong == 'latitude') {
239 239
 			$deg = substr($dms, 0, 2);
240 240
 			$min = substr($dms, 2, 4);
@@ -242,10 +242,10 @@  discard block
 block discarded – undo
242 242
 			$deg = substr($dms, 0, 3);
243 243
 			$min = substr($dms, 3, 5);
244 244
 		}
245
-		return $deg+(($min*60)/3600);
245
+		return $deg + (($min*60)/3600);
246 246
 	}
247 247
 	
248
-	public function convertDM($coord,$latlong) {
248
+	public function convertDM($coord, $latlong) {
249 249
 		if ($latlong == 'latitude') {
250 250
 			if ($coord < 0) $NSEW = 'S';
251 251
 			else $NSEW = 'N';
@@ -255,9 +255,9 @@  discard block
 block discarded – undo
255 255
 		}
256 256
 		$coord = abs($coord);
257 257
 		$deg = floor($coord);
258
-		$coord = ($coord-$deg)*60;
258
+		$coord = ($coord - $deg)*60;
259 259
 		$min = $coord;
260
-		return array('deg' => $deg,'min' => $min,'NSEW' => $NSEW);
260
+		return array('deg' => $deg, 'min' => $min, 'NSEW' => $NSEW);
261 261
 	}
262 262
 	
263 263
 	/**
@@ -269,8 +269,8 @@  discard block
 block discarded – undo
269 269
 	public function xcopy($source, $dest)
270 270
 	{
271 271
 		$files = glob($source.'*.*');
272
-		foreach($files as $file){
273
-			$file_to_go = str_replace($source,$dest,$file);
272
+		foreach ($files as $file) {
273
+			$file_to_go = str_replace($source, $dest, $file);
274 274
 			copy($file, $file_to_go);
275 275
 		}
276 276
 		return true;
@@ -281,9 +281,9 @@  discard block
 block discarded – undo
281 281
 	* @param	String $url url to check
282 282
 	* @return	bool Return true on succes false on failure
283 283
 	*/
284
-	public function urlexist($url){
285
-		$headers=get_headers($url);
286
-		return stripos($headers[0],"200 OK")?true:false;
284
+	public function urlexist($url) {
285
+		$headers = get_headers($url);
286
+		return stripos($headers[0], "200 OK") ? true : false;
287 287
 	}
288 288
 	
289 289
 	/**
@@ -294,7 +294,7 @@  discard block
 block discarded – undo
294 294
 	public function hex2str($hex) {
295 295
 		$str = '';
296 296
 		$hexln = strlen($hex);
297
-		for($i=0;$i<$hexln;$i+=2) $str .= chr(hexdec(substr($hex,$i,2)));
297
+		for ($i = 0; $i < $hexln; $i += 2) $str .= chr(hexdec(substr($hex, $i, 2)));
298 298
 		return $str;
299 299
 	}
300 300
 	
@@ -304,7 +304,7 @@  discard block
 block discarded – undo
304 304
 	* @return	String Return result
305 305
 	*/
306 306
 	public function hex2rgb($hex) {
307
-		$hex = str_replace('#','',$hex);
307
+		$hex = str_replace('#', '', $hex);
308 308
 		return sscanf($hex, "%02x%02x%02x"); 
309 309
 	}
310 310
 	
@@ -312,33 +312,33 @@  discard block
 block discarded – undo
312 312
 		//difference in longitudinal coordinates
313 313
 		$dLon = deg2rad($lon2) - deg2rad($lon1);
314 314
 		//difference in the phi of latitudinal coordinates
315
-		$dPhi = log(tan(deg2rad($lat2) / 2 + pi() / 4) / tan(deg2rad($lat1) / 2 + pi() / 4));
315
+		$dPhi = log(tan(deg2rad($lat2)/2 + pi()/4)/tan(deg2rad($lat1)/2 + pi()/4));
316 316
 		//we need to recalculate $dLon if it is greater than pi
317
-		if(abs($dLon) > pi()) {
318
-			if($dLon > 0) {
319
-				$dLon = (2 * pi() - $dLon) * -1;
317
+		if (abs($dLon) > pi()) {
318
+			if ($dLon > 0) {
319
+				$dLon = (2*pi() - $dLon)*-1;
320 320
 			} else {
321
-				$dLon = 2 * pi() + $dLon;
321
+				$dLon = 2*pi() + $dLon;
322 322
 			}
323 323
 		}
324 324
 		//return the angle, normalized
325
-		return (rad2deg(atan2($dLon, $dPhi)) + 360) % 360;
325
+		return (rad2deg(atan2($dLon, $dPhi)) + 360)%360;
326 326
 	}
327 327
 	
328
-	public function checkLine($lat1,$lon1,$lat2,$lon2,$lat3,$lon3,$approx = 0.2) {
328
+	public function checkLine($lat1, $lon1, $lat2, $lon2, $lat3, $lon3, $approx = 0.2) {
329 329
 		//$a = ($lon2-$lon1)*$lat3+($lat2-$lat1)*$lon3+($lat1*$lon2+$lat2*$lon1);
330
-		$a = -($lon2-$lon1);
330
+		$a = -($lon2 - $lon1);
331 331
 		$b = $lat2 - $lat1;
332
-		$c = -($a*$lat1+$b*$lon1);
333
-		$d = $a*$lat3+$b*$lon3+$c;
332
+		$c = -($a*$lat1 + $b*$lon1);
333
+		$d = $a*$lat3 + $b*$lon3 + $c;
334 334
 		if ($d > -$approx && $d < $approx) return true;
335 335
 		else return false;
336 336
 	}
337 337
 	
338 338
 	public function array_merge_noappend() {
339 339
 		$output = array();
340
-		foreach(func_get_args() as $array) {
341
-			foreach($array as $key => $value) {
340
+		foreach (func_get_args() as $array) {
341
+			foreach ($array as $key => $value) {
342 342
 				$output[$key] = isset($output[$key]) ?
343 343
 				array_merge($output[$key], $value) : $value;
344 344
 			}
@@ -402,34 +402,34 @@  discard block
 block discarded – undo
402 402
 		return $result;
403 403
 	}
404 404
 
405
-	public function nextcoord($latitude, $longitude, $speed, $heading, $archivespeed = 1){
405
+	public function nextcoord($latitude, $longitude, $speed, $heading, $archivespeed = 1) {
406 406
 		global $globalMapRefresh;
407 407
 		$distance = ($speed*0.514444*$globalMapRefresh*$archivespeed)/1000;
408 408
 		$r = 6378;
409 409
 		$latitude = deg2rad($latitude);
410 410
 		$longitude = deg2rad($longitude);
411 411
 		$bearing = deg2rad($heading); 
412
-		$latitude2 =  asin( (sin($latitude) * cos($distance/$r)) + (cos($latitude) * sin($distance/$r) * cos($bearing)) );
413
-		$longitude2 = $longitude + atan2( sin($bearing)*sin($distance/$r)*cos($latitude), cos($distance/$r)-(sin($latitude)*sin($latitude2)) );
414
-		return array('latitude' => number_format(rad2deg($latitude2),5,'.',''),'longitude' => number_format(rad2deg($longitude2),5,'.',''));
412
+		$latitude2 = asin((sin($latitude)*cos($distance/$r)) + (cos($latitude)*sin($distance/$r)*cos($bearing)));
413
+		$longitude2 = $longitude + atan2(sin($bearing)*sin($distance/$r)*cos($latitude), cos($distance/$r) - (sin($latitude)*sin($latitude2)));
414
+		return array('latitude' => number_format(rad2deg($latitude2), 5, '.', ''), 'longitude' => number_format(rad2deg($longitude2), 5, '.', ''));
415 415
 	}
416 416
 	
417
-	public function getCoordfromDistanceBearing($latitude,$longitude,$bearing,$distance) {
417
+	public function getCoordfromDistanceBearing($latitude, $longitude, $bearing, $distance) {
418 418
 		// distance in meter
419 419
 		$R = 6378.14;
420
-		$latitude1 = $latitude * (M_PI/180);
421
-		$longitude1 = $longitude * (M_PI/180);
422
-		$brng = $bearing * (M_PI/180);
420
+		$latitude1 = $latitude*(M_PI/180);
421
+		$longitude1 = $longitude*(M_PI/180);
422
+		$brng = $bearing*(M_PI/180);
423 423
 		$d = $distance;
424 424
 
425 425
 		$latitude2 = asin(sin($latitude1)*cos($d/$R) + cos($latitude1)*sin($d/$R)*cos($brng));
426
-		$longitude2 = $longitude1 + atan2(sin($brng)*sin($d/$R)*cos($latitude1),cos($d/$R)-sin($latitude1)*sin($latitude2));
426
+		$longitude2 = $longitude1 + atan2(sin($brng)*sin($d/$R)*cos($latitude1), cos($d/$R) - sin($latitude1)*sin($latitude2));
427 427
 
428
-		$latitude2 = $latitude2 * (180/M_PI);
429
-		$longitude2 = $longitude2 * (180/M_PI);
428
+		$latitude2 = $latitude2*(180/M_PI);
429
+		$longitude2 = $longitude2*(180/M_PI);
430 430
 
431
-		$flat = round ($latitude2,6);
432
-		$flong = round ($longitude2,6);
431
+		$flat = round($latitude2, 6);
432
+		$flong = round($longitude2, 6);
433 433
 /*
434 434
 		$dx = $distance*cos($bearing);
435 435
 		$dy = $distance*sin($bearing);
@@ -438,7 +438,7 @@  discard block
 block discarded – undo
438 438
 		$flong = $longitude + $dlong;
439 439
 		$flat = $latitude + $dlat;
440 440
 */
441
-		return array('latitude' => $flat,'longitude' => $flong);
441
+		return array('latitude' => $flat, 'longitude' => $flong);
442 442
 	}
443 443
 
444 444
 	/**
@@ -452,14 +452,14 @@  discard block
 block discarded – undo
452 452
 	 * @param integer $level GZIP compression level (default: 9)
453 453
 	 * @return string New filename (with .gz appended) if success, or false if operation fails
454 454
 	 */
455
-	public function gzCompressFile($source, $level = 9){ 
456
-		$dest = $source . '.gz'; 
457
-		$mode = 'wb' . $level; 
455
+	public function gzCompressFile($source, $level = 9) { 
456
+		$dest = $source.'.gz'; 
457
+		$mode = 'wb'.$level; 
458 458
 		$error = false; 
459 459
 		if ($fp_out = gzopen($dest, $mode)) { 
460
-			if ($fp_in = fopen($source,'rb')) { 
460
+			if ($fp_in = fopen($source, 'rb')) { 
461 461
 				while (!feof($fp_in)) 
462
-					gzwrite($fp_out, fread($fp_in, 1024 * 512)); 
462
+					gzwrite($fp_out, fread($fp_in, 1024*512)); 
463 463
 				fclose($fp_in); 
464 464
 			} else {
465 465
 				$error = true; 
@@ -475,7 +475,7 @@  discard block
 block discarded – undo
475 475
 	} 
476 476
 	
477 477
 	public function remove_accents($string) {
478
-		if ( !preg_match('/[\x80-\xff]/', $string) ) return $string;
478
+		if (!preg_match('/[\x80-\xff]/', $string)) return $string;
479 479
 		$chars = array(
480 480
 		    // Decompositions for Latin-1 Supplement
481 481
 		    chr(195).chr(128) => 'A', chr(195).chr(129) => 'A',
@@ -532,7 +532,7 @@  discard block
 block discarded – undo
532 532
 		    chr(196).chr(172) => 'I', chr(196).chr(173) => 'i',
533 533
 		    chr(196).chr(174) => 'I', chr(196).chr(175) => 'i',
534 534
 		    chr(196).chr(176) => 'I', chr(196).chr(177) => 'i',
535
-		    chr(196).chr(178) => 'IJ',chr(196).chr(179) => 'ij',
535
+		    chr(196).chr(178) => 'IJ', chr(196).chr(179) => 'ij',
536 536
 		    chr(196).chr(180) => 'J', chr(196).chr(181) => 'j',
537 537
 		    chr(196).chr(182) => 'K', chr(196).chr(183) => 'k',
538 538
 		    chr(196).chr(184) => 'k', chr(196).chr(185) => 'L',
@@ -548,13 +548,13 @@  discard block
 block discarded – undo
548 548
 		    chr(197).chr(140) => 'O', chr(197).chr(141) => 'o',
549 549
 		    chr(197).chr(142) => 'O', chr(197).chr(143) => 'o',
550 550
 		    chr(197).chr(144) => 'O', chr(197).chr(145) => 'o',
551
-		    chr(197).chr(146) => 'OE',chr(197).chr(147) => 'oe',
552
-		    chr(197).chr(148) => 'R',chr(197).chr(149) => 'r',
553
-		    chr(197).chr(150) => 'R',chr(197).chr(151) => 'r',
554
-		    chr(197).chr(152) => 'R',chr(197).chr(153) => 'r',
555
-		    chr(197).chr(154) => 'S',chr(197).chr(155) => 's',
556
-		    chr(197).chr(156) => 'S',chr(197).chr(157) => 's',
557
-		    chr(197).chr(158) => 'S',chr(197).chr(159) => 's',
551
+		    chr(197).chr(146) => 'OE', chr(197).chr(147) => 'oe',
552
+		    chr(197).chr(148) => 'R', chr(197).chr(149) => 'r',
553
+		    chr(197).chr(150) => 'R', chr(197).chr(151) => 'r',
554
+		    chr(197).chr(152) => 'R', chr(197).chr(153) => 'r',
555
+		    chr(197).chr(154) => 'S', chr(197).chr(155) => 's',
556
+		    chr(197).chr(156) => 'S', chr(197).chr(157) => 's',
557
+		    chr(197).chr(158) => 'S', chr(197).chr(159) => 's',
558 558
 		    chr(197).chr(160) => 'S', chr(197).chr(161) => 's',
559 559
 		    chr(197).chr(162) => 'T', chr(197).chr(163) => 't',
560 560
 		    chr(197).chr(164) => 'T', chr(197).chr(165) => 't',
@@ -588,7 +588,7 @@  discard block
 block discarded – undo
588 588
 		for ($i = 0, $int = '', $concat_flag = true; $i < $length; $i++) {
589 589
 			if (is_numeric($string[$i]) && $concat_flag) {
590 590
 				$int .= $string[$i];
591
-			} elseif(!$concat && $concat_flag && strlen($int) > 0) {
591
+			} elseif (!$concat && $concat_flag && strlen($int) > 0) {
592 592
 				$concat_flag = false;
593 593
 			}
594 594
 		}
Please login to merge, or discard this patch.
Braces   +81 added lines, -34 removed lines patch added patch discarded remove patch
@@ -37,8 +37,11 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 		}
Please login to merge, or discard this patch.