getCurrentLocationProviderId() public static method

Returns the ID of the current LocationProvider (see UserCountry plugin code) from the Tracker cache.
public static getCurrentLocationProviderId ( )
Exemplo n.º 1
0
 public function enrichVisitWithLocation(&$visitorInfo, \Piwik\Tracker\Request $request)
 {
     require_once PIWIK_INCLUDE_PATH . "/plugins/UserCountry/LocationProvider.php";
     $ipAddress = IP::N2P(Config::getInstance()->Tracker['use_anonymized_ip_for_visit_enrichment'] == 1 ? $visitorInfo['location_ip'] : $request->getIp());
     $userInfo = array('lang' => $visitorInfo['location_browser_lang'], 'ip' => $ipAddress);
     $id = Common::getCurrentLocationProviderId();
     $provider = LocationProvider::getProviderById($id);
     if ($provider === false) {
         $id = DefaultProvider::ID;
         $provider = LocationProvider::getProviderById($id);
         Common::printDebug("GEO: no current location provider sent, falling back to default '{$id}' one.");
     }
     $location = $provider->getLocation($userInfo);
     // if we can't find a location, use default provider
     if ($location === false) {
         $defaultId = DefaultProvider::ID;
         $provider = LocationProvider::getProviderById($defaultId);
         $location = $provider->getLocation($userInfo);
         Common::printDebug("GEO: couldn't find a location with Geo Module '{$id}', using Default '{$defaultId}' provider as fallback...");
         $id = $defaultId;
     }
     Common::printDebug("GEO: Found IP {$ipAddress} location (provider '" . $id . "'): " . var_export($location, true));
     if (empty($location['country_code'])) {
         // sanity check
         $location['country_code'] = \Piwik\Tracker\Visit::UNKNOWN_CODE;
     }
     // add optional location components
     $this->updateVisitInfoWithLocation($visitorInfo, $location);
 }
Exemplo n.º 2
0
 public function __construct(LocationProvider $provider = null, LocationProvider $backupProvider = null, Cache $locationCache = null, RawLogDao $dao = null, LoggerInterface $logger = null)
 {
     if ($provider === null) {
         // note: Common::getCurrentLocationProviderId() uses the tracker cache, which is why it's used here instead
         // of accessing the option table
         $provider = LocationProvider::getProviderById(Common::getCurrentLocationProviderId());
         if (empty($provider)) {
             Common::printDebug("GEO: no current location provider sent, falling back to default '" . DefaultProvider::ID . "' one.");
             $provider = $this->getDefaultProvider();
         }
     }
     $this->provider = $provider;
     $this->backupProvider = $backupProvider ?: $this->getDefaultProvider();
     $this->locationCache = $locationCache ?: self::getDefaultLocationCache();
     $this->dao = $dao ?: new RawLogDao();
     $this->logger = $logger ?: StaticContainer::get('Psr\\Log\\LoggerInterface');
 }
Exemplo n.º 3
0
 private function getProvider()
 {
     $id = Common::getCurrentLocationProviderId();
     $provider = LocationProvider::getProviderById($id);
     if ($provider === false) {
         $provider = $this->getDefaultProvider();
         Common::printDebug("GEO: no current location provider sent, falling back to default '{$id}' one.");
     }
     return $provider;
 }