Piwik\Plugins\UserCountry\LocationProvider::getAllProviderInfo PHP Метод

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

The following information is provided for each provider: 'id' - The provider's unique string ID. 'title' - The provider's title. 'description' - A description of how the location provider works. 'status' - Either self::NOT_INSTALLED, self::INSTALLED or self::BROKEN. 'statusMessage' - If the status is self::BROKEN, then the message describes why. 'location' - A pretty formatted location of the current IP address (IP::getIpFromHeader()). An example result: array( 'geoip_php' => array('id' => 'geoip_php', 'title' => '...', 'desc' => '...', 'status' => GeoIp::BROKEN, 'statusMessage' => '...', 'location' => '...') 'geoip_serverbased' => array(...) )
public static getAllProviderInfo ( string $newline = " ", boolean $includeExtra = false ) : array
$newline string What to separate lines with in the pretty locations.
$includeExtra boolean Whether to include ISP/Org info in formatted location.
Результат array
    public static function getAllProviderInfo($newline = "\n", $includeExtra = false)
    {
        $allInfo = array();
        foreach (self::getAllProviders() as $provider) {
            $info = $provider->getInfo();
            $status = self::INSTALLED;
            $location = false;
            $statusMessage = false;
            $availableOrMessage = $provider->isAvailable();
            if ($availableOrMessage !== true) {
                $status = self::NOT_INSTALLED;
                if (is_string($availableOrMessage)) {
                    $statusMessage = $availableOrMessage;
                }
            } else {
                $workingOrError = $provider->isWorking();
                if ($workingOrError === true) {
                    $locInfo = array('ip' => IP::getIpFromHeader(), 'lang' => Common::getBrowserLanguage(), 'disable_fallbacks' => true);
                    $location = $provider->getLocation($locInfo);
                    $location = self::prettyFormatLocation($location, $newline, $includeExtra);
                } else {
                    $status = self::BROKEN;
                    $statusMessage = $workingOrError;
                }
            }
            $info['status'] = $status;
            $info['statusMessage'] = $statusMessage;
            $info['location'] = $location;
            $allInfo[$info['order']] = $info;
        }
        ksort($allInfo);
        $result = array();
        foreach ($allInfo as $info) {
            $result[$info['id']] = $info;
        }
        return $result;
    }

Usage Example

Пример #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();
 }
All Usage Examples Of Piwik\Plugins\UserCountry\LocationProvider::getAllProviderInfo