diff options
Diffstat (limited to 'plugins/UserCountry/functions.php')
-rw-r--r-- | plugins/UserCountry/functions.php | 34 |
1 files changed, 31 insertions, 3 deletions
diff --git a/plugins/UserCountry/functions.php b/plugins/UserCountry/functions.php index afab257068..f02003776d 100644 --- a/plugins/UserCountry/functions.php +++ b/plugins/UserCountry/functions.php @@ -10,7 +10,10 @@ namespace Piwik\Plugins\UserCountry; use Piwik\DataTable; +use Piwik\Option; use Piwik\Piwik; +use Piwik\Plugin\Manager; +use Piwik\Plugins\GeoIp2\LocationProvider\GeoIp2; use Piwik\Plugins\UserCountry\LocationProvider\GeoIp; use Piwik\Tracker\Visit; @@ -106,6 +109,31 @@ function getElementFromStringArray($label, $separator, $index, $emptyValue = fal } /** + * Returns region name for the given regionCode / countryCode combination + * using the currently set location provider + * + * @param string $countryCode + * @param string $regionCode + * @return string + */ +function getRegionNameFromCodes($countryCode, $regionCode) +{ + if (!Manager::getInstance()->isPluginActivated('GeoIp2') || + LocationProvider::getCurrentProvider() instanceof GeoIp) { + return GeoIp::getRegionNameFromCodes($countryCode, $regionCode); + } + + $name = GeoIp2::getRegionNameFromCodes($countryCode, $regionCode); + + // fallback if no translation for with GeoIP2 + if ($name == Piwik::translate('General_Unknown')) { + $name = GeoIp::getRegionNameFromCodes($countryCode, $regionCode); + } + + return $name; +} + +/** * Returns the region name using the label of a Visits by Region report. * * @param string $label A label containing a region code followed by '|' and a country code, eg, @@ -123,7 +151,7 @@ function getRegionName($label) } list($regionCode, $countryCode) = explode(Archiver::LOCATION_SEPARATOR, $label); - return GeoIp::getRegionNameFromCodes($countryCode, $regionCode); + return getRegionNameFromCodes($countryCode, $regionCode); } /** @@ -146,7 +174,7 @@ function getPrettyRegionName($label) list($regionCode, $countryCode) = explode(Archiver::LOCATION_SEPARATOR, $label); - $result = GeoIp::getRegionNameFromCodes($countryCode, $regionCode); + $result = getRegionNameFromCodes($countryCode, $regionCode); if ($countryCode != Visit::UNKNOWN_CODE && $countryCode != '') { $result .= ', ' . countryTranslate($countryCode); } @@ -185,7 +213,7 @@ function getPrettyCityName($label) $result = $cityName; if ($countryCode != Visit::UNKNOWN_CODE && $countryCode != '') { if ($regionCode != '' && $regionCode != Visit::UNKNOWN_CODE) { - $regionName = GeoIp::getRegionNameFromCodes($countryCode, $regionCode); + $regionName = getRegionNameFromCodes($countryCode, $regionCode); $result .= ', ' . $regionName; } $result .= ', ' . countryTranslate($countryCode); |