Version 4.5.0
This commit is contained in:
1 parent
1a0c7fd3c2
commit
f79dcf067a
3791 files changed
+248032
-76372
No files matched your search
@@ -0,0 +1,149 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief Base class for Geolocation
|
||||
* @author <a href='https://www.invisioncommunity.com'>Invision Power Services, Inc.</a>
|
||||
* @copyright (c) Invision Power Services, Inc.
|
||||
* @license https://www.invisioncommunity.com/legal/standards/
|
||||
* @package Invision Community
|
||||
* @since 28 Aug 2018
|
||||
*/
|
||||
|
||||
namespace IPS\Geolocation\Api\GraphQL;
|
||||
use GraphQL\Type\Definition\ObjectType;
|
||||
use IPS\Api\GraphQL\TypeRegistry;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Base class for GeoLocation
|
||||
*/
|
||||
class _GeoLocationType extends ObjectType
|
||||
{
|
||||
/**
|
||||
* Get root type
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$config = [
|
||||
'name' => 'GeoLocation',
|
||||
'description' => 'Returns GeoLocation data',
|
||||
'fields' => [
|
||||
'id' => [
|
||||
'type' => TypeRegistry::id(),
|
||||
'resolve' => function ($geolocation) {
|
||||
// This field allows Apollo to more effectively cache results.
|
||||
return md5( $geolocation->toString() );
|
||||
}
|
||||
],
|
||||
'lat' => [
|
||||
'type' => TypeRegistry::float(),
|
||||
'resolve' => function ($geolocation) {
|
||||
return $geolocation->lat;
|
||||
}
|
||||
],
|
||||
'long' => [
|
||||
'type' => TypeRegistry::float(),
|
||||
'resolve' => function ($geolocation) {
|
||||
return $geolocation->long;
|
||||
}
|
||||
],
|
||||
'addressLines' => [
|
||||
'type' => TypeRegistry::string(),
|
||||
'resolve' => function ($geolocation) {
|
||||
return self::buildAddressPiece($geolocation, 'addressLines');
|
||||
}
|
||||
],
|
||||
'city' => [
|
||||
'type' => TypeRegistry::string(),
|
||||
'resolve' => function ($geolocation) {
|
||||
return self::buildAddressPiece($geolocation, 'city');
|
||||
}
|
||||
],
|
||||
'region' => [
|
||||
'type' => TypeRegistry::string(),
|
||||
'resolve' => function ($geolocation) {
|
||||
return self::buildAddressPiece($geolocation, 'region');
|
||||
}
|
||||
],
|
||||
'postalCode' => [
|
||||
'type' => TypeRegistry::string(),
|
||||
'resolve' => function ($geolocation) {
|
||||
return self::buildAddressPiece($geolocation, 'postalCode');
|
||||
}
|
||||
],
|
||||
'country' => [
|
||||
'type' => TypeRegistry::string(),
|
||||
'resolve' => function ($geolocation) {
|
||||
return self::buildAddressPiece($geolocation, 'country');
|
||||
}
|
||||
],
|
||||
'address' => [
|
||||
'type' => TypeRegistry::string(),
|
||||
'resolve' => function ($geolocation) {
|
||||
$output = array();
|
||||
|
||||
foreach ( array( 'addressLines', 'city', 'region', 'postalCode', 'country' ) as $k )
|
||||
{
|
||||
if( $piece = self::buildAddressPiece($geolocation, $k) )
|
||||
{
|
||||
$output[] = $piece;
|
||||
}
|
||||
}
|
||||
|
||||
return implode( ",\n", $output );
|
||||
}
|
||||
]
|
||||
]
|
||||
];
|
||||
|
||||
parent::__construct($config);
|
||||
}
|
||||
|
||||
protected static function buildAddressPiece($geolocation, $type)
|
||||
{
|
||||
$output = array();
|
||||
if ( $geolocation->$type )
|
||||
{
|
||||
if ( $type == 'country' )
|
||||
{
|
||||
if( $geolocation->country !== \IPS\GeoLocation::buildFromJson( \IPS\Settings::i()->site_address )->country )
|
||||
{
|
||||
try
|
||||
{
|
||||
$output[] = \IPS\Member::loggedIn()->language()->get( htmlspecialchars( 'country-' . $geolocation->country, ENT_DISALLOWED, 'UTF-8', FALSE ), FALSE, array( 'strtoupper' => TRUE ) );
|
||||
}
|
||||
catch ( \UnderflowException $e )
|
||||
{
|
||||
$output[] = htmlspecialchars( $geolocation->country, ENT_DISALLOWED, 'UTF-8', FALSE );
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( \is_array( $geolocation->$type ) )
|
||||
{
|
||||
foreach ( $geolocation->$type as $v )
|
||||
{
|
||||
if( $v )
|
||||
{
|
||||
$output[] = htmlspecialchars( $v, ENT_DISALLOWED, 'UTF-8', FALSE );
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$output[] = htmlspecialchars( $geolocation->$type, ENT_DISALLOWED, 'UTF-8', FALSE );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return implode("\n", $output);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
/**
|
||||
* @brief Type registry for \IPS\GeoLocation types
|
||||
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
|
||||
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
|
||||
* @license http://www.invisionpower.com/legal/standards/
|
||||
* @package IPS Community Suite
|
||||
* @since 29 Aug 2018
|
||||
* @version SVN_VERSION_NUMBER
|
||||
*/
|
||||
|
||||
namespace IPS\GeoLocation\Api\GraphQL;
|
||||
use GraphQL\Type\Definition\Type;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
}
|
||||
|
||||
/**
|
||||
* \IPS\GeoLocation base types
|
||||
*/
|
||||
class _TypeRegistry
|
||||
{
|
||||
protected static $geolocation;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
// Defined to suppress static warnings
|
||||
}
|
||||
|
||||
/**
|
||||
* @return GeoLocationType
|
||||
*/
|
||||
public static function geolocation()
|
||||
{
|
||||
return self::$geolocation ?: (self::$geolocation = new \IPS\GeoLocation\Api\GraphQL\GeoLocationType());
|
||||
}
|
||||
}
|
||||
@@ -11,7 +11,7 @@
|
||||
namespace IPS\GeoLocation;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
namespace IPS\GeoLocation\GeoCoder;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
@@ -38,7 +38,7 @@ class _Google extends \IPS\GeoLocation\GeoCoder
|
||||
$data = \IPS\Http\Url::external( "https://maps.googleapis.com/maps/api/geocode/json" )->setQueryString( array(
|
||||
'latlng' => "{$lat},{$long}",
|
||||
'sensor' => 'false',
|
||||
'key' => \IPS\Settings::i()->google_maps_api_key
|
||||
'key' => \IPS\Settings::i()->google_maps_api_key_secret ?: \IPS\Settings::i()->google_maps_api_key
|
||||
) )->request()->get()->decodeJson();
|
||||
|
||||
$obj = new \IPS\GeoLocation;
|
||||
@@ -48,7 +48,7 @@ class _Google extends \IPS\GeoLocation\GeoCoder
|
||||
$_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'] ) AND \is_array( $data['results'] ) AND \count( $data['results'] ) )
|
||||
{
|
||||
foreach( $data['results'][0]['address_components'] as $component )
|
||||
{
|
||||
@@ -113,7 +113,7 @@ class _Google extends \IPS\GeoLocation\GeoCoder
|
||||
$data = \IPS\Http\Url::external( "https://maps.googleapis.com/maps/api/geocode/json" )->setQueryString( array(
|
||||
'address' => $geoLocation->toString(),
|
||||
'sensor' => 'false',
|
||||
'key' => \IPS\Settings::i()->google_maps_api_key
|
||||
'key' => \IPS\Settings::i()->google_maps_api_key_secret ?: \IPS\Settings::i()->google_maps_api_key
|
||||
) )->request()->get()->decodeJson();
|
||||
}
|
||||
catch( \RuntimeException $e )
|
||||
@@ -121,7 +121,7 @@ class _Google extends \IPS\GeoLocation\GeoCoder
|
||||
return;
|
||||
}
|
||||
|
||||
if ( !count( $data['results'] ) )
|
||||
if ( !\count( $data['results'] ) )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
namespace IPS\GeoLocation\GeoCoder;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
@@ -47,7 +47,7 @@ class _Mapbox extends \IPS\GeoLocation\GeoCoder
|
||||
$_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'] ) AND \is_array( $data['results'] ) AND \count( $data['results'] ) )
|
||||
{
|
||||
foreach( $data['results'][0]['address_components'] as $component )
|
||||
{
|
||||
@@ -118,7 +118,7 @@ class _Mapbox extends \IPS\GeoLocation\GeoCoder
|
||||
return;
|
||||
}
|
||||
|
||||
if ( !isset( $data['features'] ) or !count( $data['features'] ) )
|
||||
if ( !isset( $data['features'] ) or !\count( $data['features'] ) )
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -130,7 +130,7 @@ class _Mapbox extends \IPS\GeoLocation\GeoCoder
|
||||
|
||||
if( $setAddress === TRUE )
|
||||
{
|
||||
if( isset( $data['results'] ) AND is_array( $data['results'] ) AND count( $data['results'] ) )
|
||||
if( isset( $data['results'] ) AND \is_array( $data['results'] ) AND \count( $data['results'] ) )
|
||||
{
|
||||
foreach( $data['results'][0]['address_components'] as $component )
|
||||
{
|
||||
|
||||
Whitespace-only changes.
@@ -11,7 +11,7 @@
|
||||
namespace IPS;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
@@ -467,8 +467,8 @@ class _GeoLocation
|
||||
/**
|
||||
* Get by IP address
|
||||
*
|
||||
* @param string $ip IP Address
|
||||
* @return \IPS\GeoLocation
|
||||
* @param string|array $ip IP Address or array of IP addresses
|
||||
* @return \IPS\GeoLocation|array
|
||||
* @throws \BadFunctionCallException Service is not available
|
||||
* @throws \IPS\Http\Request\Exception Error communicating with external service
|
||||
* @throws \RuntimeException Error within the external service
|
||||
@@ -488,24 +488,66 @@ class _GeoLocation
|
||||
{
|
||||
throw new \BadFunctionCallException;
|
||||
}
|
||||
|
||||
/* If the parameter is an array, the response will be an array */
|
||||
if( \is_array( $ip ) )
|
||||
{
|
||||
$result = array();
|
||||
$needToLookup = array();
|
||||
}
|
||||
|
||||
/* Check the cache */
|
||||
try
|
||||
{
|
||||
$data = \IPS\Db::i()->select( 'data', 'core_geoip_cache', array( 'ip_address=?', $ip ) )->first();
|
||||
if ( !$data )
|
||||
if( \is_array( $ip ) )
|
||||
{
|
||||
/* @note This was changed from an \UnderflowException to be consistent with the \OutOfRangeException thrown later on, otherwise the system will keep trying even when it should not. cleanup task will remove out of date entries and it can try again then. */
|
||||
throw new \OutOfRangeException;
|
||||
$atLeastOneFailed = FALSE;
|
||||
|
||||
foreach( $ip as $ipAddress )
|
||||
{
|
||||
try
|
||||
{
|
||||
$data = \IPS\Db::i()->select( 'data', 'core_geoip_cache', array( 'ip_address=?', $ipAddress ) )->first();
|
||||
|
||||
$result[ $ipAddress ] = $data;
|
||||
}
|
||||
catch( \UnderflowException $e )
|
||||
{
|
||||
$atLeastOneFailed = TRUE;
|
||||
$needToLookup[] = $ipAddress;
|
||||
}
|
||||
}
|
||||
|
||||
/* If any of the requested IP addresses failed, we need to look them up */
|
||||
if( $atLeastOneFailed )
|
||||
{
|
||||
throw new \UnderflowException;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
$data = \IPS\Db::i()->select( 'data', 'core_geoip_cache', array( 'ip_address=?', $ip ) )->first();
|
||||
if ( !$data )
|
||||
{
|
||||
/* @note This was changed from an \UnderflowException to be consistent with the \OutOfRangeException thrown later on, otherwise the system will keep trying even when it should not. cleanup task will remove out of date entries and it can try again then. */
|
||||
throw new \OutOfRangeException;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Not in the cache - get from tge external service */
|
||||
/* Not in the cache - get from the external service */
|
||||
catch ( \UnderflowException $e )
|
||||
{
|
||||
/* Fetch */
|
||||
$response = \IPS\Http\Url::ips( 'geoip/' . urlencode( $ip ) )->request()->login( \IPS\Settings::i()->ipb_reg_number, '' )->get();
|
||||
|
||||
/* Fetch the details */
|
||||
if( \is_array( $ip ) AND \count( $needToLookup ) )
|
||||
{
|
||||
$response = \IPS\Http\Url::ips( 'geoip/' . urlencode( json_encode( $needToLookup ) ) )->request()->login( \IPS\Settings::i()->ipb_reg_number, '' )->get();
|
||||
}
|
||||
else
|
||||
{
|
||||
$response = \IPS\Http\Url::ips( 'geoip/' . urlencode( $ip ) )->request()->login( \IPS\Settings::i()->ipb_reg_number, '' )->get();
|
||||
}
|
||||
|
||||
/* If it's a 404, the IP doesn't exist, we still store NULL to prevent multiple calls */
|
||||
if ( $response->httpResponseCode == 404 )
|
||||
{
|
||||
@@ -523,24 +565,62 @@ class _GeoLocation
|
||||
else
|
||||
{
|
||||
$data = (string) $response;
|
||||
|
||||
if( \is_array( $ip ) )
|
||||
{
|
||||
$data = json_decode( $data, true );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Cache */
|
||||
\IPS\Db::i()->replace( 'core_geoip_cache', array(
|
||||
'ip_address' => $ip,
|
||||
'data' => $data,
|
||||
'date' => time()
|
||||
) );
|
||||
}
|
||||
|
||||
/* If there's nothing, throw an exception */
|
||||
if ( !$data )
|
||||
{
|
||||
throw new \OutOfRangeException;
|
||||
if( \is_array( $ip ) )
|
||||
{
|
||||
if( \is_array( $data ) )
|
||||
{
|
||||
foreach( $data as $k => $v )
|
||||
{
|
||||
/* Database and buildFromJson need this as json */
|
||||
$v = $v ? json_encode( $v ) : NULL;
|
||||
|
||||
$result[ $k ] = $v;
|
||||
\IPS\Db::i()->replace( 'core_geoip_cache', array(
|
||||
'ip_address' => $k,
|
||||
'data' => $v,
|
||||
'date' => time()
|
||||
) );
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
\IPS\Db::i()->replace( 'core_geoip_cache', array(
|
||||
'ip_address' => $ip,
|
||||
'data' => $data,
|
||||
'date' => time()
|
||||
) );
|
||||
}
|
||||
}
|
||||
|
||||
/* Return */
|
||||
return static::buildFromJson( $data );
|
||||
if( \is_array( $ip ) )
|
||||
{
|
||||
foreach( $result as $ipAddress => $ipData )
|
||||
{
|
||||
$result[ $ipAddress ] = $ipData ? static::buildFromJson( $ipData ) : NULL;
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* If there's nothing, throw an exception */
|
||||
if ( !$data )
|
||||
{
|
||||
throw new \OutOfRangeException;
|
||||
}
|
||||
|
||||
return static::buildFromJson( $data );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -645,11 +725,11 @@ class _GeoLocation
|
||||
$output[] = $name;
|
||||
}
|
||||
|
||||
foreach ( array( 'addressLines', 'city', 'region', 'postalCode' ) as $k )
|
||||
foreach ( array( 'business', 'addressLines', 'city', 'region', 'postalCode' ) as $k )
|
||||
{
|
||||
if ( $this->$k )
|
||||
if ( isset( $this->$k ) and $this->$k )
|
||||
{
|
||||
if ( is_array( $this->$k ) )
|
||||
if ( \is_array( $this->$k ) )
|
||||
{
|
||||
foreach ( $this->$k as $v )
|
||||
{
|
||||
@@ -727,7 +807,7 @@ class _GeoLocation
|
||||
$address = json_decode( $data, TRUE );
|
||||
$mapper = new static;
|
||||
|
||||
if ( is_array( $address ) )
|
||||
if ( \is_array( $address ) )
|
||||
{
|
||||
foreach( $address as $k => $v )
|
||||
{
|
||||
@@ -753,7 +833,10 @@ class _GeoLocation
|
||||
*/
|
||||
public function apiOutput( \IPS\Member $authorizedMember = NULL )
|
||||
{
|
||||
return $this;
|
||||
$returnObject = clone $this;
|
||||
$returnObject->addressLines = array_values( $returnObject->addressLines );
|
||||
|
||||
return $returnObject;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
namespace IPS\GeoLocation\Maps;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
@@ -49,6 +49,41 @@ class _Google
|
||||
* @return string
|
||||
*/
|
||||
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 );
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the map image URL
|
||||
*
|
||||
* @param int $width Width
|
||||
* @param int $height Height
|
||||
* @param float|NULL $zoom The zoom amount (a value between 0 being totally zoomed out view of the world, and 1 being as fully zoomed in as possible) or NULL to zoom automatically based on how much data is available
|
||||
* @param int $scale Google maps scale to use (https://developers.google.com/maps/documentation/static-maps/intro#scale_values)
|
||||
* @param string $maptype Type of map to use. Valid values are roadmap (default), satellite, terrain, and hybrid (https://developers.google.com/maps/documentation/static-maps/intro#MapTypes)
|
||||
* @return \IPS\Http\Url|NULL
|
||||
*/
|
||||
public function mapUrl( $width, $height, $zoom=NULL, $scale=1, $maptype='roadmap' )
|
||||
{
|
||||
$location = $this->_getLocation();
|
||||
|
||||
return \IPS\Http\Url::external( 'https://maps.googleapis.com/maps/api/staticmap' )->setQueryString( array(
|
||||
'center' => $location,
|
||||
'zoom' => $zoom === NULL ? NULL : ceil( $zoom * 8 ),
|
||||
'size' => "{$width}x{$height}",
|
||||
'markers' => $location,
|
||||
'key' => \IPS\Settings::i()->google_maps_api_key,
|
||||
'scale' => $scale,
|
||||
'maptype' => $maptype
|
||||
) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch the location
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function _getLocation()
|
||||
{
|
||||
if ( $this->geolocation->lat and $this->geolocation->long )
|
||||
{
|
||||
@@ -61,7 +96,7 @@ class _Google
|
||||
{
|
||||
if ( $this->geolocation->$k )
|
||||
{
|
||||
if ( is_array( $this->geolocation->$k ) )
|
||||
if ( \is_array( $this->geolocation->$k ) )
|
||||
{
|
||||
foreach ( array_reverse( $this->geolocation->$k ) as $v )
|
||||
{
|
||||
@@ -80,18 +115,6 @@ class _Google
|
||||
$location = implode( ', ', array_reverse( $location ) );
|
||||
}
|
||||
|
||||
$linkUrl = \IPS\Http\Url::external( 'https://maps.google.com/' )->setQueryString( 'q', $location );
|
||||
|
||||
$imageUrl = \IPS\Http\Url::external( 'https://maps.googleapis.com/maps/api/staticmap' )->setQueryString( array(
|
||||
'center' => $location,
|
||||
'zoom' => $zoom === NULL ? NULL : ceil( $zoom * 8 ),
|
||||
'size' => "{$width}x{$height}",
|
||||
'markers' => $location,
|
||||
'key' => \IPS\Settings::i()->google_maps_api_key,
|
||||
'scale' => $scale,
|
||||
'maptype' => $maptype
|
||||
) );
|
||||
|
||||
return \IPS\Theme::i()->getTemplate( 'global', 'core', 'global' )->staticMap( $linkUrl, $imageUrl, $this->geolocation->lat, $this->geolocation->long );
|
||||
return $location;
|
||||
}
|
||||
}
|
||||
@@ -11,7 +11,7 @@
|
||||
namespace IPS\GeoLocation\Maps;
|
||||
|
||||
/* To prevent PHP errors (extending class does not exist) revealing path */
|
||||
if ( !defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
if ( !\defined( '\IPS\SUITE_UNIQUE_KEY' ) )
|
||||
{
|
||||
header( ( isset( $_SERVER['SERVER_PROTOCOL'] ) ? $_SERVER['SERVER_PROTOCOL'] : 'HTTP/1.0' ) . ' 403 Forbidden' );
|
||||
exit;
|
||||
@@ -53,12 +53,28 @@ class _Mapbox
|
||||
return "";
|
||||
}
|
||||
|
||||
return \IPS\Theme::i()->getTemplate( 'global', 'core', 'global' )->staticMap( NULL, $this->mapUrl( $width, $height, $zoom ), $this->geolocation->lat, $this->geolocation->long, $width, $height );
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the map image URL
|
||||
*
|
||||
* @param int $width Width
|
||||
* @param int $height Height
|
||||
* @param float|NULL $zoom The zoom amount (a value between 0 being totally zoomed out view of the world, and 1 being as fully zoomed in as possible) or NULL to zoom automatically based on how much data is available
|
||||
* @return \IPS\Http\Url|NULL
|
||||
*/
|
||||
public function mapUrl( $width, $height, $zoom=NULL )
|
||||
{
|
||||
if( !($this->geolocation->long and $this->geolocation->lat ) )
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
$location = str_replace( ',', '.', $this->geolocation->long ) . ',' . str_replace( ',', '.', $this->geolocation->lat );
|
||||
|
||||
$imageUrl = \IPS\Http\Url::external( "https://api.mapbox.com/styles/v1/mapbox/streets-v10/static/pin-l-marker+f00({$location})/{$location},14,0,60/{$width}x{$height}@2x" )->setQueryString( array(
|
||||
return \IPS\Http\Url::external( "https://api.mapbox.com/styles/v1/mapbox/streets-v10/static/pin-l-marker+f00({$location})/{$location},14,0,60/{$width}x{$height}@2x" )->setQueryString( array(
|
||||
'access_token' => \IPS\Settings::i()->mapbox_api_key,
|
||||
) );
|
||||
|
||||
return \IPS\Theme::i()->getTemplate( 'global', 'core', 'global' )->staticMap( NULL, $imageUrl, $this->geolocation->lat, $this->geolocation->long );
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user