@@ -13,13 +13,13 @@ discard block |
||
| 13 | 13 | * @param Array $headers header to submit with the form |
| 14 | 14 | * @return String the result |
| 15 | 15 | */ |
| 16 | - public function getData($url, $type = 'get', $data = '', $headers = '',$cookie = '',$referer = '',$timeout = '',$useragent = '') { |
|
| 16 | + public function getData($url, $type = 'get', $data = '', $headers = '', $cookie = '', $referer = '', $timeout = '', $useragent = '') { |
|
| 17 | 17 | $ch = curl_init(); |
| 18 | 18 | curl_setopt($ch, CURLOPT_URL, $url); |
| 19 | 19 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); |
| 20 | 20 | curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); |
| 21 | 21 | curl_setopt($ch, CURLINFO_HEADER_OUT, true); |
| 22 | - curl_setopt($ch,CURLOPT_ENCODING , "gzip"); |
|
| 22 | + curl_setopt($ch, CURLOPT_ENCODING, "gzip"); |
|
| 23 | 23 | //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'); |
| 24 | 24 | // curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (X11; Linux x86_64; rv:42.0) Gecko/20100101 Firefox/42.0'); |
| 25 | 25 | if ($useragent == '') { |
@@ -29,13 +29,13 @@ discard block |
||
| 29 | 29 | } |
| 30 | 30 | if ($timeout == '') curl_setopt($ch, CURLOPT_TIMEOUT, 10); |
| 31 | 31 | else curl_setopt($ch, CURLOPT_TIMEOUT, $timeout); |
| 32 | - curl_setopt($ch, CURLOPT_HEADERFUNCTION, array('Common',"curlResponseHeaderCallback")); |
|
| 32 | + curl_setopt($ch, CURLOPT_HEADERFUNCTION, array('Common', "curlResponseHeaderCallback")); |
|
| 33 | 33 | if ($type == 'post') { |
| 34 | 34 | curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); |
| 35 | 35 | if (is_array($data)) { |
| 36 | 36 | curl_setopt($ch, CURLOPT_POST, count($data)); |
| 37 | 37 | $data_string = ''; |
| 38 | - foreach($data as $key=>$value) { $data_string .= $key.'='.$value.'&'; } |
|
| 38 | + foreach ($data as $key=>$value) { $data_string .= $key.'='.$value.'&'; } |
|
| 39 | 39 | rtrim($data_string, '&'); |
| 40 | 40 | curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string); |
| 41 | 41 | } else { |
@@ -47,7 +47,7 @@ discard block |
||
| 47 | 47 | } |
| 48 | 48 | if ($cookie != '') { |
| 49 | 49 | if (is_array($cookie)) { |
| 50 | - curl_setopt($ch, CURLOPT_COOKIE, implode($cookie,';')); |
|
| 50 | + curl_setopt($ch, CURLOPT_COOKIE, implode($cookie, ';')); |
|
| 51 | 51 | } else { |
| 52 | 52 | curl_setopt($ch, CURLOPT_COOKIE, $cookie); |
| 53 | 53 | } |
@@ -58,13 +58,13 @@ discard block |
||
| 58 | 58 | $result = curl_exec($ch); |
| 59 | 59 | $info = curl_getinfo($ch); |
| 60 | 60 | curl_close($ch); |
| 61 | - if ($info['http_code'] == '503' && strstr($result,'DDoS protection by CloudFlare')) { |
|
| 61 | + if ($info['http_code'] == '503' && strstr($result, 'DDoS protection by CloudFlare')) { |
|
| 62 | 62 | echo "Cloudflare Detected\n"; |
| 63 | 63 | require_once(dirname(__FILE__).'/libs/cloudflare-bypass/libraries/cloudflareClass.php'); |
| 64 | 64 | $useragent = UAgent::random(); |
| 65 | 65 | cloudflare::useUserAgent($useragent); |
| 66 | 66 | if ($clearanceCookie = cloudflare::bypass($url)) { |
| 67 | - return $this->getData($url,'get',$data,$headers,$clearanceCookie,$referer,$timeout,$useragent); |
|
| 67 | + return $this->getData($url, 'get', $data, $headers, $clearanceCookie, $referer, $timeout, $useragent); |
|
| 68 | 68 | } |
| 69 | 69 | } else { |
| 70 | 70 | return $result; |
@@ -105,27 +105,27 @@ discard block |
||
| 105 | 105 | if ($data == '') return array(); |
| 106 | 106 | $html = str_get_html($data); |
| 107 | 107 | if ($html === false) return array(); |
| 108 | - $tabledata=array(); |
|
| 109 | - foreach($html->find('tr') as $element) |
|
| 108 | + $tabledata = array(); |
|
| 109 | + foreach ($html->find('tr') as $element) |
|
| 110 | 110 | { |
| 111 | 111 | $td = array(); |
| 112 | - foreach( $element->find('th') as $row) |
|
| 112 | + foreach ($element->find('th') as $row) |
|
| 113 | 113 | { |
| 114 | 114 | $td [] = trim($row->plaintext); |
| 115 | 115 | } |
| 116 | - $td=array_filter($td); |
|
| 116 | + $td = array_filter($td); |
|
| 117 | 117 | $tabledata[] = $td; |
| 118 | 118 | |
| 119 | 119 | $td = array(); |
| 120 | 120 | $tdi = array(); |
| 121 | - foreach( $element->find('td') as $row) |
|
| 121 | + foreach ($element->find('td') as $row) |
|
| 122 | 122 | { |
| 123 | 123 | $td [] = trim($row->plaintext); |
| 124 | 124 | $tdi [] = trim($row->innertext); |
| 125 | 125 | } |
| 126 | - $td=array_filter($td); |
|
| 127 | - $tdi=array_filter($tdi); |
|
| 128 | - $tabledata[]=array_merge($td,$tdi); |
|
| 126 | + $td = array_filter($td); |
|
| 127 | + $tdi = array_filter($tdi); |
|
| 128 | + $tabledata[] = array_merge($td, $tdi); |
|
| 129 | 129 | } |
| 130 | 130 | $html->clear(); |
| 131 | 131 | unset($html); |
@@ -140,8 +140,8 @@ discard block |
||
| 140 | 140 | public function text2array($data) { |
| 141 | 141 | $html = str_get_html($data); |
| 142 | 142 | if ($html === false) return array(); |
| 143 | - $tabledata=array(); |
|
| 144 | - foreach($html->find('p') as $element) |
|
| 143 | + $tabledata = array(); |
|
| 144 | + foreach ($html->find('p') as $element) |
|
| 145 | 145 | { |
| 146 | 146 | $tabledata [] = trim($element->plaintext); |
| 147 | 147 | } |
@@ -161,11 +161,11 @@ discard block |
||
| 161 | 161 | */ |
| 162 | 162 | public function distance($lat, $lon, $latc, $lonc, $unit = 'km') { |
| 163 | 163 | if ($lat == $latc && $lon == $lonc) return 0; |
| 164 | - $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; |
|
| 164 | + $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; |
|
| 165 | 165 | if ($unit == "km") { |
| 166 | - return round($dist * 1.609344); |
|
| 166 | + return round($dist*1.609344); |
|
| 167 | 167 | } elseif ($unit == "m") { |
| 168 | - return round($dist * 1.609344 * 1000); |
|
| 168 | + return round($dist*1.609344*1000); |
|
| 169 | 169 | } elseif ($unit == "mile" || $unit == "mi") { |
| 170 | 170 | return round($dist); |
| 171 | 171 | } elseif ($unit == "nm") { |
@@ -181,7 +181,7 @@ discard block |
||
| 181 | 181 | * @param float $distance distance covered |
| 182 | 182 | * @return whether distance is realistic |
| 183 | 183 | */ |
| 184 | - public function withinThreshold ($timeDifference, $distance) { |
|
| 184 | + public function withinThreshold($timeDifference, $distance) { |
|
| 185 | 185 | $x = abs($timeDifference); |
| 186 | 186 | $d = abs($distance); |
| 187 | 187 | if ($x == 0 || $d == 0) return true; |
@@ -197,12 +197,12 @@ discard block |
||
| 197 | 197 | return ($array !== array_values($array)); |
| 198 | 198 | } |
| 199 | 199 | |
| 200 | - public function isInteger($input){ |
|
| 200 | + public function isInteger($input) { |
|
| 201 | 201 | return(ctype_digit(strval($input))); |
| 202 | 202 | } |
| 203 | 203 | |
| 204 | 204 | |
| 205 | - public function convertDec($dms,$latlong) { |
|
| 205 | + public function convertDec($dms, $latlong) { |
|
| 206 | 206 | if ($latlong == 'latitude') { |
| 207 | 207 | $deg = substr($dms, 0, 2); |
| 208 | 208 | $min = substr($dms, 2, 4); |
@@ -210,7 +210,7 @@ discard block |
||
| 210 | 210 | $deg = substr($dms, 0, 3); |
| 211 | 211 | $min = substr($dms, 3, 5); |
| 212 | 212 | } |
| 213 | - return $deg+(($min*60)/3600); |
|
| 213 | + return $deg + (($min*60)/3600); |
|
| 214 | 214 | } |
| 215 | 215 | |
| 216 | 216 | /** |
@@ -222,8 +222,8 @@ discard block |
||
| 222 | 222 | public function xcopy($source, $dest) |
| 223 | 223 | { |
| 224 | 224 | $files = glob($source.'*.*'); |
| 225 | - foreach($files as $file){ |
|
| 226 | - $file_to_go = str_replace($source,$dest,$file); |
|
| 225 | + foreach ($files as $file) { |
|
| 226 | + $file_to_go = str_replace($source, $dest, $file); |
|
| 227 | 227 | copy($file, $file_to_go); |
| 228 | 228 | } |
| 229 | 229 | return true; |
@@ -234,9 +234,9 @@ discard block |
||
| 234 | 234 | * @param String $url url to check |
| 235 | 235 | * @return bool Return true on succes false on failure |
| 236 | 236 | */ |
| 237 | - public function urlexist($url){ |
|
| 238 | - $headers=get_headers($url); |
|
| 239 | - return stripos($headers[0],"200 OK")?true:false; |
|
| 237 | + public function urlexist($url) { |
|
| 238 | + $headers = get_headers($url); |
|
| 239 | + return stripos($headers[0], "200 OK") ? true : false; |
|
| 240 | 240 | } |
| 241 | 241 | |
| 242 | 242 | /** |
@@ -247,7 +247,7 @@ discard block |
||
| 247 | 247 | public function hex2str($hex) { |
| 248 | 248 | $str = ''; |
| 249 | 249 | $hexln = strlen($hex); |
| 250 | - for($i=0;$i<$hexln;$i+=2) $str .= chr(hexdec(substr($hex,$i,2))); |
|
| 250 | + for ($i = 0; $i < $hexln; $i += 2) $str .= chr(hexdec(substr($hex, $i, 2))); |
|
| 251 | 251 | return $str; |
| 252 | 252 | } |
| 253 | 253 | |
@@ -256,33 +256,33 @@ discard block |
||
| 256 | 256 | //difference in longitudinal coordinates |
| 257 | 257 | $dLon = deg2rad($lon2) - deg2rad($lon1); |
| 258 | 258 | //difference in the phi of latitudinal coordinates |
| 259 | - $dPhi = log(tan(deg2rad($lat2) / 2 + pi() / 4) / tan(deg2rad($lat1) / 2 + pi() / 4)); |
|
| 259 | + $dPhi = log(tan(deg2rad($lat2)/2 + pi()/4)/tan(deg2rad($lat1)/2 + pi()/4)); |
|
| 260 | 260 | //we need to recalculate $dLon if it is greater than pi |
| 261 | - if(abs($dLon) > pi()) { |
|
| 262 | - if($dLon > 0) { |
|
| 263 | - $dLon = (2 * pi() - $dLon) * -1; |
|
| 261 | + if (abs($dLon) > pi()) { |
|
| 262 | + if ($dLon > 0) { |
|
| 263 | + $dLon = (2*pi() - $dLon)*-1; |
|
| 264 | 264 | } else { |
| 265 | - $dLon = 2 * pi() + $dLon; |
|
| 265 | + $dLon = 2*pi() + $dLon; |
|
| 266 | 266 | } |
| 267 | 267 | } |
| 268 | 268 | //return the angle, normalized |
| 269 | - return (rad2deg(atan2($dLon, $dPhi)) + 360) % 360; |
|
| 269 | + return (rad2deg(atan2($dLon, $dPhi)) + 360)%360; |
|
| 270 | 270 | } |
| 271 | 271 | |
| 272 | - public function checkLine($lat1,$lon1,$lat2,$lon2,$lat3,$lon3,$approx = 0.1) { |
|
| 272 | + public function checkLine($lat1, $lon1, $lat2, $lon2, $lat3, $lon3, $approx = 0.1) { |
|
| 273 | 273 | //$a = ($lon2-$lon1)*$lat3+($lat2-$lat1)*$lon3+($lat1*$lon2+$lat2*$lon1); |
| 274 | - $a = -($lon2-$lon1); |
|
| 274 | + $a = -($lon2 - $lon1); |
|
| 275 | 275 | $b = $lat2 - $lat1; |
| 276 | - $c = -($a*$lat1+$b*$lon1); |
|
| 277 | - $d = $a*$lat3+$b*$lon3+$c; |
|
| 276 | + $c = -($a*$lat1 + $b*$lon1); |
|
| 277 | + $d = $a*$lat3 + $b*$lon3 + $c; |
|
| 278 | 278 | if ($d > -$approx && $d < $approx) return true; |
| 279 | 279 | else return false; |
| 280 | 280 | } |
| 281 | 281 | |
| 282 | 282 | public function array_merge_noappend() { |
| 283 | 283 | $output = array(); |
| 284 | - foreach(func_get_args() as $array) { |
|
| 285 | - foreach($array as $key => $value) { |
|
| 284 | + foreach (func_get_args() as $array) { |
|
| 285 | + foreach ($array as $key => $value) { |
|
| 286 | 286 | $output[$key] = isset($output[$key]) ? |
| 287 | 287 | array_merge($output[$key], $value) : $value; |
| 288 | 288 | } |
@@ -323,34 +323,34 @@ discard block |
||
| 323 | 323 | return $result; |
| 324 | 324 | } |
| 325 | 325 | |
| 326 | - public function nextcoord($latitude, $longitude, $speed, $heading, $archivespeed = 1){ |
|
| 326 | + public function nextcoord($latitude, $longitude, $speed, $heading, $archivespeed = 1) { |
|
| 327 | 327 | global $globalMapRefresh; |
| 328 | 328 | $distance = ($speed*0.514444*$globalMapRefresh*$archivespeed)/1000; |
| 329 | 329 | $r = 6378; |
| 330 | 330 | $latitude = deg2rad($latitude); |
| 331 | 331 | $longitude = deg2rad($longitude); |
| 332 | 332 | $bearing = deg2rad($heading); |
| 333 | - $latitude2 = asin( (sin($latitude) * cos($distance/$r)) + (cos($latitude) * sin($distance/$r) * cos($bearing)) ); |
|
| 334 | - $longitude2 = $longitude + atan2( sin($bearing)*sin($distance/$r)*cos($latitude), cos($distance/$r)-(sin($latitude)*sin($latitude2)) ); |
|
| 335 | - return array('latitude' => number_format(rad2deg($latitude2),5,'.',''),'longitude' => number_format(rad2deg($longitude2),5,'.','')); |
|
| 333 | + $latitude2 = asin((sin($latitude)*cos($distance/$r)) + (cos($latitude)*sin($distance/$r)*cos($bearing))); |
|
| 334 | + $longitude2 = $longitude + atan2(sin($bearing)*sin($distance/$r)*cos($latitude), cos($distance/$r) - (sin($latitude)*sin($latitude2))); |
|
| 335 | + return array('latitude' => number_format(rad2deg($latitude2), 5, '.', ''), 'longitude' => number_format(rad2deg($longitude2), 5, '.', '')); |
|
| 336 | 336 | } |
| 337 | 337 | |
| 338 | - public function getCoordfromDistanceBearing($latitude,$longitude,$bearing,$distance) { |
|
| 338 | + public function getCoordfromDistanceBearing($latitude, $longitude, $bearing, $distance) { |
|
| 339 | 339 | // distance in meter |
| 340 | 340 | $R = 6378.14; |
| 341 | - $latitude1 = $latitude * (M_PI/180); |
|
| 342 | - $longitude1 = $longitude * (M_PI/180); |
|
| 343 | - $brng = $bearing * (M_PI/180); |
|
| 341 | + $latitude1 = $latitude*(M_PI/180); |
|
| 342 | + $longitude1 = $longitude*(M_PI/180); |
|
| 343 | + $brng = $bearing*(M_PI/180); |
|
| 344 | 344 | $d = $distance; |
| 345 | 345 | |
| 346 | 346 | $latitude2 = asin(sin($latitude1)*cos($d/$R) + cos($latitude1)*sin($d/$R)*cos($brng)); |
| 347 | - $longitude2 = $longitude1 + atan2(sin($brng)*sin($d/$R)*cos($latitude1),cos($d/$R)-sin($latitude1)*sin($latitude2)); |
|
| 347 | + $longitude2 = $longitude1 + atan2(sin($brng)*sin($d/$R)*cos($latitude1), cos($d/$R) - sin($latitude1)*sin($latitude2)); |
|
| 348 | 348 | |
| 349 | - $latitude2 = $latitude2 * (180/M_PI); |
|
| 350 | - $longitude2 = $longitude2 * (180/M_PI); |
|
| 349 | + $latitude2 = $latitude2*(180/M_PI); |
|
| 350 | + $longitude2 = $longitude2*(180/M_PI); |
|
| 351 | 351 | |
| 352 | - $flat = round ($latitude2,6); |
|
| 353 | - $flong = round ($longitude2,6); |
|
| 352 | + $flat = round($latitude2, 6); |
|
| 353 | + $flong = round($longitude2, 6); |
|
| 354 | 354 | /* |
| 355 | 355 | $dx = $distance*cos($bearing); |
| 356 | 356 | $dy = $distance*sin($bearing); |
@@ -359,7 +359,7 @@ discard block |
||
| 359 | 359 | $flong = $longitude + $dlong; |
| 360 | 360 | $flat = $latitude + $dlat; |
| 361 | 361 | */ |
| 362 | - return array('latitude' => $flat,'longitude' => $flong); |
|
| 362 | + return array('latitude' => $flat, 'longitude' => $flong); |
|
| 363 | 363 | } |
| 364 | 364 | |
| 365 | 365 | /** |
@@ -373,14 +373,14 @@ discard block |
||
| 373 | 373 | * @param integer $level GZIP compression level (default: 9) |
| 374 | 374 | * @return string New filename (with .gz appended) if success, or false if operation fails |
| 375 | 375 | */ |
| 376 | - public function gzCompressFile($source, $level = 9){ |
|
| 377 | - $dest = $source . '.gz'; |
|
| 378 | - $mode = 'wb' . $level; |
|
| 376 | + public function gzCompressFile($source, $level = 9) { |
|
| 377 | + $dest = $source.'.gz'; |
|
| 378 | + $mode = 'wb'.$level; |
|
| 379 | 379 | $error = false; |
| 380 | 380 | if ($fp_out = gzopen($dest, $mode)) { |
| 381 | - if ($fp_in = fopen($source,'rb')) { |
|
| 381 | + if ($fp_in = fopen($source, 'rb')) { |
|
| 382 | 382 | while (!feof($fp_in)) |
| 383 | - gzwrite($fp_out, fread($fp_in, 1024 * 512)); |
|
| 383 | + gzwrite($fp_out, fread($fp_in, 1024*512)); |
|
| 384 | 384 | fclose($fp_in); |
| 385 | 385 | } else { |
| 386 | 386 | $error = true; |