From: Stefan Schantl Date: Tue, 12 May 2015 18:41:35 +0000 (+0200) Subject: country.cgi: Rework script. X-Git-Tag: v2.17-core91~30^2^2~16^2 X-Git-Url: http://git.ipfire.org/?p=ipfire-2.x.git;a=commitdiff_plain;h=8fba24ec1503d9cf3ace983d35dc0bab54a1e510 country.cgi: Rework script. * Introduce new method to get all country codes. In the past just the countries has been used for which flag icons where available, which is just not what we want. * Finish column when the last element in the array has passed and we have an uneven amount of items * Improve code style. --- diff --git a/html/cgi-bin/country.cgi b/html/cgi-bin/country.cgi index 60c2e5869e..f2ae813009 100644 --- a/html/cgi-bin/country.cgi +++ b/html/cgi-bin/country.cgi @@ -23,12 +23,9 @@ use strict; use Locale::Codes::Country; -my $flagdir = '/srv/web/ipfire/html/images/flags'; +my $col; my $lines = '1'; my $lines2 = ''; -my @flaglist=(); -my @flaglistfiles=(); -my $flag = ''; require '/var/ipfire/general-functions.pl'; require "${General::swroot}/geoip-functions.pl"; @@ -41,44 +38,41 @@ require "${General::swroot}/header.pl"; &Header::openbigbox('100%', 'left'); &Header::openbox('100%', 'left', $Lang::tr{'country codes and flags'}); -print ""; -print ""; -print ""; -print ""; -print ""; -print ""; -print ""; -print ""; - -@flaglist = <$flagdir/*>; - -undef @flaglistfiles; - -foreach (@flaglist) -{ - if (!-d) { push(@flaglistfiles,substr($_,rindex($_,"/")+1)); } -} -my $col=""; -foreach $flag (@flaglistfiles) -{ + +print< + + + + + + + + + +END + +# Get a list of all supported country codes. +my @countries = Locale::Codes::Country::all_country_codes(); + +# Loop through whole country list. +foreach my $country (@countries) { $lines++; - my $flagcode = uc(substr($flag, 0, 2)); - my $fcode = lc($flagcode); + # Convert country code into upper case. + my $country_uc = uc($country); # Get flag icon for of the country. - my $flag_icon = &GeoIP::get_flag_icon($fcode); + my $flag_icon = &GeoIP::get_flag_icon($country); + + # Get country name. + my $name = &GeoIP::get_full_country_name($country); - my $country = Locale::Country::code2country($fcode); - if($fcode eq 'eu') { $country = 'Europe'; } - if($fcode eq 'tp') { $country = 'East Timor'; } - if($fcode eq 'yu') { $country = 'Yugoslavia'; } if ($lines % 2) { - print ""; - print ""; - print "\n"; - } - else { + print ""; + print ""; + print "\n"; + } else { $lines2++; if($lines2 % 2) { $col="style='background-color:${Header::table2colour};'"; @@ -86,25 +80,25 @@ foreach $flag (@flaglistfiles) $col="style='background-color:${Header::table1colour};'"; } print ""; - print ""; - print ""; - print ""; + print ""; + print ""; + print ""; print ""; + + # Finish column when the last element in the array has passed and we have an uneven amount of items. + if ( $country eq $countries[-1] ) { + print "\n"; + print "\n"; + print "\n"; + } } } - - print "
$Lang::tr{'flag'}$Lang::tr{'countrycode'}$Lang::tr{'country'} $Lang::tr{'flag'}$Lang::tr{'countrycode'}$Lang::tr{'country'}
$Lang::tr{'flag'}$Lang::tr{'countrycode'}$Lang::tr{'country'} $Lang::tr{'flag'}$Lang::tr{'countrycode'}$Lang::tr{'country'}
$flagcode$flagcode$country
$country_uc$country_uc$name
$flagcode$flagcode$country$country_uc$country_uc$name    
"; &Header::closebox(); &Header::closebigbox(); -print < -$Lang::tr{'back'} - -END -; +print "
$Lang::tr{'back'}
\n"; &Header::closepage();