getCountryISO() public static method

Returns either a specific or all ISO-3166 country names.
public static getCountryISO ( string $code = null ) : mixed
$code string The ISO 3166 country code.
return mixed If a country code has been requested will return the corresponding country name. If empty will return an array of all the country codes and their names.
Exemplo n.º 1
0
 /**
  * Returns avaiable countries
  */
 static function getCountries()
 {
     try {
         return Horde::loadConfiguration('countries.php', 'countries', 'folks');
     } catch (Horde_Exception $e) {
         return Horde_Nls::getCountryISO();
     }
 }
Exemplo n.º 2
0
 /**
  */
 protected function _params()
 {
     // @todo Find a way to allow not loading the entire metar location
     // database in memory. I.e., allow entering free-form text like
     // the other weather block.
     try {
         $rows = $this->_weather->getLocations();
     } catch (Horde_Exception $e) {
         // No data available.
         return;
     }
     $locations = array();
     foreach ($rows as $row) {
         $locations[Horde_Nls_Translation::t(Horde_Nls::getCountryISO($row['country']))][$row['icao']] = sprintf('%s (%s, %s, %s)', $row['name'], !empty($row['municipality']) ? $row['municipality'] : '', $row['state'], $row['country']);
     }
     uksort($locations, 'strcoll');
     return array('location' => array('type' => 'mlenum', 'name' => _("Location"), 'default' => 'KSFB', 'values' => $locations), 'units' => array('type' => 'enum', 'name' => _("Units"), 'default' => Horde_Service_Weather::UNITS_STANDARD, 'values' => array(Horde_Service_Weather::UNITS_STANDARD => _("Standard"), Horde_Service_Weather::UNITS_METRIC => _("Metric"))), 'knots' => array('type' => 'checkbox', 'name' => _("Wind speed in knots"), 'default' => 0), 'taf' => array('type' => 'checkbox', 'name' => _("Display forecast (TAF)"), 'default' => 0));
 }
Exemplo n.º 3
0
 function init($prompt = null)
 {
     parent::init(Horde_Nls::getCountryISO(), $prompt);
 }
Exemplo n.º 4
0
 /**
  * Given a 2-letter country code, returns a country string.
  *
  * @param string $code  The country code.
  *
  * @return string  The country string.
  */
 protected function _getName($code)
 {
     $code = Horde_String::upper($code);
     $geoip_codes = array('AP' => Horde_Nls_Translation::t("Asia/Pacific Region"), 'EU' => Horde_Nls_Translation::t("Europe"), 'A1' => Horde_Nls_Translation::t("Anonymous Proxy"), 'A2' => Horde_Nls_Translation::t("Satellite Provider"), 'O1' => Horde_Nls_Translation::t("Other"));
     return isset($geoip_codes[$code]) ? $geoip_codes[$code] : strval(Horde_Nls::getCountryISO($code));
 }
Exemplo n.º 5
0
 /**
  * Convert the contact to an ActiveSync contact message
  *
  * @param Turba_Object $object  The turba object to convert
  * @param array $options        Options:
  *   - protocolversion: (float)  The EAS version to support
  *                      DEFAULT: 2.5
  *   - bodyprefs: (array)  A BODYPREFERENCE array.
  *                DEFAULT: none (No body prefs enforced).
  *   - truncation: (integer)  Truncate event body to this length
  *                 DEFAULT: none (No truncation).
  *   - device: (Horde_ActiveSync_Device) The device object.
  *
  * @return Horde_ActiveSync_Message_Contact
  */
 public function toASContact(Turba_Object $object, array $options = array())
 {
     global $injector;
     $message = new Horde_ActiveSync_Message_Contact(array('logger' => $injector->getInstance('Horde_Log_Logger'), 'protocolversion' => $options['protocolversion'], 'device' => !empty($options['device']) ? $options['device'] : null));
     $hash = $object->getAttributes();
     if (!isset($hash['lastname']) && isset($hash['name'])) {
         $this->_guessName($hash);
     }
     // Ensure we have at least a good guess as to separate address fields.
     // Not ideal, but EAS does not have a single "address" field so we must
     // map "common" to either home or work. I choose home since
     // work/non-personal installs will be more likely to have separated
     // address fields.
     if (!empty($hash['commonAddress'])) {
         if (!isset($hash['commonStreet'])) {
             $hash['commonStreet'] = $hash['commonHome'];
         }
         foreach (array('Address', 'Street', 'POBox', 'Extended', 'City', 'Province', 'PostalCode', 'Country') as $field) {
             $hash['home' . $field] = $hash['common' . $field];
         }
     } else {
         if (isset($hash['homeAddress']) && !isset($hash['homeStreet'])) {
             $hash['homeStreet'] = $hash['homeAddress'];
         }
         if (isset($hash['workAddress']) && !isset($hash['workStreet'])) {
             $hash['workStreet'] = $hash['workAddress'];
         }
     }
     $hooks = $injector->getInstance('Horde_Core_Hooks');
     $decode_hook = $hooks->hookExists('decode_attribute', 'turba');
     foreach ($hash as $field => $value) {
         if ($decode_hook) {
             try {
                 $value = $hooks->callHook('decode_attribute', 'turba', array($field, $value, $object));
             } catch (Turba_Exception $e) {
                 Horde::log($e);
             }
         }
         if (isset(self::$_asMap[$field])) {
             try {
                 $message->{self::$_asMap[$field]} = $value;
             } catch (InvalidArgumentException $e) {
             }
             continue;
         }
         switch ($field) {
             case 'photo':
                 $message->picture = base64_encode($value);
                 break;
             case 'homeCountry':
                 $message->homecountry = !empty($hash['homeCountryFree']) ? $hash['homeCountryFree'] : !empty($hash['homeCountry']) ? Horde_Nls::getCountryISO($hash['homeCountry']) : null;
                 break;
             case 'otherCountry':
                 $message->othercountry = !empty($hash['otherCountryFree']) ? $hash['otherCountryFree'] : !empty($hash['otherCountry']) ? Horde_Nls::getCountryISO($hash['otherCountry']) : null;
                 break;
             case 'workCountry':
                 $message->businesscountry = !empty($hash['workCountryFree']) ? $hash['workCountryFree'] : !empty($hash['workCountry']) ? Horde_Nls::getCountryISO($hash['workCountry']) : null;
                 break;
             case 'email':
                 $message->email1address = $value;
                 break;
             case 'homeEmail':
                 $message->email2address = $value;
                 break;
             case 'workEmail':
                 $message->email3address = $value;
                 break;
             case 'emails':
                 $address = 1;
                 foreach (explode(',', $value) as $email) {
                     while ($address <= 3 && $message->{'email' . $address . 'address'}) {
                         $address++;
                     }
                     if ($address > 3) {
                         break;
                     }
                     $message->{'email' . $address . 'address'} = $email;
                     $address++;
                 }
                 break;
             case 'children':
                 // Children FROM horde are a simple string value. Even though EAS
                 // uses an array stucture to pass them, we pass as a single
                 // string since we can't assure what delimter the user will
                 // use and (at least in some languages) a comma can be used
                 // within a full name.
                 $message->children = array($value);
                 break;
             case 'notes':
                 if ($options['protocolversion'] > Horde_ActiveSync::VERSION_TWOFIVE) {
                     $bp = $options['bodyprefs'];
                     $note = new Horde_ActiveSync_Message_AirSyncBaseBody();
                     // No HTML supported in Turba's notes. Always use plaintext.
                     $note->type = Horde_ActiveSync::BODYPREF_TYPE_PLAIN;
                     if (isset($bp[Horde_ActiveSync::BODYPREF_TYPE_PLAIN]['truncationsize'])) {
                         if (Horde_String::length($value) > $bp[Horde_ActiveSync::BODYPREF_TYPE_PLAIN]['truncationsize']) {
                             $note->data = Horde_String::substr($value, 0, $bp[Horde_ActiveSync::BODYPREF_TYPE_PLAIN]['truncationsize']);
                             $note->truncated = 1;
                         } else {
                             $note->data = $value;
                         }
                         $note->estimateddatasize = Horde_String::length($value);
                     }
                     $message->airsyncbasebody = $note;
                 } else {
                     // EAS 2.5
                     $message->body = $value;
                     $message->bodysize = strlen($message->body);
                     $message->bodytruncated = 0;
                 }
                 break;
             case 'birthday':
             case 'anniversary':
                 if (!empty($value) && $value != '0000-00-00') {
                     try {
                         $date = new Horde_Date($value);
                     } catch (Horde_Date_Exception $e) {
                         $message->{$field} = null;
                     }
                     // Some sanity checking to make sure the date was
                     // successfully parsed.
                     if ($date->month != 0) {
                         $message->{$field} = $date;
                     } else {
                         $message->{$field} = null;
                     }
                 } else {
                     $message->{$field} = null;
                 }
                 break;
         }
     }
     /* Get tags. */
     $message->categories = explode(',', $object->getValue('__tags'));
     if (empty($this->fileas)) {
         $message->fileas = Turba::formatName($object);
     }
     return $message;
 }