phpgroupware-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Phpgroupware-cvs] [18963] update country class generator and generate a


From: Dave Hall
Subject: [Phpgroupware-cvs] [18963] update country class generator and generate a new version
Date: Mon, 06 Oct 2008 10:33:46 +0000

Revision: 18963
          
http://svn.sv.gnu.org/viewvc/?view=rev&root=phpgroupware&revision=18963
Author:   skwashd
Date:     2008-10-06 10:33:45 +0000 (Mon, 06 Oct 2008)

Log Message:
-----------
update country class generator and generate a new version

Modified Paths:
--------------
    modules/phpgwapi/trunk/doc/generate-class-country.php
    modules/phpgwapi/trunk/inc/class.country.inc.php

Modified: modules/phpgwapi/trunk/doc/generate-class-country.php
===================================================================
--- modules/phpgwapi/trunk/doc/generate-class-country.php       2008-10-05 
14:05:17 UTC (rev 18962)
+++ modules/phpgwapi/trunk/doc/generate-class-country.php       2008-10-06 
10:33:45 UTC (rev 18963)
@@ -14,48 +14,85 @@
        * @copyright Portions Copyright (C) 2006 Free Software Foundation 
http://www.fsf.org/
        * @license http://www.gnu.org/licenses/gpl.html GNU General Public 
License
        */
-       echo"<?php\n";
-?>
+
+       $year = date('Y');
+
+       // Do not change this, it ensures we are using utf-8 :)
+       setlocale(LC_ALL, 'en_US.UTF-8');
+
+       $raw_file = 
file_get_contents('http://www.iso.ch/iso/en/prods-services/iso3166ma/02iso-3166-code-lists/list-en1-semic.txt');
+       $cc_list = explode("\r\n", $raw_file);
+       if ( count($cc_list) < 3 )
+       {
+               echo "Invalid country code list, exiting\n";
+               exit;
+       }
+       unset($cc_list[0]);
+
+
+       echo <<<CODE
+<?php
        /**
-       * Countries
+       * phpGroupWare - ISO 3166 Countries and Continents
+       *
+       * @auhtor Dave Hall skwashd at phpGroupWare.org
        * @author Mark Peters <address@hidden>
-       * @auhtor Dave Hall skwashd at phpGroupWare.org
        * @author Bettine Gille ceb at phpGroupWare.org
-       * @copyright Copyright (C) 2001 - 2006 Free Software Foundation 
http://www.fsf.org/
+       * @copyright Copyright (C) 2001 - {$year} Free Software Foundation 
http://www.fsf.org/
        * @license http://www.gnu.org/licenses/gpl.html GNU General Public 
License
        * @interal do not edit, edit and run 
phpgwapi/doc/generate-class-country.php to regenerate this class
        * @package phpgwapi
        * @subpackage contacts
-       * @version $Id$
+       * @version \$Id: \$
        */
 
+       /*
+          This program is free software: you can redistribute it and/or modify
+          it under the terms of the GNU General Public License as published by
+          the Free Software Foundation, either version 3 of the License, or
+          (at your option) any later version.
+
+          This program is distributed in the hope that it will be useful,
+          but WITHOUT ANY WARRANTY; without even the implied warranty of
+          MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+          GNU General Public License for more details.
+
+          You should have received a copy of the GNU General Public License
+          along with this program.  If not, see <http://www.gnu.org/licenses/>.
+        */
+
        /**
        * Countries
        *
        * @package phpgwapi
        * @subpackage contacts
        */
-       class country
+       class phpgwapi_country
        {
 
                /**
-               * @var array $continent_array a list of continents
+               * @var array \$continent_array a list of continents
                */
-               var $continent_array = array();
-<?php
-       // Do not change this, it ensures we are using utf-8 :)
-       setlocale(LC_ALL, 'en_US.UTF-8');
+               public static \$continent_array = array
+               (
+                       'africa'                => 'Africa',
+                       'antarctica'    => 'Antarctica',
+                       'asia'                  => 'Asia',
+                       'australia'             => 'Australia',
+                       'europe'                => 'Europe',
+                       'northamerica'  => 'North America',
+                       'southamerica'  => 'South America'
+               );
 
-       $raw_file = 
file_get_contents('http://www.iso.ch/iso/en/prods-services/iso3166ma/02iso-3166-code-lists/list-en1-semic.txt');
-       $cc_list = explode("\r\n", $raw_file);
-       if ( count($cc_list) < 3 )
-       {
-               echo "Invalid country code list, exiting\n";
-               exit;
-       }
-       unset($cc_list[0]);
 
-       echo "\n\t\t/**\n\t\t* @var array \$country_array list of ISO 3166 
country codes\n\t\t*/\n\t\tvar \$country_array = array\n\t\t(\n\t\t\t'  '\t=> 
'Select One',\n";
+               /**
+               * @var array $country_array list of ISO 3166 country codes
+               */
+               public static \$country_array = array
+               (
+
+CODE;
+
        sort($cc_list, SORT_LOCALE_STRING);
        foreach ( $cc_list as $entry )
        {
@@ -67,46 +104,35 @@
                $country = explode(';', iconv('ISO-8859-1', 'UTF-8', $entry));
                echo "\t\t\t'" . trim($country[1]) . "'\t=> '" . 
addslashes(trim($country[0])) . "',\n";
        }
-       echo "\t\t);\n\n";
+       echo <<<CODE
+               );
+
+CODE
 ?>
-               /**
-               * @constructor
-               */
-               function country()
-               {
-                       $this->continent_array = array
-                       (
-                               'africa'                => lang('africa'),
-                               'antarctica'    => lang('antarctica'),
-                               'asia'                  => lang('asia'),
-                               'australia'             => lang('australia'),
-                               'europe'                => lang('europe'),
-                               'northamerica'  => lang('northamerica'),
-                               'southamerica'  => lang('southamerica')
-                       );
-               }
 
                /**
-               * Create a select box filled with countries
+               * Translate the list of countries
                *
-               * @param string $selected the currently selected country
-               * @param string $name the name of the select box element in the 
form, used for both the id and name attributes
-               * @return string the html for a select box form element
+               * @return array list of translated country names iso_code => 
(translated) official name
                */
-               function form_select($selected,$name='')
+               public static function get_translated_list()
                {
-                       if($name=='')
+                       static $translated_list = null;
+                       if ( is_null($translated_list) )
                        {
-                               $name = 'country';
+                                $translated_list = array();
+                                foreach ( phpgwapi_country::$country_array as 
$code => $name )
+                                {
+                                       $translated = lang($name);
+                                       if ( $translated == "{$name}*" )
+                                       {
+                                               $translated = $name;
+                                       }
+                                       $translated_list[$code] = $translated;
+                                }
+                                asort($translated_list);
                        }
-                       $str = "<select name=\"$name\" id=\"$name\">\n";
-                       reset($this->country_array);
-                       while(list($key,$value) = each($this->country_array))
-                       {
-                               $str .= ' <option value="'.$key.'"'.($selected 
== $key?' selected="selected"':'').'>'.$value.'</option>'."\n";
-                       }
-                       $str .= '</select>'."\n";
-                       return $str;
+                       return $translated_list;
                }
 
                /**
@@ -117,9 +143,9 @@
                */
                function get_full_name($selected)
                {
-                       if ( isset($this->country_array[$selected]) )
+                       if ( isset(self::$country_array[$selected]) )
                        {
-                               return($this->country_array[$selected]);
+                               return(self::$country_array[$selected]);
                        }
                        return '';
                }
@@ -135,12 +161,12 @@
                {
                        $GLOBALS['phpgw']->xslttpl->add_file('countries');
 
-                       foreach($this->continent_array as $cname => $ctitle)
+                       foreach(self::continent_array as $cname => $ctitle)
                        {
                                $carray[] = array
                                (
                                        'continent_name'        => $cname,
-                                       'continent_title'       => $ctitle,
+                                       'continent_title'       => 
lang($ctitle),
                                        'selected'                      => 
$cname == $selected ? 'selected' : ''
                                );
                        }
@@ -164,7 +190,7 @@
                {
                        $GLOBALS['phpgw']->xslttpl->add_file('countries');
 
-                       foreach($this->country_array as $ccode => $cname)
+                       foreach(self::$country_array as $ccode => $cname)
                        {
                                $carray[] = array
                                (
@@ -182,4 +208,3 @@
                        );
                }
        }
-<?php echo '?>';?>

Modified: modules/phpgwapi/trunk/inc/class.country.inc.php
===================================================================
--- modules/phpgwapi/trunk/inc/class.country.inc.php    2008-10-05 14:05:17 UTC 
(rev 18962)
+++ modules/phpgwapi/trunk/inc/class.country.inc.php    2008-10-06 10:33:45 UTC 
(rev 18963)
@@ -1,10 +1,11 @@
 <?php
        /**
-       * Countries
+       * phpGroupWare - ISO 3166 Countries and Continents
+       *
+       * @auhtor Dave Hall skwashd at phpGroupWare.org
        * @author Mark Peters <address@hidden>
-       * @auhtor Dave Hall skwashd at phpGroupWare.org
        * @author Bettine Gille ceb at phpGroupWare.org
-       * @copyright Copyright (C) 2001 - 2006 Free Software Foundation 
http://www.fsf.org/
+       * @copyright Copyright (C) 2001 - 2008 Free Software Foundation 
http://www.fsf.org/
        * @license http://www.gnu.org/licenses/gpl.html GNU General Public 
License
        * @interal do not edit, edit and run 
phpgwapi/doc/generate-class-country.php to regenerate this class
        * @package phpgwapi
@@ -50,8 +51,9 @@
                        'southamerica'  => 'South America'
                );
 
+
                /**
-               * @var array $country_array list of ISO 3166 country codes
+               * @var array  list of ISO 3166 country codes
                */
                public static $country_array = array
                (
@@ -107,8 +109,8 @@
                        'CD'    => 'CONGO, THE DEMOCRATIC REPUBLIC OF THE',
                        'CK'    => 'COOK ISLANDS',
                        'CR'    => 'COSTA RICA',
-                       'CI'    => 'COTE D\'IVOIRE',
                        'HR'    => 'CROATIA',
+                       'CI'    => 'CÔTE D\'IVOIRE',
                        'CU'    => 'CUBA',
                        'CY'    => 'CYPRUS',
                        'CZ'    => 'CZECH REPUBLIC',
@@ -238,9 +240,11 @@
                        'RO'    => 'ROMANIA',
                        'RU'    => 'RUSSIAN FEDERATION',
                        'RW'    => 'RWANDA',
+                       'BL'    => 'SAINT BARTHÉLEMY',
                        'SH'    => 'SAINT HELENA',
                        'KN'    => 'SAINT KITTS AND NEVIS',
                        'LC'    => 'SAINT LUCIA',
+                       'MF'    => 'SAINT MARTIN',
                        'PM'    => 'SAINT PIERRE AND MIQUELON',
                        'VC'    => 'SAINT VINCENT AND THE GRENADINES',
                        'WS'    => 'SAMOA',
@@ -399,4 +403,3 @@
                        );
                }
        }
-?>






reply via email to

[Prev in Thread] Current Thread [Next in Thread]