Version 4.1.19

This commit is contained in:
Neo committed 2025-12-19 05:38:56 -08:00
1 parent 28bd025b35
commit 2bd5025018
2674 files changed
+233518 -77766

No files matched your search

+169 -49
View File
@@ -2,9 +2,9 @@
/**
* @brief GeoLocation
* @author <a href='http://www.invisionpower.com'>Invision Power Services, Inc.</a>
* @copyright (c) 2001 - SVN_YYYY Invision Power Services, Inc.
* @copyright (c) 2001 - 2016 Invision Power Services, Inc.
* @license http://www.invisionpower.com/legal/standards/
* @package IPS Social Suite
* @package IPS Community Suite
* @since 19 Apr 2013
* @version SVN_VERSION_NUMBER
*/
@@ -103,6 +103,7 @@ class _GeoLocation
'FJ', // Fiji
'FI', // Finland
'FR', // France
'FX', // France, Metropolitan
'GF', // French Guiana
'PF', // French Polynesia
'TF', // French Southern Territories
@@ -282,6 +283,45 @@ class _GeoLocation
* @brief State List
*/
public static $states = array(
'AU' => array(
'Australian Capital Territory',
'New South Wales',
'Northern Territory',
'Queensland',
'South Australia',
'Tasmania',
'Victoria',
'Western Australia',
),
'BR' => array(
'Acre',
'Alagoas',
'Amapá',
'Amazonas',
'Bahia',
'Ceará',
'Distrito Federal',
'Espírito Santo',
'Goiás',
'Maranhão',
'Mato Grosso',
'Mato Grosso do Sul',
'Minas Gerais',
'Paraná',
'Paraíba',
'Pará',
'Pernambuco',
'Piauí',
'Rio de Janeiro',
'Rio Grande do Norte',
'Rio Grande do Sul',
'Rondônia',
'Roraima',
'Santa Catarina',
'Sergipe',
'São Paulo',
'Tocantins'
),
'CA' => array(
"Alberta",
"British Columbia",
@@ -297,6 +337,28 @@ class _GeoLocation
"Saskatchewan",
"Yukon",
),
'PT' => array(
"Aveiro",
"Azores",
"Beja",
"Braga",
"Braganca",
"Castelo Branco",
"Coimbra",
"Evora",
"Faro",
"Guarda",
"Leiria",
"Lisboa",
"Madeira Islands",
"Portalegre",
"Porto",
"Santarem",
"Setubal",
"Viana do Castelo",
"Vila Real",
"Viseu",
),
'US' => array(
"Alabama",
"Alaska",
@@ -361,38 +423,6 @@ class _GeoLocation
"Armed Forces - Europe",
"Armed Forces - Pacific",
),
'PT' => array(
"Aveiro",
"Azores",
"Beja",
"Braga",
"Braganca",
"Castelo Branco",
"Coimbra",
"Evora",
"Faro",
"Guarda",
"Leiria",
"Lisboa",
"Madeira Islands",
"Portalegre",
"Porto",
"Santarem",
"Setubal",
"Viana do Castelo",
"Vila Real",
"Viseu",
),
'AU' => array(
'Australian Capital Territory',
'New South Wales',
'Northern Territory',
'Queensland',
'South Australia',
'Tasmania',
'Victoria',
'Western Australia',
),
);
/**
@@ -440,19 +470,77 @@ class _GeoLocation
*
* @param string $ip IP Address
* @return \IPS\GeoLocation
* @throws \BadFunctionCallException
* @throws \IPS\Http\Request\Exception
* @throws \BadFunctionCallException Service is not available
* @throws \IPS\Http\Request\Exception Error communicating with external service
* @throws \RuntimeException Error within the external service
* @throws \OutOfRangeException IP address is not in database
*/
public static function getByIp( $ip )
{
if ( \IPS\Settings::i()->ipsgeoip )
{
return static::buildFromJson( \IPS\Http\Url::ips( 'geoip/' . urlencode( $ip ) )->request()->login( \IPS\Settings::i()->ipb_reg_number, '' )->get() );
}
else
{
/* If the service is not turned on - throw an exception */
if ( !\IPS\Settings::i()->ipsgeoip )
{
throw new \BadFunctionCallException;
}
/* If the license key is invalid or expired the service won't work, so throw an exception */
$licenseData = \IPS\IPS::licenseKey();
if( !$licenseData or !$licenseData['active'] )
{
throw new \BadFunctionCallException;
}
/* Check the cache */
try
{
$data = \IPS\Db::i()->select( 'data', 'core_geoip_cache', array( 'ip_address=?', $ip ) )->first();
if ( !$data )
{
throw new \UnderflowException;
}
}
/* Not in the cache - get from tge external service */
catch ( \UnderflowException $e )
{
/* Fetch */
$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 )
{
$data = NULL;
}
/* If it's anything other than a 200, log it and throw exception */
elseif ( $response->httpResponseCode != 200 )
{
\IPS\Log::log( "GeoIP Error\n\nRequested IP: {$ip}\n\nResponse:\n" . print_r( $response, TRUE ), 'geoip' );
throw new \RuntimeException;
}
/* Otherwise it's fine */
else
{
$data = (string) $response;
}
/* 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;
}
/* Return */
return static::buildFromJson( $data );
}
/**
@@ -466,10 +554,14 @@ class _GeoLocation
*/
public static function getByLatLong( $lat, $long )
{
if ( \IPS\Settings::i()->googlemaps )
if ( \IPS\Settings::i()->google_maps_api_key )
{
$data = \IPS\Http\Url::external( ( \IPS\Request::i()->isSecure() ? 'https://' : 'http://' ) . "maps.googleapis.com/maps/api/geocode/json?latlng=" . urlencode( $lat ) . "," . urlencode( $long ) . "&sensor=false" )->request()->get()->decodeJson();
$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
) )->request()->get()->decodeJson();
$obj = new static;
$obj->lat = $lat;
$obj->long = $long;
@@ -533,11 +625,15 @@ class _GeoLocation
*/
public function getLatLong()
{
if ( \IPS\Settings::i()->googlemaps AND $this->toString() )
if ( \IPS\Settings::i()->google_maps_api_key AND $this->toString() )
{
try
{
$data = \IPS\Http\Url::external( ( \IPS\Request::i()->isSecure() ? 'https://' : 'http://' ) . "maps.googleapis.com/maps/api/geocode/json?address=" . urlencode( $this->toString() ) . "&sensor=false" )->request()->get()->decodeJson();
$data = \IPS\Http\Url::external( "https://maps.googleapis.com/maps/api/geocode/json" )->setQueryString( array(
'address' => $this->toString(),
'sensor' => 'false',
'key' => \IPS\Settings::i()->google_maps_api_key
) )->request()->get()->decodeJson();
}
catch( \RuntimeException $e )
{
@@ -628,7 +724,14 @@ class _GeoLocation
}
if ( $this->country and $this->country !== static::buildFromJson( \IPS\Settings::i()->site_address )->country )
{
$output[] = \IPS\Member::loggedIn()->language()->get( htmlspecialchars( 'country-' . $this->country, \IPS\HTMLENTITIES, 'UTF-8', FALSE ), FALSE, array( 'strtoupper' => TRUE ) );
try
{
$output[] = \IPS\Member::loggedIn()->language()->get( htmlspecialchars( 'country-' . $this->country, \IPS\HTMLENTITIES, 'UTF-8', FALSE ), FALSE, array( 'strtoupper' => TRUE ) );
}
catch ( \UnderflowException $e )
{
$output[] = htmlspecialchars( $this->country, \IPS\HTMLENTITIES, 'UTF-8', FALSE );
}
}
if ( !empty( $output ) )
@@ -653,7 +756,7 @@ class _GeoLocation
{
if ( $this->map === NULL )
{
if ( \IPS\Settings::i()->googlemaps )
if ( \IPS\Settings::i()->googlemaps and \IPS\Settings::i()->google_maps_api_key )
{
$this->map = new \IPS\GeoLocation\Maps\Google( $this );
}
@@ -687,4 +790,21 @@ class _GeoLocation
return (string) $mapper;
}
/**
* Get output for API
*
* @return array
* @apiresponse float lat Latitude
* @apiresponse float long Longitude
* @apiresponse [string] addressLines Lines of the street address
* @apiresponse string city City
* @apiresponse string region State/Region
* @apiresponse string country 2-letter country code
* @apiresponse string postalCode ZIP/Postal Code
*/
public function apiOutput()
{
return $this;
}
}