Completed
Push — master ( 523b76...c0c7e7 )
by Yannick
11:24
created
require/class.Common.php 1 patch
Spacing   +76 added lines, -76 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;
@@ -116,27 +116,27 @@  discard block
 block discarded – undo
116 116
 		if ($data == '') return array();
117 117
 		$html = str_get_html($data);
118 118
 		if ($html === false) return array();
119
-		$tabledata=array();
120
-		foreach($html->find('tr') as $element)
119
+		$tabledata = array();
120
+		foreach ($html->find('tr') as $element)
121 121
 		{
122 122
 			$td = array();
123
-			foreach( $element->find('th') as $row)
123
+			foreach ($element->find('th') as $row)
124 124
 			{
125 125
 				$td [] = trim($row->plaintext);
126 126
 			}
127
-			$td=array_filter($td);
127
+			$td = array_filter($td);
128 128
 			$tabledata[] = $td;
129 129
 
130 130
 			$td = array();
131 131
 			$tdi = array();
132
-			foreach( $element->find('td') as $row)
132
+			foreach ($element->find('td') as $row)
133 133
 			{
134 134
 				$td [] = trim($row->plaintext);
135 135
 				$tdi [] = trim($row->innertext);
136 136
 			}
137
-			$td=array_filter($td);
138
-			$tdi=array_filter($tdi);
139
-			$tabledata[]=array_merge($td,$tdi);
137
+			$td = array_filter($td);
138
+			$tdi = array_filter($tdi);
139
+			$tabledata[] = array_merge($td, $tdi);
140 140
 		}
141 141
 		$html->clear();
142 142
 		unset($html);
@@ -151,8 +151,8 @@  discard block
 block discarded – undo
151 151
 	public function text2array($data) {
152 152
 		$html = str_get_html($data);
153 153
 		if ($html === false) return array();
154
-		$tabledata=array();
155
-		foreach($html->find('p') as $element)
154
+		$tabledata = array();
155
+		foreach ($html->find('p') as $element)
156 156
 		{
157 157
 			$tabledata [] = trim($element->plaintext);
158 158
 		}
@@ -172,11 +172,11 @@  discard block
 block discarded – undo
172 172
 	*/
173 173
 	public function distance($lat, $lon, $latc, $lonc, $unit = 'km') {
174 174
 		if ($lat == $latc && $lon == $lonc) return 0;
175
-		$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;
175
+		$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;
176 176
 		if ($unit == "km") {
177
-			return round($dist * 1.609344);
177
+			return round($dist*1.609344);
178 178
 		} elseif ($unit == "m") {
179
-			return round($dist * 1.609344 * 1000);
179
+			return round($dist*1.609344*1000);
180 180
 		} elseif ($unit == "mile" || $unit == "mi") {
181 181
 			return round($dist);
182 182
 		} elseif ($unit == "nm") {
@@ -192,7 +192,7 @@  discard block
 block discarded – undo
192 192
 	* @param float $distance distance covered
193 193
 	* @return whether distance is realistic
194 194
 	*/
195
-	public function withinThreshold ($timeDifference, $distance) {
195
+	public function withinThreshold($timeDifference, $distance) {
196 196
 		$x = abs($timeDifference);
197 197
 		$d = abs($distance);
198 198
 		if ($x == 0 || $d == 0) return true;
@@ -208,12 +208,12 @@  discard block
 block discarded – undo
208 208
 		return ($array !== array_values($array));
209 209
 	}
210 210
 
211
-	public function isInteger($input){
211
+	public function isInteger($input) {
212 212
 	    return(ctype_digit(strval($input)));
213 213
 	}
214 214
 
215 215
 
216
-	public function convertDec($dms,$latlong) {
216
+	public function convertDec($dms, $latlong) {
217 217
 		if ($latlong == 'latitude') {
218 218
 			$deg = substr($dms, 0, 2);
219 219
 			$min = substr($dms, 2, 4);
@@ -221,10 +221,10 @@  discard block
 block discarded – undo
221 221
 			$deg = substr($dms, 0, 3);
222 222
 			$min = substr($dms, 3, 5);
223 223
 		}
224
-		return $deg+(($min*60)/3600);
224
+		return $deg + (($min*60)/3600);
225 225
 	}
226 226
 	
227
-	public function convertDM($coord,$latlong) {
227
+	public function convertDM($coord, $latlong) {
228 228
 		if ($latlong == 'latitude') {
229 229
 			if ($coord < 0) $NSEW = 'S';
230 230
 			else $NSEW = 'N';
@@ -234,9 +234,9 @@  discard block
 block discarded – undo
234 234
 		}
235 235
 		$coord = abs($coord);
236 236
 		$deg = floor($coord);
237
-		$coord = ($coord-$deg)*60;
237
+		$coord = ($coord - $deg)*60;
238 238
 		$min = $coord;
239
-		return array('deg' => $deg,'min' => $min,'NSEW' => $NSEW);
239
+		return array('deg' => $deg, 'min' => $min, 'NSEW' => $NSEW);
240 240
 	}
241 241
 	
242 242
 	/**
@@ -248,8 +248,8 @@  discard block
 block discarded – undo
248 248
 	public function xcopy($source, $dest)
249 249
 	{
250 250
 		$files = glob($source.'*.*');
251
-		foreach($files as $file){
252
-			$file_to_go = str_replace($source,$dest,$file);
251
+		foreach ($files as $file) {
252
+			$file_to_go = str_replace($source, $dest, $file);
253 253
 			copy($file, $file_to_go);
254 254
 		}
255 255
 		return true;
@@ -260,9 +260,9 @@  discard block
 block discarded – undo
260 260
 	* @param	String $url url to check
261 261
 	* @return	bool Return true on succes false on failure
262 262
 	*/
263
-	public function urlexist($url){
264
-		$headers=get_headers($url);
265
-		return stripos($headers[0],"200 OK")?true:false;
263
+	public function urlexist($url) {
264
+		$headers = get_headers($url);
265
+		return stripos($headers[0], "200 OK") ? true : false;
266 266
 	}
267 267
 	
268 268
 	/**
@@ -273,7 +273,7 @@  discard block
 block discarded – undo
273 273
 	public function hex2str($hex) {
274 274
 		$str = '';
275 275
 		$hexln = strlen($hex);
276
-		for($i=0;$i<$hexln;$i+=2) $str .= chr(hexdec(substr($hex,$i,2)));
276
+		for ($i = 0; $i < $hexln; $i += 2) $str .= chr(hexdec(substr($hex, $i, 2)));
277 277
 		return $str;
278 278
 	}
279 279
 	
@@ -283,7 +283,7 @@  discard block
 block discarded – undo
283 283
 	* @return	String Return result
284 284
 	*/
285 285
 	public function hex2rgb($hex) {
286
-		$hex = str_replace('#','',$hex);
286
+		$hex = str_replace('#', '', $hex);
287 287
 		return sscanf($hex, "%02x%02x%02x"); 
288 288
 	}
289 289
 	
@@ -291,33 +291,33 @@  discard block
 block discarded – undo
291 291
 		//difference in longitudinal coordinates
292 292
 		$dLon = deg2rad($lon2) - deg2rad($lon1);
293 293
 		//difference in the phi of latitudinal coordinates
294
-		$dPhi = log(tan(deg2rad($lat2) / 2 + pi() / 4) / tan(deg2rad($lat1) / 2 + pi() / 4));
294
+		$dPhi = log(tan(deg2rad($lat2)/2 + pi()/4)/tan(deg2rad($lat1)/2 + pi()/4));
295 295
 		//we need to recalculate $dLon if it is greater than pi
296
-		if(abs($dLon) > pi()) {
297
-			if($dLon > 0) {
298
-				$dLon = (2 * pi() - $dLon) * -1;
296
+		if (abs($dLon) > pi()) {
297
+			if ($dLon > 0) {
298
+				$dLon = (2*pi() - $dLon)*-1;
299 299
 			} else {
300
-				$dLon = 2 * pi() + $dLon;
300
+				$dLon = 2*pi() + $dLon;
301 301
 			}
302 302
 		}
303 303
 		//return the angle, normalized
304
-		return (rad2deg(atan2($dLon, $dPhi)) + 360) % 360;
304
+		return (rad2deg(atan2($dLon, $dPhi)) + 360)%360;
305 305
 	}
306 306
 	
307
-	public function checkLine($lat1,$lon1,$lat2,$lon2,$lat3,$lon3,$approx = 0.2) {
307
+	public function checkLine($lat1, $lon1, $lat2, $lon2, $lat3, $lon3, $approx = 0.2) {
308 308
 		//$a = ($lon2-$lon1)*$lat3+($lat2-$lat1)*$lon3+($lat1*$lon2+$lat2*$lon1);
309
-		$a = -($lon2-$lon1);
309
+		$a = -($lon2 - $lon1);
310 310
 		$b = $lat2 - $lat1;
311
-		$c = -($a*$lat1+$b*$lon1);
312
-		$d = $a*$lat3+$b*$lon3+$c;
311
+		$c = -($a*$lat1 + $b*$lon1);
312
+		$d = $a*$lat3 + $b*$lon3 + $c;
313 313
 		if ($d > -$approx && $d < $approx) return true;
314 314
 		else return false;
315 315
 	}
316 316
 	
317 317
 	public function array_merge_noappend() {
318 318
 		$output = array();
319
-		foreach(func_get_args() as $array) {
320
-			foreach($array as $key => $value) {
319
+		foreach (func_get_args() as $array) {
320
+			foreach ($array as $key => $value) {
321 321
 				$output[$key] = isset($output[$key]) ?
322 322
 				array_merge($output[$key], $value) : $value;
323 323
 			}
@@ -381,34 +381,34 @@  discard block
 block discarded – undo
381 381
 		return $result;
382 382
 	}
383 383
 
384
-	public function nextcoord($latitude, $longitude, $speed, $heading, $archivespeed = 1){
384
+	public function nextcoord($latitude, $longitude, $speed, $heading, $archivespeed = 1) {
385 385
 		global $globalMapRefresh;
386 386
 		$distance = ($speed*0.514444*$globalMapRefresh*$archivespeed)/1000;
387 387
 		$r = 6378;
388 388
 		$latitude = deg2rad($latitude);
389 389
 		$longitude = deg2rad($longitude);
390 390
 		$bearing = deg2rad($heading); 
391
-		$latitude2 =  asin( (sin($latitude) * cos($distance/$r)) + (cos($latitude) * sin($distance/$r) * cos($bearing)) );
392
-		$longitude2 = $longitude + atan2( sin($bearing)*sin($distance/$r)*cos($latitude), cos($distance/$r)-(sin($latitude)*sin($latitude2)) );
393
-		return array('latitude' => number_format(rad2deg($latitude2),5,'.',''),'longitude' => number_format(rad2deg($longitude2),5,'.',''));
391
+		$latitude2 = asin((sin($latitude)*cos($distance/$r)) + (cos($latitude)*sin($distance/$r)*cos($bearing)));
392
+		$longitude2 = $longitude + atan2(sin($bearing)*sin($distance/$r)*cos($latitude), cos($distance/$r) - (sin($latitude)*sin($latitude2)));
393
+		return array('latitude' => number_format(rad2deg($latitude2), 5, '.', ''), 'longitude' => number_format(rad2deg($longitude2), 5, '.', ''));
394 394
 	}
395 395
 	
396
-	public function getCoordfromDistanceBearing($latitude,$longitude,$bearing,$distance) {
396
+	public function getCoordfromDistanceBearing($latitude, $longitude, $bearing, $distance) {
397 397
 		// distance in meter
398 398
 		$R = 6378.14;
399
-		$latitude1 = $latitude * (M_PI/180);
400
-		$longitude1 = $longitude * (M_PI/180);
401
-		$brng = $bearing * (M_PI/180);
399
+		$latitude1 = $latitude*(M_PI/180);
400
+		$longitude1 = $longitude*(M_PI/180);
401
+		$brng = $bearing*(M_PI/180);
402 402
 		$d = $distance;
403 403
 
404 404
 		$latitude2 = asin(sin($latitude1)*cos($d/$R) + cos($latitude1)*sin($d/$R)*cos($brng));
405
-		$longitude2 = $longitude1 + atan2(sin($brng)*sin($d/$R)*cos($latitude1),cos($d/$R)-sin($latitude1)*sin($latitude2));
405
+		$longitude2 = $longitude1 + atan2(sin($brng)*sin($d/$R)*cos($latitude1), cos($d/$R) - sin($latitude1)*sin($latitude2));
406 406
 
407
-		$latitude2 = $latitude2 * (180/M_PI);
408
-		$longitude2 = $longitude2 * (180/M_PI);
407
+		$latitude2 = $latitude2*(180/M_PI);
408
+		$longitude2 = $longitude2*(180/M_PI);
409 409
 
410
-		$flat = round ($latitude2,6);
411
-		$flong = round ($longitude2,6);
410
+		$flat = round($latitude2, 6);
411
+		$flong = round($longitude2, 6);
412 412
 /*
413 413
 		$dx = $distance*cos($bearing);
414 414
 		$dy = $distance*sin($bearing);
@@ -417,7 +417,7 @@  discard block
 block discarded – undo
417 417
 		$flong = $longitude + $dlong;
418 418
 		$flat = $latitude + $dlat;
419 419
 */
420
-		return array('latitude' => $flat,'longitude' => $flong);
420
+		return array('latitude' => $flat, 'longitude' => $flong);
421 421
 	}
422 422
 
423 423
 	/**
@@ -431,14 +431,14 @@  discard block
 block discarded – undo
431 431
 	 * @param integer $level GZIP compression level (default: 9)
432 432
 	 * @return string New filename (with .gz appended) if success, or false if operation fails
433 433
 	 */
434
-	public function gzCompressFile($source, $level = 9){ 
435
-		$dest = $source . '.gz'; 
436
-		$mode = 'wb' . $level; 
434
+	public function gzCompressFile($source, $level = 9) { 
435
+		$dest = $source.'.gz'; 
436
+		$mode = 'wb'.$level; 
437 437
 		$error = false; 
438 438
 		if ($fp_out = gzopen($dest, $mode)) { 
439
-			if ($fp_in = fopen($source,'rb')) { 
439
+			if ($fp_in = fopen($source, 'rb')) { 
440 440
 				while (!feof($fp_in)) 
441
-					gzwrite($fp_out, fread($fp_in, 1024 * 512)); 
441
+					gzwrite($fp_out, fread($fp_in, 1024*512)); 
442 442
 				fclose($fp_in); 
443 443
 			} else {
444 444
 				$error = true; 
@@ -454,7 +454,7 @@  discard block
 block discarded – undo
454 454
 	} 
455 455
 	
456 456
 	public function remove_accents($string) {
457
-		if ( !preg_match('/[\x80-\xff]/', $string) ) return $string;
457
+		if (!preg_match('/[\x80-\xff]/', $string)) return $string;
458 458
 		$chars = array(
459 459
 		    // Decompositions for Latin-1 Supplement
460 460
 		    chr(195).chr(128) => 'A', chr(195).chr(129) => 'A',
@@ -511,7 +511,7 @@  discard block
 block discarded – undo
511 511
 		    chr(196).chr(172) => 'I', chr(196).chr(173) => 'i',
512 512
 		    chr(196).chr(174) => 'I', chr(196).chr(175) => 'i',
513 513
 		    chr(196).chr(176) => 'I', chr(196).chr(177) => 'i',
514
-		    chr(196).chr(178) => 'IJ',chr(196).chr(179) => 'ij',
514
+		    chr(196).chr(178) => 'IJ', chr(196).chr(179) => 'ij',
515 515
 		    chr(196).chr(180) => 'J', chr(196).chr(181) => 'j',
516 516
 		    chr(196).chr(182) => 'K', chr(196).chr(183) => 'k',
517 517
 		    chr(196).chr(184) => 'k', chr(196).chr(185) => 'L',
@@ -527,13 +527,13 @@  discard block
 block discarded – undo
527 527
 		    chr(197).chr(140) => 'O', chr(197).chr(141) => 'o',
528 528
 		    chr(197).chr(142) => 'O', chr(197).chr(143) => 'o',
529 529
 		    chr(197).chr(144) => 'O', chr(197).chr(145) => 'o',
530
-		    chr(197).chr(146) => 'OE',chr(197).chr(147) => 'oe',
531
-		    chr(197).chr(148) => 'R',chr(197).chr(149) => 'r',
532
-		    chr(197).chr(150) => 'R',chr(197).chr(151) => 'r',
533
-		    chr(197).chr(152) => 'R',chr(197).chr(153) => 'r',
534
-		    chr(197).chr(154) => 'S',chr(197).chr(155) => 's',
535
-		    chr(197).chr(156) => 'S',chr(197).chr(157) => 's',
536
-		    chr(197).chr(158) => 'S',chr(197).chr(159) => 's',
530
+		    chr(197).chr(146) => 'OE', chr(197).chr(147) => 'oe',
531
+		    chr(197).chr(148) => 'R', chr(197).chr(149) => 'r',
532
+		    chr(197).chr(150) => 'R', chr(197).chr(151) => 'r',
533
+		    chr(197).chr(152) => 'R', chr(197).chr(153) => 'r',
534
+		    chr(197).chr(154) => 'S', chr(197).chr(155) => 's',
535
+		    chr(197).chr(156) => 'S', chr(197).chr(157) => 's',
536
+		    chr(197).chr(158) => 'S', chr(197).chr(159) => 's',
537 537
 		    chr(197).chr(160) => 'S', chr(197).chr(161) => 's',
538 538
 		    chr(197).chr(162) => 'T', chr(197).chr(163) => 't',
539 539
 		    chr(197).chr(164) => 'T', chr(197).chr(165) => 't',
@@ -567,7 +567,7 @@  discard block
 block discarded – undo
567 567
 		for ($i = 0, $int = '', $concat_flag = true; $i < $length; $i++) {
568 568
 			if (is_numeric($string[$i]) && $concat_flag) {
569 569
 				$int .= $string[$i];
570
-			} elseif(!$concat && $concat_flag && strlen($int) > 0) {
570
+			} elseif (!$concat && $concat_flag && strlen($int) > 0) {
571 571
 				$concat_flag = false;
572 572
 			}
573 573
 		}
Please login to merge, or discard this patch.