芝麻web文件管理V1.00
编辑当前文件:/var/www/cognitio.in/wp-content/plugins/wp-mail-smtp/src/Geo.php
sanitize_text_field( $request['latitude'] ), 'longitude' => sanitize_text_field( $request['longitude'] ), 'city' => isset( $request['city'] ) ? sanitize_text_field( $request['city'] ) : '', 'region' => isset( $request['region_name'] ) ? sanitize_text_field( $request['region_name'] ) : '', 'country' => isset( $request['country_iso'] ) ? sanitize_text_field( $request['country_iso'] ) : '', 'postal' => isset( $request['zip_code'] ) ? sanitize_text_field( $request['zip_code'] ) : '', ]; return $data; } } $request = wp_remote_get( 'https://ipapi.co/' . $ip . '/json' ); if ( ! is_wp_error( $request ) ) { $request = json_decode( wp_remote_retrieve_body( $request ), true ); if ( ! empty( $request['latitude'] ) && ! empty( $request['longitude'] ) ) { $data = [ 'latitude' => sanitize_text_field( $request['latitude'] ), 'longitude' => sanitize_text_field( $request['longitude'] ), 'city' => isset( $request['city'] ) ? sanitize_text_field( $request['city'] ) : '', 'region' => isset( $request['region'] ) ? sanitize_text_field( $request['region'] ) : '', 'country' => isset( $request['country'] ) ? sanitize_text_field( $request['country'] ) : '', 'postal' => isset( $request['postal'] ) ? sanitize_text_field( $request['postal'] ) : '', ]; return $data; } } $request = wp_remote_get( 'https://tools.keycdn.com/geo.json?host=' . $ip, [ 'user-agent' => 'keycdn-tools:' . get_home_url(), ] ); if ( ! is_wp_error( $request ) ) { $request = json_decode( wp_remote_retrieve_body( $request ), true ); if ( ! empty( $request['data']['geo']['latitude'] ) && ! empty( $request['data']['geo']['longitude'] ) ) { $data = [ 'latitude' => sanitize_text_field( $request['data']['geo']['latitude'] ), 'longitude' => sanitize_text_field( $request['data']['geo']['longitude'] ), 'city' => isset( $request['data']['geo']['city'] ) ? sanitize_text_field( $request['data']['geo']['city'] ) : '', 'region' => isset( $request['data']['geo']['region_name'] ) ? sanitize_text_field( $request['data']['geo']['region_name'] ) : '', 'country' => isset( $request['data']['geo']['country_code'] ) ? sanitize_text_field( $request['data']['geo']['country_code'] ) : '', 'postal' => isset( $request['data']['geo']['postal_code'] ) ? sanitize_text_field( $request['data']['geo']['postal_code'] ) : '', ]; return $data; } } return []; } /** * This routine calculates the distance between two points (given the latitude/longitude of those points). * Definitions: South latitudes are negative, east longitudes are positive. * * @see https://www.geodatasource.com/developers/php * * @since 1.5.0 * * @param float $lat1 Latitude of point 1 (in decimal degrees). * @param float $lon1 Longitude of point 1 (in decimal degrees). * @param float $lat2 Latitude of point 2 (in decimal degrees). * @param float $lon2 Longitude of point 2 (in decimal degrees). * @param string $unit Supported values: M, K, N. Miles by default. * * @return float|int */ public static function get_distance_between( $lat1, $lon1, $lat2, $lon2, $unit = 'M' ) { if ( ( $lat1 === $lat2 ) && ( $lon1 === $lon2 ) ) { return 0; } $theta = $lon1 - $lon2; $dist = sin( deg2rad( $lat1 ) ) * sin( deg2rad( $lat2 ) ) + cos( deg2rad( $lat1 ) ) * cos( deg2rad( $lat2 ) ) * cos( deg2rad( $theta ) ); $dist = acos( $dist ); $dist = rad2deg( $dist ); $miles = $dist * 60 * 1.1515; $unit = strtoupper( $unit ); if ( $unit === 'K' ) { return ( $miles * 1.609344 ); } elseif ( $unit === 'N' ) { return ( $miles * 0.8684 ); } return $miles; } }