getCurrentProviderId() публичный статический Метод

The used provider is stored in the 'usercountry.location_provider' option. This function should not be called by the Tracker.
public static getCurrentProviderId ( ) : string
Результат string
Пример #1
0
 public function adminIndex()
 {
     $this->dieIfGeolocationAdminIsDisabled();
     Piwik::checkUserHasSuperUserAccess();
     $view = new View('@UserCountry/adminIndex');
     $allProviderInfo = LocationProvider::getAllProviderInfo($newline = '<br/>', $includeExtra = true);
     $view->locationProviders = $allProviderInfo;
     $view->currentProviderId = LocationProvider::getCurrentProviderId();
     $view->thisIP = IP::getIpFromHeader();
     $geoIPDatabasesInstalled = GeoIp::isDatabaseInstalled();
     $view->geoIPDatabasesInstalled = $geoIPDatabasesInstalled;
     $view->updatePeriodOptions = $this->getPeriodUpdateOptions();
     // check if there is a working provider (that isn't the default one)
     $isThereWorkingProvider = false;
     foreach ($allProviderInfo as $id => $provider) {
         if ($id != DefaultProvider::ID && $provider['status'] == LocationProvider::INSTALLED) {
             $isThereWorkingProvider = true;
             break;
         }
     }
     $view->isThereWorkingProvider = $isThereWorkingProvider;
     // if using either the Apache or PECL module, they are working and there are no databases
     // in misc, then the databases are located outside of Piwik, so we cannot update them
     $view->showGeoIPUpdateSection = true;
     $currentProviderId = LocationProvider::getCurrentProviderId();
     if (!$geoIPDatabasesInstalled && ($currentProviderId == ServerBased::ID || $currentProviderId == Pecl::ID) && $allProviderInfo[$currentProviderId]['status'] == LocationProvider::INSTALLED) {
         $view->showGeoIPUpdateSection = false;
     }
     $this->setUpdaterManageVars($view);
     $this->setBasicVariablesView($view);
     $this->setBasicVariablesAdminView($view);
     return $view->render();
 }
Пример #2
0
 public function configureView(ViewDataTable $view)
 {
     $view->config->show_exclude_low_population = false;
     $view->config->addTranslation('label', $this->dimension->getName());
     $view->config->documentation = $this->documentation;
     $view->requestConfig->filter_limit = 5;
     if (LocationProvider::getCurrentProviderId() == LocationProvider\DefaultProvider::ID) {
         // if we're using the default location provider, add a note explaining how it works
         $footerMessage = Piwik::translate("General_Note") . ': ' . Piwik::translate('UserCountry_DefaultLocationProviderExplanation', array('<a rel="noreferrer"  target="_blank" href="http://piwik.org/docs/geo-locate/">', '</a>'));
         $view->config->show_footer_message = $footerMessage;
     }
 }
Пример #3
0
 public function execute()
 {
     $isPiwikInstalling = !Config::getInstance()->existsLocalConfig();
     if ($isPiwikInstalling) {
         // Skip the diagnostic if Piwik is being installed
         return array();
     }
     $label = $this->translator->translate('UserCountry_Geolocation');
     $currentProviderId = LocationProvider::getCurrentProviderId();
     $allProviders = LocationProvider::getAllProviderInfo();
     $isRecommendedProvider = in_array($currentProviderId, array(LocationProvider\GeoIp\Php::ID, $currentProviderId == LocationProvider\GeoIp\Pecl::ID));
     $isProviderInstalled = $allProviders[$currentProviderId]['status'] == LocationProvider::INSTALLED;
     if ($isRecommendedProvider && $isProviderInstalled) {
         return array(DiagnosticResult::singleResult($label, DiagnosticResult::STATUS_OK));
     }
     if ($isProviderInstalled) {
         $comment = $this->translator->translate('UserCountry_GeoIpLocationProviderNotRecomnended') . ' ';
         $comment .= $this->translator->translate('UserCountry_GeoIpLocationProviderDesc_ServerBased2', array('<a href="http://piwik.org/docs/geo-locate/" rel="noreferrer" target="_blank">', '', '', '</a>'));
     } else {
         $comment = $this->translator->translate('UserCountry_DefaultLocationProviderDesc1') . ' ';
         $comment .= $this->translator->translate('UserCountry_DefaultLocationProviderDesc2', array('<a href="http://piwik.org/docs/geo-locate/" rel="noreferrer" target="_blank">', '', '', '</a>'));
     }
     return array(DiagnosticResult::singleResult($label, DiagnosticResult::STATUS_WARNING, $comment));
 }
Пример #4
0
 private function setLocationProvider($file)
 {
     GeoIp::$dbNames['loc'] = array($file);
     GeoIp::$geoIPDatabaseDir = 'tests/lib/geoip-files';
     LocationProvider::$providers = null;
     LocationProvider::setCurrentProvider(self::GEOIP_IMPL_TO_TEST);
     if (LocationProvider::getCurrentProviderId() !== self::GEOIP_IMPL_TO_TEST) {
         throw new Exception("Failed to set the current location provider to '" . self::GEOIP_IMPL_TO_TEST . "'.");
     }
     $possibleFiles = GeoIp::$dbNames['loc'];
     if (GeoIp::getPathToGeoIpDatabase($possibleFiles) === false) {
         throw new Exception("The GeoIP location provider cannot find the '{$file}' file! Tests will fail.");
     }
 }
Пример #5
0
 /**
  * Uses a location provider to find/guess the location of an IP address.
  *
  * See LocationProvider::getLocation to see the details
  * of the result of this function.
  *
  * @param string $ip The IP address.
  * @param bool|string $provider The ID of the provider to use or false to use the
  *                               currently configured one.
  * @throws Exception
  * @return array|false
  */
 public function getLocationFromIP($ip, $provider = false)
 {
     Piwik::checkUserHasSomeViewAccess();
     if (empty($provider)) {
         $provider = LocationProvider::getCurrentProviderId();
     }
     $oProvider = LocationProvider::getProviderById($provider);
     if (empty($oProvider)) {
         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}'!");
     }
     $location['ip'] = $ip;
     return $location;
 }
Пример #6
0
 private function configureViewForGetCountry(ViewDataTable $view)
 {
     $view->config->show_goals = true;
     $view->config->show_exclude_low_population = false;
     $view->config->addTranslation('label', Piwik::translate('UserCountry_Country'));
     $view->config->documentation = Piwik::translate('UserCountry_getCountryDocumentation');
     $view->requestConfig->filter_limit = 5;
     if (LocationProvider::getCurrentProviderId() == DefaultProvider::ID) {
         // if we're using the default location provider, add a note explaining how it works
         $footerMessage = Piwik::translate("General_Note") . ': ' . Piwik::translate('UserCountry_DefaultLocationProviderExplanation', array('<a target="_blank" href="http://piwik.org/docs/geo-locate/">', '</a>'));
         $view->config->show_footer_message = $footerMessage;
     }
 }
Пример #7
0
 private static function checkGeolocation(&$result)
 {
     $currentProviderId = LocationProvider::getCurrentProviderId();
     $allProviders = LocationProvider::getAllProviderInfo();
     $isRecommendedProvider = in_array($currentProviderId, array(LocationProvider\GeoIp\Php::ID, $currentProviderId == LocationProvider\GeoIp\Pecl::ID));
     $isProviderInstalled = $allProviders[$currentProviderId]['status'] == LocationProvider::INSTALLED;
     $result['geolocation_using_non_recommended'] = $result['geolocation_ok'] = false;
     if ($isRecommendedProvider && $isProviderInstalled) {
         $result['geolocation_ok'] = true;
     } elseif ($isProviderInstalled) {
         $result['geolocation_using_non_recommended'] = true;
     }
 }
Пример #8
0
 public function setTrackerCacheGeneral(&$cache)
 {
     $cache['currentLocationProviderId'] = LocationProvider::getCurrentProviderId();
 }