Sindbad~EG File Manager

Current Path : /home/xiedrke/entrepot/wp-content/plugins/realpress/app/Helpers/
Upload File :
Current File : /home/xiedrke/entrepot/wp-content/plugins/realpress/app/Helpers/YelpNearBy.php

<?php

namespace RealPress\Helpers;

/**
 * Class YelpNearBy
 * @package RealPress\Helpers
 */
class YelpNearBy {
	/**
	 * @param $term
	 * @param array $lat_lng
	 *
	 * @return array
	 */
	public static function get_data( $term, array $lat_lng = array() ) {
		$api_key = Settings::get_setting_detail( 'group:yelp_nearby:fields:api' );
		if ( empty( $api_key ) ) {
			return array(
				'status' => 'error',
				'msg'    => esc_html__( 'Please set up API in the setting.', 'realpress' ),
			);
		}
		$location  = implode( ',', $lat_lng );
		$query_url = add_query_arg(
			array(
				'term'     => $term,
				'location' => $location,
				'limit'    => Settings::get_setting_detail( 'group:yelp_nearby:fields:limit' ),
				'sort_by'  => 'distance',
			),
			'https://api.yelp.com/v3/businesses/search'
		);

		$args = array(
			'user-agent' => '',
			'headers'    => array(
				'authorization' => 'Bearer ' . $api_key,
			),
		);

		$response = wp_safe_remote_get( $query_url, $args );
		if ( is_wp_error( $response ) ) {
			return array(
				'status' => 'error',
				'msg'    => $response->get_error_message(),
			);
		}

		$body = wp_remote_retrieve_body( $response );
		$data = json_decode( $body, false );

		return array(
			'status' => 'success',
			'data'   => $data,
		);
	}

	/**
	 * @param $lat_1
	 * @param $lng_1
	 * @param $lat_2
	 * @param $lng_2
	 * @param string $unit
	 *
	 * @return float
	 */
	public static function get_distance( $lat_1, $lng_1, $lat_2, $lng_2, string $unit = 'km' ) {
		$theta = $lng_1 - $lng_2;
		$dist  = sin( deg2rad( $lat_1 ) ) * sin( deg2rad( $lat_2 ) ) + cos( deg2rad( $lat_1 ) ) * cos( deg2rad( $lat_2 ) ) * cos( deg2rad( $theta ) );
		$dist  = acos( $dist );

		if ( $unit === 'km' ) {
			$dist = $dist * 60 * 1.609344;
		} elseif ( $unit === 'miles' ) {
			$dist = $dist * 60 * 1.1515;
		}

		return rad2deg( $dist );
	}
}

Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists