Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbenakamoorthi <benaka.moorthi@gmail.com>2012-11-20 11:56:56 +0400
committerbenakamoorthi <benaka.moorthi@gmail.com>2012-11-20 11:56:56 +0400
commitde85e310edad4172fee20dd5cc20dc680258bbbc (patch)
tree0e3f16e27c65997b0d2e985575803c4c38d0dbf2 /plugins/UserCountry
parente7eacc2e7ff3221cada1f99ce3f15ef2f348e59a (diff)
Fixes #3534, add UserCountry.getLocationFromIP method as proxy for GeoIP functionality.
git-svn-id: http://dev.piwik.org/svn/trunk@7494 59fd770c-687e-43c8-a1e3-f5a4ff64c105
Diffstat (limited to 'plugins/UserCountry')
-rw-r--r--plugins/UserCountry/API.php34
1 files changed, 34 insertions, 0 deletions
diff --git a/plugins/UserCountry/API.php b/plugins/UserCountry/API.php
index b684ebdb41..ab7016eee6 100644
--- a/plugins/UserCountry/API.php
+++ b/plugins/UserCountry/API.php
@@ -156,6 +156,40 @@ class Piwik_UserCountry_API
return $dataTable;
}
+ /**
+ * Uses a location provider to find/guess the location of an IP address.
+ *
+ * See Piwik_UserCountry_LocationProvider::getLocation to see the details
+ * of the result of this function.
+ *
+ * @param string $ip The IP address.
+ * @param string|false $provider The ID of the provider to use or false to use the
+ * currently configured one.
+ */
+ public function getLocationFromIP( $ip, $provider = false )
+ {
+ Piwik::checkUserHasSomeViewAccess();
+
+ if ($provider === false)
+ {
+ $provider = Piwik_UserCountry_LocationProvider::getCurrentProviderId();
+ }
+
+ $oProvider = Piwik_UserCountry_LocationProvider::getProviderById($provider);
+ if ($oProvider === false)
+ {
+ throw new Exception("Cannot find the '$provider' provider. It is either an invalid provider "
+ . "ID or the ID of a provider that is not working.");
+ }
+
+ $location = $oProvider->getLocation(array('ip' => $ip));
+ if (empty($location))
+ {
+ throw new Exception("Could not geolocate '$ip'!");
+ }
+ return $location;
+ }
+
protected function getDataTable($name, $idSite, $period, $date, $segment)
{
Piwik::checkUserHasViewAccess( $idSite );