This is the API documentation for concrete5 version 5.6 and earlier. View Current API Documentation
 1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 
<?php
/**
 * @package Helpers
 * @category Concrete
 * @author Andrew Embler <[email protected]>
 * @copyright  Copyright (c) 2003-2008 Concrete5. (http://www.concrete5.org)
 * @license    http://www.concrete5.org/license/     MIT License
 */

/**
 * Grabs a list of countries commonly used in web forms.
 * @package Helpers
 * @category Concrete
 * @author Andrew Embler <[email protected]>
 * @copyright  Copyright (c) 2003-2008 Concrete5. (http://www.concrete5.org)
 * @license    http://www.concrete5.org/license/     MIT License
 */

defined('C5_EXECUTE') or die("Access Denied.");
class Concrete5_Helper_Lists_Countries {

    /** Locale for which we currently loaded the data.
    * @var string
    */
    protected $locale = null;

    protected $countries = array();

    public function reset() {
        $locale = Localization::activeLocale();
        if($locale === $this->locale) {
            return;
        }
        $this->locale = $locale;
        Loader::library('3rdparty/Zend/Locale');
        $countries = Zend_Locale::getTranslationList('territory', $locale, 2);
        unset(
            // Fake countries
            $countries['FX'], // Metropolitan France (it's not a country, but its the part of France located in Europe, but we've already FR - France)
            $countries['IM'], // Isle of Man (it's a British Crown Dependency)
            $countries['JE'], // Jersey (it's a British Crown Dependency)
            $countries['NT'], // Neutral Zone
            $countries['PU'], // U.S. Miscellaneous Pacific Islands
            $countries['ZZ'], // Unknown or Invalid Region
            // Dismissed countries
            $countries['CS'], // Serbia and Montenegro (since 2006 has been spitted in Serbia and Montenegro)
            $countries['CT'], // Canton and Enderbury Islands (merged into Kiribati since 1979)
            $countries['DD'], // East Germany (merged with West Germany into Germany in 1990)
            $countries['PC'], // Pacific Islands Trust Territory (no more existing since 1994)
            $countries['PZ'], // Panama Canal Zone (merged into Panama since 2000)
            $countries['SU'], // Union of Soviet Socialist Republics (splitted into several countries since 1991)
            $countries['VD'], // North Vietnam (merged with South Vietnam into Socialist Republic of Vietnam in 1976)
            $countries['YD']  // People's Democratic Republic of Yemen (no more existing since 1990)
        );
        $countriesFromEvent = Events::fire('on_get_countries_list', $countries);
        if(is_array($countriesFromEvent)) {
            $countries = $countriesFromEvent;
        } else {
            asort($countries, SORT_LOCALE_STRING);
        }
        $this->countries = $countries;
    }

    /** Returns an array of countries with their short name as the key and their full name as the value
    * @return array Keys are the country codes, values are the county names
    */
    public function getCountries() {
        return $this->countries;
    }

    /** Gets a country full name given its code
    * @param string $code The country code
    * @return string
    */
    public function getCountryName($code) {
        $countries = $this->getCountries(true);
        return $countries[$code];
    }

}