getCountryList(); array_walk($countryList, function (&$item, $key) { $item = Piwik::translate('Intl_Country_' . strtoupper($key)); }); asort($countryList); //order by localized name return $countryList; } public function registerEvents() { return [ "Tracker.isExcludedVisit" => "checkExcludedCountry", ]; } public function checkExcludedCountry(&$excluded, Request $request) { $logger = StaticContainer::getContainer()->get("Psr\Log\LoggerInterface"); $provider = LocationProvider::getProviderById(Common::getCurrentLocationProviderId()); $settings = new SystemSettings(); $location = $provider->getLocation(["ip" => $request->getIpString()]); $countryCode = strtolower($location[LocationProvider::COUNTRY_CODE_KEY]); if (!$location || empty($countryCode)) { $logger->debug("ExcludeCountries could not detect a location"); return; } $excludeBool = $settings->excludeBool->getValue(); if ($excludeBool) { $countries = $this->settingToCountryCodes($settings->excludedCountries); if (in_array($countryCode, $countries)) { $logger->debug("request excluded by ExcludeCountries plugin (" . $countryCode . ")"); $excluded = true; } } else { $countries = $this->settingToCountryCodes($settings->includedCountries); if (!in_array($countryCode, $countries)) { $logger->debug("request excluded by ExcludeCountries plugin (" . $countryCode . ")"); $excluded = true; } } } private function settingToCountryCodes(Setting $setting) { $codes = []; foreach ($setting->getValue() as $value) { if (!empty($value["country"])) { $codes[] = $value["country"]; } } return $codes; } }