Version 4.7.6

This commit is contained in:
Neo committed 2025-12-19 16:05:19 -08:00
1 parent 8ba7d43898
commit 7b7404e741
1085 files changed
+30590 -7837

No files matched your search

+81
View File
@@ -22,6 +22,87 @@ if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
*/
class _Google extends \IPS\GeoLocation\GeoCoder
{
/**
* Get by location string
*
* @param string $location
* @return \IPS\GeoLocation
* @throws \BadFunctionCallException
*/
public static function decodeLocation( string $location )
{
if ( \IPS\Settings::i()->googlemaps AND \IPS\Settings::i()->google_maps_api_key )
{
$data = \IPS\Http\Url::external( "https://maps.googleapis.com/maps/api/geocode/json" )->setQueryString( array(
'address' => $location,
'sensor' => 'false',
'key' => \IPS\Settings::i()->google_maps_api_key_secret ?: \IPS\Settings::i()->google_maps_api_key
) )->request()->get()->decodeJson();
$obj = new \IPS\GeoLocation;
$_address = '';
/* Make sure the response from Google is valid */
if( isset( $data['results'] ) AND \is_array( $data['results'] ) AND \count( $data['results'] ) )
{
if( isset( $data['results'][0]['geometry'] ) AND $data['results'][0]['geometry']['location'] )
{
$obj->lat = $data['results'][0]['geometry']['location']['lat'];
$obj->long = $data['results'][0]['geometry']['location']['lng'];
}
if( isset( $data['results'][0]['name'] ) )
{
$obj->placeName = $data['results'][0]['name'];
}
foreach( $data['results'][0]['address_components'] as $component )
{
if( $component['types'][0] == 'street_number' )
{
$_address = $component['long_name'];
}
elseif( $component['types'][0] == 'route' )
{
$_address .= " " . $component['long_name'];
}
if( $component['types'][0] == 'postal_code' )
{
$obj->postalCode = $component['long_name'];
}
if( $component['types'][0] == 'country' )
{
$obj->country = $component['short_name'];
}
if( $component['types'][0] == 'administrative_area_level_1' )
{
$obj->region = $component['long_name'];
}
if( $component['types'][0] == 'locality' )
{
$obj->city = $component['long_name'];
}
}
}
if( $_address )
{
$obj->addressLines = array( $_address );
}
return $obj;
}
else
{
throw new \BadFunctionCallException;
}
}
/**
* Get by latitude and longitude
*
+76
View File
@@ -22,6 +22,82 @@ if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
*/
class _Mapbox extends \IPS\GeoLocation\GeoCoder
{
/**
* Get by location string
*
* @param string $location
* @return \IPS\GeoLocation
* @throws \BadFunctionCallException
*/
public static function decodeLocation( string $location )
{
if ( \IPS\Settings::i()->mapbox AND \IPS\Settings::i()->mapbox_api_key )
{
$data = \IPS\Http\Url::external( "https://api.mapbox.com/geocoding/v5/mapbox.places/{$location}.json" )->setQueryString( array(
'access_token' => \IPS\Settings::i()->mapbox_api_key,
) )->request()->get()->decodeJson();
$obj = new \IPS\GeoLocation;
$_address = '';
/* Make sure the response from Mapbox is valid */
if( isset( $data['results'] ) AND \is_array( $data['results'] ) AND \count( $data['results'] ) )
{
if( isset( $data['results'][0]['geometry'] ) AND isset( $data['results'][0]['geometry']['coordinates'] ) )
{
$obj->long = $data['results'][0]['geometry']['coordinates'][0];
$obj->lat = $data['results'][0]['geometry']['coordinates'][1];
}
$obj->placeName = $data['results'][0]['place_name'];
foreach( $data['results'][0]['address_components'] as $component )
{
if( $component['types'][0] == 'street_number' )
{
$_address = $component['long_name'];
}
elseif( $component['types'][0] == 'route' )
{
$_address .= " " . $component['long_name'];
}
if( $component['types'][0] == 'postal_code' )
{
$obj->postalCode = $component['long_name'];
}
if( $component['types'][0] == 'country' )
{
$obj->country = $component['short_name'];
}
if( $component['types'][0] == 'administrative_area_level_1' )
{
$obj->region = $component['long_name'];
}
if( $component['types'][0] == 'locality' )
{
$obj->city = $component['long_name'];
}
}
}
if( $_address )
{
$obj->addressLines = array( $_address );
}
return $obj;
}
else
{
throw new \BadFunctionCallException;
}
}
/**
* Get by latitude and longitude
*
+16
View File
@@ -457,6 +457,11 @@ class _GeoLocation
* @brief Postal Code
*/
public $postalCode;
/**
* @brief Place Name
*/
public $placeName;
/**
* @brief Map
@@ -622,6 +627,17 @@ class _GeoLocation
}
}
/**
* Geocode Location
*
* @param string $input Location search term
* @return static
*/
public static function geocodeLocation( $input = NULL )
{
return \IPS\GeoLocation\GeoCoder::i()->decodeLocation( $input );
}
/**
* @brief Cached lookups to prevent duplicate lookups
*/
+13 -1
View File
@@ -50,7 +50,19 @@ class _Google
*/
public function render( $width, $height, $zoom=NULL, $scale=1, $maptype='roadmap' )
{
return \IPS\Theme::i()->getTemplate( 'global', 'core', 'global' )->staticMap( \IPS\Http\Url::external( 'https://maps.google.com/' )->setQueryString( 'q', $this->_getLocation() ), $this->mapUrl( $width, $height, $zoom, $scale, $maptype ), $this->geolocation->lat, $this->geolocation->long, $width, $height );
\IPS\Output::i()->jsFiles = array_merge( \IPS\Output::i()->jsFiles, \IPS\Output::i()->js( 'global_core.js', 'core', 'global' ) );
return \IPS\Settings::i()->google_maps_static_use_embed ?
\IPS\Theme::i()->getTemplate( 'global', 'core', 'global' )->googleMap( array(
'lat' => $this->geolocation->lat,
'long' => $this->geolocation->long,
'key' => \IPS\Settings::i()->google_maps_api_key,
'zoom' => $zoom,
'scale' => $scale,
'maptype' => $maptype,
'width' => $width,
'height' => $height )) :
\IPS\Theme::i()->getTemplate( 'global', 'core', 'global' )->staticMap( \IPS\Http\Url::external( 'https://maps.google.com/' )->setQueryString( 'q', $this->_getLocation() ), $this->mapUrl( $width, $height, $zoom, $scale, $maptype ), $this->geolocation->lat, $this->geolocation->long, $width, $height );
}
/**