Ejemplo n.º 1
0
/**
 * Returns the name of a city + the name of its region + the name of its country using
 * the label of a Visits by City report.
 * 
 * @param string $label A label containing a city name, region code + country code,
 *                      separated by two '|' chars: 'Paris|A8|FR'
 * @return string|false eg. 'Paris, Ile de France, France' or false if $label ==
 *                      Piwik_DataTable::LABEL_SUMMARY_ROW.
 */
function Piwik_UserCountry_getPrettyCityName($label)
{
    if ($label == Piwik_DataTable::LABEL_SUMMARY_ROW) {
        return $label;
    }
    if ($label == '') {
        return Piwik_Translate('General_Unknown');
    }
    // get city name, region code & country code
    $parts = explode(Piwik_UserCountry::LOCATION_SEPARATOR, $label);
    $cityName = $parts[0];
    $regionCode = $parts[1];
    $countryCode = $parts[2];
    if ($cityName == Piwik_Tracker_Visit::UNKNOWN_CODE || $cityName == '') {
        $cityName = Piwik_Translate('General_Unknown');
    }
    $result = $cityName;
    if ($countryCode != Piwik_Tracker_Visit::UNKNOWN_CODE && $countryCode != '') {
        if ($regionCode != '' && $regionCode != Piwik_Tracker_Visit::UNKNOWN_CODE) {
            $regionName = Piwik_UserCountry_LocationProvider_GeoIp::getRegionNameFromCodes($countryCode, $regionCode);
            $result .= ', ' . $regionName;
        }
        $result .= ', ' . Piwik_CountryTranslate($countryCode);
    }
    return $result;
}
Ejemplo n.º 2
0
 function getPrettyLocation()
 {
     $parts = array();
     // add city if it's known
     if ($this->details['location_city'] != '') {
         $parts[] = $this->details['location_city'];
     }
     // add region if it's known
     $region = $this->details['location_region'];
     if ($region != '' && $region != Piwik_Tracker_Visit::UNKNOWN_CODE) {
         $parts[] = Piwik_UserCountry_LocationProvider_GeoIp::getRegionNameFromCodes($this->details['location_country'], $region);
     }
     // add country & return concatenated result
     $parts[] = $this->getCountryName();
     return implode(', ', $parts);
 }