Commit:    468b7365484650e84bb9322568b907cd7ddaa71a
Author:    Hannes Magnusson <[email protected]>         Fri, 28 Mar 2014 
00:24:21 -0700
Parents:   71620bd09e7e28ce985bef1e9cdeca7fdb9f625e
Branches:  master

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

Log:
Always use 3letter country codes - except when parsing usergroups.js

This quickfixes invalid flags, default listing, links, and makes it consistent 
with the rest of
the site

Changed paths:
  M  include/layout.inc
  M  include/site.inc
  M  ug.php


Diff:
diff --git a/include/layout.inc b/include/layout.inc
index 92df808..e3e7828 100644
--- a/include/layout.inc
+++ b/include/layout.inc
@@ -604,13 +604,15 @@ function get_near_usergroups()
 
 }
 function get_usergroups_in($country, &$allcountries = array()) {
+    global $COUNTRY_ALPHA_2_TO_3;
+
     $filename = $_SERVER["DOCUMENT_ROOT"] . "/backend/usergroups.json";
 
     $matches = array();
     $data = json_decode(file_get_contents($filename), true);
     foreach($data["groups"] as $group) {
         if (isset($group["country"])) {
-            $allcountries[$group["country"]] = 1;
+            $allcountries[$COUNTRY_ALPHA_2_TO_3[$group["country"]]] = 1;
             if ($group["country"] == $country) {
                 $matches[] = $group;
             }
diff --git a/include/site.inc b/include/site.inc
index 6960180..b3f8277 100644
--- a/include/site.inc
+++ b/include/site.inc
@@ -11,6 +11,10 @@ include $_SERVER['DOCUMENT_ROOT'] . '/include/countries.inc';
 // Define $COUNTRIES_ALPHA2 array
 include $_SERVER['DOCUMENT_ROOT'] . '/include/countries-alpha2.inc';
 
+// Define $COUNTRY_ALPHA_2_TO_3 array
+include $_SERVER['DOCUMENT_ROOT'] . '/include/countries_alpha_mapping.inc';
+
+
 // Define $LANGUAGES array
 include $_SERVER['DOCUMENT_ROOT'] . '/include/languages.inc';
 
diff --git a/ug.php b/ug.php
index e779e61..50103ac 100644
--- a/ug.php
+++ b/ug.php
@@ -12,10 +12,10 @@ site_header("Hypertext Preprocessor",
 
 
 function print_cc_header($country) {
-    global $COUNTRIES_ALPHA2;
+    global $COUNTRIES;
     ?>
     <div class="country" id="<?php echo $country ?>">
-    <h2 class="title countrytitle">User Groups in <?php echo 
$COUNTRIES_ALPHA2[$country] ?>
+    <h2 class="title countrytitle">User Groups in <?php echo 
$COUNTRIES[$country] ?>
         <img height="25" width="45" src="/images/flags/beta/<?php echo 
strtolower($country) ?>.png">
     </h2>
     <ul class="ugs">
@@ -71,7 +71,7 @@ function ug_get_next_even_from_ical_array($ical) {
     return array("event" => $data);
 }
 function print_ug_matches($matches) {
-    global $COUNTRIES_ALPHA2, $country;
+    global $COUNTRIES, $country;
     $content = "";
     echo '<dl>';
     foreach($matches as $group) {
@@ -93,23 +93,16 @@ function print_ug_matches($matches) {
         echo '<dt class="ug"><a href="'. $group["url"].'">' . $group["name"] . 
"</a></dt><dd>$details</dd>";
     }
     if (!$matches) {
-        echo "<dt>Sorry</dt><dd>There are no known User Groups in 
{$COUNTRIES_ALPHA2[$country]} at this time :(</dd>";
+        echo "<dt>Sorry</dt><dd>There are no known User Groups in 
{$COUNTRIES[$country]} at this time :(</dd>";
     }
     echo "</dl>";
 }
 
-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);
-$country = isset($_GET["cc"]) ? $_GET["cc"] : $COUNTRY_ALPHA_2;
+//$COUNTRY_ALPHA_2 = get_alpha2_country_from_alpha3($COUNTRY);
+$country = isset($_GET["cc"]) ? $_GET["cc"] : $COUNTRY;
 $allcountries = array();
-$matches = get_usergroups_in($country, $allcountries);
-if (isset($COUNTRIES_ALPHA2[$country])) {
+$matches = get_usergroups_in($COUNTRY_ALPHA_3_TO_2[$country], $allcountries);
+if (isset($COUNTRIES[$country])) {
     print_cc_header($country);
     print_ug_matches($matches);
 } else {
@@ -117,15 +110,15 @@ if (isset($COUNTRIES_ALPHA2[$country])) {
 }
 
 uksort($allcountries, function($first, $second){
-    global $COUNTRIES_ALPHA2;
-    return strnatcasecmp($COUNTRIES_ALPHA2[$first], 
$COUNTRIES_ALPHA2[$second]);
+    global $COUNTRIES;
+    return strnatcasecmp($COUNTRIES[$first], $COUNTRIES[$second]);
 });
 
 $SIDEBAR_DATA = <<< EOF
     <p class="panel"><a href="http://php.ug/ug/promote";>Register new UG</a></p>
 EOF;
 foreach($allcountries as $country => $nada) {
-    $SIDEBAR_DATA .= '<p class="panel"><a href="/ug.php?cc=' . $country . '">' 
. $COUNTRIES_ALPHA2[$country] . '</a></p>';
+    $SIDEBAR_DATA .= '<p class="panel"><a href="/ug.php?cc=' . $country . '">' 
. $COUNTRIES[$country] . '</a></p>';
 }
 
 // Print the common footer.


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

Reply via email to