Commit:    36363ee66ccf98f81dcb872f0679cec89ccc1b9b
Author:    Andreas Heigl <andr...@heigl.org>         Thu, 27 Mar 2014 21:17:02 
+0100
Parents:   3fcbf8d60de18591b7e4ec5d8ecc71d5d960f4b3
Branches:  master

Link:       
http://git.php.net/?p=web/php.git;a=commitdiff;h=36363ee66ccf98f81dcb872f0679cec89ccc1b9b

Log:
Adds possibility to map alpha3 to alpha2 code

Currently the country-code automatically detected by the site is a three
letter code. Therefore current users will always see an 'Unknown
Country' when they try to see alist of Usergroups. To show them lists in
their country I've added a mapping between 3- and 2-letter code

Changed paths:
  A  include/countries_alpha_mapping.inc
  M  ug.php


Diff:
diff --git a/include/countries_alpha_mapping.inc 
b/include/countries_alpha_mapping.inc
new file mode 100644
index 0000000..70e0a1f
--- /dev/null
+++ b/include/countries_alpha_mapping.inc
@@ -0,0 +1,254 @@
+<?php
+/**
+ * This file has been extracted from 
http://opengeocode.org/download/countrynames.txt
+ */
+return array(
+ "AFG" => "AF",
+ "ALA" => "AX",
+ "ALB" => "AL",
+ "DZA" => "DZ",
+ "ASM" => "AS",
+ "AND" => "AD",
+ "AGO" => "AO",
+ "AIA" => "AI",
+ "ATA" => "AQ",
+ "ATG" => "AG",
+ "ARG" => "AR",
+ "ARM" => "AM",
+ "ABW" => "AW",
+ "AUS" => "AU",
+ "AUT" => "AT",
+ "AZE" => "AZ",
+ "BHS" => "BS",
+ "BHR" => "BH",
+ "BGD" => "BD",
+ "BRB" => "BB",
+ "BLR" => "BY",
+ "BEL" => "BE",
+ "BLZ" => "BZ",
+ "BEN" => "BJ",
+ "BMU" => "BM",
+ "BTN" => "BT",
+ "BOL" => "BO",
+ "BES" => "BQ",
+ "BIH" => "BA",
+ "BWA" => "BW",
+ "BVT" => "BV",
+ "BRA" => "BR",
+ "IOT" => "IO",
+ "BRN" => "BN",
+ "BGR" => "BG",
+ "BFA" => "BF",
+ "BDI" => "BI",
+ "KHM" => "KH",
+ "CMR" => "CM",
+ "CAN" => "CA",
+ "CPV" => "CV",
+ "CYM" => "KY",
+ "CAF" => "CF",
+ "TCD" => "TD",
+ "CHL" => "CL",
+ "CHN" => "CN",
+ "CXR" => "CX",
+ "CCK" => "CC",
+ "COL" => "CO",
+ "COM" => "KM",
+ "COG" => "CG",
+ "COD" => "CD",
+ "COK" => "CK",
+ "CRI" => "CR",
+ "CIV" => "CI",
+ "HRV" => "HR",
+ "CUB" => "CU",
+ "CUW" => "CW",
+ "CYP" => "CY",
+ "CZE" => "CZ",
+ "DNK" => "DK",
+ "DJI" => "DJ",
+ "DMA" => "DM",
+ "DOM" => "DO",
+ "ECU" => "EC",
+ "EGY" => "EG",
+ "SLV" => "SV",
+ "GNQ" => "GQ",
+ "ERI" => "ER",
+ "EST" => "EE",
+ "ETH" => "ET",
+ "FLK" => "FK",
+ "534" => "FO",
+ "FJI" => "FJ",
+ "FIN" => "FI",
+ "FRA" => "FR",
+ "GUF" => "GF",
+ "PYF" => "PF",
+ "ATF" => "TF",
+ "GAB" => "GA",
+ "GMB" => "GM",
+ "GEO" => "GE",
+ "DEU" => "DE",
+ "GHA" => "GH",
+ "GIB" => "GI",
+ "GRC" => "GR",
+ "GRL" => "GL",
+ "GRD" => "GD",
+ "GLP" => "GP",
+ "GUM" => "GU",
+ "GTM" => "GT",
+ "GGY" => "GG",
+ "GIN" => "GN",
+ "GNB" => "GW",
+ "GUY" => "GY",
+ "HTI" => "HT",
+ "HMD" => "HM",
+ "VAT" => "VA",
+ "HND" => "HN",
+ "HKG" => "HK",
+ "HUN" => "HU",
+ "ISL" => "IS",
+ "IND" => "IN",
+ "IDN" => "ID",
+ "IRN" => "IR",
+ "IRQ" => "IQ",
+ "IRL" => "IE",
+ "IMN" => "IM",
+ "ISR" => "IL",
+ "ITA" => "IT",
+ "JAM" => "JM",
+ "JPN" => "JP",
+ "JEY" => "JE",
+ "JOR" => "JO",
+ "KAZ" => "KZ",
+ "KEN" => "KE",
+ "KIR" => "KI",
+ "PRK" => "KP",
+ "KOR" => "KR",
+ "KWT" => "KW",
+ "KGZ" => "KG",
+ "LAO" => "LA",
+ "LVA" => "LV",
+ "LBN" => "LB",
+ "LSO" => "LS",
+ "LBR" => "LR",
+ "LBY" => "LY",
+ "LIE" => "LI",
+ "LTU" => "LT",
+ "LUX" => "LU",
+ "MAC" => "MO",
+ "MKD" => "MK",
+ "MDG" => "MG",
+ "MWI" => "MW",
+ "MYS" => "MY",
+ "MDV" => "MV",
+ "MLI" => "ML",
+ "MLT" => "MT",
+ "MHL" => "MH",
+ "MTQ" => "MQ",
+ "MRT" => "MR",
+ "MUS" => "MU",
+ "MYT" => "YT",
+ "MEX" => "MX",
+ "FSM" => "FM",
+ "MDA" => "MD",
+ "MCO" => "MC",
+ "MNG" => "MN",
+ "MNE" => "ME",
+ "MSR" => "MS",
+ "MAR" => "MA",
+ "MOZ" => "MZ",
+ "MMR" => "MM",
+ "NAM" => "NA",
+ "NRU" => "NR",
+ "NPL" => "NP",
+ "NLD" => "NL",
+ "NCL" => "NC",
+ "NZL" => "NZ",
+ "NIC" => "NI",
+ "NER" => "NE",
+ "NGA" => "NG",
+ "NIU" => "NU",
+ "NFK" => "NF",
+ "MNP" => "MP",
+ "NOR" => "NO",
+ "PSE" => "PS",
+ "OMN" => "OM",
+ "PAK" => "PK",
+ "PLW" => "PW",
+ "PAN" => "PA",
+ "PNG" => "PG",
+ "PRY" => "PY",
+ "PER" => "PE",
+ "PHL" => "PH",
+ "PCN" => "PN",
+ "POL" => "PL",
+ "PRT" => "PT",
+ "PRI" => "PR",
+ "QAT" => "QA",
+ "REU" => "RE",
+ "ROU" => "RO",
+ "RUS" => "RU",
+ "RWA" => "RW",
+ "534" => "BL",
+ "SHN" => "SH",
+ "KNA" => "KN",
+ "LCA" => "LC",
+ "MAF" => "MF",
+ "SPM" => "PM",
+ "VCT" => "VC",
+ "WSM" => "WS",
+ "SMR" => "SM",
+ "STP" => "ST",
+ "SAU" => "SA",
+ "SEN" => "SN",
+ "SRB" => "RS",
+ "SYC" => "SC",
+ "SLE" => "SL",
+ "SGP" => "SG",
+ "SXM" => "SX",
+ "SVK" => "SK",
+ "SVN" => "SI",
+ "SLB" => "SB",
+ "SOM" => "SO",
+ "ZAF" => "ZA",
+ "SGS" => "GS",
+ "ESP" => "ES",
+ "LKA" => "LK",
+ "SDN" => "SD",
+ "SUR" => "SR",
+ "534" => "SJ",
+ "SWZ" => "SZ",
+ "SWE" => "SE",
+ "CHE" => "CH",
+ "SYR" => "SY",
+ "TWN" => "TW",
+ "TJK" => "TJ",
+ "TZA" => "TZ",
+ "THA" => "TH",
+ "TLS" => "TL",
+ "TGO" => "TG",
+ "TKL" => "TK",
+ "TON" => "TO",
+ "TTO" => "TT",
+ "TUN" => "TN",
+ "TUR" => "TR",
+ "TKM" => "TM",
+ "TCA" => "TC",
+ "TUV" => "TV",
+ "UGA" => "UG",
+ "UKR" => "UA",
+ "ARE" => "AE",
+ "GBR" => "GB",
+ "USA" => "US",
+ "UMI" => "UM",
+ "URY" => "UY",
+ "UZB" => "UZ",
+ "VUT" => "VU",
+ "VEN" => "VE",
+ "VNM" => "VN",
+ "VGB" => "VG",
+ "VIR" => "VI",
+ "WLF" => "WF",
+ "ESH" => "EH",
+ "YEM" => "YE",
+ "ZMB" => "ZM",
+ "ZWE" => "ZW",
+ );
\ No newline at end of file
diff --git a/ug.php b/ug.php
index d485eaf..76747c3 100644
--- a/ug.php
+++ b/ug.php
@@ -98,7 +98,16 @@ function print_ug_matches($matches) {
     echo "</dl>";
 }
 
-$country = isset($_GET["cc"]) ? $_GET["cc"] : $COUNTRY;
+function get_alpha2_country_from_alpha3($country) {
+    $countries = include dirname(__FILE__) . 
'/include/countries_alpha_mapping.inc';
+    if (! isset($countries[$country])) {
+        return '';
+    }
+    return $countries[$country];
+}
+$COUNTRY_ALPHA_2 = get_alpha2_country_from_alpha3($COUNTRY);
+echo $COUNTRY_ALPHA_2 . '::' . $COUNTRY;
+$country = isset($_GET["cc"]) ? $_GET["cc"] : $COUNTRY_ALPHA_2;
 $allcountries = array();
 if (isset($COUNTRIES_ALPHA2[$country])) {
     $matches = get_usergroups_in($country, $allcountries);


--
PHP Webmaster List Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to