PHP Class Piwik\Plugins\UserCountry\LocationProvider

LocationProviders attempt to determine a visitor's location using visit information. All LocationProviders require a visitor's IP address, some require more, such as the browser language.
Mostrar archivo Open project: piwik/piwik Class Usage Examples

Public Properties

Property Type Description
$providers array An array of all provider instances. Access it through static methods.

Public Methods

Method Description
completeLocationResult ( array &$location ) Tries to fill in any missing information in a location result.
getAllProviderInfo ( string $newline = " ", boolean $includeExtra = false ) : array Returns an array mapping provider IDs w/ information about the provider, for each location provider.
getAllProviders ( ) : LocationProvider[] Returns every available provider instance.
getAvailableProviders ( ) : array Returns all provider instances that are 'available'. An 'available' provider is one that is available for use. They may not necessarily be working.
getCurrentProvider ( ) : LocationProvider | null Returns the provider instance of the current location provider.
getCurrentProviderId ( ) : string Returns the ID of the currently used location provider.
getId ( )
getLocation ( array $info ) : array | false Returns location information based on visitor information.
getProviderById ( string $providerId ) : LocationProvider | null Returns a provider instance by ID or false if the ID is invalid or unavailable.
getSupportedLocationInfo ( ) : array Returns an array mapping location result keys w/ bool values indicating whether that information is supported by this provider. If it is not supported, that means this provider either cannot get this information, or is not configured to get it.
isAvailable ( ) : boolean Returns true if this provider is available for use, false if otherwise.
isWorking ( ) : boolean Returns true if this provider is working, false if otherwise.
prettyFormatLocation ( array | false $locationInfo, string $newline = " ", boolean $includeExtra = false ) : string Returns a prettified location result.
setCurrentProvider ( string $providerId ) : LocationProvider Sets the provider to use when tracking.

Protected Methods

Method Description
getIpFromInfo ( array $info ) : string | null Returns an IP address from an array that was passed into getLocation. This will return an IPv4 address or IPv6 address.
getLocationProviders ( Plugin $plugin ) : LocationProvider[] Get all lo that are defined by the given plugin.

Method Details

completeLocationResult() public method

This method will try to set the continent code, continent name and country code using other information. Note: This function must always be called by location providers in getLocation.
public completeLocationResult ( array &$location )
$location array The location information to modify.

getAllProviderInfo() public static method

The following information is provided for each provider: 'id' - The provider's unique string ID. 'title' - The provider's title. 'description' - A description of how the location provider works. 'status' - Either self::NOT_INSTALLED, self::INSTALLED or self::BROKEN. 'statusMessage' - If the status is self::BROKEN, then the message describes why. 'location' - A pretty formatted location of the current IP address (IP::getIpFromHeader()). An example result: array( 'geoip_php' => array('id' => 'geoip_php', 'title' => '...', 'desc' => '...', 'status' => GeoIp::BROKEN, 'statusMessage' => '...', 'location' => '...') 'geoip_serverbased' => array(...) )
public static getAllProviderInfo ( string $newline = " ", boolean $includeExtra = false ) : array
$newline string What to separate lines with in the pretty locations.
$includeExtra boolean Whether to include ISP/Org info in formatted location.
return array

getAllProviders() public static method

Returns every available provider instance.
public static getAllProviders ( ) : LocationProvider[]
return LocationProvider[]

getAvailableProviders() public static method

Returns all provider instances that are 'available'. An 'available' provider is one that is available for use. They may not necessarily be working.
public static getAvailableProviders ( ) : array
return array

getCurrentProvider() public static method

This function should not be called by the Tracker.
public static getCurrentProvider ( ) : LocationProvider | null
return LocationProvider | null

getCurrentProviderId() public static method

The used provider is stored in the 'usercountry.location_provider' option. This function should not be called by the Tracker.
public static getCurrentProviderId ( ) : string
return string

getId() public method

public getId ( )

getIpFromInfo() protected method

Returns an IP address from an array that was passed into getLocation. This will return an IPv4 address or IPv6 address.
protected getIpFromInfo ( array $info ) : string | null
$info array Must have 'ip' key.
return string | null

getLocation() abstract public method

The result of this function will be an array. The array can store some or all of the following information: - Continent Code: The code of the visitor's continent. (array key is self::CONTINENT_CODE_KEY) - Continent Name: The name of the visitor's continent. (array key is self::CONTINENT_NAME_KEY) - Country Code: The code of the visitor's country. (array key is self::COUNTRY_CODE_KEY) - Country Name: The name of the visitor's country. (array key is self::COUNTRY_NAME_KEY) - Region Code: The code of the visitor's region. (array key is self::REGION_CODE_KEY) - Region Name: The name of the visitor's region. (array key is self::REGION_NAME_KEY) - City Name: The name of the visitor's city. (array key is self::CITY_NAME_KEY) - Area Code: The visitor's area code. (array key is self::AREA_CODE_KEY) - Latitude: The visitor's latitude. (array key is self::LATITUDE_KEY) - Longitude: The visitor's longitude. (array key is self::LONGITUDE_KEY) - Postal Code: The visitor's postal code. (array key is self::POSTAL_CODE_KEY) - ISP: The visitor's ISP. (array key is self::ISP_KEY) - Org: The company/organization of the visitor's IP. (array key is self::ORG_KEY) All LocationProviders will attempt to return the country of the visitor.
abstract public getLocation ( array $info ) : array | false
$info array What this must contain depends on the specific provider implementation. All providers require an 'ip' key mapped to the visitor's IP address.
return array | false

getLocationProviders() protected static method

Get all lo that are defined by the given plugin.
protected static getLocationProviders ( Plugin $plugin ) : LocationProvider[]
$plugin Piwik\Plugin
return LocationProvider[]

getProviderById() public static method

Returns a provider instance by ID or false if the ID is invalid or unavailable.
public static getProviderById ( string $providerId ) : LocationProvider | null
$providerId string
return LocationProvider | null

getSupportedLocationInfo() abstract public method

Returns an array mapping location result keys w/ bool values indicating whether that information is supported by this provider. If it is not supported, that means this provider either cannot get this information, or is not configured to get it.
abstract public getSupportedLocationInfo ( ) : array
return array eg. array(self::CONTINENT_CODE_KEY => true, self::CONTINENT_NAME_KEY => true, self::ORG_KEY => false) The result is not guaranteed to have keys for every type of location info.

isAvailable() abstract public method

Returns true if this provider is available for use, false if otherwise.
abstract public isAvailable ( ) : boolean
return boolean

isWorking() abstract public method

Returns true if this provider is working, false if otherwise.
abstract public isWorking ( ) : boolean
return boolean

prettyFormatLocation() public static method

Returns a prettified location result.
public static prettyFormatLocation ( array | false $locationInfo, string $newline = " ", boolean $includeExtra = false ) : string
$locationInfo array | false
$newline string The line separator (ie, \n or
).
$includeExtra boolean Whether to include ISP/Organization info.
return string

setCurrentProvider() public static method

Sets the provider to use when tracking.
public static setCurrentProvider ( string $providerId ) : LocationProvider
$providerId string The ID of the provider to use.
return LocationProvider The new current provider.

Property Details

$providers public_oe static_oe property

An array of all provider instances. Access it through static methods.
public static array $providers
return array